History

netfilter: cttimeout: use option structure

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

Florian Westphal committed 4 years ago

Commit 7afa3881 parent 8dd86783 files · +26 −24Browse files

Unified · Split

3 files
  1. include/net/netfilter/nf_conntrack_timeout.h +6 −2
  2. net/netfilter/nf_conntrack_timeout.c +13 −18
  3. net/netfilter/nfnetlink_cttimeout.c +7 −4
include/net/netfilter/nf_conntrack_timeout.h+6−2
@@ -108,8 +108,12 @@ static inline void nf_ct_destroy_timeout(struct nf_conn *ct) · 107 unmodified lines
108108 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
109109
110110 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
111−extern struct nf_ct_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);
112−extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);
111+struct nf_ct_timeout_hooks {
112+ struct nf_ct_timeout *(*timeout_find_get)(struct net *net, const char *name);
113+ void (*timeout_put)(struct nf_ct_timeout *timeout);
114+};
115+
116+extern const struct nf_ct_timeout_hooks *nf_ct_timeout_hook;
113117 #endif
114118
115119 #endif /* _NF_CONNTRACK_TIMEOUT_H */
net/netfilter/nf_conntrack_timeout.c+13−18
@@ -22,12 +22,8 @@ · 21 unmodified lines
2222 #include <net/netfilter/nf_conntrack_l4proto.h>
2323 #include <net/netfilter/nf_conntrack_timeout.h>
2424
25−struct nf_ct_timeout *
26−(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name) __read_mostly;
27−EXPORT_SYMBOL_GPL(nf_ct_timeout_find_get_hook);
28−
29−void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout) __read_mostly;
30−EXPORT_SYMBOL_GPL(nf_ct_timeout_put_hook);
25+const struct nf_ct_timeout_hooks *nf_ct_timeout_hook __read_mostly;
26+EXPORT_SYMBOL_GPL(nf_ct_timeout_hook);
3127
3228 static int untimeout(struct nf_conn *ct, void *timeout)
3329 {
@@ -48,31 +44,30 @@ EXPORT_SYMBOL_GPL(nf_ct_untimeout); · 14 unmodified lines
4844
4945 static void __nf_ct_timeout_put(struct nf_ct_timeout *timeout)
5046 {
51− typeof(nf_ct_timeout_put_hook) timeout_put;
47+ const struct nf_ct_timeout_hooks *h = rcu_dereference(nf_ct_timeout_hook);
5248
53− timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
54− if (timeout_put)
55− timeout_put(timeout);
49+ if (h)
50+ h->timeout_put(timeout);
5651 }
5752
5853 int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
5954 u8 l3num, u8 l4num, const char *timeout_name)
6055 {
61− typeof(nf_ct_timeout_find_get_hook) timeout_find_get;
56+ const struct nf_ct_timeout_hooks *h;
6257 struct nf_ct_timeout *timeout;
6358 struct nf_conn_timeout *timeout_ext;
6459 const char *errmsg = NULL;
6560 int ret = 0;
6661
6762 rcu_read_lock();
68− timeout_find_get = rcu_dereference(nf_ct_timeout_find_get_hook);
69− if (!timeout_find_get) {
63+ h = rcu_dereference(nf_ct_timeout_hook);
64+ if (!h) {
7065 ret = -ENOENT;
7166 errmsg = "Timeout policy base is empty";
7267 goto out;
7368 }
7469
75− timeout = timeout_find_get(net, timeout_name);
70+ timeout = h->timeout_find_get(net, timeout_name);
7671 if (!timeout) {
7772 ret = -ENOENT;
7873 pr_info_ratelimited("No such timeout policy \"%s\"\n",
@@ -119,15 +114,15 @@ EXPORT_SYMBOL_GPL(nf_ct_set_timeout); · 40 unmodified lines
119114 void nf_ct_destroy_timeout(struct nf_conn *ct)
120115 {
121116 struct nf_conn_timeout *timeout_ext;
122− typeof(nf_ct_timeout_put_hook) timeout_put;
117+ const struct nf_ct_timeout_hooks *h;
123118
124119 rcu_read_lock();
125− timeout_put = rcu_dereference(nf_ct_timeout_put_hook);
120+ h = rcu_dereference(nf_ct_timeout_hook);
126121
127− if (timeout_put) {
122+ if (h) {
128123 timeout_ext = nf_ct_timeout_find(ct);
129124 if (timeout_ext) {
130− timeout_put(timeout_ext->timeout);
125+ h->timeout_put(timeout_ext->timeout);
131126 RCU_INIT_POINTER(timeout_ext->timeout, NULL);
132127 }
133128 }
net/netfilter/nfnetlink_cttimeout.c+7−4
@@ -605,6 +605,11 @@ static struct pernet_operations cttimeout_ops = { · 604 unmodified lines
605605 .size = sizeof(struct nfct_timeout_pernet),
606606 };
607607
608+static const struct nf_ct_timeout_hooks hooks = {
609+ .timeout_find_get = ctnl_timeout_find_get,
610+ .timeout_put = ctnl_timeout_put,
611+};
612+
608613 static int __init cttimeout_init(void)
609614 {
610615 int ret;
@@ -619,8 +624,7 @@ static int __init cttimeout_init(void) · 8 unmodified lines
619624 "nfnetlink.\n");
620625 goto err_out;
621626 }
622− RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, ctnl_timeout_find_get);
623− RCU_INIT_POINTER(nf_ct_timeout_put_hook, ctnl_timeout_put);
627+ RCU_INIT_POINTER(nf_ct_timeout_hook, &hooks);
624628 return 0;
625629
626630 err_out:
@@ -633,8 +637,7 @@ static void __exit cttimeout_exit(void) · 6 unmodified lines
633637 nfnetlink_subsys_unregister(&cttimeout_subsys);
634638
635639 unregister_pernet_subsys(&cttimeout_ops);
636− RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, NULL);
637− RCU_INIT_POINTER(nf_ct_timeout_put_hook, NULL);
640+ RCU_INIT_POINTER(nf_ct_timeout_hook, NULL);
638641 synchronize_rcu();
639642 }
640643

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t