16#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
17#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
24#if defined(CONFIG_IEEE802154)
53#if defined(CONFIG_NET_PKT_ALLOC_STATS)
54struct net_pkt_alloc_stats {
60struct net_pkt_alloc_stats_slab {
61 struct net_pkt_alloc_stats ok;
62 struct net_pkt_alloc_stats fail;
63 struct k_mem_slab *slab;
66#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
67 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
72#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
76struct net_pkt_cursor {
118#if defined(CONFIG_NET_TCP)
122#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
123 struct net_if *orig_iface;
126#if defined(CONFIG_NET_VPN)
131 union net_ip_header ip_hdr;
133 union net_proto_header proto_hdr;
139#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
161#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
162 defined(CONFIG_TRACING_NET_CORE)
167#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
168 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
183#if defined(CONFIG_NET_PKT_ALLOC_STATS)
184 struct net_pkt_alloc_stats_slab *alloc_stats;
195#if defined(CONFIG_NET_IP)
212#if defined(CONFIG_NET_IPV4_ACD)
219#if defined(CONFIG_NET_LLDP)
240#if defined(CONFIG_NET_IP_FRAGMENT)
243#if defined(CONFIG_NET_PKT_TIMESTAMP)
249#if defined(CONFIG_NET_IP)
254#if defined(CONFIG_NET_IPV6)
257#if defined(CONFIG_NET_IPV4)
263#if defined(CONFIG_NET_IPV4)
266#if defined(CONFIG_NET_IPV6)
271#if defined(CONFIG_NET_IP_FRAGMENT)
273#if defined(CONFIG_NET_IPV4_FRAGMENT)
279#if defined(CONFIG_NET_IPV6_FRAGMENT)
289#if defined(CONFIG_NET_IPV6)
301#if defined(CONFIG_NET_IP_DSCP_ECN)
310#if defined(CONFIG_NET_VLAN)
319#if defined(NET_PKT_HAS_CONTROL_BLOCK)
324#if defined(CONFIG_IEEE802154)
328 struct net_pkt_cb_ieee802154 cb;
337#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
349 struct sockaddr_storage remote_storage;
353#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
358#if defined(CONFIG_NET_IPV4_PMTU)
379static inline void net_pkt_set_context(
struct net_pkt *pkt,
385static inline struct net_if *net_pkt_iface(
struct net_pkt *pkt)
390static inline void net_pkt_set_iface(
struct net_pkt *pkt,
struct net_if *iface)
401 pkt->lladdr_src.type = type;
402 pkt->lladdr_dst.type = type;
406static inline struct net_if *net_pkt_orig_iface(
struct net_pkt *pkt)
408#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
409 return pkt->orig_iface;
415static inline void net_pkt_set_orig_iface(
struct net_pkt *pkt,
418#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
419 pkt->orig_iface = iface;
426#if defined(CONFIG_NET_VPN)
427static inline struct net_if *net_pkt_vpn_iface(
struct net_pkt *pkt)
429 return pkt->vpn.
iface;
432static inline void net_pkt_set_vpn_iface(
struct net_pkt *pkt,
435 pkt->vpn.
iface = iface;
438static inline union net_ip_header *net_pkt_vpn_ip_hdr(
struct net_pkt *pkt)
440 return &pkt->vpn.ip_hdr;
443static inline void net_pkt_set_vpn_ip_hdr(
struct net_pkt *pkt,
444 union net_ip_header *ip_hdr)
446 pkt->vpn.ip_hdr = *ip_hdr;
449static inline union net_proto_header *net_pkt_vpn_udp_hdr(
struct net_pkt *pkt)
451 return &pkt->vpn.proto_hdr;
454static inline void net_pkt_set_vpn_udp_hdr(
struct net_pkt *pkt,
455 union net_proto_header *proto_hdr)
457 pkt->vpn.proto_hdr = *proto_hdr;
460static inline int net_pkt_vpn_peer_id(
struct net_pkt *pkt)
462 return pkt->vpn.peer_id;
465static inline void net_pkt_set_vpn_peer_id(
struct net_pkt *pkt,
468 pkt->vpn.peer_id = peer_id;
477static inline void net_pkt_set_family(
struct net_pkt *pkt,
uint8_t family)
479 pkt->family = family;
482static inline bool net_pkt_is_ptp(
struct net_pkt *pkt)
484 return !!(pkt->ptp_pkt);
487static inline void net_pkt_set_ptp(
struct net_pkt *pkt,
bool is_ptp)
489 pkt->ptp_pkt = is_ptp;
492static inline bool net_pkt_is_tx_timestamping(
struct net_pkt *pkt)
494#if defined(CONFIG_NET_PKT_TIMESTAMP)
495 return !!(pkt->tx_timestamping);
503static inline void net_pkt_set_tx_timestamping(
struct net_pkt *pkt,
bool is_timestamping)
505#if defined(CONFIG_NET_PKT_TIMESTAMP)
506 pkt->tx_timestamping = is_timestamping;
509 ARG_UNUSED(is_timestamping);
513static inline bool net_pkt_is_rx_timestamping(
struct net_pkt *pkt)
515#if defined(CONFIG_NET_PKT_TIMESTAMP)
516 return !!(pkt->rx_timestamping);
524static inline void net_pkt_set_rx_timestamping(
struct net_pkt *pkt,
bool is_timestamping)
526#if defined(CONFIG_NET_PKT_TIMESTAMP)
527 pkt->rx_timestamping = is_timestamping;
530 ARG_UNUSED(is_timestamping);
534static inline bool net_pkt_is_captured(
struct net_pkt *pkt)
536 return !!(pkt->captured);
539static inline void net_pkt_set_captured(
struct net_pkt *pkt,
bool is_captured)
541 pkt->captured = is_captured;
544static inline bool net_pkt_is_l2_bridged(
struct net_pkt *pkt)
546 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
549static inline void net_pkt_set_l2_bridged(
struct net_pkt *pkt,
bool is_l2_bridged)
552 pkt->l2_bridged = is_l2_bridged;
556static inline bool net_pkt_is_l2_processed(
struct net_pkt *pkt)
558 return !!(pkt->l2_processed);
561static inline void net_pkt_set_l2_processed(
struct net_pkt *pkt,
562 bool is_l2_processed)
564 pkt->l2_processed = is_l2_processed;
567static inline bool net_pkt_is_chksum_done(
struct net_pkt *pkt)
569 return !!(pkt->chksum_done);
572static inline void net_pkt_set_chksum_done(
struct net_pkt *pkt,
575 pkt->chksum_done = is_chksum_done;
580#if defined(CONFIG_NET_IP)
581 return pkt->ip_hdr_len;
589static inline void net_pkt_set_ip_hdr_len(
struct net_pkt *pkt,
uint8_t len)
591#if defined(CONFIG_NET_IP)
592 pkt->ip_hdr_len = len;
601#if defined(CONFIG_NET_IP_DSCP_ECN)
610static inline void net_pkt_set_ip_dscp(
struct net_pkt *pkt,
uint8_t dscp)
612#if defined(CONFIG_NET_IP_DSCP_ECN)
622#if defined(CONFIG_NET_IP_DSCP_ECN)
631static inline void net_pkt_set_ip_ecn(
struct net_pkt *pkt,
uint8_t ecn)
633#if defined(CONFIG_NET_IP_DSCP_ECN)
646static inline void net_pkt_set_eof(
struct net_pkt *pkt,
bool eof)
651static inline bool net_pkt_forwarding(
struct net_pkt *pkt)
653 return !!(pkt->forwarding);
656static inline void net_pkt_set_forwarding(
struct net_pkt *pkt,
bool forward)
658 pkt->forwarding = forward;
661#if defined(CONFIG_NET_IPV4)
664 return pkt->ipv4_ttl;
667static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
675 return pkt->ipv4_opts_len;
678static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
681 pkt->ipv4_opts_len = opts_len;
691static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
704static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
708 ARG_UNUSED(opts_len);
712#if defined(CONFIG_NET_IPV6)
713static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
715 return pkt->ipv6_ext_opt_len;
718static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
721 pkt->ipv6_ext_opt_len = len;
726 return pkt->ipv6_next_hdr;
729static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
732 pkt->ipv6_next_hdr = next_hdr;
737 return pkt->ipv6_ext_len;
740static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
742 pkt->ipv6_ext_len = len;
747 return pkt->ipv6_prev_hdr_start;
750static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
753 pkt->ipv6_prev_hdr_start = offset;
758 return pkt->ipv6_hop_limit;
761static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
764 pkt->ipv6_hop_limit = hop_limit;
767static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
774static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
788static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
792 ARG_UNUSED(next_hdr);
802static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
815static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
829static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
833 ARG_UNUSED(hop_limit);
839#if defined(CONFIG_NET_IPV6)
840 return pkt->ipv6_ext_len;
841#elif defined(CONFIG_NET_IPV4)
842 return pkt->ipv4_opts_len;
850#if defined(CONFIG_NET_IPV4_PMTU)
851static inline bool net_pkt_ipv4_pmtu(
struct net_pkt *pkt)
853 return !!pkt->ipv4_pmtu;
856static inline void net_pkt_set_ipv4_pmtu(
struct net_pkt *pkt,
bool value)
858 pkt->ipv4_pmtu = value;
861static inline bool net_pkt_ipv4_pmtu(
struct net_pkt *pkt)
868static inline void net_pkt_set_ipv4_pmtu(
struct net_pkt *pkt,
bool value)
875#if defined(CONFIG_NET_IPV4_FRAGMENT)
876static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
878 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
881static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
883 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
888 pkt->ipv4_fragment.flags =
flags;
893 return pkt->ipv4_fragment.id;
896static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
898 pkt->ipv4_fragment.id = id;
901static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
908static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
928static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
935#if defined(CONFIG_NET_IPV6_FRAGMENT)
938 return pkt->ipv6_fragment.hdr_start;
941static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
944 pkt->ipv6_fragment.hdr_start = start;
947static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
949 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
951static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
953 return (pkt->ipv6_fragment.flags & 0x01) != 0;
956static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
959 pkt->ipv6_fragment.flags =
flags;
964 return pkt->ipv6_fragment.id;
967static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
970 pkt->ipv6_fragment.id = id;
980static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
987static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
994static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
1001static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
1015static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
1023#if defined(CONFIG_NET_IP_FRAGMENT)
1024static inline bool net_pkt_is_ip_reassembled(
struct net_pkt *pkt)
1026 return !!(pkt->ip_reassembled);
1029static inline void net_pkt_set_ip_reassembled(
struct net_pkt *pkt,
1032 pkt->ip_reassembled = reassembled;
1035static inline bool net_pkt_is_ip_reassembled(
struct net_pkt *pkt)
1042static inline void net_pkt_set_ip_reassembled(
struct net_pkt *pkt,
1046 ARG_UNUSED(reassembled);
1052 return pkt->priority;
1055static inline void net_pkt_set_priority(
struct net_pkt *pkt,
1058 pkt->priority = priority;
1061#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1062static inline bool net_pkt_is_cooked_mode(
struct net_pkt *pkt)
1064 return pkt->cooked_mode_pkt;
1067static inline void net_pkt_set_cooked_mode(
struct net_pkt *pkt,
bool value)
1069 pkt->cooked_mode_pkt = value;
1072static inline bool net_pkt_is_cooked_mode(
struct net_pkt *pkt)
1079static inline void net_pkt_set_cooked_mode(
struct net_pkt *pkt,
bool value)
1086#if defined(CONFIG_NET_VLAN)
1092static inline void net_pkt_set_vlan_tag(
struct net_pkt *pkt,
uint16_t tag)
1102static inline void net_pkt_set_vlan_priority(
struct net_pkt *pkt,
1108static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
1113static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
1118static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
1120 pkt->vlan_tci = tci;
1125 return pkt->vlan_tci;
1135static inline void net_pkt_set_vlan_tag(
struct net_pkt *pkt,
uint16_t tag)
1148static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
1155static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
1168static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
1175#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1178 return &pkt->timestamp;
1181static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
1184 pkt->timestamp.second = timestamp->
second;
1185 pkt->timestamp.nanosecond = timestamp->
nanosecond;
1193static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
1205static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
1209 ARG_UNUSED(timestamp);
1219static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
1222 ARG_UNUSED(timestamp);
1226#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1227 defined(CONFIG_TRACING_NET_CORE)
1231 return pkt->create_time;
1234static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
1237 pkt->create_time = create_time;
1247static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
1251 ARG_UNUSED(create_time);
1257#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1258 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1261 return pkt->detail.stat;
1264static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1266 return pkt->detail.count;
1269static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1271 memset(&pkt->detail, 0,
sizeof(pkt->detail));
1277 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1278 NET_ERR(
"Detail stats count overflow (%d >= %d)",
1279 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1283 pkt->detail.stat[pkt->detail.count++] = tick;
1286#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1287#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1296static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1303static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1308static inline void net_pkt_set_stats_tick(
struct net_pkt *pkt,
uint32_t tick)
1314#define net_pkt_set_tx_stats_tick(pkt, tick)
1315#define net_pkt_set_rx_stats_tick(pkt, tick)
1329static inline bool net_pkt_is_empty(
struct net_pkt *pkt)
1336 return &pkt->lladdr_src;
1341 return &pkt->lladdr_dst;
1344static inline void net_pkt_lladdr_swap(
struct net_pkt *pkt)
1349 net_pkt_lladdr_src(pkt)->
addr,
1350 net_pkt_lladdr_src(pkt)->
len);
1352 net_pkt_lladdr_dst(pkt)->
addr,
1353 net_pkt_lladdr_dst(pkt)->
len);
1356 net_pkt_lladdr_src(pkt)->
len);
1359static inline void net_pkt_lladdr_clear(
struct net_pkt *pkt)
1367 return pkt->ll_proto_type;
1372 pkt->ll_proto_type =
type;
1375#if defined(CONFIG_NET_IPV4_ACD)
1376static inline bool net_pkt_ipv4_acd(
struct net_pkt *pkt)
1378 return !!(pkt->ipv4_acd_arp_msg);
1381static inline void net_pkt_set_ipv4_acd(
struct net_pkt *pkt,
1382 bool is_acd_arp_msg)
1384 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1387static inline bool net_pkt_ipv4_acd(
struct net_pkt *pkt)
1394static inline void net_pkt_set_ipv4_acd(
struct net_pkt *pkt,
1395 bool is_acd_arp_msg)
1398 ARG_UNUSED(is_acd_arp_msg);
1402#if defined(CONFIG_NET_LLDP)
1403static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1405 return !!(pkt->lldp_pkt);
1408static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1410 pkt->lldp_pkt = is_lldp;
1413static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1420static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1423 ARG_UNUSED(is_lldp);
1427#if defined(CONFIG_NET_L2_PPP)
1428static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1430 return !!(pkt->ppp_msg);
1433static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1436 pkt->ppp_msg = is_ppp_msg;
1439static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1446static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1450 ARG_UNUSED(is_ppp_msg);
1454#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1455static inline void *net_pkt_cb(
struct net_pkt *pkt)
1460static inline void *net_pkt_cb(
struct net_pkt *pkt)
1468#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1469#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1471static inline void net_pkt_set_src_ipv6_addr(
struct net_pkt *pkt)
1474 net_pkt_context(pkt)),
1475 (
struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1478static inline void net_pkt_set_overwrite(
struct net_pkt *pkt,
bool overwrite)
1480 pkt->overwrite = overwrite;
1483static inline bool net_pkt_is_being_overwritten(
struct net_pkt *pkt)
1485 return !!(pkt->overwrite);
1488#ifdef CONFIG_NET_PKT_FILTER
1490bool net_pkt_filter_send_ok(
struct net_pkt *pkt);
1491bool net_pkt_filter_recv_ok(
struct net_pkt *pkt);
1495static inline bool net_pkt_filter_send_ok(
struct net_pkt *pkt)
1502static inline bool net_pkt_filter_recv_ok(
struct net_pkt *pkt)
1511#if defined(CONFIG_NET_PKT_FILTER) && \
1512 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1514bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt);
1518static inline bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt)
1527#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1529bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt);
1533static inline bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt)
1542#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1543static inline struct sockaddr *net_pkt_remote_address(
struct net_pkt *pkt)
1545 return &pkt->remote;
1548static inline void net_pkt_set_remote_address(
struct net_pkt *pkt,
1552 memcpy(&pkt->remote, address, len);
1571#define NET_PKT_SLAB_DEFINE(name, count) \
1572 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4); \
1573 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1571#define NET_PKT_SLAB_DEFINE(name, count) \ …
1578#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1595#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1596 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1595#define NET_PKT_DATA_POOL_DEFINE(name, count) \ …
1601#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1602 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1603#define NET_PKT_DEBUG_ENABLED
1606#if defined(NET_PKT_DEBUG_ENABLED)
1618#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1619 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1621struct net_buf *net_pkt_get_reserve_rx_data_debug(
size_t min_len,
1625#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1626 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1628struct net_buf *net_pkt_get_reserve_tx_data_debug(
size_t min_len,
1632#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1633 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1635struct net_buf *net_pkt_get_frag_debug(
struct net_pkt *pkt,
size_t min_len,
1637 const char *caller,
int line);
1638#define net_pkt_get_frag(pkt, min_len, timeout) \
1639 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1641void net_pkt_unref_debug(
struct net_pkt *pkt,
const char *caller,
int line);
1642#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1644struct net_pkt *net_pkt_ref_debug(
struct net_pkt *pkt,
const char *caller,
1646#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1649 const char *caller,
int line);
1650#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1652void net_pkt_frag_unref_debug(
struct net_buf *frag,
1653 const char *caller,
int line);
1654#define net_pkt_frag_unref(frag) \
1655 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1660 const char *caller,
int line);
1661#define net_pkt_frag_del(pkt, parent, frag) \
1662 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1664void net_pkt_frag_add_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1665 const char *caller,
int line);
1666#define net_pkt_frag_add(pkt, frag) \
1667 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1669void net_pkt_frag_insert_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1670 const char *caller,
int line);
1671#define net_pkt_frag_insert(pkt, frag) \
1672 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1678#if defined(NET_PKT_DEBUG_ENABLED)
1688#define net_pkt_print_frags(pkt)
1691#if !defined(NET_PKT_DEBUG_ENABLED)
1710#if !defined(NET_PKT_DEBUG_ENABLED)
1728#if !defined(NET_PKT_DEBUG_ENABLED)
1746#if !defined(NET_PKT_DEBUG_ENABLED)
1763#if !defined(NET_PKT_DEBUG_ENABLED)
1776#if !defined(NET_PKT_DEBUG_ENABLED)
1789#if !defined(NET_PKT_DEBUG_ENABLED)
1802#if !defined(NET_PKT_DEBUG_ENABLED)
1811#if !defined(NET_PKT_DEBUG_ENABLED)
1827#if !defined(NET_PKT_DEBUG_ENABLED)
1837#if !defined(NET_PKT_DEBUG_ENABLED)
1864 struct k_mem_slab **tx,
1870#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1874void net_pkt_print(
void);
1876typedef void (*net_pkt_allocs_cb_t)(
struct net_pkt *pkt,
1878 const char *func_alloc,
1880 const char *func_free,
1885void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb,
void *
user_data);
1887const char *net_pkt_slab2str(
struct k_mem_slab *slab);
1888const char *net_pkt_pool2str(
struct net_buf_pool *pool);
1891#define net_pkt_print(...)
1897#if defined(NET_PKT_DEBUG_ENABLED)
1900 const char *caller,
int line);
1901#define net_pkt_alloc(_timeout) \
1902 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1904struct net_pkt *net_pkt_alloc_from_slab_debug(
struct k_mem_slab *
slab,
1906 const char *caller,
int line);
1907#define net_pkt_alloc_from_slab(_slab, _timeout) \
1908 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1911 const char *caller,
int line);
1912#define net_pkt_rx_alloc(_timeout) \
1913 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1919#define net_pkt_alloc_on_iface(_iface, _timeout) \
1920 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1926#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1927 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1930int net_pkt_alloc_buffer_debug(
struct net_pkt *pkt,
1934 const char *caller,
int line);
1935#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1936 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1939int net_pkt_alloc_buffer_raw_debug(
struct net_pkt *pkt,
size_t size,
1941 const char *caller,
int line);
1942#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1943 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1953#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1955 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1966#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1968 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1972int net_pkt_alloc_buffer_with_reserve_debug(
struct net_pkt *pkt,
1979#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
1980 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
1981 _timeout, __func__, __LINE__)
1986#if !defined(NET_PKT_DEBUG_ENABLED)
2000#if !defined(NET_PKT_DEBUG_ENABLED)
2019#if !defined(NET_PKT_DEBUG_ENABLED)
2033#if !defined(NET_PKT_DEBUG_ENABLED)
2054#if !defined(NET_PKT_DEBUG_ENABLED)
2076#if !defined(NET_PKT_DEBUG_ENABLED)
2094#if !defined(NET_PKT_DEBUG_ENABLED)
2119#if !defined(NET_PKT_DEBUG_ENABLED)
2230 struct net_pkt_cursor *backup)
2232 backup->buf = pkt->
cursor.buf;
2233 backup->pos = pkt->
cursor.pos;
2243 struct net_pkt_cursor *backup)
2245 pkt->
cursor.buf = backup->buf;
2246 pkt->
cursor.pos = backup->pos;
2615struct net_pkt_data_access {
2616#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2622#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2623#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2624 struct net_pkt_data_access _name = { \
2625 .size = sizeof(_type), \
2628#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2629 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2632#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2633 _type _hdr_##_name; \
2634 struct net_pkt_data_access _name = { \
2635 .data = &_hdr_##_name, \
2636 .size = sizeof(_type), \
2639#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2640 struct net_pkt_data_access _name = { \
2642 .size = sizeof(_type), \
2663 struct net_pkt_data_access *access);
2679 struct net_pkt_data_access *access);
2686 struct net_pkt_data_access *access)
long atomic_t
Definition atomic_types.h:15
VLAN specific definitions.
unsigned short int sa_family_t
Socket address family type.
Definition net_ip.h:168
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:124
size_t socklen_t
Length of a socket address.
Definition net_ip.h:172
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:132
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2667
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:747
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1159
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:2150
static int net_linkaddr_clear(struct net_linkaddr *lladdr)
Clear link address.
Definition net_linkaddr.h:200
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:2486
int net_pkt_alloc_buffer_with_reserve(struct net_pkt *pkt, size_t size, size_t reserve, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate buffer for a net_pkt and reserve some space in the first net_buf.
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)
Definition net_pkt.h:1688
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:2467
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.
static size_t net_pkt_get_len(struct net_pkt *pkt)
Get the total amount of bytes stored in a packet.
Definition net_pkt.h:2547
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:2450
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:2256
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:2229
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:2685
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:2524
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:2242
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:2505
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:2376
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:103
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:210
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:231
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:148
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:81
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:56
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition ethernet_vlan.h:32
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition ethernet_vlan.h:94
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:44
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:107
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:68
#define NULL
Definition iar_missing_defs.h:20
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:97
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:143
Kernel timeout type.
Definition sys_clock.h:65
Network buffer pool representation.
Definition net_buf.h:1078
Network buffer representation.
Definition net_buf.h:1006
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1032
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1053
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1035
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:208
Network Interface structure.
Definition net_if.h:714
Hardware link address structure.
Definition net_linkaddr.h:74
uint8_t addr[6]
The array of bytes representing the address.
Definition net_linkaddr.h:82
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:76
uint8_t len
The real length of the ll address.
Definition net_linkaddr.h:79
Network packet.
Definition net_pkt.h:91
struct net_buf * frags
buffer fragment
Definition net_pkt.h:103
struct net_context * context
Network connection context.
Definition net_pkt.h:111
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:108
struct net_if * iface
Network interface.
Definition net_pkt.h:114
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:96
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:104
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:99
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
uint32_t nanosecond
Nanoseconds.
Definition ptp_time.h:134
uint64_t second
Second value.
Definition ptp_time.h:130
Generic sockaddr struct.
Definition net_ip.h:408
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition byteorder.h:272
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:268