zephyr/subsys/net/ip/promiscuous.c
Ulf Magnusson 984bfae831 global: Remove leading/trailing blank lines in files
Remove leading/trailing blank lines in .c, .h, .py, .rst, .yml, and
.yaml files.

Will avoid failures with the new CI test in
https://github.com/zephyrproject-rtos/ci-tools/pull/112, though it only
checks changed files.

Move the 'target-notes' target in boards/xtensa/odroid_go/doc/index.rst
to get rid of the trailing blank line there. It was probably misplaced.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-12-11 19:17:27 +01:00

99 lines
1.5 KiB
C

/** @file
* @brief Promiscuous mode support
*
* Allow user to receive all network packets that are seen by a
* network interface. This requires that network device driver
* supports promiscuous mode.
*/
/*
* Copyright (c) 2018 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <logging/log.h>
LOG_MODULE_REGISTER(net_promisc, CONFIG_NET_PROMISC_LOG_LEVEL);
#include <kernel.h>
#include <errno.h>
#include <net/net_if.h>
#include <net/net_core.h>
#include <net/net_pkt.h>
static K_FIFO_DEFINE(promiscuous_queue);
static atomic_t enabled = ATOMIC_INIT(0);
struct net_pkt *net_promisc_mode_wait_data(s32_t timeout)
{
return k_fifo_get(&promiscuous_queue, timeout);
}
int net_promisc_mode_on(struct net_if *iface)
{
int ret;
if (!iface) {
return -EINVAL;
}
ret = net_if_set_promisc(iface);
if (!ret) {
atomic_inc(&enabled);
}
return ret;
}
static void flush_queue(void)
{
struct net_pkt *pkt;
while (1) {
pkt = k_fifo_get(&promiscuous_queue, K_NO_WAIT);
if (!pkt) {
return;
}
net_pkt_unref(pkt);
}
}
int net_promisc_mode_off(struct net_if *iface)
{
atomic_val_t prev;
bool ret;
ret = net_if_is_promisc(iface);
if (ret) {
net_if_unset_promisc(iface);
prev = atomic_dec(&enabled);
if (prev == 1) {
atomic_clear(&enabled);
flush_queue();
}
return 0;
}
return -EALREADY;
}
enum net_verdict net_promisc_mode_input(struct net_pkt *pkt)
{
if (!pkt) {
return NET_CONTINUE;
}
if (!atomic_get(&enabled)) {
return NET_DROP;
}
k_fifo_put(&promiscuous_queue, pkt);
return NET_OK;
}