Zephyr API Documentation  3.7.0-rc1
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
47struct net_context;
48
51/* buffer cursor used in net_pkt */
52struct net_pkt_cursor {
54 struct net_buf *buf;
56 uint8_t *pos;
57};
58
67struct net_pkt {
73
75 struct k_mem_slab *slab;
76
78 union {
79 struct net_buf *frags;
80 struct net_buf *buffer;
81 };
82
84 struct net_pkt_cursor cursor;
85
88
90 struct net_if *iface;
91
94#if defined(CONFIG_NET_TCP)
96 sys_snode_t next;
97#endif
98#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
99 struct net_if *orig_iface; /* Original network interface */
100#endif
101
102#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
121 struct net_ptp_time timestamp;
122#endif
123
124#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
125 struct {
127 uint32_t create_time;
128
129#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
130 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
136 struct {
137 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
138 int count;
139 } detail;
140#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
141 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
142 };
143#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
144
146 atomic_t atomic_ref;
147
148 /* Filled by layer 2 when network packet is received. */
149 struct net_linkaddr lladdr_src;
150 struct net_linkaddr lladdr_dst;
151 uint16_t ll_proto_type;
152
153#if defined(CONFIG_NET_IP)
154 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
155#endif
156
157 uint8_t overwrite : 1; /* Is packet content being overwritten? */
158 uint8_t eof : 1; /* Last packet before EOF */
159 uint8_t ptp_pkt : 1; /* For outgoing packet: is this packet
160 * a L2 PTP packet.
161 * Used only if defined (CONFIG_NET_L2_PTP)
162 */
163 uint8_t forwarding : 1; /* Are we forwarding this pkt
164 * Used only if defined(CONFIG_NET_ROUTE)
165 */
166 uint8_t family : 3; /* Address family, see net_ip.h */
167
168 /* bitfield byte alignment boundary */
169
170#if defined(CONFIG_NET_IPV4_ACD)
171 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
172 * message.
173 * Note: family needs to be
174 * AF_INET.
175 */
176#endif
177#if defined(CONFIG_NET_LLDP)
178 uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
179 * Note: family needs to be
180 * AF_UNSPEC.
181 */
182#endif
183 uint8_t ppp_msg : 1; /* This is a PPP message */
184 uint8_t captured : 1; /* Set to 1 if this packet is already being
185 * captured
186 */
187 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
188 * and already contains its L2 header to be
189 * preserved. Useful only if
190 * defined(CONFIG_NET_ETHERNET_BRIDGE).
191 */
192 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
193 * processed by the L2
194 */
195 uint8_t chksum_done : 1; /* Checksum has already been computed for
196 * the packet.
197 */
198#if defined(CONFIG_NET_IP_FRAGMENT)
199 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
200#endif
201#if defined(CONFIG_NET_PKT_TIMESTAMP)
202 uint8_t tx_timestamping : 1;
203 uint8_t rx_timestamping : 1;
204#endif
205 /* bitfield byte alignment boundary */
206
207#if defined(CONFIG_NET_IP)
208 union {
209 /* IPv6 hop limit or IPv4 ttl for this network packet.
210 * The value is shared between IPv6 and IPv4.
211 */
212#if defined(CONFIG_NET_IPV6)
213 uint8_t ipv6_hop_limit;
214#endif
215#if defined(CONFIG_NET_IPV4)
216 uint8_t ipv4_ttl;
217#endif
218 };
219
220 union {
221#if defined(CONFIG_NET_IPV4)
222 uint8_t ipv4_opts_len; /* length of IPv4 header options */
223#endif
224#if defined(CONFIG_NET_IPV6)
225 uint16_t ipv6_ext_len; /* length of extension headers */
226#endif
227 };
228
229#if defined(CONFIG_NET_IP_FRAGMENT)
230 union {
231#if defined(CONFIG_NET_IPV4_FRAGMENT)
232 struct {
233 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
234 uint16_t id; /* Fragment ID */
235 } ipv4_fragment;
236#endif /* CONFIG_NET_IPV4_FRAGMENT */
237#if defined(CONFIG_NET_IPV6_FRAGMENT)
238 struct {
239 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
240 uint32_t id; /* Fragment id */
241 uint16_t hdr_start; /* Where starts the fragment header */
242 } ipv6_fragment;
243#endif /* CONFIG_NET_IPV6_FRAGMENT */
244 };
245#endif /* CONFIG_NET_IP_FRAGMENT */
246
247#if defined(CONFIG_NET_IPV6)
248 /* Where is the start of the last header before payload data
249 * in IPv6 packet. This is offset value from start of the IPv6
250 * packet. Note that this value should be updated by who ever
251 * adds IPv6 extension headers to the network packet.
252 */
253 uint16_t ipv6_prev_hdr_start;
254
255 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
256 uint8_t ipv6_next_hdr; /* What is the very first next header */
257#endif /* CONFIG_NET_IPV6 */
258
259#if defined(CONFIG_NET_IP_DSCP_ECN)
261 uint8_t ip_dscp : 6;
262
264 uint8_t ip_ecn : 2;
265#endif /* CONFIG_NET_IP_DSCP_ECN */
266#endif /* CONFIG_NET_IP */
267
268#if defined(CONFIG_NET_VLAN)
269 /* VLAN TCI (Tag Control Information). This contains the Priority
270 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
271 * Identifier (VID, called more commonly VLAN tag). This value is
272 * kept in host byte order.
273 */
274 uint16_t vlan_tci;
275#endif /* CONFIG_NET_VLAN */
276
277#if defined(NET_PKT_HAS_CONTROL_BLOCK)
278 /* TODO: Evolve this into a union of orthogonal
279 * control block declarations if further L2
280 * stacks require L2-specific attributes.
281 */
282#if defined(CONFIG_IEEE802154)
283 /* The following structure requires a 4-byte alignment
284 * boundary to avoid padding.
285 */
286 struct net_pkt_cb_ieee802154 cb;
287#endif /* CONFIG_IEEE802154 */
288#endif /* NET_PKT_HAS_CONTROL_BLOCK */
289
293 uint8_t priority;
294
295#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
296 /* Remote address of the recived packet. This is only used by
297 * network interfaces with an offloaded TCP/IP stack, or if we
298 * have network tunneling in use.
299 */
300 union {
301 struct sockaddr remote;
302
303 /* This will make sure that there is enough storage to store
304 * the address struct. The access to value is via remote
305 * address.
306 */
307 struct sockaddr_storage remote_storage;
308 };
309#endif /* CONFIG_NET_OFFLOAD */
310
311#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
312 /* Tell the capture api that this is a captured packet */
313 uint8_t cooked_mode_pkt : 1;
314#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
315
316 /* @endcond */
317};
318
321/* The interface real ll address */
322static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
323{
324 return net_if_get_link_addr(pkt->iface);
325}
326
327static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
328{
329 return pkt->context;
330}
331
332static inline void net_pkt_set_context(struct net_pkt *pkt,
333 struct net_context *ctx)
334{
335 pkt->context = ctx;
336}
337
338static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
339{
340 return pkt->iface;
341}
342
343static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
344{
345 pkt->iface = iface;
346
347 /* If the network interface is set in pkt, then also set the type of
348 * the network address that is stored in pkt. This is done here so
349 * that the address type is properly set and is not forgotten.
350 */
351 if (iface) {
352 uint8_t type = net_if_get_link_addr(iface)->type;
353
354 pkt->lladdr_src.type = type;
355 pkt->lladdr_dst.type = type;
356 }
357}
358
359static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
360{
361#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
362 return pkt->orig_iface;
363#else
364 return pkt->iface;
365#endif
366}
367
368static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
369 struct net_if *iface)
370{
371#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
372 pkt->orig_iface = iface;
373#else
374 ARG_UNUSED(pkt);
375 ARG_UNUSED(iface);
376#endif
377}
378
379static inline uint8_t net_pkt_family(struct net_pkt *pkt)
380{
381 return pkt->family;
382}
383
384static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
385{
386 pkt->family = family;
387}
388
389static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
390{
391 return !!(pkt->ptp_pkt);
392}
393
394static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
395{
396 pkt->ptp_pkt = is_ptp;
397}
398
399static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
400{
401#if defined(CONFIG_NET_PKT_TIMESTAMP)
402 return !!(pkt->tx_timestamping);
403#else
404 ARG_UNUSED(pkt);
405
406 return false;
407#endif
408}
409
410static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
411{
412#if defined(CONFIG_NET_PKT_TIMESTAMP)
413 pkt->tx_timestamping = is_timestamping;
414#else
415 ARG_UNUSED(pkt);
416 ARG_UNUSED(is_timestamping);
417#endif
418}
419
420static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
421{
422#if defined(CONFIG_NET_PKT_TIMESTAMP)
423 return !!(pkt->rx_timestamping);
424#else
425 ARG_UNUSED(pkt);
426
427 return false;
428#endif
429}
430
431static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
432{
433#if defined(CONFIG_NET_PKT_TIMESTAMP)
434 pkt->rx_timestamping = is_timestamping;
435#else
436 ARG_UNUSED(pkt);
437 ARG_UNUSED(is_timestamping);
438#endif
439}
440
441static inline bool net_pkt_is_captured(struct net_pkt *pkt)
442{
443 return !!(pkt->captured);
444}
445
446static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
447{
448 pkt->captured = is_captured;
449}
450
451static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
452{
453 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
454}
455
456static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
457{
458 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
459 pkt->l2_bridged = is_l2_bridged;
460 }
461}
462
463static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
464{
465 return !!(pkt->l2_processed);
466}
467
468static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
469 bool is_l2_processed)
470{
471 pkt->l2_processed = is_l2_processed;
472}
473
474static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
475{
476 return !!(pkt->chksum_done);
477}
478
479static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
480 bool is_chksum_done)
481{
482 pkt->chksum_done = is_chksum_done;
483}
484
485static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
486{
487#if defined(CONFIG_NET_IP)
488 return pkt->ip_hdr_len;
489#else
490 ARG_UNUSED(pkt);
491
492 return 0;
493#endif
494}
495
496static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
497{
498#if defined(CONFIG_NET_IP)
499 pkt->ip_hdr_len = len;
500#else
501 ARG_UNUSED(pkt);
502 ARG_UNUSED(len);
503#endif
504}
505
506static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
507{
508#if defined(CONFIG_NET_IP_DSCP_ECN)
509 return pkt->ip_dscp;
510#else
511 ARG_UNUSED(pkt);
512
513 return 0;
514#endif
515}
516
517static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
518{
519#if defined(CONFIG_NET_IP_DSCP_ECN)
520 pkt->ip_dscp = dscp;
521#else
522 ARG_UNUSED(pkt);
523 ARG_UNUSED(dscp);
524#endif
525}
526
527static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
528{
529#if defined(CONFIG_NET_IP_DSCP_ECN)
530 return pkt->ip_ecn;
531#else
532 ARG_UNUSED(pkt);
533
534 return 0;
535#endif
536}
537
538static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
539{
540#if defined(CONFIG_NET_IP_DSCP_ECN)
541 pkt->ip_ecn = ecn;
542#else
543 ARG_UNUSED(pkt);
544 ARG_UNUSED(ecn);
545#endif
546}
547
548static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
549{
550 return pkt->eof;
551}
552
553static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
554{
555 pkt->eof = eof;
556}
557
558static inline bool net_pkt_forwarding(struct net_pkt *pkt)
559{
560 return !!(pkt->forwarding);
561}
562
563static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
564{
565 pkt->forwarding = forward;
566}
567
568#if defined(CONFIG_NET_IPV4)
569static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
570{
571 return pkt->ipv4_ttl;
572}
573
574static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
575 uint8_t ttl)
576{
577 pkt->ipv4_ttl = ttl;
578}
579
580static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
581{
582 return pkt->ipv4_opts_len;
583}
584
585static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
586 uint8_t opts_len)
587{
588 pkt->ipv4_opts_len = opts_len;
589}
590#else
591static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
592{
593 ARG_UNUSED(pkt);
594
595 return 0;
596}
597
598static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
599 uint8_t ttl)
600{
601 ARG_UNUSED(pkt);
602 ARG_UNUSED(ttl);
603}
604
605static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
606{
607 ARG_UNUSED(pkt);
608 return 0;
609}
610
611static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
612 uint8_t opts_len)
613{
614 ARG_UNUSED(pkt);
615 ARG_UNUSED(opts_len);
616}
617#endif
618
619#if defined(CONFIG_NET_IPV6)
620static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
621{
622 return pkt->ipv6_ext_opt_len;
623}
624
625static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
626 uint8_t len)
627{
628 pkt->ipv6_ext_opt_len = len;
629}
630
631static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
632{
633 return pkt->ipv6_next_hdr;
634}
635
636static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
637 uint8_t next_hdr)
638{
639 pkt->ipv6_next_hdr = next_hdr;
640}
641
642static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
643{
644 return pkt->ipv6_ext_len;
645}
646
647static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
648{
649 pkt->ipv6_ext_len = len;
650}
651
652static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
653{
654 return pkt->ipv6_prev_hdr_start;
655}
656
657static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
658 uint16_t offset)
659{
660 pkt->ipv6_prev_hdr_start = offset;
661}
662
663static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
664{
665 return pkt->ipv6_hop_limit;
666}
667
668static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
669 uint8_t hop_limit)
670{
671 pkt->ipv6_hop_limit = hop_limit;
672}
673#else /* CONFIG_NET_IPV6 */
674static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
675{
676 ARG_UNUSED(pkt);
677
678 return 0;
679}
680
681static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
682 uint8_t len)
683{
684 ARG_UNUSED(pkt);
685 ARG_UNUSED(len);
686}
687
688static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
689{
690 ARG_UNUSED(pkt);
691
692 return 0;
693}
694
695static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
696 uint8_t next_hdr)
697{
698 ARG_UNUSED(pkt);
699 ARG_UNUSED(next_hdr);
700}
701
702static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
703{
704 ARG_UNUSED(pkt);
705
706 return 0;
707}
708
709static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
710{
711 ARG_UNUSED(pkt);
712 ARG_UNUSED(len);
713}
714
715static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
716{
717 ARG_UNUSED(pkt);
718
719 return 0;
720}
721
722static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
723 uint16_t offset)
724{
725 ARG_UNUSED(pkt);
726 ARG_UNUSED(offset);
727}
728
729static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
730{
731 ARG_UNUSED(pkt);
732
733 return 0;
734}
735
736static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
737 uint8_t hop_limit)
738{
739 ARG_UNUSED(pkt);
740 ARG_UNUSED(hop_limit);
741}
742#endif /* CONFIG_NET_IPV6 */
743
744static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
745{
746#if defined(CONFIG_NET_IPV6)
747 return pkt->ipv6_ext_len;
748#elif defined(CONFIG_NET_IPV4)
749 return pkt->ipv4_opts_len;
750#else
751 ARG_UNUSED(pkt);
752
753 return 0;
754#endif
755}
756
757#if defined(CONFIG_NET_IPV4_FRAGMENT)
758static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
759{
760 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
761}
762
763static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
764{
765 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
766}
767
768static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
769{
770 pkt->ipv4_fragment.flags = flags;
771}
772
773static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
774{
775 return pkt->ipv4_fragment.id;
776}
777
778static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
779{
780 pkt->ipv4_fragment.id = id;
781}
782#else /* CONFIG_NET_IPV4_FRAGMENT */
783static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
784{
785 ARG_UNUSED(pkt);
786
787 return 0;
788}
789
790static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
791{
792 ARG_UNUSED(pkt);
793
794 return 0;
795}
796
797static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
798{
799 ARG_UNUSED(pkt);
800 ARG_UNUSED(flags);
801}
802
803static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
804{
805 ARG_UNUSED(pkt);
806
807 return 0;
808}
809
810static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
811{
812 ARG_UNUSED(pkt);
813 ARG_UNUSED(id);
814}
815#endif /* CONFIG_NET_IPV4_FRAGMENT */
816
817#if defined(CONFIG_NET_IPV6_FRAGMENT)
818static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
819{
820 return pkt->ipv6_fragment.hdr_start;
821}
822
823static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
824 uint16_t start)
825{
826 pkt->ipv6_fragment.hdr_start = start;
827}
828
829static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
830{
831 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
832}
833static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
834{
835 return (pkt->ipv6_fragment.flags & 0x01) != 0;
836}
837
838static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
840{
841 pkt->ipv6_fragment.flags = flags;
842}
843
844static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
845{
846 return pkt->ipv6_fragment.id;
847}
848
849static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
850 uint32_t id)
851{
852 pkt->ipv6_fragment.id = id;
853}
854#else /* CONFIG_NET_IPV6_FRAGMENT */
855static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
856{
857 ARG_UNUSED(pkt);
858
859 return 0;
860}
861
862static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
863 uint16_t start)
864{
865 ARG_UNUSED(pkt);
866 ARG_UNUSED(start);
867}
868
869static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
870{
871 ARG_UNUSED(pkt);
872
873 return 0;
874}
875
876static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
877{
878 ARG_UNUSED(pkt);
879
880 return 0;
881}
882
883static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
885{
886 ARG_UNUSED(pkt);
887 ARG_UNUSED(flags);
888}
889
890static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
891{
892 ARG_UNUSED(pkt);
893
894 return 0;
895}
896
897static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
898 uint32_t id)
899{
900 ARG_UNUSED(pkt);
901 ARG_UNUSED(id);
902}
903#endif /* CONFIG_NET_IPV6_FRAGMENT */
904
905#if defined(CONFIG_NET_IP_FRAGMENT)
906static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
907{
908 return !!(pkt->ip_reassembled);
909}
910
911static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
912 bool reassembled)
913{
914 pkt->ip_reassembled = reassembled;
915}
916#else /* CONFIG_NET_IP_FRAGMENT */
917static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
918{
919 ARG_UNUSED(pkt);
920
921 return false;
922}
923
924static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
925 bool reassembled)
926{
927 ARG_UNUSED(pkt);
928 ARG_UNUSED(reassembled);
929}
930#endif /* CONFIG_NET_IP_FRAGMENT */
931
932static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
933{
934 return pkt->priority;
935}
936
937static inline void net_pkt_set_priority(struct net_pkt *pkt,
938 uint8_t priority)
939{
940 pkt->priority = priority;
941}
942
943#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
944static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
945{
946 return pkt->cooked_mode_pkt;
947}
948
949static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
950{
951 pkt->cooked_mode_pkt = value;
952}
953#else
954static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
955{
956 ARG_UNUSED(pkt);
957
958 return false;
959}
960
961static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
962{
963 ARG_UNUSED(pkt);
964 ARG_UNUSED(value);
965}
966#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
967
968#if defined(CONFIG_NET_VLAN)
969static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
970{
971 return net_eth_vlan_get_vid(pkt->vlan_tci);
972}
973
974static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
975{
976 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
977}
978
979static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
980{
981 return net_eth_vlan_get_pcp(pkt->vlan_tci);
982}
983
984static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
985 uint8_t priority)
986{
987 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
988}
989
990static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
991{
992 return net_eth_vlan_get_dei(pkt->vlan_tci);
993}
994
995static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
996{
997 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
998}
999
1000static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1001{
1002 pkt->vlan_tci = tci;
1003}
1004
1005static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1006{
1007 return pkt->vlan_tci;
1008}
1009#else
1010static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1011{
1012 ARG_UNUSED(pkt);
1013
1014 return NET_VLAN_TAG_UNSPEC;
1015}
1016
1017static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1018{
1019 ARG_UNUSED(pkt);
1020 ARG_UNUSED(tag);
1021}
1022
1023static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1024{
1025 ARG_UNUSED(pkt);
1026
1027 return 0;
1028}
1029
1030static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1031{
1032 ARG_UNUSED(pkt);
1033
1034 return false;
1035}
1036
1037static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1038{
1039 ARG_UNUSED(pkt);
1040 ARG_UNUSED(dei);
1041}
1042
1043static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1044{
1045 ARG_UNUSED(pkt);
1046
1047 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1048}
1049
1050static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1051{
1052 ARG_UNUSED(pkt);
1053 ARG_UNUSED(tci);
1054}
1055#endif
1056
1057#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1058static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1059{
1060 return &pkt->timestamp;
1061}
1062
1063static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1064 struct net_ptp_time *timestamp)
1065{
1066 pkt->timestamp.second = timestamp->second;
1067 pkt->timestamp.nanosecond = timestamp->nanosecond;
1068}
1069
1070static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1071{
1072 return net_ptp_time_to_ns(&pkt->timestamp);
1073}
1074
1075static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1076{
1077 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1078}
1079#else
1080static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1081{
1082 ARG_UNUSED(pkt);
1083
1084 return NULL;
1085}
1086
1087static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1088 struct net_ptp_time *timestamp)
1089{
1090 ARG_UNUSED(pkt);
1091 ARG_UNUSED(timestamp);
1092}
1093
1094static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1095{
1096 ARG_UNUSED(pkt);
1097
1098 return 0;
1099}
1100
1101static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1102{
1103 ARG_UNUSED(pkt);
1104 ARG_UNUSED(timestamp);
1105}
1106#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1107
1108#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
1109static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1110{
1111 return pkt->create_time;
1112}
1113
1114static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1115 uint32_t create_time)
1116{
1117 pkt->create_time = create_time;
1118}
1119#else
1120static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1121{
1122 ARG_UNUSED(pkt);
1123
1124 return 0U;
1125}
1126
1127static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1128 uint32_t create_time)
1129{
1130 ARG_UNUSED(pkt);
1131 ARG_UNUSED(create_time);
1132}
1133#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
1134
1138static inline uint64_t net_pkt_txtime(struct net_pkt *pkt)
1139{
1140#if defined(CONFIG_NET_PKT_TXTIME)
1141 return pkt->timestamp.second * NSEC_PER_SEC + pkt->timestamp.nanosecond;
1142#else
1143 ARG_UNUSED(pkt);
1144
1145 return 0;
1146#endif /* CONFIG_NET_PKT_TXTIME */
1147}
1148
1153static inline void net_pkt_set_txtime(struct net_pkt *pkt, uint64_t txtime)
1154{
1155#if defined(CONFIG_NET_PKT_TXTIME)
1156 pkt->timestamp.second = txtime / NSEC_PER_SEC;
1157 pkt->timestamp.nanosecond = txtime % NSEC_PER_SEC;
1158#else
1159 ARG_UNUSED(pkt);
1160 ARG_UNUSED(txtime);
1161#endif /* CONFIG_NET_PKT_TXTIME */
1162}
1163
1164#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1165 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1166static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1167{
1168 return pkt->detail.stat;
1169}
1170
1171static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1172{
1173 return pkt->detail.count;
1174}
1175
1176static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1177{
1178 memset(&pkt->detail, 0, sizeof(pkt->detail));
1179}
1180
1181static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1182 uint32_t tick)
1183{
1184 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1185 NET_ERR("Detail stats count overflow (%d >= %d)",
1186 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1187 return;
1188 }
1189
1190 pkt->detail.stat[pkt->detail.count++] = tick;
1191}
1192
1193#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1194#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1195#else
1196static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1197{
1198 ARG_UNUSED(pkt);
1199
1200 return NULL;
1201}
1202
1203static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1204{
1205 ARG_UNUSED(pkt);
1206
1207 return 0;
1208}
1209
1210static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1211{
1212 ARG_UNUSED(pkt);
1213}
1214
1215static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1216{
1217 ARG_UNUSED(pkt);
1218 ARG_UNUSED(tick);
1219}
1220
1221#define net_pkt_set_tx_stats_tick(pkt, tick)
1222#define net_pkt_set_rx_stats_tick(pkt, tick)
1223#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1224 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1225
1226static inline size_t net_pkt_get_len(struct net_pkt *pkt)
1227{
1228 return net_buf_frags_len(pkt->frags);
1229}
1230
1231static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1232{
1233 return pkt->frags->data;
1234}
1235
1236static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1237{
1238 return pkt->frags->data;
1239}
1240
1241static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1242{
1243 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1244}
1245
1246static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1247{
1248 return &pkt->lladdr_src;
1249}
1250
1251static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1252{
1253 return &pkt->lladdr_dst;
1254}
1255
1256static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1257{
1258 uint8_t *addr = net_pkt_lladdr_src(pkt)->addr;
1259
1260 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1261 net_pkt_lladdr_dst(pkt)->addr = addr;
1262}
1263
1264static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1265{
1266 net_pkt_lladdr_src(pkt)->addr = NULL;
1267 net_pkt_lladdr_src(pkt)->len = 0U;
1268}
1269
1270static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1271{
1272 return pkt->ll_proto_type;
1273}
1274
1275static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1276{
1277 pkt->ll_proto_type = type;
1278}
1279
1280#if defined(CONFIG_NET_IPV4_ACD)
1281static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1282{
1283 return !!(pkt->ipv4_acd_arp_msg);
1284}
1285
1286static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1287 bool is_acd_arp_msg)
1288{
1289 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1290}
1291#else /* CONFIG_NET_IPV4_ACD */
1292static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1293{
1294 ARG_UNUSED(pkt);
1295
1296 return false;
1297}
1298
1299static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1300 bool is_acd_arp_msg)
1301{
1302 ARG_UNUSED(pkt);
1303 ARG_UNUSED(is_acd_arp_msg);
1304}
1305#endif /* CONFIG_NET_IPV4_ACD */
1306
1307#if defined(CONFIG_NET_LLDP)
1308static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1309{
1310 return !!(pkt->lldp_pkt);
1311}
1312
1313static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1314{
1315 pkt->lldp_pkt = is_lldp;
1316}
1317#else
1318static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1319{
1320 ARG_UNUSED(pkt);
1321
1322 return false;
1323}
1324
1325static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1326{
1327 ARG_UNUSED(pkt);
1328 ARG_UNUSED(is_lldp);
1329}
1330#endif /* CONFIG_NET_LLDP */
1331
1332#if defined(CONFIG_NET_L2_PPP)
1333static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1334{
1335 return !!(pkt->ppp_msg);
1336}
1337
1338static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1339 bool is_ppp_msg)
1340{
1341 pkt->ppp_msg = is_ppp_msg;
1342}
1343#else /* CONFIG_NET_L2_PPP */
1344static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1345{
1346 ARG_UNUSED(pkt);
1347
1348 return false;
1349}
1350
1351static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1352 bool is_ppp_msg)
1353{
1354 ARG_UNUSED(pkt);
1355 ARG_UNUSED(is_ppp_msg);
1356}
1357#endif /* CONFIG_NET_L2_PPP */
1358
1359#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1360static inline void *net_pkt_cb(struct net_pkt *pkt)
1361{
1362 return &pkt->cb;
1363}
1364#else
1365static inline void *net_pkt_cb(struct net_pkt *pkt)
1366{
1367 ARG_UNUSED(pkt);
1368
1369 return NULL;
1370}
1371#endif
1372
1373#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1374#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1375
1376static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1377{
1379 net_pkt_context(pkt)),
1380 (struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1381}
1382
1383static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1384{
1385 pkt->overwrite = overwrite;
1386}
1387
1388static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1389{
1390 return !!(pkt->overwrite);
1391}
1392
1393#ifdef CONFIG_NET_PKT_FILTER
1394
1395bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1396bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1397
1398#else
1399
1400static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1401{
1402 ARG_UNUSED(pkt);
1403
1404 return true;
1405}
1406
1407static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1408{
1409 ARG_UNUSED(pkt);
1410
1411 return true;
1412}
1413
1414#endif /* CONFIG_NET_PKT_FILTER */
1415
1416#if defined(CONFIG_NET_PKT_FILTER) && \
1417 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1418
1419bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1420
1421#else
1422
1423static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1424{
1425 ARG_UNUSED(pkt);
1426
1427 return true;
1428}
1429
1430#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1431
1432#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1433
1434bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1435
1436#else
1437
1438static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1439{
1440 ARG_UNUSED(pkt);
1441
1442 return true;
1443}
1444
1445#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1446
1447#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1448static inline struct sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1449{
1450 return &pkt->remote;
1451}
1452
1453static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1454 struct sockaddr *address,
1455 socklen_t len)
1456{
1457 memcpy(&pkt->remote, address, len);
1458}
1459#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1460
1461/* @endcond */
1462
1476#define NET_PKT_SLAB_DEFINE(name, count) \
1477 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4)
1478
1481/* Backward compatibility macro */
1482#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1483
1499#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1500 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1501 0, NULL)
1502
1505#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1506 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1507#define NET_PKT_DEBUG_ENABLED
1508#endif
1509
1510#if defined(NET_PKT_DEBUG_ENABLED)
1511
1512/* Debug versions of the net_pkt functions that are used when tracking
1513 * buffer usage.
1514 */
1515
1516struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1517 size_t min_len,
1518 k_timeout_t timeout,
1519 const char *caller,
1520 int line);
1521
1522#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1523 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1524
1525struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1526 k_timeout_t timeout,
1527 const char *caller,
1528 int line);
1529#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1530 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1531
1532struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1533 k_timeout_t timeout,
1534 const char *caller,
1535 int line);
1536#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1537 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1538
1539struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1540 k_timeout_t timeout,
1541 const char *caller, int line);
1542#define net_pkt_get_frag(pkt, min_len, timeout) \
1543 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1544
1545void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1546#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1547
1548struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1549 int line);
1550#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1551
1552struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1553 const char *caller, int line);
1554#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1555
1556void net_pkt_frag_unref_debug(struct net_buf *frag,
1557 const char *caller, int line);
1558#define net_pkt_frag_unref(frag) \
1559 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1560
1561struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1562 struct net_buf *parent,
1563 struct net_buf *frag,
1564 const char *caller, int line);
1565#define net_pkt_frag_del(pkt, parent, frag) \
1566 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1567
1568void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1569 const char *caller, int line);
1570#define net_pkt_frag_add(pkt, frag) \
1571 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1572
1573void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1574 const char *caller, int line);
1575#define net_pkt_frag_insert(pkt, frag) \
1576 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1577#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1578 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1579 */
1589#if defined(NET_PKT_DEBUG_ENABLED)
1590void net_pkt_print_frags(struct net_pkt *pkt);
1591#else
1592#define net_pkt_print_frags(pkt)
1593#endif
1594
1609#if !defined(NET_PKT_DEBUG_ENABLED)
1611 size_t min_len, k_timeout_t timeout);
1612#endif
1613
1628#if !defined(NET_PKT_DEBUG_ENABLED)
1629struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1630#endif
1631
1646#if !defined(NET_PKT_DEBUG_ENABLED)
1647struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1648#endif
1649
1662#if !defined(NET_PKT_DEBUG_ENABLED)
1663struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1664 k_timeout_t timeout);
1665#endif
1666
1676#if !defined(NET_PKT_DEBUG_ENABLED)
1677void net_pkt_unref(struct net_pkt *pkt);
1678#endif
1679
1689#if !defined(NET_PKT_DEBUG_ENABLED)
1690struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1691#endif
1692
1702#if !defined(NET_PKT_DEBUG_ENABLED)
1703struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1704#endif
1705
1711#if !defined(NET_PKT_DEBUG_ENABLED)
1712void net_pkt_frag_unref(struct net_buf *frag);
1713#endif
1714
1725#if !defined(NET_PKT_DEBUG_ENABLED)
1727 struct net_buf *parent,
1728 struct net_buf *frag);
1729#endif
1730
1737#if !defined(NET_PKT_DEBUG_ENABLED)
1738void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1739#endif
1740
1747#if !defined(NET_PKT_DEBUG_ENABLED)
1748void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1749#endif
1750
1757void net_pkt_compact(struct net_pkt *pkt);
1758
1767void net_pkt_get_info(struct k_mem_slab **rx,
1768 struct k_mem_slab **tx,
1769 struct net_buf_pool **rx_data,
1770 struct net_buf_pool **tx_data);
1771
1774#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1778void net_pkt_print(void);
1779
1780typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1781 struct net_buf *buf,
1782 const char *func_alloc,
1783 int line_alloc,
1784 const char *func_free,
1785 int line_free,
1786 bool in_use,
1787 void *user_data);
1788
1789void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1790
1791const char *net_pkt_slab2str(struct k_mem_slab *slab);
1792const char *net_pkt_pool2str(struct net_buf_pool *pool);
1793
1794#else
1795#define net_pkt_print(...)
1796#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1797
1798/* New allocator, and API are defined below.
1799 * This will be simpler when time will come to get rid of former API above.
1800 */
1801#if defined(NET_PKT_DEBUG_ENABLED)
1802
1803struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1804 const char *caller, int line);
1805#define net_pkt_alloc(_timeout) \
1806 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1807
1808struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1809 k_timeout_t timeout,
1810 const char *caller, int line);
1811#define net_pkt_alloc_from_slab(_slab, _timeout) \
1812 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1813
1814struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1815 const char *caller, int line);
1816#define net_pkt_rx_alloc(_timeout) \
1817 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1818
1819struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1820 k_timeout_t timeout,
1821 const char *caller,
1822 int line);
1823#define net_pkt_alloc_on_iface(_iface, _timeout) \
1824 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1825
1826struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1827 k_timeout_t timeout,
1828 const char *caller,
1829 int line);
1830#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1831 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1832 __func__, __LINE__)
1833
1834int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1835 size_t size,
1836 enum net_ip_protocol proto,
1837 k_timeout_t timeout,
1838 const char *caller, int line);
1839#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1840 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1841 __func__, __LINE__)
1842
1843int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1844 k_timeout_t timeout,
1845 const char *caller, int line);
1846#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1847 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1848 __func__, __LINE__)
1849
1850struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1851 size_t size,
1852 sa_family_t family,
1853 enum net_ip_protocol proto,
1854 k_timeout_t timeout,
1855 const char *caller,
1856 int line);
1857#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1858 _proto, _timeout) \
1859 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1860 _proto, _timeout, \
1861 __func__, __LINE__)
1862
1863struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1864 size_t size,
1865 sa_family_t family,
1866 enum net_ip_protocol proto,
1867 k_timeout_t timeout,
1868 const char *caller,
1869 int line);
1870#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1871 _proto, _timeout) \
1872 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1873 _proto, _timeout, \
1874 __func__, __LINE__)
1875#endif /* NET_PKT_DEBUG_ENABLED */
1888#if !defined(NET_PKT_DEBUG_ENABLED)
1890#endif
1891
1906#if !defined(NET_PKT_DEBUG_ENABLED)
1907struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
1908 k_timeout_t timeout);
1909#endif
1910
1921#if !defined(NET_PKT_DEBUG_ENABLED)
1923#endif
1924
1933#if !defined(NET_PKT_DEBUG_ENABLED)
1935 k_timeout_t timeout);
1936
1939/* Same as above but specifically for RX packet */
1940struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
1941 k_timeout_t timeout);
1944#endif
1945
1961#if !defined(NET_PKT_DEBUG_ENABLED)
1963 size_t size,
1964 enum net_ip_protocol proto,
1965 k_timeout_t timeout);
1966#endif
1967
1981#if !defined(NET_PKT_DEBUG_ENABLED)
1982int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
1983 k_timeout_t timeout);
1984#endif
1985
1997#if !defined(NET_PKT_DEBUG_ENABLED)
1999 size_t size,
2000 sa_family_t family,
2001 enum net_ip_protocol proto,
2002 k_timeout_t timeout);
2003
2006/* Same as above but specifically for RX packet */
2007struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2008 size_t size,
2009 sa_family_t family,
2010 enum net_ip_protocol proto,
2011 k_timeout_t timeout);
2012
2015#endif
2016
2023void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2024
2036
2053 enum net_ip_protocol proto);
2054
2064
2079int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2080
2089
2096static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2097 struct net_pkt_cursor *backup)
2098{
2099 backup->buf = pkt->cursor.buf;
2100 backup->pos = pkt->cursor.pos;
2101}
2102
2109static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2110 struct net_pkt_cursor *backup)
2111{
2112 pkt->cursor.buf = backup->buf;
2113 pkt->cursor.pos = backup->pos;
2114}
2115
2123static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2124{
2125 return pkt->cursor.pos;
2126}
2127
2148int net_pkt_skip(struct net_pkt *pkt, size_t length);
2149
2164int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2165
2179int net_pkt_copy(struct net_pkt *pkt_dst,
2180 struct net_pkt *pkt_src,
2181 size_t length);
2182
2192struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2193
2203struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2204
2214 k_timeout_t timeout);
2215
2229int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2230
2243static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2244{
2245 return net_pkt_read(pkt, data, 1);
2246}
2247
2260int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2261
2274int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2275
2288int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2289
2303int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2304
2317static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2318{
2319 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2320}
2321
2334static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2335{
2336 uint16_t data_be16 = htons(data);
2337
2338 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2339}
2340
2353static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2354{
2355 uint32_t data_be32 = htonl(data);
2356
2357 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2358}
2359
2372static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2373{
2374 uint32_t data_le32 = sys_cpu_to_le32(data);
2375
2376 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2377}
2378
2391static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2392{
2393 uint16_t data_le16 = sys_cpu_to_le16(data);
2394
2395 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2396}
2397
2406
2419int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2420
2433int net_pkt_pull(struct net_pkt *pkt, size_t length);
2434
2444
2456bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2457
2467
2470struct net_pkt_data_access {
2471#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2472 void *data;
2473#endif
2474 const size_t size;
2475};
2476
2477#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2478#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2479 struct net_pkt_data_access _name = { \
2480 .size = sizeof(_type), \
2481 }
2482
2483#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2484 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2485
2486#else
2487#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2488 _type _hdr_##_name; \
2489 struct net_pkt_data_access _name = { \
2490 .data = &_hdr_##_name, \
2491 .size = sizeof(_type), \
2492 }
2493
2494#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2495 struct net_pkt_data_access _name = { \
2496 .data = NULL, \
2497 .size = sizeof(_type), \
2498 }
2499
2500#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2501
2517void *net_pkt_get_data(struct net_pkt *pkt,
2518 struct net_pkt_data_access *access);
2519
2534 struct net_pkt_data_access *access);
2535
2540static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2541 struct net_pkt_data_access *access)
2542{
2543 return net_pkt_skip(pkt, access->size);
2544}
2545
2550#ifdef __cplusplus
2551}
2552#endif
2553
2554#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
long atomic_t
Definition: atomic_types.h:15
#define ALWAYS_INLINE
Definition: common.h:129
VLAN specific definitions.
#define NSEC_PER_SEC
number of nanoseconds per second
Definition: sys_clock.h:107
unsigned short int sa_family_t
Socket address family type.
Definition: net_ip.h:164
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition: net_ip.h:120
size_t socklen_t
Length of a socket address.
Definition: net_ip.h:168
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition: net_ip.h:128
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition: net_ip.h:62
static size_t net_buf_frags_len(struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition: buf.h:2717
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition: net_context.h:709
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition: net_if.h:1075
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:2006
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:2353
void net_pkt_cursor_init(struct net_pkt *pkt)
Initialize net_pkt cursor.
int net_pkt_skip(struct net_pkt *pkt, size_t length)
Skip some data from a net_pkt.
struct net_pkt * net_pkt_shallow_clone(struct net_pkt *pkt, k_timeout_t timeout)
Clone pkt and increase the refcount of its buffer.
void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer)
Append a buffer in packet.
#define net_pkt_print_frags(pkt)
Print fragment list and the fragment sizes.
Definition: net_pkt.h:1592
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:2334
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:2317
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:2123
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:2096
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:2540
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:2391
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:2109
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:2372
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:2243
struct net_buf * net_pkt_get_frag(struct net_pkt *pkt, size_t min_len, k_timeout_t timeout)
Get a data fragment that might be from user specific buffer pool or from global DATA pool.
size_t net_pkt_get_contiguous_len(struct net_pkt *pkt)
Get the contiguous buffer space.
int64_t net_time_t
Any occurrence of net_time_t specifies a concept of nanosecond resolution scalar time span,...
Definition: net_time.h:101
static net_time_t net_ptp_time_to_ns(struct net_ptp_time *ts)
Convert a PTP timestamp to a nanosecond precision timestamp, both related to the local network refere...
Definition: ptp_time.h:208
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:229
struct _snode sys_snode_t
Single-linked list node structure.
Definition: slist.h:39
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition: util_macro.h:124
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition: ethernet_vlan.h:76
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition: ethernet_vlan.h:51
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition: ethernet_vlan.h:30
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition: ethernet_vlan.h:89
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition: ethernet_vlan.h:39
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition: ethernet_vlan.h:102
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition: ethernet_vlan.h:63
Packet data common to all IEEE 802.15.4 L2 layers.
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:139
Kernel timeout type.
Definition: sys_clock.h:65
Network buffer pool representation.
Definition: buf.h:1076
Network buffer representation.
Definition: buf.h:1004
uint8_t * data
Pointer to the start of data in the buffer.
Definition: buf.h:1030
uint8_t user_data[]
System metadata for this buffer.
Definition: buf.h:1051
uint16_t len
Length of the data behind the data pointer.
Definition: buf.h:1033
Note that we do not store the actual source IP address in the context because the address is already ...
Definition: net_context.h:205
Network Interface structure.
Definition: net_if.h:678
Hardware link address structure.
Definition: net_linkaddr.h:67
uint8_t * addr
The array of byte representing the address.
Definition: net_linkaddr.h:69
uint8_t type
What kind of address is this for.
Definition: net_linkaddr.h:75
Network packet.
Definition: net_pkt.h:67
struct net_buf * frags
buffer fragment
Definition: net_pkt.h:79
struct net_context * context
Network connection context.
Definition: net_pkt.h:87
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition: net_pkt.h:84
struct net_if * iface
Network interface.
Definition: net_pkt.h:90
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition: net_pkt.h:72
struct net_buf * buffer
alias to a buffer fragment
Definition: net_pkt.h:80
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition: net_pkt.h:75
(Generalized) Precision Time Protocol Timestamp format.
Definition: ptp_time.h:109
uint32_t nanosecond
Nanoseconds.
Definition: ptp_time.h:132
uint64_t second
Second value.
Definition: ptp_time.h:128
Generic sockaddr struct.
Definition: net_ip.h:385
Definition: stat.h:92
#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