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