Skip to contentSkip to conversation

mptcp: netlink event support

PATCH In review Florian Westphal 3 participants 16 messages Jan 20, 2021 – Jan 27, 2021

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author
#0 lore raw

v2 cover mptcp: netlink event support

This is round 2 of the netlink event series.
No changes here except in patch 4 (minor checkpatch format nit) and patch 5.

Changes since v1:
- add missing export of ssk->sk_err.
This is now done for subflow related events (Mathieu)
- fix a few indendations (Mathieu)
- Update uapi comments (Mathieu)
- fix checkpatch complaints
- fix REM/LOC_ID, its NLA_U8 (Mat, Mathieu)

Florian Westphal (5):
mptcp: split __mptcp_close_ssk helper
mptcp: pass subflow socket to a few helpers
mptcp: avoid lock_fast usage in accept path
genetlink: add CAP_NET_ADMIN test for multicast bind
mptcp: add netlink event support

 include/net/genetlink.h    |   1 +
 include/uapi/linux/mptcp.h |  73 ++++++++++
 net/mptcp/options.c        |   2 +-
 net/mptcp/pm.c             |  24 +++-
 net/mptcp/pm_netlink.c     | 265 ++++++++++++++++++++++++++++++++++++-
 net/mptcp/protocol.c       |  30 +++--
 net/mptcp/protocol.h       |  14 +-
 net/mptcp/subflow.c        |   2 +-
 net/netlink/genetlink.c    |  32 +++++
 9 files changed, 418 insertions(+), 25 deletions(-)
Signature · 1 line
2.26.2
author
#1 lore raw

PATCH v2 1/5 mptcp: split __mptcp_close_ssk helper

Prepare for subflow close events:

When mptcp connection is torn down its enough to send the mptcp socket close notification rather than a subflow close event for all of the subflows followed by the mptcp close event.

This splits the helper: mptcp_close_ssk() will emit the close notification, __mptcp_close_ssk will not.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/pm_netlink.c |  4 ++--
 net/mptcp/protocol.c   | 12 +++++++++---
 net/mptcp/protocol.h   |  4 ++--
 3 files changed, 13 insertions(+), 7 deletions(-)
net/mptcp/pm_netlink.c +2 -2
index 03cb22c5a546..e2f40985b450 100644
@@ -596,7 +596,7 @@ static void mptcp_pm_nl_rm_addr_received(struct mptcp_sock *msk)
 
 		spin_unlock_bh(&msk->pm.lock);
 		mptcp_subflow_shutdown(sk, ssk, how);
-		__mptcp_close_ssk(sk, ssk, subflow);
+		mptcp_close_ssk(sk, ssk, subflow);
 		spin_lock_bh(&msk->pm.lock);
 
 		msk->pm.add_addr_accepted--;
@@ -666,7 +666,7 @@ void mptcp_pm_nl_rm_subflow_received(struct mptcp_sock *msk, u8 rm_id)
 
 		spin_unlock_bh(&msk->pm.lock);
 		mptcp_subflow_shutdown(sk, ssk, how);
-		__mptcp_close_ssk(sk, ssk, subflow);
+		mptcp_close_ssk(sk, ssk, subflow);
 		spin_lock_bh(&msk->pm.lock);
 
 		msk->pm.local_addr_used--;
net/mptcp/protocol.c +9 -3
index e9ad8cb5268b..52ab2ae3d51d 100644
@@ -2114,8 +2114,8 @@ static struct sock *mptcp_subflow_get_retrans(const struct mptcp_sock *msk)
  * so we need to use tcp_close() after detaching them from the mptcp
  * parent socket.
  */
-void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
-		       struct mptcp_subflow_context *subflow)
+static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
+			      struct mptcp_subflow_context *subflow)
 {
 	list_del(&subflow->node);
 
@@ -2147,6 +2147,12 @@ void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
 	sock_put(ssk);
 }
 
+void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
+		     struct mptcp_subflow_context *subflow)
+{
+	__mptcp_close_ssk(sk, ssk, subflow);
+}
+
 static unsigned int mptcp_sync_mss(struct sock *sk, u32 pmtu)
 {
 	return 0;
@@ -2164,7 +2170,7 @@ static void __mptcp_close_subflow(struct mptcp_sock *msk)
 		if (inet_sk_state_load(ssk) != TCP_CLOSE)
 			continue;
 
-		__mptcp_close_ssk((struct sock *)msk, ssk, subflow);
+		mptcp_close_ssk((struct sock *)msk, ssk, subflow);
 	}
 }
 
net/mptcp/protocol.h +2 -2
index 98b0169ab531..2b8f90f523c7 100644
@@ -538,8 +538,8 @@ void mptcp_subflow_fully_established(struct mptcp_subflow_context *subflow,
 bool mptcp_subflow_data_available(struct sock *sk);
 void __init mptcp_subflow_init(void);
 void mptcp_subflow_shutdown(struct sock *sk, struct sock *ssk, int how);
-void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
-		       struct mptcp_subflow_context *subflow);
+void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
+		     struct mptcp_subflow_context *subflow);
 void mptcp_subflow_reset(struct sock *ssk);
 void mptcp_sock_graft(struct sock *sk, struct socket *parent);
 struct socket *__mptcp_nmpc_socket(const struct mptcp_sock *msk);
