Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches

Network packet capture support functions. More...

Data Structures

struct  net_capture_cooked
 The context information for cooked mode capture. More...
struct  net_capture_info
 Network packet capture device information. More...

Macros

#define NET_CAPTURE_LL_ADDRLEN   8
 Maximum length of a link-layer address.

Typedefs

typedef void(* net_capture_cb_t) (struct net_capture_info *info, void *user_data)
 Callback used while iterating over capture devices.

Enumerations

enum  net_capture_packet_type {
  NET_CAPTURE_HOST , NET_CAPTURE_BROADCAST , NET_CAPTURE_MULTICAST , NET_CAPTURE_OTHERHOST ,
  NET_CAPTURE_OUTGOING
}
 The type and direction of the captured data. More...

Functions

int net_capture_setup (const char *remote_addr, const char *my_local_addr, const char *peer_addr, const struct device **dev)
 Setup network packet capturing support.
static int net_capture_cleanup (const struct device *dev)
 Cleanup network packet capturing support.
static int net_capture_enable (const struct device *dev, struct net_if *iface)
 Enable network packet capturing support.
static bool net_capture_is_enabled (const struct device *dev)
 Is network packet capture enabled or disabled.
static int net_capture_disable (const struct device *dev)
 Disable network packet capturing support.
static void net_capture_pkt (struct net_if *iface, struct net_pkt *pkt)
 Check if the network packet needs to be captured or not.
static int net_capture_cooked_setup (struct net_capture_cooked *ctx, uint16_t hatype, uint16_t halen, uint8_t *addr)
 Initialize cooked mode capture context.
static void net_capture_data (struct net_capture_cooked *ctx, const uint8_t *data, size_t len, enum net_capture_packet_type type, uint16_t ptype)
 Capture arbitrary data from source that does not have an interface.
static void net_capture_foreach (net_capture_cb_t cb, void *user_data)
 Go through all the capture devices in order to get information about them.

Detailed Description

Network packet capture support functions.

Since
2.6
Version
0.8.0

Macro Definition Documentation

◆ NET_CAPTURE_LL_ADDRLEN

#define NET_CAPTURE_LL_ADDRLEN   8

#include <capture.h>

Maximum length of a link-layer address.

Typedef Documentation

◆ net_capture_cb_t

typedef void(* net_capture_cb_t) (struct net_capture_info *info, void *user_data)

#include <capture.h>

Callback used while iterating over capture devices.

Parameters
infoInformation about capture device
user_dataA valid pointer to user data or NULL

Enumeration Type Documentation

◆ net_capture_packet_type

#include <capture.h>

The type and direction of the captured data.

Enumerator
NET_CAPTURE_HOST 

Packet was sent to us by somebody else.

NET_CAPTURE_BROADCAST 

Packet was broadcast by somebody else.

NET_CAPTURE_MULTICAST 

Packet was multicast, but not broadcast, by somebody else.

NET_CAPTURE_OTHERHOST 

Packet was sent by somebody else to somebody else.

NET_CAPTURE_OUTGOING 

Packet was sent by us.

Function Documentation

◆ net_capture_cleanup()

int net_capture_cleanup ( const struct device * dev)
inlinestatic

#include <capture.h>

Cleanup network packet capturing support.

This should be called after the capturing is done and resources can be released.

Parameters
devNetwork capture device. User must allocate using the net_capture_setup() function.
Returns
0 if ok, <0 if network packet capture cleanup failed

◆ net_capture_cooked_setup()

int net_capture_cooked_setup ( struct net_capture_cooked * ctx,
uint16_t hatype,
uint16_t halen,
uint8_t * addr )
inlinestatic

#include <capture.h>

Initialize cooked mode capture context.

Parameters
ctxCooked context struct allocated by user.
hatypeLink-layer address type
halenLink-layer address length (maximum is 8 bytes)
addrLink-layer address
Returns
0 if ok, <0 if context initialization failed

◆ net_capture_data()

void net_capture_data ( struct net_capture_cooked * ctx,
const uint8_t * data,
size_t len,
enum net_capture_packet_type type,
uint16_t ptype )
inlinestatic

#include <capture.h>

Capture arbitrary data from source that does not have an interface.

This can be used if you do not have a network interface that you want to capture from. For example low level modem device below PPP containing HDLC frames, CANBUS data or Bluetooth packets etc. The data given to this function should only contain full link layer packets so that packet boundary is not lost.

Parameters
ctxCooked mode capture context.
dataData to capture.
lenLength of the data.
typeThe direction and type of the packet (did we sent it etc).
ptypeProtocol type id. These are the ETH_P_* types set in ethernet.h

◆ net_capture_disable()

int net_capture_disable ( const struct device * dev)
inlinestatic

#include <capture.h>

Disable network packet capturing support.

Parameters
devNetwork capture device
Returns
0 if ok, <0 if network packet capture disable failed

◆ net_capture_enable()

int net_capture_enable ( const struct device * dev,
struct net_if * iface )
inlinestatic

#include <capture.h>

Enable network packet capturing support.

This creates tunnel network interface where all the captured packets are pushed. The captured network packets are placed in UDP packets that are sent to tunnel peer.

Parameters
devNetwork capture device
ifaceNetwork interface we are starting to capture packets.
Returns
0 if ok, <0 if network packet capture enable failed

◆ net_capture_foreach()

void net_capture_foreach ( net_capture_cb_t cb,
void * user_data )
inlinestatic

#include <capture.h>

Go through all the capture devices in order to get information about them.

This is mainly useful in net-shell to print data about currently active captures.

Parameters
cbCallback to call for each capture device
user_dataUser supplied data

◆ net_capture_is_enabled()

bool net_capture_is_enabled ( const struct device * dev)
inlinestatic

#include <capture.h>

Is network packet capture enabled or disabled.

Parameters
devNetwork capture device. If set to NULL, then the default capture device is used.
Returns
True if enabled, False if network capture is disabled.

◆ net_capture_pkt()

void net_capture_pkt ( struct net_if * iface,
struct net_pkt * pkt )
inlinestatic

#include <capture.h>

Check if the network packet needs to be captured or not.

This is called for every network packet being sent.

Parameters
ifaceNetwork interface the packet is being sent
pktThe network packet that is sent

◆ net_capture_setup()

int net_capture_setup ( const char * remote_addr,
const char * my_local_addr,
const char * peer_addr,
const struct device ** dev )

#include <capture.h>

Setup network packet capturing support.

Parameters
remote_addrThe value tells the tunnel remote/outer endpoint IP address. The IP address can be either IPv4 or IPv6 address. This address is used to select the network interface where the tunnel is created.
my_local_addrThe local/inner IP address of the tunnel. Can contain also port number which is used as UDP source port.
peer_addrThe peer/inner IP address of the tunnel. Can contain also port number which is used as UDP destination port.
devNetwork capture device. This is returned to the caller.
Returns
0 if ok, <0 if network packet capture setup failed