Skip to content
Permalink
Browse files

net: if: Add promiscuous mode set / unset functionality

User is able to set the network interface to promiscuous mode
and query the promisc mode status.

Note that currently this is only supported for ethernet bearer.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information...
jukkar committed Jul 20, 2018
1 parent 72f75e5 commit b19cb207cb2b5d1b54f8af7ce8f8da4c6da231a5
Showing with 75 additions and 0 deletions.
  1. +31 −0 include/net/net_if.h
  2. +44 −0 subsys/net/ip/net_if.c
@@ -161,6 +161,9 @@ enum {
/* interface is pointopoint */
NET_IF_POINTOPOINT,

/* interface is in promiscuous mode */
NET_IF_PROMISC,

/* Total number of flags - must be at the end of the enum */
NET_IF_NUM_FLAGS
};
@@ -1673,6 +1676,34 @@ void net_if_call_timestamp_cb(struct net_pkt *pkt);
void net_if_add_tx_timestamp(struct net_pkt *pkt);
#endif /* CONFIG_NET_PKT_TIMESTAMP */

/**
* @brief Set network interface into promiscuous mode
*
* @details Note that not all network technologies will support this.
*
* @param iface Pointer to network interface
*
* @return 0 on success, <0 if error
*/
int net_if_set_promisc(struct net_if *iface);

/**
* @brief Set network interface into normal mode
*
* @param iface Pointer to network interface
*/
void net_if_unset_promisc(struct net_if *iface);

/**
* @brief Check if promiscuous mode is set or not.
*
* @param iface Pointer to network interface
*
* @return True if interface is in promisc mode,
* False if interface is not in in promiscuous mode.
*/
bool net_if_is_promisc(struct net_if *iface);

struct net_if_api {
void (*init)(struct net_if *iface);
int (*send)(struct net_if *iface, struct net_pkt *pkt);
@@ -2315,6 +2315,50 @@ int net_if_down(struct net_if *iface)
return 0;
}

int net_if_set_promisc(struct net_if *iface)
{
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)) {
return -ENOTSUP;
}

ret = net_eth_promisc_mode(iface, true);
if (ret < 0) {
return ret;
}
#else
return -ENOTSUP;
#endif

ret = atomic_test_and_set_bit(iface->if_dev->flags, NET_IF_PROMISC);
if (ret) {
return -EALREADY;
}

return 0;
}

void net_if_unset_promisc(struct net_if *iface)
{
NET_ASSERT(iface);

atomic_clear_bit(iface->if_dev->flags, NET_IF_PROMISC);
}

bool net_if_is_promisc(struct net_if *iface)
{
NET_ASSERT(iface);

return atomic_test_bit(iface->if_dev->flags, NET_IF_PROMISC);
}

#if defined(CONFIG_NET_PKT_TIMESTAMP)
static void net_tx_ts_thread(void)
{

0 comments on commit b19cb20

Please sign in to comment.
You can’t perform that action at this time.