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 <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2024-04-25 09:47:23 +03:00 committed by Fabio Baltieri
parent 4fe9909949
commit 07599e3a53
3 changed files with 39 additions and 0 deletions

View file

@ -971,6 +971,24 @@ static inline bool net_eth_get_vlan_status(struct net_if *iface)
} }
#endif #endif
/**
* @brief Check if the given interface is a VLAN interface.
*
* @param iface Network interface
*
* @return True if this network interface is VLAN one, false if not.
*/
#if defined(CONFIG_NET_VLAN)
bool net_eth_is_vlan_interface(struct net_if *iface);
#else
static inline bool net_eth_is_vlan_interface(struct net_if *iface)
{
ARG_UNUSED(iface);
return false;
}
#endif
#if !defined(CONFIG_ETH_DRIVER_RAW_MODE) #if !defined(CONFIG_ETH_DRIVER_RAW_MODE)
#define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \ #define Z_ETH_NET_DEVICE_INIT_INSTANCE(node_id, dev_id, name, instance, \

View file

@ -336,6 +336,22 @@ uint16_t net_eth_get_vlan_tag(struct net_if *iface)
return tag; return tag;
} }
bool net_eth_is_vlan_interface(struct net_if *iface)
{
enum virtual_interface_caps caps;
if (net_if_l2(iface) != &NET_L2_GET_NAME(VIRTUAL)) {
return false;
}
caps = net_virtual_get_iface_capabilities(iface);
if (!(caps & VIRTUAL_INTERFACE_VLAN)) {
return false;
}
return true;
}
bool net_eth_get_vlan_status(struct net_if *iface) bool net_eth_get_vlan_status(struct net_if *iface)
{ {
bool status = false; bool status = false;

View file

@ -581,6 +581,11 @@ static void test_vlan_enable(void)
ARRAY_FOR_EACH_PTR(vlan_interfaces, vlan_iface) { ARRAY_FOR_EACH_PTR(vlan_interfaces, vlan_iface) {
uint16_t tag; uint16_t tag;
ret = net_eth_is_vlan_interface(*vlan_iface);
zassert_equal(ret, true,
"Not identified as VLAN interface %d",
net_if_get_by_iface(*vlan_iface));
if (*vlan_iface == iface) { if (*vlan_iface == iface) {
tag = net_eth_get_vlan_tag(*vlan_iface); tag = net_eth_get_vlan_tag(*vlan_iface);