Skip to content

Commit a318d3d

Browse files
committed
Merge branch 'nexthop-fix-two-nexthop-group-statistics-issues'
Ido Schimmel says: ==================== nexthop: Fix two nexthop group statistics issues Fix two issues that were introduced as part of the recent nexthop group statistics submission. See the commit messages for more details. ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 5f20e6a + e006858 commit a318d3d

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

net/ipv4/nexthop.c

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,11 @@ static void nh_grp_entry_stats_inc(struct nh_grp_entry *nhge)
674674
{
675675
struct nh_grp_entry_stats *cpu_stats;
676676

677-
cpu_stats = this_cpu_ptr(nhge->stats);
677+
cpu_stats = get_cpu_ptr(nhge->stats);
678678
u64_stats_update_begin(&cpu_stats->syncp);
679679
u64_stats_inc(&cpu_stats->packets);
680680
u64_stats_update_end(&cpu_stats->syncp);
681+
put_cpu_ptr(cpu_stats);
681682
}
682683

683684
static void nh_grp_entry_stats_read(struct nh_grp_entry *nhge,
@@ -3230,10 +3231,12 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh,
32303231
return -EINVAL;
32313232
}
32323233

3233-
if (tb[NHA_OP_FLAGS])
3234-
*op_flags = nla_get_u32(tb[NHA_OP_FLAGS]);
3235-
else
3236-
*op_flags = 0;
3234+
if (op_flags) {
3235+
if (tb[NHA_OP_FLAGS])
3236+
*op_flags = nla_get_u32(tb[NHA_OP_FLAGS]);
3237+
else
3238+
*op_flags = 0;
3239+
}
32373240

32383241
return 0;
32393242
}
@@ -3242,24 +3245,24 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh,
32423245
static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
32433246
struct netlink_ext_ack *extack)
32443247
{
3248+
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_del)];
32453249
struct net *net = sock_net(skb->sk);
3246-
struct nlattr *tb[NHA_MAX + 1];
32473250
struct nl_info nlinfo = {
32483251
.nlh = nlh,
32493252
.nl_net = net,
32503253
.portid = NETLINK_CB(skb).portid,
32513254
};
32523255
struct nexthop *nh;
3253-
u32 op_flags;
32543256
int err;
32553257
u32 id;
32563258

3257-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
3258-
rtm_nh_policy_del, extack);
3259+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3260+
ARRAY_SIZE(rtm_nh_policy_del) - 1, rtm_nh_policy_del,
3261+
extack);
32593262
if (err < 0)
32603263
return err;
32613264

3262-
err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack);
3265+
err = nh_valid_get_del_req(nlh, tb, &id, NULL, extack);
32633266
if (err)
32643267
return err;
32653268

@@ -3276,16 +3279,17 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
32763279
static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh,
32773280
struct netlink_ext_ack *extack)
32783281
{
3282+
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)];
32793283
struct net *net = sock_net(in_skb->sk);
3280-
struct nlattr *tb[NHA_MAX + 1];
32813284
struct sk_buff *skb = NULL;
32823285
struct nexthop *nh;
32833286
u32 op_flags;
32843287
int err;
32853288
u32 id;
32863289

3287-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
3288-
rtm_nh_policy_get, extack);
3290+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3291+
ARRAY_SIZE(rtm_nh_policy_get) - 1, rtm_nh_policy_get,
3292+
extack);
32893293
if (err < 0)
32903294
return err;
32913295

@@ -3397,26 +3401,27 @@ static int __nh_valid_dump_req(const struct nlmsghdr *nlh, struct nlattr **tb,
33973401
return -EINVAL;
33983402
}
33993403

3400-
if (tb[NHA_OP_FLAGS])
3401-
filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]);
3402-
else
3403-
filter->op_flags = 0;
3404-
34053404
return 0;
34063405
}
34073406

34083407
static int nh_valid_dump_req(const struct nlmsghdr *nlh,
34093408
struct nh_dump_filter *filter,
34103409
struct netlink_callback *cb)
34113410
{
3412-
struct nlattr *tb[NHA_MAX + 1];
3411+
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump)];
34133412
int err;
34143413

3415-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
3414+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3415+
ARRAY_SIZE(rtm_nh_policy_dump) - 1,
34163416
rtm_nh_policy_dump, cb->extack);
34173417
if (err < 0)
34183418
return err;
34193419

3420+
if (tb[NHA_OP_FLAGS])
3421+
filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]);
3422+
else
3423+
filter->op_flags = 0;
3424+
34203425
return __nh_valid_dump_req(nlh, tb, filter, cb->extack);
34213426
}
34223427

@@ -3547,10 +3552,11 @@ static int nh_valid_dump_bucket_req(const struct nlmsghdr *nlh,
35473552
struct netlink_callback *cb)
35483553
{
35493554
struct nlattr *res_tb[ARRAY_SIZE(rtm_nh_res_bucket_policy_dump)];
3550-
struct nlattr *tb[NHA_MAX + 1];
3555+
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_dump_bucket)];
35513556
int err;
35523557

3553-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
3558+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3559+
ARRAY_SIZE(rtm_nh_policy_dump_bucket) - 1,
35543560
rtm_nh_policy_dump_bucket, NULL);
35553561
if (err < 0)
35563562
return err;
@@ -3715,16 +3721,16 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh,
37153721
u32 *id, u16 *bucket_index,
37163722
struct netlink_ext_ack *extack)
37173723
{
3718-
struct nlattr *tb[NHA_MAX + 1];
3719-
u32 op_flags;
3724+
struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get_bucket)];
37203725
int err;
37213726

3722-
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
3727+
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
3728+
ARRAY_SIZE(rtm_nh_policy_get_bucket) - 1,
37233729
rtm_nh_policy_get_bucket, extack);
37243730
if (err < 0)
37253731
return err;
37263732

3727-
err = nh_valid_get_del_req(nlh, tb, id, &op_flags, extack);
3733+
err = nh_valid_get_del_req(nlh, tb, id, NULL, extack);
37283734
if (err)
37293735
return err;
37303736

tools/testing/selftests/net/fib_nexthops.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,12 @@ basic()
20662066
run_cmd "$IP nexthop get id 1"
20672067
log_test $? 2 "Nexthop get on non-existent id"
20682068

2069+
run_cmd "$IP nexthop del id 1"
2070+
log_test $? 2 "Nexthop del with non-existent id"
2071+
2072+
run_cmd "$IP nexthop del id 1 group 1/2/3/4/5/6/7/8"
2073+
log_test $? 2 "Nexthop del with non-existent id and extra attributes"
2074+
20692075
# attempt to create nh without a device or gw - fails
20702076
run_cmd "$IP nexthop add id 1"
20712077
log_test $? 2 "Nexthop with no device or gateway"

0 commit comments

Comments
 (0)