mptcp: Implement interim path manager
Subsystems (2)
Peter Krystad
PATCH v2 1/1 mptcp: Implement interim path manager
Two features: 1) When an incoming connection is received announce a local address and 2) When an outgoing connection is fully established and a remote address has been received initiate a secondary subflow.
The second local address must be hard-coded for now.
v2: take a reference on the mptcp_sock while work is queued.
--- net/mptcp/pm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-)
net/mptcp/pm.c +60 -4
@@ -8,6 +8,10 @@#include <net/mptcp.h> #include "protocol.h" +struct workqueue_struct *mptcp_wq; +static void announce_addr_worker (struct work_struct *work); +static void create_subflow_worker (struct work_struct *work); +/* path manager command handlers */ int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,
@@ -91,16 +95,34 @@ int pm_remove_subflow(u32 token, u8 remote_id)void pm_new_connection (struct mptcp_sock *msk,int server_side) { -pr_debug ("msk=%p" , msk); +struct mptcp_pm_data *pm = &msk->pm; + +pr_debug ("msk=%p, token=%u" , msk, msk->token); - msk->pm.server_side = server_side; + pm->server_side = server_side; + pm->token = msk->token; + +/* trigger announce address in interim local path manager */ +if (pm->server_side) { +sock_hold ((struct sock *)msk); +INIT_WORK (&pm->addr_work, announce_addr_worker); +queue_work (mptcp_wq, &pm->addr_work); + } }void pm_fully_established (struct mptcp_sock *msk) { +struct mptcp_pm_data *pm = &msk->pm; +pr_debug ("msk=%p" , msk); - msk->pm.fully_established =1 ; +/* trigger create subflow in interim local path manager */ +if (!pm->server_side && !pm->fully_established && pm->remote_valid) { +sock_hold ((struct sock *)msk); +INIT_WORK (&pm->subflow_work, create_subflow_worker); +queue_work (mptcp_wq, &pm->subflow_work); + } + pm->fully_established =1 ; }void pm_connection_closed (struct mptcp_sock *msk)
@@ -120,12 +142,21 @@ void pm_subflow_closed(struct mptcp_sock *msk, u8 id)void pm_add_addr (struct mptcp_sock *msk,const struct in_addr *addr,u8 id) { +struct mptcp_pm_data *pm = &msk->pm; +pr_debug ("msk=%p, addr=%x, remote_id=%d" , msk, addr->s_addr, id); msk->pm.remote_addr.s_addr = addr->s_addr; msk->pm.remote_id = id; msk->pm.remote_family =AF_INET ; - msk->pm.remote_valid =1 ; + +/* trigger create subflow in interim local path manager */ +if (!pm->server_side && !pm->remote_valid && pm->fully_established) { +sock_hold ((struct sock *)msk); +INIT_WORK (&pm->subflow_work, create_subflow_worker); +queue_work (mptcp_wq, &pm->subflow_work); + } + pm->remote_valid =1 ; }void pm_add_addr6 (struct mptcp_sock *msk,const struct in6_addr *addr,u8 id)
@@ -177,4 +208,29 @@ int pm_get_local_id(struct request_sock *req, struct sock *sk,void pm_init (void ) { + mptcp_wq =alloc_workqueue ("mptcp_wq" ,WQ_UNBOUND |WQ_MEM_RECLAIM ,8 ); +if (!mptcp_wq) +panic ("Failed to allocate workqueue" ); +} + +static void announce_addr_worker (struct work_struct *work) +{ + struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data, + addr_work); + struct mptcp_sock *msk = container_of(pm, struct mptcp_sock, pm); +struct in_addr addr; + +/* @@ hard-code address to announce here... */ +pm_announce_addr (pm->token,AF_INET ,1 , &addr); +sock_put ((struct sock *)msk); +} + +static void create_subflow_worker (struct work_struct *work) +{ + struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data, + subflow_work); + struct mptcp_sock *msk = container_of(pm, struct mptcp_sock, pm); + +pm_create_subflow (pm->token, pm->remote_id); +sock_put ((struct sock *)msk); }
Signature · 1 line
2.17.2
Paolo Abeni
Hi Peter,
Quoted 37 lines · Peter Krystad
Two features: 1) When an incoming connection is received announce a local address and 2) When an outgoing connection is fully established and a remote address has been received initiate a secondary subflow.
The second local address must be hard-coded for now.
v2: take a reference on the
mptcp_sockwhile work is queued.Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>--- net/mptcp/pm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-)net/mptcp/pm.c +7
-1@@ -8,6 +8,10 @@#include <net/mptcp.h> #include "protocol.h" +struct workqueue_struct *mptcp_wq; +static void announce_addr_worker (struct work_struct *work); +static void create_subflow_worker (struct work_struct *work); +/* path manager command handlers */ int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,@@ -91,16 +95,34 @@ int pm_remove_subflow(u32 token, u8 remote_id)void pm_new_connection (struct mptcp_sock *msk,int server_side) { -pr_debug ("msk=%p" , msk); +struct mptcp_pm_data *pm = &msk->pm; + +pr_debug ("msk=%p, token=%u" , msk, msk->token);
net/mptcp/pm.c int pm_remove_subflow(u32 token, u8 remote_id) · line 109
Quoted 10 lines
net/mptcp/pm.c +8
-1- msk->pm.server_side = server_side; + pm->server_side = server_side; + pm->token = msk->token; + +/* trigger announce address in interim local path manager */ +if (pm->server_side) { +sock_hold ((struct sock *)msk); +INIT_WORK (&pm->addr_work, announce_addr_worker); +queue_work (mptcp_wq, &pm->addr_work);
I'm sorry to keep adding things, I missed some details when I did my previous comment.
It looks like the above code is called with only ssk lock held.
To be safe in case of multiple subflows, we would need some additional locking (e.g. a pm-level spinlock) and perhaps something alike:
if (queue_work(...)) sock_hold(...)
If there is agreement, I think we can take the patch as is, and then clean it up with incremental changes - we would touch it anyway to add the sysctl interface.
Paolo
Peter Krystad
Quoted 54 lines · Paolo Abeni
Hi Peter,
Quoted 37 lines · Peter Krystad
Two features: 1) When an incoming connection is received announce a local address and 2) When an outgoing connection is fully established and a remote address has been received initiate a secondary subflow.
The second local address must be hard-coded for now.
v2: take a reference on the
mptcp_sockwhile work is queued.Signed-off-by Peter Krystad <peter.krystad(a)linux.intel.com>--- net/mptcp/pm.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-)net/mptcp/pm.c +7
-1@@ -8,6 +8,10 @@#include <net/mptcp.h> #include "protocol.h" +struct workqueue_struct *mptcp_wq; +static void announce_addr_worker (struct work_struct *work); +static void create_subflow_worker (struct work_struct *work); +/* path manager command handlers */ int pm_announce_addr(u32 token, sa_family_t family, u8 local_id,@@ -91,16 +95,34 @@ int pm_remove_subflow(u32 token, u8 remote_id)void pm_new_connection (struct mptcp_sock *msk,int server_side) { -pr_debug ("msk=%p" , msk); +struct mptcp_pm_data *pm = &msk->pm; + +pr_debug ("msk=%p, token=%u" , msk, msk->token);net/mptcp/pm.c int pm_remove_subflow(u32 token, u8 remote_id) · line 109
Quoted 10 lines
net/mptcp/pm.c +8
-1- msk->pm.server_side = server_side; + pm->server_side = server_side; + pm->token = msk->token; + +/* trigger announce address in interim local path manager */ +if (pm->server_side) { +sock_hold ((struct sock *)msk); +INIT_WORK (&pm->addr_work, announce_addr_worker); +queue_work (mptcp_wq, &pm->addr_work);I'm sorry to keep adding things, I missed some details when I did my previous comment.
Quoted 1 line
It looks like the above code is called with only ssk lock held.
Are you sure? pm_new_connection() is called in two places:mptcp_finish_connect() and mptcp_accept(). These are the two places where the subflow and msk locks are taken in reverse order, but they are held.
Quoted 5 lines
To be safe in case of multiple subflows, we would need some additional locking (e.g. a pm-level spinlock) and perhaps something alike:
if (queue_work(...)) sock_hold(...)
I'll submit a v3 with this change, it is correct.
Peter.
Quoted 6 lines
If there is agreement, I think we can take the patch as is, and then clean it up with incremental changes - we would touch it anyway to add the sysctl interface.
Paolo