Signature · 1 line
2.26.2
author
#2 lore raw

PATCH v2 2/5 mptcp: pass subflow socket to a few helpers

In reply to Florian Westphal

Pass the first/initial subflow to the existing functions so they can pass this on to the notification handler that is added later in the series.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/options.c  | 2 +-
 net/mptcp/pm.c       | 4 ++--
 net/mptcp/protocol.c | 4 ++--
 net/mptcp/protocol.h | 4 ++--
 net/mptcp/subflow.c  | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
net/mptcp/options.c +1 -1
index 331d460d82fa..775f0576592e 100644
@@ -866,7 +866,7 @@ static bool check_fully_established(struct mptcp_sock *msk, struct sock *ssk,
 		clear_3rdack_retransmission(ssk);
 		mptcp_pm_subflow_established(msk, subflow);
 	} else {
-		mptcp_pm_fully_established(msk);
+		mptcp_pm_fully_established(msk, ssk, GFP_ATOMIC);
 	}
 	return true;
 
net/mptcp/pm.c +2 -2
index 882b4ece950a..b3f53432b3ea 100644
@@ -68,7 +68,7 @@ int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id)
 
 /* path manager event handlers */
 
-void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side)
+void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
 
@@ -119,7 +119,7 @@ static bool mptcp_pm_schedule_work(struct mptcp_sock *msk,
 	return true;
 }
 
-void mptcp_pm_fully_established(struct mptcp_sock *msk)
+void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk, gfp_t gfp)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
 
net/mptcp/protocol.c +2 -2
index 52ab2ae3d51d..a88fee9b0870 100644
@@ -3030,7 +3030,7 @@ void mptcp_finish_connect(struct sock *ssk)
 	WRITE_ONCE(msk->can_ack, 1);
 	WRITE_ONCE(msk->snd_una, msk->write_seq);
 
-	mptcp_pm_new_connection(msk, 0);
+	mptcp_pm_new_connection(msk, ssk, 0);
 
 	mptcp_rcv_space_init(msk, ssk);
 }
@@ -3274,7 +3274,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
 		list_add(&subflow->node, &msk->conn_list);
 		sock_hold(msk->first);
 		if (mptcp_is_fully_established(newsk))
-			mptcp_pm_fully_established(msk);
+			mptcp_pm_fully_established(msk, msk->first, GFP_KERNEL);
 
 		mptcp_copy_inaddrs(newsk, msk->first);
 		mptcp_rcv_space_init(msk, msk->first);
net/mptcp/protocol.h +2 -2
index 2b8f90f523c7..bf0b3d8d7146 100644
@@ -638,8 +638,8 @@ void mptcp_crypto_hmac_sha(u64 key1, u64 key2, u8 *msg, int len, void *hmac);
 
 void __init mptcp_pm_init(void);
 void mptcp_pm_data_init(struct mptcp_sock *msk);
