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_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
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_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_IP_FRAGMENT)
301 union {
302#if defined(CONFIG_NET_IPV4_FRAGMENT)
303 struct {
304 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
305 uint16_t id; /* Fragment ID */
306 } ipv4_fragment;
307#endif /* CONFIG_NET_IPV4_FRAGMENT */
308#if defined(CONFIG_NET_IPV6_FRAGMENT)
309 struct {
310 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
311 uint32_t id; /* Fragment id */
312 uint16_t hdr_start; /* Where starts the fragment header */
313 } ipv6_fragment;
314#endif /* CONFIG_NET_IPV6_FRAGMENT */
315 };
316#endif /* CONFIG_NET_IP_FRAGMENT */
317
318#if defined(CONFIG_NET_IPV6)
319 /* Where is the start of the last header before payload data
320 * in IPv6 packet. This is offset value from start of the IPv6
321 * packet. Note that this value should be updated by who ever
322 * adds IPv6 extension headers to the network packet.
323 */
324 uint16_t ipv6_prev_hdr_start;
325
326 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
327 uint8_t ipv6_next_hdr; /* What is the very first next header */
328#endif /* CONFIG_NET_IPV6 */
329
330#if defined(CONFIG_NET_IP_DSCP_ECN)
332 uint8_t ip_dscp : 6;
333
335 uint8_t ip_ecn : 2;
336#endif /* CONFIG_NET_IP_DSCP_ECN */
337#endif /* CONFIG_NET_IP */
338
339#if defined(CONFIG_NET_VLAN)
340 /* VLAN TCI (Tag Control Information). This contains the Priority
341 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
342 * Identifier (VID, called more commonly VLAN tag). This value is
343 * kept in host byte order.
344 */
345 uint16_t vlan_tci;
346#endif /* CONFIG_NET_VLAN */
347
348#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
349 /* Control block which could be used by any layer */
350 union {
351 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
352#if defined(CONFIG_IEEE802154)
353 /* The following structure requires a 4-byte alignment
354 * boundary to avoid padding.
355 */
356 struct net_pkt_cb_ieee802154 cb_ieee802154;
357#endif /* CONFIG_IEEE802154 */
358 } cb;
359#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
360
364 uint8_t priority;
365
366#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
367 /* Remote address of the received packet. This is only used by
368 * network interfaces with an offloaded TCP/IP stack, or if we
369 * have network tunneling in use.
370 */
371 union {
372 struct net_sockaddr remote;
373
374 /* This will make sure that there is enough storage to store
375 * the address struct. The access to value is via remote
376 * address.
377 */
378 struct net_sockaddr_storage remote_storage;
379 };
380#endif /* CONFIG_NET_OFFLOAD */
381
382#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
383 /* Tell the capture api that this is a captured packet */
384 uint8_t cooked_mode_pkt : 1;
385#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
386
387#if defined(CONFIG_NET_IPV4_PMTU)
388 /* Path MTU needed for this destination address */
389 uint8_t ipv4_pmtu : 1;
390#endif /* CONFIG_NET_IPV4_PMTU */
391
392 /* @endcond */
393};
394
396
397/* The interface real ll address */
398static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
399{
400 return net_if_get_link_addr(pkt->iface);
401}
402
403static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
404{
405 return pkt->context;
406}
407
408static inline void net_pkt_set_context(struct net_pkt *pkt,
409 struct net_context *ctx)
410{
411 pkt->context = ctx;
412}
413
414static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
415{
416 return pkt->iface;
417}
418
419static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
420{
421 pkt->iface = iface;
422
423 /* If the network interface is set in pkt, then also set the type of
424 * the network address that is stored in pkt. This is done here so
425 * that the address type is properly set and is not forgotten.
426 */
427 if (iface) {
428 uint8_t type = net_if_get_link_addr(iface)->type;
429
430 pkt->lladdr_src.type = type;
431 pkt->lladdr_dst.type = type;
432 }
433}
434
435static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
436{
437#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
438 return pkt->orig_iface;
439#else
440 return pkt->iface;
441#endif
442}
443
444static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
445 struct net_if *iface)
446{
447#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
448 pkt->orig_iface = iface;
449#else
450 ARG_UNUSED(pkt);
451 ARG_UNUSED(iface);
452#endif
453}
454
455#if defined(CONFIG_NET_VPN)
456static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
457{
458 return pkt->vpn.iface;
459}
460
461static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
462 struct net_if *iface)
463{
464 pkt->vpn.iface = iface;
465}
466
467static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
468{
469 return &pkt->vpn.ip_hdr;
470}
471
472static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
473 union net_ip_header *ip_hdr)
474{
475 pkt->vpn.ip_hdr = *ip_hdr;
476}
477
478static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
479{
480 return &pkt->vpn.proto_hdr;
481}
482
483static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
484 union net_proto_header *proto_hdr)
485{
486 pkt->vpn.proto_hdr = *proto_hdr;
487}
488
489static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
490{
491 return pkt->vpn.peer_id;
492}
493
494static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
495 int peer_id)
496{
497 pkt->vpn.peer_id = peer_id;
498}
499#endif /* CONFIG_NET_VPN */
500
501static inline uint8_t net_pkt_family(struct net_pkt *pkt)
502{
503 return pkt->family;
504}
505
506static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
507{
508 pkt->family = family;
509}
510
511static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
512{
513 return !!(pkt->ptp_pkt);
514}
515
516static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
517{
518 pkt->ptp_pkt = is_ptp;
519}
520
521static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
522{
523#if defined(CONFIG_NET_PKT_TIMESTAMP)
524 return !!(pkt->tx_timestamping);
525#else
526 ARG_UNUSED(pkt);
527
528 return false;
529#endif
530}
531
532static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
533{
534#if defined(CONFIG_NET_PKT_TIMESTAMP)
535 pkt->tx_timestamping = is_timestamping;
536#else
537 ARG_UNUSED(pkt);
538 ARG_UNUSED(is_timestamping);
539#endif
540}
541
542static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
543{
544#if defined(CONFIG_NET_PKT_TIMESTAMP)
545 return !!(pkt->rx_timestamping);
546#else
547 ARG_UNUSED(pkt);
548
549 return false;
550#endif
551}
552
553static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
554{
555#if defined(CONFIG_NET_PKT_TIMESTAMP)
556 pkt->rx_timestamping = is_timestamping;
557#else
558 ARG_UNUSED(pkt);
559 ARG_UNUSED(is_timestamping);
560#endif
561}
562
563static inline bool net_pkt_is_captured(struct net_pkt *pkt)
564{
565 return !!(pkt->captured);
566}
567
568static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
569{
570 pkt->captured = is_captured;
571}
572
573static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
574{
575 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
576}
577
578static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
579{
580 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
581 pkt->l2_bridged = is_l2_bridged;
582 }
583}
584
585static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
586{
587 return !!(pkt->l2_processed);
588}
589
590static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
591 bool is_l2_processed)
592{
593 pkt->l2_processed = is_l2_processed;
594}
595
596static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
597{
598 return !!(pkt->chksum_done);
599}
600
601static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
602 bool is_chksum_done)
603{
604 pkt->chksum_done = is_chksum_done;
605}
606
607static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
608{
609#if defined(CONFIG_NET_IP)
610 return pkt->ip_hdr_len;
611#else
612 ARG_UNUSED(pkt);
613
614 return 0;
615#endif
616}
617
618static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
619{
620#if defined(CONFIG_NET_IP)
621 pkt->ip_hdr_len = len;
622#else
623 ARG_UNUSED(pkt);
624 ARG_UNUSED(len);
625#endif
626}
627
628static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
629{
630#if defined(CONFIG_NET_IP_DSCP_ECN)
631 return pkt->ip_dscp;
632#else
633 ARG_UNUSED(pkt);
634
635 return 0;
636#endif
637}
638
639static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
640{
641#if defined(CONFIG_NET_IP_DSCP_ECN)
642 pkt->ip_dscp = dscp;
643#else
644 ARG_UNUSED(pkt);
645 ARG_UNUSED(dscp);
646#endif
647}
648
649static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
650{
651#if defined(CONFIG_NET_IP_DSCP_ECN)
652 return pkt->ip_ecn;
653#else
654 ARG_UNUSED(pkt);
655
656 return 0;
657#endif
658}
659
660static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
661{
662#if defined(CONFIG_NET_IP_DSCP_ECN)
663 pkt->ip_ecn = ecn;
664#else
665 ARG_UNUSED(pkt);
666 ARG_UNUSED(ecn);
667#endif
668}
669
670static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
671{
672 return pkt->eof;
673}
674
675static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
676{
677 pkt->eof = eof;
678}
679
680static inline bool net_pkt_forwarding(struct net_pkt *pkt)
681{
682 return !!(pkt->forwarding);
683}
684
685static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
686{
687 pkt->forwarding = forward;
688}
689
690#if defined(CONFIG_NET_IPV4)
691static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
692{
693 return pkt->ipv4_ttl;
694}
695
696static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
697 uint8_t ttl)
698{
699 pkt->ipv4_ttl = ttl;
700}
701
702static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
703{
704 return pkt->ipv4_opts_len;
705}
706
707static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
708 uint8_t opts_len)
709{
710 pkt->ipv4_opts_len = opts_len;
711}
712#else
713static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
714{
715 ARG_UNUSED(pkt);
716
717 return 0;
718}
719
720static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
721 uint8_t ttl)
722{
723 ARG_UNUSED(pkt);
724 ARG_UNUSED(ttl);
725}
726
727static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
728{
729 ARG_UNUSED(pkt);
730 return 0;
731}
732
733static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
734 uint8_t opts_len)
735{
736 ARG_UNUSED(pkt);
737 ARG_UNUSED(opts_len);
738}
739#endif
740
741#if defined(CONFIG_NET_IPV6)
742static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
743{
744 return pkt->ipv6_ext_opt_len;
745}
746
747static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
748 uint8_t len)
749{
750 pkt->ipv6_ext_opt_len = len;
751}
752
753static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
754{
755 return pkt->ipv6_next_hdr;
756}
757
758static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
759 uint8_t next_hdr)
760{
761 pkt->ipv6_next_hdr = next_hdr;
762}
763
764static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
765{
766 return pkt->ipv6_ext_len;
767}
768
769static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
770{
771 pkt->ipv6_ext_len = len;
772}
773
774static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
775{
776 return pkt->ipv6_prev_hdr_start;
777}
778
779static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
780 uint16_t offset)
781{
782 pkt->ipv6_prev_hdr_start = offset;
783}
784
785static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
786{
787 return pkt->ipv6_hop_limit;
788}
789
790static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
791 uint8_t hop_limit)
792{
793 pkt->ipv6_hop_limit = hop_limit;
794}
795#else /* CONFIG_NET_IPV6 */
796static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
797{
798 ARG_UNUSED(pkt);
799
800 return 0;
801}
802
803static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
804 uint8_t len)
805{
806 ARG_UNUSED(pkt);
807 ARG_UNUSED(len);
808}
809
810static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
811{
812 ARG_UNUSED(pkt);
813
814 return 0;
815}
816
817static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
818 uint8_t next_hdr)
819{
820 ARG_UNUSED(pkt);
821 ARG_UNUSED(next_hdr);
822}
823
824static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
825{
826 ARG_UNUSED(pkt);
827
828 return 0;
829}
830
831static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
832{
833 ARG_UNUSED(pkt);
834 ARG_UNUSED(len);
835}
836
837static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
838{
839 ARG_UNUSED(pkt);
840
841 return 0;
842}
843
844static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
845 uint16_t offset)
846{
847 ARG_UNUSED(pkt);
848 ARG_UNUSED(offset);
849}
850
851static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
852{
853 ARG_UNUSED(pkt);
854
855 return 0;
856}
857
858static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
859 uint8_t hop_limit)
860{
861 ARG_UNUSED(pkt);
862 ARG_UNUSED(hop_limit);
863}
864#endif /* CONFIG_NET_IPV6 */
865
866static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
867{
868#if defined(CONFIG_NET_IPV6)
869 return pkt->ipv6_ext_len;
870#elif defined(CONFIG_NET_IPV4)
871 return pkt->ipv4_opts_len;
872#else
873 ARG_UNUSED(pkt);
874
875 return 0;
876#endif
877}
878
879#if defined(CONFIG_NET_IPV4_PMTU)
880static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
881{
882 return !!pkt->ipv4_pmtu;
883}
884
885static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
886{
887 pkt->ipv4_pmtu = value;
888}
889#else
890static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
891{
892 ARG_UNUSED(pkt);
893
894 return false;
895}
896
897static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
898{
899 ARG_UNUSED(pkt);
900 ARG_UNUSED(value);
901}
902#endif /* CONFIG_NET_IPV4_PMTU */
903
904#if defined(CONFIG_NET_IPV4_FRAGMENT)
905static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
906{
907 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
908}
909
910static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
911{
912 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
913}
914
915static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
916{
917 pkt->ipv4_fragment.flags = flags;
918}
919
920static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
921{
922 return pkt->ipv4_fragment.id;
923}
924
925static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
926{
927 pkt->ipv4_fragment.id = id;
928}
929#else /* CONFIG_NET_IPV4_FRAGMENT */
930static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
931{
932 ARG_UNUSED(pkt);
933
934 return 0;
935}
936
937static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
938{
939 ARG_UNUSED(pkt);
940
941 return 0;
942}
943
944static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
945{
946 ARG_UNUSED(pkt);
947 ARG_UNUSED(flags);
948}
949
950static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
951{
952 ARG_UNUSED(pkt);
953
954 return 0;
955}
956
957static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
958{
959 ARG_UNUSED(pkt);
960 ARG_UNUSED(id);
961}
962#endif /* CONFIG_NET_IPV4_FRAGMENT */
963
964#if defined(CONFIG_NET_IPV6_FRAGMENT)
965static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
966{
967 return pkt->ipv6_fragment.hdr_start;
968}
969
970static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
971 uint16_t start)
972{
973 pkt->ipv6_fragment.hdr_start = start;
974}
975
976static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
977{
978 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
979}
980static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
981{
982 return (pkt->ipv6_fragment.flags & 0x01) != 0;
983}
984
985static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
987{
988 pkt->ipv6_fragment.flags = flags;
989}
990
991static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
992{
993 return pkt->ipv6_fragment.id;
994}
995
996static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
997 uint32_t id)
998{
999 pkt->ipv6_fragment.id = id;
1000}
1001#else /* CONFIG_NET_IPV6_FRAGMENT */
1002static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1003{
1004 ARG_UNUSED(pkt);
1005
1006 return 0;
1007}
1008
1009static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1010 uint16_t start)
1011{
1012 ARG_UNUSED(pkt);
1013 ARG_UNUSED(start);
1014}
1015
1016static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1017{
1018 ARG_UNUSED(pkt);
1019
1020 return 0;
1021}
1022
1023static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1024{
1025 ARG_UNUSED(pkt);
1026
1027 return 0;
1028}
1029
1030static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1032{
1033 ARG_UNUSED(pkt);
1034 ARG_UNUSED(flags);
1035}
1036
1037static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1038{
1039 ARG_UNUSED(pkt);
1040
1041 return 0;
1042}
1043
1044static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1045 uint32_t id)
1046{
1047 ARG_UNUSED(pkt);
1048 ARG_UNUSED(id);
1049}
1050#endif /* CONFIG_NET_IPV6_FRAGMENT */
1051
1052static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1053{
1054 return !!(pkt->loopback);
1055}
1056
1057static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1058 bool loopback)
1059{
1060 pkt->loopback = loopback;
1061}
1062
1063#if defined(CONFIG_NET_IP_FRAGMENT)
1064static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1065{
1066 return !!(pkt->ip_reassembled);
1067}
1068
1069static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1070 bool reassembled)
1071{
1072 pkt->ip_reassembled = reassembled;
1073}
1074#else /* CONFIG_NET_IP_FRAGMENT */
1075static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1076{
1077 ARG_UNUSED(pkt);
1078
1079 return false;
1080}
1081
1082static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1083 bool reassembled)
1084{
1085 ARG_UNUSED(pkt);
1086 ARG_UNUSED(reassembled);
1087}
1088#endif /* CONFIG_NET_IP_FRAGMENT */
1089
1090static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1091{
1092 return pkt->priority;
1093}
1094
1095static inline void net_pkt_set_priority(struct net_pkt *pkt,
1096 uint8_t priority)
1097{
1098 pkt->priority = priority;
1099}
1100
1101#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1102static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1103{
1104 return pkt->cooked_mode_pkt;
1105}
1106
1107static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1108{
1109 pkt->cooked_mode_pkt = value;
1110}
1111#else
1112static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1113{
1114 ARG_UNUSED(pkt);
1115
1116 return false;
1117}
1118
1119static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1120{
1121 ARG_UNUSED(pkt);
1122 ARG_UNUSED(value);
1123}
1124#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1125
1126#if defined(CONFIG_NET_VLAN)
1127static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1128{
1129 return net_eth_vlan_get_vid(pkt->vlan_tci);
1130}
1131
1132static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1133{
1134 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1135}
1136
1137static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1138{
1139 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1140}
1141
1142static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1143 uint8_t priority)
1144{
1145 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1146}
1147
1148static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1149{
1150 return net_eth_vlan_get_dei(pkt->vlan_tci);
1151}
1152
1153static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1154{
1155 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1156}
1157
1158static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1159{
1160 pkt->vlan_tci = tci;
1161}
1162
1163static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1164{
1165 return pkt->vlan_tci;
1166}
1167#else
1168static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1169{
1170 ARG_UNUSED(pkt);
1171
1172 return NET_VLAN_TAG_UNSPEC;
1173}
1174
1175static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1176{
1177 ARG_UNUSED(pkt);
1178 ARG_UNUSED(tag);
1179}
1180
1181static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1182{
1183 ARG_UNUSED(pkt);
1184
1185 return 0;
1186}
1187
1188static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1189{
1190 ARG_UNUSED(pkt);
1191
1192 return false;
1193}
1194
1195static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1196{
1197 ARG_UNUSED(pkt);
1198 ARG_UNUSED(dei);
1199}
1200
1201static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1202{
1203 ARG_UNUSED(pkt);
1204
1205 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1206}
1207
1208static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1209{
1210 ARG_UNUSED(pkt);
1211 ARG_UNUSED(tci);
1212}
1213#endif
1214
1215#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1216static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1217{
1218 return &pkt->timestamp;
1219}
1220
1221static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1222 struct net_ptp_time *timestamp)
1223{
1224 pkt->timestamp.second = timestamp->second;
1225 pkt->timestamp.nanosecond = timestamp->nanosecond;
1226}
1227
1228static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1229{
1230 return net_ptp_time_to_ns(&pkt->timestamp);
1231}
1232
1233static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1234{
1235 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1236}
1237#else
1238static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1239{
1240 ARG_UNUSED(pkt);
1241
1242 return NULL;
1243}
1244
1245static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1246 struct net_ptp_time *timestamp)
1247{
1248 ARG_UNUSED(pkt);
1249 ARG_UNUSED(timestamp);
1250}
1251
1252static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1253{
1254 ARG_UNUSED(pkt);
1255
1256 return 0;
1257}
1258
1259static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1260{
1261 ARG_UNUSED(pkt);
1262 ARG_UNUSED(timestamp);
1263}
1264#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1265
1266#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1267 defined(CONFIG_TRACING_NET_CORE)
1268
1269static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1270{
1271 return pkt->create_time;
1272}
1273
1274static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1275 uint32_t create_time)
1276{
1277 pkt->create_time = create_time;
1278}
1279#else
1280static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1281{
1282 ARG_UNUSED(pkt);
1283
1284 return 0U;
1285}
1286
1287static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1288 uint32_t create_time)
1289{
1290 ARG_UNUSED(pkt);
1291 ARG_UNUSED(create_time);
1292}
1293#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1294 * CONFIG_TRACING_NET_CORE
1295 */
1296
1297#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1298 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1299static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1300{
1301 return pkt->detail.stat;
1302}
1303
1304static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1305{
1306 return pkt->detail.count;
1307}
1308
1309static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1310{
1311 memset(&pkt->detail, 0, sizeof(pkt->detail));
1312}
1313
1314static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1315 uint32_t tick)
1316{
1317 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1318 printk("ERROR: Detail stats count overflow (%d >= %d)",
1319 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1320 return;
1321 }
1322
1323 pkt->detail.stat[pkt->detail.count++] = tick;
1324}
1325
1326#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1327#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1328#else
1329static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1330{
1331 ARG_UNUSED(pkt);
1332
1333 return NULL;
1334}
1335
1336static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1337{
1338 ARG_UNUSED(pkt);
1339
1340 return 0;
1341}
1342
1343static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1344{
1345 ARG_UNUSED(pkt);
1346}
1347
1348static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1349{
1350 ARG_UNUSED(pkt);
1351 ARG_UNUSED(tick);
1352}
1353
1354#define net_pkt_set_tx_stats_tick(pkt, tick)
1355#define net_pkt_set_rx_stats_tick(pkt, tick)
1356#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1357 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1358
1359static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1360{
1361 return pkt->frags->data;
1362}
1363
1364static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1365{
1366 return pkt->frags->data;
1367}
1368
1369static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1370{
1371 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1372}
1373
1374static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1375{
1376 return &pkt->lladdr_src;
1377}
1378
1379static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1380{
1381 return &pkt->lladdr_dst;
1382}
1383
1384static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1385{
1386 struct net_linkaddr tmp;
1387
1388 memcpy(tmp.addr,
1389 net_pkt_lladdr_src(pkt)->addr,
1390 net_pkt_lladdr_src(pkt)->len);
1391 memcpy(net_pkt_lladdr_src(pkt)->addr,
1392 net_pkt_lladdr_dst(pkt)->addr,
1393 net_pkt_lladdr_dst(pkt)->len);
1394 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1395 tmp.addr,
1396 net_pkt_lladdr_src(pkt)->len);
1397}
1398
1399static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1400{
1401 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1402 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1403}
1404
1405static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1406{
1407 return pkt->ll_proto_type;
1408}
1409
1410static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1411{
1412 pkt->ll_proto_type = type;
1413}
1414
1415#if defined(CONFIG_NET_IPV4_ACD)
1416static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1417{
1418 return !!(pkt->ipv4_acd_arp_msg);
1419}
1420
1421static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1422 bool is_acd_arp_msg)
1423{
1424 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1425}
1426#else /* CONFIG_NET_IPV4_ACD */
1427static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1428{
1429 ARG_UNUSED(pkt);
1430
1431 return false;
1432}
1433
1434static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1435 bool is_acd_arp_msg)
1436{
1437 ARG_UNUSED(pkt);
1438 ARG_UNUSED(is_acd_arp_msg);
1439}
1440#endif /* CONFIG_NET_IPV4_ACD */
1441
1442#if defined(CONFIG_NET_LLDP)
1443static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1444{
1445 return !!(pkt->lldp_pkt);
1446}
1447
1448static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1449{
1450 pkt->lldp_pkt = is_lldp;
1451}
1452#else
1453static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1454{
1455 ARG_UNUSED(pkt);
1456
1457 return false;
1458}
1459
1460static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1461{
1462 ARG_UNUSED(pkt);
1463 ARG_UNUSED(is_lldp);
1464}
1465#endif /* CONFIG_NET_LLDP */
1466
1467#if defined(CONFIG_NET_L2_PPP)
1468static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1469{
1470 return !!(pkt->ppp_msg);
1471}
1472
1473static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1474 bool is_ppp_msg)
1475{
1476 pkt->ppp_msg = is_ppp_msg;
1477}
1478#else /* CONFIG_NET_L2_PPP */
1479static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1480{
1481 ARG_UNUSED(pkt);
1482
1483 return false;
1484}
1485
1486static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1487 bool is_ppp_msg)
1488{
1489 ARG_UNUSED(pkt);
1490 ARG_UNUSED(is_ppp_msg);
1491}
1492#endif /* CONFIG_NET_L2_PPP */
1493
1494#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1495static inline void *net_pkt_cb(struct net_pkt *pkt)
1496{
1497 return &pkt->cb;
1498}
1499#else
1500static inline void *net_pkt_cb(struct net_pkt *pkt)
1501{
1502 ARG_UNUSED(pkt);
1503
1504 return NULL;
1505}
1506#endif
1507
1508#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1509#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1510
1511static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1512{
1514 net_pkt_context(pkt)),
1515 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1516}
1517
1518static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1519{
1520 pkt->overwrite = overwrite;
1521}
1522
1523static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1524{
1525 return !!(pkt->overwrite);
1526}
1527
1528#ifdef CONFIG_NET_PKT_FILTER
1529
1530bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1531bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1532
1533#else
1534
1535static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1536{
1537 ARG_UNUSED(pkt);
1538
1539 return true;
1540}
1541
1542static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1543{
1544 ARG_UNUSED(pkt);
1545
1546 return true;
1547}
1548
1549#endif /* CONFIG_NET_PKT_FILTER */
1550
1551#if defined(CONFIG_NET_PKT_FILTER) && \
1552 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1553
1554bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1555
1556#else
1557
1558static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1559{
1560 ARG_UNUSED(pkt);
1561
1562 return true;
1563}
1564
1565#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1566
1567#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1568
1569bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1570
1571#else
1572
1573static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1574{
1575 ARG_UNUSED(pkt);
1576
1577 return true;
1578}
1579
1580#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1581
1582#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1583static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1584{
1585 return &pkt->remote;
1586}
1587
1588static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1589 struct net_sockaddr *address,
1590 net_socklen_t len)
1591{
1592 memcpy(&pkt->remote, address, len);
1593}
1594#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1595
1596/* @endcond */
1597
1611#define NET_PKT_SLAB_DEFINE(name, count) \
1612 K_MEM_SLAB_DEFINE_TYPE(name, struct net_pkt, count); \
1613 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1614
1616
1617/* Backward compatibility macro */
1618#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1619
1621
1635#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1636 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1637 0, NULL)
1638
1640
1641#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1642 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1643#define NET_PKT_DEBUG_ENABLED
1644#endif
1645
1646#if defined(NET_PKT_DEBUG_ENABLED)
1647
1648/* Debug versions of the net_pkt functions that are used when tracking
1649 * buffer usage.
1650 */
1651
1652struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1653 size_t min_len,
1654 k_timeout_t timeout,
1655 const char *caller,
1656 int line);
1657
1658#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1659 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1660
1661struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1662 k_timeout_t timeout,
1663 const char *caller,
1664 int line);
1665#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1666 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1667
1668struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1669 k_timeout_t timeout,
1670 const char *caller,
1671 int line);
1672#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1673 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1674
1675struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1676 k_timeout_t timeout,
1677 const char *caller, int line);
1678#define net_pkt_get_frag(pkt, min_len, timeout) \
1679 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1680
1681void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1682#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1683
1684struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1685 int line);
1686#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1687
1688struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1689 const char *caller, int line);
1690#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1691
1692void net_pkt_frag_unref_debug(struct net_buf *frag,
1693 const char *caller, int line);
1694#define net_pkt_frag_unref(frag) \
1695 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1696
1697struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1698 struct net_buf *parent,
1699 struct net_buf *frag,
1700 const char *caller, int line);
1701#define net_pkt_frag_del(pkt, parent, frag) \
1702 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1703
1704void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1705 const char *caller, int line);
1706#define net_pkt_frag_add(pkt, frag) \
1707 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1708
1709void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1710 const char *caller, int line);
1711#define net_pkt_frag_insert(pkt, frag) \
1712 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1713#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1714 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1715 */
1717
1718#if defined(NET_PKT_DEBUG_ENABLED)
1726void net_pkt_print_frags(struct net_pkt *pkt);
1727#else
1728#define net_pkt_print_frags(pkt)
1729#endif
1730
1731#if !defined(NET_PKT_DEBUG_ENABLED)
1747 size_t min_len, k_timeout_t timeout);
1748#endif
1749
1750#if !defined(NET_PKT_DEBUG_ENABLED)
1765struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1766#endif
1767
1768#if !defined(NET_PKT_DEBUG_ENABLED)
1783struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1784#endif
1785
1786#if !defined(NET_PKT_DEBUG_ENABLED)
1799struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1800 k_timeout_t timeout);
1801#endif
1802
1803#if !defined(NET_PKT_DEBUG_ENABLED)
1813void net_pkt_unref(struct net_pkt *pkt);
1814#endif
1815
1816#if !defined(NET_PKT_DEBUG_ENABLED)
1826struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1827#endif
1828
1829#if !defined(NET_PKT_DEBUG_ENABLED)
1839struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1840#endif
1841
1842#if !defined(NET_PKT_DEBUG_ENABLED)
1848void net_pkt_frag_unref(struct net_buf *frag);
1849#endif
1850
1851#if !defined(NET_PKT_DEBUG_ENABLED)
1863 struct net_buf *parent,
1864 struct net_buf *frag);
1865#endif
1866
1867#if !defined(NET_PKT_DEBUG_ENABLED)
1874void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1875#endif
1876
1877#if !defined(NET_PKT_DEBUG_ENABLED)
1884void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1885#endif
1886
1893void net_pkt_compact(struct net_pkt *pkt);
1894
1903void net_pkt_get_info(struct k_mem_slab **rx,
1904 struct k_mem_slab **tx,
1905 struct net_buf_pool **rx_data,
1906 struct net_buf_pool **tx_data);
1907
1909
1910#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1914void net_pkt_print(void);
1915
1916typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1917 struct net_buf *buf,
1918 const char *func_alloc,
1919 int line_alloc,
1920 const char *func_free,
1921 int line_free,
1922 bool in_use,
1923 void *user_data);
1924
1925void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1926
1927const char *net_pkt_slab2str(struct k_mem_slab *slab);
1928const char *net_pkt_pool2str(struct net_buf_pool *pool);
1929
1930#else
1931#define net_pkt_print(...)
1932#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1933
1934/* New allocator, and API are defined below.
1935 * This will be simpler when time will come to get rid of former API above.
1936 */
1937#if defined(NET_PKT_DEBUG_ENABLED)
1938
1939struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1940 const char *caller, int line);
1941#define net_pkt_alloc(_timeout) \
1942 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1943
1944struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1945 k_timeout_t timeout,
1946 const char *caller, int line);
1947#define net_pkt_alloc_from_slab(_slab, _timeout) \
1948 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1949
1950struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1951 const char *caller, int line);
1952#define net_pkt_rx_alloc(_timeout) \
1953 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1954
1955struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1956 k_timeout_t timeout,
1957 const char *caller,
1958 int line);
1959#define net_pkt_alloc_on_iface(_iface, _timeout) \
1960 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1961
1962struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1963 k_timeout_t timeout,
1964 const char *caller,
1965 int line);
1966#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1967 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1968 __func__, __LINE__)
1969
1970int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1971 size_t size,
1972 enum net_ip_protocol proto,
1973 k_timeout_t timeout,
1974 const char *caller, int line);
1975#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1976 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1977 __func__, __LINE__)
1978
1979int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1980 k_timeout_t timeout,
1981 const char *caller, int line);
1982#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1983 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1984 __func__, __LINE__)
1985
1986struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1987 size_t size,
1988 net_sa_family_t family,
1989 enum net_ip_protocol proto,
1990 k_timeout_t timeout,
1991 const char *caller,
1992 int line);
1993#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1994 _proto, _timeout) \
1995 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1996 _proto, _timeout, \
1997 __func__, __LINE__)
1998
1999struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
2000 size_t size,
2001 net_sa_family_t family,
2002 enum net_ip_protocol proto,
2003 k_timeout_t timeout,
2004 const char *caller,
2005 int line);
2006#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
2007 _proto, _timeout) \
2008 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
2009 _proto, _timeout, \
2010 __func__, __LINE__)
2011
2012int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
2013 size_t size,
2014 size_t reserve,
2015 enum net_ip_protocol proto,
2016 k_timeout_t timeout,
2017 const char *caller,
2018 int line);
2019#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
2020 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
2021 _timeout, __func__, __LINE__)
2022
2023#endif /* NET_PKT_DEBUG_ENABLED */
2025
2026#if !defined(NET_PKT_DEBUG_ENABLED)
2038#endif
2039
2040#if !defined(NET_PKT_DEBUG_ENABLED)
2055struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2056 k_timeout_t timeout);
2057#endif
2058
2059#if !defined(NET_PKT_DEBUG_ENABLED)
2071#endif
2072
2073#if !defined(NET_PKT_DEBUG_ENABLED)
2083 k_timeout_t timeout);
2084
2086
2087/* Same as above but specifically for RX packet */
2088struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2089 k_timeout_t timeout);
2091
2092#endif
2093
2094#if !defined(NET_PKT_DEBUG_ENABLED)
2111 size_t size,
2112 enum net_ip_protocol proto,
2113 k_timeout_t timeout);
2114#endif
2115
2116#if !defined(NET_PKT_DEBUG_ENABLED)
2134#if !defined(NET_PKT_DEBUG_ENABLED)
2136 size_t size,
2137 size_t reserve,
2138 enum net_ip_protocol proto,
2139 k_timeout_t timeout);
2140#endif
2141
2155int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2156 k_timeout_t timeout);
2157#endif
2158
2159#if !defined(NET_PKT_DEBUG_ENABLED)
2172 size_t size,
2173 net_sa_family_t family,
2174 enum net_ip_protocol proto,
2175 k_timeout_t timeout);
2176
2178
2179/* Same as above but specifically for RX packet */
2180struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2181 size_t size,
2182 net_sa_family_t family,
2183 enum net_ip_protocol proto,
2184 k_timeout_t timeout);
2185
2187
2188#endif
2189
2196void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2197
2209
2226 enum net_ip_protocol proto);
2227
2237
2252int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2253
2262
2269static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2270 struct net_pkt_cursor *backup)
2271{
2272 backup->buf = pkt->cursor.buf;
2273 backup->pos = pkt->cursor.pos;
2274}
2275
2282static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2283 struct net_pkt_cursor *backup)
2284{
2285 pkt->cursor.buf = backup->buf;
2286 pkt->cursor.pos = backup->pos;
2287}
2288
2296static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2297{
2298 return pkt->cursor.pos;
2299}
2300
2318int net_pkt_skip(struct net_pkt *pkt, size_t length);
2319
2334int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2335
2349int net_pkt_copy(struct net_pkt *pkt_dst,
2350 struct net_pkt *pkt_src,
2351 size_t length);
2352
2362struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2363
2373struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2374
2384 k_timeout_t timeout);
2385
2399int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2400
2413static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2414{
2415 return net_pkt_read(pkt, data, 1);
2416}
2417
2430int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2431
2444int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2445
2458int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2459
2472int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2473
2486int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2487
2500int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2501
2515int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2516
2529static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2530{
2531 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2532}
2533
2546static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2547{
2548 uint16_t data_be16 = net_htons(data);
2549
2550 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2551}
2552
2565static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2566{
2567 uint32_t data_be32 = net_htonl(data);
2568
2569 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2570}
2571
2584static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2585{
2586 uint32_t data_le32 = sys_cpu_to_le32(data);
2587
2588 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2589}
2590
2603static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2604{
2605 uint16_t data_le16 = sys_cpu_to_le16(data);
2606
2607 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2608}
2609
2618
2626static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2627{
2628 return net_buf_frags_len(pkt->frags);
2629}
2630
2643int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2644
2658int net_pkt_pull(struct net_pkt *pkt, size_t length);
2659
2669
2681bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2682
2692
2694
2695struct net_pkt_data_access {
2696#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2697 void *data;
2698#endif
2699 const size_t size;
2700};
2701
2702#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2703#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2704 struct net_pkt_data_access _name = { \
2705 .size = sizeof(_type), \
2706 }
2707
2708#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2709 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2710
2711#else
2712#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2713 _type _hdr_##_name; \
2714 struct net_pkt_data_access _name = { \
2715 .data = &_hdr_##_name, \
2716 .size = sizeof(_type), \
2717 }
2718
2719#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2720 struct net_pkt_data_access _name = { \
2721 .data = NULL, \
2722 .size = sizeof(_type), \
2723 }
2724
2725#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2726
2728
2742void *net_pkt_get_data(struct net_pkt *pkt,
2743 struct net_pkt_data_access *access);
2744
2759 struct net_pkt_data_access *access);
2760
2765static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2766 struct net_pkt_data_access *access)
2767{
2768 return net_pkt_skip(pkt, access->size);
2769}
2770
2774
2775#ifdef __cplusplus
2776}
2777#endif
2778
2779#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
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:2565
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:1728
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:2546
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:2626
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:2529
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:2296
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:2269
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:2765
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:2603
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:2282
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:2584
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:2413
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
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