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

netfilter: nf_ct_dccp: add dccp_kmemdup_sysctl_table function

This patch is a cleanup. It adds dccp_kmemdup_sysctl_table to
split code into smaller chunks. Yet it prepares introduction
of nf_conntrack_proto_*_sysctl.c.

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
54b8873f 22ac0377

+30 -24
+30 -24
net/netfilter/nf_conntrack_proto_dccp.c
··· 387 387 /* this module per-net specifics */ 388 388 static int dccp_net_id __read_mostly; 389 389 struct dccp_net { 390 - struct nf_proto_net np; 390 + struct nf_proto_net pn; 391 391 int dccp_loose; 392 392 unsigned int dccp_timeout[CT_DCCP_MAX + 1]; 393 393 }; ··· 815 815 }; 816 816 #endif /* CONFIG_SYSCTL */ 817 817 818 + static int dccp_kmemdup_sysctl_table(struct nf_proto_net *pn, 819 + struct dccp_net *dn) 820 + { 821 + #ifdef CONFIG_SYSCTL 822 + if (pn->ctl_table) 823 + return 0; 824 + 825 + pn->ctl_table = kmemdup(dccp_sysctl_table, 826 + sizeof(dccp_sysctl_table), 827 + GFP_KERNEL); 828 + if (!pn->ctl_table) 829 + return -ENOMEM; 830 + 831 + pn->ctl_table[0].data = &dn->dccp_timeout[CT_DCCP_REQUEST]; 832 + pn->ctl_table[1].data = &dn->dccp_timeout[CT_DCCP_RESPOND]; 833 + pn->ctl_table[2].data = &dn->dccp_timeout[CT_DCCP_PARTOPEN]; 834 + pn->ctl_table[3].data = &dn->dccp_timeout[CT_DCCP_OPEN]; 835 + pn->ctl_table[4].data = &dn->dccp_timeout[CT_DCCP_CLOSEREQ]; 836 + pn->ctl_table[5].data = &dn->dccp_timeout[CT_DCCP_CLOSING]; 837 + pn->ctl_table[6].data = &dn->dccp_timeout[CT_DCCP_TIMEWAIT]; 838 + pn->ctl_table[7].data = &dn->dccp_loose; 839 + #endif 840 + return 0; 841 + } 842 + 818 843 static int dccp_init_net(struct net *net, u_int16_t proto) 819 844 { 820 845 struct dccp_net *dn = dccp_pernet(net); 821 - struct nf_proto_net *pn = (struct nf_proto_net *)dn; 846 + struct nf_proto_net *pn = &dn->pn; 822 847 823 - #ifdef CONFIG_SYSCTL 824 - if (!pn->ctl_table) { 825 - #else 826 - if (!pn->users++) { 827 - #endif 848 + if (!pn->users) { 828 849 /* default values */ 829 850 dn->dccp_loose = 1; 830 851 dn->dccp_timeout[CT_DCCP_REQUEST] = 2 * DCCP_MSL; ··· 855 834 dn->dccp_timeout[CT_DCCP_CLOSEREQ] = 64 * HZ; 856 835 dn->dccp_timeout[CT_DCCP_CLOSING] = 64 * HZ; 857 836 dn->dccp_timeout[CT_DCCP_TIMEWAIT] = 2 * DCCP_MSL; 858 - #ifdef CONFIG_SYSCTL 859 - pn->ctl_table = kmemdup(dccp_sysctl_table, 860 - sizeof(dccp_sysctl_table), 861 - GFP_KERNEL); 862 - if (!pn->ctl_table) 863 - return -ENOMEM; 864 - 865 - pn->ctl_table[0].data = &dn->dccp_timeout[CT_DCCP_REQUEST]; 866 - pn->ctl_table[1].data = &dn->dccp_timeout[CT_DCCP_RESPOND]; 867 - pn->ctl_table[2].data = &dn->dccp_timeout[CT_DCCP_PARTOPEN]; 868 - pn->ctl_table[3].data = &dn->dccp_timeout[CT_DCCP_OPEN]; 869 - pn->ctl_table[4].data = &dn->dccp_timeout[CT_DCCP_CLOSEREQ]; 870 - pn->ctl_table[5].data = &dn->dccp_timeout[CT_DCCP_CLOSING]; 871 - pn->ctl_table[6].data = &dn->dccp_timeout[CT_DCCP_TIMEWAIT]; 872 - pn->ctl_table[7].data = &dn->dccp_loose; 873 - #endif 874 837 } 875 - return 0; 838 + 839 + return dccp_kmemdup_sysctl_table(pn, dn); 876 840 } 877 841 878 842 static struct nf_conntrack_l4proto dccp_proto4 __read_mostly = {