-void mptcp_pm_new_connection(struct mptcp_sock *msk, int server_side);
-void mptcp_pm_fully_established(struct mptcp_sock *msk);
+void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int server_side);
+void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk, gfp_t gfp);
 bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk);
 void mptcp_pm_connection_closed(struct mptcp_sock *msk);
 void mptcp_pm_subflow_established(struct mptcp_sock *msk,
net/mptcp/subflow.c +1 -1
index 88a165408b07..1b22004b7c22 100644
@@ -679,7 +679,7 @@ static struct sock *subflow_syn_recv_sock(const struct sock *sk,
 			 * created mptcp socket
 			 */
 			new_msk->sk_destruct = mptcp_sock_destruct;
-			mptcp_pm_new_connection(mptcp_sk(new_msk), 1);
+			mptcp_pm_new_connection(mptcp_sk(new_msk), child, 1);
 			mptcp_token_accept(subflow_req, mptcp_sk(new_msk));
 			ctx->conn = new_msk;
 			new_msk = NULL;
Signature · 1 line
2.26.2
author
#3 lore raw

PATCH v2 3/5 mptcp: avoid lock_fast usage in accept path

In reply to Florian Westphal

Once event support is added this may need to allocate memory while msk lock is held with softirqs disabled.

Not using lock_fast also allows to do the allocation with GFP_KERNEL.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 net/mptcp/protocol.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/mptcp/protocol.c +2 -3
index a88fee9b0870..3989135a2d9a 100644
@@ -3262,9 +3262,8 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
 		struct mptcp_sock *msk = mptcp_sk(newsock->sk);
 		struct mptcp_subflow_context *subflow;
 		struct sock *newsk = newsock->sk;
-		bool slowpath;
 
-		slowpath = lock_sock_fast(newsk);
+		lock_sock(newsk);
 
 		/* PM/worker can now acquire the first subflow socket
 		 * lock without racing with listener queue cleanup,
@@ -3290,7 +3289,7 @@ static int mptcp_stream_accept(struct socket *sock, struct socket *newsock,
 			if (!ssk->sk_socket)
 				mptcp_sock_graft(ssk, newsock);
 		}
-		unlock_sock_fast(newsk, slowpath);
+		release_sock(newsk);
 	}
 
 	if (inet_csk_listen_poll(ssock->sk))
Signature · 1 line
2.26.2
author
#4 lore raw

PATCH v2 4/5 genetlink: add CAP_NET_ADMIN test for multicast bind

In reply to Florian Westphal

genetlink sets NL_CFG_F_NONROOT_RECV for its netlink socket so anyone can subscribe to multicast messages.

rtnetlink doesn't allow this unconditionally, rtnetlink_bind() restricts bind requests to CAP_NET_ADMIN for a few groups.

This allows to set GENL_UNS_ADMIN_PERM flag on genl mcast groups to mandate CAP_NET_ADMIN.

This will be used by the upcoming mptcp netlink event facility which exposes the token (mptcp connection identifier) to userspace.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 include/net/genetlink.h |  1 +
 net/netlink/genetlink.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
include/net/genetlink.h +1 -0
index e55ec1597ce7..7cb3fa8310ed 100644
@@ -14,6 +14,7 @@
  */
 struct genl_multicast_group {
 	char			name[GENL_NAMSIZ];
+	u8			flags;
 };
 
 struct genl_ops;
net/netlink/genetlink.c +32 -0
index c992424e4d63..2d6fdf40df66 100644
@@ -1360,11 +1360,43 @@ static struct genl_family genl_ctrl __ro_after_init = {
 	.netnsok = true,
 };
 
+static int genl_bind(struct net *net, int group)
+{
+	const struct genl_family *family;
+	unsigned int id;
+	int ret = 0;
+
+	genl_lock_all();
+
+	idr_for_each_entry(&genl_fam_idr, family, id) {
+		const struct genl_multicast_group *grp;
+		int i;
+
+		if (family->n_mcgrps == 0)
+			continue;
+
+		i = group - family->mcgrp_offset;
+		if (i < 0 || i >= family->n_mcgrps)
+			continue;
+
+		grp = &family->mcgrps[i];
+		if ((grp->flags & GENL_UNS_ADMIN_PERM) &&
+		    !ns_capable(net->user_ns, CAP_NET_ADMIN))
+			ret = -EPERM;
+
+		break;
+	}
+
+	genl_unlock_all();
+	return ret;
+}
+
 static int __net_init genl_pernet_init(struct net *net)
 {
 	struct netlink_kernel_cfg cfg = {
 		.input		= genl_rcv,
 		.flags		= NL_CFG_F_NONROOT_RECV,
+		.bind		= genl_bind,
 	};
 
 	/* we'll bump the group number right afterwards */
Signature · 1 line
2.26.2
author
#6 lore raw

PATCH v2 5/5 mptcp: add netlink event support

In reply to Florian Westphal

Allow userspace (mptcpd) to subscribe to mptcp genl multicast events. This implementation reuses the same event API as the mptcp kernel fork to ease integration of existing tools, e.g. mptcpd.

Supported events include:
1. start and close of an mptcp connection
2. start and close of subflows (joins)
3. announce and withdrawals of addresses
4. subflow priority (backup/non-backup) change.

Signed-off-by Florian Westphal <fw(a)strlen.de>
---
 include/uapi/linux/mptcp.h |  73 +++++++++++
 net/mptcp/pm.c             |  20 ++-
 net/mptcp/pm_netlink.c     | 261 ++++++++++++++++++++++++++++++++++++-
 net/mptcp/protocol.c       |   9 +-
 net/mptcp/protocol.h       |   6 +
 5 files changed, 362 insertions(+), 7 deletions(-)
include/uapi/linux/mptcp.h +73 -0
index 3674a451a18c..4983ced8e1f8 100644
@@ -36,6 +36,7 @@ enum {
 /* netlink interface */
 #define MPTCP_PM_NAME		"mptcp_pm"
 #define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_EV_GRP_NAME    "mptcp_events"
 #define MPTCP_PM_VER		0x1
 
 /*
@@ -104,4 +105,76 @@ struct mptcp_info {
 	__u64	mptcpi_rcv_nxt;
 };
 
+/*
+ * MPTCP_EVENT_CREATED: token, family, saddr4 | saddr6, daddr4 | daddr6,
+ *                      sport, dport
+ * A new MPTCP connection has been created. It is the good time to allocate
+ * memory and send ADD_ADDR if needed. Depending on the traffic-patterns
+ * it can take a long time until the MPTCP_EVENT_ESTABLISHED is sent.
+ *
+ * MPTCP_EVENT_ESTABLISHED: token, family, saddr4 | saddr6, daddr4 | daddr6,
+ *			    sport, dport
+ * A MPTCP connection is established (can start new subflows).
+ *
+ * MPTCP_EVENT_CLOSED: token
+ * A MPTCP connection has stopped.
+ *
+ * MPTCP_EVENT_ANNOUNCED: token, rem_id, family, daddr4 | daddr6 [, dport]
+ * A new address has been announced by the peer.
+ *
+ * MPTCP_EVENT_REMOVED: token, rem_id
+ * An address has been lost by the peer.
+ *
+ * MPTCP_EVENT_SUB_ESTABLISHED: token, family, saddr4 | saddr6,
+ *                              daddr4 | daddr6, sport, dport, backup,
+ *                              if_idx [, error]
+ * A new subflow has been established. 'error' should not be set.
+ *
+ * MPTCP_EVENT_SUB_CLOSED: token, family, saddr4 | saddr6, daddr4 | daddr6,
+ *                         sport, dport, backup, if_idx [, error]
+ * A subflow has been closed. An error (copy of sk_err) could be set if an
+ * error has been detected for this subflow.
+ *
+ * MPTCP_EVENT_SUB_PRIORITY: token, family, saddr4 | saddr6, daddr4 | daddr6,
+ *                           sport, dport, backup, if_idx [, error]
+ *       The priority of a subflow has changed. 'error' should not be set.
+ */
+enum mptcp_event_type {
+	MPTCP_EVENT_UNSPEC = 0,
+	MPTCP_EVENT_CREATED = 1,
+	MPTCP_EVENT_ESTABLISHED = 2,
+	MPTCP_EVENT_CLOSED = 3,
+
+	MPTCP_EVENT_ANNOUNCED = 6,
+	MPTCP_EVENT_REMOVED = 7,
+
+	MPTCP_EVENT_SUB_ESTABLISHED = 10,
+	MPTCP_EVENT_SUB_CLOSED = 11,
+
+	MPTCP_EVENT_SUB_PRIORITY = 13,
+};
+
+enum mptcp_event_attr {
+	MPTCP_ATTR_UNSPEC = 0,
+
+	MPTCP_ATTR_TOKEN,	/* u32 */
+	MPTCP_ATTR_FAMILY,	/* u16 */
+	MPTCP_ATTR_LOC_ID,	/* u8 */
+	MPTCP_ATTR_REM_ID,	/* u8 */
+	MPTCP_ATTR_SADDR4,	/* be32 */
+	MPTCP_ATTR_SADDR6,	/* struct in6_addr */
+	MPTCP_ATTR_DADDR4,	/* be32 */
+	MPTCP_ATTR_DADDR6,	/* struct in6_addr */
+	MPTCP_ATTR_SPORT,	/* be16 */
+	MPTCP_ATTR_DPORT,	/* be16 */
+	MPTCP_ATTR_BACKUP,	/* u8 */
+	MPTCP_ATTR_ERROR,	/* u8 */
+	MPTCP_ATTR_FLAGS,	/* u16 */
+	MPTCP_ATTR_TIMEOUT,	/* u32 */
+	MPTCP_ATTR_IF_IDX,	/* s32 */
+
+	__MPTCP_ATTR_AFTER_LAST
+};
+#define MPTCP_ATTR_MAX (__MPTCP_ATTR_AFTER_LAST - 1)
+
 #endif /* _UAPI_MPTCP_H */
net/mptcp/pm.c +15 -5
index b3f53432b3ea..3a09b6e32f8f 100644
@@ -75,6 +75,7 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int
 	pr_debug("msk=%p, token=%u side=%d", msk, msk->token, server_side);
 
 	WRITE_ONCE(pm->server_side, server_side);
+	mptcp_event(MPTCP_EVENT_CREATED, msk, ssk, GFP_ATOMIC);
 }
 
 bool mptcp_pm_allow_new_subflow(struct mptcp_sock *msk)
@@ -122,13 +123,10 @@ static bool mptcp_pm_schedule_work(struct mptcp_sock *msk,
 void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk, gfp_t gfp)
 {
 	struct mptcp_pm_data *pm = &msk->pm;
+	bool announce = false;
 
 	pr_debug("msk=%p", msk);
 
-	/* try to avoid acquiring the lock below */
-	if (!READ_ONCE(pm->work_pending))
-		return;
-
 	spin_lock_bh(&pm->lock);
 
 	/* mptcp_pm_fully_established() can be invoked by multiple
@@ -138,9 +136,15 @@ void mptcp_pm_fully_established(struct mptcp_sock *msk, const struct sock *ssk,
 	if (READ_ONCE(pm->work_pending) &&
 	    !(msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)))
 		mptcp_pm_schedule_work(msk, MPTCP_PM_ESTABLISHED);
-	msk->pm.status |= BIT(MPTCP_PM_ALREADY_ESTABLISHED);
 
+	if ((msk->pm.status & BIT(MPTCP_PM_ALREADY_ESTABLISHED)) == 0)
+		announce = true;
+
+	msk->pm.status |= BIT(MPTCP_PM_ALREADY_ESTABLISHED);
 	spin_unlock_bh(&pm->lock);
+
+	if (announce)
+		mptcp_event(MPTCP_EVENT_ESTABLISHED, msk, ssk, gfp);
 }
 
 void mptcp_pm_connection_closed(struct mptcp_sock *msk)
@@ -179,6 +183,8 @@ void mptcp_pm_add_addr_received(struct mptcp_sock *msk,
 	pr_debug("msk=%p remote_id=%d accept=%d", msk, addr->id,
 		 READ_ONCE(pm->accept_addr));
 
+	mptcp_event_addr_announced(msk, addr);
+
 	spin_lock_bh(&pm->lock);
 
 	if (!READ_ONCE(pm->accept_addr)) {
@@ -206,6 +212,8 @@ void mptcp_pm_rm_addr_received(struct mptcp_sock *msk, u8 rm_id)
 
 	pr_debug("msk=%p remote_id=%d", msk, rm_id);
 
+	mptcp_event_addr_removed(msk, rm_id);
+
 	spin_lock_bh(&pm->lock);
 	mptcp_pm_schedule_work(msk, MPTCP_PM_RM_ADDR_RECEIVED);
 	pm->rm_id = rm_id;
@@ -218,6 +226,8 @@ void mptcp_pm_mp_prio_received(struct sock *sk, u8 bkup)
 
 	pr_debug("subflow->backup=%d, bkup=%d\n", subflow->backup, bkup);
 	subflow->backup = bkup;
+
+	mptcp_event(MPTCP_EVENT_SUB_PRIORITY, mptcp_sk(subflow->conn), sk, GFP_ATOMIC);
 }
 
 /* path manager helpers */
net/mptcp/pm_netlink.c +260 -1

276 lines not on this page · raw message

net/mptcp/protocol.c +8 -1
index 3989135a2d9a..b5ba832ca58b 100644
@@ -2150,6 +2150,7 @@ static void __mptcp_close_ssk(struct sock *sk, struct sock *ssk,
 void mptcp_close_ssk(struct sock *sk, struct sock *ssk,
 		     struct mptcp_subflow_context *subflow)
 {
+	mptcp_event(MPTCP_EVENT_SUB_CLOSED, mptcp_sk(sk), ssk, GFP_KERNEL);
 	__mptcp_close_ssk(sk, ssk, subflow);
 }
 
@@ -2586,6 +2587,10 @@ static void mptcp_close(struct sock *sk, long timeout)
 	release_sock(sk);
 	if (do_cancel_work)
 		mptcp_cancel_work(sk);
+
+	if (mptcp_sk(sk)->token)
+		mptcp_event(MPTCP_EVENT_CLOSED, mptcp_sk(sk), NULL, GFP_KERNEL);
+
 	sock_put(sk);
 }
 
@@ -3059,7 +3064,7 @@ bool mptcp_finish_join(struct sock *ssk)
 		return false;
 
 	if (!msk->pm.server_side)
-		return true;
+		goto out;
 
 	if (!mptcp_pm_allow_new_subflow(msk))
 		return false;
@@ -3086,6 +3091,8 @@ bool mptcp_finish_join(struct sock *ssk)
 	if (parent_sock && !ssk->sk_socket)
 		mptcp_sock_graft(ssk, parent_sock);
 	subflow->map_seq = READ_ONCE(msk->ack_seq);
+out:
+	mptcp_event(MPTCP_EVENT_SUB_ESTABLISHED, msk, ssk, GFP_ATOMIC);
 	return true;
 }
 
net/mptcp/protocol.h +6 -0
index bf0b3d8d7146..447ce4631b43 100644
@@ -10,6 +10,7 @@
 #include <linux/random.h>
 #include <net/tcp.h>
 #include <net/inet_connection_sock.h>
+#include <uapi/linux/mptcp.h>
 
 #define MPTCP_SUPPORTED_VERSION	1
 
@@ -665,6 +666,11 @@ int mptcp_pm_announce_addr(struct mptcp_sock *msk,
 int mptcp_pm_remove_addr(struct mptcp_sock *msk, u8 local_id);
 int mptcp_pm_remove_subflow(struct mptcp_sock *msk, u8 local_id);
 
+void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
+		 const struct sock *ssk, gfp_t gfp);
+void mptcp_event_addr_announced(const struct mptcp_sock *msk, const struct mptcp_addr_info *info);
+void mptcp_event_addr_removed(const struct mptcp_sock *msk, u8 id);
+
 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk)
 {
 	return READ_ONCE(msk->pm.addr_signal) & BIT(MPTCP_ADD_ADDR_SIGNAL);
Signature · 1 line
2.26.2
#7 lore raw

[MPTCP] Re: [PATCH v2 mptcp-next 5/5] mptcp: add netlink event support

Hi Florian,

Quoted 11 lines · Florian Westphal

Allow userspace (mptcpd) to subscribe to mptcp genl multicast events. This implementation reuses the same event API as the mptcp kernel fork to ease integration of existing tools, e.g. mptcpd.

Supported events include:
1. start and close of an mptcp connection
2. start and close of subflows (joins)
3. announce and withdrawals of addresses
4. subflow priority (backup/non-backup) change.

Signed-off-by Florian Westphal <fw(a)strlen.de>

Thank you for the v2!

(...)

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

Quoted 9 lines
include/uapi/linux/mptcp.h +1 -0
index 3674a451a18c..4983ced8e1f8 100644
@@ -36,6 +36,7 @@ enum {
  /* netlink interface */
  #define MPTCP_PM_NAME		"mptcp_pm"
  #define MPTCP_PM_CMD_GRP_NAME	"mptcp_pm_cmds"
+#define MPTCP_PM_EV_GRP_NAME    "mptcp_events"

We will check if it is OK for Ossama :)

(...)

Quoted 4 lines
net/mptcp/pm_netlink.c +0 -0
index e2f40985b450..c2939362f47a 100644

(...)

Quoted 16 lines
net/mptcp/pm_netlink.c +16 -0
+static int mptcp_event_put_token_and_ssk(struct sk_buff *skb,
+					 const struct mptcp_sock *msk,
+					 const struct sock *ssk)
+{
+	const struct sock *sk = (const struct sock *)msk;
+	const struct mptcp_subflow_context *sf;
+	u8 sk_err;
+
+	if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
+		return -EMSGSIZE;
+
+	if (mptcp_event_add_subflow(skb, ssk))
+		return -EMSGSIZE;
+
+	sf = mptcp_subflow_ctx(ssk);
+	if (WARN_ON_ONCE(!sf))

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) · line 1571

Quoted 10 lines
net/mptcp/pm_netlink.c +10 -0
+		return -EINVAL;
+
+	if (nla_put_u8(skb, MPTCP_ATTR_BACKUP, sf->backup))
+		return -EMSGSIZE;
+
+	if (ssk->sk_bound_dev_if &&
+	    nla_put_s32(skb, MPTCP_ATTR_IF_IDX, ssk->sk_bound_dev_if))
+		return -EMSGSIZE;
+
+	sk_err = ssk->sk_err;

Could we have an error set on the msk? (sk->sk_err)
I don't remember why but in mptcp.org, we take the one of the subflow if there is one and we fallback to the sk_err of the meta. But I don't remember in which case we can have sk_err set on the meta. And not sure if we can have one in the msk :)

It seems that we look for sk_err only in the ssk (subflow.c) and in mptcp_recvmsg() but maybe just because this code is an adaptation of the one from TCP?

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) · line 1577

Quoted 6 lines
net/mptcp/pm_netlink.c +6 -0
+	if (sk_err && sk->sk_state == TCP_ESTABLISHED &&
+	    nla_put_u8(skb, MPTCP_ATTR_ERROR, sk_err))
+		return -EMSGSIZE;
+
+	return 0;
+}

