[NET]: Add some sparse annotations to network driver stack.
[linux-2.6/history.git] / include / linux / netfilter.h
blobbbb389af97880f419539951898ba3195f131b3cf
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
14 /* Responses from hook functions. */
15 #define NF_DROP 0
16 #define NF_ACCEPT 1
17 #define NF_STOLEN 2
18 #define NF_QUEUE 3
19 #define NF_REPEAT 4
20 #define NF_MAX_VERDICT NF_REPEAT
22 /* Generic cache responses from hook functions.
23 <= 0x2000 is used for protocol-flags. */
24 #define NFC_UNKNOWN 0x4000
25 #define NFC_ALTERED 0x8000
27 #ifdef __KERNEL__
28 #include <linux/config.h>
29 #ifdef CONFIG_NETFILTER
31 extern void netfilter_init(void);
33 /* Largest hook number + 1 */
34 #define NF_MAX_HOOKS 8
36 struct sk_buff;
37 struct net_device;
39 typedef unsigned int nf_hookfn(unsigned int hooknum,
40 struct sk_buff **skb,
41 const struct net_device *in,
42 const struct net_device *out,
43 int (*okfn)(struct sk_buff *));
45 struct nf_hook_ops
47 struct list_head list;
49 /* User fills in from here down. */
50 nf_hookfn *hook;
51 struct module *owner;
52 int pf;
53 int hooknum;
54 /* Hooks are ordered in ascending priority. */
55 int priority;
58 struct nf_sockopt_ops
60 struct list_head list;
62 int pf;
64 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
65 int set_optmin;
66 int set_optmax;
67 int (*set)(struct sock *sk, int optval, void *user, unsigned int len);
69 int get_optmin;
70 int get_optmax;
71 int (*get)(struct sock *sk, int optval, void *user, int *len);
73 /* Number of users inside set() or get(). */
74 unsigned int use;
75 struct task_struct *cleanup_task;
78 /* Each queued (to userspace) skbuff has one of these. */
79 struct nf_info
81 /* The ops struct which sent us to userspace. */
82 struct nf_hook_ops *elem;
84 /* If we're sent to userspace, this keeps housekeeping info */
85 int pf;
86 unsigned int hook;
87 struct net_device *indev, *outdev;
88 int (*okfn)(struct sk_buff *);
91 /* Function to register/unregister hook points. */
92 int nf_register_hook(struct nf_hook_ops *reg);
93 void nf_unregister_hook(struct nf_hook_ops *reg);
95 /* Functions to register get/setsockopt ranges (non-inclusive). You
96 need to check permissions yourself! */
97 int nf_register_sockopt(struct nf_sockopt_ops *reg);
98 void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
100 extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
102 typedef void nf_logfn(unsigned int hooknum,
103 const struct sk_buff *skb,
104 const struct net_device *in,
105 const struct net_device *out,
106 const char *prefix);
108 /* Function to register/unregister log function. */
109 int nf_log_register(int pf, nf_logfn *logfn);
110 void nf_log_unregister(int pf, nf_logfn *logfn);
112 /* Calls the registered backend logging function */
113 void nf_log_packet(int pf,
114 unsigned int hooknum,
115 const struct sk_buff *skb,
116 const struct net_device *in,
117 const struct net_device *out,
118 const char *fmt, ...);
120 /* Activate hook; either okfn or kfree_skb called, unless a hook
121 returns NF_STOLEN (in which case, it's up to the hook to deal with
122 the consequences).
124 Returns -ERRNO if packet dropped. Zero means queued, stolen or
125 accepted.
128 /* RR:
129 > I don't want nf_hook to return anything because people might forget
130 > about async and trust the return value to mean "packet was ok".
133 Just document it clearly, then you can expect some sense from kernel
134 coders :)
137 /* This is gross, but inline doesn't cut it for avoiding the function
138 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
139 #ifdef CONFIG_NETFILTER_DEBUG
140 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
141 nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
142 #define NF_HOOK_THRESH nf_hook_slow
143 #else
144 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
145 (list_empty(&nf_hooks[(pf)][(hook)]) \
146 ? (okfn)(skb) \
147 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
148 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
149 (list_empty(&nf_hooks[(pf)][(hook)]) \
150 ? (okfn)(skb) \
151 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
152 #endif
154 int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb,
155 struct net_device *indev, struct net_device *outdev,
156 int (*okfn)(struct sk_buff *), int thresh);
158 /* Call setsockopt() */
159 int nf_setsockopt(struct sock *sk, int pf, int optval, char *opt,
160 int len);
161 int nf_getsockopt(struct sock *sk, int pf, int optval, char *opt,
162 int *len);
164 /* Packet queuing */
165 typedef int (*nf_queue_outfn_t)(struct sk_buff *skb,
166 struct nf_info *info, void *data);
167 extern int nf_register_queue_handler(int pf,
168 nf_queue_outfn_t outfn, void *data);
169 extern int nf_unregister_queue_handler(int pf);
170 extern void nf_reinject(struct sk_buff *skb,
171 struct nf_info *info,
172 unsigned int verdict);
174 extern void (*ip_ct_attach)(struct sk_buff *, struct nf_ct_info *);
176 #ifdef CONFIG_NETFILTER_DEBUG
177 extern void nf_dump_skb(int pf, struct sk_buff *skb);
178 #endif
180 /* FIXME: Before cache is ever used, this must be implemented for real. */
181 extern void nf_invalidate_cache(int pf);
183 #else /* !CONFIG_NETFILTER */
184 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
185 #endif /*CONFIG_NETFILTER*/
187 #endif /*__KERNEL__*/
188 #endif /*__LINUX_NETFILTER_H*/