16#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
17#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
24#if defined(CONFIG_IEEE802154)
90#if defined(CONFIG_NET_TCP)
94#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
98#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
120#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
125#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
126 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
149#if defined(CONFIG_NET_IP)
166#if defined(CONFIG_NET_IPV4_AUTO)
173#if defined(CONFIG_NET_LLDP)
180#if defined(CONFIG_NET_TCP)
200#if defined(CONFIG_NET_IP)
205#if defined(CONFIG_NET_IPV6)
208#if defined(CONFIG_NET_IPV4)
214#if defined(CONFIG_NET_IPV4)
217#if defined(CONFIG_NET_IPV6)
222#if defined(CONFIG_NET_IPV4_FRAGMENT) || defined(CONFIG_NET_IPV6_FRAGMENT)
224#if defined(CONFIG_NET_IPV4_FRAGMENT)
230#if defined(CONFIG_NET_IPV6_FRAGMENT)
240#if defined(CONFIG_NET_IPV6)
252#if defined(CONFIG_NET_IP_DSCP_ECN)
261#if defined(CONFIG_NET_VLAN)
270#if defined(NET_PKT_HAS_CONTROL_BLOCK)
275#if defined(CONFIG_IEEE802154)
279 struct net_pkt_cb_ieee802154 cb;
304static inline void net_pkt_set_context(
struct net_pkt *pkt,
310static inline struct net_if *net_pkt_iface(
struct net_pkt *pkt)
315static inline void net_pkt_set_iface(
struct net_pkt *pkt,
struct net_if *iface)
326 pkt->lladdr_src.type = type;
327 pkt->lladdr_dst.type = type;
331static inline struct net_if *net_pkt_orig_iface(
struct net_pkt *pkt)
333#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
334 return pkt->orig_iface;
340static inline void net_pkt_set_orig_iface(
struct net_pkt *pkt,
343#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
344 pkt->orig_iface = iface;
353static inline void net_pkt_set_family(
struct net_pkt *pkt,
uint8_t family)
355 pkt->family = family;
358static inline bool net_pkt_is_ptp(
struct net_pkt *pkt)
360 return !!(pkt->ptp_pkt);
363static inline void net_pkt_set_ptp(
struct net_pkt *pkt,
bool is_ptp)
365 pkt->ptp_pkt = is_ptp;
368static inline bool net_pkt_is_captured(
struct net_pkt *pkt)
370 return !!(pkt->captured);
373static inline void net_pkt_set_captured(
struct net_pkt *pkt,
bool is_captured)
375 pkt->captured = is_captured;
378static inline bool net_pkt_is_l2_bridged(
struct net_pkt *pkt)
380 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
383static inline void net_pkt_set_l2_bridged(
struct net_pkt *pkt,
bool is_l2_bridged)
386 pkt->l2_bridged = is_l2_bridged;
390static inline bool net_pkt_is_l2_processed(
struct net_pkt *pkt)
392 return !!(pkt->l2_processed);
395static inline void net_pkt_set_l2_processed(
struct net_pkt *pkt,
396 bool is_l2_processed)
398 pkt->l2_processed = is_l2_processed;
403#if defined(CONFIG_NET_IP)
404 return pkt->ip_hdr_len;
410static inline void net_pkt_set_ip_hdr_len(
struct net_pkt *pkt,
uint8_t len)
412#if defined(CONFIG_NET_IP)
413 pkt->ip_hdr_len = len;
419#if defined(CONFIG_NET_IP_DSCP_ECN)
426static inline void net_pkt_set_ip_dscp(
struct net_pkt *pkt,
uint8_t dscp)
428#if defined(CONFIG_NET_IP_DSCP_ECN)
435#if defined(CONFIG_NET_IP_DSCP_ECN)
442static inline void net_pkt_set_ip_ecn(
struct net_pkt *pkt,
uint8_t ecn)
444#if defined(CONFIG_NET_IP_DSCP_ECN)
451#if defined(CONFIG_NET_TCP)
452 return pkt->tcp_first_msg;
458static inline void net_pkt_set_tcp_1st_msg(
struct net_pkt *pkt,
bool is_1st)
460#if defined(CONFIG_NET_TCP)
461 pkt->tcp_first_msg = is_1st;
473static inline void net_pkt_set_eof(
struct net_pkt *pkt,
bool eof)
478static inline bool net_pkt_forwarding(
struct net_pkt *pkt)
480 return !!(pkt->forwarding);
483static inline void net_pkt_set_forwarding(
struct net_pkt *pkt,
bool forward)
485 pkt->forwarding = forward;
488#if defined(CONFIG_NET_IPV4)
491 return pkt->ipv4_ttl;
494static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
502 return pkt->ipv4_opts_len;
505static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
508 pkt->ipv4_opts_len = opts_len;
518static inline void net_pkt_set_ipv4_ttl(
struct net_pkt *pkt,
531static inline void net_pkt_set_ipv4_opts_len(
struct net_pkt *pkt,
535 ARG_UNUSED(opts_len);
539#if defined(CONFIG_NET_IPV6)
540static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
542 return pkt->ipv6_ext_opt_len;
545static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
548 pkt->ipv6_ext_opt_len = len;
553 return pkt->ipv6_next_hdr;
556static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
559 pkt->ipv6_next_hdr = next_hdr;
564 return pkt->ipv6_ext_len;
567static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
569 pkt->ipv6_ext_len = len;
574 return pkt->ipv6_prev_hdr_start;
577static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
580 pkt->ipv6_prev_hdr_start = offset;
585 return pkt->ipv6_hop_limit;
588static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
591 pkt->ipv6_hop_limit = hop_limit;
594static inline uint8_t net_pkt_ipv6_ext_opt_len(
struct net_pkt *pkt)
601static inline void net_pkt_set_ipv6_ext_opt_len(
struct net_pkt *pkt,
615static inline void net_pkt_set_ipv6_next_hdr(
struct net_pkt *pkt,
619 ARG_UNUSED(next_hdr);
629static inline void net_pkt_set_ipv6_ext_len(
struct net_pkt *pkt,
uint16_t len)
642static inline void net_pkt_set_ipv6_hdr_prev(
struct net_pkt *pkt,
656static inline void net_pkt_set_ipv6_hop_limit(
struct net_pkt *pkt,
660 ARG_UNUSED(hop_limit);
666#if defined(CONFIG_NET_IPV6)
667 return pkt->ipv6_ext_len;
668#elif defined(CONFIG_NET_IPV4)
669 return pkt->ipv4_opts_len;
677#if defined(CONFIG_NET_IPV4_FRAGMENT)
678static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
680 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
683static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
685 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
690 pkt->ipv4_fragment.flags =
flags;
695 return pkt->ipv4_fragment.id;
698static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
700 pkt->ipv4_fragment.id = id;
703static inline uint16_t net_pkt_ipv4_fragment_offset(
struct net_pkt *pkt)
710static inline bool net_pkt_ipv4_fragment_more(
struct net_pkt *pkt)
730static inline void net_pkt_set_ipv4_fragment_id(
struct net_pkt *pkt,
uint32_t id)
737#if defined(CONFIG_NET_IPV6_FRAGMENT)
740 return pkt->ipv6_fragment.hdr_start;
743static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
746 pkt->ipv6_fragment.hdr_start = start;
749static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
751 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
753static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
755 return (pkt->ipv6_fragment.flags & 0x01) != 0;
758static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
761 pkt->ipv6_fragment.flags =
flags;
766 return pkt->ipv6_fragment.id;
769static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
772 pkt->ipv6_fragment.id = id;
782static inline void net_pkt_set_ipv6_fragment_start(
struct net_pkt *pkt,
789static inline uint16_t net_pkt_ipv6_fragment_offset(
struct net_pkt *pkt)
796static inline bool net_pkt_ipv6_fragment_more(
struct net_pkt *pkt)
803static inline void net_pkt_set_ipv6_fragment_flags(
struct net_pkt *pkt,
817static inline void net_pkt_set_ipv6_fragment_id(
struct net_pkt *pkt,
827 return pkt->priority;
830static inline void net_pkt_set_priority(
struct net_pkt *pkt,
833 pkt->priority = priority;
836#if defined(CONFIG_NET_VLAN)
842static inline void net_pkt_set_vlan_tag(
struct net_pkt *pkt,
uint16_t tag)
852static inline void net_pkt_set_vlan_priority(
struct net_pkt *pkt,
858static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
863static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
868static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
875 return pkt->vlan_tci;
883static inline void net_pkt_set_vlan_tag(
struct net_pkt *pkt,
uint16_t tag)
895static inline bool net_pkt_vlan_dei(
struct net_pkt *pkt)
900static inline void net_pkt_set_vlan_dei(
struct net_pkt *pkt,
bool dei)
911static inline void net_pkt_set_vlan_tci(
struct net_pkt *pkt,
uint16_t tci)
918#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
921 return &pkt->timestamp;
924static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
927 pkt->timestamp.second = timestamp->
second;
928 pkt->timestamp.nanosecond = timestamp->
nanosecond;
936static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
948static inline void net_pkt_set_timestamp(
struct net_pkt *pkt,
952 ARG_UNUSED(timestamp);
962static inline void net_pkt_set_timestamp_ns(
struct net_pkt *pkt,
net_time_t timestamp)
965 ARG_UNUSED(timestamp);
969#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
972 return pkt->create_time;
975static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
978 pkt->create_time = create_time;
988static inline void net_pkt_set_create_time(
struct net_pkt *pkt,
992 ARG_UNUSED(create_time);
1001#if defined(CONFIG_NET_PKT_TXTIME)
1002 return pkt->timestamp.second *
NSEC_PER_SEC + pkt->timestamp.nanosecond;
1014static inline void net_pkt_set_txtime(
struct net_pkt *pkt,
uint64_t txtime)
1016#if defined(CONFIG_NET_PKT_TXTIME)
1025#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1026 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1029 return pkt->detail.stat;
1032static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1034 return pkt->detail.count;
1037static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1039 memset(&pkt->detail, 0,
sizeof(pkt->detail));
1045 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1046 NET_ERR(
"Detail stats count overflow (%d >= %d)",
1047 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1051 pkt->detail.stat[pkt->detail.count++] = tick;
1054#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1055#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1064static inline int net_pkt_stats_tick_count(
struct net_pkt *pkt)
1071static inline void net_pkt_stats_tick_reset(
struct net_pkt *pkt)
1076static inline void net_pkt_set_stats_tick(
struct net_pkt *pkt,
uint32_t tick)
1082#define net_pkt_set_tx_stats_tick(pkt, tick)
1083#define net_pkt_set_rx_stats_tick(pkt, tick)
1087static inline size_t net_pkt_get_len(
struct net_pkt *pkt)
1102static inline bool net_pkt_is_empty(
struct net_pkt *pkt)
1109 return &pkt->lladdr_src;
1114 return &pkt->lladdr_dst;
1117static inline void net_pkt_lladdr_swap(
struct net_pkt *pkt)
1121 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1122 net_pkt_lladdr_dst(pkt)->addr =
addr;
1125static inline void net_pkt_lladdr_clear(
struct net_pkt *pkt)
1127 net_pkt_lladdr_src(pkt)->addr = NULL;
1128 net_pkt_lladdr_src(pkt)->len = 0U;
1133 return pkt->ll_proto_type;
1138 pkt->ll_proto_type =
type;
1141#if defined(CONFIG_NET_IPV4_AUTO)
1142static inline bool net_pkt_ipv4_auto(
struct net_pkt *pkt)
1144 return !!(pkt->ipv4_auto_arp_msg);
1147static inline void net_pkt_set_ipv4_auto(
struct net_pkt *pkt,
1148 bool is_auto_arp_msg)
1150 pkt->ipv4_auto_arp_msg = is_auto_arp_msg;
1153static inline bool net_pkt_ipv4_auto(
struct net_pkt *pkt)
1160static inline void net_pkt_set_ipv4_auto(
struct net_pkt *pkt,
1161 bool is_auto_arp_msg)
1164 ARG_UNUSED(is_auto_arp_msg);
1168#if defined(CONFIG_NET_LLDP)
1169static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1171 return !!(pkt->lldp_pkt);
1174static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1176 pkt->lldp_pkt = is_lldp;
1179static inline bool net_pkt_is_lldp(
struct net_pkt *pkt)
1186static inline void net_pkt_set_lldp(
struct net_pkt *pkt,
bool is_lldp)
1189 ARG_UNUSED(is_lldp);
1193#if defined(CONFIG_NET_L2_PPP)
1194static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1196 return !!(pkt->ppp_msg);
1199static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1202 pkt->ppp_msg = is_ppp_msg;
1205static inline bool net_pkt_is_ppp(
struct net_pkt *pkt)
1212static inline void net_pkt_set_ppp(
struct net_pkt *pkt,
1216 ARG_UNUSED(is_ppp_msg);
1220#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1221static inline void *net_pkt_cb(
struct net_pkt *pkt)
1226static inline void *net_pkt_cb(
struct net_pkt *pkt)
1234#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1235#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1237static inline void net_pkt_set_src_ipv6_addr(
struct net_pkt *pkt)
1240 net_pkt_context(pkt)),
1241 (
struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1244static inline void net_pkt_set_overwrite(
struct net_pkt *pkt,
bool overwrite)
1246 pkt->overwrite = overwrite;
1249static inline bool net_pkt_is_being_overwritten(
struct net_pkt *pkt)
1251 return !!(pkt->overwrite);
1254#ifdef CONFIG_NET_PKT_FILTER
1256bool net_pkt_filter_send_ok(
struct net_pkt *pkt);
1257bool net_pkt_filter_recv_ok(
struct net_pkt *pkt);
1261static inline bool net_pkt_filter_send_ok(
struct net_pkt *pkt)
1268static inline bool net_pkt_filter_recv_ok(
struct net_pkt *pkt)
1277#if defined(CONFIG_NET_PKT_FILTER) && \
1278 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1280bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt);
1284static inline bool net_pkt_filter_ip_recv_ok(
struct net_pkt *pkt)
1293#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1295bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt);
1299static inline bool net_pkt_filter_local_in_recv_ok(
struct net_pkt *pkt)
1323#define NET_PKT_SLAB_DEFINE(name, count) \
1324 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4)
1327#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1342#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1343 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1348#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1349 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1350#define NET_PKT_DEBUG_ENABLED
1353#if defined(NET_PKT_DEBUG_ENABLED)
1365#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1366 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1368struct net_buf *net_pkt_get_reserve_rx_data_debug(
size_t min_len,
1372#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1373 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1375struct net_buf *net_pkt_get_reserve_tx_data_debug(
size_t min_len,
1379#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1380 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1382struct net_buf *net_pkt_get_frag_debug(
struct net_pkt *pkt,
size_t min_len,
1384 const char *caller,
int line);
1385#define net_pkt_get_frag(pkt, min_len, timeout) \
1386 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1388void net_pkt_unref_debug(
struct net_pkt *pkt,
const char *caller,
int line);
1389#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1391struct net_pkt *net_pkt_ref_debug(
struct net_pkt *pkt,
const char *caller,
1393#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1396 const char *caller,
int line);
1397#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1399void net_pkt_frag_unref_debug(
struct net_buf *frag,
1400 const char *caller,
int line);
1401#define net_pkt_frag_unref(frag) \
1402 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1407 const char *caller,
int line);
1408#define net_pkt_frag_del(pkt, parent, frag) \
1409 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1411void net_pkt_frag_add_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1412 const char *caller,
int line);
1413#define net_pkt_frag_add(pkt, frag) \
1414 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1416void net_pkt_frag_insert_debug(
struct net_pkt *pkt,
struct net_buf *frag,
1417 const char *caller,
int line);
1418#define net_pkt_frag_insert(pkt, frag) \
1419 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1432#if defined(NET_PKT_DEBUG_ENABLED)
1435#define net_pkt_print_frags(pkt)
1452#if !defined(NET_PKT_DEBUG_ENABLED)
1470#if !defined(NET_PKT_DEBUG_ENABLED)
1486#if !defined(NET_PKT_DEBUG_ENABLED)
1500#if !defined(NET_PKT_DEBUG_ENABLED)
1513#if !defined(NET_PKT_DEBUG_ENABLED)
1526#if !defined(NET_PKT_DEBUG_ENABLED)
1535#if !defined(NET_PKT_DEBUG_ENABLED)
1549#if !defined(NET_PKT_DEBUG_ENABLED)
1561#if !defined(NET_PKT_DEBUG_ENABLED)
1571#if !defined(NET_PKT_DEBUG_ENABLED)
1592 struct k_mem_slab **tx,
1598#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1602void net_pkt_print(
void);
1604typedef void (*net_pkt_allocs_cb_t)(
struct net_pkt *pkt,
1606 const char *func_alloc,
1608 const char *func_free,
1613void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb,
void *
user_data);
1615const char *net_pkt_slab2str(
struct k_mem_slab *slab);
1616const char *net_pkt_pool2str(
struct net_buf_pool *pool);
1619#define net_pkt_print(...)
1625#if defined(NET_PKT_DEBUG_ENABLED)
1628 const char *caller,
int line);
1629#define net_pkt_alloc(_timeout) \
1630 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1632struct net_pkt *net_pkt_alloc_from_slab_debug(
struct k_mem_slab *
slab,
1634 const char *caller,
int line);
1635#define net_pkt_alloc_from_slab(_slab, _timeout) \
1636 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1639 const char *caller,
int line);
1640#define net_pkt_rx_alloc(_timeout) \
1641 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1647#define net_pkt_alloc_on_iface(_iface, _timeout) \
1648 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1654#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1655 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1658int net_pkt_alloc_buffer_debug(
struct net_pkt *pkt,
1662 const char *caller,
int line);
1663#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1664 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1674#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1676 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1687#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1689 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1705#if !defined(NET_PKT_DEBUG_ENABLED)
1723#if !defined(NET_PKT_DEBUG_ENABLED)
1738#if !defined(NET_PKT_DEBUG_ENABLED)
1750#if !defined(NET_PKT_DEBUG_ENABLED)
1774#if !defined(NET_PKT_DEBUG_ENABLED)
1792#if !defined(NET_PKT_DEBUG_ENABLED)
2193#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2199#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2200#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2201 struct net_pkt_data_access _name = { \
2202 .size = sizeof(_type), \
2205#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2206 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2209#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2210 _type _hdr_##_name; \
2211 struct net_pkt_data_access _name = { \
2212 .data = &_hdr_##_name, \
2213 .size = sizeof(_type), \
2216#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2217 struct net_pkt_data_access _name = { \
2219 .size = sizeof(_type), \
long atomic_t
Definition: atomic.h:22
#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:164
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition: net_ip.h:120
#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(struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition: buf.h:2454
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition: net_context.h:649
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition: net_if.h:945
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:1762
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)
Definition: net_pkt.h:2099
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:1435
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.
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_alloc_with_buffer(struct net_if *iface, size_t size, sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout)
struct net_pkt * net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout)
Clone pkt and its buffer.
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)
Definition: net_pkt.h:2091
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)
Definition: net_pkt.h:2085
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.
struct net_pkt * net_pkt_rx_alloc_on_iface(struct net_if *iface, k_timeout_t timeout)
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:1913
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:1886
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:2260
static int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
Definition: net_pkt.h:2115
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:1899
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)
Definition: net_pkt.h:2107
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)
Definition: net_pkt.h:2022
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:193
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:214
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
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)
IPv6 address struct.
Definition: net_ip.h:139
Kernel timeout type.
Definition: sys_clock.h:65
Network buffer pool representation.
Definition: buf.h:971
Network buffer representation.
Definition: buf.h:906
uint8_t * data
Pointer to the start of data in the buffer.
Definition: buf.h:932
uint8_t user_data[]
System metadata for this buffer.
Definition: buf.h:951
uint16_t len
Length of the data behind the data pointer.
Definition: buf.h:935
Note that we do not store the actual source IP address in the context because the address is already ...
Definition: net_context.h:201
Network Interface structure.
Definition: net_if.h:595
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
uint8_t * pos
Current position in the data buffer of the net_buf.
Definition: net_pkt.h:54
struct net_buf * buf
Current net_buf pointer by the cursor.
Definition: net_pkt.h:52
Definition: net_pkt.h:2192
const size_t size
Definition: net_pkt.h:2196
void * data
Definition: net_pkt.h:2194
Network packet.
Definition: net_pkt.h:63
struct net_buf * frags
Definition: net_pkt.h:75
struct net_context * context
Network connection context.
Definition: net_pkt.h:83
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition: net_pkt.h:80
struct net_if * iface
Network interface.
Definition: net_pkt.h:86
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition: net_pkt.h:68
struct net_buf * buffer
Definition: net_pkt.h:76
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition: net_pkt.h:71
(Generalized) Precision Time Protocol Timestamp format.
Definition: ptp_time.h:109
uint32_t nanosecond
Nanoseconds.
Definition: ptp_time.h:127
uint64_t second
Definition: ptp_time.h:123
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition: byteorder.h:262
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition: byteorder.h:258