aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2017-01-23 12:21:57 -0500
committerPablo Neira Ayuso <pablo@netfilter.org>2017-02-02 08:31:54 -0500
commitc74454fadd5ea6fc866ffe2c417a0dba56b2bf1c (patch)
tree7e2ab906478778bc0733840c6e5cc46bfceeda4c
parentcb9c68363efb6d1f950ec55fb06e031ee70db5fc (diff)
netfilter: add and use nf_ct_set helper
Add a helper to assign a nf_conn entry and the ctinfo bits to an sk_buff. This avoids changing code in followup patch that merges skb->nfct and skb->nfctinfo into skb->_nfct. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r--include/net/ip_vs.h3
-rw-r--r--include/net/netfilter/nf_conntrack.h8
-rw-r--r--net/ipv4/netfilter/ipt_SYNPROXY.c3
-rw-r--r--net/ipv4/netfilter/nf_conntrack_proto_icmp.c3
-rw-r--r--net/ipv4/netfilter/nf_dup_ipv4.c3
-rw-r--r--net/ipv6/netfilter/ip6t_SYNPROXY.c3
-rw-r--r--net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c6
-rw-r--r--net/ipv6/netfilter/nf_dup_ipv6.c3
-rw-r--r--net/netfilter/nf_conntrack_core.c11
-rw-r--r--net/netfilter/nft_ct.c3
-rw-r--r--net/netfilter/xt_CT.c6
-rw-r--r--net/openvswitch/conntrack.c6
12 files changed, 24 insertions, 34 deletions
diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
index 2a344ebd7ebe..4b46c591b542 100644
--- a/include/net/ip_vs.h
+++ b/include/net/ip_vs.h
@@ -1559,8 +1559,7 @@ static inline void ip_vs_notrack(struct sk_buff *skb)
1559 nf_conntrack_put(&ct->ct_general); 1559 nf_conntrack_put(&ct->ct_general);
1560 untracked = nf_ct_untracked_get(); 1560 untracked = nf_ct_untracked_get();
1561 nf_conntrack_get(&untracked->ct_general); 1561 nf_conntrack_get(&untracked->ct_general);
1562 skb->nfct = &untracked->ct_general; 1562 nf_ct_set(skb, untracked, IP_CT_NEW);
1563 skb->nfctinfo = IP_CT_NEW;
1564 } 1563 }
1565#endif 1564#endif
1566} 1565}
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h
index 5916aa9ab3f0..d704aed11684 100644
--- a/include/net/netfilter/nf_conntrack.h
+++ b/include/net/netfilter/nf_conntrack.h
@@ -34,6 +34,7 @@ union nf_conntrack_proto {
34 struct ip_ct_sctp sctp; 34 struct ip_ct_sctp sctp;
35 struct ip_ct_tcp tcp; 35 struct ip_ct_tcp tcp;
36 struct nf_ct_gre gre; 36 struct nf_ct_gre gre;
37 unsigned int tmpl_padto;
37}; 38};
38 39
39union nf_conntrack_expect_proto { 40union nf_conntrack_expect_proto {
@@ -341,6 +342,13 @@ struct nf_conn *nf_ct_tmpl_alloc(struct net *net,
341 gfp_t flags); 342 gfp_t flags);
342void nf_ct_tmpl_free(struct nf_conn *tmpl); 343void nf_ct_tmpl_free(struct nf_conn *tmpl);
343 344
345static inline void
346nf_ct_set(struct sk_buff *skb, struct nf_conn *ct, enum ip_conntrack_info info)
347{
348 skb->nfct = &ct->ct_general;
349 skb->nfctinfo = info;
350}
351
344#define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count) 352#define NF_CT_STAT_INC(net, count) __this_cpu_inc((net)->ct.stat->count)
345#define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count) 353#define NF_CT_STAT_INC_ATOMIC(net, count) this_cpu_inc((net)->ct.stat->count)
346#define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v)) 354#define NF_CT_STAT_ADD_ATOMIC(net, count, v) this_cpu_add((net)->ct.stat->count, (v))
diff --git a/net/ipv4/netfilter/ipt_SYNPROXY.c b/net/ipv4/netfilter/ipt_SYNPROXY.c
index a12d4f0aa674..3240a2614e82 100644
--- a/net/ipv4/netfilter/ipt_SYNPROXY.c
+++ b/net/ipv4/netfilter/ipt_SYNPROXY.c
@@ -57,8 +57,7 @@ synproxy_send_tcp(struct net *net,
57 goto free_nskb; 57 goto free_nskb;
58 58
59 if (nfct) { 59 if (nfct) {
60 nskb->nfct = nfct; 60 nf_ct_set(nskb, (struct nf_conn *)nfct, ctinfo);
61 nskb->nfctinfo = ctinfo;
62 nf_conntrack_get(nfct); 61 nf_conntrack_get(nfct);
63 } 62 }
64 63
diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
index 478a025909fc..73c591d8a9a8 100644
--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
@@ -172,8 +172,7 @@ icmp_error_message(struct net *net, struct nf_conn *tmpl, struct sk_buff *skb,
172 ctinfo += IP_CT_IS_REPLY; 172 ctinfo += IP_CT_IS_REPLY;
173 173
174 /* Update skb to refer to this connection */ 174 /* Update skb to refer to this connection */
175 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general; 175 nf_ct_set(skb, nf_ct_tuplehash_to_ctrack(h), ctinfo);
176 skb->nfctinfo = ctinfo;
177 return NF_ACCEPT; 176 return NF_ACCEPT;
178} 177}
179 178
diff --git a/net/ipv4/netfilter/nf_dup_ipv4.c b/net/ipv4/netfilter/nf_dup_ipv4.c
index 1a5e1f53ceaa..f0dbff05fc28 100644
--- a/net/ipv4/netfilter/nf_dup_ipv4.c
+++ b/net/ipv4/netfilter/nf_dup_ipv4.c
@@ -69,8 +69,7 @@ void nf_dup_ipv4(struct net *net, struct sk_buff *skb, unsigned int hooknum,
69#if IS_ENABLED(CONFIG_NF_CONNTRACK) 69#if IS_ENABLED(CONFIG_NF_CONNTRACK)
70 /* Avoid counting cloned packets towards the original connection. */ 70 /* Avoid counting cloned packets towards the original connection. */
71 nf_reset(skb); 71 nf_reset(skb);
72 skb->nfct = &nf_ct_untracked_get()->ct_general; 72 nf_ct_set(skb, nf_ct_untracked_get(), IP_CT_NEW);
73 skb->nfctinfo = IP_CT_NEW;
74 nf_conntrack_get(skb_nfct(skb)); 73 nf_conntrack_get(skb_nfct(skb));
75#endif 74#endif
76 /* 75 /*
diff --git a/net/ipv6/netfilter/ip6t_SYNPROXY.c b/net/ipv6/netfilter/ip6t_SYNPROXY.c
index 2dc01d2c6ec0..4ef1ddd4bbbd 100644
--- a/net/ipv6/netfilter/ip6t_SYNPROXY.c
+++ b/net/ipv6/netfilter/ip6t_SYNPROXY.c
@@ -71,8 +71,7 @@ synproxy_send_tcp(struct net *net,
71 skb_dst_set(nskb, dst); 71 skb_dst_set(nskb, dst);
72 72
73 if (nfct) { 73 if (nfct) {
74 nskb->nfct = nfct; 74 nf_ct_set(nskb, (struct nf_conn *)nfct, ctinfo);
75 nskb->nfctinfo = ctinfo;
76 nf_conntrack_get(nfct); 75 nf_conntrack_get(nfct);
77 } 76 }
78 77
diff --git a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
index 09f1661a4e88..d2c2ccbfbe72 100644
--- a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
+++ b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
@@ -189,8 +189,7 @@ icmpv6_error_message(struct net *net, struct nf_conn *tmpl,
189 } 189 }
190 190
191 /* Update skb to refer to this connection */ 191 /* Update skb to refer to this connection */
192 skb->nfct = &nf_ct_tuplehash_to_ctrack(h)->ct_general; 192 nf_ct_set(skb, nf_ct_tuplehash_to_ctrack(h), ctinfo);
193 skb->nfctinfo = ctinfo;
194 return NF_ACCEPT; 193 return NF_ACCEPT;
195} 194}
196 195
@@ -222,8 +221,7 @@ icmpv6_error(struct net *net, struct nf_conn *tmpl,
222 type = icmp6h->icmp6_type - 130; 221 type = icmp6h->icmp6_type - 130;
223 if (type >= 0 && type < sizeof(noct_valid_new) && 222 if (type >= 0 && type < sizeof(noct_valid_new) &&
224 noct_valid_new[type]) { 223 noct_valid_new[type]) {
225 skb->nfct = &nf_ct_untracked_get()->ct_general; 224 nf_ct_set(skb, nf_ct_untracked_get(), IP_CT_NEW);
226 skb->nfctinfo = IP_CT_NEW;
227 nf_conntrack_get(skb_nfct(skb)); 225 nf_conntrack_get(skb_nfct(skb));
228 return NF_ACCEPT; 226 return NF_ACCEPT;
229 } 227 }
diff --git a/net/ipv6/netfilter/nf_dup_ipv6.c b/net/ipv6/netfilter/nf_dup_ipv6.c
index 5f52e5f90e7e..ff04f6a7f45b 100644
--- a/net/ipv6/netfilter/nf_dup_ipv6.c
+++ b/net/ipv6/netfilter/nf_dup_ipv6.c
@@ -58,8 +58,7 @@ void nf_dup_ipv6(struct net *net, struct sk_buff *skb, unsigned int hooknum,
58 58
59#if IS_ENABLED(CONFIG_NF_CONNTRACK) 59#if IS_ENABLED(CONFIG_NF_CONNTRACK)
60 nf_reset(skb); 60 nf_reset(skb);
61 skb->nfct = &nf_ct_untracked_get()->ct_general; 61 nf_ct_set(skb, nf_ct_untracked_get(), IP_CT_NEW);
62 skb->nfctinfo = IP_CT_NEW;
63 nf_conntrack_get(skb->nfct); 62 nf_conntrack_get(skb->nfct);
64#endif 63#endif
65 if (hooknum == NF_INET_PRE_ROUTING || 64 if (hooknum == NF_INET_PRE_ROUTING ||
diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
index 78aebf0ee6e3..c9bd10747864 100644
--- a/net/netfilter/nf_conntrack_core.c
+++ b/net/netfilter/nf_conntrack_core.c
@@ -691,10 +691,7 @@ static int nf_ct_resolve_clash(struct net *net, struct sk_buff *skb,
691 691
692 nf_ct_acct_merge(ct, ctinfo, loser_ct); 692 nf_ct_acct_merge(ct, ctinfo, loser_ct);
693 nf_conntrack_put(&loser_ct->ct_general); 693 nf_conntrack_put(&loser_ct->ct_general);
694 /* Assign conntrack already in hashes to this skbuff. Don't 694 nf_ct_set(skb, ct, oldinfo);
695 * modify skb->nfctinfo to ensure consistent stateful filtering.
696 */
697 skb->nfct = &ct->ct_general;
698 return NF_ACCEPT; 695 return NF_ACCEPT;
699 } 696 }
700 NF_CT_STAT_INC(net, drop); 697 NF_CT_STAT_INC(net, drop);
@@ -1282,8 +1279,7 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl,
1282 } 1279 }
1283 *set_reply = 0; 1280 *set_reply = 0;
1284 } 1281 }
1285 skb->nfct = &ct->ct_general; 1282 nf_ct_set(skb, ct, *ctinfo);
1286 skb->nfctinfo = *ctinfo;
1287 return ct; 1283 return ct;
1288} 1284}
1289 1285
@@ -1526,8 +1522,7 @@ static void nf_conntrack_attach(struct sk_buff *nskb, const struct sk_buff *skb)
1526 ctinfo = IP_CT_RELATED; 1522 ctinfo = IP_CT_RELATED;
1527 1523
1528 /* Attach to new skbuff, and increment count */ 1524 /* Attach to new skbuff, and increment count */
1529 nskb->nfct = &ct->ct_general; 1525 nf_ct_set(nskb, ct, ctinfo);
1530 nskb->nfctinfo = ctinfo;
1531 nf_conntrack_get(skb_nfct(nskb)); 1526 nf_conntrack_get(skb_nfct(nskb));
1532} 1527}
1533 1528
diff --git a/net/netfilter/nft_ct.c b/net/netfilter/nft_ct.c
index d774d7823688..66a2377510e1 100644
--- a/net/netfilter/nft_ct.c
+++ b/net/netfilter/nft_ct.c
@@ -554,8 +554,7 @@ static void nft_notrack_eval(const struct nft_expr *expr,
554 554
555 ct = nf_ct_untracked_get(); 555 ct = nf_ct_untracked_get();
556 atomic_inc(&ct->ct_general.use); 556 atomic_inc(&ct->ct_general.use);
557 skb->nfct = &ct->ct_general; 557 nf_ct_set(skb, ct, IP_CT_NEW);
558 skb->nfctinfo = IP_CT_NEW;
559} 558}
560 559
561static struct nft_expr_type nft_notrack_type; 560static struct nft_expr_type nft_notrack_type;
diff --git a/net/netfilter/xt_CT.c b/net/netfilter/xt_CT.c
index cd7e29910ae1..51f00e1e1208 100644
--- a/net/netfilter/xt_CT.c
+++ b/net/netfilter/xt_CT.c
@@ -30,8 +30,7 @@ static inline int xt_ct_target(struct sk_buff *skb, struct nf_conn *ct)
30 if (!ct) 30 if (!ct)
31 ct = nf_ct_untracked_get(); 31 ct = nf_ct_untracked_get();
32 atomic_inc(&ct->ct_general.use); 32 atomic_inc(&ct->ct_general.use);
33 skb->nfct = &ct->ct_general; 33 nf_ct_set(skb, ct, IP_CT_NEW);
34 skb->nfctinfo = IP_CT_NEW;
35 34
36 return XT_CONTINUE; 35 return XT_CONTINUE;
37} 36}
@@ -413,8 +412,7 @@ notrack_tg(struct sk_buff *skb, const struct xt_action_param *par)
413 if (skb->nfct != NULL) 412 if (skb->nfct != NULL)
414 return XT_CONTINUE; 413 return XT_CONTINUE;
415 414
416 skb->nfct = &nf_ct_untracked_get()->ct_general; 415 nf_ct_set(skb, nf_ct_untracked_get(), IP_CT_NEW);
417 skb->nfctinfo = IP_CT_NEW;
418 nf_conntrack_get(skb_nfct(skb)); 416 nf_conntrack_get(skb_nfct(skb));
419 417
420 return XT_CONTINUE; 418 return XT_CONTINUE;
diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c
index 452557946147..d1fbfcaa009a 100644
--- a/net/openvswitch/conntrack.c
+++ b/net/openvswitch/conntrack.c
@@ -460,8 +460,7 @@ ovs_ct_find_existing(struct net *net, const struct nf_conntrack_zone *zone,
460 460
461 ct = nf_ct_tuplehash_to_ctrack(h); 461 ct = nf_ct_tuplehash_to_ctrack(h);
462 462
463 skb->nfct = &ct->ct_general; 463 nf_ct_set(skb, ct, ovs_ct_get_info(h));
464 skb->nfctinfo = ovs_ct_get_info(h);
465 return ct; 464 return ct;
466} 465}
467 466
@@ -724,8 +723,7 @@ static int __ovs_ct_lookup(struct net *net, struct sw_flow_key *key,
724 if (skb_nfct(skb)) 723 if (skb_nfct(skb))
725 nf_conntrack_put(skb_nfct(skb)); 724 nf_conntrack_put(skb_nfct(skb));
726 nf_conntrack_get(&tmpl->ct_general); 725 nf_conntrack_get(&tmpl->ct_general);
727 skb->nfct = &tmpl->ct_general; 726 nf_ct_set(skb, tmpl, IP_CT_NEW);
728 skb->nfctinfo = IP_CT_NEW;
729 } 727 }
730 728
731 err = nf_conntrack_in(net, info->family, 729 err = nf_conntrack_in(net, info->family,