tc: m_vlan: Add priority option to push vlan action

The current vlan push action supports only vid and protocol options.
Add priority option.

Example script that adds vlan push action with vid and priority:

tc filter add dev veth0 protocol ip parent ffff: \
	flower \
	indev veth0 \
	action vlan push id 100 priority 5

Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
This commit is contained in:
Hadar Hen Zion 2016-09-01 09:45:48 +03:00 committed by Stephen Hemminger
parent 745d917260
commit 0e43ed9dea
2 changed files with 26 additions and 1 deletions

View File

@ -12,6 +12,8 @@ vlan - vlan manipulation module
.IR PUSH " := " .IR PUSH " := "
.BR push " [ " protocol .BR push " [ " protocol
.IR VLANPROTO " ]" .IR VLANPROTO " ]"
.BR " [ " priority
.IR VLANPRIO " ] "
.BI id " VLANID" .BI id " VLANID"
.ti -8 .ti -8
@ -55,6 +57,9 @@ for hexadecimal interpretation, etc.).
Choose the VLAN protocol to use. At the time of writing, the kernel accepts only Choose the VLAN protocol to use. At the time of writing, the kernel accepts only
.BR 802.1Q " or " 802.1ad . .BR 802.1Q " or " 802.1ad .
.TP .TP
.BI priority " VLANPRIO"
Choose the VLAN priority to use. Decimal number in range of 0-7.
.TP
.I CONTROL .I CONTROL
How to continue after executing this action. How to continue after executing this action.
.RS .RS

View File

@ -22,7 +22,7 @@
static void explain(void) static void explain(void)
{ {
fprintf(stderr, "Usage: vlan pop\n"); fprintf(stderr, "Usage: vlan pop\n");
fprintf(stderr, " vlan push [ protocol VLANPROTO ] id VLANID [CONTROL]\n"); fprintf(stderr, " vlan push [ protocol VLANPROTO ] id VLANID [ priority VLANPRIO ] [CONTROL]\n");
fprintf(stderr, " VLANPROTO is one of 802.1Q or 802.1AD\n"); fprintf(stderr, " VLANPROTO is one of 802.1Q or 802.1AD\n");
fprintf(stderr, " with default: 802.1Q\n"); fprintf(stderr, " with default: 802.1Q\n");
fprintf(stderr, " CONTROL := reclassify | pipe | drop | continue | pass\n"); fprintf(stderr, " CONTROL := reclassify | pipe | drop | continue | pass\n");
@ -45,6 +45,8 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p,
int id_set = 0; int id_set = 0;
__u16 proto; __u16 proto;
int proto_set = 0; int proto_set = 0;
__u8 prio;
int prio_set = 0;
struct tc_vlan parm = { 0 }; struct tc_vlan parm = { 0 };
if (matches(*argv, "vlan") != 0) if (matches(*argv, "vlan") != 0)
@ -91,6 +93,17 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p,
if (ll_proto_a2n(&proto, *argv)) if (ll_proto_a2n(&proto, *argv))
invarg("protocol is invalid", *argv); invarg("protocol is invalid", *argv);
proto_set = 1; proto_set = 1;
} else if (matches(*argv, "priority") == 0) {
if (action != TCA_VLAN_ACT_PUSH) {
fprintf(stderr, "\"%s\" is only valid for push\n",
*argv);
explain();
return -1;
}
NEXT_ARG();
if (get_u8(&prio, *argv, 0) || (prio & ~0x7))
invarg("prio is invalid", *argv);
prio_set = 1;
} else if (matches(*argv, "help") == 0) { } else if (matches(*argv, "help") == 0) {
usage(); usage();
} else { } else {
@ -138,6 +151,9 @@ static int parse_vlan(struct action_util *a, int *argc_p, char ***argv_p,
addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PROTOCOL, &proto, 2); addattr_l(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PROTOCOL, &proto, 2);
} }
if (prio_set)
addattr8(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PRIORITY, prio);
tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail; tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
*argc_p = argc; *argc_p = argc;
@ -180,6 +196,10 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
ll_proto_n2a(rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]), ll_proto_n2a(rta_getattr_u16(tb[TCA_VLAN_PUSH_VLAN_PROTOCOL]),
b1, sizeof(b1))); b1, sizeof(b1)));
} }
if (tb[TCA_VLAN_PUSH_VLAN_PRIORITY]) {
val = rta_getattr_u8(tb[TCA_VLAN_PUSH_VLAN_PRIORITY]);
fprintf(f, " priority %u", val);
}
break; break;
} }
fprintf(f, " %s", action_n2a(parm->action)); fprintf(f, " %s", action_n2a(parm->action));