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