Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_pkt.h
Go to the documentation of this file.
1
10
11/*
12 * Copyright (c) 2016 Intel Corporation
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 */
16
17/* Data buffer API - used for all data to/from net */
18
19#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
20#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
21
22#include <zephyr/types.h>
23#include <stdbool.h>
24
25#include <zephyr/net_buf.h>
26
27#if defined(CONFIG_IEEE802154)
29#endif
30#include <zephyr/net/net_core.h>
32#include <zephyr/net/net_ip.h>
33#include <zephyr/net/net_if.h>
35#include <zephyr/net/net_time.h>
37#include <zephyr/net/ptp_time.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
52
53struct net_context;
54
75#define NET_PKT_FRAG_FOR_EACH(_pkt, _var) \
76 for (struct net_buf *_var = (_pkt)->frags; _var != NULL; \
77 _var = _var->frags)
78
80
81#if defined(CONFIG_NET_PKT_ALLOC_STATS)
82struct net_pkt_alloc_stats {
83 uint64_t alloc_sum;
84 uint64_t time_sum;
85 uint32_t count;
86};
87
88struct net_pkt_alloc_stats_slab {
89 struct net_pkt_alloc_stats ok;
90 struct net_pkt_alloc_stats fail;
91 struct k_mem_slab *slab;
92};
93
94#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
95 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
96 .slab = &slab_name, \
97 }
98
99#else
100#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
101#endif /* CONFIG_NET_PKT_ALLOC_STATS */
102
103/* buffer cursor used in net_pkt */
104struct net_pkt_cursor {
106 struct net_buf *buf;
108 uint8_t *pos;
109};
110
112
119struct net_pkt {
125
127 struct k_mem_slab *slab;
128
130 union {
131 struct net_buf *frags;
132 struct net_buf *buffer;
133 };
134
136 struct net_pkt_cursor cursor;
137
140
142 struct net_if *iface;
143
145
146#if defined(CONFIG_NET_TCP)
148 sys_snode_t next;
149#endif
150#if defined(CONFIG_NET_PKT_ORIG_IFACE)
151 struct net_if *orig_iface; /* Original network interface */
152#endif
153
154#if defined(CONFIG_NET_VPN)
155 struct {
157 struct net_if *iface;
159 union net_ip_header ip_hdr;
161 union net_proto_header proto_hdr;
163 int peer_id;
164 } vpn;
165#endif
166
167#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
186 struct net_ptp_time timestamp;
187#endif
188
189#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
190 defined(CONFIG_TRACING_NET_CORE)
191 struct {
193 uint32_t create_time;
194
195#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
196 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
202 struct {
203 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
204 int count;
205 } detail;
206#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
207 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
208 };
209#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
210
211#if defined(CONFIG_NET_PKT_ALLOC_STATS)
212 struct net_pkt_alloc_stats_slab *alloc_stats;
213#endif /* CONFIG_NET_PKT_ALLOC_STATS */
214
216 atomic_t atomic_ref;
217
218 /* Filled by layer 2 when network packet is received. */
219 struct net_linkaddr lladdr_src;
220 struct net_linkaddr lladdr_dst;
221 uint16_t ll_proto_type;
222
223#if defined(CONFIG_NET_IP)
224 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
225#endif
226
227 uint8_t overwrite : 1; /* Is packet content being overwritten? */
228 uint8_t eof : 1; /* Last packet before EOF */
229 uint8_t forwarding : 1; /* Are we forwarding this pkt
230 * Used only if defined(CONFIG_NET_IPV6_ROUTE)
231 */
232 uint8_t family : 3; /* Address family, see net_ip.h */
233
234 /* bitfield byte alignment boundary */
235
236#if defined(CONFIG_NET_IPV4_ACD)
237 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
238 * message.
239 * Note: family needs to be
240 * NET_AF_INET.
241 */
242#endif
243 uint8_t ppp_msg : 1; /* This is a PPP message */
244 uint8_t captured : 1; /* Set to 1 if this packet is already being
245 * captured
246 */
247 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
248 * and already contains its L2 header to be
249 * preserved. Useful only if
250 * defined(CONFIG_NET_ETHERNET_BRIDGE).
251 */
252 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
253 * processed by the L2
254 */
255 uint8_t chksum_done : 1; /* Checksum has already been computed for
256 * the packet.
257 */
258 uint8_t loopback : 1; /* Packet is a loop back packet. */
259#if defined(CONFIG_NET_IP_FRAGMENT)
260 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
261#endif
262#if defined(CONFIG_NET_PKT_TIMESTAMP)
263 uint8_t tx_timestamping : 1;
264 uint8_t rx_timestamping : 1;
265#endif
266 /* bitfield byte alignment boundary */
267
268#if defined(CONFIG_NET_IP)
269 union {
270 /* IPv6 hop limit or IPv4 ttl for this network packet.
271 * The value is shared between IPv6 and IPv4.
272 */
273#if defined(CONFIG_NET_IPV6)
274 uint8_t ipv6_hop_limit;
275#endif
276#if defined(CONFIG_NET_IPV4)
277 uint8_t ipv4_ttl;
278#endif
279 };
280
281 union {
282#if defined(CONFIG_NET_IPV4)
283 uint8_t ipv4_opts_len; /* length of IPv4 header options */
284#endif
285#if defined(CONFIG_NET_IPV6)
286 uint16_t ipv6_ext_len; /* length of extension headers */
287#endif
288 };
289
290#if defined(CONFIG_NET_IPV4_ROUTE)
291 /* IPv4 address that should be resolved at L2 for transmission.
292 * Routed packets use this to steer link-layer resolution towards the
293 * next on-link IPv4 address.
294 */
295 struct net_in_addr ipv4_ll_resolve_addr;
296#endif /* CONFIG_NET_IPV4_ROUTE */
297
298#if defined(CONFIG_NET_IP_FRAGMENT)
299 union {
300#if defined(CONFIG_NET_IPV4_FRAGMENT)
301 struct {
302 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
303 uint16_t id; /* Fragment ID */
304 } ipv4_fragment;
305#endif /* CONFIG_NET_IPV4_FRAGMENT */
306#if defined(CONFIG_NET_IPV6_FRAGMENT)
307 struct {
308 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
309 uint32_t id; /* Fragment id */
310 uint16_t hdr_start; /* Where starts the fragment header */
311 } ipv6_fragment;
312#endif /* CONFIG_NET_IPV6_FRAGMENT */
313 };
314#endif /* CONFIG_NET_IP_FRAGMENT */
315
316#if defined(CONFIG_NET_IPV6)
317 /* Where is the start of the last header before payload data
318 * in IPv6 packet. This is offset value from start of the IPv6
319 * packet. Note that this value should be updated by who ever
320 * adds IPv6 extension headers to the network packet.
321 */
322 uint16_t ipv6_prev_hdr_start;
323
324 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
325 uint8_t ipv6_next_hdr; /* What is the very first next header */
326#endif /* CONFIG_NET_IPV6 */
327
328#if defined(CONFIG_NET_IP_DSCP_ECN)
330 uint8_t ip_dscp : 6;
331
333 uint8_t ip_ecn : 2;
334#endif /* CONFIG_NET_IP_DSCP_ECN */
335#endif /* CONFIG_NET_IP */
336
337#if defined(CONFIG_NET_VLAN)
338 /* VLAN TCI (Tag Control Information). This contains the Priority
339 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
340 * Identifier (VID, called more commonly VLAN tag). This value is
341 * kept in host byte order.
342 */
343 uint16_t vlan_tci;
344#endif /* CONFIG_NET_VLAN */
345
346#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
347 /* Control block which could be used by any layer */
348 union {
349 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
350#if defined(CONFIG_IEEE802154)
351 /* The following structure requires a 4-byte alignment
352 * boundary to avoid padding.
353 */
354 struct net_pkt_cb_ieee802154 cb_ieee802154;
355#endif /* CONFIG_IEEE802154 */
356 } cb;
357#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
358
362 uint8_t priority;
363
364#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
365 /* Remote address of the received packet. This is only used by
366 * network interfaces with an offloaded TCP/IP stack, or if we
367 * have network tunneling in use.
368 */
369 union {
370 struct net_sockaddr remote;
371
372 /* This will make sure that there is enough storage to store
373 * the address struct. The access to value is via remote
374 * address.
375 */
376 struct net_sockaddr_storage remote_storage;
377 };
378#endif /* CONFIG_NET_OFFLOAD */
379
380#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
381 /* Tell the capture api that this is a captured packet */
382 uint8_t cooked_mode_pkt : 1;
383#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
384
385#if defined(CONFIG_NET_IPV4_PMTU)
386 /* Path MTU needed for this destination address */
387 uint8_t ipv4_pmtu : 1;
388#endif /* CONFIG_NET_IPV4_PMTU */
389#if defined(CONFIG_NET_IPV4_ROUTE)
390 uint8_t ipv4_ll_resolve_addr_set : 1;
391#endif /* CONFIG_NET_IPV4_ROUTE */
392
393 /* Disable local IP fragmentation for this packet. */
394 uint8_t dont_fragment : 1;
395
396 /* @endcond */
397};
398
400
401/* The interface real ll address */
402static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
403{
404 return net_if_get_link_addr(pkt->iface);
405}
406
407static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
408{
409 return pkt->context;
410}
411
412static inline void net_pkt_set_context(struct net_pkt *pkt,
413 struct net_context *ctx)
414{
415 pkt->context = ctx;
416}
417
418static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
419{
420 return pkt->iface;
421}
422
423static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
424{
425 pkt->iface = iface;
426
427 /* If the network interface is set in pkt, then also set the type of
428 * the network address that is stored in pkt. This is done here so
429 * that the address type is properly set and is not forgotten.
430 */
431 if (iface) {
432 uint8_t type = net_if_get_link_addr(iface)->type;
433
434 pkt->lladdr_src.type = type;
435 pkt->lladdr_dst.type = type;
436 }
437}
438
439static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
440{
441#if defined(CONFIG_NET_PKT_ORIG_IFACE)
442 return pkt->orig_iface;
443#else
444 return pkt->iface;
445#endif
446}
447
448static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
449 struct net_if *iface)
450{
451#if defined(CONFIG_NET_PKT_ORIG_IFACE)
452 pkt->orig_iface = iface;
453#else
454 ARG_UNUSED(pkt);
455 ARG_UNUSED(iface);
456#endif
457}
458
459#if defined(CONFIG_NET_VPN)
460static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
461{
462 return pkt->vpn.iface;
463}
464
465static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
466 struct net_if *iface)
467{
468 pkt->vpn.iface = iface;
469}
470
471static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
472{
473 return &pkt->vpn.ip_hdr;
474}
475
476static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
477 union net_ip_header *ip_hdr)
478{
479 pkt->vpn.ip_hdr = *ip_hdr;
480}
481
482static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
483{
484 return &pkt->vpn.proto_hdr;
485}
486
487static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
488 union net_proto_header *proto_hdr)
489{
490 pkt->vpn.proto_hdr = *proto_hdr;
491}
492
493static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
494{
495 return pkt->vpn.peer_id;
496}
497
498static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
499 int peer_id)
500{
501 pkt->vpn.peer_id = peer_id;
502}
503#endif /* CONFIG_NET_VPN */
504
505static inline uint8_t net_pkt_family(struct net_pkt *pkt)
506{
507 return pkt->family;
508}
509
510static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
511{
512 pkt->family = family;
513}
514
515static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
516{
517#if defined(CONFIG_NET_PKT_TIMESTAMP)
518 return !!(pkt->tx_timestamping);
519#else
520 ARG_UNUSED(pkt);
521
522 return false;
523#endif
524}
525
526static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
527{
528#if defined(CONFIG_NET_PKT_TIMESTAMP)
529 pkt->tx_timestamping = is_timestamping;
530#else
531 ARG_UNUSED(pkt);
532 ARG_UNUSED(is_timestamping);
533#endif
534}
535
536static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
537{
538#if defined(CONFIG_NET_PKT_TIMESTAMP)
539 return !!(pkt->rx_timestamping);
540#else
541 ARG_UNUSED(pkt);
542
543 return false;
544#endif
545}
546
547static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
548{
549#if defined(CONFIG_NET_PKT_TIMESTAMP)
550 pkt->rx_timestamping = is_timestamping;
551#else
552 ARG_UNUSED(pkt);
553 ARG_UNUSED(is_timestamping);
554#endif
555}
556
557static inline bool net_pkt_is_captured(struct net_pkt *pkt)
558{
559 return !!(pkt->captured);
560}
561
562static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
563{
564 pkt->captured = is_captured;
565}
566
567static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
568{
569 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
570}
571
572static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
573{
574 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
575 pkt->l2_bridged = is_l2_bridged;
576 }
577}
578
579static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
580{
581 return !!(pkt->l2_processed);
582}
583
584static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
585 bool is_l2_processed)
586{
587 pkt->l2_processed = is_l2_processed;
588}
589
590static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
591{
592 return !!(pkt->chksum_done);
593}
594
595static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
596 bool is_chksum_done)
597{
598 pkt->chksum_done = is_chksum_done;
599}
600
601static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
602{
603#if defined(CONFIG_NET_IP)
604 return pkt->ip_hdr_len;
605#else
606 ARG_UNUSED(pkt);
607
608 return 0;
609#endif
610}
611
612static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
613{
614#if defined(CONFIG_NET_IP)
615 pkt->ip_hdr_len = len;
616#else
617 ARG_UNUSED(pkt);
618 ARG_UNUSED(len);
619#endif
620}
621
622static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
623{
624#if defined(CONFIG_NET_IP_DSCP_ECN)
625 return pkt->ip_dscp;
626#else
627 ARG_UNUSED(pkt);
628
629 return 0;
630#endif
631}
632
633static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
634{
635#if defined(CONFIG_NET_IP_DSCP_ECN)
636 pkt->ip_dscp = dscp;
637#else
638 ARG_UNUSED(pkt);
639 ARG_UNUSED(dscp);
640#endif
641}
642
643static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
644{
645#if defined(CONFIG_NET_IP_DSCP_ECN)
646 return pkt->ip_ecn;
647#else
648 ARG_UNUSED(pkt);
649
650 return 0;
651#endif
652}
653
654static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
655{
656#if defined(CONFIG_NET_IP_DSCP_ECN)
657 pkt->ip_ecn = ecn;
658#else
659 ARG_UNUSED(pkt);
660 ARG_UNUSED(ecn);
661#endif
662}
663
664static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
665{
666 return pkt->eof;
667}
668
669static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
670{
671 pkt->eof = eof;
672}
673
674static inline bool net_pkt_forwarding(struct net_pkt *pkt)
675{
676 return !!(pkt->forwarding);
677}
678
679static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
680{
681 pkt->forwarding = forward;
682}
683
684#if defined(CONFIG_NET_IPV4)
685static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
686{
687 return pkt->ipv4_ttl;
688}
689
690static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
691 uint8_t ttl)
692{
693 pkt->ipv4_ttl = ttl;
694}
695
696static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
697{
698 return pkt->ipv4_opts_len;
699}
700
701static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
702 uint8_t opts_len)
703{
704 pkt->ipv4_opts_len = opts_len;
705}
706#else
707static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
708{
709 ARG_UNUSED(pkt);
710
711 return 0;
712}
713
714static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
715 uint8_t ttl)
716{
717 ARG_UNUSED(pkt);
718 ARG_UNUSED(ttl);
719}
720
721static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
722{
723 ARG_UNUSED(pkt);
724 return 0;
725}
726
727static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
728 uint8_t opts_len)
729{
730 ARG_UNUSED(pkt);
731 ARG_UNUSED(opts_len);
732}
733#endif
734
735#if defined(CONFIG_NET_IPV6)
736static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
737{
738 return pkt->ipv6_ext_opt_len;
739}
740
741static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
742 uint8_t len)
743{
744 pkt->ipv6_ext_opt_len = len;
745}
746
747static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
748{
749 return pkt->ipv6_next_hdr;
750}
751
752static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
753 uint8_t next_hdr)
754{
755 pkt->ipv6_next_hdr = next_hdr;
756}
757
758static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
759{
760 return pkt->ipv6_ext_len;
761}
762
763static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
764{
765 pkt->ipv6_ext_len = len;
766}
767
768static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
769{
770 return pkt->ipv6_prev_hdr_start;
771}
772
773static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
774 uint16_t offset)
775{
776 pkt->ipv6_prev_hdr_start = offset;
777}
778
779static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
780{
781 return pkt->ipv6_hop_limit;
782}
783
784static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
785 uint8_t hop_limit)
786{
787 pkt->ipv6_hop_limit = hop_limit;
788}
789#else /* CONFIG_NET_IPV6 */
790static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
791{
792 ARG_UNUSED(pkt);
793
794 return 0;
795}
796
797static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
798 uint8_t len)
799{
800 ARG_UNUSED(pkt);
801 ARG_UNUSED(len);
802}
803
804static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
805{
806 ARG_UNUSED(pkt);
807
808 return 0;
809}
810
811static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
812 uint8_t next_hdr)
813{
814 ARG_UNUSED(pkt);
815 ARG_UNUSED(next_hdr);
816}
817
818static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
819{
820 ARG_UNUSED(pkt);
821
822 return 0;
823}
824
825static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
826{
827 ARG_UNUSED(pkt);
828 ARG_UNUSED(len);
829}
830
831static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
832{
833 ARG_UNUSED(pkt);
834
835 return 0;
836}
837
838static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
839 uint16_t offset)
840{
841 ARG_UNUSED(pkt);
842 ARG_UNUSED(offset);
843}
844
845static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
846{
847 ARG_UNUSED(pkt);
848
849 return 0;
850}
851
852static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
853 uint8_t hop_limit)
854{
855 ARG_UNUSED(pkt);
856 ARG_UNUSED(hop_limit);
857}
858#endif /* CONFIG_NET_IPV6 */
859
860static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
861{
862#if defined(CONFIG_NET_IPV6)
863 return pkt->ipv6_ext_len;
864#elif defined(CONFIG_NET_IPV4)
865 return pkt->ipv4_opts_len;
866#else
867 ARG_UNUSED(pkt);
868
869 return 0;
870#endif
871}
872
873#if defined(CONFIG_NET_IPV4_PMTU)
874static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
875{
876 return !!pkt->ipv4_pmtu;
877}
878
879static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
880{
881 pkt->ipv4_pmtu = value;
882}
883#else
884static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
885{
886 ARG_UNUSED(pkt);
887
888 return false;
889}
890
891static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
892{
893 ARG_UNUSED(pkt);
894 ARG_UNUSED(value);
895}
896#endif /* CONFIG_NET_IPV4_PMTU */
897
898#if defined(CONFIG_NET_IPV4_ROUTE)
899static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
900{
901 return pkt->ipv4_ll_resolve_addr_set ? &pkt->ipv4_ll_resolve_addr : NULL;
902}
903
904static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
905 const struct net_in_addr *addr)
906{
907 if (addr != NULL) {
908 net_ipaddr_copy(&pkt->ipv4_ll_resolve_addr, addr);
909 pkt->ipv4_ll_resolve_addr_set = 1U;
910 } else {
911 pkt->ipv4_ll_resolve_addr_set = 0U;
912 }
913}
914#else
915static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
916{
917 ARG_UNUSED(pkt);
918
919 return NULL;
920}
921
922static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
923 const struct net_in_addr *addr)
924{
925 ARG_UNUSED(pkt);
926 ARG_UNUSED(addr);
927}
928#endif /* CONFIG_NET_IPV4_ROUTE */
929
930static inline bool net_pkt_dont_fragment(struct net_pkt *pkt)
931{
932 return !!pkt->dont_fragment;
933}
934
935static inline void net_pkt_set_dont_fragment(struct net_pkt *pkt, bool value)
936{
937 pkt->dont_fragment = value;
938}
939
940#if defined(CONFIG_NET_IPV4_FRAGMENT)
941static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
942{
943 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
944}
945
946static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
947{
948 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
949}
950
951static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
952{
953 pkt->ipv4_fragment.flags = flags;
954}
955
956static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
957{
958 return pkt->ipv4_fragment.id;
959}
960
961static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
962{
963 pkt->ipv4_fragment.id = id;
964}
965#else /* CONFIG_NET_IPV4_FRAGMENT */
966static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
967{
968 ARG_UNUSED(pkt);
969
970 return 0;
971}
972
973static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
974{
975 ARG_UNUSED(pkt);
976
977 return 0;
978}
979
980static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
981{
982 ARG_UNUSED(pkt);
983 ARG_UNUSED(flags);
984}
985
986static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
987{
988 ARG_UNUSED(pkt);
989
990 return 0;
991}
992
993static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
994{
995 ARG_UNUSED(pkt);
996 ARG_UNUSED(id);
997}
998#endif /* CONFIG_NET_IPV4_FRAGMENT */
999
1000#if defined(CONFIG_NET_IPV6_FRAGMENT)
1001static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1002{
1003 return pkt->ipv6_fragment.hdr_start;
1004}
1005
1006static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1007 uint16_t start)
1008{
1009 pkt->ipv6_fragment.hdr_start = start;
1010}
1011
1012static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1013{
1014 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
1015}
1016static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1017{
1018 return (pkt->ipv6_fragment.flags & 0x01) != 0;
1019}
1020
1021static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1023{
1024 pkt->ipv6_fragment.flags = flags;
1025}
1026
1027static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1028{
1029 return pkt->ipv6_fragment.id;
1030}
1031
1032static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1033 uint32_t id)
1034{
1035 pkt->ipv6_fragment.id = id;
1036}
1037#else /* CONFIG_NET_IPV6_FRAGMENT */
1038static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1039{
1040 ARG_UNUSED(pkt);
1041
1042 return 0;
1043}
1044
1045static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1046 uint16_t start)
1047{
1048 ARG_UNUSED(pkt);
1049 ARG_UNUSED(start);
1050}
1051
1052static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1053{
1054 ARG_UNUSED(pkt);
1055
1056 return 0;
1057}
1058
1059static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1060{
1061 ARG_UNUSED(pkt);
1062
1063 return 0;
1064}
1065
1066static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1068{
1069 ARG_UNUSED(pkt);
1070 ARG_UNUSED(flags);
1071}
1072
1073static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1074{
1075 ARG_UNUSED(pkt);
1076
1077 return 0;
1078}
1079
1080static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1081 uint32_t id)
1082{
1083 ARG_UNUSED(pkt);
1084 ARG_UNUSED(id);
1085}
1086#endif /* CONFIG_NET_IPV6_FRAGMENT */
1087
1088static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1089{
1090 return !!(pkt->loopback);
1091}
1092
1093static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1094 bool loopback)
1095{
1096 pkt->loopback = loopback;
1097}
1098
1099#if defined(CONFIG_NET_IP_FRAGMENT)
1100static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1101{
1102 return !!(pkt->ip_reassembled);
1103}
1104
1105static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1106 bool reassembled)
1107{
1108 pkt->ip_reassembled = reassembled;
1109}
1110#else /* CONFIG_NET_IP_FRAGMENT */
1111static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1112{
1113 ARG_UNUSED(pkt);
1114
1115 return false;
1116}
1117
1118static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1119 bool reassembled)
1120{
1121 ARG_UNUSED(pkt);
1122 ARG_UNUSED(reassembled);
1123}
1124#endif /* CONFIG_NET_IP_FRAGMENT */
1125
1126static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1127{
1128 return pkt->priority;
1129}
1130
1131static inline void net_pkt_set_priority(struct net_pkt *pkt,
1132 uint8_t priority)
1133{
1134 pkt->priority = priority;
1135}
1136
1137#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1138static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1139{
1140 return pkt->cooked_mode_pkt;
1141}
1142
1143static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1144{
1145 pkt->cooked_mode_pkt = value;
1146}
1147#else
1148static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1149{
1150 ARG_UNUSED(pkt);
1151
1152 return false;
1153}
1154
1155static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1156{
1157 ARG_UNUSED(pkt);
1158 ARG_UNUSED(value);
1159}
1160#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1161
1162#if defined(CONFIG_NET_VLAN)
1163static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1164{
1165 return net_eth_vlan_get_vid(pkt->vlan_tci);
1166}
1167
1168static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1169{
1170 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1171}
1172
1173static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1174{
1175 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1176}
1177
1178static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1179 uint8_t priority)
1180{
1181 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1182}
1183
1184static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1185{
1186 return net_eth_vlan_get_dei(pkt->vlan_tci);
1187}
1188
1189static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1190{
1191 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1192}
1193
1194static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1195{
1196 pkt->vlan_tci = tci;
1197}
1198
1199static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1200{
1201 return pkt->vlan_tci;
1202}
1203#else
1204static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1205{
1206 ARG_UNUSED(pkt);
1207
1208 return NET_VLAN_TAG_UNSPEC;
1209}
1210
1211static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1212{
1213 ARG_UNUSED(pkt);
1214 ARG_UNUSED(tag);
1215}
1216
1217static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1218{
1219 ARG_UNUSED(pkt);
1220
1221 return 0;
1222}
1223
1224static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1225{
1226 ARG_UNUSED(pkt);
1227
1228 return false;
1229}
1230
1231static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1232{
1233 ARG_UNUSED(pkt);
1234 ARG_UNUSED(dei);
1235}
1236
1237static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1238{
1239 ARG_UNUSED(pkt);
1240
1241 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1242}
1243
1244static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1245{
1246 ARG_UNUSED(pkt);
1247 ARG_UNUSED(tci);
1248}
1249#endif
1250
1251#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1252static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1253{
1254 return &pkt->timestamp;
1255}
1256
1257static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1258 struct net_ptp_time *timestamp)
1259{
1260 pkt->timestamp.second = timestamp->second;
1261 pkt->timestamp.nanosecond = timestamp->nanosecond;
1262}
1263
1264static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1265{
1266 return net_ptp_time_to_ns(&pkt->timestamp);
1267}
1268
1269static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1270{
1271 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1272}
1273#else
1274static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1275{
1276 ARG_UNUSED(pkt);
1277
1278 return NULL;
1279}
1280
1281static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1282 struct net_ptp_time *timestamp)
1283{
1284 ARG_UNUSED(pkt);
1285 ARG_UNUSED(timestamp);
1286}
1287
1288static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1289{
1290 ARG_UNUSED(pkt);
1291
1292 return 0;
1293}
1294
1295static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1296{
1297 ARG_UNUSED(pkt);
1298 ARG_UNUSED(timestamp);
1299}
1300#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1301
1302#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1303 defined(CONFIG_TRACING_NET_CORE)
1304
1305static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1306{
1307 return pkt->create_time;
1308}
1309
1310static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1311 uint32_t create_time)
1312{
1313 pkt->create_time = create_time;
1314}
1315#else
1316static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1317{
1318 ARG_UNUSED(pkt);
1319
1320 return 0U;
1321}
1322
1323static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1324 uint32_t create_time)
1325{
1326 ARG_UNUSED(pkt);
1327 ARG_UNUSED(create_time);
1328}
1329#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1330 * CONFIG_TRACING_NET_CORE
1331 */
1332
1333#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1334 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1335static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1336{
1337 return pkt->detail.stat;
1338}
1339
1340static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1341{
1342 return pkt->detail.count;
1343}
1344
1345static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1346{
1347 memset(&pkt->detail, 0, sizeof(pkt->detail));
1348}
1349
1350static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1351 uint32_t tick)
1352{
1353 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1354 printk("ERROR: Detail stats count overflow (%d >= %d)",
1355 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1356 return;
1357 }
1358
1359 pkt->detail.stat[pkt->detail.count++] = tick;
1360}
1361
1362#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1363#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1364#else
1365static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1366{
1367 ARG_UNUSED(pkt);
1368
1369 return NULL;
1370}
1371
1372static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1373{
1374 ARG_UNUSED(pkt);
1375
1376 return 0;
1377}
1378
1379static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1380{
1381 ARG_UNUSED(pkt);
1382}
1383
1384static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1385{
1386 ARG_UNUSED(pkt);
1387 ARG_UNUSED(tick);
1388}
1389
1390#define net_pkt_set_tx_stats_tick(pkt, tick)
1391#define net_pkt_set_rx_stats_tick(pkt, tick)
1392#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1393 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1394
1395static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1396{
1397 return pkt->frags->data;
1398}
1399
1400static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1401{
1402 return pkt->frags->data;
1403}
1404
1405static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1406{
1407 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1408}
1409
1410static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1411{
1412 return &pkt->lladdr_src;
1413}
1414
1415static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1416{
1417 return &pkt->lladdr_dst;
1418}
1419
1420static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1421{
1422 struct net_linkaddr tmp;
1423
1424 memcpy(tmp.addr,
1425 net_pkt_lladdr_src(pkt)->addr,
1426 net_pkt_lladdr_src(pkt)->len);
1427 memcpy(net_pkt_lladdr_src(pkt)->addr,
1428 net_pkt_lladdr_dst(pkt)->addr,
1429 net_pkt_lladdr_dst(pkt)->len);
1430 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1431 tmp.addr,
1432 net_pkt_lladdr_src(pkt)->len);
1433}
1434
1435static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1436{
1437 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1438 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1439}
1440
1441static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1442{
1443 return pkt->ll_proto_type;
1444}
1445
1446static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1447{
1448 pkt->ll_proto_type = type;
1449}
1450
1451#if defined(CONFIG_NET_IPV4_ACD)
1452static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1453{
1454 return !!(pkt->ipv4_acd_arp_msg);
1455}
1456
1457static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1458 bool is_acd_arp_msg)
1459{
1460 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1461}
1462#else /* CONFIG_NET_IPV4_ACD */
1463static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1464{
1465 ARG_UNUSED(pkt);
1466
1467 return false;
1468}
1469
1470static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1471 bool is_acd_arp_msg)
1472{
1473 ARG_UNUSED(pkt);
1474 ARG_UNUSED(is_acd_arp_msg);
1475}
1476#endif /* CONFIG_NET_IPV4_ACD */
1477
1478#if defined(CONFIG_NET_L2_PPP)
1479static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1480{
1481 return !!(pkt->ppp_msg);
1482}
1483
1484static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1485 bool is_ppp_msg)
1486{
1487 pkt->ppp_msg = is_ppp_msg;
1488}
1489#else /* CONFIG_NET_L2_PPP */
1490static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1491{
1492 ARG_UNUSED(pkt);
1493
1494 return false;
1495}
1496
1497static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1498 bool is_ppp_msg)
1499{
1500 ARG_UNUSED(pkt);
1501 ARG_UNUSED(is_ppp_msg);
1502}
1503#endif /* CONFIG_NET_L2_PPP */
1504
1505#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1506static inline void *net_pkt_cb(struct net_pkt *pkt)
1507{
1508 return &pkt->cb;
1509}
1510#else
1511static inline void *net_pkt_cb(struct net_pkt *pkt)
1512{
1513 ARG_UNUSED(pkt);
1514
1515 return NULL;
1516}
1517#endif
1518
1519#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1520#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1521
1522static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1523{
1525 net_pkt_context(pkt)),
1526 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1527}
1528
1529static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1530{
1531 pkt->overwrite = overwrite;
1532}
1533
1534static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1535{
1536 return !!(pkt->overwrite);
1537}
1538
1539#ifdef CONFIG_NET_PKT_FILTER
1540
1541bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1542bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1543
1544#else
1545
1546static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1547{
1548 ARG_UNUSED(pkt);
1549
1550 return true;
1551}
1552
1553static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1554{
1555 ARG_UNUSED(pkt);
1556
1557 return true;
1558}
1559
1560#endif /* CONFIG_NET_PKT_FILTER */
1561
1562#if defined(CONFIG_NET_PKT_FILTER) && \
1563 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1564
1565bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1566
1567#else
1568
1569static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1570{
1571 ARG_UNUSED(pkt);
1572
1573 return true;
1574}
1575
1576#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1577
1578#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1579
1580bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1581
1582#else
1583
1584static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1585{
1586 ARG_UNUSED(pkt);
1587
1588 return true;
1589}
1590
1591#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1592
1593#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1594static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1595{
1596 return &pkt->remote;
1597}
1598
1599static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1600 struct net_sockaddr *address,
1601 net_socklen_t len)
1602{
1603 memcpy(&pkt->remote, address, len);
1604}
1605#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1606
1607/* @endcond */
1608
1622#define NET_PKT_SLAB_DEFINE(name, count) \
1623 K_MEM_SLAB_DEFINE_TYPE(name, struct net_pkt, count); \
1624 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1625
1627
1628/* Backward compatibility macro */
1629#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1630
1632
1646#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1647 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1648 0, NULL)
1649
1651
1652#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1653 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1654#define NET_PKT_DEBUG_ENABLED
1655#endif
1656
1657#if defined(NET_PKT_DEBUG_ENABLED)
1658
1659/* Debug versions of the net_pkt functions that are used when tracking
1660 * buffer usage.
1661 */
1662
1663struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1664 size_t min_len,
1665 k_timeout_t timeout,
1666 const char *caller,
1667 int line);
1668
1669#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1670 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1671
1672struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1673 k_timeout_t timeout,
1674 const char *caller,
1675 int line);
1676#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1677 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1678
1679struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1680 k_timeout_t timeout,
1681 const char *caller,
1682 int line);
1683#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1684 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1685
1686struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1687 k_timeout_t timeout,
1688 const char *caller, int line);
1689#define net_pkt_get_frag(pkt, min_len, timeout) \
1690 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1691
1692void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1693#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1694
1695struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1696 int line);
1697#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1698
1699struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1700 const char *caller, int line);
1701#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1702
1703void net_pkt_frag_unref_debug(struct net_buf *frag,
1704 const char *caller, int line);
1705#define net_pkt_frag_unref(frag) \
1706 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1707
1708struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1709 struct net_buf *parent,
1710 struct net_buf *frag,
1711 const char *caller, int line);
1712#define net_pkt_frag_del(pkt, parent, frag) \
1713 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1714
1715void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1716 const char *caller, int line);
1717#define net_pkt_frag_add(pkt, frag) \
1718 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1719
1720void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1721 const char *caller, int line);
1722#define net_pkt_frag_insert(pkt, frag) \
1723 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1724#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1725 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1726 */
1728
1729#if defined(NET_PKT_DEBUG_ENABLED)
1737void net_pkt_print_frags(struct net_pkt *pkt);
1738#else
1739#define net_pkt_print_frags(pkt)
1740#endif
1741
1742#if !defined(NET_PKT_DEBUG_ENABLED)
1758 size_t min_len, k_timeout_t timeout);
1759#endif
1760
1761#if !defined(NET_PKT_DEBUG_ENABLED)
1776struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1777#endif
1778
1779#if !defined(NET_PKT_DEBUG_ENABLED)
1794struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1795#endif
1796
1797#if !defined(NET_PKT_DEBUG_ENABLED)
1810struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1811 k_timeout_t timeout);
1812#endif
1813
1814#if !defined(NET_PKT_DEBUG_ENABLED)
1824void net_pkt_unref(struct net_pkt *pkt);
1825#endif
1826
1827#if !defined(NET_PKT_DEBUG_ENABLED)
1837struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1838#endif
1839
1840#if !defined(NET_PKT_DEBUG_ENABLED)
1850struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1851#endif
1852
1853#if !defined(NET_PKT_DEBUG_ENABLED)
1859void net_pkt_frag_unref(struct net_buf *frag);
1860#endif
1861
1862#if !defined(NET_PKT_DEBUG_ENABLED)
1874 struct net_buf *parent,
1875 struct net_buf *frag);
1876#endif
1877
1878#if !defined(NET_PKT_DEBUG_ENABLED)
1885void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1886#endif
1887
1888#if !defined(NET_PKT_DEBUG_ENABLED)
1895void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1896#endif
1897
1904void net_pkt_compact(struct net_pkt *pkt);
1905
1914void net_pkt_get_info(struct k_mem_slab **rx,
1915 struct k_mem_slab **tx,
1916 struct net_buf_pool **rx_data,
1917 struct net_buf_pool **tx_data);
1918
1920
1921#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1925void net_pkt_print(void);
1926
1927typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1928 struct net_buf *buf,
1929 const char *func_alloc,
1930 int line_alloc,
1931 const char *func_free,
1932 int line_free,
1933 bool in_use,
1934 void *user_data);
1935
1936void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1937
1938const char *net_pkt_slab2str(struct k_mem_slab *slab);
1939const char *net_pkt_pool2str(struct net_buf_pool *pool);
1940
1941#else
1942#define net_pkt_print(...)
1943#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1944
1945/* New allocator, and API are defined below.
1946 * This will be simpler when time will come to get rid of former API above.
1947 */
1948#if defined(NET_PKT_DEBUG_ENABLED)
1949
1950struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1951 const char *caller, int line);
1952#define net_pkt_alloc(_timeout) \
1953 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1954
1955struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1956 k_timeout_t timeout,
1957 const char *caller, int line);
1958#define net_pkt_alloc_from_slab(_slab, _timeout) \
1959 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1960
1961struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1962 const char *caller, int line);
1963#define net_pkt_rx_alloc(_timeout) \
1964 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1965
1966struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1967 k_timeout_t timeout,
1968 const char *caller,
1969 int line);
1970#define net_pkt_alloc_on_iface(_iface, _timeout) \
1971 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1972
1973struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1974 k_timeout_t timeout,
1975 const char *caller,
1976 int line);
1977#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1978 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1979 __func__, __LINE__)
1980
1981int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1982 size_t size,
1983 enum net_ip_protocol proto,
1984 k_timeout_t timeout,
1985 const char *caller, int line);
1986#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1987 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1988 __func__, __LINE__)
1989
1990int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1991 k_timeout_t timeout,
1992 const char *caller, int line);
1993#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1994 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1995 __func__, __LINE__)
1996
1997struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1998 size_t size,
1999 net_sa_family_t family,
2000 enum net_ip_protocol proto,
2001 k_timeout_t timeout,
2002 const char *caller,
2003 int line);
2004#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
2005 _proto, _timeout) \
2006 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
2007 _proto, _timeout, \
2008 __func__, __LINE__)
2009
2010struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
2011 size_t size,
2012 net_sa_family_t family,
2013 enum net_ip_protocol proto,
2014 k_timeout_t timeout,
2015 const char *caller,
2016 int line);
2017#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
2018 _proto, _timeout) \
2019 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
2020 _proto, _timeout, \
2021 __func__, __LINE__)
2022
2023int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
2024 size_t size,
2025 size_t reserve,
2026 enum net_ip_protocol proto,
2027 k_timeout_t timeout,
2028 const char *caller,
2029 int line);
2030#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
2031 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
2032 _timeout, __func__, __LINE__)
2033
2034#endif /* NET_PKT_DEBUG_ENABLED */
2036
2037#if !defined(NET_PKT_DEBUG_ENABLED)
2049#endif
2050
2051#if !defined(NET_PKT_DEBUG_ENABLED)
2066struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2067 k_timeout_t timeout);
2068#endif
2069
2070#if !defined(NET_PKT_DEBUG_ENABLED)
2082#endif
2083
2084#if !defined(NET_PKT_DEBUG_ENABLED)
2094 k_timeout_t timeout);
2095
2097
2098/* Same as above but specifically for RX packet */
2099struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2100 k_timeout_t timeout);
2102
2103#endif
2104
2105#if !defined(NET_PKT_DEBUG_ENABLED)
2122 size_t size,
2123 enum net_ip_protocol proto,
2124 k_timeout_t timeout);
2125#endif
2126
2127#if !defined(NET_PKT_DEBUG_ENABLED)
2145#if !defined(NET_PKT_DEBUG_ENABLED)
2147 size_t size,
2148 size_t reserve,
2149 enum net_ip_protocol proto,
2150 k_timeout_t timeout);
2151#endif
2152
2166int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2167 k_timeout_t timeout);
2168#endif
2169
2170#if !defined(NET_PKT_DEBUG_ENABLED)
2183 size_t size,
2184 net_sa_family_t family,
2185 enum net_ip_protocol proto,
2186 k_timeout_t timeout);
2187
2189
2190/* Same as above but specifically for RX packet */
2191struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2192 size_t size,
2193 net_sa_family_t family,
2194 enum net_ip_protocol proto,
2195 k_timeout_t timeout);
2196
2198
2199#endif
2200
2207void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2208
2220
2237 enum net_ip_protocol proto);
2238
2248
2263int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2264
2273
2280static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2281 struct net_pkt_cursor *backup)
2282{
2283 backup->buf = pkt->cursor.buf;
2284 backup->pos = pkt->cursor.pos;
2285}
2286
2293static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2294 struct net_pkt_cursor *backup)
2295{
2296 pkt->cursor.buf = backup->buf;
2297 pkt->cursor.pos = backup->pos;
2298}
2299
2307static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2308{
2309 return pkt->cursor.pos;
2310}
2311
2329int net_pkt_skip(struct net_pkt *pkt, size_t length);
2330
2345int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2346
2360int net_pkt_copy(struct net_pkt *pkt_dst,
2361 struct net_pkt *pkt_src,
2362 size_t length);
2363
2373struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2374
2384struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2385
2395 k_timeout_t timeout);
2396
2410int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2411
2424static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2425{
2426 return net_pkt_read(pkt, data, 1);
2427}
2428
2441int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2442
2455int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2456
2469int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2470
2483int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2484
2497int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2498
2511int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2512
2526int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2527
2540static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2541{
2542 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2543}
2544
2557static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2558{
2559 uint16_t data_be16 = net_htons(data);
2560
2561 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2562}
2563
2576static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2577{
2578 uint32_t data_be32 = net_htonl(data);
2579
2580 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2581}
2582
2595static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2596{
2597 uint32_t data_le32 = sys_cpu_to_le32(data);
2598
2599 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2600}
2601
2614static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2615{
2616 uint16_t data_le16 = sys_cpu_to_le16(data);
2617
2618 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2619}
2620
2629
2637static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2638{
2639 return net_buf_frags_len(pkt->frags);
2640}
2641
2654int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2655
2669int net_pkt_pull(struct net_pkt *pkt, size_t length);
2670
2680
2692bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2693
2703
2705
2706struct net_pkt_data_access {
2707#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2708 void *data;
2709#endif
2710 const size_t size;
2711};
2712
2713#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2714#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2715 struct net_pkt_data_access _name = { \
2716 .size = sizeof(_type), \
2717 }
2718
2719#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2720 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2721
2722#else
2723#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2724 _type _hdr_##_name; \
2725 struct net_pkt_data_access _name = { \
2726 .data = &_hdr_##_name, \
2727 .size = sizeof(_type), \
2728 }
2729
2730#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2731 struct net_pkt_data_access _name = { \
2732 .data = NULL, \
2733 .size = sizeof(_type), \
2734 }
2735
2736#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2737
2739
2753void *net_pkt_get_data(struct net_pkt *pkt,
2754 struct net_pkt_data_access *access);
2755
2770 struct net_pkt_data_access *access);
2771
2776static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2777 struct net_pkt_data_access *access)
2778{
2779 return net_pkt_skip(pkt, access->size);
2780}
2781
2785
2786#ifdef __cplusplus
2787}
2788#endif
2789
2790#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
VLAN specific definitions.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:31
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:172
#define net_htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:133
#define net_ipaddr_copy(dest, src)
Copy an IPv4 or IPv6 address.
Definition net_ip.h:1070
unsigned short int net_sa_family_t
Socket address family type.
Definition net_ip.h:169
#define net_htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:125
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2852
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:700
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1269
static const struct net_in6_addr * net_if_ipv6_select_src_addr(struct net_if *iface, const struct net_in6_addr *dst)
Get a IPv6 source address that should be used when sending network data to destination.
Definition net_if.h:2253
static int net_linkaddr_clear(struct net_linkaddr *lladdr)
Clear link address.
Definition net_linkaddr.h:209
void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag)
Add a fragment to a packet at the end of its fragment list.
static int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
Write a uint32_t big endian data to a net_pkt.
Definition net_pkt.h:2576
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:1739
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:2557
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:2637
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:2540
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:2307
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:2280
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:2776
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:2614
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:2293
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:2595
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:2424
struct net_buf * net_pkt_get_frag(struct net_pkt *pkt, size_t min_len, k_timeout_t timeout)
Get a data fragment that might be from user specific buffer pool or from global DATA pool.
size_t net_pkt_get_contiguous_len(struct net_pkt *pkt)
Get the contiguous buffer space.
int64_t net_time_t
Any occurrence of net_time_t specifies a concept of nanosecond resolution scalar time span,...
Definition net_time.h:103
static net_time_t net_ptp_time_to_ns(struct net_ptp_time *ts)
Convert a PTP timestamp to a nanosecond precision timestamp, both related to the local network refere...
Definition ptp_time.h:210
static struct net_ptp_time ns_to_net_ptp_time(net_time_t nsec)
Convert a nanosecond precision timestamp to a PTP timestamp, both related to the local network refere...
Definition ptp_time.h:231
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:42
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:154
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:81
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:56
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition ethernet_vlan.h:32
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition ethernet_vlan.h:94
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:44
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:107
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:68
Packet data common to all IEEE 802.15.4 L2 layers.
Buffer management.
Network context definitions.
Network core definitions.
Public API for network interface.
IPv6 and IPv4 definitions.
Public API for network link address.
Representation of nanosecond resolution elapsed time and timestamps in the network stack.
flags
Definition parser.h:97
static void printk(const char *fmt,...)
Print kernel debugging message.
Definition printk.h:64
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:203
Network Interface structure.
Definition net_if.h:733
IPv6 address struct.
Definition net_ip.h:144
IPv4 address struct.
Definition net_ip.h:156
Hardware link address structure.
Definition net_linkaddr.h:83
uint8_t addr[6]
The array of bytes representing the address.
Definition net_linkaddr.h:91
uint8_t type
What kind of address is this for.
Definition net_linkaddr.h:85
uint8_t len
The real length of the ll address.
Definition net_linkaddr.h:88
Network packet.
Definition net_pkt.h:119
struct net_buf * frags
buffer fragment
Definition net_pkt.h:131
struct net_context * context
Network connection context.
Definition net_pkt.h:139
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:136
struct net_if * iface
Network interface.
Definition net_pkt.h:142
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:124
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:132
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:127
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
uint32_t nanosecond
Nanoseconds.
Definition ptp_time.h:134
uint64_t second
Second value.
Definition ptp_time.h:130
Generic sockaddr struct.
Definition net_ip.h:455
Definition stat.h:57
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition byteorder.h:284
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:280