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) || 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; /* 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 /* Disable local IP fragmentation for this packet. */
404 uint8_t dont_fragment : 1;
405
406 /* @endcond */
407};
408
410
411/* The interface real ll address */
412static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
413{
414 return net_if_get_link_addr(pkt->iface);
415}
416
417static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
418{
419 return pkt->context;
420}
421
422static inline void net_pkt_set_context(struct net_pkt *pkt,
423 struct net_context *ctx)
424{
425 pkt->context = ctx;
426}
427
428static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
429{
430 return pkt->iface;
431}
432
433static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
434{
435 struct net_linkaddr *lladdr = net_if_get_link_addr(iface);
436
437 pkt->iface = iface;
438
439 /* If the network interface is set in pkt, then also set the type of
440 * the network address that is stored in pkt. This is done here so
441 * that the address type is properly set and is not forgotten.
442 */
443 if (lladdr != NULL) {
444 pkt->lladdr_src.type = lladdr->type;
445 pkt->lladdr_dst.type = lladdr->type;
446 }
447}
448
449static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
450{
451#if defined(CONFIG_NET_PKT_ORIG_IFACE)
452 return pkt->orig_iface;
453#else
454 return pkt->iface;
455#endif
456}
457
458static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
459 struct net_if *iface)
460{
461#if defined(CONFIG_NET_PKT_ORIG_IFACE)
462 pkt->orig_iface = iface;
463#else
464 ARG_UNUSED(pkt);
465 ARG_UNUSED(iface);
466#endif
467}
468
469#if defined(CONFIG_NET_VPN)
470static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
471{
472 return pkt->vpn.iface;
473}
474
475static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
476 struct net_if *iface)
477{
478 pkt->vpn.iface = iface;
479}
480
481static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
482{
483 return &pkt->vpn.ip_hdr;
484}
485
486static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
487 union net_ip_header *ip_hdr)
488{
489 pkt->vpn.ip_hdr = *ip_hdr;
490}
491
492static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
493{
494 return &pkt->vpn.proto_hdr;
495}
496
497static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
498 union net_proto_header *proto_hdr)
499{
500 pkt->vpn.proto_hdr = *proto_hdr;
501}
502
503static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
504{
505 return pkt->vpn.peer_id;
506}
507
508static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
509 int peer_id)
510{
511 pkt->vpn.peer_id = peer_id;
512}
513#endif /* CONFIG_NET_VPN */
514
515#if defined(CONFIG_NET_UDP_OPTIONS)
516static inline uint16_t net_pkt_udp_opt_surplus_len(struct net_pkt *pkt)
517{
518 return pkt->udp_opt_surplus_len;
519}
520
521static inline void net_pkt_set_udp_opt_surplus_len(struct net_pkt *pkt,
522 uint16_t len)
523{
524 pkt->udp_opt_surplus_len = len;
525}
526#else
527static inline uint16_t net_pkt_udp_opt_surplus_len(struct net_pkt *pkt)
528{
529 ARG_UNUSED(pkt);
530
531 return 0;
532}
533
534#define net_pkt_set_udp_opt_surplus_len(...)
535#endif /* CONFIG_NET_UDP_OPTIONS */
536
537static inline uint8_t net_pkt_family(struct net_pkt *pkt)
538{
539 return pkt->family;
540}
541
542static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
543{
544 pkt->family = family;
545}
546
547static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
548{
549#if defined(CONFIG_NET_PKT_TIMESTAMP)
550 return !!(pkt->tx_timestamping);
551#else
552 ARG_UNUSED(pkt);
553
554 return false;
555#endif
556}
557
558static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
559{
560#if defined(CONFIG_NET_PKT_TIMESTAMP)
561 pkt->tx_timestamping = is_timestamping;
562#else
563 ARG_UNUSED(pkt);
564 ARG_UNUSED(is_timestamping);
565#endif
566}
567
568static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
569{
570#if defined(CONFIG_NET_PKT_TIMESTAMP)
571 return !!(pkt->rx_timestamping);
572#else
573 ARG_UNUSED(pkt);
574
575 return false;
576#endif
577}
578
579static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
580{
581#if defined(CONFIG_NET_PKT_TIMESTAMP)
582 pkt->rx_timestamping = is_timestamping;
583#else
584 ARG_UNUSED(pkt);
585 ARG_UNUSED(is_timestamping);
586#endif
587}
588
589static inline bool net_pkt_is_captured(struct net_pkt *pkt)
590{
591 return !!(pkt->captured);
592}
593
594static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
595{
596 pkt->captured = is_captured;
597}
598
599static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
600{
601 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
602}
603
604static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
605{
606 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
607 pkt->l2_bridged = is_l2_bridged;
608 }
609}
610
611static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
612{
613 return !!(pkt->l2_processed);
614}
615
616static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
617 bool is_l2_processed)
618{
619 pkt->l2_processed = is_l2_processed;
620}
621
622static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
623{
624 return !!(pkt->chksum_done);
625}
626
627static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
628 bool is_chksum_done)
629{
630 pkt->chksum_done = is_chksum_done;
631}
632
633static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
634{
635#if defined(CONFIG_NET_IP)
636 return pkt->ip_hdr_len;
637#else
638 ARG_UNUSED(pkt);
639
640 return 0;
641#endif
642}
643
644static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
645{
646#if defined(CONFIG_NET_IP)
647 pkt->ip_hdr_len = len;
648#else
649 ARG_UNUSED(pkt);
650 ARG_UNUSED(len);
651#endif
652}
653
654static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
655{
656#if defined(CONFIG_NET_IP_DSCP_ECN)
657 return pkt->ip_dscp;
658#else
659 ARG_UNUSED(pkt);
660
661 return 0;
662#endif
663}
664
665static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
666{
667#if defined(CONFIG_NET_IP_DSCP_ECN)
668 pkt->ip_dscp = dscp;
669#else
670 ARG_UNUSED(pkt);
671 ARG_UNUSED(dscp);
672#endif
673}
674
675static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
676{
677#if defined(CONFIG_NET_IP_DSCP_ECN)
678 return pkt->ip_ecn;
679#else
680 ARG_UNUSED(pkt);
681
682 return 0;
683#endif
684}
685
686static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
687{
688#if defined(CONFIG_NET_IP_DSCP_ECN)
689 pkt->ip_ecn = ecn;
690#else
691 ARG_UNUSED(pkt);
692 ARG_UNUSED(ecn);
693#endif
694}
695
696static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
697{
698 return pkt->eof;
699}
700
701static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
702{
703 pkt->eof = eof;
704}
705
706static inline bool net_pkt_forwarding(struct net_pkt *pkt)
707{
708 return !!(pkt->forwarding);
709}
710
711static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
712{
713 pkt->forwarding = forward;
714}
715
716#if defined(CONFIG_NET_IPV4)
717static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
718{
719 return pkt->ipv4_ttl;
720}
721
722static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
723 uint8_t ttl)
724{
725 pkt->ipv4_ttl = ttl;
726}
727
728static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
729{
730 return pkt->ipv4_opts_len;
731}
732
733static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
734 uint8_t opts_len)
735{
736 pkt->ipv4_opts_len = opts_len;
737}
738#else
739static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
740{
741 ARG_UNUSED(pkt);
742
743 return 0;
744}
745
746static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
747 uint8_t ttl)
748{
749 ARG_UNUSED(pkt);
750 ARG_UNUSED(ttl);
751}
752
753static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
754{
755 ARG_UNUSED(pkt);
756 return 0;
757}
758
759static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
760 uint8_t opts_len)
761{
762 ARG_UNUSED(pkt);
763 ARG_UNUSED(opts_len);
764}
765#endif
766
767#if defined(CONFIG_NET_IPV6)
768static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
769{
770 return pkt->ipv6_ext_opt_len;
771}
772
773static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
774 uint8_t len)
775{
776 pkt->ipv6_ext_opt_len = len;
777}
778
779static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
780{
781 return pkt->ipv6_next_hdr;
782}
783
784static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
785 uint8_t next_hdr)
786{
787 pkt->ipv6_next_hdr = next_hdr;
788}
789
790static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
791{
792 return pkt->ipv6_ext_len;
793}
794
795static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
796{
797 pkt->ipv6_ext_len = len;
798}
799
800static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
801{
802 return pkt->ipv6_prev_hdr_start;
803}
804
805static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
806 uint16_t offset)
807{
808 pkt->ipv6_prev_hdr_start = offset;
809}
810
811static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
812{
813 return pkt->ipv6_hop_limit;
814}
815
816static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
817 uint8_t hop_limit)
818{
819 pkt->ipv6_hop_limit = hop_limit;
820}
821#else /* CONFIG_NET_IPV6 */
822static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
823{
824 ARG_UNUSED(pkt);
825
826 return 0;
827}
828
829static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
830 uint8_t len)
831{
832 ARG_UNUSED(pkt);
833 ARG_UNUSED(len);
834}
835
836static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
837{
838 ARG_UNUSED(pkt);
839
840 return 0;
841}
842
843static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
844 uint8_t next_hdr)
845{
846 ARG_UNUSED(pkt);
847 ARG_UNUSED(next_hdr);
848}
849
850static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
851{
852 ARG_UNUSED(pkt);
853
854 return 0;
855}
856
857static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
858{
859 ARG_UNUSED(pkt);
860 ARG_UNUSED(len);
861}
862
863static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
864{
865 ARG_UNUSED(pkt);
866
867 return 0;
868}
869
870static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
871 uint16_t offset)
872{
873 ARG_UNUSED(pkt);
874 ARG_UNUSED(offset);
875}
876
877static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
878{
879 ARG_UNUSED(pkt);
880
881 return 0;
882}
883
884static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
885 uint8_t hop_limit)
886{
887 ARG_UNUSED(pkt);
888 ARG_UNUSED(hop_limit);
889}
890#endif /* CONFIG_NET_IPV6 */
891
892static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
893{
894#if defined(CONFIG_NET_IPV6)
895 return pkt->ipv6_ext_len;
896#elif defined(CONFIG_NET_IPV4)
897 return pkt->ipv4_opts_len;
898#else
899 ARG_UNUSED(pkt);
900
901 return 0;
902#endif
903}
904
905#if defined(CONFIG_NET_IPV4_PMTU)
906static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
907{
908 return !!pkt->ipv4_pmtu;
909}
910
911static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
912{
913 pkt->ipv4_pmtu = value;
914}
915#else
916static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
917{
918 ARG_UNUSED(pkt);
919
920 return false;
921}
922
923static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
924{
925 ARG_UNUSED(pkt);
926 ARG_UNUSED(value);
927}
928#endif /* CONFIG_NET_IPV4_PMTU */
929
930#if defined(CONFIG_NET_IPV4_ROUTE)
931static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
932{
933 return pkt->ipv4_ll_resolve_addr_set ? &pkt->ipv4_ll_resolve_addr : NULL;
934}
935
936static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
937 const struct net_in_addr *addr)
938{
939 if (addr != NULL) {
940 net_ipaddr_copy(&pkt->ipv4_ll_resolve_addr, addr);
941 pkt->ipv4_ll_resolve_addr_set = 1U;
942 } else {
943 pkt->ipv4_ll_resolve_addr_set = 0U;
944 }
945}
946#else
947static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
948{
949 ARG_UNUSED(pkt);
950
951 return NULL;
952}
953
954static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
955 const struct net_in_addr *addr)
956{
957 ARG_UNUSED(pkt);
958 ARG_UNUSED(addr);
959}
960#endif /* CONFIG_NET_IPV4_ROUTE */
961
962static inline bool net_pkt_dont_fragment(struct net_pkt *pkt)
963{
964 return !!pkt->dont_fragment;
965}
966
967static inline void net_pkt_set_dont_fragment(struct net_pkt *pkt, bool value)
968{
969 pkt->dont_fragment = value;
970}
971
972#if defined(CONFIG_NET_IPV4_FRAGMENT)
973static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
974{
975 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
976}
977
978static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
979{
980 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
981}
982
983static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
984{
985 pkt->ipv4_fragment.flags = flags;
986}
987
988static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
989{
990 return pkt->ipv4_fragment.id;
991}
992
993static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
994{
995 pkt->ipv4_fragment.id = id;
996}
997#else /* CONFIG_NET_IPV4_FRAGMENT */
998static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
999{
1000 ARG_UNUSED(pkt);
1001
1002 return 0;
1003}
1004
1005static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
1006{
1007 ARG_UNUSED(pkt);
1008
1009 return 0;
1010}
1011
1012static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
1013{
1014 ARG_UNUSED(pkt);
1015 ARG_UNUSED(flags);
1016}
1017
1018static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
1019{
1020 ARG_UNUSED(pkt);
1021
1022 return 0;
1023}
1024
1025static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
1026{
1027 ARG_UNUSED(pkt);
1028 ARG_UNUSED(id);
1029}
1030#endif /* CONFIG_NET_IPV4_FRAGMENT */
1031
1032#if defined(CONFIG_NET_IPV6_FRAGMENT)
1033static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1034{
1035 return pkt->ipv6_fragment.hdr_start;
1036}
1037
1038static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1039 uint16_t start)
1040{
1041 pkt->ipv6_fragment.hdr_start = start;
1042}
1043
1044static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1045{
1046 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
1047}
1048static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1049{
1050 return (pkt->ipv6_fragment.flags & 0x01) != 0;
1051}
1052
1053static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1055{
1056 pkt->ipv6_fragment.flags = flags;
1057}
1058
1059static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1060{
1061 return pkt->ipv6_fragment.id;
1062}
1063
1064static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1065 uint32_t id)
1066{
1067 pkt->ipv6_fragment.id = id;
1068}
1069#else /* CONFIG_NET_IPV6_FRAGMENT */
1070static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1071{
1072 ARG_UNUSED(pkt);
1073
1074 return 0;
1075}
1076
1077static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1078 uint16_t start)
1079{
1080 ARG_UNUSED(pkt);
1081 ARG_UNUSED(start);
1082}
1083
1084static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1085{
1086 ARG_UNUSED(pkt);
1087
1088 return 0;
1089}
1090
1091static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1092{
1093 ARG_UNUSED(pkt);
1094
1095 return 0;
1096}
1097
1098static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1100{
1101 ARG_UNUSED(pkt);
1102 ARG_UNUSED(flags);
1103}
1104
1105static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1106{
1107 ARG_UNUSED(pkt);
1108
1109 return 0;
1110}
1111
1112static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1113 uint32_t id)
1114{
1115 ARG_UNUSED(pkt);
1116 ARG_UNUSED(id);
1117}
1118#endif /* CONFIG_NET_IPV6_FRAGMENT */
1119
1120static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1121{
1122 return !!(pkt->loopback);
1123}
1124
1125static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1126 bool loopback)
1127{
1128 pkt->loopback = loopback;
1129}
1130
1131#if defined(CONFIG_NET_IP_FRAGMENT)
1132static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1133{
1134 return !!(pkt->ip_reassembled);
1135}
1136
1137static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1138 bool reassembled)
1139{
1140 pkt->ip_reassembled = reassembled;
1141}
1142#else /* CONFIG_NET_IP_FRAGMENT */
1143static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1144{
1145 ARG_UNUSED(pkt);
1146
1147 return false;
1148}
1149
1150static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1151 bool reassembled)
1152{
1153 ARG_UNUSED(pkt);
1154 ARG_UNUSED(reassembled);
1155}
1156#endif /* CONFIG_NET_IP_FRAGMENT */
1157
1158static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1159{
1160 return pkt->priority;
1161}
1162
1163static inline void net_pkt_set_priority(struct net_pkt *pkt,
1164 uint8_t priority)
1165{
1166 pkt->priority = priority;
1167}
1168
1169#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1170static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1171{
1172 return pkt->cooked_mode_pkt;
1173}
1174
1175static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1176{
1177 pkt->cooked_mode_pkt = value;
1178}
1179#else
1180static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1181{
1182 ARG_UNUSED(pkt);
1183
1184 return false;
1185}
1186
1187static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1188{
1189 ARG_UNUSED(pkt);
1190 ARG_UNUSED(value);
1191}
1192#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1193
1194#if defined(CONFIG_NET_VLAN)
1195static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1196{
1197 return net_eth_vlan_get_vid(pkt->vlan_tci);
1198}
1199
1200static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1201{
1202 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1203}
1204
1205static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1206{
1207 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1208}
1209
1210static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1211 uint8_t priority)
1212{
1213 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1214}
1215
1216static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1217{
1218 return net_eth_vlan_get_dei(pkt->vlan_tci);
1219}
1220
1221static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1222{
1223 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1224}
1225
1226static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1227{
1228 pkt->vlan_tci = tci;
1229}
1230
1231static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1232{
1233 return pkt->vlan_tci;
1234}
1235#else
1236static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1237{
1238 ARG_UNUSED(pkt);
1239
1240 return NET_VLAN_TAG_UNSPEC;
1241}
1242
1243static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1244{
1245 ARG_UNUSED(pkt);
1246 ARG_UNUSED(tag);
1247}
1248
1249static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1250{
1251 ARG_UNUSED(pkt);
1252
1253 return 0;
1254}
1255
1256static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1257{
1258 ARG_UNUSED(pkt);
1259
1260 return false;
1261}
1262
1263static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1264{
1265 ARG_UNUSED(pkt);
1266 ARG_UNUSED(dei);
1267}
1268
1269static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1270{
1271 ARG_UNUSED(pkt);
1272
1273 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1274}
1275
1276static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1277{
1278 ARG_UNUSED(pkt);
1279 ARG_UNUSED(tci);
1280}
1281#endif
1282
1283#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1284static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1285{
1286 return &pkt->timestamp;
1287}
1288
1289static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1290 struct net_ptp_time *timestamp)
1291{
1292 pkt->timestamp.second = timestamp->second;
1293 pkt->timestamp.nanosecond = timestamp->nanosecond;
1294}
1295
1296static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1297{
1298 return net_ptp_time_to_ns(&pkt->timestamp);
1299}
1300
1301static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1302{
1303 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1304}
1305#else
1306static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1307{
1308 ARG_UNUSED(pkt);
1309
1310 return NULL;
1311}
1312
1313static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1314 struct net_ptp_time *timestamp)
1315{
1316 ARG_UNUSED(pkt);
1317 ARG_UNUSED(timestamp);
1318}
1319
1320static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1321{
1322 ARG_UNUSED(pkt);
1323
1324 return 0;
1325}
1326
1327static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1328{
1329 ARG_UNUSED(pkt);
1330 ARG_UNUSED(timestamp);
1331}
1332#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1333
1334#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1335 defined(CONFIG_TRACING_NET_CORE)
1336
1337static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1338{
1339 return pkt->create_time;
1340}
1341
1342static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1343 uint32_t create_time)
1344{
1345 pkt->create_time = create_time;
1346}
1347#else
1348static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1349{
1350 ARG_UNUSED(pkt);
1351
1352 return 0U;
1353}
1354
1355static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1356 uint32_t create_time)
1357{
1358 ARG_UNUSED(pkt);
1359 ARG_UNUSED(create_time);
1360}
1361#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1362 * CONFIG_TRACING_NET_CORE
1363 */
1364
1365#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1366 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1367static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1368{
1369 return pkt->detail.stat;
1370}
1371
1372static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1373{
1374 return pkt->detail.count;
1375}
1376
1377static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1378{
1379 memset(&pkt->detail, 0, sizeof(pkt->detail));
1380}
1381
1382static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1383 uint32_t tick)
1384{
1385 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1386 printk("ERROR: Detail stats count overflow (%d >= %d)",
1387 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1388 return;
1389 }
1390
1391 pkt->detail.stat[pkt->detail.count++] = tick;
1392}
1393
1394#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1395#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1396#else
1397static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1398{
1399 ARG_UNUSED(pkt);
1400
1401 return NULL;
1402}
1403
1404static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1405{
1406 ARG_UNUSED(pkt);
1407
1408 return 0;
1409}
1410
1411static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1412{
1413 ARG_UNUSED(pkt);
1414}
1415
1416static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1417{
1418 ARG_UNUSED(pkt);
1419 ARG_UNUSED(tick);
1420}
1421
1422#define net_pkt_set_tx_stats_tick(pkt, tick)
1423#define net_pkt_set_rx_stats_tick(pkt, tick)
1424#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1425 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1426
1427static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1428{
1429 return pkt->frags->data;
1430}
1431
1432static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1433{
1434 return pkt->frags->data;
1435}
1436
1437static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1438{
1439 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1440}
1441
1442static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1443{
1444 return &pkt->lladdr_src;
1445}
1446
1447static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1448{
1449 return &pkt->lladdr_dst;
1450}
1451
1452static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1453{
1454 struct net_linkaddr tmp;
1455
1456 memcpy(tmp.addr,
1457 net_pkt_lladdr_src(pkt)->addr,
1458 net_pkt_lladdr_src(pkt)->len);
1459 memcpy(net_pkt_lladdr_src(pkt)->addr,
1460 net_pkt_lladdr_dst(pkt)->addr,
1461 net_pkt_lladdr_dst(pkt)->len);
1462 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1463 tmp.addr,
1464 net_pkt_lladdr_src(pkt)->len);
1465}
1466
1467static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1468{
1469 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1470 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1471}
1472
1473static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1474{
1475 return pkt->ll_proto_type;
1476}
1477
1478static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1479{
1480 pkt->ll_proto_type = type;
1481}
1482
1483#if defined(CONFIG_NET_IPV4_ACD)
1484static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1485{
1486 return !!(pkt->ipv4_acd_arp_msg);
1487}
1488
1489static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1490 bool is_acd_arp_msg)
1491{
1492 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1493}
1494#else /* CONFIG_NET_IPV4_ACD */
1495static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1496{
1497 ARG_UNUSED(pkt);
1498
1499 return false;
1500}
1501
1502static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1503 bool is_acd_arp_msg)
1504{
1505 ARG_UNUSED(pkt);
1506 ARG_UNUSED(is_acd_arp_msg);
1507}
1508#endif /* CONFIG_NET_IPV4_ACD */
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
1939void net_pkt_compact(struct net_pkt *pkt);
1940
1949void net_pkt_get_info(struct k_mem_slab **rx,
1950 struct k_mem_slab **tx,
1951 struct net_buf_pool **rx_data,
1952 struct net_buf_pool **tx_data);
1953
1955
1956#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1960void net_pkt_print(void);
1961
1962typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1963 struct net_buf *buf,
1964 const char *func_alloc,
1965 int line_alloc,
1966 const char *func_free,
1967 int line_free,
1968 bool in_use,
1969 void *user_data);
1970
1971void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1972
1973const char *net_pkt_slab2str(struct k_mem_slab *slab);
1974const char *net_pkt_pool2str(struct net_buf_pool *pool);
1975
1976#else
1977#define net_pkt_print(...)
1978#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1979
1980/* New allocator, and API are defined below.
1981 * This will be simpler when time will come to get rid of former API above.
1982 */
1983#if defined(NET_PKT_DEBUG_ENABLED)
1984
1985struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1986 const char *caller, int line);
1987#define net_pkt_alloc(_timeout) \
1988 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1989
1990struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1991 k_timeout_t timeout,
1992 const char *caller, int line);
1993#define net_pkt_alloc_from_slab(_slab, _timeout) \
1994 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1995
1996struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1997 const char *caller, int line);
1998#define net_pkt_rx_alloc(_timeout) \
1999 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
2000
2001struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
2002 k_timeout_t timeout,
2003 const char *caller,
2004 int line);
2005#define net_pkt_alloc_on_iface(_iface, _timeout) \
2006 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
2007
2008struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
2009 k_timeout_t timeout,
2010 const char *caller,
2011 int line);
2012#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
2013 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
2014 __func__, __LINE__)
2015
2016int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
2017 size_t size,
2018 enum net_ip_protocol proto,
2019 k_timeout_t timeout,
2020 const char *caller, int line);
2021#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
2022 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
2023 __func__, __LINE__)
2024
2025int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
2026 k_timeout_t timeout,
2027 const char *caller, int line);
2028#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
2029 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
2030 __func__, __LINE__)
2031
2032struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
2033 size_t size,
2034 net_sa_family_t family,
2035 enum net_ip_protocol proto,
2036 k_timeout_t timeout,
2037 const char *caller,
2038 int line);
2039#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
2040 _proto, _timeout) \
2041 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
2042 _proto, _timeout, \
2043 __func__, __LINE__)
2044
2045struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
2046 size_t size,
2047 net_sa_family_t family,
2048 enum net_ip_protocol proto,
2049 k_timeout_t timeout,
2050 const char *caller,
2051 int line);
2052#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
2053 _proto, _timeout) \
2054 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
2055 _proto, _timeout, \
2056 __func__, __LINE__)
2057
2058int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
2059 size_t size,
2060 size_t reserve,
2061 enum net_ip_protocol proto,
2062 k_timeout_t timeout,
2063 const char *caller,
2064 int line);
2065#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
2066 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
2067 _timeout, __func__, __LINE__)
2068
2069#endif /* NET_PKT_DEBUG_ENABLED */
2071
2072#if !defined(NET_PKT_DEBUG_ENABLED)
2084#endif
2085
2086#if !defined(NET_PKT_DEBUG_ENABLED)
2101struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2102 k_timeout_t timeout);
2103#endif
2104
2105#if !defined(NET_PKT_DEBUG_ENABLED)
2117#endif
2118
2119#if !defined(NET_PKT_DEBUG_ENABLED)
2129 k_timeout_t timeout);
2130
2132
2133/* Same as above but specifically for RX packet */
2134struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2135 k_timeout_t timeout);
2137
2138#endif
2139
2140#if !defined(NET_PKT_DEBUG_ENABLED)
2157 size_t size,
2158 enum net_ip_protocol proto,
2159 k_timeout_t timeout);
2160#endif
2161
2162#if !defined(NET_PKT_DEBUG_ENABLED)
2180#if !defined(NET_PKT_DEBUG_ENABLED)
2182 size_t size,
2183 size_t reserve,
2184 enum net_ip_protocol proto,
2185 k_timeout_t timeout);
2186#endif
2187
2201int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2202 k_timeout_t timeout);
2203#endif
2204
2205#if !defined(NET_PKT_DEBUG_ENABLED)
2218 size_t size,
2219 net_sa_family_t family,
2220 enum net_ip_protocol proto,
2221 k_timeout_t timeout);
2222
2224
2225/* Same as above but specifically for RX packet */
2226struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2227 size_t size,
2228 net_sa_family_t family,
2229 enum net_ip_protocol proto,
2230 k_timeout_t timeout);
2231
2233
2234#endif
2235
2242void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2243
2255
2272 enum net_ip_protocol proto);
2273
2283
2298int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2299
2308
2315static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2316 struct net_pkt_cursor *backup)
2317{
2318 backup->buf = pkt->cursor.buf;
2319 backup->pos = pkt->cursor.pos;
2320}
2321
2328static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2329 struct net_pkt_cursor *backup)
2330{
2331 pkt->cursor.buf = backup->buf;
2332 pkt->cursor.pos = backup->pos;
2333}
2334
2342static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2343{
2344 return pkt->cursor.pos;
2345}
2346
2364int net_pkt_skip(struct net_pkt *pkt, size_t length);
2365
2380int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2381
2395int net_pkt_copy(struct net_pkt *pkt_dst,
2396 struct net_pkt *pkt_src,
2397 size_t length);
2398
2408struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2409
2419struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2420
2430 k_timeout_t timeout);
2431
2445int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2446
2459static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2460{
2461 return net_pkt_read(pkt, data, 1);
2462}
2463
2476int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2477
2490int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2491
2504int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2505
2518int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2519
2532int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2533
2546int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2547
2561int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2562
2575static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2576{
2577 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2578}
2579
2592static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2593{
2594 uint16_t data_be16 = net_htons(data);
2595
2596 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2597}
2598
2611static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2612{
2613 uint32_t data_be32 = net_htonl(data);
2614
2615 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2616}
2617
2630static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2631{
2632 uint32_t data_le32 = sys_cpu_to_le32(data);
2633
2634 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2635}
2636
2649static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2650{
2651 uint16_t data_le16 = sys_cpu_to_le16(data);
2652
2653 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2654}
2655
2664
2672static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2673{
2674 return net_buf_frags_len(pkt->frags);
2675}
2676
2689int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2690
2709int net_pkt_pull(struct net_pkt *pkt, size_t length);
2710
2720
2732bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2733
2743
2745
2746struct net_pkt_data_access {
2747#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2748 void *data;
2749#endif
2750 const size_t size;
2751};
2752
2753#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2754#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2755 struct net_pkt_data_access _name = { \
2756 .size = sizeof(_type), \
2757 }
2758
2759#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2760 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2761
2762#else
2763#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2764 _type _hdr_##_name; \
2765 struct net_pkt_data_access _name = { \
2766 .data = &_hdr_##_name, \
2767 .size = sizeof(_type), \
2768 }
2769
2770#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2771 struct net_pkt_data_access _name = { \
2772 .data = NULL, \
2773 .size = sizeof(_type), \
2774 }
2775
2776#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2777
2779
2793void *net_pkt_get_data(struct net_pkt *pkt,
2794 struct net_pkt_data_access *access);
2795
2810 struct net_pkt_data_access *access);
2811
2816static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2817 struct net_pkt_data_access *access)
2818{
2819 return net_pkt_skip(pkt, access->size);
2820}
2821
2825
2826#ifdef __cplusplus
2827}
2828#endif
2829
2830#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
VLAN specific definitions.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
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:1117
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:2905
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:1300
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:2374
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:2611
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 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:2592
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:2672
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:2575
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:2342
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:2315
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:2816
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:2649
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:2328
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:2630
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:2459
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: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.
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:97
static void printk(const char *fmt,...)
Print kernel debugging message.
Definition printk.h:64
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:1184
Network buffer representation.
Definition net_buf.h:1048
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1137
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1158
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1140
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:764
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:455
#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