Zephyr Project API 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_pkt.h
Go to the documentation of this file.
1
8/*
9 * Copyright (c) 2016 Intel Corporation
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13
14/* Data buffer API - used for all data to/from net */
15
16#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
17#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
18
19#include <zephyr/types.h>
20#include <stdbool.h>
21
22#include <zephyr/net_buf.h>
23
24#if defined(CONFIG_IEEE802154)
26#endif
27#include <zephyr/net/net_core.h>
29#include <zephyr/net/net_ip.h>
30#include <zephyr/net/net_if.h>
32#include <zephyr/net/net_time.h>
34#include <zephyr/net/ptp_time.h>
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
49struct net_context;
50
53#if defined(CONFIG_NET_PKT_ALLOC_STATS)
54struct net_pkt_alloc_stats {
55 uint64_t alloc_sum;
56 uint64_t time_sum;
57 uint32_t count;
58};
59
60struct net_pkt_alloc_stats_slab {
61 struct net_pkt_alloc_stats ok;
62 struct net_pkt_alloc_stats fail;
63 struct k_mem_slab *slab;
64};
65
66#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
67 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
68 .slab = &slab_name, \
69 }
70
71#else
72#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
73#endif /* CONFIG_NET_PKT_ALLOC_STATS */
74
75/* buffer cursor used in net_pkt */
76struct net_pkt_cursor {
78 struct net_buf *buf;
80 uint8_t *pos;
81};
82
91struct net_pkt {
97
99 struct k_mem_slab *slab;
100
102 union {
103 struct net_buf *frags;
104 struct net_buf *buffer;
105 };
106
108 struct net_pkt_cursor cursor;
109
112
114 struct net_if *iface;
115
118#if defined(CONFIG_NET_TCP)
120 sys_snode_t next;
121#endif
122#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
123 struct net_if *orig_iface; /* Original network interface */
124#endif
125
126#if defined(CONFIG_NET_VPN)
127 struct {
129 struct net_if *iface;
131 union net_ip_header ip_hdr;
133 union net_proto_header proto_hdr;
135 int peer_id;
136 } vpn;
137#endif
138
139#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
158 struct net_ptp_time timestamp;
159#endif
160
161#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
162 defined(CONFIG_TRACING_NET_CORE)
163 struct {
165 uint32_t create_time;
166
167#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
168 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
174 struct {
175 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
176 int count;
177 } detail;
178#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
179 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
180 };
181#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
182
183#if defined(CONFIG_NET_PKT_ALLOC_STATS)
184 struct net_pkt_alloc_stats_slab *alloc_stats;
185#endif /* CONFIG_NET_PKT_ALLOC_STATS */
186
188 atomic_t atomic_ref;
189
190 /* Filled by layer 2 when network packet is received. */
191 struct net_linkaddr lladdr_src;
192 struct net_linkaddr lladdr_dst;
193 uint16_t ll_proto_type;
194
195#if defined(CONFIG_NET_IP)
196 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
197#endif
198
199 uint8_t overwrite : 1; /* Is packet content being overwritten? */
200 uint8_t eof : 1; /* Last packet before EOF */
201 uint8_t ptp_pkt : 1; /* For outgoing packet: is this packet
202 * a L2 PTP packet.
203 * Used only if defined (CONFIG_NET_L2_PTP)
204 */
205 uint8_t forwarding : 1; /* Are we forwarding this pkt
206 * Used only if defined(CONFIG_NET_ROUTE)
207 */
208 uint8_t family : 3; /* Address family, see net_ip.h */
209
210 /* bitfield byte alignment boundary */
211
212#if defined(CONFIG_NET_IPV4_ACD)
213 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
214 * message.
215 * Note: family needs to be
216 * AF_INET.
217 */
218#endif
219#if defined(CONFIG_NET_LLDP)
220 uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
221 * Note: family needs to be
222 * AF_UNSPEC.
223 */
224#endif
225 uint8_t ppp_msg : 1; /* This is a PPP message */
226 uint8_t captured : 1; /* Set to 1 if this packet is already being
227 * captured
228 */
229 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
230 * and already contains its L2 header to be
231 * preserved. Useful only if
232 * defined(CONFIG_NET_ETHERNET_BRIDGE).
233 */
234 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
235 * processed by the L2
236 */
237 uint8_t chksum_done : 1; /* Checksum has already been computed for
238 * the packet.
239 */
240 uint8_t loopback : 1; /* Packet is a loop back packet. */
241#if defined(CONFIG_NET_IP_FRAGMENT)
242 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
243#endif
244#if defined(CONFIG_NET_PKT_TIMESTAMP)
245 uint8_t tx_timestamping : 1;
246 uint8_t rx_timestamping : 1;
247#endif
248 /* bitfield byte alignment boundary */
249
250#if defined(CONFIG_NET_IP)
251 union {
252 /* IPv6 hop limit or IPv4 ttl for this network packet.
253 * The value is shared between IPv6 and IPv4.
254 */
255#if defined(CONFIG_NET_IPV6)
256 uint8_t ipv6_hop_limit;
257#endif
258#if defined(CONFIG_NET_IPV4)
259 uint8_t ipv4_ttl;
260#endif
261 };
262
263 union {
264#if defined(CONFIG_NET_IPV4)
265 uint8_t ipv4_opts_len; /* length of IPv4 header options */
266#endif
267#if defined(CONFIG_NET_IPV6)
268 uint16_t ipv6_ext_len; /* length of extension headers */
269#endif
270 };
271
272#if defined(CONFIG_NET_IP_FRAGMENT)
273 union {
274#if defined(CONFIG_NET_IPV4_FRAGMENT)
275 struct {
276 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
277 uint16_t id; /* Fragment ID */
278 } ipv4_fragment;
279#endif /* CONFIG_NET_IPV4_FRAGMENT */
280#if defined(CONFIG_NET_IPV6_FRAGMENT)
281 struct {
282 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
283 uint32_t id; /* Fragment id */
284 uint16_t hdr_start; /* Where starts the fragment header */
285 } ipv6_fragment;
286#endif /* CONFIG_NET_IPV6_FRAGMENT */
287 };
288#endif /* CONFIG_NET_IP_FRAGMENT */
289
290#if defined(CONFIG_NET_IPV6)
291 /* Where is the start of the last header before payload data
292 * in IPv6 packet. This is offset value from start of the IPv6
293 * packet. Note that this value should be updated by who ever
294 * adds IPv6 extension headers to the network packet.
295 */
296 uint16_t ipv6_prev_hdr_start;
297
298 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
299 uint8_t ipv6_next_hdr; /* What is the very first next header */
300#endif /* CONFIG_NET_IPV6 */
301
302#if defined(CONFIG_NET_IP_DSCP_ECN)
304 uint8_t ip_dscp : 6;
305
307 uint8_t ip_ecn : 2;
308#endif /* CONFIG_NET_IP_DSCP_ECN */
309#endif /* CONFIG_NET_IP */
310
311#if defined(CONFIG_NET_VLAN)
312 /* VLAN TCI (Tag Control Information). This contains the Priority
313 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
314 * Identifier (VID, called more commonly VLAN tag). This value is
315 * kept in host byte order.
316 */
317 uint16_t vlan_tci;
318#endif /* CONFIG_NET_VLAN */
319
320#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
321 /* Control block which could be used by any layer */
322 union {
323 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
324#if defined(CONFIG_IEEE802154)
325 /* The following structure requires a 4-byte alignment
326 * boundary to avoid padding.
327 */
328 struct net_pkt_cb_ieee802154 cb_ieee802154;
329#endif /* CONFIG_IEEE802154 */
330 } cb;
331#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
332
336 uint8_t priority;
337
338#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
339 /* Remote address of the received packet. This is only used by
340 * network interfaces with an offloaded TCP/IP stack, or if we
341 * have network tunneling in use.
342 */
343 union {
344 struct sockaddr remote;
345
346 /* This will make sure that there is enough storage to store
347 * the address struct. The access to value is via remote
348 * address.
349 */
350 struct sockaddr_storage remote_storage;
351 };
352#endif /* CONFIG_NET_OFFLOAD */
353
354#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
355 /* Tell the capture api that this is a captured packet */
356 uint8_t cooked_mode_pkt : 1;
357#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
358
359#if defined(CONFIG_NET_IPV4_PMTU)
360 /* Path MTU needed for this destination address */
361 uint8_t ipv4_pmtu : 1;
362#endif /* CONFIG_NET_IPV4_PMTU */
363
364 /* @endcond */
365};
366
369/* The interface real ll address */
370static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
371{
372 return net_if_get_link_addr(pkt->iface);
373}
374
375static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
376{
377 return pkt->context;
378}
379
380static inline void net_pkt_set_context(struct net_pkt *pkt,
381 struct net_context *ctx)
382{
383 pkt->context = ctx;
384}
385
386static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
387{
388 return pkt->iface;
389}
390
391static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
392{
393 pkt->iface = iface;
394
395 /* If the network interface is set in pkt, then also set the type of
396 * the network address that is stored in pkt. This is done here so
397 * that the address type is properly set and is not forgotten.
398 */
399 if (iface) {
400 uint8_t type = net_if_get_link_addr(iface)->type;
401
402 pkt->lladdr_src.type = type;
403 pkt->lladdr_dst.type = type;
404 }
405}
406
407static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
408{
409#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
410 return pkt->orig_iface;
411#else
412 return pkt->iface;
413#endif
414}
415
416static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
417 struct net_if *iface)
418{
419#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
420 pkt->orig_iface = iface;
421#else
422 ARG_UNUSED(pkt);
423 ARG_UNUSED(iface);
424#endif
425}
426
427#if defined(CONFIG_NET_VPN)
428static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
429{
430 return pkt->vpn.iface;
431}
432
433static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
434 struct net_if *iface)
435{
436 pkt->vpn.iface = iface;
437}
438
439static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
440{
441 return &pkt->vpn.ip_hdr;
442}
443
444static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
445 union net_ip_header *ip_hdr)
446{
447 pkt->vpn.ip_hdr = *ip_hdr;
448}
449
450static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
451{
452 return &pkt->vpn.proto_hdr;
453}
454
455static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
456 union net_proto_header *proto_hdr)
457{
458 pkt->vpn.proto_hdr = *proto_hdr;
459}
460
461static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
462{
463 return pkt->vpn.peer_id;
464}
465
466static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
467 int peer_id)
468{
469 pkt->vpn.peer_id = peer_id;
470}
471#endif /* CONFIG_NET_VPN */
472
473static inline uint8_t net_pkt_family(struct net_pkt *pkt)
474{
475 return pkt->family;
476}
477
478static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
479{
480 pkt->family = family;
481}
482
483static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
484{
485 return !!(pkt->ptp_pkt);
486}
487
488static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
489{
490 pkt->ptp_pkt = is_ptp;
491}
492
493static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
494{
495#if defined(CONFIG_NET_PKT_TIMESTAMP)
496 return !!(pkt->tx_timestamping);
497#else
498 ARG_UNUSED(pkt);
499
500 return false;
501#endif
502}
503
504static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
505{
506#if defined(CONFIG_NET_PKT_TIMESTAMP)
507 pkt->tx_timestamping = is_timestamping;
508#else
509 ARG_UNUSED(pkt);
510 ARG_UNUSED(is_timestamping);
511#endif
512}
513
514static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
515{
516#if defined(CONFIG_NET_PKT_TIMESTAMP)
517 return !!(pkt->rx_timestamping);
518#else
519 ARG_UNUSED(pkt);
520
521 return false;
522#endif
523}
524
525static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
526{
527#if defined(CONFIG_NET_PKT_TIMESTAMP)
528 pkt->rx_timestamping = is_timestamping;
529#else
530 ARG_UNUSED(pkt);
531 ARG_UNUSED(is_timestamping);
532#endif
533}
534
535static inline bool net_pkt_is_captured(struct net_pkt *pkt)
536{
537 return !!(pkt->captured);
538}
539
540static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
541{
542 pkt->captured = is_captured;
543}
544
545static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
546{
547 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
548}
549
550static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
551{
552 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
553 pkt->l2_bridged = is_l2_bridged;
554 }
555}
556
557static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
558{
559 return !!(pkt->l2_processed);
560}
561
562static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
563 bool is_l2_processed)
564{
565 pkt->l2_processed = is_l2_processed;
566}
567
568static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
569{
570 return !!(pkt->chksum_done);
571}
572
573static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
574 bool is_chksum_done)
575{
576 pkt->chksum_done = is_chksum_done;
577}
578
579static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
580{
581#if defined(CONFIG_NET_IP)
582 return pkt->ip_hdr_len;
583#else
584 ARG_UNUSED(pkt);
585
586 return 0;
587#endif
588}
589
590static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
591{
592#if defined(CONFIG_NET_IP)
593 pkt->ip_hdr_len = len;
594#else
595 ARG_UNUSED(pkt);
596 ARG_UNUSED(len);
597#endif
598}
599
600static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
601{
602#if defined(CONFIG_NET_IP_DSCP_ECN)
603 return pkt->ip_dscp;
604#else
605 ARG_UNUSED(pkt);
606
607 return 0;
608#endif
609}
610
611static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
612{
613#if defined(CONFIG_NET_IP_DSCP_ECN)
614 pkt->ip_dscp = dscp;
615#else
616 ARG_UNUSED(pkt);
617 ARG_UNUSED(dscp);
618#endif
619}
620
621static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
622{
623#if defined(CONFIG_NET_IP_DSCP_ECN)
624 return pkt->ip_ecn;
625#else
626 ARG_UNUSED(pkt);
627
628 return 0;
629#endif
630}
631
632static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
633{
634#if defined(CONFIG_NET_IP_DSCP_ECN)
635 pkt->ip_ecn = ecn;
636#else
637 ARG_UNUSED(pkt);
638 ARG_UNUSED(ecn);
639#endif
640}
641
642static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
643{
644 return pkt->eof;
645}
646
647static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
648{
649 pkt->eof = eof;
650}
651
652static inline bool net_pkt_forwarding(struct net_pkt *pkt)
653{
654 return !!(pkt->forwarding);
655}
656
657static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
658{
659 pkt->forwarding = forward;
660}
661
662#if defined(CONFIG_NET_IPV4)
663static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
664{
665 return pkt->ipv4_ttl;
666}
667
668static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
669 uint8_t ttl)
670{
671 pkt->ipv4_ttl = ttl;
672}
673
674static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
675{
676 return pkt->ipv4_opts_len;
677}
678
679static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
680 uint8_t opts_len)
681{
682 pkt->ipv4_opts_len = opts_len;
683}
684#else
685static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
686{
687 ARG_UNUSED(pkt);
688
689 return 0;
690}
691
692static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
693 uint8_t ttl)
694{
695 ARG_UNUSED(pkt);
696 ARG_UNUSED(ttl);
697}
698
699static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
700{
701 ARG_UNUSED(pkt);
702 return 0;
703}
704
705static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
706 uint8_t opts_len)
707{
708 ARG_UNUSED(pkt);
709 ARG_UNUSED(opts_len);
710}
711#endif
712
713#if defined(CONFIG_NET_IPV6)
714static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
715{
716 return pkt->ipv6_ext_opt_len;
717}
718
719static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
720 uint8_t len)
721{
722 pkt->ipv6_ext_opt_len = len;
723}
724
725static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
726{
727 return pkt->ipv6_next_hdr;
728}
729
730static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
731 uint8_t next_hdr)
732{
733 pkt->ipv6_next_hdr = next_hdr;
734}
735
736static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
737{
738 return pkt->ipv6_ext_len;
739}
740
741static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
742{
743 pkt->ipv6_ext_len = len;
744}
745
746static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
747{
748 return pkt->ipv6_prev_hdr_start;
749}
750
751static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
752 uint16_t offset)
753{
754 pkt->ipv6_prev_hdr_start = offset;
755}
756
757static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
758{
759 return pkt->ipv6_hop_limit;
760}
761
762static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
763 uint8_t hop_limit)
764{
765 pkt->ipv6_hop_limit = hop_limit;
766}
767#else /* CONFIG_NET_IPV6 */
768static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
769{
770 ARG_UNUSED(pkt);
771
772 return 0;
773}
774
775static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
776 uint8_t len)
777{
778 ARG_UNUSED(pkt);
779 ARG_UNUSED(len);
780}
781
782static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
783{
784 ARG_UNUSED(pkt);
785
786 return 0;
787}
788
789static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
790 uint8_t next_hdr)
791{
792 ARG_UNUSED(pkt);
793 ARG_UNUSED(next_hdr);
794}
795
796static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
797{
798 ARG_UNUSED(pkt);
799
800 return 0;
801}
802
803static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
804{
805 ARG_UNUSED(pkt);
806 ARG_UNUSED(len);
807}
808
809static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
810{
811 ARG_UNUSED(pkt);
812
813 return 0;
814}
815
816static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
817 uint16_t offset)
818{
819 ARG_UNUSED(pkt);
820 ARG_UNUSED(offset);
821}
822
823static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
824{
825 ARG_UNUSED(pkt);
826
827 return 0;
828}
829
830static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
831 uint8_t hop_limit)
832{
833 ARG_UNUSED(pkt);
834 ARG_UNUSED(hop_limit);
835}
836#endif /* CONFIG_NET_IPV6 */
837
838static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
839{
840#if defined(CONFIG_NET_IPV6)
841 return pkt->ipv6_ext_len;
842#elif defined(CONFIG_NET_IPV4)
843 return pkt->ipv4_opts_len;
844#else
845 ARG_UNUSED(pkt);
846
847 return 0;
848#endif
849}
850
851#if defined(CONFIG_NET_IPV4_PMTU)
852static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
853{
854 return !!pkt->ipv4_pmtu;
855}
856
857static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
858{
859 pkt->ipv4_pmtu = value;
860}
861#else
862static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
863{
864 ARG_UNUSED(pkt);
865
866 return false;
867}
868
869static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
870{
871 ARG_UNUSED(pkt);
872 ARG_UNUSED(value);
873}
874#endif /* CONFIG_NET_IPV4_PMTU */
875
876#if defined(CONFIG_NET_IPV4_FRAGMENT)
877static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
878{
879 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
880}
881
882static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
883{
884 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
885}
886
887static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
888{
889 pkt->ipv4_fragment.flags = flags;
890}
891
892static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
893{
894 return pkt->ipv4_fragment.id;
895}
896
897static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
898{
899 pkt->ipv4_fragment.id = id;
900}
901#else /* CONFIG_NET_IPV4_FRAGMENT */
902static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
903{
904 ARG_UNUSED(pkt);
905
906 return 0;
907}
908
909static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
910{
911 ARG_UNUSED(pkt);
912
913 return 0;
914}
915
916static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
917{
918 ARG_UNUSED(pkt);
919 ARG_UNUSED(flags);
920}
921
922static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
923{
924 ARG_UNUSED(pkt);
925
926 return 0;
927}
928
929static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
930{
931 ARG_UNUSED(pkt);
932 ARG_UNUSED(id);
933}
934#endif /* CONFIG_NET_IPV4_FRAGMENT */
935
936#if defined(CONFIG_NET_IPV6_FRAGMENT)
937static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
938{
939 return pkt->ipv6_fragment.hdr_start;
940}
941
942static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
943 uint16_t start)
944{
945 pkt->ipv6_fragment.hdr_start = start;
946}
947
948static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
949{
950 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
951}
952static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
953{
954 return (pkt->ipv6_fragment.flags & 0x01) != 0;
955}
956
957static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
959{
960 pkt->ipv6_fragment.flags = flags;
961}
962
963static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
964{
965 return pkt->ipv6_fragment.id;
966}
967
968static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
969 uint32_t id)
970{
971 pkt->ipv6_fragment.id = id;
972}
973#else /* CONFIG_NET_IPV6_FRAGMENT */
974static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
975{
976 ARG_UNUSED(pkt);
977
978 return 0;
979}
980
981static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
982 uint16_t start)
983{
984 ARG_UNUSED(pkt);
985 ARG_UNUSED(start);
986}
987
988static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
989{
990 ARG_UNUSED(pkt);
991
992 return 0;
993}
994
995static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
996{
997 ARG_UNUSED(pkt);
998
999 return 0;
1000}
1001
1002static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1004{
1005 ARG_UNUSED(pkt);
1006 ARG_UNUSED(flags);
1007}
1008
1009static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1010{
1011 ARG_UNUSED(pkt);
1012
1013 return 0;
1014}
1015
1016static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1017 uint32_t id)
1018{
1019 ARG_UNUSED(pkt);
1020 ARG_UNUSED(id);
1021}
1022#endif /* CONFIG_NET_IPV6_FRAGMENT */
1023
1024static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1025{
1026 return !!(pkt->loopback);
1027}
1028
1029static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1030 bool loopback)
1031{
1032 pkt->loopback = loopback;
1033}
1034
1035#if defined(CONFIG_NET_IP_FRAGMENT)
1036static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1037{
1038 return !!(pkt->ip_reassembled);
1039}
1040
1041static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1042 bool reassembled)
1043{
1044 pkt->ip_reassembled = reassembled;
1045}
1046#else /* CONFIG_NET_IP_FRAGMENT */
1047static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1048{
1049 ARG_UNUSED(pkt);
1050
1051 return false;
1052}
1053
1054static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1055 bool reassembled)
1056{
1057 ARG_UNUSED(pkt);
1058 ARG_UNUSED(reassembled);
1059}
1060#endif /* CONFIG_NET_IP_FRAGMENT */
1061
1062static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1063{
1064 return pkt->priority;
1065}
1066
1067static inline void net_pkt_set_priority(struct net_pkt *pkt,
1068 uint8_t priority)
1069{
1070 pkt->priority = priority;
1071}
1072
1073#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1074static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1075{
1076 return pkt->cooked_mode_pkt;
1077}
1078
1079static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1080{
1081 pkt->cooked_mode_pkt = value;
1082}
1083#else
1084static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1085{
1086 ARG_UNUSED(pkt);
1087
1088 return false;
1089}
1090
1091static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1092{
1093 ARG_UNUSED(pkt);
1094 ARG_UNUSED(value);
1095}
1096#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1097
1098#if defined(CONFIG_NET_VLAN)
1099static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1100{
1101 return net_eth_vlan_get_vid(pkt->vlan_tci);
1102}
1103
1104static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1105{
1106 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1107}
1108
1109static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1110{
1111 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1112}
1113
1114static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1115 uint8_t priority)
1116{
1117 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1118}
1119
1120static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1121{
1122 return net_eth_vlan_get_dei(pkt->vlan_tci);
1123}
1124
1125static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1126{
1127 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1128}
1129
1130static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1131{
1132 pkt->vlan_tci = tci;
1133}
1134
1135static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1136{
1137 return pkt->vlan_tci;
1138}
1139#else
1140static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1141{
1142 ARG_UNUSED(pkt);
1143
1144 return NET_VLAN_TAG_UNSPEC;
1145}
1146
1147static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1148{
1149 ARG_UNUSED(pkt);
1150 ARG_UNUSED(tag);
1151}
1152
1153static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1154{
1155 ARG_UNUSED(pkt);
1156
1157 return 0;
1158}
1159
1160static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1161{
1162 ARG_UNUSED(pkt);
1163
1164 return false;
1165}
1166
1167static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1168{
1169 ARG_UNUSED(pkt);
1170 ARG_UNUSED(dei);
1171}
1172
1173static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1174{
1175 ARG_UNUSED(pkt);
1176
1177 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1178}
1179
1180static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1181{
1182 ARG_UNUSED(pkt);
1183 ARG_UNUSED(tci);
1184}
1185#endif
1186
1187#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1188static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1189{
1190 return &pkt->timestamp;
1191}
1192
1193static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1194 struct net_ptp_time *timestamp)
1195{
1196 pkt->timestamp.second = timestamp->second;
1197 pkt->timestamp.nanosecond = timestamp->nanosecond;
1198}
1199
1200static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1201{
1202 return net_ptp_time_to_ns(&pkt->timestamp);
1203}
1204
1205static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1206{
1207 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1208}
1209#else
1210static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1211{
1212 ARG_UNUSED(pkt);
1213
1214 return NULL;
1215}
1216
1217static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1218 struct net_ptp_time *timestamp)
1219{
1220 ARG_UNUSED(pkt);
1221 ARG_UNUSED(timestamp);
1222}
1223
1224static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1225{
1226 ARG_UNUSED(pkt);
1227
1228 return 0;
1229}
1230
1231static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1232{
1233 ARG_UNUSED(pkt);
1234 ARG_UNUSED(timestamp);
1235}
1236#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1237
1238#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1239 defined(CONFIG_TRACING_NET_CORE)
1240
1241static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1242{
1243 return pkt->create_time;
1244}
1245
1246static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1247 uint32_t create_time)
1248{
1249 pkt->create_time = create_time;
1250}
1251#else
1252static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1253{
1254 ARG_UNUSED(pkt);
1255
1256 return 0U;
1257}
1258
1259static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1260 uint32_t create_time)
1261{
1262 ARG_UNUSED(pkt);
1263 ARG_UNUSED(create_time);
1264}
1265#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1266 * CONFIG_TRACING_NET_CORE
1267 */
1268
1269#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1270 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1271static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1272{
1273 return pkt->detail.stat;
1274}
1275
1276static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1277{
1278 return pkt->detail.count;
1279}
1280
1281static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1282{
1283 memset(&pkt->detail, 0, sizeof(pkt->detail));
1284}
1285
1286static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1287 uint32_t tick)
1288{
1289 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1290 NET_ERR("Detail stats count overflow (%d >= %d)",
1291 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1292 return;
1293 }
1294
1295 pkt->detail.stat[pkt->detail.count++] = tick;
1296}
1297
1298#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1299#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1300#else
1301static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1302{
1303 ARG_UNUSED(pkt);
1304
1305 return NULL;
1306}
1307
1308static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1309{
1310 ARG_UNUSED(pkt);
1311
1312 return 0;
1313}
1314
1315static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1316{
1317 ARG_UNUSED(pkt);
1318}
1319
1320static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1321{
1322 ARG_UNUSED(pkt);
1323 ARG_UNUSED(tick);
1324}
1325
1326#define net_pkt_set_tx_stats_tick(pkt, tick)
1327#define net_pkt_set_rx_stats_tick(pkt, tick)
1328#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1329 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1330
1331static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1332{
1333 return pkt->frags->data;
1334}
1335
1336static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1337{
1338 return pkt->frags->data;
1339}
1340
1341static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1342{
1343 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1344}
1345
1346static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1347{
1348 return &pkt->lladdr_src;
1349}
1350
1351static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1352{
1353 return &pkt->lladdr_dst;
1354}
1355
1356static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1357{
1358 struct net_linkaddr tmp;
1359
1360 memcpy(tmp.addr,
1361 net_pkt_lladdr_src(pkt)->addr,
1362 net_pkt_lladdr_src(pkt)->len);
1363 memcpy(net_pkt_lladdr_src(pkt)->addr,
1364 net_pkt_lladdr_dst(pkt)->addr,
1365 net_pkt_lladdr_dst(pkt)->len);
1366 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1367 tmp.addr,
1368 net_pkt_lladdr_src(pkt)->len);
1369}
1370
1371static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1372{
1373 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1374 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1375}
1376
1377static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1378{
1379 return pkt->ll_proto_type;
1380}
1381
1382static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1383{
1384 pkt->ll_proto_type = type;
1385}
1386
1387#if defined(CONFIG_NET_IPV4_ACD)
1388static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1389{
1390 return !!(pkt->ipv4_acd_arp_msg);
1391}
1392
1393static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1394 bool is_acd_arp_msg)
1395{
1396 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1397}
1398#else /* CONFIG_NET_IPV4_ACD */
1399static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1400{
1401 ARG_UNUSED(pkt);
1402
1403 return false;
1404}
1405
1406static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1407 bool is_acd_arp_msg)
1408{
1409 ARG_UNUSED(pkt);
1410 ARG_UNUSED(is_acd_arp_msg);
1411}
1412#endif /* CONFIG_NET_IPV4_ACD */
1413
1414#if defined(CONFIG_NET_LLDP)
1415static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1416{
1417 return !!(pkt->lldp_pkt);
1418}
1419
1420static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1421{
1422 pkt->lldp_pkt = is_lldp;
1423}
1424#else
1425static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1426{
1427 ARG_UNUSED(pkt);
1428
1429 return false;
1430}
1431
1432static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1433{
1434 ARG_UNUSED(pkt);
1435 ARG_UNUSED(is_lldp);
1436}
1437#endif /* CONFIG_NET_LLDP */
1438
1439#if defined(CONFIG_NET_L2_PPP)
1440static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1441{
1442 return !!(pkt->ppp_msg);
1443}
1444
1445static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1446 bool is_ppp_msg)
1447{
1448 pkt->ppp_msg = is_ppp_msg;
1449}
1450#else /* CONFIG_NET_L2_PPP */
1451static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1452{
1453 ARG_UNUSED(pkt);
1454
1455 return false;
1456}
1457
1458static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1459 bool is_ppp_msg)
1460{
1461 ARG_UNUSED(pkt);
1462 ARG_UNUSED(is_ppp_msg);
1463}
1464#endif /* CONFIG_NET_L2_PPP */
1465
1466#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1467static inline void *net_pkt_cb(struct net_pkt *pkt)
1468{
1469 return &pkt->cb;
1470}
1471#else
1472static inline void *net_pkt_cb(struct net_pkt *pkt)
1473{
1474 ARG_UNUSED(pkt);
1475
1476 return NULL;
1477}
1478#endif
1479
1480#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1481#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1482
1483static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1484{
1486 net_pkt_context(pkt)),
1487 (struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1488}
1489
1490static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1491{
1492 pkt->overwrite = overwrite;
1493}
1494
1495static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1496{
1497 return !!(pkt->overwrite);
1498}
1499
1500#ifdef CONFIG_NET_PKT_FILTER
1501
1502bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1503bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1504
1505#else
1506
1507static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1508{
1509 ARG_UNUSED(pkt);
1510
1511 return true;
1512}
1513
1514static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1515{
1516 ARG_UNUSED(pkt);
1517
1518 return true;
1519}
1520
1521#endif /* CONFIG_NET_PKT_FILTER */
1522
1523#if defined(CONFIG_NET_PKT_FILTER) && \
1524 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1525
1526bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1527
1528#else
1529
1530static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1531{
1532 ARG_UNUSED(pkt);
1533
1534 return true;
1535}
1536
1537#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1538
1539#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1540
1541bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1542
1543#else
1544
1545static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1546{
1547 ARG_UNUSED(pkt);
1548
1549 return true;
1550}
1551
1552#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1553
1554#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1555static inline struct sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1556{
1557 return &pkt->remote;
1558}
1559
1560static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1561 struct sockaddr *address,
1562 socklen_t len)
1563{
1564 memcpy(&pkt->remote, address, len);
1565}
1566#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1567
1568/* @endcond */
1569
1583#define NET_PKT_SLAB_DEFINE(name, count) \
1584 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4); \
1585 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1586
1589/* Backward compatibility macro */
1590#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1591
1607#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1608 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1609 0, NULL)
1610
1613#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1614 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1615#define NET_PKT_DEBUG_ENABLED
1616#endif
1617
1618#if defined(NET_PKT_DEBUG_ENABLED)
1619
1620/* Debug versions of the net_pkt functions that are used when tracking
1621 * buffer usage.
1622 */
1623
1624struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1625 size_t min_len,
1626 k_timeout_t timeout,
1627 const char *caller,
1628 int line);
1629
1630#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1631 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1632
1633struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1634 k_timeout_t timeout,
1635 const char *caller,
1636 int line);
1637#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1638 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1639
1640struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1641 k_timeout_t timeout,
1642 const char *caller,
1643 int line);
1644#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1645 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1646
1647struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1648 k_timeout_t timeout,
1649 const char *caller, int line);
1650#define net_pkt_get_frag(pkt, min_len, timeout) \
1651 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1652
1653void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1654#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1655
1656struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1657 int line);
1658#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1659
1660struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1661 const char *caller, int line);
1662#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1663
1664void net_pkt_frag_unref_debug(struct net_buf *frag,
1665 const char *caller, int line);
1666#define net_pkt_frag_unref(frag) \
1667 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1668
1669struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1670 struct net_buf *parent,
1671 struct net_buf *frag,
1672 const char *caller, int line);
1673#define net_pkt_frag_del(pkt, parent, frag) \
1674 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1675
1676void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1677 const char *caller, int line);
1678#define net_pkt_frag_add(pkt, frag) \
1679 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1680
1681void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1682 const char *caller, int line);
1683#define net_pkt_frag_insert(pkt, frag) \
1684 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1685#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1686 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1687 */
1690#if defined(NET_PKT_DEBUG_ENABLED)
1698void net_pkt_print_frags(struct net_pkt *pkt);
1699#else
1700#define net_pkt_print_frags(pkt)
1701#endif
1702
1703#if !defined(NET_PKT_DEBUG_ENABLED)
1719 size_t min_len, k_timeout_t timeout);
1720#endif
1721
1722#if !defined(NET_PKT_DEBUG_ENABLED)
1737struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1738#endif
1739
1740#if !defined(NET_PKT_DEBUG_ENABLED)
1755struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1756#endif
1757
1758#if !defined(NET_PKT_DEBUG_ENABLED)
1771struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1772 k_timeout_t timeout);
1773#endif
1774
1775#if !defined(NET_PKT_DEBUG_ENABLED)
1785void net_pkt_unref(struct net_pkt *pkt);
1786#endif
1787
1788#if !defined(NET_PKT_DEBUG_ENABLED)
1798struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1799#endif
1800
1801#if !defined(NET_PKT_DEBUG_ENABLED)
1811struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1812#endif
1813
1814#if !defined(NET_PKT_DEBUG_ENABLED)
1820void net_pkt_frag_unref(struct net_buf *frag);
1821#endif
1822
1823#if !defined(NET_PKT_DEBUG_ENABLED)
1835 struct net_buf *parent,
1836 struct net_buf *frag);
1837#endif
1838
1839#if !defined(NET_PKT_DEBUG_ENABLED)
1846void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1847#endif
1848
1849#if !defined(NET_PKT_DEBUG_ENABLED)
1856void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1857#endif
1858
1865void net_pkt_compact(struct net_pkt *pkt);
1866
1875void net_pkt_get_info(struct k_mem_slab **rx,
1876 struct k_mem_slab **tx,
1877 struct net_buf_pool **rx_data,
1878 struct net_buf_pool **tx_data);
1879
1882#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1886void net_pkt_print(void);
1887
1888typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1889 struct net_buf *buf,
1890 const char *func_alloc,
1891 int line_alloc,
1892 const char *func_free,
1893 int line_free,
1894 bool in_use,
1895 void *user_data);
1896
1897void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1898
1899const char *net_pkt_slab2str(struct k_mem_slab *slab);
1900const char *net_pkt_pool2str(struct net_buf_pool *pool);
1901
1902#else
1903#define net_pkt_print(...)
1904#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1905
1906/* New allocator, and API are defined below.
1907 * This will be simpler when time will come to get rid of former API above.
1908 */
1909#if defined(NET_PKT_DEBUG_ENABLED)
1910
1911struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1912 const char *caller, int line);
1913#define net_pkt_alloc(_timeout) \
1914 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1915
1916struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1917 k_timeout_t timeout,
1918 const char *caller, int line);
1919#define net_pkt_alloc_from_slab(_slab, _timeout) \
1920 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1921
1922struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1923 const char *caller, int line);
1924#define net_pkt_rx_alloc(_timeout) \
1925 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1926
1927struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1928 k_timeout_t timeout,
1929 const char *caller,
1930 int line);
1931#define net_pkt_alloc_on_iface(_iface, _timeout) \
1932 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1933
1934struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1935 k_timeout_t timeout,
1936 const char *caller,
1937 int line);
1938#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1939 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1940 __func__, __LINE__)
1941
1942int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1943 size_t size,
1944 enum net_ip_protocol proto,
1945 k_timeout_t timeout,
1946 const char *caller, int line);
1947#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1948 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1949 __func__, __LINE__)
1950
1951int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1952 k_timeout_t timeout,
1953 const char *caller, int line);
1954#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1955 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1956 __func__, __LINE__)
1957
1958struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1959 size_t size,
1960 sa_family_t family,
1961 enum net_ip_protocol proto,
1962 k_timeout_t timeout,
1963 const char *caller,
1964 int line);
1965#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1966 _proto, _timeout) \
1967 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1968 _proto, _timeout, \
1969 __func__, __LINE__)
1970
1971struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1972 size_t size,
1973 sa_family_t family,
1974 enum net_ip_protocol proto,
1975 k_timeout_t timeout,
1976 const char *caller,
1977 int line);
1978#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1979 _proto, _timeout) \
1980 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1981 _proto, _timeout, \
1982 __func__, __LINE__)
1983
1984int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
1985 size_t size,
1986 size_t reserve,
1987 enum net_ip_protocol proto,
1988 k_timeout_t timeout,
1989 const char *caller,
1990 int line);
1991#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
1992 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
1993 _timeout, __func__, __LINE__)
1994
1995#endif /* NET_PKT_DEBUG_ENABLED */
1998#if !defined(NET_PKT_DEBUG_ENABLED)
2010#endif
2011
2012#if !defined(NET_PKT_DEBUG_ENABLED)
2027struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2028 k_timeout_t timeout);
2029#endif
2030
2031#if !defined(NET_PKT_DEBUG_ENABLED)
2043#endif
2044
2045#if !defined(NET_PKT_DEBUG_ENABLED)
2055 k_timeout_t timeout);
2056
2059/* Same as above but specifically for RX packet */
2060struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2061 k_timeout_t timeout);
2064#endif
2065
2066#if !defined(NET_PKT_DEBUG_ENABLED)
2083 size_t size,
2084 enum net_ip_protocol proto,
2085 k_timeout_t timeout);
2086#endif
2087
2088#if !defined(NET_PKT_DEBUG_ENABLED)
2106#if !defined(NET_PKT_DEBUG_ENABLED)
2108 size_t size,
2109 size_t reserve,
2110 enum net_ip_protocol proto,
2111 k_timeout_t timeout);
2112#endif
2113
2127int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2128 k_timeout_t timeout);
2129#endif
2130
2131#if !defined(NET_PKT_DEBUG_ENABLED)
2144 size_t size,
2145 sa_family_t family,
2146 enum net_ip_protocol proto,
2147 k_timeout_t timeout);
2148
2151/* Same as above but specifically for RX packet */
2152struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2153 size_t size,
2154 sa_family_t family,
2155 enum net_ip_protocol proto,
2156 k_timeout_t timeout);
2157
2160#endif
2161
2168void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2169
2181
2198 enum net_ip_protocol proto);
2199
2209
2224int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2225
2234
2241static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2242 struct net_pkt_cursor *backup)
2243{
2244 backup->buf = pkt->cursor.buf;
2245 backup->pos = pkt->cursor.pos;
2246}
2247
2254static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2255 struct net_pkt_cursor *backup)
2256{
2257 pkt->cursor.buf = backup->buf;
2258 pkt->cursor.pos = backup->pos;
2259}
2260
2268static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2269{
2270 return pkt->cursor.pos;
2271}
2272
2293int net_pkt_skip(struct net_pkt *pkt, size_t length);
2294
2309int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2310
2324int net_pkt_copy(struct net_pkt *pkt_dst,
2325 struct net_pkt *pkt_src,
2326 size_t length);
2327
2337struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2338
2348struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2349
2359 k_timeout_t timeout);
2360
2374int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2375
2388static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2389{
2390 return net_pkt_read(pkt, data, 1);
2391}
2392
2405int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2406
2419int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2420
2433int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2434
2448int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2449
2462static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2463{
2464 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2465}
2466
2479static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2480{
2481 uint16_t data_be16 = htons(data);
2482
2483 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2484}
2485
2498static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2499{
2500 uint32_t data_be32 = htonl(data);
2501
2502 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2503}
2504
2517static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2518{
2519 uint32_t data_le32 = sys_cpu_to_le32(data);
2520
2521 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2522}
2523
2536static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2537{
2538 uint16_t data_le16 = sys_cpu_to_le16(data);
2539
2540 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2541}
2542
2551
2559static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2560{
2561 return net_buf_frags_len(pkt->frags);
2562}
2563
2576int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2577
2591int net_pkt_pull(struct net_pkt *pkt, size_t length);
2592
2602
2614bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2615
2625
2628struct net_pkt_data_access {
2629#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2630 void *data;
2631#endif
2632 const size_t size;
2633};
2634
2635#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2636#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2637 struct net_pkt_data_access _name = { \
2638 .size = sizeof(_type), \
2639 }
2640
2641#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2642 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2643
2644#else
2645#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2646 _type _hdr_##_name; \
2647 struct net_pkt_data_access _name = { \
2648 .data = &_hdr_##_name, \
2649 .size = sizeof(_type), \
2650 }
2651
2652#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2653 struct net_pkt_data_access _name = { \
2654 .data = NULL, \
2655 .size = sizeof(_type), \
2656 }
2657
2658#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2659
2675void *net_pkt_get_data(struct net_pkt *pkt,
2676 struct net_pkt_data_access *access);
2677
2692 struct net_pkt_data_access *access);
2693
2698static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2699 struct net_pkt_data_access *access)
2700{
2701 return net_pkt_skip(pkt, access->size);
2702}
2703
2708#ifdef __cplusplus
2709}
2710#endif
2711
2712#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
long atomic_t
Definition atomic_types.h:15
VLAN specific definitions.
unsigned short int sa_family_t
Socket address family type.
Definition net_ip.h:168
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:124
size_t socklen_t
Length of a socket address.
Definition net_ip.h:172
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:132
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:2713
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:1204
static const struct in6_addr * net_if_ipv6_select_src_addr(struct net_if *iface, const struct in6_addr *dst)
Get a IPv6 source address that should be used when sending network data to destination.
Definition net_if.h:2212
static int net_linkaddr_clear(struct net_linkaddr *lladdr)
Clear link address.
Definition net_linkaddr.h:196
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:2498
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_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:1700
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.
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.
struct net_pkt * net_pkt_alloc_with_buffer(struct net_if *iface, size_t size, sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate a network packet and buffer at once.
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:2479
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:2559
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.
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:2462
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:2268
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:2241
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:2698
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:2536
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:2254
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:2517
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:2388
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:148
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:160
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
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)
IPv6 address struct.
Definition net_ip.h:143
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1079
Network buffer representation.
Definition net_buf.h:1006
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1032
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1053
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1035
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:726
Hardware link address structure.
Definition net_linkaddr.h:70
uint8_t addr[6]
The array of bytes representing the address.
Definition net_linkaddr.h:78
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:72
uint8_t len
The real length of the ll address.
Definition net_linkaddr.h:75
Network packet.
Definition net_pkt.h:91
struct net_buf * frags
buffer fragment
Definition net_pkt.h:103
struct net_context * context
Network connection context.
Definition net_pkt.h:111
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:108
struct net_if * iface
Network interface.
Definition net_pkt.h:114
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:96
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:104
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:99
(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:410
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