]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/linux/inetdevice.h
[IPV4]: Convert IPv4 devconf to an array
[mirror_ubuntu-bionic-kernel.git] / include / linux / inetdevice.h
CommitLineData
1da177e4
LT
1#ifndef _LINUX_INETDEVICE_H
2#define _LINUX_INETDEVICE_H
3
4#ifdef __KERNEL__
5
6#include <linux/if.h>
7#include <linux/netdevice.h>
8#include <linux/rcupdate.h>
9#include <linux/timer.h>
10
11struct ipv4_devconf
12{
1da177e4 13 void *sysctl;
42f811b8 14 int data[__NET_IPV4_CONF_MAX - 1];
1da177e4
LT
15};
16
17extern struct ipv4_devconf ipv4_devconf;
18
19struct in_device
20{
21 struct net_device *dev;
22 atomic_t refcnt;
23 int dead;
24 struct in_ifaddr *ifa_list; /* IP ifaddr chain */
25 rwlock_t mc_list_lock;
26 struct ip_mc_list *mc_list; /* IP multicast filter chain */
27 spinlock_t mc_tomb_lock;
28 struct ip_mc_list *mc_tomb;
29 unsigned long mr_v1_seen;
30 unsigned long mr_v2_seen;
31 unsigned long mr_maxdelay;
32 unsigned char mr_qrv;
33 unsigned char mr_gq_running;
34 unsigned char mr_ifc_count;
35 struct timer_list mr_gq_timer; /* general query timer */
36 struct timer_list mr_ifc_timer; /* interface change timer */
37
38 struct neigh_parms *arp_parms;
39 struct ipv4_devconf cnf;
40 struct rcu_head rcu_head;
41};
42
42f811b8
HX
43#define IPV4_DEVCONF(cnf, attr) ((cnf).data[NET_IPV4_CONF_ ## attr - 1])
44#define IPV4_DEVCONF_ALL(attr) IPV4_DEVCONF(ipv4_devconf, attr)
45
46static inline int ipv4_devconf_get(struct in_device *in_dev, int index)
47{
48 index--;
49 return in_dev->cnf.data[index];
50}
51
52static inline void ipv4_devconf_set(struct in_device *in_dev, int index,
53 int val)
54{
55 index--;
56 in_dev->cnf.data[index] = val;
57}
58
59#define IN_DEV_CONF_GET(in_dev, attr) \
60 ipv4_devconf_get((in_dev), NET_IPV4_CONF_ ## attr)
61#define IN_DEV_CONF_SET(in_dev, attr, val) \
62 ipv4_devconf_set((in_dev), NET_IPV4_CONF_ ## attr, (val))
63
64#define IN_DEV_ANDCONF(in_dev, attr) \
65 (IPV4_DEVCONF_ALL(attr) && IN_DEV_CONF_GET((in_dev), attr))
66#define IN_DEV_ORCONF(in_dev, attr) \
67 (IPV4_DEVCONF_ALL(attr) || IN_DEV_CONF_GET((in_dev), attr))
68#define IN_DEV_MAXCONF(in_dev, attr) \
69 (max(IPV4_DEVCONF_ALL(attr), IN_DEV_CONF_GET((in_dev), attr)))
70
71#define IN_DEV_FORWARD(in_dev) IN_DEV_CONF_GET((in_dev), FORWARDING)
72#define IN_DEV_MFORWARD(in_dev) (IPV4_DEVCONF_ALL(MC_FORWARDING) && \
73 IPV4_DEVCONF((in_dev)->cnf, \
74 MC_FORWARDING))
75#define IN_DEV_RPFILTER(in_dev) IN_DEV_ANDCONF((in_dev), RP_FILTER)
76#define IN_DEV_SOURCE_ROUTE(in_dev) IN_DEV_ANDCONF((in_dev), \
77 ACCEPT_SOURCE_ROUTE)
78#define IN_DEV_BOOTP_RELAY(in_dev) IN_DEV_ANDCONF((in_dev), BOOTP_RELAY)
79
80#define IN_DEV_LOG_MARTIANS(in_dev) IN_DEV_ORCONF((in_dev), LOG_MARTIANS)
81#define IN_DEV_PROXY_ARP(in_dev) IN_DEV_ORCONF((in_dev), PROXY_ARP)
82#define IN_DEV_SHARED_MEDIA(in_dev) IN_DEV_ORCONF((in_dev), SHARED_MEDIA)
83#define IN_DEV_TX_REDIRECTS(in_dev) IN_DEV_ORCONF((in_dev), SEND_REDIRECTS)
84#define IN_DEV_SEC_REDIRECTS(in_dev) IN_DEV_ORCONF((in_dev), \
85 SECURE_REDIRECTS)
86#define IN_DEV_IDTAG(in_dev) IN_DEV_CONF_GET(in_dev, TAG)
87#define IN_DEV_MEDIUM_ID(in_dev) IN_DEV_CONF_GET(in_dev, MEDIUM_ID)
88#define IN_DEV_PROMOTE_SECONDARIES(in_dev) \
89 IN_DEV_ORCONF((in_dev), \
90 PROMOTE_SECONDARIES)
1da177e4
LT
91
92#define IN_DEV_RX_REDIRECTS(in_dev) \
93 ((IN_DEV_FORWARD(in_dev) && \
42f811b8 94 IN_DEV_ANDCONF((in_dev), ACCEPT_REDIRECTS)) \
1da177e4 95 || (!IN_DEV_FORWARD(in_dev) && \
42f811b8 96 IN_DEV_ORCONF((in_dev), ACCEPT_REDIRECTS)))
1da177e4 97
42f811b8
HX
98#define IN_DEV_ARPFILTER(in_dev) IN_DEV_ORCONF((in_dev), ARPFILTER)
99#define IN_DEV_ARP_ANNOUNCE(in_dev) IN_DEV_MAXCONF((in_dev), ARP_ANNOUNCE)
100#define IN_DEV_ARP_IGNORE(in_dev) IN_DEV_MAXCONF((in_dev), ARP_IGNORE)
1da177e4
LT
101
102struct in_ifaddr
103{
104 struct in_ifaddr *ifa_next;
105 struct in_device *ifa_dev;
106 struct rcu_head rcu_head;
a144ea4b
AV
107 __be32 ifa_local;
108 __be32 ifa_address;
109 __be32 ifa_mask;
110 __be32 ifa_broadcast;
111 __be32 ifa_anycast;
1da177e4
LT
112 unsigned char ifa_scope;
113 unsigned char ifa_flags;
114 unsigned char ifa_prefixlen;
115 char ifa_label[IFNAMSIZ];
116};
117
118extern int register_inetaddr_notifier(struct notifier_block *nb);
119extern int unregister_inetaddr_notifier(struct notifier_block *nb);
120
60cad5da 121extern struct net_device *ip_dev_find(__be32 addr);
ff428d72 122extern int inet_addr_onlink(struct in_device *in_dev, __be32 a, __be32 b);
1da177e4
LT
123extern int devinet_ioctl(unsigned int cmd, void __user *);
124extern void devinet_init(void);
125extern struct in_device *inetdev_init(struct net_device *dev);
126extern struct in_device *inetdev_by_index(int);
a61ced5d 127extern __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope);
60cad5da
AV
128extern __be32 inet_confirm_addr(const struct net_device *dev, __be32 dst, __be32 local, int scope);
129extern struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix, __be32 mask);
1da177e4
LT
130extern void inet_forward_change(void);
131
60cad5da 132static __inline__ int inet_ifa_match(__be32 addr, struct in_ifaddr *ifa)
1da177e4
LT
133{
134 return !((addr^ifa->ifa_address)&ifa->ifa_mask);
135}
136
137/*
138 * Check if a mask is acceptable.
139 */
140
714e85be 141static __inline__ int bad_mask(__be32 mask, __be32 addr)
1da177e4 142{
714e85be 143 __u32 hmask;
1da177e4
LT
144 if (addr & (mask = ~mask))
145 return 1;
714e85be
AV
146 hmask = ntohl(mask);
147 if (hmask & (hmask+1))
1da177e4
LT
148 return 1;
149 return 0;
150}
151
152#define for_primary_ifa(in_dev) { struct in_ifaddr *ifa; \
153 for (ifa = (in_dev)->ifa_list; ifa && !(ifa->ifa_flags&IFA_F_SECONDARY); ifa = ifa->ifa_next)
154
155#define for_ifa(in_dev) { struct in_ifaddr *ifa; \
156 for (ifa = (in_dev)->ifa_list; ifa; ifa = ifa->ifa_next)
157
158
159#define endfor_ifa(in_dev) }
160
e5ed6399
HX
161static inline struct in_device *__in_dev_get_rcu(const struct net_device *dev)
162{
163 struct in_device *in_dev = dev->ip_ptr;
164 if (in_dev)
165 in_dev = rcu_dereference(in_dev);
166 return in_dev;
167}
168
1da177e4
LT
169static __inline__ struct in_device *
170in_dev_get(const struct net_device *dev)
171{
172 struct in_device *in_dev;
173
174 rcu_read_lock();
e5ed6399 175 in_dev = __in_dev_get_rcu(dev);
1da177e4
LT
176 if (in_dev)
177 atomic_inc(&in_dev->refcnt);
178 rcu_read_unlock();
179 return in_dev;
180}
181
182static __inline__ struct in_device *
e5ed6399 183__in_dev_get_rtnl(const struct net_device *dev)
1da177e4
LT
184{
185 return (struct in_device*)dev->ip_ptr;
186}
187
188extern void in_dev_finish_destroy(struct in_device *idev);
189
190static inline void in_dev_put(struct in_device *idev)
191{
192 if (atomic_dec_and_test(&idev->refcnt))
193 in_dev_finish_destroy(idev);
194}
195
196#define __in_dev_put(idev) atomic_dec(&(idev)->refcnt)
197#define in_dev_hold(idev) atomic_inc(&(idev)->refcnt)
198
199#endif /* __KERNEL__ */
200
60cad5da 201static __inline__ __be32 inet_make_mask(int logmask)
1da177e4
LT
202{
203 if (logmask)
204 return htonl(~((1<<(32-logmask))-1));
205 return 0;
206}
207
714e85be 208static __inline__ int inet_mask_len(__be32 mask)
1da177e4 209{
714e85be
AV
210 __u32 hmask = ntohl(mask);
211 if (!hmask)
1da177e4 212 return 0;
714e85be 213 return 32 - ffz(~hmask);
1da177e4
LT
214}
215
216
217#endif /* _LINUX_INETDEVICE_H */