From nobody Thu May 16 09:48:09 2024 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D23FC125B5 for ; Tue, 19 Dec 2023 08:20:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="giK7D5ct" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3Li9lFIPJk+suN5sphynXyeONR8VesPy1/x5786HlBE=; b=giK7D5ctvbwt3+jSDhab987qQnHH1WGOnuX1sBsXCEusC7il1pB1JvWJXIiT81atYBBeRP gPFDi9PhR4fnl7uRJ0QFQYAKESxhTqu+HHE4ZQIAvSRTPfudahl2dqGS6V5Hv/QOkP9bQ7 6QlFYnSY1dLD9UttKr/pT41R9hEF8YY= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 01/14] mptcp: export mptcp_genl_family & mptcp_nl_fill_addr Date: Tue, 19 Dec 2023 16:19:12 +0800 Message-Id: <2b3d93475c7b90a86095cb5d1704d9a1652a07d1.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch exports struct mptcp_genl_family and mptcp_nl_fill_addr() helper to allow them can be used in pm_userspace.c. Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 9 +++------ net/mptcp/protocol.h | 4 ++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 1b754cf525de..29fdef4cfdfd 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -18,9 +18,6 @@ #include "protocol.h" #include "mib.h" =20 -/* forward declaration */ -static struct genl_family mptcp_genl_family; - static int pm_nl_pernet_id; =20 struct mptcp_pm_add_entry { @@ -1614,8 +1611,8 @@ int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb,= struct genl_info *info) return 0; } =20 -static int mptcp_nl_fill_addr(struct sk_buff *skb, - struct mptcp_pm_addr_entry *entry) +int mptcp_nl_fill_addr(struct sk_buff *skb, + struct mptcp_pm_addr_entry *entry) { struct mptcp_addr_info *addr =3D &entry->addr; struct nlattr *attr; @@ -2259,7 +2256,7 @@ void mptcp_event(enum mptcp_event_type type, const st= ruct mptcp_sock *msk, nlmsg_free(skb); } =20 -static struct genl_family mptcp_genl_family __ro_after_init =3D { +struct genl_family mptcp_genl_family __ro_after_init =3D { .name =3D MPTCP_PM_NAME, .version =3D MPTCP_PM_VER, .netnsok =3D true, diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index f7b9c1b995df..9b0b3fa65ae5 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -341,6 +341,8 @@ struct mptcp_sock { #define mptcp_for_each_subflow_safe(__msk, __subflow, __tmp) \ list_for_each_entry_safe(__subflow, __tmp, &((__msk)->conn_list), node) =20 +extern struct genl_family mptcp_genl_family; + static inline void msk_owned_by_me(const struct mptcp_sock *msk) { sock_owned_by_me((const struct sock *)msk); @@ -961,6 +963,8 @@ void mptcp_fastopen_gen_msk_ackseq(struct mptcp_sock *m= sk, struct mptcp_subflow_ const struct mptcp_options_received *mp_opt); void mptcp_fastopen_subflow_synack_set_params(struct mptcp_subflow_context= *subflow, struct request_sock *req); +int mptcp_nl_fill_addr(struct sk_buff *skb, + struct mptcp_pm_addr_entry *entry); =20 static inline bool mptcp_pm_should_add_signal(struct mptcp_sock *msk) { --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FFE7125BD for ; Tue, 19 Dec 2023 08:20:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ab0DCfxU" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yQzPOKzALhlcTTVN4YZHZgQULMs1UKux4rzRxPo0vZ0=; b=ab0DCfxU1kur91iNq2u4IOY7sgOdgVk7ZpPHlbR80FiQ8ebbzbDXTlS4+O4xVkSdR737mC VgKCd2yJp/7OYNcx6/6yWq/XqN3UXeS0OCMXvVitIisZuPxz+eQq/ei0SGPECeYYeguQIn PuFCnQDf9DA2beIA4dJYPIvuyxGFc5Y= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 02/14] mptcp: implement mptcp_userspace_pm_dump_addr Date: Tue, 19 Dec 2023 16:19:13 +0800 Message-Id: <66f2d1ffbdece95a755594d7d2c209b771424d11.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch implements mptcp_userspace_pm_dump_addr() to dump addresses from userspace pm address list. Use mptcp_token_get_sock() to get the msk from the given token, if userspace PM is enabled in it, traverse each address entry in address list, put every entry to userspace using mptcp_pm_nl_put_entry_msg(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 51 ++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index efecbe3cf415..5494293537bb 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -550,3 +550,54 @@ int mptcp_userspace_pm_set_flags(struct net *net, stru= ct nlattr *token, sock_put(sk); return ret; } + +int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, + struct netlink_callback *cb) +{ + const struct genl_info *info =3D genl_info_dump(cb); + struct net *net =3D sock_net(msg->sk); + struct mptcp_pm_addr_entry *entry; + struct mptcp_sock *msk; + int id =3D cb->args[0]; + int ret =3D -EINVAL; + struct sock *sk; + void *hdr; + + if (!info->attrs[MPTCP_PM_ATTR_TOKEN]) + return ret; + + msk =3D mptcp_token_get_sock(net, nla_get_u32(info->attrs[MPTCP_PM_ATTR_T= OKEN])); + if (!msk) + return ret; + + if (!mptcp_pm_is_userspace(msk)) + return ret; + + sk =3D (struct sock *)msk; + + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (entry->addr.id <=3D id) + continue; + + hdr =3D genlmsg_put(msg, NETLINK_CB(cb->skb).portid, + cb->nlh->nlmsg_seq, &mptcp_genl_family, + NLM_F_MULTI, MPTCP_PM_CMD_GET_ADDR); + if (!hdr) + break; + + if (mptcp_nl_fill_addr(msg, entry) < 0) { + genlmsg_cancel(msg, hdr); + break; + } + + id =3D entry->addr.id; + genlmsg_end(msg, hdr); + } + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + + cb->args[0] =3D id; + return msg->len; +} diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 9b0b3fa65ae5..7c0d592a9a45 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1029,6 +1029,8 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, = unsigned int remaining, int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc); int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_inf= o *skc); int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_a= ddr_info *skc); +int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, + struct netlink_callback *cb); =20 void __init mptcp_pm_nl_init(void); void mptcp_pm_nl_work(struct mptcp_sock *msk); --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB740F9EC for ; Tue, 19 Dec 2023 08:20:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="deIhZmUy" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974031; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BSdqxbpKtl1EqadsNb/cqGZSWH3ZsvlKh/9nSVcuGVI=; b=deIhZmUyFJZHK5Dr3Ebq8zzAq3zcoqK1REYnLTuQ0RRCKrxIu1dcpFZWKRUi0CmQdmgRMW p+nIxTZ8j/zI6sHNQU/QM/BCamh+vLx0RFbBFbN1jexBc1nIVW+FYhwG4SKH5X8UveK67S 8qNuu0c1S/yttOIGDNTwvuIsiwDNblk= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 03/14] mptcp: dump addrs in userspace pm list Date: Tue, 19 Dec 2023 16:19:14 +0800 Message-Id: <4b675a9502b0e830308dfcc7cd36084929958bb6.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch renames mptcp_pm_nl_get_addr_dumpit() to in-kernel netlink PM dump addrs function mptcp_pm_nl_dump_addr(), then invoke both in-kernel PM mptcp_pm_nl_dump_addr() and userspace PM mptcp_userspace_pm_dump_addr() dump addrs functions in mptcp_pm_nl_get_addr_dumpit(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 29fdef4cfdfd..812dc719269a 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1700,8 +1700,8 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, st= ruct genl_info *info) return ret; } =20 -int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) +static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, + struct netlink_callback *cb) { struct net *net =3D sock_net(msg->sk); struct mptcp_pm_addr_entry *entry; @@ -1743,6 +1743,13 @@ int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, return msg->len; } =20 +int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) +{ + return mptcp_pm_nl_dump_addr(msg, cb) + + mptcp_userspace_pm_dump_addr(msg, cb); +} + static int parse_limit(struct genl_info *info, int id, unsigned int *limit) { struct nlattr *attr =3D info->attrs[id]; --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-175.mta0.migadu.com (out-175.mta0.migadu.com [91.218.175.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9024F11710 for ; Tue, 19 Dec 2023 08:20:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ctdp3zLz" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974032; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8/RjjDcTgSLNZ9qHoiZL6CBCBxEaszcio1NpFLqZrms=; b=ctdp3zLzuRFSNPKNZTBAQdBgnzFyopEwXp77twy+tpOLV1OK4sD+bnWQulg/8PQYMDAg7K FLS1WpFyOmkDiYxuEz+qC4WDtOk5qg2b7qyMbSduQ3O5S77VH1CNaXXrE1FHDl1xrOPm8M 3c0PKnuXrDbPGtPFgyszUTDFqQbtyyE= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 04/14] mptcp: check userspace pm subflow flag Date: Tue, 19 Dec 2023 16:19:15 +0800 Message-Id: <78b69df5915efa1e7a15d51b55d87a727787fb09.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch uses mptcp_pm_parse_entry() instead of mptcp_pm_parse_addr() to get the flags of the entry. Add MPTCP_PM_ADDR_FLAG_SUBFLOW flag check in mptcp_pm_nl_subflow_create_doit(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 5494293537bb..8702dc5759ca 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -348,12 +348,19 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *s= kb, struct genl_info *info) goto create_err; } =20 - err =3D mptcp_pm_parse_addr(laddr, info, &addr_l); + err =3D mptcp_pm_parse_entry(laddr, info, true, &local); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, laddr, "error parsing local addr"); goto create_err; } =20 + if (!(local.flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)) { + GENL_SET_ERR_MSG(info, "invalid addr flags"); + err =3D -EINVAL; + goto create_err; + } + addr_l =3D local.addr; + err =3D mptcp_pm_parse_addr(raddr, info, &addr_r); if (err < 0) { NL_SET_ERR_MSG_ATTR(info->extack, raddr, "error parsing remote addr"); @@ -366,7 +373,6 @@ int mptcp_pm_nl_subflow_create_doit(struct sk_buff *skb= , struct genl_info *info) goto create_err; } =20 - local.addr =3D addr_l; err =3D mptcp_userspace_pm_append_new_local_addr(msk, &local); if (err < 0) { GENL_SET_ERR_MSG(info, "did not match address and id"); --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC09D111BC for ; Tue, 19 Dec 2023 08:20:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="q+kfHkHJ" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974034; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gjqYl5HjrE/PcyKOI4j2xbJwPljHGTqCFh0OUGGn4/o=; b=q+kfHkHJir4EvN7vPx5lDBSfGCRr+slwCH44GkcekCloNSTevYtyzwepFqCyffLPv+aK21 iEQFm/pFHPggTmnoDQ1pFu92sxiPiqI+oteig7QqowcIFft7a0RRA//d4gTQXBh/U0KocQ ixsUPksA5iEVILHULfr++gZWOZXpfQE= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 05/14] mptcp: add token for get-addr in yaml Date: Tue, 19 Dec 2023 16:19:16 +0800 Message-Id: <237f1ba1a1bca36f6d389192ab18ef079f446bb8.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch adds token paramenter together with addr in get-addr section in mptcp.yaml, then use the following commands to update mptcp_pm_gen.c and mptcp_pm_gen.h: ./tools/net/ynl/ynl-gen-c.py --mode kernel \ --spec Documentation/netlink/specs/mptcp.yaml --source \ -o net/mptcp/mptcp_pm_gen.c ./tools/net/ynl/ynl-gen-c.py --mode kernel \ --spec Documentation/netlink/specs/mptcp.yaml --header \ -o net/mptcp/mptcp_pm_gen.h Signed-off-by: Geliang Tang --- Documentation/netlink/specs/mptcp.yaml | 5 ++++- net/mptcp/mptcp_pm_gen.c | 7 ++++--- net/mptcp/mptcp_pm_gen.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Documentation/netlink/specs/mptcp.yaml b/Documentation/netlink= /specs/mptcp.yaml index 49f90cfb4698..cc731dbaa427 100644 --- a/Documentation/netlink/specs/mptcp.yaml +++ b/Documentation/netlink/specs/mptcp.yaml @@ -292,20 +292,23 @@ operations: - name: get-addr doc: Get endpoint information - attribute-set: endpoint + attribute-set: attr dont-validate: [ strict ] flags: [ uns-admin-perm ] do: &get-addr-attrs request: attributes: - addr + - token reply: attributes: - addr + - token dump: reply: attributes: - addr + - token - name: flush-addrs doc: flush addresses diff --git a/net/mptcp/mptcp_pm_gen.c b/net/mptcp/mptcp_pm_gen.c index a2325e70ddab..69c8857b4c5d 100644 --- a/net/mptcp/mptcp_pm_gen.c +++ b/net/mptcp/mptcp_pm_gen.c @@ -32,8 +32,9 @@ const struct nla_policy mptcp_pm_del_addr_nl_policy[MPTCP= _PM_ENDPOINT_ADDR + 1] }; =20 /* MPTCP_PM_CMD_GET_ADDR - do */ -const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ENDPOINT_ADDR= + 1] =3D { - [MPTCP_PM_ENDPOINT_ADDR] =3D NLA_POLICY_NESTED(mptcp_pm_address_nl_policy= ), +const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ATTR_TOKEN + = 1] =3D { + [MPTCP_PM_ATTR_ADDR] =3D NLA_POLICY_NESTED(mptcp_pm_address_nl_policy), + [MPTCP_PM_ATTR_TOKEN] =3D { .type =3D NLA_U32, }, }; =20 /* MPTCP_PM_CMD_FLUSH_ADDRS - do */ @@ -110,7 +111,7 @@ const struct genl_ops mptcp_pm_nl_ops[11] =3D { .doit =3D mptcp_pm_nl_get_addr_doit, .dumpit =3D mptcp_pm_nl_get_addr_dumpit, .policy =3D mptcp_pm_get_addr_nl_policy, - .maxattr =3D MPTCP_PM_ENDPOINT_ADDR, + .maxattr =3D MPTCP_PM_ATTR_TOKEN, .flags =3D GENL_UNS_ADMIN_PERM, }, { diff --git a/net/mptcp/mptcp_pm_gen.h b/net/mptcp/mptcp_pm_gen.h index 10579d184587..3963c55950b7 100644 --- a/net/mptcp/mptcp_pm_gen.h +++ b/net/mptcp/mptcp_pm_gen.h @@ -18,7 +18,7 @@ extern const struct nla_policy mptcp_pm_add_addr_nl_polic= y[MPTCP_PM_ENDPOINT_ADD =20 extern const struct nla_policy mptcp_pm_del_addr_nl_policy[MPTCP_PM_ENDPOI= NT_ADDR + 1]; =20 -extern const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ENDPOI= NT_ADDR + 1]; +extern const struct nla_policy mptcp_pm_get_addr_nl_policy[MPTCP_PM_ATTR_T= OKEN + 1]; =20 extern const struct nla_policy mptcp_pm_flush_addrs_nl_policy[MPTCP_PM_END= POINT_ADDR + 1]; =20 --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-181.mta0.migadu.com (out-181.mta0.migadu.com [91.218.175.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 249001170D for ; Tue, 19 Dec 2023 08:20:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="a+vQQW6D" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iCRljyM6OH4MsBLRN/q3Q8fR6iBdnpBdYGMdYVR28SY=; b=a+vQQW6DP8BBsAOB8JcZe7kAJMBEf5hXnyjBRfU8W5NsBH8Z4v7AqxAfakXyJ9vgva/NnB GdR7xRrQryRwTxi/YlfhULTfLJz0mVLknS4kkHte8tz1hN7K5bWbAu7vxu5ykGvN5vkGBC 701NDApCkAnhYIC3jT5BdTdMLkFSDEs= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 06/14] selftests: mptcp: add userspace pm subflow flag Date: Tue, 19 Dec 2023 16:19:17 +0800 Message-Id: <2caf165eb8dc4c71ca62d4b8bcaaea2a601c62a4.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch adds the address flag MPTCP_PM_ADDR_FLAG_SUBFLOW in csf() in pm_nl_ctl.c when subflow is created by a userspace PM. Signed-off-by: Geliang Tang --- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c b/tools/testing/= selftests/net/mptcp/pm_nl_ctl.c index 49369c4a5f26..e97856323ec3 100644 --- a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c +++ b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c @@ -453,6 +453,7 @@ int csf(int fd, int pm_family, int argc, char *argv[]) char data[NLMSG_ALIGN(sizeof(struct nlmsghdr)) + NLMSG_ALIGN(sizeof(struct genlmsghdr)) + 1024]; + u_int32_t flags =3D MPTCP_PM_ADDR_FLAG_SUBFLOW; const char *params[5]; struct nlmsghdr *nh; struct rtattr *addr; @@ -558,6 +559,13 @@ int csf(int fd, int pm_family, int argc, char *argv[]) off +=3D NLMSG_ALIGN(rta->rta_len); } =20 + /* addr flags */ + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ADDR_ATTR_FLAGS; + rta->rta_len =3D RTA_LENGTH(4); + memcpy(RTA_DATA(rta), &flags, 4); + off +=3D NLMSG_ALIGN(rta->rta_len); + addr->rta_len =3D off - addr_start; } =20 --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CD1811709 for ; Tue, 19 Dec 2023 08:20:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="doKAY1Zq" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IUNLUS9kjQsNN5jTynBv12p6pFgdSs7eV0RbzSa0hYU=; b=doKAY1Zqi0XYdym24SOQalZy+LpnWsq+nPbaRAMZ9kooHPZzcYEhaGuVInH9lvcD1vXOJW Pay7Zzd2q7D/Bx94PBfO0y/cB2KqzikRMsyiDgW7mgHcNojguUopGvXn9y52wS5+TVdZjd 36IZb9OzbdYUtznntirEsrrXDnmRM5Y= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 07/14] selftests: mptcp: add token for dump_addr Date: Tue, 19 Dec 2023 16:19:18 +0800 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The command dump_addr() of pm_nl_ctl can be used like this in in-kernel PM: pm_nl_ctl dump This patch adds token argument for it to support userspace PM: pm_nl_ctl dump token $token If 'token $token' is passed to dump_addr(), copy it into the kernel netlink. Signed-off-by: Geliang Tang --- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c b/tools/testing/= selftests/net/mptcp/pm_nl_ctl.c index e97856323ec3..8d7d1b4ed28e 100644 --- a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c +++ b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c @@ -1127,8 +1127,16 @@ int dump_addrs(int fd, int pm_family, int argc, char= *argv[]) 1024]; pid_t pid =3D getpid(); struct nlmsghdr *nh; + u_int32_t token =3D 0; + struct rtattr *rta; int off =3D 0; =20 + if (argc !=3D 2 && argc !=3D 4) + syntax(argv); + + if (argc =3D=3D 4 && !strcmp(argv[2], "token")) + token =3D strtoul(argv[3], NULL, 10); + memset(data, 0, sizeof(data)); nh =3D (void *)data; off =3D init_genl_req(data, pm_family, MPTCP_PM_CMD_GET_ADDR, @@ -1138,6 +1146,15 @@ int dump_addrs(int fd, int pm_family, int argc, char= *argv[]) nh->nlmsg_pid =3D pid; nh->nlmsg_len =3D off; =20 + /* token */ + if (token) { + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ATTR_TOKEN; + rta->rta_len =3D RTA_LENGTH(4); + memcpy(RTA_DATA(rta), &token, 4); + off +=3D NLMSG_ALIGN(rta->rta_len); + } + print_addrs(nh, pm_family, do_nl_req(fd, nh, off, sizeof(data))); return 0; } --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5944B111BC for ; Tue, 19 Dec 2023 08:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="h4vSytb+" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ERiB6Pet9ivx6wj4QdFsUs/qDRxTIgiskMJwm/GxbRs=; b=h4vSytb++WfoBuK8kEQQaSUgKs8AZ9loEpjp429v2gUkeknLwdgVIX7kY/jCJZRs6INokM dNe+ucqytgiC3vapPoXmtrJX+/c8NPYU1Cmmo+mOyvkcI37GnxjgAtD7zu6AwWpOB+T1EP 2MygQnPkvuqfYjqiNb2C1VLVEaASGuo= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 08/14] selftests: mptcp: add check_output helper Date: Tue, 19 Dec 2023 16:19:19 +0800 Message-Id: <39b18d670f19c9f2c9b0431905c9c8b9167fd85b.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Similar to check() in pm_netlink.sh, add a new helper check_output() in mptcp_join.sh to check the output of the given commands. Signed-off-by: Geliang Tang --- .../testing/selftests/net/mptcp/mptcp_join.sh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index 3a5b63026191..25d3f32644ed 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -21,6 +21,7 @@ cinfail=3D"" cinsent=3D"" tmpfile=3D"" cout=3D"" +check_output_err=3D"" capout=3D"" ns1=3D"" ns2=3D"" @@ -186,6 +187,7 @@ init() { cout=3D$(mktemp) evts_ns1=3D$(mktemp) evts_ns2=3D$(mktemp) + check_output_err=3D$(mktemp) =20 trap cleanup EXIT =20 @@ -199,6 +201,7 @@ cleanup() rm -f "$sin" "$sout" "$cinsent" "$cinfail" rm -f "$tmpfile" rm -rf $evts_ns1 $evts_ns2 + rm -f $check_output_err cleanup_partial } =20 @@ -3357,6 +3360,30 @@ userspace_pm_rm_sf() wait_rm_sf $1 "${cnt}" } =20 +check_output() +{ + local cmd=3D"$1" + local expected=3D"$2" + local msg=3D"$3" + local out=3D`$cmd 2>$check_output_err` + local cmd_ret=3D$? + + printf "%-42s" "$msg" + if [ $cmd_ret -ne 0 ]; then + mptcp_lib_print_err "[ FAIL ] command execution '$cmd' stderr " + cat $check_output_err + ret=3D${KSFT_FAIL} + return $cmd_ret + elif [ "$out" =3D "$expected" ]; then + mptcp_lib_print_ok "[ OK ]" + return 0 + else + mptcp_lib_print_err "[ FAIL ] expected '$expected' got '$out'" + ret=3D${KSFT_FAIL} + return 1 + fi +} + userspace_tests() { # userspace pm type prevents add_addr --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB9CD11C9E for ; Tue, 19 Dec 2023 08:20:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="gZY4QF35" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=z/Ii6GsSUtx5/gkFNNJl6jtYbkzb/prif7eMb5oRvzo=; b=gZY4QF3565U7b/uYM69aNVzK5dT6UPLSITLANzp1ZmYF1LlioE5TVeFs4BZYS8CbXB1A0X 4mU3xJFTb5Kk9mhFuAJykEb9332Tv3+zQynN+aZj/kxlypWe0j9e0GImg6tP/XisU4bhYU hKERo3zCG/kAnadOFWG03L/ExZKUBk0= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 09/14] selftests: mptcp: dump userspace addrs list Date: Tue, 19 Dec 2023 16:19:20 +0800 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch adds a new helper userspace_pm_dump() to dump addresses for the userspace PM. Add two new tests for userspace pm dump address and subflow. Use userspace_pm_add_addr() and userspace_pm_add_sf() to add an address and a suflow. Signed-off-by: Geliang Tang --- .../testing/selftests/net/mptcp/mptcp_join.sh | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index 25d3f32644ed..403200394aa7 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -3360,6 +3360,18 @@ userspace_pm_rm_sf() wait_rm_sf $1 "${cnt}" } =20 +# $1: ns +userspace_pm_dump() +{ + local evts=3D$evts_ns1 + local tk + + [ "$1" =3D=3D "$ns2" ] && evts=3D$evts_ns2 + tk=3D$(mptcp_lib_evts_get_info token "$evts") + + ip netns exec $1 ./pm_nl_ctl dump token $tk +} + check_output() { local cmd=3D"$1" @@ -3573,6 +3585,50 @@ userspace_tests() kill_events_pids wait $tests_pid fi + + # userspace pm dump address + if reset_with_events "userspace pm dump address" && + continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then + set_userspace_pm $ns1 + pm_nl_set_limits $ns2 1 1 + speed=3D5 \ + run_tests $ns1 $ns2 10.0.1.1 & + local tests_pid=3D$! + wait_mpj $ns1 + userspace_pm_add_addr $ns1 10.0.2.1 10 + chk_join_nr 1 1 1 + chk_add_nr 1 1 + chk_mptcp_info subflows 1 subflows 1 + chk_subflows_total 2 2 + chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 + local dump=3D"id 10 flags signal 10.0.2.1" + check_output "userspace_pm_dump $ns1" \ + "$dump" " dump addrs signal" + kill_events_pids + wait $tests_pid + fi + + # userspace pm dump subflow + if reset_with_events "userspace pm dump subflow" && + continue_if mptcp_lib_has_file '/proc/sys/net/mptcp/pm_type'; then + set_userspace_pm $ns2 + pm_nl_set_limits $ns1 0 1 + speed=3D5 \ + run_tests $ns1 $ns2 10.0.1.1 & + local tests_pid=3D$! + wait_mpj $ns2 + chk_mptcp_info subflows 0 subflows 0 + chk_subflows_total 1 1 + userspace_pm_add_sf $ns2 10.0.3.2 20 + chk_join_nr 1 1 1 + chk_mptcp_info subflows 1 subflows 1 + chk_subflows_total 2 2 + local dump=3D"id 20 flags subflow 10.0.3.2" + check_output "userspace_pm_dump $ns2" \ + "$dump" " dump addrs subflow" + kill_events_pids + wait $tests_pid + fi } =20 endpoint_tests() --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A09B11725 for ; Tue, 19 Dec 2023 08:20:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tyx5fNUb" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cfyArrTApZaACeseNQMs49xtlN1ghZT6BjUlc1hSTtc=; b=tyx5fNUbInZKDldEHLAYYCC8WEFinA8TM2dwPsYEd1XDmoUriGbtG58c/BSRZVxO9vJV5i cT6Z+q0C/h5rcw/DwHKvkBkp8dsFIPqaGge4/e+JukpnoI88lgVY853Bs8sYVo6y0ihTyA xUpuPvn/hLYYxRkzRq1Aukj2sl+cOfs= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 10/14] mptcp: add userspace_pm_lookup_addr_by_id helper Date: Tue, 19 Dec 2023 16:19:21 +0800 Message-Id: <7e7b09a45050a5588d9c9f5af78532c2d79ca954.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Corresponding __lookup_addr_by_id() helper in the in-kernel netlink PM, this patch adds a new helper mptcp_userspace_pm_lookup_addr_by_id() to lookup the address entry with the given id on the userspace pm local address list. Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 8702dc5759ca..0a4cbb9e6e41 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -105,19 +105,26 @@ static int mptcp_userspace_pm_delete_local_addr(struc= t mptcp_sock *msk, return -EINVAL; } =20 +static struct mptcp_pm_addr_entry * +mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int = id) +{ + struct mptcp_pm_addr_entry *entry; + + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (entry->addr.id =3D=3D id) + return entry; + } + return NULL; +} + int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id, u8 *flags, int *ifindex) { - struct mptcp_pm_addr_entry *entry, *match =3D NULL; + struct mptcp_pm_addr_entry *match; =20 spin_lock_bh(&msk->pm.lock); - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (id =3D=3D entry->addr.id) { - match =3D entry; - break; - } - } + match =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id); spin_unlock_bh(&msk->pm.lock); if (match) { *flags =3D match->flags; @@ -249,7 +256,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct= genl_info *info) { struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; struct nlattr *id =3D info->attrs[MPTCP_PM_ATTR_LOC_ID]; - struct mptcp_pm_addr_entry *match =3D NULL; + struct mptcp_pm_addr_entry *match; struct mptcp_pm_addr_entry *entry; struct mptcp_sock *msk; LIST_HEAD(free_list); @@ -286,13 +293,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struc= t genl_info *info) =20 lock_sock(sk); =20 - list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { - if (entry->addr.id =3D=3D id_val) { - match =3D entry; - break; - } - } - + match =3D mptcp_userspace_pm_lookup_addr_by_id(msk, id_val); if (!match) { GENL_SET_ERR_MSG(info, "address with specified id not found"); release_sock(sk); --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F146311700 for ; Tue, 19 Dec 2023 08:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ZS8YKw1f" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uvmV24YhjCerQgKs5nga6WhjgK7IkAE5EYu24MYK6iM=; b=ZS8YKw1fro9R3xBo2TtyxmiYYUOwmC3gOYO5+HEXIKrlyl871JNVCrwDFwT5JcRCsLGFbZ rxt66Ug93FGh+1P5dEPA/cKNIcyC35NmD0aZ+cXg3Kq43+5z1JCDw5DYZ9G7lsEKkrxmdb qIWZIZaj4LrwYIn7VbsZLI7PIMcMKDg= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 11/14] mptcp: implement mptcp_userspace_pm_get_addr Date: Tue, 19 Dec 2023 16:19:22 +0800 Message-Id: <1b82e297c498833fc3daa4cf4b404226cb5edc60.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch implements mptcp_userspace_pm_get_addr() to get an address from userspace pm address list according the given 'token' and 'id'. Use nla_get_u32() to get the u32 value of 'token', then pass it to mptcp_token_get_sock() to get the msk. Pass 'msk' and 'id' to the helper mptcp_userspace_pm_lookup_addr_by_id() to get the address entry. Put this entry to userspace using mptcp_pm_nl_put_entry_info(). Signed-off-by: Geliang Tang --- net/mptcp/pm_userspace.c | 66 ++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 2 ++ 2 files changed, 68 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 0a4cbb9e6e41..cf0c04006baa 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -608,3 +608,69 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, cb->args[0] =3D id; return msg->len; } + +int mptcp_userspace_pm_get_addr(struct sk_buff *skb, + struct genl_info *info) +{ + struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; + struct nlattr *token =3D info->attrs[MPTCP_PM_ATTR_TOKEN]; + struct mptcp_pm_addr_entry addr, *entry; + struct net *net =3D sock_net(skb->sk); + struct mptcp_sock *msk; + struct sk_buff *msg; + int ret =3D -EINVAL; + struct sock *sk; + void *reply; + + msk =3D mptcp_token_get_sock(net, nla_get_u32(token)); + if (!msk) + return ret; + + if (!mptcp_pm_is_userspace(msk)) + return ret; + + ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); + if (ret < 0) + return ret; + + msg =3D nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + reply =3D genlmsg_put_reply(msg, info, &mptcp_genl_family, 0, + info->genlhdr->cmd); + if (!reply) { + GENL_SET_ERR_MSG(info, "not enough space in Netlink message"); + ret =3D -EMSGSIZE; + goto fail; + } + + sk =3D (struct sock *)msk; + + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + entry =3D mptcp_userspace_pm_lookup_addr_by_id(msk, addr.addr.id); + if (!entry) { + GENL_SET_ERR_MSG(info, "address not found"); + ret =3D -EINVAL; + goto unlock_fail; + } + + ret =3D mptcp_nl_fill_addr(msg, entry); + if (ret) + goto unlock_fail; + + genlmsg_end(msg, reply); + ret =3D genlmsg_reply(msg, info); + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + return ret; + +unlock_fail: + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + +fail: + nlmsg_free(msg); + return ret; +} diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 7c0d592a9a45..b4c340439abd 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1031,6 +1031,8 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, = struct mptcp_addr_info *skc int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_a= ddr_info *skc); int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); +int mptcp_userspace_pm_get_addr(struct sk_buff *skb, + struct genl_info *info); =20 void __init mptcp_pm_nl_init(void); void mptcp_pm_nl_work(struct mptcp_sock *msk); --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CB1E11725 for ; Tue, 19 Dec 2023 08:20:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="bcJxjOGe" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974044; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3rJ8+ohgW9OuaEtFrHx3ROOmIHU6wZv+xOE5wlpTBPY=; b=bcJxjOGe5aDJyvrVzZf84RUuOlvZf31zTc6rBmFphP2d3+Knjcb2Oj/YSSuN+MW+/LAudA Q+519xFMfd+OB7QGHcQoFBhGbJETKoajt3ohDLqpF2FyDtX/N/NbkEXI7ww/OdR/W5fWv5 Ok15T+x0b79uV1MVqIT5TpZuhghSbrw= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 12/14] mptcp: get addr in userspace pm list Date: Tue, 19 Dec 2023 16:19:23 +0800 Message-Id: In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch renames mptcp_pm_nl_get_addr_doit() to in-kernel netlink PM get addr function mptcp_pm_nl_get_addr(). If a token is gotten in mptcp_pm_nl_get_addr_doit(), that means a userspace PM is used. So invoke mptcp_userspace_pm_get_addr() to get addr in userspace PM list. Otherwise, invoke mptcp_pm_nl_get_addr(). Signed-off-by: Geliang Tang --- net/mptcp/pm_netlink.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 812dc719269a..41a22301608b 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1650,7 +1650,7 @@ int mptcp_nl_fill_addr(struct sk_buff *skb, return -EMSGSIZE; } =20 -int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) +int mptcp_pm_nl_get_addr(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr =3D info->attrs[MPTCP_PM_ENDPOINT_ADDR]; struct pm_nl_pernet *pernet =3D genl_info_pm_nl(info); @@ -1700,6 +1700,13 @@ int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, s= truct genl_info *info) return ret; } =20 +int mptcp_pm_nl_get_addr_doit(struct sk_buff *skb, struct genl_info *info) +{ + if (info->attrs[MPTCP_PM_ATTR_TOKEN]) + return mptcp_userspace_pm_get_addr(skb, info); + return mptcp_pm_nl_get_addr(skb, info); +} + static int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb) { --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 475661172A for ; Tue, 19 Dec 2023 08:20:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="s16qq6rW" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9YLvVFOoCNrJSE4AAms04hq4jtYeWYnHs4+hrwO8rGs=; b=s16qq6rW4SF4ZyTRbEWPnsgL0RM8ZMSbssGQCSDuXCcMjLFQOEs86at+Qa/yAUp7vu+/fg hvvLkOSSS12D4Nf6DnkVldi9kKyePxBeafspp+Mu6992bImKRrS9AFz4yNRU2ZAj2kIdZW qdK2Z5e9zUMW/m03ZvnfMc+6xb4jXaI= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 13/14] selftests: mptcp: add token for get_addr Date: Tue, 19 Dec 2023 16:19:24 +0800 Message-Id: <2b7acfb51055109bf4ca778f351ba0747d4bf305.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The command get_addr() of pm_nl_ctl can be used like this in in-kernel PM: pm_nl_ctl get $id This patch adds token argument for it to support userspace PM: pm_nl_ctl get $id token $token If 'token $token' is passed to get_addr(), copy it into the kernel netlink. Signed-off-by: Geliang Tang --- tools/testing/selftests/net/mptcp/pm_nl_ctl.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c b/tools/testing/= selftests/net/mptcp/pm_nl_ctl.c index 8d7d1b4ed28e..7426a2cbd4a0 100644 --- a/tools/testing/selftests/net/mptcp/pm_nl_ctl.c +++ b/tools/testing/selftests/net/mptcp/pm_nl_ctl.c @@ -1087,6 +1087,7 @@ int get_addr(int fd, int pm_family, int argc, char *a= rgv[]) 1024]; struct rtattr *rta, *nest; struct nlmsghdr *nh; + u_int32_t token =3D 0; int nest_start; u_int8_t id; int off =3D 0; @@ -1097,10 +1098,12 @@ int get_addr(int fd, int pm_family, int argc, char = *argv[]) MPTCP_PM_VER); =20 /* the only argument is the address id */ - if (argc !=3D 3) + if (argc !=3D 3 && argc !=3D 5) syntax(argv); =20 id =3D atoi(argv[2]); + if (argc =3D=3D 5 && !strcmp(argv[3], "token")) + token =3D strtoul(argv[4], NULL, 10); =20 nest_start =3D off; nest =3D (void *)(data + off); @@ -1116,6 +1119,15 @@ int get_addr(int fd, int pm_family, int argc, char *= argv[]) off +=3D NLMSG_ALIGN(rta->rta_len); nest->rta_len =3D off - nest_start; =20 + /* token */ + if (token) { + rta =3D (void *)(data + off); + rta->rta_type =3D MPTCP_PM_ATTR_TOKEN; + rta->rta_len =3D RTA_LENGTH(4); + memcpy(RTA_DATA(rta), &token, 4); + off +=3D NLMSG_ALIGN(rta->rta_len); + } + print_addrs(nh, pm_family, do_nl_req(fd, nh, off, sizeof(data))); return 0; } --=20 2.35.3 From nobody Thu May 16 09:48:09 2024 Received: from out-186.mta0.migadu.com (out-186.mta0.migadu.com [91.218.175.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEAD11170D for ; Tue, 19 Dec 2023 08:20:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="H/NR0d+2" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1702974048; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hdzLm6bVu2drPN48mINIesrGgiK0TBHVz/DyGjVUDz0=; b=H/NR0d+2ejTuhtAA2hhqcIeagbS/HeXb8kM8McO8wNWEKbcbkBFEVEBg9hkfnbuQ94CacT 2AluR28qbHISc8PMyunPWBJ5DjZ+PD7DYqBX+TZ/nnd9eo5iiXTXdFvrRkpmCZ6htE/HDN XJOpyNCGMvlAQsjIp6P8s28fbDNz/Jg= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v3 14/14] selftests: mptcp: userspace pm get addr tests Date: Tue, 19 Dec 2023 16:19:25 +0800 Message-Id: <9a8034c76311d8871fb8d9e69aefc459b2e607ec.1702973751.git.geliang.tang@linux.dev> In-Reply-To: References: Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" This patch adds a new helper userspace_pm_get_addr() in mptcp_join.sh. In it, parse the token value from the output of 'pm_nl_ctl events', then pass it to pm_nl_ctl get_addr command. Use this helper in userspace pm dump tests. Signed-off-by: Geliang Tang --- tools/testing/selftests/net/mptcp/mptcp_join.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testin= g/selftests/net/mptcp/mptcp_join.sh index 403200394aa7..e603baa1d4a8 100755 --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh @@ -3372,6 +3372,18 @@ userspace_pm_dump() ip netns exec $1 ./pm_nl_ctl dump token $tk } =20 +# $1: ns ; $2: id +userspace_pm_get_addr() +{ + local evts=3D$evts_ns1 + local tk + + [ "$1" =3D=3D "$ns2" ] && evts=3D$evts_ns2 + tk=3D$(mptcp_lib_evts_get_info token "$evts") + + ip netns exec $1 ./pm_nl_ctl get $2 token $tk +} + check_output() { local cmd=3D"$1" @@ -3602,6 +3614,8 @@ userspace_tests() chk_subflows_total 2 2 chk_mptcp_info add_addr_signal 1 add_addr_accepted 1 local dump=3D"id 10 flags signal 10.0.2.1" + check_output "userspace_pm_get_addr $ns1 10" \ + "$dump" " get id 10 addr" check_output "userspace_pm_dump $ns1" \ "$dump" " dump addrs signal" kill_events_pids @@ -3624,6 +3638,8 @@ userspace_tests() chk_mptcp_info subflows 1 subflows 1 chk_subflows_total 2 2 local dump=3D"id 20 flags subflow 10.0.3.2" + check_output "userspace_pm_get_addr $ns2 20" \ + "$dump" " get id 20 addr" check_output "userspace_pm_dump $ns2" \ "$dump" " dump addrs subflow" kill_events_pids --=20 2.35.3