summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2019-09-13 09:22:43 -0400
committerDavid S. Miller <davem@davemloft.net>2019-09-13 09:22:43 -0400
commit022c10d6c73b0a4e67a0294e55b2310626f17f75 (patch)
tree7f735a8eac0ddd1166a8533d66da8036f4a7fb4b
parent172ca8308b0517ca2522a8c885755fd5c20294e7 (diff)
parent0d32e7048d927418300b9f5415ca546e44621ef1 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next
Pablo Neira Ayuso says: ==================== Netfilter updates for net-next The following patchset contains Netfilter updates for net-next: 1) Fix error path of nf_tables_updobj(), from Dan Carpenter. 2) Move large structure away from stack in the nf_tables offload infrastructure, from Arnd Bergmann. 3) Move indirect flow_block logic to nf_tables_offload. 4) Support for synproxy objects, from Fernando Fernandez Mancera. 5) Support for fwd and dup offload. 6) Add __nft_offload_get_chain() helper, this implicitly fixes missing mutex and check for offload flags in the indirect block support, patch from wenxu. 7) Remove rules on device unregistration, from wenxu. This includes two preparation patches to reuse nft_flow_offload_chain() and nft_flow_offload_rule(). Large batch from Jeremy Sowden to make a second pass to the CONFIG_HEADER_TEST support and a bit of housekeeping: 8) Missing include guard in conntrack label header, from Jeremy Sowden. 9) A few coding style errors: trailing whitespace, incorrect indent in Kconfig, and semicolons at the end of function definitions. 10) Remove unused ipt_init() and ip6t_init() declarations. 11) Inline xt_hashlimit, ebt_802_3 and xt_physdev headers. They are only used once. 12) Update include directive in several netfilter files. 13) Remove unused include/net/netfilter/ipv6/nf_conntrack_icmpv6.h. 14) Move nf_ip6_ext_hdr() to include/linux/netfilter_ipv6.h 15) Move several synproxy structure definitions to nf_synproxy.h 16) Move nf_bridge_frag_data structure to include/linux/netfilter_bridge.h 17) Clean up static inline definitions in nf_conntrack_ecache.h. 18) Replace defined(CONFIG...) || defined(CONFIG...MODULE) with IS_ENABLED(CONFIG...). 19) Missing inline function conditional definitions based on Kconfig preferences in synproxy and nf_conntrack_timeout. 20) Update br_nf_pre_routing_ipv6() definition. 21) Move conntrack code in linux/skbuff.h to nf_conntrack headers. 22) Several patches to remove superfluous CONFIG_NETFILTER and CONFIG_NF_CONNTRACK checks in headers, coming from the initial batch support for CONFIG_HEADER_TEST for netfilter. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/netfilter.h4
-rw-r--r--include/linux/netfilter/ipset/ip_set_getport.h2
-rw-r--r--include/linux/netfilter/nf_conntrack_common.h20
-rw-r--r--include/linux/netfilter/x_tables.h8
-rw-r--r--include/linux/netfilter/xt_hashlimit.h11
-rw-r--r--include/linux/netfilter/xt_physdev.h8
-rw-r--r--include/linux/netfilter_arp/arp_tables.h2
-rw-r--r--include/linux/netfilter_bridge.h7
-rw-r--r--include/linux/netfilter_bridge/ebt_802_3.h12
-rw-r--r--include/linux/netfilter_bridge/ebtables.h3
-rw-r--r--include/linux/netfilter_ipv4/ip_tables.h9
-rw-r--r--include/linux/netfilter_ipv6.h28
-rw-r--r--include/linux/netfilter_ipv6/ip6_tables.h20
-rw-r--r--include/linux/skbuff.h32
-rw-r--r--include/net/netfilter/br_netfilter.h4
-rw-r--r--include/net/netfilter/ipv6/nf_conntrack_icmpv6.h21
-rw-r--r--include/net/netfilter/nf_conntrack.h25
-rw-r--r--include/net/netfilter/nf_conntrack_acct.h4
-rw-r--r--include/net/netfilter/nf_conntrack_bridge.h11
-rw-r--r--include/net/netfilter/nf_conntrack_core.h8
-rw-r--r--include/net/netfilter/nf_conntrack_ecache.h84
-rw-r--r--include/net/netfilter/nf_conntrack_expect.h2
-rw-r--r--include/net/netfilter/nf_conntrack_extend.h2
-rw-r--r--include/net/netfilter/nf_conntrack_l4proto.h16
-rw-r--r--include/net/netfilter/nf_conntrack_labels.h11
-rw-r--r--include/net/netfilter/nf_conntrack_synproxy.h41
-rw-r--r--include/net/netfilter/nf_conntrack_timeout.h4
-rw-r--r--include/net/netfilter/nf_conntrack_timestamp.h16
-rw-r--r--include/net/netfilter/nf_conntrack_tuple.h4
-rw-r--r--include/net/netfilter/nf_conntrack_zones.h6
-rw-r--r--include/net/netfilter/nf_dup_netdev.h6
-rw-r--r--include/net/netfilter/nf_flow_table.h6
-rw-r--r--include/net/netfilter/nf_nat.h21
-rw-r--r--include/net/netfilter/nf_nat_masquerade.h1
-rw-r--r--include/net/netfilter/nf_queue.h4
-rw-r--r--include/net/netfilter/nf_synproxy.h44
-rw-r--r--include/net/netfilter/nf_tables.h8
-rw-r--r--include/net/netfilter/nf_tables_offload.h10
-rw-r--r--include/uapi/linux/netfilter/nf_tables.h3
-rw-r--r--net/bridge/netfilter/ebt_802_3.c8
-rw-r--r--net/bridge/netfilter/nf_conntrack_bridge.c15
-rw-r--r--net/ipv4/netfilter/Kconfig8
-rw-r--r--net/ipv4/netfilter/Makefile2
-rw-r--r--net/ipv6/netfilter.c4
-rw-r--r--net/ipv6/netfilter/ip6t_ipv6header.c4
-rw-r--r--net/ipv6/netfilter/nf_log_ipv6.c4
-rw-r--r--net/ipv6/netfilter/nf_socket_ipv6.c1
-rw-r--r--net/netfilter/Kconfig8
-rw-r--r--net/netfilter/Makefile2
-rw-r--r--net/netfilter/nf_conntrack_ecache.c1
-rw-r--r--net/netfilter/nf_conntrack_expect.c2
-rw-r--r--net/netfilter/nf_conntrack_helper.c5
-rw-r--r--net/netfilter/nf_conntrack_proto_icmpv6.c1
-rw-r--r--net/netfilter/nf_conntrack_standalone.c1
-rw-r--r--net/netfilter/nf_conntrack_timeout.c1
-rw-r--r--net/netfilter/nf_dup_netdev.c21
-rw-r--r--net/netfilter/nf_flow_table_core.c1
-rw-r--r--net/netfilter/nf_nat_core.c6
-rw-r--r--net/netfilter/nf_tables_api.c25
-rw-r--r--net/netfilter/nf_tables_offload.c186
-rw-r--r--net/netfilter/nft_dup_netdev.c12
-rw-r--r--net/netfilter/nft_flow_offload.c3
-rw-r--r--net/netfilter/nft_fwd_netdev.c12
-rw-r--r--net/netfilter/nft_synproxy.c143
-rw-r--r--net/netfilter/xt_connlimit.c2
-rw-r--r--net/netfilter/xt_hashlimit.c7
-rw-r--r--net/netfilter/xt_physdev.c5
-rw-r--r--net/sched/act_ct.c2
68 files changed, 603 insertions, 417 deletions
diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index 049aeb40fa35..77ebb61faf48 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -15,7 +15,6 @@
15#include <linux/netdevice.h> 15#include <linux/netdevice.h>
16#include <net/net_namespace.h> 16#include <net/net_namespace.h>
17 17
18#ifdef CONFIG_NETFILTER
19static inline int NF_DROP_GETERR(int verdict) 18static inline int NF_DROP_GETERR(int verdict)
20{ 19{
21 return -(verdict >> NF_VERDICT_QBITS); 20 return -(verdict >> NF_VERDICT_QBITS);
@@ -118,6 +117,7 @@ struct nf_hook_entries {
118 */ 117 */
119}; 118};
120 119
120#ifdef CONFIG_NETFILTER
121static inline struct nf_hook_ops **nf_hook_entries_get_hook_ops(const struct nf_hook_entries *e) 121static inline struct nf_hook_ops **nf_hook_entries_get_hook_ops(const struct nf_hook_entries *e)
122{ 122{
123 unsigned int n = e->num_hook_entries; 123 unsigned int n = e->num_hook_entries;
@@ -422,7 +422,7 @@ nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)
422} 422}
423#endif /*CONFIG_NETFILTER*/ 423#endif /*CONFIG_NETFILTER*/
424 424
425#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 425#if IS_ENABLED(CONFIG_NF_CONNTRACK)
426#include <linux/netfilter/nf_conntrack_zones_common.h> 426#include <linux/netfilter/nf_conntrack_zones_common.h>
427 427
428extern void (*ip_ct_attach)(struct sk_buff *, const struct sk_buff *) __rcu; 428extern void (*ip_ct_attach)(struct sk_buff *, const struct sk_buff *) __rcu;
diff --git a/include/linux/netfilter/ipset/ip_set_getport.h b/include/linux/netfilter/ipset/ip_set_getport.h
index a906df06948b..d74cd112b88a 100644
--- a/include/linux/netfilter/ipset/ip_set_getport.h
+++ b/include/linux/netfilter/ipset/ip_set_getport.h
@@ -9,7 +9,7 @@
9extern bool ip_set_get_ip4_port(const struct sk_buff *skb, bool src, 9extern bool ip_set_get_ip4_port(const struct sk_buff *skb, bool src,
10 __be16 *port, u8 *proto); 10 __be16 *port, u8 *proto);
11 11
12#if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) 12#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
13extern bool ip_set_get_ip6_port(const struct sk_buff *skb, bool src, 13extern bool ip_set_get_ip6_port(const struct sk_buff *skb, bool src,
14 __be16 *port, u8 *proto); 14 __be16 *port, u8 *proto);
15#else 15#else
diff --git a/include/linux/netfilter/nf_conntrack_common.h b/include/linux/netfilter/nf_conntrack_common.h
index e142b2b5f1ea..1db83c931d9c 100644
--- a/include/linux/netfilter/nf_conntrack_common.h
+++ b/include/linux/netfilter/nf_conntrack_common.h
@@ -2,6 +2,7 @@
2#ifndef _NF_CONNTRACK_COMMON_H 2#ifndef _NF_CONNTRACK_COMMON_H
3#define _NF_CONNTRACK_COMMON_H 3#define _NF_CONNTRACK_COMMON_H
4 4
5#include <linux/atomic.h>
5#include <uapi/linux/netfilter/nf_conntrack_common.h> 6#include <uapi/linux/netfilter/nf_conntrack_common.h>
6 7
7struct ip_conntrack_stat { 8struct ip_conntrack_stat {
@@ -19,4 +20,23 @@ struct ip_conntrack_stat {
19 unsigned int search_restart; 20 unsigned int search_restart;
20}; 21};
21 22
23#define NFCT_INFOMASK 7UL
24#define NFCT_PTRMASK ~(NFCT_INFOMASK)
25
26struct nf_conntrack {
27 atomic_t use;
28};
29
30void nf_conntrack_destroy(struct nf_conntrack *nfct);
31static inline void nf_conntrack_put(struct nf_conntrack *nfct)
32{
33 if (nfct && atomic_dec_and_test(&nfct->use))
34 nf_conntrack_destroy(nfct);
35}
36static inline void nf_conntrack_get(struct nf_conntrack *nfct)
37{
38 if (nfct)
39 atomic_inc(&nfct->use);
40}
41
22#endif /* _NF_CONNTRACK_COMMON_H */ 42#endif /* _NF_CONNTRACK_COMMON_H */
diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
index ae62bf1c6824..1b261c51b3a3 100644
--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -35,15 +35,12 @@ struct xt_action_param {
35 union { 35 union {
36 const void *matchinfo, *targinfo; 36 const void *matchinfo, *targinfo;
37 }; 37 };
38#if IS_ENABLED(CONFIG_NETFILTER)
39 const struct nf_hook_state *state; 38 const struct nf_hook_state *state;
40#endif
41 int fragoff; 39 int fragoff;
42 unsigned int thoff; 40 unsigned int thoff;
43 bool hotdrop; 41 bool hotdrop;
44}; 42};
45 43
46#if IS_ENABLED(CONFIG_NETFILTER)
47static inline struct net *xt_net(const struct xt_action_param *par) 44static inline struct net *xt_net(const struct xt_action_param *par)
48{ 45{
49 return par->state->net; 46 return par->state->net;
@@ -78,7 +75,6 @@ static inline u_int8_t xt_family(const struct xt_action_param *par)
78{ 75{
79 return par->state->pf; 76 return par->state->pf;
80} 77}
81#endif
82 78
83/** 79/**
84 * struct xt_mtchk_param - parameters for match extensions' 80 * struct xt_mtchk_param - parameters for match extensions'
@@ -340,7 +336,7 @@ void xt_free_table_info(struct xt_table_info *info);
340 336
341/** 337/**
342 * xt_recseq - recursive seqcount for netfilter use 338 * xt_recseq - recursive seqcount for netfilter use
343 * 339 *
344 * Packet processing changes the seqcount only if no recursion happened 340 * Packet processing changes the seqcount only if no recursion happened
345 * get_counters() can use read_seqcount_begin()/read_seqcount_retry(), 341 * get_counters() can use read_seqcount_begin()/read_seqcount_retry(),
346 * because we use the normal seqcount convention : 342 * because we use the normal seqcount convention :
@@ -450,9 +446,7 @@ xt_get_per_cpu_counter(struct xt_counters *cnt, unsigned int cpu)
450 return cnt; 446 return cnt;
451} 447}
452 448
453#if IS_ENABLED(CONFIG_NETFILTER)
454struct nf_hook_ops *xt_hook_ops_alloc(const struct xt_table *, nf_hookfn *); 449struct nf_hook_ops *xt_hook_ops_alloc(const struct xt_table *, nf_hookfn *);
455#endif
456 450
457#ifdef CONFIG_COMPAT 451#ifdef CONFIG_COMPAT
458#include <net/compat.h> 452#include <net/compat.h>
diff --git a/include/linux/netfilter/xt_hashlimit.h b/include/linux/netfilter/xt_hashlimit.h
deleted file mode 100644
index 169d03983589..000000000000
--- a/include/linux/netfilter/xt_hashlimit.h
+++ /dev/null
@@ -1,11 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _XT_HASHLIMIT_H
3#define _XT_HASHLIMIT_H
4
5#include <uapi/linux/netfilter/xt_hashlimit.h>
6
7#define XT_HASHLIMIT_ALL (XT_HASHLIMIT_HASH_DIP | XT_HASHLIMIT_HASH_DPT | \
8 XT_HASHLIMIT_HASH_SIP | XT_HASHLIMIT_HASH_SPT | \
9 XT_HASHLIMIT_INVERT | XT_HASHLIMIT_BYTES |\
10 XT_HASHLIMIT_RATE_MATCH)
11#endif /*_XT_HASHLIMIT_H*/
diff --git a/include/linux/netfilter/xt_physdev.h b/include/linux/netfilter/xt_physdev.h
deleted file mode 100644
index 4ca0593949cd..000000000000
--- a/include/linux/netfilter/xt_physdev.h
+++ /dev/null
@@ -1,8 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _XT_PHYSDEV_H
3#define _XT_PHYSDEV_H
4
5#include <linux/if.h>
6#include <uapi/linux/netfilter/xt_physdev.h>
7
8#endif /*_XT_PHYSDEV_H*/
diff --git a/include/linux/netfilter_arp/arp_tables.h b/include/linux/netfilter_arp/arp_tables.h
index 1b7b35bb9c27..e98028f00e47 100644
--- a/include/linux/netfilter_arp/arp_tables.h
+++ b/include/linux/netfilter_arp/arp_tables.h
@@ -49,7 +49,6 @@ struct arpt_error {
49} 49}
50 50
51extern void *arpt_alloc_initial_table(const struct xt_table *); 51extern void *arpt_alloc_initial_table(const struct xt_table *);
52#if IS_ENABLED(CONFIG_NETFILTER)
53int arpt_register_table(struct net *net, const struct xt_table *table, 52int arpt_register_table(struct net *net, const struct xt_table *table,
54 const struct arpt_replace *repl, 53 const struct arpt_replace *repl,
55 const struct nf_hook_ops *ops, struct xt_table **res); 54 const struct nf_hook_ops *ops, struct xt_table **res);
@@ -58,7 +57,6 @@ void arpt_unregister_table(struct net *net, struct xt_table *table,
58extern unsigned int arpt_do_table(struct sk_buff *skb, 57extern unsigned int arpt_do_table(struct sk_buff *skb,
59 const struct nf_hook_state *state, 58 const struct nf_hook_state *state,
60 struct xt_table *table); 59 struct xt_table *table);
61#endif
62 60
63#ifdef CONFIG_COMPAT 61#ifdef CONFIG_COMPAT
64#include <net/compat.h> 62#include <net/compat.h>
diff --git a/include/linux/netfilter_bridge.h b/include/linux/netfilter_bridge.h
index 5f2614d02e03..f980edfdd278 100644
--- a/include/linux/netfilter_bridge.h
+++ b/include/linux/netfilter_bridge.h
@@ -5,6 +5,13 @@
5#include <uapi/linux/netfilter_bridge.h> 5#include <uapi/linux/netfilter_bridge.h>
6#include <linux/skbuff.h> 6#include <linux/skbuff.h>
7 7
8struct nf_bridge_frag_data {
9 char mac[ETH_HLEN];
10 bool vlan_present;
11 u16 vlan_tci;
12 __be16 vlan_proto;
13};
14
8#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 15#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
9 16
10int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb); 17int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
diff --git a/include/linux/netfilter_bridge/ebt_802_3.h b/include/linux/netfilter_bridge/ebt_802_3.h
deleted file mode 100644
index c6147f9c0d80..000000000000
--- a/include/linux/netfilter_bridge/ebt_802_3.h
+++ /dev/null
@@ -1,12 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef __LINUX_BRIDGE_EBT_802_3_H
3#define __LINUX_BRIDGE_EBT_802_3_H
4
5#include <linux/skbuff.h>
6#include <uapi/linux/netfilter_bridge/ebt_802_3.h>
7
8static inline struct ebt_802_3_hdr *ebt_802_3_hdr(const struct sk_buff *skb)
9{
10 return (struct ebt_802_3_hdr *)skb_mac_header(skb);
11}
12#endif
diff --git a/include/linux/netfilter_bridge/ebtables.h b/include/linux/netfilter_bridge/ebtables.h
index b5b2d371f0ef..162f59d0d17a 100644
--- a/include/linux/netfilter_bridge/ebtables.h
+++ b/include/linux/netfilter_bridge/ebtables.h
@@ -105,7 +105,7 @@ struct ebt_table {
105 105
106#define EBT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) & \ 106#define EBT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) & \
107 ~(__alignof__(struct _xt_align)-1)) 107 ~(__alignof__(struct _xt_align)-1))
108#if IS_ENABLED(CONFIG_NETFILTER) 108
109extern int ebt_register_table(struct net *net, 109extern int ebt_register_table(struct net *net,
110 const struct ebt_table *table, 110 const struct ebt_table *table,
111 const struct nf_hook_ops *ops, 111 const struct nf_hook_ops *ops,
@@ -115,7 +115,6 @@ extern void ebt_unregister_table(struct net *net, struct ebt_table *table,
115extern unsigned int ebt_do_table(struct sk_buff *skb, 115extern unsigned int ebt_do_table(struct sk_buff *skb,
116 const struct nf_hook_state *state, 116 const struct nf_hook_state *state,
117 struct ebt_table *table); 117 struct ebt_table *table);
118#endif
119 118
120/* True if the hook mask denotes that the rule is in a base chain, 119/* True if the hook mask denotes that the rule is in a base chain,
121 * used in the check() functions */ 120 * used in the check() functions */
diff --git a/include/linux/netfilter_ipv4/ip_tables.h b/include/linux/netfilter_ipv4/ip_tables.h
index f40a65481df4..e9e1ed74cdf1 100644
--- a/include/linux/netfilter_ipv4/ip_tables.h
+++ b/include/linux/netfilter_ipv4/ip_tables.h
@@ -17,21 +17,16 @@
17 17
18#include <linux/if.h> 18#include <linux/if.h>
19#include <linux/in.h> 19#include <linux/in.h>
20#include <linux/init.h>
20#include <linux/ip.h> 21#include <linux/ip.h>
21#include <linux/skbuff.h> 22#include <linux/skbuff.h>
22
23#include <linux/init.h>
24#include <uapi/linux/netfilter_ipv4/ip_tables.h> 23#include <uapi/linux/netfilter_ipv4/ip_tables.h>
25 24
26extern void ipt_init(void) __init;
27
28#if IS_ENABLED(CONFIG_NETFILTER)
29int ipt_register_table(struct net *net, const struct xt_table *table, 25int ipt_register_table(struct net *net, const struct xt_table *table,
30 const struct ipt_replace *repl, 26 const struct ipt_replace *repl,
31 const struct nf_hook_ops *ops, struct xt_table **res); 27 const struct nf_hook_ops *ops, struct xt_table **res);
32void ipt_unregister_table(struct net *net, struct xt_table *table, 28void ipt_unregister_table(struct net *net, struct xt_table *table,
33 const struct nf_hook_ops *ops); 29 const struct nf_hook_ops *ops);
34#endif
35 30
36/* Standard entry. */ 31/* Standard entry. */
37struct ipt_standard { 32struct ipt_standard {
@@ -67,11 +62,9 @@ struct ipt_error {
67} 62}
68 63
69extern void *ipt_alloc_initial_table(const struct xt_table *); 64extern void *ipt_alloc_initial_table(const struct xt_table *);
70#if IS_ENABLED(CONFIG_NETFILTER)
71extern unsigned int ipt_do_table(struct sk_buff *skb, 65extern unsigned int ipt_do_table(struct sk_buff *skb,
72 const struct nf_hook_state *state, 66 const struct nf_hook_state *state,
73 struct xt_table *table); 67 struct xt_table *table);
74#endif
75 68
76#ifdef CONFIG_COMPAT 69#ifdef CONFIG_COMPAT
77#include <net/compat.h> 70#include <net/compat.h>
diff --git a/include/linux/netfilter_ipv6.h b/include/linux/netfilter_ipv6.h
index 7beb681e1ce5..aac42c28fe62 100644
--- a/include/linux/netfilter_ipv6.h
+++ b/include/linux/netfilter_ipv6.h
@@ -1,7 +1,7 @@
1/* IPv6-specific defines for netfilter. 1/* IPv6-specific defines for netfilter.
2 * (C)1998 Rusty Russell -- This code is GPL. 2 * (C)1998 Rusty Russell -- This code is GPL.
3 * (C)1999 David Jeffery 3 * (C)1999 David Jeffery
4 * this header was blatantly ripped from netfilter_ipv4.h 4 * this header was blatantly ripped from netfilter_ipv4.h
5 * it's amazing what adding a bunch of 6s can do =8^) 5 * it's amazing what adding a bunch of 6s can do =8^)
6 */ 6 */
7#ifndef __LINUX_IP6_NETFILTER_H 7#ifndef __LINUX_IP6_NETFILTER_H
@@ -10,6 +10,18 @@
10#include <uapi/linux/netfilter_ipv6.h> 10#include <uapi/linux/netfilter_ipv6.h>
11#include <net/tcp.h> 11#include <net/tcp.h>
12 12
13/* Check for an extension */
14static inline int
15nf_ip6_ext_hdr(u8 nexthdr)
16{ return (nexthdr == IPPROTO_HOPOPTS) ||
17 (nexthdr == IPPROTO_ROUTING) ||
18 (nexthdr == IPPROTO_FRAGMENT) ||
19 (nexthdr == IPPROTO_ESP) ||
20 (nexthdr == IPPROTO_AH) ||
21 (nexthdr == IPPROTO_NONE) ||
22 (nexthdr == IPPROTO_DSTOPTS);
23}
24
13/* Extra routing may needed on local out, as the QUEUE target never returns 25/* Extra routing may needed on local out, as the QUEUE target never returns
14 * control to the table. 26 * control to the table.
15 */ 27 */
@@ -20,7 +32,7 @@ struct ip6_rt_info {
20}; 32};
21 33
22struct nf_queue_entry; 34struct nf_queue_entry;
23struct nf_ct_bridge_frag_data; 35struct nf_bridge_frag_data;
24 36
25/* 37/*
26 * Hook functions for ipv6 to allow xt_* modules to be built-in even 38 * Hook functions for ipv6 to allow xt_* modules to be built-in even
@@ -49,9 +61,9 @@ struct nf_ipv6_ops {
49 int (*br_defrag)(struct net *net, struct sk_buff *skb, u32 user); 61 int (*br_defrag)(struct net *net, struct sk_buff *skb, u32 user);
50 int (*br_fragment)(struct net *net, struct sock *sk, 62 int (*br_fragment)(struct net *net, struct sock *sk,
51 struct sk_buff *skb, 63 struct sk_buff *skb,
52 struct nf_ct_bridge_frag_data *data, 64 struct nf_bridge_frag_data *data,
53 int (*output)(struct net *, struct sock *sk, 65 int (*output)(struct net *, struct sock *sk,
54 const struct nf_ct_bridge_frag_data *data, 66 const struct nf_bridge_frag_data *data,
55 struct sk_buff *)); 67 struct sk_buff *));
56#endif 68#endif
57}; 69};
@@ -123,16 +135,16 @@ static inline int nf_ipv6_br_defrag(struct net *net, struct sk_buff *skb,
123} 135}
124 136
125int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, 137int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
126 struct nf_ct_bridge_frag_data *data, 138 struct nf_bridge_frag_data *data,
127 int (*output)(struct net *, struct sock *sk, 139 int (*output)(struct net *, struct sock *sk,
128 const struct nf_ct_bridge_frag_data *data, 140 const struct nf_bridge_frag_data *data,
129 struct sk_buff *)); 141 struct sk_buff *));
130 142
131static inline int nf_br_ip6_fragment(struct net *net, struct sock *sk, 143static inline int nf_br_ip6_fragment(struct net *net, struct sock *sk,
132 struct sk_buff *skb, 144 struct sk_buff *skb,
133 struct nf_ct_bridge_frag_data *data, 145 struct nf_bridge_frag_data *data,
134 int (*output)(struct net *, struct sock *sk, 146 int (*output)(struct net *, struct sock *sk,
135 const struct nf_ct_bridge_frag_data *data, 147 const struct nf_bridge_frag_data *data,
136 struct sk_buff *)) 148 struct sk_buff *))
137{ 149{
138#if IS_MODULE(CONFIG_IPV6) 150#if IS_MODULE(CONFIG_IPV6)
diff --git a/include/linux/netfilter_ipv6/ip6_tables.h b/include/linux/netfilter_ipv6/ip6_tables.h
index 53b7309613bf..78ab959c4575 100644
--- a/include/linux/netfilter_ipv6/ip6_tables.h
+++ b/include/linux/netfilter_ipv6/ip6_tables.h
@@ -17,16 +17,13 @@
17 17
18#include <linux/if.h> 18#include <linux/if.h>
19#include <linux/in6.h> 19#include <linux/in6.h>
20#include <linux/init.h>
20#include <linux/ipv6.h> 21#include <linux/ipv6.h>
21#include <linux/skbuff.h> 22#include <linux/skbuff.h>
22
23#include <linux/init.h>
24#include <uapi/linux/netfilter_ipv6/ip6_tables.h> 23#include <uapi/linux/netfilter_ipv6/ip6_tables.h>
25 24
26extern void ip6t_init(void) __init;
27
28extern void *ip6t_alloc_initial_table(const struct xt_table *); 25extern void *ip6t_alloc_initial_table(const struct xt_table *);
29#if IS_ENABLED(CONFIG_NETFILTER) 26
30int ip6t_register_table(struct net *net, const struct xt_table *table, 27int ip6t_register_table(struct net *net, const struct xt_table *table,
31 const struct ip6t_replace *repl, 28 const struct ip6t_replace *repl,
32 const struct nf_hook_ops *ops, struct xt_table **res); 29 const struct nf_hook_ops *ops, struct xt_table **res);
@@ -35,19 +32,6 @@ void ip6t_unregister_table(struct net *net, struct xt_table *table,
35extern unsigned int ip6t_do_table(struct sk_buff *skb, 32extern unsigned int ip6t_do_table(struct sk_buff *skb,
36 const struct nf_hook_state *state, 33 const struct nf_hook_state *state,
37 struct xt_table *table); 34 struct xt_table *table);
38#endif
39
40/* Check for an extension */
41static inline int
42ip6t_ext_hdr(u8 nexthdr)
43{ return (nexthdr == IPPROTO_HOPOPTS) ||
44 (nexthdr == IPPROTO_ROUTING) ||
45 (nexthdr == IPPROTO_FRAGMENT) ||
46 (nexthdr == IPPROTO_ESP) ||
47 (nexthdr == IPPROTO_AH) ||
48 (nexthdr == IPPROTO_NONE) ||
49 (nexthdr == IPPROTO_DSTOPTS);
50}
51 35
52#ifdef CONFIG_COMPAT 36#ifdef CONFIG_COMPAT
53#include <net/compat.h> 37#include <net/compat.h>
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 028e684fa974..907209c0794e 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -37,6 +37,9 @@
37#include <linux/in6.h> 37#include <linux/in6.h>
38#include <linux/if_packet.h> 38#include <linux/if_packet.h>
39#include <net/flow.h> 39#include <net/flow.h>
40#if IS_ENABLED(CONFIG_NF_CONNTRACK)
41#include <linux/netfilter/nf_conntrack_common.h>
42#endif
40 43
41/* The interface for checksum offload between the stack and networking drivers 44/* The interface for checksum offload between the stack and networking drivers
42 * is as follows... 45 * is as follows...
@@ -244,12 +247,6 @@ struct bpf_prog;
244union bpf_attr; 247union bpf_attr;
245struct skb_ext; 248struct skb_ext;
246 249
247#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
248struct nf_conntrack {
249 atomic_t use;
250};
251#endif
252
253#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) 250#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
254struct nf_bridge_info { 251struct nf_bridge_info {
255 enum { 252 enum {
@@ -914,7 +911,6 @@ static inline bool skb_pfmemalloc(const struct sk_buff *skb)
914#define SKB_DST_NOREF 1UL 911#define SKB_DST_NOREF 1UL
915#define SKB_DST_PTRMASK ~(SKB_DST_NOREF) 912#define SKB_DST_PTRMASK ~(SKB_DST_NOREF)
916 913
917#define SKB_NFCT_PTRMASK ~(7UL)
918/** 914/**
919 * skb_dst - returns skb dst_entry 915 * skb_dst - returns skb dst_entry
920 * @skb: buffer 916 * @skb: buffer
@@ -4040,25 +4036,27 @@ static inline void skb_remcsum_process(struct sk_buff *skb, void *ptr,
4040static inline struct nf_conntrack *skb_nfct(const struct sk_buff *skb) 4036static inline struct nf_conntrack *skb_nfct(const struct sk_buff *skb)
4041{ 4037{
4042#if IS_ENABLED(CONFIG_NF_CONNTRACK) 4038#if IS_ENABLED(CONFIG_NF_CONNTRACK)
4043 return (void *)(skb->_nfct & SKB_NFCT_PTRMASK); 4039 return (void *)(skb->_nfct & NFCT_PTRMASK);
4044#else 4040#else
4045 return NULL; 4041 return NULL;
4046#endif 4042#endif
4047} 4043}
4048 4044
4049#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE) 4045static inline unsigned long skb_get_nfct(const struct sk_buff *skb)
4050void nf_conntrack_destroy(struct nf_conntrack *nfct);
4051static inline void nf_conntrack_put(struct nf_conntrack *nfct)
4052{ 4046{
4053 if (nfct && atomic_dec_and_test(&nfct->use)) 4047#if IS_ENABLED(CONFIG_NF_CONNTRACK)
4054 nf_conntrack_destroy(nfct); 4048 return skb->_nfct;
4049#else
4050 return 0UL;
4051#endif
4055} 4052}
4056static inline void nf_conntrack_get(struct nf_conntrack *nfct) 4053
4054static inline void skb_set_nfct(struct sk_buff *skb, unsigned long nfct)
4057{ 4055{
4058 if (nfct) 4056#if IS_ENABLED(CONFIG_NF_CONNTRACK)
4059 atomic_inc(&nfct->use); 4057 skb->_nfct = nfct;
4060}
4061#endif 4058#endif
4059}
4062 4060
4063#ifdef CONFIG_SKB_EXTENSIONS 4061#ifdef CONFIG_SKB_EXTENSIONS
4064enum skb_ext_id { 4062enum skb_ext_id {
diff --git a/include/net/netfilter/br_netfilter.h b/include/net/netfilter/br_netfilter.h
index 2a613c84d49f..371696ec11b2 100644
--- a/include/net/netfilter/br_netfilter.h
+++ b/include/net/netfilter/br_netfilter.h
@@ -55,7 +55,6 @@ static inline struct rtable *bridge_parent_rtable(const struct net_device *dev)
55struct net_device *setup_pre_routing(struct sk_buff *skb, 55struct net_device *setup_pre_routing(struct sk_buff *skb,
56 const struct net *net); 56 const struct net *net);
57 57
58#if IS_ENABLED(CONFIG_NETFILTER)
59#if IS_ENABLED(CONFIG_IPV6) 58#if IS_ENABLED(CONFIG_IPV6)
60int br_validate_ipv6(struct net *net, struct sk_buff *skb); 59int br_validate_ipv6(struct net *net, struct sk_buff *skb);
61unsigned int br_nf_pre_routing_ipv6(void *priv, 60unsigned int br_nf_pre_routing_ipv6(void *priv,
@@ -68,12 +67,11 @@ static inline int br_validate_ipv6(struct net *net, struct sk_buff *skb)
68} 67}
69 68
70static inline unsigned int 69static inline unsigned int
71br_nf_pre_routing_ipv6(const struct nf_hook_ops *ops, struct sk_buff *skb, 70br_nf_pre_routing_ipv6(void *priv, struct sk_buff *skb,
72 const struct nf_hook_state *state) 71 const struct nf_hook_state *state)
73{ 72{
74 return NF_ACCEPT; 73 return NF_ACCEPT;
75} 74}
76#endif 75#endif
77#endif
78 76
79#endif /* _BR_NETFILTER_H_ */ 77#endif /* _BR_NETFILTER_H_ */
diff --git a/include/net/netfilter/ipv6/nf_conntrack_icmpv6.h b/include/net/netfilter/ipv6/nf_conntrack_icmpv6.h
deleted file mode 100644
index c86895bc5eb6..000000000000
--- a/include/net/netfilter/ipv6/nf_conntrack_icmpv6.h
+++ /dev/null
@@ -1,21 +0,0 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * ICMPv6 tracking.
4 *
5 * 21 Apl 2004: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
6 * - separated from nf_conntrack_icmp.h
7 *
8 * Derived from include/linux/netfiter_ipv4/ip_conntrack_icmp.h
9 */
10
11#ifndef _NF_CONNTRACK_ICMPV6_H
12#define _NF_CONNTRACK_ICMPV6_H
13
14#ifndef ICMPV6_NI_QUERY
15#define ICMPV6_NI_QUERY 139
16#endif
17#ifndef ICMPV6_NI_REPLY
18#define ICMPV6_NI_REPLY 140
19#endif
20
21#endif /* _NF_CONNTRACK_ICMPV6_H */
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 2cc304efe7f9..9f551f3b69c6 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -13,17 +13,14 @@
13#ifndef _NF_CONNTRACK_H 13#ifndef _NF_CONNTRACK_H
14#define _NF_CONNTRACK_H 14#define _NF_CONNTRACK_H
15 15
16#include <linux/netfilter/nf_conntrack_common.h>
17
18#include <linux/bitops.h> 16#include <linux/bitops.h>
19#include <linux/compiler.h> 17#include <linux/compiler.h>
20#include <linux/atomic.h>
21 18
19#include <linux/netfilter/nf_conntrack_common.h>
22#include <linux/netfilter/nf_conntrack_tcp.h> 20#include <linux/netfilter/nf_conntrack_tcp.h>
23#include <linux/netfilter/nf_conntrack_dccp.h> 21#include <linux/netfilter/nf_conntrack_dccp.h>
24#include <linux/netfilter/nf_conntrack_sctp.h> 22#include <linux/netfilter/nf_conntrack_sctp.h>
25#include <linux/netfilter/nf_conntrack_proto_gre.h> 23#include <linux/netfilter/nf_conntrack_proto_gre.h>
26#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
27 24
28#include <net/netfilter/nf_conntrack_tuple.h> 25#include <net/netfilter/nf_conntrack_tuple.h>
29 26
@@ -59,7 +56,6 @@ struct nf_conntrack_net {
59#include <net/netfilter/ipv6/nf_conntrack_ipv6.h> 56#include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
60 57
61struct nf_conn { 58struct nf_conn {
62#if IS_ENABLED(CONFIG_NF_CONNTRACK)
63 /* Usage count in here is 1 for hash table, 1 per skb, 59 /* Usage count in here is 1 for hash table, 1 per skb,
64 * plus 1 for any connection(s) we are `master' for 60 * plus 1 for any connection(s) we are `master' for
65 * 61 *
@@ -69,7 +65,6 @@ struct nf_conn {
69 * beware nf_ct_get() is different and don't inc refcnt. 65 * beware nf_ct_get() is different and don't inc refcnt.
70 */ 66 */
71 struct nf_conntrack ct_general; 67 struct nf_conntrack ct_general;
72#endif
73 68
74 spinlock_t lock; 69 spinlock_t lock;
75 /* jiffies32 when this ct is considered dead */ 70 /* jiffies32 when this ct is considered dead */
@@ -150,18 +145,14 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
150int nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple, 145int nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
151 const struct nf_conn *ignored_conntrack); 146 const struct nf_conn *ignored_conntrack);
152 147
153#if IS_ENABLED(CONFIG_NF_CONNTRACK)
154
155#define NFCT_INFOMASK 7UL
156#define NFCT_PTRMASK ~(NFCT_INFOMASK)
157
158/* Return conntrack_info and tuple hash for given skb. */ 148/* Return conntrack_info and tuple hash for given skb. */
159static inline struct nf_conn * 149static inline struct nf_conn *
160nf_ct_get(const struct sk_buff *skb, enum ip_conntrack_info *ctinfo) 150nf_ct_get(const struct sk_buff *skb, enum ip_conntrack_info *ctinfo)
161{ 151{
162 *ctinfo = skb->_nfct & NFCT_INFOMASK; 152 unsigned long nfct = skb_get_nfct(skb);
163 153
164 return (struct nf_conn *)(skb->_nfct & NFCT_PTRMASK); 154 *ctinfo = nfct & NFCT_INFOMASK;
155 return (struct nf_conn *)(nfct & NFCT_PTRMASK);
165} 156}
166 157
167/* decrement reference count on a conntrack */ 158/* decrement reference count on a conntrack */
@@ -171,8 +162,6 @@ static inline void nf_ct_put(struct nf_conn *ct)
171 nf_conntrack_put(&ct->ct_general); 162 nf_conntrack_put(&ct->ct_general);
172} 163}
173 164
174#endif
175
176/* Protocol module loading */ 165/* Protocol module loading */
177int nf_ct_l3proto_try_module_get(unsigned short l3proto); 166int nf_ct_l3proto_try_module_get(unsigned short l3proto);
178void nf_ct_l3proto_module_put(unsigned short l3proto); 167void nf_ct_l3proto_module_put(unsigned short l3proto);
@@ -324,16 +313,12 @@ void nf_ct_tmpl_free(struct nf_conn *tmpl);
324 313
325u32 nf_ct_get_id(const struct nf_conn *ct); 314u32 nf_ct_get_id(const struct nf_conn *ct);
326 315
327#if IS_ENABLED(CONFIG_NF_CONNTRACK)
328
329static inline void 316static inline void
330nf_ct_set(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info info) 317nf_ct_set(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info info)
331{ 318{
332 skb->_nfct = (unsigned long)ct | info; 319 skb_set_nfct(skb, (unsigned long)ct | info);
333} 320}
334 321
335#endif
336
337#define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count) 322#define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count)
338#define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count) 323#define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count)
339#define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v)) 324#define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v))
diff --git a/include/net/netfilter/nf_conntrack_acct.h b/include/net/netfilter/nf_conntrack_acct.h
index ad9f2172dee1..f7a060c6eb28 100644
--- a/include/net/netfilter/nf_conntrack_acct.h
+++ b/include/net/netfilter/nf_conntrack_acct.h
@@ -45,7 +45,7 @@ struct nf_conn_acct *nf_ct_acct_ext_add(struct nf_conn *ct, gfp_t gfp)
45#else 45#else
46 return NULL; 46 return NULL;
47#endif 47#endif
48}; 48}
49 49
50/* Check if connection tracking accounting is enabled */ 50/* Check if connection tracking accounting is enabled */
51static inline bool nf_ct_acct_enabled(struct net *net) 51static inline bool nf_ct_acct_enabled(struct net *net)
@@ -65,11 +65,9 @@ static inline void nf_ct_set_acct(struct net *net, bool enable)
65#endif 65#endif
66} 66}
67 67
68#if IS_ENABLED(CONFIG_NF_CONNTRACK)
69void nf_conntrack_acct_pernet_init(struct net *net); 68void nf_conntrack_acct_pernet_init(struct net *net);
70 69
71int nf_conntrack_acct_init(void); 70int nf_conntrack_acct_init(void);
72void nf_conntrack_acct_fini(void); 71void nf_conntrack_acct_fini(void);
73#endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */
74 72
75#endif /* _NF_CONNTRACK_ACCT_H */ 73#endif /* _NF_CONNTRACK_ACCT_H */
diff --git a/include/net/netfilter/nf_conntrack_bridge.h b/include/net/netfilter/nf_conntrack_bridge.h
index 34c28f248b18..c564281ede5e 100644
--- a/include/net/netfilter/nf_conntrack_bridge.h
+++ b/include/net/netfilter/nf_conntrack_bridge.h
@@ -5,10 +5,10 @@
5#include <linux/types.h> 5#include <linux/types.h>
6#include <uapi/linux/if_ether.h> 6#include <uapi/linux/if_ether.h>
7 7
8struct nf_hook_ops;
9
8struct nf_ct_bridge_info { 10struct nf_ct_bridge_info {
9#if IS_ENABLED(CONFIG_NETFILTER)
10 struct nf_hook_ops *ops; 11 struct nf_hook_ops *ops;
11#endif
12 unsigned int ops_size; 12 unsigned int ops_size;
13 struct module *me; 13 struct module *me;
14}; 14};
@@ -16,11 +16,4 @@ struct nf_ct_bridge_info {
16void nf_ct_bridge_register(struct nf_ct_bridge_info *info); 16void nf_ct_bridge_register(struct nf_ct_bridge_info *info);
17void nf_ct_bridge_unregister(struct nf_ct_bridge_info *info); 17void nf_ct_bridge_unregister(struct nf_ct_bridge_info *info);
18 18
19struct nf_ct_bridge_frag_data {
20 char mac[ETH_HLEN];
21 bool vlan_present;
22 u16 vlan_tci;
23 __be16 vlan_proto;
24};
25
26#endif 19#endif
diff --git a/include/net/netfilter/nf_conntrack_core.h b/include/net/netfilter/nf_conntrack_core.h
index 71a2d9cb64ea..09f2efea0b97 100644
--- a/include/net/netfilter/nf_conntrack_core.h
+++ b/include/net/netfilter/nf_conntrack_core.h
@@ -14,16 +14,16 @@
14#define _NF_CONNTRACK_CORE_H 14#define _NF_CONNTRACK_CORE_H
15 15
16#include <linux/netfilter.h> 16#include <linux/netfilter.h>
17#include <net/netfilter/nf_conntrack_l4proto.h> 17#include <net/netfilter/nf_conntrack.h>
18#include <net/netfilter/nf_conntrack_ecache.h> 18#include <net/netfilter/nf_conntrack_ecache.h>
19#include <net/netfilter/nf_conntrack_l4proto.h>
19 20
20/* This header is used to share core functionality between the 21/* This header is used to share core functionality between the
21 standalone connection tracking module, and the compatibility layer's use 22 standalone connection tracking module, and the compatibility layer's use
22 of connection tracking. */ 23 of connection tracking. */
23 24
24#if IS_ENABLED(CONFIG_NETFILTER) 25unsigned int nf_conntrack_in(struct sk_buff *skb,
25unsigned int nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state); 26 const struct nf_hook_state *state);
26#endif
27 27
28int nf_conntrack_init_net(struct net *net); 28int nf_conntrack_init_net(struct net *net);
29void nf_conntrack_cleanup_net(struct net *net); 29void nf_conntrack_cleanup_net(struct net *net);
diff --git a/include/net/netfilter/nf_conntrack_ecache.h b/include/net/netfilter/nf_conntrack_ecache.h
index 52b44192b43f..eb81f9195e28 100644
--- a/include/net/netfilter/nf_conntrack_ecache.h
+++ b/include/net/netfilter/nf_conntrack_ecache.h
@@ -61,9 +61,10 @@ nf_ct_ecache_ext_add(struct nf_conn *ct, u16 ctmask, u16 expmask, gfp_t gfp)
61#else 61#else
62 return NULL; 62 return NULL;
63#endif 63#endif
64}; 64}
65 65
66#ifdef CONFIG_NF_CONNTRACK_EVENTS 66#ifdef CONFIG_NF_CONNTRACK_EVENTS
67
67/* This structure is passed to event handler */ 68/* This structure is passed to event handler */
68struct nf_ct_event { 69struct nf_ct_event {
69 struct nf_conn *ct; 70 struct nf_conn *ct;
@@ -84,9 +85,26 @@ void nf_ct_deliver_cached_events(struct nf_conn *ct);
84int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct, 85int nf_conntrack_eventmask_report(unsigned int eventmask, struct nf_conn *ct,
85 u32 portid, int report); 86 u32 portid, int report);
86 87
88#else
89
90static inline void nf_ct_deliver_cached_events(const struct nf_conn *ct)
91{
92}
93
94static inline int nf_conntrack_eventmask_report(unsigned int eventmask,
95 struct nf_conn *ct,
96 u32 portid,
97 int report)
98{
99 return 0;
100}
101
102#endif
103
87static inline void 104static inline void
88nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct) 105nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
89{ 106{
107#ifdef CONFIG_NF_CONNTRACK_EVENTS
90 struct net *net = nf_ct_net(ct); 108 struct net *net = nf_ct_net(ct);
91 struct nf_conntrack_ecache *e; 109 struct nf_conntrack_ecache *e;
92 110
@@ -98,31 +116,42 @@ nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
98 return; 116 return;
99 117
100 set_bit(event, &e->cache); 118 set_bit(event, &e->cache);
119#endif
101} 120}
102 121
103static inline int 122static inline int
104nf_conntrack_event_report(enum ip_conntrack_events event, struct nf_conn *ct, 123nf_conntrack_event_report(enum ip_conntrack_events event, struct nf_conn *ct,
105 u32 portid, int report) 124 u32 portid, int report)
106{ 125{
126#ifdef CONFIG_NF_CONNTRACK_EVENTS
107 const struct net *net = nf_ct_net(ct); 127 const struct net *net = nf_ct_net(ct);
108 128
109 if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb)) 129 if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
110 return 0; 130 return 0;
111 131
112 return nf_conntrack_eventmask_report(1 << event, ct, portid, report); 132 return nf_conntrack_eventmask_report(1 << event, ct, portid, report);
133#else
134 return 0;
135#endif
113} 136}
114 137
115static inline int 138static inline int
116nf_conntrack_event(enum ip_conntrack_events event, struct nf_conn *ct) 139nf_conntrack_event(enum ip_conntrack_events event, struct nf_conn *ct)
117{ 140{
141#ifdef CONFIG_NF_CONNTRACK_EVENTS
118 const struct net *net = nf_ct_net(ct); 142 const struct net *net = nf_ct_net(ct);
119 143
120 if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb)) 144 if (!rcu_access_pointer(net->ct.nf_conntrack_event_cb))
121 return 0; 145 return 0;
122 146
123 return nf_conntrack_eventmask_report(1 << event, ct, 0, 0); 147 return nf_conntrack_eventmask_report(1 << event, ct, 0, 0);
148#else
149 return 0;
150#endif
124} 151}
125 152
153#ifdef CONFIG_NF_CONNTRACK_EVENTS
154
126struct nf_exp_event { 155struct nf_exp_event {
127 struct nf_conntrack_expect *exp; 156 struct nf_conntrack_expect *exp;
128 u32 portid; 157 u32 portid;
@@ -148,41 +177,18 @@ void nf_conntrack_ecache_pernet_fini(struct net *net);
148int nf_conntrack_ecache_init(void); 177int nf_conntrack_ecache_init(void);
149void nf_conntrack_ecache_fini(void); 178void nf_conntrack_ecache_fini(void);
150 179
151static inline void nf_conntrack_ecache_delayed_work(struct net *net) 180#else /* CONFIG_NF_CONNTRACK_EVENTS */
181
182static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e,
183 struct nf_conntrack_expect *exp,
184 u32 portid,
185 int report)
152{ 186{
153 if (!delayed_work_pending(&net->ct.ecache_dwork)) {
154 schedule_delayed_work(&net->ct.ecache_dwork, HZ);
155 net->ct.ecache_dwork_pending = true;
156 }
157} 187}
158 188
159static inline void nf_conntrack_ecache_work(struct net *net) 189static inline void nf_conntrack_ecache_pernet_init(struct net *net)
160{ 190{
161 if (net->ct.ecache_dwork_pending) {
162 net->ct.ecache_dwork_pending = false;
163 mod_delayed_work(system_wq, &net->ct.ecache_dwork, 0);
164 }
165} 191}
166#else /* CONFIG_NF_CONNTRACK_EVENTS */
167static inline void nf_conntrack_event_cache(enum ip_conntrack_events event,
168 struct nf_conn *ct) {}
169static inline int nf_conntrack_eventmask_report(unsigned int eventmask,
170 struct nf_conn *ct,
171 u32 portid,
172 int report) { return 0; }
173static inline int nf_conntrack_event(enum ip_conntrack_events event,
174 struct nf_conn *ct) { return 0; }
175static inline int nf_conntrack_event_report(enum ip_conntrack_events event,
176 struct nf_conn *ct,
177 u32 portid,
178 int report) { return 0; }
179static inline void nf_ct_deliver_cached_events(const struct nf_conn *ct) {}
180static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e,
181 struct nf_conntrack_expect *exp,
182 u32 portid,
183 int report) {}
184
185static inline void nf_conntrack_ecache_pernet_init(struct net *net) {}
186 192
187static inline void nf_conntrack_ecache_pernet_fini(struct net *net) 193static inline void nf_conntrack_ecache_pernet_fini(struct net *net)
188{ 194{
@@ -197,14 +203,26 @@ static inline void nf_conntrack_ecache_fini(void)
197{ 203{
198} 204}
199 205
206#endif /* CONFIG_NF_CONNTRACK_EVENTS */
207
200static inline void nf_conntrack_ecache_delayed_work(struct net *net) 208static inline void nf_conntrack_ecache_delayed_work(struct net *net)
201{ 209{
210#ifdef CONFIG_NF_CONNTRACK_EVENTS
211 if (!delayed_work_pending(&net->ct.ecache_dwork)) {
212 schedule_delayed_work(&net->ct.ecache_dwork, HZ);
213 net->ct.ecache_dwork_pending = true;
214 }
215#endif
202} 216}
203 217
204static inline void nf_conntrack_ecache_work(struct net *net) 218static inline void nf_conntrack_ecache_work(struct net *net)
205{ 219{
220#ifdef CONFIG_NF_CONNTRACK_EVENTS
221 if (net->ct.ecache_dwork_pending) {
222 net->ct.ecache_dwork_pending = false;
223 mod_delayed_work(system_wq, &net->ct.ecache_dwork, 0);
224 }
225#endif
206} 226}
207#endif /* CONFIG_NF_CONNTRACK_EVENTS */
208 227
209#endif /*_NF_CONNTRACK_ECACHE_H*/ 228#endif /*_NF_CONNTRACK_ECACHE_H*/
210
diff --git a/include/net/netfilter/nf_conntrack_expect.h b/include/net/netfilter/nf_conntrack_expect.h
index 573429be4d59..0855b60fba17 100644
--- a/include/net/netfilter/nf_conntrack_expect.h
+++ b/include/net/netfilter/nf_conntrack_expect.h
@@ -126,7 +126,7 @@ void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
126 const union nf_inet_addr *, 126 const union nf_inet_addr *,
127 u_int8_t, const __be16 *, const __be16 *); 127 u_int8_t, const __be16 *, const __be16 *);
128void nf_ct_expect_put(struct nf_conntrack_expect *exp); 128void nf_ct_expect_put(struct nf_conntrack_expect *exp);
129int nf_ct_expect_related_report(struct nf_conntrack_expect *expect, 129int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
130 u32 portid, int report, unsigned int flags); 130 u32 portid, int report, unsigned int flags);
131static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect, 131static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect,
132 unsigned int flags) 132 unsigned int flags)
diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
index 21f887c5058c..112a6f40dfaf 100644
--- a/include/net/netfilter/nf_conntrack_extend.h
+++ b/include/net/netfilter/nf_conntrack_extend.h
@@ -8,7 +8,7 @@
8 8
9enum nf_ct_ext_id { 9enum nf_ct_ext_id {
10 NF_CT_EXT_HELPER, 10 NF_CT_EXT_HELPER,
11#if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE) 11#if IS_ENABLED(CONFIG_NF_NAT)
12 NF_CT_EXT_NAT, 12 NF_CT_EXT_NAT,
13#endif 13#endif
14 NF_CT_EXT_SEQADJ, 14 NF_CT_EXT_SEQADJ,
diff --git a/include/net/netfilter/nf_conntrack_l4proto.h b/include/net/netfilter/nf_conntrack_l4proto.h
index c200b95d27ae..4cad1f0a327a 100644
--- a/include/net/netfilter/nf_conntrack_l4proto.h
+++ b/include/net/netfilter/nf_conntrack_l4proto.h
@@ -75,7 +75,6 @@ bool nf_conntrack_invert_icmp_tuple(struct nf_conntrack_tuple *tuple,
75bool nf_conntrack_invert_icmpv6_tuple(struct nf_conntrack_tuple *tuple, 75bool nf_conntrack_invert_icmpv6_tuple(struct nf_conntrack_tuple *tuple,
76 const struct nf_conntrack_tuple *orig); 76 const struct nf_conntrack_tuple *orig);
77 77
78#if IS_ENABLED(CONFIG_NETFILTER)
79int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb, 78int nf_conntrack_inet_error(struct nf_conn *tmpl, struct sk_buff *skb,
80 unsigned int dataoff, 79 unsigned int dataoff,
81 const struct nf_hook_state *state, 80 const struct nf_hook_state *state,
@@ -132,7 +131,6 @@ int nf_conntrack_gre_packet(struct nf_conn *ct,
132 unsigned int dataoff, 131 unsigned int dataoff,
133 enum ip_conntrack_info ctinfo, 132 enum ip_conntrack_info ctinfo,
134 const struct nf_hook_state *state); 133 const struct nf_hook_state *state);
135#endif
136 134
137void nf_conntrack_generic_init_net(struct net *net); 135void nf_conntrack_generic_init_net(struct net *net);
138void nf_conntrack_tcp_init_net(struct net *net); 136void nf_conntrack_tcp_init_net(struct net *net);
@@ -181,41 +179,41 @@ void nf_ct_l4proto_log_invalid(const struct sk_buff *skb,
181#if IS_ENABLED(CONFIG_NF_CONNTRACK) 179#if IS_ENABLED(CONFIG_NF_CONNTRACK)
182static inline struct nf_generic_net *nf_generic_pernet(struct net *net) 180static inline struct nf_generic_net *nf_generic_pernet(struct net *net)
183{ 181{
184 return &net->ct.nf_ct_proto.generic; 182 return &net->ct.nf_ct_proto.generic;
185} 183}
186 184
187static inline struct nf_tcp_net *nf_tcp_pernet(struct net *net) 185static inline struct nf_tcp_net *nf_tcp_pernet(struct net *net)
188{ 186{
189 return &net->ct.nf_ct_proto.tcp; 187 return &net->ct.nf_ct_proto.tcp;
190} 188}
191 189
192static inline struct nf_udp_net *nf_udp_pernet(struct net *net) 190static inline struct nf_udp_net *nf_udp_pernet(struct net *net)
193{ 191{
194 return &net->ct.nf_ct_proto.udp; 192 return &net->ct.nf_ct_proto.udp;
195} 193}
196 194
197static inline struct nf_icmp_net *nf_icmp_pernet(struct net *net) 195static inline struct nf_icmp_net *nf_icmp_pernet(struct net *net)
198{ 196{
199 return &net->ct.nf_ct_proto.icmp; 197 return &net->ct.nf_ct_proto.icmp;
200} 198}
201 199
202static inline struct nf_icmp_net *nf_icmpv6_pernet(struct net *net) 200static inline struct nf_icmp_net *nf_icmpv6_pernet(struct net *net)
203{ 201{
204 return &net->ct.nf_ct_proto.icmpv6; 202 return &net->ct.nf_ct_proto.icmpv6;
205} 203}
206#endif 204#endif
207 205
208#ifdef CONFIG_NF_CT_PROTO_DCCP 206#ifdef CONFIG_NF_CT_PROTO_DCCP
209static inline struct nf_dccp_net *nf_dccp_pernet(struct net *net) 207static inline struct nf_dccp_net *nf_dccp_pernet(struct net *net)
210{ 208{
211 return &net->ct.nf_ct_proto.dccp; 209 return &net->ct.nf_ct_proto.dccp;
212} 210}
213#endif 211#endif
214 212
215#ifdef CONFIG_NF_CT_PROTO_SCTP 213#ifdef CONFIG_NF_CT_PROTO_SCTP
216static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net) 214static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net)
217{ 215{
218 return &net->ct.nf_ct_proto.sctp; 216 return &net->ct.nf_ct_proto.sctp;
219} 217}
220#endif 218#endif
221 219
diff --git a/include/net/netfilter/nf_conntrack_labels.h b/include/net/netfilter/nf_conntrack_labels.h
index 4eacce6f3bcc..ba916411c4e1 100644
--- a/include/net/netfilter/nf_conntrack_labels.h
+++ b/include/net/netfilter/nf_conntrack_labels.h
@@ -1,11 +1,14 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2#include <linux/types.h> 2
3#include <net/net_namespace.h> 3#ifndef _NF_CONNTRACK_LABELS_H
4#define _NF_CONNTRACK_LABELS_H
5
4#include <linux/netfilter/nf_conntrack_common.h> 6#include <linux/netfilter/nf_conntrack_common.h>
5#include <linux/netfilter/nf_conntrack_tuple_common.h> 7#include <linux/netfilter/nf_conntrack_tuple_common.h>
8#include <linux/types.h>
9#include <net/net_namespace.h>
6#include <net/netfilter/nf_conntrack.h> 10#include <net/netfilter/nf_conntrack.h>
7#include <net/netfilter/nf_conntrack_extend.h> 11#include <net/netfilter/nf_conntrack_extend.h>
8
9#include <uapi/linux/netfilter/xt_connlabel.h> 12#include <uapi/linux/netfilter/xt_connlabel.h>
10 13
11#define NF_CT_LABELS_MAX_SIZE ((XT_CONNLABEL_MAXBIT + 1) / BITS_PER_BYTE) 14#define NF_CT_LABELS_MAX_SIZE ((XT_CONNLABEL_MAXBIT + 1) / BITS_PER_BYTE)
@@ -51,3 +54,5 @@ static inline void nf_conntrack_labels_fini(void) {}
51static inline int nf_connlabels_get(struct net *net, unsigned int bit) { return 0; } 54static inline int nf_connlabels_get(struct net *net, unsigned int bit) { return 0; }
52static inline void nf_connlabels_put(struct net *net) {} 55static inline void nf_connlabels_put(struct net *net) {}
53#endif 56#endif
57
58#endif /* _NF_CONNTRACK_LABELS_H */
diff --git a/include/net/netfilter/nf_conntrack_synproxy.h b/include/net/netfilter/nf_conntrack_synproxy.h
index 2f0171d24997..6a3ab081e4bf 100644
--- a/include/net/netfilter/nf_conntrack_synproxy.h
+++ b/include/net/netfilter/nf_conntrack_synproxy.h
@@ -32,6 +32,7 @@ static inline struct nf_conn_synproxy *nfct_synproxy_ext_add(struct nf_conn *ct)
32static inline bool nf_ct_add_synproxy(struct nf_conn *ct, 32static inline bool nf_ct_add_synproxy(struct nf_conn *ct,
33 const struct nf_conn *tmpl) 33 const struct nf_conn *tmpl)
34{ 34{
35#if IS_ENABLED(CONFIG_NETFILTER_SYNPROXY)
35 if (tmpl && nfct_synproxy(tmpl)) { 36 if (tmpl && nfct_synproxy(tmpl)) {
36 if (!nfct_seqadj_ext_add(ct)) 37 if (!nfct_seqadj_ext_add(ct))
37 return false; 38 return false;
@@ -39,47 +40,9 @@ static inline bool nf_ct_add_synproxy(struct nf_conn *ct,
39 if (!nfct_synproxy_ext_add(ct)) 40 if (!nfct_synproxy_ext_add(ct))
40 return false; 41 return false;
41 } 42 }
43#endif
42 44
43 return true; 45 return true;
44} 46}
45 47
46struct synproxy_stats {
47 unsigned int syn_received;
48 unsigned int cookie_invalid;
49 unsigned int cookie_valid;
50 unsigned int cookie_retrans;
51 unsigned int conn_reopened;
52};
53
54struct synproxy_net {
55 struct nf_conn *tmpl;
56 struct synproxy_stats __percpu *stats;
57 unsigned int hook_ref4;
58 unsigned int hook_ref6;
59};
60
61extern unsigned int synproxy_net_id;
62static inline struct synproxy_net *synproxy_pernet(struct net *net)
63{
64 return net_generic(net, synproxy_net_id);
65}
66
67struct synproxy_options {
68 u8 options;
69 u8 wscale;
70 u16 mss_option;
71 u16 mss_encode;
72 u32 tsval;
73 u32 tsecr;
74};
75
76struct tcphdr;
77struct nf_synproxy_info;
78bool synproxy_parse_options(const struct sk_buff *skb, unsigned int doff,
79 const struct tcphdr *th,
80 struct synproxy_options *opts);
81
82void synproxy_init_timestamp_cookie(const struct nf_synproxy_info *info,
83 struct synproxy_options *opts);
84
85#endif /* _NF_CONNTRACK_SYNPROXY_H */ 48#endif /* _NF_CONNTRACK_SYNPROXY_H */
diff --git a/include/net/netfilter/nf_conntrack_timeout.h b/include/net/netfilter/nf_conntrack_timeout.h
index 00a8fbb2d735..6dd72396f534 100644
--- a/include/net/netfilter/nf_conntrack_timeout.h
+++ b/include/net/netfilter/nf_conntrack_timeout.h
@@ -32,6 +32,7 @@ struct nf_conn_timeout {
32static inline unsigned int * 32static inline unsigned int *
33nf_ct_timeout_data(const struct nf_conn_timeout *t) 33nf_ct_timeout_data(const struct nf_conn_timeout *t)
34{ 34{
35#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
35 struct nf_ct_timeout *timeout; 36 struct nf_ct_timeout *timeout;
36 37
37 timeout = rcu_dereference(t->timeout); 38 timeout = rcu_dereference(t->timeout);
@@ -39,6 +40,9 @@ nf_ct_timeout_data(const struct nf_conn_timeout *t)
39 return NULL; 40 return NULL;
40 41
41 return (unsigned int *)timeout->data; 42 return (unsigned int *)timeout->data;
43#else
44 return NULL;
45#endif
42} 46}
43 47
44static inline 48static inline
diff --git a/include/net/netfilter/nf_conntrack_timestamp.h b/include/net/netfilter/nf_conntrack_timestamp.h
index 2b8aeba649aa..820ea34b6029 100644
--- a/include/net/netfilter/nf_conntrack_timestamp.h
+++ b/include/net/netfilter/nf_conntrack_timestamp.h
@@ -38,22 +38,6 @@ struct nf_conn_tstamp *nf_ct_tstamp_ext_add(struct nf_conn *ct, gfp_t gfp)
38#endif 38#endif
39}; 39};
40 40
41static inline bool nf_ct_tstamp_enabled(struct net *net)
42{
43#if IS_ENABLED(CONFIG_NF_CONNTRACK)
44 return net->ct.sysctl_tstamp != 0;
45#else
46 return false;
47#endif
48}
49
50static inline void nf_ct_set_tstamp(struct net *net, bool enable)
51{
52#if IS_ENABLED(CONFIG_NF_CONNTRACK)
53 net->ct.sysctl_tstamp = enable;
54#endif
55}
56
57#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP 41#ifdef CONFIG_NF_CONNTRACK_TIMESTAMP
58void nf_conntrack_tstamp_pernet_init(struct net *net); 42void nf_conntrack_tstamp_pernet_init(struct net *net);
59 43
diff --git a/include/net/netfilter/nf_conntrack_tuple.h b/include/net/netfilter/nf_conntrack_tuple.h
index 480c87b44a96..9334371c94e2 100644
--- a/include/net/netfilter/nf_conntrack_tuple.h
+++ b/include/net/netfilter/nf_conntrack_tuple.h
@@ -121,10 +121,9 @@ struct nf_conntrack_tuple_hash {
121 struct nf_conntrack_tuple tuple; 121 struct nf_conntrack_tuple tuple;
122}; 122};
123 123
124#if IS_ENABLED(CONFIG_NETFILTER)
125static inline bool __nf_ct_tuple_src_equal(const struct nf_conntrack_tuple *t1, 124static inline bool __nf_ct_tuple_src_equal(const struct nf_conntrack_tuple *t1,
126 const struct nf_conntrack_tuple *t2) 125 const struct nf_conntrack_tuple *t2)
127{ 126{
128 return (nf_inet_addr_cmp(&t1->src.u3, &t2->src.u3) && 127 return (nf_inet_addr_cmp(&t1->src.u3, &t2->src.u3) &&
129 t1->src.u.all == t2->src.u.all && 128 t1->src.u.all == t2->src.u.all &&
130 t1->src.l3num == t2->src.l3num); 129 t1->src.l3num == t2->src.l3num);
@@ -184,6 +183,5 @@ nf_ct_tuple_mask_cmp(const struct nf_conntrack_tuple *t,
184 return nf_ct_tuple_src_mask_cmp(t, tuple, mask) && 183 return nf_ct_tuple_src_mask_cmp(t, tuple, mask) &&
185 __nf_ct_tuple_dst_equal(t, tuple); 184 __nf_ct_tuple_dst_equal(t, tuple);
186} 185}
187#endif
188 186
189#endif /* _NF_CONNTRACK_TUPLE_H */ 187#endif /* _NF_CONNTRACK_TUPLE_H */
diff --git a/include/net/netfilter/nf_conntrack_zones.h b/include/net/netfilter/nf_conntrack_zones.h
index 52950baa3ab5..48dbadb96fb3 100644
--- a/include/net/netfilter/nf_conntrack_zones.h
+++ b/include/net/netfilter/nf_conntrack_zones.h
@@ -3,9 +3,7 @@
3#define _NF_CONNTRACK_ZONES_H 3#define _NF_CONNTRACK_ZONES_H
4 4
5#include <linux/netfilter/nf_conntrack_zones_common.h> 5#include <linux/netfilter/nf_conntrack_zones_common.h>
6 6#include <net/netfilter/nf_conntrack.h>
7#if IS_ENABLED(CONFIG_NF_CONNTRACK)
8#include <net/netfilter/nf_conntrack_extend.h>
9 7
10static inline const struct nf_conntrack_zone * 8static inline const struct nf_conntrack_zone *
11nf_ct_zone(const struct nf_conn *ct) 9nf_ct_zone(const struct nf_conn *ct)
@@ -87,5 +85,5 @@ static inline bool nf_ct_zone_equal_any(const struct nf_conn *a,
87 return true; 85 return true;
88#endif 86#endif
89} 87}
90#endif /* IS_ENABLED(CONFIG_NF_CONNTRACK) */ 88
91#endif /* _NF_CONNTRACK_ZONES_H */ 89#endif /* _NF_CONNTRACK_ZONES_H */
diff --git a/include/net/netfilter/nf_dup_netdev.h b/include/net/netfilter/nf_dup_netdev.h
index 181672672160..b175d271aec9 100644
--- a/include/net/netfilter/nf_dup_netdev.h
+++ b/include/net/netfilter/nf_dup_netdev.h
@@ -7,4 +7,10 @@
7void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif); 7void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif);
8void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif); 8void nf_fwd_netdev_egress(const struct nft_pktinfo *pkt, int oif);
9 9
10struct nft_offload_ctx;
11struct nft_flow_rule;
12
13int nft_fwd_dup_netdev_offload(struct nft_offload_ctx *ctx,
14 struct nft_flow_rule *flow,
15 enum flow_action_id id, int oif);
10#endif 16#endif
diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
index 609df33b1209..b37a7d608134 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -17,9 +17,7 @@ struct nf_flowtable_type {
17 int family; 17 int family;
18 int (*init)(struct nf_flowtable *ft); 18 int (*init)(struct nf_flowtable *ft);
19 void (*free)(struct nf_flowtable *ft); 19 void (*free)(struct nf_flowtable *ft);
20#if IS_ENABLED(CONFIG_NETFILTER)
21 nf_hookfn *hook; 20 nf_hookfn *hook;
22#endif
23 struct module *owner; 21 struct module *owner;
24}; 22};
25 23
@@ -117,14 +115,12 @@ struct flow_ports {
117 __be16 source, dest; 115 __be16 source, dest;
118}; 116};
119 117
120#if IS_ENABLED(CONFIG_NETFILTER)
121unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb, 118unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
122 const struct nf_hook_state *state); 119 const struct nf_hook_state *state);
123unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb, 120unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
124 const struct nf_hook_state *state); 121 const struct nf_hook_state *state);
125#endif
126 122
127#define MODULE_ALIAS_NF_FLOWTABLE(family) \ 123#define MODULE_ALIAS_NF_FLOWTABLE(family) \
128 MODULE_ALIAS("nf-flowtable-" __stringify(family)) 124 MODULE_ALIAS("nf-flowtable-" __stringify(family))
129 125
130#endif /* _FLOW_OFFLOAD_H */ 126#endif /* _NF_FLOW_TABLE_H */
diff --git a/include/net/netfilter/nf_nat.h b/include/net/netfilter/nf_nat.h
index eec208fb9c23..0d412dd63707 100644
--- a/include/net/netfilter/nf_nat.h
+++ b/include/net/netfilter/nf_nat.h
@@ -1,9 +1,14 @@
1/* SPDX-License-Identifier: GPL-2.0 */ 1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _NF_NAT_H 2#ifndef _NF_NAT_H
3#define _NF_NAT_H 3#define _NF_NAT_H
4
5#include <linux/list.h>
4#include <linux/netfilter_ipv4.h> 6#include <linux/netfilter_ipv4.h>
5#include <linux/netfilter/nf_nat.h> 7#include <linux/netfilter/nf_conntrack_pptp.h>
8#include <net/netfilter/nf_conntrack.h>
9#include <net/netfilter/nf_conntrack_extend.h>
6#include <net/netfilter/nf_conntrack_tuple.h> 10#include <net/netfilter/nf_conntrack_tuple.h>
11#include <uapi/linux/netfilter/nf_nat.h>
7 12
8enum nf_nat_manip_type { 13enum nf_nat_manip_type {
9 NF_NAT_MANIP_SRC, 14 NF_NAT_MANIP_SRC,
@@ -14,20 +19,14 @@ enum nf_nat_manip_type {
14#define HOOK2MANIP(hooknum) ((hooknum) != NF_INET_POST_ROUTING && \ 19#define HOOK2MANIP(hooknum) ((hooknum) != NF_INET_POST_ROUTING && \
15 (hooknum) != NF_INET_LOCAL_IN) 20 (hooknum) != NF_INET_LOCAL_IN)
16 21
17#include <linux/list.h>
18#include <linux/netfilter/nf_conntrack_pptp.h>
19#include <net/netfilter/nf_conntrack_extend.h>
20
21/* per conntrack: nat application helper private data */ 22/* per conntrack: nat application helper private data */
22union nf_conntrack_nat_help { 23union nf_conntrack_nat_help {
23 /* insert nat helper private data here */ 24 /* insert nat helper private data here */
24#if defined(CONFIG_NF_NAT_PPTP) || defined(CONFIG_NF_NAT_PPTP_MODULE) 25#if IS_ENABLED(CONFIG_NF_NAT_PPTP)
25 struct nf_nat_pptp nat_pptp_info; 26 struct nf_nat_pptp nat_pptp_info;
26#endif 27#endif
27}; 28};
28 29
29struct nf_conn;
30
31/* The structure embedded in the conntrack structure. */ 30/* The structure embedded in the conntrack structure. */
32struct nf_conn_nat { 31struct nf_conn_nat {
33 union nf_conntrack_nat_help help; 32 union nf_conntrack_nat_help help;
@@ -48,7 +47,7 @@ struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct);
48 47
49static inline struct nf_conn_nat *nfct_nat(const struct nf_conn *ct) 48static inline struct nf_conn_nat *nfct_nat(const struct nf_conn *ct)
50{ 49{
51#if defined(CONFIG_NF_NAT) || defined(CONFIG_NF_NAT_MODULE) 50#if IS_ENABLED(CONFIG_NF_NAT)
52 return nf_ct_ext_find(ct, NF_CT_EXT_NAT); 51 return nf_ct_ext_find(ct, NF_CT_EXT_NAT);
53#else 52#else
54 return NULL; 53 return NULL;
@@ -69,12 +68,10 @@ static inline bool nf_nat_oif_changed(unsigned int hooknum,
69#endif 68#endif
70} 69}
71 70
72#if IS_ENABLED(CONFIG_NETFILTER)
73int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, 71int nf_nat_register_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,
74 const struct nf_hook_ops *nat_ops, unsigned int ops_count); 72 const struct nf_hook_ops *nat_ops, unsigned int ops_count);
75void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops, 73void nf_nat_unregister_fn(struct net *net, u8 pf, const struct nf_hook_ops *ops,
76 unsigned int ops_count); 74 unsigned int ops_count);
77#endif
78 75
79unsigned int nf_nat_packet(struct nf_conn *ct, enum ip_conntrack_info ctinfo, 76unsigned int nf_nat_packet(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
80 unsigned int hooknum, struct sk_buff *skb); 77 unsigned int hooknum, struct sk_buff *skb);
@@ -94,7 +91,6 @@ int nf_nat_icmpv6_reply_translation(struct sk_buff *skb, struct nf_conn *ct,
94 enum ip_conntrack_info ctinfo, 91 enum ip_conntrack_info ctinfo,
95 unsigned int hooknum, unsigned int hdrlen); 92 unsigned int hooknum, unsigned int hdrlen);
96 93
97#if IS_ENABLED(CONFIG_NETFILTER)
98int nf_nat_ipv4_register_fn(struct net *net, const struct nf_hook_ops *ops); 94int nf_nat_ipv4_register_fn(struct net *net, const struct nf_hook_ops *ops);
99void nf_nat_ipv4_unregister_fn(struct net *net, const struct nf_hook_ops *ops); 95void nf_nat_ipv4_unregister_fn(struct net *net, const struct nf_hook_ops *ops);
100 96
@@ -107,7 +103,6 @@ void nf_nat_inet_unregister_fn(struct net *net, const struct nf_hook_ops *ops);
107unsigned int 103unsigned int
108nf_nat_inet_fn(void *priv, struct sk_buff *skb, 104nf_nat_inet_fn(void *priv, struct sk_buff *skb,
109 const struct nf_hook_state *state); 105 const struct nf_hook_state *state);
110#endif
111 106
112int nf_xfrm_me_harder(struct net *n, struct sk_buff *s, unsigned int family); 107int nf_xfrm_me_harder(struct net *n, struct sk_buff *s, unsigned int family);
113 108
diff --git a/include/net/netfilter/nf_nat_masquerade.h b/include/net/netfilter/nf_nat_masquerade.h
index 54a14d643c34..be7abc9d5f22 100644
--- a/include/net/netfilter/nf_nat_masquerade.h
+++ b/include/net/netfilter/nf_nat_masquerade.h
@@ -2,6 +2,7 @@
2#ifndef _NF_NAT_MASQUERADE_H_ 2#ifndef _NF_NAT_MASQUERADE_H_
3#define _NF_NAT_MASQUERADE_H_ 3#define _NF_NAT_MASQUERADE_H_
4 4
5#include <linux/skbuff.h>
5#include <net/netfilter/nf_nat.h> 6#include <net/netfilter/nf_nat.h>
6 7
7unsigned int 8unsigned int
diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
index 80edb46a1bbc..47088083667b 100644
--- a/include/net/netfilter/nf_queue.h
+++ b/include/net/netfilter/nf_queue.h
@@ -15,9 +15,7 @@ struct nf_queue_entry {
15 unsigned int id; 15 unsigned int id;
16 unsigned int hook_index; /* index in hook_entries->hook[] */ 16 unsigned int hook_index; /* index in hook_entries->hook[] */
17 17
18#if IS_ENABLED(CONFIG_NETFILTER)
19 struct nf_hook_state state; 18 struct nf_hook_state state;
20#endif
21 u16 size; /* sizeof(entry) + saved route keys */ 19 u16 size; /* sizeof(entry) + saved route keys */
22 20
23 /* extra space to store route keys */ 21 /* extra space to store route keys */
@@ -123,9 +121,7 @@ nfqueue_hash(const struct sk_buff *skb, u16 queue, u16 queues_total, u8 family,
123 return queue; 121 return queue;
124} 122}
125 123
126#if IS_ENABLED(CONFIG_NETFILTER)
127int nf_queue(struct sk_buff *skb, struct nf_hook_state *state, 124int nf_queue(struct sk_buff *skb, struct nf_hook_state *state,
128 unsigned int index, unsigned int verdict); 125 unsigned int index, unsigned int verdict);
129#endif
130 126
131#endif /* _NF_QUEUE_H */ 127#endif /* _NF_QUEUE_H */
diff --git a/include/net/netfilter/nf_synproxy.h b/include/net/netfilter/nf_synproxy.h
index dc420b47e3aa..a336f9434e73 100644
--- a/include/net/netfilter/nf_synproxy.h
+++ b/include/net/netfilter/nf_synproxy.h
@@ -11,6 +11,44 @@
11#include <net/netfilter/nf_conntrack_seqadj.h> 11#include <net/netfilter/nf_conntrack_seqadj.h>
12#include <net/netfilter/nf_conntrack_synproxy.h> 12#include <net/netfilter/nf_conntrack_synproxy.h>
13 13
14struct synproxy_stats {
15 unsigned int syn_received;
16 unsigned int cookie_invalid;
17 unsigned int cookie_valid;
18 unsigned int cookie_retrans;
19 unsigned int conn_reopened;
20};
21
22struct synproxy_net {
23 struct nf_conn *tmpl;
24 struct synproxy_stats __percpu *stats;
25 unsigned int hook_ref4;
26 unsigned int hook_ref6;
27};
28
29extern unsigned int synproxy_net_id;
30static inline struct synproxy_net *synproxy_pernet(struct net *net)
31{
32 return net_generic(net, synproxy_net_id);
33}
34
35struct synproxy_options {
36 u8 options;
37 u8 wscale;
38 u16 mss_option;
39 u16 mss_encode;
40 u32 tsval;
41 u32 tsecr;
42};
43
44struct nf_synproxy_info;
45bool synproxy_parse_options(const struct sk_buff *skb, unsigned int doff,
46 const struct tcphdr *th,
47 struct synproxy_options *opts);
48
49void synproxy_init_timestamp_cookie(const struct nf_synproxy_info *info,
50 struct synproxy_options *opts);
51
14void synproxy_send_client_synack(struct net *net, const struct sk_buff *skb, 52void synproxy_send_client_synack(struct net *net, const struct sk_buff *skb,
15 const struct tcphdr *th, 53 const struct tcphdr *th,
16 const struct synproxy_options *opts); 54 const struct synproxy_options *opts);
@@ -20,10 +58,10 @@ bool synproxy_recv_client_ack(struct net *net,
20 const struct tcphdr *th, 58 const struct tcphdr *th,
21 struct synproxy_options *opts, u32 recv_seq); 59 struct synproxy_options *opts, u32 recv_seq);
22 60
23#if IS_ENABLED(CONFIG_NETFILTER) 61struct nf_hook_state;
62
24unsigned int ipv4_synproxy_hook(void *priv, struct sk_buff *skb, 63unsigned int ipv4_synproxy_hook(void *priv, struct sk_buff *skb,
25 const struct nf_hook_state *nhs); 64 const struct nf_hook_state *nhs);
26#endif
27int nf_synproxy_ipv4_init(struct synproxy_net *snet, struct net *net); 65int nf_synproxy_ipv4_init(struct synproxy_net *snet, struct net *net);
28void nf_synproxy_ipv4_fini(struct synproxy_net *snet, struct net *net); 66void nf_synproxy_ipv4_fini(struct synproxy_net *snet, struct net *net);
29 67
@@ -37,10 +75,8 @@ bool synproxy_recv_client_ack_ipv6(struct net *net, const struct sk_buff *skb,
37 const struct tcphdr *th, 75 const struct tcphdr *th,
38 struct synproxy_options *opts, u32 recv_seq); 76 struct synproxy_options *opts, u32 recv_seq);
39 77
40#if IS_ENABLED(CONFIG_NETFILTER)
41unsigned int ipv6_synproxy_hook(void *priv, struct sk_buff *skb, 78unsigned int ipv6_synproxy_hook(void *priv, struct sk_buff *skb,
42 const struct nf_hook_state *nhs); 79 const struct nf_hook_state *nhs);
43#endif
44int nf_synproxy_ipv6_init(struct synproxy_net *snet, struct net *net); 80int nf_synproxy_ipv6_init(struct synproxy_net *snet, struct net *net);
45void nf_synproxy_ipv6_fini(struct synproxy_net *snet, struct net *net); 81void nf_synproxy_ipv6_fini(struct synproxy_net *snet, struct net *net);
46#else 82#else
diff --git a/include/net/netfilter/nf_tables.h b/include/net/netfilter/nf_tables.h
index 3d9e66aa0139..2655e03dbe1b 100644
--- a/include/net/netfilter/nf_tables.h
+++ b/include/net/netfilter/nf_tables.h
@@ -26,7 +26,6 @@ struct nft_pktinfo {
26 struct xt_action_param xt; 26 struct xt_action_param xt;
27}; 27};
28 28
29#if IS_ENABLED(CONFIG_NETFILTER)
30static inline struct net *nft_net(const struct nft_pktinfo *pkt) 29static inline struct net *nft_net(const struct nft_pktinfo *pkt)
31{ 30{
32 return pkt->xt.state->net; 31 return pkt->xt.state->net;
@@ -59,7 +58,6 @@ static inline void nft_set_pktinfo(struct nft_pktinfo *pkt,
59 pkt->skb = skb; 58 pkt->skb = skb;
60 pkt->xt.state = state; 59 pkt->xt.state = state;
61} 60}
62#endif
63 61
64static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt, 62static inline void nft_set_pktinfo_unspec(struct nft_pktinfo *pkt,
65 struct sk_buff *skb) 63 struct sk_buff *skb)
@@ -947,11 +945,9 @@ struct nft_chain_type {
947 int family; 945 int family;
948 struct module *owner; 946 struct module *owner;
949 unsigned int hook_mask; 947 unsigned int hook_mask;
950#if IS_ENABLED(CONFIG_NETFILTER)
951 nf_hookfn *hooks[NF_MAX_HOOKS]; 948 nf_hookfn *hooks[NF_MAX_HOOKS];
952 int (*ops_register)(struct net *net, const struct nf_hook_ops *ops); 949 int (*ops_register)(struct net *net, const struct nf_hook_ops *ops);
953 void (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops); 950 void (*ops_unregister)(struct net *net, const struct nf_hook_ops *ops);
954#endif
955}; 951};
956 952
957int nft_chain_validate_dependency(const struct nft_chain *chain, 953int nft_chain_validate_dependency(const struct nft_chain *chain,
@@ -977,9 +973,7 @@ struct nft_stats {
977 * @flow_block: flow block (for hardware offload) 973 * @flow_block: flow block (for hardware offload)
978 */ 974 */
979struct nft_base_chain { 975struct nft_base_chain {
980#if IS_ENABLED(CONFIG_NETFILTER)
981 struct nf_hook_ops ops; 976 struct nf_hook_ops ops;
982#endif
983 const struct nft_chain_type *type; 977 const struct nft_chain_type *type;
984 u8 policy; 978 u8 policy;
985 u8 flags; 979 u8 flags;
@@ -1179,9 +1173,7 @@ struct nft_flowtable {
1179 use:30; 1173 use:30;
1180 u64 handle; 1174 u64 handle;
1181 /* runtime data below here */ 1175 /* runtime data below here */
1182#if IS_ENABLED(CONFIG_NETFILTER)
1183 struct nf_hook_ops *ops ____cacheline_aligned; 1176 struct nf_hook_ops *ops ____cacheline_aligned;
1184#endif
1185 struct nf_flowtable data; 1177 struct nf_flowtable data;
1186}; 1178};
1187 1179
diff --git a/include/net/netfilter/nf_tables_offload.h b/include/net/netfilter/nf_tables_offload.h
index db104665a9e4..03cf5856d76f 100644
--- a/include/net/netfilter/nf_tables_offload.h
+++ b/include/net/netfilter/nf_tables_offload.h
@@ -26,6 +26,7 @@ struct nft_offload_ctx {
26 u8 protonum; 26 u8 protonum;
27 } dep; 27 } dep;
28 unsigned int num_actions; 28 unsigned int num_actions;
29 struct net *net;
29 struct nft_offload_reg regs[NFT_REG32_15 + 1]; 30 struct nft_offload_reg regs[NFT_REG32_15 + 1];
30}; 31};
31 32
@@ -61,13 +62,9 @@ struct nft_flow_rule {
61#define NFT_OFFLOAD_F_ACTION (1 << 0) 62#define NFT_OFFLOAD_F_ACTION (1 << 0)
62 63
63struct nft_rule; 64struct nft_rule;
64struct nft_flow_rule *nft_flow_rule_create(const struct nft_rule *rule); 65struct nft_flow_rule *nft_flow_rule_create(struct net *net, const struct nft_rule *rule);
65void nft_flow_rule_destroy(struct nft_flow_rule *flow); 66void nft_flow_rule_destroy(struct nft_flow_rule *flow);
66int nft_flow_rule_offload_commit(struct net *net); 67int nft_flow_rule_offload_commit(struct net *net);
67void nft_indr_block_get_and_ing_cmd(struct net_device *dev,
68 flow_indr_block_bind_cb_t *cb,
69 void *cb_priv,
70 enum flow_block_command command);
71 68
72#define NFT_OFFLOAD_MATCH(__key, __base, __field, __len, __reg) \ 69#define NFT_OFFLOAD_MATCH(__key, __base, __field, __len, __reg) \
73 (__reg)->base_offset = \ 70 (__reg)->base_offset = \
@@ -80,4 +77,7 @@ void nft_indr_block_get_and_ing_cmd(struct net_device *dev,
80 77
81int nft_chain_offload_priority(struct nft_base_chain *basechain); 78int nft_chain_offload_priority(struct nft_base_chain *basechain);
82 79
80int nft_offload_init(void);
81void nft_offload_exit(void);
82
83#endif 83#endif
diff --git a/include/uapi/linux/netfilter/nf_tables.h b/include/uapi/linux/netfilter/nf_tables.h
index 0ff932dadc8e..ed8881ad18ed 100644
--- a/include/uapi/linux/netfilter/nf_tables.h
+++ b/include/uapi/linux/netfilter/nf_tables.h
@@ -1481,7 +1481,8 @@ enum nft_ct_expectation_attributes {
1481#define NFT_OBJECT_CT_TIMEOUT 7 1481#define NFT_OBJECT_CT_TIMEOUT 7
1482#define NFT_OBJECT_SECMARK 8 1482#define NFT_OBJECT_SECMARK 8
1483#define NFT_OBJECT_CT_EXPECT 9 1483#define NFT_OBJECT_CT_EXPECT 9
1484#define __NFT_OBJECT_MAX 10 1484#define NFT_OBJECT_SYNPROXY 10
1485#define __NFT_OBJECT_MAX 11
1485#define NFT_OBJECT_MAX (__NFT_OBJECT_MAX - 1) 1486#define NFT_OBJECT_MAX (__NFT_OBJECT_MAX - 1)
1486 1487
1487/** 1488/**
diff --git a/net/bridge/netfilter/ebt_802_3.c b/net/bridge/netfilter/ebt_802_3.c
index 2c8fe24400e5..68c2519bdc52 100644
--- a/net/bridge/netfilter/ebt_802_3.c
+++ b/net/bridge/netfilter/ebt_802_3.c
@@ -11,7 +11,13 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/netfilter/x_tables.h> 12#include <linux/netfilter/x_tables.h>
13#include <linux/netfilter_bridge/ebtables.h> 13#include <linux/netfilter_bridge/ebtables.h>
14#include <linux/netfilter_bridge/ebt_802_3.h> 14#include <linux/skbuff.h>
15#include <uapi/linux/netfilter_bridge/ebt_802_3.h>
16
17static struct ebt_802_3_hdr *ebt_802_3_hdr(const struct sk_buff *skb)
18{
19 return (struct ebt_802_3_hdr *)skb_mac_header(skb);
20}
15 21
16static bool 22static bool
17ebt_802_3_mt(const struct sk_buff *skb, struct xt_action_param *par) 23ebt_802_3_mt(const struct sk_buff *skb, struct xt_action_param *par)
diff --git a/net/bridge/netfilter/nf_conntrack_bridge.c b/net/bridge/netfilter/nf_conntrack_bridge.c
index 4f5444d2a526..8842798c29e6 100644
--- a/net/bridge/netfilter/nf_conntrack_bridge.c
+++ b/net/bridge/netfilter/nf_conntrack_bridge.c
@@ -17,7 +17,6 @@
17#include <net/netfilter/nf_conntrack_bridge.h> 17#include <net/netfilter/nf_conntrack_bridge.h>
18 18
19#include <linux/netfilter/nf_tables.h> 19#include <linux/netfilter/nf_tables.h>
20#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
21#include <net/netfilter/nf_tables.h> 20#include <net/netfilter/nf_tables.h>
22 21
23#include "../br_private.h" 22#include "../br_private.h"
@@ -27,9 +26,9 @@
27 */ 26 */
28static int nf_br_ip_fragment(struct net *net, struct sock *sk, 27static int nf_br_ip_fragment(struct net *net, struct sock *sk,
29 struct sk_buff *skb, 28 struct sk_buff *skb,
30 struct nf_ct_bridge_frag_data *data, 29 struct nf_bridge_frag_data *data,
31 int (*output)(struct net *, struct sock *sk, 30 int (*output)(struct net *, struct sock *sk,
32 const struct nf_ct_bridge_frag_data *data, 31 const struct nf_bridge_frag_data *data,
33 struct sk_buff *)) 32 struct sk_buff *))
34{ 33{
35 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size; 34 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size;
@@ -279,7 +278,7 @@ static unsigned int nf_ct_bridge_pre(void *priv, struct sk_buff *skb,
279} 278}
280 279
281static void nf_ct_bridge_frag_save(struct sk_buff *skb, 280static void nf_ct_bridge_frag_save(struct sk_buff *skb,
282 struct nf_ct_bridge_frag_data *data) 281 struct nf_bridge_frag_data *data)
283{ 282{
284 if (skb_vlan_tag_present(skb)) { 283 if (skb_vlan_tag_present(skb)) {
285 data->vlan_present = true; 284 data->vlan_present = true;
@@ -294,10 +293,10 @@ static void nf_ct_bridge_frag_save(struct sk_buff *skb,
294static unsigned int 293static unsigned int
295nf_ct_bridge_refrag(struct sk_buff *skb, const struct nf_hook_state *state, 294nf_ct_bridge_refrag(struct sk_buff *skb, const struct nf_hook_state *state,
296 int (*output)(struct net *, struct sock *sk, 295 int (*output)(struct net *, struct sock *sk,
297 const struct nf_ct_bridge_frag_data *data, 296 const struct nf_bridge_frag_data *data,
298 struct sk_buff *)) 297 struct sk_buff *))
299{ 298{
300 struct nf_ct_bridge_frag_data data; 299 struct nf_bridge_frag_data data;
301 300
302 if (!BR_INPUT_SKB_CB(skb)->frag_max_size) 301 if (!BR_INPUT_SKB_CB(skb)->frag_max_size)
303 return NF_ACCEPT; 302 return NF_ACCEPT;
@@ -320,7 +319,7 @@ nf_ct_bridge_refrag(struct sk_buff *skb, const struct nf_hook_state *state,
320 319
321/* Actually only slow path refragmentation needs this. */ 320/* Actually only slow path refragmentation needs this. */
322static int nf_ct_bridge_frag_restore(struct sk_buff *skb, 321static int nf_ct_bridge_frag_restore(struct sk_buff *skb,
323 const struct nf_ct_bridge_frag_data *data) 322 const struct nf_bridge_frag_data *data)
324{ 323{
325 int err; 324 int err;
326 325
@@ -341,7 +340,7 @@ static int nf_ct_bridge_frag_restore(struct sk_buff *skb,
341} 340}
342 341
343static int nf_ct_bridge_refrag_post(struct net *net, struct sock *sk, 342static int nf_ct_bridge_refrag_post(struct net *net, struct sock *sk,
344 const struct nf_ct_bridge_frag_data *data, 343 const struct nf_bridge_frag_data *data,
345 struct sk_buff *skb) 344 struct sk_buff *skb)
346{ 345{
347 int err; 346 int err;
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index 69e76d677f9e..f17b402111ce 100644
--- a/net/ipv4/netfilter/Kconfig
+++ b/net/ipv4/netfilter/Kconfig
@@ -272,7 +272,7 @@ config IP_NF_TARGET_CLUSTERIP
272 The CLUSTERIP target allows you to build load-balancing clusters of 272 The CLUSTERIP target allows you to build load-balancing clusters of
273 network servers without having a dedicated load-balancing 273 network servers without having a dedicated load-balancing
274 router/server/switch. 274 router/server/switch.
275 275
276 To compile it as a module, choose M here. If unsure, say N. 276 To compile it as a module, choose M here. If unsure, say N.
277 277
278config IP_NF_TARGET_ECN 278config IP_NF_TARGET_ECN
@@ -281,7 +281,7 @@ config IP_NF_TARGET_ECN
281 depends on NETFILTER_ADVANCED 281 depends on NETFILTER_ADVANCED
282 ---help--- 282 ---help---
283 This option adds a `ECN' target, which can be used in the iptables mangle 283 This option adds a `ECN' target, which can be used in the iptables mangle
284 table. 284 table.
285 285
286 You can use this target to remove the ECN bits from the IPv4 header of 286 You can use this target to remove the ECN bits from the IPv4 header of
287 an IP packet. This is particularly useful, if you need to work around 287 an IP packet. This is particularly useful, if you need to work around
@@ -306,7 +306,7 @@ config IP_NF_RAW
306 This option adds a `raw' table to iptables. This table is the very 306 This option adds a `raw' table to iptables. This table is the very
307 first in the netfilter framework and hooks in at the PREROUTING 307 first in the netfilter framework and hooks in at the PREROUTING
308 and OUTPUT chains. 308 and OUTPUT chains.
309 309
310 If you want to compile it as a module, say M here and read 310 If you want to compile it as a module, say M here and read
311 <file:Documentation/kbuild/modules.rst>. If unsure, say `N'. 311 <file:Documentation/kbuild/modules.rst>. If unsure, say `N'.
312 312
@@ -318,7 +318,7 @@ config IP_NF_SECURITY
318 help 318 help
319 This option adds a `security' table to iptables, for use 319 This option adds a `security' table to iptables, for use
320 with Mandatory Access Control (MAC) policy. 320 with Mandatory Access Control (MAC) policy.
321 321
322 If unsure, say N. 322 If unsure, say N.
323 323
324endif # IP_NF_IPTABLES 324endif # IP_NF_IPTABLES
diff --git a/net/ipv4/netfilter/Makefile b/net/ipv4/netfilter/Makefile
index c50e0ec095d2..7c497c78105f 100644
--- a/net/ipv4/netfilter/Makefile
+++ b/net/ipv4/netfilter/Makefile
@@ -31,7 +31,7 @@ obj-$(CONFIG_NFT_DUP_IPV4) += nft_dup_ipv4.o
31# flow table support 31# flow table support
32obj-$(CONFIG_NF_FLOW_TABLE_IPV4) += nf_flow_table_ipv4.o 32obj-$(CONFIG_NF_FLOW_TABLE_IPV4) += nf_flow_table_ipv4.o
33 33
34# generic IP tables 34# generic IP tables
35obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o 35obj-$(CONFIG_IP_NF_IPTABLES) += ip_tables.o
36 36
37# the three instances of ip_tables 37# the three instances of ip_tables
diff --git a/net/ipv6/netfilter.c b/net/ipv6/netfilter.c
index 61819ed858b1..a9bff556d3b2 100644
--- a/net/ipv6/netfilter.c
+++ b/net/ipv6/netfilter.c
@@ -113,9 +113,9 @@ int __nf_ip6_route(struct net *net, struct dst_entry **dst,
113EXPORT_SYMBOL_GPL(__nf_ip6_route); 113EXPORT_SYMBOL_GPL(__nf_ip6_route);
114 114
115int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, 115int br_ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
116 struct nf_ct_bridge_frag_data *data, 116 struct nf_bridge_frag_data *data,
117 int (*output)(struct net *, struct sock *sk, 117 int (*output)(struct net *, struct sock *sk,
118 const struct nf_ct_bridge_frag_data *data, 118 const struct nf_bridge_frag_data *data,
119 struct sk_buff *)) 119 struct sk_buff *))
120{ 120{
121 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size; 121 int frag_max_size = BR_INPUT_SKB_CB(skb)->frag_max_size;
diff --git a/net/ipv6/netfilter/ip6t_ipv6header.c b/net/ipv6/netfilter/ip6t_ipv6header.c
index 0fc6326ef499..c52ff929c93b 100644
--- a/net/ipv6/netfilter/ip6t_ipv6header.c
+++ b/net/ipv6/netfilter/ip6t_ipv6header.c
@@ -16,7 +16,7 @@
16#include <net/ipv6.h> 16#include <net/ipv6.h>
17 17
18#include <linux/netfilter/x_tables.h> 18#include <linux/netfilter/x_tables.h>
19#include <linux/netfilter_ipv6/ip6_tables.h> 19#include <linux/netfilter_ipv6.h>
20#include <linux/netfilter_ipv6/ip6t_ipv6header.h> 20#include <linux/netfilter_ipv6/ip6t_ipv6header.h>
21 21
22MODULE_LICENSE("GPL"); 22MODULE_LICENSE("GPL");
@@ -42,7 +42,7 @@ ipv6header_mt6(const struct sk_buff *skb, struct xt_action_param *par)
42 len = skb->len - ptr; 42 len = skb->len - ptr;
43 temp = 0; 43 temp = 0;
44 44
45 while (ip6t_ext_hdr(nexthdr)) { 45 while (nf_ip6_ext_hdr(nexthdr)) {
46 const struct ipv6_opt_hdr *hp; 46 const struct ipv6_opt_hdr *hp;
47 struct ipv6_opt_hdr _hdr; 47 struct ipv6_opt_hdr _hdr;
48 int hdrlen; 48 int hdrlen;
diff --git a/net/ipv6/netfilter/nf_log_ipv6.c b/net/ipv6/netfilter/nf_log_ipv6.c
index f53bd8f01219..22b80db6d882 100644
--- a/net/ipv6/netfilter/nf_log_ipv6.c
+++ b/net/ipv6/netfilter/nf_log_ipv6.c
@@ -18,7 +18,7 @@
18#include <net/route.h> 18#include <net/route.h>
19 19
20#include <linux/netfilter.h> 20#include <linux/netfilter.h>
21#include <linux/netfilter_ipv6/ip6_tables.h> 21#include <linux/netfilter_ipv6.h>
22#include <linux/netfilter/xt_LOG.h> 22#include <linux/netfilter/xt_LOG.h>
23#include <net/netfilter/nf_log.h> 23#include <net/netfilter/nf_log.h>
24 24
@@ -70,7 +70,7 @@ static void dump_ipv6_packet(struct net *net, struct nf_log_buf *m,
70 fragment = 0; 70 fragment = 0;
71 ptr = ip6hoff + sizeof(struct ipv6hdr); 71 ptr = ip6hoff + sizeof(struct ipv6hdr);
72 currenthdr = ih->nexthdr; 72 currenthdr = ih->nexthdr;
73 while (currenthdr != NEXTHDR_NONE && ip6t_ext_hdr(currenthdr)) { 73 while (currenthdr != NEXTHDR_NONE && nf_ip6_ext_hdr(currenthdr)) {
74 struct ipv6_opt_hdr _hdr; 74 struct ipv6_opt_hdr _hdr;
75 const struct ipv6_opt_hdr *hp; 75 const struct ipv6_opt_hdr *hp;
76 76
diff --git a/net/ipv6/netfilter/nf_socket_ipv6.c b/net/ipv6/netfilter/nf_socket_ipv6.c
index 437d95545c31..b9df879c48d3 100644
--- a/net/ipv6/netfilter/nf_socket_ipv6.c
+++ b/net/ipv6/netfilter/nf_socket_ipv6.c
@@ -12,7 +12,6 @@
12#include <net/sock.h> 12#include <net/sock.h>
13#include <net/inet_sock.h> 13#include <net/inet_sock.h>
14#include <net/inet6_hashtables.h> 14#include <net/inet6_hashtables.h>
15#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
16#include <net/netfilter/nf_socket.h> 15#include <net/netfilter/nf_socket.h>
17#if IS_ENABLED(CONFIG_NF_CONNTRACK) 16#if IS_ENABLED(CONFIG_NF_CONNTRACK)
18#include <net/netfilter/nf_conntrack.h> 17#include <net/netfilter/nf_conntrack.h>
diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
index 0d65f4d39494..34ec7afec116 100644
--- a/net/netfilter/Kconfig
+++ b/net/netfilter/Kconfig
@@ -20,7 +20,7 @@ config NETFILTER_FAMILY_ARP
20 bool 20 bool
21 21
22config NETFILTER_NETLINK_ACCT 22config NETFILTER_NETLINK_ACCT
23tristate "Netfilter NFACCT over NFNETLINK interface" 23 tristate "Netfilter NFACCT over NFNETLINK interface"
24 depends on NETFILTER_ADVANCED 24 depends on NETFILTER_ADVANCED
25 select NETFILTER_NETLINK 25 select NETFILTER_NETLINK
26 help 26 help
@@ -34,7 +34,7 @@ config NETFILTER_NETLINK_QUEUE
34 help 34 help
35 If this option is enabled, the kernel will include support 35 If this option is enabled, the kernel will include support
36 for queueing packets via NFNETLINK. 36 for queueing packets via NFNETLINK.
37 37
38config NETFILTER_NETLINK_LOG 38config NETFILTER_NETLINK_LOG
39 tristate "Netfilter LOG over NFNETLINK interface" 39 tristate "Netfilter LOG over NFNETLINK interface"
40 default m if NETFILTER_ADVANCED=n 40 default m if NETFILTER_ADVANCED=n
@@ -1502,7 +1502,7 @@ config NETFILTER_XT_MATCH_REALM
1502 This option adds a `realm' match, which allows you to use the realm 1502 This option adds a `realm' match, which allows you to use the realm
1503 key from the routing subsystem inside iptables. 1503 key from the routing subsystem inside iptables.
1504 1504
1505 This match pretty much resembles the CONFIG_NET_CLS_ROUTE4 option 1505 This match pretty much resembles the CONFIG_NET_CLS_ROUTE4 option
1506 in tc world. 1506 in tc world.
1507 1507
1508 If you want to compile it as a module, say M here and read 1508 If you want to compile it as a module, say M here and read
@@ -1523,7 +1523,7 @@ config NETFILTER_XT_MATCH_SCTP
1523 depends on NETFILTER_ADVANCED 1523 depends on NETFILTER_ADVANCED
1524 default IP_SCTP 1524 default IP_SCTP
1525 help 1525 help
1526 With this option enabled, you will be able to use the 1526 With this option enabled, you will be able to use the
1527 `sctp' match in order to match on SCTP source/destination ports 1527 `sctp' match in order to match on SCTP source/destination ports
1528 and SCTP chunk types. 1528 and SCTP chunk types.
1529 1529
diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
index 9270a7fae484..4fc075b612fe 100644
--- a/net/netfilter/Makefile
+++ b/net/netfilter/Makefile
@@ -124,7 +124,7 @@ nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o
124 124
125obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o 125obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
126 126
127# generic X tables 127# generic X tables
128obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o 128obj-$(CONFIG_NETFILTER_XTABLES) += x_tables.o xt_tcpudp.o
129 129
130# combos 130# combos
diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
index 5e2812ee2149..6fba74b5aaf7 100644
--- a/net/netfilter/nf_conntrack_ecache.c
+++ b/net/netfilter/nf_conntrack_ecache.c
@@ -24,6 +24,7 @@
24 24
25#include <net/netfilter/nf_conntrack.h> 25#include <net/netfilter/nf_conntrack.h>
26#include <net/netfilter/nf_conntrack_core.h> 26#include <net/netfilter/nf_conntrack_core.h>
27#include <net/netfilter/nf_conntrack_ecache.h>
27#include <net/netfilter/nf_conntrack_extend.h> 28#include <net/netfilter/nf_conntrack_extend.h>
28 29
29static DEFINE_MUTEX(nf_ct_ecache_mutex); 30static DEFINE_MUTEX(nf_ct_ecache_mutex);
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index 65364de915d1..42557d2b6a90 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -25,8 +25,10 @@
25 25
26#include <net/netfilter/nf_conntrack.h> 26#include <net/netfilter/nf_conntrack.h>
27#include <net/netfilter/nf_conntrack_core.h> 27#include <net/netfilter/nf_conntrack_core.h>
28#include <net/netfilter/nf_conntrack_ecache.h>
28#include <net/netfilter/nf_conntrack_expect.h> 29#include <net/netfilter/nf_conntrack_expect.h>
29#include <net/netfilter/nf_conntrack_helper.h> 30#include <net/netfilter/nf_conntrack_helper.h>
31#include <net/netfilter/nf_conntrack_l4proto.h>
30#include <net/netfilter/nf_conntrack_tuple.h> 32#include <net/netfilter/nf_conntrack_tuple.h>
31#include <net/netfilter/nf_conntrack_zones.h> 33#include <net/netfilter/nf_conntrack_zones.h>
32 34
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
index 8d729e7c36ff..118f415928ae 100644
--- a/net/netfilter/nf_conntrack_helper.c
+++ b/net/netfilter/nf_conntrack_helper.c
@@ -21,10 +21,11 @@
21#include <linux/rtnetlink.h> 21#include <linux/rtnetlink.h>
22 22
23#include <net/netfilter/nf_conntrack.h> 23#include <net/netfilter/nf_conntrack.h>
24#include <net/netfilter/nf_conntrack_l4proto.h>
25#include <net/netfilter/nf_conntrack_helper.h>
26#include <net/netfilter/nf_conntrack_core.h> 24#include <net/netfilter/nf_conntrack_core.h>
25#include <net/netfilter/nf_conntrack_ecache.h>
27#include <net/netfilter/nf_conntrack_extend.h> 26#include <net/netfilter/nf_conntrack_extend.h>
27#include <net/netfilter/nf_conntrack_helper.h>
28#include <net/netfilter/nf_conntrack_l4proto.h>
28#include <net/netfilter/nf_log.h> 29#include <net/netfilter/nf_log.h>
29 30
30static DEFINE_MUTEX(nf_ct_helper_mutex); 31static DEFINE_MUTEX(nf_ct_helper_mutex);
diff --git a/net/netfilter/nf_conntrack_proto_icmpv6.c b/net/netfilter/nf_conntrack_proto_icmpv6.c
index 7e317e6698ba..6f9144e1f1c1 100644
--- a/net/netfilter/nf_conntrack_proto_icmpv6.c
+++ b/net/netfilter/nf_conntrack_proto_icmpv6.c
@@ -22,7 +22,6 @@
22#include <net/netfilter/nf_conntrack_core.h> 22#include <net/netfilter/nf_conntrack_core.h>
23#include <net/netfilter/nf_conntrack_timeout.h> 23#include <net/netfilter/nf_conntrack_timeout.h>
24#include <net/netfilter/nf_conntrack_zones.h> 24#include <net/netfilter/nf_conntrack_zones.h>
25#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
26#include <net/netfilter/nf_log.h> 25#include <net/netfilter/nf_log.h>
27 26
28static const unsigned int nf_ct_icmpv6_timeout = 30*HZ; 27static const unsigned int nf_ct_icmpv6_timeout = 30*HZ;
diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
index 88d4127df863..410809c669e1 100644
--- a/net/netfilter/nf_conntrack_standalone.c
+++ b/net/netfilter/nf_conntrack_standalone.c
@@ -1167,7 +1167,6 @@ static int __init nf_conntrack_standalone_init(void)
1167 if (ret < 0) 1167 if (ret < 0)
1168 goto out_start; 1168 goto out_start;
1169 1169
1170 BUILD_BUG_ON(SKB_NFCT_PTRMASK != NFCT_PTRMASK);
1171 BUILD_BUG_ON(NFCT_INFOMASK <= IP_CT_NUMBER); 1170 BUILD_BUG_ON(NFCT_INFOMASK <= IP_CT_NUMBER);
1172 1171
1173#ifdef CONFIG_SYSCTL 1172#ifdef CONFIG_SYSCTL
diff --git a/net/netfilter/nf_conntrack_timeout.c b/net/netfilter/nf_conntrack_timeout.c
index 13d0f4a92647..14387e0b8008 100644
--- a/net/netfilter/nf_conntrack_timeout.c
+++ b/net/netfilter/nf_conntrack_timeout.c
@@ -19,6 +19,7 @@
19#include <net/netfilter/nf_conntrack.h> 19#include <net/netfilter/nf_conntrack.h>
20#include <net/netfilter/nf_conntrack_core.h> 20#include <net/netfilter/nf_conntrack_core.h>
21#include <net/netfilter/nf_conntrack_extend.h> 21#include <net/netfilter/nf_conntrack_extend.h>
22#include <net/netfilter/nf_conntrack_l4proto.h>
22#include <net/netfilter/nf_conntrack_timeout.h> 23#include <net/netfilter/nf_conntrack_timeout.h>
23 24
24struct nf_ct_timeout * 25struct nf_ct_timeout *
diff --git a/net/netfilter/nf_dup_netdev.c b/net/netfilter/nf_dup_netdev.c
index 5a35ef08c3cb..f108a76925dd 100644
--- a/net/netfilter/nf_dup_netdev.c
+++ b/net/netfilter/nf_dup_netdev.c
@@ -10,6 +10,7 @@
10#include <linux/netfilter.h> 10#include <linux/netfilter.h>
11#include <linux/netfilter/nf_tables.h> 11#include <linux/netfilter/nf_tables.h>
12#include <net/netfilter/nf_tables.h> 12#include <net/netfilter/nf_tables.h>
13#include <net/netfilter/nf_tables_offload.h>
13#include <net/netfilter/nf_dup_netdev.h> 14#include <net/netfilter/nf_dup_netdev.h>
14 15
15static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev) 16static void nf_do_netdev_egress(struct sk_buff *skb, struct net_device *dev)
@@ -50,5 +51,25 @@ void nf_dup_netdev_egress(const struct nft_pktinfo *pkt, int oif)
50} 51}
51EXPORT_SYMBOL_GPL(nf_dup_netdev_egress); 52EXPORT_SYMBOL_GPL(nf_dup_netdev_egress);
52 53
54int nft_fwd_dup_netdev_offload(struct nft_offload_ctx *ctx,
55 struct nft_flow_rule *flow,
56 enum flow_action_id id, int oif)
57{
58 struct flow_action_entry *entry;
59 struct net_device *dev;
60
61 /* nft_flow_rule_destroy() releases the reference on this device. */
62 dev = dev_get_by_index(ctx->net, oif);
63 if (!dev)
64 return -EOPNOTSUPP;
65
66 entry = &flow->rule->action.entries[ctx->num_actions++];
67 entry->id = id;
68 entry->dev = dev;
69
70 return 0;
71}
72EXPORT_SYMBOL_GPL(nft_fwd_dup_netdev_offload);
73
53MODULE_LICENSE("GPL"); 74MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>"); 75MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 80a8f9ae4c93..09310a1bd91f 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -11,6 +11,7 @@
11#include <net/netfilter/nf_flow_table.h> 11#include <net/netfilter/nf_flow_table.h>
12#include <net/netfilter/nf_conntrack.h> 12#include <net/netfilter/nf_conntrack.h>
13#include <net/netfilter/nf_conntrack_core.h> 13#include <net/netfilter/nf_conntrack_core.h>
14#include <net/netfilter/nf_conntrack_l4proto.h>
14#include <net/netfilter/nf_conntrack_tuple.h> 15#include <net/netfilter/nf_conntrack_tuple.h>
15 16
16struct flow_offload_entry { 17struct flow_offload_entry {
diff --git a/net/netfilter/nf_nat_core.c b/net/netfilter/nf_nat_core.c
index 3f6023ed4966..bfc555fcbc72 100644
--- a/net/netfilter/nf_nat_core.c
+++ b/net/netfilter/nf_nat_core.c
@@ -18,12 +18,12 @@
18 18
19#include <net/netfilter/nf_conntrack.h> 19#include <net/netfilter/nf_conntrack.h>
20#include <net/netfilter/nf_conntrack_core.h> 20#include <net/netfilter/nf_conntrack_core.h>
21#include <net/netfilter/nf_nat.h>
22#include <net/netfilter/nf_nat_helper.h>
23#include <net/netfilter/nf_conntrack_helper.h> 21#include <net/netfilter/nf_conntrack_helper.h>
24#include <net/netfilter/nf_conntrack_seqadj.h> 22#include <net/netfilter/nf_conntrack_seqadj.h>
25#include <net/netfilter/nf_conntrack_zones.h> 23#include <net/netfilter/nf_conntrack_zones.h>
26#include <linux/netfilter/nf_nat.h> 24#include <net/netfilter/nf_nat.h>
25#include <net/netfilter/nf_nat_helper.h>
26#include <uapi/linux/netfilter/nf_nat.h>
27 27
28#include "nf_internals.h" 28#include "nf_internals.h"
29 29
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 013d28899cab..e4a68dc42694 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2853,7 +2853,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
2853 return nft_table_validate(net, table); 2853 return nft_table_validate(net, table);
2854 2854
2855 if (chain->flags & NFT_CHAIN_HW_OFFLOAD) { 2855 if (chain->flags & NFT_CHAIN_HW_OFFLOAD) {
2856 flow = nft_flow_rule_create(rule); 2856 flow = nft_flow_rule_create(net, rule);
2857 if (IS_ERR(flow)) 2857 if (IS_ERR(flow))
2858 return PTR_ERR(flow); 2858 return PTR_ERR(flow);
2859 2859
@@ -5151,7 +5151,7 @@ static int nf_tables_updobj(const struct nft_ctx *ctx,
5151 newobj = nft_obj_init(ctx, type, attr); 5151 newobj = nft_obj_init(ctx, type, attr);
5152 if (IS_ERR(newobj)) { 5152 if (IS_ERR(newobj)) {
5153 err = PTR_ERR(newobj); 5153 err = PTR_ERR(newobj);
5154 goto err1; 5154 goto err_free_trans;
5155 } 5155 }
5156 5156
5157 nft_trans_obj(trans) = obj; 5157 nft_trans_obj(trans) = obj;
@@ -5160,9 +5160,9 @@ static int nf_tables_updobj(const struct nft_ctx *ctx,
5160 list_add_tail(&trans->list, &ctx->net->nft.commit_list); 5160 list_add_tail(&trans->list, &ctx->net->nft.commit_list);
5161 5161
5162 return 0; 5162 return 0;
5163err1: 5163
5164err_free_trans:
5164 kfree(trans); 5165 kfree(trans);
5165 kfree(newobj);
5166 return err; 5166 return err;
5167} 5167}
5168 5168
@@ -7669,11 +7669,6 @@ static struct pernet_operations nf_tables_net_ops = {
7669 .exit = nf_tables_exit_net, 7669 .exit = nf_tables_exit_net,
7670}; 7670};
7671 7671
7672static struct flow_indr_block_ing_entry block_ing_entry = {
7673 .cb = nft_indr_block_get_and_ing_cmd,
7674 .list = LIST_HEAD_INIT(block_ing_entry.list),
7675};
7676
7677static int __init nf_tables_module_init(void) 7672static int __init nf_tables_module_init(void)
7678{ 7673{
7679 int err; 7674 int err;
@@ -7699,14 +7694,20 @@ static int __init nf_tables_module_init(void)
7699 if (err < 0) 7694 if (err < 0)
7700 goto err4; 7695 goto err4;
7701 7696
7697 err = nft_offload_init();
7698 if (err < 0)
7699 goto err5;
7700
7702 /* must be last */ 7701 /* must be last */
7703 err = nfnetlink_subsys_register(&nf_tables_subsys); 7702 err = nfnetlink_subsys_register(&nf_tables_subsys);
7704 if (err < 0) 7703 if (err < 0)
7705 goto err5; 7704 goto err6;
7706 7705
7707 nft_chain_route_init(); 7706 nft_chain_route_init();
7708 flow_indr_add_block_ing_cb(&block_ing_entry); 7707
7709 return err; 7708 return err;
7709err6:
7710 nft_offload_exit();
7710err5: 7711err5:
7711 rhltable_destroy(&nft_objname_ht); 7712 rhltable_destroy(&nft_objname_ht);
7712err4: 7713err4:
@@ -7722,8 +7723,8 @@ err1:
7722 7723
7723static void __exit nf_tables_module_exit(void) 7724static void __exit nf_tables_module_exit(void)
7724{ 7725{
7725 flow_indr_del_block_ing_cb(&block_ing_entry);
7726 nfnetlink_subsys_unregister(&nf_tables_subsys); 7726 nfnetlink_subsys_unregister(&nf_tables_subsys);
7727 nft_offload_exit();
7727 unregister_netdevice_notifier(&nf_tables_flowtable_notifier); 7728 unregister_netdevice_notifier(&nf_tables_flowtable_notifier);
7728 nft_chain_filter_fini(); 7729 nft_chain_filter_fini();
7729 nft_chain_route_fini(); 7730 nft_chain_route_fini();
diff --git a/net/netfilter/nf_tables_offload.c b/net/netfilter/nf_tables_offload.c
index 3c2725ade61b..21bb772cb4b7 100644
--- a/net/netfilter/nf_tables_offload.c
+++ b/net/netfilter/nf_tables_offload.c
@@ -28,13 +28,10 @@ static struct nft_flow_rule *nft_flow_rule_alloc(int num_actions)
28 return flow; 28 return flow;
29} 29}
30 30
31struct nft_flow_rule *nft_flow_rule_create(const struct nft_rule *rule) 31struct nft_flow_rule *nft_flow_rule_create(struct net *net,
32 const struct nft_rule *rule)
32{ 33{
33 struct nft_offload_ctx ctx = { 34 struct nft_offload_ctx *ctx;
34 .dep = {
35 .type = NFT_OFFLOAD_DEP_UNSPEC,
36 },
37 };
38 struct nft_flow_rule *flow; 35 struct nft_flow_rule *flow;
39 int num_actions = 0, err; 36 int num_actions = 0, err;
40 struct nft_expr *expr; 37 struct nft_expr *expr;
@@ -52,21 +49,32 @@ struct nft_flow_rule *nft_flow_rule_create(const struct nft_rule *rule)
52 return ERR_PTR(-ENOMEM); 49 return ERR_PTR(-ENOMEM);
53 50
54 expr = nft_expr_first(rule); 51 expr = nft_expr_first(rule);
52
53 ctx = kzalloc(sizeof(struct nft_offload_ctx), GFP_KERNEL);
54 if (!ctx) {
55 err = -ENOMEM;
56 goto err_out;
57 }
58 ctx->net = net;
59 ctx->dep.type = NFT_OFFLOAD_DEP_UNSPEC;
60
55 while (expr->ops && expr != nft_expr_last(rule)) { 61 while (expr->ops && expr != nft_expr_last(rule)) {
56 if (!expr->ops->offload) { 62 if (!expr->ops->offload) {
57 err = -EOPNOTSUPP; 63 err = -EOPNOTSUPP;
58 goto err_out; 64 goto err_out;
59 } 65 }
60 err = expr->ops->offload(&ctx, flow, expr); 66 err = expr->ops->offload(ctx, flow, expr);
61 if (err < 0) 67 if (err < 0)
62 goto err_out; 68 goto err_out;
63 69
64 expr = nft_expr_next(expr); 70 expr = nft_expr_next(expr);
65 } 71 }
66 flow->proto = ctx.dep.l3num; 72 flow->proto = ctx->dep.l3num;
73 kfree(ctx);
67 74
68 return flow; 75 return flow;
69err_out: 76err_out:
77 kfree(ctx);
70 nft_flow_rule_destroy(flow); 78 nft_flow_rule_destroy(flow);
71 79
72 return ERR_PTR(err); 80 return ERR_PTR(err);
@@ -74,6 +82,19 @@ err_out:
74 82
75void nft_flow_rule_destroy(struct nft_flow_rule *flow) 83void nft_flow_rule_destroy(struct nft_flow_rule *flow)
76{ 84{
85 struct flow_action_entry *entry;
86 int i;
87
88 flow_action_for_each(i, entry, &flow->rule->action) {
89 switch (entry->id) {
90 case FLOW_ACTION_REDIRECT:
91 case FLOW_ACTION_MIRRED:
92 dev_put(entry->dev);
93 break;
94 default:
95 break;
96 }
97 }
77 kfree(flow->rule); 98 kfree(flow->rule);
78 kfree(flow); 99 kfree(flow);
79} 100}
@@ -134,20 +155,20 @@ int nft_chain_offload_priority(struct nft_base_chain *basechain)
134 return 0; 155 return 0;
135} 156}
136 157
137static int nft_flow_offload_rule(struct nft_trans *trans, 158static int nft_flow_offload_rule(struct nft_chain *chain,
159 struct nft_rule *rule,
160 struct nft_flow_rule *flow,
138 enum flow_cls_command command) 161 enum flow_cls_command command)
139{ 162{
140 struct nft_flow_rule *flow = nft_trans_flow_rule(trans);
141 struct nft_rule *rule = nft_trans_rule(trans);
142 struct flow_cls_offload cls_flow = {}; 163 struct flow_cls_offload cls_flow = {};
143 struct nft_base_chain *basechain; 164 struct nft_base_chain *basechain;
144 struct netlink_ext_ack extack; 165 struct netlink_ext_ack extack;
145 __be16 proto = ETH_P_ALL; 166 __be16 proto = ETH_P_ALL;
146 167
147 if (!nft_is_base_chain(trans->ctx.chain)) 168 if (!nft_is_base_chain(chain))
148 return -EOPNOTSUPP; 169 return -EOPNOTSUPP;
149 170
150 basechain = nft_base_chain(trans->ctx.chain); 171 basechain = nft_base_chain(chain);
151 172
152 if (flow) 173 if (flow)
153 proto = flow->proto; 174 proto = flow->proto;
@@ -273,12 +294,13 @@ static int nft_indr_block_offload_cmd(struct nft_base_chain *chain,
273 294
274#define FLOW_SETUP_BLOCK TC_SETUP_BLOCK 295#define FLOW_SETUP_BLOCK TC_SETUP_BLOCK
275 296
276static int nft_flow_offload_chain(struct nft_trans *trans, 297static int nft_flow_offload_chain(struct nft_chain *chain,
298 u8 *ppolicy,
277 enum flow_block_command cmd) 299 enum flow_block_command cmd)
278{ 300{
279 struct nft_chain *chain = trans->ctx.chain;
280 struct nft_base_chain *basechain; 301 struct nft_base_chain *basechain;
281 struct net_device *dev; 302 struct net_device *dev;
303 u8 policy;
282 304
283 if (!nft_is_base_chain(chain)) 305 if (!nft_is_base_chain(chain))
284 return -EOPNOTSUPP; 306 return -EOPNOTSUPP;
@@ -288,10 +310,10 @@ static int nft_flow_offload_chain(struct nft_trans *trans,
288 if (!dev) 310 if (!dev)
289 return -EOPNOTSUPP; 311 return -EOPNOTSUPP;
290 312
313 policy = ppolicy ? *ppolicy : basechain->policy;
314
291 /* Only default policy to accept is supported for now. */ 315 /* Only default policy to accept is supported for now. */
292 if (cmd == FLOW_BLOCK_BIND && 316 if (cmd == FLOW_BLOCK_BIND && policy != -1 && policy != NF_ACCEPT)
293 nft_trans_chain_policy(trans) != -1 &&
294 nft_trans_chain_policy(trans) != NF_ACCEPT)
295 return -EOPNOTSUPP; 317 return -EOPNOTSUPP;
296 318
297 if (dev->netdev_ops->ndo_setup_tc) 319 if (dev->netdev_ops->ndo_setup_tc)
@@ -304,6 +326,7 @@ int nft_flow_rule_offload_commit(struct net *net)
304{ 326{
305 struct nft_trans *trans; 327 struct nft_trans *trans;
306 int err = 0; 328 int err = 0;
329 u8 policy;
307 330
308 list_for_each_entry(trans, &net->nft.commit_list, list) { 331 list_for_each_entry(trans, &net->nft.commit_list, list) {
309 if (trans->ctx.family != NFPROTO_NETDEV) 332 if (trans->ctx.family != NFPROTO_NETDEV)
@@ -314,13 +337,17 @@ int nft_flow_rule_offload_commit(struct net *net)
314 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD)) 337 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
315 continue; 338 continue;
316 339
317 err = nft_flow_offload_chain(trans, FLOW_BLOCK_BIND); 340 policy = nft_trans_chain_policy(trans);
341 err = nft_flow_offload_chain(trans->ctx.chain, &policy,
342 FLOW_BLOCK_BIND);
318 break; 343 break;
319 case NFT_MSG_DELCHAIN: 344 case NFT_MSG_DELCHAIN:
320 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD)) 345 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
321 continue; 346 continue;
322 347
323 err = nft_flow_offload_chain(trans, FLOW_BLOCK_UNBIND); 348 policy = nft_trans_chain_policy(trans);
349 err = nft_flow_offload_chain(trans->ctx.chain, &policy,
350 FLOW_BLOCK_BIND);
324 break; 351 break;
325 case NFT_MSG_NEWRULE: 352 case NFT_MSG_NEWRULE:
326 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD)) 353 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
@@ -330,14 +357,20 @@ int nft_flow_rule_offload_commit(struct net *net)
330 !(trans->ctx.flags & NLM_F_APPEND)) 357 !(trans->ctx.flags & NLM_F_APPEND))
331 return -EOPNOTSUPP; 358 return -EOPNOTSUPP;
332 359
333 err = nft_flow_offload_rule(trans, FLOW_CLS_REPLACE); 360 err = nft_flow_offload_rule(trans->ctx.chain,
361 nft_trans_rule(trans),
362 nft_trans_flow_rule(trans),
363 FLOW_CLS_REPLACE);
334 nft_flow_rule_destroy(nft_trans_flow_rule(trans)); 364 nft_flow_rule_destroy(nft_trans_flow_rule(trans));
335 break; 365 break;
336 case NFT_MSG_DELRULE: 366 case NFT_MSG_DELRULE:
337 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD)) 367 if (!(trans->ctx.chain->flags & NFT_CHAIN_HW_OFFLOAD))
338 continue; 368 continue;
339 369
340 err = nft_flow_offload_rule(trans, FLOW_CLS_DESTROY); 370 err = nft_flow_offload_rule(trans->ctx.chain,
371 nft_trans_rule(trans),
372 nft_trans_flow_rule(trans),
373 FLOW_CLS_DESTROY);
341 break; 374 break;
342 } 375 }
343 376
@@ -348,32 +381,103 @@ int nft_flow_rule_offload_commit(struct net *net)
348 return err; 381 return err;
349} 382}
350 383
351void nft_indr_block_get_and_ing_cmd(struct net_device *dev, 384static struct nft_chain *__nft_offload_get_chain(struct net_device *dev)
352 flow_indr_block_bind_cb_t *cb,
353 void *cb_priv,
354 enum flow_block_command command)
355{ 385{
386 struct nft_base_chain *basechain;
356 struct net *net = dev_net(dev); 387 struct net *net = dev_net(dev);
357 const struct nft_table *table; 388 const struct nft_table *table;
358 const struct nft_chain *chain; 389 struct nft_chain *chain;
359 390
360 list_for_each_entry_rcu(table, &net->nft.tables, list) { 391 list_for_each_entry(table, &net->nft.tables, list) {
361 if (table->family != NFPROTO_NETDEV) 392 if (table->family != NFPROTO_NETDEV)
362 continue; 393 continue;
363 394
364 list_for_each_entry_rcu(chain, &table->chains, list) { 395 list_for_each_entry(chain, &table->chains, list) {
365 if (nft_is_base_chain(chain)) { 396 if (!nft_is_base_chain(chain) ||
366 struct nft_base_chain *basechain; 397 !(chain->flags & NFT_CHAIN_HW_OFFLOAD))
367 398 continue;
368 basechain = nft_base_chain(chain); 399
369 if (!strncmp(basechain->dev_name, dev->name, 400 basechain = nft_base_chain(chain);
370 IFNAMSIZ)) { 401 if (strncmp(basechain->dev_name, dev->name, IFNAMSIZ))
371 nft_indr_block_ing_cmd(dev, basechain, 402 continue;
372 cb, cb_priv, 403
373 command); 404 return chain;
374 return;
375 }
376 }
377 } 405 }
378 } 406 }
407
408 return NULL;
409}
410
411static void nft_indr_block_cb(struct net_device *dev,
412 flow_indr_block_bind_cb_t *cb, void *cb_priv,
413 enum flow_block_command cmd)
414{
415 struct net *net = dev_net(dev);
416 struct nft_chain *chain;
417
418 mutex_lock(&net->nft.commit_mutex);
419 chain = __nft_offload_get_chain(dev);
420 if (chain) {
421 struct nft_base_chain *basechain;
422
423 basechain = nft_base_chain(chain);
424 nft_indr_block_ing_cmd(dev, basechain, cb, cb_priv, cmd);
425 }
426 mutex_unlock(&net->nft.commit_mutex);
427}
428
429static void nft_offload_chain_clean(struct nft_chain *chain)
430{
431 struct nft_rule *rule;
432
433 list_for_each_entry(rule, &chain->rules, list) {
434 nft_flow_offload_rule(chain, rule,
435 NULL, FLOW_CLS_DESTROY);
436 }
437
438 nft_flow_offload_chain(chain, NULL, FLOW_BLOCK_UNBIND);
439}
440
441static int nft_offload_netdev_event(struct notifier_block *this,
442 unsigned long event, void *ptr)
443{
444 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
445 struct net *net = dev_net(dev);
446 struct nft_chain *chain;
447
448 mutex_lock(&net->nft.commit_mutex);
449 chain = __nft_offload_get_chain(dev);
450 if (chain)
451 nft_offload_chain_clean(chain);
452 mutex_unlock(&net->nft.commit_mutex);
453
454 return NOTIFY_DONE;
455}
456
457static struct flow_indr_block_ing_entry block_ing_entry = {
458 .cb = nft_indr_block_cb,
459 .list = LIST_HEAD_INIT(block_ing_entry.list),
460};
461
462static struct notifier_block nft_offload_netdev_notifier = {
463 .notifier_call = nft_offload_netdev_event,
464};
465
466int nft_offload_init(void)
467{
468 int err;
469
470 err = register_netdevice_notifier(&nft_offload_netdev_notifier);
471 if (err < 0)
472 return err;
473
474 flow_indr_add_block_ing_cb(&block_ing_entry);
475
476 return 0;
477}
478
479void nft_offload_exit(void)
480{
481 flow_indr_del_block_ing_cb(&block_ing_entry);
482 unregister_netdevice_notifier(&nft_offload_netdev_notifier);
379} 483}
diff --git a/net/netfilter/nft_dup_netdev.c b/net/netfilter/nft_dup_netdev.c
index c6052fdd2c40..c2e78c160fd7 100644
--- a/net/netfilter/nft_dup_netdev.c
+++ b/net/netfilter/nft_dup_netdev.c
@@ -10,6 +10,7 @@
10#include <linux/netfilter.h> 10#include <linux/netfilter.h>
11#include <linux/netfilter/nf_tables.h> 11#include <linux/netfilter/nf_tables.h>
12#include <net/netfilter/nf_tables.h> 12#include <net/netfilter/nf_tables.h>
13#include <net/netfilter/nf_tables_offload.h>
13#include <net/netfilter/nf_dup_netdev.h> 14#include <net/netfilter/nf_dup_netdev.h>
14 15
15struct nft_dup_netdev { 16struct nft_dup_netdev {
@@ -56,6 +57,16 @@ nla_put_failure:
56 return -1; 57 return -1;
57} 58}
58 59
60static int nft_dup_netdev_offload(struct nft_offload_ctx *ctx,
61 struct nft_flow_rule *flow,
62 const struct nft_expr *expr)
63{
64 const struct nft_dup_netdev *priv = nft_expr_priv(expr);
65 int oif = ctx->regs[priv->sreg_dev].data.data[0];
66
67 return nft_fwd_dup_netdev_offload(ctx, flow, FLOW_ACTION_MIRRED, oif);
68}
69
59static struct nft_expr_type nft_dup_netdev_type; 70static struct nft_expr_type nft_dup_netdev_type;
60static const struct nft_expr_ops nft_dup_netdev_ops = { 71static const struct nft_expr_ops nft_dup_netdev_ops = {
61 .type = &nft_dup_netdev_type, 72 .type = &nft_dup_netdev_type,
@@ -63,6 +74,7 @@ static const struct nft_expr_ops nft_dup_netdev_ops = {
63 .eval = nft_dup_netdev_eval, 74 .eval = nft_dup_netdev_eval,
64 .init = nft_dup_netdev_init, 75 .init = nft_dup_netdev_init,
65 .dump = nft_dup_netdev_dump, 76 .dump = nft_dup_netdev_dump,
77 .offload = nft_dup_netdev_offload,
66}; 78};
67 79
68static struct nft_expr_type nft_dup_netdev_type __read_mostly = { 80static struct nft_expr_type nft_dup_netdev_type __read_mostly = {
diff --git a/net/netfilter/nft_flow_offload.c b/net/netfilter/nft_flow_offload.c
index 01705ad74a9a..22cf236eb5d5 100644
--- a/net/netfilter/nft_flow_offload.c
+++ b/net/netfilter/nft_flow_offload.c
@@ -6,12 +6,13 @@
6#include <linux/netfilter.h> 6#include <linux/netfilter.h>
7#include <linux/workqueue.h> 7#include <linux/workqueue.h>
8#include <linux/spinlock.h> 8#include <linux/spinlock.h>
9#include <linux/netfilter/nf_conntrack_common.h>
9#include <linux/netfilter/nf_tables.h> 10#include <linux/netfilter/nf_tables.h>
10#include <net/ip.h> /* for ipv4 options. */ 11#include <net/ip.h> /* for ipv4 options. */
11#include <net/netfilter/nf_tables.h> 12#include <net/netfilter/nf_tables.h>
12#include <net/netfilter/nf_tables_core.h> 13#include <net/netfilter/nf_tables_core.h>
13#include <net/netfilter/nf_conntrack_core.h> 14#include <net/netfilter/nf_conntrack_core.h>
14#include <linux/netfilter/nf_conntrack_common.h> 15#include <net/netfilter/nf_conntrack_extend.h>
15#include <net/netfilter/nf_flow_table.h> 16#include <net/netfilter/nf_flow_table.h>
16 17
17struct nft_flow_offload { 18struct nft_flow_offload {
diff --git a/net/netfilter/nft_fwd_netdev.c b/net/netfilter/nft_fwd_netdev.c
index 61b7f93ac681..aba11c2333f3 100644
--- a/net/netfilter/nft_fwd_netdev.c
+++ b/net/netfilter/nft_fwd_netdev.c
@@ -12,6 +12,7 @@
12#include <linux/ip.h> 12#include <linux/ip.h>
13#include <linux/ipv6.h> 13#include <linux/ipv6.h>
14#include <net/netfilter/nf_tables.h> 14#include <net/netfilter/nf_tables.h>
15#include <net/netfilter/nf_tables_offload.h>
15#include <net/netfilter/nf_dup_netdev.h> 16#include <net/netfilter/nf_dup_netdev.h>
16#include <net/neighbour.h> 17#include <net/neighbour.h>
17#include <net/ip.h> 18#include <net/ip.h>
@@ -63,6 +64,16 @@ nla_put_failure:
63 return -1; 64 return -1;
64} 65}
65 66
67static int nft_fwd_netdev_offload(struct nft_offload_ctx *ctx,
68 struct nft_flow_rule *flow,
69 const struct nft_expr *expr)
70{
71 const struct nft_fwd_netdev *priv = nft_expr_priv(expr);
72 int oif = ctx->regs[priv->sreg_dev].data.data[0];
73
74 return nft_fwd_dup_netdev_offload(ctx, flow, FLOW_ACTION_REDIRECT, oif);
75}
76
66struct nft_fwd_neigh { 77struct nft_fwd_neigh {
67 enum nft_registers sreg_dev:8; 78 enum nft_registers sreg_dev:8;
68 enum nft_registers sreg_addr:8; 79 enum nft_registers sreg_addr:8;
@@ -194,6 +205,7 @@ static const struct nft_expr_ops nft_fwd_netdev_ops = {
194 .eval = nft_fwd_netdev_eval, 205 .eval = nft_fwd_netdev_eval,
195 .init = nft_fwd_netdev_init, 206 .init = nft_fwd_netdev_init,
196 .dump = nft_fwd_netdev_dump, 207 .dump = nft_fwd_netdev_dump,
208 .offload = nft_fwd_netdev_offload,
197}; 209};
198 210
199static const struct nft_expr_ops * 211static const struct nft_expr_ops *
diff --git a/net/netfilter/nft_synproxy.c b/net/netfilter/nft_synproxy.c
index db4c23f5dfcb..e2c1fc608841 100644
--- a/net/netfilter/nft_synproxy.c
+++ b/net/netfilter/nft_synproxy.c
@@ -24,7 +24,7 @@ static void nft_synproxy_tcp_options(struct synproxy_options *opts,
24 const struct tcphdr *tcp, 24 const struct tcphdr *tcp,
25 struct synproxy_net *snet, 25 struct synproxy_net *snet,
26 struct nf_synproxy_info *info, 26 struct nf_synproxy_info *info,
27 struct nft_synproxy *priv) 27 const struct nft_synproxy *priv)
28{ 28{
29 this_cpu_inc(snet->stats->syn_received); 29 this_cpu_inc(snet->stats->syn_received);
30 if (tcp->ece && tcp->cwr) 30 if (tcp->ece && tcp->cwr)
@@ -41,14 +41,13 @@ static void nft_synproxy_tcp_options(struct synproxy_options *opts,
41 NF_SYNPROXY_OPT_ECN); 41 NF_SYNPROXY_OPT_ECN);
42} 42}
43 43
44static void nft_synproxy_eval_v4(const struct nft_expr *expr, 44static void nft_synproxy_eval_v4(const struct nft_synproxy *priv,
45 struct nft_regs *regs, 45 struct nft_regs *regs,
46 const struct nft_pktinfo *pkt, 46 const struct nft_pktinfo *pkt,
47 const struct tcphdr *tcp, 47 const struct tcphdr *tcp,
48 struct tcphdr *_tcph, 48 struct tcphdr *_tcph,
49 struct synproxy_options *opts) 49 struct synproxy_options *opts)
50{ 50{
51 struct nft_synproxy *priv = nft_expr_priv(expr);
52 struct nf_synproxy_info info = priv->info; 51 struct nf_synproxy_info info = priv->info;
53 struct net *net = nft_net(pkt); 52 struct net *net = nft_net(pkt);
54 struct synproxy_net *snet = synproxy_pernet(net); 53 struct synproxy_net *snet = synproxy_pernet(net);
@@ -73,14 +72,13 @@ static void nft_synproxy_eval_v4(const struct nft_expr *expr,
73} 72}
74 73
75#if IS_ENABLED(CONFIG_NF_TABLES_IPV6) 74#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
76static void nft_synproxy_eval_v6(const struct nft_expr *expr, 75static void nft_synproxy_eval_v6(const struct nft_synproxy *priv,
77 struct nft_regs *regs, 76 struct nft_regs *regs,
78 const struct nft_pktinfo *pkt, 77 const struct nft_pktinfo *pkt,
79 const struct tcphdr *tcp, 78 const struct tcphdr *tcp,
80 struct tcphdr *_tcph, 79 struct tcphdr *_tcph,
81 struct synproxy_options *opts) 80 struct synproxy_options *opts)
82{ 81{
83 struct nft_synproxy *priv = nft_expr_priv(expr);
84 struct nf_synproxy_info info = priv->info; 82 struct nf_synproxy_info info = priv->info;
85 struct net *net = nft_net(pkt); 83 struct net *net = nft_net(pkt);
86 struct synproxy_net *snet = synproxy_pernet(net); 84 struct synproxy_net *snet = synproxy_pernet(net);
@@ -105,9 +103,9 @@ static void nft_synproxy_eval_v6(const struct nft_expr *expr,
105} 103}
106#endif /* CONFIG_NF_TABLES_IPV6*/ 104#endif /* CONFIG_NF_TABLES_IPV6*/
107 105
108static void nft_synproxy_eval(const struct nft_expr *expr, 106static void nft_synproxy_do_eval(const struct nft_synproxy *priv,
109 struct nft_regs *regs, 107 struct nft_regs *regs,
110 const struct nft_pktinfo *pkt) 108 const struct nft_pktinfo *pkt)
111{ 109{
112 struct synproxy_options opts = {}; 110 struct synproxy_options opts = {};
113 struct sk_buff *skb = pkt->skb; 111 struct sk_buff *skb = pkt->skb;
@@ -140,23 +138,22 @@ static void nft_synproxy_eval(const struct nft_expr *expr,
140 138
141 switch (skb->protocol) { 139 switch (skb->protocol) {
142 case htons(ETH_P_IP): 140 case htons(ETH_P_IP):
143 nft_synproxy_eval_v4(expr, regs, pkt, tcp, &_tcph, &opts); 141 nft_synproxy_eval_v4(priv, regs, pkt, tcp, &_tcph, &opts);
144 return; 142 return;
145#if IS_ENABLED(CONFIG_NF_TABLES_IPV6) 143#if IS_ENABLED(CONFIG_NF_TABLES_IPV6)
146 case htons(ETH_P_IPV6): 144 case htons(ETH_P_IPV6):
147 nft_synproxy_eval_v6(expr, regs, pkt, tcp, &_tcph, &opts); 145 nft_synproxy_eval_v6(priv, regs, pkt, tcp, &_tcph, &opts);
148 return; 146 return;
149#endif 147#endif
150 } 148 }
151 regs->verdict.code = NFT_BREAK; 149 regs->verdict.code = NFT_BREAK;
152} 150}
153 151
154static int nft_synproxy_init(const struct nft_ctx *ctx, 152static int nft_synproxy_do_init(const struct nft_ctx *ctx,
155 const struct nft_expr *expr, 153 const struct nlattr * const tb[],
156 const struct nlattr * const tb[]) 154 struct nft_synproxy *priv)
157{ 155{
158 struct synproxy_net *snet = synproxy_pernet(ctx->net); 156 struct synproxy_net *snet = synproxy_pernet(ctx->net);
159 struct nft_synproxy *priv = nft_expr_priv(expr);
160 u32 flags; 157 u32 flags;
161 int err; 158 int err;
162 159
@@ -206,8 +203,7 @@ nf_ct_failure:
206 return err; 203 return err;
207} 204}
208 205
209static void nft_synproxy_destroy(const struct nft_ctx *ctx, 206static void nft_synproxy_do_destroy(const struct nft_ctx *ctx)
210 const struct nft_expr *expr)
211{ 207{
212 struct synproxy_net *snet = synproxy_pernet(ctx->net); 208 struct synproxy_net *snet = synproxy_pernet(ctx->net);
213 209
@@ -229,10 +225,8 @@ static void nft_synproxy_destroy(const struct nft_ctx *ctx,
229 nf_ct_netns_put(ctx->net, ctx->family); 225 nf_ct_netns_put(ctx->net, ctx->family);
230} 226}
231 227
232static int nft_synproxy_dump(struct sk_buff *skb, const struct nft_expr *expr) 228static int nft_synproxy_do_dump(struct sk_buff *skb, struct nft_synproxy *priv)
233{ 229{
234 const struct nft_synproxy *priv = nft_expr_priv(expr);
235
236 if (nla_put_be16(skb, NFTA_SYNPROXY_MSS, htons(priv->info.mss)) || 230 if (nla_put_be16(skb, NFTA_SYNPROXY_MSS, htons(priv->info.mss)) ||
237 nla_put_u8(skb, NFTA_SYNPROXY_WSCALE, priv->info.wscale) || 231 nla_put_u8(skb, NFTA_SYNPROXY_WSCALE, priv->info.wscale) ||
238 nla_put_be32(skb, NFTA_SYNPROXY_FLAGS, htonl(priv->info.options))) 232 nla_put_be32(skb, NFTA_SYNPROXY_FLAGS, htonl(priv->info.options)))
@@ -244,6 +238,15 @@ nla_put_failure:
244 return -1; 238 return -1;
245} 239}
246 240
241static void nft_synproxy_eval(const struct nft_expr *expr,
242 struct nft_regs *regs,
243 const struct nft_pktinfo *pkt)
244{
245 const struct nft_synproxy *priv = nft_expr_priv(expr);
246
247 nft_synproxy_do_eval(priv, regs, pkt);
248}
249
247static int nft_synproxy_validate(const struct nft_ctx *ctx, 250static int nft_synproxy_validate(const struct nft_ctx *ctx,
248 const struct nft_expr *expr, 251 const struct nft_expr *expr,
249 const struct nft_data **data) 252 const struct nft_data **data)
@@ -252,6 +255,28 @@ static int nft_synproxy_validate(const struct nft_ctx *ctx,
252 (1 << NF_INET_FORWARD)); 255 (1 << NF_INET_FORWARD));
253} 256}
254 257
258static int nft_synproxy_init(const struct nft_ctx *ctx,
259 const struct nft_expr *expr,
260 const struct nlattr * const tb[])
261{
262 struct nft_synproxy *priv = nft_expr_priv(expr);
263
264 return nft_synproxy_do_init(ctx, tb, priv);
265}
266
267static void nft_synproxy_destroy(const struct nft_ctx *ctx,
268 const struct nft_expr *expr)
269{
270 nft_synproxy_do_destroy(ctx);
271}
272
273static int nft_synproxy_dump(struct sk_buff *skb, const struct nft_expr *expr)
274{
275 struct nft_synproxy *priv = nft_expr_priv(expr);
276
277 return nft_synproxy_do_dump(skb, priv);
278}
279
255static struct nft_expr_type nft_synproxy_type; 280static struct nft_expr_type nft_synproxy_type;
256static const struct nft_expr_ops nft_synproxy_ops = { 281static const struct nft_expr_ops nft_synproxy_ops = {
257 .eval = nft_synproxy_eval, 282 .eval = nft_synproxy_eval,
@@ -271,14 +296,89 @@ static struct nft_expr_type nft_synproxy_type __read_mostly = {
271 .maxattr = NFTA_SYNPROXY_MAX, 296 .maxattr = NFTA_SYNPROXY_MAX,
272}; 297};
273 298
299static int nft_synproxy_obj_init(const struct nft_ctx *ctx,
300 const struct nlattr * const tb[],
301 struct nft_object *obj)
302{
303 struct nft_synproxy *priv = nft_obj_data(obj);
304
305 return nft_synproxy_do_init(ctx, tb, priv);
306}
307
308static void nft_synproxy_obj_destroy(const struct nft_ctx *ctx,
309 struct nft_object *obj)
310{
311 nft_synproxy_do_destroy(ctx);
312}
313
314static int nft_synproxy_obj_dump(struct sk_buff *skb,
315 struct nft_object *obj, bool reset)
316{
317 struct nft_synproxy *priv = nft_obj_data(obj);
318
319 return nft_synproxy_do_dump(skb, priv);
320}
321
322static void nft_synproxy_obj_eval(struct nft_object *obj,
323 struct nft_regs *regs,
324 const struct nft_pktinfo *pkt)
325{
326 const struct nft_synproxy *priv = nft_obj_data(obj);
327
328 nft_synproxy_do_eval(priv, regs, pkt);
329}
330
331static void nft_synproxy_obj_update(struct nft_object *obj,
332 struct nft_object *newobj)
333{
334 struct nft_synproxy *newpriv = nft_obj_data(newobj);
335 struct nft_synproxy *priv = nft_obj_data(obj);
336
337 priv->info = newpriv->info;
338}
339
340static struct nft_object_type nft_synproxy_obj_type;
341static const struct nft_object_ops nft_synproxy_obj_ops = {
342 .type = &nft_synproxy_obj_type,
343 .size = sizeof(struct nft_synproxy),
344 .init = nft_synproxy_obj_init,
345 .destroy = nft_synproxy_obj_destroy,
346 .dump = nft_synproxy_obj_dump,
347 .eval = nft_synproxy_obj_eval,
348 .update = nft_synproxy_obj_update,
349};
350
351static struct nft_object_type nft_synproxy_obj_type __read_mostly = {
352 .type = NFT_OBJECT_SYNPROXY,
353 .ops = &nft_synproxy_obj_ops,
354 .maxattr = NFTA_SYNPROXY_MAX,
355 .policy = nft_synproxy_policy,
356 .owner = THIS_MODULE,
357};
358
274static int __init nft_synproxy_module_init(void) 359static int __init nft_synproxy_module_init(void)
275{ 360{
276 return nft_register_expr(&nft_synproxy_type); 361 int err;
362
363 err = nft_register_obj(&nft_synproxy_obj_type);
364 if (err < 0)
365 return err;
366
367 err = nft_register_expr(&nft_synproxy_type);
368 if (err < 0)
369 goto err;
370
371 return 0;
372
373err:
374 nft_unregister_obj(&nft_synproxy_obj_type);
375 return err;
277} 376}
278 377
279static void __exit nft_synproxy_module_exit(void) 378static void __exit nft_synproxy_module_exit(void)
280{ 379{
281 return nft_unregister_expr(&nft_synproxy_type); 380 nft_unregister_expr(&nft_synproxy_type);
381 nft_unregister_obj(&nft_synproxy_obj_type);
282} 382}
283 383
284module_init(nft_synproxy_module_init); 384module_init(nft_synproxy_module_init);
@@ -287,3 +387,4 @@ module_exit(nft_synproxy_module_exit);
287MODULE_LICENSE("GPL"); 387MODULE_LICENSE("GPL");
288MODULE_AUTHOR("Fernando Fernandez <ffmancera@riseup.net>"); 388MODULE_AUTHOR("Fernando Fernandez <ffmancera@riseup.net>");
289MODULE_ALIAS_NFT_EXPR("synproxy"); 389MODULE_ALIAS_NFT_EXPR("synproxy");
390MODULE_ALIAS_NFT_OBJ(NFT_OBJECT_SYNPROXY);
diff --git a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
index bc6c8ab0fa62..46fcac75f726 100644
--- a/net/netfilter/xt_connlimit.c
+++ b/net/netfilter/xt_connlimit.c
@@ -13,6 +13,8 @@
13 */ 13 */
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 15
16#include <linux/ip.h>
17#include <linux/ipv6.h>
16#include <linux/module.h> 18#include <linux/module.h>
17#include <linux/skbuff.h> 19#include <linux/skbuff.h>
18#include <linux/netfilter/x_tables.h> 20#include <linux/netfilter/x_tables.h>
diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
index 2d2691dd51e0..ced3fc8fad7c 100644
--- a/net/netfilter/xt_hashlimit.c
+++ b/net/netfilter/xt_hashlimit.c
@@ -34,9 +34,14 @@
34#include <linux/netfilter/x_tables.h> 34#include <linux/netfilter/x_tables.h>
35#include <linux/netfilter_ipv4/ip_tables.h> 35#include <linux/netfilter_ipv4/ip_tables.h>
36#include <linux/netfilter_ipv6/ip6_tables.h> 36#include <linux/netfilter_ipv6/ip6_tables.h>
37#include <linux/netfilter/xt_hashlimit.h>
38#include <linux/mutex.h> 37#include <linux/mutex.h>
39#include <linux/kernel.h> 38#include <linux/kernel.h>
39#include <uapi/linux/netfilter/xt_hashlimit.h>
40
41#define XT_HASHLIMIT_ALL (XT_HASHLIMIT_HASH_DIP | XT_HASHLIMIT_HASH_DPT | \
42 XT_HASHLIMIT_HASH_SIP | XT_HASHLIMIT_HASH_SPT | \
43 XT_HASHLIMIT_INVERT | XT_HASHLIMIT_BYTES |\
44 XT_HASHLIMIT_RATE_MATCH)
40 45
41MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
42MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>"); 47MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
diff --git a/net/netfilter/xt_physdev.c b/net/netfilter/xt_physdev.c
index b92b22ce8abd..ec6ed6fda96c 100644
--- a/net/netfilter/xt_physdev.c
+++ b/net/netfilter/xt_physdev.c
@@ -5,12 +5,13 @@
5/* (C) 2001-2003 Bart De Schuymer <bdschuym@pandora.be> 5/* (C) 2001-2003 Bart De Schuymer <bdschuym@pandora.be>
6 */ 6 */
7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8
9#include <linux/if.h>
8#include <linux/module.h> 10#include <linux/module.h>
9#include <linux/skbuff.h> 11#include <linux/skbuff.h>
10#include <linux/netfilter_bridge.h> 12#include <linux/netfilter_bridge.h>
11#include <linux/netfilter/xt_physdev.h>
12#include <linux/netfilter/x_tables.h> 13#include <linux/netfilter/x_tables.h>
13#include <net/netfilter/br_netfilter.h> 14#include <uapi/linux/netfilter/xt_physdev.h>
14 15
15MODULE_LICENSE("GPL"); 16MODULE_LICENSE("GPL");
16MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>"); 17MODULE_AUTHOR("Bart De Schuymer <bdschuym@pandora.be>");
diff --git a/net/sched/act_ct.c b/net/sched/act_ct.c
index cdd6f3818097..fcc46025e790 100644
--- a/net/sched/act_ct.c
+++ b/net/sched/act_ct.c
@@ -24,12 +24,12 @@
24#include <uapi/linux/tc_act/tc_ct.h> 24#include <uapi/linux/tc_act/tc_ct.h>
25#include <net/tc_act/tc_ct.h> 25#include <net/tc_act/tc_ct.h>
26 26
27#include <linux/netfilter/nf_nat.h>
28#include <net/netfilter/nf_conntrack.h> 27#include <net/netfilter/nf_conntrack.h>
29#include <net/netfilter/nf_conntrack_core.h> 28#include <net/netfilter/nf_conntrack_core.h>
30#include <net/netfilter/nf_conntrack_zones.h> 29#include <net/netfilter/nf_conntrack_zones.h>
31#include <net/netfilter/nf_conntrack_helper.h> 30#include <net/netfilter/nf_conntrack_helper.h>
32#include <net/netfilter/ipv6/nf_defrag_ipv6.h> 31#include <net/netfilter/ipv6/nf_defrag_ipv6.h>
32#include <uapi/linux/netfilter/nf_nat.h>
33 33
34static struct tc_action_ops act_ct_ops; 34static struct tc_action_ops act_ct_ops;
35static unsigned int ct_net_id; 35static unsigned int ct_net_id;