[TG3]: Add TSO firmware license
[linux-block.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{
13 int accept_redirects;
14 int send_redirects;
15 int secure_redirects;
16 int shared_media;
17 int accept_source_route;
18 int rp_filter;
19 int proxy_arp;
20 int bootp_relay;
21 int log_martians;
22 int forwarding;
23 int mc_forwarding;
24 int tag;
25 int arp_filter;
26 int arp_announce;
27 int arp_ignore;
28 int medium_id;
29 int no_xfrm;
30 int no_policy;
31 int force_igmp_version;
8f937c60 32 int promote_secondaries;
1da177e4
LT
33 void *sysctl;
34};
35
36extern struct ipv4_devconf ipv4_devconf;
37
38struct in_device
39{
40 struct net_device *dev;
41 atomic_t refcnt;
42 int dead;
43 struct in_ifaddr *ifa_list; /* IP ifaddr chain */
44 rwlock_t mc_list_lock;
45 struct ip_mc_list *mc_list; /* IP multicast filter chain */
46 spinlock_t mc_tomb_lock;
47 struct ip_mc_list *mc_tomb;
48 unsigned long mr_v1_seen;
49 unsigned long mr_v2_seen;
50 unsigned long mr_maxdelay;
51 unsigned char mr_qrv;
52 unsigned char mr_gq_running;
53 unsigned char mr_ifc_count;
54 struct timer_list mr_gq_timer; /* general query timer */
55 struct timer_list mr_ifc_timer; /* interface change timer */
56
57 struct neigh_parms *arp_parms;
58 struct ipv4_devconf cnf;
59 struct rcu_head rcu_head;
60};
61
62#define IN_DEV_FORWARD(in_dev) ((in_dev)->cnf.forwarding)
63#define IN_DEV_MFORWARD(in_dev) (ipv4_devconf.mc_forwarding && (in_dev)->cnf.mc_forwarding)
64#define IN_DEV_RPFILTER(in_dev) (ipv4_devconf.rp_filter && (in_dev)->cnf.rp_filter)
65#define IN_DEV_SOURCE_ROUTE(in_dev) (ipv4_devconf.accept_source_route && (in_dev)->cnf.accept_source_route)
66#define IN_DEV_BOOTP_RELAY(in_dev) (ipv4_devconf.bootp_relay && (in_dev)->cnf.bootp_relay)
67
68#define IN_DEV_LOG_MARTIANS(in_dev) (ipv4_devconf.log_martians || (in_dev)->cnf.log_martians)
69#define IN_DEV_PROXY_ARP(in_dev) (ipv4_devconf.proxy_arp || (in_dev)->cnf.proxy_arp)
70#define IN_DEV_SHARED_MEDIA(in_dev) (ipv4_devconf.shared_media || (in_dev)->cnf.shared_media)
71#define IN_DEV_TX_REDIRECTS(in_dev) (ipv4_devconf.send_redirects || (in_dev)->cnf.send_redirects)
72#define IN_DEV_SEC_REDIRECTS(in_dev) (ipv4_devconf.secure_redirects || (in_dev)->cnf.secure_redirects)
73#define IN_DEV_IDTAG(in_dev) ((in_dev)->cnf.tag)
74#define IN_DEV_MEDIUM_ID(in_dev) ((in_dev)->cnf.medium_id)
8f937c60 75#define IN_DEV_PROMOTE_SECONDARIES(in_dev) (ipv4_devconf.promote_secondaries || (in_dev)->cnf.promote_secondaries)
1da177e4
LT
76
77#define IN_DEV_RX_REDIRECTS(in_dev) \
78 ((IN_DEV_FORWARD(in_dev) && \
79 (ipv4_devconf.accept_redirects && (in_dev)->cnf.accept_redirects)) \
80 || (!IN_DEV_FORWARD(in_dev) && \
81 (ipv4_devconf.accept_redirects || (in_dev)->cnf.accept_redirects)))
82
83#define IN_DEV_ARPFILTER(in_dev) (ipv4_devconf.arp_filter || (in_dev)->cnf.arp_filter)
84#define IN_DEV_ARP_ANNOUNCE(in_dev) (max(ipv4_devconf.arp_announce, (in_dev)->cnf.arp_announce))
85#define IN_DEV_ARP_IGNORE(in_dev) (max(ipv4_devconf.arp_ignore, (in_dev)->cnf.arp_ignore))
86
87struct in_ifaddr
88{
89 struct in_ifaddr *ifa_next;
90 struct in_device *ifa_dev;
91 struct rcu_head rcu_head;
92 u32 ifa_local;
93 u32 ifa_address;
94 u32 ifa_mask;
95 u32 ifa_broadcast;
96 u32 ifa_anycast;
97 unsigned char ifa_scope;
98 unsigned char ifa_flags;
99 unsigned char ifa_prefixlen;
100 char ifa_label[IFNAMSIZ];
101};
102
103extern int register_inetaddr_notifier(struct notifier_block *nb);
104extern int unregister_inetaddr_notifier(struct notifier_block *nb);
105
106extern struct net_device *ip_dev_find(u32 addr);
107extern int inet_addr_onlink(struct in_device *in_dev, u32 a, u32 b);
108extern int devinet_ioctl(unsigned int cmd, void __user *);
109extern void devinet_init(void);
110extern struct in_device *inetdev_init(struct net_device *dev);
111extern struct in_device *inetdev_by_index(int);
112extern u32 inet_select_addr(const struct net_device *dev, u32 dst, int scope);
113extern u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scope);
114extern struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, u32 prefix, u32 mask);
115extern void inet_forward_change(void);
116
117static __inline__ int inet_ifa_match(u32 addr, struct in_ifaddr *ifa)
118{
119 return !((addr^ifa->ifa_address)&ifa->ifa_mask);
120}
121
122/*
123 * Check if a mask is acceptable.
124 */
125
126static __inline__ int bad_mask(u32 mask, u32 addr)
127{
128 if (addr & (mask = ~mask))
129 return 1;
130 mask = ntohl(mask);
131 if (mask & (mask+1))
132 return 1;
133 return 0;
134}
135
136#define for_primary_ifa(in_dev) { struct in_ifaddr *ifa; \
137 for (ifa = (in_dev)->ifa_list; ifa && !(ifa->ifa_flags&IFA_F_SECONDARY); ifa = ifa->ifa_next)
138
139#define for_ifa(in_dev) { struct in_ifaddr *ifa; \
140 for (ifa = (in_dev)->ifa_list; ifa; ifa = ifa->ifa_next)
141
142
143#define endfor_ifa(in_dev) }
144
145static __inline__ struct in_device *
146in_dev_get(const struct net_device *dev)
147{
148 struct in_device *in_dev;
149
150 rcu_read_lock();
151 in_dev = dev->ip_ptr;
152 if (in_dev)
153 atomic_inc(&in_dev->refcnt);
154 rcu_read_unlock();
155 return in_dev;
156}
157
158static __inline__ struct in_device *
159__in_dev_get(const struct net_device *dev)
160{
161 return (struct in_device*)dev->ip_ptr;
162}
163
164extern void in_dev_finish_destroy(struct in_device *idev);
165
166static inline void in_dev_put(struct in_device *idev)
167{
168 if (atomic_dec_and_test(&idev->refcnt))
169 in_dev_finish_destroy(idev);
170}
171
172#define __in_dev_put(idev) atomic_dec(&(idev)->refcnt)
173#define in_dev_hold(idev) atomic_inc(&(idev)->refcnt)
174
175#endif /* __KERNEL__ */
176
177static __inline__ __u32 inet_make_mask(int logmask)
178{
179 if (logmask)
180 return htonl(~((1<<(32-logmask))-1));
181 return 0;
182}
183
184static __inline__ int inet_mask_len(__u32 mask)
185{
186 if (!(mask = ntohl(mask)))
187 return 0;
188 return 32 - ffz(~mask);
189}
190
191
192#endif /* _LINUX_INETDEVICE_H */