Zephyr API Documentation 4.5.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) || defined(CONFIG_NET_UDP_OPTIONS)
147 /* TCP or UDP are mutually exclusive so they can share the same memory */
148 union {
149#if defined(CONFIG_NET_TCP)
151 sys_snode_t next;
152#endif
153#if defined(CONFIG_NET_UDP_OPTIONS)
155 uint16_t udp_opt_surplus_len;
156#endif
157 };
158#endif /* CONFIG_NET_TCP || CONFIG_NET_UDP_OPTIONS */
159
160#if defined(CONFIG_NET_PKT_ORIG_IFACE)
161 struct net_if *orig_iface; /* Original network interface */
162#endif
163
164#if defined(CONFIG_NET_VPN)
165 struct {
167 struct net_if *iface;
169 union net_ip_header ip_hdr;
171 union net_proto_header proto_hdr;
173 int peer_id;
174 } vpn;
175#endif
176
177#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
196 struct net_ptp_time timestamp;
197#endif
198
199#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
200 defined(CONFIG_TRACING_NET_CORE)
201 struct {
203 uint32_t create_time;
204
205#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
206 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
212 struct {
213 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
214 int count;
215 } detail;
216#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
217 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
218 };
219#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
220
221#if defined(CONFIG_NET_PKT_ALLOC_STATS)
222 struct net_pkt_alloc_stats_slab *alloc_stats;
223#endif /* CONFIG_NET_PKT_ALLOC_STATS */
224
226 atomic_t atomic_ref;
227
228 /* Filled by layer 2 when network packet is received. */
229 struct net_linkaddr lladdr_src;
230 struct net_linkaddr lladdr_dst;
231 uint16_t ll_proto_type;
232
233#if defined(CONFIG_NET_IP)
234 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
235#endif
236
237 uint8_t overwrite : 1; /* Is packet content being overwritten? */
238 uint8_t eof : 1; /* Last packet before EOF */
239 uint8_t forwarding : 1; /* Are we forwarding this pkt
240 * Used only if defined(CONFIG_NET_IPV6_ROUTE)
241 */
242 uint8_t family : 3; /* Address family, see net_ip.h */
243
244 /* bitfield byte alignment boundary */
245
246#if defined(CONFIG_NET_IPV4_ACD)
247 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
248 * message.
249 * Note: family needs to be
250 * NET_AF_INET.
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; /* The transport layer checksum is already
266 * in the packet, see
267 * net_pkt_is_chksum_done().
268 */
269 uint8_t loopback : 1; /* Packet is a loop back packet. */
270#if defined(CONFIG_NET_IP_FRAGMENT)
271 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
272#endif
273#if defined(CONFIG_NET_PKT_TIMESTAMP)
274 uint8_t tx_timestamping : 1;
275 uint8_t rx_timestamping : 1;
276#endif
277 /* bitfield byte alignment boundary */
278
279#if defined(CONFIG_NET_IP)
280 union {
281 /* IPv6 hop limit or IPv4 ttl for this network packet.
282 * The value is shared between IPv6 and IPv4.
283 */
284#if defined(CONFIG_NET_IPV6)
285 uint8_t ipv6_hop_limit;
286#endif
287#if defined(CONFIG_NET_IPV4)
288 uint8_t ipv4_ttl;
289#endif
290 };
291
292 union {
293#if defined(CONFIG_NET_IPV4)
294 uint8_t ipv4_opts_len; /* length of IPv4 header options */
295#endif
296#if defined(CONFIG_NET_IPV6)
297 uint16_t ipv6_ext_len; /* length of extension headers */
298#endif
299 };
300
301#if defined(CONFIG_NET_IPV4_ROUTE)
302 /* IPv4 address that should be resolved at L2 for transmission.
303 * Routed packets use this to steer link-layer resolution towards the
304 * next on-link IPv4 address.
305 */
306 struct net_in_addr ipv4_ll_resolve_addr;
307#endif /* CONFIG_NET_IPV4_ROUTE */
308
309#if defined(CONFIG_NET_IP_FRAGMENT)
310 union {
311#if defined(CONFIG_NET_IPV4_FRAGMENT)
312 struct {
313 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
314 uint16_t id; /* Fragment ID */
315 } ipv4_fragment;
316#endif /* CONFIG_NET_IPV4_FRAGMENT */
317#if defined(CONFIG_NET_IPV6_FRAGMENT)
318 struct {
319 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
320 uint32_t id; /* Fragment id */
321 uint16_t hdr_start; /* Where starts the fragment header */
322 } ipv6_fragment;
323#endif /* CONFIG_NET_IPV6_FRAGMENT */
324 };
325#endif /* CONFIG_NET_IP_FRAGMENT */
326
327#if defined(CONFIG_NET_IPV6)
328 /* Where is the start of the last header before payload data
329 * in IPv6 packet. This is offset value from start of the IPv6
330 * packet. Note that this value should be updated by who ever
331 * adds IPv6 extension headers to the network packet.
332 */
333 uint16_t ipv6_prev_hdr_start;
334
335 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
336
337 /* Next header value. For a packet to send, the extension header that
338 * follows the IPv6 header. For a received packet, the upper layer
339 * protocol.
340 */
341 uint8_t ipv6_next_hdr;
342#endif /* CONFIG_NET_IPV6 */
343
344#if defined(CONFIG_NET_IP_DSCP_ECN)
346 uint8_t ip_dscp : 6;
347
349 uint8_t ip_ecn : 2;
350#endif /* CONFIG_NET_IP_DSCP_ECN */
351#endif /* CONFIG_NET_IP */
352
353#if defined(CONFIG_NET_VLAN)
354 /* VLAN TCI (Tag Control Information). This contains the Priority
355 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
356 * Identifier (VID, called more commonly VLAN tag). This value is
357 * kept in host byte order.
358 */
359 uint16_t vlan_tci;
360#endif /* CONFIG_NET_VLAN */
361
362#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
363 /* Control block which could be used by any layer */
364 union {
365 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
366#if defined(CONFIG_IEEE802154)
367 /* The following structure requires a 4-byte alignment
368 * boundary to avoid padding.
369 */
370 struct net_pkt_cb_ieee802154 cb_ieee802154;
371#endif /* CONFIG_IEEE802154 */
372 } cb;
373#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
374
378 uint8_t priority;
379
380#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
381 /* Remote address of the received packet. This is only used by
382 * network interfaces with an offloaded TCP/IP stack, or if we
383 * have network tunneling in use.
384 */
385 union {
386 struct net_sockaddr remote;
387
388 /* This will make sure that there is enough storage to store
389 * the address struct. The access to value is via remote
390 * address.
391 */
392 struct net_sockaddr_storage remote_storage;
393 };
394#endif /* CONFIG_NET_OFFLOAD */
395
396#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
397 /* Tell the capture api that this is a captured packet */
398 uint8_t cooked_mode_pkt : 1;
399#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
400
401#if defined(CONFIG_NET_IPV4_PMTU)
402 /* Path MTU needed for this destination address */
403 uint8_t ipv4_pmtu : 1;
404#endif /* CONFIG_NET_IPV4_PMTU */
405#if defined(CONFIG_NET_IPV4_ROUTE)
406 uint8_t ipv4_ll_resolve_addr_set : 1;
407#endif /* CONFIG_NET_IPV4_ROUTE */
408
409 /* Disable local IP fragmentation for this packet. */
410 uint8_t dont_fragment : 1;
411
412 /* @endcond */
413};
414
416
417/* The interface real ll address */
418static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
419{
420 return net_if_get_link_addr(pkt->iface);
421}
422
423static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
424{
425 return pkt->context;
426}
427
428static inline void net_pkt_set_context(struct net_pkt *pkt,
429 struct net_context *ctx)
430{
431 pkt->context = ctx;
432}
433
434static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
435{
436 return pkt->iface;
437}
438
439static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
440{
441 struct net_linkaddr *lladdr = net_if_get_link_addr(iface);
442
443 pkt->iface = iface;
444
445 /* If the network interface is set in pkt, then also set the type of
446 * the network address that is stored in pkt. This is done here so
447 * that the address type is properly set and is not forgotten.
448 */
449 if (lladdr != NULL) {
450 pkt->lladdr_src.type = lladdr->type;
451 pkt->lladdr_dst.type = lladdr->type;
452 }
453}
454
455static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
456{
457#if defined(CONFIG_NET_PKT_ORIG_IFACE)
458 return pkt->orig_iface;
459#else
460 return pkt->iface;
461#endif
462}
463
464static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
465 struct net_if *iface)
466{
467#if defined(CONFIG_NET_PKT_ORIG_IFACE)
468 pkt->orig_iface = iface;
469#else
470 ARG_UNUSED(pkt);
471 ARG_UNUSED(iface);
472#endif
473}
474
475#if defined(CONFIG_NET_VPN)
476static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
477{
478 return pkt->vpn.iface;
479}
480
481static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
482 struct net_if *iface)
483{
484 pkt->vpn.iface = iface;
485}
486
487static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
488{
489 return &pkt->vpn.ip_hdr;
490}
491
492static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
493 union net_ip_header *ip_hdr)
494{
495 pkt->vpn.ip_hdr = *ip_hdr;
496}
497
498static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
499{
500 return &pkt->vpn.proto_hdr;
501}
502
503static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
504 union net_proto_header *proto_hdr)
505{
506 pkt->vpn.proto_hdr = *proto_hdr;
507}
508
509static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
510{
511 return pkt->vpn.peer_id;
512}
513
514static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
515 int peer_id)
516{
517 pkt->vpn.peer_id = peer_id;
518}
519#endif /* CONFIG_NET_VPN */
520
521#if defined(CONFIG_NET_UDP_OPTIONS)
522static inline uint16_t net_pkt_udp_opt_surplus_len(struct net_pkt *pkt)
523{
524 return pkt->udp_opt_surplus_len;
525}
526
527static inline void net_pkt_set_udp_opt_surplus_len(struct net_pkt *pkt,
528 uint16_t len)
529{
530 pkt->udp_opt_surplus_len = len;
531}
532#else
533static inline uint16_t net_pkt_udp_opt_surplus_len(struct net_pkt *pkt)
534{
535 ARG_UNUSED(pkt);
536
537 return 0;
538}
539
540#define net_pkt_set_udp_opt_surplus_len(...)
541#endif /* CONFIG_NET_UDP_OPTIONS */
542
543static inline uint8_t net_pkt_family(struct net_pkt *pkt)
544{
545 return pkt->family;
546}
547
548static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
549{
550 pkt->family = family;
551}
552
553static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
554{
555#if defined(CONFIG_NET_PKT_TIMESTAMP)
556 return !!(pkt->tx_timestamping);
557#else
558 ARG_UNUSED(pkt);
559
560 return false;
561#endif
562}
563
564static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
565{
566#if defined(CONFIG_NET_PKT_TIMESTAMP)
567 pkt->tx_timestamping = is_timestamping;
568#else
569 ARG_UNUSED(pkt);
570 ARG_UNUSED(is_timestamping);
571#endif
572}
573
574static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
575{
576#if defined(CONFIG_NET_PKT_TIMESTAMP)
577 return !!(pkt->rx_timestamping);
578#else
579 ARG_UNUSED(pkt);
580
581 return false;
582#endif
583}
584
585static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
586{
587#if defined(CONFIG_NET_PKT_TIMESTAMP)
588 pkt->rx_timestamping = is_timestamping;
589#else
590 ARG_UNUSED(pkt);
591 ARG_UNUSED(is_timestamping);
592#endif
593}
594
595static inline bool net_pkt_is_captured(struct net_pkt *pkt)
596{
597 return !!(pkt->captured);
598}
599
600static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
601{
602 pkt->captured = is_captured;
603}
604
605static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
606{
607 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
608}
609
610static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
611{
612 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
613 pkt->l2_bridged = is_l2_bridged;
614 }
615}
616
617static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
618{
619 return !!(pkt->l2_processed);
620}
621
622static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
623 bool is_l2_processed)
624{
625 pkt->l2_processed = is_l2_processed;
626}
627
645static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
646{
647 return !!(pkt->chksum_done);
648}
649
650static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
651 bool is_chksum_done)
652{
653 pkt->chksum_done = is_chksum_done;
654}
655
656static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
657{
658#if defined(CONFIG_NET_IP)
659 return pkt->ip_hdr_len;
660#else
661 ARG_UNUSED(pkt);
662
663 return 0;
664#endif
665}
666
667static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
668{
669#if defined(CONFIG_NET_IP)
670 pkt->ip_hdr_len = len;
671#else
672 ARG_UNUSED(pkt);
673 ARG_UNUSED(len);
674#endif
675}
676
677static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
678{
679#if defined(CONFIG_NET_IP_DSCP_ECN)
680 return pkt->ip_dscp;
681#else
682 ARG_UNUSED(pkt);
683
684 return 0;
685#endif
686}
687
688static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
689{
690#if defined(CONFIG_NET_IP_DSCP_ECN)
691 pkt->ip_dscp = dscp;
692#else
693 ARG_UNUSED(pkt);
694 ARG_UNUSED(dscp);
695#endif
696}
697
698static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
699{
700#if defined(CONFIG_NET_IP_DSCP_ECN)
701 return pkt->ip_ecn;
702#else
703 ARG_UNUSED(pkt);
704
705 return 0;
706#endif
707}
708
709static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
710{
711#if defined(CONFIG_NET_IP_DSCP_ECN)
712 pkt->ip_ecn = ecn;
713#else
714 ARG_UNUSED(pkt);
715 ARG_UNUSED(ecn);
716#endif
717}
718
719static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
720{
721 return pkt->eof;
722}
723
724static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
725{
726 pkt->eof = eof;
727}
728
729static inline bool net_pkt_forwarding(struct net_pkt *pkt)
730{
731 return !!(pkt->forwarding);
732}
733
734static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
735{
736 pkt->forwarding = forward;
737}
738
739#if defined(CONFIG_NET_IPV4)
740static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
741{
742 return pkt->ipv4_ttl;
743}
744
745static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
746 uint8_t ttl)
747{
748 pkt->ipv4_ttl = ttl;
749}
750
751static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
752{
753 return pkt->ipv4_opts_len;
754}
755
756static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
757 uint8_t opts_len)
758{
759 pkt->ipv4_opts_len = opts_len;
760}
761#else
762static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
763{
764 ARG_UNUSED(pkt);
765
766 return 0;
767}
768
769static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
770 uint8_t ttl)
771{
772 ARG_UNUSED(pkt);
773 ARG_UNUSED(ttl);
774}
775
776static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
777{
778 ARG_UNUSED(pkt);
779 return 0;
780}
781
782static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
783 uint8_t opts_len)
784{
785 ARG_UNUSED(pkt);
786 ARG_UNUSED(opts_len);
787}
788#endif
789
790#if defined(CONFIG_NET_IPV6)
791static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
792{
793 return pkt->ipv6_ext_opt_len;
794}
795
796static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
797 uint8_t len)
798{
799 pkt->ipv6_ext_opt_len = len;
800}
801
802static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
803{
804 return pkt->ipv6_next_hdr;
805}
806
807static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
808 uint8_t next_hdr)
809{
810 pkt->ipv6_next_hdr = next_hdr;
811}
812
813static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
814{
815 return pkt->ipv6_ext_len;
816}
817
818static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
819{
820 pkt->ipv6_ext_len = len;
821}
822
823static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
824{
825 return pkt->ipv6_prev_hdr_start;
826}
827
828static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
829 uint16_t offset)
830{
831 pkt->ipv6_prev_hdr_start = offset;
832}
833
834static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
835{
836 return pkt->ipv6_hop_limit;
837}
838
839static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
840 uint8_t hop_limit)
841{
842 pkt->ipv6_hop_limit = hop_limit;
843}
844#else /* CONFIG_NET_IPV6 */
845static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
846{
847 ARG_UNUSED(pkt);
848
849 return 0;
850}
851
852static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
853 uint8_t len)
854{
855 ARG_UNUSED(pkt);
856 ARG_UNUSED(len);
857}
858
859static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
860{
861 ARG_UNUSED(pkt);
862
863 return 0;
864}
865
866static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
867 uint8_t next_hdr)
868{
869 ARG_UNUSED(pkt);
870 ARG_UNUSED(next_hdr);
871}
872
873static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
874{
875 ARG_UNUSED(pkt);
876
877 return 0;
878}
879
880static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
881{
882 ARG_UNUSED(pkt);
883 ARG_UNUSED(len);
884}
885
886static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
887{
888 ARG_UNUSED(pkt);
889
890 return 0;
891}
892
893static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
894 uint16_t offset)
895{
896 ARG_UNUSED(pkt);
897 ARG_UNUSED(offset);
898}
899
900static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
901{
902 ARG_UNUSED(pkt);
903
904 return 0;
905}
906
907static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
908 uint8_t hop_limit)
909{
910 ARG_UNUSED(pkt);
911 ARG_UNUSED(hop_limit);
912}
913#endif /* CONFIG_NET_IPV6 */
914
915static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
916{
917#if defined(CONFIG_NET_IPV6)
918 return pkt->ipv6_ext_len;
919#elif defined(CONFIG_NET_IPV4)
920 return pkt->ipv4_opts_len;
921#else
922 ARG_UNUSED(pkt);
923
924 return 0;
925#endif
926}
927
928#if defined(CONFIG_NET_IPV4_PMTU)
929static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
930{
931 return !!pkt->ipv4_pmtu;
932}
933
934static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
935{
936 pkt->ipv4_pmtu = value;
937}
938#else
939static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
940{
941 ARG_UNUSED(pkt);
942
943 return false;
944}
945
946static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
947{
948 ARG_UNUSED(pkt);
949 ARG_UNUSED(value);
950}
951#endif /* CONFIG_NET_IPV4_PMTU */
952
953#if defined(CONFIG_NET_IPV4_ROUTE)
954static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
955{
956 return pkt->ipv4_ll_resolve_addr_set ? &pkt->ipv4_ll_resolve_addr : NULL;
957}
958
959static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
960 const struct net_in_addr *addr)
961{
962 if (addr != NULL) {
963 net_ipaddr_copy(&pkt->ipv4_ll_resolve_addr, addr);
964 pkt->ipv4_ll_resolve_addr_set = 1U;
965 } else {
966 pkt->ipv4_ll_resolve_addr_set = 0U;
967 }
968}
969#else
970static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
971{
972 ARG_UNUSED(pkt);
973
974 return NULL;
975}
976
977static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
978 const struct net_in_addr *addr)
979{
980 ARG_UNUSED(pkt);
981 ARG_UNUSED(addr);
982}
983#endif /* CONFIG_NET_IPV4_ROUTE */
984
985static inline bool net_pkt_dont_fragment(struct net_pkt *pkt)
986{
987 return !!pkt->dont_fragment;
988}
989
990static inline void net_pkt_set_dont_fragment(struct net_pkt *pkt, bool value)
991{
992 pkt->dont_fragment = value;
993}
994
995#if defined(CONFIG_NET_IPV4_FRAGMENT)
996static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
997{
998 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
999}
1000
1001static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
1002{
1003 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
1004}
1005
1006static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
1007{
1008 pkt->ipv4_fragment.flags = flags;
1009}
1010
1011static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
1012{
1013 return pkt->ipv4_fragment.id;
1014}
1015
1016static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
1017{
1018 pkt->ipv4_fragment.id = id;
1019}
1020#else /* CONFIG_NET_IPV4_FRAGMENT */
1021static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
1022{
1023 ARG_UNUSED(pkt);
1024
1025 return 0;
1026}
1027
1028static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
1029{
1030 ARG_UNUSED(pkt);
1031
1032 return 0;
1033}
1034
1035static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
1036{
1037 ARG_UNUSED(pkt);
1038 ARG_UNUSED(flags);
1039}
1040
1041static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
1042{
1043 ARG_UNUSED(pkt);
1044
1045 return 0;
1046}
1047
1048static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
1049{
1050 ARG_UNUSED(pkt);
1051 ARG_UNUSED(id);
1052}
1053#endif /* CONFIG_NET_IPV4_FRAGMENT */
1054
1055#if defined(CONFIG_NET_IPV6_FRAGMENT)
1056static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1057{
1058 return pkt->ipv6_fragment.hdr_start;
1059}
1060
1061static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1062 uint16_t start)
1063{
1064 pkt->ipv6_fragment.hdr_start = start;
1065}
1066
1067static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1068{
1069 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
1070}
1071static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1072{
1073 return (pkt->ipv6_fragment.flags & 0x01) != 0;
1074}
1075
1076static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1078{
1079 pkt->ipv6_fragment.flags = flags;
1080}
1081
1082static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1083{
1084 return pkt->ipv6_fragment.id;
1085}
1086
1087static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1088 uint32_t id)
1089{
1090 pkt->ipv6_fragment.id = id;
1091}
1092#else /* CONFIG_NET_IPV6_FRAGMENT */
1093static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1094{
1095 ARG_UNUSED(pkt);
1096
1097 return 0;
1098}
1099
1100static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1101 uint16_t start)
1102{
1103 ARG_UNUSED(pkt);
1104 ARG_UNUSED(start);
1105}
1106
1107static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1108{
1109 ARG_UNUSED(pkt);
1110
1111 return 0;
1112}
1113
1114static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1115{
1116 ARG_UNUSED(pkt);
1117
1118 return 0;
1119}
1120
1121static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1123{
1124 ARG_UNUSED(pkt);
1125 ARG_UNUSED(flags);
1126}
1127
1128static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1129{
1130 ARG_UNUSED(pkt);
1131
1132 return 0;
1133}
1134
1135static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1136 uint32_t id)
1137{
1138 ARG_UNUSED(pkt);
1139 ARG_UNUSED(id);
1140}
1141#endif /* CONFIG_NET_IPV6_FRAGMENT */
1142
1143static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1144{
1145 return !!(pkt->loopback);
1146}
1147
1148static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1149 bool loopback)
1150{
1151 pkt->loopback = loopback;
1152}
1153
1154#if defined(CONFIG_NET_IP_FRAGMENT)
1155static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1156{
1157 return !!(pkt->ip_reassembled);
1158}
1159
1160static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1161 bool reassembled)
1162{
1163 pkt->ip_reassembled = reassembled;
1164}
1165#else /* CONFIG_NET_IP_FRAGMENT */
1166static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1167{
1168 ARG_UNUSED(pkt);
1169
1170 return false;
1171}
1172
1173static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1174 bool reassembled)
1175{
1176 ARG_UNUSED(pkt);
1177 ARG_UNUSED(reassembled);
1178}
1179#endif /* CONFIG_NET_IP_FRAGMENT */
1180
1181static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1182{
1183 return pkt->priority;
1184}
1185
1186static inline void net_pkt_set_priority(struct net_pkt *pkt,
1187 uint8_t priority)
1188{
1189 pkt->priority = priority;
1190}
1191
1192#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1193static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1194{
1195 return pkt->cooked_mode_pkt;
1196}
1197
1198static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1199{
1200 pkt->cooked_mode_pkt = value;
1201}
1202#else
1203static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1204{
1205 ARG_UNUSED(pkt);
1206
1207 return false;
1208}
1209
1210static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1211{
1212 ARG_UNUSED(pkt);
1213 ARG_UNUSED(value);
1214}
1215#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1216
1217#if defined(CONFIG_NET_VLAN)
1218static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1219{
1220 return net_eth_vlan_get_vid(pkt->vlan_tci);
1221}
1222
1223static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1224{
1225 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1226}
1227
1228static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1229{
1230 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1231}
1232
1233static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1234 uint8_t priority)
1235{
1236 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1237}
1238
1239static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1240{
1241 return net_eth_vlan_get_dei(pkt->vlan_tci);
1242}
1243
1244static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1245{
1246 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1247}
1248
1249static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1250{
1251 pkt->vlan_tci = tci;
1252}
1253
1254static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1255{
1256 return pkt->vlan_tci;
1257}
1258#else
1259static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1260{
1261 ARG_UNUSED(pkt);
1262
1263 return NET_VLAN_TAG_UNSPEC;
1264}
1265
1266static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1267{
1268 ARG_UNUSED(pkt);
1269 ARG_UNUSED(tag);
1270}
1271
1272static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1273{
1274 ARG_UNUSED(pkt);
1275
1276 return 0;
1277}
1278
1279static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1280{
1281 ARG_UNUSED(pkt);
1282
1283 return false;
1284}
1285
1286static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1287{
1288 ARG_UNUSED(pkt);
1289 ARG_UNUSED(dei);
1290}
1291
1292static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1293{
1294 ARG_UNUSED(pkt);
1295
1296 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1297}
1298
1299static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1300{
1301 ARG_UNUSED(pkt);
1302 ARG_UNUSED(tci);
1303}
1304#endif
1305
1306#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1307static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1308{
1309 return &pkt->timestamp;
1310}
1311
1312static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1313 struct net_ptp_time *timestamp)
1314{
1315 pkt->timestamp.second = timestamp->second;
1316 pkt->timestamp.nanosecond = timestamp->nanosecond;
1317}
1318
1319static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1320{
1321 return net_ptp_time_to_ns(&pkt->timestamp);
1322}
1323
1324static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1325{
1326 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1327}
1328#else
1329static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1330{
1331 ARG_UNUSED(pkt);
1332
1333 return NULL;
1334}
1335
1336static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1337 struct net_ptp_time *timestamp)
1338{
1339 ARG_UNUSED(pkt);
1340 ARG_UNUSED(timestamp);
1341}
1342
1343static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1344{
1345 ARG_UNUSED(pkt);
1346
1347 return 0;
1348}
1349
1350static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1351{
1352 ARG_UNUSED(pkt);
1353 ARG_UNUSED(timestamp);
1354}
1355#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1356
1357#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1358 defined(CONFIG_TRACING_NET_CORE)
1359
1360static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1361{
1362 return pkt->create_time;
1363}
1364
1365static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1366 uint32_t create_time)
1367{
1368 pkt->create_time = create_time;
1369}
1370#else
1371static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1372{
1373 ARG_UNUSED(pkt);
1374
1375 return 0U;
1376}
1377
1378static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1379 uint32_t create_time)
1380{
1381 ARG_UNUSED(pkt);
1382 ARG_UNUSED(create_time);
1383}
1384#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1385 * CONFIG_TRACING_NET_CORE
1386 */
1387
1388#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1389 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1390static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1391{
1392 return pkt->detail.stat;
1393}
1394
1395static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1396{
1397 return pkt->detail.count;
1398}
1399
1400static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1401{
1402 memset(&pkt->detail, 0, sizeof(pkt->detail));
1403}
1404
1405static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1406 uint32_t tick)
1407{
1408 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1409 printk("ERROR: Detail stats count overflow (%d >= %d)",
1410 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1411 return;
1412 }
1413
1414 pkt->detail.stat[pkt->detail.count++] = tick;
1415}
1416
1417#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1418#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1419#else
1420static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1421{
1422 ARG_UNUSED(pkt);
1423
1424 return NULL;
1425}
1426
1427static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1428{
1429 ARG_UNUSED(pkt);
1430
1431 return 0;
1432}
1433
1434static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1435{
1436 ARG_UNUSED(pkt);
1437}
1438
1439static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1440{
1441 ARG_UNUSED(pkt);
1442 ARG_UNUSED(tick);
1443}
1444
1445#define net_pkt_set_tx_stats_tick(pkt, tick)
1446#define net_pkt_set_rx_stats_tick(pkt, tick)
1447#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1448 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1449
1450static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1451{
1452 return pkt->frags->data;
1453}
1454
1455static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1456{
1457 return pkt->frags->data;
1458}
1459
1460static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1461{
1462 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1463}
1464
1465static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1466{
1467 return &pkt->lladdr_src;
1468}
1469
1470static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1471{
1472 return &pkt->lladdr_dst;
1473}
1474
1475static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1476{
1477 struct net_linkaddr tmp;
1478
1479 memcpy(tmp.addr,
1480 net_pkt_lladdr_src(pkt)->addr,
1481 net_pkt_lladdr_src(pkt)->len);
1482 memcpy(net_pkt_lladdr_src(pkt)->addr,
1483 net_pkt_lladdr_dst(pkt)->addr,
1484 net_pkt_lladdr_dst(pkt)->len);
1485 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1486 tmp.addr,
1487 net_pkt_lladdr_src(pkt)->len);
1488}
1489
1490static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1491{
1492 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1493 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1494}
1495
1496static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1497{
1498 return pkt->ll_proto_type;
1499}
1500
1501static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1502{
1503 pkt->ll_proto_type = type;
1504}
1505
1506#if defined(CONFIG_NET_IPV4_ACD)
1507static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1508{
1509 return !!(pkt->ipv4_acd_arp_msg);
1510}
1511
1512static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1513 bool is_acd_arp_msg)
1514{
1515 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1516}
1517#else /* CONFIG_NET_IPV4_ACD */
1518static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1519{
1520 ARG_UNUSED(pkt);
1521
1522 return false;
1523}
1524
1525static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1526 bool is_acd_arp_msg)
1527{
1528 ARG_UNUSED(pkt);
1529 ARG_UNUSED(is_acd_arp_msg);
1530}
1531#endif /* CONFIG_NET_IPV4_ACD */
1532
1533#if defined(CONFIG_NET_L2_PPP)
1534static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1535{
1536 return !!(pkt->ppp_msg);
1537}
1538
1539static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1540 bool is_ppp_msg)
1541{
1542 pkt->ppp_msg = is_ppp_msg;
1543}
1544#else /* CONFIG_NET_L2_PPP */
1545static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1546{
1547 ARG_UNUSED(pkt);
1548
1549 return false;
1550}
1551
1552static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1553 bool is_ppp_msg)
1554{
1555 ARG_UNUSED(pkt);
1556 ARG_UNUSED(is_ppp_msg);
1557}
1558#endif /* CONFIG_NET_L2_PPP */
1559
1560#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1561static inline void *net_pkt_cb(struct net_pkt *pkt)
1562{
1563 return &pkt->cb;
1564}
1565#else
1566static inline void *net_pkt_cb(struct net_pkt *pkt)
1567{
1568 ARG_UNUSED(pkt);
1569
1570 return NULL;
1571}
1572#endif
1573
1574#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1575#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1576
1577static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1578{
1580 net_pkt_context(pkt)),
1581 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1582}
1583
1584static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1585{
1586 pkt->overwrite = overwrite;
1587}
1588
1589static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1590{
1591 return !!(pkt->overwrite);
1592}
1593
1594#ifdef CONFIG_NET_PKT_FILTER
1595
1596bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1597bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1598
1599#else
1600
1601static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1602{
1603 ARG_UNUSED(pkt);
1604
1605 return true;
1606}
1607
1608static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1609{
1610 ARG_UNUSED(pkt);
1611
1612 return true;
1613}
1614
1615#endif /* CONFIG_NET_PKT_FILTER */
1616
1617#if defined(CONFIG_NET_PKT_FILTER) && \
1618 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1619
1620bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1621
1622#else
1623
1624static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1625{
1626 ARG_UNUSED(pkt);
1627
1628 return true;
1629}
1630
1631#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1632
1633#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1634
1635bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1636
1637#else
1638
1639static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1640{
1641 ARG_UNUSED(pkt);
1642
1643 return true;
1644}
1645
1646#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1647
1648#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1649static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1650{
1651 return &pkt->remote;
1652}
1653
1654static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1655 struct net_sockaddr *address,
1656 net_socklen_t len)
1657{
1658 memcpy(&pkt->remote, address, len);
1659}
1660#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1661
1662/* @endcond */
1663
1677#define NET_PKT_SLAB_DEFINE(name, count) \
1678 K_MEM_SLAB_DEFINE_TYPE(name, struct net_pkt, count); \
1679 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1680
1682
1683/* Backward compatibility macro */
1684#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1685
1687
1701#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1702 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1703 0, NULL)
1704
1706
1707#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1708 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1709#define NET_PKT_DEBUG_ENABLED
1710#endif
1711
1712#if defined(NET_PKT_DEBUG_ENABLED)
1713
1714/* Debug versions of the net_pkt functions that are used when tracking
1715 * buffer usage.
1716 */
1717
1718struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1719 size_t min_len,
1720 k_timeout_t timeout,
1721 const char *caller,
1722 int line);
1723
1724#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1725 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1726
1727struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1728 k_timeout_t timeout,
1729 const char *caller,
1730 int line);
1731#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1732 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1733
1734struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1735 k_timeout_t timeout,
1736 const char *caller,
1737 int line);
1738#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1739 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1740
1741struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1742 k_timeout_t timeout,
1743 const char *caller, int line);
1744#define net_pkt_get_frag(pkt, min_len, timeout) \
1745 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1746
1747void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1748#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1749
1750struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1751 int line);
1752#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1753
1754struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1755 const char *caller, int line);
1756#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1757
1758void net_pkt_frag_unref_debug(struct net_buf *frag,
1759 const char *caller, int line);
1760#define net_pkt_frag_unref(frag) \
1761 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1762
1763struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1764 struct net_buf *parent,
1765 struct net_buf *frag,
1766 const char *caller, int line);
1767#define net_pkt_frag_del(pkt, parent, frag) \
1768 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1769
1770void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1771 const char *caller, int line);
1772#define net_pkt_frag_add(pkt, frag) \
1773 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1774
1775void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1776 const char *caller, int line);
1777#define net_pkt_frag_insert(pkt, frag) \
1778 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1779#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1780 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1781 */
1783
1784#if defined(NET_PKT_DEBUG_ENABLED)
1792void net_pkt_print_frags(struct net_pkt *pkt);
1793#else
1794#define net_pkt_print_frags(pkt)
1795#endif
1796
1797#if !defined(NET_PKT_DEBUG_ENABLED)
1813 size_t min_len, k_timeout_t timeout);
1814#endif
1815
1816#if !defined(NET_PKT_DEBUG_ENABLED)
1831struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1832#endif
1833
1834#if !defined(NET_PKT_DEBUG_ENABLED)
1849struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1850#endif
1851
1852#if !defined(NET_PKT_DEBUG_ENABLED)
1865struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1866 k_timeout_t timeout);
1867#endif
1868
1869#if !defined(NET_PKT_DEBUG_ENABLED)
1879void net_pkt_unref(struct net_pkt *pkt);
1880#endif
1881
1882#if !defined(NET_PKT_DEBUG_ENABLED)
1892struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1893#endif
1894
1895#if !defined(NET_PKT_DEBUG_ENABLED)
1905struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1906#endif
1907
1908#if !defined(NET_PKT_DEBUG_ENABLED)
1914void net_pkt_frag_unref(struct net_buf *frag);
1915#endif
1916
1917#if !defined(NET_PKT_DEBUG_ENABLED)
1929 struct net_buf *parent,
1930 struct net_buf *frag);
1931#endif
1932
1933#if !defined(NET_PKT_DEBUG_ENABLED)
1940void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1941#endif
1942
1943#if !defined(NET_PKT_DEBUG_ENABLED)
1950void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1951#endif
1952
1962void net_pkt_compact(struct net_pkt *pkt);
1963
1972void net_pkt_get_info(struct k_mem_slab **rx,
1973 struct k_mem_slab **tx,
1974 struct net_buf_pool **rx_data,
1975 struct net_buf_pool **tx_data);
1976
1978
1979#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1983void net_pkt_print(void);
1984
1985typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1986 struct net_buf *buf,
1987 const char *func_alloc,
1988 int line_alloc,
1989 const char *func_free,
1990 int line_free,
1991 bool in_use,
1992 void *user_data);
1993
1994void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1995
1996const char *net_pkt_slab2str(struct k_mem_slab *slab);
1997const char *net_pkt_pool2str(struct net_buf_pool *pool);
1998
1999#else
2000#define net_pkt_print(...)
2001#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
2002
2003/* New allocator, and API are defined below.
2004 * This will be simpler when time will come to get rid of former API above.
2005 */
2006#if defined(NET_PKT_DEBUG_ENABLED)
2007
2008struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
2009 const char *caller, int line);
2010#define net_pkt_alloc(_timeout) \
2011 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
2012
2013struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
2014 k_timeout_t timeout,
2015 const char *caller, int line);
2016#define net_pkt_alloc_from_slab(_slab, _timeout) \
2017 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
2018
2019struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
2020 const char *caller, int line);
2021#define net_pkt_rx_alloc(_timeout) \
2022 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
2023
2024struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
2025 k_timeout_t timeout,
2026 const char *caller,
2027 int line);
2028#define net_pkt_alloc_on_iface(_iface, _timeout) \
2029 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
2030
2031struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
2032 k_timeout_t timeout,
2033 const char *caller,
2034 int line);
2035#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
2036 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
2037 __func__, __LINE__)
2038
2039int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
2040 size_t size,
2041 enum net_ip_protocol proto,
2042 k_timeout_t timeout,
2043 const char *caller, int line);
2044#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
2045 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
2046 __func__, __LINE__)
2047
2048int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
2049 k_timeout_t timeout,
2050 const char *caller, int line);
2051#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
2052 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
2053 __func__, __LINE__)
2054
2055struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
2056 size_t size,
2057 net_sa_family_t family,
2058 enum net_ip_protocol proto,
2059 k_timeout_t timeout,
2060 const char *caller,
2061 int line);
2062#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
2063 _proto, _timeout) \
2064 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
2065 _proto, _timeout, \
2066 __func__, __LINE__)
2067
2068struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
2069 size_t size,
2070 net_sa_family_t family,
2071 enum net_ip_protocol proto,
2072 k_timeout_t timeout,
2073 const char *caller,
2074 int line);
2075#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
2076 _proto, _timeout) \
2077 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
2078 _proto, _timeout, \
2079 __func__, __LINE__)
2080
2081int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
2082 size_t size,
2083 size_t reserve,
2084 enum net_ip_protocol proto,
2085 k_timeout_t timeout,
2086 const char *caller,
2087 int line);
2088#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
2089 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
2090 _timeout, __func__, __LINE__)
2091
2092#endif /* NET_PKT_DEBUG_ENABLED */
2094
2095#if !defined(NET_PKT_DEBUG_ENABLED)
2107#endif
2108
2109#if !defined(NET_PKT_DEBUG_ENABLED)
2124struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2125 k_timeout_t timeout);
2126#endif
2127
2128#if !defined(NET_PKT_DEBUG_ENABLED)
2140#endif
2141
2142#if !defined(NET_PKT_DEBUG_ENABLED)
2152 k_timeout_t timeout);
2153
2155
2156/* Same as above but specifically for RX packet */
2157struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2158 k_timeout_t timeout);
2160
2161#endif
2162
2163#if !defined(NET_PKT_DEBUG_ENABLED)
2180 size_t size,
2181 enum net_ip_protocol proto,
2182 k_timeout_t timeout);
2183#endif
2184
2185#if !defined(NET_PKT_DEBUG_ENABLED)
2203#if !defined(NET_PKT_DEBUG_ENABLED)
2205 size_t size,
2206 size_t reserve,
2207 enum net_ip_protocol proto,
2208 k_timeout_t timeout);
2209#endif
2210
2224int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2225 k_timeout_t timeout);
2226#endif
2227
2228#if !defined(NET_PKT_DEBUG_ENABLED)
2241 size_t size,
2242 net_sa_family_t family,
2243 enum net_ip_protocol proto,
2244 k_timeout_t timeout);
2245
2247
2248/* Same as above but specifically for RX packet */
2249struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2250 size_t size,
2251 net_sa_family_t family,
2252 enum net_ip_protocol proto,
2253 k_timeout_t timeout);
2254
2256
2257#endif
2258
2265void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2266
2278
2295 enum net_ip_protocol proto);
2296
2306
2321int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2322
2331
2338static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2339 struct net_pkt_cursor *backup)
2340{
2341 backup->buf = pkt->cursor.buf;
2342 backup->pos = pkt->cursor.pos;
2343}
2344
2351static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2352 struct net_pkt_cursor *backup)
2353{
2354 pkt->cursor.buf = backup->buf;
2355 pkt->cursor.pos = backup->pos;
2356}
2357
2365static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2366{
2367 return pkt->cursor.pos;
2368}
2369
2387int net_pkt_skip(struct net_pkt *pkt, size_t length);
2388
2403int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2404
2418int net_pkt_copy(struct net_pkt *pkt_dst,
2419 struct net_pkt *pkt_src,
2420 size_t length);
2421
2431struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2432
2442struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2443
2453 k_timeout_t timeout);
2454
2468int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2469
2482static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2483{
2484 return net_pkt_read(pkt, data, 1);
2485}
2486
2499int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2500
2513int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2514
2527int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2528
2541int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2542
2555int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2556
2569int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2570
2584int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2585
2598static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2599{
2600 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2601}
2602
2615static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2616{
2617 uint16_t data_be16 = net_htons(data);
2618
2619 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2620}
2621
2634static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2635{
2636 uint32_t data_be32 = net_htonl(data);
2637
2638 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2639}
2640
2653static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2654{
2655 uint32_t data_le32 = sys_cpu_to_le32(data);
2656
2657 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2658}
2659
2672static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2673{
2674 uint16_t data_le16 = sys_cpu_to_le16(data);
2675
2676 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2677}
2678
2687
2695static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2696{
2697 return net_buf_frags_len(pkt->frags);
2698}
2699
2712int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2713
2732int net_pkt_pull(struct net_pkt *pkt, size_t length);
2733
2743
2755bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2756
2766
2768
2769struct net_pkt_data_access {
2770#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2771 void *data;
2772#endif
2773 const size_t size;
2774};
2775
2776#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2777#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2778 struct net_pkt_data_access _name = { \
2779 .size = sizeof(_type), \
2780 }
2781
2782#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2783 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2784
2785#else
2786#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2787 _type _hdr_##_name; \
2788 struct net_pkt_data_access _name = { \
2789 .data = &_hdr_##_name, \
2790 .size = sizeof(_type), \
2791 }
2792
2793#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2794 struct net_pkt_data_access _name = { \
2795 .data = NULL, \
2796 .size = sizeof(_type), \
2797 }
2798
2799#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2800
2802
2816void *net_pkt_get_data(struct net_pkt *pkt,
2817 struct net_pkt_data_access *access);
2818
2833 struct net_pkt_data_access *access);
2834
2839static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2840 struct net_pkt_data_access *access)
2841{
2842 return net_pkt_skip(pkt, access->size);
2843}
2844
2848
2849#ifdef __cplusplus
2850}
2851#endif
2852
2853#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
VLAN specific definitions.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
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:1124
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:3056
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:784
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1378
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:2501
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:2634
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:1794
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 the current cursor position.
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:2615
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:2695
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:2598
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:2365
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:2338
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:2839
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:2672
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:2351
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:2653
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:2482
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:44
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:166
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.
Header file for the logging core.
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:86
void printk(const char *fmt,...)
Print kernel debugging message.
Public functions for the Precision Time Protocol time specification.
int stat(const char *__restrict __path, struct stat *__restrict __sbuf)
__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:1199
Network buffer representation.
Definition net_buf.h:1062
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1152
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1173
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1155
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:207
Network Interface structure.
Definition net_if.h:875
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:462
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition byteorder.h:292
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:288