netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Machata <petrm@nvidia.com>
To: <netdev@vger.kernel.org>
Cc: David Ahern <dsahern@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>,
	"Petr Machata" <petrm@nvidia.com>
Subject: [PATCH net-next 08/12] nexthop: Extract a common helper for parsing dump attributes
Date: Thu, 28 Jan 2021 13:49:20 +0100	[thread overview]
Message-ID: <abc4e50cfa17069b15644755da69bf7c1f47855d.1611836479.git.petrm@nvidia.com> (raw)
In-Reply-To: <cover.1611836479.git.petrm@nvidia.com>

Requests to dump nexthops have many attributes in common with those that
requests to dump buckets of resilient NH groups will have. However, they
have different policies. To allow reuse of this code, extract a
policy-agnostic wrapper out of nh_valid_dump_req(), and convert this
function into a thin wrapper around it.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
---
 net/ipv4/nexthop.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
index ad48e5d71bf9..1c4f10fe3b4e 100644
--- a/net/ipv4/nexthop.c
+++ b/net/ipv4/nexthop.c
@@ -2015,22 +2015,13 @@ static bool nh_dump_filtered(struct nexthop *nh,
 	return false;
 }
 
-static int nh_valid_dump_req(const struct nlmsghdr *nlh,
-			     struct nh_dump_filter *filter,
-			     struct netlink_callback *cb)
+static int __nh_valid_dump_req(const struct nlmsghdr *nlh, struct nlattr **tb,
+			       struct nh_dump_filter *filter,
+			       struct netlink_ext_ack *extack)
 {
-	struct netlink_ext_ack *extack = cb->extack;
-	struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump)];
 	struct nhmsg *nhm;
-	int err;
 	u32 idx;
 
-	err = nlmsg_parse(nlh, sizeof(*nhm), tb,
-			  ARRAY_SIZE(rtm_nh_policy_dump) - 1,
-			  rtm_nh_policy_dump, NULL);
-	if (err < 0)
-		return err;
-
 	if (tb[NHA_OIF]) {
 		idx = nla_get_u32(tb[NHA_OIF]);
 		if (idx > INT_MAX) {
@@ -2059,6 +2050,22 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh,
 	return 0;
 }
 
+static int nh_valid_dump_req(const struct nlmsghdr *nlh,
+			     struct nh_dump_filter *filter,
+			     struct netlink_callback *cb)
+{
+	struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump)];
+	int err;
+
+	err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
+			  ARRAY_SIZE(rtm_nh_policy_dump) - 1,
+			  rtm_nh_policy_dump, cb->extack);
+	if (err < 0)
+		return err;
+
+	return __nh_valid_dump_req(nlh, tb, filter, cb->extack);
+}
+
 /* rtnl */
 static int rtm_dump_nexthop(struct sk_buff *skb, struct netlink_callback *cb)
 {
-- 
2.26.2


  parent reply	other threads:[~2021-01-28 12:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 12:49 [PATCH net-next 00/12] nexthop: Preparations for resilient next-hop groups Petr Machata
2021-01-28 12:49 ` [PATCH net-next 01/12] nexthop: Rename nexthop_free_mpath Petr Machata
2021-01-29  3:05   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 02/12] nexthop: Dispatch nexthop_select_path() by group type Petr Machata
2021-01-29  3:08   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 03/12] nexthop: Introduce to struct nh_grp_entry a per-type union Petr Machata
2021-01-29  3:09   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 04/12] nexthop: Assert the invariant that a NH group is of only one type Petr Machata
2021-01-29  3:10   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 05/12] nexthop: Use enum to encode notification type Petr Machata
2021-01-29  3:12   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 06/12] nexthop: Dispatch notifier init()/fini() by group type Petr Machata
2021-01-29  3:13   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 07/12] nexthop: Extract dump filtering parameters into a single structure Petr Machata
2021-01-29  3:16   ` David Ahern
2021-01-28 12:49 ` Petr Machata [this message]
2021-01-29  3:17   ` [PATCH net-next 08/12] nexthop: Extract a common helper for parsing dump attributes David Ahern
2021-01-28 12:49 ` [PATCH net-next 09/12] nexthop: Strongly-type context of rtm_dump_nexthop() Petr Machata
2021-01-29  3:18   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 10/12] nexthop: Extract a helper for walking the next-hop tree Petr Machata
2021-01-29  3:19   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 11/12] nexthop: Add a callback parameter to rtm_dump_walk_nexthops() Petr Machata
2021-01-29  3:20   ` David Ahern
2021-01-28 12:49 ` [PATCH net-next 12/12] nexthop: Extract a helper for validation of get/del RTNL requests Petr Machata
2021-01-29  3:21   ` David Ahern
2021-01-29  3:24 ` [PATCH net-next 00/12] nexthop: Preparations for resilient next-hop groups David Ahern
2021-01-29  5:10 ` patchwork-bot+netdevbpf

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=abc4e50cfa17069b15644755da69bf7c1f47855d.1611836479.git.petrm@nvidia.com \
    --to=petrm@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).