Skip to contentSkip to conversation

use skb->protocol as l3 protocol dependency

PATCH In review Florian Westphal 2 participants 7 messages Jun 18, 2019 – Jun 19, 2019 netfilter

lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

cover use skb->protocol as l3 protocol dependency

Real patch is the last one, first two do preparation work:
1. Allow removal of the dependency for the reject statement
2. Keep exact icmp type for bridge when printing.
This is needed so we do not lose the l3 protocol information. In the ip family, "reject" and "reject with icmp type port-unreachable" are the same, but in case of bridge the latter adds a protocol dependency on ipv4, whereas the former rejects ip with icmp and ipv6 with a similar icmp-v6 error packet.
3. Prefer meta protocol for bridge family for all implicit depencencies.

 include/statement.h                   |    3 
 src/json.c                            |    6 -
 src/meta.c                            |    6 -
 src/netlink_delinearize.c             |   10 +
 src/payload.c                         |   18 +++
 src/statement.c                       |    6 -
 tests/py/bridge/ether.t               |    4 
 tests/py/bridge/ether.t.json.output   |   48 ---------
 tests/py/bridge/ether.t.payload       |   24 +++-
 tests/py/bridge/icmpX.t.payload       |    4 
 tests/py/bridge/reject.t              |   28 ++---
 tests/py/bridge/reject.t.json.output  |  170 +++++---------------------------
 tests/py/bridge/reject.t.payload      |   24 ++--
 tests/py/inet/ip_tcp.t.payload.bridge |    8 -
 tests/py/inet/sets.t.payload.bridge   |    4 
 tests/py/ip/ip.t.payload.bridge       |  180 +++++++++++++++++-----------------
 16 files changed, 217 insertions(+), 326 deletions(-)
author maintainer
#1 lore raw

PATCH 1/3 netlink_delinerize: remove network header dep for reject statement also in bridge family

add rule bridge test-bridge input reject with icmp type ...

is shown as

ether type ip reject type ...

i.e., the dependency is not removed.

Allow dependency removal -- this adds a problem where some icmp types will be shortened to 'reject', losing the icmp ipv4 dependency.

Next patch resolves this problem by disabling short-hand abbreviations for bridge reject statements.

---
 src/netlink_delinearize.c            |   4 +
 tests/py/bridge/ether.t.json.output  |  48 +-------
 tests/py/bridge/reject.t             |  28 ++---
 tests/py/bridge/reject.t.json.output | 170 +++++----------------------
 4 files changed, 50 insertions(+), 200 deletions(-)
src/netlink_delinearize.c +4 -0
index 1f63d9d5e2c2..4d720d2938fc 100644
@@ -2217,6 +2217,10 @@ static void stmt_reject_postprocess(struct rule_pp_ctx *rctx)
 		default:
 			break;
 		}
+
+		if (payload_dependency_exists(&rctx->pdctx, PROTO_BASE_NETWORK_HDR))
+			payload_dependency_release(&rctx->pdctx);
+
 		break;
 	default:
 		break;
tests/py/bridge/ether.t.json.output +4 -44

76 lines not on this page · raw message

tests/py/bridge/reject.t +14 -14
index ad5280f7d573..ee7e93c81449 100644
@@ -3,24 +3,24 @@
 *bridge;test-bridge;input
 
 # The output is specific for bridge family
-reject with icmp type host-unreachable;ok;ether type ip reject with icmp type host-unreachable
-reject with icmp type net-unreachable;ok;ether type ip reject with icmp type net-unreachable
-reject with icmp type prot-unreachable;ok;ether type ip reject with icmp type prot-unreachable
-reject with icmp type port-unreachable;ok;ether type ip reject
-reject with icmp type net-prohibited;ok;ether type ip reject with icmp type net-prohibited
-reject with icmp type host-prohibited;ok;ether type ip reject with icmp type host-prohibited
-reject with icmp type admin-prohibited;ok;ether type ip reject with icmp type admin-prohibited
-
-reject with icmpv6 type no-route;ok;ether type ip6 reject with icmpv6 type no-route
-reject with icmpv6 type admin-prohibited;ok;ether type ip6 reject with icmpv6 type admin-prohibited
-reject with icmpv6 type addr-unreachable;ok;ether type ip6 reject with icmpv6 type addr-unreachable
-reject with icmpv6 type port-unreachable;ok;ether type ip6 reject
+reject with icmp type host-unreachable;ok
+reject with icmp type net-unreachable;ok
+reject with icmp type prot-unreachable;ok
+reject with icmp type port-unreachable;ok
+reject with icmp type net-prohibited;ok
+reject with icmp type host-prohibited;ok
+reject with icmp type admin-prohibited;ok
+
+reject with icmpv6 type no-route;ok
+reject with icmpv6 type admin-prohibited;ok
+reject with icmpv6 type addr-unreachable;ok
+reject with icmpv6 type port-unreachable;ok
 
 mark 12345 ip protocol tcp reject with tcp reset;ok;meta mark 0x00003039 ip protocol 6 reject with tcp reset
 
 reject;ok
