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