1 #ifndef __LINUX_NETFILTER_H
2 #define __LINUX_NETFILTER_H
5 #include <linux/init.h>
6 #include <linux/types.h>
7 #include <linux/skbuff.h>
10 #include <linux/wait.h>
11 #include <linux/list.h>
13 #include <linux/compiler.h>
15 /* Responses from hook functions. */
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 */
36 /* Generic cache responses from hook functions.
37 <= 0x2000 is used for protocol-flags. */
38 #define NFC_UNKNOWN 0x4000
39 #define NFC_ALTERED 0x8000
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
54 typedef unsigned int nf_hookfn(unsigned int hooknum
,
56 const struct net_device
*in
,
57 const struct net_device
*out
,
58 int (*okfn
)(struct sk_buff
*));
62 struct list_head list
;
64 /* User fills in from here down. */
69 /* Hooks are ordered in ascending priority. */
75 struct list_head list
;
79 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
82 int (*set
)(struct sock
*sk
, int optval
, void __user
*user
, unsigned int len
);
86 int (*get
)(struct sock
*sk
, int optval
, void __user
*user
, int *len
);
88 /* Number of users inside set() or get(). */
90 struct task_struct
*cleanup_task
;
93 /* Each queued (to userspace) skbuff has one of these. */
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 */
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 /* those NF_LOG_* defines and struct nf_loginfo are legacy definitios that will
118 * disappear once iptables is replaced with pkttables. Please DO NOT use them
119 * for any new code! */
120 #define NF_LOG_TCPSEQ 0x01 /* Log TCP sequence numbers */
121 #define NF_LOG_TCPOPT 0x02 /* Log TCP options */
122 #define NF_LOG_IPOPT 0x04 /* Log IP options */
123 #define NF_LOG_UID 0x08 /* Log UID owning local socket */
124 #define NF_LOG_MASK 0x0f
126 #define NF_LOG_TYPE_LOG 0x01
127 #define NF_LOG_TYPE_ULOG 0x02
135 u_int16_t qthreshold
;
144 typedef void nf_logfn(unsigned int pf
,
145 unsigned int hooknum
,
146 const struct sk_buff
*skb
,
147 const struct net_device
*in
,
148 const struct net_device
*out
,
149 const struct nf_loginfo
*li
,
158 /* Function to register/unregister log function. */
159 int nf_log_register(int pf
, struct nf_logger
*logger
);
160 int nf_log_unregister_pf(int pf
);
161 void nf_log_unregister_logger(struct nf_logger
*logger
);
163 /* Calls the registered backend logging function */
164 void nf_log_packet(int pf
,
165 unsigned int hooknum
,
166 const struct sk_buff
*skb
,
167 const struct net_device
*in
,
168 const struct net_device
*out
,
169 struct nf_loginfo
*li
,
170 const char *fmt
, ...);
172 int nf_hook_slow(int pf
, unsigned int hook
, struct sk_buff
**pskb
,
173 struct net_device
*indev
, struct net_device
*outdev
,
174 int (*okfn
)(struct sk_buff
*), int thresh
);
177 * nf_hook_thresh - call a netfilter hook
179 * Returns 1 if the hook has allowed the packet to pass. The function
180 * okfn must be invoked by the caller in this case. Any other return
181 * value indicates the packet has been consumed by the hook.
183 static inline int nf_hook_thresh(int pf
, unsigned int hook
,
184 struct sk_buff
**pskb
,
185 struct net_device
*indev
,
186 struct net_device
*outdev
,
187 int (*okfn
)(struct sk_buff
*), int thresh
)
189 #ifndef CONFIG_NETFILTER_DEBUG
190 if (list_empty(&nf_hooks
[pf
][hook
]))
193 return nf_hook_slow(pf
, hook
, pskb
, indev
, outdev
, okfn
, thresh
);
196 static inline int nf_hook(int pf
, unsigned int hook
, struct sk_buff
**pskb
,
197 struct net_device
*indev
, struct net_device
*outdev
,
198 int (*okfn
)(struct sk_buff
*))
200 return nf_hook_thresh(pf
, hook
, pskb
, indev
, outdev
, okfn
, INT_MIN
);
203 /* Activate hook; either okfn or kfree_skb called, unless a hook
204 returns NF_STOLEN (in which case, it's up to the hook to deal with
207 Returns -ERRNO if packet dropped. Zero means queued, stolen or
212 > I don't want nf_hook to return anything because people might forget
213 > about async and trust the return value to mean "packet was ok".
216 Just document it clearly, then you can expect some sense from kernel
220 /* This is gross, but inline doesn't cut it for avoiding the function
221 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
223 /* HX: It's slightly less gross now. */
225 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
227 if ((__ret=nf_hook_thresh(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1)\
228 __ret = (okfn)(skb); \
231 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
232 NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, INT_MIN)
234 /* Call setsockopt() */
235 int nf_setsockopt(struct sock
*sk
, int pf
, int optval
, char __user
*opt
,
237 int nf_getsockopt(struct sock
*sk
, int pf
, int optval
, char __user
*opt
,
241 struct nf_queue_handler
{
242 int (*outfn
)(struct sk_buff
*skb
, struct nf_info
*info
,
243 unsigned int queuenum
, void *data
);
247 extern int nf_register_queue_handler(int pf
,
248 struct nf_queue_handler
*qh
);
249 extern int nf_unregister_queue_handler(int pf
);
250 extern void nf_unregister_queue_handlers(struct nf_queue_handler
*qh
);
251 extern void nf_reinject(struct sk_buff
*skb
,
252 struct nf_info
*info
,
253 unsigned int verdict
);
255 extern void (*ip_ct_attach
)(struct sk_buff
*, struct sk_buff
*);
256 extern void nf_ct_attach(struct sk_buff
*, struct sk_buff
*);
258 /* FIXME: Before cache is ever used, this must be implemented for real. */
259 extern void nf_invalidate_cache(int pf
);
261 /* Call this before modifying an existing packet: ensures it is
262 modifiable and linear to the point you care about (writable_len).
263 Returns true or false. */
264 extern int skb_make_writable(struct sk_buff
**pskb
, unsigned int writable_len
);
266 struct nf_queue_rerouter
{
267 void (*save
)(const struct sk_buff
*skb
, struct nf_info
*info
);
268 int (*reroute
)(struct sk_buff
**skb
, const struct nf_info
*info
);
272 #define nf_info_reroute(x) ((void *)x + sizeof(struct nf_info))
274 extern int nf_register_queue_rerouter(int pf
, struct nf_queue_rerouter
*rer
);
275 extern int nf_unregister_queue_rerouter(int pf
);
277 #include <net/flow.h>
278 extern void (*ip_nat_decode_session
)(struct sk_buff
*, struct flowi
*);
281 nf_nat_decode_session(struct sk_buff
*skb
, struct flowi
*fl
, int family
)
283 #ifdef CONFIG_IP_NF_NAT_NEEDED
284 void (*decodefn
)(struct sk_buff
*, struct flowi
*);
286 if (family
== AF_INET
&& (decodefn
= ip_nat_decode_session
) != NULL
)
291 #ifdef CONFIG_PROC_FS
292 #include <linux/proc_fs.h>
293 extern struct proc_dir_entry
*proc_net_netfilter
;
296 #else /* !CONFIG_NETFILTER */
297 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
298 static inline int nf_hook_thresh(int pf
, unsigned int hook
,
299 struct sk_buff
**pskb
,
300 struct net_device
*indev
,
301 struct net_device
*outdev
,
302 int (*okfn
)(struct sk_buff
*), int thresh
)
306 static inline int nf_hook(int pf
, unsigned int hook
, struct sk_buff
**pskb
,
307 struct net_device
*indev
, struct net_device
*outdev
,
308 int (*okfn
)(struct sk_buff
*))
312 static inline void nf_ct_attach(struct sk_buff
*new, struct sk_buff
*skb
) {}
315 nf_nat_decode_session(struct sk_buff
*skb
, struct flowi
*fl
, int family
) {}
316 #endif /*CONFIG_NETFILTER*/
318 #endif /*__KERNEL__*/
319 #endif /*__LINUX_NETFILTER_H*/