diff options
author | Patrick McHardy <kaber@trash.net> | 2007-05-03 06:28:49 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2007-05-03 06:28:49 -0400 |
commit | dc1f6bff6a9d6733a07b9b97905bc824c055e8f4 (patch) | |
tree | 09c0ee7f91354b7d68ac2c0d6f53da6738530fdc /fs/afs/netdevices.c | |
parent | 4e9cac2ba437fcb093c7417b1cd91a77ebd1756a (diff) |
[AFS]: Replace rtnetlink client by direct dev_base walking
Replace the large and complicated rtnetlink client by two simple
functions for getting the MAC address for the first ethernet device
and building a list of IPv4 addresses.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'fs/afs/netdevices.c')
-rw-r--r-- | fs/afs/netdevices.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/fs/afs/netdevices.c b/fs/afs/netdevices.c new file mode 100644 index 000000000000..2b3087357fa9 --- /dev/null +++ b/fs/afs/netdevices.c | |||
@@ -0,0 +1,54 @@ | |||
1 | /* AFS network device helpers | ||
2 | * | ||
3 | * Copyright (c) 2007 Patrick McHardy <kaber@trash.net> | ||
4 | */ | ||
5 | |||
6 | #include <linux/string.h> | ||
7 | #include <linux/rtnetlink.h> | ||
8 | #include <linux/inetdevice.h> | ||
9 | #include <linux/netdevice.h> | ||
10 | #include <linux/if_arp.h> | ||
11 | #include "internal.h" | ||
12 | |||
13 | int afs_get_MAC_address(u8 mac[ETH_ALEN]) | ||
14 | { | ||
15 | struct net_device *dev; | ||
16 | int ret = -ENODEV; | ||
17 | |||
18 | rtnl_lock(); | ||
19 | dev = __dev_getfirstbyhwtype(ARPHRD_ETHER); | ||
20 | if (dev) { | ||
21 | memcpy(mac, dev->dev_addr, ETH_ALEN); | ||
22 | ret = 0; | ||
23 | } | ||
24 | rtnl_unlock(); | ||
25 | return ret; | ||
26 | } | ||
27 | |||
28 | int afs_get_ipv4_interfaces(struct afs_interface *bufs, size_t maxbufs, | ||
29 | bool wantloopback) | ||
30 | { | ||
31 | struct net_device *dev; | ||
32 | struct in_device *idev; | ||
33 | int n = 0; | ||
34 | |||
35 | rtnl_lock(); | ||
36 | for (dev = dev_base; dev; dev = dev->next) { | ||
37 | if (dev->type == ARPHRD_LOOPBACK && !wantloopback) | ||
38 | continue; | ||
39 | idev = __in_dev_get_rtnl(dev); | ||
40 | if (!idev) | ||
41 | continue; | ||
42 | for_primary_ifa(idev) { | ||
43 | if (n == maxbufs) | ||
44 | goto out; | ||
45 | bufs[n].address.s_addr = ifa->ifa_address; | ||
46 | bufs[n].netmask.s_addr = ifa->ifa_mask; | ||
47 | bufs[n].mtu = dev->mtu; | ||
48 | n++; | ||
49 | } endfor_ifa(idev) | ||
50 | } | ||
51 | out: | ||
52 | rtnl_unlock(); | ||
53 | return n; | ||
54 | } | ||