patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / include / linux / netfilter.h
1 #ifndef __LINUX_NETFILTER_H
2 #define __LINUX_NETFILTER_H
3
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
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
21
22 /* Generic cache responses from hook functions.
23    <= 0x2000 is used for protocol-flags. */
24 #define NFC_UNKNOWN 0x4000
25 #define NFC_ALTERED 0x8000
26
27 #ifdef __KERNEL__
28 #include <linux/config.h>
29 #ifdef CONFIG_NETFILTER
30
31 extern void netfilter_init(void);
32
33 /* Largest hook number + 1 */
34 #define NF_MAX_HOOKS 8
35
36 struct sk_buff;
37 struct net_device;
38
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 *));
44
45 struct nf_hook_ops
46 {
47         struct list_head list;
48
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;
56 };
57
58 struct nf_sockopt_ops
59 {
60         struct list_head list;
61
62         int pf;
63
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 *user, unsigned int len);
68
69         int get_optmin;
70         int get_optmax;
71         int (*get)(struct sock *sk, int optval, void __user *user, int *len);
72
73         /* Number of users inside set() or get(). */
74         unsigned int use;
75         struct task_struct *cleanup_task;
76 };
77
78 /* Each queued (to userspace) skbuff has one of these. */
79 struct nf_info
80 {
81         /* The ops struct which sent us to userspace. */
82         struct nf_hook_ops *elem;
83         
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 *);
89 };
90                                                                                 
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);
94
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);
99
100 extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS];
101
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);
107
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);
111
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, ...);
119                    
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).
123
124    Returns -ERRNO if packet dropped.  Zero means queued, stolen or
125    accepted.
126 */
127
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".
131
132    AK:
133    Just document it clearly, then you can expect some sense from kernel
134    coders :)
135 */
136
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
153
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);
157
158 /* Call setsockopt() */
159 int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt, 
160                   int len);
161 int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt,
162                   int *len);
163
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);
173
174 extern inline struct ipt_target *
175 ipt_find_target_lock(const char *name, int *error, struct semaphore *mutex);
176 extern inline struct ip6t_target *
177 ip6t_find_target_lock(const char *name, int *error, struct semaphore *mutex);
178 extern inline struct arpt_target *
179 arpt_find_target_lock(const char *name, int *error, struct semaphore *mutex);
180 extern void (*ip_ct_attach)(struct sk_buff *, struct nf_ct_info *);
181
182 #ifdef CONFIG_NETFILTER_DEBUG
183 extern void nf_dump_skb(int pf, struct sk_buff *skb);
184 #endif
185
186 /* FIXME: Before cache is ever used, this must be implemented for real. */
187 extern void nf_invalidate_cache(int pf);
188
189 #else /* !CONFIG_NETFILTER */
190 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
191 #endif /*CONFIG_NETFILTER*/
192
193 #endif /*__KERNEL__*/
194 #endif /*__LINUX_NETFILTER_H*/