From patchwork Thu Feb 15 18:25:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 201691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp37352dyb; Thu, 15 Feb 2024 10:26:44 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXm1oNA1ghEUvY8rBkSBMhBsry1uOhShiY7KdalXC1FZP7BxXGuxKWqlPPfvETkTNWNdGmdRRbpbt/EUHXnBOeRfsNA7w== X-Google-Smtp-Source: AGHT+IGKt1uEDSGBRqTdK07zbGokFRMoypUSTXH8GZ7jzdna1d34dL8bdx4lzre/ki4zWJOeMrOB X-Received: by 2002:a05:620a:2009:b0:787:2a6e:6e08 with SMTP id c9-20020a05620a200900b007872a6e6e08mr2981632qka.15.1708021604563; Thu, 15 Feb 2024 10:26:44 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708021604; cv=pass; d=google.com; s=arc-20160816; b=TcGu0gxpIbVAlLr+LQd6bUBKrTPCJ8M12knf8YaC8GFjKnBYggHnv4kYOBk7MVLW2P tYTC43fZZ6ZVUOpKBQ1AyJfFP34kXgOT5MvuMHZqt7UQXgmXzMt3wvATAqMkwwETAsXT Re5VI0ZP+3RiNhCTndkmSqON92xH6h9oXyq7LLbO97c7LIZAZVwtkySwCkPYG3UROUrI 01IyzdT9s2rLR9Ucf8O84MMR5IH0w3I0MkULBTwiVDwJALmxTc9esCf7o72P9U6aW0fv f3F4zBLOYyZnACy5DxO50R1nsrT5dSd5aZBFI8qNAm13RZKjOiB36UexCTSJzUbiDLpZ mvhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=e3RQhgJl4lFlNjgUiER+ZVFaSWHDX1CxjRT0pF+JHkQ=; fh=9OgH39SPvd1/fx3vLudq3fGSzfFUtiCA3rk1gIJhyc8=; b=poBTIvTHwl2VqJXyu/w15fIsf+4TarA5Ii0yxAHKgkrJq1HiHAY6aluwaICJ+oQJW4 2z0/eAzSqt3pTPsgVsuLZKQc7lIA+bJ2YzFlVVtzkFioUvjW0dJiL+j72e9hXkWWyBuE PyjsM8KRxGHHH/9uAFYzSS41T/3wLeWxildhmgQfRS9ZMRuIiGRjZeAk9MB8HD7Pwkcb R1E70bIOOVu9N5+TW75zvSv6JZnA+S3RLwaJRr7fXvJ7amfnvzg6NFTo2u/By7Hmm+qK CDQABIuZEChiGihSLWWfG06p/WUw6jf9HAnIRaCSuvrWsaOkyBb/31vfFOySY2iB+0pv FGew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XYLlcY6M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67493-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67493-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m11-20020ae9e00b000000b00785d6c5e0bcsi1995106qkk.434.2024.02.15.10.26.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 10:26:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-67493-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XYLlcY6M; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-67493-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-67493-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 517A01C216C9 for ; Thu, 15 Feb 2024 18:26:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5200713A866; Thu, 15 Feb 2024 18:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XYLlcY6M" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8C5C413A248; Thu, 15 Feb 2024 18:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021544; cv=none; b=V/+B7nyP9qX3V9a3unknPxtFbnnL8BsttT3gXrS1dgP4uOqfXySfLQ+pB221HlrLlIx3HZalWJuUMrsFHSByjJZpBF1P2RB74sJnZBnLYcpyeTXl24uk/A0NCQicvuj/4ddg7g/WziZslCjPrEgLq2zx51a7T9sszqYDSGk2PWg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708021544; c=relaxed/simple; bh=TLNtJSmJT4K3/W4FxZHb8No2F0zaMpy2B5q0q484CfY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rUFQDXvcXaGv4yoVYoKu5QeEmOM+bPVKhVhEZyvnxRZ95ht4OmAlj5QcTI06J4qpzhyBDyB2og3zw3+RQa/vIXDe0Gzkdg31mxROwhJ/Om0ppal9Zys0FiYQQsfRIMQ8jtzsVUFpniLohfIYxEhb0acSRGP3sqLw6orcIf9qemA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XYLlcY6M; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 093D5C43394; Thu, 15 Feb 2024 18:25:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708021544; bh=TLNtJSmJT4K3/W4FxZHb8No2F0zaMpy2B5q0q484CfY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XYLlcY6MyhsZbb6WGDBU8WYMdjSg1OrXlIK4q3CZzwpx+oF5vzc2QY7qpCimPOQ4L ssLuBHPHbEgv3QQmO1a2ohFwK2ARsI/GoztmEyNLyrtE9kDXV1MW4mi0hZARJ8DkIJ aC+AdexVSPAOfhcJY26f4rRuB5MT4WbwEcMdGSbsnJO+wrQPAfwufXsbDG2lE2SHAM V53obrPomwSI6NCS5ypJpmX3ENHIcncrU1BMHKTRuDTcnehijUuDmehLwoXrMUM5m/ 6k5mIRxjkIy3CdHSotbC4rgX3DLY0LipEmgPT+ZBvLLb/TiQqUciIcX7QNnNzXgpWU PfsLdAA1+T1JA== From: "Matthieu Baerts (NGI0)" Date: Thu, 15 Feb 2024 19:25:29 +0100 Subject: [PATCH net 02/13] mptcp: add needs_id for netlink appending addr Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240215-upstream-net-20240215-misc-fixes-v1-2-8c01a55d8f6a@kernel.org> References: <20240215-upstream-net-20240215-misc-fixes-v1-0-8c01a55d8f6a@kernel.org> In-Reply-To: <20240215-upstream-net-20240215-misc-fixes-v1-0-8c01a55d8f6a@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Davide Caratti , Shuah Khan Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang , stable@vger.kernel.org X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=3209; i=matttbe@kernel.org; h=from:subject:message-id; bh=iuITD/hKkENPzn19h1Lnm4q3SQB2KOC2z7d4DpfDq0k=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBlzlcckP2ZdgSCyKKwvr7D2wVc1WxBIQH7PGWrY LW1QcUH5pGJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZc5XHAAKCRD2t4JPQmmg czzLEACrCQivCeCBiu2GXkiATG3dUET+CAxtWT/5ds+eqKL80ySow+PoZyycqE+oQeCn6BgDbwC uSNtOh7wFay5QtvJmNm8IsDzMM/lj+JPx/zF/hIX1MdQUerYp96YsOsHLdREqH+Ob4BXjMZPCz0 yV2q9ohUXvFtMBmkfeYoxI4bG9tU3um2n+p3hE98QOWIOFYhZ5bZ3alOP/dZnjHZYxu6K0WRCiM Ff2EDKRGtdBmVkwpdUQORL5RB7YwrwmBQMXEvD0LZG0quWCMj3hYM/4crTeZDJfFdqY8KEWnTLf 22UspRBBlCM0cvN83uVviZvtfuYeQS96eXtko+b+3sCUEVsGWvmPMmYMw2Rjg9j1ZMYyDQz6PVq 3Yk2YLTFb8I030Li/5DMlgc2oiONLDTO4WoY1zRCItj2Wq0NjK3+fKInqMXo22gWS2W2lpKlMQ/ xLlPHg/+60JCVBx2k07t2jLZa71sY/3e6kG3UrMePD0qrqfucKGRUMv5d2rz4nvG0dUux+/l4X7 CoLBFdQTp55AhdEllowADKPe6njYBPVa9bfx7ItAJGBcHDFOQZtH84AHqpj6LtZCPTMHCUOqSoW qXEFeRZ/oLOK0DgkWOMgKxbDdfTt8ouR+AHk1cAmEL6P/j/csD1gprLnIESwM37NiuYgoyyjzEN //9OiObr3/fuouA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790990461870384040 X-GMAIL-MSGID: 1790990461870384040 From: Geliang Tang Just the same as userspace PM, a new parameter needs_id is added for in-kernel PM mptcp_pm_nl_append_new_local_addr() too. Add a new helper mptcp_pm_has_addr_attr_id() to check whether an address ID is set from PM or not. In mptcp_pm_nl_get_local_id(), needs_id is always true, but in mptcp_pm_nl_add_addr_doit(), pass mptcp_pm_has_addr_attr_id() to needs_it. Fixes: efd5a4c04e18 ("mptcp: add the address ID assignment bitmap") Cc: stable@vger.kernel.org Signed-off-by: Geliang Tang Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_netlink.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 287a60381eae..a24c9128dee9 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -901,7 +901,8 @@ static void __mptcp_pm_release_addr_entry(struct mptcp_pm_addr_entry *entry) } static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, - struct mptcp_pm_addr_entry *entry) + struct mptcp_pm_addr_entry *entry, + bool needs_id) { struct mptcp_pm_addr_entry *cur, *del_entry = NULL; unsigned int addr_max; @@ -949,7 +950,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, } } - if (!entry->addr.id) { + if (!entry->addr.id && needs_id) { find_next: entry->addr.id = find_next_zero_bit(pernet->id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1, @@ -960,7 +961,7 @@ static int mptcp_pm_nl_append_new_local_addr(struct pm_nl_pernet *pernet, } } - if (!entry->addr.id) + if (!entry->addr.id && needs_id) goto out; __set_bit(entry->addr.id, pernet->id_bitmap); @@ -1092,7 +1093,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc entry->ifindex = 0; entry->flags = MPTCP_PM_ADDR_FLAG_IMPLICIT; entry->lsk = NULL; - ret = mptcp_pm_nl_append_new_local_addr(pernet, entry); + ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, true); if (ret < 0) kfree(entry); @@ -1285,6 +1286,18 @@ static int mptcp_nl_add_subflow_or_signal_addr(struct net *net) return 0; } +static bool mptcp_pm_has_addr_attr_id(const struct nlattr *attr, + struct genl_info *info) +{ + struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1]; + + if (!nla_parse_nested_deprecated(tb, MPTCP_PM_ADDR_ATTR_MAX, attr, + mptcp_pm_address_nl_policy, info->extack) && + tb[MPTCP_PM_ADDR_ATTR_ID]) + return true; + return false; +} + int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info) { struct nlattr *attr = info->attrs[MPTCP_PM_ENDPOINT_ADDR]; @@ -1326,7 +1339,8 @@ int mptcp_pm_nl_add_addr_doit(struct sk_buff *skb, struct genl_info *info) goto out_free; } } - ret = mptcp_pm_nl_append_new_local_addr(pernet, entry); + ret = mptcp_pm_nl_append_new_local_addr(pernet, entry, + !mptcp_pm_has_addr_attr_id(attr, info)); if (ret < 0) { GENL_SET_ERR_MSG_FMT(info, "too many addresses or duplicate one: %d", ret); goto out_free;