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

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>

authored by

Gao feng and committed by
Pablo Neira Ayuso
51b4c824 dee7364e

+26 -17
+26 -17
net/netfilter/nf_conntrack_proto_udplite.c
··· 234 234 }; 235 235 #endif /* CONFIG_SYSCTL */ 236 236 237 + static int udplite_kmemdup_sysctl_table(struct nf_proto_net *pn, 238 + struct udplite_net *un) 239 + { 240 + #ifdef CONFIG_SYSCTL 241 + if (pn->ctl_table) 242 + return 0; 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]; 252 + #endif 253 + return 0; 254 + } 255 + 237 256 static int udplite_init_net(struct net *net, u_int16_t proto) 238 257 { 239 - int i; 240 258 struct udplite_net *un = udplite_pernet(net); 241 - struct nf_proto_net *pn = (struct nf_proto_net *)un; 242 - #ifdef CONFIG_SYSCTL 243 - if (!pn->ctl_table) { 244 - #else 245 - if (!pn->users++) { 246 - #endif 259 + struct nf_proto_net *pn = &un->pn; 260 + 261 + if (!pn->users) { 262 + int i; 263 + 247 264 for (i = 0 ; i < UDPLITE_CT_MAX; i++) 248 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 271 static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly =