diff options
author | Gao feng <gaofeng@cn.fujitsu.com> | 2012-06-21 00:36:45 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-06-27 13:12:52 -0400 |
commit | 51b4c824fcd15b73931fdd945cc101b9d4791b17 (patch) | |
tree | 7082a10c0e766076902c10964b57154d3cbae695 /net | |
parent | dee7364e0e522f9cd90187c28dbb64889a17e191 (diff) |
netfilter: nf_ct_udplite: add udplite_kmemdup_sysctl_table function
This cleans up nf_conntrack_l4proto_udplite[4,6] and it prepares
the moving of the sysctl code to nf_conntrack_proto_*_sysctl.c
to reduce the ifdef pollution.
And use nf_proto_net.users to identify if it's the first time
we use the nf_proto_net, in that case, we initialize it.
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net')
-rw-r--r-- | net/netfilter/nf_conntrack_proto_udplite.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/net/netfilter/nf_conntrack_proto_udplite.c b/net/netfilter/nf_conntrack_proto_udplite.c index d33e5115803..4b66df20928 100644 --- a/net/netfilter/nf_conntrack_proto_udplite.c +++ b/net/netfilter/nf_conntrack_proto_udplite.c | |||
@@ -234,29 +234,38 @@ static struct ctl_table udplite_sysctl_table[] = { | |||
234 | }; | 234 | }; |
235 | #endif /* CONFIG_SYSCTL */ | 235 | #endif /* CONFIG_SYSCTL */ |
236 | 236 | ||
237 | static int udplite_init_net(struct net *net, u_int16_t proto) | 237 | static int udplite_kmemdup_sysctl_table(struct nf_proto_net *pn, |
238 | struct udplite_net *un) | ||
238 | { | 239 | { |
239 | int i; | ||
240 | struct udplite_net *un = udplite_pernet(net); | ||
241 | struct nf_proto_net *pn = (struct nf_proto_net *)un; | ||
242 | #ifdef CONFIG_SYSCTL | 240 | #ifdef CONFIG_SYSCTL |
243 | if (!pn->ctl_table) { | 241 | if (pn->ctl_table) |
244 | #else | 242 | return 0; |
245 | if (!pn->users++) { | 243 | |
244 | pn->ctl_table = kmemdup(udplite_sysctl_table, | ||
245 | sizeof(udplite_sysctl_table), | ||
246 | GFP_KERNEL); | ||
247 | if (!pn->ctl_table) | ||
248 | return -ENOMEM; | ||
249 | |||
250 | pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED]; | ||
251 | pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED]; | ||
246 | #endif | 252 | #endif |
253 | return 0; | ||
254 | } | ||
255 | |||
256 | static int udplite_init_net(struct net *net, u_int16_t proto) | ||
257 | { | ||
258 | struct udplite_net *un = udplite_pernet(net); | ||
259 | struct nf_proto_net *pn = &un->pn; | ||
260 | |||
261 | if (!pn->users) { | ||
262 | int i; | ||
263 | |||
247 | for (i = 0 ; i < UDPLITE_CT_MAX; i++) | 264 | for (i = 0 ; i < UDPLITE_CT_MAX; i++) |
248 | un->timeouts[i] = udplite_timeouts[i]; | 265 | un->timeouts[i] = udplite_timeouts[i]; |
249 | #ifdef CONFIG_SYSCTL | ||
250 | pn->ctl_table = kmemdup(udplite_sysctl_table, | ||
251 | sizeof(udplite_sysctl_table), | ||
252 | GFP_KERNEL); | ||
253 | if (!pn->ctl_table) | ||
254 | return -ENOMEM; | ||
255 | pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED]; | ||
256 | pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED]; | ||
257 | #endif | ||
258 | } | 266 | } |
259 | return 0; | 267 | |
268 | return udplite_kmemdup_sysctl_table(pn, un); | ||
260 | } | 269 | } |
261 | 270 | ||
262 | static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = | 271 | static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly = |