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 /* only for userspace compatibility */
26 /* Generic cache responses from hook functions.
27 <= 0x2000 is used for protocol-flags. */
28 #define NFC_UNKNOWN 0x4000
29 #define NFC_ALTERED 0x8000
33 #include <linux/config.h>
34 #ifdef CONFIG_NETFILTER
36 extern void netfilter_init(void);
38 /* Largest hook number + 1 */
39 #define NF_MAX_HOOKS 8
44 typedef unsigned int nf_hookfn(unsigned int hooknum,
46 const struct net_device *in,
47 const struct net_device *out,
48 int (*okfn)(struct sk_buff *));
52 struct list_head list;
54 /* User fills in from here down. */
59 /* Hooks are ordered in ascending priority. */
65 struct list_head list;
69 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
72 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
76 int (*get)(struct sock *sk, int optval, void __user *user, int *len);
78 /* Number of users inside set() or get(). */
80 struct task_struct *cleanup_task;
83 /* Each queued (to userspace) skbuff has one of these. */
86 /* The ops struct which sent us to userspace. */
87 struct nf_hook_ops *elem;
89 /* If we're sent to userspace, this keeps housekeeping info */
92 struct net_device *indev, *outdev;
93 int (*okfn)(struct sk_buff *);
96 /* Function to register/unregister hook points. */
97 int nf_register_hook(struct nf_hook_ops *reg);
98 void nf_unregister_hook(struct nf_hook_ops *reg);
100 /* Functions to register get/setsockopt ranges (non-inclusive). You
101 need to check permissions yourself! */
102 int nf_register_sockopt(struct nf_sockopt_ops *reg);
103 void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
105 extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
107 typedef void nf_logfn(unsigned int hooknum,
108 const struct sk_buff *skb,
109 const struct net_device *in,
110 const struct net_device *out,
113 /* Function to register/unregister log function. */
114 int nf_log_register(int pf, nf_logfn *logfn);
115 void nf_log_unregister(int pf, nf_logfn *logfn);
117 /* Calls the registered backend logging function */
118 void nf_log_packet(int pf,
119 unsigned int hooknum,
120 const struct sk_buff *skb,
121 const struct net_device *in,
122 const struct net_device *out,
123 const char *fmt, ...);
125 /* Activate hook; either okfn or kfree_skb called, unless a hook
126 returns NF_STOLEN (in which case, it's up to the hook to deal with
129 Returns -ERRNO if packet dropped. Zero means queued, stolen or
134 > I don't want nf_hook to return anything because people might forget
135 > about async and trust the return value to mean "packet was ok".
138 Just document it clearly, then you can expect some sense from kernel
142 /* This is gross, but inline doesn't cut it for avoiding the function
143 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
144 #ifdef CONFIG_NETFILTER_DEBUG
145 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
147 if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
148 __ret = (okfn)(skb); \
150 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
152 if ((__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
153 __ret = (okfn)(skb); \
156 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
158 if (list_empty(&nf_hooks[pf][hook]) || \
159 (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, INT_MIN)) == 1) \
160 __ret = (okfn)(skb); \
162 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
164 if (list_empty(&nf_hooks[pf][hook]) || \
165 (__ret=nf_hook_slow(pf, hook, &(skb), indev, outdev, okfn, thresh)) == 1) \
166 __ret = (okfn)(skb); \
170 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff **pskb,
171 struct net_device *indev, struct net_device *outdev,
172 int (*okfn)(struct sk_buff *), int thresh);
174 /* Call setsockopt() */
175 int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt,
177 int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
181 typedef int (*nf_queue_outfn_t)(struct sk_buff *skb,
182 struct nf_info *info, void *data);
183 extern int nf_register_queue_handler(int pf,
184 nf_queue_outfn_t outfn, void *data);
185 extern int nf_unregister_queue_handler(int pf);
186 extern void nf_reinject(struct sk_buff *skb,
187 struct nf_info *info,
188 unsigned int verdict);
190 extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *);
191 extern void nf_ct_attach(struct sk_buff *, struct sk_buff *);
193 /* FIXME: Before cache is ever used, this must be implemented for real. */
194 extern void nf_invalidate_cache(int pf);
196 #else /* !CONFIG_NETFILTER */
197 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
198 static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
199 #endif /*CONFIG_NETFILTER*/
201 #endif /*__KERNEL__*/
202 #endif /*__LINUX_NETFILTER_H*/