Skip to content

Commit 0bccf8e

Browse files
pmachatakuba-moo
authored andcommitted
nexthop: Extract a helper for validation of get/del RTNL requests
Validation of messages for get / del of a next hop is the same as will be validation of messages for get of a resilient next hop group bucket. The difference is that policy for resilient next hop group buckets is a superset of that used for next-hop get. It is therefore possible to reuse the code that validates the nhmsg fields, extracts the next-hop ID, and validates that. To that end, extract from nh_valid_get_del_req() a helper __nh_valid_get_del_req() that does just that. Make the nlh argument const so that the function can be called from the dump context, which only has a const nlh. Propagate the constness to nh_valid_get_del_req(). Signed-off-by: Petr Machata <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e948217 commit 0bccf8e

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

net/ipv4/nexthop.c

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,37 +1872,44 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
18721872
return err;
18731873
}
18741874

1875-
static int nh_valid_get_del_req(struct nlmsghdr *nlh, u32 *id,
1876-
struct netlink_ext_ack *extack)
1875+
static int __nh_valid_get_del_req(const struct nlmsghdr *nlh,
1876+
struct nlattr **tb, u32 *id,
1877+
struct netlink_ext_ack *extack)
18771878
{
18781879
struct nhmsg *nhm = nlmsg_data(nlh);
1879-
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)];
1880-
int err;
1881-
1882-
err = nlmsg_parse(nlh, sizeof(*nhm), tb,
1883-
ARRAY_SIZE(rtm_nh_policy_get) - 1,
1884-
rtm_nh_policy_get, extack);
1885-
if (err < 0)
1886-
return err;
18871880

1888-
err = -EINVAL;
18891881
if (nhm->nh_protocol || nhm->resvd || nhm->nh_scope || nhm->nh_flags) {
18901882
NL_SET_ERR_MSG(extack, "Invalid values in header");
1891-
goto out;
1883+
return -EINVAL;
18921884
}
18931885

18941886
if (!tb[NHA_ID]) {
18951887
NL_SET_ERR_MSG(extack, "Nexthop id is missing");
1896-
goto out;
1888+
return -EINVAL;
18971889
}
18981890

18991891
*id = nla_get_u32(tb[NHA_ID]);
1900-
if (!(*id))
1892+
if (!(*id)) {
19011893
NL_SET_ERR_MSG(extack, "Invalid nexthop id");
1902-
else
1903-
err = 0;
1904-
out:
1905-
return err;
1894+
return -EINVAL;
1895+
}
1896+
1897+
return 0;
1898+
}
1899+
1900+
static int nh_valid_get_del_req(const struct nlmsghdr *nlh, u32 *id,
1901+
struct netlink_ext_ack *extack)
1902+
{
1903+
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)];
1904+
int err;
1905+
1906+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
1907+
ARRAY_SIZE(rtm_nh_policy_get) - 1,
1908+
rtm_nh_policy_get, extack);
1909+
if (err < 0)
1910+
return err;
1911+
1912+
return __nh_valid_get_del_req(nlh, tb, id, extack);
19061913
}
19071914

19081915
/* rtnl */

0 commit comments

Comments
 (0)