* [MPTCP] [RFC v2 02/10] mptcp: token: remove two unneeded helpers
@ 2019-08-29 9:06 Florian Westphal
0 siblings, 0 replies; only message in thread
From: Florian Westphal @ 2019-08-29 9:06 UTC (permalink / raw)
To: mptcp
[-- Attachment #1: Type: text/plain, Size: 5666 bytes --]
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 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.
v2: remove a stray WARN_ON (Matthieu)
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 | 49 ++++++++++----------------------------------
4 files changed, 27 insertions(+), 48 deletions(-)
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index c98b92512adf..a34b76d097f6 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -13,7 +13,7 @@
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)
@@ -38,7 +38,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;
@@ -52,7 +52,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;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index e97ac14115a2..1655283dbd6a 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -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);
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index 27afc64d377f..fc507e091cf5 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -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);
}
}
diff --git a/net/mptcp/token.c b/net/mptcp/token.c
index 19b63bd34315..b63ce35c9ed3 100644
--- a/net/mptcp/token.c
+++ b/net/mptcp/token.c
@@ -290,23 +290,6 @@ void token_new_connect(struct sock *sk)
spin_unlock_bh(&token_tree_lock);
}
-/* take reference to connection and create nonce for secondary subflow */
-void token_new_subflow(struct sock *sk)
-{
- struct subflow_context *subflow = subflow_ctx(sk);
- struct sock *conn;
-
- pr_debug("subflow=%p", subflow);
-
- spin_lock_bh(&token_tree_lock);
- conn = __token_lookup(subflow->token);
- if (conn)
- sock_hold(conn);
- spin_unlock_bh(&token_tree_lock);
-
- get_random_bytes(&subflow->local_nonce, sizeof(u32));
-}
-
void token_new_accept(struct sock *sk)
{
struct subflow_context *subflow = subflow_ctx(sk);
@@ -330,26 +313,16 @@ 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.
+ *
+ * returns NULL if no connection with the given token value exists.
+ */
+struct mptcp_sock *mptcp_token_get_sock(u32 token)
{
struct sock *conn;
@@ -359,7 +332,7 @@ struct sock *token_lookup_get(u32 token)
sock_hold(conn);
spin_unlock_bh(&token_tree_lock);
- return conn;
+ return mptcp_sk(conn);
}
void token_destroy_request(u32 token)
--
2.21.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-08-29 9:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-29 9:06 [MPTCP] [RFC v2 02/10] mptcp: token: remove two unneeded helpers Florian Westphal
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.