Skip to content

Commit 2118f93

Browse files
pmachatadavem330
authored andcommitted
net: nexthop: Adjust netlink policy parsing for a new attribute
A following patch will introduce a new attribute, op-specific flags to adjust the behavior of an operation. Different operations will recognize different flags. - To make the differentiation possible, stop sharing the policies for get and del operations. - To allow querying for presence of the attribute, have all the attribute arrays sized to NHA_MAX, regardless of what is permitted by policy, and pass the corresponding value to nlmsg_parse() as well. Signed-off-by: Petr Machata <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3b43f19 commit 2118f93

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

net/ipv4/nexthop.c

+28-30
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ static const struct nla_policy rtm_nh_policy_get[] = {
4343
[NHA_ID] = { .type = NLA_U32 },
4444
};
4545

46+
static const struct nla_policy rtm_nh_policy_del[] = {
47+
[NHA_ID] = { .type = NLA_U32 },
48+
};
49+
4650
static const struct nla_policy rtm_nh_policy_dump[] = {
4751
[NHA_OIF] = { .type = NLA_U32 },
4852
[NHA_GROUPS] = { .type = NLA_FLAG },
@@ -2966,9 +2970,9 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
29662970
return err;
29672971
}
29682972

2969-
static int __nh_valid_get_del_req(const struct nlmsghdr *nlh,
2970-
struct nlattr **tb, u32 *id,
2971-
struct netlink_ext_ack *extack)
2973+
static int nh_valid_get_del_req(const struct nlmsghdr *nlh,
2974+
struct nlattr **tb, u32 *id,
2975+
struct netlink_ext_ack *extack)
29722976
{
29732977
struct nhmsg *nhm = nlmsg_data(nlh);
29742978

@@ -2991,26 +2995,12 @@ static int __nh_valid_get_del_req(const struct nlmsghdr *nlh,
29912995
return 0;
29922996
}
29932997

2994-
static int nh_valid_get_del_req(const struct nlmsghdr *nlh, u32 *id,
2995-
struct netlink_ext_ack *extack)
2996-
{
2997-
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)];
2998-
int err;
2999-
3000-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3001-
ARRAY_SIZE(rtm_nh_policy_get) - 1,
3002-
rtm_nh_policy_get, extack);
3003-
if (err < 0)
3004-
return err;
3005-
3006-
return __nh_valid_get_del_req(nlh, tb, id, extack);
3007-
}
3008-
30092998
/* rtnl */
30102999
static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
30113000
struct netlink_ext_ack *extack)
30123001
{
30133002
struct net *net = sock_net(skb->sk);
3003+
struct nlattr *tb[NHA_MAX + 1];
30143004
struct nl_info nlinfo = {
30153005
.nlh = nlh,
30163006
.nl_net = net,
@@ -3020,7 +3010,12 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
30203010
int err;
30213011
u32 id;
30223012

3023-
err = nh_valid_get_del_req(nlh, &id, extack);
3013+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
3014+
rtm_nh_policy_del, extack);
3015+
if (err < 0)
3016+
return err;
3017+
3018+
err = nh_valid_get_del_req(nlh, tb, &id, extack);
30243019
if (err)
30253020
return err;
30263021

@@ -3038,12 +3033,18 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh,
30383033
struct netlink_ext_ack *extack)
30393034
{
30403035
struct net *net = sock_net(in_skb->sk);
3036+
struct nlattr *tb[NHA_MAX + 1];
30413037
struct sk_buff *skb = NULL;
30423038
struct nexthop *nh;
30433039
int err;
30443040
u32 id;
30453041

3046-
err = nh_valid_get_del_req(nlh, &id, extack);
3042+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
3043+
rtm_nh_policy_get, extack);
3044+
if (err < 0)
3045+
return err;
3046+
3047+
err = nh_valid_get_del_req(nlh, tb, &id, extack);
30473048
if (err)
30483049
return err;
30493050

@@ -3157,11 +3158,10 @@ static int nh_valid_dump_req(const struct nlmsghdr *nlh,
31573158
struct nh_dump_filter *filter,
31583159
struct netlink_callback *cb)
31593160
{
3160-
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump)];
3161+
struct nlattr *tb[NHA_MAX + 1];
31613162
int err;
31623163

3163-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3164-
ARRAY_SIZE(rtm_nh_policy_dump) - 1,
3164+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
31653165
rtm_nh_policy_dump, cb->extack);
31663166
if (err < 0)
31673167
return err;
@@ -3300,11 +3300,10 @@ static int nh_valid_dump_bucket_req(const struct nlmsghdr *nlh,
33003300
struct netlink_callback *cb)
33013301
{
33023302
struct nlattr *res_tb[ARRAY_SIZE(rtm_nh_res_bucket_policy_dump)];
3303-
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump_bucket)];
3303+
struct nlattr *tb[NHA_MAX + 1];
33043304
int err;
33053305

3306-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3307-
ARRAY_SIZE(rtm_nh_policy_dump_bucket) - 1,
3306+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
33083307
rtm_nh_policy_dump_bucket, NULL);
33093308
if (err < 0)
33103309
return err;
@@ -3474,16 +3473,15 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh,
34743473
u32 *id, u16 *bucket_index,
34753474
struct netlink_ext_ack *extack)
34763475
{
3477-
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get_bucket)];
3476+
struct nlattr *tb[NHA_MAX + 1];
34783477
int err;
34793478

3480-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3481-
ARRAY_SIZE(rtm_nh_policy_get_bucket) - 1,
3479+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
34823480
rtm_nh_policy_get_bucket, extack);
34833481
if (err < 0)
34843482
return err;
34853483

3486-
err = __nh_valid_get_del_req(nlh, tb, id, extack);
3484+
err = nh_valid_get_del_req(nlh, tb, id, extack);
34873485
if (err)
34883486
return err;
34893487

0 commit comments

Comments
 (0)