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

netfilter: nf_ct_sctp: merge sctpv[4,6]_net_init into sctp_net_init

Merge sctpv4_net_init and sctpv6_net_init into sctp_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 i

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
f42c4183 51b4c824

+24 -45
+24 -45
net/netfilter/nf_conntrack_proto_sctp.c
··· 707 707 #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 708 708 #endif 709 709 710 - static void sctp_init_net_data(struct sctp_net *sn) 711 - { 712 - int i; 713 - #ifdef CONFIG_SYSCTL 714 - if (!sn->pn.ctl_table) { 715 - #else 716 - if (!sn->pn.users++) { 717 - #endif 718 - for (i = 0; i < SCTP_CONNTRACK_MAX; i++) 719 - sn->timeouts[i] = sctp_timeouts[i]; 720 - } 721 - } 722 - 723 - static int sctp_kmemdup_sysctl_table(struct nf_proto_net *pn) 710 + static int sctp_kmemdup_sysctl_table(struct nf_proto_net *pn, 711 + struct sctp_net *sn) 724 712 { 725 713 #ifdef CONFIG_SYSCTL 726 - struct sctp_net *sn = (struct sctp_net *)pn; 727 714 if (pn->ctl_table) 728 715 return 0; 729 716 ··· 731 744 return 0; 732 745 } 733 746 734 - static int sctp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn) 747 + static int sctp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn, 748 + struct sctp_net *sn) 735 749 { 736 750 #ifdef CONFIG_SYSCTL 737 751 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 738 - struct sctp_net *sn = (struct sctp_net *)pn; 739 752 pn->ctl_compat_table = kmemdup(sctp_compat_sysctl_table, 740 753 sizeof(sctp_compat_sysctl_table), 741 754 GFP_KERNEL); ··· 754 767 return 0; 755 768 } 756 769 757 - static int sctpv4_init_net(struct net *net, u_int16_t proto) 770 + static int sctp_init_net(struct net *net, u_int16_t proto) 758 771 { 759 772 int ret; 760 773 struct sctp_net *sn = sctp_pernet(net); 761 - struct nf_proto_net *pn = (struct nf_proto_net *)sn; 774 + struct nf_proto_net *pn = &sn->pn; 762 775 763 - sctp_init_net_data(sn); 776 + if (!pn->users) { 777 + int i; 764 778 765 - ret = sctp_kmemdup_compat_sysctl_table(pn); 766 - if (ret < 0) 767 - return ret; 768 - 769 - ret = sctp_kmemdup_sysctl_table(pn); 770 - 771 - #ifdef CONFIG_SYSCTL 772 - #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT 773 - if (ret < 0) { 774 - 775 - kfree(pn->ctl_compat_table); 776 - pn->ctl_compat_table = NULL; 779 + for (i = 0; i < SCTP_CONNTRACK_MAX; i++) 780 + sn->timeouts[i] = sctp_timeouts[i]; 777 781 } 778 - #endif 779 - #endif 782 + 783 + if (proto == AF_INET) { 784 + ret = sctp_kmemdup_compat_sysctl_table(pn, sn); 785 + if (ret < 0) 786 + return ret; 787 + 788 + ret = sctp_kmemdup_sysctl_table(pn, sn); 789 + if (ret < 0) 790 + nf_ct_kfree_compat_sysctl_table(pn); 791 + } else 792 + ret = sctp_kmemdup_sysctl_table(pn, sn); 793 + 780 794 return ret; 781 - } 782 - 783 - static int sctpv6_init_net(struct net *net, u_int16_t proto) 784 - { 785 - struct sctp_net *sn = sctp_pernet(net); 786 - struct nf_proto_net *pn = (struct nf_proto_net *)sn; 787 - 788 - sctp_init_net_data(sn); 789 - return sctp_kmemdup_sysctl_table(pn); 790 795 } 791 796 792 797 static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = { ··· 812 833 }, 813 834 #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 814 835 .net_id = &sctp_net_id, 815 - .init_net = sctpv4_init_net, 836 + .init_net = sctp_init_net, 816 837 }; 817 838 818 839 static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = { ··· 846 867 #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ 847 868 #endif 848 869 .net_id = &sctp_net_id, 849 - .init_net = sctpv6_init_net, 870 + .init_net = sctp_init_net, 850 871 }; 851 872 852 873 static int sctp_net_init(struct net *net)