Add support for 8021.AD frame matching
Florian Westphal
maintainercover Add support for 8021.AD frame matching
This allows to match vlan frames with 8021.AD ("QinQ") type.
Plan 'vlan id 1' will imply 8021Q, just as before, so explicit type specification is needed.
This in turn makes it necessary to extend dependency removal so that it will not auto-remove 8021ad check.
Add test case to make sure depdenencies are generated correctly, this includes checks for 'vlan id 2' in a 'vlan id 1' vlan tag stack.
Florian Westphal (4):
src: vlan: allow matching vlan id insider 802.1ad frame
proto: add 8021ad as mnemonic for IEEE 802.1AD (0x88a8) ether type
payload: be careful on vlan dependency removal
tests: add 8021.AD vlan test cases
src/payload.c | 29 ++++- src/proto.c | 4 + src/scanner.l | 1 + tests/py/bridge/vlan.t | 5 + tests/py/bridge/vlan.t.json | 176 ++++++++++++++++++++++++++ tests/py/bridge/vlan.t.json.output | 173 +++++++++++++++++++++++++ tests/py/bridge/vlan.t.payload | 45 +++++++ tests/py/bridge/vlan.t.payload.netdev | 51 ++++++++ 8 files changed, 481 insertions(+), 3 deletions(-)
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH 1/4 src: vlan: allow matching vlan id insider 802.1ad frame
This makes "ether type 0x88a8 vlan id 342" work.
Before this change, nft would still insert a dependency on 802.1q so the rule would never match.
--- src/proto.c | 3 +++ 1 file changed, 3 insertions(+)
src/proto.c +3 -0
@@ -1027,6 +1027,7 @@ const struct proto_desc proto_vlan = {PROTO_LINK (__constant_htons (ETH_P_ARP ), &proto_arp),PROTO_LINK (__constant_htons (ETH_P_IPV6 ), &proto_ip6),PROTO_LINK (__constant_htons (ETH_P_8021Q ), &proto_vlan), +PROTO_LINK (__constant_htons (ETH_P_8021AD ), &proto_vlan), }, .templates = {
@@ -1099,6 +1100,7 @@ const struct proto_desc proto_eth = {PROTO_LINK (__constant_htons (ETH_P_ARP ), &proto_arp),PROTO_LINK (__constant_htons (ETH_P_IPV6 ), &proto_ip6),PROTO_LINK (__constant_htons (ETH_P_8021Q ), &proto_vlan), + PROTO_LINK(__constant_htons(ETH_P_8021AD), &proto_vlan), }, .templates = { [ETHHDR_DADDR] = ETHHDR_ADDR("daddr", ether_dhost),
@@ -1124,6 +1126,7 @@ const struct proto_desc proto_netdev = {PROTO_LINK (__constant_htons (ETH_P_ARP ), &proto_arp),PROTO_LINK (__constant_htons (ETH_P_IPV6 ), &proto_ip6),PROTO_LINK (__constant_htons (ETH_P_8021Q ), &proto_vlan), + PROTO_LINK(__constant_htons(ETH_P_8021AD), &proto_vlan), }, .templates = { [0] = PROTO_META_TEMPLATE("protocol", ðertype_type, NFT_META_PROTOCOL, 16),
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH 2/4 proto: add 8021ad as mnemonic for IEEE 802.1AD (0x88a8) ether type
In reply to Florian Westphal--- src/proto.c | 1 + src/scanner.l | 1 + 2 files changed, 2 insertions(+)
src/proto.c +1 -0
@@ -1058,6 +1058,7 @@ static const struct symbol_table ethertype_tbl = { SYMBOL("arp", __constant_htons(ETH_P_ARP)), SYMBOL("ip6", __constant_htons(ETH_P_IPV6)), SYMBOL("vlan", __constant_htons(ETH_P_8021Q)), + SYMBOL("8021ad", __constant_htons(ETH_P_8021AD)),SYMBOL_LIST_END }, };
src/scanner.l +1 -0
@@ -422,6 +422,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "cfi" { return CFI; } "pcp" { return PCP; } } +"8021ad" { yylval->string = xstrdup(yytext); return STRING; } "arp" { scanner_push_start_cond(yyscanner, SCANSTATE_ARP); return ARP; } <SCANSTATE_ARP>{
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH 3/4 payload: be careful on vlan dependency removal
In reply to Florian Westphal'vlan ...' implies 8021Q frame. In case the expression tests something else (802.1AD for example) its not an implictly added one, so keep it.
--- src/payload.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
src/payload.c +26 -3
@@ -661,6 +661,24 @@ static bool payload_may_dependency_kill_icmp(struct payload_dep_ctx *ctx, structreturn ctx->icmp_type == icmp_type; } +static bool payload_may_dependency_kill_ll (struct payload_dep_ctx *ctx,struct expr *expr) +{ +const struct expr *dep = ctx->pdep->expr; + +/* Never remove a 'vlan type 0x...' expression, they are never added implicitly */ +if (dep->left->payload.desc == &proto_vlan) +return false; + +/* 'vlan id 2' implies 'ether type 8021Q'. If a different protocol is +* tested, this is not a redundant expression. +*/ +if (dep->left->payload.desc == &proto_eth && + dep->right->etype ==EXPR_VALUE && dep->right->len ==16 ) +return mpz_get_uint16 (dep->right->value) ==ETH_P_8021Q ; + +return true; +} +static bool payload_may_dependency_kill (struct payload_dep_ctx *ctx,unsigned int family,struct expr *expr) {
@@ -689,9 +707,14 @@ static bool payload_may_dependency_kill(struct payload_dep_ctx *ctx,* for stacked protocols if we only have protcol type matches. */ if (dep->left->etype ==EXPR_PAYLOAD && dep->op ==OP_EQ && - expr->flags &EXPR_F_PROTOCOL && - expr->payload.base == dep->left->payload.base) -return false; + expr->payload.base == dep->left->payload.base) { +if (expr->flags &EXPR_F_PROTOCOL ) +return false; + +if (expr->payload.base ==PROTO_BASE_LL_HDR ) +return payload_may_dependency_kill_ll (ctx, expr); + } +break ; }
Signature · 1 line
2.26.3
Florian Westphal
maintainerPATCH 4/4 tests: add 8021.AD vlan test cases
In reply to Florian WestphalCheck nft doesn't remove the explicit '8021ad' type check and that the expected dependency chains are generated.
--- tests/py/bridge/vlan.t | 5 + tests/py/bridge/vlan.t.json | 176 ++++++++++++++++++++++++++ tests/py/bridge/vlan.t.json.output | 173 +++++++++++++++++++++++++ tests/py/bridge/vlan.t.payload | 45 +++++++ tests/py/bridge/vlan.t.payload.netdev | 51 ++++++++ 5 files changed, 450 insertions(+)
tests/py/bridge/vlan.t +5 -0
@@ -34,6 +34,11 @@ vlan id { 1, 2, 4, 100, 4096 };fail ether type vlan ip protocol 1 accept;ok +# IEEE 802.1AD +ether type 8021ad vlan id 1 ip protocol 6 accept;ok +ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip counter;ok +ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip ip protocol 6;ok;ether type 8021ad vlan id 1 vlan type vlan vlan id 2 ip protocol 6 + # illegal dependencies ether type ip vlan id 1;fail ether type ip vlan id 1 ip saddr 10.0.0.1;fail
tests/py/bridge/vlan.t.json +176 -0
179 lines not on this page · raw message
tests/py/bridge/vlan.t.json.output +173 -0
176 lines not on this page · raw message
tests/py/bridge/vlan.t.payload +45 -0
48 lines not on this page · raw message
tests/py/bridge/vlan.t.payload.netdev +51 -0
54 lines not on this page · raw message
Signature · 1 line
2.26.3
Florian Westphal
maintainer[PATCH nft 5/4] proto: replace vlan ether type with 8021q
In reply to Florian WestphalPrevious patches added "8021ad" mnemonic for IEEE 802.1AD frame type. This adds the 8021q shorthand for the existing 'vlan' frame type.
nft will continue to recognize 'ether type vlan', but listing will now print 8021q.
Adjust all test cases accordingly.
--- src/proto.c | 5 ++++- src/scanner.l | 1 + tests/py/any/meta.t | 4 ++-- tests/py/any/meta.t.json | 4 ++-- tests/py/any/meta.t.json.output | 6 +++--- tests/py/any/meta.t.payload | 2 +- tests/py/bridge/meta.t | 2 +- tests/py/bridge/meta.t.json | 2 +- tests/py/bridge/reject.t | 6 +++--- tests/py/bridge/reject.t.json | 6 +++--- tests/py/bridge/reject.t.json.output | 3 +-- tests/py/bridge/reject.t.payload | 2 +- tests/py/bridge/vlan.t | 6 +++--- tests/py/bridge/vlan.t.json | 8 ++++---- tests/py/bridge/vlan.t.json.output | 10 +++++----- tests/py/bridge/vlan.t.payload | 4 ++-- tests/py/bridge/vlan.t.payload.netdev | 4 ++-- 17 files changed, 39 insertions(+), 36 deletions(-)
src/proto.c +4 -1
@@ -1057,8 +1057,11 @@ static const struct symbol_table ethertype_tbl = { SYMBOL("ip", __constant_htons(ETH_P_IP)), SYMBOL("arp", __constant_htons(ETH_P_ARP)), SYMBOL("ip6", __constant_htons(ETH_P_IPV6)), - SYMBOL("vlan", __constant_htons(ETH_P_8021Q)), + SYMBOL("8021q", __constant_htons(ETH_P_8021Q)), SYMBOL("8021ad", __constant_htons(ETH_P_8021AD)), + +/* for compatibility with older versions */ + SYMBOL("vlan", __constant_htons(ETH_P_8021Q)),SYMBOL_LIST_END }, };
src/scanner.l +1 -0
@@ -423,6 +423,7 @@ addrstring ({macaddr}|{ip4addr}|{ip6addr}) "pcp" { return PCP; } } "8021ad" { yylval->string = xstrdup(yytext); return STRING; } +"8021q" { yylval->string = xstrdup(yytext); return STRING; } "arp" { scanner_push_start_cond(yyscanner, SCANSTATE_ARP); return ARP; } <SCANSTATE_ARP>{
tests/py/any/meta.t +2 -2
@@ -20,8 +20,8 @@ meta length != { 33, 55, 67, 88};ok meta length { 33-55, 66-88};ok meta length != { 33-55, 66-88};ok -meta protocol { ip, arp, ip6, vlan };ok;meta protocol { ip6, ip, vlan, arp} -meta protocol != {ip, arp, ip6, vlan};ok +meta protocol { ip, arp, ip6, vlan };ok;meta protocol { ip6, ip, 8021q, arp} +meta protocol != {ip, arp, ip6, 8021q};ok meta protocol ip;ok meta protocol != ip;ok
tests/py/any/meta.t.json +2 -2
@@ -199,7 +199,7 @@ } ] -# meta protocol != {ip, arp, ip6, vlan} +# meta protocol != {ip, arp, ip6, 8021q} [ { "match": {
@@ -212,7 +212,7 @@ "ip", "arp", "ip6", - "vlan" + "8021q" ] } }
tests/py/any/meta.t.json.output +3 -3
@@ -10,7 +10,7 @@ "set": [ "ip", "arp", - "vlan", + "8021q", "ip6" ] }
@@ -18,7 +18,7 @@ } ] -# meta protocol != {ip, arp, ip6, vlan} +# meta protocol != {ip, arp, ip6, 8021q} [ { "match": {
@@ -30,7 +30,7 @@ "set": [ "ip", "arp", - "vlan", + "8021q", "ip6" ] }
tests/py/any/meta.t.payload +1 -1
@@ -68,7 +68,7 @@ ip test-ip4 input [ meta load protocol => reg 1 ] [ lookup reg 1 set __set%d ] -# meta protocol != {ip, arp, ip6, vlan} +# meta protocol != {ip, arp, ip6, 8021q} __set%d test-ip4 3 __set%d test-ip4 0 element 00000008 : 0 [end] element 00000608 : 0 [end] element 0000dd86 : 0 [end] element 00000081 : 0 [end]
tests/py/bridge/meta.t +1 -1
@@ -4,5 +4,5 @@ meta obrname "br0";ok meta ibrname "br0";ok -meta ibrvproto vlan;ok +meta ibrvproto vlan;ok;meta ibrvproto 8021q meta ibrpvid 100;ok
tests/py/bridge/meta.t.json +1 -1
@@ -32,7 +32,7 @@ "meta": { "key": "ibrvproto" } }, "op": "==", - "right": "vlan" + "right": "8021q" } } ]
tests/py/bridge/reject.t +3 -3
@@ -30,13 +30,13 @@ reject with icmpx type port-unreachable;ok;reject ether type ipv6 reject with icmp type host-unreachable;fail ether type ip6 reject with icmp type host-unreachable;fail ether type ip reject with icmpv6 type no-route;fail -ether type vlan reject;ok +ether type vlan reject;ok;ether type 8021q reject ether type arp reject;fail -ether type vlan reject with tcp reset;ok;meta l4proto 6 ether type vlan reject with tcp reset +ether type vlan reject with tcp reset;ok;meta l4proto 6 ether type 8021q reject with tcp reset ether type arp reject with tcp reset;fail ip protocol udp reject with tcp reset;fail ether type ip reject with icmpx type admin-prohibited;ok ether type ip6 reject with icmpx type admin-prohibited;ok -ether type vlan reject with icmpx type admin-prohibited;ok +ether type 8021q reject with icmpx type admin-prohibited;ok ether type arp reject with icmpx type admin-prohibited;fail
tests/py/bridge/reject.t.json +3 -3
@@ -289,7 +289,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
@@ -318,7 +318,7 @@ } ] -# ether type vlan reject with icmpx type admin-prohibited +# ether type 8021q reject with icmpx type admin-prohibited [ { "match": {
@@ -329,7 +329,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
tests/py/bridge/reject.t.json.output +1 -2
@@ -71,7 +71,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
@@ -81,4 +81,3 @@ } } ] -
tests/py/bridge/reject.t.payload +1 -1
@@ -132,7 +132,7 @@ bridge [ cmp eq reg 1 0x00000081 ] [ reject type 1 code 0 ] -# ether type vlan reject with icmpx type admin-prohibited +# ether type 8021q reject with icmpx type admin-prohibited bridge [ payload load 2b @ link header + 12 => reg 1 ] [ cmp eq reg 1 0x00000081 ]
tests/py/bridge/vlan.t +3 -3
@@ -32,12 +32,12 @@ ether type vlan vlan id 1 ip saddr 10.0.0.0/23 udp dport 53;ok;vlan id 1 ip sadd vlan id { 1, 2, 4, 100, 4095 } vlan pcp 1-3;ok vlan id { 1, 2, 4, 100, 4096 };fail -ether type vlan ip protocol 1 accept;ok +ether type vlan ip protocol 1 accept;ok;ether type 8021q ip protocol 1 accept # IEEE 802.1AD ether type 8021ad vlan id 1 ip protocol 6 accept;ok -ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip counter;ok -ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip ip protocol 6;ok;ether type 8021ad vlan id 1 vlan type vlan vlan id 2 ip protocol 6 +ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip counter;ok +ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip ip protocol 6;ok;ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 ip protocol 6 # illegal dependencies ether type ip vlan id 1;fail
tests/py/bridge/vlan.t.json +4 -4
@@ -573,7 +573,7 @@ } ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip counter +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip counter [ { "match": {
@@ -608,7 +608,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
@@ -643,7 +643,7 @@ } ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip ip protocol 6 +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip ip protocol 6 [ { "match": {
@@ -678,7 +678,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
tests/py/bridge/vlan.t.json.output +5 -5
@@ -9,7 +9,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
@@ -72,7 +72,7 @@ } ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip counter +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip counter [ { "match": {
@@ -107,7 +107,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
@@ -139,7 +139,7 @@ } ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip ip protocol 6 +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip ip protocol 6 [ { "match": {
@@ -174,7 +174,7 @@ } }, "op": "==", - "right": "vlan" + "right": "8021q" } }, {
tests/py/bridge/vlan.t.payload +2 -2
@@ -222,7 +222,7 @@ bridge [ cmp eq reg 1 0x00000006 ] [ immediate reg 0 accept ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip counter +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip counter bridge [ payload load 2b @ link header + 12 => reg 1 ] [ cmp eq reg 1 0x0000a888 ]
@@ -238,7 +238,7 @@ bridge [ cmp eq reg 1 0x00000008 ] [ counter pkts 0 bytes 0 ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip ip protocol 6 +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip ip protocol 6 bridge [ payload load 2b @ link header + 12 => reg 1 ] [ cmp eq reg 1 0x0000a888 ]
tests/py/bridge/vlan.t.payload.netdev +2 -2
@@ -260,7 +260,7 @@ netdev [ cmp eq reg 1 0x00000006 ] [ immediate reg 0 accept ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip counter +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip counter netdev [ meta load iiftype => reg 1 ] [ cmp eq reg 1 0x00000001 ]
@@ -278,7 +278,7 @@ netdev [ cmp eq reg 1 0x00000008 ] [ counter pkts 0 bytes 0 ] -# ether type 8021ad vlan id 1 vlan type vlan vlan id 2 vlan type ip ip protocol 6 +# ether type 8021ad vlan id 1 vlan type 8021q vlan id 2 vlan type ip ip protocol 6 netdev [ meta load iiftype => reg 1 ] [ cmp eq reg 1 0x00000001 ]
Signature · 1 line
2.26.3