All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kishen Maloor <kishen.maloor@intel.com>
To: kishen.maloor@intel.com, mptcp@lists.linux.dev
Subject: [PATCH mptcp-next 13/21] mptcp: netlink: Add MPTCP_PM_CMD_ANNOUNCE
Date: Thu, 16 Dec 2021 17:23:06 -0500	[thread overview]
Message-ID: <20211216222314.1244708-14-kishen.maloor@intel.com> (raw)
In-Reply-To: <20211216222314.1244708-1-kishen.maloor@intel.com>

This change adds a MPTCP netlink interface for issuing
ADD_ADDR advertisements over the chosen MPTCP connection from a
userspace path manager.

The command requires the following parameters:
{ token, { loc_id, family, daddr4 | daddr6 [, dport] } [, if_idx],
flags/signal }.

Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
---
 include/uapi/linux/mptcp.h |   2 +
 net/mptcp/pm_netlink.c     | 111 +++++++++++++++++++++++++++++++++++++
 2 files changed, 113 insertions(+)

diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h
index f106a3941cdf..40380be396c8 100644
--- a/include/uapi/linux/mptcp.h
+++ b/include/uapi/linux/mptcp.h
@@ -55,6 +55,7 @@ enum {
 	MPTCP_PM_ATTR_ADDR,				/* nested address */
 	MPTCP_PM_ATTR_RCV_ADD_ADDRS,			/* u32 */
 	MPTCP_PM_ATTR_SUBFLOWS,				/* u32 */
+	MPTCP_PM_ATTR_TOKEN,				/* u32 */
 
 	__MPTCP_PM_ATTR_MAX
 };
@@ -92,6 +93,7 @@ enum {
 	MPTCP_PM_CMD_SET_LIMITS,
 	MPTCP_PM_CMD_GET_LIMITS,
 	MPTCP_PM_CMD_SET_FLAGS,
+	MPTCP_PM_CMD_ANNOUNCE,
 
 	__MPTCP_PM_CMD_AFTER_LAST
 };
diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 067a74ad7c5c..2e9ca5730b10 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1268,6 +1268,7 @@ static const struct nla_policy mptcp_pm_policy[MPTCP_PM_ATTR_MAX + 1] = {
 					NLA_POLICY_NESTED(mptcp_pm_addr_policy),
 	[MPTCP_PM_ATTR_RCV_ADD_ADDRS]	= { .type	= NLA_U32,	},
 	[MPTCP_PM_ATTR_SUBFLOWS]	= { .type	= NLA_U32,	},
+	[MPTCP_PM_ATTR_TOKEN]		= { .type	= NLA_U32,	},
 };
 
 void mptcp_pm_nl_subflow_chk_stale(const struct mptcp_sock *msk, struct sock *ssk)
@@ -2028,6 +2029,111 @@ static int mptcp_nl_addr_backup(struct net *net,
 	return ret;
 }
 