Thank you for the other modifications!

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#8 lore raw

[MPTCP] Re: [PATCH v2 mptcp-next 5/5] mptcp: add netlink event support

Quoted 3 lines · Matthieu Baerts

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) · line 1571

Quoted 1 line
net/mptcp/pm_netlink.c +1 -0
+	sk_err = ssk->sk_err;

Could we have an error set on the msk? (sk->sk_err)

Userspace interacts with the msk so it should already get proper errnos via syscalls, no?

#9 lore raw

[MPTCP] Re: [PATCH v2 mptcp-next 5/5] mptcp: add netlink event support

Quoted 7 lines · Florian Westphal
Quoted 3 lines · Matthieu Baerts

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) · line 1571

Quoted 1 line
net/mptcp/pm_netlink.c +1 -0
+	sk_err = ssk->sk_err;

Could we have an error set on the msk? (sk->sk_err)

Userspace interacts with the msk so it should already get proper errnos via syscalls, no?

I think likely the module (e.g. mptcpd) interacting with this in-kernel Netlink PM is not the one which initiated the connection (msk).

On the other hand, we also check that the msk is still in established mode. What kind of error could we have?

In mptcp.org, we might have taken the one from the meta "just in case".

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
Reviewed-by
#10 lore raw

[MPTCP] Re: [PATCH v2 mptcp-next 5/5] mptcp: add netlink event support

In reply to Matthieu Baerts

Hi Florian,

Quoted 13 lines · Matthieu Baerts

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

Quoted 9 lines · Florian Westphal
include/uapi/linux/mptcp.h +1 -0
index 3674a451a18c..4983ced8e1f8 100644
@@ -36,6 +36,7 @@ enum {
    /* netlink interface */
    #define MPTCP_PM_NAME        "mptcp_pm"
    #define MPTCP_PM_CMD_GRP_NAME    "mptcp_pm_cmds"
+#define MPTCP_PM_EV_GRP_NAME    "mptcp_events"

We will check if it is OK for Ossama :)

Just to be sure it is clear for everyone, it was decided yesterday at the weekly meeting to switch to "mptcp_pm_events".

Quoted 27 lines
Quoted 4 lines
net/mptcp/pm_netlink.c +0 -0
index e2f40985b450..c2939362f47a 100644

(...)

Quoted 20 lines
net/mptcp/pm_netlink.c +20 -0
+static int mptcp_event_put_token_and_ssk(struct sk_buff *skb,
+                     const struct mptcp_sock *msk,
+                     const struct sock *ssk)
+{
+    const struct sock *sk = (const struct sock *)msk;
+    const struct mptcp_subflow_context *sf;
+    u8 sk_err;
+
+    if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
+        return -EMSGSIZE;
+
+    if (mptcp_event_add_subflow(skb, ssk))
+        return -EMSGSIZE;
+
+    sf = mptcp_subflow_ctx(ssk);
+    if (WARN_ON_ONCE(!sf))
+        return -EINVAL;
+
+    if (nla_put_u8(skb, MPTCP_ATTR_BACKUP, sf->backup))
+        return -EMSGSIZE;
Quoted 8 lines

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) · line 1571

