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>
14 /* Responses from hook functions. */
20 #define NF_MAX_VERDICT NF_REPEAT
22 /* Generic cache responses from hook functions. */
23 #define NFC_ALTERED 0x8000
24 #define NFC_UNKNOWN 0x4000
27 #include <linux/config.h>
28 #ifdef CONFIG_NETFILTER
30 extern void netfilter_init(void);
32 /* Largest hook number + 1 */
33 #define NF_MAX_HOOKS 8
38 typedef unsigned int nf_hookfn(unsigned int hooknum,
40 const struct net_device *in,
41 const struct net_device *out,
42 int (*okfn)(struct sk_buff *));
46 struct list_head list;
48 /* User fills in from here down. */
52 /* Hooks are ordered in ascending priority. */
58 struct list_head list;
62 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
65 int (*set)(struct sock *sk, int optval, void *user, unsigned int len);
69 int (*get)(struct sock *sk, int optval, void *user, int *len);
71 /* Number of users inside set() or get(). */
73 struct task_struct *cleanup_task;
76 /* Each queued (to userspace) skbuff has one of these. */
79 /* The ops struct which sent us to userspace. */
80 struct nf_hook_ops *elem;
82 /* If we're sent to userspace, this keeps housekeeping info */
85 struct net_device *indev, *outdev;
86 int (*okfn)(struct sk_buff *);
89 /* Function to register/unregister hook points. */
90 int nf_register_hook(struct nf_hook_ops *reg);
91 void nf_unregister_hook(struct nf_hook_ops *reg);
93 /* Functions to register get/setsockopt ranges (non-inclusive). You
94 need to check permissions yourself! */
95 int nf_register_sockopt(struct nf_sockopt_ops *reg);
96 void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
98 extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
100 /* Activate hook; either okfn or kfree_skb called, unless a hook
101 returns NF_STOLEN (in which case, it's up to the hook to deal with
104 Returns -ERRNO if packet dropped. Zero means queued, stolen or
109 > I don't want nf_hook to return anything because people might forget
110 > about async and trust the return value to mean "packet was ok".
113 Just document it clearly, then you can expect some sense from kernel
117 /* This is gross, but inline doesn't cut it for avoiding the function
118 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
119 #ifdef CONFIG_NETFILTER_DEBUG
120 #define NF_HOOK nf_hook_slow
122 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
123 (list_empty(&nf_hooks[(pf)][(hook)]) \
125 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn)))
128 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
129 struct net_device *indev, struct net_device *outdev,
130 int (*okfn)(struct sk_buff *));
132 /* Call setsockopt() */
133 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
135 int nf_getsockopt(struct sock *sk, int pf, int optval, char *opt,
139 typedef int (*nf_queue_outfn_t)(struct sk_buff *skb,
140 struct nf_info *info, void *data);
141 extern int nf_register_queue_handler(int pf,
142 nf_queue_outfn_t outfn, void *data);
143 extern int nf_unregister_queue_handler(int pf);
144 extern void nf_reinject(struct sk_buff *skb,
145 struct nf_info *info,
146 unsigned int verdict);
148 extern void (*ip_ct_attach)(struct sk_buff *, struct nf_ct_info *);
150 #ifdef CONFIG_NETFILTER_DEBUG
151 extern void nf_dump_skb(int pf, struct sk_buff *skb);
154 /* FIXME: Before cache is ever used, this must be implemented for real. */
155 extern void nf_invalidate_cache(int pf);
157 #else /* !CONFIG_NETFILTER */
158 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
159 #endif /*CONFIG_NETFILTER*/
161 /* From arch/i386/kernel/smp.c:
163 * Why isn't this somewhere standard ??
165 * Maybe because this procedure is horribly buggy, and does
166 * not deserve to live. Think about signedness issues for five
167 * seconds to see why. - Linus
170 /* Two signed, return a signed. */
171 #define SMAX(a,b) ((ssize_t)(a)>(ssize_t)(b) ? (ssize_t)(a) : (ssize_t)(b))
172 #define SMIN(a,b) ((ssize_t)(a)<(ssize_t)(b) ? (ssize_t)(a) : (ssize_t)(b))
174 /* Two unsigned, return an unsigned. */
175 #define UMAX(a,b) ((size_t)(a)>(size_t)(b) ? (size_t)(a) : (size_t)(b))
176 #define UMIN(a,b) ((size_t)(a)<(size_t)(b) ? (size_t)(a) : (size_t)(b))
178 /* Two unsigned, return a signed. */
179 #define SUMAX(a,b) ((size_t)(a)>(size_t)(b) ? (ssize_t)(a) : (ssize_t)(b))
180 #define SUMIN(a,b) ((size_t)(a)<(size_t)(b) ? (ssize_t)(a) : (ssize_t)(b))
181 #endif /*__KERNEL__*/
183 #endif /*__LINUX_NETFILTER_H*/