[AFS]: Replace rtnetlink client by direct dev_base walking
[safe/jmp/linux-2.6] / fs / afs / netdevices.c
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 }