~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/afs/netdevices.c

Version: ~ [ linux-5.3-rc5 ] ~ [ linux-5.2.9 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.67 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.139 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.189 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.189 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.72 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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 <net/net_namespace.h>
 12 #include "internal.h"
 13 
 14 /*
 15  * get a MAC address from a random ethernet interface that has a real one
 16  * - the buffer will normally be 6 bytes in size
 17  */
 18 int afs_get_MAC_address(u8 *mac, size_t maclen)
 19 {
 20         struct net_device *dev;
 21         int ret = -ENODEV;
 22 
 23         BUG_ON(maclen != ETH_ALEN);
 24 
 25         rtnl_lock();
 26         dev = __dev_getfirstbyhwtype(&init_net, 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  */
 40 int 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(&init_net, 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         }
 65 out:
 66         rtnl_unlock();
 67         return n;
 68 }
 69 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp