16#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
17#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
24#if defined(CONFIG_IEEE802154)
54struct net_pkt_cursor {
96#if defined(CONFIG_NET_TCP)
100#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
101 struct net_if *orig_iface;
104#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
126#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
127 defined(CONFIG_TRACING_NET_CORE)
132#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
133 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
156#if defined(CONFIG_NET_IP)
173#if defined(CONFIG_NET_IPV4_ACD)
180#if defined(CONFIG_NET_LLDP)
201#if defined(CONFIG_NET_IP_FRAGMENT)
204#if defined(CONFIG_NET_PKT_TIMESTAMP)
210#if defined(CONFIG_NET_IP)
215#if defined(CONFIG_NET_IPV6)
218#if defined(CONFIG_NET_IPV4)
224#if defined(CONFIG_NET_IPV4)
227#if defined(CONFIG_NET_IPV6)
232#if defined(CONFIG_NET_IP_FRAGMENT)
234#if defined(CONFIG_NET_IPV4_FRAGMENT)
240#if defined(CONFIG_NET_IPV6_FRAGMENT)
250#if defined(CONFIG_NET_IPV6)
262#if defined(CONFIG_NET_IP_DSCP_ECN)
271#if defined(CONFIG_NET_VLAN)
280#if defined(NET_PKT_HAS_CONTROL_BLOCK)
285#if defined(CONFIG_IEEE802154)
289 struct net_pkt_cb_ieee802154 cb;
298#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
310 struct sockaddr_storage remote_storage;
314#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
335static inline void net_pkt_set_context(
struct net_pkt *pkt,
341static inline struct net_if *net_pkt_iface(
struct net_pkt *pkt)
346static inline void net_pkt_set_iface(
struct net_pkt *pkt,
struct net_if *iface)
357 pkt->lladdr_src.type = type;
358 pkt->lladdr_dst.type = type;
362static inline struct net_if *net_pkt_orig_iface(
struct net_pkt *pkt)
364#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
365 return pkt->orig_iface;
371static inline void net_pkt_set_orig_iface(
struct net_pkt *pkt,
374#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
375 pkt->orig_iface = iface;
387static inline void net_pkt_set_family(
struct net_pkt *pkt,
uint8_t family)
389 pkt->family = family;
392static inline bool net_pkt_is_ptp(
struct net_pkt *pkt)
394 return !!(pkt->ptp_pkt);
397static inline void net_pkt_set_ptp(
struct net_pkt *pkt,
bool is_ptp)
399 pkt->ptp_pkt = is_ptp;
402static inline bool net_pkt_is_tx_timestamping(
struct net_pkt *pkt)
404#if defined(CONFIG_NET_PKT_TIMESTAMP)
405 return !!(pkt->tx_timestamping);
413static inline void net_pkt_set_tx_timestamping(
struct net_pkt *pkt,
bool is_timestamping)
415#if defined(CONFIG_NET_PKT_TIMESTAMP)
416 pkt->tx_timestamping = is_timestamping;
419 ARG_UNUSED(is_timestamping);
423static inline bool net_pkt_is_rx_timestamping(
struct net_pkt *pkt)
425#if defined(CONFIG_NET_PKT_TIMESTAMP)
426 return !!(pkt->rx_timestamping);
434static inline void net_pkt_set_rx_timestamping(
struct net_pkt *pkt,
bool is_timestamping)
436#if defined(CONFIG_NET_PKT_TIMESTAMP)
437 pkt->rx_timestamping = is_timestamping;
440 ARG_UNUSED(is_timestamping);
444static inline bool net_pkt_is_captured(
struct net_pkt *pkt)
446 return !!(pkt->captured);
449static inline void net_pkt_set_captured(
struct net_pkt *pkt,
bool is_captured)
451 pkt->captured = is_captured;
454static inline bool net_pkt_is_l2_bridged(
struct net_pkt *pkt)
456 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
459static inline void net_pkt_set_l2_bridged(
struct net_pkt *pkt,
bool is_l2_bridged)
462 pkt->l2_bridged = is_l2_bridged;
466static inline bool net_pkt_is_l2_processed(
struct net_pkt *pkt)
468 return !!(pkt->l2_processed);
471static inline void net_pkt_set_l2_processed(
struct net_pkt *pkt,
472 bool is_l2_processed)
474 pkt->l2_processed = is_l2_processed;
477static inline bool net_pkt_is_chksum_done(
struct net_pkt *pkt)
479 return !!(pkt->chksum_done);
482static inline void net_pkt_set_chksum_done(
struct net_pkt *pkt,
485 pkt->chksum_done = is_chksum_done;
490#if defined(CONFIG_NET_IP)
491 return pkt->ip_hdr_len;
499static inline void net_pkt_set_ip_hdr_len(
struct net_pkt *pkt,
uint8_t len)
501#if defined(CONFIG_NET_IP)
502 pkt->ip_hdr_len = len;
511#if defined(CONFIG_NET_IP_DSCP_ECN)
520static inline void net_pkt_set_ip_dscp(
struct net_pkt *pkt,
uint8_t dscp)
522#if defined(CONFIG_NET_IP_DSCP_ECN)
532#if defined(CONFIG_NET_IP_DSCP_ECN)
541static inline void net_pkt_set_ip_ecn(
struct net_pkt *pkt,
uint8_t ecn)
543#if defined(CONFIG_NET_IP_DSCP_ECN)
556static inline void net_pkt_set_eof(
struct net_pkt *pkt,
bool eof)
561static inline bool net_pkt_forwarding(
struct net_pkt *pkt)
563 return !!(pkt->forwarding);
566static inline void net_pkt_set_forwarding(
struct net_pkt *pkt,
bool forward)
568 pkt->forwarding = forward;
571#if defined(CONFIG_NET_IPV4)
574 return pkt->ipv4_ttl;
577static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
585 return pkt->ipv4_opts_len;
588static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
591 pkt->ipv4_opts_len = opts_len;
601static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
614static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
618 ARG_UNUSED(opts_len);
622#if defined(CONFIG_NET_IPV6)
623static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
625 return pkt->ipv6_ext_opt_len;
628static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
631 pkt->ipv6_ext_opt_len = len;
636 return pkt->ipv6_next_hdr;
639static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
642 pkt->ipv6_next_hdr = next_hdr;
647 return pkt->ipv6_ext_len;
650static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
652 pkt->ipv6_ext_len = len;
657 return pkt->ipv6_prev_hdr_start;
660static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
663 pkt->ipv6_prev_hdr_start = offset;
668 return pkt->ipv6_hop_limit;
671static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
674 pkt->ipv6_hop_limit = hop_limit;
677static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
684static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
698static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
702 ARG_UNUSED(next_hdr);
712static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
725static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
739static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
743 ARG_UNUSED(hop_limit);
749#if defined(CONFIG_NET_IPV6)
750 return pkt->ipv6_ext_len;
751#elif defined(CONFIG_NET_IPV4)
752 return pkt->ipv4_opts_len;
760#if defined(CONFIG_NET_IPV4_FRAGMENT)
761static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
763 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
766static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
768 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
773 pkt->ipv4_fragment.flags =
flags;
778 return pkt->ipv4_fragment.id;
781static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
783 pkt->ipv4_fragment.id = id;
786static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
793static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
813static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
820#if defined(CONFIG_NET_IPV6_FRAGMENT)
823 return pkt->ipv6_fragment.hdr_start;
826static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
829 pkt->ipv6_fragment.hdr_start = start;
832static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
834 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
836static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
838 return (pkt->ipv6_fragment.flags & 0x01) != 0;
841static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
844 pkt->ipv6_fragment.flags =
flags;
849 return pkt->ipv6_fragment.id;
852static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
855 pkt->ipv6_fragment.id = id;
865static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
872static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
879static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
886static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
900static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
908#if defined(CONFIG_NET_IP_FRAGMENT)
909static inline bool net_pkt_is_ip_reassembled(
struct net_pkt *pkt)
911 return !!(pkt->ip_reassembled);
914static inline void net_pkt_set_ip_reassembled(
struct net_pkt *pkt,
917 pkt->ip_reassembled = reassembled;
920static inline bool net_pkt_is_ip_reassembled(
struct net_pkt *pkt)
927static inline void net_pkt_set_ip_reassembled(
struct net_pkt *pkt,
931 ARG_UNUSED(reassembled);
937 return pkt->priority;
940static inline void net_pkt_set_priority(
struct net_pkt *pkt,
943 pkt->priority = priority;
946#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
947static inline bool net_pkt_is_cooked_mode(
struct net_pkt *pkt)
949 return pkt->cooked_mode_pkt;
952static inline void net_pkt_set_cooked_mode(
struct net_pkt *pkt,
bool value)
954 pkt->cooked_mode_pkt = value;
957static inline bool net_pkt_is_cooked_mode(
struct net_pkt *pkt)
964static inline void net_pkt_set_cooked_mode(
struct net_pkt *pkt,
bool value)
971#if defined(CONFIG_NET_VLAN)
977static inline void net_pkt_set_vlan_tag(
struct net_pkt *pkt,
uint16_t tag)
987static inline void net_pkt_set_vlan_priority(
struct net_pkt *pkt,
993static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
998static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
1003static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
1005 pkt->vlan_tci = tci;
1010 return pkt->vlan_tci;
1020static inline void net_pkt_set_vlan_tag(
struct net_pkt *pkt,
uint16_t tag)
1033static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
1040static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
1053static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
1060#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1063 return &pkt->timestamp;
1066static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
1069 pkt->timestamp.second = timestamp->
second;
1070 pkt->timestamp.nanosecond = timestamp->
nanosecond;
1078static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
1090static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
1094 ARG_UNUSED(timestamp);
1104static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
1107 ARG_UNUSED(timestamp);
1111#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1112 defined(CONFIG_TRACING_NET_CORE)
1116 return pkt->create_time;
1119static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
1122 pkt->create_time = create_time;
1132static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
1136 ARG_UNUSED(create_time);
1147#if defined(CONFIG_NET_PKT_TXTIME)
1148 return pkt->timestamp.second *
NSEC_PER_SEC + pkt->timestamp.nanosecond;
1160static inline void net_pkt_set_txtime(
struct net_pkt *pkt,
uint64_t txtime)
1162#if defined(CONFIG_NET_PKT_TXTIME)
1171#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1172 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1175 return pkt->detail.stat;
1178static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1180 return pkt->detail.count;
1183static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1185 memset(&pkt->detail, 0,
sizeof(pkt->detail));
1191 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1192 NET_ERR(
"Detail stats count overflow (%d >= %d)",
1193 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1197 pkt->detail.stat[pkt->detail.count++] = tick;
1200#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1201#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1210static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1217static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1222static inline void net_pkt_set_stats_tick(
struct net_pkt *pkt,
uint32_t tick)
1228#define net_pkt_set_tx_stats_tick(pkt, tick)
1229#define net_pkt_set_rx_stats_tick(pkt, tick)
1233static inline size_t net_pkt_get_len(
struct net_pkt *pkt)
1248static inline bool net_pkt_is_empty(
struct net_pkt *pkt)
1255 return &pkt->lladdr_src;
1260 return &pkt->lladdr_dst;
1263static inline void net_pkt_lladdr_swap(
struct net_pkt *pkt)
1267 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1268 net_pkt_lladdr_dst(pkt)->addr =
addr;
1271static inline void net_pkt_lladdr_clear(
struct net_pkt *pkt)
1273 net_pkt_lladdr_src(pkt)->addr = NULL;
1274 net_pkt_lladdr_src(pkt)->len = 0U;
1279 return pkt->ll_proto_type;
1284 pkt->ll_proto_type =
type;
1287#if defined(CONFIG_NET_IPV4_ACD)
1288static inline bool net_pkt_ipv4_acd(
struct net_pkt *pkt)
1290 return !!(pkt->ipv4_acd_arp_msg);
1293static inline void net_pkt_set_ipv4_acd(
struct net_pkt *pkt,
1294 bool is_acd_arp_msg)
1296 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1299static inline bool net_pkt_ipv4_acd(
struct net_pkt *pkt)
1306static inline void net_pkt_set_ipv4_acd(
struct net_pkt *pkt,
1307 bool is_acd_arp_msg)
1310 ARG_UNUSED(is_acd_arp_msg);
1314#if defined(CONFIG_NET_LLDP)
1315static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1317 return !!(pkt->lldp_pkt);
1320static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1322 pkt->lldp_pkt = is_lldp;
1325static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1332static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1335 ARG_UNUSED(is_lldp);
1339#if defined(CONFIG_NET_L2_PPP)
1340static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1342 return !!(pkt->ppp_msg);
1345static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1348 pkt->ppp_msg = is_ppp_msg;
1351static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1358static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1362 ARG_UNUSED(is_ppp_msg);
1366#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1367static inline void *net_pkt_cb(
struct net_pkt *pkt)
1372static inline void *net_pkt_cb(
struct net_pkt *pkt)
1380#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1381#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1383static inline void net_pkt_set_src_ipv6_addr(
struct net_pkt *pkt)
1386 net_pkt_context(pkt)),
1387 (
struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1390static inline void net_pkt_set_overwrite(
struct net_pkt *pkt,
bool overwrite)
1392 pkt->overwrite = overwrite;
1395static inline bool net_pkt_is_being_overwritten(
struct net_pkt *pkt)
1397 return !!(pkt->overwrite);
1400#ifdef CONFIG_NET_PKT_FILTER
1402bool net_pkt_filter_send_ok(
struct net_pkt *pkt);
1403bool net_pkt_filter_recv_ok(
struct net_pkt *pkt);
1407static inline bool net_pkt_filter_send_ok(
struct net_pkt *pkt)
1414static inline bool net_pkt_filter_recv_ok(
struct net_pkt *pkt)
1423#if defined(CONFIG_NET_PKT_FILTER) && \
1424 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1426bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt);
1430static inline bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt)
1439#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1441bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt);
1445static inline bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt)
1454#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1455static inline struct sockaddr *net_pkt_remote_address(
struct net_pkt *pkt)
1457 return &pkt->remote;
1460static inline void net_pkt_set_remote_address(
struct net_pkt *pkt,
1464 memcpy(&pkt->remote, address, len);
1483#define NET_PKT_SLAB_DEFINE(name, count) \
1484 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4)
1489#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1506#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1507 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1512#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1513 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1514#define NET_PKT_DEBUG_ENABLED
1517#if defined(NET_PKT_DEBUG_ENABLED)
1529#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1530 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1532struct net_buf *net_pkt_get_reserve_rx_data_debug(
size_t min_len,
1536#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1537 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1539struct net_buf *net_pkt_get_reserve_tx_data_debug(
size_t min_len,
1543#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1544 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1546struct net_buf *net_pkt_get_frag_debug(
struct net_pkt *pkt,
size_t min_len,
1548 const char *caller,
int line);
1549#define net_pkt_get_frag(pkt, min_len, timeout) \
1550 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1552void net_pkt_unref_debug(
struct net_pkt *pkt,
const char *caller,
int line);
1553#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1555struct net_pkt *net_pkt_ref_debug(
struct net_pkt *pkt,
const char *caller,
1557#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1560 const char *caller,
int line);
1561#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1563void net_pkt_frag_unref_debug(
struct net_buf *frag,
1564 const char *caller,
int line);
1565#define net_pkt_frag_unref(frag) \
1566 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1571 const char *caller,
int line);
1572#define net_pkt_frag_del(pkt, parent, frag) \
1573 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1575void net_pkt_frag_add_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1576 const char *caller,
int line);
1577#define net_pkt_frag_add(pkt, frag) \
1578 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1580void net_pkt_frag_insert_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1581 const char *caller,
int line);
1582#define net_pkt_frag_insert(pkt, frag) \
1583 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1589#if defined(NET_PKT_DEBUG_ENABLED)
1599#define net_pkt_print_frags(pkt)
1602#if !defined(NET_PKT_DEBUG_ENABLED)
1621#if !defined(NET_PKT_DEBUG_ENABLED)
1639#if !defined(NET_PKT_DEBUG_ENABLED)
1657#if !defined(NET_PKT_DEBUG_ENABLED)
1674#if !defined(NET_PKT_DEBUG_ENABLED)
1687#if !defined(NET_PKT_DEBUG_ENABLED)
1700#if !defined(NET_PKT_DEBUG_ENABLED)
1713#if !defined(NET_PKT_DEBUG_ENABLED)
1722#if !defined(NET_PKT_DEBUG_ENABLED)
1738#if !defined(NET_PKT_DEBUG_ENABLED)
1748#if !defined(NET_PKT_DEBUG_ENABLED)
1775 struct k_mem_slab **tx,
1781#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1785void net_pkt_print(
void);
1787typedef void (*net_pkt_allocs_cb_t)(
struct net_pkt *pkt,
1789 const char *func_alloc,
1791 const char *func_free,
1796void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb,
void *
user_data);
1798const char *net_pkt_slab2str(
struct k_mem_slab *slab);
1799const char *net_pkt_pool2str(
struct net_buf_pool *pool);
1802#define net_pkt_print(...)
1808#if defined(NET_PKT_DEBUG_ENABLED)
1811 const char *caller,
int line);
1812#define net_pkt_alloc(_timeout) \
1813 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1815struct net_pkt *net_pkt_alloc_from_slab_debug(
struct k_mem_slab *
slab,
1817 const char *caller,
int line);
1818#define net_pkt_alloc_from_slab(_slab, _timeout) \
1819 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1822 const char *caller,
int line);
1823#define net_pkt_rx_alloc(_timeout) \
1824 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1830#define net_pkt_alloc_on_iface(_iface, _timeout) \
1831 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1837#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1838 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1841int net_pkt_alloc_buffer_debug(
struct net_pkt *pkt,
1845 const char *caller,
int line);
1846#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1847 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1850int net_pkt_alloc_buffer_raw_debug(
struct net_pkt *pkt,
size_t size,
1852 const char *caller,
int line);
1853#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1854 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1864#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1866 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1877#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1879 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1885#if !defined(NET_PKT_DEBUG_ENABLED)
1899#if !defined(NET_PKT_DEBUG_ENABLED)
1918#if !defined(NET_PKT_DEBUG_ENABLED)
1932#if !defined(NET_PKT_DEBUG_ENABLED)
1953#if !defined(NET_PKT_DEBUG_ENABLED)
1975#if !defined(NET_PKT_DEBUG_ENABLED)
1993#if !defined(NET_PKT_DEBUG_ENABLED)
2104 struct net_pkt_cursor *backup)
2106 backup->buf = pkt->
cursor.buf;
2107 backup->pos = pkt->
cursor.pos;
2117 struct net_pkt_cursor *backup)
2119 pkt->
cursor.buf = backup->buf;
2120 pkt->
cursor.pos = backup->pos;
2477struct net_pkt_data_access {
2478#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2484#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2485#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2486 struct net_pkt_data_access _name = { \
2487 .size = sizeof(_type), \
2490#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2491 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2494#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2495 _type _hdr_##_name; \
2496 struct net_pkt_data_access _name = { \
2497 .data = &_hdr_##_name, \
2498 .size = sizeof(_type), \
2501#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2502 struct net_pkt_data_access _name = { \
2504 .size = sizeof(_type), \
2525 struct net_pkt_data_access *access);
2541 struct net_pkt_data_access *access);
2548 struct net_pkt_data_access *access)
long atomic_t
Definition atomic_types.h:15
#define ALWAYS_INLINE
Definition common.h:129
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:167
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:123
size_t socklen_t
Length of a socket address.
Definition net_ip.h:171
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:131
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:2711
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:711
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1078
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:2045
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:2360
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:1599
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:2341
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:2324
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:2130
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:2103
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:2547
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:2398
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:2116
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:2379
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:2250
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:124
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:78
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:53
#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:91
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:41
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:104
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:65
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
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:142
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:207
Network Interface structure.
Definition net_if.h:680
Hardware link address structure.
Definition net_linkaddr.h:69
uint8_t * addr
The array of byte representing the address.
Definition net_linkaddr.h:71
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:77
Network packet.
Definition net_pkt.h:69
struct net_buf * frags
buffer fragment
Definition net_pkt.h:81
struct net_context * context
Network connection context.
Definition net_pkt.h:89
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:86
struct net_if * iface
Network interface.
Definition net_pkt.h:92
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:74
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:82
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:77
(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:388
#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