ipv4: call __ip_options_echo() in cookie_v4_check()
Subsystems (3)
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.
--- net/ipv4/syncookies.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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 ; }
Signature · 1 line
1.8.3.1
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.
--- 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
@@ -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
@@ -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
@@ -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
Re: [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check()
Quoted 10 lines · Cong Wang
From: Cong Wang <[email protected]>
cookie_v4_check()allocatesip_options_rcuin the same way withtcp_v4_save_options(), we can just make it a helper function.Cc Krzysztof Kolasa <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by Cong Wang <[email protected]>---
Re: [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check()
In reply to Cong WangFrom: Cong Wang <[email protected]>
Date: Wed, 15 Oct 2014 14:33:21 -0700
Quoted 9 lines
From: Cong Wang <[email protected]>
cookie_v4_check()allocatesip_options_rcuin the same way withtcp_v4_save_options(), we can just make it a helper function.Cc Krzysztof Kolasa <[email protected]>Cc Eric Dumazet <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied.
PATCH 3/3 ipv4: clean up cookie_v4_check()
In reply to Cong WangFrom: 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
@@ -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
@@ -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
@@ -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
Re: [Patch net 3/3] ipv4: clean up cookie_v4_check()
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.
Cc Krzysztof Kolasa <[email protected]>Cc Eric Dumazet <[email protected]>Tested-by Krzysztof Kolasa <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by Cong Wang <[email protected]>---
Re: [Patch net 3/3] ipv4: clean up cookie_v4_check()
In reply to Cong WangFrom: 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.
Cc Krzysztof Kolasa <[email protected]>Cc Eric Dumazet <[email protected]>Tested-by Krzysztof Kolasa <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied.
Quoted 23 lines · Cong Wang
From: Cong Wang <[email protected]>
commit
971f10eca186cab238c49da("tcp: betterTCP_SKB_CBlayout to reduce cache line misses") missed thatcookie_v4_check()still callsip_options_echo()which usesIPCB(). It should useTCPCB()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]>Reported-by Krzysztof Kolasa <[email protected]>Tested-by Krzysztof Kolasa <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by Cong Wang <[email protected]>--- net/ipv4/syncookies.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/ipv4/syncookies.c +0
-0
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 ; }
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: betterTCP_SKB_CBlayout to reduce cache line misses") missed thatcookie_v4_check()still callsip_options_echo()which usesIPCB(). It should useTCPCB()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]>Reported-by Krzysztof Kolasa <[email protected]>Tested-by Krzysztof Kolasa <[email protected]>Signed-off-by Cong Wang <[email protected]>Signed-off-by Cong Wang <[email protected]>
Applied.