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 <= 0x2000 is used for protocol-flags. */
24 #define NFC_UNKNOWN 0x4000
25 #define NFC_ALTERED 0x8000
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
39 typedef unsigned int nf_hookfn(unsigned int hooknum
,
41 const struct net_device
*in
,
42 const struct net_device
*out
,
43 int (*okfn
)(struct sk_buff
*));
47 struct list_head list
;
49 /* User fills in from here down. */
54 /* Hooks are ordered in ascending priority. */
60 struct list_head list
;
64 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
67 int (*set
)(struct sock
*sk
, int optval
, void *user
, unsigned int len
);
71 int (*get
)(struct sock
*sk
, int optval
, void *user
, int *len
);
73 /* Number of users inside set() or get(). */
75 struct task_struct
*cleanup_task
;
78 /* Each queued (to userspace) skbuff has one of these. */
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 */
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
,
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
124 Returns -ERRNO if packet dropped. Zero means queued, stolen or
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
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
144 #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \
145 (list_empty(&nf_hooks[(pf)][(hook)]) \
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)]) \
151 : nf_hook_slow((pf), (hook), (skb), (indev), (outdev), (okfn), (thresh)))
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
,
161 int nf_getsockopt(struct sock
*sk
, int pf
, int optval
, char *opt
,
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
);
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*/