cfq-iosched: fix rcu freeing of cfq io contexts
[deliverable/linux.git] / include / linux / netfilter.h
CommitLineData
1da177e4
LT
1#ifndef __LINUX_NETFILTER_H
2#define __LINUX_NETFILTER_H
3
4#ifdef __KERNEL__
5#include <linux/init.h>
6#include <linux/types.h>
7#include <linux/skbuff.h>
8#include <linux/net.h>
9#include <linux/if.h>
2e3075a2
JE
10#include <linux/in.h>
11#include <linux/in6.h>
1da177e4
LT
12#include <linux/wait.h>
13#include <linux/list.h>
14#endif
15#include <linux/compiler.h>
16
17/* Responses from hook functions. */
18#define NF_DROP 0
19#define NF_ACCEPT 1
20#define NF_STOLEN 2
21#define NF_QUEUE 3
22#define NF_REPEAT 4
23#define NF_STOP 5
24#define NF_MAX_VERDICT NF_STOP
25
0ab43f84
HW
26/* we overload the higher bits for encoding auxiliary data such as the queue
27 * number. Not nice, but better than additional function arguments. */
28#define NF_VERDICT_MASK 0x0000ffff
29#define NF_VERDICT_BITS 16
30
31#define NF_VERDICT_QMASK 0xffff0000
32#define NF_VERDICT_QBITS 16
33
fbabbed8 34#define NF_QUEUE_NR(x) ((((x) << NF_VERDICT_BITS) & NF_VERDICT_QMASK) | NF_QUEUE)
0ab43f84 35
6869c4d8
HW
36/* only for userspace compatibility */
37#ifndef __KERNEL__
1da177e4
LT
38/* Generic cache responses from hook functions.
39 <= 0x2000 is used for protocol-flags. */
40#define NFC_UNKNOWN 0x4000
41#define NFC_ALTERED 0x8000
6869c4d8 42#endif
1da177e4 43
6e23ae2a
PM
44enum nf_inet_hooks {
45 NF_INET_PRE_ROUTING,
46 NF_INET_LOCAL_IN,
47 NF_INET_FORWARD,
48 NF_INET_LOCAL_OUT,
49 NF_INET_POST_ROUTING,
50 NF_INET_NUMHOOKS
51};
52
643a2c15 53union nf_inet_addr {
7b33ed22 54 __u32 all[4];
643a2c15
JE
55 __be32 ip;
56 __be32 ip6[4];
2e3075a2
JE
57 struct in_addr in;
58 struct in6_addr in6;
643a2c15
JE
59};
60
1da177e4 61#ifdef __KERNEL__
1da177e4
LT
62#ifdef CONFIG_NETFILTER
63
64extern void netfilter_init(void);
65
66/* Largest hook number + 1 */
67#define NF_MAX_HOOKS 8
68
69struct sk_buff;
70struct net_device;
71
72typedef unsigned int nf_hookfn(unsigned int hooknum,
3db05fea 73 struct sk_buff *skb,
1da177e4
LT
74 const struct net_device *in,
75 const struct net_device *out,
76 int (*okfn)(struct sk_buff *));
77
78struct nf_hook_ops
79{
80 struct list_head list;
81
82 /* User fills in from here down. */
83 nf_hookfn *hook;
84 struct module *owner;
85 int pf;
86 int hooknum;
87 /* Hooks are ordered in ascending priority. */
88 int priority;
89};
90
91struct nf_sockopt_ops
92{
93 struct list_head list;
94
95 int pf;
96
97 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
98 int set_optmin;
99 int set_optmax;
100 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
3fdadf7d
DM
101 int (*compat_set)(struct sock *sk, int optval,
102 void __user *user, unsigned int len);
1da177e4
LT
103
104 int get_optmin;
105 int get_optmax;
106 int (*get)(struct sock *sk, int optval, void __user *user, int *len);
3fdadf7d
DM
107 int (*compat_get)(struct sock *sk, int optval,
108 void __user *user, int *len);
1da177e4 109
16fcec35
NH
110 /* Use the module struct to lock set/get code in place */
111 struct module *owner;
1da177e4
LT
112};
113
1da177e4
LT
114/* Function to register/unregister hook points. */
115int nf_register_hook(struct nf_hook_ops *reg);
116void nf_unregister_hook(struct nf_hook_ops *reg);
972d1cb1
PM
117int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
118void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
1da177e4
LT
119
120/* Functions to register get/setsockopt ranges (non-inclusive). You
121 need to check permissions yourself! */
122int nf_register_sockopt(struct nf_sockopt_ops *reg);
123void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
124
d62f9ed4
PM
125#ifdef CONFIG_SYSCTL
126/* Sysctl registration */
b3fd3ffe
PE
127extern struct ctl_path nf_net_netfilter_sysctl_path[];
128extern struct ctl_path nf_net_ipv4_netfilter_sysctl_path[];
d62f9ed4
PM
129#endif /* CONFIG_SYSCTL */
130
1da177e4
LT
131extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
132
3db05fea 133int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
16a6677f
PM
134 struct net_device *indev, struct net_device *outdev,
135 int (*okfn)(struct sk_buff *), int thresh);
136
137/**
138 * nf_hook_thresh - call a netfilter hook
139 *
140 * Returns 1 if the hook has allowed the packet to pass. The function
141 * okfn must be invoked by the caller in this case. Any other return
142 * value indicates the packet has been consumed by the hook.
143 */
144static inline int nf_hook_thresh(int pf, unsigned int hook,
3db05fea 145 struct sk_buff *skb,
16a6677f
PM
146 struct net_device *indev,
147 struct net_device *outdev,
48d5cad8
PM
148 int (*okfn)(struct sk_buff *), int thresh,
149 int cond)
16a6677f 150{
48d5cad8
PM
151 if (!cond)
152 return 1;
16a6677f
PM
153#ifndef CONFIG_NETFILTER_DEBUG
154 if (list_empty(&nf_hooks[pf][hook]))
155 return 1;
156#endif
3db05fea 157 return nf_hook_slow(pf, hook, skb, indev, outdev, okfn, thresh);
16a6677f
PM
158}
159
3db05fea 160static inline int nf_hook(int pf, unsigned int hook, struct sk_buff *skb,
16a6677f
PM
161 struct net_device *indev, struct net_device *outdev,
162 int (*okfn)(struct sk_buff *))
163{
3db05fea 164 return nf_hook_thresh(pf, hook, skb, indev, outdev, okfn, INT_MIN, 1);
16a6677f 165}
1da177e4
LT
166
167/* Activate hook; either okfn or kfree_skb called, unless a hook
168 returns NF_STOLEN (in which case, it's up to the hook to deal with
169 the consequences).
170
171 Returns -ERRNO if packet dropped. Zero means queued, stolen or
172 accepted.
173*/
174
175/* RR:
176 > I don't want nf_hook to return anything because people might forget
177 > about async and trust the return value to mean "packet was ok".
178
179 AK:
180 Just document it clearly, then you can expect some sense from kernel
181 coders :)
182*/
183
184/* This is gross, but inline doesn't cut it for avoiding the function
185 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
16a6677f
PM
186
187/* HX: It's slightly less gross now. */
188
1da177e4
LT
189#define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
190({int __ret; \
3db05fea 191if ((__ret=nf_hook_thresh(pf, hook, (skb), indev, outdev, okfn, thresh, 1)) == 1)\
48d5cad8
PM
192 __ret = (okfn)(skb); \
193__ret;})
194
195#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \
196({int __ret; \
3db05fea 197if ((__ret=nf_hook_thresh(pf, hook, (skb), indev, outdev, okfn, INT_MIN, cond)) == 1)\
1da177e4
LT
198 __ret = (okfn)(skb); \
199__ret;})
1da177e4 200
16a6677f
PM
201#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
202 NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, INT_MIN)
1da177e4
LT
203
204/* Call setsockopt() */
205int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt,
206 int len);
207int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
208 int *len);
209
3fdadf7d
DM
210int compat_nf_setsockopt(struct sock *sk, int pf, int optval,
211 char __user *opt, int len);
212int compat_nf_getsockopt(struct sock *sk, int pf, int optval,
213 char __user *opt, int *len);
214
089af26c
HW
215/* Call this before modifying an existing packet: ensures it is
216 modifiable and linear to the point you care about (writable_len).
217 Returns true or false. */
37d41879 218extern int skb_make_writable(struct sk_buff *skb, unsigned int writable_len);
089af26c 219
1841a4c7 220struct flowi;
02f014d8 221struct nf_queue_entry;
c01cd429 222
bce8032e
PM
223struct nf_afinfo {
224 unsigned short family;
b51655b9 225 __sum16 (*checksum)(struct sk_buff *skb, unsigned int hook,
422c346f 226 unsigned int dataoff, u_int8_t protocol);
1841a4c7 227 int (*route)(struct dst_entry **dst, struct flowi *fl);
bce8032e 228 void (*saveroute)(const struct sk_buff *skb,
02f014d8 229 struct nf_queue_entry *entry);
3db05fea 230 int (*reroute)(struct sk_buff *skb,
02f014d8 231 const struct nf_queue_entry *entry);
bce8032e 232 int route_key_size;
2cc7d573
HW
233};
234
1e796fda
PM
235extern const struct nf_afinfo *nf_afinfo[NPROTO];
236static inline const struct nf_afinfo *nf_get_afinfo(unsigned short family)
bce8032e
PM
237{
238 return rcu_dereference(nf_afinfo[family]);
239}
2cc7d573 240
b51655b9 241static inline __sum16
422c346f
PM
242nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff,
243 u_int8_t protocol, unsigned short family)
244{
1e796fda 245 const struct nf_afinfo *afinfo;
b51655b9 246 __sum16 csum = 0;
422c346f
PM
247
248 rcu_read_lock();
249 afinfo = nf_get_afinfo(family);
250 if (afinfo)
251 csum = afinfo->checksum(skb, hook, dataoff, protocol);
252 rcu_read_unlock();
253 return csum;
254}
255
1e796fda
PM
256extern int nf_register_afinfo(const struct nf_afinfo *afinfo);
257extern void nf_unregister_afinfo(const struct nf_afinfo *afinfo);
bce8032e 258
eb9c7ebe
PM
259#include <net/flow.h>
260extern void (*ip_nat_decode_session)(struct sk_buff *, struct flowi *);
261
262static inline void
263nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family)
264{
051578cc 265#ifdef CONFIG_NF_NAT_NEEDED
eb9c7ebe
PM
266 void (*decodefn)(struct sk_buff *, struct flowi *);
267
051578cc
PM
268 if (family == AF_INET) {
269 rcu_read_lock();
270 decodefn = rcu_dereference(ip_nat_decode_session);
271 if (decodefn)
272 decodefn(skb, fl);
273 rcu_read_unlock();
274 }
eb9c7ebe
PM
275#endif
276}
277
608c8e4f
HW
278#ifdef CONFIG_PROC_FS
279#include <linux/proc_fs.h>
280extern struct proc_dir_entry *proc_net_netfilter;
281#endif
282
1da177e4
LT
283#else /* !CONFIG_NETFILTER */
284#define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
48d5cad8 285#define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb)
f53b61d8 286static inline int nf_hook_thresh(int pf, unsigned int hook,
3db05fea 287 struct sk_buff *skb,
f53b61d8
DM
288 struct net_device *indev,
289 struct net_device *outdev,
48d5cad8
PM
290 int (*okfn)(struct sk_buff *), int thresh,
291 int cond)
f53b61d8 292{
3db05fea 293 return okfn(skb);
f53b61d8 294}
3db05fea 295static inline int nf_hook(int pf, unsigned int hook, struct sk_buff *skb,
f53b61d8
DM
296 struct net_device *indev, struct net_device *outdev,
297 int (*okfn)(struct sk_buff *))
298{
9c92d348 299 return 1;
f53b61d8 300}
f53b61d8 301struct flowi;
eb9c7ebe
PM
302static inline void
303nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family) {}
1da177e4
LT
304#endif /*CONFIG_NETFILTER*/
305
5f79e0f9
YK
306#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
307extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *);
308extern void nf_ct_attach(struct sk_buff *, struct sk_buff *);
de6e05c4 309extern void (*nf_ct_destroy)(struct nf_conntrack *);
5f79e0f9
YK
310#else
311static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
312#endif
313
1da177e4
LT
314#endif /*__KERNEL__*/
315#endif /*__LINUX_NETFILTER_H*/
This page took 0.598001 seconds and 5 git commands to generate.