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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/skbuff.h> |
| 7 | #include <linux/net.h> |
| 8 | #include <linux/if.h> |
Jan Engelhardt | 2e3075a | 2008-01-14 23:40:34 -0800 | [diff] [blame] | 9 | #include <linux/in.h> |
| 10 | #include <linux/in6.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/wait.h> |
| 12 | #include <linux/list.h> |
| 13 | #endif |
Patrick McHardy | c8942f1 | 2008-05-21 14:08:38 -0700 | [diff] [blame] | 14 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/compiler.h> |
| 16 | |
| 17 | /* Responses from hook functions. */ |
| 18 | #define NF_DROP 0 |
| 19 | #define NF_ACCEPT 1 |
| 20 | #define NF_STOLEN 2 |
| 21 | #define NF_QUEUE 3 |
| 22 | #define NF_REPEAT 4 |
| 23 | #define NF_STOP 5 |
| 24 | #define NF_MAX_VERDICT NF_STOP |
| 25 | |
Harald Welte | 0ab43f8 | 2005-08-09 19:43:44 -0700 | [diff] [blame] | 26 | /* we overload the higher bits for encoding auxiliary data such as the queue |
| 27 | * number. Not nice, but better than additional function arguments. */ |
| 28 | #define NF_VERDICT_MASK 0x0000ffff |
| 29 | #define NF_VERDICT_BITS 16 |
| 30 | |
| 31 | #define NF_VERDICT_QMASK 0xffff0000 |
| 32 | #define NF_VERDICT_QBITS 16 |
| 33 | |
Patrick McHardy | fbabbed | 2008-02-27 12:21:18 -0800 | [diff] [blame] | 34 | #define NF_QUEUE_NR(x) ((((x) << NF_VERDICT_BITS) & NF_VERDICT_QMASK) | NF_QUEUE) |
Harald Welte | 0ab43f8 | 2005-08-09 19:43:44 -0700 | [diff] [blame] | 35 | |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 36 | /* only for userspace compatibility */ |
| 37 | #ifndef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | /* Generic cache responses from hook functions. |
| 39 | <= 0x2000 is used for protocol-flags. */ |
| 40 | #define NFC_UNKNOWN 0x4000 |
| 41 | #define NFC_ALTERED 0x8000 |
Harald Welte | 6869c4d | 2005-08-09 19:24:19 -0700 | [diff] [blame] | 42 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 44 | enum nf_inet_hooks { |
| 45 | NF_INET_PRE_ROUTING, |
| 46 | NF_INET_LOCAL_IN, |
| 47 | NF_INET_FORWARD, |
| 48 | NF_INET_LOCAL_OUT, |
| 49 | NF_INET_POST_ROUTING, |
| 50 | NF_INET_NUMHOOKS |
| 51 | }; |
| 52 | |
Jan Engelhardt | 7e9c6ee | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 53 | enum { |
| 54 | NFPROTO_UNSPEC = 0, |
| 55 | NFPROTO_IPV4 = 2, |
| 56 | NFPROTO_ARP = 3, |
| 57 | NFPROTO_BRIDGE = 7, |
| 58 | NFPROTO_IPV6 = 10, |
| 59 | NFPROTO_DECNET = 12, |
| 60 | NFPROTO_NUMPROTO, |
| 61 | }; |
| 62 | |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 63 | union nf_inet_addr { |
Patrick McHardy | 7b33ed2 | 2008-02-19 17:20:33 -0800 | [diff] [blame] | 64 | __u32 all[4]; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 65 | __be32 ip; |
| 66 | __be32 ip6[4]; |
Jan Engelhardt | 2e3075a | 2008-01-14 23:40:34 -0800 | [diff] [blame] | 67 | struct in_addr in; |
| 68 | struct in6_addr in6; |
Jan Engelhardt | 643a2c1 | 2007-12-17 22:43:50 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #ifdef CONFIG_NETFILTER |
| 73 | |
Patrick McHardy | b8beedd | 2008-03-25 20:09:33 -0700 | [diff] [blame] | 74 | static inline int nf_inet_addr_cmp(const union nf_inet_addr *a1, |
| 75 | const union nf_inet_addr *a2) |
| 76 | { |
| 77 | return a1->all[0] == a2->all[0] && |
| 78 | a1->all[1] == a2->all[1] && |
| 79 | a1->all[2] == a2->all[2] && |
| 80 | a1->all[3] == a2->all[3]; |
| 81 | } |
| 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | extern void netfilter_init(void); |
| 84 | |
| 85 | /* Largest hook number + 1 */ |
| 86 | #define NF_MAX_HOOKS 8 |
| 87 | |
| 88 | struct sk_buff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | typedef unsigned int nf_hookfn(unsigned int hooknum, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 91 | struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | const struct net_device *in, |
| 93 | const struct net_device *out, |
| 94 | int (*okfn)(struct sk_buff *)); |
| 95 | |
| 96 | struct nf_hook_ops |
| 97 | { |
| 98 | struct list_head list; |
| 99 | |
| 100 | /* User fills in from here down. */ |
| 101 | nf_hookfn *hook; |
| 102 | struct module *owner; |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 103 | u_int8_t pf; |
| 104 | unsigned int hooknum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | /* Hooks are ordered in ascending priority. */ |
| 106 | int priority; |
| 107 | }; |
| 108 | |
| 109 | struct nf_sockopt_ops |
| 110 | { |
| 111 | struct list_head list; |
| 112 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 113 | u_int8_t pf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
| 115 | /* Non-inclusive ranges: use 0/0/NULL to never get called. */ |
| 116 | int set_optmin; |
| 117 | int set_optmax; |
| 118 | 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] | 119 | int (*compat_set)(struct sock *sk, int optval, |
| 120 | void __user *user, unsigned int len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | int get_optmin; |
| 123 | int get_optmax; |
| 124 | int (*get)(struct sock *sk, int optval, void __user *user, int *len); |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 125 | int (*compat_get)(struct sock *sk, int optval, |
| 126 | void __user *user, int *len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
Neil Horman | 16fcec3 | 2007-09-11 11:28:26 +0200 | [diff] [blame] | 128 | /* Use the module struct to lock set/get code in place */ |
| 129 | struct module *owner; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | }; |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* Function to register/unregister hook points. */ |
| 133 | int nf_register_hook(struct nf_hook_ops *reg); |
| 134 | void nf_unregister_hook(struct nf_hook_ops *reg); |
Patrick McHardy | 972d1cb | 2006-04-06 14:09:12 -0700 | [diff] [blame] | 135 | int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n); |
| 136 | void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
| 138 | /* Functions to register get/setsockopt ranges (non-inclusive). You |
| 139 | need to check permissions yourself! */ |
| 140 | int nf_register_sockopt(struct nf_sockopt_ops *reg); |
| 141 | void nf_unregister_sockopt(struct nf_sockopt_ops *reg); |
| 142 | |
Patrick McHardy | d62f9ed | 2006-11-29 02:35:17 +0100 | [diff] [blame] | 143 | #ifdef CONFIG_SYSCTL |
| 144 | /* Sysctl registration */ |
Pavel Emelyanov | b3fd3ff | 2008-01-09 00:34:02 -0800 | [diff] [blame] | 145 | extern struct ctl_path nf_net_netfilter_sysctl_path[]; |
| 146 | extern struct ctl_path nf_net_ipv4_netfilter_sysctl_path[]; |
Patrick McHardy | d62f9ed | 2006-11-29 02:35:17 +0100 | [diff] [blame] | 147 | #endif /* CONFIG_SYSCTL */ |
| 148 | |
Jan Engelhardt | 7e9c6ee | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 149 | extern struct list_head nf_hooks[NFPROTO_NUMPROTO][NF_MAX_HOOKS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 151 | int nf_hook_slow(u_int8_t pf, unsigned int hook, struct sk_buff *skb, |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 152 | struct net_device *indev, struct net_device *outdev, |
| 153 | int (*okfn)(struct sk_buff *), int thresh); |
| 154 | |
| 155 | /** |
| 156 | * nf_hook_thresh - call a netfilter hook |
| 157 | * |
| 158 | * Returns 1 if the hook has allowed the packet to pass. The function |
| 159 | * okfn must be invoked by the caller in this case. Any other return |
| 160 | * value indicates the packet has been consumed by the hook. |
| 161 | */ |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 162 | static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 163 | struct sk_buff *skb, |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 164 | struct net_device *indev, |
| 165 | struct net_device *outdev, |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 166 | int (*okfn)(struct sk_buff *), int thresh, |
| 167 | int cond) |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 168 | { |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 169 | if (!cond) |
| 170 | return 1; |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 171 | #ifndef CONFIG_NETFILTER_DEBUG |
| 172 | if (list_empty(&nf_hooks[pf][hook])) |
| 173 | return 1; |
| 174 | #endif |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 175 | return nf_hook_slow(pf, hook, skb, indev, outdev, okfn, thresh); |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 178 | static inline int nf_hook(u_int8_t pf, unsigned int hook, struct sk_buff *skb, |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 179 | struct net_device *indev, struct net_device *outdev, |
| 180 | int (*okfn)(struct sk_buff *)) |
| 181 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 182 | 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] | 183 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | /* Activate hook; either okfn or kfree_skb called, unless a hook |
| 186 | returns NF_STOLEN (in which case, it's up to the hook to deal with |
| 187 | the consequences). |
| 188 | |
| 189 | Returns -ERRNO if packet dropped. Zero means queued, stolen or |
| 190 | accepted. |
| 191 | */ |
| 192 | |
| 193 | /* RR: |
| 194 | > I don't want nf_hook to return anything because people might forget |
| 195 | > about async and trust the return value to mean "packet was ok". |
| 196 | |
| 197 | AK: |
| 198 | Just document it clearly, then you can expect some sense from kernel |
| 199 | coders :) |
| 200 | */ |
| 201 | |
| 202 | /* This is gross, but inline doesn't cut it for avoiding the function |
| 203 | call in fast path: gcc doesn't inline (needs value tracking?). --RR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Patrick McHardy | 16a6677 | 2006-01-06 23:01:48 -0800 | [diff] [blame] | 205 | /* HX: It's slightly less gross now. */ |
| 206 | |
| 207 | #define NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, thresh) \ |
| 208 | ({int __ret; \ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 209 | 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] | 210 | __ret = (okfn)(skb); \ |
| 211 | __ret;}) |
| 212 | |
| 213 | #define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) \ |
| 214 | ({int __ret; \ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 215 | 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] | 216 | __ret = (okfn)(skb); \ |
| 217 | __ret;}) |
| 218 | |
| 219 | #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) \ |
| 220 | NF_HOOK_THRESH(pf, hook, skb, indev, outdev, okfn, INT_MIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | /* Call setsockopt() */ |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 223 | int nf_setsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 224 | unsigned int len); |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 225 | int nf_getsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | int *len); |
| 227 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 228 | int compat_nf_setsockopt(struct sock *sk, u_int8_t pf, int optval, |
David S. Miller | b705884 | 2009-09-30 16:12:20 -0700 | [diff] [blame] | 229 | char __user *opt, unsigned int len); |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 230 | int compat_nf_getsockopt(struct sock *sk, u_int8_t pf, int optval, |
Dmitry Mishin | 3fdadf7 | 2006-03-20 22:45:21 -0800 | [diff] [blame] | 231 | char __user *opt, int *len); |
| 232 | |
Harald Welte | 089af26 | 2005-08-09 19:37:23 -0700 | [diff] [blame] | 233 | /* Call this before modifying an existing packet: ensures it is |
| 234 | modifiable and linear to the point you care about (writable_len). |
| 235 | Returns true or false. */ |
Herbert Xu | 37d4187 | 2007-10-14 00:39:18 -0700 | [diff] [blame] | 236 | 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] | 237 | |
Patrick McHardy | 1841a4c | 2007-12-05 01:22:05 -0800 | [diff] [blame] | 238 | struct flowi; |
Patrick McHardy | 02f014d | 2007-12-05 01:26:33 -0800 | [diff] [blame] | 239 | struct nf_queue_entry; |
Patrick McHardy | c01cd42 | 2007-12-05 01:24:48 -0800 | [diff] [blame] | 240 | |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 241 | struct nf_afinfo { |
| 242 | unsigned short family; |
Al Viro | b51655b | 2006-11-14 21:40:42 -0800 | [diff] [blame] | 243 | __sum16 (*checksum)(struct sk_buff *skb, unsigned int hook, |
Patrick McHardy | 422c346 | 2006-04-06 14:18:43 -0700 | [diff] [blame] | 244 | unsigned int dataoff, u_int8_t protocol); |
Patrick McHardy | d63a650 | 2008-03-20 15:15:53 +0100 | [diff] [blame] | 245 | __sum16 (*checksum_partial)(struct sk_buff *skb, |
| 246 | unsigned int hook, |
| 247 | unsigned int dataoff, |
| 248 | unsigned int len, |
| 249 | u_int8_t protocol); |
Patrick McHardy | 1841a4c | 2007-12-05 01:22:05 -0800 | [diff] [blame] | 250 | int (*route)(struct dst_entry **dst, struct flowi *fl); |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 251 | void (*saveroute)(const struct sk_buff *skb, |
Patrick McHardy | 02f014d | 2007-12-05 01:26:33 -0800 | [diff] [blame] | 252 | struct nf_queue_entry *entry); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 253 | int (*reroute)(struct sk_buff *skb, |
Patrick McHardy | 02f014d | 2007-12-05 01:26:33 -0800 | [diff] [blame] | 254 | const struct nf_queue_entry *entry); |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 255 | int route_key_size; |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
Jan Engelhardt | 7e9c6ee | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 258 | extern const struct nf_afinfo *nf_afinfo[NFPROTO_NUMPROTO]; |
Patrick McHardy | 1e796fd | 2007-12-17 22:42:27 -0800 | [diff] [blame] | 259 | static inline const struct nf_afinfo *nf_get_afinfo(unsigned short family) |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 260 | { |
| 261 | return rcu_dereference(nf_afinfo[family]); |
| 262 | } |
Harald Welte | 2cc7d57 | 2005-08-09 19:42:34 -0700 | [diff] [blame] | 263 | |
Al Viro | b51655b | 2006-11-14 21:40:42 -0800 | [diff] [blame] | 264 | static inline __sum16 |
Patrick McHardy | 422c346 | 2006-04-06 14:18:43 -0700 | [diff] [blame] | 265 | nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff, |
| 266 | u_int8_t protocol, unsigned short family) |
| 267 | { |
Patrick McHardy | 1e796fd | 2007-12-17 22:42:27 -0800 | [diff] [blame] | 268 | const struct nf_afinfo *afinfo; |
Al Viro | b51655b | 2006-11-14 21:40:42 -0800 | [diff] [blame] | 269 | __sum16 csum = 0; |
Patrick McHardy | 422c346 | 2006-04-06 14:18:43 -0700 | [diff] [blame] | 270 | |
| 271 | rcu_read_lock(); |
| 272 | afinfo = nf_get_afinfo(family); |
| 273 | if (afinfo) |
| 274 | csum = afinfo->checksum(skb, hook, dataoff, protocol); |
| 275 | rcu_read_unlock(); |
| 276 | return csum; |
| 277 | } |
| 278 | |
Patrick McHardy | d63a650 | 2008-03-20 15:15:53 +0100 | [diff] [blame] | 279 | static inline __sum16 |
| 280 | nf_checksum_partial(struct sk_buff *skb, unsigned int hook, |
| 281 | unsigned int dataoff, unsigned int len, |
| 282 | u_int8_t protocol, unsigned short family) |
| 283 | { |
| 284 | const struct nf_afinfo *afinfo; |
| 285 | __sum16 csum = 0; |
| 286 | |
| 287 | rcu_read_lock(); |
| 288 | afinfo = nf_get_afinfo(family); |
| 289 | if (afinfo) |
| 290 | csum = afinfo->checksum_partial(skb, hook, dataoff, len, |
| 291 | protocol); |
| 292 | rcu_read_unlock(); |
| 293 | return csum; |
| 294 | } |
| 295 | |
Patrick McHardy | 1e796fd | 2007-12-17 22:42:27 -0800 | [diff] [blame] | 296 | extern int nf_register_afinfo(const struct nf_afinfo *afinfo); |
| 297 | extern void nf_unregister_afinfo(const struct nf_afinfo *afinfo); |
Patrick McHardy | bce8032 | 2006-04-06 14:18:09 -0700 | [diff] [blame] | 298 | |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 299 | #include <net/flow.h> |
| 300 | extern void (*ip_nat_decode_session)(struct sk_buff *, struct flowi *); |
| 301 | |
| 302 | static inline void |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 303 | nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family) |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 304 | { |
Patrick McHardy | 051578c | 2007-12-17 22:42:51 -0800 | [diff] [blame] | 305 | #ifdef CONFIG_NF_NAT_NEEDED |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 306 | void (*decodefn)(struct sk_buff *, struct flowi *); |
| 307 | |
Patrick McHardy | 051578c | 2007-12-17 22:42:51 -0800 | [diff] [blame] | 308 | if (family == AF_INET) { |
| 309 | rcu_read_lock(); |
| 310 | decodefn = rcu_dereference(ip_nat_decode_session); |
| 311 | if (decodefn) |
| 312 | decodefn(skb, fl); |
| 313 | rcu_read_unlock(); |
| 314 | } |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 315 | #endif |
| 316 | } |
| 317 | |
Harald Welte | 608c8e4 | 2005-08-09 19:58:27 -0700 | [diff] [blame] | 318 | #ifdef CONFIG_PROC_FS |
| 319 | #include <linux/proc_fs.h> |
| 320 | extern struct proc_dir_entry *proc_net_netfilter; |
| 321 | #endif |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | #else /* !CONFIG_NETFILTER */ |
| 324 | #define NF_HOOK(pf, hook, skb, indev, outdev, okfn) (okfn)(skb) |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 325 | #define NF_HOOK_COND(pf, hook, skb, indev, outdev, okfn, cond) (okfn)(skb) |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 326 | static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook, |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 327 | struct sk_buff *skb, |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 328 | struct net_device *indev, |
| 329 | struct net_device *outdev, |
Patrick McHardy | 48d5cad | 2006-02-15 15:10:22 -0800 | [diff] [blame] | 330 | int (*okfn)(struct sk_buff *), int thresh, |
| 331 | int cond) |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 332 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 333 | return okfn(skb); |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 334 | } |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 335 | static inline int nf_hook(u_int8_t pf, unsigned int hook, struct sk_buff *skb, |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 336 | struct net_device *indev, struct net_device *outdev, |
| 337 | int (*okfn)(struct sk_buff *)) |
| 338 | { |
Patrick McHardy | 9c92d34 | 2006-02-15 15:18:19 -0800 | [diff] [blame] | 339 | return 1; |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 340 | } |
David S. Miller | f53b61d | 2006-01-07 12:50:27 -0800 | [diff] [blame] | 341 | struct flowi; |
Patrick McHardy | eb9c7eb | 2006-01-06 23:06:30 -0800 | [diff] [blame] | 342 | static inline void |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 343 | nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family) |
| 344 | { |
| 345 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | #endif /*CONFIG_NETFILTER*/ |
| 347 | |
Yasuyuki Kozakai | 5f79e0f | 2007-03-23 11:17:07 -0700 | [diff] [blame] | 348 | #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) |
| 349 | extern void (*ip_ct_attach)(struct sk_buff *, struct sk_buff *); |
| 350 | extern void nf_ct_attach(struct sk_buff *, struct sk_buff *); |
Yasuyuki Kozakai | de6e05c | 2007-03-23 11:17:27 -0700 | [diff] [blame] | 351 | extern void (*nf_ct_destroy)(struct nf_conntrack *); |
Yasuyuki Kozakai | 5f79e0f | 2007-03-23 11:17:07 -0700 | [diff] [blame] | 352 | #else |
| 353 | static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {} |
| 354 | #endif |
| 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | #endif /*__KERNEL__*/ |
| 357 | #endif /*__LINUX_NETFILTER_H*/ |