Skip to contentSkip to conversation

add locking to PM APis, implement PM netlink

PATCH Superseded Paolo Abeni 4 participants 28 messages Feb 21, 2020 – Feb 26, 2020

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Paolo Abeni

author
#0 lore raw

v3 cover add locking to PM APis, implement PM netlink

This implement the locking required by the PM to allow concurent subflow accessing the msk PM data in a safe way. Such data is protected via a msk-level spinlock. It relies on the Double checked locking to avoid contention in the most common scenarion (no or very little PM "actions").

Additionally changes more than a bit the PM hooks/APIs, to be hopefully simpler and avoiding duplicate code (no v4/v6 variant, work queue management done by the core PM infra).

It also introduce the PM netlink - it replace the current basic ones, the related patch has been dropped locally.

git tree available at:

https://github.com/pabeni/mptcp/tree/mptcp_net-next_part3_6

changes from v2:
- hook the new tests into the self-tests infra

changes from v1:
- 2 new patches: mp_join self-tests (9/9) and a specific mp_join fix (6/9)
- fixed several bugs as pointed out by the above tests
- added support for bind to interface

changes from RFC:
- cleanup uAPIs
- added self-tests for the uAPIs
- fixed ton of bugs
- included feedback from Mat

 include/uapi/linux/mptcp.h                        |   53 +
 net/mptcp/Makefile                                |    3 
 net/mptcp/options.c                               |   60 -
 net/mptcp/pm.c                                    |  353 +++------
 net/mptcp/pm_netlink.c                            |  828 ++++++++++++++++++++++
 net/mptcp/protocol.c                              |   14 
 net/mptcp/protocol.h                              |  113 +--
 net/mptcp/subflow.c                               |   65 +
 tools/testing/selftests/net/mptcp/Makefile        |    9 
 tools/testing/selftests/net/mptcp/mptcp_connect.c |   19 
 tools/testing/selftests/net/mptcp/mptcp_join.sh   |  296 +++++++
 tools/testing/selftests/net/mptcp/pm_netlink.sh   |  123 +++
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c     |  600 +++++++++++++++
 13 files changed, 2221 insertions(+), 315 deletions(-)
author
#1 lore raw

PATCH v3 1/9 Squash-to: "mptcp: Add ADD_ADDR handling"

Drop addr_signal flag: it belong to the PM and
needs additional locking

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c  | 5 -----
 net/mptcp/protocol.h | 1 -
 2 files changed, 6 deletions(-)
net/mptcp/options.c +0 -5
index 439bb14e29dc..331b020d64ae 100644
@@ -438,9 +438,6 @@ static bool mptcp_established_options_addr(struct sock *sk,
 	if (!msk)
 		return false;
 
-	if (!msk->addr_signal)
-		return false;
-
 	id = 0;
 	memset(&saddr, 0, sizeof(saddr));
 
@@ -463,8 +460,6 @@ static bool mptcp_established_options_addr(struct sock *sk,
 	}
 #endif
 
-	msk->addr_signal = 0;
-
 	return true;
 }
 
net/mptcp/protocol.h +0 -1
index fa707a57f000..65ba8ddb62e6 100644
@@ -91,7 +91,6 @@ struct mptcp_sock {
 	struct skb_ext	*cached_ext;	/* for the next sendmsg */
 	struct socket	*subflow; /* outgoing connect/listener/!mp_capable */
 	struct sock	*first;
-	u8		addr_signal;
 };
 
 #define mptcp_for_each_subflow(__msk, __subflow)			\
Signature · 1 line
2.21.1
author
#2 lore raw

PATCH v3 2/9 Squash-to: "mptcp: Add path manager interface"

In reply to Paolo Abeni

Factor out PM addr info to simplify PM data definition and simplify the PM hooks/APIs.

The PM will carry a single local and remote addrs - the one currently being processed, if any. It's up to the PM impl, e.g. netlink, maintain additional per msk data, if needed.

Account the number of created subflow and received addresses, to enforce limits.

Add a spinlock to protect PM datas, so that we can manipulate them from subflow BH.

Delegate events handling to a workqueue, so that PM events can be processed with both the above spinlock and the msk socket lock held. The PM impl should hook inside the worker.

v1 -> v2:
- be sure to initialize the address port before calling mptcp_pm_add_addr()

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c  |  46 ++++++++++--------
 net/mptcp/pm.c       | 112 ++++++++++++++-----------------------------
 net/mptcp/protocol.c |   2 +
 net/mptcp/protocol.h |  98 ++++++++++++++++++++++---------------
 4 files changed, 123 insertions(+), 135 deletions(-)
net/mptcp/options.c +25 -21
index 6a2d6cea7d54..08456c8e25b3 100644
@@ -432,34 +432,30 @@ static bool mptcp_established_options_addr(struct sock *sk,
 {
 	struct mptcp_subflow_context *subflow = mptcp_subflow_ctx(sk);
 	struct mptcp_sock *msk = mptcp_sk(subflow->conn);
-	struct sockaddr_storage saddr;
-	u8 id;
+	struct mptcp_addr_info saddr;
+	int len;
 
 	if (!msk)
 		return false;
 
-	if (!msk->pm.fully_established)
+	if (!mptcp_pm_should_signal(msk) ||
+	    !(mptcp_pm_addr_signal(msk, remaining, &saddr)))
 		return false;
 
-	if (mptcp_pm_addr_signal(msk, &id, &saddr))
+	len = mptcp_add_addr_len(saddr.family);
+	if (remaining < len)
 		return false;
 
-	if (saddr.ss_family == AF_INET) {
-		if (remaining < TCPOLEN_MPTCP_ADD_ADDR)
-			return false;
+	*size = len;
+	opts->addr_id = saddr.id;
+	if (saddr.family == AF_INET) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
-		opts->addr_id = id;
-		opts->addr = ((struct sockaddr_in *)&saddr)->sin_addr;
-		*size = TCPOLEN_MPTCP_ADD_ADDR;
+		opts->addr = saddr.addr;
 	}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-	else if (saddr.ss_family == AF_INET6) {
-		if (remaining < TCPOLEN_MPTCP_ADD_ADDR6)
-			return false;
+	else if (saddr.family == AF_INET6) {
 		opts->suboptions |= OPTION_MPTCP_ADD_ADDR6;
-		opts->addr_id = id;
-		opts->addr6 = ((struct sockaddr_in6 *)&saddr)->sin6_addr;
-		*size = TCPOLEN_MPTCP_ADD_ADDR6;
+		opts->addr6 = saddr.addr6;
 	}
 #endif
 
@@ -557,13 +553,21 @@ void mptcp_incoming_options(struct sock *sk, struct sk_buff *skb,
 		return;
 
 	if (msk && mp_opt->add_addr) {
-		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4)
-			mptcp_pm_add_addr(msk, &mp_opt->addr, mp_opt->addr_id);
+		struct mptcp_addr_info addr;
+
+		addr.port = 0;
+		addr.id = mp_opt->addr_id;
+		if (mp_opt->family == MPTCP_ADDR_IPVERSION_4) {
+			addr.family = AF_INET;
+			addr.addr = mp_opt->addr;
+		}
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-		else if (mp_opt->family == MPTCP_ADDR_IPVERSION_6)
-			mptcp_pm_add_addr6(msk, &mp_opt->addr6,
-					   mp_opt->addr_id);
+		else if (mp_opt->family == MPTCP_ADDR_IPVERSION_6) {
+			addr.family = AF_INET6;
+			addr.addr6 = mp_opt->addr6;
+		}
 #endif
+		mptcp_pm_add_addr(msk, &addr);
 		mp_opt->add_addr = 0;
 	}
 
net/mptcp/pm.c +36 -76

170 lines not on this page · raw message

net/mptcp/protocol.c +2 -0
index dfb7fe3352de..fff8f2701385 100644
@@ -552,6 +552,8 @@ static int __mptcp_init_sock(struct sock *sk)
 
 	msk->first = NULL;
 
+	mptcp_pm_data_init(msk);
+
 	return 0;
 }
 
net/mptcp/protocol.h +60 -38

121 lines not on this page · raw message

Signature · 1 line
2.21.1
#3 lore raw

[MPTCP] Re: [PATCH v3 2/9] Squash-to: "mptcp: Add path manager interface"

Hi Paolo,

Thank you for looking at that!

Quoted 34 lines · Paolo Abeni

Factor out PM addr info to simplify PM data definition and simplify the PM hooks/APIs.

The PM will carry a single local and remote addrs - the one currently being processed, if any. It's up to the PM impl, e.g. netlink, maintain additional per msk data, if needed.

Account the number of created subflow and received addresses, to enforce limits.

Add a spinlock to protect PM datas, so that we can manipulate them from subflow BH.

Delegate events handling to a workqueue, so that PM events can be processed with both the above spinlock and the msk socket lock held. The PM impl should hook inside the worker.

v1 -> v2:
- be sure to initialize the address port before calling

    mptcp_pm_add_addr()
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
  net/mptcp/options.c  |  46 ++++++++++--------
  net/mptcp/pm.c       | 112 ++++++++++++++-----------------------------
  net/mptcp/protocol.c |   2 +
  net/mptcp/protocol.h |  98 ++++++++++++++++++++++---------------
  4 files changed, 123 insertions(+), 135 deletions(-)
net/mptcp/pm.c +0 -0
index c9f508451f2e..08f00f251838 100644
@@ -8,38 +8,22 @@

[...]

net/mptcp/pm.c void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id) · line 99

Quoted 10 lines
net/mptcp/pm.c +10 -0
+void mptcp_pm_data_init(struct mptcp_sock *msk)
+{
+	msk->pm.add_addr_signaled = 0;
+	msk->pm.add_addr_accepted = 0;
+	msk->pm.local_addr_used = 0;
+	WRITE_ONCE(msk->pm.work_pending, false);
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	WRITE_ONCE(msk->pm.fully_established, false);
+	WRITE_ONCE(msk->pm.accept_addr, false);
+	msk->pm.status = MPTCP_PM_IDLE;

Just by curiosity, why do we need to reset those fields to 0? Is this msk not already init to 0? Can we not memset the whole pm part?

Quoted 5 lines
net/mptcp/pm.c +2 -1
-	return 0;
+	spin_lock_init(&msk->pm.lock);
+	INIT_WORK(&msk->pm.work, pm_worker);
  }

[...]

Quoted 4 lines
net/mptcp/protocol.h +0 -0
index 1d658d9aac36..7e43a2a09a68 100644

[...]

net/mptcp/protocol.h void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u32 nonce1, u32 nonce2, · line 320

Quoted 7 lines
net/mptcp/protocol.h +3 -4
-int mptcp_pm_addr_signal(struct mptcp_sock *msk, u8 *id,
-			 struct sockaddr_storage *saddr);
-int mptcp_pm_get_local_id(struct request_sock *req, struct sock *sk,
-			  const struct sk_buff *skb);
+bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
+			  struct mptcp_addr_info *saddr);
+int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);

I guess I will see that in another patch but why "struct sock_common" instead of "struc sock"?

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
author
#4 lore raw

[MPTCP] Re: [PATCH v3 2/9] Squash-to: "mptcp: Add path manager interface"

Quoted 42 lines · Matthieu Baerts

Hi Paolo,

Thank you for looking at that!

Quoted 34 lines · Paolo Abeni

Factor out PM addr info to simplify PM data definition and simplify the PM hooks/APIs.

The PM will carry a single local and remote addrs - the one currently being processed, if any. It's up to the PM impl, e.g. netlink, maintain additional per msk data, if needed.

Account the number of created subflow and received addresses, to enforce limits.

Add a spinlock to protect PM datas, so that we can manipulate them from subflow BH.

Delegate events handling to a workqueue, so that PM events can be processed with both the above spinlock and the msk socket lock held. The PM impl should hook inside the worker.

v1 -> v2:
- be sure to initialize the address port before calling

    mptcp_pm_add_addr()
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
  net/mptcp/options.c  |  46 ++++++++++--------
  net/mptcp/pm.c       | 112 ++++++++++++++-----------------------------
  net/mptcp/protocol.c |   2 +
  net/mptcp/protocol.h |  98 ++++++++++++++++++++++---------------
  4 files changed, 123 insertions(+), 135 deletions(-)
net/mptcp/pm.c +0 -0
index c9f508451f2e..08f00f251838 100644
@@ -8,38 +8,22 @@

[...]

Quoted 12 lines

net/mptcp/pm.c void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id) · line 99

Quoted 10 lines
net/mptcp/pm.c +10 -0
+void mptcp_pm_data_init(struct mptcp_sock *msk)
+{
+	msk->pm.add_addr_signaled = 0;
+	msk->pm.add_addr_accepted = 0;
+	msk->pm.local_addr_used = 0;
+	WRITE_ONCE(msk->pm.work_pending, false);
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	WRITE_ONCE(msk->pm.fully_established, false);
+	WRITE_ONCE(msk->pm.accept_addr, false);
+	msk->pm.status = MPTCP_PM_IDLE;

Just by curiosity, why do we need to reset those fields to 0? Is this msk not already init to 0? Can we not memset the whole pm part?

Uhm... we don't need that for sk_alloc(), but we need the above after mptcp_sk_clone_lock().

memset() could be more efficient than direct assigment if clearing a wider memory area, see 236222d39347e0e486010f10c1493e83dbbdfba8.

For a bunch of fields we are better off explicitly setting them, I think.

Quoted 10 lines

net/mptcp/pm.c

Quoted 7 lines
net/mptcp/pm.c +3 -4
-int mptcp_pm_addr_signal(struct mptcp_sock *msk, u8 *id,
-			 struct sockaddr_storage *saddr);
-int mptcp_pm_get_local_id(struct request_sock *req, struct sock *sk,
-			  const struct sk_buff *skb);
+bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
+			  struct mptcp_addr_info *saddr);
+int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);

I guess I will see that in another patch but why "struct sock_common" instead of "struc sock"?

I guess you are already there, anyway mptcp_pm_get_local_id() must be called on both request_sock and tcp_sock.

Cheers,

Paolo

#5 lore raw

[MPTCP] Re: [PATCH v3 2/9] Squash-to: "mptcp: Add path manager interface"

Hi Paolo,

Quoted 56 lines · Paolo Abeni
Quoted 42 lines · Matthieu Baerts

Hi Paolo,

Thank you for looking at that!

Quoted 34 lines · Paolo Abeni

Factor out PM addr info to simplify PM data definition and simplify the PM hooks/APIs.

The PM will carry a single local and remote addrs - the one currently being processed, if any. It's up to the PM impl, e.g. netlink, maintain additional per msk data, if needed.

Account the number of created subflow and received addresses, to enforce limits.

Add a spinlock to protect PM datas, so that we can manipulate them from subflow BH.

Delegate events handling to a workqueue, so that PM events can be processed with both the above spinlock and the msk socket lock held. The PM impl should hook inside the worker.

v1 -> v2:
- be sure to initialize the address port before calling

     mptcp_pm_add_addr()
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
   net/mptcp/options.c  |  46 ++++++++++--------
   net/mptcp/pm.c       | 112 ++++++++++++++-----------------------------
   net/mptcp/protocol.c |   2 +
   net/mptcp/protocol.h |  98 ++++++++++++++++++++++---------------
   4 files changed, 123 insertions(+), 135 deletions(-)
net/mptcp/pm.c +0 -0
index c9f508451f2e..08f00f251838 100644
@@ -8,38 +8,22 @@

[...]

Quoted 12 lines

net/mptcp/pm.c void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id) · line 99

Quoted 10 lines
net/mptcp/pm.c +10 -0
+void mptcp_pm_data_init(struct mptcp_sock *msk)
+{
+	msk->pm.add_addr_signaled = 0;
+	msk->pm.add_addr_accepted = 0;
+	msk->pm.local_addr_used = 0;
+	WRITE_ONCE(msk->pm.work_pending, false);
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	WRITE_ONCE(msk->pm.fully_established, false);
+	WRITE_ONCE(msk->pm.accept_addr, false);
+	msk->pm.status = MPTCP_PM_IDLE;

Just by curiosity, why do we need to reset those fields to 0? Is this msk not already init to 0? Can we not memset the whole pm part?

Quoted 2 lines

Uhm... we don't need that for sk_alloc(), but we need the above after mptcp_sk_clone_lock().

Oh OK, thank you for the clarification!

Quoted 2 lines

memset() could be more efficient than direct assigment if clearing a wider memory area, see 236222d39347e0e486010f10c1493e83dbbdfba8.

Thank you for the pointer and for the tests you did before :)

Quoted 2 lines

For a bunch of fields we are better off explicitly setting them, I think.

Fine for me, as long as we don't forget one!

Quoted 11 lines
Quoted 10 lines

net/mptcp/pm.c

Quoted 7 lines
net/mptcp/pm.c +3 -4
-int mptcp_pm_addr_signal(struct mptcp_sock *msk, u8 *id,
-			 struct sockaddr_storage *saddr);
-int mptcp_pm_get_local_id(struct request_sock *req, struct sock *sk,
-			  const struct sk_buff *skb);
+bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
+			  struct mptcp_addr_info *saddr);
+int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);

I guess I will see that in another patch but why "struct sock_common" instead of "struc sock"?

Quoted 2 lines

I guess you are already there, anyway mptcp_pm_get_local_id() must be called on both request_sock and tcp_sock.

Yes sorry, I was looking in the new PM netlink but the answer was in the next patch :)

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
author
#6 lore raw

PATCH v3 3/9 Squash-to: "mptcp: Add handling of incoming MP_JOIN requests"

In reply to Paolo Abeni

Update mptcp_pm_get_local_id() callers to new API.

Hook mptcp_pm_subflow_established() when MP_JOIN completes successfully

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c | 7 +++++--
 net/mptcp/subflow.c | 5 ++++-
 2 files changed, 9 insertions(+), 3 deletions(-)
net/mptcp/options.c +5 -2
index 5047755baf0d..1b7681885ace 100644
@@ -128,7 +128,6 @@ void mptcp_parse_option(const struct sk_buff *skb, const unsigned char *ptr,
 		}
 		break;
 
-
 	case MPTCPOPT_DSS:
 		pr_debug("DSS");
 		ptr++;
@@ -565,8 +564,12 @@ static bool check_fourth_ack(struct mptcp_subflow_context *subflow,
 		   TCP_SKB_CB(skb)->seq != subflow->ssn_offset + 1))
 		return true;
 
-	if (mp_opt->use_ack)
+	if (mp_opt->use_ack) {
 		subflow->fourth_ack = 1;
+		if (subflow->mp_join)
+			mptcp_pm_subflow_established(mptcp_sk(subflow->conn),
+						     subflow);
+	}
 
 	if (subflow->can_ack)
 		return true;