-ether type ip reject;ok
-ether type ip6 reject;ok
+ether type ip reject;ok;reject with icmp type port-unreachable
+ether type ip6 reject;ok;reject with icmpv6 type port-unreachable
 
 reject with icmpx type host-unreachable;ok
 reject with icmpx type no-route;ok
tests/py/bridge/reject.t.json.output +28 -142

248 lines not on this page · raw message

Signature · 1 line
2.21.0
maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH nft 1/3] netlink_delinerize: remove network header dep for reject statement also in bridge family

Quoted 8 lines · Florian Westphal

add rule bridge test-bridge input reject with icmp type ...

is shown as

ether type ip reject type ...

i.e., the dependency is not removed.

Quoted 7 lines

Allow dependency removal -- this adds a problem where some icmp types will be shortened to 'reject', losing the icmp ipv4 dependency.

Next patch resolves this problem by disabling short-hand abbreviations for bridge reject statements.

author maintainer
#3 lore raw

PATCH 2/3 src: statement: disable reject statement type omission for bridge

In reply to Florian Westphal

add rule bridge test-bridge input reject with icmp type port-unreachable

... will be printed as 'reject', which is fine on ip family, but not on bridge -- 'with icmp type' adds an ipv4 dependency, but simple reject does not (it will use icmpx to also reject ipv6 packets with an icmpv6 error).

Add a toggle to supress short-hand versions in this case.

---
 include/statement.h       | 3 ++-
 src/json.c                | 6 ++++--
 src/netlink_delinearize.c | 6 ++++++
 src/statement.c           | 6 ++++--
 4 files changed, 16 insertions(+), 5 deletions(-)
include/statement.h +2 -1
index 91d6e0e2cb81..6fb5cf15f8bd 100644
@@ -102,8 +102,9 @@ extern void __limit_stmt_print(const struct limit_stmt *limit);
 
 struct reject_stmt {
 	struct expr		*expr;
-	enum nft_reject_types	type;
+	enum nft_reject_types	type:8;
 	int8_t			icmp_code;
+	uint8_t			verbose_print:1;
 	unsigned int		family;
 };
 
src/json.c +4 -2
index a503a97500a9..e0127c5741a0 100644
@@ -1311,13 +1311,15 @@ json_t *reject_stmt_json(const struct stmt *stmt, struct output_ctx *octx)
 	case NFT_REJECT_ICMP_UNREACH:
 		switch (stmt->reject.family) {
 		case NFPROTO_IPV4:
-			if (stmt->reject.icmp_code == ICMP_PORT_UNREACH)
+			if (!stmt->reject.verbose_print &&
+			    stmt->reject.icmp_code == ICMP_PORT_UNREACH)
 				break;
 			type = "icmp";
 			jexpr = expr_print_json(stmt->reject.expr, octx);
 			break;
 		case NFPROTO_IPV6:
-			if (stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT)
+			if (!stmt->reject.verbose_print &&
+			    stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT)
 				break;
 			type = "icmpv6";
 			jexpr = expr_print_json(stmt->reject.expr, octx);
src/netlink_delinearize.c +6 -0
index 4d720d2938fc..a4044f0c7329 100644
@@ -2202,6 +2202,12 @@ static void stmt_reject_postprocess(struct rule_pp_ctx *rctx)
 			datatype_set(stmt->reject.expr, &icmpx_code_type);
 			break;
 		}
+
+		/* always print full icmp(6) name, simple 'reject' might be ambiguious
+		 * because ipv4 vs. ipv6 info might be lost
+		 */
+		stmt->reject.verbose_print = 1;
+
 		base = rctx->pctx.protocol[PROTO_BASE_LL_HDR].desc;
 		desc = rctx->pctx.protocol[PROTO_BASE_NETWORK_HDR].desc;
 		protocol = proto_find_num(base, desc);
src/statement.c +4 -2
index a9e8b3ae0780..c5594233a45f 100644
@@ -516,13 +516,15 @@ static void reject_stmt_print(const struct stmt *stmt, struct output_ctx *octx)
 	case NFT_REJECT_ICMP_UNREACH:
 		switch (stmt->reject.family) {
 		case NFPROTO_IPV4:
-			if (stmt->reject.icmp_code == ICMP_PORT_UNREACH)
+			if (!stmt->reject.verbose_print &&
+			     stmt->reject.icmp_code == ICMP_PORT_UNREACH)
 				break;
 			nft_print(octx, " with icmp type ");
 			expr_print(stmt->reject.expr, octx);
 			break;
 		case NFPROTO_IPV6:
-			if (stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT)
+			if (!stmt->reject.verbose_print &&
+			    stmt->reject.icmp_code == ICMP6_DST_UNREACH_NOPORT)
 				break;
 			nft_print(octx, " with icmpv6 type ");
 			expr_print(stmt->reject.expr, octx);
Signature · 1 line
2.21.0
maintainer Acked-by on v1 2/3
#4 lore raw

Re: [PATCH nft 2/3] src: statement: disable reject statement type omission for bridge

Quoted 9 lines · Florian Westphal

add rule bridge test-bridge input reject with icmp type port-unreachable

... will be printed as 'reject', which is fine on ip family, but not on bridge -- 'with icmp type' adds an ipv4 dependency, but simple reject does not (it will use icmpx to also reject ipv6 packets with an icmpv6 error).

Add a toggle to supress short-hand versions in this case.

author maintainer
#5 lore raw

PATCH 3/3 src: prefer meta protocol as bridge l3 dependency

In reply to Florian Westphal

On families other than 'ip', the rule

ip protocol icmp

needs a dependency on the ip protocol so we do not treat e.g. an ipv6 header as ip.

Bridge currently uses eth_hdr.type for this, but that will cause the rule above to not match in case the ip packet is within a VLAN tagged frame -- ether.type will appear as ETH_P_8021Q.

Due to vlan tag stripping, skb->protocol will be ETH_P_IP -- so prefer to use this instead.

---
 src/meta.c                            |   6 +-
 src/payload.c                         |  18 +++
 tests/py/bridge/ether.t               |   4 +-
 tests/py/bridge/ether.t.payload       |  24 ++--
 tests/py/bridge/icmpX.t.payload       |   4 +-
 tests/py/bridge/reject.t.payload      |  24 ++--
 tests/py/inet/ip_tcp.t.payload.bridge |   8 +-
 tests/py/inet/sets.t.payload.bridge   |   4 +-
 tests/py/ip/ip.t.payload.bridge       | 180 +++++++++++++-------------
 9 files changed, 151 insertions(+), 121 deletions(-)
src/meta.c +5 -1
index 583e790ff47d..1e8964eb48c4 100644
@@ -539,7 +539,11 @@ static void meta_expr_pctx_update(struct proto_ctx *ctx,
 		proto_ctx_update(ctx, PROTO_BASE_TRANSPORT_HDR, &expr->location, desc);
 		break;
 	case NFT_META_PROTOCOL:
-		if (h->base < PROTO_BASE_NETWORK_HDR && ctx->family != NFPROTO_NETDEV)
+		if (h->base != PROTO_BASE_LL_HDR)
+			return;
+
+		if (ctx->family != NFPROTO_NETDEV &&
+		    ctx->family != NFPROTO_BRIDGE)
 			return;
 
 		desc = proto_find_upper(h->desc, ntohs(mpz_get_uint16(right->value)));
src/payload.c +18 -0
index 338a4b762cf8..7e4f935be293 100644
@@ -18,6 +18,7 @@
 #include <net/if_arp.h>
 #include <arpa/inet.h>
 #include <linux/netfilter.h>
+#include <linux/if_ether.h>
 
 #include <rule.h>
 #include <expression.h>
@@ -369,6 +370,23 @@ int payload_gen_dependency(struct eval_ctx *ctx, const struct expr *expr,
 				  "no %s protocol specified",
 				  proto_base_names[expr->payload.base - 1]);
 
+	if (ctx->pctx.family == NFPROTO_BRIDGE && desc == &proto_eth) {
+		/* prefer netdev proto, which adds dependencies based
+		 * on skb->protocol.
+		 *
+		 * This has the advantage that we will also match
+		 * vlan encapsulated traffic.
+		 *
+		 * eth_hdr(skb)->type would not match, as nft_payload
+		 * will pretend vlan tag was not offloaded, i.e.
+		 * type is ETH_P_8021Q in such a case, but skb->protocol
+		 * would still match the l3 header type.
+		 */
+		if (expr->payload.desc == &proto_ip ||
+		    expr->payload.desc == &proto_ip6)
+			desc = &proto_netdev;
+	}
+
 	return payload_add_dependency(ctx, desc, expr->payload.desc, expr, res);
 }
 
tests/py/bridge/ether.t +2 -2
index 15f5f857b198..e4f75d160477 100644
@@ -2,8 +2,8 @@
 
 *bridge;test-bridge;input
 
-tcp dport 22 iiftype ether ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:4 accept;ok;tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4 accept
-tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04;ok;tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4
+tcp dport 22 iiftype ether ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:4 accept;ok;tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04 accept
+tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04;ok
 tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4;ok
 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4 accept;ok
 
tests/py/bridge/ether.t.payload +16 -8
index 1caa2d509ea2..eaff9c312bae 100644
@@ -6,10 +6,12 @@ bridge test-bridge input
   [ cmp eq reg 1 0x00001600 ]
   [ meta load iiftype => reg 1 ]
   [ cmp eq reg 1 0x00000001 ]
-  [ payload load 8b @ link header + 6 => reg 1 ]
-  [ cmp eq reg 1 0x0c540f00 0x00080411 ]
+  [ meta load protocol => reg 1 ]
+  [ cmp eq reg 1 0x00000008 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x04030201 ]
+  [ payload load 6b @ link header + 6 => reg 1 ]
+  [ cmp eq reg 1 0x0c540f00 0x00000411 ]
   [ immediate reg 0 accept ]
 
 # tcp dport 22 ip daddr 1.2.3.4 ether saddr 00:0f:54:0c:11:04
@@ -18,10 +20,12 @@ bridge test-bridge input
   [ cmp eq reg 1 0x00000006 ]
   [ payload load 2b @ transport header + 2 => reg 1 ]
   [ cmp eq reg 1 0x00001600 ]
-  [ payload load 8b @ link header + 6 => reg 1 ]
-  [ cmp eq reg 1 0x0c540f00 0x00080411 ]
+  [ meta load protocol => reg 1 ]
+  [ cmp eq reg 1 0x00000008 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x04030201 ]
+  [ payload load 6b @ link header + 6 => reg 1 ]
+  [ cmp eq reg 1 0x0c540f00 0x00000411 ]
 
 # tcp dport 22 ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4
 bridge test-bridge input
@@ -29,15 +33,19 @@ bridge test-bridge input
   [ cmp eq reg 1 0x00000006 ]
   [ payload load 2b @ transport header + 2 => reg 1 ]
   [ cmp eq reg 1 0x00001600 ]
-  [ payload load 8b @ link header + 6 => reg 1 ]
-  [ cmp eq reg 1 0x0c540f00 0x00080411 ]
+  [ payload load 6b @ link header + 6 => reg 1 ]
+  [ cmp eq reg 1 0x0c540f00 0x00000411 ]
+  [ meta load protocol => reg 1 ]
+  [ cmp eq reg 1 0x00000008 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x04030201 ]
 
 # ether saddr 00:0f:54:0c:11:04 ip daddr 1.2.3.4 accept
 bridge test-bridge input
-  [ payload load 8b @ link header + 6 => reg 1 ]
-  [ cmp eq reg 1 0x0c540f00 0x00080411 ]
+  [ payload load 6b @ link header + 6 => reg 1 ]
+  [ cmp eq reg 1 0x0c540f00 0x00000411 ]
+  [ meta load protocol => reg 1 ]
+  [ cmp eq reg 1 0x00000008 ]
   [ payload load 4b @ network header + 16 => reg 1 ]
   [ cmp eq reg 1 0x04030201 ]
   [ immediate reg 0 accept ]
tests/py/bridge/icmpX.t.payload +2 -2
index 0fab1abf61ea..f9ea7b60450a 100644
@@ -1,6 +1,6 @@
 # ip protocol icmp icmp type echo-request
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ payload load 1b @ network header + 9 => reg 1 ]
   [ cmp eq reg 1 0x00000001 ]
