diff mbox series

src: add vlan_id type

Message ID 20190820164523.18464-1-michael-dev@fami-braun.de
State Not Applicable
Delegated to: Pablo Neira
Headers show
Series src: add vlan_id type | expand

Commit Message

michael-dev Aug. 20, 2019, 4:45 p.m. UTC
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
	}
}

Signed-off-by: Michael Braun <michael-dev@fami-braun.de>
---
 include/datatype.h |  2 ++
 src/datatype.c     |  1 +
 src/proto.c        | 11 ++++++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

Comments

Pablo Neira Ayuso Aug. 20, 2019, 5:57 p.m. UTC | #1
On Tue, Aug 20, 2019 at 06:45:23PM +0200, Michael Braun wrote:
> 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.
diff mbox series

Patch

diff --git a/include/datatype.h b/include/datatype.h
index c1d08cc2..9678d0da 100644
--- a/include/datatype.h
+++ b/include/datatype.h
@@ -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);
 
diff --git a/src/datatype.c b/src/datatype.c
index c5a01346..2bf0bb18 100644
--- a/src/datatype.c
+++ b/src/datatype.c
@@ -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)
diff --git a/src/proto.c b/src/proto.c
index 40ce590e..efcd6119 100644
--- a/src/proto.c
+++ b/src/proto.c
@@ -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),
 	},
 };