Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_pkt.h
Go to the documentation of this file.
1
10
11/*
12 * Copyright (c) 2016 Intel Corporation
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 */
16
17/* Data buffer API - used for all data to/from net */
18
19#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
20#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
21
22#include <zephyr/types.h>
23#include <stdbool.h>
24
25#include <zephyr/net_buf.h>
26
27#if defined(CONFIG_IEEE802154)
29#endif
30#include <zephyr/net/net_core.h>
32#include <zephyr/net/net_ip.h>
33#include <zephyr/net/net_if.h>
35#include <zephyr/net/net_time.h>
37#include <zephyr/net/ptp_time.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
52
53struct net_context;
54
75#define NET_PKT_FRAG_FOR_EACH(_pkt, _var) \
76 for (struct net_buf *_var = (_pkt)->frags; _var != NULL; \
77 _var = _var->frags)
78
80
81#if defined(CONFIG_NET_PKT_ALLOC_STATS)
82struct net_pkt_alloc_stats {
83 uint64_t alloc_sum;
84 uint64_t time_sum;
85 uint32_t count;
86};
87
88struct net_pkt_alloc_stats_slab {
89 struct net_pkt_alloc_stats ok;
90 struct net_pkt_alloc_stats fail;
91 struct k_mem_slab *slab;
92};
93
94#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
95 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
96 .slab = &slab_name, \
97 }
98
99#else
100#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
101#endif /* CONFIG_NET_PKT_ALLOC_STATS */
102
103/* buffer cursor used in net_pkt */
104struct net_pkt_cursor {
106 struct net_buf *buf;
108 uint8_t *pos;
109};
110
112
119struct net_pkt {
125
127 struct k_mem_slab *slab;
128
130 union {
131 struct net_buf *frags;
132 struct net_buf *buffer;
133 };
134
136 struct net_pkt_cursor cursor;
137
140
142 struct net_if *iface;
143
145
146#if defined(CONFIG_NET_TCP)
148 sys_snode_t next;
149#endif
150#if defined(CONFIG_NET_PKT_ORIG_IFACE)
151 struct net_if *orig_iface; /* Original network interface */
152#endif
153
154#if defined(CONFIG_NET_VPN)
155 struct {
157 struct net_if *iface;
159 union net_ip_header ip_hdr;
161 union net_proto_header proto_hdr;
163 int peer_id;
164 } vpn;
165#endif
166
167#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
186 struct net_ptp_time timestamp;
187#endif
188
189#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
190 defined(CONFIG_TRACING_NET_CORE)
191 struct {
193 uint32_t create_time;
194
195#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
196 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
202 struct {
203 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
204 int count;
205 } detail;
206#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
207 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
208 };
209#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
210
211#if defined(CONFIG_NET_PKT_ALLOC_STATS)
212 struct net_pkt_alloc_stats_slab *alloc_stats;
213#endif /* CONFIG_NET_PKT_ALLOC_STATS */
214
216 atomic_t atomic_ref;
217
218 /* Filled by layer 2 when network packet is received. */
219 struct net_linkaddr lladdr_src;
220 struct net_linkaddr lladdr_dst;
221 uint16_t ll_proto_type;
222
223#if defined(CONFIG_NET_IP)
224 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
225#endif
226
227 uint8_t overwrite : 1; /* Is packet content being overwritten? */
228 uint8_t eof : 1; /* Last packet before EOF */
229 uint8_t ptp_pkt : 1; /* For outgoing packet: is this packet
230 * a L2 PTP packet.
231 * Used only if defined (CONFIG_NET_L2_PTP)
232 */
233 uint8_t forwarding : 1; /* Are we forwarding this pkt
234 * Used only if defined(CONFIG_NET_IPV6_ROUTE)
235 */
236 uint8_t family : 3; /* Address family, see net_ip.h */
237
238 /* bitfield byte alignment boundary */
239
240#if defined(CONFIG_NET_IPV4_ACD)
241 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
242 * message.
243 * Note: family needs to be
244 * NET_AF_INET.
245 */
246#endif
247#if defined(CONFIG_NET_LLDP)
248 uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
249 * Note: family needs to be
250 * NET_AF_UNSPEC.
251 */
252#endif
253 uint8_t ppp_msg : 1; /* This is a PPP message */
254 uint8_t captured : 1; /* Set to 1 if this packet is already being
255 * captured
256 */
257 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
258 * and already contains its L2 header to be
259 * preserved. Useful only if
260 * defined(CONFIG_NET_ETHERNET_BRIDGE).
261 */
262 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
263 * processed by the L2
264 */
265 uint8_t chksum_done : 1; /* Checksum has already been computed for
266 * the packet.
267 */
268 uint8_t loopback : 1; /* Packet is a loop back packet. */
269#if defined(CONFIG_NET_IP_FRAGMENT)
270 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
271#endif
272#if defined(CONFIG_NET_PKT_TIMESTAMP)
273 uint8_t tx_timestamping : 1;
274 uint8_t rx_timestamping : 1;
275#endif
276 /* bitfield byte alignment boundary */
277
278#if defined(CONFIG_NET_IP)
279 union {
280 /* IPv6 hop limit or IPv4 ttl for this network packet.
281 * The value is shared between IPv6 and IPv4.
282 */
283#if defined(CONFIG_NET_IPV6)
284 uint8_t ipv6_hop_limit;
285#endif
286#if defined(CONFIG_NET_IPV4)
287 uint8_t ipv4_ttl;
288#endif
289 };
290
291 union {
292#if defined(CONFIG_NET_IPV4)
293 uint8_t ipv4_opts_len; /* length of IPv4 header options */
294#endif
295#if defined(CONFIG_NET_IPV6)
296 uint16_t ipv6_ext_len; /* length of extension headers */
297#endif
298 };
299
300#if defined(CONFIG_NET_IPV4_ROUTE)
301 /* IPv4 address that should be resolved at L2 for transmission.
302 * Routed packets use this to steer link-layer resolution towards the
303 * next on-link IPv4 address.
304 */
305 struct net_in_addr ipv4_ll_resolve_addr;
306#endif /* CONFIG_NET_IPV4_ROUTE */
307
308#if defined(CONFIG_NET_IP_FRAGMENT)
309 union {
310#if defined(CONFIG_NET_IPV4_FRAGMENT)
311 struct {
312 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
313 uint16_t id; /* Fragment ID */
314 } ipv4_fragment;
315#endif /* CONFIG_NET_IPV4_FRAGMENT */
316#if defined(CONFIG_NET_IPV6_FRAGMENT)
317 struct {
318 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
319 uint32_t id; /* Fragment id */
320 uint16_t hdr_start; /* Where starts the fragment header */
321 } ipv6_fragment;
322#endif /* CONFIG_NET_IPV6_FRAGMENT */
323 };
324#endif /* CONFIG_NET_IP_FRAGMENT */
325
326#if defined(CONFIG_NET_IPV6)
327 /* Where is the start of the last header before payload data
328 * in IPv6 packet. This is offset value from start of the IPv6
329 * packet. Note that this value should be updated by who ever
330 * adds IPv6 extension headers to the network packet.
331 */
332 uint16_t ipv6_prev_hdr_start;
333
334 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
335 uint8_t ipv6_next_hdr; /* What is the very first next header */
336#endif /* CONFIG_NET_IPV6 */
337
338#if defined(CONFIG_NET_IP_DSCP_ECN)
340 uint8_t ip_dscp : 6;
341
343 uint8_t ip_ecn : 2;
344#endif /* CONFIG_NET_IP_DSCP_ECN */
345#endif /* CONFIG_NET_IP */
346
347#if defined(CONFIG_NET_VLAN)
348 /* VLAN TCI (Tag Control Information). This contains the Priority
349 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
350 * Identifier (VID, called more commonly VLAN tag). This value is
351 * kept in host byte order.
352 */
353 uint16_t vlan_tci;
354#endif /* CONFIG_NET_VLAN */
355
356#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
357 /* Control block which could be used by any layer */
358 union {
359 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
360#if defined(CONFIG_IEEE802154)
361 /* The following structure requires a 4-byte alignment
362 * boundary to avoid padding.
363 */
364 struct net_pkt_cb_ieee802154 cb_ieee802154;
365#endif /* CONFIG_IEEE802154 */
366 } cb;
367#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
368
372 uint8_t priority;
373
374#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
375 /* Remote address of the received packet. This is only used by
376 * network interfaces with an offloaded TCP/IP stack, or if we
377 * have network tunneling in use.
378 */
379 union {
380 struct net_sockaddr remote;
381
382 /* This will make sure that there is enough storage to store
383 * the address struct. The access to value is via remote
384 * address.
385 */
386 struct net_sockaddr_storage remote_storage;
387 };
388#endif /* CONFIG_NET_OFFLOAD */
389
390#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
391 /* Tell the capture api that this is a captured packet */
392 uint8_t cooked_mode_pkt : 1;
393#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
394
395#if defined(CONFIG_NET_IPV4_PMTU)
396 /* Path MTU needed for this destination address */
397 uint8_t ipv4_pmtu : 1;
398#endif /* CONFIG_NET_IPV4_PMTU */
399#if defined(CONFIG_NET_IPV4_ROUTE)
400 uint8_t ipv4_ll_resolve_addr_set : 1;
401#endif /* CONFIG_NET_IPV4_ROUTE */
402
403 /* @endcond */
404};
405
407
408/* The interface real ll address */
409static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
410{
411 return net_if_get_link_addr(pkt->iface);
412}
413
414static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
415{
416 return pkt->context;
417}
418
419static inline void net_pkt_set_context(struct net_pkt *pkt,
420 struct net_context *ctx)
421{
422 pkt->context = ctx;
423}
424
425static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
426{
427 return pkt->iface;
428}
429
430static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
431{
432 pkt->iface = iface;
433
434 /* If the network interface is set in pkt, then also set the type of
435 * the network address that is stored in pkt. This is done here so
436 * that the address type is properly set and is not forgotten.
437 */
438 if (iface) {
439 uint8_t type = net_if_get_link_addr(iface)->type;
440
441 pkt->lladdr_src.type = type;
442 pkt->lladdr_dst.type = type;
443 }
444}
445
446static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
447{
448#if defined(CONFIG_NET_PKT_ORIG_IFACE)
449 return pkt->orig_iface;
450#else
451 return pkt->iface;
452#endif
453}
454
455static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
456 struct net_if *iface)
457{
458#if defined(CONFIG_NET_PKT_ORIG_IFACE)
459 pkt->orig_iface = iface;
460#else
461 ARG_UNUSED(pkt);
462 ARG_UNUSED(iface);
463#endif
464}
465
466#if defined(CONFIG_NET_VPN)
467static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
468{
469 return pkt->vpn.iface;
470}
471
472static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
473 struct net_if *iface)
474{
475 pkt->vpn.iface = iface;
476}
477
478static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
479{
480 return &pkt->vpn.ip_hdr;
481}
482
483static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
484 union net_ip_header *ip_hdr)
485{
486 pkt->vpn.ip_hdr = *ip_hdr;
487}
488
489static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
490{
491 return &pkt->vpn.proto_hdr;
492}
493
494static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
495 union net_proto_header *proto_hdr)
496{
497 pkt->vpn.proto_hdr = *proto_hdr;
498}
499
500static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
501{
502 return pkt->vpn.peer_id;
503}
504
505static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
506 int peer_id)
507{
508 pkt->vpn.peer_id = peer_id;
509}
510#endif /* CONFIG_NET_VPN */
511
512static inline uint8_t net_pkt_family(struct net_pkt *pkt)
513{
514 return pkt->family;
515}
516
517static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
518{
519 pkt->family = family;
520}
521
522static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
523{
524 return !!(pkt->ptp_pkt);
525}
526
527static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
528{
529 pkt->ptp_pkt = is_ptp;
530}
531
532static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
533{
534#if defined(CONFIG_NET_PKT_TIMESTAMP)
535 return !!(pkt->tx_timestamping);
536#else
537 ARG_UNUSED(pkt);
538
539 return false;
540#endif
541}
542
543static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
544{
545#if defined(CONFIG_NET_PKT_TIMESTAMP)
546 pkt->tx_timestamping = is_timestamping;
547#else
548 ARG_UNUSED(pkt);
549 ARG_UNUSED(is_timestamping);
550#endif
551}
552
553static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
554{
555#if defined(CONFIG_NET_PKT_TIMESTAMP)
556 return !!(pkt->rx_timestamping);
557#else
558 ARG_UNUSED(pkt);
559
560 return false;
561#endif
562}
563
564static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
565{
566#if defined(CONFIG_NET_PKT_TIMESTAMP)
567 pkt->rx_timestamping = is_timestamping;
568#else
569 ARG_UNUSED(pkt);
570 ARG_UNUSED(is_timestamping);
571#endif
572}
573
574static inline bool net_pkt_is_captured(struct net_pkt *pkt)
575{
576 return !!(pkt->captured);
577}
578
579static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
580{
581 pkt->captured = is_captured;
582}
583
584static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
585{
586 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
587}
588
589static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
590{
591 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
592 pkt->l2_bridged = is_l2_bridged;
593 }
594}
595
596static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
597{
598 return !!(pkt->l2_processed);
599}
600
601static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
602 bool is_l2_processed)
603{
604 pkt->l2_processed = is_l2_processed;
605}
606
607static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
608{
609 return !!(pkt->chksum_done);
610}
611
612static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
613 bool is_chksum_done)
614{
615 pkt->chksum_done = is_chksum_done;
616}
617
618static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
619{
620#if defined(CONFIG_NET_IP)
621 return pkt->ip_hdr_len;
622#else
623 ARG_UNUSED(pkt);
624
625 return 0;
626#endif
627}
628
629static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
630{
631#if defined(CONFIG_NET_IP)
632 pkt->ip_hdr_len = len;
633#else
634 ARG_UNUSED(pkt);
635 ARG_UNUSED(len);
636#endif
637}
638
639static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
640{
641#if defined(CONFIG_NET_IP_DSCP_ECN)
642 return pkt->ip_dscp;
643#else
644 ARG_UNUSED(pkt);
645
646 return 0;
647#endif
648}
649
650static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
651{
652#if defined(CONFIG_NET_IP_DSCP_ECN)
653 pkt->ip_dscp = dscp;
654#else
655 ARG_UNUSED(pkt);
656 ARG_UNUSED(dscp);
657#endif
658}
659
660static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
661{
662#if defined(CONFIG_NET_IP_DSCP_ECN)
663 return pkt->ip_ecn;
664#else
665 ARG_UNUSED(pkt);
666
667 return 0;
668#endif
669}
670
671static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
672{
673#if defined(CONFIG_NET_IP_DSCP_ECN)
674 pkt->ip_ecn = ecn;
675#else
676 ARG_UNUSED(pkt);
677 ARG_UNUSED(ecn);
678#endif
679}
680
681static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
682{
683 return pkt->eof;
684}
685
686static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
687{
688 pkt->eof = eof;
689}
690
691static inline bool net_pkt_forwarding(struct net_pkt *pkt)
692{
693 return !!(pkt->forwarding);
694}
695
696static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
697{
698 pkt->forwarding = forward;
699}
700
701#if defined(CONFIG_NET_IPV4)
702static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
703{
704 return pkt->ipv4_ttl;
705}
706
707static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
708 uint8_t ttl)
709{
710 pkt->ipv4_ttl = ttl;
711}
712
713static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
714{
715 return pkt->ipv4_opts_len;
716}
717
718static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
719 uint8_t opts_len)
720{
721 pkt->ipv4_opts_len = opts_len;
722}
723#else
724static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
725{
726 ARG_UNUSED(pkt);
727
728 return 0;
729}
730
731static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
732 uint8_t ttl)
733{
734 ARG_UNUSED(pkt);
735 ARG_UNUSED(ttl);
736}
737
738static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
739{
740 ARG_UNUSED(pkt);
741 return 0;
742}
743
744static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
745 uint8_t opts_len)
746{
747 ARG_UNUSED(pkt);
748 ARG_UNUSED(opts_len);
749}
750#endif
751
752#if defined(CONFIG_NET_IPV6)
753static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
754{
755 return pkt->ipv6_ext_opt_len;
756}
757
758static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
759 uint8_t len)
760{
761 pkt->ipv6_ext_opt_len = len;
762}
763
764static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
765{
766 return pkt->ipv6_next_hdr;
767}
768
769static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
770 uint8_t next_hdr)
771{
772 pkt->ipv6_next_hdr = next_hdr;
773}
774
775static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
776{
777 return pkt->ipv6_ext_len;
778}
779
780static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
781{
782 pkt->ipv6_ext_len = len;
783}
784
785static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
786{
787 return pkt->ipv6_prev_hdr_start;
788}
789
790static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
791 uint16_t offset)
792{
793 pkt->ipv6_prev_hdr_start = offset;
794}
795
796static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
797{
798 return pkt->ipv6_hop_limit;
799}
800
801static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
802 uint8_t hop_limit)
803{
804 pkt->ipv6_hop_limit = hop_limit;
805}
806#else /* CONFIG_NET_IPV6 */
807static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
808{
809 ARG_UNUSED(pkt);
810
811 return 0;
812}
813
814static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
815 uint8_t len)
816{
817 ARG_UNUSED(pkt);
818 ARG_UNUSED(len);
819}
820
821static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
822{
823 ARG_UNUSED(pkt);
824
825 return 0;
826}
827
828static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
829 uint8_t next_hdr)
830{
831 ARG_UNUSED(pkt);
832 ARG_UNUSED(next_hdr);
833}
834
835static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
836{
837 ARG_UNUSED(pkt);
838
839 return 0;
840}
841
842static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
843{
844 ARG_UNUSED(pkt);
845 ARG_UNUSED(len);
846}
847
848static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
849{
850 ARG_UNUSED(pkt);
851
852 return 0;
853}
854
855static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
856 uint16_t offset)
857{
858 ARG_UNUSED(pkt);
859 ARG_UNUSED(offset);
860}
861
862static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
863{
864 ARG_UNUSED(pkt);
865
866 return 0;
867}
868
869static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
870 uint8_t hop_limit)
871{
872 ARG_UNUSED(pkt);
873 ARG_UNUSED(hop_limit);
874}
875#endif /* CONFIG_NET_IPV6 */
876
877static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
878{
879#if defined(CONFIG_NET_IPV6)
880 return pkt->ipv6_ext_len;
881#elif defined(CONFIG_NET_IPV4)
882 return pkt->ipv4_opts_len;
883#else
884 ARG_UNUSED(pkt);
885
886 return 0;
887#endif
888}
889
890#if defined(CONFIG_NET_IPV4_PMTU)
891static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
892{
893 return !!pkt->ipv4_pmtu;
894}
895
896static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
897{
898 pkt->ipv4_pmtu = value;
899}
900#else
901static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
902{
903 ARG_UNUSED(pkt);
904
905 return false;
906}
907
908static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
909{
910 ARG_UNUSED(pkt);
911 ARG_UNUSED(value);
912}
913#endif /* CONFIG_NET_IPV4_PMTU */
914
915#if defined(CONFIG_NET_IPV4_ROUTE)
916static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
917{
918 return pkt->ipv4_ll_resolve_addr_set ? &pkt->ipv4_ll_resolve_addr : NULL;
919}
920
921static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
922 const struct net_in_addr *addr)
923{
924 if (addr != NULL) {
925 net_ipaddr_copy(&pkt->ipv4_ll_resolve_addr, addr);
926 pkt->ipv4_ll_resolve_addr_set = 1U;
927 } else {
928 pkt->ipv4_ll_resolve_addr_set = 0U;
929 }
930}
931#else
932static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
933{
934 ARG_UNUSED(pkt);
935
936 return NULL;
937}
938
939static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
940 const struct net_in_addr *addr)
941{
942 ARG_UNUSED(pkt);
943 ARG_UNUSED(addr);
944}
945#endif /* CONFIG_NET_IPV4_ROUTE */
946
947#if defined(CONFIG_NET_IPV4_FRAGMENT)
948static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
949{
950 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
951}
952
953static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
954{
955 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
956}
957
958static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
959{
960 pkt->ipv4_fragment.flags = flags;
961}
962
963static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
964{
965 return pkt->ipv4_fragment.id;
966}
967
968static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
969{
970 pkt->ipv4_fragment.id = id;
971}
972#else /* CONFIG_NET_IPV4_FRAGMENT */
973static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
974{
975 ARG_UNUSED(pkt);
976
977 return 0;
978}
979
980static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
981{
982 ARG_UNUSED(pkt);
983
984 return 0;
985}
986
987static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
988{
989 ARG_UNUSED(pkt);
990 ARG_UNUSED(flags);
991}
992
993static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
994{
995 ARG_UNUSED(pkt);
996
997 return 0;
998}
999
1000static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
1001{
1002 ARG_UNUSED(pkt);
1003 ARG_UNUSED(id);
1004}
1005#endif /* CONFIG_NET_IPV4_FRAGMENT */
1006
1007#if defined(CONFIG_NET_IPV6_FRAGMENT)
1008static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1009{
1010 return pkt->ipv6_fragment.hdr_start;
1011}
1012
1013static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1014 uint16_t start)
1015{
1016 pkt->ipv6_fragment.hdr_start = start;
1017}
1018
1019static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1020{
1021 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
1022}
1023static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1024{
1025 return (pkt->ipv6_fragment.flags & 0x01) != 0;
1026}
1027
1028static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1030{
1031 pkt->ipv6_fragment.flags = flags;
1032}
1033
1034static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1035{
1036 return pkt->ipv6_fragment.id;
1037}
1038
1039static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1040 uint32_t id)
1041{
1042 pkt->ipv6_fragment.id = id;
1043}
1044#else /* CONFIG_NET_IPV6_FRAGMENT */
1045static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1046{
1047 ARG_UNUSED(pkt);
1048
1049 return 0;
1050}
1051
1052static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1053 uint16_t start)
1054{
1055 ARG_UNUSED(pkt);
1056 ARG_UNUSED(start);
1057}
1058
1059static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1060{
1061 ARG_UNUSED(pkt);
1062
1063 return 0;
1064}
1065
1066static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1067{
1068 ARG_UNUSED(pkt);
1069
1070 return 0;
1071}
1072
1073static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1075{
1076 ARG_UNUSED(pkt);
1077 ARG_UNUSED(flags);
1078}
1079
1080static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1081{
1082 ARG_UNUSED(pkt);
1083
1084 return 0;
1085}
1086
1087static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1088 uint32_t id)
1089{
1090 ARG_UNUSED(pkt);
1091 ARG_UNUSED(id);
1092}
1093#endif /* CONFIG_NET_IPV6_FRAGMENT */
1094
1095static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1096{
1097 return !!(pkt->loopback);
1098}
1099
1100static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1101 bool loopback)
1102{
1103 pkt->loopback = loopback;
1104}
1105
1106#if defined(CONFIG_NET_IP_FRAGMENT)
1107static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1108{
1109 return !!(pkt->ip_reassembled);
1110}
1111
1112static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1113 bool reassembled)
1114{
1115 pkt->ip_reassembled = reassembled;
1116}
1117#else /* CONFIG_NET_IP_FRAGMENT */
1118static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1119{
1120 ARG_UNUSED(pkt);
1121
1122 return false;
1123}
1124
1125static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1126 bool reassembled)
1127{
1128 ARG_UNUSED(pkt);
1129 ARG_UNUSED(reassembled);
1130}
1131#endif /* CONFIG_NET_IP_FRAGMENT */
1132
1133static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1134{
1135 return pkt->priority;
1136}
1137
1138static inline void net_pkt_set_priority(struct net_pkt *pkt,
1139 uint8_t priority)
1140{
1141 pkt->priority = priority;
1142}
1143
1144#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1145static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1146{
1147 return pkt->cooked_mode_pkt;
1148}
1149
1150static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1151{
1152 pkt->cooked_mode_pkt = value;
1153}
1154#else
1155static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1156{
1157 ARG_UNUSED(pkt);
1158
1159 return false;
1160}
1161
1162static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1163{
1164 ARG_UNUSED(pkt);
1165 ARG_UNUSED(value);
1166}
1167#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1168
1169#if defined(CONFIG_NET_VLAN)
1170static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1171{
1172 return net_eth_vlan_get_vid(pkt->vlan_tci);
1173}
1174
1175static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1176{
1177 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1178}
1179
1180static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1181{
1182 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1183}
1184
1185static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1186 uint8_t priority)
1187{
1188 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1189}
1190
1191static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1192{
1193 return net_eth_vlan_get_dei(pkt->vlan_tci);
1194}
1195
1196static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1197{
1198 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1199}
1200
1201static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1202{
1203 pkt->vlan_tci = tci;
1204}
1205
1206static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1207{
1208 return pkt->vlan_tci;
1209}
1210#else
1211static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1212{
1213 ARG_UNUSED(pkt);
1214
1215 return NET_VLAN_TAG_UNSPEC;
1216}
1217
1218static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1219{
1220 ARG_UNUSED(pkt);
1221 ARG_UNUSED(tag);
1222}
1223
1224static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1225{
1226 ARG_UNUSED(pkt);
1227
1228 return 0;
1229}
1230
1231static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1232{
1233 ARG_UNUSED(pkt);
1234
1235 return false;
1236}
1237
1238static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1239{
1240 ARG_UNUSED(pkt);
1241 ARG_UNUSED(dei);
1242}
1243
1244static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1245{
1246 ARG_UNUSED(pkt);
1247
1248 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1249}
1250
1251static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1252{
1253 ARG_UNUSED(pkt);
1254 ARG_UNUSED(tci);
1255}
1256#endif
1257
1258#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1259static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1260{
1261 return &pkt->timestamp;
1262}
1263
1264static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1265 struct net_ptp_time *timestamp)
1266{
1267 pkt->timestamp.second = timestamp->second;
1268 pkt->timestamp.nanosecond = timestamp->nanosecond;
1269}
1270
1271static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1272{
1273 return net_ptp_time_to_ns(&pkt->timestamp);
1274}
1275
1276static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1277{
1278 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1279}
1280#else
1281static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1282{
1283 ARG_UNUSED(pkt);
1284
1285 return NULL;
1286}
1287
1288static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1289 struct net_ptp_time *timestamp)
1290{
1291 ARG_UNUSED(pkt);
1292 ARG_UNUSED(timestamp);
1293}
1294
1295static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1296{
1297 ARG_UNUSED(pkt);
1298
1299 return 0;
1300}
1301
1302static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1303{
1304 ARG_UNUSED(pkt);
1305 ARG_UNUSED(timestamp);
1306}
1307#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1308
1309#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1310 defined(CONFIG_TRACING_NET_CORE)
1311
1312static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1313{
1314 return pkt->create_time;
1315}
1316
1317static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1318 uint32_t create_time)
1319{
1320 pkt->create_time = create_time;
1321}
1322#else
1323static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1324{
1325 ARG_UNUSED(pkt);
1326
1327 return 0U;
1328}
1329
1330static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1331 uint32_t create_time)
1332{
1333 ARG_UNUSED(pkt);
1334 ARG_UNUSED(create_time);
1335}
1336#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1337 * CONFIG_TRACING_NET_CORE
1338 */
1339
1340#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1341 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1342static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1343{
1344 return pkt->detail.stat;
1345}
1346
1347static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1348{
1349 return pkt->detail.count;
1350}
1351
1352static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1353{
1354 memset(&pkt->detail, 0, sizeof(pkt->detail));
1355}
1356
1357static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1358 uint32_t tick)
1359{
1360 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1361 printk("ERROR: Detail stats count overflow (%d >= %d)",
1362 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1363 return;
1364 }
1365
1366 pkt->detail.stat[pkt->detail.count++] = tick;
1367}
1368
1369#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1370#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1371#else
1372static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1373{
1374 ARG_UNUSED(pkt);
1375
1376 return NULL;
1377}
1378
1379static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1380{
1381 ARG_UNUSED(pkt);
1382
1383 return 0;
1384}
1385
1386static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1387{
1388 ARG_UNUSED(pkt);
1389}
1390
1391static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1392{
1393 ARG_UNUSED(pkt);
1394 ARG_UNUSED(tick);
1395}
1396
1397#define net_pkt_set_tx_stats_tick(pkt, tick)
1398#define net_pkt_set_rx_stats_tick(pkt, tick)
1399#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1400 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1401
1402static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1403{
1404 return pkt->frags->data;
1405}
1406
1407static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1408{
1409 return pkt->frags->data;
1410}
1411
1412static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1413{
1414 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1415}
1416
1417static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1418{
1419 return &pkt->lladdr_src;
1420}
1421
1422static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1423{
1424 return &pkt->lladdr_dst;
1425}
1426
1427static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1428{
1429 struct net_linkaddr tmp;
1430
1431 memcpy(tmp.addr,
1432 net_pkt_lladdr_src(pkt)->addr,
1433 net_pkt_lladdr_src(pkt)->len);
1434 memcpy(net_pkt_lladdr_src(pkt)->addr,
1435 net_pkt_lladdr_dst(pkt)->addr,
1436 net_pkt_lladdr_dst(pkt)->len);
1437 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1438 tmp.addr,
1439 net_pkt_lladdr_src(pkt)->len);
1440}
1441
1442static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1443{
1444 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1445 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1446}
1447
1448static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1449{
1450 return pkt->ll_proto_type;
1451}
1452
1453static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1454{
1455 pkt->ll_proto_type = type;
1456}
1457
1458#if defined(CONFIG_NET_IPV4_ACD)
1459static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1460{
1461 return !!(pkt->ipv4_acd_arp_msg);
1462}
1463
1464static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1465 bool is_acd_arp_msg)
1466{
1467 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1468}
1469#else /* CONFIG_NET_IPV4_ACD */
1470static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1471{
1472 ARG_UNUSED(pkt);
1473
1474 return false;
1475}
1476
1477static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1478 bool is_acd_arp_msg)
1479{
1480 ARG_UNUSED(pkt);
1481 ARG_UNUSED(is_acd_arp_msg);
1482}
1483#endif /* CONFIG_NET_IPV4_ACD */
1484
1485#if defined(CONFIG_NET_LLDP)
1486static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1487{
1488 return !!(pkt->lldp_pkt);
1489}
1490
1491static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1492{
1493 pkt->lldp_pkt = is_lldp;
1494}
1495#else
1496static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1497{
1498 ARG_UNUSED(pkt);
1499
1500 return false;
1501}
1502
1503static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1504{
1505 ARG_UNUSED(pkt);
1506 ARG_UNUSED(is_lldp);
1507}
1508#endif /* CONFIG_NET_LLDP */
1509
1510#if defined(CONFIG_NET_L2_PPP)
1511static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1512{
1513 return !!(pkt->ppp_msg);
1514}
1515
1516static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1517 bool is_ppp_msg)
1518{
1519 pkt->ppp_msg = is_ppp_msg;
1520}
1521#else /* CONFIG_NET_L2_PPP */
1522static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1523{
1524 ARG_UNUSED(pkt);
1525
1526 return false;
1527}
1528
1529static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1530 bool is_ppp_msg)
1531{
1532 ARG_UNUSED(pkt);
1533 ARG_UNUSED(is_ppp_msg);
1534}
1535#endif /* CONFIG_NET_L2_PPP */
1536
1537#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1538static inline void *net_pkt_cb(struct net_pkt *pkt)
1539{
1540 return &pkt->cb;
1541}
1542#else
1543static inline void *net_pkt_cb(struct net_pkt *pkt)
1544{
1545 ARG_UNUSED(pkt);
1546
1547 return NULL;
1548}
1549#endif
1550
1551#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1552#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1553
1554static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1555{
1557 net_pkt_context(pkt)),
1558 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1559}
1560
1561static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1562{
1563 pkt->overwrite = overwrite;
1564}
1565
1566static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1567{
1568 return !!(pkt->overwrite);
1569}
1570
1571#ifdef CONFIG_NET_PKT_FILTER
1572
1573bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1574bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1575
1576#else
1577
1578static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1579{
1580 ARG_UNUSED(pkt);
1581
1582 return true;
1583}
1584
1585static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1586{
1587 ARG_UNUSED(pkt);
1588
1589 return true;
1590}
1591
1592#endif /* CONFIG_NET_PKT_FILTER */
1593
1594#if defined(CONFIG_NET_PKT_FILTER) && \
1595 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1596
1597bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1598
1599#else
1600
1601static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1602{
1603 ARG_UNUSED(pkt);
1604
1605 return true;
1606}
1607
1608#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1609
1610#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1611
1612bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1613
1614#else
1615
1616static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1617{
1618 ARG_UNUSED(pkt);
1619
1620 return true;
1621}
1622
1623#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1624
1625#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1626static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1627{
1628 return &pkt->remote;
1629}
1630
1631static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1632 struct net_sockaddr *address,
1633 net_socklen_t len)
1634{
1635 memcpy(&pkt->remote, address, len);
1636}
1637#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1638
1639/* @endcond */
1640
1654#define NET_PKT_SLAB_DEFINE(name, count) \
1655 K_MEM_SLAB_DEFINE_TYPE(name, struct net_pkt, count); \
1656 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1657
1659
1660/* Backward compatibility macro */
1661#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1662
1664
1678#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1679 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1680 0, NULL)
1681
1683
1684#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1685 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1686#define NET_PKT_DEBUG_ENABLED
1687#endif
1688
1689#if defined(NET_PKT_DEBUG_ENABLED)
1690
1691/* Debug versions of the net_pkt functions that are used when tracking
1692 * buffer usage.
1693 */
1694
1695struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1696 size_t min_len,
1697 k_timeout_t timeout,
1698 const char *caller,
1699 int line);
1700
1701#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1702 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1703
1704struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1705 k_timeout_t timeout,
1706 const char *caller,
1707 int line);
1708#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1709 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1710
1711struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1712 k_timeout_t timeout,
1713 const char *caller,
1714 int line);
1715#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1716 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1717
1718struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1719 k_timeout_t timeout,
1720 const char *caller, int line);
1721#define net_pkt_get_frag(pkt, min_len, timeout) \
1722 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1723
1724void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1725#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1726
1727struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1728 int line);
1729#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1730
1731struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1732 const char *caller, int line);
1733#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1734
1735void net_pkt_frag_unref_debug(struct net_buf *frag,
1736 const char *caller, int line);
1737#define net_pkt_frag_unref(frag) \
1738 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1739
1740struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1741 struct net_buf *parent,
1742 struct net_buf *frag,
1743 const char *caller, int line);
1744#define net_pkt_frag_del(pkt, parent, frag) \
1745 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1746
1747void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1748 const char *caller, int line);
1749#define net_pkt_frag_add(pkt, frag) \
1750 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1751
1752void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1753 const char *caller, int line);
1754#define net_pkt_frag_insert(pkt, frag) \
1755 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1756#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1757 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1758 */
1760
1761#if defined(NET_PKT_DEBUG_ENABLED)
1769void net_pkt_print_frags(struct net_pkt *pkt);
1770#else
1771#define net_pkt_print_frags(pkt)
1772#endif
1773
1774#if !defined(NET_PKT_DEBUG_ENABLED)
1790 size_t min_len, k_timeout_t timeout);
1791#endif
1792
1793#if !defined(NET_PKT_DEBUG_ENABLED)
1808struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1809#endif
1810
1811#if !defined(NET_PKT_DEBUG_ENABLED)
1826struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1827#endif
1828
1829#if !defined(NET_PKT_DEBUG_ENABLED)
1842struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1843 k_timeout_t timeout);
1844#endif
1845
1846#if !defined(NET_PKT_DEBUG_ENABLED)
1856void net_pkt_unref(struct net_pkt *pkt);
1857#endif
1858
1859#if !defined(NET_PKT_DEBUG_ENABLED)
1869struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1870#endif
1871
1872#if !defined(NET_PKT_DEBUG_ENABLED)
1882struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1883#endif
1884
1885#if !defined(NET_PKT_DEBUG_ENABLED)
1891void net_pkt_frag_unref(struct net_buf *frag);
1892#endif
1893
1894#if !defined(NET_PKT_DEBUG_ENABLED)
1906 struct net_buf *parent,
1907 struct net_buf *frag);
1908#endif
1909
1910#if !defined(NET_PKT_DEBUG_ENABLED)
1917void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1918#endif
1919
1920#if !defined(NET_PKT_DEBUG_ENABLED)
1927void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1928#endif
1929
1936void net_pkt_compact(struct net_pkt *pkt);
1937
1946void net_pkt_get_info(struct k_mem_slab **rx,
1947 struct k_mem_slab **tx,
1948 struct net_buf_pool **rx_data,
1949 struct net_buf_pool **tx_data);
1950
1952
1953#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1957void net_pkt_print(void);
1958
1959typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1960 struct net_buf *buf,
1961 const char *func_alloc,
1962 int line_alloc,
1963 const char *func_free,
1964 int line_free,
1965 bool in_use,
1966 void *user_data);
1967
1968void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1969
1970const char *net_pkt_slab2str(struct k_mem_slab *slab);
1971const char *net_pkt_pool2str(struct net_buf_pool *pool);
1972
1973#else
1974#define net_pkt_print(...)
1975#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1976
1977/* New allocator, and API are defined below.
1978 * This will be simpler when time will come to get rid of former API above.
1979 */
1980#if defined(NET_PKT_DEBUG_ENABLED)
1981
1982struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1983 const char *caller, int line);
1984#define net_pkt_alloc(_timeout) \
1985 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1986
1987struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1988 k_timeout_t timeout,
1989 const char *caller, int line);
1990#define net_pkt_alloc_from_slab(_slab, _timeout) \
1991 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1992
1993struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1994 const char *caller, int line);
1995#define net_pkt_rx_alloc(_timeout) \
1996 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1997
1998struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1999 k_timeout_t timeout,
2000 const char *caller,
2001 int line);
2002#define net_pkt_alloc_on_iface(_iface, _timeout) \
2003 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
2004
2005struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
2006 k_timeout_t timeout,
2007 const char *caller,
2008 int line);
2009#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
2010 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
2011 __func__, __LINE__)
2012
2013int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
2014 size_t size,
2015 enum net_ip_protocol proto,
2016 k_timeout_t timeout,
2017 const char *caller, int line);
2018#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
2019 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
2020 __func__, __LINE__)
2021
2022int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
2023 k_timeout_t timeout,
2024 const char *caller, int line);
2025#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
2026 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
2027 __func__, __LINE__)
2028
2029struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
2030 size_t size,
2031 net_sa_family_t family,
2032 enum net_ip_protocol proto,
2033 k_timeout_t timeout,
2034 const char *caller,
2035 int line);
2036#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
2037 _proto, _timeout) \
2038 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
2039 _proto, _timeout, \
2040 __func__, __LINE__)
2041
2042struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
2043 size_t size,
2044 net_sa_family_t family,
2045 enum net_ip_protocol proto,
2046 k_timeout_t timeout,
2047 const char *caller,
2048 int line);
2049#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
2050 _proto, _timeout) \
2051 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
2052 _proto, _timeout, \
2053 __func__, __LINE__)
2054
2055int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
2056 size_t size,
2057 size_t reserve,
2058 enum net_ip_protocol proto,
2059 k_timeout_t timeout,
2060 const char *caller,
2061 int line);
2062#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
2063 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
2064 _timeout, __func__, __LINE__)
2065
2066#endif /* NET_PKT_DEBUG_ENABLED */
2068
2069#if !defined(NET_PKT_DEBUG_ENABLED)
2081#endif
2082
2083#if !defined(NET_PKT_DEBUG_ENABLED)
2098struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2099 k_timeout_t timeout);
2100#endif
2101
2102#if !defined(NET_PKT_DEBUG_ENABLED)
2114#endif
2115
2116#if !defined(NET_PKT_DEBUG_ENABLED)
2126 k_timeout_t timeout);
2127
2129
2130/* Same as above but specifically for RX packet */
2131struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2132 k_timeout_t timeout);
2134
2135#endif
2136
2137#if !defined(NET_PKT_DEBUG_ENABLED)
2154 size_t size,
2155 enum net_ip_protocol proto,
2156 k_timeout_t timeout);
2157#endif
2158
2159#if !defined(NET_PKT_DEBUG_ENABLED)
2177#if !defined(NET_PKT_DEBUG_ENABLED)
2179 size_t size,
2180 size_t reserve,
2181 enum net_ip_protocol proto,
2182 k_timeout_t timeout);
2183#endif
2184
2198int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2199 k_timeout_t timeout);
2200#endif
2201
2202#if !defined(NET_PKT_DEBUG_ENABLED)
2215 size_t size,
2216 net_sa_family_t family,
2217 enum net_ip_protocol proto,
2218 k_timeout_t timeout);
2219
2221
2222/* Same as above but specifically for RX packet */
2223struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2224 size_t size,
2225 net_sa_family_t family,
2226 enum net_ip_protocol proto,
2227 k_timeout_t timeout);
2228
2230
2231#endif
2232
2239void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2240
2252
2269 enum net_ip_protocol proto);
2270
2280
2295int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2296
2305
2312static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2313 struct net_pkt_cursor *backup)
2314{
2315 backup->buf = pkt->cursor.buf;
2316 backup->pos = pkt->cursor.pos;
2317}
2318
2325static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2326 struct net_pkt_cursor *backup)
2327{
2328 pkt->cursor.buf = backup->buf;
2329 pkt->cursor.pos = backup->pos;
2330}
2331
2339static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2340{
2341 return pkt->cursor.pos;
2342}
2343
2361int net_pkt_skip(struct net_pkt *pkt, size_t length);
2362
2377int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2378
2392int net_pkt_copy(struct net_pkt *pkt_dst,
2393 struct net_pkt *pkt_src,
2394 size_t length);
2395
2405struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2406
2416struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2417
2427 k_timeout_t timeout);
2428
2442int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2443
2456static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2457{
2458 return net_pkt_read(pkt, data, 1);
2459}
2460
2473int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2474
2487int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2488
2501int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2502
2515int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2516
2529int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2530
2543int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2544
2558int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2559
2572static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2573{
2574 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2575}
2576
2589static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2590{
2591 uint16_t data_be16 = net_htons(data);
2592
2593 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2594}
2595
2608static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2609{
2610 uint32_t data_be32 = net_htonl(data);
2611
2612 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2613}
2614
2627static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2628{
2629 uint32_t data_le32 = sys_cpu_to_le32(data);
2630
2631 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2632}
2633
2646static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2647{
2648 uint16_t data_le16 = sys_cpu_to_le16(data);
2649
2650 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2651}
2652
2661
2669static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2670{
2671 return net_buf_frags_len(pkt->frags);
2672}
2673
2686int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2687
2701int net_pkt_pull(struct net_pkt *pkt, size_t length);
2702
2712
2724bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2725
2735
2737
2738struct net_pkt_data_access {
2739#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2740 void *data;
2741#endif
2742 const size_t size;
2743};
2744
2745#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2746#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2747 struct net_pkt_data_access _name = { \
2748 .size = sizeof(_type), \
2749 }
2750
2751#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2752 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2753
2754#else
2755#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2756 _type _hdr_##_name; \
2757 struct net_pkt_data_access _name = { \
2758 .data = &_hdr_##_name, \
2759 .size = sizeof(_type), \
2760 }
2761
2762#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2763 struct net_pkt_data_access _name = { \
2764 .data = NULL, \
2765 .size = sizeof(_type), \
2766 }
2767
2768#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2769
2771
2785void *net_pkt_get_data(struct net_pkt *pkt,
2786 struct net_pkt_data_access *access);
2787
2802 struct net_pkt_data_access *access);
2803
2808static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2809 struct net_pkt_data_access *access)
2810{
2811 return net_pkt_skip(pkt, access->size);
2812}
2813
2817
2818#ifdef __cplusplus
2819}
2820#endif
2821
2822#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
long atomic_t
Definition atomic_types.h:15
VLAN specific definitions.
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:172
#define net_htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:133
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1064
unsigned short int net_sa_family_t
Socket address family type.
Definition net_ip.h:169
#define net_htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:125
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:2819
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:752
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1271
static const struct net_in6_addr * net_if_ipv6_select_src_addr(struct net_if *iface, const struct net_in6_addr *dst)
Get a IPv6 source address that should be used when sending network data to destination.
Definition net_if.h:2271
static int net_linkaddr_clear(struct net_linkaddr *lladdr)
Clear link address.
Definition net_linkaddr.h:209
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:2608
int net_pkt_alloc_buffer_with_reserve(struct net_pkt *pkt, size_t size, size_t reserve, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate buffer for a net_pkt and reserve some space in the first net_buf.
void net_pkt_cursor_init(struct net_pkt *pkt)
Initialize net_pkt cursor.
int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data)
Read uint32_t little endian data from a net_pkt.
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:1771
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 start of the packet.
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.
struct net_pkt * net_pkt_alloc_with_buffer(struct net_if *iface, size_t size, net_sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate a network packet and buffer at once.
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.
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:2589
struct net_pkt * net_pkt_alloc(k_timeout_t timeout)
Allocate an initialized net_pkt.
int net_pkt_read(struct net_pkt *pkt, void *data, size_t length)
Read some data from a net_pkt.
static size_t net_pkt_get_len(struct net_pkt *pkt)
Get the total amount of bytes stored in a packet.
Definition net_pkt.h:2669
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.
int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data)
Read uint64_t little endian data from a net_pkt.
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:2572
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:2339
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:2312
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:2808
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:2646
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:2325
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:2627
int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data)
Read uint64_t big endian data from a net_pkt.
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:2456
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:154
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:81
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:56
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition ethernet_vlan.h:32
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition ethernet_vlan.h:94
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:44
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:107
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:68
Packet data common to all IEEE 802.15.4 L2 layers.
Buffer management.
Network context definitions.
Network core definitions.
Public API for network interface.
IPv6 and IPv4 definitions.
Public API for network link address.
Representation of nanosecond resolution elapsed time and timestamps in the network stack.
flags
Definition parser.h:97
static void printk(const char *fmt,...)
Print kernel debugging message.
Definition printk.h:51
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)
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1151
Network buffer representation.
Definition net_buf.h:1015
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1104
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1125
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1107
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:209
Network Interface structure.
Definition net_if.h:735
IPv6 address struct.
Definition net_ip.h:144
IPv4 address struct.
Definition net_ip.h:156
Hardware link address structure.
Definition net_linkaddr.h:83
uint8_t addr[6]
The array of bytes representing the address.
Definition net_linkaddr.h:91
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:85
uint8_t len
The real length of the ll address.
Definition net_linkaddr.h:88
Network packet.
Definition net_pkt.h:119
struct net_buf * frags
buffer fragment
Definition net_pkt.h:131
struct net_context * context
Network connection context.
Definition net_pkt.h:139
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:136
struct net_if * iface
Network interface.
Definition net_pkt.h:142
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:124
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:132
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:127
(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:449
Definition stat.h:57
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition byteorder.h:272
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:268