Zephyr API Documentation 4.0.99
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#if defined(CONFIG_NET_IPV4_PMTU)
346 /* Path MTU needed for this destination address */
347 uint8_t ipv4_pmtu : 1;
348#endif /* CONFIG_NET_IPV4_PMTU */
349
350 /* @endcond */
351};
352
355/* The interface real ll address */
356static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
357{
358 return net_if_get_link_addr(pkt->iface);
359}
360
361static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
362{
363 return pkt->context;
364}
365
366static inline void net_pkt_set_context(struct net_pkt *pkt,
367 struct net_context *ctx)
368{
369 pkt->context = ctx;
370}
371
372static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
373{
374 return pkt->iface;
375}
376
377static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
378{
379 pkt->iface = iface;
380
381 /* If the network interface is set in pkt, then also set the type of
382 * the network address that is stored in pkt. This is done here so
383 * that the address type is properly set and is not forgotten.
384 */
385 if (iface) {
386 uint8_t type = net_if_get_link_addr(iface)->type;
387
388 pkt->lladdr_src.type = type;
389 pkt->lladdr_dst.type = type;
390 }
391}
392
393static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
394{
395#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
396 return pkt->orig_iface;
397#else
398 return pkt->iface;
399#endif
400}
401
402static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
403 struct net_if *iface)
404{
405#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
406 pkt->orig_iface = iface;
407#else
408 ARG_UNUSED(pkt);
409 ARG_UNUSED(iface);
410#endif
411}
412
413static inline uint8_t net_pkt_family(struct net_pkt *pkt)
414{
415 return pkt->family;
416}
417
418static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
419{
420 pkt->family = family;
421}
422
423static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
424{
425 return !!(pkt->ptp_pkt);
426}
427
428static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
429{
430 pkt->ptp_pkt = is_ptp;
431}
432
433static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
434{
435#if defined(CONFIG_NET_PKT_TIMESTAMP)
436 return !!(pkt->tx_timestamping);
437#else
438 ARG_UNUSED(pkt);
439
440 return false;
441#endif
442}
443
444static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
445{
446#if defined(CONFIG_NET_PKT_TIMESTAMP)
447 pkt->tx_timestamping = is_timestamping;
448#else
449 ARG_UNUSED(pkt);
450 ARG_UNUSED(is_timestamping);
451#endif
452}
453
454static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
455{
456#if defined(CONFIG_NET_PKT_TIMESTAMP)
457 return !!(pkt->rx_timestamping);
458#else
459 ARG_UNUSED(pkt);
460
461 return false;
462#endif
463}
464
465static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
466{
467#if defined(CONFIG_NET_PKT_TIMESTAMP)
468 pkt->rx_timestamping = is_timestamping;
469#else
470 ARG_UNUSED(pkt);
471 ARG_UNUSED(is_timestamping);
472#endif
473}
474
475static inline bool net_pkt_is_captured(struct net_pkt *pkt)
476{
477 return !!(pkt->captured);
478}
479
480static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
481{
482 pkt->captured = is_captured;
483}
484
485static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
486{
487 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
488}
489
490static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
491{
492 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
493 pkt->l2_bridged = is_l2_bridged;
494 }
495}
496
497static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
498{
499 return !!(pkt->l2_processed);
500}
501
502static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
503 bool is_l2_processed)
504{
505 pkt->l2_processed = is_l2_processed;
506}
507
508static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
509{
510 return !!(pkt->chksum_done);
511}
512
513static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
514 bool is_chksum_done)
515{
516 pkt->chksum_done = is_chksum_done;
517}
518
519static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
520{
521#if defined(CONFIG_NET_IP)
522 return pkt->ip_hdr_len;
523#else
524 ARG_UNUSED(pkt);
525
526 return 0;
527#endif
528}
529
530static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
531{
532#if defined(CONFIG_NET_IP)
533 pkt->ip_hdr_len = len;
534#else
535 ARG_UNUSED(pkt);
536 ARG_UNUSED(len);
537#endif
538}
539
540static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
541{
542#if defined(CONFIG_NET_IP_DSCP_ECN)
543 return pkt->ip_dscp;
544#else
545 ARG_UNUSED(pkt);
546
547 return 0;
548#endif
549}
550
551static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
552{
553#if defined(CONFIG_NET_IP_DSCP_ECN)
554 pkt->ip_dscp = dscp;
555#else
556 ARG_UNUSED(pkt);
557 ARG_UNUSED(dscp);
558#endif
559}
560
561static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
562{
563#if defined(CONFIG_NET_IP_DSCP_ECN)
564 return pkt->ip_ecn;
565#else
566 ARG_UNUSED(pkt);
567
568 return 0;
569#endif
570}
571
572static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
573{
574#if defined(CONFIG_NET_IP_DSCP_ECN)
575 pkt->ip_ecn = ecn;
576#else
577 ARG_UNUSED(pkt);
578 ARG_UNUSED(ecn);
579#endif
580}
581
582static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
583{
584 return pkt->eof;
585}
586
587static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
588{
589 pkt->eof = eof;
590}
591
592static inline bool net_pkt_forwarding(struct net_pkt *pkt)
593{
594 return !!(pkt->forwarding);
595}
596
597static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
598{
599 pkt->forwarding = forward;
600}
601
602#if defined(CONFIG_NET_IPV4)
603static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
604{
605 return pkt->ipv4_ttl;
606}
607
608static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
609 uint8_t ttl)
610{
611 pkt->ipv4_ttl = ttl;
612}
613
614static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
615{
616 return pkt->ipv4_opts_len;
617}
618
619static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
620 uint8_t opts_len)
621{
622 pkt->ipv4_opts_len = opts_len;
623}
624#else
625static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
626{
627 ARG_UNUSED(pkt);
628
629 return 0;
630}
631
632static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
633 uint8_t ttl)
634{
635 ARG_UNUSED(pkt);
636 ARG_UNUSED(ttl);
637}
638
639static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
640{
641 ARG_UNUSED(pkt);
642 return 0;
643}
644
645static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
646 uint8_t opts_len)
647{
648 ARG_UNUSED(pkt);
649 ARG_UNUSED(opts_len);
650}
651#endif
652
653#if defined(CONFIG_NET_IPV6)
654static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
655{
656 return pkt->ipv6_ext_opt_len;
657}
658
659static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
660 uint8_t len)
661{
662 pkt->ipv6_ext_opt_len = len;
663}
664
665static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
666{
667 return pkt->ipv6_next_hdr;
668}
669
670static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
671 uint8_t next_hdr)
672{
673 pkt->ipv6_next_hdr = next_hdr;
674}
675
676static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
677{
678 return pkt->ipv6_ext_len;
679}
680
681static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
682{
683 pkt->ipv6_ext_len = len;
684}
685
686static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
687{
688 return pkt->ipv6_prev_hdr_start;
689}
690
691static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
692 uint16_t offset)
693{
694 pkt->ipv6_prev_hdr_start = offset;
695}
696
697static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
698{
699 return pkt->ipv6_hop_limit;
700}
701
702static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
703 uint8_t hop_limit)
704{
705 pkt->ipv6_hop_limit = hop_limit;
706}
707#else /* CONFIG_NET_IPV6 */
708static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
709{
710 ARG_UNUSED(pkt);
711
712 return 0;
713}
714
715static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
716 uint8_t len)
717{
718 ARG_UNUSED(pkt);
719 ARG_UNUSED(len);
720}
721
722static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
723{
724 ARG_UNUSED(pkt);
725
726 return 0;
727}
728
729static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
730 uint8_t next_hdr)
731{
732 ARG_UNUSED(pkt);
733 ARG_UNUSED(next_hdr);
734}
735
736static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
737{
738 ARG_UNUSED(pkt);
739
740 return 0;
741}
742
743static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
744{
745 ARG_UNUSED(pkt);
746 ARG_UNUSED(len);
747}
748
749static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
750{
751 ARG_UNUSED(pkt);
752
753 return 0;
754}
755
756static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
757 uint16_t offset)
758{
759 ARG_UNUSED(pkt);
760 ARG_UNUSED(offset);
761}
762
763static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
764{
765 ARG_UNUSED(pkt);
766
767 return 0;
768}
769
770static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
771 uint8_t hop_limit)
772{
773 ARG_UNUSED(pkt);
774 ARG_UNUSED(hop_limit);
775}
776#endif /* CONFIG_NET_IPV6 */
777
778static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
779{
780#if defined(CONFIG_NET_IPV6)
781 return pkt->ipv6_ext_len;
782#elif defined(CONFIG_NET_IPV4)
783 return pkt->ipv4_opts_len;
784#else
785 ARG_UNUSED(pkt);
786
787 return 0;
788#endif
789}
790
791#if defined(CONFIG_NET_IPV4_PMTU)
792static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
793{
794 return !!pkt->ipv4_pmtu;
795}
796
797static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
798{
799 pkt->ipv4_pmtu = value;
800}
801#else
802static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
803{
804 ARG_UNUSED(pkt);
805
806 return false;
807}
808
809static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
810{
811 ARG_UNUSED(pkt);
812 ARG_UNUSED(value);
813}
814#endif /* CONFIG_NET_IPV4_PMTU */
815
816#if defined(CONFIG_NET_IPV4_FRAGMENT)
817static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
818{
819 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
820}
821
822static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
823{
824 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
825}
826
827static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
828{
829 pkt->ipv4_fragment.flags = flags;
830}
831
832static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
833{
834 return pkt->ipv4_fragment.id;
835}
836
837static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
838{
839 pkt->ipv4_fragment.id = id;
840}
841#else /* CONFIG_NET_IPV4_FRAGMENT */
842static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
843{
844 ARG_UNUSED(pkt);
845
846 return 0;
847}
848
849static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
850{
851 ARG_UNUSED(pkt);
852
853 return 0;
854}
855
856static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
857{
858 ARG_UNUSED(pkt);
859 ARG_UNUSED(flags);
860}
861
862static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
863{
864 ARG_UNUSED(pkt);
865
866 return 0;
867}
868
869static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
870{
871 ARG_UNUSED(pkt);
872 ARG_UNUSED(id);
873}
874#endif /* CONFIG_NET_IPV4_FRAGMENT */
875
876#if defined(CONFIG_NET_IPV6_FRAGMENT)
877static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
878{
879 return pkt->ipv6_fragment.hdr_start;
880}
881
882static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
883 uint16_t start)
884{
885 pkt->ipv6_fragment.hdr_start = start;
886}
887
888static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
889{
890 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
891}
892static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
893{
894 return (pkt->ipv6_fragment.flags & 0x01) != 0;
895}
896
897static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
899{
900 pkt->ipv6_fragment.flags = flags;
901}
902
903static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
904{
905 return pkt->ipv6_fragment.id;
906}
907
908static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
909 uint32_t id)
910{
911 pkt->ipv6_fragment.id = id;
912}
913#else /* CONFIG_NET_IPV6_FRAGMENT */
914static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
915{
916 ARG_UNUSED(pkt);
917
918 return 0;
919}
920
921static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
922 uint16_t start)
923{
924 ARG_UNUSED(pkt);
925 ARG_UNUSED(start);
926}
927
928static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
929{
930 ARG_UNUSED(pkt);
931
932 return 0;
933}
934
935static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
936{
937 ARG_UNUSED(pkt);
938
939 return 0;
940}
941
942static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
944{
945 ARG_UNUSED(pkt);
946 ARG_UNUSED(flags);
947}
948
949static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
950{
951 ARG_UNUSED(pkt);
952
953 return 0;
954}
955
956static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
957 uint32_t id)
958{
959 ARG_UNUSED(pkt);
960 ARG_UNUSED(id);
961}
962#endif /* CONFIG_NET_IPV6_FRAGMENT */
963
964#if defined(CONFIG_NET_IP_FRAGMENT)
965static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
966{
967 return !!(pkt->ip_reassembled);
968}
969
970static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
971 bool reassembled)
972{
973 pkt->ip_reassembled = reassembled;
974}
975#else /* CONFIG_NET_IP_FRAGMENT */
976static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
977{
978 ARG_UNUSED(pkt);
979
980 return false;
981}
982
983static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
984 bool reassembled)
985{
986 ARG_UNUSED(pkt);
987 ARG_UNUSED(reassembled);
988}
989#endif /* CONFIG_NET_IP_FRAGMENT */
990
991static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
992{
993 return pkt->priority;
994}
995
996static inline void net_pkt_set_priority(struct net_pkt *pkt,
997 uint8_t priority)
998{
999 pkt->priority = priority;
1000}
1001
1002#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1003static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1004{
1005 return pkt->cooked_mode_pkt;
1006}
1007
1008static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1009{
1010 pkt->cooked_mode_pkt = value;
1011}
1012#else
1013static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1014{
1015 ARG_UNUSED(pkt);
1016
1017 return false;
1018}
1019
1020static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1021{
1022 ARG_UNUSED(pkt);
1023 ARG_UNUSED(value);
1024}
1025#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1026
1027#if defined(CONFIG_NET_VLAN)
1028static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1029{
1030 return net_eth_vlan_get_vid(pkt->vlan_tci);
1031}
1032
1033static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1034{
1035 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1036}
1037
1038static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1039{
1040 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1041}
1042
1043static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1044 uint8_t priority)
1045{
1046 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1047}
1048
1049static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1050{
1051 return net_eth_vlan_get_dei(pkt->vlan_tci);
1052}
1053
1054static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1055{
1056 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1057}
1058
1059static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1060{
1061 pkt->vlan_tci = tci;
1062}
1063
1064static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1065{
1066 return pkt->vlan_tci;
1067}
1068#else
1069static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1070{
1071 ARG_UNUSED(pkt);
1072
1073 return NET_VLAN_TAG_UNSPEC;
1074}
1075
1076static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1077{
1078 ARG_UNUSED(pkt);
1079 ARG_UNUSED(tag);
1080}
1081
1082static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1083{
1084 ARG_UNUSED(pkt);
1085
1086 return 0;
1087}
1088
1089static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1090{
1091 ARG_UNUSED(pkt);
1092
1093 return false;
1094}
1095
1096static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1097{
1098 ARG_UNUSED(pkt);
1099 ARG_UNUSED(dei);
1100}
1101
1102static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1103{
1104 ARG_UNUSED(pkt);
1105
1106 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1107}
1108
1109static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1110{
1111 ARG_UNUSED(pkt);
1112 ARG_UNUSED(tci);
1113}
1114#endif
1115
1116#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1117static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1118{
1119 return &pkt->timestamp;
1120}
1121
1122static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1123 struct net_ptp_time *timestamp)
1124{
1125 pkt->timestamp.second = timestamp->second;
1126 pkt->timestamp.nanosecond = timestamp->nanosecond;
1127}
1128
1129static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1130{
1131 return net_ptp_time_to_ns(&pkt->timestamp);
1132}
1133
1134static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1135{
1136 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1137}
1138#else
1139static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1140{
1141 ARG_UNUSED(pkt);
1142
1143 return NULL;
1144}
1145
1146static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1147 struct net_ptp_time *timestamp)
1148{
1149 ARG_UNUSED(pkt);
1150 ARG_UNUSED(timestamp);
1151}
1152
1153static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1154{
1155 ARG_UNUSED(pkt);
1156
1157 return 0;
1158}
1159
1160static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1161{
1162 ARG_UNUSED(pkt);
1163 ARG_UNUSED(timestamp);
1164}
1165#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1166
1167#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1168 defined(CONFIG_TRACING_NET_CORE)
1169
1170static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1171{
1172 return pkt->create_time;
1173}
1174
1175static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1176 uint32_t create_time)
1177{
1178 pkt->create_time = create_time;
1179}
1180#else
1181static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1182{
1183 ARG_UNUSED(pkt);
1184
1185 return 0U;
1186}
1187
1188static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1189 uint32_t create_time)
1190{
1191 ARG_UNUSED(pkt);
1192 ARG_UNUSED(create_time);
1193}
1194#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1195 * CONFIG_TRACING_NET_CORE
1196 */
1197
1198#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1199 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1200static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1201{
1202 return pkt->detail.stat;
1203}
1204
1205static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1206{
1207 return pkt->detail.count;
1208}
1209
1210static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1211{
1212 memset(&pkt->detail, 0, sizeof(pkt->detail));
1213}
1214
1215static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1216 uint32_t tick)
1217{
1218 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1219 NET_ERR("Detail stats count overflow (%d >= %d)",
1220 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1221 return;
1222 }
1223
1224 pkt->detail.stat[pkt->detail.count++] = tick;
1225}
1226
1227#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1228#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1229#else
1230static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1231{
1232 ARG_UNUSED(pkt);
1233
1234 return NULL;
1235}
1236
1237static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1238{
1239 ARG_UNUSED(pkt);
1240
1241 return 0;
1242}
1243
1244static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1245{
1246 ARG_UNUSED(pkt);
1247}
1248
1249static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1250{
1251 ARG_UNUSED(pkt);
1252 ARG_UNUSED(tick);
1253}
1254
1255#define net_pkt_set_tx_stats_tick(pkt, tick)
1256#define net_pkt_set_rx_stats_tick(pkt, tick)
1257#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1258 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1259
1260static inline size_t net_pkt_get_len(struct net_pkt *pkt)
1261{
1262 return net_buf_frags_len(pkt->frags);
1263}
1264
1265static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1266{
1267 return pkt->frags->data;
1268}
1269
1270static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1271{
1272 return pkt->frags->data;
1273}
1274
1275static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1276{
1277 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1278}
1279
1280static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1281{
1282 return &pkt->lladdr_src;
1283}
1284
1285static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1286{
1287 return &pkt->lladdr_dst;
1288}
1289
1290static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1291{
1292 uint8_t *addr = net_pkt_lladdr_src(pkt)->addr;
1293
1294 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1295 net_pkt_lladdr_dst(pkt)->addr = addr;
1296}
1297
1298static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1299{
1300 net_pkt_lladdr_src(pkt)->addr = NULL;
1301 net_pkt_lladdr_src(pkt)->len = 0U;
1302}
1303
1304static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1305{
1306 return pkt->ll_proto_type;
1307}
1308
1309static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1310{
1311 pkt->ll_proto_type = type;
1312}
1313
1314#if defined(CONFIG_NET_IPV4_ACD)
1315static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1316{
1317 return !!(pkt->ipv4_acd_arp_msg);
1318}
1319
1320static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1321 bool is_acd_arp_msg)
1322{
1323 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1324}
1325#else /* CONFIG_NET_IPV4_ACD */
1326static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1327{
1328 ARG_UNUSED(pkt);
1329
1330 return false;
1331}
1332
1333static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1334 bool is_acd_arp_msg)
1335{
1336 ARG_UNUSED(pkt);
1337 ARG_UNUSED(is_acd_arp_msg);
1338}
1339#endif /* CONFIG_NET_IPV4_ACD */
1340
1341#if defined(CONFIG_NET_LLDP)
1342static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1343{
1344 return !!(pkt->lldp_pkt);
1345}
1346
1347static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1348{
1349 pkt->lldp_pkt = is_lldp;
1350}
1351#else
1352static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1353{
1354 ARG_UNUSED(pkt);
1355
1356 return false;
1357}
1358
1359static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1360{
1361 ARG_UNUSED(pkt);
1362 ARG_UNUSED(is_lldp);
1363}
1364#endif /* CONFIG_NET_LLDP */
1365
1366#if defined(CONFIG_NET_L2_PPP)
1367static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1368{
1369 return !!(pkt->ppp_msg);
1370}
1371
1372static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1373 bool is_ppp_msg)
1374{
1375 pkt->ppp_msg = is_ppp_msg;
1376}
1377#else /* CONFIG_NET_L2_PPP */
1378static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1379{
1380 ARG_UNUSED(pkt);
1381
1382 return false;
1383}
1384
1385static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1386 bool is_ppp_msg)
1387{
1388 ARG_UNUSED(pkt);
1389 ARG_UNUSED(is_ppp_msg);
1390}
1391#endif /* CONFIG_NET_L2_PPP */
1392
1393#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1394static inline void *net_pkt_cb(struct net_pkt *pkt)
1395{
1396 return &pkt->cb;
1397}
1398#else
1399static inline void *net_pkt_cb(struct net_pkt *pkt)
1400{
1401 ARG_UNUSED(pkt);
1402
1403 return NULL;
1404}
1405#endif
1406
1407#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1408#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1409
1410static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1411{
1413 net_pkt_context(pkt)),
1414 (struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1415}
1416
1417static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1418{
1419 pkt->overwrite = overwrite;
1420}
1421
1422static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1423{
1424 return !!(pkt->overwrite);
1425}
1426
1427#ifdef CONFIG_NET_PKT_FILTER
1428
1429bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1430bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1431
1432#else
1433
1434static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1435{
1436 ARG_UNUSED(pkt);
1437
1438 return true;
1439}
1440
1441static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1442{
1443 ARG_UNUSED(pkt);
1444
1445 return true;
1446}
1447
1448#endif /* CONFIG_NET_PKT_FILTER */
1449
1450#if defined(CONFIG_NET_PKT_FILTER) && \
1451 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1452
1453bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1454
1455#else
1456
1457static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1458{
1459 ARG_UNUSED(pkt);
1460
1461 return true;
1462}
1463
1464#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1465
1466#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1467
1468bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1469
1470#else
1471
1472static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1473{
1474 ARG_UNUSED(pkt);
1475
1476 return true;
1477}
1478
1479#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1480
1481#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1482static inline struct sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1483{
1484 return &pkt->remote;
1485}
1486
1487static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1488 struct sockaddr *address,
1489 socklen_t len)
1490{
1491 memcpy(&pkt->remote, address, len);
1492}
1493#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1494
1495/* @endcond */
1496
1510#define NET_PKT_SLAB_DEFINE(name, count) \
1511 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4); \
1512 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1513
1516/* Backward compatibility macro */
1517#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1518
1534#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1535 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1536 0, NULL)
1537
1540#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1541 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1542#define NET_PKT_DEBUG_ENABLED
1543#endif
1544
1545#if defined(NET_PKT_DEBUG_ENABLED)
1546
1547/* Debug versions of the net_pkt functions that are used when tracking
1548 * buffer usage.
1549 */
1550
1551struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1552 size_t min_len,
1553 k_timeout_t timeout,
1554 const char *caller,
1555 int line);
1556
1557#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1558 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1559
1560struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1561 k_timeout_t timeout,
1562 const char *caller,
1563 int line);
1564#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1565 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1566
1567struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1568 k_timeout_t timeout,
1569 const char *caller,
1570 int line);
1571#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1572 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1573
1574struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1575 k_timeout_t timeout,
1576 const char *caller, int line);
1577#define net_pkt_get_frag(pkt, min_len, timeout) \
1578 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1579
1580void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1581#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1582
1583struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1584 int line);
1585#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1586
1587struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1588 const char *caller, int line);
1589#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1590
1591void net_pkt_frag_unref_debug(struct net_buf *frag,
1592 const char *caller, int line);
1593#define net_pkt_frag_unref(frag) \
1594 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1595
1596struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1597 struct net_buf *parent,
1598 struct net_buf *frag,
1599 const char *caller, int line);
1600#define net_pkt_frag_del(pkt, parent, frag) \
1601 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1602
1603void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1604 const char *caller, int line);
1605#define net_pkt_frag_add(pkt, frag) \
1606 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1607
1608void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1609 const char *caller, int line);
1610#define net_pkt_frag_insert(pkt, frag) \
1611 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1612#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1613 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1614 */
1617#if defined(NET_PKT_DEBUG_ENABLED)
1625void net_pkt_print_frags(struct net_pkt *pkt);
1626#else
1627#define net_pkt_print_frags(pkt)
1628#endif
1629
1630#if !defined(NET_PKT_DEBUG_ENABLED)
1646 size_t min_len, k_timeout_t timeout);
1647#endif
1648
1649#if !defined(NET_PKT_DEBUG_ENABLED)
1664struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1665#endif
1666
1667#if !defined(NET_PKT_DEBUG_ENABLED)
1682struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1683#endif
1684
1685#if !defined(NET_PKT_DEBUG_ENABLED)
1698struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1699 k_timeout_t timeout);
1700#endif
1701
1702#if !defined(NET_PKT_DEBUG_ENABLED)
1712void net_pkt_unref(struct net_pkt *pkt);
1713#endif
1714
1715#if !defined(NET_PKT_DEBUG_ENABLED)
1725struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1726#endif
1727
1728#if !defined(NET_PKT_DEBUG_ENABLED)
1738struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1739#endif
1740
1741#if !defined(NET_PKT_DEBUG_ENABLED)
1747void net_pkt_frag_unref(struct net_buf *frag);
1748#endif
1749
1750#if !defined(NET_PKT_DEBUG_ENABLED)
1762 struct net_buf *parent,
1763 struct net_buf *frag);
1764#endif
1765
1766#if !defined(NET_PKT_DEBUG_ENABLED)
1773void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1774#endif
1775
1776#if !defined(NET_PKT_DEBUG_ENABLED)
1783void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1784#endif
1785
1792void net_pkt_compact(struct net_pkt *pkt);
1793
1802void net_pkt_get_info(struct k_mem_slab **rx,
1803 struct k_mem_slab **tx,
1804 struct net_buf_pool **rx_data,
1805 struct net_buf_pool **tx_data);
1806
1809#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1813void net_pkt_print(void);
1814
1815typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1816 struct net_buf *buf,
1817 const char *func_alloc,
1818 int line_alloc,
1819 const char *func_free,
1820 int line_free,
1821 bool in_use,
1822 void *user_data);
1823
1824void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1825
1826const char *net_pkt_slab2str(struct k_mem_slab *slab);
1827const char *net_pkt_pool2str(struct net_buf_pool *pool);
1828
1829#else
1830#define net_pkt_print(...)
1831#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1832
1833/* New allocator, and API are defined below.
1834 * This will be simpler when time will come to get rid of former API above.
1835 */
1836#if defined(NET_PKT_DEBUG_ENABLED)
1837
1838struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1839 const char *caller, int line);
1840#define net_pkt_alloc(_timeout) \
1841 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1842
1843struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1844 k_timeout_t timeout,
1845 const char *caller, int line);
1846#define net_pkt_alloc_from_slab(_slab, _timeout) \
1847 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1848
1849struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1850 const char *caller, int line);
1851#define net_pkt_rx_alloc(_timeout) \
1852 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1853
1854struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1855 k_timeout_t timeout,
1856 const char *caller,
1857 int line);
1858#define net_pkt_alloc_on_iface(_iface, _timeout) \
1859 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1860
1861struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1862 k_timeout_t timeout,
1863 const char *caller,
1864 int line);
1865#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1866 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1867 __func__, __LINE__)
1868
1869int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1870 size_t size,
1871 enum net_ip_protocol proto,
1872 k_timeout_t timeout,
1873 const char *caller, int line);
1874#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1875 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1876 __func__, __LINE__)
1877
1878int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1879 k_timeout_t timeout,
1880 const char *caller, int line);
1881#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1882 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1883 __func__, __LINE__)
1884
1885struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1886 size_t size,
1887 sa_family_t family,
1888 enum net_ip_protocol proto,
1889 k_timeout_t timeout,
1890 const char *caller,
1891 int line);
1892#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1893 _proto, _timeout) \
1894 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1895 _proto, _timeout, \
1896 __func__, __LINE__)
1897
1898struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1899 size_t size,
1900 sa_family_t family,
1901 enum net_ip_protocol proto,
1902 k_timeout_t timeout,
1903 const char *caller,
1904 int line);
1905#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1906 _proto, _timeout) \
1907 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1908 _proto, _timeout, \
1909 __func__, __LINE__)
1910#endif /* NET_PKT_DEBUG_ENABLED */
1913#if !defined(NET_PKT_DEBUG_ENABLED)
1925#endif
1926
1927#if !defined(NET_PKT_DEBUG_ENABLED)
1942struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
1943 k_timeout_t timeout);
1944#endif
1945
1946#if !defined(NET_PKT_DEBUG_ENABLED)
1958#endif
1959
1960#if !defined(NET_PKT_DEBUG_ENABLED)
1970 k_timeout_t timeout);
1971
1974/* Same as above but specifically for RX packet */
1975struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
1976 k_timeout_t timeout);
1979#endif
1980
1981#if !defined(NET_PKT_DEBUG_ENABLED)
1998 size_t size,
1999 enum net_ip_protocol proto,
2000 k_timeout_t timeout);
2001#endif
2002
2003#if !defined(NET_PKT_DEBUG_ENABLED)
2017int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2018 k_timeout_t timeout);
2019#endif
2020
2021#if !defined(NET_PKT_DEBUG_ENABLED)
2034 size_t size,
2035 sa_family_t family,
2036 enum net_ip_protocol proto,
2037 k_timeout_t timeout);
2038
2041/* Same as above but specifically for RX packet */
2042struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2043 size_t size,
2044 sa_family_t family,
2045 enum net_ip_protocol proto,
2046 k_timeout_t timeout);
2047
2050#endif
2051
2058void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2059
2071
2088 enum net_ip_protocol proto);
2089
2099
2114int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2115
2124
2131static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2132 struct net_pkt_cursor *backup)
2133{
2134 backup->buf = pkt->cursor.buf;
2135 backup->pos = pkt->cursor.pos;
2136}
2137
2144static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2145 struct net_pkt_cursor *backup)
2146{
2147 pkt->cursor.buf = backup->buf;
2148 pkt->cursor.pos = backup->pos;
2149}
2150
2158static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2159{
2160 return pkt->cursor.pos;
2161}
2162
2183int net_pkt_skip(struct net_pkt *pkt, size_t length);
2184
2199int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2200
2214int net_pkt_copy(struct net_pkt *pkt_dst,
2215 struct net_pkt *pkt_src,
2216 size_t length);
2217
2227struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2228
2238struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2239
2249 k_timeout_t timeout);
2250
2264int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2265
2278static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2279{
2280 return net_pkt_read(pkt, data, 1);
2281}
2282
2295int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2296
2309int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2310
2323int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2324
2338int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2339
2352static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2353{
2354 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2355}
2356
2369static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2370{
2371 uint16_t data_be16 = htons(data);
2372
2373 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2374}
2375
2388static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2389{
2390 uint32_t data_be32 = htonl(data);
2391
2392 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2393}
2394
2407static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2408{
2409 uint32_t data_le32 = sys_cpu_to_le32(data);
2410
2411 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2412}
2413
2426static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2427{
2428 uint16_t data_le16 = sys_cpu_to_le16(data);
2429
2430 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2431}
2432
2441
2454int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2455
2468int net_pkt_pull(struct net_pkt *pkt, size_t length);
2469
2479
2491bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2492
2502
2505struct net_pkt_data_access {
2506#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2507 void *data;
2508#endif
2509 const size_t size;
2510};
2511
2512#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2513#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2514 struct net_pkt_data_access _name = { \
2515 .size = sizeof(_type), \
2516 }
2517
2518#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2519 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2520
2521#else
2522#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2523 _type _hdr_##_name; \
2524 struct net_pkt_data_access _name = { \
2525 .data = &_hdr_##_name, \
2526 .size = sizeof(_type), \
2527 }
2528
2529#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2530 struct net_pkt_data_access _name = { \
2531 .data = NULL, \
2532 .size = sizeof(_type), \
2533 }
2534
2535#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2536
2552void *net_pkt_get_data(struct net_pkt *pkt,
2553 struct net_pkt_data_access *access);
2554
2569 struct net_pkt_data_access *access);
2570
2575static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2576 struct net_pkt_data_access *access)
2577{
2578 return net_pkt_skip(pkt, access->size);
2579}
2580
2585#ifdef __cplusplus
2586}
2587#endif
2588
2589#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:168
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:124
size_t socklen_t
Length of a socket address.
Definition net_ip.h:172
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:132
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2711
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:727
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1088
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:2055
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:2388
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:1627
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:2369
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:2352
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:2158
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:2131
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:2575
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:2426
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:2144
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:2407
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:2278
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:143
Kernel timeout type.
Definition sys_clock.h:65
Network buffer pool representation.
Definition net_buf.h:1078
Network buffer representation.
Definition net_buf.h:1006
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1032
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1053
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1035
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:207
Network Interface structure.
Definition net_if.h:690
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:408
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