zephyr/subsys/net/l2/dummy/dummy.c
Jukka Rissanen ce2abc26b5 net: capture: Catch sent and received packets
Create net_l2_send() function which will be called by each L2
sending function so that we can catch all the network packets
that are being sent. Some L2 layers send things a bit differently,
so in those cases call the net_capture_send() directly by the L2
layer.
Add network packet capture call in receive side after the pkt has
been received by the RX queue handler. This avoids calling the
net_capture_send() from ISR context.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2021-04-02 07:24:06 -04:00

54 lines
1.1 KiB
C

/*
* Copyright (c) 2016 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <logging/log.h>
LOG_MODULE_REGISTER(net_l2_dummy, LOG_LEVEL_NONE);
#include <net/net_core.h>
#include <net/net_l2.h>
#include <net/net_if.h>
#include <net/net_pkt.h>
#include <net/dummy.h>
static inline enum net_verdict dummy_recv(struct net_if *iface,
struct net_pkt *pkt)
{
net_pkt_lladdr_src(pkt)->addr = NULL;
net_pkt_lladdr_src(pkt)->len = 0U;
net_pkt_lladdr_src(pkt)->type = NET_LINK_DUMMY;
net_pkt_lladdr_dst(pkt)->addr = NULL;
net_pkt_lladdr_dst(pkt)->len = 0U;
net_pkt_lladdr_dst(pkt)->type = NET_LINK_DUMMY;
return NET_CONTINUE;
}
static inline int dummy_send(struct net_if *iface, struct net_pkt *pkt)
{
const struct dummy_api *api = net_if_get_device(iface)->api;
int ret;
if (!api) {
return -ENOENT;
}
ret = net_l2_send(api->send, net_if_get_device(iface), iface, pkt);
if (!ret) {
ret = net_pkt_get_len(pkt);
net_pkt_unref(pkt);
}
return ret;
}
static enum net_l2_flags dummy_flags(struct net_if *iface)
{
return NET_L2_MULTICAST;
}
NET_L2_INIT(DUMMY_L2, dummy_recv, dummy_send, NULL, dummy_flags);