net/mptcp/subflow.c +4 -1
index a8dedbd8d458..5710b439e418 100644
@@ -55,6 +55,7 @@ static bool subflow_token_join_request(struct request_sock *req,
 	struct mptcp_subflow_request_sock *subflow_req = mptcp_subflow_rsk(req);
 	u8 hmac[MPTCPOPT_HMAC_LEN];
 	struct mptcp_sock *msk;
+	int local_id;
 
 	msk = mptcp_token_get_sock(subflow_req->token);
 	if (!msk) {
@@ -63,10 +64,12 @@ static bool subflow_token_join_request(struct request_sock *req,
 		return false;
 	}
 
-	if (mptcp_pm_get_local_id(req, (struct sock *)msk, skb)) {
+	local_id = mptcp_pm_get_local_id(msk, (struct sock_common *)req);
+	if (local_id < 0) {
 		sock_put((struct sock *)msk);
 		return false;
 	}
+	subflow_req->local_id = local_id;
 
 	get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
 
Signature · 1 line
2.21.1
author
#7 lore raw

PATCH v3 4/9 Squash-to: "mptcp: Add handling of outgoing MP_JOIN requests"

In reply to Paolo Abeni

record local id for outgoing MP_JOIN connection.

join_id is the local address id, set as such in mptcp_syn_options()

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c  |  2 +-
 net/mptcp/protocol.h |  7 ++++--
 net/mptcp/subflow.c  | 60 ++++++++++++++++++++++++++++++++------------
 3 files changed, 50 insertions(+), 19 deletions(-)
net/mptcp/options.c +1 -1
index b09d1136f945..961617a16fae 100644
@@ -309,7 +309,7 @@ bool mptcp_syn_options(struct sock *sk, const struct sk_buff *skb,
 		pr_debug("remote_token=%u, nonce=%u", subflow->remote_token,
 			 subflow->local_nonce);
 		opts->suboptions = OPTION_MPTCP_MPJ_SYN;
-		opts->join_id = subflow->remote_id;
+		opts->join_id = subflow->local_id;
 		opts->token = subflow->remote_token;
 		opts->nonce = subflow->local_nonce;
 		opts->backup = subflow->request_bkup;
net/mptcp/protocol.h +5 -2
index 9cd7e94a41ee..c4d935330cac 100644
@@ -256,8 +256,11 @@ mptcp_subflow_get_mapped_dsn(const struct mptcp_subflow_context *subflow)
 int mptcp_is_enabled(struct net *net);
 bool mptcp_subflow_data_available(struct sock *sk);
 void mptcp_subflow_init(void);
-int mptcp_subflow_connect(struct sock *sk, struct sockaddr *local,
-			  struct sockaddr *remote, u8 remote_id);
+
+/* called with sk socket lock held */
+int __mptcp_subflow_connect(struct sock *sk, int ifindex,
+			    const struct mptcp_addr_info *loc,
+			    const struct mptcp_addr_info *remote);
 int mptcp_subflow_create_socket(struct sock *sk, struct socket **new_sock);
 
 static inline void mptcp_subflow_tcp_fallback(struct sock *sk,
net/mptcp/subflow.c +44 -16

122 lines not on this page · raw message

Signature · 1 line
2.21.1
author
#8 lore raw

PATCH v3 5/9 Squash-to: "mptcp: Implement path manager interface commands"

In reply to Paolo Abeni

Implement stubs for PM events delegating the action to the work queue. This allows acquiring whatever lock is needed to perform the actual implementation.

Try to avoid scheduling the worker if no action is needed/possible. I relies on the accounting info included into the PM struct and on great deal of double-checked locking [anti-]pattern.

v1 -> v2:
- fix several issues in mptcp_pm_addr_signal()

RFC -> v1:
- simplify/cleanup mptcp_pm_work_pending() - Mat
- likewise simplify/cleanup mptcp_pm_add_addr()

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/pm.c | 223 +++++++++++++++++++------------------------------
 1 file changed, 86 insertions(+), 137 deletions(-)
net/mptcp/pm.c +86 -137
index 30bce85adda1..d6e60b4bdb56 100644
@@ -15,147 +15,17 @@ static struct workqueue_struct *pm_wq;
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 			   const struct mptcp_addr_info *addr)
 {
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	int err = 0;
+	pr_debug("msk=%p, local_id=%d", msk, addr->id);
 
-	if (!msk)
-		return -EINVAL;
-
-	if (msk->pm.local_valid) {
-		err = -EBADR;
-		goto announce_put;
-	}
-
-	pr_debug("msk=%p, local_id=%d", msk, local_id);
-	msk->pm.local_valid = 1;
-	msk->pm.local_id = local_id;
-	msk->pm.local_family = AF_INET;
-	msk->pm.local_addr = *addr;
-	msk->addr_signal = 1;
-
-announce_put:
-	sock_put((struct sock *)msk);
-	return err;
-}
-
-#if IS_ENABLED(CONFIG_MPTCP_IPV6)
-int mptcp_pm_announce_addr6(u32 token, u8 local_id, struct in6_addr *addr)
-{
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	int err = 0;
-
-	if (!msk)
-		return -EINVAL;
-
-	if (msk->pm.local_valid) {
-		err = -EBADR;
-		goto announce_put;
-	}
-
-	pr_debug("msk=%p, local_id=%d", msk, local_id);
-	msk->pm.local_valid = 1;
-	msk->pm.local_id = local_id;
-	msk->pm.local_family = AF_INET6;
-	msk->pm.local_addr6 = *addr;
-	msk->addr_signal = 1;
-
-announce_put:
-	sock_put((struct sock *)msk);
-	return err;
-}
-#endif
-
-int mptcp_pm_remove_addr(u32 token, u8 local_id)
-{
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-
-	if (!msk)
-		return -EINVAL;
-
-	pr_debug("msk=%p", msk);
-	msk->pm.local_valid = 0;
-
-	sock_put((struct sock *)msk);
+	msk->pm.local = *addr;
+	WRITE_ONCE(msk->pm.addr_signal, true);
 	return 0;
 }
 
-int mptcp_pm_create_subflow(u32 token, u8 remote_id, struct in_addr *addr)
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
 {
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	struct sockaddr_in remote;
-	struct sockaddr_in local;
-	struct sock *sk;
-	int err;
-
-	if (!msk)
-		return -EINVAL;
-
-	pr_debug("msk=%p", msk);
-
-	sk = (struct sock *)msk;
-	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
-		err = -EBADR;
-		goto create_put;
-	}
-
-	local.sin_family = AF_INET;
-	local.sin_port = 0;
-	if (addr)
-		local.sin_addr = *addr;
-	else
-		local.sin_addr.s_addr = htonl(INADDR_ANY);
-
-	remote.sin_family = msk->pm.remote_family;
-	remote.sin_port = inet_sk(sk)->inet_dport;
-	remote.sin_addr = msk->pm.remote_addr;
-
-	err = mptcp_subflow_connect(sk, (struct sockaddr *)&local,
-				    (struct sockaddr *)&remote, remote_id);
-
-create_put:
-	sock_put(sk);
-	return err;
-}
-
-#if IS_ENABLED(CONFIG_MPTCP_IPV6)
-int mptcp_pm_create_subflow6(u32 token, u8 remote_id, struct in6_addr *addr)
-{
-	struct mptcp_sock *msk = mptcp_token_get_sock(token);
-	struct sockaddr_in6 remote;
-	struct sockaddr_in6 local;
-	struct sock *sk;
-	int err;
-
-	if (!msk)
-		return -EINVAL;
-
-	pr_debug("msk=%p", msk);
-	sk = (struct sock *)msk;
-
-	if (!msk->pm.remote_valid || remote_id != msk->pm.remote_id) {
-		err = -EBADR;
-		goto create_put;
-	}
-
-	local.sin6_family = AF_INET6;
-	local.sin6_port = 0;
-	if (addr)
-		local.sin6_addr = *addr;
-	else
-		local.sin6_addr = in6addr_any;
-
-	remote.sin6_family = msk->pm.remote_family;
-	remote.sin6_port = inet_sk(sk)->inet_dport;
-	remote.sin6_addr = msk->pm.remote_addr6;
-
-	err = mptcp_subflow_connect(sk, (struct sockaddr *)&local,
-				    (struct sockaddr *)&remote, remote_id);
-
-create_put:
-	sock_put(sk);
-	return err;
+	return -ENOTSUPP;
 }
-#endif
 
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 remote_id)
 {
@@ -173,11 +43,36 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side)
 	WRITE_ONCE(pm->server_side, server_side);
 }
 
+static bool mptcp_pm_schedule_work(struct mptcp_sock *msk,
+				   enum mptcp_pm_status new_status)
+{
+	if (msk->pm.status != MPTCP_PM_IDLE)
+		return false;
+
+	if (queue_work(pm_wq, &msk->pm.work)) {
+		msk->pm.status = new_status;
+		sock_hold((struct sock *)msk);
+		return true;
+	}
+	return false;
+}
+
 void mptcp_pm_fully_established(struct mptcp_sock *msk)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
 
 	pr_debug("msk=%p", msk);
+
+	/* try to avoid acquiring the lock below */
+	if (READ_ONCE(pm->fully_established))
+		return;
+
+	spin_lock_bh(&pm->lock);
+	if (!READ_ONCE(pm->fully_established) &&
+	    mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED))
+		WRITE_ONCE(pm->fully_established, true);
+
+	spin_unlock_bh(&pm->lock);
 }
 
 void mptcp_pm_connection_closed(struct mptcp_sock *msk)
@@ -188,7 +83,19 @@ void mptcp_pm_connection_closed(struct mptcp_sock *msk)
 void mptcp_pm_subflow_established(struct mptcp_sock *msk,
 				  struct mptcp_subflow_context *subflow)
 {
+	struct mptcp_pm_data *pm = &msk->pm;
+
 	pr_debug("msk=%p", msk);
+
+	if (!READ_ONCE(pm->work_pending))
+		return;
+
+	spin_lock_bh(&pm->lock);
+
+	if (READ_ONCE(pm->work_pending))
+		mptcp_pm_schedule_work(msk, MPTCP_PM_SUBFLOW_ESTABLISHED);
+
+	spin_unlock_bh(&pm->lock);
 }
 
 void mptcp_pm_subflow_closed(struct mptcp_sock *msk, u8 id)
@@ -201,7 +108,21 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
 {
 	struct mptcp_pm_data *pm = &msk->pm;
 
-	pr_debug("msk=%p, remote_id=%d", msk, addr->id);
+	pr_debug("msk=%p remote_id=%d accept=%d", msk, addr->id,
+		 READ_ONCE(pm->accept_addr));
+
+	/* avoid acquiring the lock if there is no room for fouther addresses */
+	if (!READ_ONCE(pm->accept_addr))
+		return;
+
+	spin_lock_bh(&pm->lock);
+
+	/* be sure there is something to signal re-checking under PM lock */
+	if (READ_ONCE(pm->accept_addr) &&
+	    mptcp_pm_schedule_work(msk, MPTCP_PM_ADD_ADDR))
+		pm->remote = *addr;
+
+	spin_unlock_bh(&pm->lock);
 }
 
 /* path manager helpers */
@@ -209,7 +130,24 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
 bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			  struct mptcp_addr_info *saddr)
 {
-	return false;
+	int ret = false;
+
+	spin_lock_bh(&msk->pm.lock);
+
+	/* double check after the lock is acquired */
+	if (!mptcp_pm_should_signal(msk))
+		goto out_unlock;
+
+	if (remaining < mptcp_add_addr_len(msk->pm.local.family))
+		goto out_unlock;
+
+	*saddr = msk->pm.local;
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	ret = true;
+
+out_unlock:
+	spin_unlock_bh(&msk->pm.lock);
+	return ret;
 }
 
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
@@ -219,6 +157,17 @@ int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 
 static void pm_worker(struct work_struct *work)
 {
+	struct mptcp_pm_data *pm = container_of(work, struct mptcp_pm_data,
+						work);
+	struct mptcp_sock *msk = container_of(pm, struct mptcp_sock, pm);
+	struct sock *sk = (struct sock *)msk;
+
+	switch (READ_ONCE(pm->status)) {
+	default:
+		break;
+	}
+
+	sock_put(sk);
 }
 
 void mptcp_pm_data_init(struct mptcp_sock *msk)
Signature · 1 line
2.21.1
#9 lore raw

[MPTCP] Re: [PATCH v3 5/9] Squash-to: "mptcp: Implement path manager interface commands"

Hi Paolo,

Quoted 38 lines · Paolo Abeni

Implement stubs for PM events delegating the action to the work queue. This allows acquiring whatever lock is needed to perform the actual implementation.

Try to avoid scheduling the worker if no action is needed/possible. I relies on the accounting info included into the PM struct and on great deal of double-checked locking [anti-]pattern.

v1 -> v2:
- fix several issues in mptcp_pm_addr_signal()

RFC -> v1:
- simplify/cleanup mptcp_pm_work_pending() - Mat
- likewise simplify/cleanup mptcp_pm_add_addr()

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
  net/mptcp/pm.c | 223 +++++++++++++++++++------------------------------
  1 file changed, 86 insertions(+), 137 deletions(-)
net/mptcp/pm.c +9 -1
index 30bce85adda1..d6e60b4bdb56 100644
@@ -209,7 +130,24 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
  bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
  			  struct mptcp_addr_info *saddr)
  {
-	return false;
+	int ret = false;
+
+	spin_lock_bh(&msk->pm.lock);
+
+	/* double check after the lock is acquired */
+	if (!mptcp_pm_should_signal(msk))
+		goto out_unlock;
+
+	if (remaining < mptcp_add_addr_len(msk->pm.local.family))

net/mptcp/pm.c void mptcp_pm_add_addr(struct mptcp_sock *msk, · line 151

Quoted 10 lines
net/mptcp/pm.c +9 -0
+		goto out_unlock;
+
+	*saddr = msk->pm.local;
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	ret = true;
+
+out_unlock:
+	spin_unlock_bh(&msk->pm.lock);
+	return ret;
  }

I would still need to digest this new code (and look at the next patches) but if a PM has to announce more than one ADD_ADDR, would it be notified when the first one has been sent? To know when it can call mptcp_pm_announce_addr() again.

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
author
#10 lore raw

[MPTCP] Re: [PATCH v3 5/9] Squash-to: "mptcp: Implement path manager interface commands"

Quoted 48 lines · Matthieu Baerts

Hi Paolo,

Quoted 45 lines · Paolo Abeni

Implement stubs for PM events delegating the action to the work queue. This allows acquiring whatever lock is needed to perform the actual implementation.

Try to avoid scheduling the worker if no action is needed/possible. I relies on the accounting info included into the PM struct and on great deal of double-checked locking [anti-]pattern.

v1 -> v2:
- fix several issues in mptcp_pm_addr_signal()

RFC -> v1:
- simplify/cleanup mptcp_pm_work_pending() - Mat
- likewise simplify/cleanup mptcp_pm_add_addr()

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
  net/mptcp/pm.c | 223 +++++++++++++++++++------------------------------
  1 file changed, 86 insertions(+), 137 deletions(-)
net/mptcp/pm.c +16 -1
index 30bce85adda1..d6e60b4bdb56 100644
@@ -209,7 +130,24 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
  bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
  			  struct mptcp_addr_info *saddr)
  {
-	return false;
+	int ret = false;
+
+	spin_lock_bh(&msk->pm.lock);
+
+	/* double check after the lock is acquired */
+	if (!mptcp_pm_should_signal(msk))
+		goto out_unlock;
+
+	if (remaining < mptcp_add_addr_len(msk->pm.local.family))
+		goto out_unlock;
+
+	*saddr = msk->pm.local;
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	ret = true;
+
+out_unlock:
Quoted 8 lines

net/mptcp/pm.c void mptcp_pm_add_addr(struct mptcp_sock *msk, · line 151

Quoted 3 lines
net/mptcp/pm.c +2 -0
+	spin_unlock_bh(&msk->pm.lock);
+	return ret;
  }

I would still need to digest this new code (and look at the next patches) but if a PM has to announce more than one ADD_ADDR, would it be notified when the first one has been sent? To know when it can call mptcp_pm_announce_addr() again.

Good question :) Currently we don't have yet the infrastructure for such notification. I think we could add that on top of reliable add_addr delivery: we can attach the next addr signaling to 'add_addr echo' opt reception.

I tried to keep the NL APIs/infrastructure generic enough to adjust the above.

Cheers,

Paolo

#11 lore raw

[MPTCP] Re: [PATCH v3 5/9] Squash-to: "mptcp: Implement path manager interface commands"

Hi Paolo,

Quoted 58 lines · Paolo Abeni
Quoted 48 lines · Matthieu Baerts

Hi Paolo,

Quoted 45 lines · Paolo Abeni

Implement stubs for PM events delegating the action to the work queue. This allows acquiring whatever lock is needed to perform the actual implementation.

Try to avoid scheduling the worker if no action is needed/possible. I relies on the accounting info included into the PM struct and on great deal of double-checked locking [anti-]pattern.

v1 -> v2:
- fix several issues in mptcp_pm_addr_signal()

RFC -> v1:
- simplify/cleanup mptcp_pm_work_pending() - Mat
- likewise simplify/cleanup mptcp_pm_add_addr()

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
   net/mptcp/pm.c | 223 +++++++++++++++++++------------------------------
   1 file changed, 86 insertions(+), 137 deletions(-)
net/mptcp/pm.c +16 -1
index 30bce85adda1..d6e60b4bdb56 100644
@@ -209,7 +130,24 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
   bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
   			  struct mptcp_addr_info *saddr)
   {
-	return false;
+	int ret = false;
+
+	spin_lock_bh(&msk->pm.lock);
+
+	/* double check after the lock is acquired */
+	if (!mptcp_pm_should_signal(msk))
+		goto out_unlock;
+
+	if (remaining < mptcp_add_addr_len(msk->pm.local.family))
+		goto out_unlock;
+
+	*saddr = msk->pm.local;
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	ret = true;
+
+out_unlock:
Quoted 8 lines

net/mptcp/pm.c void mptcp_pm_add_addr(struct mptcp_sock *msk, · line 151

Quoted 3 lines
net/mptcp/pm.c +2 -0
+	spin_unlock_bh(&msk->pm.lock);
+	return ret;
   }

I would still need to digest this new code (and look at the next patches) but if a PM has to announce more than one ADD_ADDR, would it be notified when the first one has been sent? To know when it can call mptcp_pm_announce_addr() again.

Quoted 4 lines

Good question :) Currently we don't have yet the infrastructure for such notification. I think we could add that on top of reliable add_addr delivery: we can attach the next addr signaling to 'add_addr echo' opt reception.

Good idea! I forgot about the ADD_ADDRv1!

Quoted 2 lines

I tried to keep the NL APIs/infrastructure generic enough to adjust the above.

That's good, thank you for that!

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
author
#12 lore raw

PATCH v3 6/9 Squash-to: subflow: place further subflows on new 'join_list'

In reply to Paolo Abeni

mptcp_finish_join() may race with __mptcp_subflow_connect(). If mptcp_finish_join() completes before we reach the list_add_tail() call in __mptcp_subflow_connect() we get a data corruption due to double list add.

We need add to join_list only passive sockets, so fix the above avoiding the add for client socks.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/protocol.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
net/mptcp/protocol.c +5 -7
index f753cd1884fe..59f76d97237a 100644
@@ -1400,16 +1400,14 @@ bool mptcp_finish_join(struct sock *sk)
 		return false;
 
 	parent_sock = READ_ONCE(parent->sk_socket);
-	if (parent_sock) {
-		if (!sk->sk_socket)
-			mptcp_sock_graft(sk, parent_sock);
+	if (parent_sock && !sk->sk_socket) {
+		mptcp_sock_graft(sk, parent_sock);
 
 		/* active connections are already on conn_list */
-		if (list_empty(&subflow->node)) {
-			spin_lock_bh(&msk->join_list_lock);
+		spin_lock_bh(&msk->join_list_lock);
+		if (!WARN_ON_ONCE(!list_empty(&subflow->node)))
 			list_add_tail(&subflow->node, &msk->join_list);
-			spin_unlock_bh(&msk->join_list_lock);
-		}
+		spin_unlock_bh(&msk->join_list_lock);
 	}
 	return true;
 }
Signature · 1 line
2.21.1
author
#13 lore raw

PATCH v3 7/9 mptcp: add netlink based PM

In reply to Paolo Abeni

Expose to U/S a netlink family to control the PM, setting:

- list of local addresses to be signaled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react

When the msk is fully established, the PM netlink attempts to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.

After exausting the 'local' list, the PM tries to announce the 'signal' list via the ADD_ADDR option. Since we currenlty lack the ADD_ADDR echo (and related event) only the first addr is sent.

Idea is to add an additional PM hook for ADD_ADDR echo, to allow the PM netlink announcing multiple addresses, in sequence.

v1 -> v2:
- explicitly reset pm status to idle after processing a command
- fix msk pm initialization
- fix mptcp_pm_nl_add_addr bugs
- added ifindex support
- hopefully clearer local function names
- always use IS_ENABLED(CONFIG_MPTCP_IPV6) instead of IS_ENABLED(CONFIG_IPV6)

RFC -> v1:
- simplified NL API
- reduced {WRITE,READ}_ONCE boilerplate due to PM changes
- add check for duplicate addresses

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 include/uapi/linux/mptcp.h |  53 +++
 net/mptcp/Makefile         |   3 +-
 net/mptcp/pm.c             |  18 +-
 net/mptcp/pm_netlink.c     | 828 +++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h       |   7 +
 5 files changed, 907 insertions(+), 2 deletions(-)
 create mode 100644 net/mptcp/pm_netlink.c
include/uapi/linux/mptcp.h +53 -0
index 3912a9808fa2..8990c564680d 100644
@@ -31,4 +31,57 @@ enum {
 };
 
 #define MPTCP_SUBFLOW_MAX (__MPTCP_SUBFLOW_MAX - 1)
+
+/* netlink interface */
+#define MPTCP_PM_NAME		"mptcp_pm"
+#define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_VER		0x1
+
+/*
+ * ATTR types defined for MPTCP
+ */
+enum mptcp_pm_attrs {
+	MPTCP_PM_ATTR_UNSPEC,
+
+	MPTCP_PM_ATTR_ADDR,				/* nested address */
+	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
+
+	__MPTCP_PM_ATTR_MAX
+};
+
+#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
+
+enum mptcp_pm_addr_addrs {
+	MPTCP_PM_ADDR_ATTR_UNSPEC,
+
+	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_ID,				/* u8 */
+	MPTCP_PM_ADDR_ATTR_ADDR4,			/* struct in_addr */
+	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
+	MPTCP_PM_ADDR_ATTR_PORT,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
+	MPTCP_PM_ADDR_ATTR_IF_IDX,			/* s32 */
+
+	__MPTCP_PM_ADDR_ATTR_MAX
+};
+
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+#define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
+#define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
+#define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)
+
+enum {
+	MPTCP_CMD_UNSPEC,
+
+	MPTCP_CMD_ADD_ADDR,
+	MPTCP_CMD_DEL_ADDR,
+	MPTCP_CMD_GET_ADDR,
+	MPTCP_CMD_FLUSH_ADDRS,
+	MPTCP_CMD_SET_RCV_ADD_ADDRS,
+	MPTCP_CMD_GET_RCV_ADD_ADDRS,
+
+	__MPTCP_CMD_AFTER_LAST
+};
+
 #endif /* _UAPI_MPTCP_H */
net/mptcp/Makefile +2 -1
index faebe8ec9f73..baa0640527c7 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o mib.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
+	   mib.o pm_netlink.o
net/mptcp/pm.c +17 -1
index d6e60b4bdb56..1d26e9851689 100644
@@ -152,7 +152,7 @@ bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 {
-	return 0;
+	return mptcp_pm_nl_get_local_id(msk, skc);
 }
 
 static void pm_worker(struct work_struct *work)
@@ -163,6 +163,18 @@ static void pm_worker(struct work_struct *work)
 	struct sock *sk = (struct sock *)msk;
 
 	switch (READ_ONCE(pm->status)) {
+	case MPTCP_PM_ADD_ADDR:
+		mptcp_pm_nl_add_addr(msk);
+		break;
+
+	case MPTCP_PM_ESTABLISHED:
+		mptcp_pm_nl_fully_established(msk);
+		break;
+
+	case MPTCP_PM_SUBFLOW_ESTABLISHED:
+		mptcp_pm_nl_subflow_established(msk);
+		break;
+
 	default:
 		break;
 	}
@@ -183,6 +195,8 @@ void mptcp_pm_data_init(struct mptcp_sock *msk)
 
 	spin_lock_init(&msk->pm.lock);
 	INIT_WORK(&msk->pm.work, pm_worker);
+
+	mptcp_pm_nl_data_init(msk);
 }
 
 void mptcp_pm_init(void)
@@ -190,4 +204,6 @@ void mptcp_pm_init(void)
 	pm_wq = alloc_workqueue("pm_wq", WQ_UNBOUND | WQ_MEM_RECLAIM, 8);
 	if (!pm_wq)
 		panic("Failed to allocate workqueue");
+
+	mptcp_pm_nl_init();
 }
net/mptcp/pm_netlink.c new file +828 -0

828 lines not on this page · raw message

net/mptcp/protocol.h +7 -0
index 5111b191a726..ea916aa22ae4 100644
@@ -391,6 +391,13 @@ bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			  struct mptcp_addr_info *saddr);
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 
+void mptcp_pm_nl_init(void);
+void mptcp_pm_nl_data_init(struct mptcp_sock *msk);
+void mptcp_pm_nl_fully_established(struct mptcp_sock *msk);
+void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk);
+void mptcp_pm_nl_add_addr(struct mptcp_sock *msk);
+int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
+
 static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
 {
 	return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);
Signature · 1 line
2.21.1
#14 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Hi Paolo,

As always, it is very good! Sorry for the delay but here are various questions and comments.

Note that I didn't really pay attention at how the locks were used, I would be glad if someone could look at this specific point. I focused my review more on the exposed API, general behaviour, Netlink stuff and typos.

Quoted 5 lines · Paolo Abeni

Expose to U/S a netlink family to control the PM, setting:

- list of local addresses to be signaled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react

It looks a bit strange to me to limit in term of ADD_ADDR. I see that all commands are linked to addresses which seem to make sense but I don't know if it is good for a generic PM.

Depending on the strategy, you might create and accept more or less subflows using the same list of local and remote addresses:

- a client with a fullmesh strategy will create a subflow from each
local address to each remote ones having the same IP family. So if the client and the server have each 2 (reachable) IPv4 A and B, there will be 4 subflows: A-A, A-B, B-A, B-B.

- another strategy could be like the fullmesh one but using each IP
only once: A-A, B-B

- slightly different: create one subflow per network interface (from
the client, it is hard to know what the server has): both client and server can have 2 NIC with one IPv4 and one v6 per NIC. The server will announce the v4 and v6 of the other NIC and the client will use one IP per interface: A4-A4, B4/6-B4/6 but not A4-A4, A6-A/B6, B4-B4, B6-B/A6 like we would have with the previous strategy.

- there are plenty of strategies for the client, e.g. ndiffport (more
subflows using the same IPs but different ports), etc. Many strategies will be dedicated to one specific use-case, then requiring a more advanced Netlink PM like the one in mptcp.org with mptcpd.

- on the server side, I think there are less strategies. Of course,
some might require a more advanced Netlink

net/mptcp/protocol.h bool mptcp_pm_addr_signal(struct mptcp_sock

Quoted 6 lines
(quoted diff) +1 -0
+}
net/mptcp/protocol.h +0 -0
index 5111b191a726..ea916aa22ae4 100644
@@ -391,6 +391,13 @@ bool mptcp_pm_addr_signal(struct mptcp_sock 

*msk, unsigned int remaining,

net/mptcp/protocol.h bool mptcp_pm_addr_signal(struct mptcp_sock · line 392

Quoted 2 lines
net/mptcp/protocol.h +0 -0
  			  struct mptcp_addr_info *saddr);
  int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct 

sock_common *skc);

net/mptcp/protocol.h bool mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,

Quoted 7 lines
net/mptcp/protocol.h +6 -0
+void mptcp_pm_nl_init(void);
+void mptcp_pm_nl_data_init(struct mptcp_sock *msk);
+void mptcp_pm_nl_fully_established(struct mptcp_sock *msk);
+void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk);
+void mptcp_pm_nl_add_addr(struct mptcp_sock *msk);
+int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct 

sock_common *skc);

Quoted 5 lines
net/mptcp/protocol.h +1 -0
+
  static inline struct mptcp_ext *mptcp_get_ext(struct sk_buff *skb)
  {
  	return (struct mptcp_ext *)skb_ext_find(skb, SKB_EXT_MPTCP);

PM but most of the time, the server's job is to announce addresses

and accept (or reject) subflows.

Also, another point: the client doesn't really have to send ADD_ADDR to the server. The server could then receive MP_JOIN from IPs that are new to the server, i.e. not announced by the client with ADD_ADDR.

Now, after having mentioned all these points, I think it can be interesting to:

- continue to manage addresses that can be announced / used to create
subflows.

- continue to pick a single strategy for the moment. Maybe best to
start with fullmesh and if needed, the userspace can block some combinations using NFTables (I almost wrote IPTables :-o). This can be extended later by adding more strategies but I think we can already do many things if the userspace selects which additional addresses to use.

- instead of having a maximum number of received ADD_ADDR that can
use, it might be more generic to limit the number of created/accepted subflows per MPTCP connection. If needed, this can be extended later with other limits: number of subflow per interface or IP and per MPTCP connection.

In other words, compared to this patch, only modifying how the limits are managed to be more generic (I think).

What do you think about that?

Maybe you still want to keep a limit for the received ADD_ADDR? I don't think we store them for the moment? I guess MPTCP_PM_ADDR_MAX is enough for now for the limit.

Quoted 3 lines

When the msk is fully established, the PM netlink attempts to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.

I guess it does that only for the client (connect, not listen).

Quoted 2 lines

After exausting the 'local' list, the PM tries to announce the 'signal' list via the ADD_ADDR option. Since we currenlty lack

(detail, we can fix that later but: s/exausting/exhausting/ and s/currenlty/currently/ and s/signaled/signalled/ (or announced))

Quoted 1 line

the ADD_ADDR echo (and related event) only the first addr is sent.

It is not clear for me why the client has to announce addresses. But if it does that, it might be better to do it before creating additional subflows? The info in the ADD_ADDR sent by the clients could maybe be used in firewalls. Better to send them before then.

I guess we can change that later, it's not fixed with the API.

Quoted 2 lines
Quoted 1 line

Idea is to add an additional PM hook for ADD_ADDR echo, to allow

the PM netlink announcing multiple addresses, in sequence.

And later in parallel to avoid delays :-)

Quoted 29 lines

v1 -> v2:
- explicitly reset pm status to idle after processing a command
- fix msk pm initialization
- fix mptcp_pm_nl_add_addr bugs
- added ifindex support
- hopefully clearer local function names
- always use IS_ENABLED(CONFIG_MPTCP_IPV6) instead of IS_ENABLED(CONFIG_IPV6)

RFC -> v1:
- simplified NL API
- reduced {WRITE,READ}_ONCE boilerplate due to PM changes
- add check for duplicate addresses

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
  include/uapi/linux/mptcp.h |  53 +++
  net/mptcp/Makefile         |   3 +-
  net/mptcp/pm.c             |  18 +-
  net/mptcp/pm_netlink.c     | 828 +++++++++++++++++++++++++++++++++++++
  net/mptcp/protocol.h       |   7 +
  5 files changed, 907 insertions(+), 2 deletions(-)

create mode 100644 net/mptcp/pm_netlink.c

include/uapi/linux/mptcp.h +0 -0
index 3912a9808fa2..8990c564680d 100644

