1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _LINUX_INETDEVICE_H
31da177e4SLinus Torvalds #define _LINUX_INETDEVICE_H
41da177e4SLinus Torvalds
51da177e4SLinus Torvalds #ifdef __KERNEL__
61da177e4SLinus Torvalds
731be3085SHerbert Xu #include <linux/bitmap.h>
81da177e4SLinus Torvalds #include <linux/if.h>
94a5a8aa6Sstephen hemminger #include <linux/ip.h>
101da177e4SLinus Torvalds #include <linux/netdevice.h>
111da177e4SLinus Torvalds #include <linux/rcupdate.h>
121da177e4SLinus Torvalds #include <linux/timer.h>
138bfe6d68SSatyam Sharma #include <linux/sysctl.h>
1495ae6b22SEric Dumazet #include <linux/rtnetlink.h>
157658b36fSReshetova, Elena #include <linux/refcount.h>
161da177e4SLinus Torvalds
17d94d9feeSEric Dumazet struct ipv4_devconf {
181da177e4SLinus Torvalds void *sysctl;
19ca7479ebSThomas Graf int data[IPV4_DEVCONF_MAX];
20ca7479ebSThomas Graf DECLARE_BITMAP(state, IPV4_DEVCONF_MAX);
211da177e4SLinus Torvalds };
221da177e4SLinus Torvalds
23e9897071SEric Dumazet #define MC_HASH_SZ_LOG 9
24e9897071SEric Dumazet
25d94d9feeSEric Dumazet struct in_device {
261da177e4SLinus Torvalds struct net_device *dev;
27c04438f5SEric Dumazet netdevice_tracker dev_tracker;
28c04438f5SEric Dumazet
297658b36fSReshetova, Elena refcount_t refcnt;
301da177e4SLinus Torvalds int dead;
312638eb8bSFlorian Westphal struct in_ifaddr __rcu *ifa_list;/* IP ifaddr chain */
32e9897071SEric Dumazet
331d7138deSEric Dumazet struct ip_mc_list __rcu *mc_list; /* IP multicast filter chain */
34e9897071SEric Dumazet struct ip_mc_list __rcu * __rcu *mc_hash;
35e9897071SEric Dumazet
36b8bae41eSRami Rosen int mc_count; /* Number of installed mcasts */
371da177e4SLinus Torvalds spinlock_t mc_tomb_lock;
381da177e4SLinus Torvalds struct ip_mc_list *mc_tomb;
391da177e4SLinus Torvalds unsigned long mr_v1_seen;
401da177e4SLinus Torvalds unsigned long mr_v2_seen;
411da177e4SLinus Torvalds unsigned long mr_maxdelay;
42966c37f2SHangbin Liu unsigned long mr_qi; /* Query Interval */
43966c37f2SHangbin Liu unsigned long mr_qri; /* Query Response Interval */
44966c37f2SHangbin Liu unsigned char mr_qrv; /* Query Robustness Variable */
451da177e4SLinus Torvalds unsigned char mr_gq_running;
46b69dd5b3SEric Dumazet u32 mr_ifc_count;
471da177e4SLinus Torvalds struct timer_list mr_gq_timer; /* general query timer */
481da177e4SLinus Torvalds struct timer_list mr_ifc_timer; /* interface change timer */
491da177e4SLinus Torvalds
501da177e4SLinus Torvalds struct neigh_parms *arp_parms;
511da177e4SLinus Torvalds struct ipv4_devconf cnf;
521da177e4SLinus Torvalds struct rcu_head rcu_head;
531da177e4SLinus Torvalds };
541da177e4SLinus Torvalds
5502291680SEric W. Biederman #define IPV4_DEVCONF(cnf, attr) ((cnf).data[IPV4_DEVCONF_ ## attr - 1])
560598f8f3SEric Dumazet #define IPV4_DEVCONF_RO(cnf, attr) READ_ONCE(IPV4_DEVCONF(cnf, attr))
57586f1211SPavel Emelyanov #define IPV4_DEVCONF_ALL(net, attr) \
58586f1211SPavel Emelyanov IPV4_DEVCONF((*(net)->ipv4.devconf_all), attr)
590598f8f3SEric Dumazet #define IPV4_DEVCONF_ALL_RO(net, attr) READ_ONCE(IPV4_DEVCONF_ALL(net, attr))
601da177e4SLinus Torvalds
ipv4_devconf_get(const struct in_device * in_dev,int index)610598f8f3SEric Dumazet static inline int ipv4_devconf_get(const struct in_device *in_dev, int index)
6242f811b8SHerbert Xu {
6342f811b8SHerbert Xu index--;
640598f8f3SEric Dumazet return READ_ONCE(in_dev->cnf.data[index]);
6542f811b8SHerbert Xu }
6642f811b8SHerbert Xu
ipv4_devconf_set(struct in_device * in_dev,int index,int val)6742f811b8SHerbert Xu static inline void ipv4_devconf_set(struct in_device *in_dev, int index,
6842f811b8SHerbert Xu int val)
6942f811b8SHerbert Xu {
7042f811b8SHerbert Xu index--;
7131be3085SHerbert Xu set_bit(index, in_dev->cnf.state);
720598f8f3SEric Dumazet WRITE_ONCE(in_dev->cnf.data[index], val);
7342f811b8SHerbert Xu }
7442f811b8SHerbert Xu
ipv4_devconf_setall(struct in_device * in_dev)7571e27da9SHerbert Xu static inline void ipv4_devconf_setall(struct in_device *in_dev)
7671e27da9SHerbert Xu {
77ca7479ebSThomas Graf bitmap_fill(in_dev->cnf.state, IPV4_DEVCONF_MAX);
7871e27da9SHerbert Xu }
7971e27da9SHerbert Xu
8042f811b8SHerbert Xu #define IN_DEV_CONF_GET(in_dev, attr) \
8102291680SEric W. Biederman ipv4_devconf_get((in_dev), IPV4_DEVCONF_ ## attr)
8242f811b8SHerbert Xu #define IN_DEV_CONF_SET(in_dev, attr, val) \
8302291680SEric W. Biederman ipv4_devconf_set((in_dev), IPV4_DEVCONF_ ## attr, (val))
8442f811b8SHerbert Xu
8542f811b8SHerbert Xu #define IN_DEV_ANDCONF(in_dev, attr) \
860598f8f3SEric Dumazet (IPV4_DEVCONF_ALL_RO(dev_net(in_dev->dev), attr) && \
87586f1211SPavel Emelyanov IN_DEV_CONF_GET((in_dev), attr))
889eb43e76SEric Dumazet
899eb43e76SEric Dumazet #define IN_DEV_NET_ORCONF(in_dev, net, attr) \
900598f8f3SEric Dumazet (IPV4_DEVCONF_ALL_RO(net, attr) || \
91586f1211SPavel Emelyanov IN_DEV_CONF_GET((in_dev), attr))
929eb43e76SEric Dumazet
939eb43e76SEric Dumazet #define IN_DEV_ORCONF(in_dev, attr) \
949eb43e76SEric Dumazet IN_DEV_NET_ORCONF(in_dev, dev_net(in_dev->dev), attr)
959eb43e76SEric Dumazet
9642f811b8SHerbert Xu #define IN_DEV_MAXCONF(in_dev, attr) \
970598f8f3SEric Dumazet (max(IPV4_DEVCONF_ALL_RO(dev_net(in_dev->dev), attr), \
98586f1211SPavel Emelyanov IN_DEV_CONF_GET((in_dev), attr)))
9942f811b8SHerbert Xu
10042f811b8SHerbert Xu #define IN_DEV_FORWARD(in_dev) IN_DEV_CONF_GET((in_dev), FORWARDING)
10101ecfe9bSPavel Emelyanov #define IN_DEV_MFORWARD(in_dev) IN_DEV_ANDCONF((in_dev), MC_FORWARDING)
1025cbf777cSXin Long #define IN_DEV_BFORWARD(in_dev) IN_DEV_ANDCONF((in_dev), BC_FORWARDING)
10327fed417SStephen Hemminger #define IN_DEV_RPFILTER(in_dev) IN_DEV_MAXCONF((in_dev), RP_FILTER)
10428f6aeeaSJamal Hadi Salim #define IN_DEV_SRC_VMARK(in_dev) IN_DEV_ORCONF((in_dev), SRC_VMARK)
10542f811b8SHerbert Xu #define IN_DEV_SOURCE_ROUTE(in_dev) IN_DEV_ANDCONF((in_dev), \
10642f811b8SHerbert Xu ACCEPT_SOURCE_ROUTE)
1078153a10cSPatrick McHardy #define IN_DEV_ACCEPT_LOCAL(in_dev) IN_DEV_ORCONF((in_dev), ACCEPT_LOCAL)
10842f811b8SHerbert Xu #define IN_DEV_BOOTP_RELAY(in_dev) IN_DEV_ANDCONF((in_dev), BOOTP_RELAY)
10942f811b8SHerbert Xu
11042f811b8SHerbert Xu #define IN_DEV_LOG_MARTIANS(in_dev) IN_DEV_ORCONF((in_dev), LOG_MARTIANS)
11142f811b8SHerbert Xu #define IN_DEV_PROXY_ARP(in_dev) IN_DEV_ORCONF((in_dev), PROXY_ARP)
1121af5318cSVincent Bernat #define IN_DEV_PROXY_ARP_PVLAN(in_dev) IN_DEV_ORCONF((in_dev), PROXY_ARP_PVLAN)
11342f811b8SHerbert Xu #define IN_DEV_SHARED_MEDIA(in_dev) IN_DEV_ORCONF((in_dev), SHARED_MEDIA)
11442f811b8SHerbert Xu #define IN_DEV_TX_REDIRECTS(in_dev) IN_DEV_ORCONF((in_dev), SEND_REDIRECTS)
11542f811b8SHerbert Xu #define IN_DEV_SEC_REDIRECTS(in_dev) IN_DEV_ORCONF((in_dev), \
11642f811b8SHerbert Xu SECURE_REDIRECTS)
11742f811b8SHerbert Xu #define IN_DEV_IDTAG(in_dev) IN_DEV_CONF_GET(in_dev, TAG)
11842f811b8SHerbert Xu #define IN_DEV_MEDIUM_ID(in_dev) IN_DEV_CONF_GET(in_dev, MEDIUM_ID)
11942f811b8SHerbert Xu #define IN_DEV_PROMOTE_SECONDARIES(in_dev) \
12042f811b8SHerbert Xu IN_DEV_ORCONF((in_dev), \
12142f811b8SHerbert Xu PROMOTE_SECONDARIES)
122d0daebc3SThomas Graf #define IN_DEV_ROUTE_LOCALNET(in_dev) IN_DEV_ORCONF(in_dev, ROUTE_LOCALNET)
1239eb43e76SEric Dumazet #define IN_DEV_NET_ROUTE_LOCALNET(in_dev, net) \
1249eb43e76SEric Dumazet IN_DEV_NET_ORCONF(in_dev, net, ROUTE_LOCALNET)
1251da177e4SLinus Torvalds
1261da177e4SLinus Torvalds #define IN_DEV_RX_REDIRECTS(in_dev) \
1271da177e4SLinus Torvalds ((IN_DEV_FORWARD(in_dev) && \
12842f811b8SHerbert Xu IN_DEV_ANDCONF((in_dev), ACCEPT_REDIRECTS)) \
1291da177e4SLinus Torvalds || (!IN_DEV_FORWARD(in_dev) && \
13042f811b8SHerbert Xu IN_DEV_ORCONF((in_dev), ACCEPT_REDIRECTS)))
1311da177e4SLinus Torvalds
1320eeb075fSAndy Gospodarek #define IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev) \
133c0c5a60fSVincent Bernat IN_DEV_ORCONF((in_dev), IGNORE_ROUTES_WITH_LINKDOWN)
1340eeb075fSAndy Gospodarek
13542f811b8SHerbert Xu #define IN_DEV_ARPFILTER(in_dev) IN_DEV_ORCONF((in_dev), ARPFILTER)
136e68c5dcfSJaehee Park #define IN_DEV_ARP_ACCEPT(in_dev) IN_DEV_MAXCONF((in_dev), ARP_ACCEPT)
13742f811b8SHerbert Xu #define IN_DEV_ARP_ANNOUNCE(in_dev) IN_DEV_MAXCONF((in_dev), ARP_ANNOUNCE)
13842f811b8SHerbert Xu #define IN_DEV_ARP_IGNORE(in_dev) IN_DEV_MAXCONF((in_dev), ARP_IGNORE)
139eefef1cfSStephen Hemminger #define IN_DEV_ARP_NOTIFY(in_dev) IN_DEV_MAXCONF((in_dev), ARP_NOTIFY)
140fcdb44d0SJames Prestwood #define IN_DEV_ARP_EVICT_NOCARRIER(in_dev) IN_DEV_ANDCONF((in_dev), \
141fcdb44d0SJames Prestwood ARP_EVICT_NOCARRIER)
1421da177e4SLinus Torvalds
143d94d9feeSEric Dumazet struct in_ifaddr {
14487173021SKuniyuki Iwashima struct hlist_node addr_lst;
1452638eb8bSFlorian Westphal struct in_ifaddr __rcu *ifa_next;
1461da177e4SLinus Torvalds struct in_device *ifa_dev;
1471da177e4SLinus Torvalds struct rcu_head rcu_head;
148a144ea4bSAl Viro __be32 ifa_local;
149a144ea4bSAl Viro __be32 ifa_address;
150a144ea4bSAl Viro __be32 ifa_mask;
151af4d768aSDavid Ahern __u32 ifa_rt_priority;
152a144ea4bSAl Viro __be32 ifa_broadcast;
1531da177e4SLinus Torvalds unsigned char ifa_scope;
1541da177e4SLinus Torvalds unsigned char ifa_prefixlen;
15547f0bd50SJacques de Laval unsigned char ifa_proto;
156ad6c8135SJiri Pirko __u32 ifa_flags;
1571da177e4SLinus Torvalds char ifa_label[IFNAMSIZ];
1585c766d64SJiri Pirko
1595c766d64SJiri Pirko /* In seconds, relative to tstamp. Expiry is at tstamp + HZ * lft. */
1605c766d64SJiri Pirko __u32 ifa_valid_lft;
1615c766d64SJiri Pirko __u32 ifa_preferred_lft;
1625c766d64SJiri Pirko unsigned long ifa_cstamp; /* created timestamp */
1635c766d64SJiri Pirko unsigned long ifa_tstamp; /* updated timestamp */
1641da177e4SLinus Torvalds };
1651da177e4SLinus Torvalds
1663ad7d246SKrister Johansen struct in_validator_info {
1673ad7d246SKrister Johansen __be32 ivi_addr;
1683ad7d246SKrister Johansen struct in_device *ivi_dev;
169de95e047SDavid Ahern struct netlink_ext_ack *extack;
1703ad7d246SKrister Johansen };
1713ad7d246SKrister Johansen
172f629d208SJoe Perches int register_inetaddr_notifier(struct notifier_block *nb);
173f629d208SJoe Perches int unregister_inetaddr_notifier(struct notifier_block *nb);
1743ad7d246SKrister Johansen int register_inetaddr_validator_notifier(struct notifier_block *nb);
1753ad7d246SKrister Johansen int unregister_inetaddr_validator_notifier(struct notifier_block *nb);
1761da177e4SLinus Torvalds
1773b022865SDavid Ahern void inet_netconf_notify_devconf(struct net *net, int event, int type,
1783b022865SDavid Ahern int ifindex, struct ipv4_devconf *devconf);
179d67b8c61SNicolas Dichtel
180f629d208SJoe Perches struct net_device *__ip_dev_find(struct net *net, __be32 addr, bool devref);
ip_dev_find(struct net * net,__be32 addr)18182efee14SEric Dumazet static inline struct net_device *ip_dev_find(struct net *net, __be32 addr)
18282efee14SEric Dumazet {
18382efee14SEric Dumazet return __ip_dev_find(net, addr, true);
18482efee14SEric Dumazet }
18582efee14SEric Dumazet
186f629d208SJoe Perches int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b);
18703aef17bSAl Viro int devinet_ioctl(struct net *net, unsigned int cmd, struct ifreq *);
188b0e99d03SArnd Bergmann #ifdef CONFIG_INET
189b0e99d03SArnd Bergmann int inet_gifconf(struct net_device *dev, char __user *buf, int len, int size);
190b0e99d03SArnd Bergmann #else
inet_gifconf(struct net_device * dev,char __user * buf,int len,int size)191b0e99d03SArnd Bergmann static inline int inet_gifconf(struct net_device *dev, char __user *buf,
192b0e99d03SArnd Bergmann int len, int size)
193b0e99d03SArnd Bergmann {
194b0e99d03SArnd Bergmann return 0;
195b0e99d03SArnd Bergmann }
196b0e99d03SArnd Bergmann #endif
197f629d208SJoe Perches void devinet_init(void);
198f629d208SJoe Perches struct in_device *inetdev_by_index(struct net *, int);
199f629d208SJoe Perches __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope);
200b601fa19SNicolas Dichtel __be32 inet_confirm_addr(struct net *net, struct in_device *in_dev, __be32 dst,
201b601fa19SNicolas Dichtel __be32 local, int scope);
202f629d208SJoe Perches struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
203f629d208SJoe Perches __be32 mask);
2046e617de8SPaolo Abeni struct in_ifaddr *inet_lookup_ifaddr_rcu(struct net *net, __be32 addr);
inet_ifa_match(__be32 addr,const struct in_ifaddr * ifa)205ef11db33SFlorian Westphal static inline bool inet_ifa_match(__be32 addr, const struct in_ifaddr *ifa)
2061da177e4SLinus Torvalds {
2071da177e4SLinus Torvalds return !((addr^ifa->ifa_address)&ifa->ifa_mask);
2081da177e4SLinus Torvalds }
2091da177e4SLinus Torvalds
2101da177e4SLinus Torvalds /*
2111da177e4SLinus Torvalds * Check if a mask is acceptable.
2121da177e4SLinus Torvalds */
2131da177e4SLinus Torvalds
bad_mask(__be32 mask,__be32 addr)214f06cc7b2SYaowei Bai static __inline__ bool bad_mask(__be32 mask, __be32 addr)
2151da177e4SLinus Torvalds {
216714e85beSAl Viro __u32 hmask;
2171da177e4SLinus Torvalds if (addr & (mask = ~mask))
218f06cc7b2SYaowei Bai return true;
219714e85beSAl Viro hmask = ntohl(mask);
220714e85beSAl Viro if (hmask & (hmask+1))
221f06cc7b2SYaowei Bai return true;
222f06cc7b2SYaowei Bai return false;
2231da177e4SLinus Torvalds }
2241da177e4SLinus Torvalds
225ef11db33SFlorian Westphal #define in_dev_for_each_ifa_rtnl(ifa, in_dev) \
2262638eb8bSFlorian Westphal for (ifa = rtnl_dereference((in_dev)->ifa_list); ifa; \
2272638eb8bSFlorian Westphal ifa = rtnl_dereference(ifa->ifa_next))
228ef11db33SFlorian Westphal
229*d4b48320SKuniyuki Iwashima #define in_dev_for_each_ifa_rtnl_net(net, ifa, in_dev) \
230*d4b48320SKuniyuki Iwashima for (ifa = rtnl_net_dereference(net, (in_dev)->ifa_list); ifa; \
231*d4b48320SKuniyuki Iwashima ifa = rtnl_net_dereference(net, ifa->ifa_next))
232*d4b48320SKuniyuki Iwashima
233ef11db33SFlorian Westphal #define in_dev_for_each_ifa_rcu(ifa, in_dev) \
2342638eb8bSFlorian Westphal for (ifa = rcu_dereference((in_dev)->ifa_list); ifa; \
2352638eb8bSFlorian Westphal ifa = rcu_dereference(ifa->ifa_next))
236ef11db33SFlorian Westphal
__in_dev_get_rcu(const struct net_device * dev)237e5ed6399SHerbert Xu static inline struct in_device *__in_dev_get_rcu(const struct net_device *dev)
238e5ed6399SHerbert Xu {
23995ae6b22SEric Dumazet return rcu_dereference(dev->ip_ptr);
240e5ed6399SHerbert Xu }
241e5ed6399SHerbert Xu
in_dev_get(const struct net_device * dev)24295ae6b22SEric Dumazet static inline struct in_device *in_dev_get(const struct net_device *dev)
2431da177e4SLinus Torvalds {
2441da177e4SLinus Torvalds struct in_device *in_dev;
2451da177e4SLinus Torvalds
2461da177e4SLinus Torvalds rcu_read_lock();
247e5ed6399SHerbert Xu in_dev = __in_dev_get_rcu(dev);
2481da177e4SLinus Torvalds if (in_dev)
2497658b36fSReshetova, Elena refcount_inc(&in_dev->refcnt);
2501da177e4SLinus Torvalds rcu_read_unlock();
2511da177e4SLinus Torvalds return in_dev;
2521da177e4SLinus Torvalds }
2531da177e4SLinus Torvalds
__in_dev_get_rtnl(const struct net_device * dev)25495ae6b22SEric Dumazet static inline struct in_device *__in_dev_get_rtnl(const struct net_device *dev)
2551da177e4SLinus Torvalds {
25606a9701fSEric Dumazet return rtnl_dereference(dev->ip_ptr);
2571da177e4SLinus Torvalds }
2581da177e4SLinus Torvalds
__in_dev_get_rtnl_net(const struct net_device * dev)259*d4b48320SKuniyuki Iwashima static inline struct in_device *__in_dev_get_rtnl_net(const struct net_device *dev)
260*d4b48320SKuniyuki Iwashima {
261*d4b48320SKuniyuki Iwashima return rtnl_net_dereference(dev_net(dev), dev->ip_ptr);
262*d4b48320SKuniyuki Iwashima }
263*d4b48320SKuniyuki Iwashima
264331c7a40SDavid Ahern /* called with rcu_read_lock or rtnl held */
ip_ignore_linkdown(const struct net_device * dev)265331c7a40SDavid Ahern static inline bool ip_ignore_linkdown(const struct net_device *dev)
266331c7a40SDavid Ahern {
267331c7a40SDavid Ahern struct in_device *in_dev;
268331c7a40SDavid Ahern bool rc = false;
269331c7a40SDavid Ahern
270331c7a40SDavid Ahern in_dev = rcu_dereference_rtnl(dev->ip_ptr);
271331c7a40SDavid Ahern if (in_dev &&
272331c7a40SDavid Ahern IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN(in_dev))
273331c7a40SDavid Ahern rc = true;
274331c7a40SDavid Ahern
275331c7a40SDavid Ahern return rc;
276331c7a40SDavid Ahern }
277331c7a40SDavid Ahern
__in_dev_arp_parms_get_rcu(const struct net_device * dev)2781d4c8c29SJiri Pirko static inline struct neigh_parms *__in_dev_arp_parms_get_rcu(const struct net_device *dev)
2791d4c8c29SJiri Pirko {
2801d4c8c29SJiri Pirko struct in_device *in_dev = __in_dev_get_rcu(dev);
2811d4c8c29SJiri Pirko
2821d4c8c29SJiri Pirko return in_dev ? in_dev->arp_parms : NULL;
2831d4c8c29SJiri Pirko }
2841d4c8c29SJiri Pirko
285f629d208SJoe Perches void in_dev_finish_destroy(struct in_device *idev);
2861da177e4SLinus Torvalds
in_dev_put(struct in_device * idev)2871da177e4SLinus Torvalds static inline void in_dev_put(struct in_device *idev)
2881da177e4SLinus Torvalds {
2897658b36fSReshetova, Elena if (refcount_dec_and_test(&idev->refcnt))
2901da177e4SLinus Torvalds in_dev_finish_destroy(idev);
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds
2937658b36fSReshetova, Elena #define __in_dev_put(idev) refcount_dec(&(idev)->refcnt)
2947658b36fSReshetova, Elena #define in_dev_hold(idev) refcount_inc(&(idev)->refcnt)
2951da177e4SLinus Torvalds
2961da177e4SLinus Torvalds #endif /* __KERNEL__ */
2971da177e4SLinus Torvalds
inet_make_mask(int logmask)29860cad5daSAl Viro static __inline__ __be32 inet_make_mask(int logmask)
2991da177e4SLinus Torvalds {
3001da177e4SLinus Torvalds if (logmask)
30184bc8868SVincent BENAYOUN return htonl(~((1U<<(32-logmask))-1));
3021da177e4SLinus Torvalds return 0;
3031da177e4SLinus Torvalds }
3041da177e4SLinus Torvalds
inet_mask_len(__be32 mask)305714e85beSAl Viro static __inline__ int inet_mask_len(__be32 mask)
3061da177e4SLinus Torvalds {
307714e85beSAl Viro __u32 hmask = ntohl(mask);
308714e85beSAl Viro if (!hmask)
3091da177e4SLinus Torvalds return 0;
310714e85beSAl Viro return 32 - ffz(~hmask);
3111da177e4SLinus Torvalds }
3121da177e4SLinus Torvalds
3131da177e4SLinus Torvalds
3141da177e4SLinus Torvalds #endif /* _LINUX_INETDEVICE_H */
315