bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout
@ 2022-05-03 16:29 Lorenzo Bianconi
  2022-05-04  3:50 ` [RFC PATCH] net: netfilter: bpf_ct_refresh_timeout() can be static kernel test robot
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Lorenzo Bianconi @ 2022-05-03 16:29 UTC (permalink / raw)
  To: bpf
  Cc: netdev, ast, daniel, andrii, davem, kuba, pabeni, pablo, fw,
	netfilter-devel, lorenzo.bianconi, brouer, toke, memxor

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 <lorenzo@kernel.org>
---
 include/net/netfilter/nf_conntrack.h |  1 +
 net/netfilter/nf_conntrack_bpf.c     | 20 ++++++++++++++++++++
 net/netfilter/nf_conntrack_core.c    | 21 +++++++++++++--------
 3 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 69e6c6a218be..02b7115b92d0 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -205,6 +205,7 @@ bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,
 		       u_int16_t l3num, struct net *net,
 		       struct nf_conntrack_tuple *tuple);
 
+void nf_ct_refresh_timeout(struct nf_conn *ct, u32 extra_jiffies);
 void __nf_ct_refresh_acct(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
 			  const struct sk_buff *skb,
 			  u32 extra_jiffies, bool do_acct);
diff --git a/net/netfilter/nf_conntrack_bpf.c b/net/netfilter/nf_conntrack_bpf.c
index bc4d5cd63a94..d6dcadf0e016 100644
--- a/net/netfilter/nf_conntrack_bpf.c
+++ b/net/netfilter/nf_conntrack_bpf.c
@@ -217,16 +217,36 @@ void bpf_ct_release(struct nf_conn *nfct)
 	nf_ct_put(nfct);
 }
 
+/* bpf_ct_refresh_timeout - Refresh nf_conn object
+ *
+ * Refresh timeout associated to the provided connection tracking entry.
+ * This must be invoked for referenced PTR_TO_BTF_ID.
+ *
+ * Parameters:
+ * @nf_conn      - Pointer to referenced nf_conn object, obtained using
+ *		   bpf_xdp_ct_lookup or bpf_skb_ct_lookup.
+ * @timeout      - delta time in msecs used to increase the ct entry lifetime.
+ */
+void bpf_ct_refresh_timeout(struct nf_conn *nfct, u32 timeout)
+{
+	if (!nfct)
+		return;
+
+	nf_ct_refresh_timeout(nfct, msecs_to_jiffies(timeout));
+}
+
 __diag_pop()
 
 BTF_SET_START(nf_ct_xdp_check_kfunc_ids)
 BTF_ID(func, bpf_xdp_ct_lookup)
 BTF_ID(func, bpf_ct_release)
+BTF_ID(func, bpf_ct_refresh_timeout);
 BTF_SET_END(nf_ct_xdp_check_kfunc_ids)
 
 BTF_SET_START(nf_ct_tc_check_kfunc_ids)
 BTF_ID(func, bpf_skb_ct_lookup)
 BTF_ID(func, bpf_ct_release)
+BTF_ID(func, bpf_ct_refresh_timeout);
 BTF_SET_END(nf_ct_tc_check_kfunc_ids)
 
 BTF_SET_START(nf_ct_acquire_kfunc_ids)
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 0164e5f522e8..f43e743728bd 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -2030,16 +2030,11 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
 }
 EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply);
 
-/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
-void __nf_ct_refresh_acct(struct nf_conn *ct,
-			  enum ip_conntrack_info ctinfo,
-			  const struct sk_buff *skb,
-			  u32 extra_jiffies,
-			  bool do_acct)
+void nf_ct_refresh_timeout(struct nf_conn *ct, u32 extra_jiffies)
 {
 	/* Only update if this is not a fixed timeout */
 	if (test_bit(IPS_FIXED_TIMEOUT_BIT, &ct->status))
-		goto acct;
+		return;
 
 	/* If not in hash table, timer will not be active yet */
 	if (nf_ct_is_confirmed(ct))
@@ -2047,7 +2042,17 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
 
 	if (READ_ONCE(ct->timeout) != extra_jiffies)
 		WRITE_ONCE(ct->timeout, extra_jiffies);
-acct:
+}
+
+/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
+void __nf_ct_refresh_acct(struct nf_conn *ct,
+			  enum ip_conntrack_info ctinfo,
+			  const struct sk_buff *skb,
+			  u32 extra_jiffies,
+			  bool do_acct)
+{
+	nf_ct_refresh_timeout(ct, extra_jiffies);
+
 	if (do_acct)
 		nf_ct_acct_update(ct, CTINFO2DIR(ctinfo), skb->len);
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [RFC PATCH] net: netfilter: bpf_ct_refresh_timeout() can be static
  2022-05-03 16:29 [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout Lorenzo Bianconi
@ 2022-05-04  3:50 ` kernel test robot
  2022-05-04  4:01 ` [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout kernel test robot
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-05-04  3:50 UTC (permalink / raw)
  To: Lorenzo Bianconi, bpf
  Cc: kbuild-all, netdev, ast, daniel, andrii, davem, kuba, pabeni,
	pablo, fw, netfilter-devel, lorenzo.bianconi, brouer, toke,
	memxor

net/netfilter/nf_conntrack_bpf.c:230:6: warning: symbol 'bpf_ct_refresh_timeout' was not declared. Should it be static?

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: kernel test robot <lkp@intel.com>
---
 net/netfilter/nf_conntrack_bpf.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/netfilter/nf_conntrack_bpf.c b/net/netfilter/nf_conntrack_bpf.c
index d6dcadf0e0166..02d2578d4bb89 100644
--- a/net/netfilter/nf_conntrack_bpf.c
+++ b/net/netfilter/nf_conntrack_bpf.c
@@ -227,7 +227,7 @@ void bpf_ct_release(struct nf_conn *nfct)
  *		   bpf_xdp_ct_lookup or bpf_skb_ct_lookup.
  * @timeout      - delta time in msecs used to increase the ct entry lifetime.
  */
-void bpf_ct_refresh_timeout(struct nf_conn *nfct, u32 timeout)
+static void bpf_ct_refresh_timeout(struct nf_conn *nfct, u32 timeout)
 {
 	if (!nfct)
 		return;

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout
  2022-05-03 16:29 [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout Lorenzo Bianconi
  2022-05-04  3:50 ` [RFC PATCH] net: netfilter: bpf_ct_refresh_timeout() can be static kernel test robot