include/uapi/linux/mptcp.h enum { · line 33

Quoted 3 lines
include/uapi/linux/mptcp.h +0 -0
@@ -31,4 +31,57 @@ enum {
  };
 
  #define MPTCP_SUBFLOW_MAX (__MPTCP_SUBFLOW_MAX - 1)

Sorry, it's not linked to this patch but we should probably add "_ATTR" here (MPTCP_SUBFLOW_ATTR_MAX) and for all entries in the enum, because we could think here it is the maximum number of subflows we can have.

I can do the modification if it is not too late.

*Davide* : I guess no upstreamed version of ss are already using this, right? Anyway because this kernel code is not upstreamed, it's not too late to change, right? :)

include/uapi/linux/mptcp.h enum { · line 38

Quoted 5 lines
include/uapi/linux/mptcp.h +5 -0
+
+/* netlink interface */
+#define MPTCP_PM_NAME		"mptcp_pm"
+#define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_VER		0x1

Should we add "_NETLINK" or "_NL" here above, just in case we have additional PMs later?

MPTCP_PM_NL_NAME "mptcp_pm_netlink"

And maybe we should do the same below? e.g. "mptcp_pm_nl_attrs"

include/uapi/linux/mptcp.h enum { · line 44

Quoted 6 lines
include/uapi/linux/mptcp.h +6 -0
+
+/*
+ * ATTR types defined for MPTCP
+ */
+enum mptcp_pm_attrs {
+	MPTCP_PM_ATTR_UNSPEC,

Because this enum will be exposed to userspace, should we force the first item to be 0? (same below)
I guess most compiler will set it to 0 by default but I think the specs don't force them to do that.

(if yes, we should also do it for "MPTCP_SUBFLOW(_ATTR)_UNSPEC")

Quoted 7 lines
include/uapi/linux/mptcp.h +7 -0
+
+	MPTCP_PM_ATTR_ADDR,				/* nested address */
+	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
+
+	__MPTCP_PM_ATTR_MAX
+};
+

include/uapi/linux/mptcp.h enum { · line 61

Quoted 10 lines
include/uapi/linux/mptcp.h +10 -0
+#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
+
+enum mptcp_pm_addr_addrs {
+	MPTCP_PM_ADDR_ATTR_UNSPEC,
+
+	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_ID,				/* u8 */
+	MPTCP_PM_ADDR_ATTR_ADDR4,			/* struct in_addr */
+	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
+	MPTCP_PM_ADDR_ATTR_PORT,			/* u16 */

(It seems you are not using it)

include/uapi/linux/mptcp.h enum { · line 72

Quoted 11 lines
include/uapi/linux/mptcp.h +11 -0
+	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
+	MPTCP_PM_ADDR_ATTR_IF_IDX,			/* s32 */
+
+	__MPTCP_PM_ADDR_ATTR_MAX
+};
+
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+#define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
+#define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
+#define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)

detail and we can fix it later if needed: I guess checkpatch will ask us to use BIT(0), etc.

include/uapi/linux/mptcp.h enum { · line 85

Quoted 13 lines
include/uapi/linux/mptcp.h +13 -0
+
+enum {
+	MPTCP_CMD_UNSPEC,
+
+	MPTCP_CMD_ADD_ADDR,
+	MPTCP_CMD_DEL_ADDR,
+	MPTCP_CMD_GET_ADDR,
+	MPTCP_CMD_FLUSH_ADDRS,
+	MPTCP_CMD_SET_RCV_ADD_ADDRS,
+	MPTCP_CMD_GET_RCV_ADD_ADDRS,
+
+	__MPTCP_CMD_AFTER_LAST
+};

A detail but maybe important before it's too late: should we add "_PM" or "_PM_NL" in the list of commands?

Also it could be nice to add (later?) comments about the API: what does each command do, which (optional) parameters to use and what reply you will get (if any).

net/mptcp/Makefile line 5

Quoted 13 lines
include/uapi/linux/mptcp.h +1 -0
+
  #endif /* _UAPI_MPTCP_H */
net/mptcp/Makefile +2 -1
index faebe8ec9f73..baa0640527c7 100644
@@ -1,4 +1,5 @@
  # SPDX-License-Identifier: GPL-2.0
  obj-$(CONFIG_MPTCP) += mptcp.o
 
-mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o mib.o
+mptcp-y := protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o diag.o \
+	   mib.o pm_netlink.o

(detail: because we might want to do other modifications in mib.c, see above, should we also modify this commit to go to the new line in this commit?)

[...]

Quoted 29 lines
net/mptcp/pm_netlink.c new file +23 -0
new file mode 100644
index 000000000000..56847e16d206
@@ -0,0 +1,828 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Multipath TCP
+ *
+ * Copyright (c) 2020, Red Hat, Inc.
+ */
+
+#include <linux/inet.h>
+#include <linux/kernel.h>
+#include <net/tcp.h>
+#include <net/netns/generic.h>
+#include <net/mptcp.h>
+#include <net/genetlink.h>
+#include <uapi/linux/mptcp.h>
+
+#include "protocol.h"
+
+/* forward declaration */
+static struct genl_family mptcp_genl_family;
+
+static int pm_nl_pernet_id;
+
+struct mptcp_pm_addr_entry {
+	struct list_head	list;

net/mptcp/pm_netlink.c line 33

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	unsigned int		flags;
+	int			ifindex;
+	struct mptcp_addr_info	addr;
+	struct rcu_head		rcu;
+};
+
+struct pm_nl_pernet {
+	/* protects pernet updates */
+	spinlock_t		lock;
+	struct list_head	addr_list;

detail: maybe clearer with local_addr_list?

Should we not maintain a list of remote_add_addr?

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	unsigned int		addrs;
+	unsigned int		add_addr_signal_max;
+	unsigned int		add_addr_accept_max;
+	unsigned int		local_addr_max;
+	unsigned int		next_id;
+};
+
+#define MPTCP_PM_ADDR_MAX	8
+
+static bool addresses_equal(const struct mptcp_addr_info *a,

net/mptcp/pm_netlink.c line 53

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+			    struct mptcp_addr_info *b, bool use_port)
+{
+	bool addr_equals;
+
+	if (a->family != b->family)
+		return false;
+
+	if (a->family == AF_INET)
+		addr_equals = !memcmp(&a->addr, &b->addr, sizeof(b->addr));
+	else

You need to surround this block with:

   #if IS_ENABLED(CONFIG_MPTCP_IPV6)

Out of curriosity, what's the recommended way to deal with IPv4 and
IPv6: should we always have "else if (a->family == AF_INET6)" (or a switch/case) or can we assume that if it is not v4, it is v6?

net/mptcp/pm_netlink.c line 54

Quoted 1 line
net/mptcp/pm_netlink.c new file +1 -0
+		addr_equals = !memcmp(&a->addr6, &b->addr6, sizeof(b->addr6));

detail: you can also use ipv6_addr_cmp(). (and not memcmp for v4?)

net/mptcp/pm_netlink.c line 67

Quoted 13 lines
net/mptcp/pm_netlink.c new file +13 -0
+
+	if (!addr_equals)
+		return false;
+	if (!use_port)
+		return true;
+
+	return a->port == b->port;
+}
+
+static void local_address(const struct sock_common *skc,
+			  struct mptcp_addr_info *addr)
+{
+	addr->family = skc->skc_family;

Should we copy the source port, just in case?

Quoted 22 lines
net/mptcp/pm_netlink.c new file +22 -0
+	if (addr->family == AF_INET)
+		addr->addr.s_addr = skc->skc_rcv_saddr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	else if (addr->family == AF_INET6)
+		addr->addr6 = skc->skc_v6_rcv_saddr;
+#endif
+}
+
+static void remote_address(const struct sock_common *skc,
+			   struct mptcp_addr_info *addr)
+{
+	addr->family = skc->skc_family;
+	addr->port = skc->skc_dport;
+	if (addr->family == AF_INET)
+		addr->addr.s_addr = skc->skc_daddr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	else if (addr->family == AF_INET6)
+		addr->addr6 = skc->skc_v6_daddr;
+#endif
+}
+
+static bool lookup_subflow_by_saddr(const struct mptcp_sock *msk,

net/mptcp/pm_netlink.c line 99

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+				    struct mptcp_addr_info *saddr)
+{
+	struct mptcp_subflow_context *subflow;
+	struct mptcp_addr_info cur;
+	struct sock_common *skc;
+
+	list_for_each_entry(subflow, &msk->conn_list, node) {
+		skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
+
+		local_address(skc, &cur);

I guess it's OK to do the copy to ease the comparison here below, right? (we are going to do that only when creating subflows so it seems fine. Maybe should we add a comment if we reuse this function later?)

Quoted 49 lines
net/mptcp/pm_netlink.c new file +49 -0
+		if (addresses_equal(&cur, saddr, false))
+			return true;
+	}
+
+	return false;
+}
+
+static struct mptcp_pm_addr_entry *
+select_local_address(const struct pm_nl_pernet *pernet,
+		     const struct mptcp_sock *msk)
+{
+	struct mptcp_pm_addr_entry *entry, *ret = NULL;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &pernet->addr_list, list) {
+		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW))
+			continue;
+		if (entry->addr.family == ((struct sock *)msk)->sk_family &&
+		    !lookup_subflow_by_saddr(msk, &entry->addr)) {
+			ret = entry;
+			break;
+		}
+	}
+	rcu_read_unlock();
+	return ret;
+}
+
+static struct mptcp_pm_addr_entry *
+select_signal_address(struct pm_nl_pernet *pernet, unsigned int pos)
+{
+	struct mptcp_pm_addr_entry *entry, *ret = NULL;
+	int i = 0;
+
+	rcu_read_lock();
+	/* do not keep any additional per socket state, just signal
+	 * the address list in order.
+	 * Note: removal from the local address list during the msk life-cycle
+	 * can lead to additional addresses not being announced.
+	 */
+	list_for_each_entry_rcu(entry, &pernet->addr_list, list) {
+		if (!(entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL))
+			continue;
+		if (i++ == pos) {
+			ret = entry;
+			break;
+		}
+	}
+	rcu_read_unlock();
+	return ret;

net/mptcp/pm_netlink.c line 158

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+}
+
+static void check_work_pending(struct mptcp_sock *msk)
+{
+	if (msk->pm.add_addr_signaled == msk->pm.add_addr_signal_max &&
+	    msk->pm.local_addr_used == msk->pm.local_addr_max)
+		WRITE_ONCE(msk->pm.work_pending, false);
+}
+
+static void mptcp_pm_create_subflow_or_signal(struct mptcp_sock *msk)

detail: I think we should avoid using signal alone because MP_FAIL, REM_ADD, MP_BACKUP, etc. are signals as well, no?
It's maybe just me but I find it clearer, when it is linked to ADD_ADDR, to use "announce" instead of the generic term "signal". But that's a detail. As long as it is clear for everybody :-)

Quoted 17 lines
net/mptcp/pm_netlink.c new file +17 -0
+{
+	struct sock *sk = (struct sock *)msk;
+	struct mptcp_pm_addr_entry *local;
+	struct mptcp_addr_info remote;
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	lock_sock(sk);
+
+	spin_lock_bh(&msk->pm.lock);
+	msk->pm.status = MPTCP_PM_IDLE;
+	pr_debug("local %d:%d signal %d:%d\n",
+		 msk->pm.local_addr_used, msk->pm.local_addr_max,
+		 msk->pm.add_addr_signaled, msk->pm.add_addr_signal_max);
+
+	/* check first if should create a new subflow */

net/mptcp/pm_netlink.c line 185

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	if (msk->pm.local_addr_used < msk->pm.local_addr_max) {
+		remote_address((struct sock_common *)sk, &remote);
+
+		local = select_local_address(pernet, msk);
+		if (local) {
+			msk->pm.local_addr_used++;
+			check_work_pending(msk);
+			spin_unlock_bh(&msk->pm.lock);
+			__mptcp_subflow_connect(sk, local->ifindex,
+						&local->addr, &remote);

Should we do anything special if this fail?
(decrement local_addr_used? retry later?)

Quoted 29 lines
net/mptcp/pm_netlink.c new file +29 -0
+			release_sock(sk);
+			return;
+		}
+
+		/* lookup failed, avoid fourther attempts later */
+		msk->pm.local_addr_used = msk->pm.local_addr_max;
+		check_work_pending(msk);
+	}
+
+	/* check for announce */
+	if (msk->pm.add_addr_signaled < msk->pm.add_addr_signal_max) {
+		local = select_signal_address(pernet,
+					      msk->pm.add_addr_signaled);
+
+		if (local) {
+			msk->pm.local_addr_used++;
+			mptcp_pm_announce_addr(msk, &local->addr);
+		} else {
+			/* pick failed, avoid fourther attempts later */
+			msk->pm.local_addr_used = msk->pm.add_addr_signal_max;
+		}
+
+		check_work_pending(msk);
+	}
+	spin_unlock_bh(&msk->pm.lock);
+	release_sock(sk);
+}
+
+void mptcp_pm_nl_fully_established(struct mptcp_sock *msk)

net/mptcp/pm_netlink.c line 224

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+{
+	mptcp_pm_create_subflow_or_signal(msk);
+}
+
+void mptcp_pm_nl_subflow_established(struct mptcp_sock *msk)
+{
+	mptcp_pm_create_subflow_or_signal(msk);
+}
+
+void mptcp_pm_nl_add_addr(struct mptcp_sock *msk)

(it's maybe just me but should we rename this by adding "_recv"? Same for the caller and related functions because it was not clear we are doing some actions not add an address or produce an add_addr but because we just received one)

Quoted 9 lines
net/mptcp/pm_netlink.c new file +9 -0
+{
+	struct sock *sk = (struct sock *)msk;
+	struct mptcp_addr_info remote;
+	struct mptcp_addr_info local;
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	spin_lock_bh(&msk->pm.lock);

net/mptcp/pm_netlink.c line 243

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	msk->pm.status = MPTCP_PM_IDLE;
+	pr_debug("accepted %d:%d remote family %d",
+		 msk->pm.add_addr_accepted, msk->pm.add_addr_accept_max,
+		 msk->pm.remote.family);
+	if (++msk->pm.add_addr_accepted >= msk->pm.add_addr_accept_max)
+		WRITE_ONCE(msk->pm.accept_addr, false);
+
+	/* connect to the specified remote address, using whatever
+	 * local address the routing configuration will pick.
+	 */

Should we try with all local IP the userspace added (+ the original one)? → to have a fullmesh

net/mptcp/pm_netlink.c line 252

Quoted 9 lines
net/mptcp/pm_netlink.c new file +9 -0
+	remote = msk->pm.remote;
+	if (!remote.port)
+		remote.port = sk->sk_dport;
+	memset(&local, 0, sizeof(local));
+	local.family = remote.family;
+	spin_unlock_bh(&msk->pm.lock);
+
+	lock_sock(sk);
+	__mptcp_subflow_connect((struct sock *)msk, 0, &local, &remote);

Should we do anything special if this fail?

net/mptcp/pm_netlink.c line 253

Quoted 1 line
net/mptcp/pm_netlink.c new file +1 -0
+	release_sock(sk);

Do we need to clear "pm.remote" somewhere? How do we deal with multiple received ADD_ADDR? Even if with the "echo", I guess we might receive a new one before the workqueue has finished dealing with the previous one, no?

net/mptcp/pm_netlink.c line 263

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+}
+
+static bool address_use_port(struct mptcp_pm_addr_entry *entry)
+{
+	return (entry->flags &
+		(MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==
+		MPTCP_PM_ADDR_FLAG_SIGNAL;
+}
+
+static int mptcp_pm_nl_append_new_addr(struct pm_nl_pernet *pernet,

detail: Here as well, should we add _local → new_local_addr?

net/mptcp/pm_netlink.c line 272

Quoted 9 lines
net/mptcp/pm_netlink.c new file +9 -0
+				       struct mptcp_pm_addr_entry *entry)
+{
+	struct mptcp_pm_addr_entry *cur;
+	int ret = -EINVAL;
+
+	spin_lock_bh(&pernet->lock);
+	/* to keep the code simple, don't do IDR-like allocation for address ID,
+	 * just bail when we exceed limits
+	 */

And we also need to support REM_ADDR here I guess.

Quoted 34 lines
net/mptcp/pm_netlink.c new file +34 -0
+	if (pernet->next_id > 255)
+		goto out;
+	if (pernet->addrs >= MPTCP_PM_ADDR_MAX)
+		goto out;
+
+	/* do not insert duplicate address, differentiate on port only
+	 * singled addresses
+	 */
+	list_for_each_entry(cur, &pernet->addr_list, list) {
+		if (addresses_equal(&cur->addr, &entry->addr,
+				    address_use_port(entry) &&
+				    address_use_port(cur)))
+			goto out;
+	}
+
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
+		pernet->add_addr_signal_max++;
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+		pernet->local_addr_max++;
+
+	entry->addr.id = pernet->next_id++;
+	pernet->addrs++;
+	list_add_tail_rcu(&entry->list, &pernet->addr_list);
+	ret = entry->addr.id;
+
+out:
+	spin_unlock_bh(&pernet->lock);
+	return ret;
+}
+
+int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
+{
+	struct mptcp_pm_addr_entry *entry;
+	struct mptcp_addr_info skc_local;

net/mptcp/pm_netlink.c line 316

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	struct mptcp_addr_info msk_local;
+	struct pm_nl_pernet *pernet;
+	int ret = -1;
+
+	if (WARN_ON_ONCE(!msk))
+		return -1;
+
+	/* The 0 ID mapping is defined by the first subflow, copied into the msk
+	 * addr
+	 */

Is it still OK to do that if the first subflow is down (but other subflows exist)? I mean, no need to have additional check to see if the subflow 0 is still alive? (I didn't check what we do with the msk for this specific case)

Quoted 125 lines
net/mptcp/pm_netlink.c new file +125 -0
+	local_address((struct sock_common *)msk, &msk_local);
+	local_address((struct sock_common *)msk, &skc_local);
+	if (addresses_equal(&msk_local, &skc_local, false))
+		return 0;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(entry, &pernet->addr_list, list) {
+		if (addresses_equal(&entry->addr, &skc_local, false)) {
+			ret = entry->addr.id;
+			break;
+		}
+	}
+	rcu_read_unlock();
+	if (ret >= 0)
+		return ret;
+
+	/* address not found, add to local list */
+	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+	if (!entry)
+		return -ENOMEM;
+
+	entry->flags = 0;
+	entry->addr = skc_local;
+	ret = mptcp_pm_nl_append_new_addr(pernet, entry);
+	if (ret < 0)
+		kfree(entry);
+
+	return ret;
+}
+
+void mptcp_pm_nl_data_init(struct mptcp_sock *msk)
+{
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	msk->pm.add_addr_signal_max = READ_ONCE(pernet->add_addr_signal_max);
+	msk->pm.add_addr_accept_max = READ_ONCE(pernet->add_addr_accept_max);
+	msk->pm.local_addr_max = READ_ONCE(pernet->local_addr_max);
+	WRITE_ONCE(msk->pm.work_pending,
+		   !!msk->pm.local_addr_max || !!msk->pm.add_addr_signal_max);
+	WRITE_ONCE(msk->pm.accept_addr, !!msk->pm.add_addr_accept_max);
+}
+
+#define MPTCP_PM_CMD_GRP_OFFSET	0
+
+static const struct genl_multicast_group mptcp_pm_mcgrps[] = {
+	[MPTCP_PM_CMD_GRP_OFFSET]	= { .name = MPTCP_PM_CMD_GRP_NAME, },
+};
+
+static const struct nla_policy
+mptcp_pm_addr_policy[MPTCP_PM_ADDR_ATTR_MAX + 1] = {
+	[MPTCP_PM_ADDR_ATTR_FAMILY]	= { .type	= NLA_U16,	},
+	[MPTCP_PM_ADDR_ATTR_ID]		= { .type	= NLA_U8,	},
+	[MPTCP_PM_ADDR_ATTR_ADDR4]	= { .type	= NLA_U32,	},
+	[MPTCP_PM_ADDR_ATTR_ADDR6]	= { .type	= NLA_EXACT_LEN,
+					    .len   = sizeof(struct in6_addr), },
+	[MPTCP_PM_ADDR_ATTR_PORT]	= { .type	= NLA_U16	},
+	[MPTCP_PM_ADDR_ATTR_FLAGS]	= { .type	= NLA_U32	},
+	[MPTCP_PM_ADDR_ATTR_IF_IDX]     = { .type	= NLA_S32	},
+};
+
+static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {
+	[MPTCP_PM_ATTR_ADDR]		=
+					NLA_POLICY_NESTED(mptcp_pm_addr_policy),
+	[MPTCP_PM_ATTR_RCV_ADD_ADDRS]	= { .type	= NLA_U32,	},
+};
+
+static int mptcp_pm_family_to_addr(int family)
+{
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	if (family == AF_INET6)
+		return MPTCP_PM_ADDR_ATTR_ADDR6;
+#endif > +	return MPTCP_PM_ADDR_ATTR_ADDR4;
+}
+
+static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
+			       bool require_family,
+			       struct mptcp_pm_addr_entry *entry)
+{
+	struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
+	int err, addr_addr;
+
+	if (!attr) {
+		GENL_SET_ERR_MSG(info, "missing address info");
+		return -EINVAL;
+	}
+
+	/* no validation needed - was already done via nested policy */
+	err = nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr,
+					  mptcp_pm_addr_policy, info->extack);
+	if (err)
+		return err;
+
+	memset(entry, 0, sizeof(*entry));
+	if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
+		if (!require_family)
+			goto skip_family;
+
+		NL_SET_ERR_MSG_ATTR(info->extack, attr,
+				    "missing family");
+		return -EINVAL;
+	}
+
+	entry->addr.family = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
+	if (entry->addr.family != AF_INET
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	    && entry->addr.family != AF_INET6
+#endif
+	    ) {
+		NL_SET_ERR_MSG_ATTR(info->extack, attr,
+				    "unknown address family");
+		return -EINVAL;
+	}
+	addr_addr = mptcp_pm_family_to_addr(entry->addr.family);
+	if (!tb[addr_addr]) {
+		NL_SET_ERR_MSG_ATTR(info->extack, attr,
+				    "missing address data");
+		return -EINVAL;
+	}
+
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	if (entry->addr.family == AF_INET6)

net/mptcp/pm_netlink.c line 452

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+		entry->addr.addr6 = nla_get_in6_addr(tb[addr_addr]);
+	else
+#endif
+		entry->addr.addr.s_addr = nla_get_in_addr(tb[addr_addr]);
+
+skip_family:
+	if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX])
+		entry->ifindex = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
+	else
+		entry->ifindex = 0;

detail: "entry" is init to 0 at the beginning of this function. Same below for the ID. Or if you remove the memset, the flags are not set to 0

net/mptcp/pm_netlink.c line 455

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+
+	if (tb[MPTCP_PM_ADDR_ATTR_ID])
+		entry->addr.id = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_ID]);

Is it not a u8?

net/mptcp/pm_netlink.c line 460

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+	else
+		entry->addr.id = 0;
+
+	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
+		entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);

(detail if you have to modify this: please add a new line here because most of the time, there is an empty line after a if-statement block)

Quoted 7 lines
net/mptcp/pm_netlink.c new file +7 -0
+	return 0;
+}
+
+static struct pm_nl_pernet *genl_info_pm_nl(struct genl_info *info)
+{
+	return net_generic(genl_info_net(info), pm_nl_pernet_id);
+}

net/mptcp/pm_netlink.c line 477

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+
+static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr, *entry;
+	int ret;
+
+	ret = mptcp_pm_parse_addr(attr, info, true, &addr);
+	if (ret)

Out of curriosity, is there a recommendation on what to check with "ret"? I mean "ret" is vague and often we can see "if (ret < 0)", like below (also because it is needed in this case), which seems clearer to me. Sometimes, "err" is used and in this case, it is clear to read: "if (err)".
No need to change anything, it's just to know what's recommended but not mandatory I guess.

net/mptcp/pm_netlink.c line 489

Quoted 12 lines
net/mptcp/pm_netlink.c new file +12 -0
+		return ret;
+
+	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+	if (!entry) {
+		GENL_SET_ERR_MSG(info, "can't allocate addr");
+		return -ENOMEM;
+	}
+
+	*entry = addr;
+	ret = mptcp_pm_nl_append_new_addr(pernet, entry);
+	if (ret < 0) {
+		GENL_SET_ERR_MSG(info, "too many addresses");

detail: Or duplicated one.

net/mptcp/pm_netlink.c line 347

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+		kfree(entry);
+		return ret;
+	}

Should we trigger here the establishement of new subflows and/or the send of ADD_ADDR for all existing MPTCP connections?

Quoted 121 lines
net/mptcp/pm_netlink.c new file +121 -0
+	return 0;
+}
+
+static struct mptcp_pm_addr_entry *
+__lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
+{
+	struct mptcp_pm_addr_entry *entry;
+
+	list_for_each_entry(entry, &pernet->addr_list, list) {
+		if (entry->addr.id == id)
+			return entry;
+	}
+	return NULL;
+}
+
+static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr, *entry;
+	int ret;
+
+	ret = mptcp_pm_parse_addr(attr, info, false, &addr);
+	if (ret)
+		return ret;
+
+	spin_lock_bh(&pernet->lock);
+	entry = __lookup_addr_by_id(pernet, addr.addr.id);
+	if (!entry) {
+		GENL_SET_ERR_MSG(info, "address not found");
+		ret = -EINVAL;
+		goto out;
+	}
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
+		pernet->add_addr_signal_max--;
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+		pernet->local_addr_max--;
+
+	pernet->addrs--;
+	list_del_rcu(&entry->list);
+	kfree_rcu(entry, rcu);
+out:
+	spin_unlock_bh(&pernet->lock);
+	return ret;
+}
+
+static void __flush_addrs(struct pm_nl_pernet *pernet)
+{
+	while (!list_empty(&pernet->addr_list)) {
+		struct mptcp_pm_addr_entry *cur;
+
+		cur = list_entry(pernet->addr_list.next,
+				 struct mptcp_pm_addr_entry, list);
+		list_del_rcu(&cur->list);
+		kfree_rcu(cur, rcu);
+	}
+}
+
+static void __reset_counters(struct pm_nl_pernet *pernet)
+{
+	pernet->add_addr_signal_max = 0;
+	pernet->add_addr_accept_max = 0;
+	pernet->local_addr_max = 0;
+	pernet->addrs = 0;
+}
+
+static int mptcp_nl_cmd_flush_addrs(struct sk_buff *skb, struct genl_info *info)
+{
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+
+	spin_lock_bh(&pernet->lock);
+	__flush_addrs(pernet);
+	__reset_counters(pernet);
+	spin_unlock_bh(&pernet->lock);
+	return 0;
+}
+
+static int mptcp_nl_fill_addr(struct sk_buff *skb,
+			      struct mptcp_pm_addr_entry *entry)
+{
+	struct mptcp_addr_info *addr = &entry->addr;
+	struct nlattr *attr;
+
+	attr = nla_nest_start(skb, MPTCP_PM_ATTR_ADDR);
+	if (!attr)
+		return -EMSGSIZE;
+
+	if (nla_put_u16(skb, MPTCP_PM_ADDR_ATTR_FAMILY, addr->family))
+		goto nla_put_failure;
+	if (nla_put_u8(skb, MPTCP_PM_ADDR_ATTR_ID, addr->id))
+		goto nla_put_failure;
+	if (nla_put_u32(skb, MPTCP_PM_ADDR_ATTR_FLAGS, entry->flags))
+		goto nla_put_failure;
+	if (entry->ifindex &&
+	    nla_put_s32(skb, MPTCP_PM_ADDR_ATTR_IF_IDX, entry->ifindex))
+		goto nla_put_failure;
+
+	if (addr->family == AF_INET)
+		nla_put_in_addr(skb, MPTCP_PM_ADDR_ATTR_ADDR4,
+				addr->addr.s_addr);
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	else if (addr->family == AF_INET6)
+		nla_put_in6_addr(skb, MPTCP_PM_ADDR_ATTR_ADDR6, &addr->addr6);
+#endif
+	nla_nest_end(skb, attr);
+	return 0;
+
+nla_put_failure:
+	nla_nest_cancel(skb, attr);
+	return -EMSGSIZE;
+}
+
+static int mptcp_nl_cmd_get_addr(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr, *entry;
+	struct sk_buff *msg;
+	void *reply;
+	int ret;
+

net/mptcp/pm_netlink.c line 624

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	ret = mptcp_pm_parse_addr(attr, info, false, &addr);
+	if (ret)
+		return ret;
+
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
+				  MPTCP_CMD_ADD_ADDR);

Should it not be MPTCP_CMD_GET_ADDR?

Can you not use info->genlhdr->cmd? (Same for the other genlmsg_put_reply())

Quoted 40 lines
net/mptcp/pm_netlink.c new file +40 -0
+	if (!reply) {
+		GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
+		ret = -EMSGSIZE;
+		goto fail;
+	}
+
+	spin_lock_bh(&pernet->lock);
+	entry = __lookup_addr_by_id(pernet, addr.addr.id);
+	if (!entry) {
+		GENL_SET_ERR_MSG(info, "address not found");
+		ret = -EINVAL;
+		goto unlock_fail;
+	}
+
+	ret = mptcp_nl_fill_addr(msg, entry);
+	if (ret)
+		goto unlock_fail;
+
+	genlmsg_end(msg, reply);
+	ret = genlmsg_reply(msg, info);
+	spin_unlock_bh(&pernet->lock);
+	return ret;
+
+unlock_fail:
+	spin_unlock_bh(&pernet->lock);
+
+fail:
+	nlmsg_free(msg);
+	return ret;
+}
+
+static int mptcp_nl_cmd_dump_addrs(struct sk_buff *msg,
+				   struct netlink_callback *cb)
+{
+	struct net *net = sock_net(msg->sk);
+	struct mptcp_pm_addr_entry *entry;
+	struct pm_nl_pernet *pernet;
+	int id = cb->args[0];
+	void *hdr;
+

net/mptcp/pm_netlink.c line 674

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	pernet = net_generic(net, pm_nl_pernet_id);
+
+	spin_lock_bh(&pernet->lock);
+	list_for_each_entry(entry, &pernet->addr_list, list) {
+		if (entry->addr.id <= id)
+			continue;
+
+		hdr = genlmsg_put(msg, NETLINK_CB(cb->skb).portid,
+				  cb->nlh->nlmsg_seq, &mptcp_genl_family,
+				  NLM_F_MULTI, MPTCP_CMD_ADD_ADDR);

same here: should it be MPTCP_CMD_GET_ADDR?

Quoted 20 lines
net/mptcp/pm_netlink.c new file +20 -0
+		if (!hdr)
+			break;
+
+		if (mptcp_nl_fill_addr(msg, entry) < 0) {
+			genlmsg_cancel(msg, hdr);
+			break;
+		}
+
+		id = entry->addr.id;
+		genlmsg_end(msg, hdr);
+	}
+	spin_unlock_bh(&pernet->lock);
+
+	cb->args[0] = id;
+	return msg->len;
+}
+
+static int
+mptcp_nl_cmd_set_rcv_add_addrs(struct sk_buff *skb, struct genl_info *info)
+{

net/mptcp/pm_netlink.c line 704

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_RCV_ADD_ADDRS];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	int limit;
+
+	if (!attr) {
+		GENL_SET_ERR_MSG(info, "missing announce accept limit");
+		return -EINVAL;
+	}
+
+	limit = nla_get_u16(attr);

it should be u32 I think.

