mptcp: refactor token code
Subsystems (2)
Florian Westphal
cover mptcp: refactor token code
This series is intentionally marked RFC so noone bothers to squash all of this into the mptcp tree.
The idea is to first do a review-friendly series, with each change done in an individual patch.
Then, once consensus is reached (maybe over several iterations), I would send a few larger patches suitable for squashing (rather than being review friendly...).
The patches remove unneeded small helpers, add 'mptcp' prefix to non-static functions, add error handling to those that may fail and adds a few comments.
Feedback welcome.
pm.c | 6 protocol.c | 5 protocol.h | 27 +-- subflow.c | 76 ++++++++-- token.c | 447 +++++++++++++++++++++++++++---------------------------------- 5 files changed, 278 insertions(+), 283 deletions(-)
Florian Westphal
RFC PATCH 1/10 mptcp: token: remove token_init
Its not needed, just use the static initialisers.
--- net/mptcp/protocol.c | 1 - net/mptcp/protocol.h | 1 - net/mptcp/token.c | 15 ++++----------- 3 files changed, 4 insertions(+), 13 deletions(-)
net/mptcp/protocol.c +0 -1
@@ -1146,7 +1146,6 @@ void mptcp_proto_init(void) mptcp_stream_ops.listen = mptcp_listen; mptcp_stream_ops.shutdown = mptcp_shutdown; -token_init ();subflow_init ();pm_init ();
net/mptcp/protocol.h +0 -1
@@ -225,7 +225,6 @@ void mptcp_get_options(const struct sk_buff *skb,void mptcp_finish_connect (struct sock *sk,int mp_capable);void mptcp_finish_join (struct sock *sk); -void token_init (void );void token_new_request (struct request_sock *req,const struct sk_buff *skb);int token_join_request (struct request_sock *req,const struct sk_buff *skb);int token_join_response (struct sock *sk);
net/mptcp/token.c +4 -11
@@ -31,10 +31,10 @@#include <net/mptcp.h> #include "protocol.h" -static struct radix_tree_root token_tree; -static struct radix_tree_root token_req_tree; -static spinlock_t token_tree_lock; -static int token_used; +static RADIX_TREE(token_tree, GFP_ATOMIC); +static RADIX_TREE(token_req_tree, GFP_ATOMIC); +static DEFINE_SPINLOCK (token_tree_lock); +static int token_used__read_mostly ;static bool find_req_token (u32 token) {
@@ -392,10 +392,3 @@ void token_destroy(u32 token)sock_put (conn);spin_unlock_bh (&token_tree_lock); } - -void token_init (void ) -{ -INIT_RADIX_TREE (&token_tree,GFP_ATOMIC ); -INIT_RADIX_TREE (&token_req_tree,GFP_ATOMIC ); -spin_lock_init (&token_tree_lock); -}
Signature · 1 line
2.21.0
Florian Westphal
RFC PATCH 2/10 mptcp: token: remove two unneeded helpers
In reply to Florian WestphalThere were three flavours of almost the same function:
token_lookup_get, the base function that takes a token value and looks up the mptcp socket associated with it.
token_new_subflow, same function, but will also set subflow->local_nonce.
token_new_join, just like lookup_get, but assigns the looked-up socket to subflow->conn.
This renames token_lookup_get to mptcp_token_get_sock to avoid make it clear this belongs to mptcp namespace, and then changes the callers of token_new_subflow to also init the nonce and token_new_join to do the assignment in the caller.
--- net/mptcp/pm.c | 6 +++--- net/mptcp/protocol.h | 4 +--- net/mptcp/subflow.c | 16 ++++++++++---- net/mptcp/token.c | 51 +++++++++++--------------------------------- 4 files changed, 29 insertions(+), 48 deletions(-)
net/mptcp/pm.c +3 -3
@@ -33,7 +33,7 @@ static int pm_pernet_id;int pm_announce_addr (u32 token,sa_family_t family,u8 local_id,struct in_addr *addr) { -struct mptcp_sock *msk =mptcp_sk (token_lookup_get (token)); +struct mptcp_sock *msk =mptcp_token_get_sock (token);int err =0 ;if (!msk)
@@ -58,7 +58,7 @@ int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,int pm_remove_addr (u32 token,u8 local_id) { -struct mptcp_sock *msk =mptcp_sk (token_lookup_get (token)); +struct mptcp_sock *msk =mptcp_token_get_sock (token);if (!msk)return -EINVAL ;
@@ -72,7 +72,7 @@ int pm_remove_addr(u32 token, u8 local_id)int pm_create_subflow (u32 token,u8 remote_id) { -struct mptcp_sock *msk =mptcp_sk (token_lookup_get (token)); +struct mptcp_sock *msk =mptcp_token_get_sock (token);struct sockaddr_in remote;struct sockaddr_in local;int err;
net/mptcp/protocol.h +1 -3
@@ -232,11 +232,9 @@ int token_join_valid(struct request_sock *req, struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);void token_new_connect (struct sock *sk); -void token_new_subflow (struct sock *sk);void token_new_accept (struct sock *sk); -int token_new_join (struct sock *sk);void token_update_accept (struct sock *sk,struct sock *conn); -struct sock *token_lookup_get (u32 token); +struct mptcp_sock *mptcp_token_get_sock (u32 token);void token_release (u32 token);void token_destroy (u32 token);
net/mptcp/subflow.c +12 -4
@@ -24,7 +24,11 @@ static int subflow_rebuild_header(struct sock *sk)token_new_connect (sk); }else if (subflow->request_join && !subflow->local_nonce) {pr_debug ("subflow=%p" , sk); -token_new_subflow (sk); +mptcp_token_get_sock (subflow->token); + +do { +get_random_bytes (&subflow->local_nonce,sizeof (u32)); + }while (!subflow->local_nonce); }return inet_sk_rebuild_header (sk);
@@ -179,10 +183,14 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,if (ctx->mp_capable) {token_new_accept (child); }else if (ctx->mp_join) { -if (token_new_join (child)) +struct mptcp_sock *owner; + + owner =mptcp_token_get_sock (ctx->token); +if (!owner) goto close_child; -else -mptcp_finish_join (child); + + ctx->conn = (struct sock *)owner; +mptcp_finish_join (child); } }
net/mptcp/token.c +13 -38
72 lines not on this page · raw message
Signature · 1 line
2.21.0
Matthieu Baerts
Re: [MPTCP] [PATCH RFC 02/10] mptcp: token: remove two unneeded helpers
Hi Florian,
Quoted 8 lines · Florian Westphal
There were three flavours of almost the same function:
token_lookup_get, the base function that takes a token value and looks up the mptcp socket associated with it.
token_new_subflow, same function, but will also setsubflow->local_nonce.
Quoted 7 lines
token_new_join, just likelookup_get, but assigns the looked-up socket tosubflow->conn.This renames
token_lookup_gettomptcp_token_get_sockto avoid make it clear this belongs to mptcp namespace, and then changes the callers oftoken_new_subflowto also init the nonce andtoken_new_jointo do the assignment in the caller.
Good idea!
Quoted 7 lines
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/pm.c | 6 +++--- net/mptcp/protocol.h | 4 +--- net/mptcp/subflow.c | 16 ++++++++++---- net/mptcp/token.c | 51 +++++++++++--------------------------------- 4 files changed, 29 insertions(+), 48 deletions(-)
(...)
Quoted 4 lines
net/mptcp/token.c +0
-0
(...)
Quoted 30 lines
net/mptcp/token.c +6
-20@@ -328,36 +311,28 @@ void token_update_accept(struct sock *sk, struct sock *conn)spin_unlock_bh (&token_tree_lock); } -int token_new_join (struct sock *sk) -{ -struct subflow_context *subflow =subflow_ctx (sk); -struct sock *conn; - -spin_lock_bh (&token_tree_lock); - conn =__token_lookup (subflow->token); -if (conn) -sock_hold (conn); -spin_unlock_bh (&token_tree_lock); - -if (!conn) -return -1 ; - - subflow->conn = conn; - -return 0 ; -} - -struct sock *token_lookup_get (u32 token) +/** +* mptcp_token_get_sock - retrieve mptcp connection sock using its token +* @token - token of the mptcp connection to retrieve +* +* This function returns the mptcp connection structure with the given token. +* A reference count on the mptcp socket returned is taken.
net/mptcp/token.c void token_update_accept(struct sock *sk, struct sock *conn) · line 329
Quoted 10 lines
net/mptcp/token.c +5
-0+* +* returns NULL if no connection with the given token value exists. +*/ +struct mptcp_sock *mptcp_token_get_sock (u32 token) {struct sock *conn;spin_lock_bh (&token_tree_lock); conn =__token_lookup (token); +if (conn &&WARN_ON_ONCE (conn == (struct sock *)&token_used))
Why do we need to do this check after each lookup?
net/mptcp/token.c void token_update_accept(struct sock *sk, struct sock *conn) · line 330
Quoted 1 line
net/mptcp/token.c +1
-0+ conn =NULL ;
(detail: a space is missing here).
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
Re: [MPTCP] [PATCH RFC 02/10] mptcp: token: remove two unneeded helpers
Matthieu Baerts <matthieu.baerts(a)tessares.net> wrote:
[ WARN_ON_ONCE ]
Quoted 1 line
Why do we need to do this check after each lookup?
Good point, I'll remove it in v2.
Its a leftover -- i saw a crash in sock_release(), and guessed it was because it tried to release the "token_used" dummy -- some places test for NULL, others also for conn == &token_used.
I couldn't reproduce it yet and added these WARN to see if that is the case or not...)
Florian Westphal
RFC PATCH 3/10 mptcp: token: rename token_join_response
In reply to Florian WestphalThis function validates the truncated hmac and computes a hmac for use in the ack packet. Rename it and place it where its used.
--- net/mptcp/protocol.h | 1 - net/mptcp/subflow.c | 28 +++++++++++++++++++++++++++- net/mptcp/token.c | 31 ------------------------------- 3 files changed, 27 insertions(+), 33 deletions(-)
net/mptcp/protocol.h +0 -1
@@ -227,7 +227,6 @@ void mptcp_finish_join(struct sock *sk);void token_new_request (struct request_sock *req,const struct sk_buff *skb);int token_join_request (struct request_sock *req,const struct sk_buff *skb); -int token_join_response (struct sock *sk);int token_join_valid (struct request_sock *req,struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);
net/mptcp/subflow.c +27 -1
@@ -96,6 +96,32 @@ static void subflow_v4_init_req(struct request_sock *req, } } +/* validate received truncated hmac and create hmac for third ACK */ +static bool subflow_hmac_ok (struct subflow_context *subflow) +{ +u8 hmac[MPTCPOPT_HMAC_LEN ]; +u64 thmac; + +pr_debug ("subflow=%p, token=%u" , subflow, subflow->token); + +crypto_hmac_sha1 (subflow->remote_key, subflow->local_key, + subflow->remote_nonce, subflow->local_nonce, + (u32 *)hmac); + + thmac =get_unaligned_be64 (hmac); +pr_debug ("thmac=%llu" , thmac); + +if (thmac != subflow->thmac) { +pr_info ("HMAC FAILURE: %llx vs %llx\n" , thmac, subflow->thmac); +return false; + } + +crypto_hmac_sha1 (subflow->local_key, subflow->remote_key, + subflow->local_nonce, subflow->remote_nonce, + (u32 *)subflow->hmac); +return true; +} +static void subflow_finish_connect (struct sock *sk,const struct sk_buff *skb) {struct subflow_context *subflow =subflow_ctx (sk);
@@ -119,7 +145,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)pr_debug ("subflow=%p, thmac=%llu, remote_nonce=%u" ,subflow_ctx (sk), subflow->thmac, subflow->remote_nonce); -if (token_join_response (sk)) { +if (!subflow_hmac_ok (subflow)) { subflow->mp_join =0 ;// @@ need to trigger RST }else {
net/mptcp/token.c +0 -31
@@ -91,28 +91,6 @@ static void new_req_join(struct request_sock *req, struct sock *sk, subflow_req->thmac); } -static int new_rsp_join (struct sock *sk) -{ -struct subflow_context *subflow =subflow_ctx (sk); -u8 hmac[MPTCPOPT_HMAC_LEN ]; -u64 thmac; - -crypto_hmac_sha1 (subflow->remote_key, subflow->local_key, - subflow->remote_nonce, subflow->local_nonce, - (u32 *)hmac); - - thmac =get_unaligned_be64 (hmac); -pr_debug ("thmac=%llu" , thmac); -if (thmac != subflow->thmac) -return -1 ; - -crypto_hmac_sha1 (subflow->local_key, subflow->remote_key, - subflow->local_nonce, subflow->remote_nonce, - (u32 *)subflow->hmac); - -return 0 ; -} -static int new_join_valid (struct request_sock *req,struct sock *sk,struct tcp_options_received *rx_opt) {
@@ -237,15 +215,6 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)return 0 ; } -/* validate received truncated hmac and create hmac for third ACK */ -int token_join_response (struct sock *sk) -{ -struct subflow_context *subflow =subflow_ctx (sk); - -pr_debug ("subflow=%p, token=%u" , subflow, subflow->token); -return new_rsp_join (sk); -} -/* validate hmac received in third ACK */ int token_join_valid (struct request_sock *req,struct tcp_options_received *rx_opt)
Signature · 1 line
2.21.0
Peter Krystad
Re: [MPTCP] [PATCH RFC 03/10] mptcp: token: rename token_join_response
Quoted 27 lines · Florian Westphal
This function validates the truncated hmac and computes a hmac for use in the ack packet. Rename it and place it where its used.
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/protocol.h | 1 - net/mptcp/subflow.c | 28 +++++++++++++++++++++++++++- net/mptcp/token.c | 31 ------------------------------- 3 files changed, 27 insertions(+), 33 deletions(-)net/mptcp/protocol.h +0
-1@@ -227,7 +227,6 @@ void mptcp_finish_join(struct sock *sk);void token_new_request (struct request_sock *req,const struct sk_buff *skb);int token_join_request (struct request_sock *req,const struct sk_buff *skb); -int token_join_response (struct sock *sk);int token_join_valid (struct request_sock *req,struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);net/mptcp/subflow.c +0
-0
net/mptcp/subflow.c static void subflow_v4_init_req(struct request_sock *req, · line 100
Quoted 5 lines
net/mptcp/subflow.c +2
-0@@ -96,6 +96,32 @@ static void subflow_v4_init_req(struct request_sock *req, } } +/* validate received truncated hmac and create hmac for third ACK */ +static bool subflow_hmac_ok (struct subflow_context *subflow)
Consider subflow_thmac_valid for this name? The routine is similiar in function to token_join_valid so maintain 'valid' naming convention? And 'thmac' is what is being validated, hmac is a different field in subflow.
Quoted 11 lines
net/mptcp/subflow.c +11
-0+{ +u8 hmac[MPTCPOPT_HMAC_LEN ]; +u64 thmac; + +pr_debug ("subflow=%p, token=%u" , subflow, subflow->token); + +crypto_hmac_sha1 (subflow->remote_key, subflow->local_key, + subflow->remote_nonce, subflow->local_nonce, + (u32 *)hmac); + + thmac =get_unaligned_be64 (hmac);
net/mptcp/subflow.c static void subflow_v4_init_req(struct request_sock *req, · line 121
Quoted 10 lines
net/mptcp/subflow.c +10
-0+pr_debug ("thmac=%llu" , thmac); + +if (thmac != subflow->thmac) { +pr_info ("HMAC FAILURE: %llx vs %llx\n" , thmac, subflow->thmac); +return false; + } + +crypto_hmac_sha1 (subflow->local_key, subflow->remote_key, + subflow->local_nonce, subflow->remote_nonce, + (u32 *)subflow->hmac);
Consider moving this call to the successful branch of the caller so this routine does one thing: validate thmac.
Peter.
Quoted 64 lines
net/mptcp/subflow.c +4
-1+return true; +} +static void subflow_finish_connect (struct sock *sk,const struct sk_buff *skb) {struct subflow_context *subflow =subflow_ctx (sk);@@ -119,7 +145,7 @@ static void subflow_finish_connect(struct sock *sk, const struct sk_buff *skb)pr_debug ("subflow=%p, thmac=%llu, remote_nonce=%u" ,subflow_ctx (sk), subflow->thmac, subflow->remote_nonce); -if (token_join_response (sk)) { +if (!subflow_hmac_ok (subflow)) { subflow->mp_join =0 ;// @@ need to trigger RST }else {net/mptcp/token.c +0
-31@@ -91,28 +91,6 @@ static void new_req_join(struct request_sock *req, struct sock *sk, subflow_req->thmac); } -static int new_rsp_join (struct sock *sk) -{ -struct subflow_context *subflow =subflow_ctx (sk); -u8 hmac[MPTCPOPT_HMAC_LEN ]; -u64 thmac; - -crypto_hmac_sha1 (subflow->remote_key, subflow->local_key, - subflow->remote_nonce, subflow->local_nonce, - (u32 *)hmac); - - thmac =get_unaligned_be64 (hmac); -pr_debug ("thmac=%llu" , thmac); -if (thmac != subflow->thmac) -return -1 ; - -crypto_hmac_sha1 (subflow->local_key, subflow->remote_key, - subflow->local_nonce, subflow->remote_nonce, - (u32 *)subflow->hmac); - -return 0 ; -} -static int new_join_valid (struct request_sock *req,struct sock *sk,struct tcp_options_received *rx_opt) {@@ -237,15 +215,6 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)return 0 ; } -/* validate received truncated hmac and create hmac for third ACK */ -int token_join_response (struct sock *sk) -{ -struct subflow_context *subflow =subflow_ctx (sk); - -pr_debug ("subflow=%p, token=%u" , subflow, subflow->token); -return new_rsp_join (sk); -} -/* validate hmac received in third ACK */ int token_join_valid (struct request_sock *req,struct tcp_options_received *rx_opt)
Florian Westphal
RFC PATCH 4/10 mptcp: token: fold new_join_valid into its caller
In reply to Florian WestphalThis helper is only used once. Both this function and its caller are reasonably small, so merge these two functions.
The function is renamed to have an mptcp prefix.
Also, prefer the crypto_mneq function rather than memcmp which might reveal timing information when doing hmac compare.
--- net/mptcp/protocol.h | 4 ++-- net/mptcp/subflow.c | 3 ++- net/mptcp/token.c | 52 +++++++++++++++++++++++++------------------- 3 files changed, 34 insertions(+), 25 deletions(-)
net/mptcp/protocol.h +2 -2
@@ -227,8 +227,8 @@ void mptcp_finish_join(struct sock *sk);void token_new_request (struct request_sock *req,const struct sk_buff *skb);int token_join_request (struct request_sock *req,const struct sk_buff *skb); -int token_join_valid (struct request_sock *req, -struct tcp_options_received *rx_opt); +bool mptcp_token_join_valid (const struct request_sock *req, +const struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);void token_new_connect (struct sock *sk);void token_new_accept (struct sock *sk);
net/mptcp/subflow.c +2 -1
@@ -194,7 +194,8 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,if (!subflow_req->mp_capable && subflow_req->mp_join) { opt_rx.mptcp.mp_join =0 ;mptcp_get_options (skb, &opt_rx); -if (!opt_rx.mptcp.mp_join ||token_join_valid (req, &opt_rx)) +if (!opt_rx.mptcp.mp_join || + !mptcp_token_join_valid (req, &opt_rx))return NULL ; }
net/mptcp/token.c +30 -22
80 lines not on this page · raw message
Signature · 1 line
2.21.0
Peter Krystad
Re: [MPTCP] [PATCH RFC 04/10] mptcp: token: fold new_join_valid into its caller
You might consider taking this one step further using an approach similiar to the one in the previous patch: move this function and the helper to a new function in subflow.c [call it subflow_hmac_valid()?] and use the existing mptcp_lookup_get() to get the conn pointer.
Peter.
Quoted 132 lines · Florian Westphal
This helper is only used once. Both this function and its caller are reasonably small, so merge these two functions.
The function is renamed to have an mptcp prefix.
Also, prefer the
crypto_mneqfunction rather than memcmp which might reveal timing information when doing hmac compare.Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/protocol.h | 4 ++-- net/mptcp/subflow.c | 3 ++- net/mptcp/token.c | 52 +++++++++++++++++++++++++------------------- 3 files changed, 34 insertions(+), 25 deletions(-)net/mptcp/protocol.h +2
-2@@ -227,8 +227,8 @@ void mptcp_finish_join(struct sock *sk);void token_new_request (struct request_sock *req,const struct sk_buff *skb);int token_join_request (struct request_sock *req,const struct sk_buff *skb); -int token_join_valid (struct request_sock *req, -struct tcp_options_received *rx_opt); +bool mptcp_token_join_valid (const struct request_sock *req, +const struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);void token_new_connect (struct sock *sk);void token_new_accept (struct sock *sk);net/mptcp/subflow.c +2
-1@@ -194,7 +194,8 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,if (!subflow_req->mp_capable && subflow_req->mp_join) { opt_rx.mptcp.mp_join =0 ;mptcp_get_options (skb, &opt_rx); -if (!opt_rx.mptcp.mp_join ||token_join_valid (req, &opt_rx)) +if (!opt_rx.mptcp.mp_join || + !mptcp_token_join_valid (req, &opt_rx))return NULL ; }net/mptcp/token.c +30
-22@@ -25,6 +25,7 @@#include <linux/radix-tree.h> #include <linux/ip.h> #include <linux/tcp.h> +#include <crypto/algapi.h> #include <net/sock.h> #include <net/inet_common.h> #include <net/protocol.h> @@ -91,20 +92,6 @@ static void new_req_join(struct request_sock *req, struct sock *sk, subflow_req->thmac); } -static int new_join_valid (struct request_sock *req,struct sock *sk, -struct tcp_options_received *rx_opt) -{ -struct subflow_request_sock *subflow_req =subflow_rsk (req); -struct mptcp_sock *msk =mptcp_sk (sk); -u8 hmac[MPTCPOPT_HMAC_LEN ]; - -crypto_hmac_sha1 (msk->remote_key, msk->local_key, - subflow_req->remote_nonce, subflow_req->local_nonce, - (u32 *)hmac); - -return memcmp (hmac, (char *)rx_opt->mptcp.hmac,MPTCPOPT_HMAC_LEN ); -} -static void new_token (const struct sock *sk) {struct subflow_context *subflow =subflow_ctx (sk);@@ -215,13 +202,26 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)return 0 ; } -/* validate hmac received in third ACK */ -int token_join_valid (struct request_sock *req, -struct tcp_options_received *rx_opt) +/** +* mptcp_token_join_valid - validate hmac received in 3whs ACK +* @req - the request socket that received the ACK +* @rx_opt - the tcp options of this ACK +* +* This function is called when a new incoming connection is about +* to finish the TCP 3whs, and that connection indicates a join +* with an existing MPTCP flow. +* +* returns true if the mptcp token (connection we want to join) +* exists and its HMAC matches the value sent from the client. +*/ +bool mptcp_token_join_valid (const struct request_sock *req, +const struct tcp_options_received *rx_opt) { -struct subflow_request_sock *subflow_req =subflow_rsk (req); +const struct subflow_request_sock *subflow_req =subflow_rsk (req); +u8 hmac[MPTCPOPT_HMAC_LEN ]; +struct mptcp_sock *msk;struct sock *conn; -int err; +bool ret;pr_debug ("subflow_req=%p, token=%u" , subflow_req, subflow_req->token);spin_lock_bh (&token_tree_lock);@@ -230,11 +230,19 @@ int token_join_valid(struct request_sock *req,sock_hold (conn);spin_unlock_bh (&token_tree_lock);if (!conn) -return -1 ; +return false; + + msk =mptcp_sk (conn); +crypto_hmac_sha1 (msk->remote_key, msk->local_key, + subflow_req->remote_nonce, subflow_req->local_nonce, + (u32 *)hmac); + + ret = true; +if (crypto_memneq (hmac, rx_opt->mptcp.hmac,sizeof (hmac))) + ret = false; - err =new_join_valid (req, conn, rx_opt);sock_put (conn); -return err; +return ret; }/* create new local key, idsn, and token for subflow */
Florian Westphal
RFC PATCH 5/10 mptcp: token: fold new_req_join into its caller
In reply to Florian Westphalsimilar to the previous change. Fold the (small) helper, then rename the function to carry an mptcp prefix.
--- net/mptcp/protocol.h | 3 ++- net/mptcp/subflow.c | 2 +- net/mptcp/token.c | 52 ++++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 25 deletions(-)
net/mptcp/protocol.h +2 -1
@@ -226,7 +226,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable);void mptcp_finish_join (struct sock *sk);void token_new_request (struct request_sock *req,const struct sk_buff *skb); -int token_join_request (struct request_sock *req,const struct sk_buff *skb); +bool mptcp_token_join_request (struct request_sock *req, +const struct sk_buff *skb);bool mptcp_token_join_valid (const struct request_sock *req,const struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);
net/mptcp/subflow.c +1 -1
@@ -89,7 +89,7 @@ static void subflow_v4_init_req(struct request_sock *req, subflow_req->remote_nonce = rx_opt.mptcp.nonce;pr_debug ("token=%u, remote_nonce=%u" , subflow_req->token, subflow_req->remote_nonce); -if (token_join_request (req, skb)) { +if (!mptcp_token_join_request (req, skb)) { subflow_req->mp_join =0 ;// @@ need to trigger RST }
net/mptcp/token.c +29 -23
79 lines not on this page · raw message
Signature · 1 line
2.21.0
Peter Krystad
Re: [MPTCP] [PATCH RFC 05/10] mptcp: token: fold new_req_join into its caller
Same comment as previous patch, this could also be moved to subflow.c and token_lookup_get() used.
Peter.
Quoted 123 lines · Florian Westphal
similar to the previous change. Fold the (small) helper, then rename the function to carry an mptcp prefix.
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/protocol.h | 3 ++- net/mptcp/subflow.c | 2 +- net/mptcp/token.c | 52 ++++++++++++++++++++++++-------------------- 3 files changed, 32 insertions(+), 25 deletions(-)net/mptcp/protocol.h +2
-1@@ -226,7 +226,8 @@ void mptcp_finish_connect(struct sock *sk, int mp_capable);void mptcp_finish_join (struct sock *sk);void token_new_request (struct request_sock *req,const struct sk_buff *skb); -int token_join_request (struct request_sock *req,const struct sk_buff *skb); +bool mptcp_token_join_request (struct request_sock *req, +const struct sk_buff *skb);bool mptcp_token_join_valid (const struct request_sock *req,const struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);net/mptcp/subflow.c +1
-1@@ -89,7 +89,7 @@ static void subflow_v4_init_req(struct request_sock *req, subflow_req->remote_nonce = rx_opt.mptcp.nonce;pr_debug ("token=%u, remote_nonce=%u" , subflow_req->token, subflow_req->remote_nonce); -if (token_join_request (req, skb)) { +if (!mptcp_token_join_request (req, skb)) { subflow_req->mp_join =0 ;// @@ need to trigger RST }net/mptcp/token.c +29
-23@@ -75,23 +75,6 @@ static void new_req_token(struct request_sock *req, subflow_req->token, subflow_req->idsn); } -static void new_req_join (struct request_sock *req,struct sock *sk, -const struct sk_buff *skb) -{ -struct subflow_request_sock *subflow_req =subflow_rsk (req); -struct mptcp_sock *msk =mptcp_sk (sk); -u8 hmac[MPTCPOPT_HMAC_LEN ]; - -get_random_bytes (&subflow_req->local_nonce,sizeof (u32)); -crypto_hmac_sha1 (msk->local_key, msk->remote_key, - subflow_req->local_nonce, subflow_req->remote_nonce, - (u32 *)hmac); - - subflow_req->thmac =get_unaligned_be64 (hmac); -pr_debug ("local_nonce=%u, thmac=%llu" , subflow_req->local_nonce, - subflow_req->thmac); -} -static void new_token (const struct sock *sk) {struct subflow_context *subflow =subflow_ctx (sk);@@ -175,10 +158,24 @@ void token_new_request(struct request_sock *req,spin_unlock_bh (&token_tree_lock); } -/* validate received token and create truncated hmac and nonce for SYN-ACK */ -int token_join_request (struct request_sock *req,const struct sk_buff *skb) +/** +* mptcp_token_join_request - validate received token and create hmac +* @req - the request socket that received the ACK +* @skb - the syn packet received +* +* This function is called when a new SYN is received that indicates a +* join with an existing MPTCP flow. +* It will compute the HMAC and nonce that will be included in the SYN/ACK. +* +* Returns true on success and false if the join request indicated an invalid +* MPTCP connection (i.e., the mptcp token is not known to us). +*/ +bool mptcp_token_join_request (struct request_sock *req, +const struct sk_buff *skb) {struct subflow_request_sock *subflow_req =subflow_rsk (req); +u8 hmac[MPTCPOPT_HMAC_LEN ]; +struct mptcp_sock *msk;struct sock *conn;pr_debug ("subflow_req=%p, token=%u" , subflow_req, subflow_req->token);@@ -189,17 +186,26 @@ int token_join_request(struct request_sock *req, const struct sk_buff *skb)spin_unlock_bh (&token_tree_lock);if (!conn) -return -1 ; +return false;if (pm_get_local_id (req, conn, skb)) {sock_put (conn); -return -1 ; +return false; } -new_req_join (req, conn, skb); +get_random_bytes (&subflow_req->local_nonce,sizeof (u32)); + + msk =mptcp_sk (conn); +crypto_hmac_sha1 (msk->local_key, msk->remote_key, + subflow_req->local_nonce, subflow_req->remote_nonce, + (u32 *)hmac); + + subflow_req->thmac =get_unaligned_be64 (hmac); +pr_debug ("local_nonce=%u, thmac=%llu" , subflow_req->local_nonce, + subflow_req->thmac);sock_put (conn); -return 0 ; +return true; }/**
Florian Westphal
RFC PATCH 6/10 mptcp: token: fold helpers into token connect/request functions
In reply to Florian WestphalThis also adds error handling -- adding an object to the radix tree might require dynamic memory allocation, so insertions can fail.
--- net/mptcp/protocol.h | 4 +- net/mptcp/subflow.c | 17 ++++-- net/mptcp/token.c | 126 ++++++++++++++++++++++--------------------- 3 files changed, 80 insertions(+), 67 deletions(-)
net/mptcp/protocol.h +2 -2
@@ -225,13 +225,13 @@ void mptcp_get_options(const struct sk_buff *skb,void mptcp_finish_connect (struct sock *sk,int mp_capable);void mptcp_finish_join (struct sock *sk); -void token_new_request (struct request_sock *req,const struct sk_buff *skb); +int mptcp_token_new_request (struct request_sock *req);bool mptcp_token_join_request (struct request_sock *req,const struct sk_buff *skb);bool mptcp_token_join_valid (const struct request_sock *req,const struct tcp_options_received *rx_opt);void token_destroy_request (u32 token); -void token_new_connect (struct sock *sk); +int mptcp_token_new_connect (struct sock *sk);void token_new_accept (struct sock *sk);void token_update_accept (struct sock *sk,struct sock *conn);struct mptcp_sock *mptcp_token_get_sock (u32 token);
net/mptcp/subflow.c +13 -4
@@ -18,10 +18,11 @@static int subflow_rebuild_header (struct sock *sk) {struct subflow_context *subflow =subflow_ctx (sk); +int err =0 ;if (subflow->request_mptcp && !subflow->token) {pr_debug ("subflow=%p" , sk); -token_new_connect (sk); + err =mptcp_token_new_connect (sk); }else if (subflow->request_join && !subflow->local_nonce) {pr_debug ("subflow=%p" , sk);mptcp_token_get_sock (subflow->token);
@@ -31,6 +32,9 @@ static int subflow_rebuild_header(struct sock *sk) }while (!subflow->local_nonce); } +if (err) +return err; +return inet_sk_rebuild_header (sk); }
@@ -68,7 +72,14 @@ static void subflow_v4_init_req(struct request_sock *req,return ;if (rx_opt.mptcp.mp_capable && listener->request_mptcp) { - subflow_req->mp_capable =1 ; +int err; + +pr_debug ("remote_key=%llu" , subflow_req->remote_key); + + err =mptcp_token_new_request (req); +if (err ==0 ) + subflow_req->mp_capable =1 ; +if (rx_opt.mptcp.version >= listener->request_version) subflow_req->version = listener->request_version;else
@@ -77,8 +88,6 @@ static void subflow_v4_init_req(struct request_sock *req, listener->request_cksum) subflow_req->checksum =1 ; subflow_req->remote_key = rx_opt.mptcp.sndr_key; -pr_debug ("remote_key=%llu" , subflow_req->remote_key); -token_new_request (req, skb);pr_debug ("syn seq=%u" ,TCP_SKB_CB (skb)->seq); subflow_req->ssn_offset =TCP_SKB_CB (skb)->seq; }else if (rx_opt.mptcp.mp_join && listener->request_mptcp) {
net/mptcp/token.c +65 -61
171 lines not on this page · raw message
Signature · 1 line
2.21.0
Florian Westphal
RFC PATCH 7/10 mptcp: token: fold update_token into its caller
In reply to Florian WestphalThe calling function is very small, so just fold this.
--- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 2 +- net/mptcp/token.c | 36 ++++++++++++++++++------------------ 3 files changed, 20 insertions(+), 20 deletions(-)
net/mptcp/protocol.c +1 -1
@@ -668,7 +668,7 @@ static struct sock *mptcp_accept(struct sock *sk, int flags, int *err, msk->remote_key = subflow->remote_key; msk->local_key = subflow->local_key; msk->token = subflow->token; -token_update_accept (new_sock->sk, new_mptcp_sock); +mptcp_token_update_accept (new_sock->sk, new_mptcp_sock); msk->subflow =NULL ;pm_new_connection (msk,1 );
net/mptcp/protocol.h +1 -1
@@ -233,7 +233,7 @@ bool mptcp_token_join_valid(const struct request_sock *req,void token_destroy_request (u32 token);int mptcp_token_new_connect (struct sock *sk);void token_new_accept (struct sock *sk); -void token_update_accept (struct sock *sk,struct sock *conn); +void mptcp_token_update_accept (struct sock *sk,struct sock *conn);struct mptcp_sock *mptcp_token_get_sock (u32 token);void token_release (u32 token);void token_destroy (u32 token);
net/mptcp/token.c +18 -18
@@ -57,21 +57,6 @@ static int insert_token(u32 token, void *conn)return radix_tree_insert (&token_tree, token, used); } -static void update_token (u32 token,void *conn) -{ -void **slot; - -pr_debug ("token=%u, conn=%p" , token, conn); - slot =radix_tree_lookup_slot (&token_tree, token); -if (slot) { -if (*slot != &token_used) -pr_err ("slot ALREADY updated!" ); - *slot = conn; - }else { -pr_warn ("token NOT FOUND!" ); - } -} -static void destroy_req_token (u32 token) {void *cur;
@@ -286,15 +271,30 @@ void token_new_accept(struct sock *sk)spin_unlock_bh (&token_tree_lock); } -void token_update_accept (struct sock *sk,struct sock *conn) +/** +* mptcp_token_update_accept - update token to map to mptcp socket +* @conn: the new struct mptcp_sock +* @sk: the initial subflow for this mptcp socket +* +* Called when the first mptcp socket is created on accept to +* refresh the dummy mapping (done to reserve the token) with +* the mptcp_socket structure that wasn't allocated before. +*/ +void mptcp_token_update_accept (struct sock *sk,struct sock *conn) {struct subflow_context *subflow =subflow_ctx (sk); +void **slot;pr_debug ("subflow=%p, conn=%p" , sk, conn);spin_lock_bh (&token_tree_lock); -update_token (subflow->token, conn); -sock_hold (conn); + slot =radix_tree_lookup_slot (&token_tree, subflow->token); +WARN_ON_ONCE (!slot); +if (slot) { +WARN_ON_ONCE (*slot != &token_used); + *slot = conn; +sock_hold (conn); + }spin_unlock_bh (&token_tree_lock); }
Signature · 1 line
2.21.0
Florian Westphal
RFC PATCH 8/10 mptcp: token: add error handling for token_new_accept
In reply to Florian WestphalInsertion into radix tree might fail, so add error handling for this.
--- net/mptcp/protocol.h | 2 +- net/mptcp/subflow.c | 5 ++++- net/mptcp/token.c | 31 +++++++++++++++---------------- 3 files changed, 20 insertions(+), 18 deletions(-)
net/mptcp/protocol.h +1 -1
@@ -232,7 +232,7 @@ bool mptcp_token_join_valid(const struct request_sock *req, const struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);int mptcp_token_new_connect (struct sock *sk); -void token_new_accept (struct sock *sk); +int mptcp_token_new_accept (u32 token);void mptcp_token_update_accept (struct sock *sk,struct sock *conn);struct mptcp_sock *mptcp_token_get_sock (u32 token);void token_release (u32 token);
net/mptcp/subflow.c +4 -1
@@ -217,7 +217,10 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, goto close_child;if (ctx->mp_capable) { -token_new_accept (child); +int ret =mptcp_token_new_accept (ctx->token); + +if (ret) + goto close_child; }else if (ctx->mp_join) {struct mptcp_sock *owner;
net/mptcp/token.c +15 -16
@@ -46,17 +46,6 @@ static struct sock *__token_lookup(u32 token)return (struct sock *)conn; } -static int insert_token (u32 token,void *conn) -{ -void *used = &token_used; - -if (conn) - used = conn; - -pr_debug ("token=%u, conn=%p" , token, used); -return radix_tree_insert (&token_tree, token, used); -} -static void destroy_req_token (u32 token) {void *cur;
@@ -260,15 +249,25 @@ int mptcp_token_new_connect(struct sock *sk)return err; } -void token_new_accept (struct sock *sk) +/** +* mptcp_token_new_accept - insert token for later processing +* @token: the token to insert to the tree +* +* Called when a SYN packet creates a new logical connection, i.e. +* is not a join request. +* +* We don't have an mptcp socket yet at that point. +* This is paired with mptcp_token_update_accept, called on accept(). +*/ +int mptcp_token_new_accept (u32 token) { -struct subflow_context *subflow =subflow_ctx (sk); - -pr_debug ("subflow=%p" , sk); +int err;spin_lock_bh (&token_tree_lock); -insert_token (subflow->token,NULL ); + err =radix_tree_insert (&token_tree, token, &token_used);spin_unlock_bh (&token_tree_lock); + +return err; }/**
Signature · 1 line
2.21.0
Matthieu Baerts
Re: [MPTCP] [PATCH RFC 08/10] mptcp: token: add error handling for token_new_accept
Hi Florian,
Just a detail :)
Quoted 27 lines · Florian Westphal
Insertion into radix tree might fail, so add error handling for this.
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/protocol.h | 2 +- net/mptcp/subflow.c | 5 ++++- net/mptcp/token.c | 31 +++++++++++++++---------------- 3 files changed, 20 insertions(+), 18 deletions(-)net/mptcp/protocol.h +1
-1@@ -232,7 +232,7 @@ bool mptcp_token_join_valid(const struct request_sock *req, const struct tcp_options_received *rx_opt);void token_destroy_request (u32 token);int mptcp_token_new_connect (struct sock *sk); -void token_new_accept (struct sock *sk); +int mptcp_token_new_accept (u32 token);void mptcp_token_update_accept (struct sock *sk,struct sock *conn);struct mptcp_sock *mptcp_token_get_sock (u32 token);void token_release (u32 token);net/mptcp/subflow.c +0
-0
net/mptcp/subflow.c static struct sock *subflow_syn_recv_sock(const struct sock *sk, · line 222
Quoted 7 lines
net/mptcp/subflow.c +3
-1@@ -217,7 +217,10 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk, goto close_child;if (ctx->mp_capable) { -token_new_accept (child); +int ret =mptcp_token_new_accept (ctx->token); + +if (ret)
Detail: do we really need "ret" here? I mean maybe you added the variable to use it somewhere else?
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
RFC PATCH 9/10 mptcp: token: fold destroy_token helper
In reply to Florian Westphal--- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 4 ++-- net/mptcp/subflow.c | 2 +- net/mptcp/token.c | 50 +++++++++++++++++++------------------------- 4 files changed, 25 insertions(+), 33 deletions(-)
net/mptcp/protocol.c +1 -1
@@ -704,7 +704,7 @@ static void mptcp_destroy(struct sock *sk)pr_debug ("msk=%p, subflow=%p" , sk, msk->subflow->sk); -token_destroy (msk->token); +mptcp_token_destroy (msk->token); }/* Only pass a small subset of level/optnames that are considered safe.
net/mptcp/protocol.h +2 -2
@@ -230,13 +230,13 @@ bool mptcp_token_join_request(struct request_sock *req, const struct sk_buff *skb);bool mptcp_token_join_valid (const struct request_sock *req,const struct tcp_options_received *rx_opt); -void token_destroy_request (u32 token); +void mptcp_token_destroy_request (u32 token);int mptcp_token_new_connect (struct sock *sk);int mptcp_token_new_accept (u32 token);void mptcp_token_update_accept (struct sock *sk,struct sock *conn);struct mptcp_sock *mptcp_token_get_sock (u32 token);void token_release (u32 token); -void token_destroy (u32 token); +void mptcp_token_destroy (u32 token);void crypto_key_sha1 (u64 key,u32 *token,u64 *idsn);static inline void crypto_key_gen_sha1 (u64 *key,u32 *token,u64 *idsn)
net/mptcp/subflow.c +1 -1
@@ -45,7 +45,7 @@ static void subflow_req_destructor(struct request_sock *req)pr_debug ("subflow_req=%p" , subflow_req);if (subflow_req->mp_capable) -token_destroy_request (subflow_req->token); +mptcp_token_destroy_request (subflow_req->token); tcp_request_sock_ops.destructor (req); }
net/mptcp/token.c +21 -29
77 lines not on this page · raw message
Signature · 1 line
2.21.0
Matthieu Baerts
Re: [MPTCP] [PATCH RFC 09/10] mptcp: token: fold destroy_token helper
Hi Florian,
Quoted 8 lines · Florian Westphal
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 4 ++-- net/mptcp/subflow.c | 2 +- net/mptcp/token.c | 50 +++++++++++++++++++------------------------- 4 files changed, 25 insertions(+), 33 deletions(-)
(...)
Quoted 38 lines
net/mptcp/token.c +1
-25@@ -39,31 +39,7 @@ static int token_used __read_mostly;static struct sock *__token_lookup (u32 token) { -void *conn; - -pr_debug ("token=%u" , token); - conn =radix_tree_lookup (&token_tree, token); -return (struct sock *)conn; -} - -static void destroy_req_token (u32 token) -{ -void *cur; - - cur =radix_tree_delete (&token_req_tree, token); -if (!cur) -pr_warn ("token NOT FOUND!" ); -} - -static struct sock *destroy_token (u32 token) -{ -void *conn; - -pr_debug ("token=%u" , token); - conn =radix_tree_delete (&token_tree, token); -if (conn && conn != &token_used) -return (struct sock *)conn; -return NULL ; +return radix_tree_lookup (&token_tree, token); }/**
net/mptcp/token.c struct mptcp_sock *mptcp_token_get_sock(u32 token) · line 304
Quoted 9 lines
net/mptcp/token.c +5
-1@@ -321,12 +297,21 @@ struct mptcp_sock *mptcp_token_get_sock(u32 token)return mptcp_sk (conn); } -void token_destroy_request (u32 token) +/** +* mptcp_token_destroy_request - remove mptcp connection/token +* @token - token of mptcp connection to remove +* +* Remove the not-yey-fully-established incoming connection identified
yey? or "yay!!!"? maybe more "yet" I guess :-D
net/mptcp/token.c struct mptcp_sock *mptcp_token_get_sock(u32 token) · line 305
Quoted 1 line
net/mptcp/token.c +1
-0+* by @token. If the connection isn't found, no action is taken.
Is it to explain why we don't do anything with *cur?
Quoted 24 lines
net/mptcp/token.c +11
-2+*/ +void mptcp_token_destroy_request (u32 token) { +const void *cur; +pr_debug ("token=%u" , token);spin_lock_bh (&token_tree_lock); -destroy_req_token (token); + cur =radix_tree_delete (&token_req_tree, token);spin_unlock_bh (&token_tree_lock); }@@ -342,13 +327,20 @@ void token_release(u32 token)spin_unlock_bh (&token_tree_lock); } -void token_destroy (u32 token) +/** +* mptcp_token_destroy - remove mptcp connection/token +* @token - token of mptcp connection to remove +* +* Remove the connection identified by @token. +* If the connection isn't found, no action is taken.
net/mptcp/token.c void token_release(u32 token) · line 344
Quoted 10 lines
net/mptcp/token.c +3
-1+*/ +void mptcp_token_destroy (u32 token) {struct sock *conn;pr_debug ("token=%u" , token);spin_lock_bh (&token_tree_lock); - conn =destroy_token (token); + conn =radix_tree_delete (&token_tree, token);if (conn)
Is it no longer needed to check "conn != &token_used" here?
Quoted 3 lines
net/mptcp/token.c +0
-0sock_put (conn);spin_unlock_bh (&token_tree_lock);
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
Re: [MPTCP] [PATCH RFC 09/10] mptcp: token: fold destroy_token helper
Quoted 8 lines · Matthieu Baerts
net/mptcp/token.c struct mptcp_sock *mptcp_token_get_sock(u32 token) · line 304
Quoted 6 lines
net/mptcp/token.c +5
-1-void token_destroy_request (u32 token) +/** +* mptcp_token_destroy_request - remove mptcp connection/token +* @token - token of mptcp connection to remove +* +* Remove the not-yey-fully-established incoming connection identified yey? or "yay!!!"? maybe more "yet" I guess :-D
Right. I'll run aspell on the series next time.
Quoted 3 lines
Quoted 1 line
+ * by @token. If the connection isn't found, no action is taken.
Is it to explain why we don't do anything with *cur?
Right, I'll remove cur.
Quoted 6 lines
net/mptcp/token.c void token_release(u32 token) · line 344
Quoted 4 lines
net/mptcp/token.c +1
-1spin_lock_bh (&token_tree_lock); - conn =destroy_token (token); + conn =radix_tree_delete (&token_tree, token);if (conn)Is it no longer needed to check "conn !=
&token_used" here?
Right, I'll add it back -- thanks!
Peter Krystad
Re: [MPTCP] [PATCH RFC 09/10] mptcp: token: fold destroy_token helper
In reply to Florian WestphalQuoted 93 lines · Florian Westphal
Signed-off-by Florian Westphal <fw(a)strlen.de>--- net/mptcp/protocol.c | 2 +- net/mptcp/protocol.h | 4 ++-- net/mptcp/subflow.c | 2 +- net/mptcp/token.c | 50 +++++++++++++++++++------------------------- 4 files changed, 25 insertions(+), 33 deletions(-)net/mptcp/protocol.c +1
-1@@ -704,7 +704,7 @@ static void mptcp_destroy(struct sock *sk)pr_debug ("msk=%p, subflow=%p" , sk, msk->subflow->sk); -token_destroy (msk->token); +mptcp_token_destroy (msk->token); }/* Only pass a small subset of level/optnames that are considered safe. net/mptcp/protocol.h +2
-2@@ -230,13 +230,13 @@ bool mptcp_token_join_request(struct request_sock *req, const struct sk_buff *skb);bool mptcp_token_join_valid (const struct request_sock *req,const struct tcp_options_received *rx_opt); -void token_destroy_request (u32 token); +void mptcp_token_destroy_request (u32 token);int mptcp_token_new_connect (struct sock *sk);int mptcp_token_new_accept (u32 token);void mptcp_token_update_accept (struct sock *sk,struct sock *conn);struct mptcp_sock *mptcp_token_get_sock (u32 token);void token_release (u32 token); -void token_destroy (u32 token); +void mptcp_token_destroy (u32 token);void crypto_key_sha1 (u64 key,u32 *token,u64 *idsn);static inline void crypto_key_gen_sha1 (u64 *key,u32 *token,u64 *idsn)net/mptcp/subflow.c +1
-1@@ -45,7 +45,7 @@ static void subflow_req_destructor(struct request_sock *req)pr_debug ("subflow_req=%p" , subflow_req);if (subflow_req->mp_capable) -token_destroy_request (subflow_req->token); +mptcp_token_destroy_request (subflow_req->token); tcp_request_sock_ops.destructor (req); }net/mptcp/token.c +1
-25@@ -39,31 +39,7 @@ static int token_used __read_mostly;static struct sock *__token_lookup (u32 token) { -void *conn; - -pr_debug ("token=%u" , token); - conn =radix_tree_lookup (&token_tree, token); -return (struct sock *)conn; -} - -static void destroy_req_token (u32 token) -{ -void *cur; - - cur =radix_tree_delete (&token_req_tree, token); -if (!cur) -pr_warn ("token NOT FOUND!" ); -} - -static struct sock *destroy_token (u32 token) -{ -void *conn; - -pr_debug ("token=%u" , token); - conn =radix_tree_delete (&token_tree, token); -if (conn && conn != &token_used) -return (struct sock *)conn; -return NULL ; +return radix_tree_lookup (&token_tree, token); }/** @@ -321,12 +297,21 @@ struct mptcp_sock *mptcp_token_get_sock(u32 token)return mptcp_sk (conn);
net/mptcp/token.c struct mptcp_sock *mptcp_token_get_sock(u32 token) · line 306
Quoted 10 lines
net/mptcp/token.c +7
-1} -void token_destroy_request (u32 token) +/** +* mptcp_token_destroy_request - remove mptcp connection/token +* @token - token of mptcp connection to remove +* +* Remove the not-yey-fully-established incoming connection identified +* by @token. If the connection isn't found, no action is taken. +*/
I would reword these comments to refer to a "connection request", there isn't a connection to remove.
Peter.
Quoted 35 lines
net/mptcp/token.c +13
-3+void mptcp_token_destroy_request (u32 token) { +const void *cur; +pr_debug ("token=%u" , token);spin_lock_bh (&token_tree_lock); -destroy_req_token (token); + cur =radix_tree_delete (&token_req_tree, token);spin_unlock_bh (&token_tree_lock); }@@ -342,13 +327,20 @@ void token_release(u32 token)spin_unlock_bh (&token_tree_lock); } -void token_destroy (u32 token) +/** +* mptcp_token_destroy - remove mptcp connection/token +* @token - token of mptcp connection to remove +* +* Remove the connection identified by @token. +* If the connection isn't found, no action is taken. +*/ +void mptcp_token_destroy (u32 token) {struct sock *conn;pr_debug ("token=%u" , token);spin_lock_bh (&token_tree_lock); - conn =destroy_token (token); + conn =radix_tree_delete (&token_tree, token);if (conn)sock_put (conn);spin_unlock_bh (&token_tree_lock);
Florian Westphal
RFC PATCH 10/10 mptcp: token: rename token_release
In reply to Florian Westphalavoid namespace pollution -- add an mptcp prefix.
--- net/mptcp/protocol.h | 2 +- net/mptcp/subflow.c | 3 +-- net/mptcp/token.c | 9 ++++++++- 3 files changed, 10 insertions(+), 4 deletions(-)
net/mptcp/protocol.h +1 -1
@@ -235,7 +235,7 @@ int mptcp_token_new_connect(struct sock *sk);int mptcp_token_new_accept (u32 token);void mptcp_token_update_accept (struct sock *sk,struct sock *conn);struct mptcp_sock *mptcp_token_get_sock (u32 token); -void token_release (u32 token); +void mptcp_token_release (u32 token);void mptcp_token_destroy (u32 token);void crypto_key_sha1 (u64 key,u32 *token,u64 *idsn);
net/mptcp/subflow.c +1 -2
@@ -386,8 +386,7 @@ static void subflow_ulp_release(struct sock *sk)struct subflow_context *ctx =subflow_ctx (sk);pr_debug ("subflow=%p" , ctx); - -token_release (ctx->token); +mptcp_token_release (ctx->token);kfree (ctx); }
net/mptcp/token.c +8 -1
@@ -315,7 +315,14 @@ void mptcp_token_destroy_request(u32 token)spin_unlock_bh (&token_tree_lock); } -void token_release (u32 token) +/** +* mptcp_token_release - put reference on token without withdrawing it +* @token - token of mptcp connection that the subflow is "leaving" +* +* This is used to close/remove a subflow without removing the +* mptcp connection from the token <-> mptcp_sk map. +*/ +void mptcp_token_release (u32 token) {struct sock *conn;
Signature · 1 line
2.21.0
Matthieu Baerts
Hi Florian,
Quoted 6 lines · Florian Westphal
This series is intentionally marked RFC so noone bothers to squash all of this into the mptcp tree.
The idea is to first do a review-friendly series, with each change done in an individual patch.
Quoted 7 lines
Then, once consensus is reached (maybe over several iterations), I would send a few larger patches suitable for squashing (rather than being review friendly...).
The patches remove unneeded small helpers, add 'mptcp' prefix to non-static functions, add error handling to those that may fail and adds a few comments.
That's a very good idea!
For the 'mptcp_' prefix, we made sure to add them to all functions exposed outside net/mptcp and Peter got the excellent idea to move all functions only needed in net/mptcp into net/mptcp/protocol.h. We didn't add 'mptcp_' prefix for all these "internal" functions but it certainly makes sense to do that. I guess it is useful when debugging if you see these functions in a call trace or in the list of functions available for tracing.
Do you think we should do the same for "crypto" and "subflow" and "pm"? I guess "pm" and "subflow" are keywords mainly used in "mptcp" but it is maybe not clear for everybody.
The patches look very good to me, just a few questions and one or two typos, nothing important. I guess other people will also have a look at them :)
Cheers,
Matt
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Florian Westphal
Quoted 11 lines · Matthieu Baerts
For the '
mptcp_' prefix, we made sure to add them to all functions exposed outside net/mptcp and Peter got the excellent idea to move all functions only needed in net/mptcp intonet/mptcp/protocol.h. We didn't add 'mptcp_' prefix for all these "internal" functions but it certainly makes sense to do that. I guess it is useful when debugging if you see these functions in a call trace or in the list of functions available for tracing.Do you think we should do the same for "crypto" and "subflow" and "pm"? I guess "pm" and "subflow" are keywords mainly used in "mptcp" but it is maybe not clear for everybody.
Yes. Subflow is maybe fine though.
pm is 'power mangement', so I think it makes sense to prefix mptcp_ there.
Quoted 3 lines
The patches look very good to me, just a few questions and one or two typos, nothing important. I guess other people will also have a look at them :)
Thanks a lot for the review, I will respin a new version later this week.
Peter Krystad
Quoted 9 lines · Florian Westphal
Quoted 8 lines · Matthieu Baerts
For the '
mptcp_' prefix, we made sure to add them to all functions exposed outside net/mptcp and Peter got the excellent idea to move all functions only needed in net/mptcp intonet/mptcp/protocol.h. We didn't add 'mptcp_' prefix for all these "internal" functions but it certainly makes sense to do that. I guess it is useful when debugging if you see these functions in a call trace or in the list of functions available for tracing.
Quoted 8 lines
Quoted 3 lines
Do you think we should do the same for "crypto" and "subflow" and "pm"? I guess "pm" and "subflow" are keywords mainly used in "mptcp" but it is maybe not clear for everybody.
Yes. Subflow is maybe fine though.
pm is 'power mangement', so I think it makes sense to prefix
mptcp_there.
Although I argued against this when creating net/mptcp/protocol.h I respect the namespace pollution issue more now. Matthieu are you volunteering to do this or do you want to have a go? Up to you.
Peter.
Quoted 10 lines
Quoted 3 lines
The patches look very good to me, just a few questions and one or two typos, nothing important. I guess other people will also have a look at them :)
Thanks a lot for the review, I will respin a new version later this week.
_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp
Matthieu Baerts
Hi Peter,
Quoted 14 lines · Peter Krystad
Quoted 13 lines · Florian Westphal
Quoted 11 lines · Matthieu Baerts
For the '
mptcp_' prefix, we made sure to add them to all functions exposed outside net/mptcp and Peter got the excellent idea to move all functions only needed in net/mptcp intonet/mptcp/protocol.h. We didn't add 'mptcp_' prefix for all these "internal" functions but it certainly makes sense to do that. I guess it is useful when debugging if you see these functions in a call trace or in the list of functions available for tracing.Do you think we should do the same for "crypto" and "subflow" and "pm"? I guess "pm" and "subflow" are keywords mainly used in "mptcp" but it is maybe not clear for everybody.
Quoted 8 lines
Quoted 4 lines
Yes. Subflow is maybe fine though.
pm is 'power mangement', so I think it makes sense to prefix
mptcp_there.Although I argued against this when creating
net/mptcp/protocol.hI respect the namespace pollution issue more now. Matthieu are you volunteering to do this or do you want to have a go? Up to you.
I would be happy to do that but I guess I should focus on helping Mat with the paper and slides.
If it is not already done by someone else, I can do it later. Maybe after/at LPC if I really want to force myself to finish the paper/slides as soon as possible :-)
Cheers,
Matt
Quoted 14 lines
Peter.
Quoted 10 lines
Quoted 3 lines
The patches look very good to me, just a few questions and one or two typos, nothing important. I guess other people will also have a look at them :)
Thanks a lot for the review, I will respin a new version later this week.
_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp
Signature · 5 lines
Matthieu Baerts | R&D Engineer matthieu.baerts(a)tessares.net Tessares SA | Hybrid Access Solutions www.tessares.net 1 Avenue Jean Monnet, 1348 Louvain-la-Neuve, Belgium
Peter Krystad
Thanks for doing this Florian.
I feel somewhat guilty providing a few suggestions regarding how you re- factored this code, please see individual PATCH comments.
Peter.
Quoted 27 lines · Florian Westphal
This series is intentionally marked RFC so noone bothers to squash all of this into the mptcp tree.
The idea is to first do a review-friendly series, with each change done in an individual patch.
Then, once consensus is reached (maybe over several iterations), I would send a few larger patches suitable for squashing (rather than being review friendly...).
The patches remove unneeded small helpers, add 'mptcp' prefix to non-static functions, add error handling to those that may fail and adds a few comments.
Feedback welcome.
pm.c | 6 protocol.c | 5 protocol.h | 27 +-- subflow.c | 76 ++++++++-- token.c | 447 +++++++++++++++++++++++++++---------------------------------- 5 files changed, 278 insertions(+), 283 deletions(-)_______________________________________________
mptcp mailing list
mptcp(a)lists.01.org
https://lists.01.org/mailman/listinfo/mptcp
Florian Westphal
Quoted 2 lines · Peter Krystad
I feel somewhat guilty providing a few suggestions regarding how you re- factored this code, please see individual PATCH comments.
Why? Your comments are not only helpful, I happen to agree with all of them - so, thanks a lot, I will incorporate your suggestions asap.