Quoted 6 lines
net/mptcp/pm_netlink.c +6 -0
+
+    if (ssk->sk_bound_dev_if &&
+        nla_put_s32(skb, MPTCP_ATTR_IF_IDX, ssk->sk_bound_dev_if))
+        return -EMSGSIZE;
+
+    sk_err = ssk->sk_err;

Could we have an error set on the msk? (sk->sk_err)

And here, as discussed yesterday, we would keep "ssk->sk_err" and not use the one from the msk.

I guess Mat and Ossama prefer to quickly validate it before applying these patches, I can wait before applying them. Or maybe I misunderstood and I can apply it sooner.
(And if we only need to change the group name, I can fix that when applying it without having to submit a new version ;-) )

For this patch:

Reviewed-by Matthieu Baerts <matthieu.baerts(a)tessares.net>

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
author
#11 lore raw

[MPTCP] Re: [PATCH v2 mptcp-next 5/5] mptcp: add netlink event support

Quoted 5 lines · Matthieu Baerts

I guess Mat and Ossama prefer to quickly validate it before applying these patches, I can wait before applying them. Or maybe I misunderstood and I can apply it sooner.
(And if we only need to change the group name, I can fix that when applying it without having to submit a new version ;-) )

Thanks, let me know if there are rejects and I can repost.

