devlink: Add 'mirror' trap action

Allow setting 'mirror' trap action for traps that support it. Extend the
devlink-trap man page and bash completion accordingly.

Example:

# devlink -jp trap show netdevsim/netdevsim10 trap igmp_query
{
    "trap": {
        "netdevsim/netdevsim10": [ {
                "name": "igmp_query",
                "type": "control",
                "generic": true,
                "action": "mirror",
                "group": "mc_snooping"
            } ]
    }
}

Signed-off-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Ido Schimmel 2020-06-07 11:36:47 +03:00 committed by Stephen Hemminger
parent fd71244a20
commit abda1e9d2b
3 changed files with 15 additions and 8 deletions

View File

@ -678,7 +678,7 @@ _devlink_trap_set_action()
COMPREPLY=( $( compgen -W "action" -- "$cur" ) ) COMPREPLY=( $( compgen -W "action" -- "$cur" ) )
;; ;;
$((7 + $i))) $((7 + $i)))
COMPREPLY=( $( compgen -W "trap drop" -- "$cur" ) ) COMPREPLY=( $( compgen -W "trap drop mirror" -- "$cur" ) )
;; ;;
esac esac
} }
@ -708,7 +708,7 @@ _devlink_trap_group_set()
case $prev in case $prev in
action) action)
COMPREPLY=( $( compgen -W "trap drop" -- "$cur" ) ) COMPREPLY=( $( compgen -W "trap drop mirror" -- "$cur" ) )
return return
;; ;;
policer) policer)

View File

@ -1156,6 +1156,8 @@ static int trap_action_get(const char *actionstr,
*p_action = DEVLINK_TRAP_ACTION_DROP; *p_action = DEVLINK_TRAP_ACTION_DROP;
} else if (strcmp(actionstr, "trap") == 0) { } else if (strcmp(actionstr, "trap") == 0) {
*p_action = DEVLINK_TRAP_ACTION_TRAP; *p_action = DEVLINK_TRAP_ACTION_TRAP;
} else if (strcmp(actionstr, "mirror") == 0) {
*p_action = DEVLINK_TRAP_ACTION_MIRROR;
} else { } else {
pr_err("Unknown trap action \"%s\"\n", actionstr); pr_err("Unknown trap action \"%s\"\n", actionstr);
return -EINVAL; return -EINVAL;
@ -7094,6 +7096,8 @@ static const char *trap_action_name(uint8_t action)
return "drop"; return "drop";
case DEVLINK_TRAP_ACTION_TRAP: case DEVLINK_TRAP_ACTION_TRAP:
return "trap"; return "trap";
case DEVLINK_TRAP_ACTION_MIRROR:
return "mirror";
default: default:
return "<unknown action>"; return "<unknown action>";
} }
@ -7168,9 +7172,9 @@ static int cmd_trap_show_cb(const struct nlmsghdr *nlh, void *data)
static void cmd_trap_help(void) 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 | mirror } ]\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 | mirror } ]\n");
pr_err(" [ policer POLICER ] [ nopolicer ]\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");

View File

@ -26,7 +26,7 @@ devlink-trap \- devlink trap configuration
.ti -8 .ti -8
.BI "devlink trap set " DEV " trap " TRAP .BI "devlink trap set " DEV " trap " TRAP
.RB "[ " action " { " trap " | " drop " } ]" .RB "[ " action " { " trap " | " drop " | " mirror " } ]"
.ti -8 .ti -8
.B "devlink trap group show" .B "devlink trap group show"
@ -36,7 +36,7 @@ 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 " | " mirror " } ]"
.br .br
.RB "[ " policer .RB "[ " policer
.IB "POLICER " ] .IB "POLICER " ]
@ -76,7 +76,7 @@ Only applicable if a devlink device is also specified.
- specifies the packet trap. - specifies the packet trap.
.TP .TP
.BR action " { " trap " | " drop " } " .BR action " { " trap " | " drop " | " mirror " } "
packet trap action. packet trap action.
.I trap .I trap
@ -85,6 +85,9 @@ packet trap action.
.I drop .I drop
- the packet is dropped by the underlying device and a copy is not sent to the CPU. - the packet is dropped by the underlying device and a copy is not sent to the CPU.
.I mirror
- the packet is forwarded by the underlying device and a copy is sent to the CPU.
.SS devlink trap group show - display available packet trap groups and their attributes .SS devlink trap group show - display available packet trap groups and their attributes
.PP .PP
@ -108,7 +111,7 @@ Only applicable if a devlink device is also specified.
- specifies the packet trap group. - specifies the packet trap group.
.TP .TP
.BR action " { " trap " | " drop " } " .BR action " { " trap " | " drop " | " mirror " } "
packet trap action. The action is set for all the packet traps member in the 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.