diff options
author | Gao feng <gaofeng@cn.fujitsu.com> | 2012-06-21 00:36:44 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2012-06-27 13:05:33 -0400 |
commit | dee7364e0e522f9cd90187c28dbb64889a17e191 (patch) | |
tree | 0b121e7709324d4d46534ead2d6ae31c88c307ef /net/netfilter | |
parent | efa758fe2c2543f70b4dbda4421c8a352703e68e (diff) |
netfilter: nf_ct_udp: merge udpv[4,6]_net_init into udp_net_init
Merge udpv4_net_init and udpv6_net_init into udp_net_init to
remove redundant code now that we have the u_int16_t proto
parameter.
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/netfilter')
-rw-r--r-- | net/netfilter/nf_conntrack_proto_udp.c | 65 |
1 files changed, 23 insertions, 42 deletions
diff --git a/net/netfilter/nf_conntrack_proto_udp.c b/net/netfilter/nf_conntrack_proto_udp.c index 2b978e6fd1c2..e7e0434c3056 100644 --- a/net/netfilter/nf_conntrack_proto_udp.c +++ b/net/netfilter/nf_conntrack_proto_udp.c | |||
@@ -235,10 +235,10 @@ static struct ctl_table udp_compat_sysctl_table[] = { | |||
235 | #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ | 235 | #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ |
236 | #endif /* CONFIG_SYSCTL */ | 236 | #endif /* CONFIG_SYSCTL */ |
237 | 237 | ||
238 | static int udp_kmemdup_sysctl_table(struct nf_proto_net *pn) | 238 | static int udp_kmemdup_sysctl_table(struct nf_proto_net *pn, |
239 | struct nf_udp_net *un) | ||
239 | { | 240 | { |
240 | #ifdef CONFIG_SYSCTL | 241 | #ifdef CONFIG_SYSCTL |
241 | struct nf_udp_net *un = (struct nf_udp_net *)pn; | ||
242 | if (pn->ctl_table) | 242 | if (pn->ctl_table) |
243 | return 0; | 243 | return 0; |
244 | pn->ctl_table = kmemdup(udp_sysctl_table, | 244 | pn->ctl_table = kmemdup(udp_sysctl_table, |
@@ -252,11 +252,11 @@ static int udp_kmemdup_sysctl_table(struct nf_proto_net *pn) | |||
252 | return 0; | 252 | return 0; |
253 | } | 253 | } |
254 | 254 | ||
255 | static int udp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn) | 255 | static int udp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn, |
256 | struct nf_udp_net *un) | ||
256 | { | 257 | { |
257 | #ifdef CONFIG_SYSCTL | 258 | #ifdef CONFIG_SYSCTL |
258 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT | 259 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT |
259 | struct nf_udp_net *un = (struct nf_udp_net *)pn; | ||
260 | pn->ctl_compat_table = kmemdup(udp_compat_sysctl_table, | 260 | pn->ctl_compat_table = kmemdup(udp_compat_sysctl_table, |
261 | sizeof(udp_compat_sysctl_table), | 261 | sizeof(udp_compat_sysctl_table), |
262 | GFP_KERNEL); | 262 | GFP_KERNEL); |
@@ -270,50 +270,31 @@ static int udp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn) | |||
270 | return 0; | 270 | return 0; |
271 | } | 271 | } |
272 | 272 | ||
273 | static void udp_init_net_data(struct nf_udp_net *un) | 273 | static int udp_init_net(struct net *net, u_int16_t proto) |
274 | { | ||
275 | int i; | ||
276 | #ifdef CONFIG_SYSCTL | ||
277 | if (!un->pn.ctl_table) { | ||
278 | #else | ||
279 | if (!un->pn.users++) { | ||
280 | #endif | ||
281 | for (i = 0; i < UDP_CT_MAX; i++) | ||
282 | un->timeouts[i] = udp_timeouts[i]; | ||
283 | } | ||
284 | } | ||
285 | |||
286 | static int udpv4_init_net(struct net *net, u_int16_t proto) | ||
287 | { | 274 | { |
288 | int ret; | 275 | int ret; |
289 | struct nf_udp_net *un = udp_pernet(net); | 276 | struct nf_udp_net *un = udp_pernet(net); |
290 | struct nf_proto_net *pn = (struct nf_proto_net *)un; | 277 | struct nf_proto_net *pn = &un->pn; |
291 | |||
292 | udp_init_net_data(un); | ||
293 | 278 | ||
294 | ret = udp_kmemdup_compat_sysctl_table(pn); | 279 | if (!pn->users) { |
295 | if (ret < 0) | 280 | int i; |
296 | return ret; | ||
297 | 281 | ||
298 | ret = udp_kmemdup_sysctl_table(pn); | 282 | for (i = 0; i < UDP_CT_MAX; i++) |
299 | #ifdef CONFIG_SYSCTL | 283 | un->timeouts[i] = udp_timeouts[i]; |
300 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT | ||
301 | if (ret < 0) { | ||
302 | kfree(pn->ctl_compat_table); | ||
303 | pn->ctl_compat_table = NULL; | ||
304 | } | 284 | } |
305 | #endif | ||
306 | #endif | ||
307 | return ret; | ||
308 | } | ||
309 | 285 | ||
310 | static int udpv6_init_net(struct net *net, u_int16_t proto) | 286 | if (proto == AF_INET) { |
311 | { | 287 | ret = udp_kmemdup_compat_sysctl_table(pn, un); |
312 | struct nf_udp_net *un = udp_pernet(net); | 288 | if (ret < 0) |
313 | struct nf_proto_net *pn = (struct nf_proto_net *)un; | 289 | return ret; |
314 | 290 | ||
315 | udp_init_net_data(un); | 291 | ret = udp_kmemdup_sysctl_table(pn, un); |
316 | return udp_kmemdup_sysctl_table(pn); | 292 | if (ret < 0) |
293 | nf_ct_kfree_compat_sysctl_table(pn); | ||
294 | } else | ||
295 | ret = udp_kmemdup_sysctl_table(pn, un); | ||
296 | |||
297 | return ret; | ||
317 | } | 298 | } |
318 | 299 | ||
319 | struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = | 300 | struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = |
@@ -343,7 +324,7 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = | |||
343 | .nla_policy = udp_timeout_nla_policy, | 324 | .nla_policy = udp_timeout_nla_policy, |
344 | }, | 325 | }, |
345 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ | 326 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
346 | .init_net = udpv4_init_net, | 327 | .init_net = udp_init_net, |
347 | }; | 328 | }; |
348 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp4); | 329 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp4); |
349 | 330 | ||
@@ -374,6 +355,6 @@ struct nf_conntrack_l4proto nf_conntrack_l4proto_udp6 __read_mostly = | |||
374 | .nla_policy = udp_timeout_nla_policy, | 355 | .nla_policy = udp_timeout_nla_policy, |
375 | }, | 356 | }, |
376 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ | 357 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ |
377 | .init_net = udpv6_init_net, | 358 | .init_net = udp_init_net, |
378 | }; | 359 | }; |
379 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp6); | 360 | EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp6); |