aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@kernel.org>2022-04-27 20:18:25 -0600
committerDavid Ahern <dsahern@kernel.org>2022-04-27 20:18:25 -0600
commitb4f805547786fc2ba3a98a604c3cbdc5b99e08bd (patch)
tree1d776fb06cb84b6f1ef4d452a6cd0f92e51ef2c0
parent39888ed09935661a453f9c02244d5fd44da8e317 (diff)
parent5788732e380caede5381af0bc0e0a3cd94c7b92a (diff)
downloadiproute2-b4f805547786fc2ba3a98a604c3cbdc5b99e08bd.tar.gz
Merge branch 'flower-vlans' into next
Boris Sukholitko says: ==================== Our customers in the fiber telecom world have network configurations where they would like to control their traffic according to the number of tags appearing in the packet. For example, TR247 GPON conformance test suite specification mostly talks about untagged, single, double tagged packets and gives lax guidelines on the vlan protocol vs. number of vlan tags. This is different from the common IT networks where 802.1Q and 802.1ad protocols are usually describe single and double tagged packet. GPON configurations that we work with have arbitrary mix the above protocols and number of vlan tags in the packet. The following patch series implement number of vlans flower filter. They add num_of_vlans flower filter as an alternative to vlan ethtype protocol matching. The end result is that the following command becomes possible: tc filter add dev eth1 ingress flower \ num_of_vlans 1 vlan_prio 5 action drop Also, from our logs, we have redirect rules such that: tc filter add dev $GPON ingress flower num_of_vlans $N \ action mirred egress redirect dev $DEV where N can range from 0 to 3 and $DEV is the function of $N. Also there are rules setting skb mark based on the number of vlans: tc filter add dev $GPON ingress flower num_of_vlans $N vlan_prio \ $P action skbedit mark $M ==================== Signed-off-by: David Ahern <dsahern@kernel.org>
-rw-r--r--tc/f_flower.c57
1 files changed, 41 insertions, 16 deletions
diff --git a/tc/f_flower.c b/tc/f_flower.c
index 686cf1214..805ca6718 100644
--- a/tc/f_flower.c
+++ b/tc/f_flower.c
@@ -48,6 +48,7 @@ static void explain(void)
"\n"
"Where: MATCH-LIST := [ MATCH-LIST ] MATCH\n"
" MATCH := { indev DEV-NAME |\n"
+ " num_of_vlans VLANS_COUNT |\n"
" vlan_id VID |\n"
" vlan_prio PRIORITY |\n"
" vlan_ethtype [ ipv4 | ipv6 | ETH-TYPE ] |\n"
@@ -159,21 +160,23 @@ err:
return err;
}
-static bool eth_type_vlan(__be16 ethertype)
+static bool eth_type_vlan(__be16 ethertype, bool good_num_of_vlans)
{
return ethertype == htons(ETH_P_8021Q) ||
- ethertype == htons(ETH_P_8021AD);
+ ethertype == htons(ETH_P_8021AD) ||
+ good_num_of_vlans;
}
static int flower_parse_vlan_eth_type(char *str, __be16 eth_type, int type,
__be16 *p_vlan_eth_type,
- struct nlmsghdr *n)
+ struct nlmsghdr *n, bool good_num_of_vlans)
{
__be16 vlan_eth_type;
- if (!eth_type_vlan(eth_type)) {
- fprintf(stderr, "Can't set \"%s\" if ethertype isn't 802.1Q or 802.1AD\n",
- type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "vlan_ethtype" : "cvlan_ethtype");
+ if (!eth_type_vlan(eth_type, good_num_of_vlans)) {
+ fprintf(stderr, "Can't set \"%s\" if ethertype isn't 802.1Q or 802.1AD and num_of_vlans %s\n",
+ type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "vlan_ethtype" : "cvlan_ethtype",
+ type == TCA_FLOWER_KEY_VLAN_ETH_TYPE ? "is 0" : "less than 2");
return -1;
}
@@ -1424,6 +1427,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
__be16 tc_proto = TC_H_MIN(t->tcm_info);
__be16 eth_type = tc_proto;
__be16 vlan_ethtype = 0;
+ __u8 num_of_vlans = 0;
__u8 ip_proto = 0xff;
__u32 flags = 0;
__u32 mtf = 0;
@@ -1525,12 +1529,22 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
if (check_ifname(*argv))
invarg("\"indev\" not a valid ifname", *argv);
addattrstrz(n, MAX_MSG, TCA_FLOWER_INDEV, *argv);
+ } else if (strcmp(*argv, "num_of_vlans") == 0) {
+ NEXT_ARG();
+ ret = get_u8(&num_of_vlans, *argv, 10);
+ if (ret < 0) {
+ fprintf(stderr, "Illegal \"num_of_vlans\"\n");
+ return -1;
+ }
+ addattr8(n, MAX_MSG,
+ TCA_FLOWER_KEY_NUM_OF_VLANS, num_of_vlans);
} else if (matches(*argv, "vlan_id") == 0) {
__u16 vid;
NEXT_ARG();
- if (!eth_type_vlan(tc_proto)) {
- fprintf(stderr, "Can't set \"vlan_id\" if ethertype isn't 802.1Q or 802.1AD\n");
+ if (!eth_type_vlan(tc_proto, num_of_vlans > 0)) {
+ fprintf(stderr, "Can't set \"vlan_id\" if ethertype isn't 802.1Q or 802.1AD"
+ " and num_of_vlans is 0\n");
return -1;
}
ret = get_u16(&vid, *argv, 10);
@@ -1543,8 +1557,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
__u8 vlan_prio;
NEXT_ARG();
- if (!eth_type_vlan(tc_proto)) {
- fprintf(stderr, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q or 802.1AD\n");
+ if (!eth_type_vlan(tc_proto, num_of_vlans > 0)) {
+ fprintf(stderr, "Can't set \"vlan_prio\" if ethertype isn't 802.1Q or 802.1AD"
+ " and num_of_vlans is 0\n");
return -1;
}
ret = get_u8(&vlan_prio, *argv, 10);
@@ -1558,7 +1573,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
NEXT_ARG();
ret = flower_parse_vlan_eth_type(*argv, eth_type,
TCA_FLOWER_KEY_VLAN_ETH_TYPE,
- &vlan_ethtype, n);
+ &vlan_ethtype, n, num_of_vlans > 0);
if (ret < 0)
return -1;
/* get new ethtype for later parsing */
@@ -1567,8 +1582,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
__u16 vid;
NEXT_ARG();
- if (!eth_type_vlan(vlan_ethtype)) {
- fprintf(stderr, "Can't set \"cvlan_id\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n");
+ if (!eth_type_vlan(vlan_ethtype, num_of_vlans > 1)) {
+ fprintf(stderr, "Can't set \"cvlan_id\" if inner vlan ethertype isn't 802.1Q or 802.1AD"
+ " and num_of_vlans is less than 2\n");
return -1;
}
ret = get_u16(&vid, *argv, 10);
@@ -1581,8 +1597,9 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
__u8 cvlan_prio;
NEXT_ARG();
- if (!eth_type_vlan(vlan_ethtype)) {
- fprintf(stderr, "Can't set \"cvlan_prio\" if inner vlan ethertype isn't 802.1Q or 802.1AD\n");
+ if (!eth_type_vlan(vlan_ethtype, num_of_vlans > 1)) {
+ fprintf(stderr, "Can't set \"cvlan_prio\" if inner vlan ethertype isn't 802.1Q or 802.1AD"
+ " and num_of_vlans is less than 2\n");
return -1;
}
ret = get_u8(&cvlan_prio, *argv, 10);
@@ -1597,7 +1614,7 @@ static int flower_parse_opt(struct filter_util *qu, char *handle,
/* get new ethtype for later parsing */
ret = flower_parse_vlan_eth_type(*argv, vlan_ethtype,
TCA_FLOWER_KEY_CVLAN_ETH_TYPE,
- &eth_type, n);
+ &eth_type, n, num_of_vlans > 1);
if (ret < 0)
return -1;
} else if (matches(*argv, "mpls") == 0) {
@@ -2694,6 +2711,14 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
open_json_object("keys");
+ if (tb[TCA_FLOWER_KEY_NUM_OF_VLANS]) {
+ struct rtattr *attr = tb[TCA_FLOWER_KEY_NUM_OF_VLANS];
+
+ print_nl();
+ print_uint(PRINT_ANY, "num_of_vlans", " num_of_vlans %d",
+ rta_getattr_u8(attr));
+ }
+
if (tb[TCA_FLOWER_KEY_VLAN_ID]) {
struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ID];