From nobody Mon Sep 16 18:50:21 2024 Received: from out-173.mta1.migadu.com (out-173.mta1.migadu.com [95.215.58.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 92C2E10F7 for ; Sat, 30 Dec 2023 02:49: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="Mzsv4KPj" 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=1703904575; 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=beVa6SDo8B0FuvaeGiUxMPc3/ZWdiLk/Niq8/zvlkCo=; b=Mzsv4KPjplXmvjTq5cAuN8MBj3lHYjXfa3z8Ew/QIMtwmqwIEejvTd8hLxJubQmot0emIQ CGQDQeJX2/MkRPvR8V6rqkIkfKMC3SmCrL4IOqz7XjQwMHE0Q1ZqkSsGjKBt1DmhCCMWo4 A9gIG2RDRRkC5vrf6OVueMRGkIGBmTA= From: Geliang Tang To: mptcp@lists.linux.dev Cc: Geliang Tang Subject: [PATCH mptcp-next v7 18/24] mptcp: implement mptcp_userspace_pm_get_addr Date: Sat, 30 Dec 2023 10:48:13 +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 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 | 70 ++++++++++++++++++++++++++++++++++++++++ net/mptcp/protocol.h | 2 ++ 2 files changed, 72 insertions(+) diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c index 6d514054fe15..4afcd5b589f0 100644 --- a/net/mptcp/pm_userspace.c +++ b/net/mptcp/pm_userspace.c @@ -641,3 +641,73 @@ int mptcp_userspace_pm_dump_addr(struct sk_buff *msg, *((struct id_bitmap *)cb->ctx) =3D *bitmap; 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) { + NL_SET_ERR_MSG_ATTR(info->extack, token, "invalid token"); + return ret; + } + + if (!mptcp_pm_is_userspace(msk)) { + GENL_SET_ERR_MSG(info, "invalid request; userspace PM not selected"); + 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 d52124490f8b..c560c310d7a6 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -1034,6 +1034,8 @@ int mptcp_pm_nl_dump_addr(struct sk_buff *msg, struct netlink_callback *cb); 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.39.2