Commit a95a7774d51e13f9cf4b7285666829b68852f07a
1 parent
8a02bdd50b
netfilter: conntrack: add nf_{tcp,udp,sctp,icmp,dccp,icmpv6,generic}_pernet()
Expose these functions to access conntrack protocol tracker netns area, nfnetlink_cttimeout needs this. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Showing 8 changed files with 63 additions and 59 deletions Side-by-side Diff
- include/net/netfilter/nf_conntrack_l4proto.h
- net/netfilter/nf_conntrack_proto_dccp.c
- net/netfilter/nf_conntrack_proto_generic.c
- net/netfilter/nf_conntrack_proto_icmp.c
- net/netfilter/nf_conntrack_proto_icmpv6.c
- net/netfilter/nf_conntrack_proto_sctp.c
- net/netfilter/nf_conntrack_proto_tcp.c
- net/netfilter/nf_conntrack_proto_udp.c
include/net/netfilter/nf_conntrack_l4proto.h
... | ... | @@ -153,5 +153,44 @@ |
153 | 153 | const char *fmt, ...) { } |
154 | 154 | #endif /* CONFIG_SYSCTL */ |
155 | 155 | |
156 | +static inline struct nf_generic_net *nf_generic_pernet(struct net *net) | |
157 | +{ | |
158 | + return &net->ct.nf_ct_proto.generic; | |
159 | +} | |
160 | + | |
161 | +static inline struct nf_tcp_net *nf_tcp_pernet(struct net *net) | |
162 | +{ | |
163 | + return &net->ct.nf_ct_proto.tcp; | |
164 | +} | |
165 | + | |
166 | +static inline struct nf_udp_net *nf_udp_pernet(struct net *net) | |
167 | +{ | |
168 | + return &net->ct.nf_ct_proto.udp; | |
169 | +} | |
170 | + | |
171 | +static inline struct nf_icmp_net *nf_icmp_pernet(struct net *net) | |
172 | +{ | |
173 | + return &net->ct.nf_ct_proto.icmp; | |
174 | +} | |
175 | + | |
176 | +static inline struct nf_icmp_net *nf_icmpv6_pernet(struct net *net) | |
177 | +{ | |
178 | + return &net->ct.nf_ct_proto.icmpv6; | |
179 | +} | |
180 | + | |
181 | +#ifdef CONFIG_NF_CT_PROTO_DCCP | |
182 | +static inline struct nf_dccp_net *nf_dccp_pernet(struct net *net) | |
183 | +{ | |
184 | + return &net->ct.nf_ct_proto.dccp; | |
185 | +} | |
186 | +#endif | |
187 | + | |
188 | +#ifdef CONFIG_NF_CT_PROTO_SCTP | |
189 | +static inline struct nf_sctp_net *nf_sctp_pernet(struct net *net) | |
190 | +{ | |
191 | + return &net->ct.nf_ct_proto.sctp; | |
192 | +} | |
193 | +#endif | |
194 | + | |
156 | 195 | #endif /*_NF_CONNTRACK_PROTOCOL_H*/ |
net/netfilter/nf_conntrack_proto_dccp.c
... | ... | @@ -384,11 +384,6 @@ |
384 | 384 | }, |
385 | 385 | }; |
386 | 386 | |
387 | -static inline struct nf_dccp_net *dccp_pernet(struct net *net) | |
388 | -{ | |
389 | - return &net->ct.nf_ct_proto.dccp; | |
390 | -} | |
391 | - | |
392 | 387 | static noinline bool |
393 | 388 | dccp_new(struct nf_conn *ct, const struct sk_buff *skb, |
394 | 389 | const struct dccp_hdr *dh) |
... | ... | @@ -401,7 +396,7 @@ |
401 | 396 | state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE]; |
402 | 397 | switch (state) { |
403 | 398 | default: |
404 | - dn = dccp_pernet(net); | |
399 | + dn = nf_dccp_pernet(net); | |
405 | 400 | if (dn->dccp_loose == 0) { |
406 | 401 | msg = "not picking up existing connection "; |
407 | 402 | goto out_invalid; |
... | ... | @@ -568,7 +563,7 @@ |
568 | 563 | |
569 | 564 | timeouts = nf_ct_timeout_lookup(ct); |
570 | 565 | if (!timeouts) |
571 | - timeouts = dccp_pernet(nf_ct_net(ct))->dccp_timeout; | |
566 | + timeouts = nf_dccp_pernet(nf_ct_net(ct))->dccp_timeout; | |
572 | 567 | nf_ct_refresh_acct(ct, ctinfo, skb, timeouts[new_state]); |
573 | 568 | |
574 | 569 | return NF_ACCEPT; |
... | ... | @@ -681,7 +676,7 @@ |
681 | 676 | static int dccp_timeout_nlattr_to_obj(struct nlattr *tb[], |
682 | 677 | struct net *net, void *data) |
683 | 678 | { |
684 | - struct nf_dccp_net *dn = dccp_pernet(net); | |
679 | + struct nf_dccp_net *dn = nf_dccp_pernet(net); | |
685 | 680 | unsigned int *timeouts = data; |
686 | 681 | int i; |
687 | 682 | |
... | ... | @@ -814,7 +809,7 @@ |
814 | 809 | |
815 | 810 | static int dccp_init_net(struct net *net) |
816 | 811 | { |
817 | - struct nf_dccp_net *dn = dccp_pernet(net); | |
812 | + struct nf_dccp_net *dn = nf_dccp_pernet(net); | |
818 | 813 | struct nf_proto_net *pn = &dn->pn; |
819 | 814 | |
820 | 815 | if (!pn->users) { |
net/netfilter/nf_conntrack_proto_generic.c
... | ... | @@ -27,11 +27,6 @@ |
27 | 27 | } |
28 | 28 | } |
29 | 29 | |
30 | -static inline struct nf_generic_net *generic_pernet(struct net *net) | |
31 | -{ | |
32 | - return &net->ct.nf_ct_proto.generic; | |
33 | -} | |
34 | - | |
35 | 30 | static bool generic_pkt_to_tuple(const struct sk_buff *skb, |
36 | 31 | unsigned int dataoff, |
37 | 32 | struct net *net, struct nf_conntrack_tuple *tuple) |
... | ... | @@ -58,7 +53,7 @@ |
58 | 53 | } |
59 | 54 | |
60 | 55 | if (!timeout) |
61 | - timeout = &generic_pernet(nf_ct_net(ct))->timeout; | |
56 | + timeout = &nf_generic_pernet(nf_ct_net(ct))->timeout; | |
62 | 57 | |
63 | 58 | nf_ct_refresh_acct(ct, ctinfo, skb, *timeout); |
64 | 59 | return NF_ACCEPT; |
... | ... | @@ -72,7 +67,7 @@ |
72 | 67 | static int generic_timeout_nlattr_to_obj(struct nlattr *tb[], |
73 | 68 | struct net *net, void *data) |
74 | 69 | { |
75 | - struct nf_generic_net *gn = generic_pernet(net); | |
70 | + struct nf_generic_net *gn = nf_generic_pernet(net); | |
76 | 71 | unsigned int *timeout = data; |
77 | 72 | |
78 | 73 | if (!timeout) |
... | ... | @@ -138,7 +133,7 @@ |
138 | 133 | |
139 | 134 | static int generic_init_net(struct net *net) |
140 | 135 | { |
141 | - struct nf_generic_net *gn = generic_pernet(net); | |
136 | + struct nf_generic_net *gn = nf_generic_pernet(net); | |
142 | 137 | struct nf_proto_net *pn = &gn->pn; |
143 | 138 | |
144 | 139 | gn->timeout = nf_ct_generic_timeout; |
net/netfilter/nf_conntrack_proto_icmp.c
... | ... | @@ -25,11 +25,6 @@ |
25 | 25 | |
26 | 26 | static const unsigned int nf_ct_icmp_timeout = 30*HZ; |
27 | 27 | |
28 | -static inline struct nf_icmp_net *icmp_pernet(struct net *net) | |
29 | -{ | |
30 | - return &net->ct.nf_ct_proto.icmp; | |
31 | -} | |
32 | - | |
33 | 28 | static bool icmp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff, |
34 | 29 | struct net *net, struct nf_conntrack_tuple *tuple) |
35 | 30 | { |
... | ... | @@ -103,7 +98,7 @@ |
103 | 98 | } |
104 | 99 | |
105 | 100 | if (!timeout) |
106 | - timeout = &icmp_pernet(nf_ct_net(ct))->timeout; | |
101 | + timeout = &nf_icmp_pernet(nf_ct_net(ct))->timeout; | |
107 | 102 | |
108 | 103 | nf_ct_refresh_acct(ct, ctinfo, skb, *timeout); |
109 | 104 | return NF_ACCEPT; |
... | ... | @@ -275,7 +270,7 @@ |
275 | 270 | struct net *net, void *data) |
276 | 271 | { |
277 | 272 | unsigned int *timeout = data; |
278 | - struct nf_icmp_net *in = icmp_pernet(net); | |
273 | + struct nf_icmp_net *in = nf_icmp_pernet(net); | |
279 | 274 | |
280 | 275 | if (tb[CTA_TIMEOUT_ICMP_TIMEOUT]) { |
281 | 276 | if (!timeout) |
... | ... | @@ -337,7 +332,7 @@ |
337 | 332 | |
338 | 333 | static int icmp_init_net(struct net *net) |
339 | 334 | { |
340 | - struct nf_icmp_net *in = icmp_pernet(net); | |
335 | + struct nf_icmp_net *in = nf_icmp_pernet(net); | |
341 | 336 | struct nf_proto_net *pn = &in->pn; |
342 | 337 | |
343 | 338 | in->timeout = nf_ct_icmp_timeout; |
net/netfilter/nf_conntrack_proto_icmpv6.c
... | ... | @@ -30,11 +30,6 @@ |
30 | 30 | |
31 | 31 | static const unsigned int nf_ct_icmpv6_timeout = 30*HZ; |
32 | 32 | |
33 | -static inline struct nf_icmp_net *icmpv6_pernet(struct net *net) | |
34 | -{ | |
35 | - return &net->ct.nf_ct_proto.icmpv6; | |
36 | -} | |
37 | - | |
38 | 33 | static bool icmpv6_pkt_to_tuple(const struct sk_buff *skb, |
39 | 34 | unsigned int dataoff, |
40 | 35 | struct net *net, |
... | ... | @@ -87,7 +82,7 @@ |
87 | 82 | |
88 | 83 | static unsigned int *icmpv6_get_timeouts(struct net *net) |
89 | 84 | { |
90 | - return &icmpv6_pernet(net)->timeout; | |
85 | + return &nf_icmpv6_pernet(net)->timeout; | |
91 | 86 | } |
92 | 87 | |
93 | 88 | /* Returns verdict for packet, or -1 for invalid. */ |
... | ... | @@ -286,7 +281,7 @@ |
286 | 281 | struct net *net, void *data) |
287 | 282 | { |
288 | 283 | unsigned int *timeout = data; |
289 | - struct nf_icmp_net *in = icmpv6_pernet(net); | |
284 | + struct nf_icmp_net *in = nf_icmpv6_pernet(net); | |
290 | 285 | |
291 | 286 | if (!timeout) |
292 | 287 | timeout = icmpv6_get_timeouts(net); |
... | ... | @@ -348,7 +343,7 @@ |
348 | 343 | |
349 | 344 | static int icmpv6_init_net(struct net *net) |
350 | 345 | { |
351 | - struct nf_icmp_net *in = icmpv6_pernet(net); | |
346 | + struct nf_icmp_net *in = nf_icmpv6_pernet(net); | |
352 | 347 | struct nf_proto_net *pn = &in->pn; |
353 | 348 | |
354 | 349 | in->timeout = nf_ct_icmpv6_timeout; |
net/netfilter/nf_conntrack_proto_sctp.c
... | ... | @@ -146,11 +146,6 @@ |
146 | 146 | } |
147 | 147 | }; |
148 | 148 | |
149 | -static inline struct nf_sctp_net *sctp_pernet(struct net *net) | |
150 | -{ | |
151 | - return &net->ct.nf_ct_proto.sctp; | |
152 | -} | |
153 | - | |
154 | 149 | #ifdef CONFIG_NF_CONNTRACK_PROCFS |
155 | 150 | /* Print out the private part of the conntrack. */ |
156 | 151 | static void sctp_print_conntrack(struct seq_file *s, struct nf_conn *ct) |
... | ... | @@ -480,7 +475,7 @@ |
480 | 475 | |
481 | 476 | timeouts = nf_ct_timeout_lookup(ct); |
482 | 477 | if (!timeouts) |
483 | - timeouts = sctp_pernet(nf_ct_net(ct))->timeouts; | |
478 | + timeouts = nf_sctp_pernet(nf_ct_net(ct))->timeouts; | |
484 | 479 | |
485 | 480 | nf_ct_refresh_acct(ct, ctinfo, skb, timeouts[new_state]); |
486 | 481 | |
... | ... | @@ -599,7 +594,7 @@ |
599 | 594 | struct net *net, void *data) |
600 | 595 | { |
601 | 596 | unsigned int *timeouts = data; |
602 | - struct nf_sctp_net *sn = sctp_pernet(net); | |
597 | + struct nf_sctp_net *sn = nf_sctp_pernet(net); | |
603 | 598 | int i; |
604 | 599 | |
605 | 600 | /* set default SCTP timeouts. */ |
... | ... | @@ -736,7 +731,7 @@ |
736 | 731 | |
737 | 732 | static int sctp_init_net(struct net *net) |
738 | 733 | { |
739 | - struct nf_sctp_net *sn = sctp_pernet(net); | |
734 | + struct nf_sctp_net *sn = nf_sctp_pernet(net); | |
740 | 735 | struct nf_proto_net *pn = &sn->pn; |
741 | 736 | |
742 | 737 | if (!pn->users) { |
net/netfilter/nf_conntrack_proto_tcp.c
... | ... | @@ -272,11 +272,6 @@ |
272 | 272 | } |
273 | 273 | }; |
274 | 274 | |
275 | -static inline struct nf_tcp_net *tcp_pernet(struct net *net) | |
276 | -{ | |
277 | - return &net->ct.nf_ct_proto.tcp; | |
278 | -} | |
279 | - | |
280 | 275 | #ifdef CONFIG_NF_CONNTRACK_PROCFS |
281 | 276 | /* Print out the private part of the conntrack. */ |
282 | 277 | static void tcp_print_conntrack(struct seq_file *s, struct nf_conn *ct) |
... | ... | @@ -475,7 +470,7 @@ |
475 | 470 | const struct tcphdr *tcph) |
476 | 471 | { |
477 | 472 | struct net *net = nf_ct_net(ct); |
478 | - struct nf_tcp_net *tn = tcp_pernet(net); | |
473 | + struct nf_tcp_net *tn = nf_tcp_pernet(net); | |
479 | 474 | struct ip_ct_tcp_state *sender = &state->seen[dir]; |
480 | 475 | struct ip_ct_tcp_state *receiver = &state->seen[!dir]; |
481 | 476 | const struct nf_conntrack_tuple *tuple = &ct->tuplehash[dir].tuple; |
... | ... | @@ -767,7 +762,7 @@ |
767 | 762 | { |
768 | 763 | enum tcp_conntrack new_state; |
769 | 764 | struct net *net = nf_ct_net(ct); |
770 | - const struct nf_tcp_net *tn = tcp_pernet(net); | |
765 | + const struct nf_tcp_net *tn = nf_tcp_pernet(net); | |
771 | 766 | const struct ip_ct_tcp_state *sender = &ct->proto.tcp.seen[0]; |
772 | 767 | const struct ip_ct_tcp_state *receiver = &ct->proto.tcp.seen[1]; |
773 | 768 | |
... | ... | @@ -841,7 +836,7 @@ |
841 | 836 | const struct nf_hook_state *state) |
842 | 837 | { |
843 | 838 | struct net *net = nf_ct_net(ct); |
844 | - struct nf_tcp_net *tn = tcp_pernet(net); | |
839 | + struct nf_tcp_net *tn = nf_tcp_pernet(net); | |
845 | 840 | struct nf_conntrack_tuple *tuple; |
846 | 841 | enum tcp_conntrack new_state, old_state; |
847 | 842 | unsigned int index, *timeouts; |
... | ... | @@ -1283,7 +1278,7 @@ |
1283 | 1278 | static int tcp_timeout_nlattr_to_obj(struct nlattr *tb[], |
1284 | 1279 | struct net *net, void *data) |
1285 | 1280 | { |
1286 | - struct nf_tcp_net *tn = tcp_pernet(net); | |
1281 | + struct nf_tcp_net *tn = nf_tcp_pernet(net); | |
1287 | 1282 | unsigned int *timeouts = data; |
1288 | 1283 | int i; |
1289 | 1284 | |
... | ... | @@ -1508,7 +1503,7 @@ |
1508 | 1503 | |
1509 | 1504 | static int tcp_init_net(struct net *net) |
1510 | 1505 | { |
1511 | - struct nf_tcp_net *tn = tcp_pernet(net); | |
1506 | + struct nf_tcp_net *tn = nf_tcp_pernet(net); | |
1512 | 1507 | struct nf_proto_net *pn = &tn->pn; |
1513 | 1508 | |
1514 | 1509 | if (!pn->users) { |
net/netfilter/nf_conntrack_proto_udp.c
... | ... | @@ -32,14 +32,9 @@ |
32 | 32 | [UDP_CT_REPLIED] = 180*HZ, |
33 | 33 | }; |
34 | 34 | |
35 | -static inline struct nf_udp_net *udp_pernet(struct net *net) | |
36 | -{ | |
37 | - return &net->ct.nf_ct_proto.udp; | |
38 | -} | |
39 | - | |
40 | 35 | static unsigned int *udp_get_timeouts(struct net *net) |
41 | 36 | { |
42 | - return udp_pernet(net)->timeouts; | |
37 | + return nf_udp_pernet(net)->timeouts; | |
43 | 38 | } |
44 | 39 | |
45 | 40 | static void udp_error_log(const struct sk_buff *skb, |
... | ... | @@ -212,7 +207,7 @@ |
212 | 207 | struct net *net, void *data) |
213 | 208 | { |
214 | 209 | unsigned int *timeouts = data; |
215 | - struct nf_udp_net *un = udp_pernet(net); | |
210 | + struct nf_udp_net *un = nf_udp_pernet(net); | |
216 | 211 | |
217 | 212 | if (!timeouts) |
218 | 213 | timeouts = un->timeouts; |
... | ... | @@ -292,7 +287,7 @@ |
292 | 287 | |
293 | 288 | static int udp_init_net(struct net *net) |
294 | 289 | { |
295 | - struct nf_udp_net *un = udp_pernet(net); | |
290 | + struct nf_udp_net *un = nf_udp_pernet(net); | |
296 | 291 | struct nf_proto_net *pn = &un->pn; |
297 | 292 | |
298 | 293 | if (!pn->users) { |