Skip to contentSkip to conversation

src: add vlan_id type

PATCH In review Michael Braun 2 participants 2 messages Aug 20, 2019 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src: add vlan_id type

This enables using vlan id in a set or a concatenation.

table bridge filter {
	set dropvlans {
		type vlan_id
		elements = { 123 }
	}
	chain FORWARD {
		type filter hook forward priority filter; policy accept;
                vlan id @dropvlans drop
	}
}
---
 include/datatype.h |  2 ++
 src/datatype.c     |  1 +
 src/proto.c        | 11 ++++++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)
include/datatype.h +2 -0
index c1d08cc2..9678d0da 100644
@@ -90,6 +90,7 @@ enum datatypes {
 	TYPE_CT_EVENTBIT,
 	TYPE_IFNAME,
 	TYPE_IGMP_TYPE,
+	TYPE_VLANID,
 	__TYPE_MAX
 };
 #define TYPE_MAX		(__TYPE_MAX - 1)
@@ -264,6 +265,7 @@ extern const struct datatype time_type;
 extern const struct datatype boolean_type;
 extern const struct datatype priority_type;
 extern const struct datatype policy_type;
+extern const struct datatype vlanid_type;
 
 void inet_service_type_print(const struct expr *expr, struct output_ctx *octx);
 
src/datatype.c +1 -0
index c5a01346..2bf0bb18 100644
@@ -71,6 +71,7 @@ static const struct datatype *datatypes[TYPE_MAX + 1] = {
 	[TYPE_BOOLEAN]		= &boolean_type,
 	[TYPE_IFNAME]		= &ifname_type,
 	[TYPE_IGMP_TYPE]	= &igmp_type_type,
+	[TYPE_VLANID]		= &vlanid_type,
 };
 
 const struct datatype *datatype_lookup(enum datatypes type)
src/proto.c +10 -1
index 40ce590e..efcd6119 100644
@@ -918,6 +918,15 @@ const struct proto_desc proto_arp = {
 
 #include <net/ethernet.h>
 
+const struct datatype vlanid_type = {
+	.type		= TYPE_VLANID,
+	.name		= "vlan_id",
+	.desc		= "802.1Q VLAN ID",
+	.byteorder	= BYTEORDER_BIG_ENDIAN,
+	.size		= 12,
+	.basetype	= &integer_type,
+};
+
 #define VLANHDR_BITFIELD(__name, __offset, __len) \
 	HDR_BITFIELD(__name, &integer_type, __offset, __len)
 #define VLANHDR_TYPE(__name, __type, __member) \
@@ -938,7 +947,7 @@ const struct proto_desc proto_vlan = {
 	.templates	= {
 		[VLANHDR_PCP]		= VLANHDR_BITFIELD("pcp", 0, 3),
 		[VLANHDR_CFI]		= VLANHDR_BITFIELD("cfi", 3, 1),
-		[VLANHDR_VID]		= VLANHDR_BITFIELD("id", 4, 12),
+		[VLANHDR_VID]		= HDR_BITFIELD("id", &vlanid_type, 4, 12),
 		[VLANHDR_TYPE]		= VLANHDR_TYPE("type", &ethertype_type, vlan_type),
 	},
 };
Signature · 1 line
2.20.1
#1 lore raw
Quoted 12 lines · Michael Braun

This enables using vlan id in a set or a concatenation.

table bridge filter {
	set dropvlans {
		type vlan_id
		elements = { 123 }
	}
	chain FORWARD {
		type filter hook forward priority filter; policy accept;
                vlan id @dropvlans drop
	}
}

Thanks for submitting your patch.

Florian sent a better approach to support for all types generically. Please, have a look at his recent typeof() series.