Skip to content

Commit f92b43c

Browse files
committed
[nrf fromtree] net: vlan: Add a function to check if interface is VLAN one
We were missing a helper function that can be used to check whether the given function is the virtual VLAN interface. Signed-off-by: Jukka Rissanen <[email protected]> (cherry picked from commit 07599e3) Signed-off-by: Robert Lubos <[email protected]>
1 parent ea89f1f commit f92b43c

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

include/zephyr/net/ethernet.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,24 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
971971
}
972972
#endif
973973

974+
/**
975+
* @brief Check if the given interface is a VLAN interface.
976+
*
977+
* @param iface Network interface
978+
*
979+
* @return True if this network interface is VLAN one, false if not.
980+
*/
981+
#if defined(CONFIG_NET_VLAN)
982+
bool net_eth_is_vlan_interface(struct net_if *iface);
983+
#else
984+
static inline bool net_eth_is_vlan_interface(struct net_if *iface)
985+
{
986+
ARG_UNUSED(iface);
987+
988+
return false;
989+
}
990+
#endif
991+
974992
#if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
975993

976994
#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \

subsys/net/l2/ethernet/vlan.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,22 @@ uint16_t net_eth_get_vlan_tag(struct net_if *iface)
336336
return tag;
337337
}
338338

339+
bool net_eth_is_vlan_interface(struct net_if *iface)
340+
{
341+
enum virtual_interface_caps caps;
342+
343+
if (net_if_l2(iface) != &NET_L2_GET_NAME(VIRTUAL)) {
344+
return false;
345+
}
346+
347+
caps = net_virtual_get_iface_capabilities(iface);
348+
if (!(caps & VIRTUAL_INTERFACE_VLAN)) {
349+
return false;
350+
}
351+
352+
return true;
353+
}
354+
339355
bool net_eth_get_vlan_status(struct net_if *iface)
340356
{
341357
bool status = false;

tests/net/vlan/src/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,11 @@ static void test_vlan_enable(void)
581581
ARRAY_FOR_EACH_PTR(vlan_interfaces, vlan_iface) {
582582
uint16_t tag;
583583

584+
ret = net_eth_is_vlan_interface(*vlan_iface);
585+
zassert_equal(ret, true,
586+
"Not identified as VLAN interface %d",
587+
net_if_get_by_iface(*vlan_iface));
588+
584589
if (*vlan_iface == iface) {
585590
tag = net_eth_get_vlan_tag(*vlan_iface);
586591

0 commit comments

Comments
 (0)