Zephyr API Documentation  3.6.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
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_AUTO)
171 uint8_t ipv4_auto_arp_msg : 1; /* Is this pkt IPv4 autoconf 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 /* bitfield byte alignment boundary */
202
203#if defined(CONFIG_NET_IP)
204 union {
205 /* IPv6 hop limit or IPv4 ttl for this network packet.
206 * The value is shared between IPv6 and IPv4.
207 */
208#if defined(CONFIG_NET_IPV6)
209 uint8_t ipv6_hop_limit;
210#endif
211#if defined(CONFIG_NET_IPV4)
212 uint8_t ipv4_ttl;
213#endif
214 };
215
216 union {
217#if defined(CONFIG_NET_IPV4)
218 uint8_t ipv4_opts_len; /* length of IPv4 header options */
219#endif
220#if defined(CONFIG_NET_IPV6)
221 uint16_t ipv6_ext_len; /* length of extension headers */
222#endif
223 };
224
225#if defined(CONFIG_NET_IP_FRAGMENT)
226 union {
227#if defined(CONFIG_NET_IPV4_FRAGMENT)
228 struct {
229 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
230 uint16_t id; /* Fragment ID */
231 } ipv4_fragment;
232#endif /* CONFIG_NET_IPV4_FRAGMENT */
233#if defined(CONFIG_NET_IPV6_FRAGMENT)
234 struct {
235 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
236 uint32_t id; /* Fragment id */
237 uint16_t hdr_start; /* Where starts the fragment header */
238 } ipv6_fragment;
239#endif /* CONFIG_NET_IPV6_FRAGMENT */
240 };
241#endif /* CONFIG_NET_IP_FRAGMENT */
242
243#if defined(CONFIG_NET_IPV6)
244 /* Where is the start of the last header before payload data
245 * in IPv6 packet. This is offset value from start of the IPv6
246 * packet. Note that this value should be updated by who ever
247 * adds IPv6 extension headers to the network packet.
248 */
249 uint16_t ipv6_prev_hdr_start;
250
251 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
252 uint8_t ipv6_next_hdr; /* What is the very first next header */
253#endif /* CONFIG_NET_IPV6 */
254
255#if defined(CONFIG_NET_IP_DSCP_ECN)
257 uint8_t ip_dscp : 6;
258
260 uint8_t ip_ecn : 2;
261#endif /* CONFIG_NET_IP_DSCP_ECN */
262#endif /* CONFIG_NET_IP */
263
264#if defined(CONFIG_NET_VLAN)
265 /* VLAN TCI (Tag Control Information). This contains the Priority
266 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
267 * Identifier (VID, called more commonly VLAN tag). This value is
268 * kept in host byte order.
269 */
270 uint16_t vlan_tci;
271#endif /* CONFIG_NET_VLAN */
272
273#if defined(NET_PKT_HAS_CONTROL_BLOCK)
274 /* TODO: Evolve this into a union of orthogonal
275 * control block declarations if further L2
276 * stacks require L2-specific attributes.
277 */
278#if defined(CONFIG_IEEE802154)
279 /* The following structure requires a 4-byte alignment
280 * boundary to avoid padding.
281 */
282 struct net_pkt_cb_ieee802154 cb;
283#endif /* CONFIG_IEEE802154 */
284#endif /* NET_PKT_HAS_CONTROL_BLOCK */
285
289 uint8_t priority;
290
291#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
292 /* Remote address of the recived packet. This is only used by
293 * network interfaces with an offloaded TCP/IP stack, or if we
294 * have network tunneling in use.
295 */
296 union {
297 struct sockaddr remote;
298
299 /* This will make sure that there is enough storage to store
300 * the address struct. The access to value is via remote
301 * address.
302 */
303 struct sockaddr_storage remote_storage;
304 };
305#endif /* CONFIG_NET_OFFLOAD */
306
307#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
308 /* Tell the capture api that this is a captured packet */
309 uint8_t cooked_mode_pkt : 1;
310#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
311
312 /* @endcond */
313};
314
317/* The interface real ll address */
318static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
319{
320 return net_if_get_link_addr(pkt->iface);
321}
322
323static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
324{
325 return pkt->context;
326}
327
328static inline void net_pkt_set_context(struct net_pkt *pkt,
329 struct net_context *ctx)
330{
331 pkt->context = ctx;
332}
333
334static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
335{
336 return pkt->iface;
337}
338
339static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
340{
341 pkt->iface = iface;
342
343 /* If the network interface is set in pkt, then also set the type of
344 * the network address that is stored in pkt. This is done here so
345 * that the address type is properly set and is not forgotten.
346 */
347 if (iface) {
348 uint8_t type = net_if_get_link_addr(iface)->type;
349
350 pkt->lladdr_src.type = type;
351 pkt->lladdr_dst.type = type;
352 }
353}
354
355static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
356{
357#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
358 return pkt->orig_iface;
359#else
360 return pkt->iface;
361#endif
362}
363
364static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
365 struct net_if *iface)
366{
367#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
368 pkt->orig_iface = iface;
369#endif
370}
371
372static inline uint8_t net_pkt_family(struct net_pkt *pkt)
373{
374 return pkt->family;
375}
376
377static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
378{
379 pkt->family = family;
380}
381
382static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
383{
384 return !!(pkt->ptp_pkt);
385}
386
387static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
388{
389 pkt->ptp_pkt = is_ptp;
390}
391
392static inline bool net_pkt_is_captured(struct net_pkt *pkt)
393{
394 return !!(pkt->captured);
395}
396
397static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
398{
399 pkt->captured = is_captured;
400}
401
402static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
403{
404 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
405}
406
407static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
408{
409 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
410 pkt->l2_bridged = is_l2_bridged;
411 }
412}
413
414static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
415{
416 return !!(pkt->l2_processed);
417}
418
419static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
420 bool is_l2_processed)
421{
422 pkt->l2_processed = is_l2_processed;
423}
424
425static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
426{
427 return !!(pkt->chksum_done);
428}
429
430static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
431 bool is_chksum_done)
432{
433 pkt->chksum_done = is_chksum_done;
434}
435
436static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
437{
438#if defined(CONFIG_NET_IP)
439 return pkt->ip_hdr_len;
440#else
441 return 0;
442#endif
443}
444
445static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
446{
447#if defined(CONFIG_NET_IP)
448 pkt->ip_hdr_len = len;
449#endif
450}
451
452static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
453{
454#if defined(CONFIG_NET_IP_DSCP_ECN)
455 return pkt->ip_dscp;
456#else
457 return 0;
458#endif
459}
460
461static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
462{
463#if defined(CONFIG_NET_IP_DSCP_ECN)
464 pkt->ip_dscp = dscp;
465#endif
466}
467
468static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
469{
470#if defined(CONFIG_NET_IP_DSCP_ECN)
471 return pkt->ip_ecn;
472#else
473 return 0;
474#endif
475}
476
477static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
478{
479#if defined(CONFIG_NET_IP_DSCP_ECN)
480 pkt->ip_ecn = ecn;
481#endif
482}
483
484static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
485{
486 return pkt->eof;
487}
488
489static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
490{
491 pkt->eof = eof;
492}
493
494static inline bool net_pkt_forwarding(struct net_pkt *pkt)
495{
496 return !!(pkt->forwarding);
497}
498
499static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
500{
501 pkt->forwarding = forward;
502}
503
504#if defined(CONFIG_NET_IPV4)
505static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
506{
507 return pkt->ipv4_ttl;
508}
509
510static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
511 uint8_t ttl)
512{
513 pkt->ipv4_ttl = ttl;
514}
515
516static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
517{
518 return pkt->ipv4_opts_len;
519}
520
521static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
522 uint8_t opts_len)
523{
524 pkt->ipv4_opts_len = opts_len;
525}
526#else
527static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
528{
529 ARG_UNUSED(pkt);
530
531 return 0;
532}
533
534static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
535 uint8_t ttl)
536{
537 ARG_UNUSED(pkt);
538 ARG_UNUSED(ttl);
539}
540
541static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
542{
543 ARG_UNUSED(pkt);
544 return 0;
545}
546
547static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
548 uint8_t opts_len)
549{
550 ARG_UNUSED(pkt);
551 ARG_UNUSED(opts_len);
552}
553#endif
554
555#if defined(CONFIG_NET_IPV6)
556static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
557{
558 return pkt->ipv6_ext_opt_len;
559}
560
561static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
562 uint8_t len)
563{
564 pkt->ipv6_ext_opt_len = len;
565}
566
567static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
568{
569 return pkt->ipv6_next_hdr;
570}
571
572static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
573 uint8_t next_hdr)
574{
575 pkt->ipv6_next_hdr = next_hdr;
576}
577
578static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
579{
580 return pkt->ipv6_ext_len;
581}
582
583static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
584{
585 pkt->ipv6_ext_len = len;
586}
587
588static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
589{
590 return pkt->ipv6_prev_hdr_start;
591}
592
593static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
594 uint16_t offset)
595{
596 pkt->ipv6_prev_hdr_start = offset;
597}
598
599static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
600{
601 return pkt->ipv6_hop_limit;
602}
603
604static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
605 uint8_t hop_limit)
606{
607 pkt->ipv6_hop_limit = hop_limit;
608}
609#else /* CONFIG_NET_IPV6 */
610static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
611{
612 ARG_UNUSED(pkt);
613
614 return 0;
615}
616
617static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
618 uint8_t len)
619{
620 ARG_UNUSED(pkt);
621 ARG_UNUSED(len);
622}
623
624static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
625{
626 ARG_UNUSED(pkt);
627
628 return 0;
629}
630
631static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
632 uint8_t next_hdr)
633{
634 ARG_UNUSED(pkt);
635 ARG_UNUSED(next_hdr);
636}
637
638static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
639{
640 ARG_UNUSED(pkt);
641
642 return 0;
643}
644
645static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
646{
647 ARG_UNUSED(pkt);
648 ARG_UNUSED(len);
649}
650
651static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
652{
653 ARG_UNUSED(pkt);
654
655 return 0;
656}
657
658static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
659 uint16_t offset)
660{
661 ARG_UNUSED(pkt);
662 ARG_UNUSED(offset);
663}
664
665static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
666{
667 ARG_UNUSED(pkt);
668
669 return 0;
670}
671
672static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
673 uint8_t hop_limit)
674{
675 ARG_UNUSED(pkt);
676 ARG_UNUSED(hop_limit);
677}
678#endif /* CONFIG_NET_IPV6 */
679
680static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
681{
682#if defined(CONFIG_NET_IPV6)
683 return pkt->ipv6_ext_len;
684#elif defined(CONFIG_NET_IPV4)
685 return pkt->ipv4_opts_len;
686#else
687 ARG_UNUSED(pkt);
688
689 return 0;
690#endif
691}
692
693#if defined(CONFIG_NET_IPV4_FRAGMENT)
694static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
695{
696 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
697}
698
699static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
700{
701 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
702}
703
704static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
705{
706 pkt->ipv4_fragment.flags = flags;
707}
708
709static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
710{
711 return pkt->ipv4_fragment.id;
712}
713
714static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
715{
716 pkt->ipv4_fragment.id = id;
717}
718#else /* CONFIG_NET_IPV4_FRAGMENT */
719static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
720{
721 ARG_UNUSED(pkt);
722
723 return 0;
724}
725
726static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
727{
728 ARG_UNUSED(pkt);
729
730 return 0;
731}
732
733static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
734{
735 ARG_UNUSED(pkt);
736 ARG_UNUSED(flags);
737}
738
739static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
740{
741 ARG_UNUSED(pkt);
742
743 return 0;
744}
745
746static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
747{
748 ARG_UNUSED(pkt);
749 ARG_UNUSED(id);
750}
751#endif /* CONFIG_NET_IPV4_FRAGMENT */
752
753#if defined(CONFIG_NET_IPV6_FRAGMENT)
754static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
755{
756 return pkt->ipv6_fragment.hdr_start;
757}
758
759static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
760 uint16_t start)
761{
762 pkt->ipv6_fragment.hdr_start = start;
763}
764
765static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
766{
767 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
768}
769static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
770{
771 return (pkt->ipv6_fragment.flags & 0x01) != 0;
772}
773
774static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
776{
777 pkt->ipv6_fragment.flags = flags;
778}
779
780static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
781{
782 return pkt->ipv6_fragment.id;
783}
784
785static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
786 uint32_t id)
787{
788 pkt->ipv6_fragment.id = id;
789}
790#else /* CONFIG_NET_IPV6_FRAGMENT */
791static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
792{
793 ARG_UNUSED(pkt);
794
795 return 0;
796}
797
798static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
799 uint16_t start)
800{
801 ARG_UNUSED(pkt);
802 ARG_UNUSED(start);
803}
804
805static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
806{
807 ARG_UNUSED(pkt);
808
809 return 0;
810}
811
812static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
813{
814 ARG_UNUSED(pkt);
815
816 return 0;
817}
818
819static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
821{
822 ARG_UNUSED(pkt);
823 ARG_UNUSED(flags);
824}
825
826static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
827{
828 ARG_UNUSED(pkt);
829
830 return 0;
831}
832
833static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
834 uint32_t id)
835{
836 ARG_UNUSED(pkt);
837 ARG_UNUSED(id);
838}
839#endif /* CONFIG_NET_IPV6_FRAGMENT */
840
841#if defined(CONFIG_NET_IP_FRAGMENT)
842static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
843{
844 return !!(pkt->ip_reassembled);
845}
846
847static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
848 bool reassembled)
849{
850 pkt->ip_reassembled = reassembled;
851}
852#else /* CONFIG_NET_IP_FRAGMENT */
853static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
854{
855 ARG_UNUSED(pkt);
856
857 return false;
858}
859
860static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
861 bool reassembled)
862{
863 ARG_UNUSED(pkt);
864 ARG_UNUSED(reassembled);
865}
866#endif /* CONFIG_NET_IP_FRAGMENT */
867
868static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
869{
870 return pkt->priority;
871}
872
873static inline void net_pkt_set_priority(struct net_pkt *pkt,
874 uint8_t priority)
875{
876 pkt->priority = priority;
877}
878
879#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
880static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
881{
882 return pkt->cooked_mode_pkt;
883}
884
885static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
886{
887 pkt->cooked_mode_pkt = value;
888}
889#else
890static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
891{
892 ARG_UNUSED(pkt);
893
894 return false;
895}
896
897static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
898{
899 ARG_UNUSED(pkt);
900 ARG_UNUSED(value);
901}
902#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
903
904#if defined(CONFIG_NET_VLAN)
905static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
906{
907 return net_eth_vlan_get_vid(pkt->vlan_tci);
908}
909
910static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
911{
912 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
913}
914
915static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
916{
917 return net_eth_vlan_get_pcp(pkt->vlan_tci);
918}
919
920static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
921 uint8_t priority)
922{
923 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
924}
925
926static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
927{
928 return net_eth_vlan_get_dei(pkt->vlan_tci);
929}
930
931static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
932{
933 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
934}
935
936static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
937{
938 pkt->vlan_tci = tci;
939}
940
941static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
942{
943 return pkt->vlan_tci;
944}
945#else
946static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
947{
948 return NET_VLAN_TAG_UNSPEC;
949}
950
951static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
952{
953 ARG_UNUSED(pkt);
954 ARG_UNUSED(tag);
955}
956
957static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
958{
959 ARG_UNUSED(pkt);
960 return 0;
961}
962
963static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
964{
965 return false;
966}
967
968static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
969{
970 ARG_UNUSED(pkt);
971 ARG_UNUSED(dei);
972}
973
974static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
975{
976 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
977}
978
979static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
980{
981 ARG_UNUSED(pkt);
982 ARG_UNUSED(tci);
983}
984#endif
985
986#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
987static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
988{
989 return &pkt->timestamp;
990}
991
992static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
993 struct net_ptp_time *timestamp)
994{
995 pkt->timestamp.second = timestamp->second;
996 pkt->timestamp.nanosecond = timestamp->nanosecond;
997}
998
999static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1000{
1001 return net_ptp_time_to_ns(&pkt->timestamp);
1002}
1003
1004static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1005{
1006 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1007}
1008#else
1009static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1010{
1011 ARG_UNUSED(pkt);
1012
1013 return NULL;
1014}
1015
1016static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1017 struct net_ptp_time *timestamp)
1018{
1019 ARG_UNUSED(pkt);
1020 ARG_UNUSED(timestamp);
1021}
1022
1023static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1024{
1025 ARG_UNUSED(pkt);
1026
1027 return 0;
1028}
1029
1030static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1031{
1032 ARG_UNUSED(pkt);
1033 ARG_UNUSED(timestamp);
1034}
1035#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1036
1037#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
1038static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1039{
1040 return pkt->create_time;
1041}
1042
1043static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1044 uint32_t create_time)
1045{
1046 pkt->create_time = create_time;
1047}
1048#else
1049static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1050{
1051 ARG_UNUSED(pkt);
1052
1053 return 0U;
1054}
1055
1056static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1057 uint32_t create_time)
1058{
1059 ARG_UNUSED(pkt);
1060 ARG_UNUSED(create_time);
1061}
1062#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
1063
1067static inline uint64_t net_pkt_txtime(struct net_pkt *pkt)
1068{
1069#if defined(CONFIG_NET_PKT_TXTIME)
1070 return pkt->timestamp.second * NSEC_PER_SEC + pkt->timestamp.nanosecond;
1071#else
1072 ARG_UNUSED(pkt);
1073
1074 return 0;
1075#endif /* CONFIG_NET_PKT_TXTIME */
1076}
1077
1082static inline void net_pkt_set_txtime(struct net_pkt *pkt, uint64_t txtime)
1083{
1084#if defined(CONFIG_NET_PKT_TXTIME)
1085 pkt->timestamp.second = txtime / NSEC_PER_SEC;
1086 pkt->timestamp.nanosecond = txtime % NSEC_PER_SEC;
1087#else
1088 ARG_UNUSED(pkt);
1089 ARG_UNUSED(txtime);
1090#endif /* CONFIG_NET_PKT_TXTIME */
1091}
1092
1093#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1094 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1095static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1096{
1097 return pkt->detail.stat;
1098}
1099
1100static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1101{
1102 return pkt->detail.count;
1103}
1104
1105static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1106{
1107 memset(&pkt->detail, 0, sizeof(pkt->detail));
1108}
1109
1110static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1111 uint32_t tick)
1112{
1113 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1114 NET_ERR("Detail stats count overflow (%d >= %d)",
1115 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1116 return;
1117 }
1118
1119 pkt->detail.stat[pkt->detail.count++] = tick;
1120}
1121
1122#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1123#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1124#else
1125static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1126{
1127 ARG_UNUSED(pkt);
1128
1129 return NULL;
1130}
1131
1132static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1133{
1134 ARG_UNUSED(pkt);
1135
1136 return 0;
1137}
1138
1139static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1140{
1141 ARG_UNUSED(pkt);
1142}
1143
1144static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1145{
1146 ARG_UNUSED(pkt);
1147 ARG_UNUSED(tick);
1148}
1149
1150#define net_pkt_set_tx_stats_tick(pkt, tick)
1151#define net_pkt_set_rx_stats_tick(pkt, tick)
1152#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1153 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1154
1155static inline size_t net_pkt_get_len(struct net_pkt *pkt)
1156{
1157 return net_buf_frags_len(pkt->frags);
1158}
1159
1160static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1161{
1162 return pkt->frags->data;
1163}
1164
1165static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1166{
1167 return pkt->frags->data;
1168}
1169
1170static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1171{
1172 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1173}
1174
1175static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1176{
1177 return &pkt->lladdr_src;
1178}
1179
1180static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1181{
1182 return &pkt->lladdr_dst;
1183}
1184
1185static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1186{
1187 uint8_t *addr = net_pkt_lladdr_src(pkt)->addr;
1188
1189 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
1190 net_pkt_lladdr_dst(pkt)->addr = addr;
1191}
1192
1193static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1194{
1195 net_pkt_lladdr_src(pkt)->addr = NULL;
1196 net_pkt_lladdr_src(pkt)->len = 0U;
1197}
1198
1199static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1200{
1201 return pkt->ll_proto_type;
1202}
1203
1204static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1205{
1206 pkt->ll_proto_type = type;
1207}
1208
1209#if defined(CONFIG_NET_IPV4_AUTO)
1210static inline bool net_pkt_ipv4_auto(struct net_pkt *pkt)
1211{
1212 return !!(pkt->ipv4_auto_arp_msg);
1213}
1214
1215static inline void net_pkt_set_ipv4_auto(struct net_pkt *pkt,
1216 bool is_auto_arp_msg)
1217{
1218 pkt->ipv4_auto_arp_msg = is_auto_arp_msg;
1219}
1220#else /* CONFIG_NET_IPV4_AUTO */
1221static inline bool net_pkt_ipv4_auto(struct net_pkt *pkt)
1222{
1223 ARG_UNUSED(pkt);
1224
1225 return false;
1226}
1227
1228static inline void net_pkt_set_ipv4_auto(struct net_pkt *pkt,
1229 bool is_auto_arp_msg)
1230{
1231 ARG_UNUSED(pkt);
1232 ARG_UNUSED(is_auto_arp_msg);
1233}
1234#endif /* CONFIG_NET_IPV4_AUTO */
1235
1236#if defined(CONFIG_NET_LLDP)
1237static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1238{
1239 return !!(pkt->lldp_pkt);
1240}
1241
1242static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1243{
1244 pkt->lldp_pkt = is_lldp;
1245}
1246#else
1247static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1248{
1249 ARG_UNUSED(pkt);
1250
1251 return false;
1252}
1253
1254static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1255{
1256 ARG_UNUSED(pkt);
1257 ARG_UNUSED(is_lldp);
1258}
1259#endif /* CONFIG_NET_LLDP */
1260
1261#if defined(CONFIG_NET_L2_PPP)
1262static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1263{
1264 return !!(pkt->ppp_msg);
1265}
1266
1267static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1268 bool is_ppp_msg)
1269{
1270 pkt->ppp_msg = is_ppp_msg;
1271}
1272#else /* CONFIG_NET_L2_PPP */
1273static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1274{
1275 ARG_UNUSED(pkt);
1276
1277 return false;
1278}
1279
1280static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1281 bool is_ppp_msg)
1282{
1283 ARG_UNUSED(pkt);
1284 ARG_UNUSED(is_ppp_msg);
1285}
1286#endif /* CONFIG_NET_L2_PPP */
1287
1288#if defined(NET_PKT_HAS_CONTROL_BLOCK)
1289static inline void *net_pkt_cb(struct net_pkt *pkt)
1290{
1291 return &pkt->cb;
1292}
1293#else
1294static inline void *net_pkt_cb(struct net_pkt *pkt)
1295{
1296 ARG_UNUSED(pkt);
1297
1298 return NULL;
1299}
1300#endif
1301
1302#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1303#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1304
1305static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1306{
1308 net_pkt_context(pkt)),
1309 (struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1310}
1311
1312static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1313{
1314 pkt->overwrite = overwrite;
1315}
1316
1317static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1318{
1319 return !!(pkt->overwrite);
1320}
1321
1322#ifdef CONFIG_NET_PKT_FILTER
1323
1324bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1325bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1326
1327#else
1328
1329static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1330{
1331 ARG_UNUSED(pkt);
1332
1333 return true;
1334}
1335
1336static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1337{
1338 ARG_UNUSED(pkt);
1339
1340 return true;
1341}
1342
1343#endif /* CONFIG_NET_PKT_FILTER */
1344
1345#if defined(CONFIG_NET_PKT_FILTER) && \
1346 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1347
1348bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1349
1350#else
1351
1352static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1353{
1354 ARG_UNUSED(pkt);
1355
1356 return true;
1357}
1358
1359#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1360
1361#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1362
1363bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1364
1365#else
1366
1367static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1368{
1369 ARG_UNUSED(pkt);
1370
1371 return true;
1372}
1373
1374#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1375
1376#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1377static inline struct sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1378{
1379 return &pkt->remote;
1380}
1381
1382static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1383 struct sockaddr *address,
1384 socklen_t len)
1385{
1386 memcpy(&pkt->remote, address, len);
1387}
1388#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1389
1390/* @endcond */
1391
1405#define NET_PKT_SLAB_DEFINE(name, count) \
1406 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4)
1407
1410/* Backward compatibility macro */
1411#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1412
1428#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1429 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1430 0, NULL)
1431
1434#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1435 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1436#define NET_PKT_DEBUG_ENABLED
1437#endif
1438
1439#if defined(NET_PKT_DEBUG_ENABLED)
1440
1441/* Debug versions of the net_pkt functions that are used when tracking
1442 * buffer usage.
1443 */
1444
1445struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1446 size_t min_len,
1447 k_timeout_t timeout,
1448 const char *caller,
1449 int line);
1450
1451#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1452 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1453
1454struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1455 k_timeout_t timeout,
1456 const char *caller,
1457 int line);
1458#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1459 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1460
1461struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1462 k_timeout_t timeout,
1463 const char *caller,
1464 int line);
1465#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1466 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1467
1468struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1469 k_timeout_t timeout,
1470 const char *caller, int line);
1471#define net_pkt_get_frag(pkt, min_len, timeout) \
1472 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1473
1474void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1475#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1476
1477struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1478 int line);
1479#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1480
1481struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1482 const char *caller, int line);
1483#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1484
1485void net_pkt_frag_unref_debug(struct net_buf *frag,
1486 const char *caller, int line);
1487#define net_pkt_frag_unref(frag) \
1488 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1489
1490struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1491 struct net_buf *parent,
1492 struct net_buf *frag,
1493 const char *caller, int line);
1494#define net_pkt_frag_del(pkt, parent, frag) \
1495 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1496
1497void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1498 const char *caller, int line);
1499#define net_pkt_frag_add(pkt, frag) \
1500 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1501
1502void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1503 const char *caller, int line);
1504#define net_pkt_frag_insert(pkt, frag) \
1505 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1506#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1507 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1508 */
1518#if defined(NET_PKT_DEBUG_ENABLED)
1519void net_pkt_print_frags(struct net_pkt *pkt);
1520#else
1521#define net_pkt_print_frags(pkt)
1522#endif
1523
1538#if !defined(NET_PKT_DEBUG_ENABLED)
1540 size_t min_len, k_timeout_t timeout);
1541#endif
1542
1557#if !defined(NET_PKT_DEBUG_ENABLED)
1558struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1559#endif
1560
1575#if !defined(NET_PKT_DEBUG_ENABLED)
1576struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1577#endif
1578
1591#if !defined(NET_PKT_DEBUG_ENABLED)
1592struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1593 k_timeout_t timeout);
1594#endif
1595
1605#if !defined(NET_PKT_DEBUG_ENABLED)
1606void net_pkt_unref(struct net_pkt *pkt);
1607#endif
1608
1618#if !defined(NET_PKT_DEBUG_ENABLED)
1619struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1620#endif
1621
1631#if !defined(NET_PKT_DEBUG_ENABLED)
1632struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1633#endif
1634
1640#if !defined(NET_PKT_DEBUG_ENABLED)
1641void net_pkt_frag_unref(struct net_buf *frag);
1642#endif
1643
1654#if !defined(NET_PKT_DEBUG_ENABLED)
1656 struct net_buf *parent,
1657 struct net_buf *frag);
1658#endif
1659
1666#if !defined(NET_PKT_DEBUG_ENABLED)
1667void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1668#endif
1669
1676#if !defined(NET_PKT_DEBUG_ENABLED)
1677void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1678#endif
1679
1686void net_pkt_compact(struct net_pkt *pkt);
1687
1696void net_pkt_get_info(struct k_mem_slab **rx,
1697 struct k_mem_slab **tx,
1698 struct net_buf_pool **rx_data,
1699 struct net_buf_pool **tx_data);
1700
1703#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1707void net_pkt_print(void);
1708
1709typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1710 struct net_buf *buf,
1711 const char *func_alloc,
1712 int line_alloc,
1713 const char *func_free,
1714 int line_free,
1715 bool in_use,
1716 void *user_data);
1717
1718void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1719
1720const char *net_pkt_slab2str(struct k_mem_slab *slab);
1721const char *net_pkt_pool2str(struct net_buf_pool *pool);
1722
1723#else
1724#define net_pkt_print(...)
1725#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1726
1727/* New allocator, and API are defined below.
1728 * This will be simpler when time will come to get rid of former API above.
1729 */
1730#if defined(NET_PKT_DEBUG_ENABLED)
1731
1732struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1733 const char *caller, int line);
1734#define net_pkt_alloc(_timeout) \
1735 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1736
1737struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1738 k_timeout_t timeout,
1739 const char *caller, int line);
1740#define net_pkt_alloc_from_slab(_slab, _timeout) \
1741 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1742
1743struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1744 const char *caller, int line);
1745#define net_pkt_rx_alloc(_timeout) \
1746 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1747
1748struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1749 k_timeout_t timeout,
1750 const char *caller,
1751 int line);
1752#define net_pkt_alloc_on_iface(_iface, _timeout) \
1753 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1754
1755struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1756 k_timeout_t timeout,
1757 const char *caller,
1758 int line);
1759#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1760 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1761 __func__, __LINE__)
1762
1763int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1764 size_t size,
1765 enum net_ip_protocol proto,
1766 k_timeout_t timeout,
1767 const char *caller, int line);
1768#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1769 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1770 __func__, __LINE__)
1771
1772int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1773 k_timeout_t timeout,
1774 const char *caller, int line);
1775#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1776 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1777 __func__, __LINE__)
1778
1779struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1780 size_t size,
1781 sa_family_t family,
1782 enum net_ip_protocol proto,
1783 k_timeout_t timeout,
1784 const char *caller,
1785 int line);
1786#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1787 _proto, _timeout) \
1788 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1789 _proto, _timeout, \
1790 __func__, __LINE__)
1791
1792struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1793 size_t size,
1794 sa_family_t family,
1795 enum net_ip_protocol proto,
1796 k_timeout_t timeout,
1797 const char *caller,
1798 int line);
1799#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1800 _proto, _timeout) \
1801 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1802 _proto, _timeout, \
1803 __func__, __LINE__)
1804#endif /* NET_PKT_DEBUG_ENABLED */
1817#if !defined(NET_PKT_DEBUG_ENABLED)
1819#endif
1820
1835#if !defined(NET_PKT_DEBUG_ENABLED)
1836struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
1837 k_timeout_t timeout);
1838#endif
1839
1850#if !defined(NET_PKT_DEBUG_ENABLED)
1852#endif
1853
1862#if !defined(NET_PKT_DEBUG_ENABLED)
1864 k_timeout_t timeout);
1865
1868/* Same as above but specifically for RX packet */
1869struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
1870 k_timeout_t timeout);
1873#endif
1874
1890#if !defined(NET_PKT_DEBUG_ENABLED)
1892 size_t size,
1893 enum net_ip_protocol proto,
1894 k_timeout_t timeout);
1895#endif
1896
1910#if !defined(NET_PKT_DEBUG_ENABLED)
1911int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
1912 k_timeout_t timeout);
1913#endif
1914
1926#if !defined(NET_PKT_DEBUG_ENABLED)
1928 size_t size,
1929 sa_family_t family,
1930 enum net_ip_protocol proto,
1931 k_timeout_t timeout);
1932
1935/* Same as above but specifically for RX packet */
1936struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
1937 size_t size,
1938 sa_family_t family,
1939 enum net_ip_protocol proto,
1940 k_timeout_t timeout);
1941
1944#endif
1945
1952void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
1953
1965
1982 enum net_ip_protocol proto);
1983
1993
2008int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2009
2018
2025static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2026 struct net_pkt_cursor *backup)
2027{
2028 backup->buf = pkt->cursor.buf;
2029 backup->pos = pkt->cursor.pos;
2030}
2031
2038static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2039 struct net_pkt_cursor *backup)
2040{
2041 pkt->cursor.buf = backup->buf;
2042 pkt->cursor.pos = backup->pos;
2043}
2044
2052static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2053{
2054 return pkt->cursor.pos;
2055}
2056
2077int net_pkt_skip(struct net_pkt *pkt, size_t length);
2078
2093int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2094
2108int net_pkt_copy(struct net_pkt *pkt_dst,
2109 struct net_pkt *pkt_src,
2110 size_t length);
2111
2121struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2122
2132struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2133
2143 k_timeout_t timeout);
2144
2158int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2159
2172static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2173{
2174 return net_pkt_read(pkt, data, 1);
2175}
2176
2189int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2190
2203int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2204
2217int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2218
2232int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2233
2246static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2247{
2248 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2249}
2250
2263static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2264{
2265 uint16_t data_be16 = htons(data);
2266
2267 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2268}
2269
2282static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2283{
2284 uint32_t data_be32 = htonl(data);
2285
2286 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2287}
2288
2301static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2302{
2303 uint32_t data_le32 = sys_cpu_to_le32(data);
2304
2305 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2306}
2307
2320static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2321{
2322 uint16_t data_le16 = sys_cpu_to_le16(data);
2323
2324 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2325}
2326
2335
2348int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2349
2362int net_pkt_pull(struct net_pkt *pkt, size_t length);
2363
2373
2385bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2386
2396
2399struct net_pkt_data_access {
2400#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2401 void *data;
2402#endif
2403 const size_t size;
2404};
2405
2406#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2407#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2408 struct net_pkt_data_access _name = { \
2409 .size = sizeof(_type), \
2410 }
2411
2412#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2413 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2414
2415#else
2416#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2417 _type _hdr_##_name; \
2418 struct net_pkt_data_access _name = { \
2419 .data = &_hdr_##_name, \
2420 .size = sizeof(_type), \
2421 }
2422
2423#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2424 struct net_pkt_data_access _name = { \
2425 .data = NULL, \
2426 .size = sizeof(_type), \
2427 }
2428
2429#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2430
2446void *net_pkt_get_data(struct net_pkt *pkt,
2447 struct net_pkt_data_access *access);
2448
2463 struct net_pkt_data_access *access);
2464
2469static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2470 struct net_pkt_data_access *access)
2471{
2472 return net_pkt_skip(pkt, access->size);
2473}
2474
2479#ifdef __cplusplus
2480}
2481#endif
2482
2483#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:705
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition: net_if.h:1072
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:2003
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:2282
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:1521
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:2263
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:2246
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:2052
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:2025
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:2469
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:2320
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:2038
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:2301
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:2172
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:675
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