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
108#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */108#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
109 109
110#ifdef CONFIG_NF_CONNTRACK_TIMEOUT110#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
111extern struct nf_ct_timeout *(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name);111struct nf_ct_timeout_hooks {
112extern void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout);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
116extern const struct nf_ct_timeout_hooks *nf_ct_timeout_hook;
113#endif117#endif
114 118
115#endif /* _NF_CONNTRACK_TIMEOUT_H */119#endif /* _NF_CONNTRACK_TIMEOUT_H */
net/netfilter/nf_conntrack_timeout.c+13−18
@@ -22,12 +22,8 @@ · 21 unmodified lines
22#include <net/netfilter/nf_conntrack_l4proto.h>22#include <net/netfilter/nf_conntrack_l4proto.h>
23#include <net/netfilter/nf_conntrack_timeout.h>23#include <net/netfilter/nf_conntrack_timeout.h>
24 24
25struct nf_ct_timeout *25const struct nf_ct_timeout_hooks *nf_ct_timeout_hook __read_mostly;
26(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name) __read_mostly;26EXPORT_SYMBOL_GPL(nf_ct_timeout_hook);
27EXPORT_SYMBOL_GPL(nf_ct_timeout_find_get_hook);
28
29void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout) __read_mostly;
30EXPORT_SYMBOL_GPL(nf_ct_timeout_put_hook);
31 27
32static int untimeout(struct nf_conn *ct, void *timeout)28static int untimeout(struct nf_conn *ct, void *timeout)
33{29{
@@ -48,31 +44,30 @@ EXPORT_SYMBOL_GPL(nf_ct_untimeout); · 14 unmodified lines
48 44
49static void __nf_ct_timeout_put(struct nf_ct_timeout *timeout)45static void __nf_ct_timeout_put(struct nf_ct_timeout *timeout)
50{46{
51 typeof(nf_ct_timeout_put_hook) timeout_put;47 const struct nf_ct_timeout_hooks *h = rcu_dereference(nf_ct_timeout_hook);
52 48
53 timeout_put = rcu_dereference(nf_ct_timeout_put_hook);49 if (h)
54 if (timeout_put)50 h->timeout_put(timeout);
55 timeout_put(timeout);
56}51}
57 52
58int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,53int nf_ct_set_timeout(struct net *net, struct nf_conn *ct,
59 u8 l3num, u8 l4num, const char *timeout_name)54 u8 l3num, u8 l4num, const char *timeout_name)
60{55{
61 typeof(nf_ct_timeout_find_get_hook) timeout_find_get;56 const struct nf_ct_timeout_hooks *h;
62 struct nf_ct_timeout *timeout;57 struct nf_ct_timeout *timeout;
63 struct nf_conn_timeout *timeout_ext;58 struct nf_conn_timeout *timeout_ext;
64 const char *errmsg = NULL;59 const char *errmsg = NULL;
65 int ret = 0;60 int ret = 0;
66 61
67 rcu_read_lock();62 rcu_read_lock();
68 timeout_find_get = rcu_dereference(nf_ct_timeout_find_get_hook);63 h = rcu_dereference(nf_ct_timeout_hook);
69 if (!timeout_find_get) {64 if (!h) {
70 ret = -ENOENT;65 ret = -ENOENT;
71 errmsg = "Timeout policy base is empty";66 errmsg = "Timeout policy base is empty";
72 goto out;67 goto out;
73 }68 }
74 69
75 timeout = timeout_find_get(net, timeout_name);70 timeout = h->timeout_find_get(net, timeout_name);
76 if (!timeout) {71 if (!timeout) {
77 ret = -ENOENT;72 ret = -ENOENT;
78 pr_info_ratelimited("No such timeout policy \"%s\"\n",73 pr_info_ratelimited("No such timeout policy \"%s\"\n",
@@ -119,15 +114,15 @@ EXPORT_SYMBOL_GPL(nf_ct_set_timeout); · 40 unmodified lines
119void nf_ct_destroy_timeout(struct nf_conn *ct)114void nf_ct_destroy_timeout(struct nf_conn *ct)
120{115{
121 struct nf_conn_timeout *timeout_ext;116 struct nf_conn_timeout *timeout_ext;
122 typeof(nf_ct_timeout_put_hook) timeout_put;117 const struct nf_ct_timeout_hooks *h;
123 118
124 rcu_read_lock();119 rcu_read_lock();
125 timeout_put = rcu_dereference(nf_ct_timeout_put_hook);120 h = rcu_dereference(nf_ct_timeout_hook);
126 121
127 if (timeout_put) {122 if (h) {
128 timeout_ext = nf_ct_timeout_find(ct);123 timeout_ext = nf_ct_timeout_find(ct);
129 if (timeout_ext) {124 if (timeout_ext) {
130 timeout_put(timeout_ext->timeout);125 h->timeout_put(timeout_ext->timeout);
131 RCU_INIT_POINTER(timeout_ext->timeout, NULL);126 RCU_INIT_POINTER(timeout_ext->timeout, NULL);
132 }127 }
133 }128 }
net/netfilter/nfnetlink_cttimeout.c+7−4
@@ -605,6 +605,11 @@ static struct pernet_operations cttimeout_ops = { · 604 unmodified lines
605 .size = sizeof(struct nfct_timeout_pernet),605 .size = sizeof(struct nfct_timeout_pernet),
606};606};
607 607
608static const struct nf_ct_timeout_hooks hooks = {
609 .timeout_find_get = ctnl_timeout_find_get,
610 .timeout_put = ctnl_timeout_put,
611};
612
608static int __init cttimeout_init(void)613static int __init cttimeout_init(void)
609{614{
610 int ret;615 int ret;
@@ -619,8 +624,7 @@ static int __init cttimeout_init(void) · 8 unmodified lines
619 "nfnetlink.\n");624 "nfnetlink.\n");
620 goto err_out;625 goto err_out;
621 }626 }
622 RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, ctnl_timeout_find_get);627 RCU_INIT_POINTER(nf_ct_timeout_hook, &hooks);
623 RCU_INIT_POINTER(nf_ct_timeout_put_hook, ctnl_timeout_put);
624 return 0;628 return 0;
625 629
626err_out:630err_out:
@@ -633,8 +637,7 @@ static void __exit cttimeout_exit(void) · 6 unmodified lines
633 nfnetlink_subsys_unregister(&cttimeout_subsys);637 nfnetlink_subsys_unregister(&cttimeout_subsys);
634 638
635 unregister_pernet_subsys(&cttimeout_ops);639 unregister_pernet_subsys(&cttimeout_ops);
636 RCU_INIT_POINTER(nf_ct_timeout_find_get_hook, NULL);640 RCU_INIT_POINTER(nf_ct_timeout_hook, NULL);
637 RCU_INIT_POINTER(nf_ct_timeout_put_hook, NULL);
638 synchronize_rcu();641 synchronize_rcu();
639}642}
640 643

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