16#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
17#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
24#if defined(CONFIG_IEEE802154)
52struct net_pkt_cursor {
94#if defined(CONFIG_NET_TCP)
98#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
102#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
124#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
129#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
130 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
153#if defined(CONFIG_NET_IP)
170#if defined(CONFIG_NET_IPV4_ACD)
177#if defined(CONFIG_NET_LLDP)
198#if defined(CONFIG_NET_IP_FRAGMENT)
201#if defined(CONFIG_NET_PKT_TIMESTAMP)
207#if defined(CONFIG_NET_IP)
212#if defined(CONFIG_NET_IPV6)
215#if defined(CONFIG_NET_IPV4)
221#if defined(CONFIG_NET_IPV4)
224#if defined(CONFIG_NET_IPV6)
229#if defined(CONFIG_NET_IP_FRAGMENT)
231#if defined(CONFIG_NET_IPV4_FRAGMENT)
237#if defined(CONFIG_NET_IPV6_FRAGMENT)
247#if defined(CONFIG_NET_IPV6)
259#if defined(CONFIG_NET_IP_DSCP_ECN)
268#if defined(CONFIG_NET_VLAN)
277#if defined(NET_PKT_HAS_CONTROL_BLOCK)
282#if defined(CONFIG_IEEE802154)
286 struct net_pkt_cb_ieee802154 cb;
295#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
307 struct sockaddr_storage remote_storage;
311#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
332static inline void net_pkt_set_context(
struct net_pkt *pkt,
338static inline struct net_if *net_pkt_iface(
struct net_pkt *pkt)
343static inline void net_pkt_set_iface(
struct net_pkt *pkt,
struct net_if *iface)
354 pkt->lladdr_src.type = type;
355 pkt->lladdr_dst.type = type;
359static inline struct net_if *net_pkt_orig_iface(
struct net_pkt *pkt)
361#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
362 return pkt->orig_iface;
368static inline void net_pkt_set_orig_iface(
struct net_pkt *pkt,
371#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
372 pkt->orig_iface = iface;
384static inline void net_pkt_set_family(
struct net_pkt *pkt,
uint8_t family)
386 pkt->family = family;
389static inline bool net_pkt_is_ptp(
struct net_pkt *pkt)
391 return !!(pkt->ptp_pkt);
394static inline void net_pkt_set_ptp(
struct net_pkt *pkt,
bool is_ptp)
396 pkt->ptp_pkt = is_ptp;
399static inline bool net_pkt_is_tx_timestamping(
struct net_pkt *pkt)
401#if defined(CONFIG_NET_PKT_TIMESTAMP)
402 return !!(pkt->tx_timestamping);
410static inline void net_pkt_set_tx_timestamping(
struct net_pkt *pkt,
bool is_timestamping)
412#if defined(CONFIG_NET_PKT_TIMESTAMP)
413 pkt->tx_timestamping = is_timestamping;
416 ARG_UNUSED(is_timestamping);
420static inline bool net_pkt_is_rx_timestamping(
struct net_pkt *pkt)
422#if defined(CONFIG_NET_PKT_TIMESTAMP)
423 return !!(pkt->rx_timestamping);
431static inline void net_pkt_set_rx_timestamping(
struct net_pkt *pkt,
bool is_timestamping)
433#if defined(CONFIG_NET_PKT_TIMESTAMP)
434 pkt->rx_timestamping = is_timestamping;
437 ARG_UNUSED(is_timestamping);
441static inline bool net_pkt_is_captured(
struct net_pkt *pkt)
443 return !!(pkt->captured);
446static inline void net_pkt_set_captured(
struct net_pkt *pkt,
bool is_captured)
448 pkt->captured = is_captured;
451static inline bool net_pkt_is_l2_bridged(
struct net_pkt *pkt)
453 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
456static inline void net_pkt_set_l2_bridged(
struct net_pkt *pkt,
bool is_l2_bridged)
459 pkt->l2_bridged = is_l2_bridged;
463static inline bool net_pkt_is_l2_processed(
struct net_pkt *pkt)
465 return !!(pkt->l2_processed);
468static inline void net_pkt_set_l2_processed(
struct net_pkt *pkt,
469 bool is_l2_processed)
471 pkt->l2_processed = is_l2_processed;
474static inline bool net_pkt_is_chksum_done(
struct net_pkt *pkt)
476 return !!(pkt->chksum_done);
479static inline void net_pkt_set_chksum_done(
struct net_pkt *pkt,
482 pkt->chksum_done = is_chksum_done;
487#if defined(CONFIG_NET_IP)
488 return pkt->ip_hdr_len;
496static inline void net_pkt_set_ip_hdr_len(
struct net_pkt *pkt,
uint8_t len)
498#if defined(CONFIG_NET_IP)
499 pkt->ip_hdr_len = len;
508#if defined(CONFIG_NET_IP_DSCP_ECN)
517static inline void net_pkt_set_ip_dscp(
struct net_pkt *pkt,
uint8_t dscp)
519#if defined(CONFIG_NET_IP_DSCP_ECN)
529#if defined(CONFIG_NET_IP_DSCP_ECN)
538static inline void net_pkt_set_ip_ecn(
struct net_pkt *pkt,
uint8_t ecn)
540#if defined(CONFIG_NET_IP_DSCP_ECN)
553static inline void net_pkt_set_eof(
struct net_pkt *pkt,
bool eof)
558static inline bool net_pkt_forwarding(
struct net_pkt *pkt)
560 return !!(pkt->forwarding);
563static inline void net_pkt_set_forwarding(
struct net_pkt *pkt,
bool forward)
565 pkt->forwarding = forward;
568#if defined(CONFIG_NET_IPV4)
571 return pkt->ipv4_ttl;
574static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
582 return pkt->ipv4_opts_len;
585static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
588 pkt->ipv4_opts_len = opts_len;
598static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
611static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
615 ARG_UNUSED(opts_len);
619#if defined(CONFIG_NET_IPV6)
620static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
622 return pkt->ipv6_ext_opt_len;
625static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
628 pkt->ipv6_ext_opt_len = len;
633 return pkt->ipv6_next_hdr;
636static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
639 pkt->ipv6_next_hdr = next_hdr;
644 return pkt->ipv6_ext_len;
647static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
649 pkt->ipv6_ext_len = len;
654 return pkt->ipv6_prev_hdr_start;
657static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
660 pkt->ipv6_prev_hdr_start = offset;
665 return pkt->ipv6_hop_limit;
668static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
671 pkt->ipv6_hop_limit = hop_limit;
674static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
681static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
695static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
699 ARG_UNUSED(next_hdr);
709static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
722static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
736static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
740 ARG_UNUSED(hop_limit);
746#if defined(CONFIG_NET_IPV6)
747 return pkt->ipv6_ext_len;
748#elif defined(CONFIG_NET_IPV4)
749 return pkt->ipv4_opts_len;
757#if defined(CONFIG_NET_IPV4_FRAGMENT)
758static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
760 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
763static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
765 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
770 pkt->ipv4_fragment.flags =
flags;
775 return pkt->ipv4_fragment.id;
778static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
780 pkt->ipv4_fragment.id = id;
783static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
790static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
810static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
817#if defined(CONFIG_NET_IPV6_FRAGMENT)
820 return pkt->ipv6_fragment.hdr_start;
823static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
826 pkt->ipv6_fragment.hdr_start = start;
829static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
831 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
833static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
835 return (pkt->ipv6_fragment.flags & 0x01) != 0;
838static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
841 pkt->ipv6_fragment.flags =
flags;
846 return pkt->ipv6_fragment.id;
849static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
852 pkt->ipv6_fragment.id = id;
862static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
869static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
876static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
883static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
897static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
905#if defined(CONFIG_NET_IP_FRAGMENT)
906static inline bool net_pkt_is_ip_reassembled(
struct net_pkt *pkt)
908 return !!(pkt->ip_reassembled);
911static inline void net_pkt_set_ip_reassembled(
struct net_pkt *pkt,
914 pkt->ip_reassembled = reassembled;
917static inline bool net_pkt_is_ip_reassembled(
struct net_pkt *pkt)
924static inline void net_pkt_set_ip_reassembled(
struct net_pkt *pkt,
928 ARG_UNUSED(reassembled);
934 return pkt->priority;
937static inline void net_pkt_set_priority(
struct net_pkt *pkt,
940 pkt->priority = priority;
943#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
944static inline bool net_pkt_is_cooked_mode(
struct net_pkt *pkt)
946 return pkt->cooked_mode_pkt;
949static inline void net_pkt_set_cooked_mode(
struct net_pkt *pkt,
bool value)
951 pkt->cooked_mode_pkt = value;
954static inline bool net_pkt_is_cooked_mode(
struct net_pkt *pkt)
961static inline void net_pkt_set_cooked_mode(
struct net_pkt *pkt,
bool value)
968#if defined(CONFIG_NET_VLAN)
984static inline void net_pkt_set_vlan_priority(
struct net_pkt *pkt,
990static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
995static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
1000static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
1002 pkt->vlan_tci = tci;
1007 return pkt->vlan_tci;
1030static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
1037static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
1050static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
1057#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1060 return &pkt->timestamp;
1063static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
1066 pkt->timestamp.second = timestamp->
second;
1067 pkt->timestamp.nanosecond = timestamp->
nanosecond;
1075static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
1087static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
1091 ARG_UNUSED(timestamp);
1101static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
1104 ARG_UNUSED(timestamp);
1108#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
1111 return pkt->create_time;
1114static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
1117 pkt->create_time = create_time;
1127static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
1131 ARG_UNUSED(create_time);
1140#if defined(CONFIG_NET_PKT_TXTIME)
1141 return pkt->timestamp.second *
NSEC_PER_SEC + pkt->timestamp.nanosecond;
1153static inline void net_pkt_set_txtime(
struct net_pkt *pkt,
uint64_t txtime)
1155#if defined(CONFIG_NET_PKT_TXTIME)
1164#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1165 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1168 return pkt->detail.stat;
1171static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1173 return pkt->detail.count;
1176static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1178 memset(&pkt->detail, 0,
sizeof(pkt->detail));
1184 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1185 NET_ERR(
"Detail stats count overflow (%d >= %d)",
1186 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1190 pkt->detail.stat[pkt->detail.count++] = tick;
1193#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1194#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1203static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1210static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1215static inline void net_pkt_set_stats_tick(
struct net_pkt *pkt,
uint32_t tick)
1221#define net_pkt_set_tx_stats_tick(pkt, tick)
1222#define net_pkt_set_rx_stats_tick(pkt, tick)
1226static inline size_t net_pkt_get_len(
struct net_pkt *pkt)
1241static inline bool net_pkt_is_empty(
struct net_pkt *pkt)
1248 return &pkt->lladdr_src;
1253 return &pkt->lladdr_dst;
1256static inline void net_pkt_lladdr_swap(
struct net_pkt *pkt)
1260 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1261 net_pkt_lladdr_dst(pkt)->addr =
addr;
1264static inline void net_pkt_lladdr_clear(
struct net_pkt *pkt)
1266 net_pkt_lladdr_src(pkt)->addr = NULL;
1267 net_pkt_lladdr_src(pkt)->len = 0U;
1272 return pkt->ll_proto_type;
1277 pkt->ll_proto_type =
type;
1280#if defined(CONFIG_NET_IPV4_ACD)
1281static inline bool net_pkt_ipv4_acd(
struct net_pkt *pkt)
1283 return !!(pkt->ipv4_acd_arp_msg);
1286static inline void net_pkt_set_ipv4_acd(
struct net_pkt *pkt,
1287 bool is_acd_arp_msg)
1289 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1292static inline bool net_pkt_ipv4_acd(
struct net_pkt *pkt)
1299static inline void net_pkt_set_ipv4_acd(
struct net_pkt *pkt,
1300 bool is_acd_arp_msg)
1303 ARG_UNUSED(is_acd_arp_msg);
1307#if defined(CONFIG_NET_LLDP)
1308static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1310 return !!(pkt->lldp_pkt);
1313static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1315 pkt->lldp_pkt = is_lldp;
1318static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1325static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1328 ARG_UNUSED(is_lldp);
1332#if defined(CONFIG_NET_L2_PPP)
1333static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1335 return !!(pkt->ppp_msg);
1338static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1341 pkt->ppp_msg = is_ppp_msg;
1344static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1351static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1355 ARG_UNUSED(is_ppp_msg);
1359#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1360static inline void *net_pkt_cb(
struct net_pkt *pkt)
1365static inline void *net_pkt_cb(
struct net_pkt *pkt)
1373#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1374#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1376static inline void net_pkt_set_src_ipv6_addr(
struct net_pkt *pkt)
1379 net_pkt_context(pkt)),
1380 (
struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1383static inline void net_pkt_set_overwrite(
struct net_pkt *pkt,
bool overwrite)
1385 pkt->overwrite = overwrite;
1388static inline bool net_pkt_is_being_overwritten(
struct net_pkt *pkt)
1390 return !!(pkt->overwrite);
1393#ifdef CONFIG_NET_PKT_FILTER
1395bool net_pkt_filter_send_ok(
struct net_pkt *pkt);
1396bool net_pkt_filter_recv_ok(
struct net_pkt *pkt);
1400static inline bool net_pkt_filter_send_ok(
struct net_pkt *pkt)
1407static inline bool net_pkt_filter_recv_ok(
struct net_pkt *pkt)
1416#if defined(CONFIG_NET_PKT_FILTER) && \
1417 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1419bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt);
1423static inline bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt)
1432#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1434bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt);
1438static inline bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt)
1447#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1448static inline struct sockaddr *net_pkt_remote_address(
struct net_pkt *pkt)
1450 return &pkt->remote;
1453static inline void net_pkt_set_remote_address(
struct net_pkt *pkt,
1457 memcpy(&pkt->remote, address, len);
1476#define NET_PKT_SLAB_DEFINE(name, count) \
1477 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4)
1482#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1499#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1500 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1505#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1506 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1507#define NET_PKT_DEBUG_ENABLED
1510#if defined(NET_PKT_DEBUG_ENABLED)
1522#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1523 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1525struct net_buf *net_pkt_get_reserve_rx_data_debug(
size_t min_len,
1529#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1530 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1532struct net_buf *net_pkt_get_reserve_tx_data_debug(
size_t min_len,
1536#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1537 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1539struct net_buf *net_pkt_get_frag_debug(
struct net_pkt *pkt,
size_t min_len,
1541 const char *caller,
int line);
1542#define net_pkt_get_frag(pkt, min_len, timeout) \
1543 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1545void net_pkt_unref_debug(
struct net_pkt *pkt,
const char *caller,
int line);
1546#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1548struct net_pkt *net_pkt_ref_debug(
struct net_pkt *pkt,
const char *caller,
1550#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1553 const char *caller,
int line);
1554#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1556void net_pkt_frag_unref_debug(
struct net_buf *frag,
1557 const char *caller,
int line);
1558#define net_pkt_frag_unref(frag) \
1559 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1564 const char *caller,
int line);
1565#define net_pkt_frag_del(pkt, parent, frag) \
1566 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1568void net_pkt_frag_add_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1569 const char *caller,
int line);
1570#define net_pkt_frag_add(pkt, frag) \
1571 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1573void net_pkt_frag_insert_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1574 const char *caller,
int line);
1575#define net_pkt_frag_insert(pkt, frag) \
1576 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1589#if defined(NET_PKT_DEBUG_ENABLED)
1592#define net_pkt_print_frags(pkt)
1609#if !defined(NET_PKT_DEBUG_ENABLED)
1628#if !defined(NET_PKT_DEBUG_ENABLED)
1646#if !defined(NET_PKT_DEBUG_ENABLED)
1662#if !defined(NET_PKT_DEBUG_ENABLED)
1676#if !defined(NET_PKT_DEBUG_ENABLED)
1689#if !defined(NET_PKT_DEBUG_ENABLED)
1702#if !defined(NET_PKT_DEBUG_ENABLED)
1711#if !defined(NET_PKT_DEBUG_ENABLED)
1725#if !defined(NET_PKT_DEBUG_ENABLED)
1737#if !defined(NET_PKT_DEBUG_ENABLED)
1747#if !defined(NET_PKT_DEBUG_ENABLED)
1768 struct k_mem_slab **tx,
1774#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1778void net_pkt_print(
void);
1780typedef void (*net_pkt_allocs_cb_t)(
struct net_pkt *pkt,
1782 const char *func_alloc,
1784 const char *func_free,
1789void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb,
void *
user_data);
1791const char *net_pkt_slab2str(
struct k_mem_slab *slab);
1792const char *net_pkt_pool2str(
struct net_buf_pool *pool);
1795#define net_pkt_print(...)
1801#if defined(NET_PKT_DEBUG_ENABLED)
1804 const char *caller,
int line);
1805#define net_pkt_alloc(_timeout) \
1806 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1808struct net_pkt *net_pkt_alloc_from_slab_debug(
struct k_mem_slab *
slab,
1810 const char *caller,
int line);
1811#define net_pkt_alloc_from_slab(_slab, _timeout) \
1812 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1815 const char *caller,
int line);
1816#define net_pkt_rx_alloc(_timeout) \
1817 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1823#define net_pkt_alloc_on_iface(_iface, _timeout) \
1824 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1830#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1831 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1834int net_pkt_alloc_buffer_debug(
struct net_pkt *pkt,
1838 const char *caller,
int line);
1839#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1840 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1843int net_pkt_alloc_buffer_raw_debug(
struct net_pkt *pkt,
size_t size,
1845 const char *caller,
int line);
1846#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1847 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1857#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1859 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1870#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1872 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1888#if !defined(NET_PKT_DEBUG_ENABLED)
1906#if !defined(NET_PKT_DEBUG_ENABLED)
1921#if !defined(NET_PKT_DEBUG_ENABLED)
1933#if !defined(NET_PKT_DEBUG_ENABLED)
1961#if !defined(NET_PKT_DEBUG_ENABLED)
1981#if !defined(NET_PKT_DEBUG_ENABLED)
1997#if !defined(NET_PKT_DEBUG_ENABLED)
2097 struct net_pkt_cursor *backup)
2099 backup->buf = pkt->
cursor.buf;
2100 backup->pos = pkt->
cursor.pos;
2110 struct net_pkt_cursor *backup)
2112 pkt->
cursor.buf = backup->buf;
2113 pkt->
cursor.pos = backup->pos;
2470struct net_pkt_data_access {
2471#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2477#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2478#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2479 struct net_pkt_data_access _name = { \
2480 .size = sizeof(_type), \
2483#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2484 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2487#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2488 _type _hdr_##_name; \
2489 struct net_pkt_data_access _name = { \
2490 .data = &_hdr_##_name, \
2491 .size = sizeof(_type), \
2494#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2495 struct net_pkt_data_access _name = { \
2497 .size = sizeof(_type), \
2518 struct net_pkt_data_access *access);
2534 struct net_pkt_data_access *access);
2541 struct net_pkt_data_access *access)
long atomic_t
Definition atomic_types.h:15
#define ALWAYS_INLINE
Definition common.h:129
ZTEST_BMEM int timeout
Definition main.c:31
ZTEST_BMEM int count
Definition main.c:33
VLAN specific definitions.
#define NSEC_PER_SEC
number of nanoseconds per second
Definition sys_clock.h:107
unsigned short int sa_family_t
Socket address family type.
Definition net_ip.h:164
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:120
size_t socklen_t
Length of a socket address.
Definition net_ip.h:168
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:128
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:62
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition buf.h:2717
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:709
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1075
static const struct in6_addr * net_if_ipv6_select_src_addr(struct net_if *iface, const struct in6_addr *dst)
Get a IPv6 source address that should be used when sending network data to destination.
Definition net_if.h:2006
void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag)
Add a fragment to a packet at the end of its fragment list.
static int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
Write a uint32_t big endian data to a net_pkt.
Definition net_pkt.h:2353
void net_pkt_cursor_init(struct net_pkt *pkt)
Initialize net_pkt cursor.
int net_pkt_skip(struct net_pkt *pkt, size_t length)
Skip some data from a net_pkt.
struct net_pkt * net_pkt_shallow_clone(struct net_pkt *pkt, k_timeout_t timeout)
Clone pkt and increase the refcount of its buffer.
void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer)
Append a buffer in packet.
#define net_pkt_print_frags(pkt)
Print fragment list and the fragment sizes.
Definition net_pkt.h:1592
int net_pkt_update_length(struct net_pkt *pkt, size_t length)
Update the overall length of a packet.
int net_pkt_pull(struct net_pkt *pkt, size_t length)
Remove data from the packet at current location.
int net_pkt_copy(struct net_pkt *pkt_dst, struct net_pkt *pkt_src, size_t length)
Copy data from a packet into another one.
struct net_pkt * net_pkt_rx_alloc(k_timeout_t timeout)
Allocate an initialized net_pkt for RX.
struct net_pkt * net_pkt_ref(struct net_pkt *pkt)
Increase the packet ref count.
int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data)
Read uint16_t big endian data from a net_pkt.
int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size, k_timeout_t timeout)
Allocate buffer for a net_pkt, of specified size, w/o any additional preconditions.
struct net_pkt * net_pkt_alloc_with_buffer(struct net_if *iface, size_t size, sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate a network packet and buffer at once.
void net_pkt_frag_unref(struct net_buf *frag)
Decrease the packet fragment ref count.
struct net_pkt * net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout)
Clone pkt and its buffer.
struct net_buf * net_pkt_get_reserve_data(struct net_buf_pool *pool, size_t min_len, k_timeout_t timeout)
Get a data buffer from a given pool.
void net_pkt_trim_buffer(struct net_pkt *pkt)
Trim net_pkt buffer.
struct net_pkt * net_pkt_alloc_on_iface(struct net_if *iface, k_timeout_t timeout)
Allocate a network packet for a specific network interface.
void net_pkt_get_info(struct k_mem_slab **rx, struct k_mem_slab **tx, struct net_buf_pool **rx_data, struct net_buf_pool **tx_data)
Get information about predefined RX, TX and DATA pools.
void net_pkt_unref(struct net_pkt *pkt)
Place packet back into the available packets slab.
static int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
Write a uint16_t big endian data to a net_pkt.
Definition net_pkt.h:2334
struct net_pkt * net_pkt_alloc(k_timeout_t timeout)
Allocate an initialized net_pkt.
int net_pkt_read(struct net_pkt *pkt, void *data, size_t length)
Read some data from a net_pkt.
struct net_buf * net_pkt_frag_del(struct net_pkt *pkt, struct net_buf *parent, struct net_buf *frag)
Delete existing fragment from a packet.
int net_pkt_set_data(struct net_pkt *pkt, struct net_pkt_data_access *access)
Set contiguous data into a network packet.
void * net_pkt_get_data(struct net_pkt *pkt, struct net_pkt_data_access *access)
Get data from a network packet in a contiguous way.
static int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
Write a byte (uint8_t) data to a net_pkt.
Definition net_pkt.h:2317
size_t net_pkt_available_payload_buffer(struct net_pkt *pkt, enum net_ip_protocol proto)
Get available buffer space for payload from a pkt.
int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data)
Read uint16_t little endian data from a net_pkt.
int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data)
Read uint32_t big endian data from a net_pkt.
int net_pkt_remove_tail(struct net_pkt *pkt, size_t length)
Remove length bytes from tail of packet.
struct net_buf * net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout)
Get TX DATA buffer from pool.
static void * net_pkt_cursor_get_pos(struct net_pkt *pkt)
Returns current position of the cursor.
Definition net_pkt.h:2123
void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag)
Insert a fragment to a packet at the beginning of its fragment list.
int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length)
Memset some data in a net_pkt.
static void net_pkt_cursor_backup(struct net_pkt *pkt, struct net_pkt_cursor *backup)
Backup net_pkt cursor.
Definition net_pkt.h:2096
void net_pkt_compact(struct net_pkt *pkt)
Compact the fragment list of a packet.
static int net_pkt_acknowledge_data(struct net_pkt *pkt, struct net_pkt_data_access *access)
Acknowledge previously contiguous data taken from a network packet Packet needs to be set to overwrit...
Definition net_pkt.h:2540
static int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
Write a uint16_t little endian data to a net_pkt.
Definition net_pkt.h:2391
static void net_pkt_cursor_restore(struct net_pkt *pkt, struct net_pkt_cursor *backup)
Restore net_pkt cursor from a backup.
Definition net_pkt.h:2109
uint16_t net_pkt_get_current_offset(struct net_pkt *pkt)
Get the actual offset in the packet from its cursor.
size_t net_pkt_remaining_data(struct net_pkt *pkt)
Get the amount of data which can be read from current cursor position.
int net_pkt_alloc_buffer(struct net_pkt *pkt, size_t size, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate buffer for a net_pkt.
int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length)
Write data into a net_pkt.
struct net_buf * net_pkt_frag_ref(struct net_buf *frag)
Increase the packet fragment ref count.
size_t net_pkt_available_buffer(struct net_pkt *pkt)
Get available buffer space from a pkt.
struct net_pkt * net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout)
Clone pkt and its buffer.
struct net_pkt * net_pkt_alloc_from_slab(struct k_mem_slab *slab, k_timeout_t timeout)
Allocate an initialized net_pkt from a specific slab.
static int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
Write a uint32_t little endian data to a net_pkt.
Definition net_pkt.h:2372
struct net_buf * net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout)
Get RX DATA buffer from pool.
bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size)
Check if a data size could fit contiguously.
static int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
Read a byte (uint8_t) from a net_pkt.
Definition net_pkt.h:2243
struct net_buf * net_pkt_get_frag(struct net_pkt *pkt, size_t min_len, k_timeout_t timeout)
Get a data fragment that might be from user specific buffer pool or from global DATA pool.
size_t net_pkt_get_contiguous_len(struct net_pkt *pkt)
Get the contiguous buffer space.
int64_t net_time_t
Any occurrence of net_time_t specifies a concept of nanosecond resolution scalar time span,...
Definition net_time.h:101
static net_time_t net_ptp_time_to_ns(struct net_ptp_time *ts)
Convert a PTP timestamp to a nanosecond precision timestamp, both related to the local network refere...
Definition ptp_time.h:208
static struct net_ptp_time ns_to_net_ptp_time(net_time_t nsec)
Convert a nanosecond precision timestamp to a PTP timestamp, both related to the local network refere...
Definition ptp_time.h:229
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:124
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:76
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:51
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition ethernet_vlan.h:30
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition ethernet_vlan.h:89
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:39
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:102
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:63
Packet data common to all IEEE 802.15.4 L2 layers.
Network context definitions.
Network core definitions.
Public API for network interface.
IPv6 and IPv4 definitions.
Public API for network link address.
Representation of nanosecond resolution elapsed time and timestamps in the network stack.
flags
Definition parser.h:96
static int pos
Definition printk.c:11
Public functions for the Precision Time Protocol time specification.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INTPTR_TYPE__ intptr_t
Definition stdint.h:104
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
IPv6 address struct.
Definition net_ip.h:139
Kernel timeout type.
Definition sys_clock.h:65
Network buffer pool representation.
Definition buf.h:1076
Network buffer representation.
Definition buf.h:1004
uint8_t * data
Pointer to the start of data in the buffer.
Definition buf.h:1030
uint16_t len
Length of the data behind the data pointer.
Definition buf.h:1033
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:205
Network Interface structure.
Definition net_if.h:678
Hardware link address structure.
Definition net_linkaddr.h:67
uint8_t * addr
The array of byte representing the address.
Definition net_linkaddr.h:69
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:75
Network packet.
Definition net_pkt.h:67
struct net_buf * frags
buffer fragment
Definition net_pkt.h:79
struct net_context * context
Network connection context.
Definition net_pkt.h:87
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:84
struct net_if * iface
Network interface.
Definition net_pkt.h:90
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:72
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:80
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:75
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:109
uint32_t nanosecond
Nanoseconds.
Definition ptp_time.h:132
uint64_t second
Second value.
Definition ptp_time.h:128
Generic sockaddr struct.
Definition net_ip.h:385
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition byteorder.h:270
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:266
static fdata_t data[2]
Definition test_fifo_contexts.c:15
static ZTEST_BMEM char buffer[8]
Definition test_mbox_api.c:433
static const char * tag(void)
Definition main.c:27
static const intptr_t user_data[5]
Definition main.c:588