Netfilter fixes for net
Subsystems (5)
Pablo Neira Ayuso
maintainerv2 cover Netfilter fixes for net
Hi,
The following patchset contains Netfilter fixes for net:
1) Restrict range element expansion in ipset to avoid soft lockup, from Jozsef Kadlecsik.
2) Memleak in error path for nf_conntrack_bridge for IPv4 packets, from Yajun Deng.
3) Simplify conntrack garbage collection strategy to avoid frequent wake-ups, from Florian Westphal.
4) Fix NFNLA_HOOK_FUNCTION_NAME string, do not include module name.
5) Missing chain family netlink attribute in chain description in nfnetlink_hook.
6) Incorrect sequence number on nfnetlink_hook dumps.
7) Use netlink request family in reply message for consistency.
8) Remove offload_pickup sysctl, use conntrack for established state instead, from Florian Westphal.
9) Translate NFPROTO_INET/ingress to NFPROTO_NETDEV/ingress, since NFPROTO_INET is not exposed through nfnetlink_hook.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git
v2: This batch includes the missing rcu_read_unlock() for patch 3/9.
Thanks!
----------------------------------------------------------------
The following changes since commit c7d102232649226a69dddd58a4942cf13cff4f7c:
Merge tag 'net-5.14-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net (2021-07-30 16:01:36 -0700)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf.git HEAD
for you to fetch changes up to 269fc69533de73a9065c0b7971bcd109880290b3:
netfilter: nfnetlink_hook: translate inet ingress to netdev (2021-08-06 17:07:41 +0200)
----------------------------------------------------------------
Florian Westphal (2):
netfilter: conntrack: collect all entries in one cycle
netfilter: conntrack: remove offload_pickup sysctl again
Jozsef Kadlecsik (1):
netfilter: ipset: Limit the maximal range of consecutive elements to add/delete
Pablo Neira Ayuso (5):
netfilter: nfnetlink_hook: strip off module name from hookfn
netfilter: nfnetlink_hook: missing chain family
netfilter: nfnetlink_hook: use the sequence number of the request message
netfilter: nfnetlink_hook: Use same family as request message
netfilter: nfnetlink_hook: translate inet ingress to netdev
Yajun Deng (1):
netfilter: nf_conntrack_bridge: Fix memory leak when error
Documentation/networking/nf_conntrack-sysctl.rst | 10 ---- include/linux/netfilter/ipset/ip_set.h | 3 + include/net/netns/conntrack.h | 2 - include/uapi/linux/netfilter/nfnetlink_hook.h | 9 +++ net/bridge/netfilter/nf_conntrack_bridge.c | 6 ++ net/netfilter/ipset/ip_set_hash_ip.c | 9 ++- net/netfilter/ipset/ip_set_hash_ipmark.c | 10 +++- net/netfilter/ipset/ip_set_hash_ipport.c | 3 + net/netfilter/ipset/ip_set_hash_ipportip.c | 3 + net/netfilter/ipset/ip_set_hash_ipportnet.c | 3 + net/netfilter/ipset/ip_set_hash_net.c | 11 +++- net/netfilter/ipset/ip_set_hash_netiface.c | 10 +++- net/netfilter/ipset/ip_set_hash_netnet.c | 16 +++++- net/netfilter/ipset/ip_set_hash_netport.c | 11 +++- net/netfilter/ipset/ip_set_hash_netportnet.c | 16 +++++- net/netfilter/nf_conntrack_core.c | 71 ++++++++---------------- net/netfilter/nf_conntrack_proto_tcp.c | 1 - net/netfilter/nf_conntrack_proto_udp.c | 1 - net/netfilter/nf_conntrack_standalone.c | 16 ------ net/netfilter/nf_flow_table_core.c | 11 +++- net/netfilter/nfnetlink_hook.c | 24 ++++++-- 21 files changed, 151 insertions(+), 95 deletions(-)
Pablo Neira Ayuso
maintainerPATCH v2 1/9 netfilter: ipset: Limit the maximal range of consecutive elements to add/delete
From: Jozsef Kadlecsik <[email protected]>
The range size of consecutive elements were not limited. Thus one could define a huge range which may result soft lockup errors due to the long execution time. Now the range size is limited to 2^20 entries.
--- include/linux/netfilter/ipset/ip_set.h | 3 +++ net/netfilter/ipset/ip_set_hash_ip.c | 9 ++++++++- net/netfilter/ipset/ip_set_hash_ipmark.c | 10 +++++++++- net/netfilter/ipset/ip_set_hash_ipport.c | 3 +++ net/netfilter/ipset/ip_set_hash_ipportip.c | 3 +++ net/netfilter/ipset/ip_set_hash_ipportnet.c | 3 +++ net/netfilter/ipset/ip_set_hash_net.c | 11 ++++++++++- net/netfilter/ipset/ip_set_hash_netiface.c | 10 +++++++++- net/netfilter/ipset/ip_set_hash_netnet.c | 16 +++++++++++++++- net/netfilter/ipset/ip_set_hash_netport.c | 11 ++++++++++- net/netfilter/ipset/ip_set_hash_netportnet.c | 16 +++++++++++++++- 11 files changed, 88 insertions(+), 7 deletions(-)
include/linux/netfilter/ipset/ip_set.h +3 -0
@@ -196,6 +196,9 @@ struct ip_set_region {u32 elements;/* Number of elements vs timeout */ }; +/* Max range where every element is added/deleted in one step */ +#define IPSET_MAX_RANGE (1<<20) +/* The max revision number supported by any set type + 1 */ #define IPSET_REVISION_MAX 9
net/netfilter/ipset/ip_set_hash_ip.c +8 -1
@@ -132,8 +132,11 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[], ret =ip_set_get_hostipaddr4 (tb[IPSET_ATTR_IP_TO ], &ip_to);if (ret)return ret; -if (ip > ip_to) +if (ip > ip_to) { +if (ip_to ==0 ) +return -IPSET_ERR_HASH_ELEM ;swap (ip, ip_to); + } }else if (tb[IPSET_ATTR_CIDR ]) {u8 cidr =nla_get_u8 (tb[IPSET_ATTR_CIDR ]);
@@ -144,6 +147,10 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[], hosts = h->netmask ==32 ?1 :2 << (32 - h->netmask -1 ); +/* 64bit division is not allowed on 32bit */ +if (((u64 )ip_to - ip +1 ) >> (32 - h->netmask) >IPSET_MAX_RANGE ) +return -ERANGE ; +if (retried) { ip =ntohl (h->next.ip); e.ip =htonl (ip);
net/netfilter/ipset/ip_set_hash_ipmark.c +9 -1
@@ -121,6 +121,8 @@ hash_ipmark4_uadt(struct ip_set *set, struct nlattr *tb[], e.mark =ntohl (nla_get_be32 (tb[IPSET_ATTR_MARK ])); e.mark &= h->markmask; +if (e.mark ==0 && e.ip ==0 ) +return -IPSET_ERR_HASH_ELEM ;if (adt ==IPSET_TEST || !(tb[IPSET_ATTR_IP_TO ] || tb[IPSET_ATTR_CIDR ])) {
@@ -133,8 +135,11 @@ hash_ipmark4_uadt(struct ip_set *set, struct nlattr *tb[], ret =ip_set_get_hostipaddr4 (tb[IPSET_ATTR_IP_TO ], &ip_to);if (ret)return ret; -if (ip > ip_to) +if (ip > ip_to) { +if (e.mark ==0 && ip_to ==0 ) +return -IPSET_ERR_HASH_ELEM ;swap (ip, ip_to); + } }else if (tb[IPSET_ATTR_CIDR ]) {u8 cidr =nla_get_u8 (tb[IPSET_ATTR_CIDR ]);
@@ -143,6 +148,9 @@ hash_ipmark4_uadt(struct ip_set *set, struct nlattr *tb[],ip_set_mask_from_to (ip, ip_to, cidr); } +if (((u64 )ip_to - ip +1 ) >IPSET_MAX_RANGE ) +return -ERANGE ; +if (retried) ip =ntohl (h->next.ip);for (; ip <= ip_to; ip++) {
net/netfilter/ipset/ip_set_hash_ipport.c +3 -0
@@ -173,6 +173,9 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],swap (port, port_to); } +if (((u64 )ip_to - ip +1 )*(port_to - port +1 ) >IPSET_MAX_RANGE ) +return -ERANGE ; +if (retried) ip =ntohl (h->next.ip);for (; ip <= ip_to; ip++) {
net/netfilter/ipset/ip_set_hash_ipportip.c +3 -0
@@ -180,6 +180,9 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],swap (port, port_to); } +if (((u64 )ip_to - ip +1 )*(port_to - port +1 ) >IPSET_MAX_RANGE ) +return -ERANGE ; +if (retried) ip =ntohl (h->next.ip);for (; ip <= ip_to; ip++) {
net/netfilter/ipset/ip_set_hash_ipportnet.c +3 -0
@@ -253,6 +253,9 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],swap (port, port_to); } +if (((u64 )ip_to - ip +1 )*(port_to - port +1 ) >IPSET_MAX_RANGE ) +return -ERANGE ; + ip2_to = ip2_from;if (tb[IPSET_ATTR_IP2_TO ]) { ret =ip_set_get_hostipaddr4 (tb[IPSET_ATTR_IP2_TO ], &ip2_to);
net/netfilter/ipset/ip_set_hash_net.c +10 -1
@@ -140,7 +140,7 @@ hash_net4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_net4_elem e = { .cidr =HOST_MASK };struct ip_set_ext ext =IP_SET_INIT_UEXT (set); -u32 ip =0 , ip_to =0 ; +u32 ip =0 , ip_to =0 , ipn, n =0 ;int ret;if (tb[IPSET_ATTR_LINENO ])
@@ -188,6 +188,15 @@ hash_net4_uadt(struct ip_set *set, struct nlattr *tb[],if (ip +UINT_MAX == ip_to)return -IPSET_ERR_HASH_RANGE ; } + ipn = ip; +do { + ipn =ip_set_range_to_cidr (ipn, ip_to, &e.cidr); + n++; + }while (ipn++ < ip_to); + +if (n >IPSET_MAX_RANGE ) +return -ERANGE ; +if (retried) ip =ntohl (h->next.ip); do {
net/netfilter/ipset/ip_set_hash_netiface.c +9 -1
@@ -202,7 +202,7 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netiface4_elem e = { .cidr =HOST_MASK , .elem =1 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set); -u32 ip =0 , ip_to =0 ; +u32 ip =0 , ip_to =0 , ipn, n =0 ;int ret;if (tb[IPSET_ATTR_LINENO ])
@@ -256,6 +256,14 @@ hash_netiface4_uadt(struct ip_set *set, struct nlattr *tb[], }else {ip_set_mask_from_to (ip, ip_to, e.cidr); } + ipn = ip; +do { + ipn =ip_set_range_to_cidr (ipn, ip_to, &e.cidr); + n++; + }while (ipn++ < ip_to); + +if (n >IPSET_MAX_RANGE ) +return -ERANGE ;if (retried) ip =ntohl (h->next.ip);
net/netfilter/ipset/ip_set_hash_netnet.c +15 -1
@@ -168,7 +168,8 @@ hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[],struct hash_netnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 , ip_to =0 ; -u32 ip2 =0 , ip2_from =0 , ip2_to =0 ; +u32 ip2 =0 , ip2_from =0 , ip2_to =0 , ipn; +u64 n =0 , m =0 ;int ret;if (tb[IPSET_ATTR_LINENO ])
@@ -244,6 +245,19 @@ hash_netnet4_uadt(struct ip_set *set, struct nlattr *tb[], }else {ip_set_mask_from_to (ip2_from, ip2_to, e.cidr[1 ]); } + ipn = ip; +do { + ipn =ip_set_range_to_cidr (ipn, ip_to, &e.cidr[0 ]); + n++; + }while (ipn++ < ip_to); + ipn = ip2_from; +do { + ipn =ip_set_range_to_cidr (ipn, ip2_to, &e.cidr[1 ]); + m++; + }while (ipn++ < ip2_to); + +if (n*m >IPSET_MAX_RANGE ) +return -ERANGE ;if (retried) { ip =ntohl (h->next.ip[0 ]);
net/netfilter/ipset/ip_set_hash_netport.c +10 -1
@@ -158,7 +158,8 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[],ipset_adtfn adtfn = set->variant->adt[adt];struct hash_netport4_elem e = { .cidr =HOST_MASK -1 };struct ip_set_ext ext =IP_SET_INIT_UEXT (set); -u32 port, port_to, p =0 , ip =0 , ip_to =0 ; +u32 port, port_to, p =0 , ip =0 , ip_to =0 , ipn; +u64 n =0 ;bool with_ports = false;u8 cidr;int ret;
@@ -235,6 +236,14 @@ hash_netport4_uadt(struct ip_set *set, struct nlattr *tb[], }else {ip_set_mask_from_to (ip, ip_to, e.cidr +1 ); } + ipn = ip; +do { + ipn =ip_set_range_to_cidr (ipn, ip_to, &cidr); + n++; + }while (ipn++ < ip_to); + +if (n*(port_to - port +1 ) >IPSET_MAX_RANGE ) +return -ERANGE ;if (retried) { ip =ntohl (h->next.ip);
net/netfilter/ipset/ip_set_hash_netportnet.c +15 -1
@@ -182,7 +182,8 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[],struct hash_netportnet4_elem e = { };struct ip_set_ext ext =IP_SET_INIT_UEXT (set);u32 ip =0 , ip_to =0 , p =0 , port, port_to; -u32 ip2_from =0 , ip2_to =0 , ip2; +u32 ip2_from =0 , ip2_to =0 , ip2, ipn; +u64 n =0 , m =0 ;bool with_ports = false;int ret;
@@ -284,6 +285,19 @@ hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[], }else {ip_set_mask_from_to (ip2_from, ip2_to, e.cidr[1 ]); } + ipn = ip; +do { + ipn =ip_set_range_to_cidr (ipn, ip_to, &e.cidr[0 ]); + n++; + }while (ipn++ < ip_to); + ipn = ip2_from; +do { + ipn =ip_set_range_to_cidr (ipn, ip2_to, &e.cidr[1 ]); + m++; + }while (ipn++ < ip2_to); + +if (n*m*(port_to - port +1 ) >IPSET_MAX_RANGE ) +return -ERANGE ;if (retried) { ip =ntohl (h->next.ip[0 ]);
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 2/9 netfilter: nf_conntrack_bridge: Fix memory leak when error
In reply to Pablo Neira AyusoFrom: Yajun Deng <[email protected]>
It should be added kfree_skb_list() when err is not equal to zero in nf_br_ip_fragment().
v2: keep this aligned with IPv6.
v3: modify iter.frag_list to iter.frag.
--- net/bridge/netfilter/nf_conntrack_bridge.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/bridge/netfilter/nf_conntrack_bridge.c +6 -0
@@ -88,6 +88,12 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk, skb =ip_fraglist_next (&iter); } + +if (!err) +return 0 ; + +kfree_skb_list (iter.frag); +return err; } slow_path:
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 3/9 netfilter: conntrack: collect all entries in one cycle
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
Michal Kubecek reports that conntrack gc is responsible for frequent wakeups (every 125ms) on idle systems.
On busy systems, timed out entries are evicted during lookup. The gc worker is only needed to remove entries after system becomes idle after a busy period.
To resolve this, always scan the entire table.
If the scan is taking too long, reschedule so other work_structs can run and resume from next bucket.
After a completed scan, wait for 2 minutes before the next cycle. Heuristics for faster re-schedule are removed.
GC_SCAN_INTERVAL could be exposed as a sysctl in the future to allow tuning this as-needed or even turn the gc worker off.
--- net/netfilter/nf_conntrack_core.c | 71 ++++++++++--------------------- 1 file changed, 22 insertions(+), 49 deletions(-)
net/netfilter/nf_conntrack_core.c +22 -49
@@ -66,22 +66,17 @@ EXPORT_SYMBOL_GPL(nf_conntrack_hash);struct conntrack_gc_work {struct delayed_work dwork; -u32 last_bucket; +u32 next_bucket;bool exiting;bool early_drop; -long next_gc_run; };static __read_mostly struct kmem_cache *nf_conntrack_cachep;static DEFINE_SPINLOCK (nf_conntrack_locks_all_lock);static __read_mostly bool nf_conntrack_locks_all; -/* every gc cycle scans at most 1/GC_MAX_BUCKETS_DIV part of table */ -#define GC_MAX_BUCKETS_DIV 128u -/* upper bound of full table scan */ -#define GC_MAX_SCAN_JIFFIES (16u * HZ) -/* desired ratio of entries found to be expired */ -#define GC_EVICT_RATIO 50u +#define GC_SCAN_INTERVAL (120u * HZ) +#define GC_SCAN_MAX_DURATION msecs_to_jiffies(10)static struct conntrack_gc_work conntrack_gc_work;
@@ -1363,17 +1358,13 @@ static bool gc_worker_can_early_drop(const struct nf_conn *ct)static void gc_worker (struct work_struct *work) { -unsigned int min_interval =max (HZ /GC_MAX_BUCKETS_DIV ,1u ); -unsigned int i, goal, buckets =0 , expired_count =0 ; -unsigned int nf_conntrack_max95 =0 ; +unsigned long end_time = jiffies +GC_SCAN_MAX_DURATION ; +unsigned int i, hashsz, nf_conntrack_max95 =0 ; +unsigned long next_run =GC_SCAN_INTERVAL ;struct conntrack_gc_work *gc_work; -unsigned int ratio, scanned =0 ; -unsigned long next_run; - gc_work = container_of(work, struct conntrack_gc_work, dwork.work); - goal = nf_conntrack_htable_size /GC_MAX_BUCKETS_DIV ; - i = gc_work->last_bucket; + i = gc_work->next_bucket;if (gc_work->early_drop) nf_conntrack_max95 = nf_conntrack_max /100u *95u ;
@@ -1381,15 +1372,15 @@ static void gc_worker(struct work_struct *work)struct nf_conntrack_tuple_hash *h;struct hlist_nulls_head *ct_hash;struct hlist_nulls_node *n; -unsigned int hashsz;struct nf_conn *tmp; - i++;rcu_read_lock ();nf_conntrack_get_ht (&ct_hash, &hashsz); -if (i >= hashsz) - i =0 ; +if (i >= hashsz) { +rcu_read_unlock (); +break ; + }hlist_nulls_for_each_entry_rcu (h, n, &ct_hash[i], hnnode) {struct nf_conntrack_net *cnet;
@@ -1397,7 +1388,6 @@ static void gc_worker(struct work_struct *work) tmp =nf_ct_tuplehash_to_ctrack (h); - scanned++;if (test_bit (IPS_OFFLOAD_BIT , &tmp->status)) {nf_ct_offload_timeout (tmp);continue ;
@@ -1405,7 +1395,6 @@ static void gc_worker(struct work_struct *work)if (nf_ct_is_expired (tmp)) {nf_ct_gc_expired (tmp); - expired_count++;continue ; }
@@ -1438,7 +1427,14 @@ static void gc_worker(struct work_struct *work)*/ rcu_read_unlock ();cond_resched (); - }while (++buckets < goal); + i++; + +if (time_after (jiffies, end_time) && i < hashsz) { + gc_work->next_bucket = i; + next_run =0 ; +break ; + } + }while (i < hashsz);if (gc_work->exiting)return ;
@@ -1449,40 +1445,17 @@ static void gc_worker(struct work_struct *work)* * This worker is only here to reap expired entries when system went * idle after a busy period. -* -* The heuristics below are supposed to balance conflicting goals: -* -* 1. Minimize time until we notice a stale entry -* 2. Maximize scan intervals to not waste cycles -* -* Normally, expire ratio will be close to 0. -* -* As soon as a sizeable fraction of the entries have expired -* increase scan frequency. */ - ratio = scanned ? expired_count *100 / scanned :0 ; -if (ratio >GC_EVICT_RATIO ) { - gc_work->next_gc_run = min_interval; - }else { -unsigned int max =GC_MAX_SCAN_JIFFIES /GC_MAX_BUCKETS_DIV ; - -BUILD_BUG_ON ((GC_MAX_SCAN_JIFFIES /GC_MAX_BUCKETS_DIV ) ==0 ); - - gc_work->next_gc_run += min_interval; -if (gc_work->next_gc_run > max) - gc_work->next_gc_run = max; +if (next_run) { + gc_work->early_drop = false; + gc_work->next_bucket =0 ; } - - next_run = gc_work->next_gc_run; - gc_work->last_bucket = i; - gc_work->early_drop = false;queue_delayed_work (system_power_efficient_wq, &gc_work->dwork, next_run); }static void conntrack_gc_work_init (struct conntrack_gc_work *gc_work) {INIT_DEFERRABLE_WORK (&gc_work->dwork, gc_worker); - gc_work->next_gc_run =HZ ; gc_work->exiting = false; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 4/9 netfilter: nfnetlink_hook: strip off module name from hookfn
In reply to Pablo Neira AyusoNFNLA_HOOK_FUNCTION_NAME should include the hook function name only, the module name is already provided by NFNLA_HOOK_MODULE_NAME.
--- net/netfilter/nfnetlink_hook.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nfnetlink_hook.c +1 -0
@@ -135,6 +135,7 @@ static int nfnl_hook_dump_one(struct sk_buff *nlskb,if (module_name) {char *end; + *module_name ='\0' ; module_name +=2 ; end =strchr (module_name,']' );if (end) {
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 5/9 netfilter: nfnetlink_hook: missing chain family
In reply to Pablo Neira AyusoThe family is relevant for pseudo-families like NFPROTO_INET otherwise the user needs to rely on the hook function name to differentiate it from NFPROTO_IPV4 and NFPROTO_IPV6 names.
Add nfnl_hook_chain_desc_attributes instead of using the existing NFTA_CHAIN_* attributes, since these do not provide a family number.
--- include/uapi/linux/netfilter/nfnetlink_hook.h | 9 +++++++++ net/netfilter/nfnetlink_hook.c | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-)
include/uapi/linux/netfilter/nfnetlink_hook.h +9 -0
@@ -43,6 +43,15 @@ enum nfnl_hook_chain_info_attributes { };#define NFNLA_HOOK_INFO_MAX (__NFNLA_HOOK_INFO_MAX - 1) +enum nfnl_hook_chain_desc_attributes { +NFNLA_CHAIN_UNSPEC , +NFNLA_CHAIN_TABLE , +NFNLA_CHAIN_FAMILY , +NFNLA_CHAIN_NAME , + __NFNLA_CHAIN_MAX, +}; +#define NFNLA_CHAIN_MAX (__NFNLA_CHAIN_MAX - 1) +/** * enum nfnl_hook_chaintype - chain type *
net/netfilter/nfnetlink_hook.c +6 -2
@@ -89,11 +89,15 @@ static int nfnl_hook_put_nft_chain_info(struct sk_buff *nlskb,if (!nest2) goto cancel_nest; - ret =nla_put_string (nlskb,NFTA_CHAIN_TABLE , chain->table->name); + ret =nla_put_string (nlskb,NFNLA_CHAIN_TABLE , chain->table->name);if (ret) goto cancel_nest; - ret =nla_put_string (nlskb,NFTA_CHAIN_NAME , chain->name); + ret =nla_put_string (nlskb,NFNLA_CHAIN_NAME , chain->name); +if (ret) + goto cancel_nest; + + ret =nla_put_u8 (nlskb,NFNLA_CHAIN_FAMILY , chain->table->family);if (ret) goto cancel_nest;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 8/9 netfilter: conntrack: remove offload_pickup sysctl again
In reply to Pablo Neira AyusoFrom: Florian Westphal <[email protected]>
These two sysctls were added because the hardcoded defaults (2 minutes, tcp, 30 seconds, udp) turned out to be too low for some setups.
They appeared in 5.14-rc1 so it should be fine to remove it again.
Marcelo convinced me that there should be no difference between a flow that was offloaded vs. a flow that was not wrt. timeout handling. Thus the default is changed to those for TCP established and UDP stream, 5 days and 120 seconds, respectively.
Marcelo also suggested to account for the timeout value used for the offloading, this avoids increase beyond the value in the conntrack-sysctl and will also instantly expire the conntrack entry with altered sysctls.
Example:
nf_conntrack_udp_timeout_stream=60
nf_flowtable_udp_timeout=60
This will remove offloaded udp flows after one minute, rather than two.
An earlier version of this patch also cleared the ASSURED bit to allow nf_conntrack to evict the entry via early_drop (i.e., table full). However, it looks like we can safely assume that connection timed out via HW is still in established state, so this isn't needed.
Quoting Oz:
[..] the hardware sends all packets with a set FIN flags to sw. [..] Connections that are aged in hardware are expected to be in the established state.
In case it turns out that back-to-sw-path transition can occur for 'dodgy' connections too (e.g., one side disappeared while software-path would have been in RETRANS timeout), we can adjust this later.
--- Documentation/networking/nf_conntrack-sysctl.rst | 10 ---------- include/net/netns/conntrack.h | 2 -- net/netfilter/nf_conntrack_proto_tcp.c | 1 - net/netfilter/nf_conntrack_proto_udp.c | 1 - net/netfilter/nf_conntrack_standalone.c | 16 ---------------- net/netfilter/nf_flow_table_core.c | 11 ++++++++--- 6 files changed, 8 insertions(+), 33 deletions(-)
Documentation/networking/nf_conntrack-sysctl.rst +0 -10
@@ -191,19 +191,9 @@ nf_flowtable_tcp_timeout - INTEGER (seconds) TCP connections may be offloaded from nf conntrack to nf flow table. Once aged, the connection is returned to nf conntrack with tcp pickup timeout. -nf_flowtable_tcp_pickup - INTEGER (seconds) - default 120 - - TCP connection timeout after being aged from nf flow table offload. - nf_flowtable_udp_timeout - INTEGER (seconds) default 30 Control offload timeout for udp connections. UDP connections may be offloaded from nf conntrack to nf flow table. Once aged, the connection is returned to nf conntrack with udp pickup timeout. - -nf_flowtable_udp_pickup - INTEGER (seconds) - default 30 - - UDP connection timeout after being aged from nf flow table offload.
include/net/netns/conntrack.h +0 -2
@@ -30,7 +30,6 @@ struct nf_tcp_net {u8 tcp_ignore_invalid_rst;#if IS_ENABLED (CONFIG_NF_FLOW_TABLE )unsigned int offload_timeout; -unsigned int offload_pickup;#endif };
@@ -44,7 +43,6 @@ struct nf_udp_net {unsigned int timeouts[UDP_CT_MAX ];#if IS_ENABLED (CONFIG_NF_FLOW_TABLE )unsigned int offload_timeout; -unsigned int offload_pickup;#endif };
net/netfilter/nf_conntrack_proto_tcp.c +0 -1
@@ -1478,7 +1478,6 @@ void nf_conntrack_tcp_init_net(struct net *net)#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) tn->offload_timeout =30 *HZ ; - tn->offload_pickup =120 *HZ ;#endif }
net/netfilter/nf_conntrack_proto_udp.c +0 -1
@@ -271,7 +271,6 @@ void nf_conntrack_udp_init_net(struct net *net)#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) un->offload_timeout =30 *HZ ; - un->offload_pickup =30 *HZ ;#endif }
net/netfilter/nf_conntrack_standalone.c +0 -16
@@ -575,7 +575,6 @@ enum nf_ct_sysctl_index { NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_UNACK,#if IS_ENABLED (CONFIG_NF_FLOW_TABLE )NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD , -NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD_PICKUP , #endifNF_SYSCTL_CT_PROTO_TCP_LOOSE , NF_SYSCTL_CT_PROTO_TCP_LIBERAL,
@@ -585,7 +584,6 @@ enum nf_ct_sysctl_index { NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM,#if IS_ENABLED (CONFIG_NF_FLOW_TABLE )NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_OFFLOAD , -NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_OFFLOAD_PICKUP , #endifNF_SYSCTL_CT_PROTO_TIMEOUT_ICMP , NF_SYSCTL_CT_PROTO_TIMEOUT_ICMPV6,
@@ -776,12 +774,6 @@ static struct ctl_table nf_ct_sysctl_table[] = { .mode = 0644, .proc_handler = proc_dointvec_jiffies, }, - [NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD_PICKUP] = { - .procname = "nf_flowtable_tcp_pickup", - .maxlen = sizeof(unsigned int), - .mode = 0644, - .proc_handler = proc_dointvec_jiffies, - }, #endif [NF_SYSCTL_CT_PROTO_TCP_LOOSE] = { .procname = "nf_conntrack_tcp_loose",
@@ -832,12 +824,6 @@ static struct ctl_table nf_ct_sysctl_table[] = { .mode = 0644, .proc_handler = proc_dointvec_jiffies, }, - [NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_OFFLOAD_PICKUP] = { - .procname = "nf_flowtable_udp_pickup", - .maxlen = sizeof(unsigned int), - .mode = 0644, - .proc_handler = proc_dointvec_jiffies, - }, #endif [NF_SYSCTL_CT_PROTO_TIMEOUT_ICMP] = { .procname = "nf_conntrack_icmp_timeout",
@@ -1018,7 +1004,6 @@ static void nf_conntrack_standalone_init_tcp_sysctl(struct net *net,#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) table[NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD ].data = &tn->offload_timeout; - table[NF_SYSCTL_CT_PROTO_TIMEOUT_TCP_OFFLOAD_PICKUP ].data = &tn->offload_pickup;#endif }
@@ -1111,7 +1096,6 @@ static int nf_conntrack_standalone_init_sysctl(struct net *net) table[NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_STREAM ].data = &un->timeouts[UDP_CT_REPLIED ];#if IS_ENABLED (CONFIG_NF_FLOW_TABLE ) table[NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_OFFLOAD ].data = &un->offload_timeout; - table[NF_SYSCTL_CT_PROTO_TIMEOUT_UDP_OFFLOAD_PICKUP ].data = &un->offload_pickup;#endif nf_conntrack_standalone_init_tcp_sysctl (net, table);
net/netfilter/nf_flow_table_core.c +8 -3
@@ -183,7 +183,7 @@ static void flow_offload_fixup_ct_timeout(struct nf_conn *ct)const struct nf_conntrack_l4proto *l4proto;struct net *net =nf_ct_net (ct);int l4num =nf_ct_protonum (ct); -unsigned int timeout; +s32 timeout; l4proto =nf_ct_l4proto_find (l4num);if (!l4proto)
@@ -192,15 +192,20 @@ static void flow_offload_fixup_ct_timeout(struct nf_conn *ct)if (l4num ==IPPROTO_TCP ) {struct nf_tcp_net *tn =nf_tcp_pernet (net); - timeout = tn->offload_pickup; + timeout = tn->timeouts[TCP_CONNTRACK_ESTABLISHED ]; + timeout -= tn->offload_timeout; }else if (l4num ==IPPROTO_UDP ) {struct nf_udp_net *tn =nf_udp_pernet (net); - timeout = tn->offload_pickup; + timeout = tn->timeouts[UDP_CT_REPLIED ]; + timeout -= tn->offload_timeout; }else {return ; } +if (timeout <0 ) + timeout =0 ; +if (nf_flow_timeout_delta (ct->timeout) > (__s32 )timeout) ct->timeout = nfct_time_stamp + timeout; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 6/9 netfilter: nfnetlink_hook: use the sequence number of the request message
In reply to Pablo Neira AyusoThe sequence number allows to correlate the netlink reply message (as part of the dump) with the original request message.
The cb->seq field is internally used to detect an interference (update) of the hook list during the netlink dump, do not use it as sequence number in the netlink dump header.
--- net/netfilter/nfnetlink_hook.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/netfilter/nfnetlink_hook.c +2 -1
@@ -264,7 +264,8 @@ static int nfnl_hook_dump(struct sk_buff *nlskb, ops =nf_hook_entries_get_hook_ops (e);for (; i < e->num_hook_entries; i++) { - err =nfnl_hook_dump_one (nlskb, ctx, ops[i], cb->seq); + err =nfnl_hook_dump_one (nlskb, ctx, ops[i], + cb->nlh->nlmsg_seq);if (err)break ; }
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 7/9 netfilter: nfnetlink_hook: Use same family as request message
In reply to Pablo Neira AyusoUse the same family as the request message, for consistency. The netlink payload provides sufficient information to describe the hook object, including the family.
This makes it easier to userspace to correlate the hooks are that visited by the packets for a certain family.
--- net/netfilter/nfnetlink_hook.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
net/netfilter/nfnetlink_hook.c +3 -3
@@ -113,7 +113,7 @@ static int nfnl_hook_put_nft_chain_info(struct sk_buff *nlskb,static int nfnl_hook_dump_one (struct sk_buff *nlskb,const struct nfnl_dump_hook_data *ctx,const struct nf_hook_ops *ops, -unsigned int seq) +int family,unsigned int seq) {u16 event =nfnl_msg_type (NFNL_SUBSYS_HOOK ,NFNL_MSG_HOOK_GET );unsigned int portid =NETLINK_CB (nlskb).portid;
@@ -124,7 +124,7 @@ static int nfnl_hook_dump_one(struct sk_buff *nlskb,char *module_name;#endif nlh =nfnl_msg_put (nlskb, portid, seq, event, -NLM_F_MULTI , ops->pf,NFNETLINK_V0 ,0 ); +NLM_F_MULTI , family,NFNETLINK_V0 ,0 );if (!nlh) goto nla_put_failure;
@@ -264,7 +264,7 @@ static int nfnl_hook_dump(struct sk_buff *nlskb, ops =nf_hook_entries_get_hook_ops (e);for (; i < e->num_hook_entries; i++) { - err =nfnl_hook_dump_one (nlskb, ctx, ops[i], + err =nfnl_hook_dump_one (nlskb, ctx, ops[i], family, cb->nlh->nlmsg_seq);if (err)break ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH v2 9/9 netfilter: nfnetlink_hook: translate inet ingress to netdev
In reply to Pablo Neira AyusoThe NFPROTO_INET pseudofamily is not exposed through this new netlink interface. The netlink dump either shows NFPROTO_IPV4 or NFPROTO_IPV6 for NFPROTO_INET prerouting/input/forward/output/postrouting hooks. The NFNLA_CHAIN_FAMILY attribute provides the family chain, which specifies if this hook applies to inet traffic only (either IPv4 or IPv6).
Translate the inet/ingress hook to netdev/ingress to fully hide the NFPROTO_INET implementation details.
--- net/netfilter/nfnetlink_hook.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/netfilter/nfnetlink_hook.c +7 -1
@@ -119,6 +119,7 @@ static int nfnl_hook_dump_one(struct sk_buff *nlskb,unsigned int portid =NETLINK_CB (nlskb).portid;struct nlmsghdr *nlh;int ret = -EMSGSIZE ; +u32 hooknum;#ifdef CONFIG_KALLSYMS char sym[KSYM_SYMBOL_LEN ];char *module_name;
@@ -156,7 +157,12 @@ static int nfnl_hook_dump_one(struct sk_buff *nlskb, goto nla_put_failure;#endif - ret =nla_put_be32 (nlskb,NFNLA_HOOK_HOOKNUM ,htonl (ops->hooknum)); +if (ops->pf ==NFPROTO_INET && ops->hooknum ==NF_INET_INGRESS ) + hooknum =NF_NETDEV_INGRESS ; +else + hooknum = ops->hooknum; + + ret =nla_put_be32 (nlskb,NFNLA_HOOK_HOOKNUM ,htonl (hooknum));if (ret) goto nla_put_failure;
Signature · 1 line
2.20.1
Jakub Kicinski
maintainerQuoted 16 lines · On Fri, 6 Aug 2021 17:11:40 +0200 Pablo Neira Ayuso wrote:
1) Restrict range element expansion in ipset to avoid soft lockup, from Jozsef Kadlecsik.
2) Memleak in error path for
nf_conntrack_bridgefor IPv4 packets, from Yajun Deng.3) Simplify conntrack garbage collection strategy to avoid frequent wake-ups, from Florian Westphal.
4) Fix
NFNLA_HOOK_FUNCTION_NAMEstring, do not include module name.5) Missing chain family netlink attribute in chain description in
nfnetlink_hook.6) Incorrect sequence number on
nfnetlink_hookdumps.
Quoted 7 lines
7) Use netlink request family in reply message for consistency.
8) Remove
offload_pickupsysctl, use conntrack for established state instead, from Florian Westphal.9) Translate NFPROTO_INET/ingress to NFPROTO_NETDEV/ingress, since
NFPROTO_INETis not exposed throughnfnetlink_hook.
Looks like the bot doesn't want to respond :S
Pulled in the morning already, thanks!