]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
devlink: Add ability to bind policer to trap group
authorIdo Schimmel <idosch@mellanox.com>
Tue, 31 Mar 2020 08:42:52 +0000 (11:42 +0300)
committerDavid Ahern <dsahern@gmail.com>
Tue, 31 Mar 2020 23:25:07 +0000 (23:25 +0000)
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>
devlink/devlink.c
man/man8/devlink-trap.8

index 9380792ad423bab3aae8443dda27df9f93c36ee1..6405d4be760f675820c3a7d6b98e020afb741632 100644 (file)
@@ -1507,6 +1507,11 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required,
                        if (err)
                                return err;
                        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") &&
                           (o_all & DL_OPT_TRAP_POLICER_RATE)) {
                        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("       devlink trap show [ DEV trap TRAP ]\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 policer set DEV policer POLICER [ rate RATE ] [ burst BURST ]\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",
                     mnl_attr_get_str(tb[DEVLINK_ATTR_TRAP_GROUP_NAME]));
        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_handle_end(dl);
 }
@@ -7181,7 +7190,7 @@ static int cmd_trap_group_set(struct dl *dl)
 
        err = dl_argv_parse_put(nlh, dl,
                                DL_OPT_HANDLE | DL_OPT_TRAP_GROUP_NAME,
-                               DL_OPT_TRAP_ACTION);
+                               DL_OPT_TRAP_ACTION | DL_OPT_TRAP_POLICER_ID);
        if (err)
                return err;
 
index 113eda4ac7904867b419b2e2edf63e6ceb86fbbe..f01f831759c4d5d3c277bcb40d2c0230564e50d5 100644 (file)
@@ -37,6 +37,10 @@ devlink-trap \- devlink trap configuration
 .ti -8
 .BI "devlink trap group set " DEV " group " GROUP
 .RB "[ " action " { " trap " | " drop " } ]"
+.br
+.RB "[ " policer
+.IB "POLICER " ]
+.RB "[ " nopolicer " ]"
 
 .ti -8
 .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
 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
 
 .PP