Skip to contentSkip to conversation

ipv4: call __ip_options_echo() in cookie_v4_check()

PATCH Applied Cong Wang 3 participants 9 messages Oct 15, 2014 – Oct 17, 2014

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/3 ipv4: call __ip_options_echo() in cookie_v4_check()

From: Cong Wang <[email protected]>

commit 971f10eca186cab238c49da ("tcp: better TCP_SKB_CB layout to reduce cache line misses") missed that cookie_v4_check() still calls ip_options_echo() which uses IPCB(). It should use TCPCB() at TCP layer, so call __ip_options_echo() instead.

Fixes commit 971f10eca186cab238c49da ("tcp: better TCP_SKB_CB layout to reduce cache line misses")
Cc Krzysztof Kolasa <[email protected]>
Cc Eric Dumazet <[email protected]>
---
 net/ipv4/syncookies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/syncookies.c +1 -1
index 0431a8f..7e7401c 100644
@@ -321,7 +321,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
 		int opt_size = sizeof(struct ip_options_rcu) + opt->optlen;
 
 		ireq->opt = kmalloc(opt_size, GFP_ATOMIC);
-		if (ireq->opt != NULL && ip_options_echo(&ireq->opt->opt, skb)) {
+		if (ireq->opt != NULL && __ip_options_echo(&ireq->opt->opt, skb, opt)) {
 			kfree(ireq->opt);
 			ireq->opt = NULL;
 		}
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 2/3 ipv4: share tcp_v4_save_options() with cookie_v4_check()

From: Cong Wang <[email protected]>

cookie_v4_check() allocates ip_options_rcu in the same way with tcp_v4_save_options(), we can just make it a helper function.

Cc Krzysztof Kolasa <[email protected]>
Cc Eric Dumazet <[email protected]>
---
 include/net/tcp.h     | 20 ++++++++++++++++++++
 net/ipv4/syncookies.c | 10 +---------
 net/ipv4/tcp_ipv4.c   | 20 --------------------
 3 files changed, 21 insertions(+), 29 deletions(-)
include/net/tcp.h +20 -0
index 74efeda..869637a 100644
@@ -1666,4 +1666,24 @@ int tcpv4_offload_init(void);
 void tcp_v4_init(void);
 void tcp_init(void);
 
+/*
+ * Save and compile IPv4 options, return a pointer to it
+ */
+static inline struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb)
+{
+	const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt;
+	struct ip_options_rcu *dopt = NULL;
+
+	if (opt && opt->optlen) {
+		int opt_size = sizeof(*dopt) + opt->optlen;
+
+		dopt = kmalloc(opt_size, GFP_ATOMIC);
+		if (dopt && __ip_options_echo(&dopt->opt, skb, opt)) {
+			kfree(dopt);
+			dopt = NULL;
+		}
+	}
+	return dopt;
+}
+
 #endif	/* _TCP_H */
net/ipv4/syncookies.c +1 -9
index 7e7401c..c68d0a1 100644
@@ -317,15 +317,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
 	/* We throwed the options of the initial SYN away, so we hope
 	 * the ACK carries the same options again (see RFC1122 4.2.3.8)
 	 */
-	if (opt && opt->optlen) {
-		int opt_size = sizeof(struct ip_options_rcu) + opt->optlen;
-
-		ireq->opt = kmalloc(opt_size, GFP_ATOMIC);
-		if (ireq->opt != NULL && __ip_options_echo(&ireq->opt->opt, skb, opt)) {
-			kfree(ireq->opt);
-			ireq->opt = NULL;
-		}
-	}
+	ireq->opt = tcp_v4_save_options(skb);
 
 	if (security_inet_conn_request(sk, skb, req)) {
 		reqsk_free(req);
net/ipv4/tcp_ipv4.c +0 -20
index 552e87e..6a2a7d6 100644
@@ -880,26 +880,6 @@ bool tcp_syn_flood_action(struct sock *sk,
 }
 EXPORT_SYMBOL(tcp_syn_flood_action);
 
-/*
- * Save and compile IPv4 options into the request_sock if needed.
- */
-static struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb)
-{
-	const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt;
-	struct ip_options_rcu *dopt = NULL;
-
-	if (opt && opt->optlen) {
-		int opt_size = sizeof(*dopt) + opt->optlen;
-
-		dopt = kmalloc(opt_size, GFP_ATOMIC);
-		if (dopt && __ip_options_echo(&dopt->opt, skb, opt)) {
-			kfree(dopt);
-			dopt = NULL;
-		}
-	}
-	return dopt;
-}
-
 #ifdef CONFIG_TCP_MD5SIG
 /*
  * RFC2385 MD5 checksumming requires a mapping of
Signature · 1 line
1.8.3.1
author
#4 lore raw

PATCH 3/3 ipv4: clean up cookie_v4_check()

In reply to Cong Wang

From: Cong Wang <[email protected]>

We can retrieve opt from skb, no need to pass it as a parameter. And opt should always be non-NULL, no need to check.

---
 include/net/tcp.h     | 5 ++---
 net/ipv4/syncookies.c | 6 +++---
 net/ipv4/tcp_ipv4.c   | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)
include/net/tcp.h +2 -3
index 869637a..3a4bbbf 100644
@@ -468,8 +468,7 @@ void inet_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb);
 /* From syncookies.c */
 int __cookie_v4_check(const struct iphdr *iph, const struct tcphdr *th,
 		      u32 cookie);
-struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
-			     struct ip_options *opt);
+struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb);
 #ifdef CONFIG_SYN_COOKIES
 
 /* Syncookies use a monotonic timer which increments every 60 seconds.
@@ -1674,7 +1673,7 @@ static inline struct ip_options_rcu *tcp_v4_save_options(struct sk_buff *skb)
 	const struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt;
 	struct ip_options_rcu *dopt = NULL;
 
-	if (opt && opt->optlen) {
+	if (opt->optlen) {
 		int opt_size = sizeof(*dopt) + opt->optlen;
 
 		dopt = kmalloc(opt_size, GFP_ATOMIC);
net/ipv4/syncookies.c +3 -3
index c68d0a1..d346303 100644
@@ -255,9 +255,9 @@ bool cookie_check_timestamp(struct tcp_options_received *tcp_opt,
 }
 EXPORT_SYMBOL(cookie_check_timestamp);
 
-struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
-			     struct ip_options *opt)
+struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)
 {
+	struct ip_options *opt = &TCP_SKB_CB(skb)->header.h4.opt;
 	struct tcp_options_received tcp_opt;
 	struct inet_request_sock *ireq;
 	struct tcp_request_sock *treq;
@@ -336,7 +336,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
 	flowi4_init_output(&fl4, sk->sk_bound_dev_if, ireq->ir_mark,
 			   RT_CONN_FLAGS(sk), RT_SCOPE_UNIVERSE, IPPROTO_TCP,
 			   inet_sk_flowi_flags(sk),
-			   (opt && opt->srr) ? opt->faddr : ireq->ir_rmt_addr,
+			   opt->srr ? opt->faddr : ireq->ir_rmt_addr,
 			   ireq->ir_loc_addr, th->source, th->dest);
 	security_req_classify_flow(req, flowi4_to_flowi(&fl4));
 	rt = ip_route_output_key(sock_net(sk), &fl4);
net/ipv4/tcp_ipv4.c +1 -1
index 6a2a7d6..94d1a77 100644
@@ -1408,7 +1408,7 @@ static struct sock *tcp_v4_hnd_req(struct sock *sk, struct sk_buff *skb)
 
 #ifdef CONFIG_SYN_COOKIES
 	if (!th->syn)
-		sk = cookie_v4_check(sk, skb, &TCP_SKB_CB(skb)->header.h4.opt);
+		sk = cookie_v4_check(sk, skb);
 #endif
 	return sk;
 }
Signature · 1 line
1.8.3.1
#7 lore raw
In reply to Cong Wang
Quoted 23 lines · Cong Wang

From: Cong Wang <[email protected]>

commit 971f10eca186cab238c49da ("tcp: better TCP_SKB_CB layout to reduce cache line misses") missed that cookie_v4_check() still calls ip_options_echo() which uses IPCB(). It should use TCPCB() at TCP layer, so call __ip_options_echo() instead.

Fixes commit 971f10eca186cab238c49da ("tcp: better TCP_SKB_CB layout to reduce cache line misses")
Cc Krzysztof Kolasa <[email protected]>
Cc Eric Dumazet <[email protected]>
---
 net/ipv4/syncookies.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv4/syncookies.c +0 -0
index 0431a8f..7e7401c 100644

net/ipv4/syncookies.c struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb, · line 327

Quoted 8 lines
net/ipv4/syncookies.c +1 -1
@@ -321,7 +321,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
 		int opt_size = sizeof(struct ip_options_rcu) + opt->optlen;
 
 		ireq->opt = kmalloc(opt_size, GFP_ATOMIC);
-		if (ireq->opt != NULL && ip_options_echo(&ireq->opt->opt, skb)) {
+		if (ireq->opt != NULL && __ip_options_echo(&ireq->opt->opt, skb, opt)) {
 			kfree(ireq->opt);
 			ireq->opt = NULL;
 		}
Acked-by on v1 2/3
#2 lore raw

Re: [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check()

In reply to Cong Wang
Quoted 10 lines · Cong Wang

From: Cong Wang <[email protected]>

cookie_v4_check() allocates ip_options_rcu in the same way with tcp_v4_save_options(), we can just make it a helper function.

Cc Krzysztof Kolasa <[email protected]>
Cc Eric Dumazet <[email protected]>

---

Acked-by on v1 3/3
#5 lore raw

Re: [Patch net 3/3] ipv4: clean up cookie_v4_check()

In reply to Cong Wang
Quoted 11 lines · Cong Wang

From: Cong Wang <[email protected]>

We can retrieve opt from skb, no need to pass it as a parameter. And opt should always be non-NULL, no need to check.

---

maintainer Applied
#8 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 15 Oct 2014 14:33:20 -0700

Quoted 7 lines

From: Cong Wang <[email protected]>

commit 971f10eca186cab238c49da ("tcp: better TCP_SKB_CB layout to reduce cache line misses") missed that cookie_v4_check() still calls ip_options_echo() which uses IPCB(). It should use TCPCB() at TCP layer, so call __ip_options_echo() instead.

Quoted 7 lines
Fixes commit 971f10eca186cab238c49da ("tcp: better TCP_SKB_CB layout to reduce cache line misses")
Cc Krzysztof Kolasa <[email protected]>
Cc Eric Dumazet <[email protected]>

Applied.

maintainer Applied
#3 lore raw

Re: [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check()

In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 15 Oct 2014 14:33:21 -0700

Quoted 9 lines

From: Cong Wang <[email protected]>

cookie_v4_check() allocates ip_options_rcu in the same way with tcp_v4_save_options(), we can just make it a helper function.

Cc Krzysztof Kolasa <[email protected]>
Cc Eric Dumazet <[email protected]>

Applied.

maintainer Applied
#6 lore raw

Re: [Patch net 3/3] ipv4: clean up cookie_v4_check()

In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 15 Oct 2014 14:33:22 -0700

Quoted 10 lines

From: Cong Wang <[email protected]>

We can retrieve opt from skb, no need to pass it as a parameter. And opt should always be non-NULL, no need to check.

Applied.