Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
capture.h
Go to the documentation of this file.
1
6
7/*
8 * Copyright (c) 2021 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_CAPTURE_H_
14#define ZEPHYR_INCLUDE_NET_CAPTURE_H_
15
16#include <zephyr/kernel.h>
17#include <zephyr/device.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
31
33
34struct net_if;
35struct net_pkt;
36struct device;
37
38struct net_capture_interface_api {
42 int (*cleanup)(const struct device *dev);
43
45 int (*enable)(const struct device *dev, struct net_if *iface);
46
48 int (*disable)(const struct device *dev);
49
52 bool (*is_enabled)(const struct device *dev);
53
55 int (*send)(const struct device *dev, struct net_if *iface, struct net_pkt *pkt);
56};
57
59
75int net_capture_setup(const char *remote_addr, const char *my_local_addr, const char *peer_addr,
76 const struct device **dev);
77
89static inline int net_capture_cleanup(const struct device *dev)
90{
91#if defined(CONFIG_NET_CAPTURE)
92 const struct net_capture_interface_api *api =
93 (const struct net_capture_interface_api *)dev->api;
94
95 return api->cleanup(dev);
96#else
97 ARG_UNUSED(dev);
98
99 return -ENOTSUP;
100#endif
101}
102
115static inline int net_capture_enable(const struct device *dev, struct net_if *iface)
116{
117#if defined(CONFIG_NET_CAPTURE)
118 const struct net_capture_interface_api *api =
119 (const struct net_capture_interface_api *)dev->api;
120
121 return api->enable(dev, iface);
122#else
123 ARG_UNUSED(dev);
124 ARG_UNUSED(iface);
125
126 return -ENOTSUP;
127#endif
128}
129
138static inline bool net_capture_is_enabled(const struct device *dev)
139{
140#if defined(CONFIG_NET_CAPTURE)
141 const struct net_capture_interface_api *api;
142
143 if (dev == NULL) {
144 /* TODO: Go through all capture devices instead of one */
145 dev = device_get_binding("NET_CAPTURE0");
146 if (dev == NULL) {
147 return false;
148 }
149 }
150
151 api = (const struct net_capture_interface_api *)dev->api;
152
153 return api->is_enabled(dev);
154#else
155 ARG_UNUSED(dev);
156
157 return false;
158#endif
159}
160
168static inline int net_capture_disable(const struct device *dev)
169{
170#if defined(CONFIG_NET_CAPTURE)
171 const struct net_capture_interface_api *api =
172 (const struct net_capture_interface_api *)dev->api;
173
174 return api->disable(dev);
175#else
176 ARG_UNUSED(dev);
177
178 return -ENOTSUP;
179#endif
180}
181
183
193static inline int net_capture_send(const struct device *dev, struct net_if *iface,
194 struct net_pkt *pkt)
195{
196#if defined(CONFIG_NET_CAPTURE)
197 const struct net_capture_interface_api *api =
198 (const struct net_capture_interface_api *)dev->api;
199
200 return api->send(dev, iface, pkt);
201#else
202 ARG_UNUSED(dev);
203 ARG_UNUSED(iface);
204 ARG_UNUSED(pkt);
205
206 return -ENOTSUP;
207#endif
208}
209
211
219#if defined(CONFIG_NET_CAPTURE)
220void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt);
221#else
222static inline void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt)
223{
224 ARG_UNUSED(iface);
225 ARG_UNUSED(pkt);
226}
227#endif
228
230
240#if defined(CONFIG_NET_CAPTURE)
241int net_capture_pkt_with_status(struct net_if *iface, struct net_pkt *pkt);
242#else
243static inline int net_capture_pkt_with_status(struct net_if *iface, struct net_pkt *pkt)
244{
245 ARG_UNUSED(iface);
246 ARG_UNUSED(pkt);
247
248 return -ENOTSUP;
249}
250#endif
251
253
262
263#define NET_CAPTURE_LL_ADDRLEN 8
264
274
285#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
287 uint16_t hatype,
288 uint16_t halen,
289 uint8_t *addr);
290#else
291static inline int net_capture_cooked_setup(struct net_capture_cooked *ctx,
292 uint16_t hatype,
293 uint16_t halen,
294 uint8_t *addr)
295{
296 ARG_UNUSED(ctx);
297 ARG_UNUSED(hatype);
298 ARG_UNUSED(halen);
299 ARG_UNUSED(addr);
300
301 return -ENOTSUP;
302}
303#endif
304
319#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
320void net_capture_data(struct net_capture_cooked *ctx,
321 const uint8_t *data, size_t len,
322 enum net_capture_packet_type type,
323 uint16_t ptype);
324#else
325static inline void net_capture_data(struct net_capture_cooked *ctx,
326 const uint8_t *data, size_t len,
327 enum net_capture_packet_type type,
328 uint16_t ptype)
329{
330 ARG_UNUSED(ctx);
331 ARG_UNUSED(data);
332 ARG_UNUSED(len);
333 ARG_UNUSED(type);
334 ARG_UNUSED(ptype);
335}
336#endif
337
353
361typedef void (*net_capture_cb_t)(struct net_capture_info *info, void *user_data);
362
372#if defined(CONFIG_NET_CAPTURE)
373void net_capture_foreach(net_capture_cb_t cb, void *user_data);
374#else
375static inline void net_capture_foreach(net_capture_cb_t cb, void *user_data)
376{
377 ARG_UNUSED(cb);
378 ARG_UNUSED(user_data);
379}
380#endif
381
385
386#ifdef __cplusplus
387}
388#endif
389
390#endif /* ZEPHYR_INCLUDE_NET_CAPTURE_H_ */
const struct device * device_get_binding(const char *name)
Get a device reference from its device::name field.
static int net_capture_disable(const struct device *dev)
Disable network packet capturing support.
Definition capture.h:168
static void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt)
Check if the network packet needs to be captured or not.
Definition capture.h:222
static bool net_capture_is_enabled(const struct device *dev)
Is network packet capture enabled or disabled.
Definition capture.h:138
static int net_capture_cleanup(const struct device *dev)
Cleanup network packet capturing support.
Definition capture.h:89
net_capture_packet_type
The type and direction of the captured data.
Definition capture.h:255
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.
Definition capture.h:291
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 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.
Definition capture.h:325
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.
Definition capture.h:375
#define NET_CAPTURE_LL_ADDRLEN
Maximum length of a link-layer address.
Definition capture.h:263
void(* net_capture_cb_t)(struct net_capture_info *info, void *user_data)
Callback used while iterating over capture devices.
Definition capture.h:361
static int net_capture_enable(const struct device *dev, struct net_if *iface)
Enable network packet capturing support.
Definition capture.h:115
@ NET_CAPTURE_MULTICAST
Packet was multicast, but not broadcast, by somebody else.
Definition capture.h:258
@ NET_CAPTURE_BROADCAST
Packet was broadcast by somebody else.
Definition capture.h:257
@ NET_CAPTURE_HOST
Packet was sent to us by somebody else.
Definition capture.h:256
@ NET_CAPTURE_OTHERHOST
Packet was sent by somebody else to somebody else.
Definition capture.h:259
@ NET_CAPTURE_OUTGOING
Packet was sent by us.
Definition capture.h:260
#define ENOTSUP
Unsupported value.
Definition errno.h:115
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
ssize_t send(int sock, const void *buf, size_t len, int flags)
#define bool
Definition stdbool.h:13
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519
The context information for cooked mode capture.
Definition capture.h:266
uint16_t hatype
Link-layer address type.
Definition capture.h:268
uint8_t addr[8]
Link-layer address.
Definition capture.h:272
uint16_t halen
Link-layer address length.
Definition capture.h:270
Network packet capture device information.
Definition capture.h:339
struct net_sockaddr * peer
Peer (inner) tunnel IP address.
Definition capture.h:347
bool is_enabled
Is the capture currently enabled.
Definition capture.h:351
struct net_if * tunnel_iface
IPIP tunnel network interface where the captured packets are sent.
Definition capture.h:345
struct net_sockaddr * local
Local (inner) tunnel IP address.
Definition capture.h:349
struct net_if * capture_iface
Network interface where the network packets are captured.
Definition capture.h:343
const struct device * capture_dev
The capture device.
Definition capture.h:341
Network Interface structure.
Definition net_if.h:744
Network packet.
Definition net_pkt.h:119
Generic sockaddr struct.
Definition net_ip.h:455