From nobody Tue Feb 10 01:19:27 2026 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:a02:3b21:0:0:0:0:0 with SMTP id c33csp2012814jaa; Wed, 2 Feb 2022 19:14:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJz37fJlsw0gfNCtqwzoUldNrkNKF4+GrInUMaldHWq38HM6FnmqytbGU35yjo4G3ipf5v0V X-Received: by 2002:a63:d2:: with SMTP id 201mr1753181pga.51.1643858062473; Wed, 02 Feb 2022 19:14:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643858062; cv=none; d=google.com; s=arc-20160816; b=k0VnLAmgHjCBIGA0tGehrkHOHO+KsZWqkEKVXjgRNUmsCrYwfuZx4PcIppWC277ilI NbewIGpBFHjr4kN9SBaH9SYzu++qY7/4sGmiSCEW/8cexweDI5uI0OjUVlh5uP4Gs3Gk eRTSUTDB4NrifM9seKnqPcZTJSD8E3kkNKMR9A/TaWwcgBimMK1gdUxBcSOsJOiUfwzK 94OXiL0FaP9/gGcQ17tFtqf57rcA99/ed4C9t7RQOsJsFmPgMvlB9Hsw+X/mEjxevmKD iU63Ao+0wyJtMlqCailtFk4wo9FfJ+1j2J2po3J84jzSZJoA9I9rQ/1Z2q1NqZqz0bSi 8zpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uqeuUfwKn+rKSlnmmuRFIhy5s/IPz7MMSiWc7mKOFec=; b=lv7oKCWMS6UytPb/idvzQ7TxL5BC9Gzftcfxg7PfFuCAs28csX3dBp0YMs3NUW65mU mjCbp7QvocwRPjl9z47PAdy4tMXJpMd1TUBJR69+N4CDuD+BG3mc6rLNAxfbmvMcXZiU 2kXOTXXs3qGA9JfARVQjwYK5dLle93fLhry8SuPnxU7SymdsTjOIqt7V/rgWmxGN4rj+ lJv1SXq9ssRw3m4MOenb1j03lM7yqBzc8IqOa2yl7vrigQlAYZRmRemmoPytD+3rVX2f GVUmj+yRUukoXiHcFeh4u3QLkwb/RPj60Q/CfV3vC+IeOEflOvl8xo8tb2fkW3ahf6jG mPGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="HIyTjx1/"; spf=pass (google.com: domain of mptcp+bounces-3435-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3435-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sjc.edge.kernel.org (sjc.edge.kernel.org. [2604:1380:1000:8100::1]) by mx.google.com with ESMTPS id em13si6359307pjb.175.2022.02.02.19.14.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Feb 2022 19:14:22 -0800 (PST) Received-SPF: pass (google.com: domain of mptcp+bounces-3435-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) client-ip=2604:1380:1000:8100::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="HIyTjx1/"; spf=pass (google.com: domain of mptcp+bounces-3435-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:1000:8100::1 as permitted sender) smtp.mailfrom="mptcp+bounces-3435-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 sjc.edge.kernel.org (Postfix) with ESMTPS id 0DA663E10A3 for ; Thu, 3 Feb 2022 03:14:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7DF0E2F2D; Thu, 3 Feb 2022 03:14:15 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 69F552CA9 for ; Thu, 3 Feb 2022 03:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643858054; x=1675394054; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jVvPsInZ2WgRm5R9Yva2p4UnlfbaQfYIf1IVgaWaBbE=; b=HIyTjx1/BQ2SaMx9qdKGE8OmgrGylb10BoaF+aD0N58KXomgeM3CCm3o lu8l2T5crHblZmns3K77CVbNZxtc3FxwmXCmvx5Piw0ozfZgG+7UVcCAN /QVp4+0j0q1FSBAgF/rYL2dJDYokv3E6GzRpMR47tMJxFK/yTzwh4j8UC iKkP3taLqgNPbciHy1pTclWfL4yL+4AY1tGFnU+SVczCuRbaeFO5dAxgK Ee607bL0hbPsk77Wsk/dCHIdEQe1fFtKV3XCtVYWwH21CyRYfPWrjN3ge WD+E4VWlDSprQNp1aJY9In+Uvjwydvf7VeQ+sUIjyFy/Jl4mFSIRA/mlH g==; X-IronPort-AV: E=McAfee;i="6200,9189,10246"; a="235467502" X-IronPort-AV: E=Sophos;i="5.88,338,1635231600"; d="scan'208";a="235467502" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2022 19:14:09 -0800 X-IronPort-AV: E=Sophos;i="5.88,338,1635231600"; d="scan'208";a="631204631" Received: from otc-tsn-4.jf.intel.com ([10.23.153.135]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Feb 2022 19:14:09 -0800 From: Kishen Maloor To: kishen.maloor@intel.com, mptcp@lists.linux.dev Cc: Florian Westphal Subject: [PATCH mptcp-next v4 04/13] mptcp: netlink: split mptcp_pm_parse_addr into two functions Date: Wed, 2 Feb 2022 22:13:54 -0500 Message-Id: <20220203031403.2996549-5-kishen.maloor@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220203031403.2996549-1-kishen.maloor@intel.com> References: <20220203031403.2996549-1-kishen.maloor@intel.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Florian Westphal 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 --- 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 7058d55e3a0a..4430e4ef8058 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -1350,11 +1350,12 @@ static int mptcp_pm_family_to_addr(int family) return MPTCP_PM_ADDR_ATTR_ADDR4; } =20 -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; =20 if (!attr) { @@ -1368,27 +1369,29 @@ static int mptcp_pm_parse_addr(struct nlattr *attr,= struct genl_info *info, if (err) return err; =20 - memset(entry, 0, sizeof(*entry)); + if (tb[MPTCP_PM_ADDR_ATTR_ID]) + addr->id =3D nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]); + if (!tb[MPTCP_PM_ADDR_ATTR_FAMILY]) { if (!require_family) - goto skip_family; + return err; =20 NL_SET_ERR_MSG_ATTR(info->extack, attr, "missing family"); return -EINVAL; } =20 - entry->addr.family =3D nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]); - if (entry->addr.family !=3D AF_INET + addr->family =3D nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_FAMILY]); + if (addr->family !=3D AF_INET #if IS_ENABLED(CONFIG_MPTCP_IPV6) - && entry->addr.family !=3D AF_INET6 + && addr->family !=3D AF_INET6 #endif ) { NL_SET_ERR_MSG_ATTR(info->extack, attr, "unknown address family"); return -EINVAL; } - addr_addr =3D mptcp_pm_family_to_addr(entry->addr.family); + addr_addr =3D mptcp_pm_family_to_addr(addr->family); if (!tb[addr_addr]) { NL_SET_ERR_MSG_ATTR(info->extack, attr, "missing address data"); @@ -1396,22 +1399,37 @@ static int mptcp_pm_parse_addr(struct nlattr *attr,= struct genl_info *info, } =20 #if IS_ENABLED(CONFIG_MPTCP_IPV6) - if (entry->addr.family =3D=3D AF_INET6) - entry->addr.addr6 =3D nla_get_in6_addr(tb[addr_addr]); + if (addr->family =3D=3D AF_INET6) + addr->addr6 =3D nla_get_in6_addr(tb[addr_addr]); else #endif - entry->addr.addr.s_addr =3D nla_get_in_addr(tb[addr_addr]); + addr->addr.s_addr =3D nla_get_in_addr(tb[addr_addr]); + + if (tb[MPTCP_PM_ADDR_ATTR_PORT]) + addr->port =3D htons(nla_get_u16(tb[MPTCP_PM_ADDR_ATTR_PORT])); + + return err; +} + +static int mptcp_pm_parse_entry(struct nlattr *attr, struct genl_info *inf= o, + 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 =3D mptcp_pm_parse_pm_addr_attr(tb, attr, info, &entry->addr, require= _family); + if (err) + return err; =20 -skip_family: if (tb[MPTCP_PM_ADDR_ATTR_IF_IDX]) { u32 val =3D nla_get_s32(tb[MPTCP_PM_ADDR_ATTR_IF_IDX]); =20 entry->ifindex =3D val; } =20 - if (tb[MPTCP_PM_ADDR_ATTR_ID]) - entry->addr.id =3D nla_get_u8(tb[MPTCP_PM_ADDR_ATTR_ID]); - if (tb[MPTCP_PM_ADDR_ATTR_FLAGS]) entry->flags =3D nla_get_u32(tb[MPTCP_PM_ADDR_ATTR_FLAGS]); =20 @@ -1459,7 +1477,7 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb,= struct genl_info *info) struct mptcp_pm_addr_entry addr, *entry; int ret; =20 - ret =3D mptcp_pm_parse_addr(attr, info, true, &addr); + ret =3D mptcp_pm_parse_entry(attr, info, true, &addr); if (ret < 0) return ret; =20 @@ -1671,7 +1689,7 @@ static int mptcp_nl_cmd_del_addr(struct sk_buff *skb,= struct genl_info *info) unsigned int addr_max; int ret; =20 - ret =3D mptcp_pm_parse_addr(attr, info, false, &addr); + ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; =20 @@ -1847,7 +1865,7 @@ static int mptcp_nl_cmd_get_addr(struct sk_buff *skb,= struct genl_info *info) void *reply; int ret; =20 - ret =3D mptcp_pm_parse_addr(attr, info, false, &addr); + ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; =20 @@ -2058,7 +2076,7 @@ static int mptcp_nl_cmd_set_flags(struct sk_buff *skb= , struct genl_info *info) u8 bkup =3D 0, lookup_by_id =3D 0; int ret; =20 - ret =3D mptcp_pm_parse_addr(attr, info, false, &addr); + ret =3D mptcp_pm_parse_entry(attr, info, false, &addr); if (ret < 0) return ret; =20 --=20 2.31.1