Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp464271lqg; Fri, 1 Mar 2024 10:20:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWr7zHAlsSeU7hDCO2f+b8eBDthh78RuOryc31+wTVwxM1cneecCz4b6PHwy7jvt+r6skCVnxi0dn6NxbalGAcM2rvo7dPU9PjR1Ksr4A== X-Google-Smtp-Source: AGHT+IEtc19UtlJmpOxPIkXkKs8yCGjVoNf5x6n1il6gKfuIuB/uMqGyscctwk4P3ZUJvrpqRmjV X-Received: by 2002:a17:907:7677:b0:a3f:98e4:7dc9 with SMTP id kk23-20020a170907767700b00a3f98e47dc9mr1974216ejc.28.1709317211406; Fri, 01 Mar 2024 10:20:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709317211; cv=pass; d=google.com; s=arc-20160816; b=IFbXrdrFPXntbDtgEtyh+V9jibuL4qTQJAlt7N1k8jMCiPOmORwq44uNUwww6pYjjV TAZNQe4GI+XnwM+86xTWNEpqhdFd2p5fGunc0H4yUirh6xDoQOmTth7NJ76CDdZjwSmS a0ogWNXMVqgLj3CIOXWp4xBogGFL5oAQd9nKS9q1riUAeKzZf/goQv0t2KDUJ3Eyx83f +IKBvFVByzyXdPi4VEP7y3ja/mIbBUrQcQeXPx4JyoeHn5ixngD9HrOgCfFG7i/5S5Ip ljBU7hYsw5aHfy2cfEZ9typjiOJ7nwZ1yxBOt4WsUZJinBjxGTtR8jaHeWe3Yfit7nOS 3kCw== 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=9no2Wtt0K6QNEmomgWlPuHiM2cndjfQnxde478qDFTg=; fh=i1fHfqb3ms9PQICjX9LbYyHHX00fft5d6t57sCy1Fok=; b=I+KO42kKL4PSTG5DkZ7Pb5K0Jg7TfWHliMGIMI0VDAaMc34Rrp8vqVa+T16ddYPF2K HWj0zEkDPDHwlEpfWd6K2t+wybfCW7ISZ2ZleSMDw3WWV5dsqL/uTlPkyMih9lE3OBlj sv5zvk5KNZubIgSmFuxGs9TjXfRrCzv0tqXDEAuZ0/kUusfFyT+sK8BDRiCYArstgmA4 RvgOi088ea0jNz9uBiw5+8kUZuyAo/n1eSmRX8oBhSTlBFwO+1ZShrW2Ydf/yXX7y9W2 LZNyNiN1LQVzQEY2r/GeLHLsHP9gnckfT3C0UUnrO7FTXrZeXEOY43VXhmM4XR1ZqKu5 1DVg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EBL3jIEM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88900-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88900-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id hg4-20020a1709072cc400b00a448a969aa1si699133ejc.379.2024.03.01.10.20.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 10:20:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88900-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EBL3jIEM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-88900-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88900-linux.lists.archive=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 am.mirrors.kernel.org (Postfix) with ESMTPS id CCB6D1F22E14 for ; Fri, 1 Mar 2024 18:20:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 980723B1AB; Fri, 1 Mar 2024 18:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EBL3jIEM" 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 A2DC43AC25; Fri, 1 Mar 2024 18:18:41 +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=1709317122; cv=none; b=ZPA+e0nx1WBHWsTH0fYrolcwjriuM2CQhxmp2hGZRv79oEjnZdi+7FFjFN8O0dYwgsikQCjjAQdP4oQSPByPv8X1aPdh2xRjmscXEK2JwshhTEdor3F0fJvyBIOtEIQzM3Rg1oFn/sXj6DC/1cml9X4DZFdlHB1qLAAuPpXgxPg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709317122; c=relaxed/simple; bh=2J2ip4Xxu7bYBw1bsYGLEY/qmSglztaVCRJZDa8cTFE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MIxKWBIY6cW/Kycx99G5WQEIboobVTma1Tk9VxujkTto99e8Pye1mo8osCGrDgJWlVhyyvKKImRDHL47C23fu2DDUxaSPlaukDti3OGAUzOpbQcVhuUUOKbRX2Bcb9Z6XE+juJ7GEN/C3GCpnvcEa+2/ad09yMsNyGlzYgHyIEI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EBL3jIEM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0E06C433C7; Fri, 1 Mar 2024 18:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709317121; bh=2J2ip4Xxu7bYBw1bsYGLEY/qmSglztaVCRJZDa8cTFE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=EBL3jIEMDupJt9hn+0oMCPPa+NAKGt32Zvd+ptBOUooQjGWN7+3nQxpnJTi3C4vah EUrC5AYcN9qYSAyaom1hP3OWNkDGpco1iOL/+HPqymvTgfpOQdbITve62rLQnYzBXw d1ToOYhMG74oYVunmZ9YG12YmSgOMp6viWjH+VKTYYhNIz4Tht+mcn48VC6tsKjw3E aD2FZ5Iptqq2B6F5mB/KlMqdb772j0LDq9thNPFlEnKfAKH9bx3h9KkCmYMsq5ml9g tgwBNcXXRUbL9n8sO5PdZ2VF3piakXkgzYcv3DR11wWa9LNGPwe4588LB8iwR3Xi0P D54ez0Eg53G+Q== From: "Matthieu Baerts (NGI0)" Date: Fri, 01 Mar 2024 19:18:27 +0100 Subject: [PATCH net-next 03/15] mptcp: implement mptcp_userspace_pm_dump_addr Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240301-upstream-net-next-20240301-mptcp-userspace-pm-dump-addr-v1-3-dc30a420b3a0@kernel.org> References: <20240301-upstream-net-next-20240301-mptcp-userspace-pm-dump-addr-v1-0-dc30a420b3a0@kernel.org> In-Reply-To: <20240301-upstream-net-next-20240301-mptcp-userspace-pm-dump-addr-v1-0-dc30a420b3a0@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Shuah Khan Cc: Geliang Tang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3214; i=matttbe@kernel.org; h=from:subject:message-id; bh=3ItNwH55x/xaZ+UgJN8s9oLJOd5rmW4EkNP6do8rk9A=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBl4hv06y6c4NEIWAkCUt6adgLqaRXfjgFtRrupc RFHEMFnP8aJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZeIb9AAKCRD2t4JPQmmg c+MtEACwhMfbqpbW7+htXjcxOM3D2r+x3zW5A0+BdS4NXpHXkLKKvSQxufbUHaJm8knD2QsGgGM 4mX7eAH/ZJFn+VkY+KcEhCf3dnFBIUu/Y7TpwufUddTViKMrFDya3s6hWv+MNBw8aKOLB6U0e2e JmpNyP/WDnZSIqUMB3Kfur32DZ5NcLRZT9ymLsRx6RxFbNgbj7ZZA+ijTuDE1suwqs7jr6NFJUj CuJKWkfFHso8HnJNci3AryGXnMZZQFXnAiHUvEec5+y6BYcj9uyxc+Gp4gKEq5Il5V0ABkdJqSU cOihZsWTtFBLS6yDWj5ui1mf7zAynKtzLI4dD6Jivw0zbG9qoZs0AfwbXyUZQnXGpJ5KpzzjxtZ YI3zctcbXjI+W+Eb5QCFtSi2OQUl2GGbIW+EM+i7VWXrbpuNCTFpwIM/4MCjAsXsfjvOf8i7aqf 9MXBwOf9mhFkXEpPZutBYK9L9dPB0hLkqhEbt74yp95EZm2bPMZ2E47o7QFXKHuwOp8SdfQIU0Z Q6bOc74yyOaRNAigjRtnB+Zm2IrEQ+vZuXJQMxjBE4RWfgTfZF94Ozly+AG/9gbW47EPn452Z3/ ENAe9iB1En6HvqbBDtms2Hik0qjCT7io1pTo/kpX2DhpcRvrJjSiGsX3eywBWRZAbCI06wuu99i Y4YZe5ED3dkCb/A== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang 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 Reviewed-by: Matthieu Baerts (NGI0) Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/pm_userspace.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 2 ++ 2 files changed, 62 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index bc97cc30f013..d6b7be3afbe5 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -572,3 +572,63 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token, sock_put(sk); return ret; } + +int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, + struct netlink_callback *cb) +{ + struct id_bitmap { + DECLARE_BITMAP(map, MPTCP_PM_MAX_ADDR_ID + 1); + } *bitmap; + const struct genl_info *info = genl_info_dump(cb); + struct net *net = sock_net(msg->sk); + struct mptcp_pm_addr_entry *entry; + struct mptcp_sock *msk; + struct nlattr *token; + int ret = -EINVAL; + struct sock *sk; + void *hdr; + + bitmap = (struct id_bitmap *)cb->ctx; + token = info->attrs[MPTCP_PM_ATTR_TOKEN]; + + msk = mptcp_token_get_sock(net, nla_get_u32(token)); + if (!msk) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + return ret; + } + + sk = (struct sock *)msk; + + if (!mptcp_pm_is_userspace(msk)) { + GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + goto out; + } + + lock_sock(sk); + spin_lock_bh(&msk->pm.lock); + list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) { + if (test_bit(entry->addr.id, bitmap->map)) + continue; + + hdr = 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; + } + + __set_bit(entry->addr.id, bitmap->map); + genlmsg_end(msg, hdr); + } + spin_unlock_bh(&msk->pm.lock); + release_sock(sk); + ret = msg->len; + +out: + sock_put(sk); + return ret; +} diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index d70fb3bf5076..ab9c8004eb56 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1042,6 +1042,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_info *skc); int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc); +int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, + struct netlink_callback *cb); static inline u8 subflow_get_local_id(const struct mptcp_subflow_context *subflow) { -- 2.43.0