* [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support
@ 2016-09-01 6:45 Hadar Hen Zion
2016-09-01 6:45 ` [PATCH iproute2 V2 1/2] tc: flower: Introduce vlan support Hadar Hen Zion
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Hadar Hen Zion @ 2016-09-01 6:45 UTC (permalink / raw)
To: Stephen Hemminger
Cc: netdev, David S. Miller, Jiri Pirko, Or Gerlitz, Amir Vadai,
Hadar Hen Zion
Hi,
This patchset introduce vlan tag support to the tc flower classifier.
In addition to adding vlan priority to vlan push action.
- The first patch adds classification according to vlan id and vlan priority to the flower.
- The second patch adds support for vlan priority to the current vlan push action.
Changes from v1:
- Remove VLAN_PRIO_MASK and VLAN_VID_MASK defines from tc_vlan.h file
Hadar Hen Zion (2):
tc: flower: Introduce vlan support
tc: m_vlan: Add priority option to push vlan action
man/man8/tc-flower.8 | 25 ++++++++++++++++-
man/man8/tc-vlan.8 | 5 ++++
tc/f_flower.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++--
tc/m_vlan.c | 22 ++++++++++++++-
4 files changed, 125 insertions(+), 5 deletions(-)
--
1.8.3.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH iproute2 V2 1/2] tc: flower: Introduce vlan support
2016-09-01 6:45 [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support Hadar Hen Zion
@ 2016-09-01 6:45 ` Hadar Hen Zion
2016-09-01 6:45 ` [PATCH iproute2 V2 2/2] tc: m_vlan: Add priority option to push vlan action Hadar Hen Zion
2016-09-01 15:40 ` [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Hadar Hen Zion @ 2016-09-01 6:45 UTC (permalink / raw)
To: Stephen Hemminger
Cc: netdev, David S. Miller, Jiri Pirko, Or Gerlitz, Amir Vadai,
Hadar Hen Zion
Classification according to vlan id and vlan priority.
Example script that adds vlan filter:
# add ingress qdisc
tc qdisc add dev ens4f0 ingress
# add a flower filter with vlan id and priority classification
tc filter add dev ens4f0 protocol 802.1Q parent ffff: \
flower \
indev ens4f0 \
vlan_ethtype ipv4 \
vlan_id 100 \
vlan_prio 3 \
action vlan pop
Signed-off-by: Hadar Hen Zion <hadarh@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
man/man8/tc-flower.8 | 25 ++++++++++++++++-
tc/f_flower.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 99 insertions(+), 4 deletions(-)
diff --git a/man/man8/tc-flower.8 b/man/man8/tc-flower.8
index 9ae10e6..74f7664 100644
--- a/man/man8/tc-flower.8
+++ b/man/man8/tc-flower.8
@@ -23,7 +23,13 @@ flower \- flow based traffic control filter
.R " | { "
.BR dst_mac " | " src_mac " } "
.IR mac_address " | "
-.BR eth_type " { " ipv4 " | " ipv6 " | "
+.BR eth_type " { " ipv4 " | " ipv6 " | " 802.1Q " | "
+.IR ETH_TYPE " } | "
+.B vlan_id
+.IR VID " | "
+.B vlan_prio
+.IR PRIORITY " | "
+.BR vlan_eth_type " { " ipv4 " | " ipv6 " | "
.IR ETH_TYPE " } | "
.BR ip_proto " { " tcp " | " udp " | "
.IR IP_PROTO " } | { "
@@ -70,6 +76,23 @@ Do not process filter by hardware.
Match on source or destination MAC address.
.TP
.BI eth_type " ETH_TYPE"
+Match on the next protocol.
+.I ETH_TYPE
+may be either
+.BR ipv4 , ipv6 , 802.1Q ,
+or an unsigned 16bit value in hexadecimal format.
+.TP
+.BI vlan_id " VID"
+Match on vlan tag id.
+.I VID
+is an unsigned 12bit value in decimal format.
+.TP
+.BI vlan_prio " priority"
+Match on vlan tag priority.
+.I PRIORITY
+is an unsigned 3bit value in decimal format.
+.TP
+.BI vlan_eth_type " VLAN_ETH_TYPE"
Match on layer three protocol.
.I ETH_TYPE
may be either
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 791ade7..2d31d1a 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -17,6 +17,7 @@
#include <net/if.h>
#include <linux/if_ether.h>
#include <linux/ip.h>
+#include <linux/tc_act/tc_vlan.h>
#include "utils.h"
#include "tc_util.h"
@@ -30,6 +31,9 @@ static void explain(void)
fprintf(stderr, "\n");
fprintf(stderr, "Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n");
fprintf(stderr, " MATCH := { indev DEV-NAME |\n");
+ fprintf(stderr, " vlan_id VID |\n");
+ fprintf(stderr, " vlan_prio PRIORITY |\n");
+ fprintf(stderr, " vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n");
fprintf(stderr, " dst_mac MAC-ADDR |\n");
fprintf(stderr, " src_mac MAC-ADDR |\n");
fprintf(stderr, " [ipv4 | ipv6 ] |\n");
@@ -61,6 +65,23 @@ static int flower_parse_eth_addr(char *str, int addr_type, int mask_type,
return 0;
}
+static int flower_parse_vlan_eth_type(char *str, __be16 eth_type, int type,
+ __be16 *p_vlan_eth_type, struct nlmsghdr *n)
+{
+ __be16 vlan_eth_type;
+
+ if (eth_type != htons(ETH_P_8021Q)) {
+ fprintf(stderr, "Can't set \"vlan_ethtype\" if ethertype isn't 802.1Q\n");
+ return -1;
+ }
+
+ if (ll_proto_a2n(&vlan_eth_type, str))
+ invarg("invalid vlan_ethtype", str);
+ addattr16(n, MAX_MSG, type, vlan_eth_type);
+ *p_vlan_eth_type = vlan_eth_type;
+ return 0;
+}
+
static int flower_parse_ip_proto(char *str, __be16 eth_type, int type,
__u8 *p_ip_proto, struct nlmsghdr *n)
{
@@ -167,6 +188,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
struct tcmsg *t = NLMSG_DATA(n);
struct rtattr *tail;
__be16 eth_type = TC_H_MIN(t->tcm_info);
+ __be16 vlan_ethtype = 0;
__u8 ip_proto = 0xff;
__u32 flags = 0;
@@ -208,6 +230,41 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
NEXT_ARG();
strncpy(ifname, *argv, sizeof(ifname) - 1);
addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, ifname);
+ } else if (matches(*argv, "vlan_id") == 0) {
+ __u16 vid;
+
+ NEXT_ARG();
+ if (eth_type != htons(ETH_P_8021Q)) {
+ fprintf(stderr, "Can't set \"vlan_id\" if ethertype isn't 802.1Q\n");
+ return -1;
+ }
+ ret = get_u16(&vid, *argv, 10);
+ if (ret < 0 || vid & ~0xfff) {
+ fprintf(stderr, "Illegal \"vlan_id\"\n");
+ return -1;
+ }
+ addattr16(n, MAX_MSG, TCA_FLOWER_KEY_VLAN_ID, vid);
+ } else if (matches(*argv, "vlan_prio") == 0) {
+ __u8 vlan_prio;
+
+ NEXT_ARG();
+ if (eth_type != htons(ETH_P_8021Q)) {
+ fprintf(stderr, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q\n");
+ return -1;
+ }
+ ret = get_u8(&vlan_prio, *argv, 10);
+ if (ret < 0 || vlan_prio & ~0x7) {
+ fprintf(stderr, "Illegal \"vlan_prio\"\n");
+ return -1;
+ }
+ addattr8(n, MAX_MSG, TCA_FLOWER_KEY_VLAN_PRIO, vlan_prio);
+ } else if (matches(*argv, "vlan_ethtype") == 0) {
+ NEXT_ARG();
+ ret = flower_parse_vlan_eth_type(*argv, eth_type,
+ TCA_FLOWER_KEY_VLAN_ETH_TYPE,
+ &vlan_ethtype, n);
+ if (ret < 0)
+ return -1;
} else if (matches(*argv, "dst_mac") == 0) {
NEXT_ARG();
ret = flower_parse_eth_addr(*argv,
@@ -230,7 +287,8 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
}
} else if (matches(*argv, "ip_proto") == 0) {
NEXT_ARG();
- ret = flower_parse_ip_proto(*argv, eth_type,
+ ret = flower_parse_ip_proto(*argv, vlan_ethtype ?
+ vlan_ethtype : eth_type,
TCA_FLOWER_KEY_IP_PROTO,
&ip_proto, n);
if (ret < 0) {
@@ -239,7 +297,8 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
}
} else if (matches(*argv, "dst_ip") == 0) {
NEXT_ARG();
- ret = flower_parse_ip_addr(*argv, eth_type,
+ ret = flower_parse_ip_addr(*argv, vlan_ethtype ?
+ vlan_ethtype : eth_type,
TCA_FLOWER_KEY_IPV4_DST,
TCA_FLOWER_KEY_IPV4_DST_MASK,
TCA_FLOWER_KEY_IPV6_DST,
@@ -251,7 +310,8 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
}
} else if (matches(*argv, "src_ip") == 0) {
NEXT_ARG();
- ret = flower_parse_ip_addr(*argv, eth_type,
+ ret = flower_parse_ip_addr(*argv, vlan_ethtype ?
+ vlan_ethtype : eth_type,
TCA_FLOWER_KEY_IPV4_SRC,
TCA_FLOWER_KEY_IPV4_SRC_MASK,
TCA_FLOWER_KEY_IPV6_SRC,
@@ -477,6 +537,18 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
fprintf(f, "\n indev %s", rta_getattr_str(attr));
}
+ if (tb[TCA_FLOWER_KEY_VLAN_ID]) {
+ struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ID];
+
+ fprintf(f, "\n vlan_id %d", rta_getattr_u16(attr));
+ }
+
+ if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) {
+ struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_PRIO];
+
+ fprintf(f, "\n vlan_prio %d", rta_getattr_u8(attr));
+ }
+
flower_print_eth_addr(f, "dst_mac", tb[TCA_FLOWER_KEY_ETH_DST],
tb[TCA_FLOWER_KEY_ETH_DST_MASK]);
flower_print_eth_addr(f, "src_mac", tb[TCA_FLOWER_KEY_ETH_SRC],
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH iproute2 V2 2/2] tc: m_vlan: Add priority option to push vlan action
2016-09-01 6:45 [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support Hadar Hen Zion
2016-09-01 6:45 ` [PATCH iproute2 V2 1/2] tc: flower: Introduce vlan support Hadar Hen Zion
@ 2016-09-01 6:45 ` Hadar Hen Zion
2016-09-01 15:40 ` [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Hadar Hen Zion @ 2016-09-01 6:45 UTC (permalink / raw)
To: Stephen Hemminger
Cc: netdev, David S. Miller, Jiri Pirko, Or Gerlitz, Amir Vadai,
Hadar Hen Zion
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>
---
man/man8/tc-vlan.8 | 5 +++++
tc/m_vlan.c | 22 +++++++++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/man/man8/tc-vlan.8 b/man/man8/tc-vlan.8
index 4bfd72b..4d0c5c8 100644
--- a/man/man8/tc-vlan.8
+++ b/man/man8/tc-vlan.8
@@ -12,6 +12,8 @@ vlan - vlan manipulation module
.IR PUSH " := "
.BR push " [ " protocol
.IR VLANPROTO " ]"
+.BR " [ " priority
+.IR VLANPRIO " ] "
.BI id " VLANID"
.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
.BR 802.1Q " or " 802.1ad .
.TP
+.BI priority " VLANPRIO"
+Choose the VLAN priority to use. Decimal number in range of 0-7.
+.TP
.I CONTROL
How to continue after executing this action.
.RS
diff --git a/tc/m_vlan.c b/tc/m_vlan.c
index ac63d9e..05a63b4 100644
--- a/tc/m_vlan.c
+++ b/tc/m_vlan.c
@@ -22,7 +22,7 @@
static void explain(void)
{
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, " with default: 802.1Q\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;
__u16 proto;
int proto_set = 0;
+ __u8 prio;
+ int prio_set = 0;
struct tc_vlan parm = { 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))
invarg("protocol is invalid", *argv);
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) {
usage();
} 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);
}
+ if (prio_set)
+ addattr8(n, MAX_MSG, TCA_VLAN_PUSH_VLAN_PRIORITY, prio);
+
tail->rta_len = (char *)NLMSG_TAIL(n) - (char *)tail;
*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]),
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;
}
fprintf(f, " %s", action_n2a(parm->action));
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support
2016-09-01 6:45 [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support Hadar Hen Zion
2016-09-01 6:45 ` [PATCH iproute2 V2 1/2] tc: flower: Introduce vlan support Hadar Hen Zion
2016-09-01 6:45 ` [PATCH iproute2 V2 2/2] tc: m_vlan: Add priority option to push vlan action Hadar Hen Zion
@ 2016-09-01 15:40 ` Stephen Hemminger
2 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2016-09-01 15:40 UTC (permalink / raw)
To: Hadar Hen Zion
Cc: netdev, David S. Miller, Jiri Pirko, Or Gerlitz, Amir Vadai
On Thu, 1 Sep 2016 09:45:46 +0300
Hadar Hen Zion <hadarh@mellanox.com> wrote:
> Hi,
>
> This patchset introduce vlan tag support to the tc flower classifier.
> In addition to adding vlan priority to vlan push action.
>
> - The first patch adds classification according to vlan id and vlan priority to the flower.
> - The second patch adds support for vlan priority to the current vlan push action.
>
> Changes from v1:
> - Remove VLAN_PRIO_MASK and VLAN_VID_MASK defines from tc_vlan.h file
>
>
> Hadar Hen Zion (2):
> tc: flower: Introduce vlan support
> tc: m_vlan: Add priority option to push vlan action
>
> man/man8/tc-flower.8 | 25 ++++++++++++++++-
> man/man8/tc-vlan.8 | 5 ++++
> tc/f_flower.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++--
> tc/m_vlan.c | 22 ++++++++++++++-
> 4 files changed, 125 insertions(+), 5 deletions(-)
>
Applied to net-next
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-09-01 15:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-01 6:45 [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support Hadar Hen Zion
2016-09-01 6:45 ` [PATCH iproute2 V2 1/2] tc: flower: Introduce vlan support Hadar Hen Zion
2016-09-01 6:45 ` [PATCH iproute2 V2 2/2] tc: m_vlan: Add priority option to push vlan action Hadar Hen Zion
2016-09-01 15:40 ` [PATCH iproute2 V2 0/2] tc: flower, m_vlan: Introduce vlan tag support Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).