Zephyr Project API 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_IPV4_ROUTING) || defined(CONFIG_NET_IPV6_ROUTING) || \
151 defined(CONFIG_NET_ETHERNET_BRIDGE)
152 struct net_if *orig_iface; /* Original network interface */
153#endif
154
155#if defined(CONFIG_NET_VPN)
156 struct {
158 struct net_if *iface;
160 union net_ip_header ip_hdr;
162 union net_proto_header proto_hdr;
164 int peer_id;
165 } vpn;
166#endif
167
168#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
187 struct net_ptp_time timestamp;
188#endif
189
190#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
191 defined(CONFIG_TRACING_NET_CORE)
192 struct {
194 uint32_t create_time;
195
196#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
197 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
203 struct {
204 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
205 int count;
206 } detail;
207#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
208 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
209 };
210#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
211
212#if defined(CONFIG_NET_PKT_ALLOC_STATS)
213 struct net_pkt_alloc_stats_slab *alloc_stats;
214#endif /* CONFIG_NET_PKT_ALLOC_STATS */
215
217 atomic_t atomic_ref;
218
219 /* Filled by layer 2 when network packet is received. */
220 struct net_linkaddr lladdr_src;
221 struct net_linkaddr lladdr_dst;
222 uint16_t ll_proto_type;
223
224#if defined(CONFIG_NET_IP)
225 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
226#endif
227
228 uint8_t overwrite : 1; /* Is packet content being overwritten? */
229 uint8_t eof : 1; /* Last packet before EOF */
230 uint8_t ptp_pkt : 1; /* For outgoing packet: is this packet
231 * a L2 PTP packet.
232 * Used only if defined (CONFIG_NET_L2_PTP)
233 */
234 uint8_t forwarding : 1; /* Are we forwarding this pkt
235 * Used only if defined(CONFIG_NET_IPV6_ROUTE)
236 */
237 uint8_t family : 3; /* Address family, see net_ip.h */
238
239 /* bitfield byte alignment boundary */
240
241#if defined(CONFIG_NET_IPV4_ACD)
242 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
243 * message.
244 * Note: family needs to be
245 * NET_AF_INET.
246 */
247#endif
248#if defined(CONFIG_NET_LLDP)
249 uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
250 * Note: family needs to be
251 * NET_AF_UNSPEC.
252 */
253#endif
254 uint8_t ppp_msg : 1; /* This is a PPP message */
255 uint8_t captured : 1; /* Set to 1 if this packet is already being
256 * captured
257 */
258 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
259 * and already contains its L2 header to be
260 * preserved. Useful only if
261 * defined(CONFIG_NET_ETHERNET_BRIDGE).
262 */
263 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
264 * processed by the L2
265 */
266 uint8_t chksum_done : 1; /* Checksum has already been computed for
267 * the packet.
268 */
269 uint8_t loopback : 1; /* Packet is a loop back packet. */
270#if defined(CONFIG_NET_IP_FRAGMENT)
271 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
272#endif
273#if defined(CONFIG_NET_PKT_TIMESTAMP)
274 uint8_t tx_timestamping : 1;
275 uint8_t rx_timestamping : 1;
276#endif
277 /* bitfield byte alignment boundary */
278
279#if defined(CONFIG_NET_IP)
280 union {
281 /* IPv6 hop limit or IPv4 ttl for this network packet.
282 * The value is shared between IPv6 and IPv4.
283 */
284#if defined(CONFIG_NET_IPV6)
285 uint8_t ipv6_hop_limit;
286#endif
287#if defined(CONFIG_NET_IPV4)
288 uint8_t ipv4_ttl;
289#endif
290 };
291
292 union {
293#if defined(CONFIG_NET_IPV4)
294 uint8_t ipv4_opts_len; /* length of IPv4 header options */
295#endif
296#if defined(CONFIG_NET_IPV6)
297 uint16_t ipv6_ext_len; /* length of extension headers */
298#endif
299 };
300
301#if defined(CONFIG_NET_IPV4_ROUTE)
302 /* IPv4 address that should be resolved at L2 for transmission.
303 * Routed packets use this to steer link-layer resolution towards the
304 * next on-link IPv4 address.
305 */
306 struct net_in_addr ipv4_ll_resolve_addr;
307#endif /* CONFIG_NET_IPV4_ROUTE */
308
309#if defined(CONFIG_NET_IP_FRAGMENT)
310 union {
311#if defined(CONFIG_NET_IPV4_FRAGMENT)
312 struct {
313 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
314 uint16_t id; /* Fragment ID */
315 } ipv4_fragment;
316#endif /* CONFIG_NET_IPV4_FRAGMENT */
317#if defined(CONFIG_NET_IPV6_FRAGMENT)
318 struct {
319 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
320 uint32_t id; /* Fragment id */
321 uint16_t hdr_start; /* Where starts the fragment header */
322 } ipv6_fragment;
323#endif /* CONFIG_NET_IPV6_FRAGMENT */
324 };
325#endif /* CONFIG_NET_IP_FRAGMENT */
326
327#if defined(CONFIG_NET_IPV6)
328 /* Where is the start of the last header before payload data
329 * in IPv6 packet. This is offset value from start of the IPv6
330 * packet. Note that this value should be updated by who ever
331 * adds IPv6 extension headers to the network packet.
332 */
333 uint16_t ipv6_prev_hdr_start;
334
335 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
336 uint8_t ipv6_next_hdr; /* What is the very first next header */
337#endif /* CONFIG_NET_IPV6 */
338
339#if defined(CONFIG_NET_IP_DSCP_ECN)
341 uint8_t ip_dscp : 6;
342
344 uint8_t ip_ecn : 2;
345#endif /* CONFIG_NET_IP_DSCP_ECN */
346#endif /* CONFIG_NET_IP */
347
348#if defined(CONFIG_NET_VLAN)
349 /* VLAN TCI (Tag Control Information). This contains the Priority
350 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
351 * Identifier (VID, called more commonly VLAN tag). This value is
352 * kept in host byte order.
353 */
354 uint16_t vlan_tci;
355#endif /* CONFIG_NET_VLAN */
356
357#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
358 /* Control block which could be used by any layer */
359 union {
360 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
361#if defined(CONFIG_IEEE802154)
362 /* The following structure requires a 4-byte alignment
363 * boundary to avoid padding.
364 */
365 struct net_pkt_cb_ieee802154 cb_ieee802154;
366#endif /* CONFIG_IEEE802154 */
367 } cb;
368#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
369
373 uint8_t priority;
374
375#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
376 /* Remote address of the received packet. This is only used by
377 * network interfaces with an offloaded TCP/IP stack, or if we
378 * have network tunneling in use.
379 */
380 union {
381 struct net_sockaddr remote;
382
383 /* This will make sure that there is enough storage to store
384 * the address struct. The access to value is via remote
385 * address.
386 */
387 struct net_sockaddr_storage remote_storage;
388 };
389#endif /* CONFIG_NET_OFFLOAD */
390
391#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
392 /* Tell the capture api that this is a captured packet */
393 uint8_t cooked_mode_pkt : 1;
394#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
395
396#if defined(CONFIG_NET_IPV4_PMTU)
397 /* Path MTU needed for this destination address */
398 uint8_t ipv4_pmtu : 1;
399#endif /* CONFIG_NET_IPV4_PMTU */
400#if defined(CONFIG_NET_IPV4_ROUTE)
401 uint8_t ipv4_ll_resolve_addr_set : 1;
402#endif /* CONFIG_NET_IPV4_ROUTE */
403
404 /* @endcond */
405};
406
408
409/* The interface real ll address */
410static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
411{
412 return net_if_get_link_addr(pkt->iface);
413}
414
415static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
416{
417 return pkt->context;
418}
419
420static inline void net_pkt_set_context(struct net_pkt *pkt,
421 struct net_context *ctx)
422{
423 pkt->context = ctx;
424}
425
426static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
427{
428 return pkt->iface;
429}
430
431static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
432{
433 pkt->iface = iface;
434
435 /* If the network interface is set in pkt, then also set the type of
436 * the network address that is stored in pkt. This is done here so
437 * that the address type is properly set and is not forgotten.
438 */
439 if (iface) {
440 uint8_t type = net_if_get_link_addr(iface)->type;
441
442 pkt->lladdr_src.type = type;
443 pkt->lladdr_dst.type = type;
444 }
445}
446
447static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
448{
449#if defined(CONFIG_NET_IPV4_ROUTING) || defined(CONFIG_NET_IPV6_ROUTING) || \
450 defined(CONFIG_NET_ETHERNET_BRIDGE)
451 return pkt->orig_iface;
452#else
453 return pkt->iface;
454#endif
455}
456
457static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
458 struct net_if *iface)
459{
460#if defined(CONFIG_NET_IPV4_ROUTING) || defined(CONFIG_NET_IPV6_ROUTING) || \
461 defined(CONFIG_NET_ETHERNET_BRIDGE)
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
950#if defined(CONFIG_NET_IPV4_FRAGMENT)
951static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
952{
953 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
954}
955
956static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
957{
958 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
959}
960
961static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
962{
963 pkt->ipv4_fragment.flags = flags;
964}
965
966static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
967{
968 return pkt->ipv4_fragment.id;
969}
970
971static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
972{
973 pkt->ipv4_fragment.id = id;
974}
975#else /* CONFIG_NET_IPV4_FRAGMENT */
976static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
977{
978 ARG_UNUSED(pkt);
979
980 return 0;
981}
982
983static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
984{
985 ARG_UNUSED(pkt);
986
987 return 0;
988}
989
990static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
991{
992 ARG_UNUSED(pkt);
993 ARG_UNUSED(flags);
994}
995
996static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
997{
998 ARG_UNUSED(pkt);
999
1000 return 0;
1001}
1002
1003static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
1004{
1005 ARG_UNUSED(pkt);
1006 ARG_UNUSED(id);
1007}
1008#endif /* CONFIG_NET_IPV4_FRAGMENT */
1009
1010#if defined(CONFIG_NET_IPV6_FRAGMENT)
1011static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1012{
1013 return pkt->ipv6_fragment.hdr_start;
1014}
1015
1016static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1017 uint16_t start)
1018{
1019 pkt->ipv6_fragment.hdr_start = start;
1020}
1021
1022static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1023{
1024 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
1025}
1026static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1027{
1028 return (pkt->ipv6_fragment.flags & 0x01) != 0;
1029}
1030
1031static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1033{
1034 pkt->ipv6_fragment.flags = flags;
1035}
1036
1037static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1038{
1039 return pkt->ipv6_fragment.id;
1040}
1041
1042static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1043 uint32_t id)
1044{
1045 pkt->ipv6_fragment.id = id;
1046}
1047#else /* CONFIG_NET_IPV6_FRAGMENT */
1048static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1049{
1050 ARG_UNUSED(pkt);
1051
1052 return 0;
1053}
1054
1055static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1056 uint16_t start)
1057{
1058 ARG_UNUSED(pkt);
1059 ARG_UNUSED(start);
1060}
1061
1062static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1063{
1064 ARG_UNUSED(pkt);
1065
1066 return 0;
1067}
1068
1069static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1070{
1071 ARG_UNUSED(pkt);
1072
1073 return 0;
1074}
1075
1076static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1078{
1079 ARG_UNUSED(pkt);
1080 ARG_UNUSED(flags);
1081}
1082
1083static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1084{
1085 ARG_UNUSED(pkt);
1086
1087 return 0;
1088}
1089
1090static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1091 uint32_t id)
1092{
1093 ARG_UNUSED(pkt);
1094 ARG_UNUSED(id);
1095}
1096#endif /* CONFIG_NET_IPV6_FRAGMENT */
1097
1098static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1099{
1100 return !!(pkt->loopback);
1101}
1102
1103static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1104 bool loopback)
1105{
1106 pkt->loopback = loopback;
1107}
1108
1109#if defined(CONFIG_NET_IP_FRAGMENT)
1110static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1111{
1112 return !!(pkt->ip_reassembled);
1113}
1114
1115static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1116 bool reassembled)
1117{
1118 pkt->ip_reassembled = reassembled;
1119}
1120#else /* CONFIG_NET_IP_FRAGMENT */
1121static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1122{
1123 ARG_UNUSED(pkt);
1124
1125 return false;
1126}
1127
1128static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1129 bool reassembled)
1130{
1131 ARG_UNUSED(pkt);
1132 ARG_UNUSED(reassembled);
1133}
1134#endif /* CONFIG_NET_IP_FRAGMENT */
1135
1136static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1137{
1138 return pkt->priority;
1139}
1140
1141static inline void net_pkt_set_priority(struct net_pkt *pkt,
1142 uint8_t priority)
1143{
1144 pkt->priority = priority;
1145}
1146
1147#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1148static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1149{
1150 return pkt->cooked_mode_pkt;
1151}
1152
1153static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1154{
1155 pkt->cooked_mode_pkt = value;
1156}
1157#else
1158static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1159{
1160 ARG_UNUSED(pkt);
1161
1162 return false;
1163}
1164
1165static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1166{
1167 ARG_UNUSED(pkt);
1168 ARG_UNUSED(value);
1169}
1170#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1171
1172#if defined(CONFIG_NET_VLAN)
1173static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1174{
1175 return net_eth_vlan_get_vid(pkt->vlan_tci);
1176}
1177
1178static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1179{
1180 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1181}
1182
1183static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1184{
1185 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1186}
1187
1188static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1189 uint8_t priority)
1190{
1191 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1192}
1193
1194static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1195{
1196 return net_eth_vlan_get_dei(pkt->vlan_tci);
1197}
1198
1199static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1200{
1201 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1202}
1203
1204static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1205{
1206 pkt->vlan_tci = tci;
1207}
1208
1209static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1210{
1211 return pkt->vlan_tci;
1212}
1213#else
1214static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1215{
1216 ARG_UNUSED(pkt);
1217
1218 return NET_VLAN_TAG_UNSPEC;
1219}
1220
1221static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1222{
1223 ARG_UNUSED(pkt);
1224 ARG_UNUSED(tag);
1225}
1226
1227static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1228{
1229 ARG_UNUSED(pkt);
1230
1231 return 0;
1232}
1233
1234static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1235{
1236 ARG_UNUSED(pkt);
1237
1238 return false;
1239}
1240
1241static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1242{
1243 ARG_UNUSED(pkt);
1244 ARG_UNUSED(dei);
1245}
1246
1247static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1248{
1249 ARG_UNUSED(pkt);
1250
1251 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1252}
1253
1254static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1255{
1256 ARG_UNUSED(pkt);
1257 ARG_UNUSED(tci);
1258}
1259#endif
1260
1261#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1262static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1263{
1264 return &pkt->timestamp;
1265}
1266
1267static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1268 struct net_ptp_time *timestamp)
1269{
1270 pkt->timestamp.second = timestamp->second;
1271 pkt->timestamp.nanosecond = timestamp->nanosecond;
1272}
1273
1274static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1275{
1276 return net_ptp_time_to_ns(&pkt->timestamp);
1277}
1278
1279static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1280{
1281 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1282}
1283#else
1284static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1285{
1286 ARG_UNUSED(pkt);
1287
1288 return NULL;
1289}
1290
1291static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1292 struct net_ptp_time *timestamp)
1293{
1294 ARG_UNUSED(pkt);
1295 ARG_UNUSED(timestamp);
1296}
1297
1298static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1299{
1300 ARG_UNUSED(pkt);
1301
1302 return 0;
1303}
1304
1305static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1306{
1307 ARG_UNUSED(pkt);
1308 ARG_UNUSED(timestamp);
1309}
1310#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1311
1312#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1313 defined(CONFIG_TRACING_NET_CORE)
1314
1315static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1316{
1317 return pkt->create_time;
1318}
1319
1320static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1321 uint32_t create_time)
1322{
1323 pkt->create_time = create_time;
1324}
1325#else
1326static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1327{
1328 ARG_UNUSED(pkt);
1329
1330 return 0U;
1331}
1332
1333static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1334 uint32_t create_time)
1335{
1336 ARG_UNUSED(pkt);
1337 ARG_UNUSED(create_time);
1338}
1339#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1340 * CONFIG_TRACING_NET_CORE
1341 */
1342
1343#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1344 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1345static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1346{
1347 return pkt->detail.stat;
1348}
1349
1350static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1351{
1352 return pkt->detail.count;
1353}
1354
1355static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1356{
1357 memset(&pkt->detail, 0, sizeof(pkt->detail));
1358}
1359
1360static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1361 uint32_t tick)
1362{
1363 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1364 printk("ERROR: Detail stats count overflow (%d >= %d)",
1365 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1366 return;
1367 }
1368
1369 pkt->detail.stat[pkt->detail.count++] = tick;
1370}
1371
1372#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1373#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1374#else
1375static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1376{
1377 ARG_UNUSED(pkt);
1378
1379 return NULL;
1380}
1381
1382static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1383{
1384 ARG_UNUSED(pkt);
1385
1386 return 0;
1387}
1388
1389static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1390{
1391 ARG_UNUSED(pkt);
1392}
1393
1394static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1395{
1396 ARG_UNUSED(pkt);
1397 ARG_UNUSED(tick);
1398}
1399
1400#define net_pkt_set_tx_stats_tick(pkt, tick)
1401#define net_pkt_set_rx_stats_tick(pkt, tick)
1402#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1403 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1404
1405static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1406{
1407 return pkt->frags->data;
1408}
1409
1410static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1411{
1412 return pkt->frags->data;
1413}
1414
1415static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1416{
1417 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1418}
1419
1420static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1421{
1422 return &pkt->lladdr_src;
1423}
1424
1425static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1426{
1427 return &pkt->lladdr_dst;
1428}
1429
1430static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1431{
1432 struct net_linkaddr tmp;
1433
1434 memcpy(tmp.addr,
1435 net_pkt_lladdr_src(pkt)->addr,
1436 net_pkt_lladdr_src(pkt)->len);
1437 memcpy(net_pkt_lladdr_src(pkt)->addr,
1438 net_pkt_lladdr_dst(pkt)->addr,
1439 net_pkt_lladdr_dst(pkt)->len);
1440 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1441 tmp.addr,
1442 net_pkt_lladdr_src(pkt)->len);
1443}
1444
1445static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1446{
1447 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1448 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1449}
1450
1451static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1452{
1453 return pkt->ll_proto_type;
1454}
1455
1456static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1457{
1458 pkt->ll_proto_type = type;
1459}
1460
1461#if defined(CONFIG_NET_IPV4_ACD)
1462static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1463{
1464 return !!(pkt->ipv4_acd_arp_msg);
1465}
1466
1467static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1468 bool is_acd_arp_msg)
1469{
1470 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1471}
1472#else /* CONFIG_NET_IPV4_ACD */
1473static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1474{
1475 ARG_UNUSED(pkt);
1476
1477 return false;
1478}
1479
1480static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1481 bool is_acd_arp_msg)
1482{
1483 ARG_UNUSED(pkt);
1484 ARG_UNUSED(is_acd_arp_msg);
1485}
1486#endif /* CONFIG_NET_IPV4_ACD */
1487
1488#if defined(CONFIG_NET_LLDP)
1489static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1490{
1491 return !!(pkt->lldp_pkt);
1492}
1493
1494static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1495{
1496 pkt->lldp_pkt = is_lldp;
1497}
1498#else
1499static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1500{
1501 ARG_UNUSED(pkt);
1502
1503 return false;
1504}
1505
1506static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1507{
1508 ARG_UNUSED(pkt);
1509 ARG_UNUSED(is_lldp);
1510}
1511#endif /* CONFIG_NET_LLDP */
1512
1513#if defined(CONFIG_NET_L2_PPP)
1514static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1515{
1516 return !!(pkt->ppp_msg);
1517}
1518
1519static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1520 bool is_ppp_msg)
1521{
1522 pkt->ppp_msg = is_ppp_msg;
1523}
1524#else /* CONFIG_NET_L2_PPP */
1525static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1526{
1527 ARG_UNUSED(pkt);
1528
1529 return false;
1530}
1531
1532static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1533 bool is_ppp_msg)
1534{
1535 ARG_UNUSED(pkt);
1536 ARG_UNUSED(is_ppp_msg);
1537}
1538#endif /* CONFIG_NET_L2_PPP */
1539
1540#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1541static inline void *net_pkt_cb(struct net_pkt *pkt)
1542{
1543 return &pkt->cb;
1544}
1545#else
1546static inline void *net_pkt_cb(struct net_pkt *pkt)
1547{
1548 ARG_UNUSED(pkt);
1549
1550 return NULL;
1551}
1552#endif
1553
1554#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1555#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1556
1557static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1558{
1560 net_pkt_context(pkt)),
1561 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1562}
1563
1564static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1565{
1566 pkt->overwrite = overwrite;
1567}
1568
1569static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1570{
1571 return !!(pkt->overwrite);
1572}
1573
1574#ifdef CONFIG_NET_PKT_FILTER
1575
1576bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1577bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1578
1579#else
1580
1581static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1582{
1583 ARG_UNUSED(pkt);
1584
1585 return true;
1586}
1587
1588static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1589{
1590 ARG_UNUSED(pkt);
1591
1592 return true;
1593}
1594
1595#endif /* CONFIG_NET_PKT_FILTER */
1596
1597#if defined(CONFIG_NET_PKT_FILTER) && \
1598 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1599
1600bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1601
1602#else
1603
1604static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1605{
1606 ARG_UNUSED(pkt);
1607
1608 return true;
1609}
1610
1611#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1612
1613#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1614
1615bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1616
1617#else
1618
1619static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1620{
1621 ARG_UNUSED(pkt);
1622
1623 return true;
1624}
1625
1626#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1627
1628#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1629static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1630{
1631 return &pkt->remote;
1632}
1633
1634static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1635 struct net_sockaddr *address,
1636 net_socklen_t len)
1637{
1638 memcpy(&pkt->remote, address, len);
1639}
1640#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1641
1642/* @endcond */
1643
1657#define NET_PKT_SLAB_DEFINE(name, count) \
1658 K_MEM_SLAB_DEFINE_TYPE(name, struct net_pkt, count); \
1659 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1660
1662
1663/* Backward compatibility macro */
1664#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1665
1667
1681#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1682 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1683 0, NULL)
1684
1686
1687#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1688 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1689#define NET_PKT_DEBUG_ENABLED
1690#endif
1691
1692#if defined(NET_PKT_DEBUG_ENABLED)
1693
1694/* Debug versions of the net_pkt functions that are used when tracking
1695 * buffer usage.
1696 */
1697
1698struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1699 size_t min_len,
1700 k_timeout_t timeout,
1701 const char *caller,
1702 int line);
1703
1704#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1705 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1706
1707struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1708 k_timeout_t timeout,
1709 const char *caller,
1710 int line);
1711#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1712 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1713
1714struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1715 k_timeout_t timeout,
1716 const char *caller,
1717 int line);
1718#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1719 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1720
1721struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1722 k_timeout_t timeout,
1723 const char *caller, int line);
1724#define net_pkt_get_frag(pkt, min_len, timeout) \
1725 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1726
1727void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1728#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1729
1730struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1731 int line);
1732#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1733
1734struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1735 const char *caller, int line);
1736#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1737
1738void net_pkt_frag_unref_debug(struct net_buf *frag,
1739 const char *caller, int line);
1740#define net_pkt_frag_unref(frag) \
1741 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1742
1743struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1744 struct net_buf *parent,
1745 struct net_buf *frag,
1746 const char *caller, int line);
1747#define net_pkt_frag_del(pkt, parent, frag) \
1748 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1749
1750void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1751 const char *caller, int line);
1752#define net_pkt_frag_add(pkt, frag) \
1753 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1754
1755void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1756 const char *caller, int line);
1757#define net_pkt_frag_insert(pkt, frag) \
1758 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1759#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1760 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1761 */
1763
1764#if defined(NET_PKT_DEBUG_ENABLED)
1772void net_pkt_print_frags(struct net_pkt *pkt);
1773#else
1774#define net_pkt_print_frags(pkt)
1775#endif
1776
1777#if !defined(NET_PKT_DEBUG_ENABLED)
1793 size_t min_len, k_timeout_t timeout);
1794#endif
1795
1796#if !defined(NET_PKT_DEBUG_ENABLED)
1811struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1812#endif
1813
1814#if !defined(NET_PKT_DEBUG_ENABLED)
1829struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1830#endif
1831
1832#if !defined(NET_PKT_DEBUG_ENABLED)
1845struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1846 k_timeout_t timeout);
1847#endif
1848
1849#if !defined(NET_PKT_DEBUG_ENABLED)
1859void net_pkt_unref(struct net_pkt *pkt);
1860#endif
1861
1862#if !defined(NET_PKT_DEBUG_ENABLED)
1872struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1873#endif
1874
1875#if !defined(NET_PKT_DEBUG_ENABLED)
1885struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1886#endif
1887
1888#if !defined(NET_PKT_DEBUG_ENABLED)
1894void net_pkt_frag_unref(struct net_buf *frag);
1895#endif
1896
1897#if !defined(NET_PKT_DEBUG_ENABLED)
1909 struct net_buf *parent,
1910 struct net_buf *frag);
1911#endif
1912
1913#if !defined(NET_PKT_DEBUG_ENABLED)
1920void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1921#endif
1922
1923#if !defined(NET_PKT_DEBUG_ENABLED)
1930void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1931#endif
1932
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
2704int net_pkt_pull(struct net_pkt *pkt, size_t length);
2705
2715
2727bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2728
2738
2740
2741struct net_pkt_data_access {
2742#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2743 void *data;
2744#endif
2745 const size_t size;
2746};
2747
2748#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2749#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2750 struct net_pkt_data_access _name = { \
2751 .size = sizeof(_type), \
2752 }
2753
2754#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2755 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2756
2757#else
2758#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2759 _type _hdr_##_name; \
2760 struct net_pkt_data_access _name = { \
2761 .data = &_hdr_##_name, \
2762 .size = sizeof(_type), \
2763 }
2764
2765#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2766 struct net_pkt_data_access _name = { \
2767 .data = NULL, \
2768 .size = sizeof(_type), \
2769 }
2770
2771#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2772
2774
2788void *net_pkt_get_data(struct net_pkt *pkt,
2789 struct net_pkt_data_access *access);
2790
2805 struct net_pkt_data_access *access);
2806
2811static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2812 struct net_pkt_data_access *access)
2813{
2814 return net_pkt_skip(pkt, access->size);
2815}
2816
2820
2821#ifdef __cplusplus
2822}
2823#endif
2824
2825#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
long atomic_t
Definition atomic_types.h:15
VLAN specific definitions.
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:172
#define net_htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:133
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1064
unsigned short int net_sa_family_t
Socket address family type.
Definition net_ip.h:169
#define net_htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:125
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2819
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:752
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1271
static const struct net_in6_addr * net_if_ipv6_select_src_addr(struct net_if *iface, const struct net_in6_addr *dst)
Get a IPv6 source address that should be used when sending network data to destination.
Definition net_if.h:2271
static int net_linkaddr_clear(struct net_linkaddr *lladdr)
Clear link address.
Definition net_linkaddr.h:209
void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag)
Add a fragment to a packet at the end of its fragment list.
static int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
Write a uint32_t big endian data to a net_pkt.
Definition net_pkt.h: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:1774
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: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:2811
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:39
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:154
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:81
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:56
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition ethernet_vlan.h:32
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition ethernet_vlan.h:94
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:44
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:107
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:68
#define NULL
Definition iar_missing_defs.h:20
Packet data common to all IEEE 802.15.4 L2 layers.
#define ALWAYS_INLINE
Definition common.h:161
Buffer management.
Network context definitions.
Network core definitions.
Public API for network interface.
IPv6 and IPv4 definitions.
Public API for network link address.
Representation of nanosecond resolution elapsed time and timestamps in the network stack.
flags
Definition parser.h:97
static void printk(const char *fmt,...)
Print kernel debugging message.
Definition printk.h:51
Public functions for the Precision Time Protocol time specification.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INTPTR_TYPE__ intptr_t
Definition stdint.h:104
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1151
Network buffer representation.
Definition net_buf.h:1015
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1104
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1125
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1107
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:209
Network Interface structure.
Definition net_if.h:735
IPv6 address struct.
Definition net_ip.h:144
IPv4 address struct.
Definition net_ip.h:156
Hardware link address structure.
Definition net_linkaddr.h:83
uint8_t addr[6]
The array of bytes representing the address.
Definition net_linkaddr.h:91
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:85
uint8_t len
The real length of the ll address.
Definition net_linkaddr.h:88
Network packet.
Definition net_pkt.h:119
struct net_buf * frags
buffer fragment
Definition net_pkt.h:131
struct net_context * context
Network connection context.
Definition net_pkt.h:139
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:136
struct net_if * iface
Network interface.
Definition net_pkt.h:142
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:124
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:132
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:127
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
uint32_t nanosecond
Nanoseconds.
Definition ptp_time.h:134
uint64_t second
Second value.
Definition ptp_time.h:130
Generic sockaddr struct.
Definition net_ip.h:449
Definition stat.h:57
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition byteorder.h:272
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:268