+static int mptcp_nl_cmd_announce(struct sk_buff *skb, struct genl_info *info)
+{
+	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
+	struct nlattr *addr = info->attrs[MPTCP_PM_ATTR_ADDR];
+	struct pm_nl_pernet *pernet = genl_info_pm_nl(info);
+	struct mptcp_pm_addr_entry addr_val;
+	struct mptcp_local_lsk *lsk_ref;
+	bool reuse_port = false;
+	struct mptcp_sock *msk;
+	struct socket *lsk;
+	u32 token_val;
+	int err;
+
+	if (!addr || !token) {
+		GENL_SET_ERR_MSG(info, "missing required inputs");
+		return -EINVAL;
+	}
+
+	token_val = nla_get_u32(token);
+
+	msk = mptcp_token_get_sock(sock_net(skb->sk), token_val);
+	if (!msk) {
+		NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token");
+		return -EINVAL;
+	}
+
+	if (READ_ONCE(msk->pm.pm_type) != MPTCP_PM_TYPE_USERSPACE) {
+		GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected");
+		return -EINVAL;
+	}
+
+	err = mptcp_pm_parse_entry(addr, info, true, &addr_val);
+	if (err < 0) {
+		GENL_SET_ERR_MSG(info, "error parsing local address");
+		return err;
+	}
+
+	if (addr_val.addr.id == 0 || !(addr_val.flags & MPTCP_PM_ADDR_FLAG_SIGNAL)) {
+		GENL_SET_ERR_MSG(info, "invalid addr id or flags");
+		return -EINVAL;
+	}
+
+	if (!addr_val.addr.port) {
+		addr_val.addr.port =
+			((struct inet_sock *)inet_sk
+			 ((struct sock *)msk))->inet_sport;
+
+		reuse_port = true;
+	}
+
+	lsk_ref = lsk_list_find(pernet, &addr_val.addr);
+
+	if (!lsk_ref) {
+		err = mptcp_pm_nl_create_listen_socket(skb->sk, &addr_val, &lsk);
+		if ((err && !reuse_port) || (err && (err != -EADDRINUSE) && reuse_port)) {
+			GENL_SET_ERR_MSG(info, "error creating listen socket");
+			return err;
+		}
+
+		if (lsk) {
+			lsk_ref = lsk_list_add(pernet, &addr_val.addr, lsk);
+			if (!lsk_ref) {
+				GENL_SET_ERR_MSG(info, "can't allocate lsk ref");
+				sock_release(lsk);
+				return -ENOMEM;
+			}
+		}
+	}
+
+	if (!reuse_port) {
+		addr_val.lsk_ref = lsk_ref;
+		lsk_ref = NULL;
+	} else {
+		addr_val.addr.port = 0;
+	}
+
+	err = mptcp_userspace_pm_append_new_local_addr(msk, &addr_val);
+	if (err < 0) {
+		if (addr_val.lsk_ref)
+			lsk_list_release(pernet, addr_val.lsk_ref);
+		else if (lsk_ref)
+			lsk_list_release(pernet, lsk_ref);
+		GENL_SET_ERR_MSG(info, "did not match address and id");
+		return err;
+	}
+
+	lock_sock((struct sock *)msk);
+	spin_lock_bh(&msk->pm.lock);
+
+	if (mptcp_pm_alloc_anno_list(msk, &addr_val, lsk_ref)) {
+		mptcp_pm_announce_addr(msk, &addr_val.addr, false);
+		mptcp_pm_nl_addr_send_ack(msk);
+	}
+
+	spin_unlock_bh(&msk->pm.lock);
+	release_sock((struct sock *)msk);
+
+	if (addr_val.lsk_ref)
+		lsk_list_release(pernet, addr_val.lsk_ref);
+	else if (lsk_ref)
+		lsk_list_release(pernet, lsk_ref);
+
+	return 0;
+}
+
 static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
 {
 	struct mptcp_pm_addr_entry addr = { .addr = { .family = AF_UNSPEC }, }, *entry;
@@ -2370,6 +2476,11 @@ static const struct genl_small_ops mptcp_pm_ops[] = {
 		.doit   = mptcp_nl_cmd_set_flags,
 		.flags  = GENL_ADMIN_PERM,
 	},
+	{
+		.cmd    = MPTCP_PM_CMD_ANNOUNCE,
+		.doit   = mptcp_nl_cmd_announce,
+		.flags  = GENL_ADMIN_PERM,
+	},
 };
 
 static struct genl_family mptcp_genl_family __ro_after_init = {
-- 
2.31.1


  parent reply	other threads:[~2021-12-16 22:24 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-16 22:22 [PATCH mptcp-next 00/21] mptcp: support userspace path management Kishen Maloor
2021-12-16 22:22 ` [PATCH mptcp-next 01/21] mptcp: do not restrict subflows with non-kernel PMs Kishen Maloor
2021-12-16 22:22 ` [PATCH mptcp-next 02/21] mptcp: store remote id from MP_JOIN SYN/ACK in local ctx Kishen Maloor
2021-12-16 22:22 ` [PATCH mptcp-next 03/21] mptcp: reflect remote port (not 0) in ANNOUNCED events Kishen Maloor
2021-12-16 22:22 ` [PATCH mptcp-next 04/21] mptcp: establish subflows from either end of connection Kishen Maloor
2021-12-17 17:41   ` Paolo Abeni
2021-12-21  7:35     ` Kishen Maloor
2021-12-16 22:22 ` [PATCH mptcp-next 05/21] mptcp: netlink: store per namespace list of refcounted listen socks Kishen Maloor
2021-12-17 16:24   ` Matthieu Baerts
2021-12-16 22:22 ` [PATCH mptcp-next 06/21] mptcp: netlink: store lsk ref in mptcp_pm_addr_entry Kishen Maloor
2021-12-17 16:25   ` Matthieu Baerts
2021-12-21  7:29     ` Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 07/21] mptcp: netlink: process IPv6 addrs in creating listening sockets Kishen Maloor
2021-12-17 16:29   ` Matthieu Baerts
2021-12-21  7:32     ` Kishen Maloor
2021-12-21  9:45       ` Paolo Abeni
2021-12-22 20:27         ` Kishen Maloor
2021-12-29 13:52       ` Matthieu Baerts
2022-01-05  3:35         ` Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 08/21] mptcp: attempt to add listening sockets for announced addrs Kishen Maloor
2021-12-17 16:34   ` Matthieu Baerts
2021-12-21  7:34     ` Kishen Maloor
2021-12-29 14:03       ` Matthieu Baerts
2022-01-05  3:37         ` Kishen Maloor
2021-12-17 18:04   ` Paolo Abeni
2021-12-18  1:17     ` Mat Martineau
2021-12-21  7:44       ` Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 09/21] mptcp: allow ADD_ADDR reissuance by userspace PMs Kishen Maloor
2021-12-17 18:38   ` Paolo Abeni
2021-12-21  7:33     ` Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 10/21] mptcp: handle local addrs announced " Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 11/21] mptcp: read attributes of addr entries managed " Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 12/21] mptcp: netlink: split mptcp_pm_parse_addr into two functions Kishen Maloor
2021-12-16 22:23 ` Kishen Maloor [this message]
2021-12-17 18:39   ` [PATCH mptcp-next 13/21] mptcp: netlink: Add MPTCP_PM_CMD_ANNOUNCE Paolo Abeni
2021-12-16 22:23 ` [PATCH mptcp-next 14/21] mptcp: selftests: support MPTCP_PM_CMD_ANNOUNCE Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 15/21] mptcp: netlink: Add MPTCP_PM_CMD_REMOVE Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 16/21] mptcp: selftests: support MPTCP_PM_CMD_REMOVE Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 17/21] mptcp: netlink: allow userspace-driven subflow establishment Kishen Maloor
2021-12-17  2:52   ` kernel test robot
2021-12-17  2:52     ` kernel test robot
2021-12-17  5:46   ` kernel test robot
2021-12-17  5:46     ` kernel test robot
2021-12-16 22:23 ` [PATCH mptcp-next 18/21] mptcp: selftests: support MPTCP_PM_CMD_SUBFLOW_CREATE Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 19/21] mptcp: selftests: support MPTCP_PM_CMD_SUBFLOW_DESTROY Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 20/21] mptcp: selftests: capture netlink events Kishen Maloor
2021-12-16 22:23 ` [PATCH mptcp-next 21/21] selftests: mptcp: functional tests for the userspace PM type Kishen Maloor
2021-12-16 22:44   ` selftests: mptcp: functional tests for the userspace PM type: Build Failure MPTCP CI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211216222314.1244708-14-kishen.maloor@intel.com \
    --to=kishen.maloor@intel.com \
    --cc=mptcp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.