Skip to content

Commit 4fd001f

Browse files
committed
Merge tag 'nf-next-25-01-19' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next
Pablo Neira Ayuso says: ==================== Netfilter updates for net-next The following batch contains Netfilter updates for net-next: 1) Unbreak set size settings for rbtree set backend, intervals in rbtree are represented as two elements, this detailed is leaked to userspace leading to bogus ENOSPC from control plane. 2) Remove dead code in br_netfilter's br_nf_pre_routing_finish() due to never matching error when looking up for route, from Antoine Tenart. 3) Simplify check for device already in use in flowtable, from Phil Sutter. 4) Three patches to restore interface name field in struct nft_hook and use it, this is to prepare for wildcard interface support. From Phil Sutter. 5) Do not remove netdev basechain when last device is gone, this is for consistency with the flowtable behaviour. This allows for netdev basechains without devices. Another patch to simplify netdev event notifier after this update. Also from Phil. 6) Two patches to add missing spinlock when flowtable updates TCP state flags, from Florian Westphal. 7) Simplify __nf_ct_refresh_acct() by removing skbuff parameter, also from Florian. 8) Flowtable gc now extends ct timeout for offloaded flow. This is to address a possible race that leads to handing over flow to classic path with long ct timeouts. 9) Tear down flow if cached rt_mtu is stale, before this patch, packet is handed over to classic path but flow entry still remained in place. 10) Revisit the flowtable teardown strategy, which was originally designed to release flowtable hardware entries early. Add a new CLOSING flag that still allows hardware to release entries when fin/rst is seen, but keeps the flow entry in place when the TCP connection is closed. Release flow after timeout or when a new syn packet is seen for TCP reopen scenario. * tag 'nf-next-25-01-19' of git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next: netfilter: flowtable: add CLOSING state netfilter: flowtable: teardown flow if cached mtu is stale netfilter: conntrack: rework offload nf_conn timeout extension logic netfilter: conntrack: remove skb argument from nf_ct_refresh netfilter: nft_flow_offload: update tcp state flags under lock netfilter: nft_flow_offload: clear tcp MAXACK flag before moving to slowpath netfilter: nf_tables: Simplify chain netdev notifier netfilter: nf_tables: Tolerate chains with no remaining hooks netfilter: nf_tables: Compare netdev hooks based on stored name netfilter: nf_tables: Use stored ifname in netdev hook dumps netfilter: nf_tables: Store user-defined hook ifname netfilter: nf_tables: Flowtable hook's pf value never varies netfilter: br_netfilter: remove unused conditional and dead code netfilter: nf_tables: fix set size with rbtree backend ==================== Link: https://patch.msgid.link/20250119172051.8261-1-pablo@netfilter.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 01f5f35 + fdbaf51 commit 4fd001f

16 files changed

+332
-185
lines changed

include/net/netfilter/nf_conntrack.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -204,24 +204,22 @@ bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,
204204
struct nf_conntrack_tuple *tuple);
205205

206206
void __nf_ct_refresh_acct(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
207-
const struct sk_buff *skb,
208-
u32 extra_jiffies, bool do_acct);
207+
u32 extra_jiffies, unsigned int bytes);
209208

210209
/* Refresh conntrack for this many jiffies and do accounting */
211210
static inline void nf_ct_refresh_acct(struct nf_conn *ct,
212211
enum ip_conntrack_info ctinfo,
213212
const struct sk_buff *skb,
214213
u32 extra_jiffies)
215214
{
216-
__nf_ct_refresh_acct(ct, ctinfo, skb, extra_jiffies, true);
215+
__nf_ct_refresh_acct(ct, ctinfo, extra_jiffies, skb->len);
217216
}
218217

219218
/* Refresh conntrack for this many jiffies */
220219
static inline void nf_ct_refresh(struct nf_conn *ct,
221-
const struct sk_buff *skb,
222220
u32 extra_jiffies)
223221
{
224-
__nf_ct_refresh_acct(ct, 0, skb, extra_jiffies, false);
222+
__nf_ct_refresh_acct(ct, 0, extra_jiffies, 0);
225223
}
226224

227225
/* kill conntrack and do accounting */
@@ -314,16 +312,6 @@ static inline bool nf_ct_should_gc(const struct nf_conn *ct)
314312

315313
#define NF_CT_DAY (86400 * HZ)
316314

317-
/* Set an arbitrary timeout large enough not to ever expire, this save
318-
* us a check for the IPS_OFFLOAD_BIT from the packet path via
319-
* nf_ct_is_expired().
320-
*/
321-
static inline void nf_ct_offload_timeout(struct nf_conn *ct)
322-
{
323-
if (nf_ct_expires(ct) < NF_CT_DAY / 2)
324-
WRITE_ONCE(ct->timeout, nfct_time_stamp + NF_CT_DAY);
325-
}
326-
327315
struct kernel_param;
328316

329317
int nf_conntrack_set_hashsize(const char *val, const struct kernel_param *kp);

include/net/netfilter/nf_flow_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ struct flow_offload_tuple_rhash {
163163
enum nf_flow_flags {
164164
NF_FLOW_SNAT,
165165
NF_FLOW_DNAT,
166+
NF_FLOW_CLOSING,
166167
NF_FLOW_TEARDOWN,
167168
NF_FLOW_HW,
168169
NF_FLOW_HW_DYING,

include/net/netfilter/nf_tables.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ struct nft_set_ext;
442442
* @remove: remove element from set
443443
* @walk: iterate over all set elements
444444
* @get: get set elements
445+
* @ksize: kernel set size
446+
* @usize: userspace set size
447+
* @adjust_maxsize: delta to adjust maximum set size
445448
* @commit: commit set elements
446449
* @abort: abort set elements
447450
* @privsize: function to return size of set private data
@@ -495,6 +498,9 @@ struct nft_set_ops {
495498
const struct nft_set *set,
496499
const struct nft_set_elem *elem,
497500
unsigned int flags);
501+
u32 (*ksize)(u32 size);
502+
u32 (*usize)(u32 size);
503+
u32 (*adjust_maxsize)(const struct nft_set *set);
498504
void (*commit)(struct nft_set *set);
499505
void (*abort)(const struct nft_set *set);
500506
u64 (*privsize)(const struct nlattr * const nla[],
@@ -1195,6 +1201,8 @@ struct nft_hook {
11951201
struct list_head list;
11961202
struct nf_hook_ops ops;
11971203
struct rcu_head rcu;
1204+
char ifname[IFNAMSIZ];
1205+
u8 ifnamelen;
11981206
};
11991207

12001208
/**
@@ -1230,8 +1238,6 @@ static inline bool nft_is_base_chain(const struct nft_chain *chain)
12301238
return chain->flags & NFT_CHAIN_BASE;
12311239
}
12321240

1233-
int __nft_release_basechain(struct nft_ctx *ctx);
1234-
12351241
unsigned int nft_do_chain(struct nft_pktinfo *pkt, void *priv);
12361242

12371243
static inline bool nft_use_inc(u32 *use)

net/bridge/br_netfilter_hooks.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -393,38 +393,10 @@ static int br_nf_pre_routing_finish(struct net *net, struct sock *sk, struct sk_
393393
reason = ip_route_input(skb, iph->daddr, iph->saddr,
394394
ip4h_dscp(iph), dev);
395395
if (reason) {
396-
struct in_device *in_dev = __in_dev_get_rcu(dev);
397-
398-
/* If err equals -EHOSTUNREACH the error is due to a
399-
* martian destination or due to the fact that
400-
* forwarding is disabled. For most martian packets,
401-
* ip_route_output_key() will fail. It won't fail for 2 types of
402-
* martian destinations: loopback destinations and destination
403-
* 0.0.0.0. In both cases the packet will be dropped because the
404-
* destination is the loopback device and not the bridge. */
405-
if (reason != SKB_DROP_REASON_IP_INADDRERRORS || !in_dev ||
406-
IN_DEV_FORWARD(in_dev))
407-
goto free_skb;
408-
409-
rt = ip_route_output(net, iph->daddr, 0,
410-
ip4h_dscp(iph), 0,
411-
RT_SCOPE_UNIVERSE);
412-
if (!IS_ERR(rt)) {
413-
/* - Bridged-and-DNAT'ed traffic doesn't
414-
* require ip_forwarding. */
415-
if (rt->dst.dev == dev) {
416-
skb_dst_drop(skb);
417-
skb_dst_set(skb, &rt->dst);
418-
goto bridged_dnat;
419-
}
420-
ip_rt_put(rt);
421-
}
422-
free_skb:
423-
kfree_skb(skb);
396+
kfree_skb_reason(skb, reason);
424397
return 0;
425398
} else {
426399
if (skb_dst(skb)->dev == dev) {
427-
bridged_dnat:
428400
skb->dev = br_indev;
429401
nf_bridge_update_protocol(skb);
430402
nf_bridge_push_encap_header(skb);

net/netfilter/nf_conntrack_amanda.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int amanda_help(struct sk_buff *skb,
106106

107107
/* increase the UDP timeout of the master connection as replies from
108108
* Amanda clients to the server can be quite delayed */
109-
nf_ct_refresh(ct, skb, master_timeout * HZ);
109+
nf_ct_refresh(ct, master_timeout * HZ);
110110

111111
/* No data? */
112112
dataoff = protoff + sizeof(struct udphdr);

net/netfilter/nf_conntrack_broadcast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ int nf_conntrack_broadcast_help(struct sk_buff *skb,
7575
nf_ct_expect_related(exp, 0);
7676
nf_ct_expect_put(exp);
7777

78-
nf_ct_refresh(ct, skb, timeout * HZ);
78+
nf_ct_refresh(ct, timeout * HZ);
7979
out:
8080
return NF_ACCEPT;
8181
}

net/netfilter/nf_conntrack_core.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,12 +1544,6 @@ static void gc_worker(struct work_struct *work)
15441544

15451545
tmp = nf_ct_tuplehash_to_ctrack(h);
15461546

1547-
if (test_bit(IPS_OFFLOAD_BIT, &tmp->status)) {
1548-
nf_ct_offload_timeout(tmp);
1549-
if (!nf_conntrack_max95)
1550-
continue;
1551-
}
1552-
15531547
if (expired_count > GC_SCAN_EXPIRED_MAX) {
15541548
rcu_read_unlock();
15551549

@@ -2089,9 +2083,8 @@ EXPORT_SYMBOL_GPL(nf_conntrack_in);
20892083
/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
20902084
void __nf_ct_refresh_acct(struct nf_conn *ct,
20912085
enum ip_conntrack_info ctinfo,
2092-
const struct sk_buff *skb,
20932086
u32 extra_jiffies,
2094-
bool do_acct)
2087+
unsigned int bytes)
20952088
{
20962089
/* Only update if this is not a fixed timeout */
20972090
if (test_bit(IPS_FIXED_TIMEOUT_BIT, &ct->status))
@@ -2104,8 +2097,8 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
21042097
if (READ_ONCE(ct->timeout) != extra_jiffies)
21052098
WRITE_ONCE(ct->timeout, extra_jiffies);
21062099
acct:
2107-
if (do_acct)
2108-
nf_ct_acct_update(ct, CTINFO2DIR(ctinfo), skb->len);
2100+
if (bytes)
2101+
nf_ct_acct_update(ct, CTINFO2DIR(ctinfo), bytes);
21092102
}
21102103
EXPORT_SYMBOL_GPL(__nf_ct_refresh_acct);
21112104

net/netfilter/nf_conntrack_h323_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ static int process_rcf(struct sk_buff *skb, struct nf_conn *ct,
13851385
if (info->timeout > 0) {
13861386
pr_debug("nf_ct_ras: set RAS connection timeout to "
13871387
"%u seconds\n", info->timeout);
1388-
nf_ct_refresh(ct, skb, info->timeout * HZ);
1388+
nf_ct_refresh(ct, info->timeout * HZ);
13891389

13901390
/* Set expect timeout */
13911391
spin_lock_bh(&nf_conntrack_expect_lock);
@@ -1433,7 +1433,7 @@ static int process_urq(struct sk_buff *skb, struct nf_conn *ct,
14331433
info->sig_port[!dir] = 0;
14341434

14351435
/* Give it 30 seconds for UCF or URJ */
1436-
nf_ct_refresh(ct, skb, 30 * HZ);
1436+
nf_ct_refresh(ct, 30 * HZ);
14371437

14381438
return 0;
14391439
}

net/netfilter/nf_conntrack_sip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ static int sip_help_tcp(struct sk_buff *skb, unsigned int protoff,
15531553
if (dataoff >= skb->len)
15541554
return NF_ACCEPT;
15551555

1556-
nf_ct_refresh(ct, skb, sip_timeout * HZ);
1556+
nf_ct_refresh(ct, sip_timeout * HZ);
15571557

15581558
if (unlikely(skb_linearize(skb)))
15591559
return NF_DROP;
@@ -1624,7 +1624,7 @@ static int sip_help_udp(struct sk_buff *skb, unsigned int protoff,
16241624
if (dataoff >= skb->len)
16251625
return NF_ACCEPT;
16261626

1627-
nf_ct_refresh(ct, skb, sip_timeout * HZ);
1627+
nf_ct_refresh(ct, sip_timeout * HZ);
16281628

16291629
if (unlikely(skb_linearize(skb)))
16301630
return NF_DROP;

0 commit comments

Comments
 (0)