Skip to content

Commit

Permalink
nexthop: Extract a common helper for parsing dump attributes
Browse files Browse the repository at this point in the history
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>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Petr Machata authored and Jakub Kicinski committed Jan 29, 2021
1 parent 56450ec commit b9ebea1
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions net/ipv4/nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit b9ebea1

Please sign in to comment.