Netfilter updates for net-next
Subsystems (7)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi,
The following patchset contains Netfilter updates for net-next:
1) Rewrite inner header IPv6 in ICMPv6 messages in ip6t_NPT, from Michael Zhou.
2) do_ip_vs_set_ctl() dereferences uninitialized value, from Peilin Ye.
3) Support for userdata in tables, from Jose M. Guisado.
4) Do not increment ct error and invalid stats at the same time, from Florian Westphal.
5) Remove ct ignore stats, also from Florian.
6) Add ct stats for clash resolution, from Florian Westphal.
7) Bump reference counter bump on ct clash resolution only, this is safe because bucket lock is held, again from Florian.
8) Use ip_is_fragment() in xt_HMARK, from YueHaibing.
9) Add wildcard support for nft_socket, from Balazs Scheidler.
10) Remove superfluous IPVS dependency on iptables, from Yaroslav Bolyukin.
11) Remove unused definition in ebt_stp, from Wang Hai.
12) Replace CONFIG_NFT_CHAIN_NAT_{IPV4,IPV6} by CONFIG_NFT_NAT in selftests/net, from Fabian Frederick.
13) Add userdata support for nft_object, from Jose M. Guisado.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thank you.
----------------------------------------------------------------
The following changes since commit 0f091e43310f5c292b7094f9f115e651358e8053:
netlabel: remove unused param from audit_log_format() (2020-08-28 09:08:51 -0700)
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 b131c96496b369c7b14125e7c50e89ac7cec8051:
netfilter: nf_tables: add userdata support for nft_object (2020-09-08 16:35:38 +0200)
----------------------------------------------------------------
Balazs Scheidler (1):
netfilter: nft_socket: add wildcard support
Fabian Frederick (1):
selftests/net: replace obsolete NFT_CHAIN configuration
Florian Westphal (4):
netfilter: conntrack: do not increment two error counters at same time
netfilter: conntrack: remove ignore stats
netfilter: conntrack: add clash resolution stat counter
netfilter: conntrack: remove unneeded nf_ct_put
Jose M. Guisado Gomez (2):
netfilter: nf_tables: add userdata attributes to nft_table
netfilter: nf_tables: add userdata support for nft_object
Michael Zhou (1):
netfilter: ip6t_NPT: rewrite addresses in ICMPv6 original packet
Peilin Ye (1):
ipvs: Fix uninit-value in do_ip_vs_set_ctl()
Wang Hai (1):
netfilter: ebt_stp: Remove unused macro BPDU_TYPE_TCN
Yaroslav Bolyukin (1):
ipvs: remove dependency on ip6_tables
YueHaibing (1):
netfilter: xt_HMARK: Use ip_is_fragment() helper
include/linux/netfilter/nf_conntrack_common.h | 2 +- include/net/ip_vs.h | 3 -- include/net/netfilter/nf_tables.h | 4 ++ include/uapi/linux/netfilter/nf_tables.h | 6 +++ include/uapi/linux/netfilter/nfnetlink_conntrack.h | 3 +- net/bridge/netfilter/ebt_stp.c | 1 - net/ipv6/netfilter/ip6t_NPT.c | 39 +++++++++++++++ net/netfilter/ipvs/Kconfig | 1 - net/netfilter/ipvs/ip_vs_ctl.c | 7 +-- net/netfilter/nf_conntrack_core.c | 25 ++++------ net/netfilter/nf_conntrack_netlink.c | 5 +- net/netfilter/nf_conntrack_standalone.c | 4 +- net/netfilter/nf_tables_api.c | 57 ++++++++++++++++++---- net/netfilter/nft_socket.c | 27 ++++++++++ net/netfilter/xt_HMARK.c | 2 +- tools/testing/selftests/net/config | 3 +- 16 files changed, 148 insertions(+), 41 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/13 netfilter: ip6t_NPT: rewrite addresses in ICMPv6 original packet
From: Michael Zhou <[email protected]>
Detect and rewrite a prefix embedded in an ICMPv6 original packet that was rewritten by a corresponding DNPT/SNPT rule so it will be recognised by the host that sent the original packet.
Example
Rules in effect on the 1:2:3:4::/64 + 5:6:7:8::/64 side router:
* SNPT src-pfx 1:2:3:4::/64 dst-pfx 5:6:7:8::/64
* DNPT src-pfx 5:6:7:8::/64 dst-pfx 1:2:3:4::/64
No rules on the 9:a:b:c::/64 side.
1. 1:2:3:4::1 sends UDP packet to 9:a:b:c::1
2. Router applies SNPT changing src to 5:6:7:8::ffef::1
3. 9:a:b:c::1 receives packet with (src 5:6:7:8::ffef::1 dst 9:a:b:c::1)
and replies with ICMPv6 port unreachable to 5:6:7:8::ffef::1, including original packet (src 5:6:7:8::ffef::1 dst 9:a:b:c::1) 4. Router forwards ICMPv6 packet with (src 9:a:b:c::1 dst 5:6:7:8::ffef::1) including original packet (src 5:6:7:8::ffef::1 dst 9:a:b:c::1) and applies DNPT changing dst to 1:2:3:4::1
5. 1:2:3:4::1 receives ICMPv6 packet with (src 9:a:b:c::1 dst 1:2:3:4::1) including original packet (src 5:6:7:8::ffef::1 dst 9:a:b:c::1). It doesn't recognise the original packet as the src doesn't match anything it originally sent
With this change, at step 4, DNPT will also rewrite the original packet src to 1:2:3:4::1, so at step 5, 1:2:3:4::1 will recognise the ICMPv6 error and provide feedback to the application properly.
Conversely, SNPT will help when ICMPv6 errors are sent from the translated network.
1. 9:a:b:c::1 sends UDP packet to 5:6:7:8::ffef::1
2. Router applies DNPT changing dst to 1:2:3:4::1
3. 1:2:3:4::1 receives packet with (src 9:a:b:c::1 dst 1:2:3:4::1)
and replies with ICMPv6 port unreachable to 9:a:b:c::1 including original packet (src 9:a:b:c::1 dst 1:2:3:4::1) 4. Router forwards ICMPv6 packet with (src 1:2:3:4::1 dst 9:a:b:c::1) including original packet (src 9:a:b:c::1 dst 1:2:3:4::1) and applies SNPT changing src to 5:6:7:8::ffef::1 5. 9:a:b:c::1 receives ICMPv6 packet with (src 5:6:7:8::ffef::1 dst 9:a:b:c::1) including original packet (src 9:a:b:c::1 dst 1:2:3:4::1). It doesn't recognise the original packet as the dst doesn't match anything it already sent
The change to SNPT means the ICMPv6 original packet dst will be rewritten to 5:6:7:8::ffef::1 in step 4, allowing the error to be properly recognised in step 5.
--- net/ipv6/netfilter/ip6t_NPT.c | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
net/ipv6/netfilter/ip6t_NPT.c +39 -0
@@ -77,16 +77,43 @@ static bool ip6t_npt_map_pfx(const struct ip6t_npt_tginfo *npt,return true; } +static struct ipv6hdr *icmpv6_bounced_ipv6hdr (struct sk_buff *skb, +struct ipv6hdr *_bounced_hdr) +{ +if (ipv6_hdr (skb)->nexthdr !=IPPROTO_ICMPV6 ) +return NULL ; + +if (!icmpv6_is_err (icmp6_hdr (skb)->icmp6_type)) +return NULL ; + +return skb_header_pointer (skb, +skb_transport_offset (skb) +sizeof (struct icmp6hdr ), +sizeof (struct ipv6hdr ), + _bounced_hdr); +} +static unsigned int ip6t_snpt_tg (struct sk_buff *skb,const struct xt_action_param *par) {const struct ip6t_npt_tginfo *npt = par->targinfo; +struct ipv6hdr _bounced_hdr; +struct ipv6hdr *bounced_hdr; +struct in6_addr bounced_pfx;if (!ip6t_npt_map_pfx (npt, &ipv6_hdr (skb)->saddr)) {icmpv6_send (skb,ICMPV6_PARAMPROB ,ICMPV6_HDR_FIELD , offsetof(struct ipv6hdr , saddr));return NF_DROP ; } + +/* rewrite dst addr of bounced packet which was sent to dst range */ + bounced_hdr =icmpv6_bounced_ipv6hdr (skb, &_bounced_hdr); +if (bounced_hdr) { +ipv6_addr_prefix (&bounced_pfx, &bounced_hdr->daddr, npt->src_pfx_len); +if (ipv6_addr_cmp (&bounced_pfx, &npt->src_pfx.in6) ==0 ) +ip6t_npt_map_pfx (npt, &bounced_hdr->daddr); + } +return XT_CONTINUE ; }
@@ -94,12 +121,24 @@ static unsigned int ip6t_dnpt_tg(struct sk_buff *skb, const struct xt_action_param *par) { const struct ip6t_npt_tginfo *npt = par->targinfo; +struct ipv6hdr _bounced_hdr; +struct ipv6hdr *bounced_hdr; +struct in6_addr bounced_pfx;if (!ip6t_npt_map_pfx (npt, &ipv6_hdr (skb)->daddr)) {icmpv6_send (skb,ICMPV6_PARAMPROB ,ICMPV6_HDR_FIELD , offsetof(struct ipv6hdr , daddr));return NF_DROP ; } + +/* rewrite src addr of bounced packet which was sent from dst range */ + bounced_hdr =icmpv6_bounced_ipv6hdr (skb, &_bounced_hdr); +if (bounced_hdr) { +ipv6_addr_prefix (&bounced_pfx, &bounced_hdr->saddr, npt->src_pfx_len); +if (ipv6_addr_cmp (&bounced_pfx, &npt->src_pfx.in6) ==0 ) +ip6t_npt_map_pfx (npt, &bounced_hdr->saddr); + } +return XT_CONTINUE ; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/13 ipvs: Fix uninit-value in do_ip_vs_set_ctl()
In reply to Pablo Neira AyusoFrom: Peilin Ye <[email protected]>
do_ip_vs_set_ctl() is referencing uninitialized stack value when len is zero. Fix it.
--- net/netfilter/ipvs/ip_vs_ctl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/netfilter/ipvs/ip_vs_ctl.c +4 -3
@@ -2508,6 +2508,10 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, sockptr_t ptr, unsigned int len)/* Set timeout values for (tcp tcpfin udp) */ ret =ip_vs_set_timeout (ipvs, (struct ip_vs_timeout_user *)arg); goto out_unlock; + }else if (!len) { +/* No more commands with len == 0 below */ + ret = -EINVAL ; + goto out_unlock; } usvc_compat = (struct ip_vs_service_user *)arg;
@@ -2584,9 +2588,6 @@ do_ip_vs_set_ctl(struct sock *sk, int cmd, sockptr_t ptr, unsigned int len)break ;case IP_VS_SO_SET_DELDEST : ret =ip_vs_del_dest (svc, &udest); -break ; -default : - ret = -EINVAL ; } out_unlock:
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 3/13 netfilter: nf_tables: add userdata attributes to nft_table
In reply to Pablo Neira AyusoFrom: "Jose M. Guisado Gomez" <[email protected]>
Enables storing userdata for nft_table. Field udata points to user data and udlen store its length.
Adds new attribute flag NFTA_TABLE_USERDATA
--- include/net/netfilter/nf_tables.h | 2 ++ include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 22 +++++++++++++++++++++- 3 files changed, 25 insertions(+), 1 deletion(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -1080,6 +1080,8 @@ struct nft_table { flags:8 , genmask:2;char *name; +u16 udlen; +u8 *udata; };void nft_register_chain_type (const struct nft_chain_type *);
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -172,6 +172,7 @@ enum nft_table_flags {* @NFTA_TABLE_NAME: name of the table (NLA_STRING) * @NFTA_TABLE_FLAGS: bitmask of enum nft_table_flags (NLA_U32) * @NFTA_TABLE_USE: number of chains in this table (NLA_U32) +* @NFTA_TABLE_USERDATA: user data (NLA_BINARY) */ enum nft_table_attributes {NFTA_TABLE_UNSPEC ,
@@ -180,6 +181,7 @@ enum nft_table_attributes {NFTA_TABLE_USE ,NFTA_TABLE_HANDLE ,NFTA_TABLE_PAD , +NFTA_TABLE_USERDATA , __NFTA_TABLE_MAX };#define NFTA_TABLE_MAX (__NFTA_TABLE_MAX - 1)
net/netfilter/nf_tables_api.c +21 -1
@@ -650,6 +650,8 @@ static const struct nla_policy nft_table_policy[NFTA_TABLE_MAX + 1] = { .len = NFT_TABLE_MAXNAMELEN - 1 }, [NFTA_TABLE_FLAGS] = { .type = NLA_U32 }, [NFTA_TABLE_HANDLE] = { .type = NLA_U64 }, + [NFTA_TABLE_USERDATA] = { .type = NLA_BINARY, + .len = NFT_USERDATA_MAXLEN } }; static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net,
@@ -676,6 +678,11 @@ static int nf_tables_fill_table_info(struct sk_buff *skb, struct net *net, NFTA_TABLE_PAD)) goto nla_put_failure; +if (table->udata) { +if (nla_put (skb,NFTA_TABLE_USERDATA , table->udlen, table->udata)) + goto nla_put_failure; + } +nlmsg_end (skb, nlh);return 0 ;
@@ -977,8 +984,9 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,int family = nfmsg->nfgen_family;const struct nlattr *attr;struct nft_table *table; -u32 flags =0 ;struct nft_ctx ctx; +u32 flags =0 ; +u16 udlen =0 ;int err;lockdep_assert_held (&net->nft.commit_mutex);
@@ -1014,6 +1022,16 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,if (table->name ==NULL ) goto err_strdup; +if (nla[NFTA_TABLE_USERDATA ]) { + udlen =nla_len (nla[NFTA_TABLE_USERDATA ]); + table->udata =kzalloc (udlen,GFP_KERNEL ); +if (table->udata ==NULL ) + goto err_table_udata; + +nla_memcpy (table->udata, nla[NFTA_TABLE_USERDATA ], udlen); + table->udlen = udlen; + } + err =rhltable_init (&table->chains_ht, &nft_chain_ht_params);if (err) goto err_chain_ht;
@@ -1036,6 +1054,8 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk, err_trans:rhltable_destroy (&table->chains_ht); err_chain_ht: +kfree (table->udata); +err_table_udata:kfree (table->name); err_strdup:kfree (table);
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 4/13 netfilter: conntrack: do not increment two error counters at same time
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
The /proc interface for nf_conntrack displays the "error" counter as "icmp_error".
It makes sense to not increment "invalid" when failing to handle an icmp packet since those are special.
For example, its possible for conntrack to see partial and/or fragmented packets inside icmp errors. This should be a separate event and not get mixed with the "invalid" counter.
Likewise, remove the "error" increment for errors from get_l4proto(). After this, the error counter will only increment for errors coming from icmp(v6) packet handling.
--- net/netfilter/nf_conntrack_core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
net/netfilter/nf_conntrack_core.c +1 -4
@@ -1725,10 +1725,8 @@ nf_conntrack_handle_icmp(struct nf_conn *tmpl,else return NF_ACCEPT ; -if (ret <=0 ) { +if (ret <=0 )NF_CT_STAT_INC_ATOMIC (state->net, error); -NF_CT_STAT_INC_ATOMIC (state->net, invalid); - }return ret; }
@@ -1813,7 +1811,6 @@ nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state) dataoff =get_l4proto (skb,skb_network_offset (skb), state->pf, &protonum);if (dataoff <=0 ) {pr_debug ("not prepared to track yet or error occurred\n" ); -NF_CT_STAT_INC_ATOMIC (state->net, error);NF_CT_STAT_INC_ATOMIC (state->net, invalid); ret =NF_ACCEPT ; goto out;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 5/13 netfilter: conntrack: remove ignore stats
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
This counter increments when nf_conntrack_in sees a packet that already has a conntrack attached or when the packet is marked as UNTRACKED. Neither is an error.
The former is normal for loopback traffic. The second happens for certain ICMPv6 packets or when nftables/ip(6)tables rules are in place.
In case someone needs to count UNTRACKED packets, or packets that are marked as untracked before conntrack_in this can be done with both nftables and ip(6)tables rules.
--- include/linux/netfilter/nf_conntrack_common.h | 1 - include/uapi/linux/netfilter/nfnetlink_conntrack.h | 2 +- net/netfilter/nf_conntrack_core.c | 4 +--- net/netfilter/nf_conntrack_netlink.c | 1 - net/netfilter/nf_conntrack_standalone.c | 2 +- 5 files changed, 3 insertions(+), 7 deletions(-)
include/linux/netfilter/nf_conntrack_common.h +0 -1
@@ -8,7 +8,6 @@struct ip_conntrack_stat {unsigned int found;unsigned int invalid; -unsigned int ignore;unsigned int insert;unsigned int insert_failed;unsigned int drop;
include/uapi/linux/netfilter/nfnetlink_conntrack.h +1 -1
@@ -247,7 +247,7 @@ enum ctattr_stats_cpu {CTA_STATS_FOUND ,CTA_STATS_NEW ,/* no longer used */ CTA_STATS_INVALID , -CTA_STATS_IGNORE , +CTA_STATS_IGNORE ,/* no longer used */ CTA_STATS_DELETE ,/* no longer used */ CTA_STATS_DELETE_LIST ,/* no longer used */ CTA_STATS_INSERT,
net/netfilter/nf_conntrack_core.c +1 -3
@@ -1800,10 +1800,8 @@ nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state)if (tmpl || ctinfo ==IP_CT_UNTRACKED ) {/* Previously seen (loopback or untracked)? Ignore. */ if ((tmpl && !nf_ct_is_template (tmpl)) || - ctinfo ==IP_CT_UNTRACKED ) { -NF_CT_STAT_INC_ATOMIC (state->net, ignore); + ctinfo ==IP_CT_UNTRACKED )return NF_ACCEPT ; - } skb->_nfct =0 ; }
net/netfilter/nf_conntrack_netlink.c +0 -1
@@ -2509,7 +2509,6 @@ ctnetlink_ct_stat_cpu_fill_info(struct sk_buff *skb, u32 portid, u32 seq, if (nla_put_be32(skb, CTA_STATS_FOUND, htonl(st->found)) || nla_put_be32(skb, CTA_STATS_INVALID, htonl(st->invalid)) || - nla_put_be32(skb, CTA_STATS_IGNORE, htonl(st->ignore)) || nla_put_be32(skb, CTA_STATS_INSERT, htonl(st->insert)) || nla_put_be32(skb, CTA_STATS_INSERT_FAILED, htonl(st->insert_failed)) ||
net/netfilter/nf_conntrack_standalone.c +1 -1
@@ -439,7 +439,7 @@ static int ct_cpu_seq_show(struct seq_file *seq, void *v) st->found,0 , st->invalid, - st->ignore, +0 ,0 ,0 , st->insert,
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 6/13 netfilter: conntrack: add clash resolution stat counter
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
There is a misconception about what "insert_failed" means.
We increment this even when a clash got resolved, so it might not indicate a problem.
Add a dedicated counter for clash resolution and only increment insert_failed if a clash cannot be resolved.
For the old /proc interface, export this in place of an older stat that got removed a while back.
For ctnetlink, export this with a new attribute.
Also correct an outdated comment that implies we add a duplicate tuple -- we only add the (unique) reply direction.
--- include/linux/netfilter/nf_conntrack_common.h | 1 + include/uapi/linux/netfilter/nfnetlink_conntrack.h | 1 + net/netfilter/nf_conntrack_core.c | 9 +++++---- net/netfilter/nf_conntrack_netlink.c | 4 +++- net/netfilter/nf_conntrack_standalone.c | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-)
include/linux/netfilter/nf_conntrack_common.h +1 -0
@@ -10,6 +10,7 @@ struct ip_conntrack_stat {unsigned int invalid;unsigned int insert;unsigned int insert_failed; +unsigned int clash_resolve;unsigned int drop;unsigned int early_drop;unsigned int error;
include/uapi/linux/netfilter/nfnetlink_conntrack.h +1 -0
@@ -256,6 +256,7 @@ enum ctattr_stats_cpu {CTA_STATS_EARLY_DROP ,CTA_STATS_ERROR ,CTA_STATS_SEARCH_RESTART , +CTA_STATS_CLASH_RESOLVE , __CTA_STATS_MAX, };#define CTA_STATS_MAX (__CTA_STATS_MAX - 1)
net/netfilter/nf_conntrack_core.c +5 -4
@@ -859,7 +859,6 @@ nf_conntrack_hash_check_insert(struct nf_conn *ct) out:nf_conntrack_double_unlock (hash, reply_hash); -NF_CT_STAT_INC (net, insert_failed);local_bh_enable ();return -EEXIST ; }
@@ -934,7 +933,7 @@ static int __nf_ct_resolve_clash(struct sk_buff *skb,nf_conntrack_put (&loser_ct->ct_general);nf_ct_set (skb, ct, ctinfo); -NF_CT_STAT_INC (net, insert_failed); +NF_CT_STAT_INC (net, clash_resolve);return NF_ACCEPT ; }
@@ -998,6 +997,8 @@ static int nf_ct_resolve_clash_harder(struct sk_buff *skb, u32 repl_idx)hlist_nulls_add_head_rcu (&loser_ct->tuplehash[IP_CT_DIR_REPLY ].hnnode, &nf_conntrack_hash[repl_idx]); + +NF_CT_STAT_INC (net, clash_resolve);return NF_ACCEPT ; }
@@ -1027,10 +1028,10 @@ static int nf_ct_resolve_clash_harder(struct sk_buff *skb, u32 repl_idx)* * Failing that, the new, unconfirmed conntrack is still added to the table * provided that the collision only occurs in the ORIGINAL direction. -* The new entry will be added after the existing one in the hash list, +* The new entry will be added only in the non-clashing REPLY direction, * so packets in the ORIGINAL direction will continue to match the existing * entry. The new entry will also have a fixed timeout so it expires -- -* due to the collision, it will not see bidirectional traffic. +* due to the collision, it will only see reply traffic. * * Returns NF_DROP if the clash could not be resolved. */
net/netfilter/nf_conntrack_netlink.c +3 -1
@@ -2516,7 +2516,9 @@ ctnetlink_ct_stat_cpu_fill_info(struct sk_buff *skb, u32 portid, u32 seq,nla_put_be32 (skb,CTA_STATS_EARLY_DROP ,htonl (st->early_drop)) ||nla_put_be32 (skb,CTA_STATS_ERROR ,htonl (st->error)) ||nla_put_be32 (skb,CTA_STATS_SEARCH_RESTART , - htonl(st->search_restart))) +htonl (st->search_restart)) || +nla_put_be32 (skb,CTA_STATS_CLASH_RESOLVE , + htonl(st->clash_resolve))) goto nla_put_failure;nlmsg_end (skb, nlh);
net/netfilter/nf_conntrack_standalone.c +1 -1
@@ -435,7 +435,7 @@ static int ct_cpu_seq_show(struct seq_file *seq, void *v) seq_printf(seq, "%08x %08x %08x %08x %08x %08x %08x %08x " "%08x %08x %08x %08x %08x %08x %08x %08x %08x\n", nr_conntracks, - 0, + st->clash_resolve, /* was: searched */ st->found, 0, st->invalid,
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 7/13 netfilter: conntrack: remove unneeded nf_ct_put
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
We can delay refcount increment until we reassign the existing entry to the current skb.
A 0 refcount can't happen while the nf_conn object is still in the hash table and parallel mutations are impossible because we hold the bucket lock.
--- net/netfilter/nf_conntrack_core.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/netfilter/nf_conntrack_core.c +3 -4
@@ -908,6 +908,7 @@ static void __nf_conntrack_insert_prepare(struct nf_conn *ct) tstamp->start =ktime_get_real_ns (); } +/* caller must hold locks to prevent concurrent changes */ static int __nf_ct_resolve_clash (struct sk_buff *skb,struct nf_conntrack_tuple_hash *h) {
@@ -921,13 +922,12 @@ static int __nf_ct_resolve_clash(struct sk_buff *skb,if (nf_ct_is_dying (ct))return NF_DROP ; -if (!atomic_inc_not_zero (&ct->ct_general.use)) -return NF_DROP ; -if (((ct->status &IPS_NAT_DONE_MASK ) ==0 ) ||nf_ct_match (ct, loser_ct)) {struct net *net =nf_ct_net (ct); +nf_conntrack_get (&ct->ct_general); +nf_ct_acct_merge (ct, ctinfo, loser_ct);nf_ct_add_to_dying_list (loser_ct);nf_conntrack_put (&loser_ct->ct_general);
@@ -937,7 +937,6 @@ static int __nf_ct_resolve_clash(struct sk_buff *skb,return NF_ACCEPT ; } -nf_ct_put (ct);return NF_DROP ; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 8/13 netfilter: xt_HMARK: Use ip_is_fragment() helper
In reply to Pablo Neira AyusoFrom: YueHaibing <[email protected]>
Use ip_is_fragment() to simpify code.
--- net/netfilter/xt_HMARK.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_HMARK.c +1 -1
@@ -276,7 +276,7 @@ hmark_pkt_set_htuple_ipv4(const struct sk_buff *skb, struct hmark_tuple *t,return 0 ;/* follow-up fragments don't contain ports, skip all fragments */ -if (ip->frag_off &htons (IP_MF |IP_OFFSET )) +if (ip_is_fragment (ip))return 0 ;hmark_set_tuple_ports (skb, (ip->ihl *4 ) + nhoff, t, info);
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 9/13 netfilter: nft_socket: add wildcard support
In reply to Pablo Neira AyusoFrom: Balazs Scheidler <[email protected]>
Add NFT_SOCKET_WILDCARD to match to wildcard socket listener.
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_socket.c | 27 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1010,10 +1010,12 @@ enum nft_socket_attributes {* * @NFT_SOCKET_TRANSPARENT: Value of the IP(V6)_TRANSPARENT socket option * @NFT_SOCKET_MARK: Value of the socket mark +* @NFT_SOCKET_WILDCARD: Whether the socket is zero-bound (e.g. 0.0.0.0 or ::0) */ enum nft_socket_keys {NFT_SOCKET_TRANSPARENT ,NFT_SOCKET_MARK , +NFT_SOCKET_WILDCARD , __NFT_SOCKET_MAX };#define NFT_SOCKET_MAX (__NFT_SOCKET_MAX - 1)
net/netfilter/nft_socket.c +27 -0
@@ -14,6 +14,25 @@ struct nft_socket { }; }; +static void nft_socket_wildcard (const struct nft_pktinfo *pkt, +struct nft_regs *regs,struct sock *sk, +u32 *dest) +{ +switch (nft_pf (pkt)) { +case NFPROTO_IPV4 : +nft_reg_store8 (dest,inet_sk (sk)->inet_rcv_saddr ==0 ); +break ; +#if IS_ENABLED (CONFIG_NF_TABLES_IPV6 ) +case NFPROTO_IPV6 : +nft_reg_store8 (dest,ipv6_addr_any (&sk->sk_v6_rcv_saddr)); +break ; +#endif +default : + regs->verdict.code =NFT_BREAK ; +return ; + } +} +static void nft_socket_eval (const struct nft_expr *expr,struct nft_regs *regs,const struct nft_pktinfo *pkt)
@@ -59,6 +78,13 @@ static void nft_socket_eval(const struct nft_expr *expr,return ; }break ; +case NFT_SOCKET_WILDCARD : +if (!sk_fullsock (sk)) { + regs->verdict.code =NFT_BREAK ; +return ; + } +nft_socket_wildcard (pkt, regs, sk, dest); +break ;default :WARN_ON (1 ); regs->verdict.code =NFT_BREAK ;
@@ -97,6 +123,7 @@ static int nft_socket_init(const struct nft_ctx *ctx, priv->key =ntohl (nla_get_u32 (tb[NFTA_SOCKET_KEY ]));switch (priv->key) {case NFT_SOCKET_TRANSPARENT : +case NFT_SOCKET_WILDCARD : len =sizeof (u8);break ;case NFT_SOCKET_MARK :
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 10/13 ipvs: remove dependency on ip6_tables
In reply to Pablo Neira AyusoFrom: Yaroslav Bolyukin <[email protected]>
This dependency was added because ipv6_find_hdr was in iptables specific code but is no longer required
--- include/net/ip_vs.h | 3 --- net/netfilter/ipvs/Kconfig | 1 - 2 files changed, 4 deletions(-)
include/net/ip_vs.h +0 -3
@@ -25,9 +25,6 @@#include <linux/ip.h> #include <linux/ipv6.h> /* for struct ipv6hdr */ #include <net/ipv6.h> -#if IS_ENABLED (CONFIG_IP_VS_IPV6 ) -#include <linux/netfilter_ipv6/ip6_tables.h> -#endif #if IS_ENABLED (CONFIG_NF_CONNTRACK )#include <net/netfilter/nf_conntrack.h> #endif
net/netfilter/ipvs/Kconfig +0 -1
@@ -29,7 +29,6 @@ if IP_VS config IP_VS_IPV6 bool "IPv6 support for IPVS" depends on IPV6 = y || IP_VS = IPV6 - select IP6_NF_IPTABLES select NF_DEFRAG_IPV6 help Add IPv6 support to IPVS.
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 11/13 netfilter: ebt_stp: Remove unused macro BPDU_TYPE_TCN
In reply to Pablo Neira AyusoFrom: Wang Hai <[email protected]>
BPDU_TYPE_TCN is never used after it was introduced. So better to remove it.
--- net/bridge/netfilter/ebt_stp.c | 1 - 1 file changed, 1 deletion(-)
net/bridge/netfilter/ebt_stp.c +0 -1
@@ -15,7 +15,6 @@#include <linux/netfilter_bridge/ebt_stp.h> #define BPDU_TYPE_CONFIG 0 -#define BPDU_TYPE_TCN 0x80struct stp_header {u8 dsap;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 12/13 selftests/net: replace obsolete NFT_CHAIN configuration
In reply to Pablo Neira AyusoFrom: Fabian Frederick <[email protected]>
Replace old parameters with global NFT_NAT from commit db8ab38880e0 ("netfilter: nf_tables: merge ipv4 and ipv6 nat chain types")
--- tools/testing/selftests/net/config | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tools/testing/selftests/net/config +1 -2
@@ -24,8 +24,7 @@ CONFIG_IP_NF_NAT=m CONFIG_NF_TABLES=m CONFIG_NF_TABLES_IPV6=y CONFIG_NF_TABLES_IPV4=y -CONFIG_NFT_CHAIN_NAT_IPV6=m -CONFIG_NFT_CHAIN_NAT_IPV4=m +CONFIG_NFT_NAT=m CONFIG_NET_SCH_FQ=m CONFIG_NET_SCH_ETF=m CONFIG_NET_SCH_NETEM=y
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 13/13 netfilter: nf_tables: add userdata support for nft_object
In reply to Pablo Neira AyusoFrom: "Jose M. Guisado Gomez" <[email protected]>
Enables storing userdata for nft_object. Initially this will store an optional comment but can be extended in the future as needed.
Adds new attribute NFTA_OBJ_USERDATA to nft_object.
--- include/net/netfilter/nf_tables.h | 2 ++ include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_tables_api.c | 35 ++++++++++++++++++------ 3 files changed, 31 insertions(+), 8 deletions(-)
include/net/netfilter/nf_tables.h +2 -0
@@ -1123,6 +1123,8 @@ struct nft_object { u32 genmask:2, use:30;u64 handle; +u16 udlen; +u8 *udata;/* runtime data below here */ const struct nft_object_ops *ops____cacheline_aligned ;unsigned char data[]
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1559,6 +1559,7 @@ enum nft_ct_expectation_attributes {* @NFTA_OBJ_DATA: stateful object data (NLA_NESTED) * @NFTA_OBJ_USE: number of references to this expression (NLA_U32) * @NFTA_OBJ_HANDLE: object handle (NLA_U64) +* @NFTA_OBJ_USERDATA: user data (NLA_BINARY) */ enum nft_object_attributes {NFTA_OBJ_UNSPEC ,
@@ -1569,6 +1570,7 @@ enum nft_object_attributes {NFTA_OBJ_USE ,NFTA_OBJ_HANDLE ,NFTA_OBJ_PAD , +NFTA_OBJ_USERDATA , __NFTA_OBJ_MAX };#define NFTA_OBJ_MAX (__NFTA_OBJ_MAX - 1)
net/netfilter/nf_tables_api.c +27 -8
@@ -5755,6 +5755,8 @@ static const struct nla_policy nft_obj_policy[NFTA_OBJ_MAX + 1] = { [NFTA_OBJ_TYPE] = { .type = NLA_U32 }, [NFTA_OBJ_DATA] = { .type = NLA_NESTED }, [NFTA_OBJ_HANDLE] = { .type = NLA_U64}, + [NFTA_OBJ_USERDATA ] = { .type =NLA_BINARY , + .len = NFT_USERDATA_MAXLEN }, }; static struct nft_object *nft_obj_init(const struct nft_ctx *ctx,
@@ -5902,6 +5904,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,struct nft_object *obj;struct nft_ctx ctx;u32 objtype; +u16 udlen;int err; if (!nla[NFTA_OBJ_TYPE] ||
@@ -5946,7 +5949,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk, obj =nft_obj_init (&ctx, type, nla[NFTA_OBJ_DATA ]);if (IS_ERR (obj)) { err =PTR_ERR (obj); - goto err1; + goto err_init; } obj->key.table = table; obj->handle =nf_tables_alloc_handle (table);
@@ -5954,32 +5957,44 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk, obj->key.name =nla_strdup (nla[NFTA_OBJ_NAME ],GFP_KERNEL );if (!obj->key.name) { err = -ENOMEM ; - goto err2; + goto err_strdup; + } + +if (nla[NFTA_OBJ_USERDATA ]) { + udlen =nla_len (nla[NFTA_OBJ_USERDATA ]); + obj->udata =kzalloc (udlen,GFP_KERNEL ); +if (obj->udata ==NULL ) + goto err_userdata; + +nla_memcpy (obj->udata, nla[NFTA_OBJ_USERDATA ], udlen); + obj->udlen = udlen; } err =nft_trans_obj_add (&ctx,NFT_MSG_NEWOBJ , obj);if (err <0 ) - goto err3; + goto err_trans; err =rhltable_insert (&nft_objname_ht, &obj->rhlhead, nft_objname_ht_params);if (err <0 ) - goto err4; + goto err_obj_ht;list_add_tail_rcu (&obj->list, &table->objects); table->use++;return 0 ; -err4: +err_obj_ht:/* queued in transaction log */ INIT_LIST_HEAD (&obj->list);return err; -err3: +err_trans:kfree (obj->key.name); -err2: +err_userdata: +kfree (obj->udata); +err_strdup:if (obj->ops->destroy) obj->ops->destroy (&ctx, obj);kfree (obj); -err1: +err_init:module_put (type->owner);return err; }
@@ -6011,6 +6026,10 @@ static int nf_tables_fill_obj_info(struct sk_buff *skb, struct net *net, NFTA_OBJ_PAD)) goto nla_put_failure; +if (obj->udata && +nla_put (skb,NFTA_OBJ_USERDATA , obj->udlen, obj->udata)) + goto nla_put_failure; +nlmsg_end (skb, nlh);return 0 ;
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Wed, 9 Sep 2020 11:42:06 +0200
Quoted 1 line
The following patchset contains Netfilter updates for net-next:
...
Quoted 3 lines
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thanks a lot.