blob: abc7fdcb9eb1a204c5a93669e7d17d618151f329 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __LINUX_NETFILTER_H
2#define __LINUX_NETFILTER_H
3
Linus Torvalds1da177e2005-04-16 15:20:36 -07004#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/skbuff.h>
6#include <linux/net.h>
7#include <linux/if.h>
Jan Engelhardt2e3075a2008-01-14 23:40:34 -08008#include <linux/in.h>
9#include <linux/in6.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/wait.h>
11#include <linux/list.h>
Zhouyi Zhoud1c85c22014-08-22 10:40:15 +080012#include <linux/static_key.h>
Pablo Neira Ayusoa2636532015-06-17 10:28:27 -050013#include <linux/netfilter_defs.h>
Eric W. Biederman085db2c2015-07-10 18:15:06 -050014#include <linux/netdevice.h>
15#include <net/net_namespace.h>
Pablo Neira Ayusoa2636532015-06-17 10:28:27 -050016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#ifdef CONFIG_NETFILTER
Florian Westphalf615df72011-01-18 15:52:14 +010018static inline int NF_DROP_GETERR(int verdict)
19{
20 return -(verdict >> NF_VERDICT_QBITS);
21}
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Patrick McHardyb8beedd2008-03-25 20:09:33 -070023static inline int nf_inet_addr_cmp(const union nf_inet_addr *a1,
24 const union nf_inet_addr *a2)
25{
26 return a1->all[0] == a2->all[0] &&
27 a1->all[1] == a2->all[1] &&
28 a1->all[2] == a2->all[2] &&
29 a1->all[3] == a2->all[3];
30}
31
Denys Fedoryshchenkoefdedd52012-05-17 23:08:57 +030032static inline void nf_inet_addr_mask(const union nf_inet_addr *a1,
33 union nf_inet_addr *result,
34 const union nf_inet_addr *mask)
35{
36 result->all[0] = a1->all[0] & mask->all[0];
37 result->all[1] = a1->all[1] & mask->all[1];
38 result->all[2] = a1->all[2] & mask->all[2];
39 result->all[3] = a1->all[3] & mask->all[3];
40}
41
Joe Perchesa0f4ecf2013-09-26 14:48:15 -070042int netfilter_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044struct sk_buff;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Patrick McHardy795aa6e2013-10-10 09:21:55 +020046struct nf_hook_ops;
David S. Millercfdfab32015-04-03 16:23:58 -040047
David Miller1c984f82015-04-05 22:19:00 -040048struct sock;
49
David S. Millercfdfab32015-04-03 16:23:58 -040050struct nf_hook_state {
51 unsigned int hook;
52 int thresh;
53 u_int8_t pf;
54 struct net_device *in;
55 struct net_device *out;
David Miller1c984f82015-04-05 22:19:00 -040056 struct sock *sk;
Eric W. Biedermanb11b1f62015-09-15 20:03:50 -050057 struct net *net;
Aaron Conolee3b37f12016-09-21 11:35:07 -040058 struct nf_hook_entry __rcu *hook_entries;
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -050059 int (*okfn)(struct net *, struct sock *, struct sk_buff *);
David S. Millercfdfab32015-04-03 16:23:58 -040060};
61
Aaron Conolee3b37f12016-09-21 11:35:07 -040062typedef unsigned int nf_hookfn(void *priv,
63 struct sk_buff *skb,
64 const struct nf_hook_state *state);
65struct nf_hook_ops {
66 struct list_head list;
67
68 /* User fills in from here down. */
69 nf_hookfn *hook;
70 struct net_device *dev;
71 void *priv;
72 u_int8_t pf;
73 unsigned int hooknum;
74 /* Hooks are ordered in ascending priority. */
75 int priority;
76};
77
78struct nf_hook_entry {
79 struct nf_hook_entry __rcu *next;
80 struct nf_hook_ops ops;
81 const struct nf_hook_ops *orig_ops;
82};
83
David Miller107a9f42015-04-05 22:18:54 -040084static inline void nf_hook_state_init(struct nf_hook_state *p,
Aaron Conolee3b37f12016-09-21 11:35:07 -040085 struct nf_hook_entry *hook_entry,
David Miller107a9f42015-04-05 22:18:54 -040086 unsigned int hook,
87 int thresh, u_int8_t pf,
88 struct net_device *indev,
89 struct net_device *outdev,
David Miller1c984f82015-04-05 22:19:00 -040090 struct sock *sk,
Eric W. Biedermanb11b1f62015-09-15 20:03:50 -050091 struct net *net,
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -050092 int (*okfn)(struct net *, struct sock *, struct sk_buff *))
David Miller107a9f42015-04-05 22:18:54 -040093{
94 p->hook = hook;
95 p->thresh = thresh;
96 p->pf = pf;
97 p->in = indev;
98 p->out = outdev;
David Miller1c984f82015-04-05 22:19:00 -040099 p->sk = sk;
Eric W. Biedermanb11b1f62015-09-15 20:03:50 -0500100 p->net = net;
Aaron Conolee3b37f12016-09-21 11:35:07 -0400101 RCU_INIT_POINTER(p->hook_entries, hook_entry);
David Miller107a9f42015-04-05 22:18:54 -0400102 p->okfn = okfn;
103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800107struct nf_sockopt_ops {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 struct list_head list;
109
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200110 u_int8_t pf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
112 /* Non-inclusive ranges: use 0/0/NULL to never get called. */
113 int set_optmin;
114 int set_optmax;
115 int (*set)(struct sock *sk, int optval, void __user *user, unsigned int len);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100116#ifdef CONFIG_COMPAT
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800117 int (*compat_set)(struct sock *sk, int optval,
118 void __user *user, unsigned int len);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100119#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 int get_optmin;
121 int get_optmax;
122 int (*get)(struct sock *sk, int optval, void __user *user, int *len);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100123#ifdef CONFIG_COMPAT
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800124 int (*compat_get)(struct sock *sk, int optval,
125 void __user *user, int *len);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100126#endif
Neil Horman16fcec32007-09-11 11:28:26 +0200127 /* Use the module struct to lock set/get code in place */
128 struct module *owner;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129};
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131/* Function to register/unregister hook points. */
Eric W. Biederman085db2c2015-07-10 18:15:06 -0500132int nf_register_net_hook(struct net *net, const struct nf_hook_ops *ops);
133void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *ops);
134int nf_register_net_hooks(struct net *net, const struct nf_hook_ops *reg,
135 unsigned int n);
136void nf_unregister_net_hooks(struct net *net, const struct nf_hook_ops *reg,
137 unsigned int n);
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139int nf_register_hook(struct nf_hook_ops *reg);
140void nf_unregister_hook(struct nf_hook_ops *reg);
Patrick McHardy972d1cb2006-04-06 14:09:12 -0700141int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
142void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
Mahesh Bandeware8bffe02016-09-16 12:59:13 -0700143int _nf_register_hooks(struct nf_hook_ops *reg, unsigned int n);
144void _nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146/* Functions to register get/setsockopt ranges (non-inclusive). You
147 need to check permissions yourself! */
148int nf_register_sockopt(struct nf_sockopt_ops *reg);
149void nf_unregister_sockopt(struct nf_sockopt_ops *reg);
150
Zhouyi Zhoud1c85c22014-08-22 10:40:15 +0800151#ifdef HAVE_JUMP_LABEL
Ingo Molnarc5905af2012-02-24 08:31:31 +0100152extern struct static_key nf_hooks_needed[NFPROTO_NUMPROTO][NF_MAX_HOOKS];
Eric Dumazeta2d7ec52011-11-18 17:32:46 +0000153#endif
154
David S. Millercfdfab32015-04-03 16:23:58 -0400155int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state);
Patrick McHardy16a66772006-01-06 23:01:48 -0800156
157/**
158 * nf_hook_thresh - call a netfilter hook
Pablo Neirab8d0aad2015-05-13 18:19:36 +0200159 *
Patrick McHardy16a66772006-01-06 23:01:48 -0800160 * Returns 1 if the hook has allowed the packet to pass. The function
161 * okfn must be invoked by the caller in this case. Any other return
162 * value indicates the packet has been consumed by the hook.
163 */
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200164static inline int nf_hook_thresh(u_int8_t pf, unsigned int hook,
Eric W. Biederman7a773502015-09-15 20:03:51 -0500165 struct net *net,
David Miller7026b1d2015-04-05 22:19:04 -0400166 struct sock *sk,
Herbert Xu3db05fe2007-10-15 00:53:15 -0700167 struct sk_buff *skb,
Patrick McHardy16a66772006-01-06 23:01:48 -0800168 struct net_device *indev,
169 struct net_device *outdev,
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500170 int (*okfn)(struct net *, struct sock *, struct sk_buff *),
David Miller7026b1d2015-04-05 22:19:04 -0400171 int thresh)
Patrick McHardy16a66772006-01-06 23:01:48 -0800172{
Aaron Conolee3b37f12016-09-21 11:35:07 -0400173 struct nf_hook_entry *hook_head;
174 int ret = 1;
Eric W. Biederman70aa9962015-07-10 18:13:20 -0500175
Florian Westphalaf4610c2016-02-25 10:08:38 +0100176#ifdef HAVE_JUMP_LABEL
177 if (__builtin_constant_p(pf) &&
178 __builtin_constant_p(hook) &&
179 !static_key_false(&nf_hooks_needed[pf][hook]))
180 return 1;
181#endif
182
Aaron Conolee3b37f12016-09-21 11:35:07 -0400183 rcu_read_lock();
184 hook_head = rcu_dereference(net->nf.hooks[pf][hook]);
185 if (hook_head) {
David Miller107a9f42015-04-05 22:18:54 -0400186 struct nf_hook_state state;
David S. Millercfdfab32015-04-03 16:23:58 -0400187
Aaron Conolee3b37f12016-09-21 11:35:07 -0400188 nf_hook_state_init(&state, hook_head, hook, thresh,
Eric W. Biedermanb11b1f62015-09-15 20:03:50 -0500189 pf, indev, outdev, sk, net, okfn);
Florian Westphalfe729262016-09-21 11:35:02 -0400190
191 ret = nf_hook_slow(skb, &state);
David S. Millercfdfab32015-04-03 16:23:58 -0400192 }
Aaron Conolee3b37f12016-09-21 11:35:07 -0400193 rcu_read_unlock();
194
195 return ret;
Patrick McHardy16a66772006-01-06 23:01:48 -0800196}
197
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500198static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,
199 struct sock *sk, struct sk_buff *skb,
200 struct net_device *indev, struct net_device *outdev,
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500201 int (*okfn)(struct net *, struct sock *, struct sk_buff *))
Patrick McHardy16a66772006-01-06 23:01:48 -0800202{
Eric W. Biederman7a773502015-09-15 20:03:51 -0500203 return nf_hook_thresh(pf, hook, net, sk, skb, indev, outdev, okfn, INT_MIN);
Patrick McHardy16a66772006-01-06 23:01:48 -0800204}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206/* Activate hook; either okfn or kfree_skb called, unless a hook
207 returns NF_STOLEN (in which case, it's up to the hook to deal with
208 the consequences).
209
210 Returns -ERRNO if packet dropped. Zero means queued, stolen or
211 accepted.
212*/
213
214/* RR:
215 > I don't want nf_hook to return anything because people might forget
216 > about async and trust the return value to mean "packet was ok".
217
218 AK:
219 Just document it clearly, then you can expect some sense from kernel
220 coders :)
221*/
222
Jan Engelhardt22490652009-06-13 04:13:26 +0200223static inline int
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500224NF_HOOK_THRESH(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk,
David Miller7026b1d2015-04-05 22:19:04 -0400225 struct sk_buff *skb, struct net_device *in,
226 struct net_device *out,
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500227 int (*okfn)(struct net *, struct sock *, struct sk_buff *),
228 int thresh)
Jan Engelhardt22490652009-06-13 04:13:26 +0200229{
Eric W. Biederman7a773502015-09-15 20:03:51 -0500230 int ret = nf_hook_thresh(pf, hook, net, sk, skb, in, out, okfn, thresh);
Jan Engelhardt22490652009-06-13 04:13:26 +0200231 if (ret == 1)
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500232 ret = okfn(net, sk, skb);
Jan Engelhardt22490652009-06-13 04:13:26 +0200233 return ret;
234}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Jan Engelhardt22490652009-06-13 04:13:26 +0200236static inline int
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500237NF_HOOK_COND(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk,
David Miller7026b1d2015-04-05 22:19:04 -0400238 struct sk_buff *skb, struct net_device *in, struct net_device *out,
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500239 int (*okfn)(struct net *, struct sock *, struct sk_buff *),
240 bool cond)
Jan Engelhardt22490652009-06-13 04:13:26 +0200241{
Patrick McHardy4bac6b12010-02-19 08:03:28 +0100242 int ret;
243
244 if (!cond ||
Eric W. Biederman7a773502015-09-15 20:03:51 -0500245 ((ret = nf_hook_thresh(pf, hook, net, sk, skb, in, out, okfn, INT_MIN)) == 1))
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500246 ret = okfn(net, sk, skb);
Jan Engelhardt22490652009-06-13 04:13:26 +0200247 return ret;
248}
Patrick McHardy16a66772006-01-06 23:01:48 -0800249
Jan Engelhardt22490652009-06-13 04:13:26 +0200250static inline int
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500251NF_HOOK(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk, struct sk_buff *skb,
Jan Engelhardt22490652009-06-13 04:13:26 +0200252 struct net_device *in, struct net_device *out,
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500253 int (*okfn)(struct net *, struct sock *, struct sk_buff *))
Jan Engelhardt22490652009-06-13 04:13:26 +0200254{
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500255 return NF_HOOK_THRESH(pf, hook, net, sk, skb, in, out, okfn, INT_MIN);
Jan Engelhardt22490652009-06-13 04:13:26 +0200256}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258/* Call setsockopt() */
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200259int nf_setsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt,
David S. Millerb7058842009-09-30 16:12:20 -0700260 unsigned int len);
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200261int nf_getsockopt(struct sock *sk, u_int8_t pf, int optval, char __user *opt,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 int *len);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100263#ifdef CONFIG_COMPAT
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200264int compat_nf_setsockopt(struct sock *sk, u_int8_t pf, int optval,
David S. Millerb7058842009-09-30 16:12:20 -0700265 char __user *opt, unsigned int len);
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200266int compat_nf_getsockopt(struct sock *sk, u_int8_t pf, int optval,
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800267 char __user *opt, int *len);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100268#endif
Dmitry Mishin3fdadf72006-03-20 22:45:21 -0800269
Harald Welte089af262005-08-09 19:37:23 -0700270/* Call this before modifying an existing packet: ensures it is
271 modifiable and linear to the point you care about (writable_len).
272 Returns true or false. */
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700273int skb_make_writable(struct sk_buff *skb, unsigned int writable_len);
Harald Welte089af262005-08-09 19:37:23 -0700274
Patrick McHardy1841a4c2007-12-05 01:22:05 -0800275struct flowi;
Patrick McHardy02f014d2007-12-05 01:26:33 -0800276struct nf_queue_entry;
Patrick McHardyc01cd422007-12-05 01:24:48 -0800277
Patrick McHardybce80322006-04-06 14:18:09 -0700278struct nf_afinfo {
279 unsigned short family;
Al Virob51655b2006-11-14 21:40:42 -0800280 __sum16 (*checksum)(struct sk_buff *skb, unsigned int hook,
Patrick McHardy422c3462006-04-06 14:18:43 -0700281 unsigned int dataoff, u_int8_t protocol);
Patrick McHardyd63a6502008-03-20 15:15:53 +0100282 __sum16 (*checksum_partial)(struct sk_buff *skb,
283 unsigned int hook,
284 unsigned int dataoff,
285 unsigned int len,
286 u_int8_t protocol);
Florian Westphal31ad3dd2011-04-04 16:56:29 +0200287 int (*route)(struct net *net, struct dst_entry **dst,
Florian Westphal0fae2e72011-04-04 17:00:54 +0200288 struct flowi *fl, bool strict);
Patrick McHardybce80322006-04-06 14:18:09 -0700289 void (*saveroute)(const struct sk_buff *skb,
Patrick McHardy02f014d2007-12-05 01:26:33 -0800290 struct nf_queue_entry *entry);
Eric W. Biedermand815d902015-09-25 15:07:28 -0500291 int (*reroute)(struct net *net, struct sk_buff *skb,
Patrick McHardy02f014d2007-12-05 01:26:33 -0800292 const struct nf_queue_entry *entry);
Patrick McHardybce80322006-04-06 14:18:09 -0700293 int route_key_size;
Harald Welte2cc7d572005-08-09 19:42:34 -0700294};
295
Eric Dumazet0e60ebe2010-11-15 18:17:21 +0100296extern const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO];
Patrick McHardy1e796fd2007-12-17 22:42:27 -0800297static inline const struct nf_afinfo *nf_get_afinfo(unsigned short family)
Patrick McHardybce80322006-04-06 14:18:09 -0700298{
299 return rcu_dereference(nf_afinfo[family]);
300}
Harald Welte2cc7d572005-08-09 19:42:34 -0700301
Al Virob51655b2006-11-14 21:40:42 -0800302static inline __sum16
Patrick McHardy422c3462006-04-06 14:18:43 -0700303nf_checksum(struct sk_buff *skb, unsigned int hook, unsigned int dataoff,
304 u_int8_t protocol, unsigned short family)
305{
Patrick McHardy1e796fd2007-12-17 22:42:27 -0800306 const struct nf_afinfo *afinfo;
Al Virob51655b2006-11-14 21:40:42 -0800307 __sum16 csum = 0;
Patrick McHardy422c3462006-04-06 14:18:43 -0700308
309 rcu_read_lock();
310 afinfo = nf_get_afinfo(family);
311 if (afinfo)
312 csum = afinfo->checksum(skb, hook, dataoff, protocol);
313 rcu_read_unlock();
314 return csum;
315}
316
Patrick McHardyd63a6502008-03-20 15:15:53 +0100317static inline __sum16
318nf_checksum_partial(struct sk_buff *skb, unsigned int hook,
319 unsigned int dataoff, unsigned int len,
320 u_int8_t protocol, unsigned short family)
321{
322 const struct nf_afinfo *afinfo;
323 __sum16 csum = 0;
324
325 rcu_read_lock();
326 afinfo = nf_get_afinfo(family);
327 if (afinfo)
328 csum = afinfo->checksum_partial(skb, hook, dataoff, len,
329 protocol);
330 rcu_read_unlock();
331 return csum;
332}
333
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700334int nf_register_afinfo(const struct nf_afinfo *afinfo);
335void nf_unregister_afinfo(const struct nf_afinfo *afinfo);
Patrick McHardybce80322006-04-06 14:18:09 -0700336
Patrick McHardyeb9c7eb2006-01-06 23:06:30 -0800337#include <net/flow.h>
Patrick McHardyc7232c92012-08-26 19:14:06 +0200338extern void (*nf_nat_decode_session_hook)(struct sk_buff *, struct flowi *);
Patrick McHardyeb9c7eb2006-01-06 23:06:30 -0800339
340static inline void
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200341nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
Patrick McHardyeb9c7eb2006-01-06 23:06:30 -0800342{
Patrick McHardy051578c2007-12-17 22:42:51 -0800343#ifdef CONFIG_NF_NAT_NEEDED
Patrick McHardyeb9c7eb2006-01-06 23:06:30 -0800344 void (*decodefn)(struct sk_buff *, struct flowi *);
345
Patrick McHardyc7232c92012-08-26 19:14:06 +0200346 rcu_read_lock();
347 decodefn = rcu_dereference(nf_nat_decode_session_hook);
348 if (decodefn)
349 decodefn(skb, fl);
350 rcu_read_unlock();
Patrick McHardyeb9c7eb2006-01-06 23:06:30 -0800351#endif
352}
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354#else /* !CONFIG_NETFILTER */
Arnd Bergmann008027c2015-10-09 20:45:42 +0200355static inline int
356NF_HOOK_COND(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk,
357 struct sk_buff *skb, struct net_device *in, struct net_device *out,
358 int (*okfn)(struct net *, struct sock *, struct sk_buff *),
359 bool cond)
360{
361 return okfn(net, sk, skb);
362}
363
364static inline int
365NF_HOOK(uint8_t pf, unsigned int hook, struct net *net, struct sock *sk,
366 struct sk_buff *skb, struct net_device *in, struct net_device *out,
367 int (*okfn)(struct net *, struct sock *, struct sk_buff *))
368{
369 return okfn(net, sk, skb);
370}
371
Eric W. Biederman29a26a52015-09-15 20:04:16 -0500372static inline int nf_hook(u_int8_t pf, unsigned int hook, struct net *net,
373 struct sock *sk, struct sk_buff *skb,
374 struct net_device *indev, struct net_device *outdev,
Eric W. Biederman0c4b51f2015-09-15 20:04:18 -0500375 int (*okfn)(struct net *, struct sock *, struct sk_buff *))
David S. Millerf53b61d2006-01-07 12:50:27 -0800376{
Patrick McHardy9c92d342006-02-15 15:18:19 -0800377 return 1;
David S. Millerf53b61d2006-01-07 12:50:27 -0800378}
David S. Millerf53b61d2006-01-07 12:50:27 -0800379struct flowi;
Patrick McHardyeb9c7eb2006-01-06 23:06:30 -0800380static inline void
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200381nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
382{
383}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#endif /*CONFIG_NETFILTER*/
385
Yasuyuki Kozakai5f79e0f2007-03-23 11:17:07 -0700386#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
Daniel Borkmann62da9862015-09-03 01:26:07 +0200387#include <linux/netfilter/nf_conntrack_zones_common.h>
388
Patrick McHardy312a0c162013-07-28 22:54:08 +0200389extern void (*ip_ct_attach)(struct sk_buff *, const struct sk_buff *) __rcu;
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700390void nf_ct_attach(struct sk_buff *, const struct sk_buff *);
Eric Dumazet0e60ebe2010-11-15 18:17:21 +0100391extern void (*nf_ct_destroy)(struct nf_conntrack *) __rcu;
Pablo Neira Ayusob7bd1802015-09-30 22:53:44 +0100392#else
393static inline void nf_ct_attach(struct sk_buff *new, struct sk_buff *skb) {}
394#endif
Pablo Neira Ayuso9cb01762012-06-07 12:13:39 +0200395
396struct nf_conn;
Patrick McHardy41d73ec2013-08-27 08:50:12 +0200397enum ip_conntrack_info;
Pablo Neira Ayuso9cb01762012-06-07 12:13:39 +0200398struct nlattr;
399
Ken-ichirou MATSUZAWAa4b47662015-10-05 11:47:13 +0900400struct nfnl_ct_hook {
Ken-ichirou MATSUZAWA224a0592015-10-05 11:49:56 +0900401 struct nf_conn *(*get_ct)(const struct sk_buff *skb,
Pablo Neira Ayusob7bd1802015-09-30 22:53:44 +0100402 enum ip_conntrack_info *ctinfo);
Pablo Neira Ayuso9cb01762012-06-07 12:13:39 +0200403 size_t (*build_size)(const struct nf_conn *ct);
Pablo Neira Ayusob7bd1802015-09-30 22:53:44 +0100404 int (*build)(struct sk_buff *skb, struct nf_conn *ct,
405 enum ip_conntrack_info ctinfo,
406 u_int16_t ct_attr, u_int16_t ct_info_attr);
Pablo Neira Ayuso9cb01762012-06-07 12:13:39 +0200407 int (*parse)(const struct nlattr *attr, struct nf_conn *ct);
Pablo Neira Ayusobd077932013-08-07 18:13:20 +0200408 int (*attach_expect)(const struct nlattr *attr, struct nf_conn *ct,
409 u32 portid, u32 report);
Patrick McHardy41d73ec2013-08-27 08:50:12 +0200410 void (*seq_adjust)(struct sk_buff *skb, struct nf_conn *ct,
411 enum ip_conntrack_info ctinfo, s32 off);
Pablo Neira Ayusod584a612012-06-20 20:52:31 +0200412};
Ken-ichirou MATSUZAWAa4b47662015-10-05 11:47:13 +0900413extern struct nfnl_ct_hook __rcu *nfnl_ct_hook;
Yasuyuki Kozakai5f79e0f2007-03-23 11:17:07 -0700414
Florian Westphale7c88992015-07-14 17:51:07 +0200415/**
416 * nf_skb_duplicated - TEE target has sent a packet
417 *
418 * When a xtables target sends a packet, the OUTPUT and POSTROUTING
419 * hooks are traversed again, i.e. nft and xtables are invoked recursively.
420 *
421 * This is used by xtables TEE target to prevent the duplicated skb from
422 * being duplicated again.
423 */
424DECLARE_PER_CPU(bool, nf_skb_duplicated);
425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426#endif /*__LINUX_NETFILTER_H*/