GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / include / linux / netfilter.h
blob341d8c4c35629e6001cde1c8b14989278388df6e
1 /* Modified by Broadcom Corp. Portions Copyright (c) Broadcom Corp, 2012. */
2 #ifndef __LINUX_NETFILTER_H
3 #define __LINUX_NETFILTER_H
5 #ifdef __KERNEL__
6 #include <linux/init.h>
7 #include <linux/skbuff.h>
8 #include <linux/net.h>
9 #include <linux/if.h>
10 #include <linux/in.h>
11 #include <linux/in6.h>
12 #include <linux/wait.h>
13 #include <linux/list.h>
14 #endif
15 #include <linux/types.h>
16 #include <linux/compiler.h>
18 /* Responses from hook functions. */
19 #define NF_DROP 0
20 #define NF_ACCEPT 1
21 #define NF_STOLEN 2
22 #define NF_QUEUE 3
23 #define NF_REPEAT 4
24 #define NF_STOP 5
25 #define NF_MAX_VERDICT NF_STOP
27 /* we overload the higher bits for encoding auxiliary data such as the queue
28 * number or errno values. Not nice, but better than additional function
29 * arguments. */
30 #define NF_VERDICT_MASK 0x000000ff
32 /* extra verdict flags have mask 0x0000ff00 */
33 #define NF_VERDICT_FLAG_QUEUE_BYPASS 0x00008000
35 /* queue number (NF_QUEUE) or errno (NF_DROP) */
36 #define NF_VERDICT_QMASK 0xffff0000
37 #define NF_VERDICT_QBITS 16
39 #define NF_QUEUE_NR(x) ((((x) << 16) & NF_VERDICT_QMASK) | NF_QUEUE)
41 #define NF_DROP_ERR(x) (((-x) << 16) | NF_DROP)
43 /* only for userspace compatibility */
44 #ifndef __KERNEL__
45 /* Generic cache responses from hook functions.
46 <= 0x2000 is used for protocol-flags. */
47 #define NFC_UNKNOWN 0x4000
48 #define NFC_ALTERED 0x8000
50 /* NF_VERDICT_BITS should be 8 now, but userspace might break if this changes */
51 #define NF_VERDICT_BITS 16
52 #endif
54 enum nf_inet_hooks {
55 NF_INET_PRE_ROUTING,
56 NF_INET_LOCAL_IN,
57 NF_INET_FORWARD,
58 NF_INET_LOCAL_OUT,
59 NF_INET_POST_ROUTING,
60 NF_INET_NUMHOOKS
63 enum {
64 NFPROTO_UNSPEC = 0,
65 NFPROTO_IPV4 = 2,
66 NFPROTO_ARP = 3,
67 NFPROTO_BRIDGE = 7,
68 NFPROTO_IPV6 = 10,
69 NFPROTO_DECNET = 12,
70 NFPROTO_NUMPROTO,
73 union nf_inet_addr {
74 __u32 all[4];
75 __be32 ip;
76 __be32 ip6[4];
77 struct in_addr in;
78 struct in6_addr in6;
81 #ifdef __KERNEL__
82 #ifdef CONFIG_NETFILTER
83 static inline int NF_DROP_GETERR(int verdict)
85 return -(verdict >> NF_VERDICT_QBITS);
88 static inline int nf_inet_addr_cmp(const union nf_inet_addr *a1,
89 const union nf_inet_addr *a2)
91 return a1->all[0] == a2->all[0] &&
92 a1->all[1] == a2->all[1] &&
93 a1->all[2] == a2->all[2] &&
94 a1->all[3] == a2->all[3];
97 extern void netfilter_init(void);
99 /* Largest hook number + 1 */
100 #define NF_MAX_HOOKS 8
102 struct sk_buff;
104 typedef unsigned int nf_hookfn(unsigned int hooknum,
105 struct sk_buff *skb,
106 const struct net_device *in,
107 const struct net_device *out,
108 int (*okfn)(struct sk_buff *));
110 struct nf_hook_ops {
111 struct list_head list;
113 /* User fills in from here down. */
114 nf_hookfn *hook;
115 struct module *owner;
116 u_int8_t pf;
117 unsigned int hooknum;
118 /* Hooks are ordered in ascending priority. */
119 int priority;
122 struct nf_sockopt_ops {
123 struct list_head list;
125 u_int8_t pf;
127 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
128 int set_optmin;
129 int set_optmax;
130 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
131 #ifdef CONFIG_COMPAT
132 int (*compat_set)(struct sock *sk, int optval,
133 void __user *user, unsigned int len);
134 #endif
135 int get_optmin;
136 int get_optmax;
137 int (*get)(struct sock *sk, int optval, void __user *user, int *len);
138 #ifdef CONFIG_COMPAT
139 int (*compat_get)(struct sock *sk, int optval,
140 void __user *user, int *len);
141 #endif
142 /* Use the module struct to lock set/get code in place */
143 struct module *owner;
146 /* Function to register/unregister hook points. */
147 int nf_register_hook(struct nf_hook_ops *reg);
148 void nf_unregister_hook(struct nf_hook_ops *reg);
149 int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
150 void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
152 /* Functions to register get/setsockopt ranges (non-inclusive). You
153 need to check permissions yourself! */
154 int nf_register_sockopt(struct nf_sockopt_ops *reg);
155 void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
157 #ifdef CONFIG_SYSCTL
158 /* Sysctl registration */
159 extern struct ctl_path nf_net_netfilter_sysctl_path[];
160 extern struct ctl_path nf_net_ipv4_netfilter_sysctl_path[];
161 #endif /* CONFIG_SYSCTL */
163 extern struct list_head nf_hooks[NFPROTO_NUMPROTO][NF_MAX_HOOKS];
165 int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
166 struct net_device *indev, struct net_device *outdev,
167 int (*okfn)(struct sk_buff *), int thresh);
170 * nf_hook_thresh - call a netfilter hook
172 * Returns 1 if the hook has allowed the packet to pass. The function
173 * okfn must be invoked by the caller in this case. Any other return
174 * value indicates the packet has been consumed by the hook.
176 static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
177 struct sk_buff *skb,
178 struct net_device *indev,
179 struct net_device *outdev,
180 int (*okfn)(struct sk_buff *), int thresh)
182 #ifndef CONFIG_NETFILTER_DEBUG
183 if (skb->tcpf_smb)
184 return 1;
185 else if (list_empty(&nf_hooks[pf][hook]))
186 return 1;
187 #endif
188 return nf_hook_slow(pf, hook, skb, indev, outdev, okfn, thresh);
191 static inline int nf_hook(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
192 struct net_device *indev, struct net_device *outdev,
193 int (*okfn)(struct sk_buff *))
195 return nf_hook_thresh(pf, hook, skb, indev, outdev, okfn, INT_MIN);
198 /* Activate hook; either okfn or kfree_skb called, unless a hook
199 returns NF_STOLEN (in which case, it's up to the hook to deal with
200 the consequences).
202 Returns -ERRNO if packet dropped. Zero means queued, stolen or
203 accepted.
206 /* RR:
207 > I don't want nf_hook to return anything because people might forget
208 > about async and trust the return value to mean "packet was ok".
211 Just document it clearly, then you can expect some sense from kernel
212 coders :)
215 static inline int
216 NF_HOOK_THRESH(uint8_t pf, unsigned int hook, struct sk_buff *skb,
217 struct net_device *in, struct net_device *out,
218 int (*okfn)(struct sk_buff *), int thresh)
220 int ret = nf_hook_thresh(pf, hook, skb, in, out, okfn, thresh);
221 if (ret == 1)
222 ret = okfn(skb);
223 return ret;
226 static inline int
227 NF_HOOK_COND(uint8_t pf, unsigned int hook, struct sk_buff *skb,
228 struct net_device *in, struct net_device *out,
229 int (*okfn)(struct sk_buff *), bool cond)
231 int ret;
233 if (!cond ||
234 ((ret = nf_hook_thresh(pf, hook, skb, in, out, okfn, INT_MIN)) == 1))
235 ret = okfn(skb);
236 return ret;
239 static inline int
240 NF_HOOK(uint8_t pf, unsigned int hook, struct sk_buff *skb,
241 struct net_device *in, struct net_device *out,
242 int (*okfn)(struct sk_buff *))
244 return NF_HOOK_THRESH(pf, hook, skb, in, out, okfn, INT_MIN);
247 /* Call setsockopt() */
248 int nf_setsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt,
249 unsigned int len);
250 int nf_getsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt,
251 int *len);
252 #ifdef CONFIG_COMPAT
253 int compat_nf_setsockopt(struct sock *sk, u_int8_t pf, int optval,
254 char __user *opt, unsigned int len);
255 int compat_nf_getsockopt(struct sock *sk, u_int8_t pf, int optval,
256 char __user *opt, int *len);
257 #endif
259 /* Call this before modifying an existing packet: ensures it is
260 modifiable and linear to the point you care about (writable_len).
261 Returns true or false. */
262 extern int skb_make_writable(struct sk_buff *skb, unsigned int writable_len);
264 struct flowi;
265 struct nf_queue_entry;
267 struct nf_afinfo {
268 unsigned short family;
269 __sum16 (*checksum)(struct sk_buff *skb, unsigned int hook,
270 unsigned int dataoff, u_int8_t protocol);
271 __sum16 (*checksum_partial)(struct sk_buff *skb,
272 unsigned int hook,
273 unsigned int dataoff,
274 unsigned int len,
275 u_int8_t protocol);
276 int (*route)(struct dst_entry **dst, struct flowi *fl);
277 void (*saveroute)(const struct sk_buff *skb,
278 struct nf_queue_entry *entry);
279 int (*reroute)(struct sk_buff *skb,
280 const struct nf_queue_entry *entry);
281 int route_key_size;
284 extern const struct nf_afinfo *nf_afinfo[NFPROTO_NUMPROTO];
285 static inline const struct nf_afinfo *nf_get_afinfo(unsigned short family)
287 return rcu_dereference(nf_afinfo[family]);
290 static inline __sum16
291 nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff,
292 u_int8_t protocol, unsigned short family)
294 const struct nf_afinfo *afinfo;
295 __sum16 csum = 0;
297 rcu_read_lock();
298 afinfo = nf_get_afinfo(family);
299 if (afinfo)
300 csum = afinfo->checksum(skb, hook, dataoff, protocol);
301 rcu_read_unlock();
302 return csum;
305 static inline __sum16
306 nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
307 unsigned int dataoff, unsigned int len,
308 u_int8_t protocol, unsigned short family)
310 const struct nf_afinfo *afinfo;
311 __sum16 csum = 0;
313 rcu_read_lock();
314 afinfo = nf_get_afinfo(family);
315 if (afinfo)
316 csum = afinfo->checksum_partial(skb, hook, dataoff, len,
317 protocol);
318 rcu_read_unlock();
319 return csum;
322 extern int nf_register_afinfo(const struct nf_afinfo *afinfo);
323 extern void nf_unregister_afinfo(const struct nf_afinfo *afinfo);
325 #include <net/flow.h>
326 extern void (*ip_nat_decode_session)(struct sk_buff *, struct flowi *);
328 static inline void
329 nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
331 #ifdef CONFIG_NF_NAT_NEEDED
332 void (*decodefn)(struct sk_buff *, struct flowi *);
334 if (family == AF_INET) {
335 rcu_read_lock();
336 decodefn = rcu_dereference(ip_nat_decode_session);
337 if (decodefn)
338 decodefn(skb, fl);
339 rcu_read_unlock();
341 #endif
344 #ifdef CONFIG_PROC_FS
345 #include <linux/proc_fs.h>
346 extern struct proc_dir_entry *proc_net_netfilter;
347 #endif
349 #else /* !CONFIG_NETFILTER */
350 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
351 #define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb)
352 static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
353 struct sk_buff *skb,
354 struct net_device *indev,
355 struct net_device *outdev,
356 int (*okfn)(struct sk_buff *), int thresh)
358 return okfn(skb);
360 static inline int nf_hook(u_int8_t pf, unsigned int hook, struct sk_buff *skb,
361 struct net_device *indev, struct net_device *outdev,
362 int (*okfn)(struct sk_buff *))
364 return 1;
366 struct flowi;
367 static inline void
368 nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
371 #endif /*CONFIG_NETFILTER*/
373 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
374 extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *);
375 extern void nf_ct_attach(struct sk_buff *, struct sk_buff *);
376 extern void (*nf_ct_destroy)(struct nf_conntrack *);
377 #else
378 static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
379 #endif
381 #endif /*__KERNEL__*/
382 #endif /*__LINUX_NETFILTER_H*/