]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
dc1f6bff PM |
2 | /* AFS network device helpers |
3 | * | |
4 | * Copyright (c) 2007 Patrick McHardy <[email protected]> | |
5 | */ | |
6 | ||
7 | #include <linux/string.h> | |
8 | #include <linux/rtnetlink.h> | |
9 | #include <linux/inetdevice.h> | |
10 | #include <linux/netdevice.h> | |
11 | #include <linux/if_arp.h> | |
881d966b | 12 | #include <net/net_namespace.h> |
dc1f6bff PM |
13 | #include "internal.h" |
14 | ||
ec9c9485 DH |
15 | /* |
16 | * get a list of this system's interface IPv4 addresses, netmasks and MTUs | |
17 | * - maxbufs must be at least 1 | |
18 | * - returns the number of interface records in the buffer | |
19 | */ | |
5b86d4ff DH |
20 | int afs_get_ipv4_interfaces(struct afs_net *net, struct afs_interface *bufs, |
21 | size_t maxbufs, bool wantloopback) | |
dc1f6bff PM |
22 | { |
23 | struct net_device *dev; | |
24 | struct in_device *idev; | |
25 | int n = 0; | |
26 | ||
ec9c9485 DH |
27 | ASSERT(maxbufs > 0); |
28 | ||
dc1f6bff | 29 | rtnl_lock(); |
5b86d4ff | 30 | for_each_netdev(net->net, dev) { |
dc1f6bff PM |
31 | if (dev->type == ARPHRD_LOOPBACK && !wantloopback) |
32 | continue; | |
33 | idev = __in_dev_get_rtnl(dev); | |
34 | if (!idev) | |
35 | continue; | |
36 | for_primary_ifa(idev) { | |
dc1f6bff PM |
37 | bufs[n].address.s_addr = ifa->ifa_address; |
38 | bufs[n].netmask.s_addr = ifa->ifa_mask; | |
39 | bufs[n].mtu = dev->mtu; | |
40 | n++; | |
ec9c9485 DH |
41 | if (n >= maxbufs) |
42 | goto out; | |
43 | } endfor_ifa(idev); | |
dc1f6bff PM |
44 | } |
45 | out: | |
46 | rtnl_unlock(); | |
47 | return n; | |
48 | } |