···135135#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */136136#endif /* CONFIG_SYSCTL */137137138138-static int generic_init_net(struct net *net)138138+static int generic_kmemdup_sysctl_table(struct nf_proto_net *pn,139139+ struct nf_generic_net *gn)139140{140140- struct nf_generic_net *gn = generic_pernet(net);141141- struct nf_proto_net *pn = (struct nf_proto_net *)gn;142142- gn->timeout = nf_ct_generic_timeout;143141#ifdef CONFIG_SYSCTL144142 pn->ctl_table = kmemdup(generic_sysctl_table,145143 sizeof(generic_sysctl_table),146144 GFP_KERNEL);147145 if (!pn->ctl_table)148146 return -ENOMEM;149149- pn->ctl_table[0].data = &gn->timeout;150147148148+ pn->ctl_table[0].data = &gn->timeout;149149+#endif150150+ return 0;151151+}152152+153153+static int generic_kmemdup_compat_sysctl_table(struct nf_proto_net *pn,154154+ struct nf_generic_net *gn)155155+{156156+#ifdef CONFIG_SYSCTL151157#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT152158 pn->ctl_compat_table = kmemdup(generic_compat_sysctl_table,153159 sizeof(generic_compat_sysctl_table),154160 GFP_KERNEL);155155- if (!pn->ctl_compat_table) {156156- kfree(pn->ctl_table);157157- pn->ctl_table = NULL;161161+ if (!pn->ctl_compat_table)158162 return -ENOMEM;159159- }163163+160164 pn->ctl_compat_table[0].data = &gn->timeout;161165#endif162166#endif163167 return 0;168168+}169169+170170+static int generic_init_net(struct net *net, u_int16_t proto)171171+{172172+ int ret;173173+ struct nf_generic_net *gn = generic_pernet(net);174174+ struct nf_proto_net *pn = &gn->pn;175175+176176+ gn->timeout = nf_ct_generic_timeout;177177+178178+ ret = generic_kmemdup_compat_sysctl_table(pn, gn);179179+ if (ret < 0)180180+ return ret;181181+182182+ ret = generic_kmemdup_sysctl_table(pn, gn);183183+ if (ret < 0)184184+ nf_ct_kfree_compat_sysctl_table(pn);185185+186186+ return ret;187187+}188188+189189+static struct nf_proto_net *generic_get_net_proto(struct net *net)190190+{191191+ return &net->ct.nf_ct_proto.generic.pn;164192}165193166194struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly =···212184 },213185#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */214186 .init_net = generic_init_net,187187+ .get_net_proto = generic_get_net_proto,215188};
+1-1
net/netfilter/nf_conntrack_proto_gre.c
···348348};349349#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */350350351351-static int gre_init_net(struct net *net)351351+static int gre_init_net(struct net *net, u_int16_t proto)352352{353353 struct netns_proto_gre *net_gre = gre_pernet(net);354354 int i;
+24-45
net/netfilter/nf_conntrack_proto_sctp.c
···707707#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */708708#endif709709710710-static void sctp_init_net_data(struct sctp_net *sn)711711-{712712- int i;713713-#ifdef CONFIG_SYSCTL714714- if (!sn->pn.ctl_table) {715715-#else716716- if (!sn->pn.users++) {717717-#endif718718- for (i = 0; i < SCTP_CONNTRACK_MAX; i++)719719- sn->timeouts[i] = sctp_timeouts[i];720720- }721721-}722722-723723-static int sctp_kmemdup_sysctl_table(struct nf_proto_net *pn)710710+static int sctp_kmemdup_sysctl_table(struct nf_proto_net *pn,711711+ struct sctp_net *sn)724712{725713#ifdef CONFIG_SYSCTL726726- struct sctp_net *sn = (struct sctp_net *)pn;727714 if (pn->ctl_table)728715 return 0;729716···731744 return 0;732745}733746734734-static int sctp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn)747747+static int sctp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn,748748+ struct sctp_net *sn)735749{736750#ifdef CONFIG_SYSCTL737751#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT738738- struct sctp_net *sn = (struct sctp_net *)pn;739752 pn->ctl_compat_table = kmemdup(sctp_compat_sysctl_table,740753 sizeof(sctp_compat_sysctl_table),741754 GFP_KERNEL);···754767 return 0;755768}756769757757-static int sctpv4_init_net(struct net *net)770770+static int sctp_init_net(struct net *net, u_int16_t proto)758771{759772 int ret;760773 struct sctp_net *sn = sctp_pernet(net);761761- struct nf_proto_net *pn = (struct nf_proto_net *)sn;774774+ struct nf_proto_net *pn = &sn->pn;762775763763- sctp_init_net_data(sn);776776+ if (!pn->users) {777777+ int i;764778765765- ret = sctp_kmemdup_compat_sysctl_table(pn);766766- if (ret < 0)767767- return ret;768768-769769- ret = sctp_kmemdup_sysctl_table(pn);770770-771771-#ifdef CONFIG_SYSCTL772772-#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT773773- if (ret < 0) {774774-775775- kfree(pn->ctl_compat_table);776776- pn->ctl_compat_table = NULL;779779+ for (i = 0; i < SCTP_CONNTRACK_MAX; i++)780780+ sn->timeouts[i] = sctp_timeouts[i];777781 }778778-#endif779779-#endif782782+783783+ if (proto == AF_INET) {784784+ ret = sctp_kmemdup_compat_sysctl_table(pn, sn);785785+ if (ret < 0)786786+ return ret;787787+788788+ ret = sctp_kmemdup_sysctl_table(pn, sn);789789+ if (ret < 0)790790+ nf_ct_kfree_compat_sysctl_table(pn);791791+ } else792792+ ret = sctp_kmemdup_sysctl_table(pn, sn);793793+780794 return ret;781781-}782782-783783-static int sctpv6_init_net(struct net *net)784784-{785785- struct sctp_net *sn = sctp_pernet(net);786786- struct nf_proto_net *pn = (struct nf_proto_net *)sn;787787-788788- sctp_init_net_data(sn);789789- return sctp_kmemdup_sysctl_table(pn);790795}791796792797static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp4 __read_mostly = {···812833 },813834#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */814835 .net_id = &sctp_net_id,815815- .init_net = sctpv4_init_net,836836+ .init_net = sctp_init_net,816837};817838818839static struct nf_conntrack_l4proto nf_conntrack_l4proto_sctp6 __read_mostly = {···846867#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */847868#endif848869 .net_id = &sctp_net_id,849849- .init_net = sctpv6_init_net,870870+ .init_net = sctp_init_net,850871};851872852873static int sctp_net_init(struct net *net)
+26-48
net/netfilter/nf_conntrack_proto_tcp.c
···821821822822static unsigned int *tcp_get_timeouts(struct net *net)823823{824824- return tcp_timeouts;824824+ return tcp_pernet(net)->timeouts;825825}826826827827/* Returns verdict for packet, or -1 for invalid. */···15331533#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */15341534#endif /* CONFIG_SYSCTL */1535153515361536-static int tcp_kmemdup_sysctl_table(struct nf_proto_net *pn)15361536+static int tcp_kmemdup_sysctl_table(struct nf_proto_net *pn,15371537+ struct nf_tcp_net *tn)15371538{15381539#ifdef CONFIG_SYSCTL15391539- struct nf_tcp_net *tn = (struct nf_tcp_net *)pn;15401540-15411540 if (pn->ctl_table)15421541 return 0;15431542···15631564 return 0;15641565}1565156615661566-static int tcp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn)15671567+static int tcp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn,15681568+ struct nf_tcp_net *tn)15671569{15681570#ifdef CONFIG_SYSCTL15691571#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT15701570- struct nf_tcp_net *tn = (struct nf_tcp_net *)pn;15711572 pn->ctl_compat_table = kmemdup(tcp_compat_sysctl_table,15721573 sizeof(tcp_compat_sysctl_table),15731574 GFP_KERNEL);···15921593 return 0;15931594}1594159515951595-static int tcpv4_init_net(struct net *net)15961596+static int tcp_init_net(struct net *net, u_int16_t proto)15961597{15971597- int i;15981598- int ret = 0;15981598+ int ret;15991599 struct nf_tcp_net *tn = tcp_pernet(net);16001600- struct nf_proto_net *pn = (struct nf_proto_net *)tn;16001600+ struct nf_proto_net *pn = &tn->pn;1601160116021602-#ifdef CONFIG_SYSCTL16031603- if (!pn->ctl_table) {16041604-#else16051605- if (!pn->users++) {16061606-#endif16021602+ if (!pn->users) {16031603+ int i;16041604+16071605 for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++)16081606 tn->timeouts[i] = tcp_timeouts[i];16091607···16091613 tn->tcp_max_retrans = nf_ct_tcp_max_retrans;16101614 }1611161516121612- ret = tcp_kmemdup_compat_sysctl_table(pn);16161616+ if (proto == AF_INET) {16171617+ ret = tcp_kmemdup_compat_sysctl_table(pn, tn);16181618+ if (ret < 0)16191619+ return ret;1613162016141614- if (ret < 0)16151615- return ret;16211621+ ret = tcp_kmemdup_sysctl_table(pn, tn);16221622+ if (ret < 0)16231623+ nf_ct_kfree_compat_sysctl_table(pn);16241624+ } else16251625+ ret = tcp_kmemdup_sysctl_table(pn, tn);1616162616171617- ret = tcp_kmemdup_sysctl_table(pn);16181618-16191619-#ifdef CONFIG_SYSCTL16201620-#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT16211621- if (ret < 0) {16221622- kfree(pn->ctl_compat_table);16231623- pn->ctl_compat_table = NULL;16241624- }16251625-#endif16261626-#endif16271627 return ret;16281628}1629162916301630-static int tcpv6_init_net(struct net *net)16301630+static struct nf_proto_net *tcp_get_net_proto(struct net *net)16311631{16321632- int i;16331633- struct nf_tcp_net *tn = tcp_pernet(net);16341634- struct nf_proto_net *pn = (struct nf_proto_net *)tn;16351635-16361636-#ifdef CONFIG_SYSCTL16371637- if (!pn->ctl_table) {16381638-#else16391639- if (!pn->users++) {16401640-#endif16411641- for (i = 0; i < TCP_CONNTRACK_TIMEOUT_MAX; i++)16421642- tn->timeouts[i] = tcp_timeouts[i];16431643- tn->tcp_loose = nf_ct_tcp_loose;16441644- tn->tcp_be_liberal = nf_ct_tcp_be_liberal;16451645- tn->tcp_max_retrans = nf_ct_tcp_max_retrans;16461646- }16471647-16481648- return tcp_kmemdup_sysctl_table(pn);16321632+ return &net->ct.nf_ct_proto.tcp.pn;16491633}1650163416511635struct nf_conntrack_l4proto nf_conntrack_l4proto_tcp4 __read_mostly =···16601684 .nla_policy = tcp_timeout_nla_policy,16611685 },16621686#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */16631663- .init_net = tcpv4_init_net,16871687+ .init_net = tcp_init_net,16881688+ .get_net_proto = tcp_get_net_proto,16641689};16651690EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp4);16661691···16971720 .nla_policy = tcp_timeout_nla_policy,16981721 },16991722#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */17001700- .init_net = tcpv6_init_net,17231723+ .init_net = tcp_init_net,17241724+ .get_net_proto = tcp_get_net_proto,17011725};17021726EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_tcp6);
+28-40
net/netfilter/nf_conntrack_proto_udp.c
···235235#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */236236#endif /* CONFIG_SYSCTL */237237238238-static int udp_kmemdup_sysctl_table(struct nf_proto_net *pn)238238+static int udp_kmemdup_sysctl_table(struct nf_proto_net *pn,239239+ struct nf_udp_net *un)239240{240241#ifdef CONFIG_SYSCTL241241- struct nf_udp_net *un = (struct nf_udp_net *)pn;242242 if (pn->ctl_table)243243 return 0;244244 pn->ctl_table = kmemdup(udp_sysctl_table,···252252 return 0;253253}254254255255-static int udp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn)255255+static int udp_kmemdup_compat_sysctl_table(struct nf_proto_net *pn,256256+ struct nf_udp_net *un)256257{257258#ifdef CONFIG_SYSCTL258259#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT259259- struct nf_udp_net *un = (struct nf_udp_net *)pn;260260 pn->ctl_compat_table = kmemdup(udp_compat_sysctl_table,261261 sizeof(udp_compat_sysctl_table),262262 GFP_KERNEL);···270270 return 0;271271}272272273273-static void udp_init_net_data(struct nf_udp_net *un)274274-{275275- int i;276276-#ifdef CONFIG_SYSCTL277277- if (!un->pn.ctl_table) {278278-#else279279- if (!un->pn.users++) {280280-#endif281281- for (i = 0; i < UDP_CT_MAX; i++)282282- un->timeouts[i] = udp_timeouts[i];283283- }284284-}285285-286286-static int udpv4_init_net(struct net *net)273273+static int udp_init_net(struct net *net, u_int16_t proto)287274{288275 int ret;289276 struct nf_udp_net *un = udp_pernet(net);290290- struct nf_proto_net *pn = (struct nf_proto_net *)un;277277+ struct nf_proto_net *pn = &un->pn;291278292292- udp_init_net_data(un);279279+ if (!pn->users) {280280+ int i;293281294294- ret = udp_kmemdup_compat_sysctl_table(pn);295295- if (ret < 0)296296- return ret;297297-298298- ret = udp_kmemdup_sysctl_table(pn);299299-#ifdef CONFIG_SYSCTL300300-#ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT301301- if (ret < 0) {302302- kfree(pn->ctl_compat_table);303303- pn->ctl_compat_table = NULL;282282+ for (i = 0; i < UDP_CT_MAX; i++)283283+ un->timeouts[i] = udp_timeouts[i];304284 }305305-#endif306306-#endif285285+286286+ if (proto == AF_INET) {287287+ ret = udp_kmemdup_compat_sysctl_table(pn, un);288288+ if (ret < 0)289289+ return ret;290290+291291+ ret = udp_kmemdup_sysctl_table(pn, un);292292+ if (ret < 0)293293+ nf_ct_kfree_compat_sysctl_table(pn);294294+ } else295295+ ret = udp_kmemdup_sysctl_table(pn, un);296296+307297 return ret;308298}309299310310-static int udpv6_init_net(struct net *net)300300+static struct nf_proto_net *udp_get_net_proto(struct net *net)311301{312312- struct nf_udp_net *un = udp_pernet(net);313313- struct nf_proto_net *pn = (struct nf_proto_net *)un;314314-315315- udp_init_net_data(un);316316- return udp_kmemdup_sysctl_table(pn);302302+ return &net->ct.nf_ct_proto.udp.pn;317303}318304319305struct nf_conntrack_l4proto nf_conntrack_l4proto_udp4 __read_mostly =···329343 .nla_policy = udp_timeout_nla_policy,330344 },331345#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */332332- .init_net = udpv4_init_net,346346+ .init_net = udp_init_net,347347+ .get_net_proto = udp_get_net_proto,333348};334349EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp4);335350···361374 .nla_policy = udp_timeout_nla_policy,362375 },363376#endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */364364- .init_net = udpv6_init_net,377377+ .init_net = udp_init_net,378378+ .get_net_proto = udp_get_net_proto,365379};366380EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_udp6);
+26-17
net/netfilter/nf_conntrack_proto_udplite.c
···234234};235235#endif /* CONFIG_SYSCTL */236236237237-static int udplite_init_net(struct net *net)237237+static int udplite_kmemdup_sysctl_table(struct nf_proto_net *pn,238238+ struct udplite_net *un)238239{239239- int i;240240- struct udplite_net *un = udplite_pernet(net);241241- struct nf_proto_net *pn = (struct nf_proto_net *)un;242240#ifdef CONFIG_SYSCTL243243- if (!pn->ctl_table) {244244-#else245245- if (!pn->users++) {241241+ if (pn->ctl_table)242242+ return 0;243243+244244+ pn->ctl_table = kmemdup(udplite_sysctl_table,245245+ sizeof(udplite_sysctl_table),246246+ GFP_KERNEL);247247+ if (!pn->ctl_table)248248+ return -ENOMEM;249249+250250+ pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED];251251+ pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED];246252#endif253253+ return 0;254254+}255255+256256+static int udplite_init_net(struct net *net, u_int16_t proto)257257+{258258+ struct udplite_net *un = udplite_pernet(net);259259+ struct nf_proto_net *pn = &un->pn;260260+261261+ if (!pn->users) {262262+ int i;263263+247264 for (i = 0 ; i < UDPLITE_CT_MAX; i++)248265 un->timeouts[i] = udplite_timeouts[i];249249-#ifdef CONFIG_SYSCTL250250- pn->ctl_table = kmemdup(udplite_sysctl_table,251251- sizeof(udplite_sysctl_table),252252- GFP_KERNEL);253253- if (!pn->ctl_table)254254- return -ENOMEM;255255- pn->ctl_table[0].data = &un->timeouts[UDPLITE_CT_UNREPLIED];256256- pn->ctl_table[1].data = &un->timeouts[UDPLITE_CT_REPLIED];257257-#endif258266 }259259- return 0;267267+268268+ return udplite_kmemdup_sysctl_table(pn, un);260269}261270262271static struct nf_conntrack_l4proto nf_conntrack_l4proto_udplite4 __read_mostly =