devlink: Add ability to bind policer to trap group

Add ability to associate a policer with a trap group. The policer can be
unbound by using the 'nopolicer' keyword. In which case, the value
encoded in the 'DEVLINK_ATTR_TRAP_POLICER_ID' attribute will be '0'.
This is consistent with ip-link 'nomaster' keyword and the 'IFLA_MASTER'
attribute.

Example:

# devlink trap group set netdevsim/netdevsim10 group l3_drops policer 2
# devlink -jp trap group show netdevsim/netdevsim10 group l3_drops
{
    "trap_group": {
        "netdevsim/netdevsim10": [ {
                "name": "l3_drops",
                "generic": true,
                "policer": 2
            } ]
    }
}

# devlink trap group set netdevsim/netdevsim10 group l3_drops nopolicer
# devlink -jp trap group show netdevsim/netdevsim10 group l3_drops
{
    "trap_group": {
        "netdevsim/netdevsim10": [ {
                "name": "l3_drops",
                "generic": true
            } ]
    }
}

Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Ido Schimmel 2020-03-31 11:42:52 +03:00 committed by David Ahern
parent a66af55693
commit 02a2a6683f
2 changed files with 22 additions and 1 deletions

View File

@ -1507,6 +1507,11 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
if (err) if (err)
return err; return err;
o_found |= DL_OPT_TRAP_POLICER_ID; o_found |= DL_OPT_TRAP_POLICER_ID;
} else if (dl_argv_match(dl, "nopolicer") &&
(o_all & DL_OPT_TRAP_POLICER_ID)) {
dl_arg_inc(dl);
opts->trap_policer_id = 0;
o_found |= DL_OPT_TRAP_POLICER_ID;
} else if (dl_argv_match(dl, "rate") && } else if (dl_argv_match(dl, "rate") &&
(o_all & DL_OPT_TRAP_POLICER_RATE)) { (o_all & DL_OPT_TRAP_POLICER_RATE)) {
dl_arg_inc(dl); dl_arg_inc(dl);
@ -7068,6 +7073,7 @@ static void cmd_trap_help(void)
pr_err("Usage: devlink trap set DEV trap TRAP [ action { trap | drop } ]\n"); pr_err("Usage: devlink trap set DEV trap TRAP [ action { trap | drop } ]\n");
pr_err(" devlink trap show [ DEV trap TRAP ]\n"); pr_err(" devlink trap show [ DEV trap TRAP ]\n");
pr_err(" devlink trap group set DEV group GROUP [ action { trap | drop } ]\n"); pr_err(" devlink trap group set DEV group GROUP [ action { trap | drop } ]\n");
pr_err(" [ policer POLICER ] [ nopolicer ]\n");
pr_err(" devlink trap group show [ DEV group GROUP ]\n"); pr_err(" devlink trap group show [ DEV group GROUP ]\n");
pr_err(" devlink trap policer set DEV policer POLICER [ rate RATE ] [ burst BURST ]\n"); pr_err(" devlink trap policer set DEV policer POLICER [ rate RATE ] [ burst BURST ]\n");
pr_err(" devlink trap policer show DEV policer POLICER\n"); pr_err(" devlink trap policer show DEV policer POLICER\n");
@ -7125,6 +7131,9 @@ static void pr_out_trap_group(struct dl *dl, struct nlattr **tb, bool array)
print_string(PRINT_ANY, "name", "name %s", print_string(PRINT_ANY, "name", "name %s",
mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME])); mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
print_bool(PRINT_ANY, "generic", " generic %s", !!tb[DEVLINK_ATTR_TRAP_GENERIC]); print_bool(PRINT_ANY, "generic", " generic %s", !!tb[DEVLINK_ATTR_TRAP_GENERIC]);
if (tb[DEVLINK_ATTR_TRAP_POLICER_ID])
print_uint(PRINT_ANY, "policer", " policer %u",
mnl_attr_get_u32(tb[DEVLINK_ATTR_TRAP_POLICER_ID]));
pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]); pr_out_stats(dl, tb[DEVLINK_ATTR_STATS]);
pr_out_handle_end(dl); pr_out_handle_end(dl);
} }
@ -7181,7 +7190,7 @@ static int cmd_trap_group_set(struct dl *dl)
err = dl_argv_parse_put(nlh, dl, err = dl_argv_parse_put(nlh, dl,
DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME, DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME,
DL_OPT_TRAP_ACTION); DL_OPT_TRAP_ACTION | DL_OPT_TRAP_POLICER_ID);
if (err) if (err)
return err; return err;

View File

@ -37,6 +37,10 @@ devlink-trap \- devlink trap configuration
.ti -8 .ti -8
.BI "devlink trap group set " DEV " group " GROUP .BI "devlink trap group set " DEV " group " GROUP
.RB "[ " action " { " trap " | " drop " } ]" .RB "[ " action " { " trap " | " drop " } ]"
.br
.RB "[ " policer
.IB "POLICER " ]
.RB "[ " nopolicer " ]"
.ti -8 .ti -8
.BI "devlink trap policer set " DEV " policer " POLICER .BI "devlink trap policer set " DEV " policer " POLICER
@ -109,6 +113,14 @@ packet trap action. The action is set for all the packet traps member in the
trap group. The actions of non-drop traps cannot be changed and are thus trap group. The actions of non-drop traps cannot be changed and are thus
skipped. skipped.
.TP
.BI policer " POLICER"
packet trap policer. The policer to bind to the packet trap group.
.TP
.B nopolicer
Unbind packet trap policer from the packet trap group.
.SS devlink trap policer set - set attributes of packet trap policer .SS devlink trap policer set - set attributes of packet trap policer
.PP .PP