Zephyr Project API 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_core.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2015 Intel Corporation
9 *
10 * SPDX-License-Identifier: Apache-2.0
11 */
12
13#ifndef ZEPHYR_INCLUDE_NET_NET_CORE_H_
14#define ZEPHYR_INCLUDE_NET_NET_CORE_H_
15
16#include <stdbool.h>
17#include <string.h>
18
19#include <zephyr/logging/log.h>
20#include <zephyr/sys/__assert.h>
21#include <zephyr/kernel.h>
22
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
51/* Network subsystem logging helpers */
52#ifdef CONFIG_THREAD_NAME
53#define NET_DBG(fmt, ...) LOG_DBG("(%s): " fmt, \
54 k_thread_name_get(k_current_get()), \
55 ##__VA_ARGS__)
56#else
57#define NET_DBG(fmt, ...) LOG_DBG("(%p): " fmt, k_current_get(), \
58 ##__VA_ARGS__)
59#endif /* CONFIG_THREAD_NAME */
60#define NET_ERR(fmt, ...) LOG_ERR(fmt, ##__VA_ARGS__)
61#define NET_WARN(fmt, ...) LOG_WRN(fmt, ##__VA_ARGS__)
62#define NET_INFO(fmt, ...) LOG_INF(fmt, ##__VA_ARGS__)
63
64#define NET_HEXDUMP_DBG(_data, _length, _str) LOG_HEXDUMP_DBG(_data, _length, _str)
65#define NET_HEXDUMP_ERR(_data, _length, _str) LOG_HEXDUMP_ERR(_data, _length, _str)
66#define NET_HEXDUMP_WARN(_data, _length, _str) LOG_HEXDUMP_WRN(_data, _length, _str)
67#define NET_HEXDUMP_INFO(_data, _length, _str) LOG_HEXDUMP_INF(_data, _length, _str)
68
69#define NET_ASSERT(cond, ...) __ASSERT(cond, "" __VA_ARGS__)
70
71/* This needs to be here in order to avoid circular include dependency between
72 * net_pkt.h and net_if.h
73 */
74#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
75 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
76#if !defined(NET_PKT_DETAIL_STATS_COUNT)
77#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL)
78
79#if defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
80#define NET_PKT_DETAIL_STATS_COUNT 4
81#else
82#define NET_PKT_DETAIL_STATS_COUNT 3
83#endif /* CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
84
85#else
86#define NET_PKT_DETAIL_STATS_COUNT 4
87#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL */
88
89#endif /* !NET_PKT_DETAIL_STATS_COUNT */
90#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
91 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
92
95struct net_buf;
96struct net_pkt;
97struct net_context;
98struct net_if;
99
113
124int net_recv_data(struct net_if *iface, struct net_pkt *pkt);
125
138int net_send_data(struct net_pkt *pkt);
139
142/* Some helper defines for traffic class support */
143#if defined(CONFIG_NET_TC_TX_COUNT) && defined(CONFIG_NET_TC_RX_COUNT)
144#define NET_TC_TX_COUNT CONFIG_NET_TC_TX_COUNT
145#define NET_TC_RX_COUNT CONFIG_NET_TC_RX_COUNT
146
147#if NET_TC_TX_COUNT > NET_TC_RX_COUNT
148#define NET_TC_COUNT NET_TC_TX_COUNT
149#else
150#define NET_TC_COUNT NET_TC_RX_COUNT
151#endif
152#else /* CONFIG_NET_TC_TX_COUNT && CONFIG_NET_TC_RX_COUNT */
153#define NET_TC_TX_COUNT 0
154#define NET_TC_RX_COUNT 0
155#define NET_TC_COUNT 0
156#endif /* CONFIG_NET_TC_TX_COUNT && CONFIG_NET_TC_RX_COUNT */
157
165struct net_l3_register {
169 const char * const name;
171 const struct net_l2 * const l2;
180 enum net_verdict (*handler)(struct net_if *iface,
181 uint16_t ptype,
182 struct net_pkt *pkt);
184 uint16_t ptype;
185};
186
187#define NET_L3_GET_NAME(l3_name, ptype) __net_l3_register_##l3_name##_##ptype
188
189#define NET_L3_REGISTER(_l2_type, _name, _ptype, _handler) \
190 static const STRUCT_SECTION_ITERABLE(net_l3_register, \
191 NET_L3_GET_NAME(_name, _ptype)) = { \
192 .ptype = _ptype, \
193 .handler = _handler, \
194 .name = STRINGIFY(_name), \
195 .l2 = _l2_type, \
196 };
197
198/* @endcond */
199
204#ifdef __cplusplus
205}
206#endif
207
208#endif /* ZEPHYR_INCLUDE_NET_NET_CORE_H_ */
int net_send_data(struct net_pkt *pkt)
Send data to network.
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
Called by lower network stack or network device driver when a network packet has been received.
net_verdict
Net Verdict.
Definition net_core.h:103
@ NET_OK
Packet has been taken care of.
Definition net_core.h:105
@ NET_DROP
Packet must be dropped.
Definition net_core.h:111
@ NET_CONTINUE
Packet has not been touched, other part should decide about its fate.
Definition net_core.h:109
Public kernel APIs.
Public API for network link address.
Network timer with wrap around.
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Network buffer representation.
Definition net_buf.h:1006
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:207
Network Interface structure.
Definition net_if.h:698
Network L2 structure.
Definition net_l2.h:58
Network packet.
Definition net_pkt.h:91