diff --git a/include/net/net_l2.h b/include/net/net_l2.h index 6e7d419d17f..769537aebc1 100644 --- a/include/net/net_l2.h +++ b/include/net/net_l2.h @@ -33,6 +33,9 @@ enum net_l2_flags { /** Do not joint solicited node multicast group */ NET_L2_MULTICAST_SKIP_JOIN_SOLICIT_NODE = BIT(1), + + /** Is promiscuous mode supported */ + NET_L2_PROMISC_MODE = BIT(2), }; struct net_l2 { diff --git a/subsys/net/ip/net_if.c b/subsys/net/ip/net_if.c index 99fc1242d32..32eeec98c86 100644 --- a/subsys/net/ip/net_if.c +++ b/subsys/net/ip/net_if.c @@ -2382,21 +2382,25 @@ done: int net_if_set_promisc(struct net_if *iface) { + enum net_l2_flags l2_flags = 0; int ret; NET_ASSERT(iface); - /* This is currently only support for ethernet. - * TODO: support also other L2 technologies. - */ -#if defined(CONFIG_NET_L2_ETHERNET) - if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) { + if (net_if_l2(iface)->get_flags) { + l2_flags = net_if_l2(iface)->get_flags(iface); + } + + if (!(l2_flags & NET_L2_PROMISC_MODE)) { return -ENOTSUP; } - ret = net_eth_promisc_mode(iface, true); - if (ret < 0) { - return ret; +#if defined(CONFIG_NET_L2_ETHERNET) + if (net_if_l2(iface) == &NET_L2_GET_NAME(ETHERNET)) { + ret = net_eth_promisc_mode(iface, true); + if (ret < 0) { + return ret; + } } #else return -ENOTSUP; diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index 3c1caed52c3..9f50a62241c 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -939,6 +939,10 @@ void ethernet_init(struct net_if *iface) ctx->ethernet_l2_flags = NET_L2_MULTICAST; + if (net_eth_get_hw_capabilities(iface) & ETHERNET_PROMISC_MODE) { + ctx->ethernet_l2_flags |= NET_L2_PROMISC_MODE; + } + #if defined(CONFIG_NET_VLAN) if (!(net_eth_get_hw_capabilities(iface) & ETHERNET_HW_VLAN)) { return;