* [PATCH] src: add vlan_id type
@ 2019-08-20 16:45 Michael Braun
2019-08-20 17:57 ` Pablo Neira Ayuso
0 siblings, 1 reply; 2+ messages in thread
From: Michael Braun @ 2019-08-20 16:45 UTC (permalink / raw)
To: netfilter-devel; +Cc: 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
}
}
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(-)
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", ðertype_type, vlan_type),
},
};
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] src: add vlan_id type
2019-08-20 16:45 [PATCH] src: add vlan_id type Michael Braun
@ 2019-08-20 17:57 ` Pablo Neira Ayuso
0 siblings, 0 replies; 2+ messages in thread
From: Pablo Neira Ayuso @ 2019-08-20 17:57 UTC (permalink / raw)
To: Michael Braun; +Cc: netfilter-devel
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-08-20 17:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20 16:45 [PATCH] src: add vlan_id type Michael Braun
2019-08-20 17:57 ` Pablo Neira Ayuso
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.