#12 lore raw

[MPTCP] Re: [PATCH v2 mptcp-next 5/5] mptcp: add netlink event support

In reply to Matthieu Baerts
Quoted 56 lines · Matthieu Baerts

Hi Florian,

Quoted 13 lines · Matthieu Baerts

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

Quoted 9 lines · Florian Westphal
include/uapi/linux/mptcp.h +1 -0
index 3674a451a18c..4983ced8e1f8 100644
@@ -36,6 +36,7 @@ enum {
    /* netlink interface */
    #define MPTCP_PM_NAME        "mptcp_pm"
    #define MPTCP_PM_CMD_GRP_NAME    "mptcp_pm_cmds"
+#define MPTCP_PM_EV_GRP_NAME    "mptcp_events"

We will check if it is OK for Ossama :)

Just to be sure it is clear for everyone, it was decided yesterday at the weekly meeting to switch to "mptcp_pm_events".

Quoted 27 lines
Quoted 4 lines
net/mptcp/pm_netlink.c +0 -0
index e2f40985b450..c2939362f47a 100644

(...)

Quoted 20 lines
net/mptcp/pm_netlink.c +20 -0
+static int mptcp_event_put_token_and_ssk(struct sk_buff *skb,
+                     const struct mptcp_sock *msk,
+                     const struct sock *ssk)
+{
+    const struct sock *sk = (const struct sock *)msk;
+    const struct mptcp_subflow_context *sf;
+    u8 sk_err;
+
+    if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
+        return -EMSGSIZE;
+
+    if (mptcp_event_add_subflow(skb, ssk))
+        return -EMSGSIZE;
+
+    sf = mptcp_subflow_ctx(ssk);
+    if (WARN_ON_ONCE(!sf))
+        return -EINVAL;
+
+    if (nla_put_u8(skb, MPTCP_ATTR_BACKUP, sf->backup))
+        return -EMSGSIZE;
Quoted 8 lines

net/mptcp/pm_netlink.c static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info) · line 1571

Quoted 6 lines
net/mptcp/pm_netlink.c +6 -0
+
+    if (ssk->sk_bound_dev_if &&
+        nla_put_s32(skb, MPTCP_ATTR_IF_IDX, ssk->sk_bound_dev_if))
+        return -EMSGSIZE;
+
+    sk_err = ssk->sk_err;

Could we have an error set on the msk? (sk->sk_err)

Quoted 9 lines

And here, as discussed yesterday, we would keep "ssk->sk_err" and not use the one from the msk.

I guess Mat and Ossama prefer to quickly validate it before applying these patches, I can wait before applying them. Or maybe I misunderstood and I can apply it sooner.
(And if we only need to change the group name, I can fix that when applying it without having to submit a new version ;-) )

