aboutsummaryrefslogtreecommitdiffstats
path: root/fs/afs/netdevices.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-04 22:36:58 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-05-04 22:36:58 -0400
commit7e20ef030dde0e52dd5a57220ee82fa9facbea4e (patch)
tree5006db4f85a2d7be2777748aaff2966e79dddc6f /fs/afs/netdevices.c
parenta3d52136ee8f7399859f9a0824470fd49b1d1a00 (diff)
parent07d939677166cc4f000c767196872a9becc2697b (diff)
Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/davem/net-2.6: (49 commits) [SCTP]: Set assoc_id correctly during INIT collision. [SCTP]: Re-order SCTP initializations to avoid race with sctp_rcv() [SCTP]: Fix the SO_REUSEADDR handling to be similar to TCP. [SCTP]: Verify all destination ports in sctp_connectx. [XFRM] SPD info TLV aggregation [XFRM] SAD info TLV aggregationx [AF_RXRPC]: Sort out MTU handling. [AF_IUCV/IUCV] : Add missing section annotations [AF_IUCV]: Implementation of a skb backlog queue [NETLINK]: Remove bogus BUG_ON [IPV6]: Some cleanups in include/net/ipv6.h [TCP]: zero out rx_opt in tcp_disconnect() [BNX2]: Fix TSO problem with small MSS. [NET]: Rework dev_base via list_head (v3) [TCP] Highspeed: Limited slow-start is nowadays in tcp_slow_start [BNX2]: Update version and reldate. [BNX2]: Print bus information for PCIE devices. [BNX2]: Add 1-shot MSI handler for 5709. [BNX2]: Restructure PHY event handling. [BNX2]: Add indirect spinlock. ...
Diffstat (limited to 'fs/afs/netdevices.c')
-rw-r--r--fs/afs/netdevices.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/fs/afs/netdevices.c b/fs/afs/netdevices.c
new file mode 100644
index 000000000000..fc27d4b52e5f
--- /dev/null
+++ b/fs/afs/netdevices.c
@@ -0,0 +1,68 @@
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/*
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)
18{
19 struct net_device *dev;
20 int ret = -ENODEV;
21
22 if (maclen != ETH_ALEN)
23 BUG();
24
25 rtnl_lock();
26 dev = __dev_getfirstbyhwtype(ARPHRD_ETHER);
27 if (dev) {
28 memcpy(mac, dev->dev_addr, maclen);
29 ret = 0;
30 }
31 rtnl_unlock();
32 return ret;
33}
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 */
40int afs_get_ipv4_interfaces(struct afs_interface *bufs, size_t maxbufs,
41 bool wantloopback)
42{
43 struct net_device *dev;
44 struct in_device *idev;
45 int n = 0;
46
47 ASSERT(maxbufs > 0);
48
49 rtnl_lock();
50 for_each_netdev(dev) {
51 if (dev->type == ARPHRD_LOOPBACK && !wantloopback)
52 continue;
53 idev = __in_dev_get_rtnl(dev);
54 if (!idev)
55 continue;
56 for_primary_ifa(idev) {
57 bufs[n].address.s_addr = ifa->ifa_address;
58 bufs[n].netmask.s_addr = ifa->ifa_mask;
59 bufs[n].mtu = dev->mtu;
60 n++;
61 if (n >= maxbufs)
62 goto out;
63 } endfor_ifa(idev);
64 }
65out:
66 rtnl_unlock();
67 return n;
68}