All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf-next] netfilter: cttimeout: use option structure
@ 2022-02-08 11:29 Florian Westphal
  2022-02-09 10:56 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2022-02-08 11:29 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal

Instead of two exported functions, export a single option structure.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 include/net/netfilter/nf_conntrack_timeout.h |  8 +++--
 net/netfilter/nf_conntrack_timeout.c         | 31 ++++++++------------
 net/netfilter/nfnetlink_cttimeout.c          | 11 ++++---
 3 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/include/net/netfilter/nf_conntrack_timeout.h b/include/net/netfilter/nf_conntrack_timeout.h
index db507e4a65bb..3ea94f6f3844 100644
--- a/include/net/netfilter/nf_conntrack_timeout.h
+++ b/include/net/netfilter/nf_conntrack_timeout.h
@@ -108,8 +108,12 @@ static inline void nf_ct_destroy_timeout(struct nf_conn *ct)
 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
 
 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
-extern struct nf_ct_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
-extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);
+struct nf_ct_timeout_hooks {
+	struct nf_ct_timeout *(*timeout_find_get)(struct net *net, const char *name);
+	void (*timeout_put)(struct nf_ct_timeout *timeout);
+};
+
+extern const struct nf_ct_timeout_hooks *nf_ct_timeout_hook;
 #endif
 
 #endif /* _NF_CONNTRACK_TIMEOUT_H */
diff --git a/net/netfilter/nf_conntrack_timeout.c b/net/netfilter/nf_conntrack_timeout.c
index cd76ccca25e8..cec166ecba77 100644
--- a/net/netfilter/nf_conntrack_timeout.c
+++ b/net/netfilter/nf_conntrack_timeout.c
@@ -22,12 +22,8 @@
 #include <net/netfilter/nf_conntrack_l4proto.h>
 #include <net/netfilter/nf_conntrack_timeout.h>
 
