vlan support updates
Pablo Neira Ayuso
maintainercover vlan support updates
Hi,
The following batch contains new vlan tests and one bugfix.
While working on the kernel fixes for nft_payload vlan mangling I found one issue with vlan matching regarding bogus protocol conflicts.
Pablo Neira Ayuso (3):
evaluate: bogus protocol conflicts in vlan with implicit dependencies
tests: shell: add vlan double tagging match simple test case
tests: shell: add vlan mangling test case
src/evaluate.c | 69 ++++++++++++++--- .../packetpath/dumps/vlan_qinq.nodump | 0 .../shell/testcases/packetpath/vlan_mangling | 75 +++++++++++++++++++ tests/shell/testcases/packetpath/vlan_qinq | 52 +++++++++++++ 4 files changed, 184 insertions(+), 12 deletions(-) create mode 100644 tests/shell/testcases/packetpath/dumps/vlan_qinq.nodump create mode 100755 tests/shell/testcases/packetpath/vlan_mangling create mode 100755 tests/shell/testcases/packetpath/vlan_qinq
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 1/3 evaluate: bogus protocol conflicts in vlan with implicit dependencies
The following command:
# nft add rule netdev x y ip saddr 10.1.1.1 icmp type echo-request vlan id set 321
fails with:
Error: conflicting link layer protocols specified: ether vs. vlan netdev x y ip saddr 10.1.1.1 icmp type echo-request vlan id set 321
^^^^^^^
which is triggered by the follow check in resolve_ll_protocol_conflict():
/* This payload and the existing context don't match, conflict. */
if (pctx->protocol[base + 1].desc != NULL)
return 1;This check was added by 39f15c243912 ("nft: support listing expressions that use non-byte header fields") and f7d5590688a6 ("tests: vlan tests") to deal with vlan support to deal with conflicting link layer protocols:
ether type ip vlan id 1
One possibility is to removing such check, but nft does not bail out and it results in bytecode that never matches:
# nft --debug=netlink netdev x y ether type ip vlan id 10 netdev x y [ meta load iiftype => reg 1 ] [ cmp eq reg 1 0x00000001 ] [ payload load 2b @ link header + 12 => reg 1 ] <---- ether type [ cmp eq reg 1 0x00000008 ] <---- ip [ payload load 2b @ link header + 12 => reg 1 ] <---- ether type [ cmp eq reg 1 0x00000081 ] <---- vlan [ payload load 2b @ link header + 14 => reg 1 ] [ bitwise reg 1 = ( reg 1 & 0x0000ff0f ) ^ 0x00000000 ] [ cmp eq reg 1 0x00000a00 ]
This is due to resolve_ll_protocol_conflict() which deals with the conflict by updating protocol context and emitting an implicit dependency, but there is already an explicit match coming from the user.
The workaround to make this work is to prepend an explicit match for vlan ethertype field, that is:
ether type vlan ip saddr 10.1.1.1 ...
^-------------^This patch adds a new helper function to check if an implicit dependency clashes with an existing statement:
# nft add rule netdev x y ether type ip vlan id 1
Error: conflicting statements
add rule netdev x y ether type ip vlan id 1
^^^^^^^^^^^^^ ~~~~~~~Theoretically, no duplicated implicit dependency should ever be emitted if protocol context is correctly handled.
Only implicit payload expression are considered at this stage, this patch can be extended to deal with other dependency types.
--- src/evaluate.c | 69 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 12 deletions(-)
src/evaluate.c +57 -12
@@ -775,6 +775,46 @@ static bool proto_is_dummy(const struct proto_desc *desc)return desc == &proto_inet || desc == &proto_netdev; } +static int stmt_dep_conflict (struct eval_ctx *ctx,const struct stmt *nstmt) +{ +struct stmt *stmt; + +list_for_each_entry (stmt, &ctx->rule->stmts, list) { +if (stmt == nstmt) +break ; + +if (stmt->ops->type !=STMT_EXPRESSION || + stmt->expr->etype !=EXPR_RELATIONAL || + stmt->expr->right->etype !=EXPR_VALUE || + stmt->expr->left->etype !=EXPR_PAYLOAD || + stmt->expr->left->etype != nstmt->expr->left->etype || + stmt->expr->left->len != nstmt->expr->left->len) +continue ; + +if (stmt->expr->left->payload.desc != nstmt->expr->left->payload.desc || + stmt->expr->left->payload.inner_desc != nstmt->expr->left->payload.inner_desc || + stmt->expr->left->payload.base != nstmt->expr->left->payload.base || + stmt->expr->left->payload.offset != nstmt->expr->left->payload.offset) +continue ; + +return stmt_binary_error (ctx, stmt, nstmt, +"conflicting statements" ); + } + +return 0 ; +} + +static int rule_stmt_dep_add (struct eval_ctx *ctx, +struct stmt *nstmt,struct stmt *stmt) +{ +rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); + +if (stmt_dep_conflict (ctx, nstmt) <0 ) +return -1 ; + +return 0 ; +} +static int resolve_ll_protocol_conflict (struct eval_ctx *ctx,const struct proto_desc *desc,struct expr *payload)
@@ -798,7 +838,8 @@ static int resolve_ll_protocol_conflict(struct eval_ctx *ctx,return err; desc = payload->payload.desc; -rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); +if (rule_stmt_dep_add (ctx, nstmt, ctx->stmt) <0 ) +return -1 ; } }else {unsigned int i;
@@ -810,10 +851,6 @@ static int resolve_ll_protocol_conflict(struct eval_ctx *ctx, } } -/* This payload and the existing context don't match, conflict. */ -if (pctx->protocol[base +1 ].desc !=NULL ) -return 1 ; - link =proto_find_num (desc, payload->payload.desc);if (link <0 ||ll_conflict_resolution_gen_dependency (ctx, link, payload, &nstmt) <0 )
@@ -822,7 +859,8 @@ static int resolve_ll_protocol_conflict(struct eval_ctx *ctx,for (i =0 ; i < pctx->stacked_ll_count; i++) payload->payload.offset += pctx->stacked_ll[i]->length; -rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); +if (rule_stmt_dep_add (ctx, nstmt, ctx->stmt) <0 ) +return -1 ;return 0 ; }
@@ -850,7 +888,8 @@ static int __expr_evaluate_payload(struct eval_ctx *ctx, struct expr *expr)if (payload_gen_dependency (ctx, payload, &nstmt) <0 )return -1 ; -rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); +if (rule_stmt_dep_add (ctx, nstmt, ctx->stmt) <0 ) +return -1 ; desc = pctx->protocol[base].desc;
@@ -870,7 +909,10 @@ static int __expr_evaluate_payload(struct eval_ctx *ctx, struct expr *expr)assert (pctx->stacked_ll_count); payload->payload.offset += pctx->stacked_ll[0 ]->length; -rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); + +if (rule_stmt_dep_add (ctx, nstmt, ctx->stmt) <0 ) +return -1 ; +return 1 ; } goto check_icmp;
@@ -911,8 +953,8 @@ check_icmp:if (payload_gen_icmp_dependency (ctx, expr, &nstmt) <0 )return -1 ; -if (nstmt) -rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); +if (nstmt &&rule_stmt_dep_add (ctx, nstmt, ctx->stmt) <0 ) +return -1 ;return 0 ; }
@@ -988,7 +1030,8 @@ static int expr_evaluate_inner(struct eval_ctx *ctx, struct expr **exprp)if (payload_gen_inner_dependency (ctx, expr, &nstmt) <0 )return -1 ; -rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); +if (rule_stmt_dep_add (ctx, nstmt, ctx->stmt) <0 ) +return -1 ;proto_ctx_update (pctx,PROTO_BASE_TRANSPORT_HDR , &expr->location, expr->payload.inner_desc); }
@@ -1119,7 +1162,9 @@ static int ct_gen_nh_dependency(struct eval_ctx *ctx, struct expr *ct)relational_expr_pctx_update (pctx, dep); nstmt =expr_stmt_alloc (&dep->location, dep); -rule_stmt_insert_at (ctx->rule, nstmt, ctx->stmt); + +if (rule_stmt_dep_add (ctx, nstmt, ctx->stmt) <0 ) +return -1 ;return 0 ; }
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/3 tests: shell: add vlan double tagging match simple test case
In reply to Pablo Neira AyusoAs a follow up for:
74cf3d16d8e9 ("tests: shell: add vlan match test case")
Add basic test for q-in-q matching support.
--- .../packetpath/dumps/vlan_qinq.nodump | 0 tests/shell/testcases/packetpath/vlan_qinq | 52 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 tests/shell/testcases/packetpath/dumps/vlan_qinq.nodump create mode 100755 tests/shell/testcases/packetpath/vlan_qinq
tests/shell/testcases/packetpath/dumps/vlan_qinq.nodump new file +0 -0
tests/shell/testcases/packetpath/vlan_qinq new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/3 tests: shell: add vlan mangling test case
In reply to Pablo Neira AyusoAs a follow up for:
74cf3d16d8e9 ("tests: shell: add vlan match test case")
--- .../shell/testcases/packetpath/vlan_mangling | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 tests/shell/testcases/packetpath/vlan_mangling
tests/shell/testcases/packetpath/vlan_mangling new file +75 -0
@@ -0,0 +1,75 @@ +#!/bin/bash + +rnd=$(mktemp -u XXXXXXXX) +ns1="nft1ifname-$rnd" +ns2="nft2ifname-$rnd" + +cleanup() +{ + ip netns del "$ns1" + ip netns del "$ns2" +} + +trap cleanup EXIT + +set -e + +ip netns add "$ns1" +ip netns add "$ns2" +ip -net "$ns1" link set lo up +ip -net "$ns2" link set lo up + +ip link add veth0 netns $ns1 type veth peer name veth0 netns $ns2 + +ip -net "$ns1" link set veth0 addr da:d3:00:01:02:03 + +ip -net "$ns1" link add vlan123 link veth0 type vlan id 123 +ip -net "$ns2" link add vlan321 link veth0 type vlan id 321 + + +for dev in veth0 ; do + ip -net "$ns1" link set $dev up + ip -net "$ns2" link set $dev up +done +ip -net "$ns1" link set vlan123 up +ip -net "$ns2" link set vlan321 up + +ip -net "$ns1" addr add 10.1.1.1/24 dev vlan123 +ip -net "$ns2" addr add 10.1.1.2/24 dev vlan321 + +ip netns exec "$ns2" $NFT -f /dev/stdin <<"EOF" +table netdev t { + chain in_update_vlan { + vlan type arp vlan id set 321 counter + ip saddr 10.1.1.1 icmp type echo-request vlan id set 321 counter + } + + chain in { + type filter hook ingress device veth0 priority filter; + ether saddr da:d3:00:01:02:03 vlan id 123 jump in_update_vlan + } + + chain out_update_vlan { + vlan type arp vlan id set 123 counter + ip daddr 10.1.1.1 icmp type echo-reply vlan id set 123 counter + } + + chain out { + type filter hook egress device veth0 priority filter; + ether daddr da:d3:00:01:02:03 vlan id 321 jump out_update_vlan + } +} +EOF + +ip netns exec "$ns1" ping -c 1 10.1.1.2 + +set +e + +ip netns exec "$ns2" $NFT list ruleset +ip netns exec "$ns2" $NFT list table netdev t | grep 'counter packets' | grep 'counter packets 0 bytes 0' +if [ $? -eq 1 ] +then + exit 0 +fi + +exit 1
Signature · 1 line
2.30.2