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>
This commit is contained in:
parent
6eef4ac390
commit
ce2abc26b5
10 changed files with 32 additions and 4 deletions
|
@ -12,7 +12,9 @@
|
|||
#ifndef ZEPHYR_INCLUDE_NET_NET_L2_H_
|
||||
#define ZEPHYR_INCLUDE_NET_NET_L2_H_
|
||||
|
||||
#include <device.h>
|
||||
#include <net/buf.h>
|
||||
#include <net/capture.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -144,6 +146,18 @@ NET_L2_DECLARE_PUBLIC(CANBUS_L2);
|
|||
#define NET_L2_DATA_INIT(name, sfx, ctx_type) \
|
||||
static ctx_type NET_L2_GET_DATA(name, sfx) __used;
|
||||
|
||||
typedef int (*net_l2_send_t)(const struct device *dev, struct net_pkt *pkt);
|
||||
|
||||
static inline int net_l2_send(net_l2_send_t send_fn,
|
||||
const struct device *dev,
|
||||
struct net_if *iface,
|
||||
struct net_pkt *pkt)
|
||||
{
|
||||
net_capture_pkt(iface, pkt);
|
||||
|
||||
return send_fn(dev, pkt);
|
||||
}
|
||||
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,6 +29,7 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL);
|
|||
#include <net/gptp.h>
|
||||
#include <net/websocket.h>
|
||||
#include <net/ethernet.h>
|
||||
#include <net/capture.h>
|
||||
|
||||
#if defined(CONFIG_NET_LLDP)
|
||||
#include <net/lldp.h>
|
||||
|
@ -371,6 +372,8 @@ static void process_rx_packet(struct k_work *work)
|
|||
|
||||
net_pkt_set_rx_stats_tick(pkt, k_cycle_get_32());
|
||||
|
||||
net_capture_pkt(net_pkt_iface(pkt), pkt);
|
||||
|
||||
net_rx(net_pkt_iface(pkt), pkt);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ LOG_MODULE_REGISTER(net_bt, CONFIG_NET_L2_BT_LOG_LEVEL);
|
|||
#include <net/net_core.h>
|
||||
#include <net/net_l2.h>
|
||||
#include <net/net_if.h>
|
||||
#include <net/capture.h>
|
||||
#include <net/bt.h>
|
||||
#include <6lo.h>
|
||||
|
||||
|
@ -108,6 +109,8 @@ static int net_bt_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
|
||||
length = net_pkt_get_len(pkt);
|
||||
|
||||
net_capture_pkt(iface, pkt);
|
||||
|
||||
/* Dettach data fragments for packet */
|
||||
buffer = pkt->buffer;
|
||||
pkt->buffer = NULL;
|
||||
|
|
|
@ -10,6 +10,7 @@ LOG_MODULE_REGISTER(net_l2_canbus, CONFIG_NET_L2_CANBUS_LOG_LEVEL);
|
|||
#include <net/net_core.h>
|
||||
#include <net/net_l2.h>
|
||||
#include <net/net_if.h>
|
||||
#include <net/capture.h>
|
||||
#include <net/net_pkt.h>
|
||||
#include <net/can.h>
|
||||
#include "canbus_internal.h"
|
||||
|
@ -1084,6 +1085,8 @@ static int canbus_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
net_pkt_cursor_init(pkt);
|
||||
pkt_len = net_pkt_get_len(pkt);
|
||||
|
||||
net_capture_pkt(iface, pkt);
|
||||
|
||||
NET_DBG("Send CAN frame to 0x%04x%s", dest_addr.addr,
|
||||
mcast ? " (mcast)" : "");
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ static inline int canbus_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
ret = api->send(net_if_get_device(iface), pkt);
|
||||
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);
|
||||
|
|
|
@ -36,7 +36,7 @@ static inline int dummy_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
ret = api->send(net_if_get_device(iface), pkt);
|
||||
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);
|
||||
|
|
|
@ -670,7 +670,7 @@ static int ethernet_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
net_pkt_cursor_init(pkt);
|
||||
|
||||
send:
|
||||
ret = api->send(net_if_get_device(iface), pkt);
|
||||
ret = net_l2_send(api->send, net_if_get_device(iface), iface, pkt);
|
||||
if (ret != 0) {
|
||||
eth_stats_update_errors_tx(iface);
|
||||
ethernet_remove_l2_header(pkt);
|
||||
|
|
|
@ -10,6 +10,7 @@ LOG_MODULE_REGISTER(net_ieee802154, CONFIG_NET_L2_IEEE802154_LOG_LEVEL);
|
|||
#include <net/net_core.h>
|
||||
#include <net/net_l2.h>
|
||||
#include <net/net_if.h>
|
||||
#include <net/capture.h>
|
||||
|
||||
#include "ipv6.h"
|
||||
|
||||
|
@ -251,6 +252,8 @@ static int ieee802154_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
return len;
|
||||
}
|
||||
|
||||
net_capture_pkt(iface, pkt);
|
||||
|
||||
fragment = ieee802154_fragment_is_needed(pkt, ll_hdr_size);
|
||||
ieee802154_fragment_ctx_init(&f_ctx, pkt, len, true);
|
||||
|
||||
|
|
|
@ -320,6 +320,8 @@ int openthread_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
net_pkt_hexdump(pkt, "IPv6 packet to send");
|
||||
}
|
||||
|
||||
net_capture_pkt(iface, pkt);
|
||||
|
||||
if (notify_new_tx_frame(pkt) != 0) {
|
||||
net_pkt_unref(pkt);
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ static int ppp_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
return -ENETDOWN;
|
||||
}
|
||||
|
||||
ret = api->send(net_if_get_device(iface), pkt);
|
||||
ret = net_l2_send(api->send, net_if_get_device(iface), iface, pkt);
|
||||
if (!ret) {
|
||||
ret = net_pkt_get_len(pkt);
|
||||
ppp_update_tx_stats(iface, pkt, ret);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue