Skip to content

Commit fe6bae4

Browse files
LorenzoBianconiKernel Patches Daemon
authored andcommitted
net: netfilter: add kfunc helper to update ct timeout
Introduce bpf_ct_refresh_timeout kfunc helper in order to update time nf_conn lifetime. Move timeout update logic in nf_ct_refresh_timeout utility routine. Signed-off-by: Lorenzo Bianconi <[email protected]> Reported-by: kernel test robot <[email protected]>
1 parent 61be210 commit fe6bae4

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

include/net/netfilter/nf_conntrack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,
205205
u_int16_t l3num, struct net *net,
206206
struct nf_conntrack_tuple *tuple);
207207

208+
void nf_ct_refresh_timeout(struct nf_conn *ct, u32 extra_jiffies);
208209
void __nf_ct_refresh_acct(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
209210
const struct sk_buff *skb,
210211
u32 extra_jiffies, bool do_acct);

net/netfilter/nf_conntrack_bpf.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,36 @@ void bpf_ct_release(struct nf_conn *nfct)
217217
nf_ct_put(nfct);
218218
}
219219

220+
/* bpf_ct_refresh_timeout - Refresh nf_conn object
221+
*
222+
* Refresh timeout associated to the provided connection tracking entry.
223+
* This must be invoked for referenced PTR_TO_BTF_ID.
224+
*
225+
* Parameters:
226+
* @nf_conn - Pointer to referenced nf_conn object, obtained using
227+
* bpf_xdp_ct_lookup or bpf_skb_ct_lookup.
228+
* @timeout - delta time in msecs used to increase the ct entry lifetime.
229+
*/
230+
void bpf_ct_refresh_timeout(struct nf_conn *nfct, u32 timeout)
231+
{
232+
if (!nfct)
233+
return;
234+
235+
nf_ct_refresh_timeout(nfct, msecs_to_jiffies(timeout));
236+
}
237+
220238
__diag_pop()
221239

222240
BTF_SET_START(nf_ct_xdp_check_kfunc_ids)
223241
BTF_ID(func, bpf_xdp_ct_lookup)
224242
BTF_ID(func, bpf_ct_release)
243+
BTF_ID(func, bpf_ct_refresh_timeout);
225244
BTF_SET_END(nf_ct_xdp_check_kfunc_ids)
226245

227246
BTF_SET_START(nf_ct_tc_check_kfunc_ids)
228247
BTF_ID(func, bpf_skb_ct_lookup)
229248
BTF_ID(func, bpf_ct_release)
249+
BTF_ID(func, bpf_ct_refresh_timeout);
230250
BTF_SET_END(nf_ct_tc_check_kfunc_ids)
231251

232252
BTF_SET_START(nf_ct_acquire_kfunc_ids)

net/netfilter/nf_conntrack_core.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,24 +2030,29 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
20302030
}
20312031
EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply);
20322032

2033-
/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
2034-
void __nf_ct_refresh_acct(struct nf_conn *ct,
2035-
enum ip_conntrack_info ctinfo,
2036-
const struct sk_buff *skb,
2037-
u32 extra_jiffies,
2038-
bool do_acct)
2033+
void nf_ct_refresh_timeout(struct nf_conn *ct, u32 extra_jiffies)
20392034
{
20402035
/* Only update if this is not a fixed timeout */
20412036
if (test_bit(IPS_FIXED_TIMEOUT_BIT, &ct->status))
2042-
goto acct;
2037+
return;
20432038

20442039
/* If not in hash table, timer will not be active yet */
20452040
if (nf_ct_is_confirmed(ct))
20462041
extra_jiffies += nfct_time_stamp;
20472042

20482043
if (READ_ONCE(ct->timeout) != extra_jiffies)
20492044
WRITE_ONCE(ct->timeout, extra_jiffies);
2050-
acct:
2045+
}
2046+
2047+
/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
2048+
void __nf_ct_refresh_acct(struct nf_conn *ct,
2049+
enum ip_conntrack_info ctinfo,
2050+
const struct sk_buff *skb,
2051+
u32 extra_jiffies,
2052+
bool do_acct)
2053+
{
2054+
nf_ct_refresh_timeout(ct, extra_jiffies);
2055+
20512056
if (do_acct)
20522057
nf_ct_acct_update(ct, CTINFO2DIR(ctinfo), skb->len);
20532058
}

0 commit comments

Comments
 (0)