Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Gao feng and committed by
Pablo Neira Ayuso
dee7364e efa758fe

+24 -43
+24 -43
net/netfilter/nf_conntrack_proto_udp.c
··· 235 235 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 236 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 241 #ifdef CONFIG_SYSCTL 241 - struct nf_udp_net *un = (struct nf_udp_net *)pn; 242 242 if (pn->ctl_table) 243 243 return 0; 244 244 pn->ctl_table = kmemdup(udp_sysctl_table, ··· 252 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 258 #ifdef CONFIG_SYSCTL 258 259 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 259 - struct nf_udp_net *un = (struct nf_udp_net *)pn; 260 260 pn->ctl_compat_table = kmemdup(udp_compat_sysctl_table, 261 261 sizeof(udp_compat_sysctl_table), 262 262 GFP_KERNEL); ··· 270 270 return 0; 271 271 } 272 272 273 - static void udp_init_net_data(struct nf_udp_net *un) 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) 273 + static int udp_init_net(struct net *net, u_int16_t proto) 287 274 { 288 275 int ret; 289 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 278 292 - udp_init_net_data(un); 279 + if (!pn->users) { 280 + int i; 293 281 294 - ret = udp_kmemdup_compat_sysctl_table(pn); 295 - if (ret < 0) 296 - return ret; 297 - 298 - ret = udp_kmemdup_sysctl_table(pn); 299 - #ifdef CONFIG_SYSCTL 300 - #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 301 - if (ret < 0) { 302 - kfree(pn->ctl_compat_table); 303 - pn->ctl_compat_table = NULL; 282 + for (i = 0; i < UDP_CT_MAX; i++) 283 + un->timeouts[i] = udp_timeouts[i]; 304 284 } 305 - #endif 306 - #endif 285 + 286 + if (proto == AF_INET) { 287 + ret = udp_kmemdup_compat_sysctl_table(pn, un); 288 + if (ret < 0) 289 + return ret; 290 + 291 + ret = udp_kmemdup_sysctl_table(pn, un); 292 + if (ret < 0) 293 + nf_ct_kfree_compat_sysctl_table(pn); 294 + } else 295 + ret = udp_kmemdup_sysctl_table(pn, un); 296 + 307 297 return ret; 308 - } 309 - 310 - static int udpv6_init_net(struct net *net, u_int16_t proto) 311 - { 312 - struct nf_udp_net *un = udp_pernet(net); 313 - struct nf_proto_net *pn = (struct nf_proto_net *)un; 314 - 315 - udp_init_net_data(un); 316 - return udp_kmemdup_sysctl_table(pn); 317 298 } 318 299 319 300 struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly = ··· 324 343 .nla_policy = udp_timeout_nla_policy, 325 344 }, 326 345 #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 327 - .init_net = udpv4_init_net, 346 + .init_net = udp_init_net, 328 347 }; 329 348 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp4); 330 349 ··· 355 374 .nla_policy = udp_timeout_nla_policy, 356 375 }, 357 376 #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 358 - .init_net = udpv6_init_net, 377 + .init_net = udp_init_net, 359 378 }; 360 379 EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp6);