* [PATCH] tcp: add server ip to encrypt cookie in fast open
@ 2013-08-08 21:06 Yuchung Cheng
2013-08-08 21:52 ` Eric Dumazet
2013-08-09 0:48 ` Neal Cardwell
0 siblings, 2 replies; 5+ messages in thread
From: Yuchung Cheng @ 2013-08-08 21:06 UTC (permalink / raw)
To: davem, ncardwell, edumazet; +Cc: netdev, Yuchung Cheng
Encrypt the cookie with both server and client IPv4 addresses,
such that multi-homed server will grant different cookies
based on both the source and destination IPs. No client change
is needed since cookie is opaque to the client.
Signed-off-by: Yuchung Cheng <ycheng@google.com>
---
include/net/tcp.h | 3 ++-
net/ipv4/tcp_fastopen.c | 13 ++++++-------
net/ipv4/tcp_ipv4.c | 10 +++++++---
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/include/net/tcp.h b/include/net/tcp.h
index 27b652f..09cb5c1 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1300,7 +1300,8 @@ void tcp_free_fastopen_req(struct tcp_sock *tp);
extern struct tcp_fastopen_context __rcu *tcp_fastopen_ctx;
int tcp_fastopen_reset_cipher(void *key, unsigned int len);
-void tcp_fastopen_cookie_gen(__be32 addr, struct tcp_fastopen_cookie *foc);
+extern void tcp_fastopen_cookie_gen(__be32 src, __be32 dst,
+ struct tcp_fastopen_cookie *foc);
#define TCP_FASTOPEN_KEY_LENGTH 16
diff --git a/net/ipv4/tcp_fastopen.c b/net/ipv4/tcp_fastopen.c
index 8f7ef0a..ab7bd35 100644
--- a/net/ipv4/tcp_fastopen.c
+++ b/net/ipv4/tcp_fastopen.c
@@ -58,23 +58,22 @@ error: kfree(ctx);
return err;
}
-/* Computes the fastopen cookie for the peer.
- * The peer address is a 128 bits long (pad with zeros for IPv4).
+/* Computes the fastopen cookie for the IP path.
+ * The path is a 128 bits long (pad with zeros for IPv4).
*
* The caller must check foc->len to determine if a valid cookie
* has been generated successfully.
*/
-void tcp_fastopen_cookie_gen(__be32 addr, struct tcp_fastopen_cookie *foc)
+void tcp_fastopen_cookie_gen(__be32 src, __be32 dst,
+ struct tcp_fastopen_cookie *foc)
{
- __be32 peer_addr[4] = { addr, 0, 0, 0 };
+ __be32 path[4] = { src, dst, 0, 0 };
struct tcp_fastopen_context *ctx;
rcu_read_lock();
ctx = rcu_dereference(tcp_fastopen_ctx);
if (ctx) {
- crypto_cipher_encrypt_one(ctx->tfm,
- foc->val,
- (__u8 *)peer_addr);
+ crypto_cipher_encrypt_one(ctx->tfm, foc->val, (__u8 *)path);
foc->len = TCP_FASTOPEN_COOKIE_SIZE;
}
rcu_read_unlock();
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 280efe5..ec27028 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1316,9 +1316,11 @@ static bool tcp_fastopen_check(struct sock *sk, struct sk_buff *skb,
tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
return true;
}
+
if (foc->len == TCP_FASTOPEN_COOKIE_SIZE) {
if ((sysctl_tcp_fastopen & TFO_SERVER_COOKIE_NOT_CHKED) == 0) {
- tcp_fastopen_cookie_gen(ip_hdr(skb)->saddr, valid_foc);
+ tcp_fastopen_cookie_gen(ip_hdr(skb)->saddr,
+ ip_hdr(skb)->daddr, valid_foc);
if ((valid_foc->len != TCP_FASTOPEN_COOKIE_SIZE) ||
memcmp(&foc->val[0], &valid_foc->val[0],
TCP_FASTOPEN_COOKIE_SIZE) != 0)
@@ -1329,14 +1331,16 @@ static bool tcp_fastopen_check(struct sock *sk, struct sk_buff *skb,
tcp_rsk(req)->rcv_nxt = TCP_SKB_CB(skb)->end_seq;
return true;
} else if (foc->len == 0) { /* Client requesting a cookie */
- tcp_fastopen_cookie_gen(ip_hdr(skb)->saddr, valid_foc);
+ tcp_fastopen_cookie_gen(ip_hdr(skb)->saddr,
+ ip_hdr(skb)->daddr, valid_foc);
NET_INC_STATS_BH(sock_net(sk),
LINUX_MIB_TCPFASTOPENCOOKIEREQD);
} else {
/* Client sent a cookie with wrong size. Treat it
* the same as invalid and return a valid one.
*/
- tcp_fastopen_cookie_gen(ip_hdr(skb)->saddr, valid_foc);
+ tcp_fastopen_cookie_gen(ip_hdr(skb)->saddr,
+ ip_hdr(skb)->daddr, valid_foc);
}
return false;
}
--
1.8.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] tcp: add server ip to encrypt cookie in fast open
2013-08-08 21:06 [PATCH] tcp: add server ip to encrypt cookie in fast open Yuchung Cheng
@ 2013-08-08 21:52 ` Eric Dumazet
2013-08-08 22:30 ` Yuchung Cheng
2013-08-09 0:48 ` Neal Cardwell
1 sibling, 1 reply; 5+ messages in thread
From: Eric Dumazet @ 2013-08-08 21:52 UTC (permalink / raw)
To: Yuchung Cheng; +Cc: davem, ncardwell, edumazet, netdev
On Thu, 2013-08-08 at 14:06 -0700, Yuchung Cheng wrote:
> Encrypt the cookie with both server and client IPv4 addresses,
> such that multi-homed server will grant different cookies
> based on both the source and destination IPs. No client change
> is needed since cookie is opaque to the client.
>
> Signed-off-by: Yuchung Cheng <ycheng@google.com>
> ---
> include/net/tcp.h | 3 ++-
> net/ipv4/tcp_fastopen.c | 13 ++++++-------
> net/ipv4/tcp_ipv4.c | 10 +++++++---
> 3 files changed, 15 insertions(+), 11 deletions(-)
Reviewed-by: Eric Dumazet <edumazet@google.com>
I presume this is net-next material ?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tcp: add server ip to encrypt cookie in fast open
2013-08-08 21:52 ` Eric Dumazet
@ 2013-08-08 22:30 ` Yuchung Cheng
0 siblings, 0 replies; 5+ messages in thread
From: Yuchung Cheng @ 2013-08-08 22:30 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David Miller, Neal Cardwell, Eric Dumazet, netdev
On Thu, Aug 8, 2013 at 2:52 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Thu, 2013-08-08 at 14:06 -0700, Yuchung Cheng wrote:
>> Encrypt the cookie with both server and client IPv4 addresses,
>> such that multi-homed server will grant different cookies
>> based on both the source and destination IPs. No client change
>> is needed since cookie is opaque to the client.
>>
>> Signed-off-by: Yuchung Cheng <ycheng@google.com>
>> ---
>> include/net/tcp.h | 3 ++-
>> net/ipv4/tcp_fastopen.c | 13 ++++++-------
>> net/ipv4/tcp_ipv4.c | 10 +++++++---
>> 3 files changed, 15 insertions(+), 11 deletions(-)
>
> Reviewed-by: Eric Dumazet <edumazet@google.com>
>
> I presume this is net-next material ?
yes net-next is what I test on. thanks for pointing that out.
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tcp: add server ip to encrypt cookie in fast open
2013-08-08 21:06 [PATCH] tcp: add server ip to encrypt cookie in fast open Yuchung Cheng
2013-08-08 21:52 ` Eric Dumazet
@ 2013-08-09 0:48 ` Neal Cardwell
2013-08-10 7:45 ` David Miller
1 sibling, 1 reply; 5+ messages in thread
From: Neal Cardwell @ 2013-08-09 0:48 UTC (permalink / raw)
To: Yuchung Cheng; +Cc: David Miller, Eric Dumazet, Netdev
On Thu, Aug 8, 2013 at 5:06 PM, Yuchung Cheng <ycheng@google.com> wrote:
> Encrypt the cookie with both server and client IPv4 addresses,
> such that multi-homed server will grant different cookies
> based on both the source and destination IPs. No client change
> is needed since cookie is opaque to the client.
>
> Signed-off-by: Yuchung Cheng <ycheng@google.com>
> ---
> include/net/tcp.h | 3 ++-
> net/ipv4/tcp_fastopen.c | 13 ++++++-------
> net/ipv4/tcp_ipv4.c | 10 +++++++---
> 3 files changed, 15 insertions(+), 11 deletions(-)
Acked-by: Neal Cardwell <ncardwell@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] tcp: add server ip to encrypt cookie in fast open
2013-08-09 0:48 ` Neal Cardwell
@ 2013-08-10 7:45 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2013-08-10 7:45 UTC (permalink / raw)
To: ncardwell; +Cc: ycheng, edumazet, netdev
From: Neal Cardwell <ncardwell@google.com>
Date: Thu, 8 Aug 2013 20:48:28 -0400
> On Thu, Aug 8, 2013 at 5:06 PM, Yuchung Cheng <ycheng@google.com> wrote:
>> Encrypt the cookie with both server and client IPv4 addresses,
>> such that multi-homed server will grant different cookies
>> based on both the source and destination IPs. No client change
>> is needed since cookie is opaque to the client.
>>
>> Signed-off-by: Yuchung Cheng <ycheng@google.com>
>> ---
>> include/net/tcp.h | 3 ++-
>> net/ipv4/tcp_fastopen.c | 13 ++++++-------
>> net/ipv4/tcp_ipv4.c | 10 +++++++---
>> 3 files changed, 15 insertions(+), 11 deletions(-)
>
> Acked-by: Neal Cardwell <ncardwell@google.com>
Applied to net-next, thanks everyone.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-08-10 7:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-08 21:06 [PATCH] tcp: add server ip to encrypt cookie in fast open Yuchung Cheng
2013-08-08 21:52 ` Eric Dumazet
2013-08-08 22:30 ` Yuchung Cheng
2013-08-09 0:48 ` Neal Cardwell
2013-08-10 7:45 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox