mptcp: syn cookie support
Subsystems (4)
Florian Westphal
RFC PATCH 1/11 mptcp: syn cookie support
Hi, this is the initial round of patches to add syn cookie support to mptcp.
Last patch extends the self-test to enable cookie mode in one of the network namespaces.
Patch #10 contains a very ugly cast, see 'XXX' in commit message for details.
The first two patches are not related to syncookie support, I can submit them independently.
JOIN support uses idea presented by Christoph, i.e. the request socket is added to the listen sk even in cookie mode (possibly moving socket past the syn backlog limit).
For this, extra accounting is added to the parent socket. In case the parent already has too many connections (including half-open ones), cookie mode is used instead (which won't work for a join request -- this will trigger tcp fallback + reset when ack comes back).
Comments welcome.
Florian Westphal
RFC PATCH 1/11 mptcp: move helper to where its used
Only used in token.c.
--- net/mptcp/protocol.h | 11 ----------- net/mptcp/token.c | 12 ++++++++++++ 2 files changed, 12 insertions(+), 11 deletions(-)
net/mptcp/protocol.h +0 -11
@@ -398,17 +398,6 @@ struct mptcp_sock *mptcp_token_iter_next(const struct net *net, long *s_slot,void mptcp_token_destroy (struct mptcp_sock *msk);void mptcp_crypto_key_sha (u64 key,u32 *token,u64 *idsn); -static inline void mptcp_crypto_key_gen_sha (u64 *key,u32 *token,u64 *idsn) -{ -/* we might consider a faster version that computes the key as a -* hash of some information available in the MPTCP socket. Use -* random data at the moment, as it's probably the safest option -* in case multiple sockets are opened in different namespaces at -* the same time. -*/ -get_random_bytes (key,sizeof (u64)); -mptcp_crypto_key_sha (*key, token, idsn); -}void mptcp_crypto_hmac_sha (u64 key1,u64 key2,u8 *msg,int len,void *hmac);
net/mptcp/token.c +12 -0
@@ -83,6 +83,18 @@ static bool __token_bucket_busy(struct token_bucket *t, u32 token)__token_lookup_req (t, token) ||__token_lookup_msk (t, token); } +static void mptcp_crypto_key_gen_sha (u64 *key,u32 *token,u64 *idsn) +{ +/* we might consider a faster version that computes the key as a +* hash of some information available in the MPTCP socket. Use +* random data at the moment, as it's probably the safest option +* in case multiple sockets are opened in different namespaces at +* the same time. +*/ +get_random_bytes (key,sizeof (u64)); +mptcp_crypto_key_sha (*key, token, idsn); +} +/** * mptcp_token_new_request - create new key/idsn/token for subflow_request * @req: the request socket
Signature · 1 line
2.26.2
Florian Westphal
RFC PATCH 2/11 tcp: remove cookie_ts bit from request_sock
In reply to Florian WestphalNo need for this anymore; nowadays output function has a 'synack_type' that tells us when the syn/ack is emitted via syncookies. The request already tells us when timestamps are supported, so we can check both to detect when we need the special timestamp for tcp option encoding.
--- include/net/request_sock.h | 3 +-- net/ipv4/tcp_input.c | 2 -- net/ipv4/tcp_output.c | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-)
include/net/request_sock.h +1 -2
@@ -54,8 +54,7 @@ struct request_sock {struct request_sock *dl_next;u16 mss;u8 num_retrans;/* number of retransmits */ - u8 cookie_ts:1; /* syncookie: encode tcpopts in timestamp */ - u8 num_timeout:7; /* number of timeouts */ +u8 num_timeout;/* number of timeouts */ u32 ts_recent;struct timer_list rsk_timer;const struct request_sock_ops *rsk_ops;
net/ipv4/tcp_input.c +0 -2
@@ -6510,7 +6510,6 @@ static void tcp_openreq_init(struct request_sock *req,struct inet_request_sock *ireq =inet_rsk (req); req->rsk_rcv_wnd =0 ;/* So that tcp_send_synack() knows! */ - req->cookie_ts =0 ;tcp_rsk (req)->rcv_isn =TCP_SKB_CB (skb)->seq;tcp_rsk (req)->rcv_nxt =TCP_SKB_CB (skb)->seq +1 ;tcp_rsk (req)->snt_synack =0 ;
@@ -6730,7 +6729,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,if (want_cookie) { isn =cookie_init_sequence (af_ops, sk, skb, &req->mss); - req->cookie_ts = tmp_opt.tstamp_ok;if (!tmp_opt.tstamp_ok)inet_rsk (req)->ecn_ok =0 ; }
net/ipv4/tcp_output.c +1 -1
@@ -3388,7 +3388,7 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,memset (&opts,0 ,sizeof (opts)); now =tcp_clock_ns ();#ifdef CONFIG_SYN_COOKIES -if (unlikely (req->cookie_ts)) +if (unlikely (synack_type ==TCP_SYNACK_COOKIE &&inet_rsk (req)->tstamp_ok)) skb->skb_mstamp_ns =cookie_init_timestamp (req, now); else#endif
Signature · 1 line
2.26.2
Christoph Paasch
[MPTCP] Re: [PATCH RFC 02/11] tcp: remove cookie_ts bit from request_sock
Hello,
Quoted 18 lines · Florian Westphal
No need for this anymore; nowadays output function has a '
synack_type' that tells us when the syn/ack is emitted via syncookies. The request already tells us when timestamps are supported, so we can check both to detect when we need the special timestamp for tcp option encoding.Signed-off-by Florian Westphal <fw(a)strlen.de>--- include/net/request_sock.h | 3 +-- net/ipv4/tcp_input.c | 2 -- net/ipv4/tcp_output.c | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-)include/net/request_sock.h +0
-0
include/net/request_sock.h struct request_sock { · line 57
Quoted 4 lines
include/net/request_sock.h +0
-1@@ -54,8 +54,7 @@ struct request_sock {struct request_sock *dl_next;u16 mss;u8 num_retrans;/* number of retransmits */ - u8 cookie_ts:1; /* syncookie: encode tcpopts in timestamp */
just a minor nit:
drivers/crypto/chelsio/chtls/chtls_cm.c is writing to that field as well - so you need to remove that there as well.
Christoph
Quoted 43 lines
include/net/request_sock.h +1
-1- u8 num_timeout:7; /* number of timeouts */ +u8 num_timeout;/* number of timeouts */ u32 ts_recent;struct timer_list rsk_timer;const struct request_sock_ops *rsk_ops;net/ipv4/tcp_input.c +0
-2@@ -6510,7 +6510,6 @@ static void tcp_openreq_init(struct request_sock *req,struct inet_request_sock *ireq =inet_rsk (req); req->rsk_rcv_wnd =0 ;/* So that tcp_send_synack() knows! */ - req->cookie_ts =0 ;tcp_rsk (req)->rcv_isn =TCP_SKB_CB (skb)->seq;tcp_rsk (req)->rcv_nxt =TCP_SKB_CB (skb)->seq +1 ;tcp_rsk (req)->snt_synack =0 ;@@ -6730,7 +6729,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,if (want_cookie) { isn =cookie_init_sequence (af_ops, sk, skb, &req->mss); - req->cookie_ts = tmp_opt.tstamp_ok;if (!tmp_opt.tstamp_ok)inet_rsk (req)->ecn_ok =0 ; }net/ipv4/tcp_output.c +1
-1@@ -3388,7 +3388,7 @@ struct sk_buff *tcp_make_synack(const struct sock *sk, struct dst_entry *dst,memset (&opts,0 ,sizeof (opts)); now =tcp_clock_ns ();#ifdef CONFIG_SYN_COOKIES -if (unlikely (req->cookie_ts)) +if (unlikely (synack_type ==TCP_SYNACK_COOKIE &&inet_rsk (req)->tstamp_ok)) skb->skb_mstamp_ns =cookie_init_timestamp (req, now); else#endif Signature · 4 lines
2.26.2 _______________________________________________ mptcp mailing list -- mptcp(a)lists.01.org To unsubscribe send an email to mptcp-leave(a)lists.01.org
Florian Westphal
RFC PATCH 3/11 tcp: syncookies: use single reqsk_free location
In reply to Florian Westphaladd a common error label and use it.
Followup patch would need to add a 3rd 'if (err) { free(x); goto out;} pattern, this will allow use of 'if (err) goto free'.
--- net/ipv4/syncookies.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
net/ipv4/syncookies.c +10 -9
@@ -363,10 +363,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)*/ RCU_INIT_POINTER (ireq->ireq_opt,tcp_v4_save_options (sock_net (sk), skb)); -if (security_inet_conn_request (sk, skb, req)) { -reqsk_free (req); - goto out; - } +if (security_inet_conn_request (sk, skb, req)) + goto out_free; req->num_retrans =0 ;
@@ -383,10 +381,8 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) ireq->ir_loc_addr, th->source, th->dest, sk->sk_uid);security_req_classify_flow (req,flowi4_to_flowi (&fl4)); rt =ip_route_output_key (sock_net (sk), &fl4); -if (IS_ERR (rt)) { -reqsk_free (req); - goto out; - } +if (IS_ERR (rt)) + goto out_free;/* Try to redo what tcp_v4_send_synack did. */ req->rsk_window_clamp = tp->window_clamp ? :dst_metric (&rt->dst,RTAX_WINDOW );
@@ -405,5 +401,10 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)*/ if (ret)inet_sk (ret)->cork.fl.u.ip4 = fl4; -out:return ret; +return ret; + +out_free: +reqsk_free (req); +out: +return ret; }
Signature · 1 line
2.26.2
Florian Westphal
RFC PATCH 4/11 mptcp: token: move retry to caller
In reply to Florian WestphalOnce syncookie support is added, no state will be stored anymore when the syn/ack is generated in syncookie mode.
When the ACK comes back, the generated key will be taken from the TCP ack, the token is re-generated and inserted into the token tree.
This means we can't retry with a new key when the token is already taken in the syncookie case.
Therefore, move the retry logic to the caller to prepare for syncookie support in mptcp.
--- net/mptcp/subflow.c | 9 ++++++++- net/mptcp/token.c | 12 ++++-------- 2 files changed, 12 insertions(+), 9 deletions(-)
net/mptcp/subflow.c +8 -1
@@ -126,11 +126,18 @@ static void subflow_init_req(struct request_sock *req, }if (mp_opt.mp_capable && listener->request_mptcp) { -int err; +int err, retries =4 ; + +again: +do { +get_random_bytes (&subflow_req->local_key,sizeof (subflow_req->local_key)); + }while (subflow_req->local_key ==0 ); err =mptcp_token_new_request (req);if (err ==0 ) subflow_req->mp_capable =1 ; +else if (retries-- >0 ) + goto again; subflow_req->ssn_offset =TCP_SKB_CB (skb)->seq; }else if (mp_opt.mp_join && listener->request_mptcp) {
net/mptcp/token.c +4 -8
@@ -109,14 +109,12 @@ static void mptcp_crypto_key_gen_sha(u64 *key, u32 *token, u64 *idsn)int mptcp_token_new_request (struct request_sock *req) {struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req); -int retries =TOKEN_MAX_RETRIES ;struct token_bucket *bucket;u32 token; -again: -mptcp_crypto_key_gen_sha (&subflow_req->local_key, - &subflow_req->token, - &subflow_req->idsn); +mptcp_crypto_key_sha (subflow_req->local_key, + &subflow_req->token, + &subflow_req->idsn);pr_debug ("req=%p local_key=%llu, token=%u, idsn=%llu\n" , req, subflow_req->local_key, subflow_req->token, subflow_req->idsn);
@@ -126,9 +124,7 @@ int mptcp_token_new_request(struct request_sock *req)spin_lock_bh (&bucket->lock);if (__token_bucket_busy (bucket, token)) {spin_unlock_bh (&bucket->lock); -if (!--retries) -return -EBUSY ; - goto again; +return -EBUSY ; }hlist_nulls_add_head_rcu (&subflow_req->token_node, &bucket->req_chain);
Signature · 1 line
2.26.2
Florian Westphal
RFC PATCH 5/11 mptcp: subflow: split subflow_init_req into helpers
In reply to Florian WestphalWhen syncookie support is added, we will need to add a variant of subflow_init_req() helper. It will do almost same thing except that it will not compute/add a token to the mptcp token tree.
To avoid excess copy&paste, this commit splits away part of the code into helpers that can then be re-used from the 'no insert' function added in a followup change.
--- net/mptcp/subflow.c | 49 ++++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 14 deletions(-)
net/mptcp/subflow.c +35 -14
@@ -91,17 +91,9 @@ static struct mptcp_sock *subflow_token_join_request(struct request_sock *req,return msk; } -static void subflow_init_req (struct request_sock *req, -const struct sock *sk_listener, -struct sk_buff *skb) +static int __subflow_init_req (struct request_sock *req,const struct sock *sk_listener) { -struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk_listener);struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req); -struct mptcp_options_received mp_opt; - -pr_debug ("subflow_req=%p, listener=%p" , subflow_req, listener); - -mptcp_get_options (skb, &mp_opt); subflow_req->mp_capable =0 ; subflow_req->mp_join =0 ;
@@ -113,18 +105,47 @@ static void subflow_init_req(struct request_sock *req,* TCP option space. */ if (rcu_access_pointer (tcp_sk (sk_listener)->md5sig_info)) -return ; +return -EINVAL ;#endif -if (mp_opt.mp_capable) { +return 0 ; +} + +static int __subflow_check_options (const struct mptcp_options_received *mp_opt, +struct request_sock *req) +{ +if (mp_opt->mp_capable) {SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_MPCAPABLEPASSIVE ); -if (mp_opt.mp_join) -return ; - }else if (mp_opt.mp_join) { +if (mp_opt->mp_join) +return -EINVAL ; + }else if (mp_opt->mp_join) {SUBFLOW_REQ_INC_STATS (req,MPTCP_MIB_JOINSYNRX ); } +return 0 ; +} + +static void subflow_init_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb) +{ +struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk_listener); +struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req); +struct mptcp_options_received mp_opt; +int ret; + +pr_debug ("subflow_req=%p, listener=%p" , subflow_req, listener); + + ret =__subflow_init_req (req, sk_listener); +if (ret) +return ; + +mptcp_get_options (skb, &mp_opt); + ret =__subflow_check_options (&mp_opt, req); +if (ret) +return ; +if (mp_opt.mp_capable && listener->request_mptcp) {int err, retries =4 ;
Signature · 1 line
2.26.2
Florian Westphal
RFC PATCH 6/11 mptcp: rename and export mptcp_subflow_request_sock_ops
In reply to Florian Westphalsyncookie code path needs to create an mptcp request sock. Prepare for this by adding mptcp prefix and making the ops struct available.
--- include/net/mptcp.h | 1 + net/mptcp/subflow.c | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-)
include/net/mptcp.h +1 -0
@@ -58,6 +58,7 @@ struct mptcp_out_options { };#ifdef CONFIG_MPTCP +extern struct request_sock_ops mptcp_subflow_request_sock_ops;void mptcp_init (void );
net/mptcp/subflow.c +5 -5
@@ -293,7 +293,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)tcp_done (sk); } -static struct request_sock_ops subflow_request_sock_ops; +struct request_sock_ops mptcp_subflow_request_sock_ops;static struct tcp_request_sock_ops subflow_request_sock_ipv4_ops;static int subflow_v4_conn_request (struct sock *sk,struct sk_buff *skb)
@@ -306,7 +306,7 @@ static int subflow_v4_conn_request(struct sock *sk, struct sk_buff *skb)if (skb_rtable (skb)->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST )) goto drop; -return tcp_conn_request (&subflow_request_sock_ops, +return tcp_conn_request (&mptcp_subflow_request_sock_ops, &subflow_request_sock_ipv4_ops, sk, skb); drop:
@@ -331,7 +331,7 @@ static int subflow_v6_conn_request(struct sock *sk, struct sk_buff *skb)if (!ipv6_unicast_destination (skb)) goto drop; -return tcp_conn_request (&subflow_request_sock_ops, +return tcp_conn_request (&mptcp_subflow_request_sock_ops, &subflow_request_sock_ipv6_ops, sk, skb); drop:
@@ -1311,8 +1311,8 @@ static int subflow_ops_init(struct request_sock_ops *subflow_ops)void __init mptcp_subflow_init (void ) { - subflow_request_sock_ops = tcp_request_sock_ops; -if (subflow_ops_init (&subflow_request_sock_ops) !=0 ) + mptcp_subflow_request_sock_ops = tcp_request_sock_ops; +if (subflow_ops_init (&mptcp_subflow_request_sock_ops) !=0 )panic ("MPTCP: failed to init subflow request sock ops\n" ); subflow_request_sock_ipv4_ops = tcp_request_sock_ipv4_ops;
Signature · 1 line
2.26.2
Florian Westphal
RFC PATCH 7/11 mptcp: subflow: add mptcp_subflow_init_cookie_req helper
In reply to Florian WestphalWill be used to initialize the mptcp request socket when a MP_CAPABLE request was handled in syncookie mode, i.e. when a TCP ACK containing a MP_CAPABLE option is a valid syncookie value.
--- include/linux/tcp.h | 1 + include/net/mptcp.h | 10 +++++++++ net/mptcp/subflow.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+)
include/linux/tcp.h +1 -0
@@ -118,6 +118,7 @@ struct tcp_request_sock {struct inet_request_sock req;const struct tcp_request_sock_ops *af_specific;u64 snt_synack;/* first SYNACK sent time */ + u8 syncookie:1;bool tfo_listener;bool is_mptcp;#if IS_ENABLED (CONFIG_MPTCP )
include/net/mptcp.h +10 -0
@@ -131,6 +131,9 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, }void mptcp_seq_show (struct seq_file *seq); +int mptcp_subflow_init_cookie_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb);#else static inline void mptcp_init (void )
@@ -204,6 +207,13 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,static inline void mptcp_space (const struct sock *ssk,int *s,int *fs) { }static inline void mptcp_seq_show (struct seq_file *seq) { } + +static inline int mptcp_subflow_init_cookie_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb) +{ +return 0 ;/* TCP fallback */ +}#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )
net/mptcp/subflow.c +53 -0
65 lines not on this page · raw message
Signature · 1 line
2.26.2
Christoph Paasch
[MPTCP] Re: [PATCH RFC 07/11] mptcp: subflow: add mptcp_subflow_init_cookie_req helper
Quoted 16 lines · Florian Westphal
Will be used to initialize the mptcp request socket when a
MP_CAPABLErequest was handled in syncookie mode, i.e. when a TCP ACK containing aMP_CAPABLEoption is a valid syncookie value.Signed-off-by Florian Westphal <fw(a)strlen.de>--- include/linux/tcp.h | 1 + include/net/mptcp.h | 10 +++++++++ net/mptcp/subflow.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+)include/linux/tcp.h +0
-0
include/linux/tcp.h struct tcp_request_sock { · line 121
Quoted 4 lines
include/linux/tcp.h +1
-0@@ -118,6 +118,7 @@ struct tcp_request_sock {struct inet_request_sock req;const struct tcp_request_sock_ops *af_specific;u64 snt_synack;/* first SYNACK sent time */ + u8 syncookie:1;
As this field will only be used in init_req, would it make sense to rather pass want_cookie from tcp_conn_request as an argument to the callback?
Christoph
Quoted 107 lines
include/linux/tcp.h +0
-0bool tfo_listener;bool is_mptcp;#if IS_ENABLED (CONFIG_MPTCP )include/net/mptcp.h +10
-0@@ -131,6 +131,9 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, }void mptcp_seq_show (struct seq_file *seq); +int mptcp_subflow_init_cookie_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb);#else static inline void mptcp_init (void )@@ -204,6 +207,13 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,static inline void mptcp_space (const struct sock *ssk,int *s,int *fs) { }static inline void mptcp_seq_show (struct seq_file *seq) { } + +static inline int mptcp_subflow_init_cookie_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb) +{ +return 0 ;/* TCP fallback */ +}#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )net/mptcp/subflow.c +53
-0@@ -154,6 +154,20 @@ static void subflow_init_req(struct request_sock *req,get_random_bytes (&subflow_req->local_key,sizeof (subflow_req->local_key)); }while (subflow_req->local_key ==0 ); +if (unlikely (tcp_rsk (req)->syncookie)) { +mptcp_crypto_key_sha (subflow_req->local_key, + &subflow_req->token, + &subflow_req->idsn); +if (mptcp_token_get_sock (subflow_req->token)) { +if (retries-- >0 ) + goto again; + }else { + subflow_req->mp_capable =1 ; + } + subflow_req->ssn_offset =TCP_SKB_CB (skb)->seq; +return ; + } + err =mptcp_token_new_request (req);if (err ==0 ) subflow_req->mp_capable =1 ;@@ -174,6 +188,45 @@ static void subflow_init_req(struct request_sock *req, } } +int mptcp_subflow_init_cookie_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb) +{ +struct mptcp_subflow_context *listener =mptcp_subflow_ctx (sk_listener); +struct mptcp_subflow_request_sock *subflow_req =mptcp_subflow_rsk (req); +struct mptcp_options_received mp_opt; +int ret; + + ret =__subflow_init_req (req, sk_listener); +if (ret) +return ret; + +mptcp_get_options (skb, &mp_opt); + ret =__subflow_check_options (&mp_opt, req); +if (ret) +return ret; + +if (mp_opt.mp_capable && listener->request_mptcp) { +int err; + +if (mp_opt.sndr_key ==0 ) +return -EINVAL ; + + subflow_req->local_key = mp_opt.rcvr_key; + err =mptcp_token_new_request (req); +if (err) +return err; + + subflow_req->mp_capable =1 ; + subflow_req->ssn_offset =TCP_SKB_CB (skb)->seq -1 ; + } +/* JOIN cannot be handled via cookies due to need +* to store the remote peer nonce value. +*/ + +return 0 ; +} +static void subflow_v4_init_req (struct request_sock *req,const struct sock *sk_listener,struct sk_buff *skb)Signature · 4 lines
2.26.2 _______________________________________________ mptcp mailing list -- mptcp(a)lists.01.org To unsubscribe send an email to mptcp-leave(a)lists.01.org
Paolo Abeni
[MPTCP] Re: [PATCH RFC 07/11] mptcp: subflow: add mptcp_subflow_init_cookie_req helper
Quoted 12 lines · Christoph Paasch
Quoted 11 lines · Florian Westphal
Will be used to initialize the mptcp request socket when a
MP_CAPABLErequest was handled in syncookie mode, i.e. when a TCP ACK containing aMP_CAPABLEoption is a valid syncookie value.Signed-off-by Florian Westphal <fw(a)strlen.de>--- include/linux/tcp.h | 1 + include/net/mptcp.h | 10 +++++++++ net/mptcp/subflow.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+)
Quoted 12 lines
include/linux/tcp.h struct tcp_request_sock { · line 121
Quoted 9 lines
include/linux/tcp.h +1
-0@@ -118,6 +118,7 @@ struct tcp_request_sock {struct inet_request_sock req;const struct tcp_request_sock_ops *af_specific;u64 snt_synack;/* first SYNACK sent time */ + u8 syncookie:1;As this field will only be used in
init_req, would it make sense to rather passwant_cookiefromtcp_conn_requestas an argument to the callback?
Otherwise, why don't a 'bool' instead?
I think it would be nice nothing in the commmit message that this new field fill a pre-existing one byte hole.
Quoted 43 lines
Christoph
Quoted 39 lines
include/linux/tcp.h +0
-0bool tfo_listener;bool is_mptcp;#if IS_ENABLED (CONFIG_MPTCP )include/net/mptcp.h +10
-0@@ -131,6 +131,9 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to, }void mptcp_seq_show (struct seq_file *seq); +int mptcp_subflow_init_cookie_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb);#else static inline void mptcp_init (void )@@ -204,6 +207,13 @@ static inline bool mptcp_skb_can_collapse(const struct sk_buff *to,static inline void mptcp_space (const struct sock *ssk,int *s,int *fs) { }static inline void mptcp_seq_show (struct seq_file *seq) { } + +static inline int mptcp_subflow_init_cookie_req (struct request_sock *req, +const struct sock *sk_listener, +struct sk_buff *skb) +{ +return 0 ;/* TCP fallback */ +}#endif /* CONFIG_MPTCP */ #if IS_ENABLED (CONFIG_MPTCP_IPV6 )net/mptcp/subflow.c +0
-0@@ -154,6 +154,20 @@ static void subflow_init_req(struct request_sock *req,get_random_bytes (&subflow_req->local_key,sizeof (subflow_req->local_key)); }while (subflow_req->local_key ==0 );
Quoted 5 lines
net/mptcp/subflow.c static void subflow_init_req(struct request_sock *req, · line 161
Quoted 5 lines
net/mptcp/subflow.c +5
-0+if (unlikely (tcp_rsk (req)->syncookie)) { +mptcp_crypto_key_sha (subflow_req->local_key, + &subflow_req->token, + &subflow_req->idsn); +if (mptcp_token_get_sock (subflow_req->token)) {
Don't we need to sock_put() the returned sock here? Perhpas we can use a new, different helper that just check for existance, without touching the sock refcount? Looks like the sock reference is not used below.
Thanks!
Paolo
Florian Westphal
RFC PATCH 8/11 tcp: syncookies: keep mptcp option enabled
In reply to Florian WestphalIf SYN packet contains MP_CAPABLE option, keep it enabled. The mptcp relevant code is changed to detect the new 'sycookie' flag in the request socket. If it is set, the socket isn't inserted into the token tree. This will only be done when the cookie ACK comes back.
--- net/ipv4/syncookies.c | 21 +++++++++++++++++---- net/ipv4/tcp_input.c | 4 +--- net/ipv6/syncookies.c | 17 ++++++++++++++--- 3 files changed, 32 insertions(+), 10 deletions(-)
net/ipv4/syncookies.c +17 -4
@@ -289,6 +289,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk);const struct tcphdr *th =tcp_hdr (skb);__u32 cookie =ntohl (th->ack_seq) -1 ; +const struct request_sock_ops *ops;struct sock *ret = sk;struct request_sock *req;int mss;
@@ -326,12 +327,27 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) goto out; ret =NULL ; - req =inet_reqsk_alloc (&tcp_request_sock_ops, sk, false);/* for safety */ + ops = &tcp_request_sock_ops; +#ifdef CONFIG_MPTCP +if (sk_is_mptcp (sk)) + ops = &mptcp_subflow_request_sock_ops; +#endif + + req =inet_reqsk_alloc (ops, sk, false);/* for safety */ if (!req) goto out; ireq =inet_rsk (req); treq =tcp_rsk (req); + treq->is_mptcp =sk_is_mptcp (sk); + +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + } + treq->rcv_isn =ntohl (th->seq) -1 ; treq->snt_isn = cookie; treq->ts_off =0 ;
@@ -350,9 +366,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) treq->snt_synack =0 ; treq->tfo_listener = false; -if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; -if (IS_ENABLED (CONFIG_SMC )) ireq->smc_ok =0 ;
net/ipv4/tcp_input.c +1 -3
@@ -6669,6 +6669,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,#if IS_ENABLED (CONFIG_MPTCP )tcp_rsk (req)->is_mptcp =0 ;#endif +tcp_rsk (req)->syncookie = want_cookie;tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp = af_ops->mss_clamp;
@@ -6691,9 +6692,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->init_req (req, sk, skb); -if (IS_ENABLED (CONFIG_MPTCP ) && want_cookie) -tcp_rsk (req)->is_mptcp =0 ; -if (security_inet_conn_request (sk, skb, req)) goto drop_and_free;
net/ipv6/syncookies.c +14 -3
@@ -134,6 +134,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk);const struct tcphdr *th =tcp_hdr (skb);__u32 cookie =ntohl (th->ack_seq) -1 ; +const struct request_sock_ops *ops;struct sock *ret = sk;struct request_sock *req;int mss;
@@ -170,7 +171,13 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) goto out; ret =NULL ; - req =inet_reqsk_alloc (&tcp6_request_sock_ops, sk, false); + ops = &tcp6_request_sock_ops; +#ifdef CONFIG_MPTCP +if (sk_is_mptcp (sk)) + ops = &mptcp_subflow_request_sock_ops; +#endif + + req =inet_reqsk_alloc (ops, sk, false);if (!req) goto out;
@@ -178,8 +185,12 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) treq =tcp_rsk (req); treq->tfo_listener = false; -if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + }if (security_inet_conn_request (sk, skb, req)) goto out_free;
Signature · 1 line
2.26.2
Paolo Abeni
[MPTCP] Re: [PATCH RFC 08/11] tcp: syncookies: keep mptcp option enabled
Quoted 114 lines · Florian Westphal
If SYN packet contains
MP_CAPABLEoption, keep it enabled. The mptcp relevant code is changed to detect the new 'sycookie' flag in the request socket. If it is set, the socket isn't inserted into the token tree. This will only be done when the cookie ACK comes back.Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/ipv4/syncookies.c | 21 +++++++++++++++++---- net/ipv4/tcp_input.c | 4 +--- net/ipv6/syncookies.c | 17 ++++++++++++++--- 3 files changed, 32 insertions(+), 10 deletions(-)net/ipv4/syncookies.c +17
-4@@ -289,6 +289,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk);const struct tcphdr *th =tcp_hdr (skb);__u32 cookie =ntohl (th->ack_seq) -1 ; +const struct request_sock_ops *ops;struct sock *ret = sk;struct request_sock *req;int mss;@@ -326,12 +327,27 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) goto out; ret =NULL ; - req =inet_reqsk_alloc (&tcp_request_sock_ops, sk, false);/* for safety */ + ops = &tcp_request_sock_ops; +#ifdef CONFIG_MPTCP +if (sk_is_mptcp (sk)) + ops = &mptcp_subflow_request_sock_ops; +#endif + + req =inet_reqsk_alloc (ops, sk, false);/* for safety */ if (!req) goto out; ireq =inet_rsk (req); treq =tcp_rsk (req); + treq->is_mptcp =sk_is_mptcp (sk); + +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + } + treq->rcv_isn =ntohl (th->seq) -1 ; treq->snt_isn = cookie; treq->ts_off =0 ;@@ -350,9 +366,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) treq->snt_synack =0 ; treq->tfo_listener = false; -if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; -if (IS_ENABLED (CONFIG_SMC )) ireq->smc_ok =0 ;net/ipv4/tcp_input.c +1
-3@@ -6669,6 +6669,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,#if IS_ENABLED (CONFIG_MPTCP )tcp_rsk (req)->is_mptcp =0 ;#endif +tcp_rsk (req)->syncookie = want_cookie;tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp = af_ops->mss_clamp;@@ -6691,9 +6692,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->init_req (req, sk, skb); -if (IS_ENABLED (CONFIG_MPTCP ) && want_cookie) -tcp_rsk (req)->is_mptcp =0 ; -if (security_inet_conn_request (sk, skb, req)) goto drop_and_free;net/ipv6/syncookies.c +8
-1@@ -134,6 +134,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk);const struct tcphdr *th =tcp_hdr (skb);__u32 cookie =ntohl (th->ack_seq) -1 ; +const struct request_sock_ops *ops;struct sock *ret = sk;struct request_sock *req;int mss;@@ -170,7 +171,13 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) goto out; ret =NULL ; - req =inet_reqsk_alloc (&tcp6_request_sock_ops, sk, false); + ops = &tcp6_request_sock_ops; +#ifdef CONFIG_MPTCP +if (sk_is_mptcp (sk)) + ops = &mptcp_subflow_request_sock_ops; +#endif + + req =inet_reqsk_alloc (ops, sk, false);if (!req) goto out;@@ -178,8 +185,12 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) treq =tcp_rsk (req);
net/ipv6/syncookies.c struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · line 193
Quoted 10 lines
net/ipv6/syncookies.c +6
-2treq->tfo_listener = false; -if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + }
It looks like 'treq->is_mptcp' is not initialized here ?
What about moving the whole oops selection, init_reqsk_alloc() call, is_mptcp init and mptcp_subflow_init_cookie_req() call in an header only helper? (say tcp_reqsk_alloc() or the like)
Thanks,
Paolo
Christoph Paasch
[MPTCP] Re: [PATCH RFC 08/11] tcp: syncookies: keep mptcp option enabled
Quoted 117 lines · Paolo Abeni
Quoted 116 lines · Florian Westphal
If SYN packet contains
MP_CAPABLEoption, keep it enabled. The mptcp relevant code is changed to detect the new 'sycookie' flag in the request socket. If it is set, the socket isn't inserted into the token tree. This will only be done when the cookie ACK comes back.Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/ipv4/syncookies.c | 21 +++++++++++++++++---- net/ipv4/tcp_input.c | 4 +--- net/ipv6/syncookies.c | 17 ++++++++++++++--- 3 files changed, 32 insertions(+), 10 deletions(-)net/ipv4/syncookies.c +17
-4@@ -289,6 +289,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk);const struct tcphdr *th =tcp_hdr (skb);__u32 cookie =ntohl (th->ack_seq) -1 ; +const struct request_sock_ops *ops;struct sock *ret = sk;struct request_sock *req;int mss;@@ -326,12 +327,27 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) goto out; ret =NULL ; - req =inet_reqsk_alloc (&tcp_request_sock_ops, sk, false);/* for safety */ + ops = &tcp_request_sock_ops; +#ifdef CONFIG_MPTCP +if (sk_is_mptcp (sk)) + ops = &mptcp_subflow_request_sock_ops; +#endif + + req =inet_reqsk_alloc (ops, sk, false);/* for safety */ if (!req) goto out; ireq =inet_rsk (req); treq =tcp_rsk (req); + treq->is_mptcp =sk_is_mptcp (sk); + +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + } + treq->rcv_isn =ntohl (th->seq) -1 ; treq->snt_isn = cookie; treq->ts_off =0 ;@@ -350,9 +366,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb) treq->snt_synack =0 ; treq->tfo_listener = false; -if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; -if (IS_ENABLED (CONFIG_SMC )) ireq->smc_ok =0 ;net/ipv4/tcp_input.c +1
-3@@ -6669,6 +6669,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,#if IS_ENABLED (CONFIG_MPTCP )tcp_rsk (req)->is_mptcp =0 ;#endif +tcp_rsk (req)->syncookie = want_cookie;tcp_clear_options (&tmp_opt); tmp_opt.mss_clamp = af_ops->mss_clamp;@@ -6691,9 +6692,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->init_req (req, sk, skb); -if (IS_ENABLED (CONFIG_MPTCP ) && want_cookie) -tcp_rsk (req)->is_mptcp =0 ; -if (security_inet_conn_request (sk, skb, req)) goto drop_and_free;net/ipv6/syncookies.c +8
-1@@ -134,6 +134,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)struct tcp_sock *tp =tcp_sk (sk);const struct tcphdr *th =tcp_hdr (skb);__u32 cookie =ntohl (th->ack_seq) -1 ; +const struct request_sock_ops *ops;struct sock *ret = sk;struct request_sock *req;int mss;@@ -170,7 +171,13 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) goto out; ret =NULL ; - req =inet_reqsk_alloc (&tcp6_request_sock_ops, sk, false); + ops = &tcp6_request_sock_ops; +#ifdef CONFIG_MPTCP +if (sk_is_mptcp (sk)) + ops = &mptcp_subflow_request_sock_ops; +#endif + + req =inet_reqsk_alloc (ops, sk, false);if (!req) goto out;@@ -178,8 +185,12 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) treq =tcp_rsk (req); treq->tfo_listener = false;
Quoted 10 lines
net/ipv6/syncookies.c struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · line 193
Quoted 8 lines
net/ipv6/syncookies.c +6
-2-if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + }It looks like '
treq->is_mptcp' is not initialized here ?
Yep, I just hit a "KASAN: slab-out-of-bounds in __subflow_init_req" due to that.
Christoph
Quoted 11 lines
What about moving the whole oops selection,
init_reqsk_alloc()call,is_mptcpinit andmptcp_subflow_init_cookie_req()call in an header only helper? (saytcp_reqsk_alloc()or the like)Thanks,
Paolo
_______________________________________________
mptcp mailing list -- mptcp(a)lists.01.org
To unsubscribe send an email to mptcp-leave(a)lists.01.org
Florian Westphal
[MPTCP] Re: [PATCH RFC 08/11] tcp: syncookies: keep mptcp option enabled
In reply to Paolo AbeniQuoted 13 lines · Paolo Abeni
net/ipv6/syncookies.c struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · line 193
Quoted 11 lines
net/ipv6/syncookies.c +6
-2treq =tcp_rsk (req); treq->tfo_listener = false; -if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + }It looks like '
treq->is_mptcp' is not initialized here ?
Yes, this is resolved now.
Quoted 3 lines
What about moving the whole oops selection,
init_reqsk_alloc()call,is_mptcpinit andmptcp_subflow_init_cookie_req()call in an header only helper? (saytcp_reqsk_alloc()or the like)
ipv6 uses tcp6_request_sock_ops, so they are not 100% the same, unfortunately.
What did you have in mind?
Paolo Abeni
[MPTCP] Re: [PATCH RFC 08/11] tcp: syncookies: keep mptcp option enabled
Quoted 17 lines · Florian Westphal
Quoted 13 lines · Paolo Abeni
net/ipv6/syncookies.c struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb) · line 193
Quoted 11 lines
net/ipv6/syncookies.c +6
-2treq =tcp_rsk (req); treq->tfo_listener = false; -if (IS_ENABLED (CONFIG_MPTCP )) - treq->is_mptcp =0 ; +if (treq->is_mptcp) { +int err =mptcp_subflow_init_cookie_req (req, sk, skb); + +if (err) + goto out_free; + }It looks like '
treq->is_mptcp' is not initialized here ?Yes, this is resolved now.
Quoted 8 lines
Quoted 3 lines
What about moving the whole oops selection,
init_reqsk_alloc()call,is_mptcpinit andmptcp_subflow_init_cookie_req()call in an header only helper? (saytcp_reqsk_alloc()or the like)ipv6 uses
tcp6_request_sock_ops, so they are not 100% the same, unfortunately.What did you have in mind?
Something alike the following (untested):
struct request_sock *tcp_reqsk_alloc(const struct request_sock_ops *ops,
struct sock *sk)
{
struct tcp_request_sock *treq;
struct request_sock * req;#ifdef CONFIG_MPTCP
if (sk_is_mptcp(sk))
ops = &mptcp_subflow_request_sock_ops;
#endif
req = inet_reqsk_alloc(ops, sk, false);
if (!req)
return req;
treq = tcp_rsk(req);
treq->is_mptcp = sk_is_mptcp(sk);
if (treq->is_mptcp &&
mptcp_subflow_init_cookie_req(req, sk, skb)) {
reqsk_free(req);
return NULL;
}
return req;
}than ipv4 may call tcp_reqsk_alloc(tcp_request_sock_ops, sk) and ipv6 tcp_reqsk_alloc(tcp6_request_sock_ops, sk). That could possibly remove the need for patch "tcp: syncookies: use single reqsk_free location"
Not sure if I missed something more...
Cheers,
Paolo
Florian Westphal
RFC PATCH 9/11 tcp: handle want_cookie clause via reqsk_put
In reply to Florian WestphalThis will allow the syn_recv_sock callback to keep the request socket around even when syncookies are used.
This will be needed to make MPTCP JOIN requests work in cookie mode.
When a JOIN request is received, we cannot use cookies because we need to remember the peers nonce value for HMAC validation.
Next patch will handle the cookie+join case by allowing the rsk to stay around provided:
1. We can find a valid mptcp socket for the 32bit token provided by the join and
2. the found mptcp socket doesn't exceed the maximum number of subflows.
To handle 2) the request socket will not only be accounted with the listener but also with the mptcp (parent) socket.
--- net/ipv4/tcp_input.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/ipv4/tcp_input.c +2 -5
@@ -6690,6 +6690,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,/* Note: tcp_v6_init_req() might override ir_iif for link locals */ inet_rsk (req)->ir_iif =inet_request_bound_dev_if (sk, skb); +refcount_set (&req->rsk_refcnt,1 ); af_ops->init_req (req, sk, skb);if (security_inet_conn_request (sk, skb, req))
@@ -6760,10 +6761,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->send_synack (sk, dst, &fl, req, &foc, !want_cookie ?TCP_SYNACK_NORMAL :TCP_SYNACK_COOKIE ); -if (want_cookie) { -reqsk_free (req); -return 0 ; - } }reqsk_put (req);return 0 ;
@@ -6771,7 +6768,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, drop_and_release:dst_release (dst); drop_and_free: -__reqsk_free (req); +reqsk_put (req); drop:tcp_listendrop (sk);return 0 ;
Signature · 1 line
2.26.2
Paolo Abeni
[MPTCP] Re: [PATCH RFC 09/11] tcp: handle want_cookie clause via reqsk_put
Quoted 28 lines · Florian Westphal
This will allow the
syn_recv_sockcallback to keep the request socket around even when syncookies are used.This will be needed to make MPTCP JOIN requests work in cookie mode.
When a JOIN request is received, we cannot use cookies because we need to remember the peers nonce value for HMAC validation.
Next patch will handle the cookie+join case by allowing the rsk to stay around provided:
1. We can find a valid mptcp socket for the 32bit token provided by the join and
2. the found mptcp socket doesn't exceed the maximum number of subflows.To handle 2) the request socket will not only be accounted with the listener but also with the mptcp (parent) socket.
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/ipv4/tcp_input.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)net/ipv4/tcp_input.c +0
-0
net/ipv4/tcp_input.c int tcp_conn_request(struct request_sock_ops *rsk_ops, · line 6693
Quoted 4 lines
net/ipv4/tcp_input.c +1
-0@@ -6690,6 +6690,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,/* Note: tcp_v6_init_req() might override ir_iif for link locals */ inet_rsk (req)->ir_iif =inet_request_bound_dev_if (sk, skb); +refcount_set (&req->rsk_refcnt,1 );
I could not find easily where sk_refcnt is increment/how is handled currently/before this patch. Can you please give some pointers?
net/ipv4/tcp_input.c int tcp_conn_request(struct request_sock_ops *rsk_ops, · line 6765
Quoted 13 lines
net/ipv4/tcp_input.c +0
-4af_ops->init_req (req, sk, skb);if (security_inet_conn_request (sk, skb, req))@@ -6760,10 +6761,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->send_synack (sk, dst, &fl, req, &foc, !want_cookie ?TCP_SYNACK_NORMAL :TCP_SYNACK_COOKIE ); -if (want_cookie) { -reqsk_free (req); -return 0 ; - } }reqsk_put (req);
This means all syn cookied req (even plain TCP ones, even on non MPTCP build) will get an additional atomic decrement, correct?
I fear the overhead could be measurable - even if the testbed is not trivial at all!
What if we avoid touching this code path, and instead store a - very limited, possibly only 1 - number of hmacs into the msk?
syn-cookied mp_join will store the hmac there. If the store is full, the mp_join subflow fails -> reset.
WDYT?
Thanks!
Paolo
Florian Westphal
[MPTCP] Re: [PATCH RFC 09/11] tcp: handle want_cookie clause via reqsk_put
Quoted 32 lines · Paolo Abeni
Quoted 31 lines · Florian Westphal
This will allow the
syn_recv_sockcallback to keep the request socket around even when syncookies are used.This will be needed to make MPTCP JOIN requests work in cookie mode.
When a JOIN request is received, we cannot use cookies because we need to remember the peers nonce value for HMAC validation.
Next patch will handle the cookie+join case by allowing the rsk to stay around provided:
1. We can find a valid mptcp socket for the 32bit token provided by the join and
2. the found mptcp socket doesn't exceed the maximum number of subflows.To handle 2) the request socket will not only be accounted with the listener but also with the mptcp (parent) socket.
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/ipv4/tcp_input.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)net/ipv4/tcp_input.c +0
-0@@ -6690,6 +6690,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,/* Note: tcp_v6_init_req() might override ir_iif for link locals */ inet_rsk (req)->ir_iif =inet_request_bound_dev_if (sk, skb);
Quoted 4 lines
net/ipv4/tcp_input.c int tcp_conn_request(struct request_sock_ops *rsk_ops, · line 6693
Quoted 1 line
net/ipv4/tcp_input.c +1
-0+refcount_set (&req->rsk_refcnt,1 );I could not find easily where
sk_refcntis increment/how is handled currently/before this patch. Can you please give some pointers?
Its 0 and set to 3 on insert via reqsk_queue_hash_req().
Quoted 16 lines
net/ipv4/tcp_input.c int tcp_conn_request(struct request_sock_ops *rsk_ops, · line 6765
Quoted 13 lines
net/ipv4/tcp_input.c +0
-4af_ops->init_req (req, sk, skb);if (security_inet_conn_request (sk, skb, req))@@ -6760,10 +6761,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->send_synack (sk, dst, &fl, req, &foc, !want_cookie ?TCP_SYNACK_NORMAL :TCP_SYNACK_COOKIE ); -if (want_cookie) { -reqsk_free (req); -return 0 ; - } }reqsk_put (req);This means all syn cookied req (even plain TCP ones, even on non MPTCP build) will get an additional atomic decrement, correct?
Yes.
Quoted 2 lines
I fear the overhead could be measurable - even if the testbed is not trivial at all!
The alternative is to allow ->init_req to say 'I do want the req to be inserted anyway', e.g. via a bit in req.
Quoted 2 lines
What if we avoid touching this code path, and instead store a - very limited, possibly only 1 - number of hmacs into the msk?
Would need to duplicate timeout logic and so on which I wanted to avoid.
But yes, thats another alternative.
Paolo Abeni
[MPTCP] Re: [PATCH RFC 09/11] tcp: handle want_cookie clause via reqsk_put
Quoted 62 lines · Florian Westphal
Quoted 32 lines · Paolo Abeni
Quoted 31 lines · Florian Westphal
This will allow the
syn_recv_sockcallback to keep the request socket around even when syncookies are used.This will be needed to make MPTCP JOIN requests work in cookie mode.
When a JOIN request is received, we cannot use cookies because we need to remember the peers nonce value for HMAC validation.
Next patch will handle the cookie+join case by allowing the rsk to stay around provided:
1. We can find a valid mptcp socket for the 32bit token provided by the join and
2. the found mptcp socket doesn't exceed the maximum number of subflows.To handle 2) the request socket will not only be accounted with the listener but also with the mptcp (parent) socket.
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/ipv4/tcp_input.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)net/ipv4/tcp_input.c +0
-0@@ -6690,6 +6690,7 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops,/* Note: tcp_v6_init_req() might override ir_iif for link locals */ inet_rsk (req)->ir_iif =inet_request_bound_dev_if (sk, skb);Quoted 4 lines
net/ipv4/tcp_input.c int tcp_conn_request(struct request_sock_ops *rsk_ops, · line 6693
Quoted 1 line
net/ipv4/tcp_input.c +1
-0+refcount_set (&req->rsk_refcnt,1 );I could not find easily where
sk_refcntis increment/how is handled currently/before this patch. Can you please give some pointers?Its 0 and set to 3 on insert via
reqsk_queue_hash_req().Quoted 16 lines
net/ipv4/tcp_input.c int tcp_conn_request(struct request_sock_ops *rsk_ops, · line 6765
Quoted 13 lines
net/ipv4/tcp_input.c +0
-4af_ops->init_req (req, sk, skb);if (security_inet_conn_request (sk, skb, req))@@ -6760,10 +6761,6 @@ int tcp_conn_request(struct request_sock_ops *rsk_ops, af_ops->send_synack (sk, dst, &fl, req, &foc, !want_cookie ?TCP_SYNACK_NORMAL :TCP_SYNACK_COOKIE ); -if (want_cookie) { -reqsk_free (req); -return 0 ; - } }reqsk_put (req);This means all syn cookied req (even plain TCP ones, even on non MPTCP build) will get an additional atomic decrement, correct?
Yes.
Quoted 2 lines
I fear the overhead could be measurable - even if the testbed is not trivial at all!
Quoted 8 lines
The alternative is to allow ->init_req to say 'I do want the req to be inserted anyway', e.g. via a bit in req.
Quoted 2 lines
What if we avoid touching this code path, and instead store a - very limited, possibly only 1 - number of hmacs into the msk?
Would need to duplicate timeout logic and so on which I wanted to avoid.
Yep that would be quite complex. I was wondering about something simpler, like using with LRU policy a static 4 slots circular buffer inside the msk (the one identified by the token). WDYT?
/P
Florian Westphal
[MPTCP] Re: [PATCH RFC 09/11] tcp: handle want_cookie clause via reqsk_put
Quoted 7 lines · Paolo Abeni
Quoted 2 lines · Florian Westphal
Would need to duplicate timeout logic and so on which I wanted to avoid.
Yep that would be quite complex. I was wondering about something simpler, like using with LRU policy a static 4 slots circular buffer inside the msk (the one identified by the token). WDYT?
But where do I get the token to find the msk from the cookie ack? Its not re-sent in the options afaics, unlike mp_capable case.
Paolo Abeni
[MPTCP] Re: [PATCH RFC 09/11] tcp: handle want_cookie clause via reqsk_put
Quoted 11 lines · Florian Westphal
Quoted 7 lines · Paolo Abeni
Quoted 2 lines · Florian Westphal
Would need to duplicate timeout logic and so on which I wanted to avoid.
Yep that would be quite complex. I was wondering about something simpler, like using with LRU policy a static 4 slots circular buffer inside the msk (the one identified by the token). WDYT?
But where do I get the token to find the msk from the cookie ack? Its not re-sent in the options afaics, unlike
mp_capablecase.
uhm... wasting even more memory we could store in each slot hmac and token (24 bytes per slot)
MPJ ACK with syncookie we could lookup the slot by hmac.
Not sure about the security implications.
Sounds too overkill?
/P
Florian Westphal
RFC PATCH 10/11 mptcp: enable JOIN requests even if cookies are in use
In reply to Florian WestphalJOIN requests do not work in syncookie mode -- for HMAC validation, the remote peers nonce is required, but this nonce is only present in the SYN.
This makes the subflow request initialisation to store the request socket even when syncookies are used.
Following restrictions apply:
1. The (32bit) token contained in the MP_JOIN SYN packet returns a valid parent connection.
2. The parent connection can accept one more subflow.
To ensure 2), all MP_JOIN requests (new incoming and existing) are accounted in the mptcp parent socket.
If the token is invalid or the parent cannot accept a new subflow, no information is stored and TCP fallback path is used.
XXX: subflow_init_req() sk_listener argument has 'const' qualifier, this patch currently uses a 'void *' cast in order to add the rsk to the listener socket.
The parent socket can't be used without further changes in TCP stack, because socket creation after 3whs completion checks that the associated socket is in LISTEN state.
--- net/mptcp/pm_netlink.c | 2 +- net/mptcp/protocol.h | 2 ++ net/mptcp/subflow.c | 57 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 4 deletions(-)
net/mptcp/pm_netlink.c +1 -1
@@ -41,7 +41,7 @@ struct pm_nl_pernet {unsigned int next_id; }; -#define MPTCP_PM_ADDR_MAX 8 +#define MPTCP_PM_ADDR_MAX MPTCP_SUBFLOWS_MAXstatic bool addresses_equal (const struct mptcp_addr_info *a,struct mptcp_addr_info *b,bool use_port)
net/mptcp/protocol.h +2 -0
@@ -154,6 +154,8 @@ enum mptcp_pm_status { MPTCP_PM_SUBFLOW_ESTABLISHED, }; +#define MPTCP_SUBFLOWS_MAX 8 +struct mptcp_pm_data {struct mptcp_addr_info local;struct mptcp_addr_info remote;
net/mptcp/subflow.c +54 -3
81 lines not on this page · raw message
Signature · 1 line
2.26.2
Paolo Abeni
[MPTCP] Re: [PATCH RFC 10/11] mptcp: enable JOIN requests even if cookies are in use
Quoted 68 lines · Florian Westphal
JOIN requests do not work in syncookie mode -- for HMAC validation, the remote peers nonce is required, but this nonce is only present in the SYN.
This makes the subflow request initialisation to store the request socket even when syncookies are used.
Following restrictions apply:
1. The (32bit) token contained in theMP_JOINSYN packet returns a valid parent connection.
2. The parent connection can accept one more subflow.To ensure 2), all
MP_JOINrequests (new incoming and existing) are accounted in the mptcp parent socket.If the token is invalid or the parent cannot accept a new subflow, no information is stored and TCP fallback path is used.
XXX:
subflow_init_req()sk_listenerargument has 'const' qualifier, this patch currently uses a 'void *' cast in order to add the rsk to the listener socket.The parent socket can't be used without further changes in TCP stack, because socket creation after 3whs completion checks that the associated socket is in LISTEN state.
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/pm_netlink.c | 2 +- net/mptcp/protocol.h | 2 ++ net/mptcp/subflow.c | 57 +++++++++++++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 4 deletions(-)net/mptcp/pm_netlink.c +1
-1@@ -41,7 +41,7 @@ struct pm_nl_pernet {unsigned int next_id; }; -#define MPTCP_PM_ADDR_MAX 8 +#define MPTCP_PM_ADDR_MAX MPTCP_SUBFLOWS_MAXstatic bool addresses_equal (const struct mptcp_addr_info *a,struct mptcp_addr_info *b,bool use_port)net/mptcp/protocol.h +2
-0@@ -154,6 +154,8 @@ enum mptcp_pm_status { MPTCP_PM_SUBFLOW_ESTABLISHED, }; +#define MPTCP_SUBFLOWS_MAX 8 +struct mptcp_pm_data {struct mptcp_addr_info local;struct mptcp_addr_info remote;net/mptcp/subflow.c +1
-0@@ -126,6 +126,46 @@ static int __subflow_check_options(const struct mptcp_options_received *mp_opt,return 0 ; } +static bool mptcp_join_store (struct mptcp_subflow_request_sock *req,struct sock *sk_listener)
net/mptcp/subflow.c static int __subflow_check_options(const struct mptcp_options_received *mp_opt, · line 139
Quoted 10 lines
net/mptcp/subflow.c +10
-0+{ +struct mptcp_sock *msk = req->msk; +struct inet_connection_sock *icsk; +struct sock *sk; + + icsk = &msk->sk; + sk = &icsk->icsk_inet.sk; + +if (inet_csk_reqsk_queue_len (sk) >=MPTCP_SUBFLOWS_MAX ) +return false;
Isn't this test a little too relaxed? e.g. shouldn't we check something alike:
if (inet_csk_reqsk_queue_len(sk) + READ_ONCE(pm->subflows) > READ_ONCE(pm->subflows_max))
Possibly we can account the pending MP_JOIN subflows in a new PM field, so we could do the above check and the follow-up increment in a consistent way with a single atomic opetation (the pm spinlock)
/P
Florian Westphal
[MPTCP] Re: [PATCH RFC 10/11] mptcp: enable JOIN requests even if cookies are in use
Quoted 15 lines · Paolo Abeni
net/mptcp/subflow.c static int __subflow_check_options(const struct mptcp_options_received *mp_opt, · line 139
Quoted 11 lines
net/mptcp/subflow.c +11
-0+static bool mptcp_join_store (struct mptcp_subflow_request_sock *req,struct sock *sk_listener) +{ +struct mptcp_sock *msk = req->msk; +struct inet_connection_sock *icsk; +struct sock *sk; + + icsk = &msk->sk; + sk = &icsk->icsk_inet.sk; + +if (inet_csk_reqsk_queue_len (sk) >=MPTCP_SUBFLOWS_MAX ) +return false;Isn't this test a little too relaxed? e.g. shouldn't we check something alike:
Quoted 6 lines
if (inet_csk_reqsk_queue_len(sk) + READ_ONCE(pm->subflows) > READ_ONCE(pm->subflows_max))Possibly we can account the pending
MP_JOINsubflows in a new PM field, so we could do the above check and the follow-up increment in a consistent way with a single atomic opetation (the pm spinlock)
Not following here -- inet_csk_reqsk_queue_len() is supposed to return the number of all subflows, both established and half-open.
Why would I need to add pm->subflows?
Paolo Abeni
[MPTCP] Re: [PATCH RFC 10/11] mptcp: enable JOIN requests even if cookies are in use
Quoted 19 lines · Florian Westphal
Quoted 18 lines · Paolo Abeni
net/mptcp/subflow.c static int __subflow_check_options(const struct mptcp_options_received *mp_opt, · line 139
Quoted 11 lines
net/mptcp/subflow.c +11
-0+static bool mptcp_join_store (struct mptcp_subflow_request_sock *req,struct sock *sk_listener) +{ +struct mptcp_sock *msk = req->msk; +struct inet_connection_sock *icsk; +struct sock *sk; + + icsk = &msk->sk; + sk = &icsk->icsk_inet.sk; + +if (inet_csk_reqsk_queue_len (sk) >=MPTCP_SUBFLOWS_MAX ) +return false;Isn't this test a little too relaxed? e.g. shouldn't we check something alike:
if (inet_csk_reqsk_queue_len(sk) + READ_ONCE(pm->subflows) > READ_ONCE(pm->subflows_max))
Quoted 8 lines
Quoted 3 lines
Possibly we can account the pending
MP_JOINsubflows in a new PM field, so we could do the above check and the follow-up increment in a consistent way with a single atomic opetation (the pm spinlock)Not following here --
inet_csk_reqsk_queue_len()is supposed to return the number of all subflows, both established and half-open.Why would I need to add
pm->subflows?
Currently the PM netlink does not accept any additional subflows when pm->subflows >= pm->subflows_max.
To be reasonable sure the pending syncookied mp_joins will be accepted, I think we should check that the currently created subflows plus the pending ones will not exceed the maximum allowed.
Not sure if the above clarify my thinking in any way, please let me know!
Cheers,
Paolo
Florian Westphal
[MPTCP] Re: [PATCH RFC 10/11] mptcp: enable JOIN requests even if cookies are in use
Quoted 24 lines · Paolo Abeni
Quoted 23 lines · Florian Westphal
Quoted 21 lines · Paolo Abeni
net/mptcp/subflow.c static int __subflow_check_options(const struct mptcp_options_received *mp_opt, · line 139
Quoted 11 lines
net/mptcp/subflow.c +11
-0+static bool mptcp_join_store (struct mptcp_subflow_request_sock *req,struct sock *sk_listener) +{ +struct mptcp_sock *msk = req->msk; +struct inet_connection_sock *icsk; +struct sock *sk; + + icsk = &msk->sk; + sk = &icsk->icsk_inet.sk; + +if (inet_csk_reqsk_queue_len (sk) >=MPTCP_SUBFLOWS_MAX ) +return false;Isn't this test a little too relaxed? e.g. shouldn't we check something alike:
if (inet_csk_reqsk_queue_len(sk) + READ_ONCE(pm->subflows) > READ_ONCE(pm->subflows_max))Possibly we can account the pending
MP_JOINsubflows in a new PM field, so we could do the above check and the follow-up increment in a consistent way with a single atomic opetation (the pm spinlock)
Quoted 7 lines
Quoted 4 lines
Not following here --
inet_csk_reqsk_queue_len()is supposed to return the number of all subflows, both established and half-open.Why would I need to add
pm->subflows?Currently the PM netlink does not accept any additional subflows when
pm->subflows>=pm->subflows_max.
You mean:
if (inet_csk_reqsk_queue_len(sk) >= MPTCP_SUBFLOWS_MAX ||
pm->subflows >= pm->subflows_max) return false;
?
(I ommitted R_ONCE for brevity only).
Florian Westphal
[MPTCP] Re: [PATCH RFC 10/11] mptcp: enable JOIN requests even if cookies are in use
In reply to Paolo AbeniQuoted 4 lines · Paolo Abeni
Quoted 1 line
Why would I need to add
pm->subflows?Currently the PM netlink does not accept any additional subflows when
pm->subflows>=pm->subflows_max.
What about mptcp_can_accept_new_subflow() helper? Is that enough?
Florian Westphal
RFC PATCH 11/11 selftests: mptcp: make 2nd net namespace use tcp syn cookies unconditionally
In reply to Florian Westphalcheck we can establish connections even in syncookie mode. Also check following MIB counters:
MPTcpExtMPCapableSYNRX (should increase for each MPTCP test) MPTcpExtMPCapableACKRX (should increase for each MPTCP test) TcpExtSyncookiesSent (should increase for listener in ns2) TcpExtSyncookiesRecv (same)
--- .../selftests/net/mptcp/mptcp_connect.sh | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_connect.sh +50 -0
@@ -196,6 +196,9 @@ ip -net "$ns4" link set ns4eth3 up ip -net "$ns4" route add default via 10.0.3.2 ip -net "$ns4" route add default via dead:beef:3::2 +# use TCP syn cookies, even if no flooding was detected. +ip netns exec "$ns2" sysctl -q net.ipv4.tcp_syncookies=2 + set_ethtool_flags() { local ns="$1" local dev="$2"
@@ -407,6 +410,11 @@ do_transfer() sleep 1 fi + local stat_synrx_last_l=$(ip netns exec ${listener_ns} nstat -z -a MPTcpExtMPCapableSYNRX | while read a count c rest ;do echo $count;done) + local stat_ackrx_last_l=$(ip netns exec ${listener_ns} nstat -z -a MPTcpExtMPCapableACKRX | while read a count c rest ;do echo $count;done) + local stat_cookietx_last=$(ip netns exec ${listener_ns} nstat -z -a TcpExtSyncookiesSent | while read a count c rest ;do echo $count;done) + local stat_cookierx_last=$(ip netns exec ${listener_ns} nstat -z -a TcpExtSyncookiesRecv | while read a count c rest ;do echo $count;done) + ip netns exec ${listener_ns} ./mptcp_connect -t $timeout -l -p $port -s ${srv_proto} $extra_args $local_addr < "$sin" > "$sout" & local spid=$!
@@ -450,6 +458,48 @@ do_transfer() check_transfer $cin $sout "file received by server" rets=$? + local stat_synrx_now_l=$(ip netns exec ${listener_ns} nstat -z -a MPTcpExtMPCapableSYNRX | while read a count c rest ;do echo $count;done) + local stat_ackrx_now_l=$(ip netns exec ${listener_ns} nstat -z -a MPTcpExtMPCapableACKRX | while read a count c rest ;do echo $count;done) + + local stat_cookietx_now=$(ip netns exec ${listener_ns} nstat -z -a TcpExtSyncookiesSent | while read a count c rest ;do echo $count;done) + local stat_cookierx_now=$(ip netns exec ${listener_ns} nstat -z -a TcpExtSyncookiesRecv | while read a count c rest ;do echo $count;done) + + expect_synrx=$((stat_synrx_last_l)) + expect_ackrx=$((stat_ackrx_last_l)) + + cookies=$(ip netns exec ${listener_ns} sysctl net.ipv4.tcp_syncookies) + cookies=${cookies##*=} + + if [ ${cl_proto} = "MPTCP" ] && [ ${srv_proto} = "MPTCP" ]; then + expect_synrx=$((stat_synrx_last_l+1)) + expect_ackrx=$((stat_ackrx_last_l+1)) + if [ $cookies -eq 2 ];then + expect_synrx=$((stat_synrx_last_l+2)) + fi + fi + if [ $cookies -eq 2 ];then + if [ $stat_cookietx_last -ge $stat_cookietx_now ] ;then + echo "${listener_ns} CookieSent: ${cl_proto} -> ${srv_proto}: did not advance" + fi + if [ $stat_cookierx_last -ge $stat_cookierx_now ] ;then + echo "${listener_ns} CookieRecv: ${cl_proto} -> ${srv_proto}: did not advance" + fi + else + if [ $stat_cookietx_last -ne $stat_cookietx_now ] ;then + echo "${listener_ns} CookieSent: ${cl_proto} -> ${srv_proto}: changed" + fi + if [ $stat_cookierx_last -ne $stat_cookierx_now ] ;then + echo "${listener_ns} CookieRecv: ${cl_proto} -> ${srv_proto}: changed" + fi + fi + + if [ $expect_synrx -ne $stat_synrx_now_l ] ;then + echo "${listener_ns} SYNRX: ${cl_proto} -> ${srv_proto}: expect ${expect_synrx}, got ${stat_synrx_now_l}" + fi + if [ $expect_ackrx -ne $stat_ackrx_now_l ] ;then + echo "${listener_ns} ACKRX: ${cl_proto} -> ${srv_proto}: expect ${expect_synrx}, got ${stat_synrx_now_l}" + fi + if [ $retc -eq 0 ] && [ $rets -eq 0 ];then echo "$duration [ OK ]" cat "$capout"
Signature · 1 line
2.26.2