@@ -18,7 +18,7 @@ bridge test-bridge input
 
 # ip6 nexthdr icmpv6 icmpv6 type echo-request
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x0000dd86 ]
   [ payload load 1b @ network header + 6 => reg 1 ]
   [ cmp eq reg 1 0x0000003a ]
tests/py/bridge/reject.t.payload +12 -12
index 888179df9c97..0d10547bbce6 100644
@@ -1,66 +1,66 @@
 # reject with icmp type host-unreachable
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ reject type 0 code 1 ]
 
 # reject with icmp type net-unreachable
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ reject type 0 code 0 ]
 
 # reject with icmp type prot-unreachable
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ reject type 0 code 2 ]
 
 # reject with icmp type port-unreachable
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ reject type 0 code 3 ]
 
 # reject with icmp type net-prohibited
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ reject type 0 code 9 ]
 
 # reject with icmp type host-prohibited
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ reject type 0 code 10 ]
 
 # reject with icmp type admin-prohibited
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ reject type 0 code 13 ]
 
 # reject with icmpv6 type no-route
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x0000dd86 ]
   [ reject type 0 code 0 ]
 
 # reject with icmpv6 type admin-prohibited
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x0000dd86 ]
   [ reject type 0 code 1 ]
 
 # reject with icmpv6 type addr-unreachable
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x0000dd86 ]
   [ reject type 0 code 3 ]
 
 # reject with icmpv6 type port-unreachable
 bridge test-bridge input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x0000dd86 ]
   [ reject type 0 code 4 ]
 
