From nobody Mon Sep 16 18:54:37 2024 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.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 AE9B6EDE for ; Sat, 30 Dec 2023 02:49:19 +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="X0D+RAte" 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=1703904556; 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=sT9yoo76F04uE3bDGChHpZ0QRIuxr7g9fKUWxi0v/LY=; b=X0D+RAteb0Z/kmN9SoS4OpQbTwLIbsCWIDMb5nHv0oh/pWd6cT1osRoXSHPrg+wgRvjgvH RC/kCurzTgZja+mw44LKFRmGAH6iOpCAASp0Ofqc3kcOlNUT5B4APtqXmp8rz/QKxxqYEI BYIxDXRqwVpRWjtc6HTZ8Os/9SHTI2A= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 01/24] mptcp: set set_id flag when parsing addr Date: Sat, 30 Dec 2023 10:47:56 +0800 Message-Id: <8f402f2cbd7571e85fbc41b9559cbb2d05bf7c58.1703904325.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" When userspace PM requires to create an ID 0 subflow in "userspace pm create id 0 subflow" test like this: userspace_pm_add_sf $ns2 10.0.3.2 0 An ID 1 subflow, in fact, is created. Since in mptcp_pm_nl_append_new_local_addr(), 'id 0' will be treated as no ID is set by userspace, and will allocate a new ID immediately: if (!e->addr.id) e->addr.id =3D find_next_zero_bit(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1, 1); To solve this issue, a new flag 'MPTCP_PM_ADDR_FLAG_SET_ID' is added to distinguish between whether userspace PM has set an ID 0 or whether userspace PM has not set any address. Add a new parameter 'set_id' for mptcp_pm_parse_pm_addr_attr(), and pass a 'set_id' flag to them. If an address id is set from userspace, this 'set_id' will be set as true. If 'set_id' is set, then the newly added flag MPTCP_PM_ADDR_FLAG_SET_ID will be set. Fixes: e5ed101a6028 ("mptcp: userspace pm allow creating id 0 subflow") Signed-off-by: Geliang Tang --- include/uapi/linux/mptcp.h | 1 + net/mptcp/pm_netlink.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/uapi/linux/mptcp.h b/include/uapi/linux/mptcp.h index 74cfe496891e..ef3663792765 100644 --- a/include/uapi/linux/mptcp.h +++ b/include/uapi/linux/mptcp.h @@ -36,6 +36,7 @@ #define MPTCP_PM_ADDR_FLAG_BACKUP (1 << 2) #define MPTCP_PM_ADDR_FLAG_FULLMESH (1 << 3) #define MPTCP_PM_ADDR_FLAG_IMPLICIT (1 << 4) +#define MPTCP_PM_ADDR_FLAG_SET_ID (1 << 5) =20 struct mptcp_info { __u8 mptcpi_subflows; diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 661c226dad18..dedc5a038b10 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1159,7 +1159,8 @@ static int mptcp_pm_parse_pm_addr_attr(struct nlattr = *tb[], const struct nlattr *attr, struct genl_info *info, struct mptcp_addr_info *addr, - bool require_family) + bool require_family, + bool *set_id) { int err, addr_addr; =20 @@ -1174,8 +1175,11 @@ static int mptcp_pm_parse_pm_addr_attr(struct nlattr= *tb[], if (err) return err; =20 - if (tb[MPTCP_PM_ADDR_ATTR_ID]) + if (tb[MPTCP_PM_ADDR_ATTR_ID]) { addr->id =3D nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]); + if (set_id) + *set_id =3D true; + } =20 if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) { if (!require_family) @@ -1223,7 +1227,7 @@ int mptcp_pm_parse_addr(struct nlattr *attr, struct g= enl_info *info, =20 memset(addr, 0, sizeof(*addr)); =20 - return mptcp_pm_parse_pm_addr_attr(tb, attr, info, addr, true); + return mptcp_pm_parse_pm_addr_attr(tb, attr, info, addr, true, NULL); } =20 int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info, @@ -1231,11 +1235,13 @@ int mptcp_pm_parse_entry(struct nlattr *attr, struc= t genl_info *info, struct mptcp_pm_addr_entry *entry) { struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1]; + bool set_id =3D false; int err; =20 memset(entry, 0, sizeof(*entry)); =20 - err =3D mptcp_pm_parse_pm_addr_attr(tb, attr, info, &entry->addr, require= _family); + err =3D mptcp_pm_parse_pm_addr_attr(tb, attr, info, &entry->addr, + require_family, &set_id); if (err) return err; =20 @@ -1248,6 +1254,9 @@ int mptcp_pm_parse_entry(struct nlattr *attr, struct = genl_info *info, if (tb[MPTCP_PM_ADDR_ATTR_FLAGS]) entry->flags =3D nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]); =20 + if (set_id) + entry->flags |=3D MPTCP_PM_ADDR_FLAG_SET_ID; + if (tb[MPTCP_PM_ADDR_ATTR_PORT]) entry->addr.port =3D htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT])); =20 --=20 2.39.2