All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kishen Maloor <kishen.maloor@intel.com>
To: kishen.maloor@intel.com, mptcp@lists.linux.dev
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH mptcp-next v2 12/21] mptcp: netlink: split mptcp_pm_parse_addr into two functions
Date: Wed, 12 Jan 2022 17:15:14 -0500	[thread overview]
Message-ID: <20220112221523.1829397-13-kishen.maloor@intel.com> (raw)
In-Reply-To: <20220112221523.1829397-1-kishen.maloor@intel.com>

From: Florian Westphal <fw@strlen.de>

Next patch will need to parse MPTCP_PM_ATTR_ADDR attributes and
fill an mptcp_addr_info structure from a different genl command
callback.

To avoid copy-paste, split the existing function to a helper
that does the common part and then call the helper from the
(renamed)mptcp_pm_parse_entry function.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 net/mptcp/pm_netlink.c | 60 +++++++++++++++++++++++++++---------------
 1 file changed, 39 insertions(+), 21 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 40c41a0498fc..07536abab3e5 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1316,11 +1316,12 @@ static int mptcp_pm_family_to_addr(int family)
 	return MPTCP_PM_ADDR_ATTR_ADDR4;
 }
 
-static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
-			       bool require_family,
-			       struct mptcp_pm_addr_entry *entry)
+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)
 {
-	struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
 	int err, addr_addr;
 
 	if (!attr) {
@@ -1334,27 +1335,29 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
 	if (err)
 		return err;
 
-	memset(entry, 0, sizeof(*entry));
+	if (tb[MPTCP_PM_ADDR_ATTR_ID])
+		addr->id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
+
 	if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) {
 		if (!require_family)
-			goto skip_family;
+			return err;
 
 		NL_SET_ERR_MSG_ATTR(info->extack, attr,
 				    "missing family");
 		return -EINVAL;
 	}
 
-	entry->addr.family = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
-	if (entry->addr.family != AF_INET
+	addr->family = nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]);
+	if (addr->family != AF_INET
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-	    && entry->addr.family != AF_INET6
+	    && addr->family != AF_INET6
 #endif
 	    ) {
 		NL_SET_ERR_MSG_ATTR(info->extack, attr,
 				    "unknown address family");
 		return -EINVAL;
 	}
-	addr_addr = mptcp_pm_family_to_addr(entry->addr.family);
+	addr_addr = mptcp_pm_family_to_addr(addr->family);
 	if (!tb[addr_addr]) {
 		NL_SET_ERR_MSG_ATTR(info->extack, attr,
 				    "missing address data");
@@ -1362,22 +1365,37 @@ static int mptcp_pm_parse_addr(struct nlattr *attr, struct genl_info *info,
 	}
 
 #if IS_ENABLED(CONFIG_MPTCP_IPV6)
-	if (entry->addr.family == AF_INET6)
-		entry->addr.addr6 = nla_get_in6_addr(tb[addr_addr]);
+	if (addr->family == AF_INET6)
+		addr->addr6 = nla_get_in6_addr(tb[addr_addr]);
 	else
 #endif
-		entry->addr.addr.s_addr = nla_get_in_addr(tb[addr_addr]);
+		addr->addr.s_addr = nla_get_in_addr(tb[addr_addr]);
+
+	if (tb[MPTCP_PM_ADDR_ATTR_PORT])
+		addr->port = htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT]));
+
+	return err;
+}
+
+static int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *info,
+				bool require_family,
+				struct mptcp_pm_addr_entry *entry)
+{
+	struct nlattr *tb[MPTCP_PM_ADDR_ATTR_MAX + 1];
+	int err;
+
+	memset(entry, 0, sizeof(*entry));
+
+	err = mptcp_pm_parse_pm_addr_attr(tb, attr, info, &entry->addr, require_family);
+	if (err)
+		return err;
 
-skip_family:
 	if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) {
 		u32 val = nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]);
 
 		entry->ifindex = val;
 	}
 
-	if (tb[MPTCP_PM_ADDR_ATTR_ID])
-		entry->addr.id = nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]);
-
 	if (tb[MPTCP_PM_ADDR_ATTR_FLAGS])
 		entry->flags = nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]);
 
@@ -1432,7 +1450,7 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
 	struct socket *lsk;
 	int ret;
 
-	ret = mptcp_pm_parse_addr(attr, info, true, &addr);
+	ret = mptcp_pm_parse_entry(attr, info, true, &addr);
 	if (ret < 0)
 		return ret;
 
@@ -1648,7 +1666,7 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb, struct genl_info *info)
 	unsigned int addr_max;
 	int ret;
 
