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