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