-	ret = mptcp_pm_parse_addr(attr, info, false, &addr);
+	ret = mptcp_pm_parse_entry(attr, info, false, &addr);
 	if (ret < 0)
 		return ret;
 
@@ -1824,7 +1842,7 @@ static int mptcp_nl_cmd_get_addr(struct sk_buff *skb, struct genl_info *info)
 	void *reply;
 	int ret;
 
-	ret = mptcp_pm_parse_addr(attr, info, false, &addr);
+	ret = mptcp_pm_parse_entry(attr, info, false, &addr);
 	if (ret < 0)
 		return ret;
 
@@ -2019,7 +2037,7 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb, struct genl_info *info)
 	u8 bkup = 0, lookup_by_id = 0;
 	int ret;
 
-	ret = mptcp_pm_parse_addr(attr, info, false, &addr);
+	ret = mptcp_pm_parse_entry(attr, info, false, &addr);
 	if (ret < 0)
 		return ret;
 
-- 
2.31.1


  parent reply	other threads:[~2022-01-12 22:16 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12 22:15 [PATCH mptcp-next v2 00/21] mptcp: support userspace path management Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 01/21] mptcp: do not restrict subflows with non-kernel PMs Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 02/21] mptcp: store remote id from MP_JOIN SYN/ACK in local ctx Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 03/21] mptcp: reflect remote port (not 0) in ANNOUNCED events Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 04/21] mptcp: establish subflows from either end of connection Kishen Maloor
2022-01-14 22:43   ` Mat Martineau
2022-01-17  8:59     ` Paolo Abeni
2022-01-19  1:26       ` Kishen Maloor
2022-01-19 12:01         ` Paolo Abeni
2022-01-19 17:59           ` Kishen Maloor
2022-01-19 18:59             ` Mat Martineau
2022-01-12 22:15 ` [PATCH mptcp-next v2 05/21] mptcp: netlink: store per namespace list of refcounted listen socks Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 06/21] mptcp: netlink: store lsk ref in mptcp_pm_addr_entry Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 07/21] mptcp: netlink: process IPv6 addrs in creating listening sockets Kishen Maloor
2022-01-14 15:27   ` Paolo Abeni
2022-01-14 22:09     ` Mat Martineau
2022-01-19  1:25       ` Kishen Maloor
2022-01-19 19:14         ` Mat Martineau
2022-01-12 22:15 ` [PATCH mptcp-next v2 08/21] mptcp: attempt to add listening sockets for announced addrs Kishen Maloor
2022-01-14 15:54   ` Paolo Abeni
2022-01-14 17:47     ` Matthieu Baerts
2022-01-14 22:26     ` Mat Martineau
2022-01-19  1:20     ` Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 09/21] mptcp: allow ADD_ADDR reissuance by userspace PMs Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 10/21] mptcp: handle local addrs announced " Kishen Maloor
2022-01-14 17:11   ` Paolo Abeni
2022-01-19  1:24     ` Kishen Maloor
2022-01-19 19:20       ` Mat Martineau
2022-01-19 20:27         ` Kishen Maloor
2022-01-19 20:44           ` Mat Martineau
2022-01-19 21:30             ` Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 11/21] mptcp: read attributes of addr entries managed " Kishen Maloor
2022-01-12 22:15 ` Kishen Maloor [this message]
2022-01-12 22:15 ` [PATCH mptcp-next v2 13/21] mptcp: netlink: Add MPTCP_PM_CMD_ANNOUNCE Kishen Maloor
2022-01-14 17:04   ` Paolo Abeni
2022-01-19  1:21     ` Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 14/21] mptcp: selftests: support MPTCP_PM_CMD_ANNOUNCE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 15/21] mptcp: netlink: Add MPTCP_PM_CMD_REMOVE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 16/21] mptcp: selftests: support MPTCP_PM_CMD_REMOVE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 17/21] mptcp: netlink: allow userspace-driven subflow establishment Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 18/21] mptcp: selftests: support MPTCP_PM_CMD_SUBFLOW_CREATE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 19/21] mptcp: selftests: support MPTCP_PM_CMD_SUBFLOW_DESTROY Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 20/21] mptcp: selftests: capture netlink events Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 21/21] selftests: mptcp: functional tests for the userspace PM type Kishen Maloor
2022-01-12 22:35   ` selftests: mptcp: functional tests for the userspace PM type: Build Failure MPTCP CI

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220112221523.1829397-13-kishen.maloor@intel.com \
    --to=kishen.maloor@intel.com \
    --cc=fw@strlen.de \
    --cc=mptcp@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.