aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2007-05-03 06:29:41 -0400
committerDavid S. Miller <davem@davemloft.net>2007-05-03 06:29:41 -0400
commitec9c948546a84d0dcee851be1009a8066958e69d (patch)
treea812ede303158d36e1d4a1530009044cd37f39ea /fs
parentdc1f6bff6a9d6733a07b9b97905bc824c055e8f4 (diff)
[AFS]: Adjust the new netdevice scanning code
Adjust the new netdevice scanning code provided by Patrick McHardy: (1) Restore the function banner comments that were dropped. (2) Rather than using an array size of 6 in some places and an array size of ETH_ALEN in others, pass a pointer instead and pass the array size through so that we can actually check it. (3) Do the buffer fill count check before checking the for_primary_ifa condition again. This permits us to skip that check should maxbufs be reached before we run out of interfaces. Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'fs')
-rw-r--r--fs/afs/internal.h2
-rw-r--r--fs/afs/main.c2
-rw-r--r--fs/afs/netdevices.c24
3 files changed, 21 insertions, 7 deletions
diff --git a/fs/afs/internal.h b/fs/afs/internal.h
index 551db896afc9..d90c158cd934 100644
--- a/fs/afs/internal.h
+++ b/fs/afs/internal.h
@@ -563,7 +563,7 @@ extern void afs_fs_exit(void);
563 * use-rtnetlink.c 563 * use-rtnetlink.c
564 */ 564 */
565extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool); 565extern int afs_get_ipv4_interfaces(struct afs_interface *, size_t, bool);
566extern int afs_get_MAC_address(u8 [6]); 566extern int afs_get_MAC_address(u8 *, size_t);
567 567
568/* 568/*
569 * vlclient.c 569 * vlclient.c
diff --git a/fs/afs/main.c b/fs/afs/main.c
index 40c2704e7557..80ec6fd19a73 100644
--- a/fs/afs/main.c
+++ b/fs/afs/main.c
@@ -54,7 +54,7 @@ static int __init afs_get_client_UUID(void)
54 54
55 /* read the MAC address of one of the external interfaces and construct 55 /* read the MAC address of one of the external interfaces and construct
56 * a UUID from it */ 56 * a UUID from it */
57 ret = afs_get_MAC_address(afs_uuid.node); 57 ret = afs_get_MAC_address(afs_uuid.node, sizeof(afs_uuid.node));
58 if (ret < 0) 58 if (ret < 0)
59 return ret; 59 return ret;
60 60
diff --git a/fs/afs/netdevices.c b/fs/afs/netdevices.c
index 2b3087357fa9..ce08977858e0 100644
--- a/fs/afs/netdevices.c
+++ b/fs/afs/netdevices.c
@@ -10,21 +10,33 @@
10#include <linux/if_arp.h> 10#include <linux/if_arp.h>
11#include "internal.h" 11#include "internal.h"
12 12
13int afs_get_MAC_address(u8 mac[ETH_ALEN]) 13/*
14 * get a MAC address from a random ethernet interface that has a real one
15 * - the buffer will normally be 6 bytes in size
16 */
17int afs_get_MAC_address(u8 *mac, size_t maclen)
14{ 18{
15 struct net_device *dev; 19 struct net_device *dev;
16 int ret = -ENODEV; 20 int ret = -ENODEV;
17 21
22 if (maclen != ETH_ALEN)
23 BUG();
24
18 rtnl_lock(); 25 rtnl_lock();
19 dev = __dev_getfirstbyhwtype(ARPHRD_ETHER); 26 dev = __dev_getfirstbyhwtype(ARPHRD_ETHER);
20 if (dev) { 27 if (dev) {
21 memcpy(mac, dev->dev_addr, ETH_ALEN); 28 memcpy(mac, dev->dev_addr, maclen);
22 ret = 0; 29 ret = 0;
23 } 30 }
24 rtnl_unlock(); 31 rtnl_unlock();
25 return ret; 32 return ret;
26} 33}
27 34
35/*
36 * get a list of this system's interface IPv4 addresses, netmasks and MTUs
37 * - maxbufs must be at least 1
38 * - returns the number of interface records in the buffer
39 */
28int afs_get_ipv4_interfaces(struct afs_interface *bufs, size_t maxbufs, 40int afs_get_ipv4_interfaces(struct afs_interface *bufs, size_t maxbufs,
29 bool wantloopback) 41 bool wantloopback)
30{ 42{
@@ -32,6 +44,8 @@ int afs_get_ipv4_interfaces(struct afs_interface *bufs, size_t maxbufs,
32 struct in_device *idev; 44 struct in_device *idev;
33 int n = 0; 45 int n = 0;
34 46
47 ASSERT(maxbufs > 0);
48
35 rtnl_lock(); 49 rtnl_lock();
36 for (dev = dev_base; dev; dev = dev->next) { 50 for (dev = dev_base; dev; dev = dev->next) {
37 if (dev->type == ARPHRD_LOOPBACK && !wantloopback) 51 if (dev->type == ARPHRD_LOOPBACK && !wantloopback)
@@ -40,13 +54,13 @@ int afs_get_ipv4_interfaces(struct afs_interface *bufs, size_t maxbufs,
40 if (!idev) 54 if (!idev)
41 continue; 55 continue;
42 for_primary_ifa(idev) { 56 for_primary_ifa(idev) {
43 if (n == maxbufs)
44 goto out;
45 bufs[n].address.s_addr = ifa->ifa_address; 57 bufs[n].address.s_addr = ifa->ifa_address;
46 bufs[n].netmask.s_addr = ifa->ifa_mask; 58 bufs[n].netmask.s_addr = ifa->ifa_mask;
47 bufs[n].mtu = dev->mtu; 59 bufs[n].mtu = dev->mtu;
48 n++; 60 n++;
49 } endfor_ifa(idev) 61 if (n >= maxbufs)
62 goto out;
63 } endfor_ifa(idev);
50 } 64 }
51out: 65out:
52 rtnl_unlock(); 66 rtnl_unlock();