Netfilter/IPVS updates for net-next
Subsystems (6)
Pablo Neira Ayuso
maintainercover Netfilter/IPVS updates for net-next
Hi David,
The following patchset contains Netfilter/IPVS updates for net-next:
1) Add .release_ops to properly unroll .select_ops, use it from nft_compat. After this change, we can remove list of extensions too to simplify this codebase.
2) Update amanda conntrack helper to support v3.4, from Florian Tham.
3) Get rid of the obsolete BUGPRINT macro in ebtables, from Florian Westphal.
4) Merge IPv4 and IPv6 masquerading infrastructure into one single module. From Florian Westphal.
5) Patchset to remove nf_nat_l3proto structure to get rid of indirections, from Florian Westphal.
6) Skip unnecessary conntrack timeout updates in case the value is still the same, also from Florian Westphal.
7) Remove unnecessary 'fall through' comments in empty switch cases, from Li RongQing.
8) Fix lookup to fixed size hashtable sets on big endian with 32-bit keys.
9) Incorrect logic to deactivate path of fixed size hashtable sets, element was being tested to self.
10) Remove nft_hash_key(), the bitmap set is always selected for 16-bit keys.
11) Use boolean whenever possible in IPVS codebase, from Andrea Claudi.
12) Enter close state in conntrack if RST matches exact sequence number, from Florian Westphal.
13) Initialize dst_cache in tunnel extension, from wenxu.
14) Pass protocol as u16 to xt_check_match and xt_check_target, from Li RongQing.
15) SCTP header is granted to be in a linear area from IPVS NAT handler, from Xin Long.
16) Don't steal packets coming from slave VRF device from the ip_sabotage_in() path, from David Ahern.
17) Fix unsafe update of basechain stats, from Li RongQing.
18) Make sure CONNTRACK_LOCKS is power of 2 to let compiler optimize modulo operation as bitwise AND, from Li RongQing.
19) Use device_attribute instead of internal definition in the IDLETIMER target, from Sami Tolvanen.
20) Merge redir, masq and IPv4/IPv6 NAT chain types, from Florian Westphal.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit ff8285f81822dc8f528b36b6c5c8ab132367e92d:
net: sched: pie: fix 64-bit division (2019-02-26 18:55:38 -0800)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to db8ab38880e06dedbfc879e75f5b0ddc495f4eb6:
netfilter: nf_tables: merge ipv4 and ipv6 nat chain types (2019-03-01 14:36:59 +0100)
----------------------------------------------------------------
Andrea Claudi (1):
ipvs: change some data types from int to bool
David Ahern (1):
netfilter: bridge: Don't sabotage nf_hook calls for an l3mdev slave
Florian Tham (1):
netfilter: nf_conntrack_amanda: add support for STATE streams
Florian Westphal (15):
netfilter: ebtables: remove BUGPRINT messages
netfilter: nat: merge ipv4 and ipv6 masquerade functionality
netfilter: nat: move nlattr parse and xfrm session decode to core
netfilter: nat: merge nf_nat_ipv4,6 into nat core
netfilter: nat: remove nf_nat_l4proto.h
netfilter: nat: remove l3 manip_pkt hook
netfilter: nat: remove csum_update hook
netfilter: nat: remove csum_recalc hook
netfilter: nat: remove l3proto struct
netfilter: nat: remove nf_nat_l3proto.h and nf_nat_core.h
netfilter: conntrack: avoid same-timeout update
netfilter: conntrack: tcp: only close if RST matches exact sequence
netfilter: nf_tables: nat: merge nft_redir protocol specific modules
netfilter: nf_tables: nat: merge nft_masq protocol specific modules
netfilter: nf_tables: merge ipv4 and ipv6 nat chain types
Li RongQing (4):
netfilter: remove unneeded switch fall-through
netfilter: convert the proto argument from u8 to u16
netfilter: nf_tables: check the result of dereferencing base_chain->stats
netfilter: nf_conntrack: ensure that CONNTRACK_LOCKS is power of 2
Pablo Neira Ayuso (4):
netfilter: nft_compat: use .release_ops and remove list of extension
netfilter: nft_set_hash: fix lookups with fixed size hash on big endian
netfilter: nft_set_hash: bogus element self comparison from deactivation path
netfilter: nft_set_hash: remove nft_hash_key()
Sami Tolvanen (1):
netfilter: xt_IDLETIMER: fix sysfs callback function type
Xin Long (1):
ipvs: get sctphdr by sctphoff in sctp_csum_check
wenxu (1):
netfilter: nft_tunnel: Add dst_cache support
include/linux/netfilter/x_tables.h | 4 +-
include/net/netfilter/nf_conntrack.h | 10 +-
include/net/netfilter/nf_nat.h | 45 +-
include/net/netfilter/nf_nat_core.h | 29 -
include/net/netfilter/nf_nat_l3proto.h | 50 --
include/net/netfilter/nf_nat_l4proto.h | 16 -
include/net/netfilter/nf_tables.h | 3 +
include/net/netfilter/nft_masq.h | 22 -
include/net/netfilter/nft_redir.h | 22 -
net/bridge/br_netfilter_hooks.c | 3 +-
net/bridge/netfilter/ebtables.c | 137 ++--
net/ipv4/netfilter/Kconfig | 50 +-
net/ipv4/netfilter/Makefile | 7 -
net/ipv4/netfilter/iptable_nat.c | 8 +-
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 388 -----------
net/ipv4/netfilter/nft_chain_nat_ipv4.c | 87 ---
net/ipv4/netfilter/nft_masq_ipv4.c | 90 ---
net/ipv4/netfilter/nft_redir_ipv4.c | 82 ---
net/ipv6/netfilter/Kconfig | 48 +-
net/ipv6/netfilter/Makefile | 7 -
net/ipv6/netfilter/ip6table_nat.c | 8 +-
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 427 ------------
net/ipv6/netfilter/nf_nat_masquerade_ipv6.c | 240 -------
net/ipv6/netfilter/nft_chain_nat_ipv6.c | 85 ---
net/ipv6/netfilter/nft_masq_ipv6.c | 91 ---
net/ipv6/netfilter/nft_redir_ipv6.c | 83 ---
net/netfilter/Kconfig | 14 +-
net/netfilter/Makefile | 3 +
net/netfilter/ipvs/ip_vs_ctl.c | 12 +-
net/netfilter/ipvs/ip_vs_ftp.c | 4 +-
net/netfilter/ipvs/ip_vs_proto_sctp.c | 7 +-
net/netfilter/ipvs/ip_vs_proto_tcp.c | 8 +-
net/netfilter/ipvs/ip_vs_proto_udp.c | 8 +-
net/netfilter/ipvs/ip_vs_xmit.c | 4 +-
net/netfilter/nf_conntrack_amanda.c | 9 +-
net/netfilter/nf_conntrack_core.c | 11 +-
net/netfilter/nf_conntrack_netlink.c | 2 +-
net/netfilter/nf_conntrack_proto_tcp.c | 50 +-
net/netfilter/nf_nat_core.c | 196 ++++--
net/netfilter/nf_nat_helper.c | 15 +-
.../nf_nat_masquerade.c} | 208 +++++-
net/netfilter/nf_nat_proto.c | 744 ++++++++++++++++++++-
net/netfilter/nf_tables_api.c | 7 +-
net/netfilter/nf_tables_core.c | 15 +-
net/netfilter/nft_chain_nat.c | 108 +++
net/netfilter/nft_compat.c | 281 ++------
net/netfilter/nft_masq.c | 180 ++++-
net/netfilter/nft_nat.c | 2 -
net/netfilter/nft_redir.c | 154 ++++-
net/netfilter/nft_set_hash.c | 38 +-
net/netfilter/nft_tunnel.c | 7 +
net/netfilter/x_tables.c | 4 +-
net/netfilter/xt_IDLETIMER.c | 14 +-
net/netfilter/xt_nat.c | 2 +-
net/openvswitch/Kconfig | 2 -
net/openvswitch/conntrack.c | 12 +-
tools/testing/selftests/net/config | 3 +-
57 files changed, 1747 insertions(+), 2419 deletions(-)
delete mode 100644 include/net/netfilter/nf_nat_core.h
delete mode 100644 include/net/netfilter/nf_nat_l3proto.h
delete mode 100644 include/net/netfilter/nf_nat_l4proto.h
delete mode 100644 include/net/netfilter/nft_masq.h
delete mode 100644 include/net/netfilter/nft_redir.h
delete mode 100644 net/ipv4/netfilter/nf_nat_l3proto_ipv4.c
delete mode 100644 net/ipv4/netfilter/nft_chain_nat_ipv4.c
delete mode 100644 net/ipv4/netfilter/nft_masq_ipv4.c
delete mode 100644 net/ipv4/netfilter/nft_redir_ipv4.c
delete mode 100644 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
delete mode 100644 net/ipv6/netfilter/nf_nat_masquerade_ipv6.c
delete mode 100644 net/ipv6/netfilter/nft_chain_nat_ipv6.c
delete mode 100644 net/ipv6/netfilter/nft_masq_ipv6.c
delete mode 100644 net/ipv6/netfilter/nft_redir_ipv6.c
rename net/{ipv4/netfilter/nf_nat_masquerade_ipv4.c => netfilter/nf_nat_masquerade.c} (51%)
create mode 100644 net/netfilter/nft_chain_nat.cPablo Neira Ayuso
maintainerPATCH 1/29 netfilter: nft_compat: use .release_ops and remove list of extension
Add .release_ops, that is called in case of error at a later stage in the expression initialization path, ie. .select_ops() has been already set up operations and that needs to be undone. This allows us to unwind .select_ops from the error path, ie. release the dynamic operations for this extension.
Moreover, allocate one single operation instead of recycling them, this comes at the cost of consuming a bit more memory per rule, but it simplifies the infrastructure.
--- include/net/netfilter/nf_tables.h | 3 + net/netfilter/nf_tables_api.c | 7 +- net/netfilter/nft_compat.c | 281 ++++++++------------------------------ 3 files changed, 64 insertions(+), 227 deletions(-)
include/net/netfilter/nf_tables.h +3 -0
@@ -690,10 +690,12 @@ static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb, gcb->elems[gcb->head.cnt++] = elem; } +struct nft_expr_ops ;/** * struct nft_expr_type - nf_tables expression type * * @select_ops: function to select nft_expr_ops +* @release_ops: release nft_expr_ops * @ops: default ops, used when no select_ops functions is present * @list: used internally * @name: Identifier
@@ -706,6 +708,7 @@ static inline void nft_set_gc_batch_add(struct nft_set_gc_batch *gcb,struct nft_expr_type {const struct nft_expr_ops *(*select_ops)(const struct nft_ctx *,const struct nlattr *const tb[]); +void (*release_ops)(const struct nft_expr_ops *ops);const struct nft_expr_ops *ops;struct list_head list;const char *name;
net/netfilter/nf_tables_api.c +6 -1
@@ -2172,6 +2172,7 @@ struct nft_expr *nft_expr_init(const struct nft_ctx *ctx, {struct nft_expr_info info;struct nft_expr *expr; +struct module *owner;int err; err =nf_tables_expr_parse (ctx, nla, &info);
@@ -2191,7 +2192,11 @@ struct nft_expr *nft_expr_init(const struct nft_ctx *ctx, err3:kfree (expr); err2: -module_put (info.ops->type->owner); + owner = info.ops->type->owner; +if (info.ops->type->release_ops) + info.ops->type->release_ops (info.ops); + +module_put (owner); err1:return ERR_PTR (err); }
net/netfilter/nft_compat.c +55 -226
439 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/29 netfilter: nf_conntrack_amanda: add support for STATE streams
In reply to Pablo Neira AyusoFrom: Florian Tham <[email protected]>
The Amanda CONNECT command has been updated to establish an optional fourth connection [0]. Previously, a CONNECT command would look like:
CONNECT DATA port0 MESG port1 INDEX port2
nf_conntrack_amanda analyses the CONNECT command string in order to learn the port numbers of the related DATA, MESG and INDEX streams. As of amanda v3.4, the CONNECT command can advertise an additional port:
CONNECT DATA port0 MESG port1 INDEX port2 STATE port3
The new STATE stream is not handled, thus the connection on the STATE port cannot be established.
The patch adds support for STATE streams to the amanda conntrack helper.
I tested with max_expected = 3, leaving the other patch hunks unmodified. Amanda reports "connection refused" and aborts. After I set max_expected to 4, the backup completes successfully.
--- net/netfilter/nf_conntrack_amanda.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
net/netfilter/nf_conntrack_amanda.c +7 -2
@@ -54,6 +54,7 @@ enum amanda_strings {SEARCH_DATA ,SEARCH_MESG ,SEARCH_INDEX , + SEARCH_STATE, }; static struct {
@@ -81,6 +82,10 @@ static struct { .string = "INDEX ", .len = 6, }, + [SEARCH_STATE] = { + .string = "STATE ", + .len = 6, + }, }; static int amanda_help(struct sk_buff *skb,
@@ -124,7 +129,7 @@ static int amanda_help(struct sk_buff *skb, goto out; stop += start; -for (i =SEARCH_DATA ; i <=SEARCH_INDEX ; i++) { +for (i =SEARCH_DATA ; i <=SEARCH_STATE ; i++) { off =skb_find_text (skb, start, stop, search[i].ts);if (off ==UINT_MAX )continue ;
@@ -168,7 +173,7 @@ static int amanda_help(struct sk_buff *skb, }static const struct nf_conntrack_expect_policy amanda_exp_policy = { - .max_expected =3 , + .max_expected =4 , .timeout =180 , };
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/29 netfilter: ebtables: remove BUGPRINT messages
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
They are however frequently triggered by syzkaller, so remove them.
ebtables userspace should never trigger any of these, so there is little value in making them pr_debug (or ratelimited).
--- net/bridge/netfilter/ebtables.c | 131 ++++++++++++---------------------------- 1 file changed, 39 insertions(+), 92 deletions(-)
net/bridge/netfilter/ebtables.c +39 -92
@@ -31,10 +31,6 @@/* needed for logical [in,out]-dev filtering */ #include "../br_private.h" -#define BUGPRINT(format, args...) printk("kernel msg: ebtables bug: please "\ - "report to author: "format, ## args) -/* #define BUGPRINT(format, args...) */ -/* Each cpu has its own set of counters, so there is no need for write_lock in * the softirq * For reading or updating the counters, the user context needs to
@@ -466,8 +462,6 @@ static int ebt_verify_pointers(const struct ebt_replace *repl,/* we make userspace set this right, * so there is no misunderstanding */ -BUGPRINT ("EBT_ENTRY_OR_ENTRIES shouldn't be set " -"in distinguisher\n" );return -EINVAL ; }if (i !=NF_BR_NUMHOOKS )
@@ -485,18 +479,14 @@ static int ebt_verify_pointers(const struct ebt_replace *repl, offset += e->next_offset; } } -if (offset != limit) { -BUGPRINT ("entries_size too small\n" ); +if (offset != limit)return -EINVAL ; - }/* check if all valid hooks have a chain */ for (i =0 ; i <NF_BR_NUMHOOKS ; i++) {if (!newinfo->hook_entry[i] && - (valid_hooks & (1 << i))) { -BUGPRINT ("Valid hook without chain\n" ); + (valid_hooks & (1 << i)))return -EINVAL ; - } }return 0 ; }
@@ -523,26 +513,20 @@ ebt_check_entry_size_and_hooks(const struct ebt_entry *e,/* this checks if the previous chain has as many entries * as it said it has */ -if (*n != *cnt) { -BUGPRINT ("nentries does not equal the nr of entries " -"in the chain\n" ); +if (*n != *cnt)return -EINVAL ; - } +if (((struct ebt_entries *)e)->policy !=EBT_DROP && ((struct ebt_entries *)e)->policy !=EBT_ACCEPT ) {/* only RETURN from udc */ if (i !=NF_BR_NUMHOOKS || - ((struct ebt_entries *)e)->policy !=EBT_RETURN ) { -BUGPRINT ("bad policy\n" ); + ((struct ebt_entries *)e)->policy !=EBT_RETURN )return -EINVAL ; - } }if (i ==NF_BR_NUMHOOKS )/* it's a user defined chain */ (*udc_cnt)++; -if (((struct ebt_entries *)e)->counter_offset != *totalcnt) { -BUGPRINT ("counter_offset != totalcnt" ); +if (((struct ebt_entries *)e)->counter_offset != *totalcnt)return -EINVAL ; - } *n = ((struct ebt_entries *)e)->nentries; *cnt =0 ;return 0 ;
@@ -550,15 +534,13 @@ ebt_check_entry_size_and_hooks(const struct ebt_entry *e,/* a plain old entry, heh */ if (sizeof (struct ebt_entry ) > e->watchers_offset || e->watchers_offset > e->target_offset || - e->target_offset >= e->next_offset) { -BUGPRINT ("entry offsets not in right order\n" ); + e->target_offset >= e->next_offset)return -EINVAL ; - } +/* this is not checked anywhere else */ -if (e->next_offset - e->target_offset <sizeof (struct ebt_entry_target )) { -BUGPRINT ("target size too small\n" ); +if (e->next_offset - e->target_offset <sizeof (struct ebt_entry_target ))return -EINVAL ; - } + (*cnt)++; (*totalcnt)++;return 0 ;
@@ -678,18 +660,15 @@ ebt_check_entry(struct ebt_entry *e, struct net *net,if (e->bitmask ==0 )return 0 ; -if (e->bitmask & ~EBT_F_MASK ) { -BUGPRINT ("Unknown flag for bitmask\n" ); +if (e->bitmask & ~EBT_F_MASK )return -EINVAL ; - } -if (e->invflags & ~EBT_INV_MASK ) { -BUGPRINT ("Unknown flag for inv bitmask\n" ); + +if (e->invflags & ~EBT_INV_MASK )return -EINVAL ; - } -if ((e->bitmask &EBT_NOPROTO ) && (e->bitmask &EBT_802_3 )) { -BUGPRINT ("NOPROTO & 802_3 not allowed\n" ); + +if ((e->bitmask &EBT_NOPROTO ) && (e->bitmask &EBT_802_3 ))return -EINVAL ; - } +/* what hook do we belong to? */ for (i =0 ; i <NF_BR_NUMHOOKS ; i++) {if (!newinfo->hook_entry[i])
@@ -748,13 +727,11 @@ ebt_check_entry(struct ebt_entry *e, struct net *net, t->u.target = target;if (t->u.target == &ebt_standard_target) {if (gap <sizeof (struct ebt_standard_target )) { -BUGPRINT ("Standard target size too big\n" ); ret = -EFAULT ; goto cleanup_watchers; }if (((struct ebt_standard_target *)t)->verdict < -NUM_STANDARD_TARGETS ) { -BUGPRINT ("Invalid standard target\n" ); ret = -EFAULT ; goto cleanup_watchers; }
@@ -813,10 +790,9 @@ static int check_chainloops(const struct ebt_entries *chain, struct ebt_cl_stackif (strcmp (t->u.name,EBT_STANDARD_TARGET )) goto letscontinue;if (e->target_offset +sizeof (struct ebt_standard_target ) > - e->next_offset) { -BUGPRINT ("Standard target size too big\n" ); + e->next_offset)return -1 ; - } + verdict = ((struct ebt_standard_target *)t)->verdict;if (verdict >=0 ) {/* jump to another chain */ struct ebt_entries *hlp2 =
@@ -825,14 +801,12 @@ static int check_chainloops(const struct ebt_entries *chain, struct ebt_cl_stackif (hlp2 == cl_s[i].cs.chaininfo)break ;/* bad destination or loop */ -if (i == udc_cnt) { -BUGPRINT ("bad destination\n" ); +if (i == udc_cnt)return -1 ; - } -if (cl_s[i].cs.n) { -BUGPRINT ("loop\n" ); + +if (cl_s[i].cs.n)return -1 ; - } +if (cl_s[i].hookmask & (1 << hooknr)) goto letscontinue;/* this can't be 0, so the loop test is correct */
@@ -865,24 +839,21 @@ static int translate_table(struct net *net, const char *name, i =0 ;while (i <NF_BR_NUMHOOKS && !newinfo->hook_entry[i]) i++; -if (i ==NF_BR_NUMHOOKS ) { -BUGPRINT ("No valid hooks specified\n" ); +if (i ==NF_BR_NUMHOOKS )return -EINVAL ; - } -if (newinfo->hook_entry[i] != (struct ebt_entries *)newinfo->entries) { -BUGPRINT ("Chains don't start at beginning\n" ); + +if (newinfo->hook_entry[i] != (struct ebt_entries *)newinfo->entries)return -EINVAL ; - } +/* make sure chains are ordered after each other in same order * as their corresponding hooks */ for (j = i +1 ; j <NF_BR_NUMHOOKS ; j++) {if (!newinfo->hook_entry[j])continue ; -if (newinfo->hook_entry[j] <= newinfo->hook_entry[i]) { -BUGPRINT ("Hook order must be followed\n" ); +if (newinfo->hook_entry[j] <= newinfo->hook_entry[i])return -EINVAL ; - } + i = j; }
@@ -900,15 +871,11 @@ static int translate_table(struct net *net, const char *name,if (ret !=0 )return ret; -if (i != j) { -BUGPRINT ("nentries does not equal the nr of entries in the " -"(last) chain\n" ); +if (i != j)return -EINVAL ; - } -if (k != newinfo->nentries) { -BUGPRINT ("Total nentries is wrong\n" ); + +if (k != newinfo->nentries)return -EINVAL ; - }/* get the location of the udc, put them in an array * while we're at it, allocate the chainstack
@@ -942,7 +909,6 @@ static int translate_table(struct net *net, const char *name, ebt_get_udc_positions, newinfo, &i, cl_s);/* sanity check */ if (i != udc_cnt) { -BUGPRINT ("i != udc_cnt\n" );vfree (cl_s);return -EFAULT ; }
@@ -1042,7 +1008,6 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl, goto free_unlock;if (repl->num_counters && repl->num_counters != t->private->nentries) { -BUGPRINT ("Wrong nr. of counters requested\n" ); ret = -EINVAL ; goto free_unlock; }
@@ -1118,15 +1083,12 @@ static int do_replace(struct net *net, const void __user *user,if (copy_from_user (&tmp, user,sizeof (tmp)) !=0 )return -EFAULT ; -if (len !=sizeof (tmp) + tmp.entries_size) { -BUGPRINT ("Wrong len argument\n" ); +if (len !=sizeof (tmp) + tmp.entries_size)return -EINVAL ; - } -if (tmp.entries_size ==0 ) { -BUGPRINT ("Entries_size never zero\n" ); +if (tmp.entries_size ==0 )return -EINVAL ; - } +/* overflow check */ if (tmp.nentries >= ((INT_MAX -sizeof (struct ebt_table_info )) /NR_CPUS -SMP_CACHE_BYTES ) /sizeof (struct ebt_counter ))
@@ -1153,7 +1115,6 @@ static int do_replace(struct net *net, const void __user *user, }if (copy_from_user ( newinfo->entries, tmp.entries, tmp.entries_size) !=0 ) { -BUGPRINT ("Couldn't copy entries from userspace\n" ); ret = -EFAULT ; goto free_entries; }
@@ -1194,10 +1155,8 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,if (input_table ==NULL || (repl = input_table->table) ==NULL || repl->entries ==NULL || repl->entries_size ==0 || - repl->counters !=NULL || input_table->private !=NULL ) { -BUGPRINT ("Bad table data for ebt_register_table!!!\n" ); + repl->counters !=NULL || input_table->private !=NULL )return -EINVAL ; - }/* Don't add one table to multiple lists. */ table =kmemdup (input_table,sizeof (struct ebt_table ),GFP_KERNEL );
@@ -1235,13 +1194,10 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table, ((char *)repl->hook_entry[i] - repl->entries); } ret =translate_table (net, repl->name, newinfo); -if (ret !=0 ) { -BUGPRINT ("Translate_table failed\n" ); +if (ret !=0 ) goto free_chainstack; - }if (table->check && table->check (newinfo, table->valid_hooks)) { -BUGPRINT ("The table doesn't like its own initial data, lol\n" ); ret = -EINVAL ; goto free_chainstack; }
@@ -1252,7 +1208,6 @@ int ebt_register_table(struct net *net, const struct ebt_table *input_table,list_for_each_entry (t, &net->xt.tables[NFPROTO_BRIDGE ], list) {if (strcmp (t->name, table->name) ==0 ) { ret = -EEXIST ; -BUGPRINT ("Table name already exists\n" ); goto free_unlock; } }
@@ -1320,7 +1275,6 @@ static int do_update_counters(struct net *net, const char *name, goto free_tmp;if (num_counters != t->private->nentries) { -BUGPRINT ("Wrong nr of counters\n" ); ret = -EINVAL ; goto unlock_mutex; }
@@ -1447,10 +1401,8 @@ static int copy_counters_to_user(struct ebt_table *t,if (num_counters ==0 )return 0 ; -if (num_counters != nentries) { -BUGPRINT ("Num_counters wrong\n" ); +if (num_counters != nentries)return -EINVAL ; - } counterstmp =vmalloc (array_size (nentries,sizeof (*counterstmp)));if (!counterstmp)
@@ -1496,15 +1448,11 @@ static int copy_everything_to_user(struct ebt_table *t, void __user *user, (tmp.num_counters ? nentries * sizeof(struct ebt_counter) : 0))return -EINVAL ; -if (tmp.nentries != nentries) { -BUGPRINT ("Nentries wrong\n" ); +if (tmp.nentries != nentries)return -EINVAL ; - } -if (tmp.entries_size != entries_size) { -BUGPRINT ("Wrong size\n" ); +if (tmp.entries_size != entries_size)return -EINVAL ; - } ret =copy_counters_to_user (t, oldcounters, tmp.counters, tmp.num_counters, nentries);
@@ -1576,7 +1524,6 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len) }mutex_unlock (&ebt_mutex);if (copy_to_user (user, &tmp, *len) !=0 ) { -BUGPRINT ("c2u Didn't work\n" ); ret = -EFAULT ;break ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/29 netfilter: nat: merge ipv4 and ipv6 masquerade functionality
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Before:
text data bss dec hex filename
13916 1412 4128 19456 4c00 nf_nat.ko 4510 968 4 5482 156a nf_nat_ipv4.ko 5146 944 8 6098 17d2 nf_nat_ipv6.ko
After:
text data bss dec hex filename
16566 1576 4136 22278 5706 nf_nat.ko
3187 844 0 4031 fbf nf_nat_ipv4.ko 3598 844 0 4442 115a nf_nat_ipv6.ko
... so no drastic changes in combined size.
--- include/net/netfilter/nf_nat.h | 6 +- net/ipv4/netfilter/Kconfig | 7 +- net/ipv4/netfilter/Makefile | 1 - net/ipv4/netfilter/nf_nat_masquerade_ipv4.c | 196 --------------- net/ipv6/netfilter/Kconfig | 11 +- net/ipv6/netfilter/Makefile | 1 - net/ipv6/netfilter/nf_nat_masquerade_ipv6.c | 240 ------------------ net/netfilter/Kconfig | 3 + net/netfilter/Makefile | 1 + net/netfilter/nf_nat_masquerade.c | 362 ++++++++++++++++++++++++++++ 10 files changed, 372 insertions(+), 456 deletions(-) delete mode 100644 net/ipv4/netfilter/nf_nat_masquerade_ipv4.c delete mode 100644 net/ipv6/netfilter/nf_nat_masquerade_ipv6.c create mode 100644 net/netfilter/nf_nat_masquerade.c
include/net/netfilter/nf_nat.h +2 -4
@@ -31,8 +31,7 @@ struct nf_conn;/* The structure embedded in the conntrack structure. */ struct nf_conn_nat {union nf_conntrack_nat_help help; -#if IS_ENABLED (CONFIG_NF_NAT_MASQUERADE_IPV4 ) || \ -IS_ENABLED (CONFIG_NF_NAT_MASQUERADE_IPV6 ) +#if IS_ENABLED (CONFIG_NF_NAT_MASQUERADE )int masq_index;#endif };
@@ -61,8 +60,7 @@ static inline bool nf_nat_oif_changed(unsigned int hooknum, struct nf_conn_nat *nat, const struct net_device *out) { -#if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV4) || \ - IS_ENABLED(CONFIG_NF_NAT_MASQUERADE_IPV6) +#if IS_ENABLED(CONFIG_NF_NAT_MASQUERADE) return nat && nat->masq_index && hooknum == NF_INET_POST_ROUTING && CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL && nat->masq_index != out->ifindex;
net/ipv4/netfilter/Kconfig +2 -5
@@ -106,9 +106,6 @@ config NF_NAT_IPV4 if NF_NAT_IPV4 -config NF_NAT_MASQUERADE_IPV4 - bool - if NF_TABLES config NFT_CHAIN_NAT_IPV4 depends on NF_TABLES_IPV4
@@ -123,7 +120,7 @@ config NFT_MASQ_IPV4 tristate "IPv4 masquerading support for nf_tables" depends on NF_TABLES_IPV4 depends on NFT_MASQ - select NF_NAT_MASQUERADE_IPV4 + select NF_NAT_MASQUERADE help This is the expression that provides IPv4 masquerading support for nf_tables.
@@ -276,7 +273,7 @@ if IP_NF_NAT config IP_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" - select NF_NAT_MASQUERADE_IPV4 + select NF_NAT_MASQUERADE default m if NETFILTER_ADVANCED=n help Masquerading is a special case of NAT: all outgoing connections are
net/ipv4/netfilter/Makefile +0 -1
@@ -4,7 +4,6 @@ # nf_nat_ipv4-y := nf_nat_l3proto_ipv4.o -nf_nat_ipv4-$(CONFIG_NF_NAT_MASQUERADE_IPV4) += nf_nat_masquerade_ipv4.o obj-$(CONFIG_NF_NAT_IPV4) += nf_nat_ipv4.o # defrag
net/ipv4/netfilter/nf_nat_masquerade_ipv4.c deleted +0 -196
196 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +2 -9
@@ -44,7 +44,7 @@ config NFT_CHAIN_NAT_IPV6 config NFT_MASQ_IPV6 tristate "IPv6 masquerade support for nf_tables" depends on NFT_MASQ - select NF_NAT_MASQUERADE_IPV6 + select NF_NAT_MASQUERADE help This is the expression that provides IPv4 masquerading support for nf_tables.
@@ -116,13 +116,6 @@ config NF_NAT_IPV6 forms of full Network Address Port Translation. This can be controlled by iptables or nft. -if NF_NAT_IPV6 - -config NF_NAT_MASQUERADE_IPV6 - bool - -endif # NF_NAT_IPV6 - config IP6_NF_IPTABLES tristate "IP6 tables support (required for filtering)" depends on INET && IPV6
@@ -324,7 +317,7 @@ if IP6_NF_NAT config IP6_NF_TARGET_MASQUERADE tristate "MASQUERADE target support" - select NF_NAT_MASQUERADE_IPV6 + select NF_NAT_MASQUERADE help Masquerading is a special case of NAT: all outgoing connections are changed to seem to come from a particular interface's address, and
net/ipv6/netfilter/Makefile +0 -1
@@ -12,7 +12,6 @@ obj-$(CONFIG_IP6_NF_SECURITY) += ip6table_security.o obj-$(CONFIG_IP6_NF_NAT) += ip6table_nat.o nf_nat_ipv6-y := nf_nat_l3proto_ipv6.o -nf_nat_ipv6-$(CONFIG_NF_NAT_MASQUERADE_IPV6) += nf_nat_masquerade_ipv6.o obj-$(CONFIG_NF_NAT_IPV6) += nf_nat_ipv6.o # defrag
net/ipv6/netfilter/nf_nat_masquerade_ipv6.c deleted +0 -240
240 lines not on this page · raw message
net/netfilter/Kconfig +3 -0
@@ -431,6 +431,9 @@ config NF_NAT_TFTP config NF_NAT_REDIRECT bool +config NF_NAT_MASQUERADE + bool + config NETFILTER_SYNPROXY tristate
net/netfilter/Makefile +1 -0
@@ -56,6 +56,7 @@ obj-$(CONFIG_NF_LOG_NETDEV) += nf_log_netdev.o obj-$(CONFIG_NF_NAT) += nf_nat.o nf_nat-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o +nf_nat-$(CONFIG_NF_NAT_MASQUERADE) += nf_nat_masquerade.o # NAT helpers obj-$(CONFIG_NF_NAT_AMANDA) += nf_nat_amanda.o
net/netfilter/nf_nat_masquerade.c new file +362 -0
362 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/29 netfilter: nat: move nlattr parse and xfrm session decode to core
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
None of these functions calls any external functions, moving them allows to avoid both the indirection and a need to export these symbols.
--- include/net/netfilter/nf_nat_l3proto.h | 9 -- net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 58 ------------- net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 60 ------------- net/netfilter/nf_nat_core.c | 142 ++++++++++++++++++++++++++----- 4 files changed, 123 insertions(+), 146 deletions(-)
include/net/netfilter/nf_nat_l3proto.h +0 -9
@@ -18,15 +18,6 @@ struct nf_nat_l3proto {void (*csum_recalc)(struct sk_buff *skb,u8 proto,void *data,__sum16 *check,int datalen,int oldlen); - -void (*decode_session)(struct sk_buff *skb, -const struct nf_conn *ct, -enum ip_conntrack_dir dir, -unsigned long statusbit, -struct flowi *fl); - -int (*nlattr_to_range)(struct nlattr *tb[], -struct nf_nat_range2 *range); };int nf_nat_l3proto_register (const struct nf_nat_l3proto *);
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c +0 -58
75 lines not on this page · raw message
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c +0 -60
77 lines not on this page · raw message
net/netfilter/nf_nat_core.c +123 -19
192 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/29 netfilter: nat: remove nf_nat_l4proto.h
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
after ipv4/6 nat tracker merge, there are no external callers, so make last function static and remove the header.
--- include/net/netfilter/nf_nat_l4proto.h | 16 ---------------- net/netfilter/nf_nat_helper.c | 1 - net/netfilter/nf_nat_proto.c | 15 ++++++--------- 3 files changed, 6 insertions(+), 26 deletions(-) delete mode 100644 include/net/netfilter/nf_nat_l4proto.h
include/net/netfilter/nf_nat_l4proto.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Header for use in defining a given protocol. */ -#ifndef _NF_NAT_L4PROTO_H -#define _NF_NAT_L4PROTO_H -#include <net/netfilter/nf_nat.h> -#include <linux/netfilter/nfnetlink_conntrack.h> - -struct nf_nat_l3proto ; - -/* Translate a packet to the target according to manip type. Return on success. */ -bool nf_nat_l4proto_manip_pkt (struct sk_buff *skb, -const struct nf_nat_l3proto *l3proto, -unsigned int iphdroff,unsigned int hdroff, -const struct nf_conntrack_tuple *tuple, -enum nf_nat_manip_type maniptype); -#endif /*_NF_NAT_L4PROTO_H*/
net/netfilter/nf_nat_helper.c +0 -1
@@ -23,7 +23,6 @@#include <net/netfilter/nf_conntrack_seqadj.h> #include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_l3proto.h> -#include <net/netfilter/nf_nat_l4proto.h> #include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_nat_helper.h>
net/netfilter/nf_nat_proto.c +6 -9
@@ -22,7 +22,6 @@#include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_core.h> #include <net/netfilter/nf_nat_l3proto.h> -#include <net/netfilter/nf_nat_l4proto.h> #include <linux/ipv6.h> #include <linux/netfilter_ipv6.h>
@@ -34,6 +33,7 @@#include <net/netfilter/nf_conntrack_core.h> #include <net/netfilter/nf_conntrack.h> +#include <linux/netfilter/nfnetlink_conntrack.h> static const struct nf_nat_l3proto nf_nat_l3proto_ipv4;#if IS_ENABLED (CONFIG_IPV6 )
@@ -320,7 +320,7 @@ gre_manip_pkt(struct sk_buff *skb,return true; } -bool nf_nat_l4proto_manip_pkt(struct sk_buff *skb, +static bool l4proto_manip_pkt(struct sk_buff *skb, const struct nf_nat_l3proto *l3proto, unsigned int iphdroff, unsigned int hdroff, const struct nf_conntrack_tuple *tuple,
@@ -356,7 +356,6 @@ bool nf_nat_l4proto_manip_pkt(struct sk_buff *skb,/* If we don't know protocol -- no error, pass it unmodified. */ return true; } -EXPORT_SYMBOL_GPL (nf_nat_l4proto_manip_pkt); static bool nf_nat_ipv4_manip_pkt(struct sk_buff *skb, unsigned int iphdroff,
@@ -372,8 +371,8 @@ static bool nf_nat_ipv4_manip_pkt(struct sk_buff *skb, iph = (void *)skb->data + iphdroff; hdroff = iphdroff + iph->ihl *4 ; -if (!nf_nat_l4proto_manip_pkt (skb, &nf_nat_l3proto_ipv4, iphdroff, - hdroff, target, maniptype)) +if (!l4proto_manip_pkt (skb, &nf_nat_l3proto_ipv4, iphdroff, + hdroff, target, maniptype))return false; iph = (void *)skb->data + iphdroff;
@@ -409,8 +408,8 @@ static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb, goto manip_addr;if ((frag_off &htons (~0x7 )) ==0 && - !nf_nat_l4proto_manip_pkt (skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff, - target, maniptype)) + !l4proto_manip_pkt (skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff, + target, maniptype))return false;/* must reload, offset might have changed */
@@ -758,8 +757,6 @@ void nf_nat_l3proto_exit(void) }#if IS_ENABLED (CONFIG_IPV6 ) -static const struct nf_nat_l3proto nf_nat_l3proto_ipv6; -static const struct nf_nat_l3proto nf_nat_l3proto_ipv6 = { .l3proto =NFPROTO_IPV6 , .manip_pkt = nf_nat_ipv6_manip_pkt,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/29 netfilter: nat: merge nf_nat_ipv4,6 into nat core
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
before:
text data bss dec hex filename
16566 1576 4136 22278 5706 nf_nat.ko
3598 844 0 4442 115a nf_nat_ipv6.ko 3187 844 0 4031 fbf nf_nat_ipv4.ko
after:
text data bss dec hex filename
22948 1612 4136 28696 7018 nf_nat.ko
... with ipv4/v6 nat now provided directly via nf_nat.ko.
Also changes:
ret = nf_nat_ipv4_fn(priv, skb, state);
if (ret != NF_DROP && ret != NF_STOLEN &&
into
if (ret != NF_ACCEPT)
return ret;everywhere.
The nat hooks never should return anything other than ACCEPT or DROP (and the latter only in rare error cases).
The original code uses multi-line ANDing including assignment-in-if:
if (ret != NF_DROP && ret != NF_STOLEN &&
!(IPCB(skb)->flags & IPSKB_XFRM_TRANSFORMED) &&
(ct = nf_ct_get(skb, &ctinfo)) != NULL) {I removed this while moving, breaking those in separate conditionals and moving the assignments into extra lines.
checkpatch still generates some warnings:
1. Overly long lines (of moved code).
Breaking them is even more ugly. so I kept this as-is.
2. use of extern function declarations in a .c file. This is necessary evil, we must call nf_nat_l3proto_register() from the nat core now.
All l3proto related functions are removed later in this series, those prototypes are then removed as well.
v2: keep empty nf_nat_ipv6_csum_update stub for CONFIG_IPV6=n case.
v3: remove IS_ENABLED(NF_NAT_IPV4/6) tests, NF_NAT_IPVx toggles
are removed here.
v4: also get rid of the assignments in conditionals.
--- net/ipv4/netfilter/Kconfig | 15 +- net/ipv4/netfilter/Makefile | 3 - net/ipv4/netfilter/nf_nat_l3proto_ipv4.c | 330 --------------- net/ipv6/netfilter/Kconfig | 15 +- net/ipv6/netfilter/Makefile | 3 - net/ipv6/netfilter/nf_nat_l3proto_ipv6.c | 367 ----------------- net/netfilter/Kconfig | 8 +- net/netfilter/nf_nat_core.c | 17 + net/netfilter/nf_nat_proto.c | 678 +++++++++++++++++++++++++++++++ net/openvswitch/Kconfig | 2 - net/openvswitch/conntrack.c | 8 +- tools/testing/selftests/net/config | 3 +- 12 files changed, 711 insertions(+), 738 deletions(-) delete mode 100644 net/ipv4/netfilter/nf_nat_l3proto_ipv4.c delete mode 100644 net/ipv6/netfilter/nf_nat_l3proto_ipv6.c
net/ipv4/netfilter/Kconfig +2 -13
@@ -94,17 +94,7 @@ config NF_REJECT_IPV4 tristate "IPv4 packet rejection" default m if NETFILTER_ADVANCED=n -config NF_NAT_IPV4 - tristate "IPv4 NAT" - depends on NF_CONNTRACK - default m if NETFILTER_ADVANCED=n - select NF_NAT - help - The IPv4 NAT option allows masquerading, port forwarding and other - forms of full Network Address Port Translation. This can be - controlled by iptables or nft. - -if NF_NAT_IPV4 +if NF_NAT if NF_TABLES config NFT_CHAIN_NAT_IPV4
@@ -163,7 +153,7 @@ config NF_NAT_H323 depends on NF_CONNTRACK default NF_CONNTRACK_H323 -endif # NF_NAT_IPV4 +endif # NF_NAT config IP_NF_IPTABLES tristate "IP tables support (required for filtering/masq/NAT)"
@@ -260,7 +250,6 @@ config IP_NF_NAT depends on NF_CONNTRACK default m if NETFILTER_ADVANCED=n select NF_NAT - select NF_NAT_IPV4 select NETFILTER_XT_NAT help This enables the `nat' table in iptables. This allows masquerading,
net/ipv4/netfilter/Makefile +0 -3
@@ -3,9 +3,6 @@ # Makefile for the netfilter modules on top of IPv4. # -nf_nat_ipv4-y := nf_nat_l3proto_ipv4.o -obj-$(CONFIG_NF_NAT_IPV4) += nf_nat_ipv4.o - # defrag obj-$(CONFIG_NF_DEFRAG_IPV4) += nf_defrag_ipv4.o
net/ipv4/netfilter/nf_nat_l3proto_ipv4.c deleted +0 -330
330 lines not on this page · raw message
net/ipv6/netfilter/Kconfig +2 -13
@@ -31,7 +31,7 @@ config NFT_CHAIN_ROUTE_IPV6 fields such as the source, destination, flowlabel, hop-limit and the packet mark. -if NF_NAT_IPV6 +if NF_NAT config NFT_CHAIN_NAT_IPV6 tristate "IPv6 nf_tables nat chain support"
@@ -57,7 +57,7 @@ config NFT_REDIR_IPV6 This is the expression that provides IPv4 redirect support for nf_tables. -endif # NF_NAT_IPV6 +endif # NF_NAT config NFT_REJECT_IPV6 select NF_REJECT_IPV6
@@ -106,16 +106,6 @@ config NF_LOG_IPV6 default m if NETFILTER_ADVANCED=n select NF_LOG_COMMON -config NF_NAT_IPV6 - tristate "IPv6 NAT" - depends on NF_CONNTRACK - depends on NETFILTER_ADVANCED - select NF_NAT - help - The IPv6 NAT option allows masquerading, port forwarding and other - forms of full Network Address Port Translation. This can be - controlled by iptables or nft. - config IP6_NF_IPTABLES tristate "IP6 tables support (required for filtering)" depends on INET && IPV6
@@ -304,7 +294,6 @@ config IP6_NF_NAT depends on NF_CONNTRACK depends on NETFILTER_ADVANCED select NF_NAT - select NF_NAT_IPV6 select NETFILTER_XT_NAT help This enables the `nat' table in ip6tables. This allows masquerading,
net/ipv6/netfilter/Makefile +0 -3
@@ -11,9 +11,6 @@ obj-$(CONFIG_IP6_NF_RAW) += ip6table_raw.o obj-$(CONFIG_IP6_NF_SECURITY) += ip6table_security.o obj-$(CONFIG_IP6_NF_NAT) += ip6table_nat.o -nf_nat_ipv6-y := nf_nat_l3proto_ipv6.o -obj-$(CONFIG_NF_NAT_IPV6) += nf_nat_ipv6.o - # defrag nf_defrag_ipv6-y := nf_defrag_ipv6_hooks.o nf_conntrack_reasm.o obj-$(CONFIG_NF_DEFRAG_IPV6) += nf_defrag_ipv6.o
net/ipv6/netfilter/nf_nat_l3proto_ipv6.c deleted +0 -367
367 lines not on this page · raw message
net/netfilter/Kconfig +7 -1
@@ -396,7 +396,13 @@ config NETFILTER_NETLINK_GLUE_CT the enqueued via NFNETLINK. config NF_NAT - tristate + tristate "Network Address Translation support" + depends on NF_CONNTRACK + default m if NETFILTER_ADVANCED=n + help + The NAT option allows masquerading, port forwarding and other + forms of full Network Address Port Translation. This can be + controlled by iptables, ip6tables or nft. config NF_NAT_NEEDED bool
net/netfilter/nf_nat_core.c +17 -0
@@ -1203,6 +1203,8 @@ static struct nf_nat_hook nat_hook = { .manip_pkt = nf_nat_manip_pkt, }; +int nf_nat_l3proto_init (void ); +void nf_nat_l3proto_exit (void );static int __init nf_nat_init (void ) {int ret, i;
@@ -1237,6 +1239,19 @@ static int __init nf_nat_init(void)WARN_ON (nf_nat_hook !=NULL );RCU_INIT_POINTER (nf_nat_hook, &nat_hook); + ret =nf_nat_l3proto_init (); +if (ret) { +nf_ct_extend_unregister (&nat_extend); +nf_ct_helper_expectfn_unregister (&follow_master_nat); +RCU_INIT_POINTER (nf_nat_hook,NULL ); + +synchronize_net (); +kvfree (nf_nat_bysource); +unregister_pernet_subsys (&nat_net_ops); + +return ret; + } +return 0 ; }
@@ -1246,6 +1261,8 @@ static void __exit nf_nat_cleanup(void)nf_ct_iterate_destroy (nf_nat_proto_clean, &clean); +nf_nat_l3proto_exit (); +nf_ct_extend_unregister (&nat_extend);nf_ct_helper_expectfn_unregister (&follow_master_nat);RCU_INIT_POINTER (nf_nat_hook,NULL );
net/netfilter/nf_nat_proto.c +678 -0
687 lines not on this page · raw message
net/openvswitch/Kconfig +0 -2
@@ -8,8 +8,6 @@ config OPENVSWITCH depends on !NF_CONNTRACK || \ (NF_CONNTRACK && ((!NF_DEFRAG_IPV6 || NF_DEFRAG_IPV6) && \ (!NF_NAT || NF_NAT) && \ - (!NF_NAT_IPV4 || NF_NAT_IPV4) && \ - (!NF_NAT_IPV6 || NF_NAT_IPV6) && \ (!NETFILTER_CONNCOUNT || NETFILTER_CONNCOUNT))) select LIBCRC32C select MPLS
net/openvswitch/conntrack.c +4 -4
@@ -745,14 +745,14 @@ static int ovs_ct_nat_execute(struct sk_buff *skb, struct nf_conn *ct,switch (ctinfo) {case IP_CT_RELATED :case IP_CT_RELATED_REPLY : -if (IS_ENABLED (CONFIG_NF_NAT_IPV4 ) && +if (IS_ENABLED (CONFIG_NF_NAT ) && skb->protocol ==htons (ETH_P_IP ) &&ip_hdr (skb)->protocol ==IPPROTO_ICMP ) {if (!nf_nat_icmp_reply_translation (skb, ct, ctinfo, hooknum)) err =NF_DROP ; goto push; - }else if (IS_ENABLED (CONFIG_NF_NAT_IPV6 ) && + }else if (IS_ENABLED (CONFIG_IPV6 ) && skb->protocol ==htons (ETH_P_IPV6 )) {__be16 frag_off;u8 nexthdr =ipv6_hdr (skb)->nexthdr;
@@ -1673,7 +1673,7 @@ static bool ovs_ct_nat_to_attr(const struct ovs_conntrack_info *info, }if (info->range.flags &NF_NAT_RANGE_MAP_IPS ) { -if (IS_ENABLED (CONFIG_NF_NAT_IPV4 ) && +if (IS_ENABLED (CONFIG_NF_NAT ) && info->family ==NFPROTO_IPV4 ) { if (nla_put_in_addr(skb, OVS_NAT_ATTR_IP_MIN, info->range.min_addr.ip) ||
@@ -1682,7 +1682,7 @@ static bool ovs_ct_nat_to_attr(const struct ovs_conntrack_info *info, (nla_put_in_addr(skb, OVS_NAT_ATTR_IP_MAX, info->range.max_addr.ip))))return false; - }else if (IS_ENABLED (CONFIG_NF_NAT_IPV6 ) && + }else if (IS_ENABLED (CONFIG_IPV6 ) && info->family ==NFPROTO_IPV6 ) { if (nla_put_in6_addr(skb, OVS_NAT_ATTR_IP_MIN, &info->range.min_addr.in6) ||
tools/testing/selftests/net/config +1 -2
@@ -17,8 +17,7 @@ CONFIG_VLAN_8021Q=y CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y CONFIG_NF_CONNTRACK=m -CONFIG_NF_NAT_IPV6=m -CONFIG_NF_NAT_IPV4=m +CONFIG_NF_NAT=m CONFIG_IP6_NF_IPTABLES=m CONFIG_IP_NF_IPTABLES=m CONFIG_IP6_NF_NAT=m
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/29 netfilter: nat: remove l3 manip_pkt hook
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We can now use direct calls.
--- include/net/netfilter/nf_nat_l3proto.h | 9 ++++----- net/netfilter/nf_nat_core.c | 17 ----------------- net/netfilter/nf_nat_proto.c | 28 ++++++++++++++++++++++++++-- 3 files changed, 30 insertions(+), 24 deletions(-)
include/net/netfilter/nf_nat_l3proto.h +4 -5
@@ -5,11 +5,6 @@struct nf_nat_l3proto {u8 l3proto; -bool (*manip_pkt)(struct sk_buff *skb, -unsigned int iphdroff, -const struct nf_conntrack_tuple *target, -enum nf_nat_manip_type maniptype); - void (*csum_update)(struct sk_buff *skb, unsigned int iphdroff, __sum16 *check, const struct nf_conntrack_tuple *t,
@@ -20,6 +15,10 @@ struct nf_nat_l3proto { int datalen, int oldlen); }; +unsigned int nf_nat_manip_pkt (struct sk_buff *skb,struct nf_conn *ct, +enum nf_nat_manip_type mtype, +enum ip_conntrack_dir dir); +int nf_nat_l3proto_register (const struct nf_nat_l3proto *);void nf_nat_l3proto_unregister (const struct nf_nat_l3proto *);const struct nf_nat_l3proto *__nf_nat_l3proto_find (u8 l3proto);
net/netfilter/nf_nat_core.c +0 -17
@@ -699,23 +699,6 @@ nf_nat_alloc_null_binding(struct nf_conn *ct, unsigned int hooknum) }EXPORT_SYMBOL_GPL (nf_nat_alloc_null_binding); -static unsigned int nf_nat_manip_pkt (struct sk_buff *skb,struct nf_conn *ct, -enum nf_nat_manip_type mtype, -enum ip_conntrack_dir dir) -{ -const struct nf_nat_l3proto *l3proto; -struct nf_conntrack_tuple target; - -/* We are aiming to look like inverse of other direction. */ -nf_ct_invert_tuple (&target, &ct->tuplehash[!dir].tuple); - - l3proto =__nf_nat_l3proto_find (target.src.l3num); -if (!l3proto->manip_pkt (skb,0 , &target, mtype)) -return NF_DROP ; - -return NF_ACCEPT ; -} -/* Do packet manipulations according to nf_nat_setup_info. */ unsigned int nf_nat_packet(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
net/netfilter/nf_nat_proto.c +26 -2
@@ -425,6 +425,32 @@ static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb,return true; } +unsigned int nf_nat_manip_pkt (struct sk_buff *skb,struct nf_conn *ct, +enum nf_nat_manip_type mtype, +enum ip_conntrack_dir dir) +{ +struct nf_conntrack_tuple target; + +/* We are aiming to look like inverse of other direction. */ +nf_ct_invert_tuple (&target, &ct->tuplehash[!dir].tuple); + +switch (target.src.l3num) { +case NFPROTO_IPV6 : +if (nf_nat_ipv6_manip_pkt (skb,0 , &target, mtype)) +return NF_ACCEPT ; +break ; +case NFPROTO_IPV4 : +if (nf_nat_ipv4_manip_pkt (skb,0 , &target, mtype)) +return NF_ACCEPT ; +break ; +default : +WARN_ON_ONCE (1 ); +break ; + } + +return NF_DROP ; +} + static void nf_nat_ipv4_csum_update(struct sk_buff *skb, unsigned int iphdroff, __sum16 *check, const struct nf_conntrack_tuple *t,
@@ -506,7 +532,6 @@ static void nf_nat_ipv6_csum_recalc(struct sk_buff *skb,static const struct nf_nat_l3proto nf_nat_l3proto_ipv4 = { .l3proto =NFPROTO_IPV4 , - .manip_pkt = nf_nat_ipv4_manip_pkt, .csum_update = nf_nat_ipv4_csum_update, .csum_recalc = nf_nat_ipv4_csum_recalc, };
@@ -759,7 +784,6 @@ void nf_nat_l3proto_exit(void)#if IS_ENABLED (CONFIG_IPV6 )static const struct nf_nat_l3proto nf_nat_l3proto_ipv6 = { .l3proto =NFPROTO_IPV6 , - .manip_pkt = nf_nat_ipv6_manip_pkt, .csum_update = nf_nat_ipv6_csum_update, .csum_recalc = nf_nat_ipv6_csum_recalc, };
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/29 netfilter: nat: remove csum_update hook
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We can now use direct calls.
--- include/net/netfilter/nf_nat_l3proto.h | 5 --- net/netfilter/nf_nat_proto.c | 69 ++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 38 deletions(-)
include/net/netfilter/nf_nat_l3proto.h +0 -5
@@ -5,11 +5,6 @@struct nf_nat_l3proto {u8 l3proto; -void (*csum_update)(struct sk_buff *skb,unsigned int iphdroff, -__sum16 *check, -const struct nf_conntrack_tuple *t, -enum nf_nat_manip_type maniptype); -void (*csum_recalc)(struct sk_buff *skb,u8 proto,void *data,__sum16 *check,int datalen,int oldlen);
net/netfilter/nf_nat_proto.c +36 -33
215 lines not on this page · raw message
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Sat, 2 Mar 2019 19:34:28 +0100
Quoted 1 line
The following patchset contains Netfilter/IPVS updates for net-next:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thanks Pablo.