@ 2022-05-04  4:01 ` kernel test robot
  2022-05-11 15:26 ` Alexei Starovoitov
  2022-05-11 19:41 ` Kumar Kartikeya Dwivedi
  3 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-05-04  4:01 UTC (permalink / raw)
  To: Lorenzo Bianconi, bpf
  Cc: kbuild-all, netdev, ast, daniel, andrii, davem, kuba, pabeni,
	pablo, fw, netfilter-devel, lorenzo.bianconi, brouer, toke,
	memxor

Hi Lorenzo,

I love your patch! Perhaps something to improve:

[auto build test WARNING on bpf-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Bianconi/net-netfilter-add-kfunc-helper-to-update-ct-timeout/20220504-003234
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20220504/202205041143.5PZf1J9F-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.2.0-20) 11.2.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/intel-lab-lkp/linux/commit/a184a0a4e28e8af16232b4ccd899f7ae976f7f64
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Lorenzo-Bianconi/net-netfilter-add-kfunc-helper-to-update-ct-timeout/20220504-003234
        git checkout a184a0a4e28e8af16232b4ccd899f7ae976f7f64
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
>> net/netfilter/nf_conntrack_bpf.c:230:6: sparse: sparse: symbol 'bpf_ct_refresh_timeout' was not declared. Should it be static?

Please review and possibly fold the followup patch.

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout
  2022-05-03 16:29 [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout Lorenzo Bianconi
  2022-05-04  3:50 ` [RFC PATCH] net: netfilter: bpf_ct_refresh_timeout() can be static kernel test robot
  2022-05-04  4:01 ` [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout kernel test robot
@ 2022-05-11 15:26 ` Alexei Starovoitov
  2022-05-11 19:41 ` Kumar Kartikeya Dwivedi
  3 siblings, 0 replies; 5+ messages in thread
From: Alexei Starovoitov @ 2022-05-11 15:26 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: bpf, Network Development, Alexei Starovoitov, Daniel Borkmann,
	Andrii Nakryiko, David S. Miller, Jakub Kicinski, Paolo Abeni,
	Pablo Neira Ayuso, Florian Westphal, netfilter-devel,
	Lorenzo Bianconi, Jesper Dangaard Brouer,
	Toke Høiland-Jørgensen, Kumar Kartikeya Dwivedi

On Tue, May 3, 2022 at 9:29 AM Lorenzo Bianconi <lorenzo@kernel.org> wrote:
>
> 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 <lorenzo@kernel.org>

Looks good, but selftest and Ack from Kumar is needed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout
  2022-05-03 16:29 [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout Lorenzo Bianconi
                   ` (2 preceding siblings ...)
  2022-05-11 15:26 ` Alexei Starovoitov
@ 2022-05-11 19:41 ` Kumar Kartikeya Dwivedi
  3 siblings, 0 replies; 5+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2022-05-11 19:41 UTC (permalink / raw)
  To: Lorenzo Bianconi
  Cc: bpf, netdev, ast, daniel, andrii, davem, kuba, pabeni, pablo, fw,
	netfilter-devel, lorenzo.bianconi, brouer, toke