Hi Matthieu -

Go ahead and apply the series to the export branch with the group name fix, if other fixes are needed after testing we can squash those.

Thanks,

--
Mat Martineau
Intel

Acked-by on v2 4/5
#5 lore raw

[MPTCP] Re: [PATCH v2 mptcp-next 4/5] genetlink: add CAP_NET_ADMIN test for multicast bind

In reply to Florian Westphal
Quoted 9 lines · Florian Westphal

genetlink sets NL_CFG_F_NONROOT_RECV for its netlink socket so anyone can subscribe to multicast messages.

rtnetlink doesn't allow this unconditionally, rtnetlink_bind() restricts bind requests to CAP_NET_ADMIN for a few groups.

This allows to set GENL_UNS_ADMIN_PERM flag on genl mcast groups to mandate CAP_NET_ADMIN.

Quoted 9 lines

This will be used by the upcoming mptcp netlink event facility which exposes the token (mptcp connection identifier) to userspace.

Signed-off-by Florian Westphal <fw(a)strlen.de>

---
include/net/genetlink.h | 1 + net/netlink/genetlink.c | 32 ++++++++++++++++++++++++++++++++

2 files changed, 33 insertions(+)
Acked-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

--
Mat Martineau
Intel

Reviewed-by on the v2 series
#13 lore raw
In reply to Florian Westphal
Quoted 19 lines · Florian Westphal

This is round 2 of the netlink event series.
No changes here except in patch 4 (minor checkpatch format nit) and patch 5.

Changes since v1:
- add missing export of ssk->sk_err.
This is now done for subflow related events (Mathieu)
- fix a few indendations (Mathieu)
- Update uapi comments (Mathieu)
- fix checkpatch complaints
- fix REM/LOC_ID, its NLA_U8 (Mat, Mathieu)

Florian Westphal (5):
mptcp: split __mptcp_close_ssk helper
mptcp: pass subflow socket to a few helpers
mptcp: avoid lock_fast usage in accept path
genetlink: add CAP_NET_ADMIN test for multicast bind
mptcp: add netlink event support

Quoted 13 lines
include/net/genetlink.h    |   1 +
include/uapi/linux/mptcp.h |  73 ++++++++++
net/mptcp/options.c        |   2 +-
net/mptcp/pm.c             |  24 +++-
net/mptcp/pm_netlink.c     | 265 ++++++++++++++++++++++++++++++++++++-
net/mptcp/protocol.c       |  30 +++--
net/mptcp/protocol.h       |  14 +-
net/mptcp/subflow.c        |   2 +-
net/netlink/genetlink.c    |  32 +++++
9 files changed, 418 insertions(+), 25 deletions(-)
Signature · 1 line
2.26.2

Just clarifying tags after my reply to the patch 5 thread, Matthieu please tag patches 1, 2, 3, and 5 with:

Reviewed-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

(patch 4 tag is different, in a separate email)

--
Mat Martineau
Intel

#14 lore raw

Hi Florian, Mat,

Quoted 7 lines · Mat Martineau
Quoted 3 lines · Florian Westphal

This is round 2 of the netlink event series.
No changes here except in patch 4 (minor checkpatch format nit) and patch 5.

Quoted 6 lines

Just clarifying tags after my reply to the patch 5 thread, Matthieu please tag patches 1, 2, 3, and 5 with:

Reviewed-by Mat Martineau <mathew.j.martineau(a)linux.intel.com>

(patch 4 tag is different, in a separate email)

Thank you for the patches and the series!

Just applied to our tree with the RvB and Acked-by tags, the modification of the group (mptcp_pm_events) and a micro checkpatch format nit (blank line after enum like the previous ones in mptcp.h).

- 57b1e8d7873c: mptcp: split __mptcp_close_ssk helper
- 37f87493bc63: mptcp: pass subflow socket to a few helpers
- 5e2330f127b5: mptcp: avoid lock_fast usage in accept path
- edd4b6f8f6ac: genetlink: add CAP_NET_ADMIN test for multicast bind
- f15cd5fd4c26: mptcp: add netlink event support
- Results: de7588363638..daa6a08b00eb

Tests + export are in progress!

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net
#15 lore raw

Hi Florian, Mat,

Quoted 1 line · Matthieu Baerts

- f15cd5fd4c26: mptcp: add netlink event support

I did a small extra modification on top of this patch to keep the alignment with the rest. Nothing important but still, if you need to copy the content of include/uapi/linux/mptcp.h elsewhere (i.e. iproute2 and mptcpd), please make sure to use the latest version :)

- 1f2bcf78ff83: mptcp: use tab to align mptcp_pm_events
- (of course no co-dev-by tag added for that)
- Results: 331067123e0c..1d8e7211c639

Tests + export are in progress.

Cheers,
Matt

Signature · 2 lines
Tessares | Belgium | Hybrid Access Solutions
www.tessares.net