Skip to content

Commit af65a3b

Browse files
committed
net: nexthop: Add NHA_OP_FLAGS
JIRA: https://issues.redhat.com/browse/RHEL-59118 commit a207eab Author: Petr Machata <petrm@nvidia.com> Date: Wed Mar 6 13:49:16 2024 +0100 net: nexthop: Add NHA_OP_FLAGS In order to add per-nexthop statistics, but still not increase netlink message size for consumers that do not care about them, there needs to be a toggle through which the user indicates their desire to get the statistics. To that end, add a new attribute, NHA_OP_FLAGS. The idea is to be able to use the attribute for carrying of arbitrary operation-specific flags, i.e. not make it specific for get / dump. Add the new attribute to get and dump policies, but do not actually allow any flags yet -- those will come later as the flags themselves are defined. Add the necessary parsing code. Signed-off-by: Petr Machata <petrm@nvidia.com> Reviewed-by: David Ahern <dsahern@kernel.org> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent 56e7028 commit af65a3b

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

include/uapi/linux/nexthop.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ enum {
6060
/* nested; nexthop bucket attributes */
6161
NHA_RES_BUCKET,
6262

63+
/* u32; operation-specific flags */
64+
NHA_OP_FLAGS,
65+
6366
__NHA_MAX,
6467
};
6568

net/ipv4/nexthop.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ static const struct nla_policy rtm_nh_policy_new[] = {
4141

4242
static const struct nla_policy rtm_nh_policy_get[] = {
4343
[NHA_ID] = { .type = NLA_U32 },
44+
[NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0),
4445
};
4546

4647
static const struct nla_policy rtm_nh_policy_del[] = {
@@ -52,6 +53,7 @@ static const struct nla_policy rtm_nh_policy_dump[] = {
5253
[NHA_GROUPS] = { .type = NLA_FLAG },
5354
[NHA_MASTER] = { .type = NLA_U32 },
5455
[NHA_FDB] = { .type = NLA_FLAG },
56+
[NHA_OP_FLAGS] = NLA_POLICY_MASK(NLA_U32, 0),
5557
};
5658

5759
static const struct nla_policy rtm_nh_res_policy_new[] = {
@@ -2969,7 +2971,7 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
29692971
}
29702972

29712973
static int nh_valid_get_del_req(const struct nlmsghdr *nlh,
2972-
struct nlattr **tb, u32 *id,
2974+
struct nlattr **tb, u32 *id, u32 *op_flags,
29732975
struct netlink_ext_ack *extack)
29742976
{
29752977
struct nhmsg *nhm = nlmsg_data(nlh);
@@ -2990,6 +2992,11 @@ static int nh_valid_get_del_req(const struct nlmsghdr *nlh,
29902992
return -EINVAL;
29912993
}
29922994

2995+
if (tb[NHA_OP_FLAGS])
2996+
*op_flags = nla_get_u32(tb[NHA_OP_FLAGS]);
2997+
else
2998+
*op_flags = 0;
2999+
29933000
return 0;
29943001
}
29953002

@@ -3005,6 +3012,7 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
30053012
.portid = NETLINK_CB(skb).portid,
30063013
};
30073014
struct nexthop *nh;
3015+
u32 op_flags;
30083016
int err;
30093017
u32 id;
30103018

@@ -3013,7 +3021,7 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
30133021
if (err < 0)
30143022
return err;
30153023

3016-
err = nh_valid_get_del_req(nlh, tb, &id, extack);
3024+
err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack);
30173025
if (err)
30183026
return err;
30193027

@@ -3034,6 +3042,7 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh,
30343042
struct nlattr *tb[NHA_MAX + 1];
30353043
struct sk_buff *skb = NULL;
30363044
struct nexthop *nh;
3045+
u32 op_flags;
30373046
int err;
30383047
u32 id;
30393048

@@ -3042,7 +3051,7 @@ static int rtm_get_nexthop(struct sk_buff *in_skb, struct nlmsghdr *nlh,
30423051
if (err < 0)
30433052
return err;
30443053

3045-
err = nh_valid_get_del_req(nlh, tb, &id, extack);
3054+
err = nh_valid_get_del_req(nlh, tb, &id, &op_flags, extack);
30463055
if (err)
30473056
return err;
30483057

@@ -3078,6 +3087,7 @@ struct nh_dump_filter {
30783087
bool group_filter;
30793088
bool fdb_filter;
30803089
u32 res_bucket_nh_id;
3090+
u32 op_flags;
30813091
};
30823092

30833093
static bool nh_dump_filtered(struct nexthop *nh,
@@ -3149,6 +3159,11 @@ static int __nh_valid_dump_req(const struct nlmsghdr *nlh, struct nlattr **tb,
31493159
return -EINVAL;
31503160
}
31513161

3162+
if (tb[NHA_OP_FLAGS])
3163+
filter->op_flags = nla_get_u32(tb[NHA_OP_FLAGS]);
3164+
else
3165+
filter->op_flags = 0;
3166+
31523167
return 0;
31533168
}
31543169

@@ -3478,14 +3493,15 @@ static int nh_valid_get_bucket_req(const struct nlmsghdr *nlh,
34783493
struct netlink_ext_ack *extack)
34793494
{
34803495
struct nlattr *tb[NHA_MAX + 1];
3496+
u32 op_flags;
34813497
int err;
34823498

34833499
err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb, NHA_MAX,
34843500
rtm_nh_policy_get_bucket, extack);
34853501
if (err < 0)
34863502
return err;
34873503

3488-
err = nh_valid_get_del_req(nlh, tb, id, extack);
3504+
err = nh_valid_get_del_req(nlh, tb, id, &op_flags, extack);
34893505
if (err)
34903506
return err;
34913507

0 commit comments

Comments
 (0)