@@ -68,7 +68,7 @@ bridge test-bridge input
 bridge test-bridge input
   [ meta load mark => reg 1 ]
   [ cmp eq reg 1 0x00003039 ]
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ payload load 1b @ network header + 9 => reg 1 ]
   [ cmp eq reg 1 0x00000006 ]
tests/py/inet/ip_tcp.t.payload.bridge +4 -4
index f9f2e0a137f6..0344cd66668c 100644
@@ -1,6 +1,6 @@
 # ip protocol tcp tcp dport 22
 bridge test-bridge input 
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ payload load 1b @ network header + 9 => reg 1 ]
   [ cmp eq reg 1 0x00000006 ]
@@ -9,7 +9,7 @@ bridge test-bridge input
 
 # ip protocol tcp ip saddr 1.2.3.4 tcp dport 22
 bridge test-bridge input 
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ payload load 1b @ network header + 9 => reg 1 ]
   [ cmp eq reg 1 0x00000006 ]
@@ -20,7 +20,7 @@ bridge test-bridge input
 
 # ip protocol tcp counter ip saddr 1.2.3.4 tcp dport 22
 bridge test-bridge input 
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ payload load 1b @ network header + 9 => reg 1 ]
   [ cmp eq reg 1 0x00000006 ]
@@ -32,7 +32,7 @@ bridge test-bridge input
 
 # ip protocol tcp counter tcp dport 22
 bridge test-bridge input 
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ payload load 1b @ network header + 9 => reg 1 ]
   [ cmp eq reg 1 0x00000006 ]
tests/py/inet/sets.t.payload.bridge +2 -2
index 6f21f827bc96..f5aaab1d79bc 100644
@@ -1,6 +1,6 @@
 # ip saddr @set1 drop
 bridge test-inet input 
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
   [ payload load 4b @ network header + 12 => reg 1 ]
   [ lookup reg 1 set set1 ]
@@ -8,7 +8,7 @@ bridge test-inet input
 
 # ip6 daddr != @set2 accept
 bridge test-inet input
-  [ payload load 2b @ link header + 12 => reg 1 ]
+  [ meta load protocol => reg 1 ]
   [ cmp eq reg 1 0x0000dd86 ]
   [ payload load 16b @ network header + 24 => reg 1 ]
   [ lookup reg 1 set set2 0x1 ]
tests/py/ip/ip.t.payload.bridge +90 -90

719 lines not on this page · raw message

Signature · 1 line
2.21.0
maintainer Acked-by on v1 3/3
#6 lore raw

Re: [PATCH nft 3/3] src: prefer meta protocol as bridge l3 dependency

Quoted 7 lines · Florian Westphal

On families other than 'ip', the rule

ip protocol icmp

needs a dependency on the ip protocol so we do not treat e.g. an ipv6 header as ip.

Quoted 8 lines

Bridge currently uses eth_hdr.type for this, but that will cause the rule above to not match in case the ip packet is within a VLAN tagged frame -- ether.type will appear as ETH_P_8021Q.

Due to vlan tag stripping, skb->protocol will be ETH_P_IP -- so prefer to use this instead.