All of lore.kernel.org
 help / color / mirror / Atom feed
* [MPTCP] [RFC] mptcp: Implement interim path manager
@ 2019-08-07 22:54 Peter Krystad
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Krystad @ 2019-08-07 22:54 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 3546 bytes --]

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.

Signed-off-by: Peter Krystad <peter.krystad(a)linux.intel.com>
---
 net/mptcp/pm.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 53 insertions(+), 4 deletions(-)

diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index c98b92512adf..d43d05511e69 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -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,32 @@ 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) {
+		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) {
+		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 +140,20 @@ 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) {
+		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 +205,25 @@ 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 in_addr addr;
+
+	/* @@ hard-code address to announce here... */
+	pm_announce_addr(pm->token, AF_INET, 1, &addr);
+}
+
+static void create_subflow_worker(struct work_struct *work)
+{
+	struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data,
+						subflow_work);
+
+	pm_create_subflow(pm->token, pm->remote_id);
 }
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [MPTCP] [RFC] mptcp: Implement interim path manager
@ 2019-08-27 19:56 Peter Krystad
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Krystad @ 2019-08-27 19:56 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 1150 bytes --]


Hi Paolo -

On Mon, 2019-08-26 at 17:20 +0200, Paolo Abeni wrote:
> On Wed, 2019-08-07 at 15:54 -0700, Peter Krystad wrote:
> > @@ -91,16 +95,32 @@ 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) {
> > +		INIT_WORK(&pm->addr_work, announce_addr_worker);
> > +		queue_work(mptcp_wq, &pm->addr_work);
> 
> I think that here we need to acquire a reference to the related msk
> socket, or we can get use-after-free depending on socket shutdown and
> workqueue scheduling.

Thanks for the review, I'll add this and submit a v2.

Peter.

> Such reference should be releases by the worker itself.
> 
> Other workqueue usage below should need a similar change.
> 
> Cheers,
> 
> Paolo
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [MPTCP] [RFC] mptcp: Implement interim path manager
@ 2019-08-26 15:20 Paolo Abeni
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Abeni @ 2019-08-26 15:20 UTC (permalink / raw)
  To: mptcp

[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

On Wed, 2019-08-07 at 15:54 -0700, Peter Krystad wrote:
> @@ -91,16 +95,32 @@ 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) {
> +		INIT_WORK(&pm->addr_work, announce_addr_worker);
> +		queue_work(mptcp_wq, &pm->addr_work);

I think that here we need to acquire a reference to the related msk
socket, or we can get use-after-free depending on socket shutdown and
workqueue scheduling.

Such reference should be releases by the worker itself.

Other workqueue usage below should need a similar change.

Cheers,

Paolo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-27 19:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07 22:54 [MPTCP] [RFC] mptcp: Implement interim path manager Peter Krystad
2019-08-26 15:20 Paolo Abeni
2019-08-27 19:56 Peter Krystad

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.