Zephyr API Documentation 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_pkt.h
Go to the documentation of this file.
1
8/*
9 * Copyright (c) 2016 Intel Corporation
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13
14/* Data buffer API - used for all data to/from net */
15
16#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
17#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
18
19#include <zephyr/types.h>
20#include <stdbool.h>
21
22#include <zephyr/net_buf.h>
23
24#if defined(CONFIG_IEEE802154)
26#endif
27#include <zephyr/net/net_core.h>
29#include <zephyr/net/net_ip.h>
30#include <zephyr/net/net_if.h>
32#include <zephyr/net/net_time.h>
34#include <zephyr/net/ptp_time.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
49struct net_context;
50
53#if defined(CONFIG_NET_PKT_ALLOC_STATS)
54struct net_pkt_alloc_stats {
55 uint64_t alloc_sum;
56 uint64_t time_sum;
57 uint32_t count;
58};
59
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;
64};
65
66#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
67 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
68 .slab = &slab_name, \
69 }
70
71#else
72#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
73#endif /* CONFIG_NET_PKT_ALLOC_STATS */
74
75/* buffer cursor used in net_pkt */
76struct net_pkt_cursor {
78 struct net_buf *buf;
80 uint8_t *pos;
81};
82
91struct net_pkt {
97
99 struct k_mem_slab *slab;
100
102 union {
103 struct net_buf *frags;
104 struct net_buf *buffer;
105 };
106
108 struct net_pkt_cursor cursor;
109
112
114 struct net_if *iface;
115
118#if defined(CONFIG_NET_TCP)
120 sys_snode_t next;
121#endif
122#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
123 struct net_if *orig_iface; /* Original network interface */
124#endif
125
126#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
145 struct net_ptp_time timestamp;
146#endif
147
148#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
149 defined(CONFIG_TRACING_NET_CORE)
150 struct {
152 uint32_t create_time;
153
154#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
155 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
161 struct {
162 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
163 int count;
164 } detail;
165#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
166 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
167 };
168#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
169
170#if defined(CONFIG_NET_PKT_ALLOC_STATS)
171 struct net_pkt_alloc_stats_slab *alloc_stats;
172#endif /* CONFIG_NET_PKT_ALLOC_STATS */
173
175 atomic_t atomic_ref;
176
177 /* Filled by layer 2 when network packet is received. */
178 struct net_linkaddr lladdr_src;
179 struct net_linkaddr lladdr_dst;
180 uint16_t ll_proto_type;
181
182#if defined(CONFIG_NET_IP)
183 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
184#endif
185
186 uint8_t overwrite : 1; /* Is packet content being overwritten? */
187 uint8_t eof : 1; /* Last packet before EOF */
188 uint8_t ptp_pkt : 1; /* For outgoing packet: is this packet
189 * a L2 PTP packet.
190 * Used only if defined (CONFIG_NET_L2_PTP)
191 */
192 uint8_t forwarding : 1; /* Are we forwarding this pkt
193 * Used only if defined(CONFIG_NET_ROUTE)
194 */
195 uint8_t family : 3; /* Address family, see net_ip.h */
196
197 /* bitfield byte alignment boundary */
198
199#if defined(CONFIG_NET_IPV4_ACD)
200 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
201 * message.
202 * Note: family needs to be
203 * AF_INET.
204 */
205#endif
206#if defined(CONFIG_NET_LLDP)
207 uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
208 * Note: family needs to be
209 * AF_UNSPEC.
210 */
211#endif
212 uint8_t ppp_msg : 1; /* This is a PPP message */
213 uint8_t captured : 1; /* Set to 1 if this packet is already being
214 * captured
215 */
216 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
217 * and already contains its L2 header to be
218 * preserved. Useful only if
219 * defined(CONFIG_NET_ETHERNET_BRIDGE).
220 */
221 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
222 * processed by the L2
223 */
224 uint8_t chksum_done : 1; /* Checksum has already been computed for
225 * the packet.
226 */
227#if defined(CONFIG_NET_IP_FRAGMENT)
228 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
229#endif
230#if defined(CONFIG_NET_PKT_TIMESTAMP)
231 uint8_t tx_timestamping : 1;
232 uint8_t rx_timestamping : 1;
233#endif
234 /* bitfield byte alignment boundary */
235
236#if defined(CONFIG_NET_IP)
237 union {
238 /* IPv6 hop limit or IPv4 ttl for this network packet.
239 * The value is shared between IPv6 and IPv4.
240 */
241#if defined(CONFIG_NET_IPV6)
242 uint8_t ipv6_hop_limit;
243#endif
244#if defined(CONFIG_NET_IPV4)
245 uint8_t ipv4_ttl;
246#endif
247 };
248
249 union {
250#if defined(CONFIG_NET_IPV4)
251 uint8_t ipv4_opts_len; /* length of IPv4 header options */
252#endif
253#if defined(CONFIG_NET_IPV6)
254 uint16_t ipv6_ext_len; /* length of extension headers */
255#endif
256 };
257
258#if defined(CONFIG_NET_IP_FRAGMENT)
259 union {
260#if defined(CONFIG_NET_IPV4_FRAGMENT)
261 struct {
262 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
263 uint16_t id; /* Fragment ID */
264 } ipv4_fragment;
265#endif /* CONFIG_NET_IPV4_FRAGMENT */
266#if defined(CONFIG_NET_IPV6_FRAGMENT)
267 struct {
268 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
269 uint32_t id; /* Fragment id */
270 uint16_t hdr_start; /* Where starts the fragment header */
271 } ipv6_fragment;
272#endif /* CONFIG_NET_IPV6_FRAGMENT */
273 };
274#endif /* CONFIG_NET_IP_FRAGMENT */
275
276#if defined(CONFIG_NET_IPV6)
277 /* Where is the start of the last header before payload data
278 * in IPv6 packet. This is offset value from start of the IPv6
279 * packet. Note that this value should be updated by who ever
280 * adds IPv6 extension headers to the network packet.
281 */
282 uint16_t ipv6_prev_hdr_start;
283
284 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
285 uint8_t ipv6_next_hdr; /* What is the very first next header */
286#endif /* CONFIG_NET_IPV6 */
287
288#if defined(CONFIG_NET_IP_DSCP_ECN)
290 uint8_t ip_dscp : 6;
291
293 uint8_t ip_ecn : 2;
294#endif /* CONFIG_NET_IP_DSCP_ECN */
295#endif /* CONFIG_NET_IP */
296
297#if defined(CONFIG_NET_VLAN)
298 /* VLAN TCI (Tag Control Information). This contains the Priority
299 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
300 * Identifier (VID, called more commonly VLAN tag). This value is
301 * kept in host byte order.
302 */
303 uint16_t vlan_tci;
304#endif /* CONFIG_NET_VLAN */
305
306#if defined(NET_PKT_HAS_CONTROL_BLOCK)
307 /* TODO: Evolve this into a union of orthogonal
308 * control block declarations if further L2
309 * stacks require L2-specific attributes.
310 */
311#if defined(CONFIG_IEEE802154)
312 /* The following structure requires a 4-byte alignment
313 * boundary to avoid padding.
314 */
315 struct net_pkt_cb_ieee802154 cb;
316#endif /* CONFIG_IEEE802154 */
317#endif /* NET_PKT_HAS_CONTROL_BLOCK */
318
322 uint8_t priority;
323
324#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
325 /* Remote address of the received packet. This is only used by
326 * network interfaces with an offloaded TCP/IP stack, or if we
327 * have network tunneling in use.
328 */
329 union {
330 struct sockaddr remote;
331
332 /* This will make sure that there is enough storage to store
333 * the address struct. The access to value is via remote
334 * address.
335 */
336 struct sockaddr_storage remote_storage;
337 };
338#endif /* CONFIG_NET_OFFLOAD */
339
340#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
341 /* Tell the capture api that this is a captured packet */
342 uint8_t cooked_mode_pkt : 1;
343#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
344
345 /* @endcond */
346};
347
350/* The interface real ll address */
351static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
352{
353 return net_if_get_link_addr(pkt->iface);
354}
355
356static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
357{
358 return pkt->context;
359}
360
361static inline void net_pkt_set_context(struct net_pkt *pkt,
362 struct net_context *ctx)
363{
364 pkt->context = ctx;
365}
366
367static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
368{
369 return pkt->iface;
370}
371
372static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
373{
374 pkt->iface = iface;
375
376 /* If the network interface is set in pkt, then also set the type of
377 * the network address that is stored in pkt. This is done here so
378 * that the address type is properly set and is not forgotten.
379 */
380 if (iface) {
381 uint8_t type = net_if_get_link_addr(iface)->type;
382
383 pkt->lladdr_src.type = type;
384 pkt->lladdr_dst.type = type;
385 }
386}
387
388static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
389{
390#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
391 return pkt->orig_iface;
392#else
393 return pkt->iface;
394#endif
395}
396
397static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
398 struct net_if *iface)
399{
400#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
401 pkt->orig_iface = iface;
402#else
403 ARG_UNUSED(pkt);
404 ARG_UNUSED(iface);
405#endif
406}
407
408static inline uint8_t net_pkt_family(struct net_pkt *pkt)
409{
410 return pkt->family;
411}
412
413static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
414{
415 pkt->family = family;
416}
417
418static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
419{
420 return !!(pkt->ptp_pkt);
421}
422
423static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
424{
425 pkt->ptp_pkt = is_ptp;
426}
427
428static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
429{
430#if defined(CONFIG_NET_PKT_TIMESTAMP)
431 return !!(pkt->tx_timestamping);
432#else
433 ARG_UNUSED(pkt);
434
435 return false;
436#endif
437}
438
439static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
440{
441#if defined(CONFIG_NET_PKT_TIMESTAMP)
442 pkt->tx_timestamping = is_timestamping;
443#else
444 ARG_UNUSED(pkt);
445 ARG_UNUSED(is_timestamping);
446#endif
447}
448
449static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
450{
451#if defined(CONFIG_NET_PKT_TIMESTAMP)
452 return !!(pkt->rx_timestamping);
453#else
454 ARG_UNUSED(pkt);
455
456 return false;
457#endif
458}
459
460static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
461{
462#if defined(CONFIG_NET_PKT_TIMESTAMP)
463 pkt->rx_timestamping = is_timestamping;
464#else
465 ARG_UNUSED(pkt);
466 ARG_UNUSED(is_timestamping);
467#endif
468}
469
470static inline bool net_pkt_is_captured(struct net_pkt *pkt)
471{
472 return !!(pkt->captured);
473}
474
475static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
476{
477 pkt->captured = is_captured;
478}
479
480static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
481{
482 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
483}
484
485static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
486{
487 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
488 pkt->l2_bridged = is_l2_bridged;
489 }
490}
491
492static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
493{
494 return !!(pkt->l2_processed);
495}
496
497static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
498 bool is_l2_processed)
499{
500 pkt->l2_processed = is_l2_processed;
501}
502
503static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
504{
505 return !!(pkt->chksum_done);
506}
507
508static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
509 bool is_chksum_done)
510{
511 pkt->chksum_done = is_chksum_done;
512}
513
514static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
515{
516#if defined(CONFIG_NET_IP)
517 return pkt->ip_hdr_len;
518#else
519 ARG_UNUSED(pkt);
520
521 return 0;
522#endif
523}
524
525static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
526{
527#if defined(CONFIG_NET_IP)
528 pkt->ip_hdr_len = len;
529#else
530 ARG_UNUSED(pkt);
531 ARG_UNUSED(len);
532#endif
533}
534
535static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
536{
537#if defined(CONFIG_NET_IP_DSCP_ECN)
538 return pkt->ip_dscp;
539#else
540 ARG_UNUSED(pkt);
541
542 return 0;
543#endif
544}
545
546static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
547{
548#if defined(CONFIG_NET_IP_DSCP_ECN)
549 pkt->ip_dscp = dscp;
550#else
551 ARG_UNUSED(pkt);
552 ARG_UNUSED(dscp);
553#endif
554}
555
556static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
557{
558#if defined(CONFIG_NET_IP_DSCP_ECN)
559 return pkt->ip_ecn;
560#else
561 ARG_UNUSED(pkt);
562
563 return 0;
564#endif
565}
566
567static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
568{
569#if defined(CONFIG_NET_IP_DSCP_ECN)
570 pkt->ip_ecn = ecn;
571#else
572 ARG_UNUSED(pkt);
573 ARG_UNUSED(ecn);
574#endif
575}
576
577static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
578{
579 return pkt->eof;
580}
581
582static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
583{
584 pkt->eof = eof;
585}
586
587static inline bool net_pkt_forwarding(struct net_pkt *pkt)
588{
589 return !!(pkt->forwarding);
590}
591
592static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
593{
594 pkt->forwarding = forward;
595}
596
597#if defined(CONFIG_NET_IPV4)
598static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
599{
600 return pkt->ipv4_ttl;
601}
602
603static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
604 uint8_t ttl)
605{
606 pkt->ipv4_ttl = ttl;
607}
608
609static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
610{
611 return pkt->ipv4_opts_len;
612}
613
614static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
615 uint8_t opts_len)
616{
617 pkt->ipv4_opts_len = opts_len;
618}
619#else
620static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
621{
622 ARG_UNUSED(pkt);
623
624 return 0;
625}
626
627static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
628 uint8_t ttl)
629{
630 ARG_UNUSED(pkt);
631 ARG_UNUSED(ttl);
632}
633
634static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
635{
636 ARG_UNUSED(pkt);
637 return 0;
638}
639
640static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
641 uint8_t opts_len)
642{
643 ARG_UNUSED(pkt);
644 ARG_UNUSED(opts_len);
645}
646#endif
647
648#if defined(CONFIG_NET_IPV6)
649static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
650{
651 return pkt->ipv6_ext_opt_len;
652}
653
654static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
655 uint8_t len)
656{
657 pkt->ipv6_ext_opt_len = len;
658}
659
660static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
661{
662 return pkt->ipv6_next_hdr;
663}
664
665static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
666 uint8_t next_hdr)
667{
668 pkt->ipv6_next_hdr = next_hdr;
669}
670
671static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
672{
673 return pkt->ipv6_ext_len;
674}
675
676static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
677{
678 pkt->ipv6_ext_len = len;
679}
680
681static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
682{
683 return pkt->ipv6_prev_hdr_start;
684}
685
686static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
687 uint16_t offset)
688{
689 pkt->ipv6_prev_hdr_start = offset;
690}
691
692static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
693{
694 return pkt->ipv6_hop_limit;
695}
696
697static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
698 uint8_t hop_limit)
699{
700 pkt->ipv6_hop_limit = hop_limit;
701}
702#else /* CONFIG_NET_IPV6 */
703static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
704{
705 ARG_UNUSED(pkt);
706
707 return 0;
708}
709
710static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
711 uint8_t len)
712{
713 ARG_UNUSED(pkt);
714 ARG_UNUSED(len);
715}
716
717static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
718{
719 ARG_UNUSED(pkt);
720
721 return 0;
722}
723
724static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
725 uint8_t next_hdr)
726{
727 ARG_UNUSED(pkt);
728 ARG_UNUSED(next_hdr);
729}
730
731static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
732{
733 ARG_UNUSED(pkt);
734
735 return 0;
736}
737
738static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
739{
740 ARG_UNUSED(pkt);
741 ARG_UNUSED(len);
742}
743
744static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
745{
746 ARG_UNUSED(pkt);
747
748 return 0;
749}
750
751static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
752 uint16_t offset)
753{
754 ARG_UNUSED(pkt);
755 ARG_UNUSED(offset);
756}
757
758static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
759{
760 ARG_UNUSED(pkt);
761
762 return 0;
763}
764
765static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
766 uint8_t hop_limit)
767{
768 ARG_UNUSED(pkt);
769 ARG_UNUSED(hop_limit);
770}
771#endif /* CONFIG_NET_IPV6 */
772
773static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
774{
775#if defined(CONFIG_NET_IPV6)
776 return pkt->ipv6_ext_len;
777#elif defined(CONFIG_NET_IPV4)
778 return pkt->ipv4_opts_len;
779#else
780 ARG_UNUSED(pkt);
781
782 return 0;
783#endif
784}
785
786#if defined(CONFIG_NET_IPV4_FRAGMENT)
787static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
788{
789 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
790}
791
792static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
793{
794 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
795}
796
797static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
798{
799 pkt->ipv4_fragment.flags = flags;
800}
801
802static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
803{
804 return pkt->ipv4_fragment.id;
805}
806
807static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
808{
809 pkt->ipv4_fragment.id = id;
810}
811#else /* CONFIG_NET_IPV4_FRAGMENT */
812static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
813{
814 ARG_UNUSED(pkt);
815
816 return 0;
817}
818
819static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
820{
821 ARG_UNUSED(pkt);
822
823 return 0;
824}
825
826static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
827{
828 ARG_UNUSED(pkt);
829 ARG_UNUSED(flags);
830}
831
832static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
833{
834 ARG_UNUSED(pkt);
835
836 return 0;
837}
838
839static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
840{
841 ARG_UNUSED(pkt);
842 ARG_UNUSED(id);
843}
844#endif /* CONFIG_NET_IPV4_FRAGMENT */
845
846#if defined(CONFIG_NET_IPV6_FRAGMENT)
847static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
848{
849 return pkt->ipv6_fragment.hdr_start;
850}
851
852static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
853 uint16_t start)
854{
855 pkt->ipv6_fragment.hdr_start = start;
856}
857
858static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
859{
860 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
861}
862static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
863{
864 return (pkt->ipv6_fragment.flags & 0x01) != 0;
865}
866
867static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
869{
870 pkt->ipv6_fragment.flags = flags;
871}
872
873static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
874{
875 return pkt->ipv6_fragment.id;
876}
877
878static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
879 uint32_t id)
880{
881 pkt->ipv6_fragment.id = id;
882}
883#else /* CONFIG_NET_IPV6_FRAGMENT */
884static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
885{
886 ARG_UNUSED(pkt);
887
888 return 0;
889}
890
891static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
892 uint16_t start)
893{
894 ARG_UNUSED(pkt);
895 ARG_UNUSED(start);
896}
897
898static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
899{
900 ARG_UNUSED(pkt);
901
902 return 0;
903}
904
905static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
906{
907 ARG_UNUSED(pkt);
908
909 return 0;
910}
911
912static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
914{
915 ARG_UNUSED(pkt);
916 ARG_UNUSED(flags);
917}
918
919static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
920{
921 ARG_UNUSED(pkt);
922
923 return 0;
924}
925
926static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
927 uint32_t id)
928{
929 ARG_UNUSED(pkt);
930 ARG_UNUSED(id);
931}
932#endif /* CONFIG_NET_IPV6_FRAGMENT */
933
934#if defined(CONFIG_NET_IP_FRAGMENT)
935static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
936{
937 return !!(pkt->ip_reassembled);
938}
939
940static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
941 bool reassembled)
942{
943 pkt->ip_reassembled = reassembled;
944}
945#else /* CONFIG_NET_IP_FRAGMENT */
946static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
947{
948 ARG_UNUSED(pkt);
949
950 return false;
951}
952
953static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
954 bool reassembled)
955{
956 ARG_UNUSED(pkt);
957 ARG_UNUSED(reassembled);
958}
959#endif /* CONFIG_NET_IP_FRAGMENT */
960
961static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
962{
963 return pkt->priority;
964}
965
966static inline void net_pkt_set_priority(struct net_pkt *pkt,
967 uint8_t priority)
968{
969 pkt->priority = priority;
970}
971
972#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
973static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
974{
975 return pkt->cooked_mode_pkt;
976}
977
978static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
979{
980 pkt->cooked_mode_pkt = value;
981}
982#else
983static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
984{
985 ARG_UNUSED(pkt);
986
987 return false;
988}
989
990static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
991{
992 ARG_UNUSED(pkt);
993 ARG_UNUSED(value);
994}
995#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
996
997#if defined(CONFIG_NET_VLAN)
998static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
999{
1000 return net_eth_vlan_get_vid(pkt->vlan_tci);
1001}
1002
1003static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1004{
1005 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1006}
1007
1008static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1009{
1010 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1011}
1012
1013static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1014 uint8_t priority)
1015{
1016 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1017}
1018
1019static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1020{
1021 return net_eth_vlan_get_dei(pkt->vlan_tci);
1022}
1023
1024static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1025{
1026 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1027}
1028
1029static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1030{
1031 pkt->vlan_tci = tci;
1032}
1033
1034static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1035{
1036 return pkt->vlan_tci;
1037}
1038#else
1039static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1040{
1041 ARG_UNUSED(pkt);
1042
1043 return NET_VLAN_TAG_UNSPEC;
1044}
1045
1046static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1047{
1048 ARG_UNUSED(pkt);
1049 ARG_UNUSED(tag);
1050}
1051
1052static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1053{
1054 ARG_UNUSED(pkt);
1055
1056 return 0;
1057}
1058
1059static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1060{
1061 ARG_UNUSED(pkt);
1062
1063 return false;
1064}
1065
1066static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1067{
1068 ARG_UNUSED(pkt);
1069 ARG_UNUSED(dei);
1070}
1071
1072static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1073{
1074 ARG_UNUSED(pkt);
1075
1076 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1077}
1078
1079static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1080{
1081 ARG_UNUSED(pkt);
1082 ARG_UNUSED(tci);
1083}
1084#endif
1085
1086#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1087static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1088{
1089 return &pkt->timestamp;
1090}
1091
1092static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1093 struct net_ptp_time *timestamp)
1094{
1095 pkt->timestamp.second = timestamp->second;
1096 pkt->timestamp.nanosecond = timestamp->nanosecond;
1097}
1098
1099static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1100{
1101 return net_ptp_time_to_ns(&pkt->timestamp);
1102}
1103
1104static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1105{
1106 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1107}
1108#else
1109static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1110{
1111 ARG_UNUSED(pkt);
1112
1113 return NULL;
1114}
1115
1116static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1117 struct net_ptp_time *timestamp)
1118{
1119 ARG_UNUSED(pkt);
1120 ARG_UNUSED(timestamp);
1121}
1122
1123static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1124{
1125 ARG_UNUSED(pkt);
1126
1127 return 0;
1128}
1129
1130static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1131{
1132 ARG_UNUSED(pkt);
1133 ARG_UNUSED(timestamp);
1134}
1135#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1136
1137#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1138 defined(CONFIG_TRACING_NET_CORE)
1139
1140static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1141{
1142 return pkt->create_time;
1143}
1144
1145static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1146 uint32_t create_time)
1147{
1148 pkt->create_time = create_time;
1149}
1150#else
1151static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1152{
1153 ARG_UNUSED(pkt);
1154
1155 return 0U;
1156}
1157
1158static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1159 uint32_t create_time)
1160{
1161 ARG_UNUSED(pkt);
1162 ARG_UNUSED(create_time);
1163}
1164#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1165 * CONFIG_TRACING_NET_CORE
1166 */
1167
1168#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1169 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1170static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1171{
1172 return pkt->detail.stat;
1173}
1174
1175static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1176{
1177 return pkt->detail.count;
1178}
1179
1180static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1181{
1182 memset(&pkt->detail, 0, sizeof(pkt->detail));
1183}
1184
1185static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1186 uint32_t tick)
1187{
1188 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1189 NET_ERR("Detail stats count overflow (%d >= %d)",
1190 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1191 return;
1192 }
1193
1194 pkt->detail.stat[pkt->detail.count++] = tick;
1195}
1196
1197#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1198#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1199#else
1200static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1201{
1202 ARG_UNUSED(pkt);
1203
1204 return NULL;
1205}
1206
1207static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1208{
1209 ARG_UNUSED(pkt);
1210
1211 return 0;
1212}
1213
1214static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1215{
1216 ARG_UNUSED(pkt);
1217}
1218
1219static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1220{
1221 ARG_UNUSED(pkt);
1222 ARG_UNUSED(tick);
1223}
1224
1225#define net_pkt_set_tx_stats_tick(pkt, tick)
1226#define net_pkt_set_rx_stats_tick(pkt, tick)
1227#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1228 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1229
1230static inline size_t net_pkt_get_len(struct net_pkt *pkt)
1231{
1232 return net_buf_frags_len(pkt->frags);
1233}
1234
1235static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1236{
1237 return pkt->frags->data;
1238}
1239
1240static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1241{
1242 return pkt->frags->data;
1243}
1244
1245static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1246{
1247 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1248}
1249
1250static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1251{
1252 return &pkt->lladdr_src;
1253}
1254
1255static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1256{
1257 return &pkt->lladdr_dst;
1258}
1259
1260static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1261{
1262 uint8_t *addr = net_pkt_lladdr_src(pkt)->addr;
1263
1264 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1265 net_pkt_lladdr_dst(pkt)->addr = addr;
1266}
1267
1268static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1269{
1270 net_pkt_lladdr_src(pkt)->addr = NULL;
1271 net_pkt_lladdr_src(pkt)->len = 0U;
1272}
1273
1274static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1275{
1276 return pkt->ll_proto_type;
1277}
1278
1279static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1280{
1281 pkt->ll_proto_type = type;
1282}
1283
1284#if defined(CONFIG_NET_IPV4_ACD)
1285static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1286{
1287 return !!(pkt->ipv4_acd_arp_msg);
1288}
1289
1290static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1291 bool is_acd_arp_msg)
1292{
1293 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1294}
1295#else /* CONFIG_NET_IPV4_ACD */
1296static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1297{
1298 ARG_UNUSED(pkt);
1299
1300 return false;
1301}
1302
1303static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1304 bool is_acd_arp_msg)
1305{
1306 ARG_UNUSED(pkt);
1307 ARG_UNUSED(is_acd_arp_msg);
1308}
1309#endif /* CONFIG_NET_IPV4_ACD */
1310
1311#if defined(CONFIG_NET_LLDP)
1312static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1313{
1314 return !!(pkt->lldp_pkt);
1315}
1316
1317static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1318{
1319 pkt->lldp_pkt = is_lldp;
1320}
1321#else
1322static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1323{
1324 ARG_UNUSED(pkt);
1325
1326 return false;
1327}
1328
1329static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1330{
1331 ARG_UNUSED(pkt);
1332 ARG_UNUSED(is_lldp);
1333}
1334#endif /* CONFIG_NET_LLDP */
1335
1336#if defined(CONFIG_NET_L2_PPP)
1337static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1338{
1339 return !!(pkt->ppp_msg);
1340}
1341
1342static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1343 bool is_ppp_msg)
1344{
1345 pkt->ppp_msg = is_ppp_msg;
1346}
1347#else /* CONFIG_NET_L2_PPP */
1348static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1349{
1350 ARG_UNUSED(pkt);
1351
1352 return false;
1353}
1354
1355static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1356 bool is_ppp_msg)
1357{
1358 ARG_UNUSED(pkt);
1359 ARG_UNUSED(is_ppp_msg);
1360}
1361#endif /* CONFIG_NET_L2_PPP */
1362
1363#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1364static inline void *net_pkt_cb(struct net_pkt *pkt)
1365{
1366 return &pkt->cb;
1367}
1368#else
1369static inline void *net_pkt_cb(struct net_pkt *pkt)
1370{
1371 ARG_UNUSED(pkt);
1372
1373 return NULL;
1374}
1375#endif
1376
1377#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1378#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1379
1380static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1381{
1383 net_pkt_context(pkt)),
1384 (struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1385}
1386
1387static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1388{
1389 pkt->overwrite = overwrite;
1390}
1391
1392static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1393{
1394 return !!(pkt->overwrite);
1395}
1396
1397#ifdef CONFIG_NET_PKT_FILTER
1398
1399bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1400bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1401
1402#else
1403
1404static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1405{
1406 ARG_UNUSED(pkt);
1407
1408 return true;
1409}
1410
1411static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1412{
1413 ARG_UNUSED(pkt);
1414
1415 return true;
1416}
1417
1418#endif /* CONFIG_NET_PKT_FILTER */
1419
1420#if defined(CONFIG_NET_PKT_FILTER) && \
1421 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1422
1423bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1424
1425#else
1426
1427static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1428{
1429 ARG_UNUSED(pkt);
1430
1431 return true;
1432}
1433
1434#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1435
1436#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1437
1438bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1439
1440#else
1441
1442static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1443{
1444 ARG_UNUSED(pkt);
1445
1446 return true;
1447}
1448
1449#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1450
1451#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1452static inline struct sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1453{
1454 return &pkt->remote;
1455}
1456
1457static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1458 struct sockaddr *address,
1459 socklen_t len)
1460{
1461 memcpy(&pkt->remote, address, len);
1462}
1463#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1464
1465/* @endcond */
1466
1480#define NET_PKT_SLAB_DEFINE(name, count) \
1481 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4); \
1482 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1483
1486/* Backward compatibility macro */
1487#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1488
1504#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1505 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1506 0, NULL)
1507
1510#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1511 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1512#define NET_PKT_DEBUG_ENABLED
1513#endif
1514
1515#if defined(NET_PKT_DEBUG_ENABLED)
1516
1517/* Debug versions of the net_pkt functions that are used when tracking
1518 * buffer usage.
1519 */
1520
1521struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1522 size_t min_len,
1523 k_timeout_t timeout,
1524 const char *caller,
1525 int line);
1526
1527#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1528 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1529
1530struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1531 k_timeout_t timeout,
1532 const char *caller,
1533 int line);
1534#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1535 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1536
1537struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1538 k_timeout_t timeout,
1539 const char *caller,
1540 int line);
1541#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1542 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1543
1544struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1545 k_timeout_t timeout,
1546 const char *caller, int line);
1547#define net_pkt_get_frag(pkt, min_len, timeout) \
1548 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1549
1550void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1551#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1552
1553struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1554 int line);
1555#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1556
1557struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1558 const char *caller, int line);
1559#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1560
1561void net_pkt_frag_unref_debug(struct net_buf *frag,
1562 const char *caller, int line);
1563#define net_pkt_frag_unref(frag) \
1564 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1565
1566struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1567 struct net_buf *parent,
1568 struct net_buf *frag,
1569 const char *caller, int line);
1570#define net_pkt_frag_del(pkt, parent, frag) \
1571 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1572
1573void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1574 const char *caller, int line);
1575#define net_pkt_frag_add(pkt, frag) \
1576 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1577
1578void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1579 const char *caller, int line);
1580#define net_pkt_frag_insert(pkt, frag) \
1581 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1582#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1583 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1584 */
1587#if defined(NET_PKT_DEBUG_ENABLED)
1595void net_pkt_print_frags(struct net_pkt *pkt);
1596#else
1597#define net_pkt_print_frags(pkt)
1598#endif
1599
1600#if !defined(NET_PKT_DEBUG_ENABLED)
1616 size_t min_len, k_timeout_t timeout);
1617#endif
1618
1619#if !defined(NET_PKT_DEBUG_ENABLED)
1634struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1635#endif
1636
1637#if !defined(NET_PKT_DEBUG_ENABLED)
1652struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1653#endif
1654
1655#if !defined(NET_PKT_DEBUG_ENABLED)
1668struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1669 k_timeout_t timeout);
1670#endif
1671
1672#if !defined(NET_PKT_DEBUG_ENABLED)
1682void net_pkt_unref(struct net_pkt *pkt);
1683#endif
1684
1685#if !defined(NET_PKT_DEBUG_ENABLED)
1695struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1696#endif
1697
1698#if !defined(NET_PKT_DEBUG_ENABLED)
1708struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1709#endif
1710
1711#if !defined(NET_PKT_DEBUG_ENABLED)
1717void net_pkt_frag_unref(struct net_buf *frag);
1718#endif
1719
1720#if !defined(NET_PKT_DEBUG_ENABLED)
1732 struct net_buf *parent,
1733 struct net_buf *frag);
1734#endif
1735
1736#if !defined(NET_PKT_DEBUG_ENABLED)
1743void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1744#endif
1745
1746#if !defined(NET_PKT_DEBUG_ENABLED)
1753void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1754#endif
1755
1762void net_pkt_compact(struct net_pkt *pkt);
1763
1772void net_pkt_get_info(struct k_mem_slab **rx,
1773 struct k_mem_slab **tx,
1774 struct net_buf_pool **rx_data,
1775 struct net_buf_pool **tx_data);
1776
1779#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1783void net_pkt_print(void);
1784
1785typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1786 struct net_buf *buf,
1787 const char *func_alloc,
1788 int line_alloc,
1789 const char *func_free,
1790 int line_free,
1791 bool in_use,
1792 void *user_data);
1793
1794void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1795
1796const char *net_pkt_slab2str(struct k_mem_slab *slab);
1797const char *net_pkt_pool2str(struct net_buf_pool *pool);
1798
1799#else
1800#define net_pkt_print(...)
1801#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1802
1803/* New allocator, and API are defined below.
1804 * This will be simpler when time will come to get rid of former API above.
1805 */
1806#if defined(NET_PKT_DEBUG_ENABLED)
1807
1808struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1809 const char *caller, int line);
1810#define net_pkt_alloc(_timeout) \
1811 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1812
1813struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1814 k_timeout_t timeout,
1815 const char *caller, int line);
1816#define net_pkt_alloc_from_slab(_slab, _timeout) \
1817 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1818
1819struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1820 const char *caller, int line);
1821#define net_pkt_rx_alloc(_timeout) \
1822 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1823
1824struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1825 k_timeout_t timeout,
1826 const char *caller,
1827 int line);
1828#define net_pkt_alloc_on_iface(_iface, _timeout) \
1829 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1830
1831struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1832 k_timeout_t timeout,
1833 const char *caller,
1834 int line);
1835#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1836 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1837 __func__, __LINE__)
1838
1839int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1840 size_t size,
1841 enum net_ip_protocol proto,
1842 k_timeout_t timeout,
1843 const char *caller, int line);
1844#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1845 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1846 __func__, __LINE__)
1847
1848int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1849 k_timeout_t timeout,
1850 const char *caller, int line);
1851#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1852 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1853 __func__, __LINE__)
1854
1855struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1856 size_t size,
1857 sa_family_t family,
1858 enum net_ip_protocol proto,
1859 k_timeout_t timeout,
1860 const char *caller,
1861 int line);
1862#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1863 _proto, _timeout) \
1864 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1865 _proto, _timeout, \
1866 __func__, __LINE__)
1867
1868struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1869 size_t size,
1870 sa_family_t family,
1871 enum net_ip_protocol proto,
1872 k_timeout_t timeout,
1873 const char *caller,
1874 int line);
1875#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1876 _proto, _timeout) \
1877 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1878 _proto, _timeout, \
1879 __func__, __LINE__)
1880#endif /* NET_PKT_DEBUG_ENABLED */
1883#if !defined(NET_PKT_DEBUG_ENABLED)
1895#endif
1896
1897#if !defined(NET_PKT_DEBUG_ENABLED)
1912struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
1913 k_timeout_t timeout);
1914#endif
1915
1916#if !defined(NET_PKT_DEBUG_ENABLED)
1928#endif
1929
1930#if !defined(NET_PKT_DEBUG_ENABLED)
1940 k_timeout_t timeout);
1941
1944/* Same as above but specifically for RX packet */
1945struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
1946 k_timeout_t timeout);
1949#endif
1950
1951#if !defined(NET_PKT_DEBUG_ENABLED)
1968 size_t size,
1969 enum net_ip_protocol proto,
1970 k_timeout_t timeout);
1971#endif
1972
1973#if !defined(NET_PKT_DEBUG_ENABLED)
1987int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
1988 k_timeout_t timeout);
1989#endif
1990
1991#if !defined(NET_PKT_DEBUG_ENABLED)
2004 size_t size,
2005 sa_family_t family,
2006 enum net_ip_protocol proto,
2007 k_timeout_t timeout);
2008
2011/* Same as above but specifically for RX packet */
2012struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2013 size_t size,
2014 sa_family_t family,
2015 enum net_ip_protocol proto,
2016 k_timeout_t timeout);
2017
2020#endif
2021
2028void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2029
2041
2058 enum net_ip_protocol proto);
2059
2069
2084int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2085
2094
2101static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2102 struct net_pkt_cursor *backup)
2103{
2104 backup->buf = pkt->cursor.buf;
2105 backup->pos = pkt->cursor.pos;
2106}
2107
2114static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2115 struct net_pkt_cursor *backup)
2116{
2117 pkt->cursor.buf = backup->buf;
2118 pkt->cursor.pos = backup->pos;
2119}
2120
2128static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2129{
2130 return pkt->cursor.pos;
2131}
2132
2153int net_pkt_skip(struct net_pkt *pkt, size_t length);
2154
2169int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2170
2184int net_pkt_copy(struct net_pkt *pkt_dst,
2185 struct net_pkt *pkt_src,
2186 size_t length);
2187
2197struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2198
2208struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2209
2219 k_timeout_t timeout);
2220
2234int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2235
2248static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2249{
2250 return net_pkt_read(pkt, data, 1);
2251}
2252
2265int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2266
2279int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2280
2293int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2294
2308int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2309
2322static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2323{
2324 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2325}
2326
2339static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2340{
2341 uint16_t data_be16 = htons(data);
2342
2343 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2344}
2345
2358static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2359{
2360 uint32_t data_be32 = htonl(data);
2361
2362 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2363}
2364
2377static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2378{
2379 uint32_t data_le32 = sys_cpu_to_le32(data);
2380
2381 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2382}
2383
2396static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2397{
2398 uint16_t data_le16 = sys_cpu_to_le16(data);
2399
2400 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2401}
2402
2411
2424int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2425
2438int net_pkt_pull(struct net_pkt *pkt, size_t length);
2439
2449
2461bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2462
2472
2475struct net_pkt_data_access {
2476#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2477 void *data;
2478#endif
2479 const size_t size;
2480};
2481
2482#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2483#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2484 struct net_pkt_data_access _name = { \
2485 .size = sizeof(_type), \
2486 }
2487
2488#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2489 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2490
2491#else
2492#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2493 _type _hdr_##_name; \
2494 struct net_pkt_data_access _name = { \
2495 .data = &_hdr_##_name, \
2496 .size = sizeof(_type), \
2497 }
2498
2499#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2500 struct net_pkt_data_access _name = { \
2501 .data = NULL, \
2502 .size = sizeof(_type), \
2503 }
2504
2505#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2506
2522void *net_pkt_get_data(struct net_pkt *pkt,
2523 struct net_pkt_data_access *access);
2524
2539 struct net_pkt_data_access *access);
2540
2545static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2546 struct net_pkt_data_access *access)
2547{
2548 return net_pkt_skip(pkt, access->size);
2549}
2550
2555#ifdef __cplusplus
2556}
2557#endif
2558
2559#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
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: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:2358
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:1597
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:2339
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:2322
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:2128
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:2101
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:2545
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:2396
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:2114
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:2377
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:2248
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:140
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.
#define ALWAYS_INLINE
Definition common.h:129
Buffer management.
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: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:388
Definition stat.h:57
#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