Zephyr API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_pkt.h
Go to the documentation of this file.
1
10
11/*
12 * Copyright (c) 2016 Intel Corporation
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 */
16
17/* Data buffer API - used for all data to/from net */
18
19#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
20#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
21
22#include <zephyr/types.h>
23#include <stdbool.h>
24
25#include <zephyr/net_buf.h>
26
27#if defined(CONFIG_IEEE802154)
29#endif
30#include <zephyr/net/net_core.h>
32#include <zephyr/net/net_ip.h>
33#include <zephyr/net/net_if.h>
35#include <zephyr/net/net_time.h>
37#include <zephyr/net/ptp_time.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
52
53struct net_context;
54
75#define NET_PKT_FRAG_FOR_EACH(_pkt, _var) \
76 for (struct net_buf *_var = (_pkt)->frags; _var != NULL; \
77 _var = _var->frags)
78
80
81#if defined(CONFIG_NET_PKT_ALLOC_STATS)
82struct net_pkt_alloc_stats {
83 uint64_t alloc_sum;
84 uint64_t time_sum;
85 uint32_t count;
86};
87
88struct net_pkt_alloc_stats_slab {
89 struct net_pkt_alloc_stats ok;
90 struct net_pkt_alloc_stats fail;
91 struct k_mem_slab *slab;
92};
93
94#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
95 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
96 .slab = &slab_name, \
97 }
98
99#else
100#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
101#endif /* CONFIG_NET_PKT_ALLOC_STATS */
102
103/* buffer cursor used in net_pkt */
104struct net_pkt_cursor {
106 struct net_buf *buf;
108 uint8_t *pos;
109};
110
112
119struct net_pkt {
125
127 struct k_mem_slab *slab;
128
130 union {
131 struct net_buf *frags;
132 struct net_buf *buffer;
133 };
134
136 struct net_pkt_cursor cursor;
137
140
142 struct net_if *iface;
143
145
146 /* TCP or UDP are mutually exclusive so they can share the same memory */
147 union {
148#if defined(CONFIG_NET_TCP)
150 sys_snode_t next;
151#endif
152#if defined(CONFIG_NET_UDP_OPTIONS)
154 uint16_t udp_opt_surplus_len;
155#endif
156 };
157
158#if defined(CONFIG_NET_PKT_ORIG_IFACE)
159 struct net_if *orig_iface; /* Original network interface */
160#endif
161
162#if defined(CONFIG_NET_VPN)
163 struct {
165 struct net_if *iface;
167 union net_ip_header ip_hdr;
169 union net_proto_header proto_hdr;
171 int peer_id;
172 } vpn;
173#endif
174
175#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
194 struct net_ptp_time timestamp;
195#endif
196
197#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
198 defined(CONFIG_TRACING_NET_CORE)
199 struct {
201 uint32_t create_time;
202
203#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
204 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
210 struct {
211 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
212 int count;
213 } detail;
214#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
215 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
216 };
217#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
218
219#if defined(CONFIG_NET_PKT_ALLOC_STATS)
220 struct net_pkt_alloc_stats_slab *alloc_stats;
221#endif /* CONFIG_NET_PKT_ALLOC_STATS */
222
224 atomic_t atomic_ref;
225
226 /* Filled by layer 2 when network packet is received. */
227 struct net_linkaddr lladdr_src;
228 struct net_linkaddr lladdr_dst;
229 uint16_t ll_proto_type;
230
231#if defined(CONFIG_NET_IP)
232 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
233#endif
234
235 uint8_t overwrite : 1; /* Is packet content being overwritten? */
236 uint8_t eof : 1; /* Last packet before EOF */
237 uint8_t forwarding : 1; /* Are we forwarding this pkt
238 * Used only if defined(CONFIG_NET_IPV6_ROUTE)
239 */
240 uint8_t family : 3; /* Address family, see net_ip.h */
241
242 /* bitfield byte alignment boundary */
243
244#if defined(CONFIG_NET_IPV4_ACD)
245 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
246 * message.
247 * Note: family needs to be
248 * NET_AF_INET.
249 */
250#endif
251 uint8_t ppp_msg : 1; /* This is a PPP message */
252 uint8_t captured : 1; /* Set to 1 if this packet is already being
253 * captured
254 */
255 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
256 * and already contains its L2 header to be
257 * preserved. Useful only if
258 * defined(CONFIG_NET_ETHERNET_BRIDGE).
259 */
260 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
261 * processed by the L2
262 */
263 uint8_t chksum_done : 1; /* Checksum has already been computed for
264 * the packet.
265 */
266 uint8_t loopback : 1; /* Packet is a loop back packet. */
267#if defined(CONFIG_NET_IP_FRAGMENT)
268 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
269#endif
270#if defined(CONFIG_NET_PKT_TIMESTAMP)
271 uint8_t tx_timestamping : 1;
272 uint8_t rx_timestamping : 1;
273#endif
274 /* bitfield byte alignment boundary */
275
276#if defined(CONFIG_NET_IP)
277 union {
278 /* IPv6 hop limit or IPv4 ttl for this network packet.
279 * The value is shared between IPv6 and IPv4.
280 */
281#if defined(CONFIG_NET_IPV6)
282 uint8_t ipv6_hop_limit;
283#endif
284#if defined(CONFIG_NET_IPV4)
285 uint8_t ipv4_ttl;
286#endif
287 };
288
289 union {
290#if defined(CONFIG_NET_IPV4)
291 uint8_t ipv4_opts_len; /* length of IPv4 header options */
292#endif
293#if defined(CONFIG_NET_IPV6)
294 uint16_t ipv6_ext_len; /* length of extension headers */
295#endif
296 };
297
298#if defined(CONFIG_NET_IPV4_ROUTE)
299 /* IPv4 address that should be resolved at L2 for transmission.
300 * Routed packets use this to steer link-layer resolution towards the
301 * next on-link IPv4 address.
302 */
303 struct net_in_addr ipv4_ll_resolve_addr;
304#endif /* CONFIG_NET_IPV4_ROUTE */
305
306#if defined(CONFIG_NET_IP_FRAGMENT)
307 union {
308#if defined(CONFIG_NET_IPV4_FRAGMENT)
309 struct {
310 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
311 uint16_t id; /* Fragment ID */
312 } ipv4_fragment;
313#endif /* CONFIG_NET_IPV4_FRAGMENT */
314#if defined(CONFIG_NET_IPV6_FRAGMENT)
315 struct {
316 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
317 uint32_t id; /* Fragment id */
318 uint16_t hdr_start; /* Where starts the fragment header */
319 } ipv6_fragment;
320#endif /* CONFIG_NET_IPV6_FRAGMENT */
321 };
322#endif /* CONFIG_NET_IP_FRAGMENT */
323
324#if defined(CONFIG_NET_IPV6)
325 /* Where is the start of the last header before payload data
326 * in IPv6 packet. This is offset value from start of the IPv6
327 * packet. Note that this value should be updated by who ever
328 * adds IPv6 extension headers to the network packet.
329 */
330 uint16_t ipv6_prev_hdr_start;
331
332 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
333 uint8_t ipv6_next_hdr; /* What is the very first next header */
334#endif /* CONFIG_NET_IPV6 */
335
336#if defined(CONFIG_NET_IP_DSCP_ECN)
338 uint8_t ip_dscp : 6;
339
341 uint8_t ip_ecn : 2;
342#endif /* CONFIG_NET_IP_DSCP_ECN */
343#endif /* CONFIG_NET_IP */
344
345#if defined(CONFIG_NET_VLAN)
346 /* VLAN TCI (Tag Control Information). This contains the Priority
347 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
348 * Identifier (VID, called more commonly VLAN tag). This value is
349 * kept in host byte order.
350 */
351 uint16_t vlan_tci;
352#endif /* CONFIG_NET_VLAN */
353
354#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
355 /* Control block which could be used by any layer */
356 union {
357 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
358#if defined(CONFIG_IEEE802154)
359 /* The following structure requires a 4-byte alignment
360 * boundary to avoid padding.
361 */
362 struct net_pkt_cb_ieee802154 cb_ieee802154;
363#endif /* CONFIG_IEEE802154 */
364 } cb;
365#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
366
370 uint8_t priority;
371
372#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
373 /* Remote address of the received packet. This is only used by
374 * network interfaces with an offloaded TCP/IP stack, or if we
375 * have network tunneling in use.
376 */
377 union {
378 struct net_sockaddr remote;
379
380 /* This will make sure that there is enough storage to store
381 * the address struct. The access to value is via remote
382 * address.
383 */
384 struct net_sockaddr_storage remote_storage;
385 };
386#endif /* CONFIG_NET_OFFLOAD */
387
388#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
389 /* Tell the capture api that this is a captured packet */
390 uint8_t cooked_mode_pkt : 1;
391#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
392
393#if defined(CONFIG_NET_IPV4_PMTU)
394 /* Path MTU needed for this destination address */
395 uint8_t ipv4_pmtu : 1;
396#endif /* CONFIG_NET_IPV4_PMTU */
397#if defined(CONFIG_NET_IPV4_ROUTE)
398 uint8_t ipv4_ll_resolve_addr_set : 1;
399#endif /* CONFIG_NET_IPV4_ROUTE */
400
401 /* Disable local IP fragmentation for this packet. */
402 uint8_t dont_fragment : 1;
403
404 /* @endcond */
405};
406
408
409/* The interface real ll address */
410static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
411{
412 return net_if_get_link_addr(pkt->iface);
413}
414
415static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
416{
417 return pkt->context;
418}
419
420static inline void net_pkt_set_context(struct net_pkt *pkt,
421 struct net_context *ctx)
422{
423 pkt->context = ctx;
424}
425
426static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
427{
428 return pkt->iface;
429}
430
431static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
432{
433 pkt->iface = iface;
434
435 /* If the network interface is set in pkt, then also set the type of
436 * the network address that is stored in pkt. This is done here so
437 * that the address type is properly set and is not forgotten.
438 */
439 if (iface) {
440 uint8_t type = net_if_get_link_addr(iface)->type;
441
442 pkt->lladdr_src.type = type;
443 pkt->lladdr_dst.type = type;
444 }
445}
446
447static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
448{
449#if defined(CONFIG_NET_PKT_ORIG_IFACE)
450 return pkt->orig_iface;
451#else
452 return pkt->iface;
453#endif
454}
455
456static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
457 struct net_if *iface)
458{
459#if defined(CONFIG_NET_PKT_ORIG_IFACE)
460 pkt->orig_iface = iface;
461#else
462 ARG_UNUSED(pkt);
463 ARG_UNUSED(iface);
464#endif
465}
466
467#if defined(CONFIG_NET_VPN)
468static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
469{
470 return pkt->vpn.iface;
471}
472
473static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
474 struct net_if *iface)
475{
476 pkt->vpn.iface = iface;
477}
478
479static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
480{
481 return &pkt->vpn.ip_hdr;
482}
483
484static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
485 union net_ip_header *ip_hdr)
486{
487 pkt->vpn.ip_hdr = *ip_hdr;
488}
489
490static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
491{
492 return &pkt->vpn.proto_hdr;
493}
494
495static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
496 union net_proto_header *proto_hdr)
497{
498 pkt->vpn.proto_hdr = *proto_hdr;
499}
500
501static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
502{
503 return pkt->vpn.peer_id;
504}
505
506static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
507 int peer_id)
508{
509 pkt->vpn.peer_id = peer_id;
510}
511#endif /* CONFIG_NET_VPN */
512
513#if defined(CONFIG_NET_UDP_OPTIONS)
514static inline uint16_t net_pkt_udp_opt_surplus_len(struct net_pkt *pkt)
515{
516 return pkt->udp_opt_surplus_len;
517}
518
519static inline void net_pkt_set_udp_opt_surplus_len(struct net_pkt *pkt,
520 uint16_t len)
521{
522 pkt->udp_opt_surplus_len = len;
523}
524#else
525static inline uint16_t net_pkt_udp_opt_surplus_len(struct net_pkt *pkt)
526{
527 return 0;
528}
529
530#define net_pkt_set_udp_opt_surplus_len(...)
531#endif /* CONFIG_NET_UDP_OPTIONS */
532
533static inline uint8_t net_pkt_family(struct net_pkt *pkt)
534{
535 return pkt->family;
536}
537
538static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
539{
540 pkt->family = family;
541}
542
543static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
544{
545#if defined(CONFIG_NET_PKT_TIMESTAMP)
546 return !!(pkt->tx_timestamping);
547#else
548 ARG_UNUSED(pkt);
549
550 return false;
551#endif
552}
553
554static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
555{
556#if defined(CONFIG_NET_PKT_TIMESTAMP)
557 pkt->tx_timestamping = is_timestamping;
558#else
559 ARG_UNUSED(pkt);
560 ARG_UNUSED(is_timestamping);
561#endif
562}
563
564static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
565{
566#if defined(CONFIG_NET_PKT_TIMESTAMP)
567 return !!(pkt->rx_timestamping);
568#else
569 ARG_UNUSED(pkt);
570
571 return false;
572#endif
573}
574
575static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
576{
577#if defined(CONFIG_NET_PKT_TIMESTAMP)
578 pkt->rx_timestamping = is_timestamping;
579#else
580 ARG_UNUSED(pkt);
581 ARG_UNUSED(is_timestamping);
582#endif
583}
584
585static inline bool net_pkt_is_captured(struct net_pkt *pkt)
586{
587 return !!(pkt->captured);
588}
589
590static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
591{
592 pkt->captured = is_captured;
593}
594
595static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
596{
597 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
598}
599
600static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
601{
602 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
603 pkt->l2_bridged = is_l2_bridged;
604 }
605}
606
607static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
608{
609 return !!(pkt->l2_processed);
610}
611
612static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
613 bool is_l2_processed)
614{
615 pkt->l2_processed = is_l2_processed;
616}
617
618static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
619{
620 return !!(pkt->chksum_done);
621}
622
623static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
624 bool is_chksum_done)
625{
626 pkt->chksum_done = is_chksum_done;
627}
628
629static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
630{
631#if defined(CONFIG_NET_IP)
632 return pkt->ip_hdr_len;
633#else
634 ARG_UNUSED(pkt);
635
636 return 0;
637#endif
638}
639
640static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
641{
642#if defined(CONFIG_NET_IP)
643 pkt->ip_hdr_len = len;
644#else
645 ARG_UNUSED(pkt);
646 ARG_UNUSED(len);
647#endif
648}
649
650static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
651{
652#if defined(CONFIG_NET_IP_DSCP_ECN)
653 return pkt->ip_dscp;
654#else
655 ARG_UNUSED(pkt);
656
657 return 0;
658#endif
659}
660
661static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
662{
663#if defined(CONFIG_NET_IP_DSCP_ECN)
664 pkt->ip_dscp = dscp;
665#else
666 ARG_UNUSED(pkt);
667 ARG_UNUSED(dscp);
668#endif
669}
670
671static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
672{
673#if defined(CONFIG_NET_IP_DSCP_ECN)
674 return pkt->ip_ecn;
675#else
676 ARG_UNUSED(pkt);
677
678 return 0;
679#endif
680}
681
682static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
683{
684#if defined(CONFIG_NET_IP_DSCP_ECN)
685 pkt->ip_ecn = ecn;
686#else
687 ARG_UNUSED(pkt);
688 ARG_UNUSED(ecn);
689#endif
690}
691
692static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
693{
694 return pkt->eof;
695}
696
697static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
698{
699 pkt->eof = eof;
700}
701
702static inline bool net_pkt_forwarding(struct net_pkt *pkt)
703{
704 return !!(pkt->forwarding);
705}
706
707static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
708{
709 pkt->forwarding = forward;
710}
711
712#if defined(CONFIG_NET_IPV4)
713static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
714{
715 return pkt->ipv4_ttl;
716}
717
718static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
719 uint8_t ttl)
720{
721 pkt->ipv4_ttl = ttl;
722}
723
724static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
725{
726 return pkt->ipv4_opts_len;
727}
728
729static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
730 uint8_t opts_len)
731{
732 pkt->ipv4_opts_len = opts_len;
733}
734#else
735static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
736{
737 ARG_UNUSED(pkt);
738
739 return 0;
740}
741
742static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
743 uint8_t ttl)
744{
745 ARG_UNUSED(pkt);
746 ARG_UNUSED(ttl);
747}
748
749static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
750{
751 ARG_UNUSED(pkt);
752 return 0;
753}
754
755static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
756 uint8_t opts_len)
757{
758 ARG_UNUSED(pkt);
759 ARG_UNUSED(opts_len);
760}
761#endif
762
763#if defined(CONFIG_NET_IPV6)
764static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
765{
766 return pkt->ipv6_ext_opt_len;
767}
768
769static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
770 uint8_t len)
771{
772 pkt->ipv6_ext_opt_len = len;
773}
774
775static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
776{
777 return pkt->ipv6_next_hdr;
778}
779
780static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
781 uint8_t next_hdr)
782{
783 pkt->ipv6_next_hdr = next_hdr;
784}
785
786static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
787{
788 return pkt->ipv6_ext_len;
789}
790
791static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
792{
793 pkt->ipv6_ext_len = len;
794}
795
796static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
797{
798 return pkt->ipv6_prev_hdr_start;
799}
800
801static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
802 uint16_t offset)
803{
804 pkt->ipv6_prev_hdr_start = offset;
805}
806
807static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
808{
809 return pkt->ipv6_hop_limit;
810}
811
812static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
813 uint8_t hop_limit)
814{
815 pkt->ipv6_hop_limit = hop_limit;
816}
817#else /* CONFIG_NET_IPV6 */
818static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
819{
820 ARG_UNUSED(pkt);
821
822 return 0;
823}
824
825static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
826 uint8_t len)
827{
828 ARG_UNUSED(pkt);
829 ARG_UNUSED(len);
830}
831
832static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
833{
834 ARG_UNUSED(pkt);
835
836 return 0;
837}
838
839static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
840 uint8_t next_hdr)
841{
842 ARG_UNUSED(pkt);
843 ARG_UNUSED(next_hdr);
844}
845
846static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
847{
848 ARG_UNUSED(pkt);
849
850 return 0;
851}
852
853static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
854{
855 ARG_UNUSED(pkt);
856 ARG_UNUSED(len);
857}
858
859static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
860{
861 ARG_UNUSED(pkt);
862
863 return 0;
864}
865
866static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
867 uint16_t offset)
868{
869 ARG_UNUSED(pkt);
870 ARG_UNUSED(offset);
871}
872
873static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
874{
875 ARG_UNUSED(pkt);
876
877 return 0;
878}
879
880static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
881 uint8_t hop_limit)
882{
883 ARG_UNUSED(pkt);
884 ARG_UNUSED(hop_limit);
885}
886#endif /* CONFIG_NET_IPV6 */
887
888static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
889{
890#if defined(CONFIG_NET_IPV6)
891 return pkt->ipv6_ext_len;
892#elif defined(CONFIG_NET_IPV4)
893 return pkt->ipv4_opts_len;
894#else
895 ARG_UNUSED(pkt);
896
897 return 0;
898#endif
899}
900
901#if defined(CONFIG_NET_IPV4_PMTU)
902static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
903{
904 return !!pkt->ipv4_pmtu;
905}
906
907static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
908{
909 pkt->ipv4_pmtu = value;
910}
911#else
912static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
913{
914 ARG_UNUSED(pkt);
915
916 return false;
917}
918
919static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
920{
921 ARG_UNUSED(pkt);
922 ARG_UNUSED(value);
923}
924#endif /* CONFIG_NET_IPV4_PMTU */
925
926#if defined(CONFIG_NET_IPV4_ROUTE)
927static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
928{
929 return pkt->ipv4_ll_resolve_addr_set ? &pkt->ipv4_ll_resolve_addr : NULL;
930}
931
932static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
933 const struct net_in_addr *addr)
934{
935 if (addr != NULL) {
936 net_ipaddr_copy(&pkt->ipv4_ll_resolve_addr, addr);
937 pkt->ipv4_ll_resolve_addr_set = 1U;
938 } else {
939 pkt->ipv4_ll_resolve_addr_set = 0U;
940 }
941}
942#else
943static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
944{
945 ARG_UNUSED(pkt);
946
947 return NULL;
948}
949
950static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
951 const struct net_in_addr *addr)
952{
953 ARG_UNUSED(pkt);
954 ARG_UNUSED(addr);
955}
956#endif /* CONFIG_NET_IPV4_ROUTE */
957
958static inline bool net_pkt_dont_fragment(struct net_pkt *pkt)
959{
960 return !!pkt->dont_fragment;
961}
962
963static inline void net_pkt_set_dont_fragment(struct net_pkt *pkt, bool value)
964{
965 pkt->dont_fragment = value;
966}
967
968#if defined(CONFIG_NET_IPV4_FRAGMENT)
969static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
970{
971 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
972}
973
974static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
975{
976 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
977}
978
979static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
980{
981 pkt->ipv4_fragment.flags = flags;
982}
983
984static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
985{
986 return pkt->ipv4_fragment.id;
987}
988
989static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
990{
991 pkt->ipv4_fragment.id = id;
992}
993#else /* CONFIG_NET_IPV4_FRAGMENT */
994static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
995{
996 ARG_UNUSED(pkt);
997
998 return 0;
999}
1000
1001static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
1002{
1003 ARG_UNUSED(pkt);
1004
1005 return 0;
1006}
1007
1008static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
1009{
1010 ARG_UNUSED(pkt);
1011 ARG_UNUSED(flags);
1012}
1013
1014static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
1015{
1016 ARG_UNUSED(pkt);
1017
1018 return 0;
1019}
1020
1021static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
1022{
1023 ARG_UNUSED(pkt);
1024 ARG_UNUSED(id);
1025}
1026#endif /* CONFIG_NET_IPV4_FRAGMENT */
1027
1028#if defined(CONFIG_NET_IPV6_FRAGMENT)
1029static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1030{
1031 return pkt->ipv6_fragment.hdr_start;
1032}
1033
1034static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1035 uint16_t start)
1036{
1037 pkt->ipv6_fragment.hdr_start = start;
1038}
1039
1040static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1041{
1042 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
1043}
1044static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1045{
1046 return (pkt->ipv6_fragment.flags & 0x01) != 0;
1047}
1048
1049static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1051{
1052 pkt->ipv6_fragment.flags = flags;
1053}
1054
1055static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1056{
1057 return pkt->ipv6_fragment.id;
1058}
1059
1060static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1061 uint32_t id)
1062{
1063 pkt->ipv6_fragment.id = id;
1064}
1065#else /* CONFIG_NET_IPV6_FRAGMENT */
1066static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1067{
1068 ARG_UNUSED(pkt);
1069
1070 return 0;
1071}
1072
1073static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1074 uint16_t start)
1075{
1076 ARG_UNUSED(pkt);
1077 ARG_UNUSED(start);
1078}
1079
1080static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1081{
1082 ARG_UNUSED(pkt);
1083
1084 return 0;
1085}
1086
1087static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1088{
1089 ARG_UNUSED(pkt);
1090
1091 return 0;
1092}
1093
1094static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1096{
1097 ARG_UNUSED(pkt);
1098 ARG_UNUSED(flags);
1099}
1100
1101static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1102{
1103 ARG_UNUSED(pkt);
1104
1105 return 0;
1106}
1107
1108static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1109 uint32_t id)
1110{
1111 ARG_UNUSED(pkt);
1112 ARG_UNUSED(id);
1113}
1114#endif /* CONFIG_NET_IPV6_FRAGMENT */
1115
1116static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1117{
1118 return !!(pkt->loopback);
1119}
1120
1121static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1122 bool loopback)
1123{
1124 pkt->loopback = loopback;
1125}
1126
1127#if defined(CONFIG_NET_IP_FRAGMENT)
1128static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1129{
1130 return !!(pkt->ip_reassembled);
1131}
1132
1133static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1134 bool reassembled)
1135{
1136 pkt->ip_reassembled = reassembled;
1137}
1138#else /* CONFIG_NET_IP_FRAGMENT */
1139static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1140{
1141 ARG_UNUSED(pkt);
1142
1143 return false;
1144}
1145
1146static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1147 bool reassembled)
1148{
1149 ARG_UNUSED(pkt);
1150 ARG_UNUSED(reassembled);
1151}
1152#endif /* CONFIG_NET_IP_FRAGMENT */
1153
1154static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1155{
1156 return pkt->priority;
1157}
1158
1159static inline void net_pkt_set_priority(struct net_pkt *pkt,
1160 uint8_t priority)
1161{
1162 pkt->priority = priority;
1163}
1164
1165#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1166static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1167{
1168 return pkt->cooked_mode_pkt;
1169}
1170
1171static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1172{
1173 pkt->cooked_mode_pkt = value;
1174}
1175#else
1176static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1177{
1178 ARG_UNUSED(pkt);
1179
1180 return false;
1181}
1182
1183static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1184{
1185 ARG_UNUSED(pkt);
1186 ARG_UNUSED(value);
1187}
1188#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1189
1190#if defined(CONFIG_NET_VLAN)
1191static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1192{
1193 return net_eth_vlan_get_vid(pkt->vlan_tci);
1194}
1195
1196static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1197{
1198 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1199}
1200
1201static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1202{
1203 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1204}
1205
1206static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1207 uint8_t priority)
1208{
1209 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1210}
1211
1212static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1213{
1214 return net_eth_vlan_get_dei(pkt->vlan_tci);
1215}
1216
1217static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1218{
1219 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1220}
1221
1222static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1223{
1224 pkt->vlan_tci = tci;
1225}
1226
1227static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1228{
1229 return pkt->vlan_tci;
1230}
1231#else
1232static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1233{
1234 ARG_UNUSED(pkt);
1235
1236 return NET_VLAN_TAG_UNSPEC;
1237}
1238
1239static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1240{
1241 ARG_UNUSED(pkt);
1242 ARG_UNUSED(tag);
1243}
1244
1245static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1246{
1247 ARG_UNUSED(pkt);
1248
1249 return 0;
1250}
1251
1252static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1253{
1254 ARG_UNUSED(pkt);
1255
1256 return false;
1257}
1258
1259static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1260{
1261 ARG_UNUSED(pkt);
1262 ARG_UNUSED(dei);
1263}
1264
1265static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1266{
1267 ARG_UNUSED(pkt);
1268
1269 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1270}
1271
1272static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1273{
1274 ARG_UNUSED(pkt);
1275 ARG_UNUSED(tci);
1276}
1277#endif
1278
1279#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1280static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1281{
1282 return &pkt->timestamp;
1283}
1284
1285static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1286 struct net_ptp_time *timestamp)
1287{
1288 pkt->timestamp.second = timestamp->second;
1289 pkt->timestamp.nanosecond = timestamp->nanosecond;
1290}
1291
1292static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1293{
1294 return net_ptp_time_to_ns(&pkt->timestamp);
1295}
1296
1297static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1298{
1299 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1300}
1301#else
1302static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1303{
1304 ARG_UNUSED(pkt);
1305
1306 return NULL;
1307}
1308
1309static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1310 struct net_ptp_time *timestamp)
1311{
1312 ARG_UNUSED(pkt);
1313 ARG_UNUSED(timestamp);
1314}
1315
1316static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1317{
1318 ARG_UNUSED(pkt);
1319
1320 return 0;
1321}
1322
1323static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1324{
1325 ARG_UNUSED(pkt);
1326 ARG_UNUSED(timestamp);
1327}
1328#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1329
1330#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1331 defined(CONFIG_TRACING_NET_CORE)
1332
1333static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1334{
1335 return pkt->create_time;
1336}
1337
1338static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1339 uint32_t create_time)
1340{
1341 pkt->create_time = create_time;
1342}
1343#else
1344static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1345{
1346 ARG_UNUSED(pkt);
1347
1348 return 0U;
1349}
1350
1351static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1352 uint32_t create_time)
1353{
1354 ARG_UNUSED(pkt);
1355 ARG_UNUSED(create_time);
1356}
1357#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1358 * CONFIG_TRACING_NET_CORE
1359 */
1360
1361#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1362 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1363static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1364{
1365 return pkt->detail.stat;
1366}
1367
1368static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1369{
1370 return pkt->detail.count;
1371}
1372
1373static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1374{
1375 memset(&pkt->detail, 0, sizeof(pkt->detail));
1376}
1377
1378static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1379 uint32_t tick)
1380{
1381 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1382 printk("ERROR: Detail stats count overflow (%d >= %d)",
1383 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1384 return;
1385 }
1386
1387 pkt->detail.stat[pkt->detail.count++] = tick;
1388}
1389
1390#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1391#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1392#else
1393static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1394{
1395 ARG_UNUSED(pkt);
1396
1397 return NULL;
1398}
1399
1400static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1401{
1402 ARG_UNUSED(pkt);
1403
1404 return 0;
1405}
1406
1407static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1408{
1409 ARG_UNUSED(pkt);
1410}
1411
1412static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1413{
1414 ARG_UNUSED(pkt);
1415 ARG_UNUSED(tick);
1416}
1417
1418#define net_pkt_set_tx_stats_tick(pkt, tick)
1419#define net_pkt_set_rx_stats_tick(pkt, tick)
1420#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1421 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1422
1423static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1424{
1425 return pkt->frags->data;
1426}
1427
1428static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1429{
1430 return pkt->frags->data;
1431}
1432
1433static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1434{
1435 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1436}
1437
1438static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1439{
1440 return &pkt->lladdr_src;
1441}
1442
1443static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1444{
1445 return &pkt->lladdr_dst;
1446}
1447
1448static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1449{
1450 struct net_linkaddr tmp;
1451
1452 memcpy(tmp.addr,
1453 net_pkt_lladdr_src(pkt)->addr,
1454 net_pkt_lladdr_src(pkt)->len);
1455 memcpy(net_pkt_lladdr_src(pkt)->addr,
1456 net_pkt_lladdr_dst(pkt)->addr,
1457 net_pkt_lladdr_dst(pkt)->len);
1458 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1459 tmp.addr,
1460 net_pkt_lladdr_src(pkt)->len);
1461}
1462
1463static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1464{
1465 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1466 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1467}
1468
1469static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1470{
1471 return pkt->ll_proto_type;
1472}
1473
1474static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1475{
1476 pkt->ll_proto_type = type;
1477}
1478
1479#if defined(CONFIG_NET_IPV4_ACD)
1480static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1481{
1482 return !!(pkt->ipv4_acd_arp_msg);
1483}
1484
1485static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1486 bool is_acd_arp_msg)
1487{
1488 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1489}
1490#else /* CONFIG_NET_IPV4_ACD */
1491static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1492{
1493 ARG_UNUSED(pkt);
1494
1495 return false;
1496}
1497
1498static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1499 bool is_acd_arp_msg)
1500{
1501 ARG_UNUSED(pkt);
1502 ARG_UNUSED(is_acd_arp_msg);
1503}
1504#endif /* CONFIG_NET_IPV4_ACD */
1505
1506#if defined(CONFIG_NET_L2_PPP)
1507static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1508{
1509 return !!(pkt->ppp_msg);
1510}
1511
1512static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1513 bool is_ppp_msg)
1514{
1515 pkt->ppp_msg = is_ppp_msg;
1516}
1517#else /* CONFIG_NET_L2_PPP */
1518static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1519{
1520 ARG_UNUSED(pkt);
1521
1522 return false;
1523}
1524
1525static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1526 bool is_ppp_msg)
1527{
1528 ARG_UNUSED(pkt);
1529 ARG_UNUSED(is_ppp_msg);
1530}
1531#endif /* CONFIG_NET_L2_PPP */
1532
1533#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1534static inline void *net_pkt_cb(struct net_pkt *pkt)
1535{
1536 return &pkt->cb;
1537}
1538#else
1539static inline void *net_pkt_cb(struct net_pkt *pkt)
1540{
1541 ARG_UNUSED(pkt);
1542
1543 return NULL;
1544}
1545#endif
1546
1547#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1548#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1549
1550static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1551{
1553 net_pkt_context(pkt)),
1554 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1555}
1556
1557static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1558{
1559 pkt->overwrite = overwrite;
1560}
1561
1562static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1563{
1564 return !!(pkt->overwrite);
1565}
1566
1567#ifdef CONFIG_NET_PKT_FILTER
1568
1569bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1570bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1571
1572#else
1573
1574static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1575{
1576 ARG_UNUSED(pkt);
1577
1578 return true;
1579}
1580
1581static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1582{
1583 ARG_UNUSED(pkt);
1584
1585 return true;
1586}
1587
1588#endif /* CONFIG_NET_PKT_FILTER */
1589
1590#if defined(CONFIG_NET_PKT_FILTER) && \
1591 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1592
1593bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1594
1595#else
1596
1597static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1598{
1599 ARG_UNUSED(pkt);
1600
1601 return true;
1602}
1603
1604#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1605
1606#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1607
1608bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1609
1610#else
1611
1612static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1613{
1614 ARG_UNUSED(pkt);
1615
1616 return true;
1617}
1618
1619#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1620
1621#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1622static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1623{
1624 return &pkt->remote;
1625}
1626
1627static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1628 struct net_sockaddr *address,
1629 net_socklen_t len)
1630{
1631 memcpy(&pkt->remote, address, len);
1632}
1633#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1634
1635/* @endcond */
1636
1650#define NET_PKT_SLAB_DEFINE(name, count) \
1651 K_MEM_SLAB_DEFINE_TYPE(name, struct net_pkt, count); \
1652 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1653
1655
1656/* Backward compatibility macro */
1657#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1658
1660
1674#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1675 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1676 0, NULL)
1677
1679
1680#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1681 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1682#define NET_PKT_DEBUG_ENABLED
1683#endif
1684
1685#if defined(NET_PKT_DEBUG_ENABLED)
1686
1687/* Debug versions of the net_pkt functions that are used when tracking
1688 * buffer usage.
1689 */
1690
1691struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1692 size_t min_len,
1693 k_timeout_t timeout,
1694 const char *caller,
1695 int line);
1696
1697#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1698 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1699
1700struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1701 k_timeout_t timeout,
1702 const char *caller,
1703 int line);
1704#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1705 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1706
1707struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1708 k_timeout_t timeout,
1709 const char *caller,
1710 int line);
1711#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1712 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1713
1714struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1715 k_timeout_t timeout,
1716 const char *caller, int line);
1717#define net_pkt_get_frag(pkt, min_len, timeout) \
1718 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1719
1720void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1721#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1722
1723struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1724 int line);
1725#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1726
1727struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1728 const char *caller, int line);
1729#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1730
1731void net_pkt_frag_unref_debug(struct net_buf *frag,
1732 const char *caller, int line);
1733#define net_pkt_frag_unref(frag) \
1734 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1735
1736struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1737 struct net_buf *parent,
1738 struct net_buf *frag,
1739 const char *caller, int line);
1740#define net_pkt_frag_del(pkt, parent, frag) \
1741 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1742
1743void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1744 const char *caller, int line);
1745#define net_pkt_frag_add(pkt, frag) \
1746 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1747
1748void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1749 const char *caller, int line);
1750#define net_pkt_frag_insert(pkt, frag) \
1751 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1752#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1753 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1754 */
1756
1757#if defined(NET_PKT_DEBUG_ENABLED)
1765void net_pkt_print_frags(struct net_pkt *pkt);
1766#else
1767#define net_pkt_print_frags(pkt)
1768#endif
1769
1770#if !defined(NET_PKT_DEBUG_ENABLED)
1786 size_t min_len, k_timeout_t timeout);
1787#endif
1788
1789#if !defined(NET_PKT_DEBUG_ENABLED)
1804struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1805#endif
1806
1807#if !defined(NET_PKT_DEBUG_ENABLED)
1822struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1823#endif
1824
1825#if !defined(NET_PKT_DEBUG_ENABLED)
1838struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1839 k_timeout_t timeout);
1840#endif
1841
1842#if !defined(NET_PKT_DEBUG_ENABLED)
1852void net_pkt_unref(struct net_pkt *pkt);
1853#endif
1854
1855#if !defined(NET_PKT_DEBUG_ENABLED)
1865struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1866#endif
1867
1868#if !defined(NET_PKT_DEBUG_ENABLED)
1878struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1879#endif
1880
1881#if !defined(NET_PKT_DEBUG_ENABLED)
1887void net_pkt_frag_unref(struct net_buf *frag);
1888#endif
1889
1890#if !defined(NET_PKT_DEBUG_ENABLED)
1902 struct net_buf *parent,
1903 struct net_buf *frag);
1904#endif
1905
1906#if !defined(NET_PKT_DEBUG_ENABLED)
1913void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1914#endif
1915
1916#if !defined(NET_PKT_DEBUG_ENABLED)
1923void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1924#endif
1925
1932void net_pkt_compact(struct net_pkt *pkt);
1933
1942void net_pkt_get_info(struct k_mem_slab **rx,
1943 struct k_mem_slab **tx,
1944 struct net_buf_pool **rx_data,
1945 struct net_buf_pool **tx_data);
1946
1948
1949#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1953void net_pkt_print(void);
1954
1955typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1956 struct net_buf *buf,
1957 const char *func_alloc,
1958 int line_alloc,
1959 const char *func_free,
1960 int line_free,
1961 bool in_use,
1962 void *user_data);
1963
1964void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1965
1966const char *net_pkt_slab2str(struct k_mem_slab *slab);
1967const char *net_pkt_pool2str(struct net_buf_pool *pool);
1968
1969#else
1970#define net_pkt_print(...)
1971#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1972
1973/* New allocator, and API are defined below.
1974 * This will be simpler when time will come to get rid of former API above.
1975 */
1976#if defined(NET_PKT_DEBUG_ENABLED)
1977
1978struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1979 const char *caller, int line);
1980#define net_pkt_alloc(_timeout) \
1981 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1982
1983struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1984 k_timeout_t timeout,
1985 const char *caller, int line);
1986#define net_pkt_alloc_from_slab(_slab, _timeout) \
1987 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1988
1989struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1990 const char *caller, int line);
1991#define net_pkt_rx_alloc(_timeout) \
1992 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1993
1994struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1995 k_timeout_t timeout,
1996 const char *caller,
1997 int line);
1998#define net_pkt_alloc_on_iface(_iface, _timeout) \
1999 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
2000
2001struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
2002 k_timeout_t timeout,
2003 const char *caller,
2004 int line);
2005#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
2006 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
2007 __func__, __LINE__)
2008
2009int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
2010 size_t size,
2011 enum net_ip_protocol proto,
2012 k_timeout_t timeout,
2013 const char *caller, int line);
2014#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
2015 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
2016 __func__, __LINE__)
2017
2018int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
2019 k_timeout_t timeout,
2020 const char *caller, int line);
2021#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
2022 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
2023 __func__, __LINE__)
2024
2025struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
2026 size_t size,
2027 net_sa_family_t family,
2028 enum net_ip_protocol proto,
2029 k_timeout_t timeout,
2030 const char *caller,
2031 int line);
2032#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
2033 _proto, _timeout) \
2034 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
2035 _proto, _timeout, \
2036 __func__, __LINE__)
2037
2038struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
2039 size_t size,
2040 net_sa_family_t family,
2041 enum net_ip_protocol proto,
2042 k_timeout_t timeout,
2043 const char *caller,
2044 int line);
2045#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
2046 _proto, _timeout) \
2047 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
2048 _proto, _timeout, \
2049 __func__, __LINE__)
2050
2051int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
2052 size_t size,
2053 size_t reserve,
2054 enum net_ip_protocol proto,
2055 k_timeout_t timeout,
2056 const char *caller,
2057 int line);
2058#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
2059 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
2060 _timeout, __func__, __LINE__)
2061
2062#endif /* NET_PKT_DEBUG_ENABLED */
2064
2065#if !defined(NET_PKT_DEBUG_ENABLED)
2077#endif
2078
2079#if !defined(NET_PKT_DEBUG_ENABLED)
2094struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2095 k_timeout_t timeout);
2096#endif
2097
2098#if !defined(NET_PKT_DEBUG_ENABLED)
2110#endif
2111
2112#if !defined(NET_PKT_DEBUG_ENABLED)
2122 k_timeout_t timeout);
2123
2125
2126/* Same as above but specifically for RX packet */
2127struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2128 k_timeout_t timeout);
2130
2131#endif
2132
2133#if !defined(NET_PKT_DEBUG_ENABLED)
2150 size_t size,
2151 enum net_ip_protocol proto,
2152 k_timeout_t timeout);
2153#endif
2154
2155#if !defined(NET_PKT_DEBUG_ENABLED)
2173#if !defined(NET_PKT_DEBUG_ENABLED)
2175 size_t size,
2176 size_t reserve,
2177 enum net_ip_protocol proto,
2178 k_timeout_t timeout);
2179#endif
2180
2194int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2195 k_timeout_t timeout);
2196#endif
2197
2198#if !defined(NET_PKT_DEBUG_ENABLED)
2211 size_t size,
2212 net_sa_family_t family,
2213 enum net_ip_protocol proto,
2214 k_timeout_t timeout);
2215
2217
2218/* Same as above but specifically for RX packet */
2219struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2220 size_t size,
2221 net_sa_family_t family,
2222 enum net_ip_protocol proto,
2223 k_timeout_t timeout);
2224
2226
2227#endif
2228
2235void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2236
2248
2265 enum net_ip_protocol proto);
2266
2276
2291int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2292
2301
2308static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2309 struct net_pkt_cursor *backup)
2310{
2311 backup->buf = pkt->cursor.buf;
2312 backup->pos = pkt->cursor.pos;
2313}
2314
2321static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2322 struct net_pkt_cursor *backup)
2323{
2324 pkt->cursor.buf = backup->buf;
2325 pkt->cursor.pos = backup->pos;
2326}
2327
2335static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2336{
2337 return pkt->cursor.pos;
2338}
2339
2357int net_pkt_skip(struct net_pkt *pkt, size_t length);
2358
2373int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2374
2388int net_pkt_copy(struct net_pkt *pkt_dst,
2389 struct net_pkt *pkt_src,
2390 size_t length);
2391
2401struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2402
2412struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2413
2423 k_timeout_t timeout);
2424
2438int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2439
2452static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2453{
2454 return net_pkt_read(pkt, data, 1);
2455}
2456
2469int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2470
2483int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2484
2497int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2498
2511int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2512
2525int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2526
2539int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2540
2554int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2555
2568static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2569{
2570 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2571}
2572
2585static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2586{
2587 uint16_t data_be16 = net_htons(data);
2588
2589 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2590}
2591
2604static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2605{
2606 uint32_t data_be32 = net_htonl(data);
2607
2608 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2609}
2610
2623static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2624{
2625 uint32_t data_le32 = sys_cpu_to_le32(data);
2626
2627 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2628}
2629
2642static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2643{
2644 uint16_t data_le16 = sys_cpu_to_le16(data);
2645
2646 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2647}
2648
2657
2665static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2666{
2667 return net_buf_frags_len(pkt->frags);
2668}
2669
2682int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2683
2697int net_pkt_pull(struct net_pkt *pkt, size_t length);
2698
2708
2720bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2721
2731
2733
2734struct net_pkt_data_access {
2735#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2736 void *data;
2737#endif
2738 const size_t size;
2739};
2740
2741#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2742#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2743 struct net_pkt_data_access _name = { \
2744 .size = sizeof(_type), \
2745 }
2746
2747#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2748 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2749
2750#else
2751#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2752 _type _hdr_##_name; \
2753 struct net_pkt_data_access _name = { \
2754 .data = &_hdr_##_name, \
2755 .size = sizeof(_type), \
2756 }
2757
2758#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2759 struct net_pkt_data_access _name = { \
2760 .data = NULL, \
2761 .size = sizeof(_type), \
2762 }
2763
2764#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2765
2767
2781void *net_pkt_get_data(struct net_pkt *pkt,
2782 struct net_pkt_data_access *access);
2783
2798 struct net_pkt_data_access *access);
2799
2804static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2805 struct net_pkt_data_access *access)
2806{
2807 return net_pkt_skip(pkt, access->size);
2808}
2809
2813
2814#ifdef __cplusplus
2815}
2816#endif
2817
2818#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:1100
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:716
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1282
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:2299
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:2604
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:1767
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:2585
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:2665
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:2568
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:2335
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:2308
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:2804
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:2642
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:2321
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:2623
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:2452
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.
Header file for the logging core.
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.
int stat(const char *__restrict __path, struct stat *__restrict __sbuf)
__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:746
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:462
#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