On Tue, May 03, 2022 at 09:59:14PM IST, Lorenzo Bianconi wrote:
> 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 <lorenzo@kernel.org>
> ---

Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>

The sparse error can be ignored, kfunc is meant to be global without a
prototype.

>  include/net/netfilter/nf_conntrack.h |  1 +
>  net/netfilter/nf_conntrack_bpf.c     | 20 ++++++++++++++++++++
>  net/netfilter/nf_conntrack_core.c    | 21 +++++++++++++--------
>  3 files changed, 34 insertions(+), 8 deletions(-)
>
> diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
> index 69e6c6a218be..02b7115b92d0 100644
> --- a/include/net/netfilter/nf_conntrack.h
> +++ b/include/net/netfilter/nf_conntrack.h
> @@ -205,6 +205,7 @@ bool nf_ct_get_tuplepr(const struct sk_buff *skb, unsigned int nhoff,
>  		       u_int16_t l3num, struct net *net,
>  		       struct nf_conntrack_tuple *tuple);
>
> +void nf_ct_refresh_timeout(struct nf_conn *ct, u32 extra_jiffies);
>  void __nf_ct_refresh_acct(struct nf_conn *ct, enum ip_conntrack_info ctinfo,
>  			  const struct sk_buff *skb,
>  			  u32 extra_jiffies, bool do_acct);
> diff --git a/net/netfilter/nf_conntrack_bpf.c b/net/netfilter/nf_conntrack_bpf.c
> index bc4d5cd63a94..d6dcadf0e016 100644
> --- a/net/netfilter/nf_conntrack_bpf.c
> +++ b/net/netfilter/nf_conntrack_bpf.c
> @@ -217,16 +217,36 @@ void bpf_ct_release(struct nf_conn *nfct)
>  	nf_ct_put(nfct);
>  }
>
> +/* bpf_ct_refresh_timeout - Refresh nf_conn object
> + *
> + * Refresh timeout associated to the provided connection tracking entry.
> + * This must be invoked for referenced PTR_TO_BTF_ID.
> + *
> + * Parameters:
> + * @nf_conn      - Pointer to referenced nf_conn object, obtained using
> + *		   bpf_xdp_ct_lookup or bpf_skb_ct_lookup.
> + * @timeout      - delta time in msecs used to increase the ct entry lifetime.
> + */
> +void bpf_ct_refresh_timeout(struct nf_conn *nfct, u32 timeout)
> +{
> +	if (!nfct)
> +		return;
> +
> +	nf_ct_refresh_timeout(nfct, msecs_to_jiffies(timeout));
> +}
> +
>  __diag_pop()
>
>  BTF_SET_START(nf_ct_xdp_check_kfunc_ids)
>  BTF_ID(func, bpf_xdp_ct_lookup)
>  BTF_ID(func, bpf_ct_release)
> +BTF_ID(func, bpf_ct_refresh_timeout);
>  BTF_SET_END(nf_ct_xdp_check_kfunc_ids)
>
>  BTF_SET_START(nf_ct_tc_check_kfunc_ids)
>  BTF_ID(func, bpf_skb_ct_lookup)
>  BTF_ID(func, bpf_ct_release)
> +BTF_ID(func, bpf_ct_refresh_timeout);
>  BTF_SET_END(nf_ct_tc_check_kfunc_ids)
>
>  BTF_SET_START(nf_ct_acquire_kfunc_ids)
> diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
> index 0164e5f522e8..f43e743728bd 100644
> --- a/net/netfilter/nf_conntrack_core.c
> +++ b/net/netfilter/nf_conntrack_core.c
> @@ -2030,16 +2030,11 @@ void nf_conntrack_alter_reply(struct nf_conn *ct,
>  }
>  EXPORT_SYMBOL_GPL(nf_conntrack_alter_reply);
>
> -/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
> -void __nf_ct_refresh_acct(struct nf_conn *ct,
> -			  enum ip_conntrack_info ctinfo,
> -			  const struct sk_buff *skb,
> -			  u32 extra_jiffies,
> -			  bool do_acct)
> +void nf_ct_refresh_timeout(struct nf_conn *ct, u32 extra_jiffies)
>  {
>  	/* Only update if this is not a fixed timeout */
>  	if (test_bit(IPS_FIXED_TIMEOUT_BIT, &ct->status))
> -		goto acct;
> +		return;
>
>  	/* If not in hash table, timer will not be active yet */
>  	if (nf_ct_is_confirmed(ct))
> @@ -2047,7 +2042,17 @@ void __nf_ct_refresh_acct(struct nf_conn *ct,
>
>  	if (READ_ONCE(ct->timeout) != extra_jiffies)
>  		WRITE_ONCE(ct->timeout, extra_jiffies);
> -acct:
> +}
> +
> +/* Refresh conntrack for this many jiffies and do accounting if do_acct is 1 */
> +void __nf_ct_refresh_acct(struct nf_conn *ct,
> +			  enum ip_conntrack_info ctinfo,
> +			  const struct sk_buff *skb,
> +			  u32 extra_jiffies,
> +			  bool do_acct)
> +{
> +	nf_ct_refresh_timeout(ct, extra_jiffies);
> +
>  	if (do_acct)
>  		nf_ct_acct_update(ct, CTINFO2DIR(ctinfo), skb->len);
>  }
> --
> 2.35.1
>

--
Kartikeya

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-11 19:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-03 16:29 [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout Lorenzo Bianconi
2022-05-04  3:50 ` [RFC PATCH] net: netfilter: bpf_ct_refresh_timeout() can be static kernel test robot
2022-05-04  4:01 ` [PATCH bpf-next] net: netfilter: add kfunc helper to update ct timeout kernel test robot
2022-05-11 15:26 ` Alexei Starovoitov
2022-05-11 19:41 ` Kumar Kartikeya Dwivedi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).