Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
capture.h
Go to the documentation of this file.
1
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
18#ifdef __cplusplus
19extern "C" {
20#endif
21
31struct net_if;
32struct net_pkt;
33struct device;
34
35struct net_capture_interface_api {
39 int (*cleanup)(const struct device *dev);
40
42 int (*enable)(const struct device *dev, struct net_if *iface);
43
45 int (*disable)(const struct device *dev);
46
49 bool (*is_enabled)(const struct device *dev);
50
52 int (*send)(const struct device *dev, struct net_if *iface, struct net_pkt *pkt);
53};
54
72int net_capture_setup(const char *remote_addr, const char *my_local_addr, const char *peer_addr,
73 const struct device **dev);
74
86static inline int net_capture_cleanup(const struct device *dev)
87{
88#if defined(CONFIG_NET_CAPTURE)
89 const struct net_capture_interface_api *api =
90 (const struct net_capture_interface_api *)dev->api;
91
92 return api->cleanup(dev);
93#else
94 ARG_UNUSED(dev);
95
96 return -ENOTSUP;
97#endif
98}
99
112static inline int net_capture_enable(const struct device *dev, struct net_if *iface)
113{
114#if defined(CONFIG_NET_CAPTURE)
115 const struct net_capture_interface_api *api =
116 (const struct net_capture_interface_api *)dev->api;
117
118 return api->enable(dev, iface);
119#else
120 ARG_UNUSED(dev);
121 ARG_UNUSED(iface);
122
123 return -ENOTSUP;
124#endif
125}
126
134static inline bool net_capture_is_enabled(const struct device *dev)
135{
136#if defined(CONFIG_NET_CAPTURE)
137 const struct net_capture_interface_api *api =
138 (const struct net_capture_interface_api *)dev->api;
139
140 return api->is_enabled(dev);
141#else
142 ARG_UNUSED(dev);
143
144 return false;
145#endif
146}
147
155static inline int net_capture_disable(const struct device *dev)
156{
157#if defined(CONFIG_NET_CAPTURE)
158 const struct net_capture_interface_api *api =
159 (const struct net_capture_interface_api *)dev->api;
160
161 return api->disable(dev);
162#else
163 ARG_UNUSED(dev);
164
165 return -ENOTSUP;
166#endif
167}
168
180static inline int net_capture_send(const struct device *dev, struct net_if *iface,
181 struct net_pkt *pkt)
182{
183#if defined(CONFIG_NET_CAPTURE)
184 const struct net_capture_interface_api *api =
185 (const struct net_capture_interface_api *)dev->api;
186
187 return api->send(dev, iface, pkt);
188#else
189 ARG_UNUSED(dev);
190 ARG_UNUSED(iface);
191 ARG_UNUSED(pkt);
192
193 return -ENOTSUP;
194#endif
195}
196
204#if defined(CONFIG_NET_CAPTURE)
205void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt);
206#else
207static inline void net_capture_pkt(struct net_if *iface, struct net_pkt *pkt)
208{
209 ARG_UNUSED(iface);
210 ARG_UNUSED(pkt);
211}
212#endif
213
214struct net_capture_info {
215 const struct device *capture_dev;
216 struct net_if *capture_iface;
217 struct net_if *tunnel_iface;
218 struct sockaddr *peer;
219 struct sockaddr *local;
220 bool is_enabled;
221};
222
230typedef void (*net_capture_cb_t)(struct net_capture_info *info, void *user_data);
231
241#if defined(CONFIG_NET_CAPTURE)
242void net_capture_foreach(net_capture_cb_t cb, void *user_data);
243#else
244static inline void net_capture_foreach(net_capture_cb_t cb, void *user_data)
245{
246 ARG_UNUSED(cb);
247 ARG_UNUSED(user_data);
248}
249#endif
250
257#ifdef __cplusplus
258}
259#endif
260
261#endif /* ZEPHYR_INCLUDE_NET_CAPTURE_H_ */
static ssize_t send(int sock, const void *buf, size_t len, int flags)
POSIX wrapper for zsock_send.
Definition: socket.h:803
static int net_capture_disable(const struct device *dev)
Disable network packet capturing support.
Definition: capture.h:155
static bool net_capture_is_enabled(const struct device *dev)
Is network packet capture enabled or disabled.
Definition: capture.h:134
static int net_capture_cleanup(const struct device *dev)
Cleanup network packet capturing support.
Definition: capture.h:86
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_enable(const struct device *dev, struct net_if *iface)
Enable network packet capturing support.
Definition: capture.h:112
#define ENOTSUP
Unsupported value.
Definition: errno.h:115
Public kernel APIs.
#define bool
Definition: stdbool.h:13
Runtime device structure (in ROM) per driver instance.
Definition: device.h:381
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387
Network Interface structure.
Definition: net_if.h:595
Network packet.
Definition: net_pkt.h:63
Generic sockaddr struct.
Definition: net_ip.h:347