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. */
21 #define NF_MAX_VERDICT NF_REPEAT
23 /* Generic cache responses from hook functions.
24 <= 0x2000 is used for protocol-flags. */
25 #define NFC_UNKNOWN 0x4000
26 #define NFC_ALTERED 0x8000
29 #include <linux/config.h>
30 #ifdef CONFIG_NETFILTER
32 extern void netfilter_init(void);
34 /* Largest hook number + 1 */
35 #define NF_MAX_HOOKS 8
40 typedef unsigned int nf_hookfn(unsigned int hooknum
,
42 const struct net_device
*in
,
43 const struct net_device
*out
,
44 int (*okfn
)(struct sk_buff
*));
48 struct list_head list
;
50 /* User fills in from here down. */
55 /* Hooks are ordered in ascending priority. */
61 struct list_head list
;
65 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
68 int (*set
)(struct sock
*sk
, int optval
, void __user
*user
, unsigned int len
);
72 int (*get
)(struct sock
*sk
, int optval
, void __user
*user
, int *len
);
74 /* Number of users inside set() or get(). */
76 struct task_struct
*cleanup_task
;
79 /* Each queued (to userspace) skbuff has one of these. */
82 /* The ops struct which sent us to userspace. */
83 struct nf_hook_ops
*elem
;
85 /* If we're sent to userspace, this keeps housekeeping info */
88 struct net_device
*indev
, *outdev
;
89 int (*okfn
)(struct sk_buff
*);
92 /* Function to register/unregister hook points. */
93 int nf_register_hook(struct nf_hook_ops
*reg
);
94 void nf_unregister_hook(struct nf_hook_ops
*reg
);
96 /* Functions to register get/setsockopt ranges (non-inclusive). You
97 need to check permissions yourself! */
98 int nf_register_sockopt(struct nf_sockopt_ops
*reg
);
99 void nf_unregister_sockopt(struct nf_sockopt_ops
*reg
);
101 extern struct list_head nf_hooks
[NPROTO
][NF_MAX_HOOKS
];
103 typedef void nf_logfn(unsigned int hooknum
,
104 const struct sk_buff
*skb
,
105 const struct net_device
*in
,
106 const struct net_device
*out
,
109 /* Function to register/unregister log function. */
110 int nf_log_register(int pf
, nf_logfn
*logfn
);
111 void nf_log_unregister(int pf
, nf_logfn
*logfn
);
113 /* Calls the registered backend logging function */
114 void nf_log_packet(int pf
,
115 unsigned int hooknum
,
116 const struct sk_buff
*skb
,
117 const struct net_device
*in
,
118 const struct net_device
*out
,
119 const char *fmt
, ...);
121 /* Activate hook; either okfn or kfree_skb called, unless a hook
122 returns NF_STOLEN (in which case, it's up to the hook to deal with
125 Returns -ERRNO if packet dropped. Zero means queued, stolen or
130 > I don't want nf_hook to return anything because people might forget
131 > about async and trust the return value to mean "packet was ok".
134 Just document it clearly, then you can expect some sense from kernel
138 /* This is gross, but inline doesn't cut it for avoiding the function
139 call in fast path: gcc doesn't inline (needs value tracking?). --RR */
140 #ifdef CONFIG_NETFILTER_DEBUG
141 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
142 nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN)
143 #define NF_HOOK_THRESH nf_hook_slow
145 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
146 (list_empty(&nf_hooks[(pf)][(hook)]) \
148 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), INT_MIN))
149 #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \
150 (list_empty(&nf_hooks[(pf)][(hook)]) \
152 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
155 int nf_hook_slow(int pf
, unsigned int hook
, struct sk_buff
*skb
,
156 struct net_device
*indev
, struct net_device
*outdev
,
157 int (*okfn
)(struct sk_buff
*), int thresh
);
159 /* Call setsockopt() */
160 int nf_setsockopt(struct sock
*sk
, int pf
, int optval
, char __user
*opt
,
162 int nf_getsockopt(struct sock
*sk
, int pf
, int optval
, char __user
*opt
,
166 typedef int (*nf_queue_outfn_t
)(struct sk_buff
*skb
,
167 struct nf_info
*info
, void *data
);
168 extern int nf_register_queue_handler(int pf
,
169 nf_queue_outfn_t outfn
, void *data
);
170 extern int nf_unregister_queue_handler(int pf
);
171 extern void nf_reinject(struct sk_buff
*skb
,
172 struct nf_info
*info
,
173 unsigned int verdict
);
175 extern inline struct ipt_target
*
176 ipt_find_target_lock(const char *name
, int *error
, struct semaphore
*mutex
);
177 extern inline struct ip6t_target
*
178 ip6t_find_target_lock(const char *name
, int *error
, struct semaphore
*mutex
);
179 extern inline struct arpt_target
*
180 arpt_find_target_lock(const char *name
, int *error
, struct semaphore
*mutex
);
181 extern void (*ip_ct_attach
)(struct sk_buff
*, struct sk_buff
*);
183 #ifdef CONFIG_NETFILTER_DEBUG
184 extern void nf_dump_skb(int pf
, struct sk_buff
*skb
);
187 /* FIXME: Before cache is ever used, this must be implemented for real. */
188 extern void nf_invalidate_cache(int pf
);
190 #else /* !CONFIG_NETFILTER */
191 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb)
192 #endif /*CONFIG_NETFILTER*/
194 #endif /*__KERNEL__*/
195 #endif /*__LINUX_NETFILTER_H*/