* [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check()
2014-10-15 21:33 [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check() Cong Wang
@ 2014-10-15 21:33 ` Cong Wang
2014-10-16 4:16 ` Eric Dumazet
2014-10-17 16:18 ` David Miller
2014-10-15 21:33 ` [Patch net 3/3] ipv4: clean up cookie_v4_check() Cong Wang
` (2 subsequent siblings)
3 siblings, 2 replies; 9+ messages in thread
From: Cong Wang @ 2014-10-15 21:33 UTC (permalink / raw)
To: netdev; +Cc: davem, Cong Wang, Krzysztof Kolasa, Eric Dumazet, Cong Wang
From: Cong Wang <cwang@twopensource.com>
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 <kkolasa@winsoft.pl>
Cc: Eric Dumazet <edumazet@google.com>
Signed-off-by: Cong Wang <cwang@twopensource.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
include/net/tcp.h | 20 ++++++++++++++++++++
net/ipv4/syncookies.c | 10 +---------
net/ipv4/tcp_ipv4.c | 20 --------------------
3 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 74efeda..869637a 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -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 */
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 7e7401c..c68d0a1 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -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);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 552e87e..6a2a7d6 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -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
--
1.8.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check()
2014-10-15 21:33 ` [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check() Cong Wang
@ 2014-10-16 4:16 ` Eric Dumazet
2014-10-17 16:18 ` David Miller
1 sibling, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2014-10-16 4:16 UTC (permalink / raw)
To: Cong Wang; +Cc: netdev, davem, Krzysztof Kolasa, Eric Dumazet, Cong Wang
On Wed, 2014-10-15 at 14:33 -0700, Cong Wang wrote:
> From: Cong Wang <cwang@twopensource.com>
>
> 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 <kkolasa@winsoft.pl>
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
Acked-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check()
2014-10-15 21:33 ` [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check() Cong Wang
2014-10-16 4:16 ` Eric Dumazet
@ 2014-10-17 16:18 ` David Miller
1 sibling, 0 replies; 9+ messages in thread
From: David Miller @ 2014-10-17 16:18 UTC (permalink / raw)
To: xiyou.wangcong; +Cc: netdev, kkolasa, edumazet, cwang
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 15 Oct 2014 14:33:21 -0700
> From: Cong Wang <cwang@twopensource.com>
>
> 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 <kkolasa@winsoft.pl>
> Cc: Eric Dumazet <edumazet@google.com>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Patch net 3/3] ipv4: clean up cookie_v4_check()
2014-10-15 21:33 [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check() Cong Wang
2014-10-15 21:33 ` [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check() Cong Wang
@ 2014-10-15 21:33 ` Cong Wang
2014-10-16 4:17 ` Eric Dumazet
2014-10-17 16:18 ` David Miller
2014-10-16 4:15 ` [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check() Eric Dumazet
2014-10-17 16:18 ` David Miller
3 siblings, 2 replies; 9+ messages in thread
From: Cong Wang @ 2014-10-15 21:33 UTC (permalink / raw)
To: netdev; +Cc: davem, Cong Wang, Krzysztof Kolasa, Eric Dumazet, Cong Wang
From: Cong Wang <cwang@twopensource.com>
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 <kkolasa@winsoft.pl>
Cc: Eric Dumazet <edumazet@google.com>
Tested-by: Krzysztof Kolasa <kkolasa@winsoft.pl>
Signed-off-by: Cong Wang <cwang@twopensource.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
include/net/tcp.h | 5 ++---
net/ipv4/syncookies.c | 6 +++---
net/ipv4/tcp_ipv4.c | 2 +-
3 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 869637a..3a4bbbf 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -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);
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index c68d0a1..d346303 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -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);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 6a2a7d6..94d1a77 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -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;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [Patch net 3/3] ipv4: clean up cookie_v4_check()
2014-10-15 21:33 ` [Patch net 3/3] ipv4: clean up cookie_v4_check() Cong Wang
@ 2014-10-16 4:17 ` Eric Dumazet
2014-10-17 16:18 ` David Miller
1 sibling, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2014-10-16 4:17 UTC (permalink / raw)
To: Cong Wang; +Cc: netdev, davem, Krzysztof Kolasa, Eric Dumazet, Cong Wang
On Wed, 2014-10-15 at 14:33 -0700, Cong Wang wrote:
> From: Cong Wang <cwang@twopensource.com>
>
> 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 <kkolasa@winsoft.pl>
> Cc: Eric Dumazet <edumazet@google.com>
> Tested-by: Krzysztof Kolasa <kkolasa@winsoft.pl>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
Acked-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch net 3/3] ipv4: clean up cookie_v4_check()
2014-10-15 21:33 ` [Patch net 3/3] ipv4: clean up cookie_v4_check() Cong Wang
2014-10-16 4:17 ` Eric Dumazet
@ 2014-10-17 16:18 ` David Miller
1 sibling, 0 replies; 9+ messages in thread
From: David Miller @ 2014-10-17 16:18 UTC (permalink / raw)
To: xiyou.wangcong; +Cc: netdev, kkolasa, edumazet, cwang
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 15 Oct 2014 14:33:22 -0700
> From: Cong Wang <cwang@twopensource.com>
>
> 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 <kkolasa@winsoft.pl>
> Cc: Eric Dumazet <edumazet@google.com>
> Tested-by: Krzysztof Kolasa <kkolasa@winsoft.pl>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check()
2014-10-15 21:33 [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check() Cong Wang
2014-10-15 21:33 ` [Patch net 2/3] ipv4: share tcp_v4_save_options() with cookie_v4_check() Cong Wang
2014-10-15 21:33 ` [Patch net 3/3] ipv4: clean up cookie_v4_check() Cong Wang
@ 2014-10-16 4:15 ` Eric Dumazet
2014-10-17 16:18 ` David Miller
3 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2014-10-16 4:15 UTC (permalink / raw)
To: Cong Wang; +Cc: netdev, davem, Krzysztof Kolasa, Eric Dumazet, Cong Wang
On Wed, 2014-10-15 at 14:33 -0700, Cong Wang wrote:
> From: Cong Wang <cwang@twopensource.com>
>
> 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 <kkolasa@winsoft.pl>
> Cc: Eric Dumazet <edumazet@google.com>
> Reported-by: Krzysztof Kolasa <kkolasa@winsoft.pl>
> Tested-by: Krzysztof Kolasa <kkolasa@winsoft.pl>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> ---
> net/ipv4/syncookies.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
> index 0431a8f..7e7401c 100644
> --- a/net/ipv4/syncookies.c
> +++ b/net/ipv4/syncookies.c
> @@ -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;
> }
Signed-off-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check()
2014-10-15 21:33 [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check() Cong Wang
` (2 preceding siblings ...)
2014-10-16 4:15 ` [Patch net 1/3] ipv4: call __ip_options_echo() in cookie_v4_check() Eric Dumazet
@ 2014-10-17 16:18 ` David Miller
3 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2014-10-17 16:18 UTC (permalink / raw)
To: xiyou.wangcong; +Cc: netdev, kkolasa, edumazet, cwang
From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 15 Oct 2014 14:33:20 -0700
> From: Cong Wang <cwang@twopensource.com>
>
> 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 <kkolasa@winsoft.pl>
> Cc: Eric Dumazet <edumazet@google.com>
> Reported-by: Krzysztof Kolasa <kkolasa@winsoft.pl>
> Tested-by: Krzysztof Kolasa <kkolasa@winsoft.pl>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Applied.
^ permalink raw reply [flat|nested] 9+ messages in thread