-struct nf_ct_timeout *
-(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name) __read_mostly;
-EXPORT_SYMBOL_GPL(nf_ct_timeout_find_get_hook);
-
-void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout) __read_mostly;
-EXPORT_SYMBOL_GPL(nf_ct_timeout_put_hook);
+const struct nf_ct_timeout_hooks *nf_ct_timeout_hook __read_mostly;
+EXPORT_SYMBOL_GPL(nf_ct_timeout_hook);
 
 static int untimeout(struct nf_conn *ct, void *timeout)
 {
@@ -48,31 +44,30 @@ EXPORT_SYMBOL_GPL(nf_ct_untimeout);
 
 static void __nf_ct_timeout_put(struct nf_ct_timeout *timeout)
 {
-	typeof(nf_ct_timeout_put_hook) timeout_put;
+	const struct nf_ct_timeout_hooks *h = rcu_dereference(nf_ct_timeout_hook);
 
-	timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
-	if (timeout_put)
-		timeout_put(timeout);
+	if (h)
+		h->timeout_put(timeout);
 }
 
 int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
 		      u8 l3num, u8 l4num, const char *timeout_name)
 {
-	typeof(nf_ct_timeout_find_get_hook) timeout_find_get;
+	const struct nf_ct_timeout_hooks *h;
 	struct nf_ct_timeout *timeout;
 	struct nf_conn_timeout *timeout_ext;
 	const char *errmsg = NULL;
 	int ret = 0;
 
 	rcu_read_lock();
-	timeout_find_get = rcu_dereference(nf_ct_timeout_find_get_hook);
-	if (!timeout_find_get) {
+	h = rcu_dereference(nf_ct_timeout_hook);
+	if (!h) {
 		ret = -ENOENT;
 		errmsg = "Timeout policy base is empty";
 		goto out;
 	}
 
-	timeout = timeout_find_get(net, timeout_name);
+	timeout = h->timeout_find_get(net, timeout_name);
 	if (!timeout) {
 		ret = -ENOENT;
 		pr_info_ratelimited("No such timeout policy \"%s\"\n",
@@ -119,15 +114,15 @@ EXPORT_SYMBOL_GPL(nf_ct_set_timeout);
 void nf_ct_destroy_timeout(struct nf_conn *ct)
 {
 	struct nf_conn_timeout *timeout_ext;
-	typeof(nf_ct_timeout_put_hook) timeout_put;
+	const struct nf_ct_timeout_hooks *h;
 
 	rcu_read_lock();
-	timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
+	h = rcu_dereference(nf_ct_timeout_hook);
 
-	if (timeout_put) {
+	if (h) {
 		timeout_ext = nf_ct_timeout_find(ct);
 		if (timeout_ext) {
-			timeout_put(timeout_ext->timeout);
+			h->timeout_put(timeout_ext->timeout);
 			RCU_INIT_POINTER(timeout_ext->timeout, NULL);
 		}
 	}
diff --git a/net/netfilter/nfnetlink_cttimeout.c b/net/netfilter/nfnetlink_cttimeout.c
index c57673d499be..b0d8888a539b 100644
--- a/net/netfilter/nfnetlink_cttimeout.c
+++ b/net/netfilter/nfnetlink_cttimeout.c
@@ -605,6 +605,11 @@ static struct pernet_operations cttimeout_ops = {
 	.size   = sizeof(struct nfct_timeout_pernet),
 };
 
+static const struct nf_ct_timeout_hooks hooks = {
+	.timeout_find_get = ctnl_timeout_find_get,
+	.timeout_put = ctnl_timeout_put,
+};
+
 static int __init cttimeout_init(void)
 {
 	int ret;
@@ -619,8 +624,7 @@ static int __init cttimeout_init(void)
 			"nfnetlink.\n");
 		goto err_out;
 	}
-	RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, ctnl_timeout_find_get);
-	RCU_INIT_POINTER(nf_ct_timeout_put_hook, ctnl_timeout_put);
+	RCU_INIT_POINTER(nf_ct_timeout_hook, &hooks);
 	return 0;
 
 err_out:
@@ -633,8 +637,7 @@ static void __exit cttimeout_exit(void)
 	nfnetlink_subsys_unregister(&cttimeout_subsys);
 
 	unregister_pernet_subsys(&cttimeout_ops);
-	RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, NULL);
-	RCU_INIT_POINTER(nf_ct_timeout_put_hook, NULL);
+	RCU_INIT_POINTER(nf_ct_timeout_hook, NULL);
 	synchronize_rcu();
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread
* Re: [PATCH nf-next] netfilter: cttimeout: use option structure
@ 2022-02-08 21:38 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2022-02-08 21:38 UTC (permalink / raw)
  To: kbuild

[-- Attachment #1: Type: text/plain, Size: 5917 bytes --]

CC: kbuild-all(a)lists.01.org
In-Reply-To: <20220208112947.26405-1-fw@strlen.de>
References: <20220208112947.26405-1-fw@strlen.de>
TO: Florian Westphal <fw@strlen.de>
TO: netfilter-devel(a)vger.kernel.org
CC: Florian Westphal <fw@strlen.de>

Hi Florian,

I love your patch! Perhaps something to improve:

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

url:    https://github.com/0day-ci/linux/commits/Florian-Westphal/netfilter-cttimeout-use-option-structure/20220208-194834
base:   https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master
:::::: branch date: 10 hours ago
:::::: commit date: 10 hours ago
config: arm64-randconfig-s032-20220208 (https://download.01.org/0day-ci/archive/20220209/202202090519.DSEDmf7v-lkp(a)intel.com/config)
compiler: aarch64-linux-gcc (GCC) 11.2.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/0day-ci/linux/commit/d47c1bd874471f3869d4b1cf4a0a9183248f9f4f
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Florian-Westphal/netfilter-cttimeout-use-option-structure/20220208-194834
        git checkout d47c1bd874471f3869d4b1cf4a0a9183248f9f4f
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=arm64 SHELL=/bin/bash net/netfilter/

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_timeout.c:32:62: sparse: sparse: incompatible types in comparison expression (different base types):
   net/netfilter/nf_conntrack_timeout.c:32:62: sparse:    struct nf_ct_timeout [noderef] __rcu *
   net/netfilter/nf_conntrack_timeout.c:32:62: sparse:    void *
   net/netfilter/nf_conntrack_timeout.c:47:47: sparse: sparse: incompatible types in comparison expression (different address spaces):
>> net/netfilter/nf_conntrack_timeout.c:47:47: sparse:    struct nf_ct_timeout_hooks const [noderef] __rcu *
>> net/netfilter/nf_conntrack_timeout.c:47:47: sparse:    struct nf_ct_timeout_hooks const *
   net/netfilter/nf_conntrack_timeout.c:63:13: sparse: sparse: incompatible types in comparison expression (different address spaces):
   net/netfilter/nf_conntrack_timeout.c:63:13: sparse:    struct nf_ct_timeout_hooks const [noderef] __rcu *
   net/netfilter/nf_conntrack_timeout.c:63:13: sparse:    struct nf_ct_timeout_hooks const *
   net/netfilter/nf_conntrack_timeout.c:120:13: sparse: sparse: incompatible types in comparison expression (different address spaces):
   net/netfilter/nf_conntrack_timeout.c:120:13: sparse:    struct nf_ct_timeout_hooks const [noderef] __rcu *
   net/netfilter/nf_conntrack_timeout.c:120:13: sparse:    struct nf_ct_timeout_hooks const *
--
   net/netfilter/nfnetlink_cttimeout.c:627:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
>> net/netfilter/nfnetlink_cttimeout.c:627:9: sparse:    struct nf_ct_timeout_hooks const [noderef] __rcu *
>> net/netfilter/nfnetlink_cttimeout.c:627:9: sparse:    struct nf_ct_timeout_hooks const *
   net/netfilter/nfnetlink_cttimeout.c:640:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
   net/netfilter/nfnetlink_cttimeout.c:640:9: sparse:    struct nf_ct_timeout_hooks const [noderef] __rcu *
   net/netfilter/nfnetlink_cttimeout.c:640:9: sparse:    struct nf_ct_timeout_hooks const *

vim +47 net/netfilter/nf_conntrack_timeout.c

dd705072412225 Pablo Neira Ayuso 2012-02-28  27  
4e665afbd7bee2 Harsha Sharma     2018-08-07  28  static int untimeout(struct nf_conn *ct, void *timeout)
4e665afbd7bee2 Harsha Sharma     2018-08-07  29  {
4e665afbd7bee2 Harsha Sharma     2018-08-07  30  	struct nf_conn_timeout *timeout_ext = nf_ct_timeout_find(ct);
4e665afbd7bee2 Harsha Sharma     2018-08-07  31  
4e665afbd7bee2 Harsha Sharma     2018-08-07 @32  	if (timeout_ext && (!timeout || timeout_ext->timeout == timeout))
4e665afbd7bee2 Harsha Sharma     2018-08-07  33  		RCU_INIT_POINTER(timeout_ext->timeout, NULL);
4e665afbd7bee2 Harsha Sharma     2018-08-07  34  
4e665afbd7bee2 Harsha Sharma     2018-08-07  35  	/* We are not intended to delete this conntrack. */
4e665afbd7bee2 Harsha Sharma     2018-08-07  36  	return 0;
4e665afbd7bee2 Harsha Sharma     2018-08-07  37  }
4e665afbd7bee2 Harsha Sharma     2018-08-07  38  
6c1fd7dc489d9b Pablo Neira Ayuso 2018-08-07  39  void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout)
4e665afbd7bee2 Harsha Sharma     2018-08-07  40  {
4e665afbd7bee2 Harsha Sharma     2018-08-07  41  	nf_ct_iterate_cleanup_net(net, untimeout, timeout, 0, 0);
4e665afbd7bee2 Harsha Sharma     2018-08-07  42  }
4e665afbd7bee2 Harsha Sharma     2018-08-07  43  EXPORT_SYMBOL_GPL(nf_ct_untimeout);
4e665afbd7bee2 Harsha Sharma     2018-08-07  44  
717700d183d65b Yi-Hung Wei       2019-03-26  45  static void __nf_ct_timeout_put(struct nf_ct_timeout *timeout)
717700d183d65b Yi-Hung Wei       2019-03-26  46  {
d47c1bd874471f Florian Westphal  2022-02-08 @47  	const struct nf_ct_timeout_hooks *h = rcu_dereference(nf_ct_timeout_hook);
717700d183d65b Yi-Hung Wei       2019-03-26  48  
d47c1bd874471f Florian Westphal  2022-02-08  49  	if (h)
d47c1bd874471f Florian Westphal  2022-02-08  50  		h->timeout_put(timeout);
717700d183d65b Yi-Hung Wei       2019-03-26  51  }
717700d183d65b Yi-Hung Wei       2019-03-26  52  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

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

end of thread, other threads:[~2022-02-09 11:58 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-08 11:29 [PATCH nf-next] netfilter: cttimeout: use option structure Florian Westphal
2022-02-09 10:56 ` Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2022-02-08 21:38 kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.