[NETFILTER]: Core changes required by upcoming nfnetlink_queue code
[linux-2.6.22.y-op.git] / include / linux / netfilter.h
blob711e05f33d686bb2616a4185750a2952789e406e
1 #ifndef __LINUX_NETFILTER_H
2 #define __LINUX_NETFILTER_H
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>
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
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
29 #define NF_VERDICT_QMASK 0xffff0000
30 #define NF_VERDICT_QBITS 16
32 #define NF_QUEUE_NR(x) ((x << NF_VERDICT_QBITS) & NF_VERDICT_QMASK || NF_QUEUE)
34 /* only for userspace compatibility */
35 #ifndef __KERNEL__
36 /* Generic cache responses from hook functions.
37 <= 0x2000 is used for protocol-flags. */
38 #define NFC_UNKNOWN 0x4000
39 #define NFC_ALTERED 0x8000
40 #endif
42 #ifdef __KERNEL__
43 #include <linux/config.h>
44 #ifdef CONFIG_NETFILTER
46 extern void netfilter_init(void);
48 /* Largest hook number + 1 */
49 #define NF_MAX_HOOKS 8
51 struct sk_buff;
52 struct net_device;
54 typedef unsigned int nf_hookfn(unsigned int hooknum,
55 struct sk_buff **skb,
56 const struct net_device *in,
57 const struct net_device *out,
58 int (*okfn)(struct sk_buff *));
60 struct nf_hook_ops
62 struct list_head list;
64 /* User fills in from here down. */
65 nf_hookfn *hook;
66 struct module *owner;
67 int pf;
68 int hooknum;
69 /* Hooks are ordered in ascending priority. */
70 int priority;
73 struct nf_sockopt_ops
75 struct list_head list;
77 int pf;
79 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
80 int set_optmin;
81 int set_optmax;
82 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
84 int get_optmin;
85 int get_optmax;
86 int (*get)(struct sock *sk, int optval, void __user *user, int *len);
88 /* Number of users inside set() or get(). */
89 unsigned int use;
90 struct task_struct *cleanup_task;
93 /* Each queued (to userspace) skbuff has one of these. */
94 struct nf_info
96 /* The ops struct which sent us to userspace. */
97 struct nf_hook_ops *elem;
99 /* If we're sent to userspace, this keeps housekeeping info */
100 int pf;
101 unsigned int hook;
102 struct net_device *indev, *outdev;
103 int (*okfn)(struct sk_buff *);
106 /* Function to register/unregister hook points. */
107 int nf_register_hook(struct nf_hook_ops *reg);
108 void nf_unregister_hook(struct nf_hook_ops *reg);
110 /* Functions to register get/setsockopt ranges (non-inclusive). You
111 need to check permissions yourself! */
112 int nf_register_sockopt(struct nf_sockopt_ops *reg);
113 void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
115 extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
117 typedef void nf_logfn(unsigned int hooknum,
118 const struct sk_buff *skb,
119 const struct net_device *in,
120 const struct net_device *out,
121 const char *prefix);
123 /* Function to register/unregister log function. */
124 int nf_log_register(int pf, nf_logfn *logfn);
125 void nf_log_unregister(int pf, nf_logfn *logfn);
127 /* Calls the registered backend logging function */
128 void nf_log_packet(int pf,
129 unsigned int hooknum,
130 const struct sk_buff *skb,
131 const struct net_device *in,
132 const struct net_device *out,
133 const char *fmt, ...);
135 /* Activate hook; either okfn or kfree_skb called, unless a hook
136 returns NF_STOLEN (in which case, it's up to the hook to deal with
137 the consequences).
139 Returns -ERRNO if packet dropped. Zero means queued, stolen or
140 accepted.
143 /* RR:
144 > I don't want nf_hook to return anything because people might forget
145 > about async and trust the return value to mean "packet was ok".
148 Just document it clearly, then you can expect some sense from kernel
149 coders :)
152 /* This is gross, but inline doesn't cut it for avoiding the function
153 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
154 #ifdef CONFIG_NETFILTER_DEBUG
155 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
156 ({int __ret; \
157 if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
158 __ret = (okfn)(skb); \
159 __ret;})
160 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
161 ({int __ret; \
162 if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
163 __ret = (okfn)(skb); \
164 __ret;})
165 #else
166 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
167 ({int __ret; \
168 if (list_empty(&nf_hooks[pf][hook]) || \
169 (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
170 __ret = (okfn)(skb); \
171 __ret;})
172 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
173 ({int __ret; \
174 if (list_empty(&nf_hooks[pf][hook]) || \
175 (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
176 __ret = (okfn)(skb); \
177 __ret;})
178 #endif
180 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
181 struct net_device *indev, struct net_device *outdev,
182 int (*okfn)(struct sk_buff *), int thresh);
184 /* Call setsockopt() */
185 int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt,
186 int len);
187 int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
188 int *len);
190 /* Packet queuing */
191 typedef int (*nf_queue_outfn_t)(struct sk_buff *skb,
192 struct nf_info *info,
193 unsigned int queuenum, void *data);
194 extern int nf_register_queue_handler(int pf,
195 nf_queue_outfn_t outfn, void *data);
196 extern int nf_unregister_queue_handler(int pf);
197 extern void nf_unregister_queue_handlers(nf_queue_outfn_t outfn);
198 extern void nf_reinject(struct sk_buff *skb,
199 struct nf_info *info,
200 unsigned int verdict);
202 extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *);
203 extern void nf_ct_attach(struct sk_buff *, struct sk_buff *);
205 /* FIXME: Before cache is ever used, this must be implemented for real. */
206 extern void nf_invalidate_cache(int pf);
208 /* Call this before modifying an existing packet: ensures it is
209 modifiable and linear to the point you care about (writable_len).
210 Returns true or false. */
211 extern int skb_make_writable(struct sk_buff **pskb, unsigned int writable_len);
213 struct nf_queue_rerouter {
214 void (*save)(const struct sk_buff *skb, struct nf_info *info);
215 int (*reroute)(struct sk_buff **skb, const struct nf_info *info);
216 int rer_size;
219 #define nf_info_reroute(x) ((void *)x + sizeof(struct nf_info))
221 extern int nf_register_queue_rerouter(int pf, struct nf_queue_rerouter *rer);
222 extern int nf_unregister_queue_rerouter(int pf);
224 #else /* !CONFIG_NETFILTER */
225 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
226 static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
227 #endif /*CONFIG_NETFILTER*/
229 #endif /*__KERNEL__*/
230 #endif /*__LINUX_NETFILTER_H*/