Skip to content

Commit f44354a

Browse files
Jukka RissanenChromeos LUCI
Jukka Rissanen
authored and
Chromeos LUCI
committed
net: vlan: Allow VLAN count to be set to 0
If VLAN count is set to 0, then only priority tagged VLAN frames that have tag value 0 can be received. Also this means that VLAN interfaces are not created which can save memory if you do not need to receive any other VLAN frames than those tagged with value 0. Fixes zephyrproject-rtos#84023 (cherry picked from commit 9c24578) Original-Signed-off-by: Jukka Rissanen <[email protected]> GitOrigin-RevId: 9c24578 Cr-Build-Id: 8724184635785024145 Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8724184635785024145 Copybot-Job-Name: zephyr-main-copybot-downstream Change-Id: I6aafe41cfed8b78a278661d86438f6b507a3bdc9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/6222354 Commit-Queue: ChromeOS Prod (Robot) <[email protected]> Bot-Commit: ChromeOS Prod (Robot) <[email protected]> Tested-by: ChromeOS Prod (Robot) <[email protected]>
1 parent 4fac018 commit f44354a

File tree

7 files changed

+69
-19
lines changed

7 files changed

+69
-19
lines changed

include/zephyr/net/ethernet.h

+15-10
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,7 @@ struct ethernet_vlan {
618618
#if defined(CONFIG_NET_VLAN_COUNT)
619619
#define NET_VLAN_MAX_COUNT CONFIG_NET_VLAN_COUNT
620620
#else
621-
/* Even thou there are no VLAN support, the minimum count must be set to 1.
622-
*/
623-
#define NET_VLAN_MAX_COUNT 1
621+
#define NET_VLAN_MAX_COUNT 0
624622
#endif
625623

626624
/** @endcond */
@@ -681,7 +679,14 @@ struct ethernet_context {
681679
struct net_if *iface;
682680

683681
#if defined(CONFIG_NET_LLDP)
684-
struct ethernet_lldp lldp[NET_VLAN_MAX_COUNT];
682+
#if NET_VLAN_MAX_COUNT > 0
683+
#define NET_LLDP_MAX_COUNT NET_VLAN_MAX_COUNT
684+
#else
685+
#define NET_LLDP_MAX_COUNT 1
686+
#endif /* NET_VLAN_MAX_COUNT > 0 */
687+
688+
/** LLDP specific parameters */
689+
struct ethernet_lldp lldp[NET_LLDP_MAX_COUNT];
685690
#endif
686691

687692
/**
@@ -988,7 +993,7 @@ int net_eth_get_hw_config(struct net_if *iface, enum ethernet_config_type type,
988993
*
989994
* @return 0 if ok, <0 if error
990995
*/
991-
#if defined(CONFIG_NET_VLAN)
996+
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
992997
int net_eth_vlan_enable(struct net_if *iface, uint16_t tag);
993998
#else
994999
static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
@@ -1008,7 +1013,7 @@ static inline int net_eth_vlan_enable(struct net_if *iface, uint16_t tag)
10081013
*
10091014
* @return 0 if ok, <0 if error
10101015
*/
1011-
#if defined(CONFIG_NET_VLAN)
1016+
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
10121017
int net_eth_vlan_disable(struct net_if *iface, uint16_t tag);
10131018
#else
10141019
static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
@@ -1031,7 +1036,7 @@ static inline int net_eth_vlan_disable(struct net_if *iface, uint16_t tag)
10311036
* @return VLAN tag for this interface or NET_VLAN_TAG_UNSPEC if VLAN
10321037
* is not configured for that interface.
10331038
*/
1034-
#if defined(CONFIG_NET_VLAN)
1039+
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
10351040
uint16_t net_eth_get_vlan_tag(struct net_if *iface);
10361041
#else
10371042
static inline uint16_t net_eth_get_vlan_tag(struct net_if *iface)
@@ -1073,7 +1078,7 @@ struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag)
10731078
* @return Network interface related to this tag or NULL if no such interface
10741079
* exists.
10751080
*/
1076-
#if defined(CONFIG_NET_VLAN)
1081+
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
10771082
struct net_if *net_eth_get_vlan_main(struct net_if *iface);
10781083
#else
10791084
static inline
@@ -1119,7 +1124,7 @@ static inline bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
11191124
*
11201125
* @return True if VLAN is enabled for this network interface, false if not.
11211126
*/
1122-
#if defined(CONFIG_NET_VLAN)
1127+
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
11231128
bool net_eth_get_vlan_status(struct net_if *iface);
11241129
#else
11251130
static inline bool net_eth_get_vlan_status(struct net_if *iface)
@@ -1137,7 +1142,7 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
11371142
*
11381143
* @return True if this network interface is VLAN one, false if not.
11391144
*/
1140-
#if defined(CONFIG_NET_VLAN)
1145+
#if defined(CONFIG_NET_VLAN) && NET_VLAN_MAX_COUNT > 0
11411146
bool net_eth_is_vlan_interface(struct net_if *iface);
11421147
#else
11431148
static inline bool net_eth_is_vlan_interface(struct net_if *iface)

subsys/net/ip/Kconfig.ipv4

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if NET_IPV4
1313

1414
config NET_IF_MAX_IPV4_COUNT
1515
int "Max number of IPv4 network interfaces in the system"
16-
default NET_VLAN_COUNT if NET_VLAN
16+
default NET_VLAN_COUNT if NET_VLAN && NET_VLAN_COUNT > 0
1717
default 2 if NET_LOOPBACK
1818
default 1
1919
help

subsys/net/ip/Kconfig.ipv6

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if NET_IPV6
1414

1515
config NET_IF_MAX_IPV6_COUNT
1616
int "Max number of IPv6 network interfaces in the system"
17-
default NET_VLAN_COUNT if NET_VLAN
17+
default NET_VLAN_COUNT if NET_VLAN && NET_VLAN_COUNT > 0
1818
default 2 if NET_LOOPBACK
1919
default 1
2020
help

subsys/net/l2/ethernet/Kconfig

+6-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ config NET_VLAN
4141
config NET_VLAN_COUNT
4242
int "Max VLAN tags supported in the system"
4343
default 1
44-
range 1 $(UINT8_MAX)
44+
range 0 $(UINT8_MAX)
4545
depends on NET_VLAN
4646
help
47-
How many VLAN tags can be configured.
47+
How many VLAN tags can be configured. If set to 0, then only
48+
priority tagged VLAN frames with tag value 0 can be handled.
49+
This is useful if you do not want to receive any other VLAN
50+
tagged frames than tag 0. This will save some memory as the
51+
VLAN virtual interface is not created in this case.
4852

4953
config NET_VLAN_TXRX_DEBUG
5054
bool "Debug received and sent packets in VLAN"

subsys/net/l2/ethernet/ethernet.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,26 @@ static enum net_verdict ethernet_recv(struct net_if *iface,
283283
!eth_is_vlan_tag_stripped(iface)) {
284284
struct net_eth_vlan_hdr *hdr_vlan =
285285
(struct net_eth_vlan_hdr *)NET_ETH_HDR(pkt);
286+
struct net_if *vlan_iface;
286287

287288
net_pkt_set_vlan_tci(pkt, ntohs(hdr_vlan->vlan.tci));
288289
type = ntohs(hdr_vlan->type);
289290
hdr_len = sizeof(struct net_eth_vlan_hdr);
290291
is_vlan_pkt = true;
291292

292-
net_pkt_set_iface(pkt,
293-
net_eth_get_vlan_iface(iface,
294-
net_pkt_vlan_tag(pkt)));
295-
296293
/* If we receive a packet with a VLAN tag, for that we don't
297294
* have a VLAN interface, drop the packet.
298295
*/
296+
vlan_iface = net_eth_get_vlan_iface(iface,
297+
net_pkt_vlan_tag(pkt));
298+
if (vlan_iface == NULL) {
299+
NET_DBG("Dropping frame, no VLAN interface for tag %d",
300+
net_pkt_vlan_tag(pkt));
301+
goto drop;
302+
}
303+
304+
net_pkt_set_iface(pkt, vlan_iface);
305+
299306
if (net_if_l2(net_pkt_iface(pkt)) == NULL) {
300307
goto drop;
301308
}

subsys/net/l2/ethernet/vlan.c

+30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ LOG_MODULE_REGISTER(net_ethernet_vlan, CONFIG_NET_L2_ETHERNET_LOG_LEVEL);
2626
#define DEBUG_RX 0
2727
#endif
2828

29+
/* If the VLAN interface count is 0, then only priority tagged (tag 0)
30+
* Ethernet frames can be received. In this case we do not need to
31+
* allocate any memory for VLAN interfaces.
32+
*/
33+
#if CONFIG_NET_VLAN_COUNT > 0
34+
2935
#define MAX_VLAN_NAME_LEN MIN(sizeof("VLAN-<#####>"), \
3036
CONFIG_NET_INTERFACE_NAME_LEN)
3137
#define MAX_VIRT_NAME_LEN MIN(sizeof("<not attached>"), \
@@ -672,3 +678,27 @@ static void vlan_iface_init(struct net_if *iface)
672678

673679
ctx->init_done = true;
674680
}
681+
682+
#else /* CONFIG_NET_VLAN_COUNT > 0 */
683+
684+
/* Dummy functions if VLAN is not really used. This is only needed
685+
* if priority tagged frames (tag 0) are supported.
686+
*/
687+
bool net_eth_is_vlan_enabled(struct ethernet_context *ctx,
688+
struct net_if *iface)
689+
{
690+
ARG_UNUSED(ctx);
691+
ARG_UNUSED(iface);
692+
693+
return true;
694+
}
695+
696+
struct net_if *net_eth_get_vlan_iface(struct net_if *iface, uint16_t tag)
697+
{
698+
if (tag == NET_VLAN_TAG_PRIORITY) {
699+
return iface;
700+
}
701+
702+
return NULL;
703+
}
704+
#endif /* CONFIG_NET_VLAN_COUNT > 0 */

subsys/net/lib/shell/net_shell_private.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,12 @@ struct net_shell_user_data {
6464
#if !defined(NET_VLAN_MAX_COUNT)
6565
#define MAX_IFACE_COUNT NET_IF_MAX_CONFIGS
6666
#else
67+
#if NET_VLAN_MAX_COUNT > 0
6768
#define MAX_IFACE_COUNT NET_VLAN_MAX_COUNT
68-
#endif
69+
#else
70+
#define MAX_IFACE_COUNT NET_IF_MAX_CONFIGS
71+
#endif /* NET_VLAN_MAX_COUNT > 0 */
72+
#endif /* !NET_VLAN_MAX_COUNT */
6973

7074
#if defined(CONFIG_NET_IPV6) && !defined(CONFIG_NET_IPV4)
7175
#define ADDR_LEN NET_IPV6_ADDR_LEN

0 commit comments

Comments
 (0)