Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | #include <linux/compiler.h> |
| 14 | |
| 15 | /* Responses from hook functions. */ |
| 16 | #define NF_DROP 0 |
| 17 | #define NF_ACCEPT 1 |
| 18 | #define NF_STOLEN 2 |
| 19 | #define NF_QUEUE 3 |
| 20 | #define NF_REPEAT 4 |
| 21 | #define NF_STOP 5 |
| 22 | #define NF_MAX_VERDICT NF_STOP |
| 23 | |
Harald Welte | 0ab43f8 | 2005-08-09 19:43:44 -0700 | [diff] [blame] | 24 | /* we overload the higher bits for encoding auxiliary data such as the queue |
| 25 | * number. Not nice, but better than additional function arguments. */ |
| 26 | #define NF_VERDICT_MASK 0x0000ffff |
| 27 | #define NF_VERDICT_BITS 16 |
| 28 | |
| 29 | #define NF_VERDICT_QMASK 0xffff0000 |
| 30 | #define NF_VERDICT_QBITS 16 |
| 31 | |
Harald Welte | b766b30 | 2005-08-12 11:36:44 -0700 | [diff] [blame] | 32 | #define NF_QUEUE_NR(x) (((x << NF_VERDICT_QBITS) & NF_VERDICT_QMASK) | NF_QUEUE) |
Harald Welte | 0ab43f8 | 2005-08-09 19:43:44 -0700 | [diff] [blame] | 33 | |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 34 | /* only for userspace compatibility */ |
| 35 | #ifndef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* Generic cache responses from hook functions. |
| 37 | <= 0x2000 is used for protocol-flags. */ |
| 38 | #define NFC_UNKNOWN 0x4000 |
| 39 | #define NFC_ALTERED 0x8000 |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 40 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | #ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #ifdef CONFIG_NETFILTER |
| 44 | |
| 45 | extern void netfilter_init(void); |
| 46 | |
| 47 | /* Largest hook number + 1 */ |
| 48 | #define NF_MAX_HOOKS 8 |
| 49 | |
| 50 | struct sk_buff; |
| 51 | struct net_device; |
| 52 | |
| 53 | typedef unsigned int nf_hookfn(unsigned int hooknum, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 54 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | const struct net_device *in, |
| 56 | const struct net_device *out, |
| 57 | int (*okfn)(struct sk_buff *)); |
| 58 | |
| 59 | struct nf_hook_ops |
| 60 | { |
| 61 | struct list_head list; |
| 62 | |
| 63 | /* User fills in from here down. */ |
| 64 | nf_hookfn *hook; |
| 65 | struct module *owner; |
| 66 | int pf; |
| 67 | int hooknum; |
| 68 | /* Hooks are ordered in ascending priority. */ |
| 69 | int priority; |
| 70 | }; |
| 71 | |
| 72 | struct nf_sockopt_ops |
| 73 | { |
| 74 | struct list_head list; |
| 75 | |
| 76 | int pf; |
| 77 | |
| 78 | /* Non-inclusive ranges: use 0/0/NULL to never get called. */ |
| 79 | int set_optmin; |
| 80 | int set_optmax; |
| 81 | int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 82 | int (*compat_set)(struct sock *sk, int optval, |
| 83 | void __user *user, unsigned int len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
| 85 | int get_optmin; |
| 86 | int get_optmax; |
| 87 | int (*get)(struct sock *sk, int optval, void __user *user, int *len); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 88 | int (*compat_get)(struct sock *sk, int optval, |
| 89 | void __user *user, int *len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Neil Horman | 16fcec3 | 2007-09-11 11:28:26 +0200 | [diff] [blame] | 91 | /* Use the module struct to lock set/get code in place */ |
| 92 | struct module *owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /* Each queued (to userspace) skbuff has one of these. */ |
| 96 | struct nf_info |
| 97 | { |
| 98 | /* The ops struct which sent us to userspace. */ |
| 99 | struct nf_hook_ops *elem; |
| 100 | |
| 101 | /* If we're sent to userspace, this keeps housekeeping info */ |
| 102 | int pf; |
| 103 | unsigned int hook; |
| 104 | struct net_device *indev, *outdev; |
| 105 | int (*okfn)(struct sk_buff *); |
| 106 | }; |
| 107 | |
| 108 | /* Function to register/unregister hook points. */ |
| 109 | int nf_register_hook(struct nf_hook_ops *reg); |
| 110 | void nf_unregister_hook(struct nf_hook_ops *reg); |
Patrick McHardy | 972d1cb | 2006-04-06 14:09:12 -0700 | [diff] [blame] | 111 | int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n); |
| 112 | void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | /* Functions to register get/setsockopt ranges (non-inclusive). You |
| 115 | need to check permissions yourself! */ |
| 116 | int nf_register_sockopt(struct nf_sockopt_ops *reg); |
| 117 | void nf_unregister_sockopt(struct nf_sockopt_ops *reg); |
| 118 | |
Patrick McHardy | d62f9ed | 2006-11-29 02:35:17 +0100 | [diff] [blame] | 119 | #ifdef CONFIG_SYSCTL |
| 120 | /* Sysctl registration */ |
| 121 | struct ctl_table_header *nf_register_sysctl_table(struct ctl_table *path, |
| 122 | struct ctl_table *table); |
| 123 | void nf_unregister_sysctl_table(struct ctl_table_header *header, |
| 124 | struct ctl_table *table); |
| 125 | extern struct ctl_table nf_net_netfilter_sysctl_path[]; |
| 126 | extern struct ctl_table nf_net_ipv4_netfilter_sysctl_path[]; |
| 127 | #endif /* CONFIG_SYSCTL */ |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | extern struct list_head nf_hooks[NPROTO][NF_MAX_HOOKS]; |
| 130 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 131 | /* those NF_LOG_* defines and struct nf_loginfo are legacy definitios that will |
| 132 | * disappear once iptables is replaced with pkttables. Please DO NOT use them |
| 133 | * for any new code! */ |
| 134 | #define NF_LOG_TCPSEQ 0x01 /* Log TCP sequence numbers */ |
| 135 | #define NF_LOG_TCPOPT 0x02 /* Log TCP options */ |
| 136 | #define NF_LOG_IPOPT 0x04 /* Log IP options */ |
| 137 | #define NF_LOG_UID 0x08 /* Log UID owning local socket */ |
| 138 | #define NF_LOG_MASK 0x0f |
| 139 | |
| 140 | #define NF_LOG_TYPE_LOG 0x01 |
| 141 | #define NF_LOG_TYPE_ULOG 0x02 |
| 142 | |
| 143 | struct nf_loginfo { |
| 144 | u_int8_t type; |
| 145 | union { |
| 146 | struct { |
| 147 | u_int32_t copy_len; |
| 148 | u_int16_t group; |
| 149 | u_int16_t qthreshold; |
| 150 | } ulog; |
| 151 | struct { |
| 152 | u_int8_t level; |
| 153 | u_int8_t logflags; |
| 154 | } log; |
| 155 | } u; |
| 156 | }; |
| 157 | |
| 158 | typedef void nf_logfn(unsigned int pf, |
| 159 | unsigned int hooknum, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | const struct sk_buff *skb, |
| 161 | const struct net_device *in, |
| 162 | const struct net_device *out, |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 163 | const struct nf_loginfo *li, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | const char *prefix); |
| 165 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 166 | struct nf_logger { |
| 167 | struct module *me; |
| 168 | nf_logfn *logfn; |
| 169 | char *name; |
| 170 | }; |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | /* Function to register/unregister log function. */ |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 173 | int nf_log_register(int pf, struct nf_logger *logger); |
Patrick McHardy | e92ad99 | 2007-02-12 11:11:55 -0800 | [diff] [blame] | 174 | void nf_log_unregister(struct nf_logger *logger); |
Patrick McHardy | 9dc6aa5 | 2007-02-12 11:11:24 -0800 | [diff] [blame] | 175 | void nf_log_unregister_pf(int pf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
| 177 | /* Calls the registered backend logging function */ |
| 178 | void nf_log_packet(int pf, |
| 179 | unsigned int hooknum, |
| 180 | const struct sk_buff *skb, |
| 181 | const struct net_device *in, |
| 182 | const struct net_device *out, |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 183 | struct nf_loginfo *li, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | const char *fmt, ...); |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 185 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 186 | int nf_hook_slow(int pf, unsigned int hook, struct sk_buff *skb, |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 187 | struct net_device *indev, struct net_device *outdev, |
| 188 | int (*okfn)(struct sk_buff *), int thresh); |
| 189 | |
| 190 | /** |
| 191 | * nf_hook_thresh - call a netfilter hook |
| 192 | * |
| 193 | * Returns 1 if the hook has allowed the packet to pass. The function |
| 194 | * okfn must be invoked by the caller in this case. Any other return |
| 195 | * value indicates the packet has been consumed by the hook. |
| 196 | */ |
| 197 | static inline int nf_hook_thresh(int pf, unsigned int hook, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 198 | struct sk_buff *skb, |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 199 | struct net_device *indev, |
| 200 | struct net_device *outdev, |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 201 | int (*okfn)(struct sk_buff *), int thresh, |
| 202 | int cond) |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 203 | { |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 204 | if (!cond) |
| 205 | return 1; |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 206 | #ifndef CONFIG_NETFILTER_DEBUG |
| 207 | if (list_empty(&nf_hooks[pf][hook])) |
| 208 | return 1; |
| 209 | #endif |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 210 | return nf_hook_slow(pf, hook, skb, indev, outdev, okfn, thresh); |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 211 | } |
| 212 | |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 213 | static inline int nf_hook(int pf, unsigned int hook, struct sk_buff *skb, |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 214 | struct net_device *indev, struct net_device *outdev, |
| 215 | int (*okfn)(struct sk_buff *)) |
| 216 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 217 | return nf_hook_thresh(pf, hook, skb, indev, outdev, okfn, INT_MIN, 1); |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | /* Activate hook; either okfn or kfree_skb called, unless a hook |
| 221 | returns NF_STOLEN (in which case, it's up to the hook to deal with |
| 222 | the consequences). |
| 223 | |
| 224 | Returns -ERRNO if packet dropped. Zero means queued, stolen or |
| 225 | accepted. |
| 226 | */ |
| 227 | |
| 228 | /* RR: |
| 229 | > I don't want nf_hook to return anything because people might forget |
| 230 | > about async and trust the return value to mean "packet was ok". |
| 231 | |
| 232 | AK: |
| 233 | Just document it clearly, then you can expect some sense from kernel |
| 234 | coders :) |
| 235 | */ |
| 236 | |
| 237 | /* This is gross, but inline doesn't cut it for avoiding the function |
| 238 | call in fast path: gcc doesn't inline (needs value tracking?). --RR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 240 | /* HX: It's slightly less gross now. */ |
| 241 | |
| 242 | #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \ |
| 243 | ({int __ret; \ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 244 | if ((__ret=nf_hook_thresh(pf, hook, (skb), indev, outdev, okfn, thresh, 1)) == 1)\ |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 245 | __ret = (okfn)(skb); \ |
| 246 | __ret;}) |
| 247 | |
| 248 | #define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \ |
| 249 | ({int __ret; \ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 250 | if ((__ret=nf_hook_thresh(pf, hook, (skb), indev, outdev, okfn, INT_MIN, cond)) == 1)\ |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 251 | __ret = (okfn)(skb); \ |
| 252 | __ret;}) |
| 253 | |
| 254 | #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \ |
| 255 | NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, INT_MIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | /* Call setsockopt() */ |
| 258 | int nf_setsockopt(struct sock *sk, int pf, int optval, char __user *opt, |
| 259 | int len); |
| 260 | int nf_getsockopt(struct sock *sk, int pf, int optval, char __user *opt, |
| 261 | int *len); |
| 262 | |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 263 | int compat_nf_setsockopt(struct sock *sk, int pf, int optval, |
| 264 | char __user *opt, int len); |
| 265 | int compat_nf_getsockopt(struct sock *sk, int pf, int optval, |
| 266 | char __user *opt, int *len); |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /* Packet queuing */ |
Harald Welte | bbd86b9f | 2005-08-09 20:23:11 -0700 | [diff] [blame] | 269 | struct nf_queue_handler { |
| 270 | int (*outfn)(struct sk_buff *skb, struct nf_info *info, |
| 271 | unsigned int queuenum, void *data); |
| 272 | void *data; |
| 273 | char *name; |
| 274 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | extern int nf_register_queue_handler(int pf, |
Harald Welte | bbd86b9f | 2005-08-09 20:23:11 -0700 | [diff] [blame] | 276 | struct nf_queue_handler *qh); |
Yasuyuki Kozakai | ce7663d | 2007-07-07 22:40:08 -0700 | [diff] [blame] | 277 | extern int nf_unregister_queue_handler(int pf, |
| 278 | struct nf_queue_handler *qh); |
Harald Welte | bbd86b9f | 2005-08-09 20:23:11 -0700 | [diff] [blame] | 279 | extern void nf_unregister_queue_handlers(struct nf_queue_handler *qh); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | extern void nf_reinject(struct sk_buff *skb, |
| 281 | struct nf_info *info, |
| 282 | unsigned int verdict); |
| 283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | /* FIXME: Before cache is ever used, this must be implemented for real. */ |
| 285 | extern void nf_invalidate_cache(int pf); |
| 286 | |
Harald Welte | 089af26 | 2005-08-09 19:37:23 -0700 | [diff] [blame] | 287 | /* Call this before modifying an existing packet: ensures it is |
| 288 | modifiable and linear to the point you care about (writable_len). |
| 289 | Returns true or false. */ |
Herbert Xu | 37d4187 | 2007-10-14 00:39:18 -0700 | [diff] [blame] | 290 | extern int skb_make_writable(struct sk_buff *skb, unsigned int writable_len); |
Harald Welte | 089af26 | 2005-08-09 19:37:23 -0700 | [diff] [blame] | 291 | |
Al Viro | 43bc0ca | 2006-11-14 21:43:23 -0800 | [diff] [blame] | 292 | static inline void nf_csum_replace4(__sum16 *sum, __be32 from, __be32 to) |
| 293 | { |
| 294 | __be32 diff[] = { ~from, to }; |
| 295 | |
| 296 | *sum = csum_fold(csum_partial((char *)diff, sizeof(diff), ~csum_unfold(*sum))); |
| 297 | } |
| 298 | |
| 299 | static inline void nf_csum_replace2(__sum16 *sum, __be16 from, __be16 to) |
| 300 | { |
| 301 | nf_csum_replace4(sum, (__force __be32)from, (__force __be32)to); |
| 302 | } |
| 303 | |
| 304 | extern void nf_proto_csum_replace4(__sum16 *sum, struct sk_buff *skb, |
| 305 | __be32 from, __be32 to, int pseudohdr); |
| 306 | |
| 307 | static inline void nf_proto_csum_replace2(__sum16 *sum, struct sk_buff *skb, |
| 308 | __be16 from, __be16 to, int pseudohdr) |
| 309 | { |
| 310 | nf_proto_csum_replace4(sum, skb, (__force __be32)from, |
| 311 | (__force __be32)to, pseudohdr); |
| 312 | } |
Patrick McHardy | 4cf411d | 2006-08-05 00:58:33 -0700 | [diff] [blame] | 313 | |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 314 | struct nf_afinfo { |
| 315 | unsigned short family; |
Al Viro | b51655b | 2006-11-14 21:40:42 -0800 | [diff] [blame] | 316 | __sum16 (*checksum)(struct sk_buff *skb, unsigned int hook, |
Patrick McHardy | 422c346 | 2006-04-06 14:18:43 -0700 | [diff] [blame] | 317 | unsigned int dataoff, u_int8_t protocol); |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 318 | void (*saveroute)(const struct sk_buff *skb, |
| 319 | struct nf_info *info); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 320 | int (*reroute)(struct sk_buff *skb, |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 321 | const struct nf_info *info); |
| 322 | int route_key_size; |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 323 | }; |
| 324 | |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 325 | extern struct nf_afinfo *nf_afinfo[]; |
| 326 | static inline struct nf_afinfo *nf_get_afinfo(unsigned short family) |
| 327 | { |
| 328 | return rcu_dereference(nf_afinfo[family]); |
| 329 | } |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 330 | |
Al Viro | b51655b | 2006-11-14 21:40:42 -0800 | [diff] [blame] | 331 | static inline __sum16 |
Patrick McHardy | 422c346 | 2006-04-06 14:18:43 -0700 | [diff] [blame] | 332 | nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, |
| 333 | u_int8_t protocol, unsigned short family) |
| 334 | { |
| 335 | struct nf_afinfo *afinfo; |
Al Viro | b51655b | 2006-11-14 21:40:42 -0800 | [diff] [blame] | 336 | __sum16 csum = 0; |
Patrick McHardy | 422c346 | 2006-04-06 14:18:43 -0700 | [diff] [blame] | 337 | |
| 338 | rcu_read_lock(); |
| 339 | afinfo = nf_get_afinfo(family); |
| 340 | if (afinfo) |
| 341 | csum = afinfo->checksum(skb, hook, dataoff, protocol); |
| 342 | rcu_read_unlock(); |
| 343 | return csum; |
| 344 | } |
| 345 | |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 346 | extern int nf_register_afinfo(struct nf_afinfo *afinfo); |
| 347 | extern void nf_unregister_afinfo(struct nf_afinfo *afinfo); |
| 348 | |
| 349 | #define nf_info_reroute(x) ((void *)x + sizeof(struct nf_info)) |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 350 | |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 351 | #include <net/flow.h> |
| 352 | extern void (*ip_nat_decode_session)(struct sk_buff *, struct flowi *); |
| 353 | |
| 354 | static inline void |
| 355 | nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family) |
| 356 | { |
Jozsef Kadlecsik | 5b1158e | 2006-12-02 22:07:13 -0800 | [diff] [blame] | 357 | #if defined(CONFIG_IP_NF_NAT_NEEDED) || defined(CONFIG_NF_NAT_NEEDED) |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 358 | void (*decodefn)(struct sk_buff *, struct flowi *); |
| 359 | |
| 360 | if (family == AF_INET && (decodefn = ip_nat_decode_session) != NULL) |
| 361 | decodefn(skb, fl); |
| 362 | #endif |
| 363 | } |
| 364 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 365 | #ifdef CONFIG_PROC_FS |
| 366 | #include <linux/proc_fs.h> |
| 367 | extern struct proc_dir_entry *proc_net_netfilter; |
| 368 | #endif |
| 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | #else /* !CONFIG_NETFILTER */ |
| 371 | #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb) |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 372 | #define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb) |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 373 | static inline int nf_hook_thresh(int pf, unsigned int hook, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 374 | struct sk_buff *skb, |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 375 | struct net_device *indev, |
| 376 | struct net_device *outdev, |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 377 | int (*okfn)(struct sk_buff *), int thresh, |
| 378 | int cond) |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 379 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 380 | return okfn(skb); |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 381 | } |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 382 | static inline int nf_hook(int pf, unsigned int hook, struct sk_buff *skb, |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 383 | struct net_device *indev, struct net_device *outdev, |
| 384 | int (*okfn)(struct sk_buff *)) |
| 385 | { |
Patrick McHardy | 9c92d34 | 2006-02-15 15:18:19 -0800 | [diff] [blame] | 386 | return 1; |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 387 | } |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 388 | struct flowi; |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 389 | static inline void |
| 390 | nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, int family) {} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | #endif /*CONFIG_NETFILTER*/ |
| 392 | |
Yasuyuki Kozakai | 5f79e0f | 2007-03-23 11:17:07 -0700 | [diff] [blame] | 393 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
| 394 | extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *); |
| 395 | extern void nf_ct_attach(struct sk_buff *, struct sk_buff *); |
Yasuyuki Kozakai | de6e05c | 2007-03-23 11:17:27 -0700 | [diff] [blame] | 396 | extern void (*nf_ct_destroy)(struct nf_conntrack *); |
Yasuyuki Kozakai | 5f79e0f | 2007-03-23 11:17:07 -0700 | [diff] [blame] | 397 | #else |
| 398 | static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {} |
| 399 | #endif |
| 400 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | #endif /*__KERNEL__*/ |
| 402 | #endif /*__LINUX_NETFILTER_H*/ |