Skip to contentSkip to conversation

add locking to PM APis, implement PM netlink

PATCH Superseded Paolo Abeni 2 participants 9 messages Feb 17, 2020 – Feb 18, 2020

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Paolo Abeni

author
#0 lore raw

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 should replace the current basic ones.

git tree available at:

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

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

TODO:
- implement MP_JOIN self-tests

---
 include/uapi/linux/mptcp.h                      |   51 +
 net/mptcp/Makefile                              |    3 
 net/mptcp/options.c                             |   59 -
 net/mptcp/pm.c                                  |  325 ++++-----
 net/mptcp/pm_netlink.c                          |  799 ++++++++++++++++++++++++
 net/mptcp/protocol.c                            |    2 
 net/mptcp/protocol.h                            |  112 ++-
 net/mptcp/subflow.c                             |   63 +
 tools/testing/selftests/net/mptcp/Makefile      |    4 
 tools/testing/selftests/net/mptcp/pm_netlink.sh |  149 ++++
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c   |  556 ++++++++++++++++
 11 files changed, 1850 insertions(+), 273 deletions(-)
author
#1 lore raw

PATCH 1/7 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 2/7 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.

Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 net/mptcp/options.c  |  45 +++++++++--------
 net/mptcp/pm.c       | 112 ++++++++++++++-----------------------------
 net/mptcp/protocol.c |   2 +
 net/mptcp/protocol.h |  98 ++++++++++++++++++++++---------------
 4 files changed, 122 insertions(+), 135 deletions(-)
net/mptcp/options.c +24 -21
index 6a2d6cea7d54..13fe6245cfcf 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,20 @@ 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.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 620af9d1c6bc..a30d26661b61 100644
@@ -605,6 +605,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
author
#3 lore raw

PATCH 3/7 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 43bfeb3fa753..c2e0576065b6 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
#4 lore raw

PATCH 4/7 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 |  6 +++--
 net/mptcp/subflow.c  | 58 ++++++++++++++++++++++++++++++++------------
 3 files changed, 47 insertions(+), 19 deletions(-)
net/mptcp/options.c +1 -1
index 29ccff13412e..2716cbc0953f 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 +4 -2
index a64a12a02d19..d16bc5a94f56 100644
@@ -256,8 +256,10 @@ 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, 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 +42 -16

120 lines not on this page · raw message

Signature · 1 line
2.21.1
author
#5 lore raw

PATCH 5/7 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.

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 | 195 ++++++++++++++++++++++---------------------------
 1 file changed, 89 insertions(+), 106 deletions(-)
net/mptcp/pm.c +89 -106
index fb66758e3f61..033393176096 100644
@@ -15,117 +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;
-}
-
-int mptcp_pm_remove_addr(struct mptcp_sock *msk, 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 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;
-
-	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)
+int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id)
 {
-	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)
 {
@@ -143,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)
@@ -158,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)
@@ -172,6 +109,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);
+
+	/* 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->add_addr_accepted++;
+		pm->remote = *addr;
+	}
+
+	spin_unlock_bh(&pm->lock);
 }
 
 /* path manager helpers */
@@ -179,7 +131,27 @@ void mptcp_pm_add_addr(struct mptcp_sock *msk,
 int mptcp_pm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 			 struct mptcp_addr_info *saddr)
 {
-	return 0;
+	struct mptcp_addr_info addr;
+	int ret = -EINVAL;
+
+	spin_lock_bh(&msk->pm.lock);
+
+	/* double check after the lock is acquired */
+	if (!mptcp_pm_should_signal(msk))
+		goto out_unlock;
+
+	/* load real data */
+	memset(&addr, 0, sizeof(addr));
+
+	if (remaining < mptcp_add_addr_len(saddr->family))
+		goto out_unlock;
+
+	WRITE_ONCE(msk->pm.addr_signal, false);
+	ret = 0;
+
+out_unlock:
+	spin_unlock_bh(&msk->pm.lock);
+	return ret;
 }
 
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
@@ -189,6 +161,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 (pm->status) {
+	default:
+		break;
+	}
+
+	sock_put(sk);
 }
 
 void mptcp_pm_data_init(struct mptcp_sock *msk)
Signature · 1 line
2.21.1
author
#6 lore raw

PATCH 6/7 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.

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 |  51 +++
 net/mptcp/Makefile         |   3 +-
 net/mptcp/pm.c             |  18 +-
 net/mptcp/pm_netlink.c     | 799 +++++++++++++++++++++++++++++++++++++
 net/mptcp/protocol.h       |   7 +
 5 files changed, 876 insertions(+), 2 deletions(-)
 create mode 100644 net/mptcp/pm_netlink.c
include/uapi/linux/mptcp.h +51 -0
index 3912a9808fa2..e560df80d45d 100644
@@ -31,4 +31,55 @@ 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,
+	MPTCP_PM_ADDR_ATTR_FLAGS,			/* u32 */
+
+	__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)
+
+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 033393176096..859a88559327 100644
@@ -156,7 +156,7 @@ int 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)
@@ -167,6 +167,18 @@ static void pm_worker(struct work_struct *work)
 	struct sock *sk = (struct sock *)msk;
 
 	switch (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;
 	}
@@ -187,6 +199,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)
@@ -194,4 +208,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 +799 -0

799 lines not on this page · raw message

net/mptcp/protocol.h +7 -0
index 9623f007f235..b8dff59cc8d1 100644
@@ -386,6 +386,13 @@ int 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
author
#7 lore raw

PATCH 7/7 selftests: add PM netlink functional tests

In reply to Paolo Abeni
Signed-off-by Paolo Abeni <pabeni(a)redhat.com>
---
 tools/testing/selftests/net/mptcp/Makefile    |   4 +-
 .../testing/selftests/net/mptcp/pm_netlink.sh | 149 +++++
 tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 556 ++++++++++++++++++
 3 files changed, 707 insertions(+), 2 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 +2 -2
index 93de52016dde..8bbb676e49b6 100644
@@ -2,11 +2,11 @@
 
 top_srcdir = ../../../../..
 
-CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g
+CFLAGS =  -Wall -Wl,--no-as-needed -O2 -g  -iquote../../../../../include/uapi/
 
 TEST_PROGS := mptcp_connect.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 +149 -0

149 lines not on this page · raw message

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

556 lines not on this page · raw message

Signature · 1 line
2.21.1
#8 lore raw

[MPTCP] Re: [PATCH 7/7] selftests: add PM netlink functional tests

Quoted 1 line · Paolo Abeni

+CFLAGS = -Wall -Wl,--no-as-needed -O2 -g -iquote../../../../../include/uapi/

hello Paolo,

nit: what about using KSFT_KHDR_INSTALL ?

Signature · 1 line
davide