Zephyr Project API 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 uint8_t *net_pkt_data(struct net_pkt *pkt)
1261{
1262 return pkt->frags->data;
1263}
1264
1265static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1266{
1267 return pkt->frags->data;
1268}
1269
1270static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1271{
1272 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1273}
1274
1275static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1276{
1277 return &pkt->lladdr_src;
1278}
1279
1280static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1281{
1282 return &pkt->lladdr_dst;
1283}
1284
1285static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1286{
1287 uint8_t *addr = net_pkt_lladdr_src(pkt)->addr;
1288
1289 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1290 net_pkt_lladdr_dst(pkt)->addr = addr;
1291}
1292
1293static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1294{
1295 net_pkt_lladdr_src(pkt)->addr = NULL;
1296 net_pkt_lladdr_src(pkt)->len = 0U;
1297}
1298
1299static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1300{
1301 return pkt->ll_proto_type;
1302}
1303
1304static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1305{
1306 pkt->ll_proto_type = type;
1307}
1308
1309#if defined(CONFIG_NET_IPV4_ACD)
1310static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1311{
1312 return !!(pkt->ipv4_acd_arp_msg);
1313}
1314
1315static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1316 bool is_acd_arp_msg)
1317{
1318 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1319}
1320#else /* CONFIG_NET_IPV4_ACD */
1321static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1322{
1323 ARG_UNUSED(pkt);
1324
1325 return false;
1326}
1327
1328static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1329 bool is_acd_arp_msg)
1330{
1331 ARG_UNUSED(pkt);
1332 ARG_UNUSED(is_acd_arp_msg);
1333}
1334#endif /* CONFIG_NET_IPV4_ACD */
1335
1336#if defined(CONFIG_NET_LLDP)
1337static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1338{
1339 return !!(pkt->lldp_pkt);
1340}
1341
1342static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1343{
1344 pkt->lldp_pkt = is_lldp;
1345}
1346#else
1347static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1348{
1349 ARG_UNUSED(pkt);
1350
1351 return false;
1352}
1353
1354static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1355{
1356 ARG_UNUSED(pkt);
1357 ARG_UNUSED(is_lldp);
1358}
1359#endif /* CONFIG_NET_LLDP */
1360
1361#if defined(CONFIG_NET_L2_PPP)
1362static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1363{
1364 return !!(pkt->ppp_msg);
1365}
1366
1367static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1368 bool is_ppp_msg)
1369{
1370 pkt->ppp_msg = is_ppp_msg;
1371}
1372#else /* CONFIG_NET_L2_PPP */
1373static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1374{
1375 ARG_UNUSED(pkt);
1376
1377 return false;
1378}
1379
1380static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1381 bool is_ppp_msg)
1382{
1383 ARG_UNUSED(pkt);
1384 ARG_UNUSED(is_ppp_msg);
1385}
1386#endif /* CONFIG_NET_L2_PPP */
1387
1388#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1389static inline void *net_pkt_cb(struct net_pkt *pkt)
1390{
1391 return &pkt->cb;
1392}
1393#else
1394static inline void *net_pkt_cb(struct net_pkt *pkt)
1395{
1396 ARG_UNUSED(pkt);
1397
1398 return NULL;
1399}
1400#endif
1401
1402#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1403#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1404
1405static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1406{
1408 net_pkt_context(pkt)),
1409 (struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1410}
1411
1412static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1413{
1414 pkt->overwrite = overwrite;
1415}
1416
1417static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1418{
1419 return !!(pkt->overwrite);
1420}
1421
1422#ifdef CONFIG_NET_PKT_FILTER
1423
1424bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1425bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1426
1427#else
1428
1429static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1430{
1431 ARG_UNUSED(pkt);
1432
1433 return true;
1434}
1435
1436static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1437{
1438 ARG_UNUSED(pkt);
1439
1440 return true;
1441}
1442
1443#endif /* CONFIG_NET_PKT_FILTER */
1444
1445#if defined(CONFIG_NET_PKT_FILTER) && \
1446 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1447
1448bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1449
1450#else
1451
1452static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1453{
1454 ARG_UNUSED(pkt);
1455
1456 return true;
1457}
1458
1459#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1460
1461#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1462
1463bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1464
1465#else
1466
1467static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1468{
1469 ARG_UNUSED(pkt);
1470
1471 return true;
1472}
1473
1474#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1475
1476#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1477static inline struct sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1478{
1479 return &pkt->remote;
1480}
1481
1482static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1483 struct sockaddr *address,
1484 socklen_t len)
1485{
1486 memcpy(&pkt->remote, address, len);
1487}
1488#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1489
1490/* @endcond */
1491
1505#define NET_PKT_SLAB_DEFINE(name, count) \
1506 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4); \
1507 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1508
1511/* Backward compatibility macro */
1512#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1513
1529#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1530 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1531 0, NULL)
1532
1535#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1536 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1537#define NET_PKT_DEBUG_ENABLED
1538#endif
1539
1540#if defined(NET_PKT_DEBUG_ENABLED)
1541
1542/* Debug versions of the net_pkt functions that are used when tracking
1543 * buffer usage.
1544 */
1545
1546struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1547 size_t min_len,
1548 k_timeout_t timeout,
1549 const char *caller,
1550 int line);
1551
1552#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1553 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1554
1555struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1556 k_timeout_t timeout,
1557 const char *caller,
1558 int line);
1559#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1560 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1561
1562struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1563 k_timeout_t timeout,
1564 const char *caller,
1565 int line);
1566#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1567 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1568
1569struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1570 k_timeout_t timeout,
1571 const char *caller, int line);
1572#define net_pkt_get_frag(pkt, min_len, timeout) \
1573 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1574
1575void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1576#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1577
1578struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1579 int line);
1580#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1581
1582struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1583 const char *caller, int line);
1584#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1585
1586void net_pkt_frag_unref_debug(struct net_buf *frag,
1587 const char *caller, int line);
1588#define net_pkt_frag_unref(frag) \
1589 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1590
1591struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1592 struct net_buf *parent,
1593 struct net_buf *frag,
1594 const char *caller, int line);
1595#define net_pkt_frag_del(pkt, parent, frag) \
1596 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1597
1598void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1599 const char *caller, int line);
1600#define net_pkt_frag_add(pkt, frag) \
1601 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1602
1603void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1604 const char *caller, int line);
1605#define net_pkt_frag_insert(pkt, frag) \
1606 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1607#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1608 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1609 */
1612#if defined(NET_PKT_DEBUG_ENABLED)
1620void net_pkt_print_frags(struct net_pkt *pkt);
1621#else
1622#define net_pkt_print_frags(pkt)
1623#endif
1624
1625#if !defined(NET_PKT_DEBUG_ENABLED)
1641 size_t min_len, k_timeout_t timeout);
1642#endif
1643
1644#if !defined(NET_PKT_DEBUG_ENABLED)
1659struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1660#endif
1661
1662#if !defined(NET_PKT_DEBUG_ENABLED)
1677struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1678#endif
1679
1680#if !defined(NET_PKT_DEBUG_ENABLED)
1693struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1694 k_timeout_t timeout);
1695#endif
1696
1697#if !defined(NET_PKT_DEBUG_ENABLED)
1707void net_pkt_unref(struct net_pkt *pkt);
1708#endif
1709
1710#if !defined(NET_PKT_DEBUG_ENABLED)
1720struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1721#endif
1722
1723#if !defined(NET_PKT_DEBUG_ENABLED)
1733struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1734#endif
1735
1736#if !defined(NET_PKT_DEBUG_ENABLED)
1742void net_pkt_frag_unref(struct net_buf *frag);
1743#endif
1744
1745#if !defined(NET_PKT_DEBUG_ENABLED)
1757 struct net_buf *parent,
1758 struct net_buf *frag);
1759#endif
1760
1761#if !defined(NET_PKT_DEBUG_ENABLED)
1768void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1769#endif
1770
1771#if !defined(NET_PKT_DEBUG_ENABLED)
1778void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1779#endif
1780
1787void net_pkt_compact(struct net_pkt *pkt);
1788
1797void net_pkt_get_info(struct k_mem_slab **rx,
1798 struct k_mem_slab **tx,
1799 struct net_buf_pool **rx_data,
1800 struct net_buf_pool **tx_data);
1801
1804#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1808void net_pkt_print(void);
1809
1810typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1811 struct net_buf *buf,
1812 const char *func_alloc,
1813 int line_alloc,
1814 const char *func_free,
1815 int line_free,
1816 bool in_use,
1817 void *user_data);
1818
1819void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1820
1821const char *net_pkt_slab2str(struct k_mem_slab *slab);
1822const char *net_pkt_pool2str(struct net_buf_pool *pool);
1823
1824#else
1825#define net_pkt_print(...)
1826#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1827
1828/* New allocator, and API are defined below.
1829 * This will be simpler when time will come to get rid of former API above.
1830 */
1831#if defined(NET_PKT_DEBUG_ENABLED)
1832
1833struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1834 const char *caller, int line);
1835#define net_pkt_alloc(_timeout) \
1836 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1837
1838struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1839 k_timeout_t timeout,
1840 const char *caller, int line);
1841#define net_pkt_alloc_from_slab(_slab, _timeout) \
1842 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1843
1844struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1845 const char *caller, int line);
1846#define net_pkt_rx_alloc(_timeout) \
1847 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1848
1849struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1850 k_timeout_t timeout,
1851 const char *caller,
1852 int line);
1853#define net_pkt_alloc_on_iface(_iface, _timeout) \
1854 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1855
1856struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1857 k_timeout_t timeout,
1858 const char *caller,
1859 int line);
1860#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1861 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1862 __func__, __LINE__)
1863
1864int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1865 size_t size,
1866 enum net_ip_protocol proto,
1867 k_timeout_t timeout,
1868 const char *caller, int line);
1869#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1870 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1871 __func__, __LINE__)
1872
1873int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1874 k_timeout_t timeout,
1875 const char *caller, int line);
1876#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1877 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1878 __func__, __LINE__)
1879
1880struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1881 size_t size,
1882 sa_family_t family,
1883 enum net_ip_protocol proto,
1884 k_timeout_t timeout,
1885 const char *caller,
1886 int line);
1887#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1888 _proto, _timeout) \
1889 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1890 _proto, _timeout, \
1891 __func__, __LINE__)
1892
1893struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1894 size_t size,
1895 sa_family_t family,
1896 enum net_ip_protocol proto,
1897 k_timeout_t timeout,
1898 const char *caller,
1899 int line);
1900#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1901 _proto, _timeout) \
1902 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1903 _proto, _timeout, \
1904 __func__, __LINE__)
1905
1906int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
1907 size_t size,
1908 size_t reserve,
1909 enum net_ip_protocol proto,
1910 k_timeout_t timeout,
1911 const char *caller,
1912 int line);
1913#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
1914 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
1915 _timeout, __func__, __LINE__)
1916
1917#endif /* NET_PKT_DEBUG_ENABLED */
1920#if !defined(NET_PKT_DEBUG_ENABLED)
1932#endif
1933
1934#if !defined(NET_PKT_DEBUG_ENABLED)
1949struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
1950 k_timeout_t timeout);
1951#endif
1952
1953#if !defined(NET_PKT_DEBUG_ENABLED)
1965#endif
1966
1967#if !defined(NET_PKT_DEBUG_ENABLED)
1977 k_timeout_t timeout);
1978
1981/* Same as above but specifically for RX packet */
1982struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
1983 k_timeout_t timeout);
1986#endif
1987
1988#if !defined(NET_PKT_DEBUG_ENABLED)
2005 size_t size,
2006 enum net_ip_protocol proto,
2007 k_timeout_t timeout);
2008#endif
2009
2010#if !defined(NET_PKT_DEBUG_ENABLED)
2028#if !defined(NET_PKT_DEBUG_ENABLED)
2030 size_t size,
2031 size_t reserve,
2032 enum net_ip_protocol proto,
2033 k_timeout_t timeout);
2034#endif
2035
2049int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2050 k_timeout_t timeout);
2051#endif
2052
2053#if !defined(NET_PKT_DEBUG_ENABLED)
2066 size_t size,
2067 sa_family_t family,
2068 enum net_ip_protocol proto,
2069 k_timeout_t timeout);
2070
2073/* Same as above but specifically for RX packet */
2074struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2075 size_t size,
2076 sa_family_t family,
2077 enum net_ip_protocol proto,
2078 k_timeout_t timeout);
2079
2082#endif
2083
2090void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2091
2103
2120 enum net_ip_protocol proto);
2121
2131
2146int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2147
2156
2163static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2164 struct net_pkt_cursor *backup)
2165{
2166 backup->buf = pkt->cursor.buf;
2167 backup->pos = pkt->cursor.pos;
2168}
2169
2176static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2177 struct net_pkt_cursor *backup)
2178{
2179 pkt->cursor.buf = backup->buf;
2180 pkt->cursor.pos = backup->pos;
2181}
2182
2190static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2191{
2192 return pkt->cursor.pos;
2193}
2194
2215int net_pkt_skip(struct net_pkt *pkt, size_t length);
2216
2231int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2232
2246int net_pkt_copy(struct net_pkt *pkt_dst,
2247 struct net_pkt *pkt_src,
2248 size_t length);
2249
2259struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2260
2270struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2271
2281 k_timeout_t timeout);
2282
2296int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2297
2310static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2311{
2312 return net_pkt_read(pkt, data, 1);
2313}
2314
2327int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2328
2341int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2342
2355int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2356
2370int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2371
2384static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2385{
2386 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2387}
2388
2401static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2402{
2403 uint16_t data_be16 = htons(data);
2404
2405 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2406}
2407
2420static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2421{
2422 uint32_t data_be32 = htonl(data);
2423
2424 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2425}
2426
2439static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2440{
2441 uint32_t data_le32 = sys_cpu_to_le32(data);
2442
2443 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2444}
2445
2458static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2459{
2460 uint16_t data_le16 = sys_cpu_to_le16(data);
2461
2462 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2463}
2464
2473
2481static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2482{
2483 return net_buf_frags_len(pkt->frags);
2484}
2485
2498int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2499
2512int net_pkt_pull(struct net_pkt *pkt, size_t length);
2513
2523
2535bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2536
2546
2549struct net_pkt_data_access {
2550#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2551 void *data;
2552#endif
2553 const size_t size;
2554};
2555
2556#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2557#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2558 struct net_pkt_data_access _name = { \
2559 .size = sizeof(_type), \
2560 }
2561
2562#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2563 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2564
2565#else
2566#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2567 _type _hdr_##_name; \
2568 struct net_pkt_data_access _name = { \
2569 .data = &_hdr_##_name, \
2570 .size = sizeof(_type), \
2571 }
2572
2573#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2574 struct net_pkt_data_access _name = { \
2575 .data = NULL, \
2576 .size = sizeof(_type), \
2577 }
2578
2579#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2580
2596void *net_pkt_get_data(struct net_pkt *pkt,
2597 struct net_pkt_data_access *access);
2598
2613 struct net_pkt_data_access *access);
2614
2619static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2620 struct net_pkt_data_access *access)
2621{
2622 return net_pkt_skip(pkt, access->size);
2623}
2624
2629#ifdef __cplusplus
2630}
2631#endif
2632
2633#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:2700
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:741
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1109
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:2091
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:2420
int net_pkt_alloc_buffer_with_reserve(struct net_pkt *pkt, size_t size, size_t reserve, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate buffer for a net_pkt and reserve some space in the first net_buf.
void net_pkt_cursor_init(struct net_pkt *pkt)
Initialize net_pkt cursor.
int net_pkt_skip(struct net_pkt *pkt, size_t length)
Skip some data from a net_pkt.
struct net_pkt * net_pkt_shallow_clone(struct net_pkt *pkt, k_timeout_t timeout)
Clone pkt and increase the refcount of its buffer.
void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer)
Append a buffer in packet.
#define net_pkt_print_frags(pkt)
Definition net_pkt.h:1622
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:2401
struct net_pkt * net_pkt_alloc(k_timeout_t timeout)
Allocate an initialized net_pkt.
int net_pkt_read(struct net_pkt *pkt, void *data, size_t length)
Read some data from a net_pkt.
static size_t net_pkt_get_len(struct net_pkt *pkt)
Get the total amount of bytes stored in a packet.
Definition net_pkt.h:2481
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:2384
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:2190
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:2163
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:2619
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:2458
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:2176
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:2439
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:2310
struct net_buf * net_pkt_get_frag(struct net_pkt *pkt, size_t min_len, k_timeout_t timeout)
Get a data fragment that might be from user specific buffer pool or from global DATA pool.
size_t net_pkt_get_contiguous_len(struct net_pkt *pkt)
Get the contiguous buffer space.
int64_t net_time_t
Any occurrence of net_time_t specifies a concept of nanosecond resolution scalar time span,...
Definition net_time.h:103
static net_time_t net_ptp_time_to_ns(struct net_ptp_time *ts)
Convert a PTP timestamp to a nanosecond precision timestamp, both related to the local network refere...
Definition ptp_time.h:210
static struct net_ptp_time ns_to_net_ptp_time(net_time_t nsec)
Convert a nanosecond precision timestamp to a PTP timestamp, both related to the local network refere...
Definition ptp_time.h:231
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:148
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:81
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:56
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition ethernet_vlan.h:32
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition ethernet_vlan.h:94
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:44
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:107
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:68
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:97
Public functions for the Precision Time Protocol time specification.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INTPTR_TYPE__ intptr_t
Definition stdint.h:104
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
IPv6 address struct.
Definition net_ip.h:143
Kernel timeout type.
Definition sys_clock.h:65
Network buffer pool representation.
Definition net_buf.h:1078
Network buffer representation.
Definition net_buf.h:1006
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1032
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1053
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1035
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:207
Network Interface structure.
Definition net_if.h:698
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:272
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:268