From 594fa241998c396eafcd105cf32467bc4cfc01b3 Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Tue, 21 Jan 2025 11:41:30 +0200 Subject: [PATCH] net: ethernet: Properly handle VLAN tag 0 Packets are forwarded to the native interface or in other words, the vlan header is simply stripped and ignored. This feature is called 'priority tagging'. Signed-off-by: Cla Mattia Galliard Signed-off-by: Jukka Rissanen --- include/zephyr/net/ethernet_vlan.h | 3 +++ subsys/net/l2/ethernet/ethernet.c | 18 ++++++++++-------- subsys/net/l2/ethernet/vlan.c | 4 ++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/zephyr/net/ethernet_vlan.h b/include/zephyr/net/ethernet_vlan.h index ba969954812..ff9f32524af 100644 --- a/include/zephyr/net/ethernet_vlan.h +++ b/include/zephyr/net/ethernet_vlan.h @@ -31,6 +31,9 @@ extern "C" { /** Unspecified VLAN tag value */ #define NET_VLAN_TAG_UNSPEC 0x0fff +/** VLAN ID for forwarding to the native interface (priority tagging) */ +#define NET_VLAN_TAG_PRIORITY 0x0000 + /** * @brief Get VLAN identifier from TCI. * diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index c93705bc11a..86825f4ff08 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -298,14 +298,16 @@ static enum net_verdict ethernet_recv(struct net_if *iface, goto drop; } - /* We could call VLAN interface directly but then the - * interface statistics would not get updated so route - * the call via Virtual L2 layer. - */ - if (net_if_l2(net_pkt_iface(pkt))->recv != NULL) { - verdict = net_if_l2(net_pkt_iface(pkt))->recv(iface, pkt); - if (verdict == NET_DROP) { - goto drop; + if (net_pkt_vlan_tag(pkt) != NET_VLAN_TAG_PRIORITY) { + /* We could call VLAN interface directly but then the + * interface statistics would not get updated so route + * the call via Virtual L2 layer. + */ + if (net_if_l2(net_pkt_iface(pkt))->recv != NULL) { + verdict = net_if_l2(net_pkt_iface(pkt))->recv(iface, pkt); + if (verdict == NET_DROP) { + goto drop; + } } } } diff --git a/subsys/net/l2/ethernet/vlan.c b/subsys/net/l2/ethernet/vlan.c index a746225ae6b..145fd585cd9 100644 --- a/subsys/net/l2/ethernet/vlan.c +++ b/subsys/net/l2/ethernet/vlan.c @@ -214,6 +214,10 @@ struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag) ctx = get_vlan(iface, tag); if (ctx == NULL) { + if (tag == NET_VLAN_TAG_PRIORITY) { + return iface; + } + return NULL; }