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