Quoted 82 lines
net/mptcp/pm_netlink.c new file +82 -0
+	if (limit > MPTCP_PM_ADDR_MAX) {
+		GENL_SET_ERR_MSG(info,
+				 "announce accept limit greater than maximum");
+		return -EINVAL;
+	}
+
+	WRITE_ONCE(pernet->add_addr_accept_max, limit);
+	return 0;
+}
+
+static int
+mptcp_nl_cmd_get_rcv_add_addrs(struct sk_buff *skb, struct genl_info *info)
+{
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct sk_buff *msg;
+	void *reply;
+
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
+				  MPTCP_CMD_GET_RCV_ADD_ADDRS);
+	if (!reply)
+		goto fail;
+
+	if (nla_put_u32(msg, MPTCP_PM_ATTR_RCV_ADD_ADDRS,
+			READ_ONCE(pernet->add_addr_accept_max)))
+		goto fail;
+
+	genlmsg_end(msg, reply);
+	return genlmsg_reply(msg, info);
+
+fail:
+	GENL_SET_ERR_MSG(info, "not enough space in Netlink message");
+	nlmsg_free(msg);
+	return -EMSGSIZE;
+}
+
+static struct genl_ops mptcp_pm_ops[] = {
+	{
+		.cmd    = MPTCP_CMD_ADD_ADDR,
+		.doit   = mptcp_nl_cmd_add_addr,
+		.flags  = GENL_ADMIN_PERM,
+	},
+	{
+		.cmd    = MPTCP_CMD_DEL_ADDR,
+		.doit   = mptcp_nl_cmd_del_addr,
+		.flags  = GENL_ADMIN_PERM,
+	},
+	{
+		.cmd    = MPTCP_CMD_FLUSH_ADDRS,
+		.doit   = mptcp_nl_cmd_flush_addrs,
+		.flags  = GENL_ADMIN_PERM,
+	},
+	{
+		.cmd    = MPTCP_CMD_GET_ADDR,
+		.doit   = mptcp_nl_cmd_get_addr,
+		.dumpit   = mptcp_nl_cmd_dump_addrs,
+		.flags  = GENL_ADMIN_PERM,
+	},
+	{
+		.cmd    = MPTCP_CMD_SET_RCV_ADD_ADDRS,
+		.doit   = mptcp_nl_cmd_set_rcv_add_addrs,
+		.flags  = GENL_ADMIN_PERM,
+	},
+	{
+		.cmd    = MPTCP_CMD_GET_RCV_ADD_ADDRS,
+		.doit   = mptcp_nl_cmd_get_rcv_add_addrs,
+		.flags  = GENL_ADMIN_PERM,
+	},
+};
+
+static struct genl_family mptcp_genl_family __ro_after_init = {
+	.name		= MPTCP_PM_NAME,
+	.version	= MPTCP_PM_VER,
+	.maxattr	= MPTCP_PM_ATTR_MAX,
+	.policy		= mptcp_pm_policy,
+	.netnsok	= true,
+	.module		= THIS_MODULE,
+	.ops		= mptcp_pm_ops,
+	.n_ops		= ARRAY_SIZE(mptcp_pm_ops),

net/mptcp/pm_netlink.c line 796

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	.mcgrps		= mptcp_pm_mcgrps,
+	.n_mcgrps	= ARRAY_SIZE(mptcp_pm_mcgrps),
+};
+
+static int __net_init pm_nl_init_net(struct net *net)
+{
+	struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
+
+	INIT_LIST_HEAD_RCU(&pernet->addr_list);
+	__reset_counters(pernet);

I guess it's not strictly needed but doesn't hurt.

Quoted 21 lines
net/mptcp/pm_netlink.c new file +21 -0
+	pernet->next_id = 1;
+	spin_lock_init(&pernet->lock);
+	return 0;
+}
+
+static void __net_exit pm_nl_exit_net(struct list_head *net_list)
+{
+	struct net *net;
+
+	list_for_each_entry(net, net_list, exit_list) {
+		/* net is removed from namespace list, can't race with
+		 * other modifiers
+		 */
+		__flush_addrs(net_generic(net, pm_nl_pernet_id));
+	}
+}
+
+static struct pernet_operations mptcp_pm_pernet_ops = {
+	.init = pm_nl_init_net,
+	.exit_batch = pm_nl_exit_net,
+	.id = &pm_nl_pernet_id,

net/mptcp/pm_netlink.c line 827

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	.size = sizeof(struct pm_nl_pernet),
+};
+
+void mptcp_pm_nl_init(void)
+{
+	if (register_pernet_subsys(&mptcp_pm_pernet_ops) < 0)
+		panic("Failed to register MPTCP PM pernet subsystem.\n");
+
+	if (genl_register_family(&mptcp_genl_family))
+		panic("Failed to register MPTCP PM netlink family");

(detail: I guess you need "\n")

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
author
#15 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Hi,

Thank you for the very detailed review. I'll try to cover your feedback asap. I have a little more details below, but I would prefer post- poning more complext stuff like full-mash and retry policy.

Quoted 36 lines · Matthieu Baerts

As always, it is very good! Sorry for the delay but here are various questions and comments.

Note that I didn't really pay attention at how the locks were used, I would be glad if someone could look at this specific point. I focused my review more on the exposed API, general behaviour, Netlink stuff and typos.

Quoted 5 lines · Paolo Abeni

Expose to U/S a netlink family to control the PM, setting:

- list of local addresses to be signaled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react

It looks a bit strange to me to limit in term of ADD_ADDR. I see that all commands are linked to addresses which seem to make sense but I don't know if it is good for a generic PM.

Depending on the strategy, you might create and accept more or less subflows using the same list of local and remote addresses:

- a client with a fullmesh strategy will create a subflow from each
local address to each remote ones having the same IP family. So if the client and the server have each 2 (reachable) IPv4 A and B, there will be 4 subflows: A-A, A-B, B-A, B-B.

- another strategy could be like the fullmesh one but using each IP
only once: A-A, B-B

- slightly different: create one subflow per network interface (from
the client, it is hard to know what the server has): both client and server can have 2 NIC with one IPv4 and one v6 per NIC. The server will announce the v4 and v6 of the other NIC and the client will use one IP per interface: A4-A4, B4/6-B4/6 but not A4-A4, A6-A/B6, B4-B4, B6-B/A6 like we would have with the previous strategy.

Quoted 7 lines

- there are plenty of strategies for the client, e.g. ndiffport (more
subflows using the same IPs but different ports), etc. Many strategies will be dedicated to one specific use-case, then requiring a more advanced Netlink PM like the one in mptcp.org with mptcpd.

- on the server side, I think there are less strategies. Of course,
some might require a more advanced Netlink

One of the main goals here was keeping this PM impl. as simple as possible. I would defer any non trivial strategy to later.

With this patch the peer will create a subflow for each local address (towards the "main" remote address) and one subflow for each received and accepted ADD_ADDR, up to the specified limit, using whatever local address the routing will pick. No full-mash.

The limit on the number of accepted address is to avoid the a malicius peer to consume a lot of resources.

Quoted 6 lines

PM but most of the time, the server's job is to announce addresses and accept (or reject) subflows.

Also, another point: the client doesn't really have to send ADD_ADDR to the server. The server could then receive MP_JOIN from IPs that are new to the server, i.e. not announced by the client with ADD_ADDR.

Yep, the above is configurable with the proposed interface.

Quoted 11 lines

Now, after having mentioned all these points, I think it can be interesting to:

- continue to manage addresses that can be announced / used to create
subflows.

- continue to pick a single strategy for the moment. Maybe best to
start with fullmesh and if needed, the userspace can block some combinations using NFTables (I almost wrote IPTables :-o). This can be extended later by adding more strategies but I think we can already do many things if the userspace selects which additional addresses to use.

I think a full-mash strategy would require a litte more state-tracking, but I'm unsure before starting coding it.

Quoted 5 lines

- instead of having a maximum number of received ADD_ADDR that can
use, it might be more generic to limit the number of created/accepted subflows per MPTCP connection. If needed, this can be extended later with other limits: number of subflow per interface or IP and per MPTCP connection.

The maximum number of received ADD_ADDR limit allows to easily model the 'server' behaviour (max accepted == 0). We could add an additional max_subflows limit, but I think it's only relevant if we do the full- mash strategy.

Quoted 9 lines

In other words, compared to this patch, only modifying how the limits are managed to be more generic (I think).

What do you think about that?

Maybe you still want to keep a limit for the received ADD_ADDR? I don't think we store them for the moment? I guess MPTCP_PM_ADDR_MAX is enough for now for the limit.

Yep, we don't store the remote addresses, and I would avoid that till is possible - potentially we could have a lot of remote addresses per namespace.

Quoted 5 lines
Quoted 3 lines

When the msk is fully established, the PM netlink attempts to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.

I guess it does that only for the client (connect, not listen).

The PM netlink currently does that for every peer with a configured not empty local address list. Yep, for a server each subflow connection is going to fail.

Quoted 9 lines
Quoted 2 lines

After exausting the 'local' list, the PM tries to announce the 'signal' list via the ADD_ADDR option. Since we currenlty lack

(detail, we can fix that later but: s/exausting/exhausting/ and s/currenlty/currently/ and s/signaled/signalled/ (or announced))

Quoted 1 line

the ADD_ADDR echo (and related event) only the first addr is sent.

It is not clear for me why the client has to announce addresses.

Just because the RFC allows that and it's very easy to implement -forbitting that would need some additional check. Also fits the unix philosopy ;)

Quoted 4 lines

But if
it does th at, it might be better to do it before creating additional
subflows? The info in the ADD_ADDR sent by the clients could maybe be used in firewalls. Better to send them before then.

Ok. Will do in the next iteration. Can you please explain the 'firewall' thing? who is used the ADD_ADDR opt?

Quoted 9 lines

+/* netlink interface */

include/uapi/linux/mptcp.h enum { · line 38

Quoted 3 lines
include/uapi/linux/mptcp.h +3 -0
+#define MPTCP_PM_NAME		"mptcp_pm"
+#define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_VER		0x1

Should we add "_NETLINK" or "_NL" here above, just in case we have additional PMs later?

MPTCP_PM_NL_NAME "mptcp_pm_netlink"

The netlink name is limited to GENL_NAMSIZ(16) - comprising the trailing '\0' so it will not fit. The 'nl' part sounds rendundant (this is a nl interface), so I explicitly avoided that in the API

Quoted 13 lines

And maybe we should do the same below? e.g. "mptcp_pm_nl_attrs"

include/uapi/linux/mptcp.h enum { · line 44

Quoted 6 lines
include/uapi/linux/mptcp.h +6 -0
+
+/*
+ * ATTR types defined for MPTCP
+ */
+enum mptcp_pm_attrs {
+	MPTCP_PM_ATTR_UNSPEC,

Because this enum will be exposed to userspace, should we force the first item to be 0? (same below)
I guess most compiler will set it to 0 by default but I think the specs don't force them to do that.

According to http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
the C99 specs require the first enum value being 0 - section 6.7.2.2 Enumeration specifiers, p: 105-106.

Quoted 11 lines
Quoted 11 lines
include/uapi/linux/mptcp.h +11 -0
+
+	MPTCP_PM_ATTR_ADDR,				/* nested address */
+	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
+
+	__MPTCP_PM_ATTR_MAX
+};
+
+#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
+
+enum mptcp_pm_addr_addrs {
+	MPTCP_PM_ADDR_ATTR_UNSPEC,
Quoted 8 lines

include/uapi/linux/mptcp.h enum { · line 61

Quoted 6 lines
include/uapi/linux/mptcp.h +6 -0
+
+	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_ID,				/* u8 */
+	MPTCP_PM_ADDR_ATTR_ADDR4,			/* struct in_addr */
+	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
+	MPTCP_PM_ADDR_ATTR_PORT,			/* u16 */

(It seems you are not using it)

Currently not used, it's there to cope with the RFC allowing a MPTCP peer to announce a local address on a specific port.

Quoted 6 lines
Quoted 6 lines
include/uapi/linux/mptcp.h +6 -0
+	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
+	MPTCP_PM_ADDR_ATTR_IF_IDX,			/* s32 */
+
+	__MPTCP_PM_ADDR_ATTR_MAX
+};
+
Quoted 8 lines

include/uapi/linux/mptcp.h enum { · line 72

Quoted 5 lines
include/uapi/linux/mptcp.h +5 -0
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+#define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
+#define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
+#define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)

detail and we can fix it later if needed: I guess checkpatch will ask us to use BIT(0), etc.

Will do in next iteration.

Quoted 8 lines
Quoted 8 lines
include/uapi/linux/mptcp.h +8 -0
+
+enum {
+	MPTCP_CMD_UNSPEC,
+
+	MPTCP_CMD_ADD_ADDR,
+	MPTCP_CMD_DEL_ADDR,
+	MPTCP_CMD_GET_ADDR,
+	MPTCP_CMD_FLUSH_ADDRS,
Quoted 8 lines

include/uapi/linux/mptcp.h enum { · line 85

Quoted 5 lines
include/uapi/linux/mptcp.h +5 -0
+	MPTCP_CMD_SET_RCV_ADD_ADDRS,
+	MPTCP_CMD_GET_RCV_ADD_ADDRS,
+
+	__MPTCP_CMD_AFTER_LAST
+};

A detail but maybe important before it's too late: should we add "_PM" or "_PM_NL" in the list of commands?

Yep, will do in the next iteration.

Quoted 3 lines

Also it could be nice to add (later?) comments about the API: what does each command do, which (optional) parameters to use and what reply you will get (if any).

Uhm... locking at existing genl family, this kind of documentation is outside the scope of the uapi header ? I guess because it will bloat the header too much ?!?

[...]

Quoted 6 lines

net/mptcp/pm_netlink.c line 33

Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+struct pm_nl_pernet {
+	/* protects pernet updates */
+	spinlock_t		lock;
+	struct list_head	addr_list;

detail: maybe clearer with local_addr_list?

Ok, will change in next iteration

Quoted 1 line

Should we not maintain a list of remote_add_addr?

I explicitly tried to avoid that: a per netns list of remote addresses could be quite long/expensive to maintain.

[...]

Quoted 14 lines

net/mptcp/pm_netlink.c line 53

Quoted 11 lines
net/mptcp/pm_netlink.c new file +11 -0
+static bool addresses_equal(const struct mptcp_addr_info *a,
+			    struct mptcp_addr_info *b, bool use_port)
+{
+	bool addr_equals;
+
+	if (a->family != b->family)
+		return false;
+
+	if (a->family == AF_INET)
+		addr_equals = !memcmp(&a->addr, &b->addr, sizeof(b->addr));
+	else

You need to surround this block with:

Quoted 1 line
   #if IS_ENABLED(CONFIG_MPTCP_IPV6)

Will do in the next iteration.

Quoted 3 lines

Out of curriosity, what's the recommended way to deal with IPv4 and
IPv6: should we always have "else if (a->family == AF_INET6)" (or a switch/case) or can we assume that if it is not v4, it is v6?

In this specific case, we can do this assumption, as the family has been validated before (by the netlink callback and/or the socket code).

Quoted 4 lines

net/mptcp/pm_netlink.c line 54

Quoted 2 lines
net/mptcp/pm_netlink.c new file +1 -0
+		addr_equals = !memcmp(&a->addr6, &b->addr6, sizeof(b->addr6));

detail: you can also use ipv6_addr_cmp(). (and not memcmp for v4?)

Will do in the next iteration.

Quoted 16 lines
Quoted 4 lines
net/mptcp/pm_netlink.c new file +3 -0
+
+	if (!addr_equals)
+		return false;

net/mptcp/pm_netlink.c line 67

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	if (!use_port)
+		return true;
+
+	return a->port == b->port;
+}
+
+static void local_address(const struct sock_common *skc,
+			  struct mptcp_addr_info *addr)
+{
+	addr->family = skc->skc_family;

Should we copy the source port, just in case?

The source port explicitly omitted for local addresses as it usually changes across subflows and we want to ignore it. I'll add a comment in the next iteration

Quoted 29 lines
Quoted 29 lines
net/mptcp/pm_netlink.c new file +28 -0
+	if (addr->family == AF_INET)
+		addr->addr.s_addr = skc->skc_rcv_saddr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	else if (addr->family == AF_INET6)
+		addr->addr6 = skc->skc_v6_rcv_saddr;
+#endif
+}
+
+static void remote_address(const struct sock_common *skc,
+			   struct mptcp_addr_info *addr)
+{
+	addr->family = skc->skc_family;
+	addr->port = skc->skc_dport;
+	if (addr->family == AF_INET)
+		addr->addr.s_addr = skc->skc_daddr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	else if (addr->family == AF_INET6)
+		addr->addr6 = skc->skc_v6_daddr;
+#endif
+}
+
+static bool lookup_subflow_by_saddr(const struct mptcp_sock *msk,
+				    struct mptcp_addr_info *saddr)
+{
+	struct mptcp_subflow_context *subflow;
+	struct mptcp_addr_info cur;
+	struct sock_common *skc;
+
Quoted 8 lines

net/mptcp/pm_netlink.c line 99

Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+	list_for_each_entry(subflow, &msk->conn_list, node) {
+		skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
+
+		local_address(skc, &cur);

I guess it's OK to do the copy to ease the comparison here below, right? (we are going to do that only when creating subflows so it seems fine. Maybe should we add a comment if we reuse this function later?)

Are you concerned about performances? I think this is really unnoticeable. The copied data will be in cache, possibly even in registers, and the overhead to traverse the subflow list (with possibly different cache misses per subflow) will be far greater.

Quoted 6 lines
Quoted 6 lines
net/mptcp/pm_netlink.c new file +6 -0
+static void check_work_pending(struct mptcp_sock *msk)
+{
+	if (msk->pm.add_addr_signaled == msk->pm.add_addr_signal_max &&
+	    msk->pm.local_addr_used == msk->pm.local_addr_max)
+		WRITE_ONCE(msk->pm.work_pending, false);
+}
Quoted 8 lines

net/mptcp/pm_netlink.c line 158

Quoted 2 lines
net/mptcp/pm_netlink.c new file +2 -0
+
+static void mptcp_pm_create_subflow_or_signal(struct mptcp_sock *msk)

detail: I think we should avoid using signal alone because MP_FAIL, REM_ADD, MP_BACKUP, etc. are signals as well, no?
It's maybe just me but I find it clearer, when it is linked to ADD_ADDR, to use "announce" instead of the generic term "signal". But that's a detail. As long as it is clear for everybody :-)

I picked 'signal' because the term was already in use in the existing code. I can change it to *'signal_addr' to be consistent with other names.

Quoted 22 lines
Quoted 22 lines
net/mptcp/pm_netlink.c new file +22 -0
+{
+	struct sock *sk = (struct sock *)msk;
+	struct mptcp_pm_addr_entry *local;
+	struct mptcp_addr_info remote;
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	lock_sock(sk);
+
+	spin_lock_bh(&msk->pm.lock);
+	msk->pm.status = MPTCP_PM_IDLE;
+	pr_debug("local %d:%d signal %d:%d\n",
+		 msk->pm.local_addr_used, msk->pm.local_addr_max,
+		 msk->pm.add_addr_signaled, msk->pm.add_addr_signal_max);
+
+	/* check first if should create a new subflow */
+	if (msk->pm.local_addr_used < msk->pm.local_addr_max) {
+		remote_address((struct sock_common *)sk, &remote);
+
+		local = select_local_address(pernet, msk);
+		if (local) {
Quoted 8 lines

net/mptcp/pm_netlink.c line 185

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+			msk->pm.local_addr_used++;
+			check_work_pending(msk);
+			spin_unlock_bh(&msk->pm.lock);
+			__mptcp_subflow_connect(sk, local->ifindex,
+						&local->addr, &remote);

Should we do anything special if this fail?
(decrement local_addr_used? retry later?)

IIRC, according to the RFC we must not retry if the address is unreachable and/or the path is not MPTCP capable. So we should retry only if failing e.g. due to an allocation error. Overall a correct retry policy looks a bit too complex for this stage to me. I think we can add that later, if needed.

[...]

Quoted 6 lines

+void mptcp_pm_nl_add_addr(struct mptcp_sock *msk)

(it's maybe just me but should we rename this by adding "_recv"? Same for the caller and related functions because it was not clear we are doing some actions not add an address or produce an add_addr but because we just received one)

Ok, will do in the next iteration.

Quoted 14 lines
Quoted 14 lines
net/mptcp/pm_netlink.c new file +14 -0
+{
+	struct sock *sk = (struct sock *)msk;
+	struct mptcp_addr_info remote;
+	struct mptcp_addr_info local;
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	spin_lock_bh(&msk->pm.lock);
+	msk->pm.status = MPTCP_PM_IDLE;
+	pr_debug("accepted %d:%d remote family %d",
+		 msk->pm.add_addr_accepted, msk->pm.add_addr_accept_max,
+		 msk->pm.remote.family);
+	if (++msk->pm.add_addr_accepted >= msk->pm.add_addr_accept_max)
Quoted 8 lines

net/mptcp/pm_netlink.c line 243

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+		WRITE_ONCE(msk->pm.accept_addr, false);
+
+	/* connect to the specified remote address, using whatever
+	 * local address the routing configuration will pick.
+	 */

Should we try with all local IP the userspace added (+ the original one)? → to have a fullmesh

I would postpone this one to later.

Quoted 12 lines

net/mptcp/pm_netlink.c line 252

Quoted 10 lines
net/mptcp/pm_netlink.c new file +9 -0
+	remote = msk->pm.remote;
+	if (!remote.port)
+		remote.port = sk->sk_dport;
+	memset(&local, 0, sizeof(local));
+	local.family = remote.family;
+	spin_unlock_bh(&msk->pm.lock);
+
+	lock_sock(sk);
+	__mptcp_subflow_connect((struct sock *)msk, 0, &local, &remote);

Should we do anything special if this fail?

Same situation as the other __mptcp_subflow_connect()

Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	release_sock(sk);

Do we need to clear "pm.remote" somewhere? How do we deal with multiple received ADD_ADDR? Even if with the "echo", I guess we might receive a new one before the workqueue has finished dealing with the previous one, no?

The idea is that the workqueue does sort of rate-limiting on subflow creation. To cope with multiple 'concurrent' addresses we need to add additiona/dynamic storage. IIRC the RFC allow us to ignore multiple ADD_ADDR options as it fit us.

Quoted 4 lines
Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+}
+
+static bool address_use_port(struct mptcp_pm_addr_entry *entry)
+{
Quoted 8 lines

net/mptcp/pm_netlink.c line 263

Quoted 6 lines
net/mptcp/pm_netlink.c new file +6 -0
+	return (entry->flags &
+		(MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==
+		MPTCP_PM_ADDR_FLAG_SIGNAL;
+}
+
+static int mptcp_pm_nl_append_new_addr(struct pm_nl_pernet *pernet,

detail: Here as well, should we add _local → new_local_addr?

Ok, will do in the next iteration.

Quoted 11 lines

net/mptcp/pm_netlink.c line 272

Quoted 9 lines
net/mptcp/pm_netlink.c new file +9 -0
+				       struct mptcp_pm_addr_entry *entry)
+{
+	struct mptcp_pm_addr_entry *cur;
+	int ret = -EINVAL;
+
+	spin_lock_bh(&pernet->lock);
+	/* to keep the code simple, don't do IDR-like allocation for address ID,
+	 * just bail when we exceed limits
+	 */

And we also need to support REM_ADDR here I guess.

Yes, we need to add REM_ADDR support. I think we don't need to add anything specific with the current implementation: we don't store locally remote addess, we don't have anything to delete and we will not re-use them later anyway (due to lack of retry policy).

Quoted 41 lines
Quoted 41 lines
net/mptcp/pm_netlink.c new file +41 -0
+	if (pernet->next_id > 255)
+		goto out;
+	if (pernet->addrs >= MPTCP_PM_ADDR_MAX)
+		goto out;
+
+	/* do not insert duplicate address, differentiate on port only
+	 * singled addresses
+	 */
+	list_for_each_entry(cur, &pernet->addr_list, list) {
+		if (addresses_equal(&cur->addr, &entry->addr,
+				    address_use_port(entry) &&
+				    address_use_port(cur)))
+			goto out;
+	}
+
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
+		pernet->add_addr_signal_max++;
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+		pernet->local_addr_max++;
+
+	entry->addr.id = pernet->next_id++;
+	pernet->addrs++;
+	list_add_tail_rcu(&entry->list, &pernet->addr_list);
+	ret = entry->addr.id;
+
+out:
+	spin_unlock_bh(&pernet->lock);
+	return ret;
+}
+
+int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
+{
+	struct mptcp_pm_addr_entry *entry;
+	struct mptcp_addr_info skc_local;
+	struct mptcp_addr_info msk_local;
+	struct pm_nl_pernet *pernet;
+	int ret = -1;
+
+	if (WARN_ON_ONCE(!msk))
+		return -1;
+
Quoted 8 lines

net/mptcp/pm_netlink.c line 316

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+	/* The 0 ID mapping is defined by the first subflow, copied into the msk
+	 * addr
+	 */

Is it still OK to do that if the first subflow is down (but other subflows exist)? I mean, no need to have additional check to see if the subflow 0 is still alive? (I didn't check what we do with the msk for this specific case)

We must always use the same ID for the same address inside an MTPCP connection scope. Once we associate '0' to one local IP we should use that association till the msk socket exists. With the current code, the first subflow socket structure will exists till mptcp_close, even if the related TCP connection is terminate well before. So this code should be safe.

[...]

Quoted 7 lines
Quoted 7 lines
net/mptcp/pm_netlink.c new file +7 -0
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	if (entry->addr.family == AF_INET6)
+		entry->addr.addr6 = nla_get_in6_addr(tb[addr_addr]);
+	else
+#endif
+		entry->addr.addr.s_addr = nla_get_in_addr(tb[addr_addr]);
+
Quoted 8 lines

net/mptcp/pm_netlink.c line 452

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+skip_family:
+	if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX])
+		entry->ifindex = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
+	else
+		entry->ifindex = 0;

detail: "entry" is init to 0 at the beginning of this function. Same below for the ID. Or if you remove the memset, the flags are not set to 0

Will drop the 'else' branch in the next iteration.

Quoted 5 lines

net/mptcp/pm_netlink.c line 455

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+
+	if (tb[MPTCP_PM_ADDR_ATTR_ID])
+		entry->addr.id = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_ID]);

Is it not a u8?

yep, funnily enough self-tests passes. Will fix in the next iteration.

Quoted 28 lines

net/mptcp/pm_netlink.c line 460

Quoted 6 lines
net/mptcp/pm_netlink.c new file +5 -0
+	else
+		entry->addr.id = 0;
+
+	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
+		entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);

(detail if you have to modify this: please add a new line here because most of the time, there is an empty line after a if-statement block)

Quoted 7 lines
net/mptcp/pm_netlink.c new file +7 -0
+	return 0;
+}
+
+static struct pm_nl_pernet *genl_info_pm_nl(struct genl_info *info)
+{
+	return net_generic(genl_info_net(info), pm_nl_pernet_id);
+}

net/mptcp/pm_netlink.c line 477

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+
+static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr, *entry;
+	int ret;
+
+	ret = mptcp_pm_parse_addr(attr, info, true, &addr);
+	if (ret)
Quoted 7 lines

Out of curriosity, is there a recommendation on what to check with "ret"? I mean "ret" is vague and often we can see "if (ret < 0)", like below (also because it is needed in this case), which seems clearer to me. Sometimes, "err" is used and in this case, it is clear to read: "if (err)".
No need to change anything, it's just to know what's recommended but not mandatory I guess.

I'll go with 'err' in the next iteration.

Quoted 15 lines

net/mptcp/pm_netlink.c line 489

Quoted 12 lines
net/mptcp/pm_netlink.c new file +12 -0
+		return ret;
+
+	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+	if (!entry) {
+		GENL_SET_ERR_MSG(info, "can't allocate addr");
+		return -ENOMEM;
+	}
+
+	*entry = addr;
+	ret = mptcp_pm_nl_append_new_addr(pernet, entry);
+	if (ret < 0) {
+		GENL_SET_ERR_MSG(info, "too many addresses");

detail: Or duplicated one.

Quoted 6 lines

net/mptcp/pm_netlink.c line 347

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+		kfree(entry);
+		return ret;
+	}

Should we trigger here the establishement of new subflows and/or the send of ADD_ADDR for all existing MPTCP connections?

To keep the things simple, I would avoid that. For servers the number of msk sockets to process could be high.

[...]

Quoted 22 lines
Quoted 9 lines
net/mptcp/pm_netlink.c new file +9 -0
+static int mptcp_nl_cmd_get_addr(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr, *entry;
+	struct sk_buff *msg;
+	void *reply;
+	int ret;
+

net/mptcp/pm_netlink.c line 624

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	ret = mptcp_pm_parse_addr(attr, info, false, &addr);
+	if (ret)
+		return ret;
+
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
+				  MPTCP_CMD_ADD_ADDR);

Should it not be MPTCP_CMD_GET_ADDR?

Quoted 1 line

Can you not use info->genlhdr->cmd? (Same for the other genlmsg_put_reply())

I think you are right. I picked 'MPTCP_CMD_ADD_ADDR' because the reply message is formatted exactly as a MPTCP_CMD_ADD_ADDR command, but it's not the correct way to do this. Will fix in the next iteration.

Quoted 15 lines

net/mptcp/pm_netlink.c line 704

Quoted 13 lines
net/mptcp/pm_netlink.c new file +12 -0
+mptcp_nl_cmd_set_rcv_add_addrs(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_RCV_ADD_ADDRS];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	int limit;
+
+	if (!attr) {
+		GENL_SET_ERR_MSG(info, "missing announce accept limit");
+		return -EINVAL;
+	}
+
+	limit = nla_get_u16(attr);

it should be u32 I think.

Yep, will fix in the next iteration.

Quoted 8 lines

net/mptcp/pm_netlink.c line 796

Quoted 6 lines
net/mptcp/pm_netlink.c new file +6 -0
+static int __net_init pm_nl_init_net(struct net *net)
+{
+	struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
+
+	INIT_LIST_HEAD_RCU(&pernet->addr_list);
+	__reset_counters(pernet);

I guess it's not strictly needed but doesn't hurt.

Needed on clone()

Quoted 10 lines

net/mptcp/pm_netlink.c line 827

Quoted 7 lines
net/mptcp/pm_netlink.c new file +7 -0
+void mptcp_pm_nl_init(void)
+{
+	if (register_pernet_subsys(&mptcp_pm_pernet_ops) < 0)
+		panic("Failed to register MPTCP PM pernet subsystem.\n");
+
+	if (genl_register_family(&mptcp_genl_family))
+		panic("Failed to register MPTCP PM netlink family");

(detail: I guess you need "\n")

will fix in the next iteration.

Thank you!

Paolo

#16 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Hi Paolo,

Thank you for your answers too all my questions! :)

Quoted 5 lines · Paolo Abeni

Hi,

Thank you for the very detailed review. I'll try to cover your feedback asap. I have a little more details below, but I would prefer post- poning more complext stuff like full-mash and retry policy.

Sounds good to me. I think the most important is to stick with one policy while still having the possibility to extend it later without breaking the API.

Quoted 45 lines · Matthieu Baerts
Quoted 36 lines

As always, it is very good! Sorry for the delay but here are various questions and comments.

Note that I didn't really pay attention at how the locks were used, I would be glad if someone could look at this specific point. I focused my review more on the exposed API, general behaviour, Netlink stuff and typos.

Quoted 5 lines · Paolo Abeni

Expose to U/S a netlink family to control the PM, setting:

- list of local addresses to be signaled.
- list of local addresses used to created subflows.
- maximum number of add_addr option to react

It looks a bit strange to me to limit in term of ADD_ADDR. I see that all commands are linked to addresses which seem to make sense but I don't know if it is good for a generic PM.

Depending on the strategy, you might create and accept more or less subflows using the same list of local and remote addresses:

- a client with a fullmesh strategy will create a subflow from each
local address to each remote ones having the same IP family. So if the client and the server have each 2 (reachable) IPv4 A and B, there will be 4 subflows: A-A, A-B, B-A, B-B.

- another strategy could be like the fullmesh one but using each IP
only once: A-A, B-B

- slightly different: create one subflow per network interface (from
the client, it is hard to know what the server has): both client and server can have 2 NIC with one IPv4 and one v6 per NIC. The server will announce the v4 and v6 of the other NIC and the client will use one IP per interface: A4-A4, B4/6-B4/6 but not A4-A4, A6-A/B6, B4-B4, B6-B/A6 like we would have with the previous strategy.

Quoted 7 lines

- there are plenty of strategies for the client, e.g. ndiffport (more
subflows using the same IPs but different ports), etc. Many strategies will be dedicated to one specific use-case, then requiring a more advanced Netlink PM like the one in mptcp.org with mptcpd.

- on the server side, I think there are less strategies. Of course,
some might require a more advanced Netlink

Quoted 7 lines

One of the main goals here was keeping this PM impl. as simple as possible. I would defer any non trivial strategy to later.

With this patch the peer will create a subflow for each local address (towards the "main" remote address) and one subflow for each received and accepted ADD_ADDR, up to the specified limit, using whatever local address the routing will pick. No full-mash.

It sounds simple and still flexible enough. The "full-mesh" feature can be added later, with or without mash as a side dish :)

In this configuration, I think we can cover the "smartphone" use-case:
one path via WiFi and one via cellular.

Quoted 2 lines

The limit on the number of accepted address is to avoid the a malicius peer to consume a lot of resources.

So only to avoid the client to create too many subflows in reaction to received ADD_ADDR, right? (and the server, even if it will fail)

Quoted 15 lines
Quoted 6 lines

PM but most of the time, the server's job is to announce addresses and accept (or reject) subflows.

Also, another point: the client doesn't really have to send ADD_ADDR to the server. The server could then receive MP_JOIN from IPs that are new to the server, i.e. not announced by the client with ADD_ADDR.

Yep, the above is configurable with the proposed interface.

Quoted 6 lines

Now, after having mentioned all these points, I think it can be interesting to:

- continue to manage addresses that can be announced / used to create
subflows.

Quoted 8 lines
Quoted 5 lines

- continue to pick a single strategy for the moment. Maybe best to
start with fullmesh and if needed, the userspace can block some combinations using NFTables (I almost wrote IPTables :-o). This can be extended later by adding more strategies but I think we can already do many things if the userspace selects which additional addresses to use.

I think a full-mash strategy would require a litte more state-tracking, but I'm unsure before starting coding it.

It seems this strategy can be extended later to cover more use-cases.

Quoted 10 lines
Quoted 5 lines

- instead of having a maximum number of received ADD_ADDR that can
use, it might be more generic to limit the number of created/accepted subflows per MPTCP connection. If needed, this can be extended later with other limits: number of subflow per interface or IP and per MPTCP connection.

The maximum number of received ADD_ADDR limit allows to easily model the 'server' behaviour (max accepted == 0). We could add an additional max_subflows limit, but I think it's only relevant if we do the full- mash strategy.

What the server will do with the received ADD_ADDR? The RFC allows the server to initiate subflows but technically, is it possible for the server to do that if the socket is in "LISTEN" mode and on "CONNECT" mode on the client side?

If we limit the number of created subflows, we can limit the number of subflows on both the client and the server. Is it possible to limit the number of subflows on the server side with the current version? (It is maybe not needed for the moment.)

(EDIT: I see below that these connections are going to fail, that's why we should put RCV_MAX to 0)

Quoted 6 lines
Quoted 6 lines

In other words, compared to this patch, only modifying how the limits are managed to be more generic (I think).

What do you think about that?

Quoted 7 lines
Quoted 3 lines

Maybe you still want to keep a limit for the received ADD_ADDR? I don't think we store them for the moment? I guess MPTCP_PM_ADDR_MAX is enough for now for the limit.

Yep, we don't store the remote addresses, and I would avoid that till is possible - potentially we could have a lot of remote addresses per namespace.

I guess if we store them, that would be per connection. So yes we can have a lot :)

But it can be needed: if a client looses one subflow or has a new available interface, it might want to re-try it later. But we can look at that later and maybe it is enough to just re-establish a subflow after an error.

Quoted 9 lines
Quoted 5 lines
Quoted 3 lines

When the msk is fully established, the PM netlink attempts to create subflow for each addr in 'local' list, waiting for each connection to be completed before attempting the next one.

I guess it does that only for the client (connect, not listen).

The PM netlink currently does that for every peer with a configured not empty local address list. Yep, for a server each subflow connection is going to fail.

OK, thank you for the clarification!

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines

After exausting the 'local' list, the PM tries to announce the 'signal' list via the ADD_ADDR option. Since we currenlty lack

(detail, we can fix that later but: s/exausting/exhausting/ and s/currenlty/currently/ and s/signaled/signalled/ (or announced))

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

the ADD_ADDR echo (and related event) only the first addr is sent.

It is not clear for me why the client has to announce addresses.

Just because the RFC allows that and it's very easy to implement -forbitting that would need some additional check. Also fits the unix philosopy ;)

If it is easier to add this support than having a separation between client and server mode, that's fine :-)

Quoted 6 lines
Quoted 4 lines

But if
it does th at, it might be better to do it before creating additional
subflows? The info in the ADD_ADDR sent by the clients could maybe be used in firewalls. Better to send them before then.

Ok. Will do in the next iteration.

When the ADD_ADDRv1 with the 'echo' will be available, does that mean we will add an "important" delay for the creation of new subflows?

I guess at some points, we might want to have the possibility to:
- send ADD_ADDR and MP_JOIN in parallel
- send ADD_ADDR then, once they have been ACKed by the server, send the MP_JOINs. For potential firewall/load-balancers, see below.

I think the firewall/load-balancer support is less important now. Worst
case: the SYN+MP_JOIN is retransmitted.
So maybe better not to delay the MP_JOIN.
Or configure the client not to send ADD_ADDR :)

Quoted 2 lines

Can you please explain the
'firewall' thing? who is used the ADD_ADDR opt?

The only use-case I can find for the client to send ADD_ADDRs is to allow stateful firewalls or load-balancers to act in prevision of the MP_JOIN they are going to receive: not to block it or to forward it to the right sub-server.
There are some techniques to allow stateless load-balancers but some might prefer stateful ones.

Quoted 8 lines
Quoted 8 lines

+/* netlink interface */

include/uapi/linux/mptcp.h enum { · line 38

Quoted 3 lines
include/uapi/linux/mptcp.h +3 -0
+#define MPTCP_PM_NAME		"mptcp_pm"
+#define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_VER		0x1

Should we add "_NETLINK" or "_NL" here above, just in case we have additional PMs later?

Quoted 5 lines
Quoted 1 line

MPTCP_PM_NL_NAME "mptcp_pm_netlink"

The netlink name is limited to GENL_NAMSIZ(16) - comprising the trailing '\0' so it will not fit. The 'nl' part sounds rendundant (this is a nl interface), so I explicitly avoided that in the API

Good point! I think only modifying "define" names is enough:

MPTCP_PM_NETLINK_NAME
MPTCP_PM_NETLINK_CMD_GRP_NAME
MPTCP_PM_NETLINK_VER

(or with _NL)

Just to avoid conflicts with potential future PMs :)

Quoted 14 lines
Quoted 13 lines

And maybe we should do the same below? e.g. "mptcp_pm_nl_attrs"

include/uapi/linux/mptcp.h enum { · line 44

Quoted 6 lines
include/uapi/linux/mptcp.h +6 -0
+
+/*
+ * ATTR types defined for MPTCP
+ */
+enum mptcp_pm_attrs {
+	MPTCP_PM_ATTR_UNSPEC,

Because this enum will be exposed to userspace, should we force the first item to be 0? (same below)
I guess most compiler will set it to 0 by default but I think the specs don't force them to do that.

Quoted 3 lines

According to http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
the C99 specs require the first enum value being 0 - section 6.7.2.2 Enumeration specifiers, p: 105-106.

Thank you for pointing me to the specs, I always thought the value would not be necesserally 0, explaining why in files from include/uapi, many first entries of enum's have "= 0" :)

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
include/uapi/linux/mptcp.h +11 -0
+
+	MPTCP_PM_ATTR_ADDR,				/* nested address */
+	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
+
+	__MPTCP_PM_ATTR_MAX
+};
+
+#define MPTCP_PM_ATTR_MAX (__MPTCP_PM_ATTR_MAX - 1)
+
+enum mptcp_pm_addr_addrs {
+	MPTCP_PM_ADDR_ATTR_UNSPEC,
Quoted 8 lines

include/uapi/linux/mptcp.h enum { · line 61

Quoted 6 lines
include/uapi/linux/mptcp.h +6 -0
+
+	MPTCP_PM_ADDR_ATTR_FAMILY,			/* u16 */
+	MPTCP_PM_ADDR_ATTR_ID,				/* u8 */
+	MPTCP_PM_ADDR_ATTR_ADDR4,			/* struct in_addr */
+	MPTCP_PM_ADDR_ATTR_ADDR6,			/* struct in6_addr */
+	MPTCP_PM_ADDR_ATTR_PORT,			/* u16 */

(It seems you are not using it)

Quoted 2 lines

Currently not used, it's there to cope with the RFC allowing a MPTCP peer to announce a local address on a specific port.

OK to keep it then!

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
include/uapi/linux/mptcp.h +6 -0
+	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
+	MPTCP_PM_ADDR_ATTR_IF_IDX,			/* s32 */
+
+	__MPTCP_PM_ADDR_ATTR_MAX
+};
+
Quoted 8 lines

include/uapi/linux/mptcp.h enum { · line 72

Quoted 5 lines
include/uapi/linux/mptcp.h +5 -0
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+#define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
+#define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
+#define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)

detail and we can fix it later if needed: I guess checkpatch will ask us to use BIT(0), etc.

Quoted 1 line

Will do in next iteration.

Thanks!

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
include/uapi/linux/mptcp.h +8 -0
+
+enum {
+	MPTCP_CMD_UNSPEC,
+
+	MPTCP_CMD_ADD_ADDR,
+	MPTCP_CMD_DEL_ADDR,
+	MPTCP_CMD_GET_ADDR,
+	MPTCP_CMD_FLUSH_ADDRS,
Quoted 8 lines

include/uapi/linux/mptcp.h enum { · line 85

Quoted 5 lines
include/uapi/linux/mptcp.h +5 -0
+	MPTCP_CMD_SET_RCV_ADD_ADDRS,
+	MPTCP_CMD_GET_RCV_ADD_ADDRS,
+
+	__MPTCP_CMD_AFTER_LAST
+};

A detail but maybe important before it's too late: should we add "_PM" or "_PM_NL" in the list of commands?

Quoted 1 line

Yep, will do in the next iteration.

Thanks!

Quoted 7 lines
Quoted 3 lines

Also it could be nice to add (later?) comments about the API: what does each command do, which (optional) parameters to use and what reply you will get (if any).

Uhm... locking at existing genl family, this kind of documentation is outside the scope of the uapi header ? I guess because it will bloat the header too much ?!?

OK, I was only thinking about something like:

MPTCP_CMD_ADD_ADDR: param1 [optional param2]
Add addresses that will be announced / used to create new subflows

Quoted 9 lines

[...]

Quoted 6 lines

net/mptcp/pm_netlink.c line 33

Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+struct pm_nl_pernet {
+	/* protects pernet updates */
+	spinlock_t		lock;
+	struct list_head	addr_list;

detail: maybe clearer with local_addr_list?

Ok, will change in next iteration

Thanks!

Quoted 4 lines
Quoted 1 line

Should we not maintain a list of remote_add_addr?

I explicitly tried to avoid that: a per netns list of remote addresses could be quite long/expensive to maintain.

Fine for me if we don't need it for the moment.

Quoted 15 lines

[...]

Quoted 14 lines

net/mptcp/pm_netlink.c line 53

Quoted 11 lines
net/mptcp/pm_netlink.c new file +11 -0
+static bool addresses_equal(const struct mptcp_addr_info *a,
+			    struct mptcp_addr_info *b, bool use_port)
+{
+	bool addr_equals;
+
+	if (a->family != b->family)
+		return false;
+
+	if (a->family == AF_INET)
+		addr_equals = !memcmp(&a->addr, &b->addr, sizeof(b->addr));
+	else

You need to surround this block with:

Quoted 3 lines
Quoted 1 line
    #if IS_ENABLED(CONFIG_MPTCP_IPV6)

Will do in the next iteration.

Thanks!

Quoted 6 lines
Quoted 3 lines

Out of curriosity, what's the recommended way to deal with IPv4 and
IPv6: should we always have "else if (a->family == AF_INET6)" (or a switch/case) or can we assume that if it is not v4, it is v6?

In this specific case, we can do this assumption, as the family has been validated before (by the netlink callback and/or the socket code).

I see, thank you!

Quoted 6 lines
Quoted 4 lines

net/mptcp/pm_netlink.c line 54

Quoted 2 lines
net/mptcp/pm_netlink.c new file +1 -0
+		addr_equals = !memcmp(&a->addr6, &b->addr6, sizeof(b->addr6));

detail: you can also use ipv6_addr_cmp(). (and not memcmp for v4?)

Will do in the next iteration.

Thanks!

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
net/mptcp/pm_netlink.c new file +7 -0
+
+	if (!addr_equals)
+		return false;
+	if (!use_port)
+		return true;
+
+	return a->port == b->port;
Quoted 8 lines

net/mptcp/pm_netlink.c line 67

Quoted 6 lines
net/mptcp/pm_netlink.c new file +6 -0
+}
+
+static void local_address(const struct sock_common *skc,
+			  struct mptcp_addr_info *addr)
+{
+	addr->family = skc->skc_family;

Should we copy the source port, just in case?

Quoted 3 lines

The source port explicitly omitted for local addresses as it usually changes across subflows and we want to ignore it. I'll add a comment in the next iteration

Fine for me, thanks, we can add it later if we need it for some other reasons.

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
net/mptcp/pm_netlink.c new file +28 -0
+	if (addr->family == AF_INET)
+		addr->addr.s_addr = skc->skc_rcv_saddr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	else if (addr->family == AF_INET6)
+		addr->addr6 = skc->skc_v6_rcv_saddr;
+#endif
+}
+
+static void remote_address(const struct sock_common *skc,
+			   struct mptcp_addr_info *addr)
+{
+	addr->family = skc->skc_family;
+	addr->port = skc->skc_dport;
+	if (addr->family == AF_INET)
+		addr->addr.s_addr = skc->skc_daddr;
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	else if (addr->family == AF_INET6)
+		addr->addr6 = skc->skc_v6_daddr;
+#endif
+}
+
+static bool lookup_subflow_by_saddr(const struct mptcp_sock *msk,
+				    struct mptcp_addr_info *saddr)
+{
+	struct mptcp_subflow_context *subflow;
+	struct mptcp_addr_info cur;
+	struct sock_common *skc;
+
Quoted 8 lines

net/mptcp/pm_netlink.c line 99

Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+	list_for_each_entry(subflow, &msk->conn_list, node) {
+		skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
+
+		local_address(skc, &cur);

I guess it's OK to do the copy to ease the comparison here below, right? (we are going to do that only when creating subflows so it seems fine. Maybe should we add a comment if we reuse this function later?)

Quoted 4 lines

Are you concerned about performances? I think this is really unnoticeable. The copied data will be in cache, possibly even in registers, and the overhead to traverse the subflow list (with possibly different cache misses per subflow) will be far greater.

Thank you for the justification. Indeed, I didn't think about the traverse of the subflow list.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
net/mptcp/pm_netlink.c new file +6 -0
+static void check_work_pending(struct mptcp_sock *msk)
+{
+	if (msk->pm.add_addr_signaled == msk->pm.add_addr_signal_max &&
+	    msk->pm.local_addr_used == msk->pm.local_addr_max)
+		WRITE_ONCE(msk->pm.work_pending, false);
+}
Quoted 8 lines

net/mptcp/pm_netlink.c line 158

Quoted 2 lines
net/mptcp/pm_netlink.c new file +2 -0
+
+static void mptcp_pm_create_subflow_or_signal(struct mptcp_sock *msk)

detail: I think we should avoid using signal alone because MP_FAIL, REM_ADD, MP_BACKUP, etc. are signals as well, no?
It's maybe just me but I find it clearer, when it is linked to ADD_ADDR, to use "announce" instead of the generic term "signal". But that's a detail. As long as it is clear for everybody :-)

Quoted 3 lines

I picked 'signal' because the term was already in use in the existing code. I can change it to *'signal_addr' to be consistent with other names.

I should have maybe react earlier and that's certainly mainly just me who is used to talk about announced addresses. I can get used to one or the other :)

Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
net/mptcp/pm_netlink.c new file +22 -0
+{
+	struct sock *sk = (struct sock *)msk;
+	struct mptcp_pm_addr_entry *local;
+	struct mptcp_addr_info remote;
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	lock_sock(sk);
+
+	spin_lock_bh(&msk->pm.lock);
+	msk->pm.status = MPTCP_PM_IDLE;
+	pr_debug("local %d:%d signal %d:%d\n",
+		 msk->pm.local_addr_used, msk->pm.local_addr_max,
+		 msk->pm.add_addr_signaled, msk->pm.add_addr_signal_max);
+
+	/* check first if should create a new subflow */
+	if (msk->pm.local_addr_used < msk->pm.local_addr_max) {
+		remote_address((struct sock_common *)sk, &remote);
+
+		local = select_local_address(pernet, msk);
+		if (local) {
Quoted 8 lines

net/mptcp/pm_netlink.c line 185

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+			msk->pm.local_addr_used++;
+			check_work_pending(msk);
+			spin_unlock_bh(&msk->pm.lock);
+			__mptcp_subflow_connect(sk, local->ifindex,
+						&local->addr, &remote);

Should we do anything special if this fail?
(decrement local_addr_used? retry later?)

Quoted 5 lines

IIRC, according to the RFC we must not retry if the address is unreachable and/or the path is not MPTCP capable. So we should retry only if failing e.g. due to an allocation error. Overall a correct retry policy looks a bit too complex for this stage to me. I think we can add that later, if needed.

Fine for me.
So no need to decrement msk->pm.local_addr_used, right?

Quoted 10 lines

[...]

Quoted 6 lines

+void mptcp_pm_nl_add_addr(struct mptcp_sock *msk)

(it's maybe just me but should we rename this by adding "_recv"? Same for the caller and related functions because it was not clear we are doing some actions not add an address or produce an add_addr but because we just received one)

Ok, will do in the next iteration.

Thanks!

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
net/mptcp/pm_netlink.c new file +14 -0
+{
+	struct sock *sk = (struct sock *)msk;
+	struct mptcp_addr_info remote;
+	struct mptcp_addr_info local;
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
+
+	spin_lock_bh(&msk->pm.lock);
+	msk->pm.status = MPTCP_PM_IDLE;
+	pr_debug("accepted %d:%d remote family %d",
+		 msk->pm.add_addr_accepted, msk->pm.add_addr_accept_max,
+		 msk->pm.remote.family);
+	if (++msk->pm.add_addr_accepted >= msk->pm.add_addr_accept_max)
Quoted 8 lines

net/mptcp/pm_netlink.c line 243

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+		WRITE_ONCE(msk->pm.accept_addr, false);
+
+	/* connect to the specified remote address, using whatever
+	 * local address the routing configuration will pick.
+	 */

Should we try with all local IP the userspace added (+ the original one)? → to have a fullmesh

Quoted 1 line

I would postpone this one to later.

Fine for me!

Quoted 13 lines
Quoted 12 lines

net/mptcp/pm_netlink.c line 252

Quoted 10 lines
net/mptcp/pm_netlink.c new file +9 -0
+	remote = msk->pm.remote;
+	if (!remote.port)
+		remote.port = sk->sk_dport;
+	memset(&local, 0, sizeof(local));
+	local.family = remote.family;
+	spin_unlock_bh(&msk->pm.lock);
+
+	lock_sock(sk);
+	__mptcp_subflow_connect((struct sock *)msk, 0, &local, &remote);

Should we do anything special if this fail?

Quoted 1 line

Same situation as the other __mptcp_subflow_connect()

Also no need to decrement msk->pm.add_addr_accepted, right?

Quoted 10 lines
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	release_sock(sk);

Do we need to clear "pm.remote" somewhere? How do we deal with multiple received ADD_ADDR? Even if with the "echo", I guess we might receive a new one before the workqueue has finished dealing with the previous one, no?

The idea is that the workqueue does sort of rate-limiting on subflow creation. To cope with multiple 'concurrent' addresses we need to add additiona/dynamic storage. IIRC the RFC allow us to ignore multiple ADD_ADDR options as it fit us.

OK, I guess it's fine for the moment. But it seems not unlikely to have a bunch of ADD_ADDR exchanged at the beginning of the connection (IPv4/v6). Or even later if the client sends new ADD_ADDRs because a new interface is available.

But that would be for later.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
net/mptcp/pm_netlink.c new file +4 -0
+}
+
+static bool address_use_port(struct mptcp_pm_addr_entry *entry)
+{
Quoted 8 lines

net/mptcp/pm_netlink.c line 263

Quoted 6 lines
net/mptcp/pm_netlink.c new file +6 -0
+	return (entry->flags &
+		(MPTCP_PM_ADDR_FLAG_SIGNAL | MPTCP_PM_ADDR_FLAG_SUBFLOW)) ==
+		MPTCP_PM_ADDR_FLAG_SIGNAL;
+}
+
+static int mptcp_pm_nl_append_new_addr(struct pm_nl_pernet *pernet,

detail: Here as well, should we add _local → new_local_addr?

Quoted 1 line

Ok, will do in the next iteration.

Thanks!

Quoted 12 lines
Quoted 11 lines

net/mptcp/pm_netlink.c line 272

Quoted 9 lines
net/mptcp/pm_netlink.c new file +9 -0
+				       struct mptcp_pm_addr_entry *entry)
+{
+	struct mptcp_pm_addr_entry *cur;
+	int ret = -EINVAL;
+
+	spin_lock_bh(&pernet->lock);
+	/* to keep the code simple, don't do IDR-like allocation for address ID,
+	 * just bail when we exceed limits
+	 */

And we also need to support REM_ADDR here I guess.

Quoted 4 lines

Yes, we need to add REM_ADDR support. I think we don't need to add anything specific with the current implementation: we don't store locally remote addess, we don't have anything to delete and we will not re-use them later anyway (due to lack of retry policy).

Sounds good to me.
Note that REM_ADDR can also be used to explain to the other host that they can close a subflow. It can be useful if one host is disconnected before having sent a FIN/RST. The other host doesn't have to keep trying.

Quoted 50 lines
Quoted 41 lines
Quoted 41 lines
net/mptcp/pm_netlink.c new file +41 -0
+	if (pernet->next_id > 255)
+		goto out;
+	if (pernet->addrs >= MPTCP_PM_ADDR_MAX)
+		goto out;
+
+	/* do not insert duplicate address, differentiate on port only
+	 * singled addresses
+	 */
+	list_for_each_entry(cur, &pernet->addr_list, list) {
+		if (addresses_equal(&cur->addr, &entry->addr,
+				    address_use_port(entry) &&
+				    address_use_port(cur)))
+			goto out;
+	}
+
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
+		pernet->add_addr_signal_max++;
+	if (entry->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+		pernet->local_addr_max++;
+
+	entry->addr.id = pernet->next_id++;
+	pernet->addrs++;
+	list_add_tail_rcu(&entry->list, &pernet->addr_list);
+	ret = entry->addr.id;
+
+out:
+	spin_unlock_bh(&pernet->lock);
+	return ret;
+}
+
+int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
+{
+	struct mptcp_pm_addr_entry *entry;
+	struct mptcp_addr_info skc_local;
+	struct mptcp_addr_info msk_local;
+	struct pm_nl_pernet *pernet;
+	int ret = -1;
+
+	if (WARN_ON_ONCE(!msk))
+		return -1;
+
Quoted 8 lines

net/mptcp/pm_netlink.c line 316

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+	/* The 0 ID mapping is defined by the first subflow, copied into the msk
+	 * addr
+	 */

Is it still OK to do that if the first subflow is down (but other subflows exist)? I mean, no need to have additional check to see if the subflow 0 is still alive? (I didn't check what we do with the msk for this specific case)

Quoted 6 lines

We must always use the same ID for the same address inside an MTPCP connection scope. Once we associate '0' to one local IP we should use that association till the msk socket exists. With the current code, the first subflow socket structure will exists till mptcp_close, even if the related TCP connection is terminate well before. So this code should be safe.

That's true, thank you for the reminder. We have enough ID anyway.

Quoted 17 lines

[...]

Quoted 7 lines
Quoted 7 lines
net/mptcp/pm_netlink.c new file +7 -0
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	if (entry->addr.family == AF_INET6)
+		entry->addr.addr6 = nla_get_in6_addr(tb[addr_addr]);
+	else
+#endif
+		entry->addr.addr.s_addr = nla_get_in_addr(tb[addr_addr]);
+
Quoted 8 lines

net/mptcp/pm_netlink.c line 452

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+skip_family:
+	if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX])
+		entry->ifindex = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
+	else
+		entry->ifindex = 0;

detail: "entry" is init to 0 at the beginning of this function. Same below for the ID. Or if you remove the memset, the flags are not set to 0

Quoted 1 line

Will drop the 'else' branch in the next iteration.

Thanks! (same for the addr.id but I guess you saw it).

Quoted 7 lines
Quoted 5 lines

net/mptcp/pm_netlink.c line 455

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+
+	if (tb[MPTCP_PM_ADDR_ATTR_ID])
+		entry->addr.id = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_ID]);

Is it not a u8?

yep, funnily enough self-tests passes. Will fix in the next iteration.

Thanks!

Quoted 35 lines
Quoted 27 lines

net/mptcp/pm_netlink.c line 460

Quoted 5 lines
net/mptcp/pm_netlink.c new file +5 -0
+	else
+		entry->addr.id = 0;
+
+	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
+		entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);

(detail if you have to modify this: please add a new line here because most of the time, there is an empty line after a if-statement block)

Quoted 7 lines
net/mptcp/pm_netlink.c new file +7 -0
+	return 0;
+}
+
+static struct pm_nl_pernet *genl_info_pm_nl(struct genl_info *info)
+{
+	return net_generic(genl_info_net(info), pm_nl_pernet_id);
+}

net/mptcp/pm_netlink.c line 477

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+
+static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr, *entry;
+	int ret;
+
+	ret = mptcp_pm_parse_addr(attr, info, true, &addr);
+	if (ret)
Quoted 7 lines

Out of curriosity, is there a recommendation on what to check with "ret"? I mean "ret" is vague and often we can see "if (ret < 0)", like below (also because it is needed in this case), which seems clearer to me. Sometimes, "err" is used and in this case, it is clear to read: "if (err)".
No need to change anything, it's just to know what's recommended but not mandatory I guess.

Quoted 1 line

I'll go with 'err' in the next iteration.

Thanks!

Quoted 22 lines
Quoted 15 lines

net/mptcp/pm_netlink.c line 489

Quoted 12 lines
net/mptcp/pm_netlink.c new file +12 -0
+		return ret;
+
+	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+	if (!entry) {
+		GENL_SET_ERR_MSG(info, "can't allocate addr");
+		return -ENOMEM;
+	}
+
+	*entry = addr;
+	ret = mptcp_pm_nl_append_new_addr(pernet, entry);
+	if (ret < 0) {
+		GENL_SET_ERR_MSG(info, "too many addresses");

detail: Or duplicated one.

Quoted 6 lines

net/mptcp/pm_netlink.c line 347

Quoted 3 lines
net/mptcp/pm_netlink.c new file +3 -0
+		kfree(entry);
+		return ret;
+	}

Should we trigger here the establishement of new subflows and/or the send of ADD_ADDR for all existing MPTCP connections?

Quoted 2 lines

To keep the things simple, I would avoid that. For servers the number of msk sockets to process could be high.

It might be required later but that can be extented. It's mostly for the client where it can be important to start new subflows for existing connections when a new ADD_ADDR is received or a new local address can be used. But that would be for later.

Quoted 23 lines

[...]

Quoted 22 lines
Quoted 9 lines
net/mptcp/pm_netlink.c new file +9 -0
+static int mptcp_nl_cmd_get_addr(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr, *entry;
+	struct sk_buff *msg;
+	void *reply;
+	int ret;
+

net/mptcp/pm_netlink.c line 624

Quoted 10 lines
net/mptcp/pm_netlink.c new file +10 -0
+	ret = mptcp_pm_parse_addr(attr, info, false, &addr);
+	if (ret)
+		return ret;
+
+	msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
+	if (!msg)
+		return -ENOMEM;
+
+	reply = genlmsg_put_reply(msg, info, &mptcp_genl_family, 0,
+				  MPTCP_CMD_ADD_ADDR);

Should it not be MPTCP_CMD_GET_ADDR?

Quoted 5 lines
Quoted 1 line

Can you not use info->genlhdr->cmd? (Same for the other genlmsg_put_reply())

I think you are right. I picked 'MPTCP_CMD_ADD_ADDR' because the reply message is formatted exactly as a MPTCP_CMD_ADD_ADDR command, but it's not the correct way to do this. Will fix in the next iteration.

Thanks!

Quoted 16 lines
Quoted 15 lines

net/mptcp/pm_netlink.c line 704

Quoted 13 lines
net/mptcp/pm_netlink.c new file +12 -0
+mptcp_nl_cmd_set_rcv_add_addrs(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *attr = info->attrs[MPTCP_PM_ATTR_RCV_ADD_ADDRS];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	int limit;
+
+	if (!attr) {
+		GENL_SET_ERR_MSG(info, "missing announce accept limit");
+		return -EINVAL;
+	}
+
+	limit = nla_get_u16(attr);

it should be u32 I think.

Quoted 1 line

Yep, will fix in the next iteration.

Thanks!

Quoted 11 lines
Quoted 9 lines

net/mptcp/pm_netlink.c line 796

Quoted 7 lines
net/mptcp/pm_netlink.c new file +6 -0
+static int __net_init pm_nl_init_net(struct net *net)
+{
+	struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
+
+	INIT_LIST_HEAD_RCU(&pernet->addr_list);
+	__reset_counters(pernet);

I guess it's not strictly needed but doesn't hurt.

Needed on clone()

I forgot about that, thank you!

Quoted 11 lines
Quoted 11 lines

net/mptcp/pm_netlink.c line 827

Quoted 8 lines
net/mptcp/pm_netlink.c new file +7 -0
+void mptcp_pm_nl_init(void)
+{
+	if (register_pernet_subsys(&mptcp_pm_pernet_ops) < 0)
+		panic("Failed to register MPTCP PM pernet subsystem.\n");
+
+	if (genl_register_family(&mptcp_genl_family))
+		panic("Failed to register MPTCP PM netlink family");

(detail: I guess you need "\n")

Quoted 1 line

will fix in the next iteration.

Thanks!

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
author
#17 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Quoted 10 lines · Matthieu Baerts
Quoted 4 lines

The maximum number of received ADD_ADDR limit allows to easily model the 'server' behaviour (max accepted == 0). We could add an additional max_subflows limit, but I think it's only relevant if we do the full- mash strategy.

What the server will do with the received ADD_ADDR? The RFC allows the server to initiate subflows but technically, is it possible for the server to do that if the socket is in "LISTEN" mode and on "CONNECT" mode on the client side?

Quoted 4 lines

If we limit the number of created subflows, we can limit the number of subflows on both the client and the server. Is it possible to limit the number of subflows on the server side with the current version? (It is maybe not needed for the moment.)

I see! Yes, currently we can't limit the number of subflows created for a single mptcp socket on a server. I'm unsure how bad that is, as usually we allow each client to create an arbitrary high number of TCP connection to the server (modulo syn flood).

Still I think adding the ability to impose such limit could be nice. It requires an additional hook (from subflow_syn_recv_sock() towards the PM). If we agree on that, I can try to cover in a separate patch/series.

Quoted 5 lines

When the ADD_ADDRv1 with the 'echo' will be available, does that mean we will add an "important" delay for the creation of new subflows?

I guess at some points, we might want to have the possibility to:
- send ADD_ADDR and MP_JOIN in parallel

We can do the above with the propososed infrastructure. We could additionally create multiple subflows in paraller, but we can't (currently) send multiple ADD_ADD "in parallel".

The main concern I have to support the latter is adding to the msk data structure new fields that related to the specific PM implementation.

(The ones currently present should be generic)

There are likely a bunch of items I missed in v4, so I suspect we will move the discussion on that series.

Thanks,

Paolo

#18 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Hi Paolo,

Quoted 21 lines · Paolo Abeni
Quoted 10 lines · Matthieu Baerts
Quoted 4 lines

The maximum number of received ADD_ADDR limit allows to easily model the 'server' behaviour (max accepted == 0). We could add an additional max_subflows limit, but I think it's only relevant if we do the full- mash strategy.

What the server will do with the received ADD_ADDR? The RFC allows the server to initiate subflows but technically, is it possible for the server to do that if the socket is in "LISTEN" mode and on "CONNECT" mode on the client side?

Quoted 4 lines

If we limit the number of created subflows, we can limit the number of subflows on both the client and the server. Is it possible to limit the number of subflows on the server side with the current version? (It is maybe not needed for the moment.)

I see! Yes, currently we can't limit the number of subflows created for a single mptcp socket on a server. I'm unsure how bad that is, as usually we allow each client to create an arbitrary high number of TCP connection to the server (modulo syn flood).

Quoted 4 lines

Still I think adding the ability to impose such limit could be nice. It requires an additional hook (from subflow_syn_recv_sock() towards the PM). If we agree on that, I can try to cover in a separate patch/series.

We can indeed see that later.

I initially thought you wanted to also protect the server but here the objective is only to protect the client which reacts when an ADD_ADDR is received.

Quoted 9 lines
Quoted 5 lines

When the ADD_ADDRv1 with the 'echo' will be available, does that mean we will add an "important" delay for the creation of new subflows?

I guess at some points, we might want to have the possibility to:
- send ADD_ADDR and MP_JOIN in parallel

We can do the above with the propososed infrastructure. We could additionally create multiple subflows in paraller, but we can't (currently) send multiple ADD_ADD "in parallel".

I we can configure the client not to send ADD_ADDR, it's fine. If we send them, we delay the MP_JOIN because that's what the firewall and load-balancers want.

Quoted 4 lines

The main concern I have to support the latter is adding to the msk data structure new fields that related to the specific PM implementation.

(The ones currently present should be generic)

The space is quite important in mptcp.org. I don't know what's the reasonable max size we can have per msk for the PM.

Quoted 2 lines

There are likely a bunch of items I missed in v4, so I suspect we will move the discussion on that series.

All good, I will look at the v4 ASAP. I hope tomorrow. But I am sure it is fine and we can probably already merge it and provide fixes, if needed, later, no?

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
#19 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

In reply to Paolo Abeni
Quoted 9 lines · Paolo Abeni

I see! Yes, currently we can't limit the number of subflows created for a single mptcp socket on a server. I'm unsure how bad that is, as usually we allow each client to create an arbitrary high number of TCP connection to the server (modulo syn flood).

Still I think adding the ability to impose such limit could be nice. It requires an additional hook (from subflow_syn_recv_sock() towards the PM). If we agree on that, I can try to cover in a separate patch/series.

I think its a must-have, as file descriptor limits don't apply.

author
#20 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Quoted 6 lines · Florian Westphal
Quoted 5 lines · Paolo Abeni

I see! Yes, currently we can't limit the number of subflows created for a single mptcp socket on a server. I'm unsure how bad that is, as usually we allow each client to create an arbitrary high number of TCP connection to the server (modulo syn flood).

Quoted 6 lines
Quoted 4 lines

Still I think adding the ability to impose such limit could be nice. It requires an additional hook (from subflow_syn_recv_sock() towards the PM). If we agree on that, I can try to cover in a separate patch/series.

I think its a must-have, as file descriptor limits don't apply.

Ok I'll work on that!

Can we still merge the series without this feature to unblock Peter ?

Thanks,

Paolo

#21 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Quoted 12 lines · Paolo Abeni
Quoted 11 lines · Florian Westphal
Quoted 9 lines · Paolo Abeni

I see! Yes, currently we can't limit the number of subflows created for a single mptcp socket on a server. I'm unsure how bad that is, as usually we allow each client to create an arbitrary high number of TCP connection to the server (modulo syn flood).

Still I think adding the ability to impose such limit could be nice. It requires an additional hook (from subflow_syn_recv_sock() towards the PM). If we agree on that, I can try to cover in a separate patch/series.

Quoted 5 lines
Quoted 1 line

I think its a must-have, as file descriptor limits don't apply.

Ok I'll work on that!

Can we still merge the series without this feature to unblock Peter ?

No objections, I did not mean that as a veto.

#22 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Hi Paolo, Florian,

Quoted 13 lines · Florian Westphal
Quoted 12 lines · Paolo Abeni
Quoted 11 lines · Florian Westphal
Quoted 9 lines · Paolo Abeni

I see! Yes, currently we can't limit the number of subflows created for a single mptcp socket on a server. I'm unsure how bad that is, as usually we allow each client to create an arbitrary high number of TCP connection to the server (modulo syn flood).

Still I think adding the ability to impose such limit could be nice. It requires an additional hook (from subflow_syn_recv_sock() towards the PM). If we agree on that, I can try to cover in a separate patch/series.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I think its a must-have, as file descriptor limits don't apply.

Ok I'll work on that!

Can we still merge the series without this feature to unblock Peter ?

No objections, I did not mean that as a veto.

Fine for me too.

I can have a look at that after Florian's rebase.

I will also drop "mptcp: Implement basic path manager" patch as mentioned in the cover-letter!

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
#23 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

In reply to Matthieu Baerts
Quoted 3 lines · Matthieu Baerts

*Davide* : I guess no upstreamed version of ss are already using this, right? Anyway because this kernel code is not upstreamed, it's not too late to change, right? :)

yes, it makes sense. At a certain point, I tried to reduce the name length as much as possible, but here _ATTR_ seems legitimate. I will send a squash-to patch in short time.

(and I will share also the 'ss' code I'm using ATM, maybe it's also useful for you)

thanks!

Signature · 1 line
davide
#24 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

Hi Davide,

Quoted 8 lines · Davide Caratti
Quoted 3 lines · Matthieu Baerts

*Davide* : I guess no upstreamed version of ss are already using this, right? Anyway because this kernel code is not upstreamed, it's not too late to change, right? :)

yes, it makes sense. At a certain point, I tried to reduce the name length as much as possible, but here _ATTR_ seems legitimate. I will send a squash-to patch in short time.

Great, thank you!

Quoted 2 lines

(and I will share also the 'ss' code I'm using ATM, maybe it's also useful for you)

Good idea!
We can also add a new repo in github.com/multipath-tcp if needed.

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
author
#25 lore raw

[MPTCP] Re: [PATCH v3 7/9] mptcp: add netlink based PM

In reply to Matthieu Baerts
Quoted 8 lines · Matthieu Baerts

include/uapi/linux/mptcp.h enum { · line 72

Quoted 5 lines
include/uapi/linux/mptcp.h +5 -0
+#define MPTCP_PM_ADDR_ATTR_MAX (__MPTCP_PM_ADDR_ATTR_MAX - 1)
+
+#define MPTCP_PM_ADDR_FLAG_SIGNAL			(1 << 0)
+#define MPTCP_PM_ADDR_FLAG_SUBFLOW			(1 << 1)
+#define MPTCP_PM_ADDR_FLAG_BACKUP			(1 << 2)

detail and we can fix it later if needed: I guess checkpatch will ask us to use BIT(0), etc.

Addendum: BIT() is not available in uapi headers and checkpatch does not complain, so I'll keep this unchanged

Cheers,

Paolo

author
#26 lore raw

PATCH v3 8/9 selftests: add PM netlink functional tests

In reply to Paolo Abeni

This introduces basic self-tests for the PM netlink, checking the basic APIs and possible exceptional values.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

---
v2 -> v3:
- include the newly added self-test script into self-tests infra

---
 tools/testing/selftests/net/mptcp/Makefile    |   7 +-
 .../testing/selftests/net/mptcp/pm_netlink.sh | 123 ++++
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 600 ++++++++++++++++++
 3 files changed, 727 insertions(+), 3 deletions(-)
 create mode 100755 tools/testing/selftests/net/mptcp/pm_netlink.sh
 create mode 100644 tools/testing/selftests/net/mptcp/pm_nl_ctl.c
tools/testing/selftests/net/mptcp/Makefile +4 -3
index 93de52016dde..2985cc2f6168 100644
@@ -1,12 +1,13 @@
 # SPDX-License-Identifier: GPL-2.0
 
 top_srcdir = ../../../../..
+KSFT_KHDR_INSTALL := 1
 
-CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
+CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g  -I$(top_srcdir)/usr/include
 
-TEST_PROGS := mptcp_connect.sh
+TEST_PROGS := mptcp_connect.sh pm_netlink.sh
 
-TEST_GEN_FILES = mptcp_connect
+TEST_GEN_FILES = mptcp_connect pm_nl_ctl
 
 EXTRA_CLEAN := *.pcap
 
tools/testing/selftests/net/mptcp/pm_netlink.sh new file +123 -0

123 lines not on this page · raw message

tools/testing/selftests/net/mptcp/pm_nl_ctl.c new file +600 -0

600 lines not on this page · raw message

Signature · 1 line
2.21.1
author
#27 lore raw

PATCH v3 9/9 selftests: add test-cases for MPTCP MP_JOIN

In reply to Paolo Abeni

Use the pm netlink to configure the creation of several subflows, and verify that via MIB counters.

Update the mptcp_connect program to allow reliable MP_JOIN handshake even on small data file

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>

---
v2 -> v3:
- update self-tests Makefile, too
- really return an error code on error

Notes:
- all the tests trying to establish subflows using multiple local addresses currently fail because we currently don' t send the 4th ack for subflows, so we don't trigger the mptcp_pm_subflow_established() function (subflows are in PREESTABLISHED status)

- need more MIB for more reliable checks,
e.g. MPTcpExtMPJoinSynTx, MPTcpExtMPJoinSynAckRx, AddAddrRx,
AddAddrTx

---
 tools/testing/selftests/net/mptcp/Makefile    |   2 +-
 .../selftests/net/mptcp/mptcp_connect.c       |  19 +-
 .../testing/selftests/net/mptcp/mptcp_join.sh | 296 ++++++++++++++++++
 3 files changed, 314 insertions(+), 3 deletions(-)
 create mode 100755 tools/testing/selftests/net/mptcp/mptcp_join.sh
tools/testing/selftests/net/mptcp/Makefile +1 -1
index 2985cc2f6168..c84589a5c646 100644
@@ -5,7 +5,7 @@ KSFT_KHDR_INSTALL := 1
 
 CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g  -I$(top_srcdir)/usr/include
 
-TEST_PROGS := mptcp_connect.sh pm_netlink.sh
+TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh
 
 TEST_GEN_FILES = mptcp_connect pm_nl_ctl
 
tools/testing/selftests/net/mptcp/mptcp_connect.c +17 -2
index 99579c0223c1..1c8696a1417a 100644
@@ -50,6 +50,7 @@ static int cfg_sock_proto	= IPPROTO_MPTCP;
 static bool tcpulp_audit;
 static int pf = AF_INET;
 static int cfg_sndbuf;
+static bool cfg_join;
 
 static void die_usage(void)
 {
@@ -230,6 +231,7 @@ static int sock_connect_mptcp(const char * const remoteaddr,
 
 static size_t do_rnd_write(const int fd, char *buf, const size_t len)
 {
+	static bool first = true;
 	unsigned int do_w;
 	ssize_t bw;
 
@@ -237,10 +239,19 @@ static size_t do_rnd_write(const int fd, char *buf, const size_t len)
 	if (do_w == 0 || do_w > len)
 		do_w = len;
 
+	if (cfg_join && first && do_w > 100)
+		do_w = 100;
+
 	bw = write(fd, buf, do_w);
 	if (bw < 0)
 		perror("write");
 
+	/* let the join handshake complete, before going on */
+	if (cfg_join && first) {
+		sleep(1);
+		first = false;
+	}
+
 	return bw;
 }
 
@@ -638,7 +649,7 @@ static void maybe_close(int fd)
 {
 	unsigned int r = rand();
 
-	if (r & 1)
+	if (!cfg_join && (r & 1))
 		close(fd);
 }
 
@@ -774,8 +785,12 @@ static void parse_opts(int argc, char **argv)
 {
 	int c;
 
-	while ((c = getopt(argc, argv, "6lp:s:hut:m:b:")) != -1) {
+	while ((c = getopt(argc, argv, "6jlp:s:hut:m:b:")) != -1) {
 		switch (c) {
+		case 'j':
+			cfg_join = true;
+			cfg_mode = CFG_MODE_POLL;
+			break;
 		case 'l':
 			listen_mode = true;
 			break;
tools/testing/selftests/net/mptcp/mptcp_join.sh new file +296 -0

297 lines not on this page · raw message

Signature · 1 line
2.21.1