Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_pkt.h
Go to the documentation of this file.
1
10
11/*
12 * Copyright (c) 2016 Intel Corporation
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 */
16
17/* Data buffer API - used for all data to/from net */
18
19#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
20#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
21
22#include <zephyr/types.h>
23#include <stdbool.h>
24
25#include <zephyr/net_buf.h>
26
27#if defined(CONFIG_IEEE802154)
29#endif
30#include <zephyr/net/net_core.h>
32#include <zephyr/net/net_ip.h>
33#include <zephyr/net/net_if.h>
35#include <zephyr/net/net_time.h>
37#include <zephyr/net/ptp_time.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
52
53struct net_context;
54
75#define NET_PKT_FRAG_FOR_EACH(_pkt, _var) \
76 for (struct net_buf *_var = (_pkt)->frags; _var != NULL; \
77 _var = _var->frags)
78
80
81#if defined(CONFIG_NET_PKT_ALLOC_STATS)
82struct net_pkt_alloc_stats {
83 uint64_t alloc_sum;
84 uint64_t time_sum;
85 uint32_t count;
86};
87
88struct net_pkt_alloc_stats_slab {
89 struct net_pkt_alloc_stats ok;
90 struct net_pkt_alloc_stats fail;
91 struct k_mem_slab *slab;
92};
93
94#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
95 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
96 .slab = &slab_name, \
97 }
98
99#else
100#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
101#endif /* CONFIG_NET_PKT_ALLOC_STATS */
102
103/* buffer cursor used in net_pkt */
104struct net_pkt_cursor {
106 struct net_buf *buf;
108 uint8_t *pos;
109};
110
112
119struct net_pkt {
125
127 struct k_mem_slab *slab;
128
130 union {
131 struct net_buf *frags;
132 struct net_buf *buffer;
133 };
134
136 struct net_pkt_cursor cursor;
137
140
142 struct net_if *iface;
143
145
146 /* 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 ARG_UNUSED(pkt);
528
529 return 0;
530}
531
532#define net_pkt_set_udp_opt_surplus_len(...)
533#endif /* CONFIG_NET_UDP_OPTIONS */
534
535static inline uint8_t net_pkt_family(struct net_pkt *pkt)
536{
537 return pkt->family;
538}
539
540static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
541{
542 pkt->family = family;
543}
544
545static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
546{
547#if defined(CONFIG_NET_PKT_TIMESTAMP)
548 return !!(pkt->tx_timestamping);
549#else
550 ARG_UNUSED(pkt);
551
552 return false;
553#endif
554}
555
556static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
557{
558#if defined(CONFIG_NET_PKT_TIMESTAMP)
559 pkt->tx_timestamping = is_timestamping;
560#else
561 ARG_UNUSED(pkt);
562 ARG_UNUSED(is_timestamping);
563#endif
564}
565
566static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
567{
568#if defined(CONFIG_NET_PKT_TIMESTAMP)
569 return !!(pkt->rx_timestamping);
570#else
571 ARG_UNUSED(pkt);
572
573 return false;
574#endif
575}
576
577static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
578{
579#if defined(CONFIG_NET_PKT_TIMESTAMP)
580 pkt->rx_timestamping = is_timestamping;
581#else
582 ARG_UNUSED(pkt);
583 ARG_UNUSED(is_timestamping);
584#endif
585}
586
587static inline bool net_pkt_is_captured(struct net_pkt *pkt)
588{
589 return !!(pkt->captured);
590}
591
592static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
593{
594 pkt->captured = is_captured;
595}
596
597static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
598{
599 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
600}
601
602static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
603{
604 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
605 pkt->l2_bridged = is_l2_bridged;
606 }
607}
608
609static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
610{
611 return !!(pkt->l2_processed);
612}
613
614static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
615 bool is_l2_processed)
616{
617 pkt->l2_processed = is_l2_processed;
618}
619
620static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
621{
622 return !!(pkt->chksum_done);
623}
624
625static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
626 bool is_chksum_done)
627{
628 pkt->chksum_done = is_chksum_done;
629}
630
631static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
632{
633#if defined(CONFIG_NET_IP)
634 return pkt->ip_hdr_len;
635#else
636 ARG_UNUSED(pkt);
637
638 return 0;
639#endif
640}
641
642static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
643{
644#if defined(CONFIG_NET_IP)
645 pkt->ip_hdr_len = len;
646#else
647 ARG_UNUSED(pkt);
648 ARG_UNUSED(len);
649#endif
650}
651
652static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
653{
654#if defined(CONFIG_NET_IP_DSCP_ECN)
655 return pkt->ip_dscp;
656#else
657 ARG_UNUSED(pkt);
658
659 return 0;
660#endif
661}
662
663static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
664{
665#if defined(CONFIG_NET_IP_DSCP_ECN)
666 pkt->ip_dscp = dscp;
667#else
668 ARG_UNUSED(pkt);
669 ARG_UNUSED(dscp);
670#endif
671}
672
673static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
674{
675#if defined(CONFIG_NET_IP_DSCP_ECN)
676 return pkt->ip_ecn;
677#else
678 ARG_UNUSED(pkt);
679
680 return 0;
681#endif
682}
683
684static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
685{
686#if defined(CONFIG_NET_IP_DSCP_ECN)
687 pkt->ip_ecn = ecn;
688#else
689 ARG_UNUSED(pkt);
690 ARG_UNUSED(ecn);
691#endif
692}
693
694static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
695{
696 return pkt->eof;
697}
698
699static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
700{
701 pkt->eof = eof;
702}
703
704static inline bool net_pkt_forwarding(struct net_pkt *pkt)
705{
706 return !!(pkt->forwarding);
707}
708
709static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
710{
711 pkt->forwarding = forward;
712}
713
714#if defined(CONFIG_NET_IPV4)
715static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
716{
717 return pkt->ipv4_ttl;
718}
719
720static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
721 uint8_t ttl)
722{
723 pkt->ipv4_ttl = ttl;
724}
725
726static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
727{
728 return pkt->ipv4_opts_len;
729}
730
731static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
732 uint8_t opts_len)
733{
734 pkt->ipv4_opts_len = opts_len;
735}
736#else
737static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
738{
739 ARG_UNUSED(pkt);
740
741 return 0;
742}
743
744static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
745 uint8_t ttl)
746{
747 ARG_UNUSED(pkt);
748 ARG_UNUSED(ttl);
749}
750
751static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
752{
753 ARG_UNUSED(pkt);
754 return 0;
755}
756
757static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
758 uint8_t opts_len)
759{
760 ARG_UNUSED(pkt);
761 ARG_UNUSED(opts_len);
762}
763#endif
764
765#if defined(CONFIG_NET_IPV6)
766static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
767{
768 return pkt->ipv6_ext_opt_len;
769}
770
771static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
772 uint8_t len)
773{
774 pkt->ipv6_ext_opt_len = len;
775}
776
777static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
778{
779 return pkt->ipv6_next_hdr;
780}
781
782static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
783 uint8_t next_hdr)
784{
785 pkt->ipv6_next_hdr = next_hdr;
786}
787
788static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
789{
790 return pkt->ipv6_ext_len;
791}
792
793static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
794{
795 pkt->ipv6_ext_len = len;
796}
797
798static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
799{
800 return pkt->ipv6_prev_hdr_start;
801}
802
803static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
804 uint16_t offset)
805{
806 pkt->ipv6_prev_hdr_start = offset;
807}
808
809static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
810{
811 return pkt->ipv6_hop_limit;
812}
813
814static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
815 uint8_t hop_limit)
816{
817 pkt->ipv6_hop_limit = hop_limit;
818}
819#else /* CONFIG_NET_IPV6 */
820static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
821{
822 ARG_UNUSED(pkt);
823
824 return 0;
825}
826
827static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
828 uint8_t len)
829{
830 ARG_UNUSED(pkt);
831 ARG_UNUSED(len);
832}
833
834static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
835{
836 ARG_UNUSED(pkt);
837
838 return 0;
839}
840
841static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
842 uint8_t next_hdr)
843{
844 ARG_UNUSED(pkt);
845 ARG_UNUSED(next_hdr);
846}
847
848static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
849{
850 ARG_UNUSED(pkt);
851
852 return 0;
853}
854
855static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
856{
857 ARG_UNUSED(pkt);
858 ARG_UNUSED(len);
859}
860
861static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
862{
863 ARG_UNUSED(pkt);
864
865 return 0;
866}
867
868static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
869 uint16_t offset)
870{
871 ARG_UNUSED(pkt);
872 ARG_UNUSED(offset);
873}
874
875static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
876{
877 ARG_UNUSED(pkt);
878
879 return 0;
880}
881
882static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
883 uint8_t hop_limit)
884{
885 ARG_UNUSED(pkt);
886 ARG_UNUSED(hop_limit);
887}
888#endif /* CONFIG_NET_IPV6 */
889
890static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
891{
892#if defined(CONFIG_NET_IPV6)
893 return pkt->ipv6_ext_len;
894#elif defined(CONFIG_NET_IPV4)
895 return pkt->ipv4_opts_len;
896#else
897 ARG_UNUSED(pkt);
898
899 return 0;
900#endif
901}
902
903#if defined(CONFIG_NET_IPV4_PMTU)
904static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
905{
906 return !!pkt->ipv4_pmtu;
907}
908
909static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
910{
911 pkt->ipv4_pmtu = value;
912}
913#else
914static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
915{
916 ARG_UNUSED(pkt);
917
918 return false;
919}
920
921static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
922{
923 ARG_UNUSED(pkt);
924 ARG_UNUSED(value);
925}
926#endif /* CONFIG_NET_IPV4_PMTU */
927
928#if defined(CONFIG_NET_IPV4_ROUTE)
929static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
930{
931 return pkt->ipv4_ll_resolve_addr_set ? &pkt->ipv4_ll_resolve_addr : NULL;
932}
933
934static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
935 const struct net_in_addr *addr)
936{
937 if (addr != NULL) {
938 net_ipaddr_copy(&pkt->ipv4_ll_resolve_addr, addr);
939 pkt->ipv4_ll_resolve_addr_set = 1U;
940 } else {
941 pkt->ipv4_ll_resolve_addr_set = 0U;
942 }
943}
944#else
945static inline const struct net_in_addr *net_pkt_ipv4_ll_resolve_addr(struct net_pkt *pkt)
946{
947 ARG_UNUSED(pkt);
948
949 return NULL;
950}
951
952static inline void net_pkt_set_ipv4_ll_resolve_addr(struct net_pkt *pkt,
953 const struct net_in_addr *addr)
954{
955 ARG_UNUSED(pkt);
956 ARG_UNUSED(addr);
957}
958#endif /* CONFIG_NET_IPV4_ROUTE */
959
960static inline bool net_pkt_dont_fragment(struct net_pkt *pkt)
961{
962 return !!pkt->dont_fragment;
963}
964
965static inline void net_pkt_set_dont_fragment(struct net_pkt *pkt, bool value)
966{
967 pkt->dont_fragment = value;
968}
969
970#if defined(CONFIG_NET_IPV4_FRAGMENT)
971static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
972{
973 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
974}
975
976static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
977{
978 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
979}
980
981static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
982{
983 pkt->ipv4_fragment.flags = flags;
984}
985
986static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
987{
988 return pkt->ipv4_fragment.id;
989}
990
991static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
992{
993 pkt->ipv4_fragment.id = id;
994}
995#else /* CONFIG_NET_IPV4_FRAGMENT */
996static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
997{
998 ARG_UNUSED(pkt);
999
1000 return 0;
1001}
1002
1003static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
1004{
1005 ARG_UNUSED(pkt);
1006
1007 return 0;
1008}
1009
1010static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
1011{
1012 ARG_UNUSED(pkt);
1013 ARG_UNUSED(flags);
1014}
1015
1016static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
1017{
1018 ARG_UNUSED(pkt);
1019
1020 return 0;
1021}
1022
1023static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
1024{
1025 ARG_UNUSED(pkt);
1026 ARG_UNUSED(id);
1027}
1028#endif /* CONFIG_NET_IPV4_FRAGMENT */
1029
1030#if defined(CONFIG_NET_IPV6_FRAGMENT)
1031static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1032{
1033 return pkt->ipv6_fragment.hdr_start;
1034}
1035
1036static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1037 uint16_t start)
1038{
1039 pkt->ipv6_fragment.hdr_start = start;
1040}
1041
1042static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1043{
1044 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
1045}
1046static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1047{
1048 return (pkt->ipv6_fragment.flags & 0x01) != 0;
1049}
1050
1051static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1053{
1054 pkt->ipv6_fragment.flags = flags;
1055}
1056
1057static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1058{
1059 return pkt->ipv6_fragment.id;
1060}
1061
1062static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1063 uint32_t id)
1064{
1065 pkt->ipv6_fragment.id = id;
1066}
1067#else /* CONFIG_NET_IPV6_FRAGMENT */
1068static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
1069{
1070 ARG_UNUSED(pkt);
1071
1072 return 0;
1073}
1074
1075static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
1076 uint16_t start)
1077{
1078 ARG_UNUSED(pkt);
1079 ARG_UNUSED(start);
1080}
1081
1082static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
1083{
1084 ARG_UNUSED(pkt);
1085
1086 return 0;
1087}
1088
1089static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1090{
1091 ARG_UNUSED(pkt);
1092
1093 return 0;
1094}
1095
1096static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1098{
1099 ARG_UNUSED(pkt);
1100 ARG_UNUSED(flags);
1101}
1102
1103static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1104{
1105 ARG_UNUSED(pkt);
1106
1107 return 0;
1108}
1109
1110static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1111 uint32_t id)
1112{
1113 ARG_UNUSED(pkt);
1114 ARG_UNUSED(id);
1115}
1116#endif /* CONFIG_NET_IPV6_FRAGMENT */
1117
1118static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1119{
1120 return !!(pkt->loopback);
1121}
1122
1123static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1124 bool loopback)
1125{
1126 pkt->loopback = loopback;
1127}
1128
1129#if defined(CONFIG_NET_IP_FRAGMENT)
1130static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1131{
1132 return !!(pkt->ip_reassembled);
1133}
1134
1135static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1136 bool reassembled)
1137{
1138 pkt->ip_reassembled = reassembled;
1139}
1140#else /* CONFIG_NET_IP_FRAGMENT */
1141static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1142{
1143 ARG_UNUSED(pkt);
1144
1145 return false;
1146}
1147
1148static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1149 bool reassembled)
1150{
1151 ARG_UNUSED(pkt);
1152 ARG_UNUSED(reassembled);
1153}
1154#endif /* CONFIG_NET_IP_FRAGMENT */
1155
1156static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1157{
1158 return pkt->priority;
1159}
1160
1161static inline void net_pkt_set_priority(struct net_pkt *pkt,
1162 uint8_t priority)
1163{
1164 pkt->priority = priority;
1165}
1166
1167#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1168static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1169{
1170 return pkt->cooked_mode_pkt;
1171}
1172
1173static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1174{
1175 pkt->cooked_mode_pkt = value;
1176}
1177#else
1178static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1179{
1180 ARG_UNUSED(pkt);
1181
1182 return false;
1183}
1184
1185static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1186{
1187 ARG_UNUSED(pkt);
1188 ARG_UNUSED(value);
1189}
1190#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1191
1192#if defined(CONFIG_NET_VLAN)
1193static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1194{
1195 return net_eth_vlan_get_vid(pkt->vlan_tci);
1196}
1197
1198static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1199{
1200 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1201}
1202
1203static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1204{
1205 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1206}
1207
1208static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1209 uint8_t priority)
1210{
1211 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1212}
1213
1214static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1215{
1216 return net_eth_vlan_get_dei(pkt->vlan_tci);
1217}
1218
1219static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1220{
1221 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1222}
1223
1224static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1225{
1226 pkt->vlan_tci = tci;
1227}
1228
1229static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1230{
1231 return pkt->vlan_tci;
1232}
1233#else
1234static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1235{
1236 ARG_UNUSED(pkt);
1237
1238 return NET_VLAN_TAG_UNSPEC;
1239}
1240
1241static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1242{
1243 ARG_UNUSED(pkt);
1244 ARG_UNUSED(tag);
1245}
1246
1247static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1248{
1249 ARG_UNUSED(pkt);
1250
1251 return 0;
1252}
1253
1254static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1255{
1256 ARG_UNUSED(pkt);
1257
1258 return false;
1259}
1260
1261static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1262{
1263 ARG_UNUSED(pkt);
1264 ARG_UNUSED(dei);
1265}
1266
1267static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1268{
1269 ARG_UNUSED(pkt);
1270
1271 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1272}
1273
1274static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1275{
1276 ARG_UNUSED(pkt);
1277 ARG_UNUSED(tci);
1278}
1279#endif
1280
1281#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1282static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1283{
1284 return &pkt->timestamp;
1285}
1286
1287static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1288 struct net_ptp_time *timestamp)
1289{
1290 pkt->timestamp.second = timestamp->second;
1291 pkt->timestamp.nanosecond = timestamp->nanosecond;
1292}
1293
1294static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1295{
1296 return net_ptp_time_to_ns(&pkt->timestamp);
1297}
1298
1299static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1300{
1301 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1302}
1303#else
1304static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1305{
1306 ARG_UNUSED(pkt);
1307
1308 return NULL;
1309}
1310
1311static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1312 struct net_ptp_time *timestamp)
1313{
1314 ARG_UNUSED(pkt);
1315 ARG_UNUSED(timestamp);
1316}
1317
1318static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1319{
1320 ARG_UNUSED(pkt);
1321
1322 return 0;
1323}
1324
1325static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1326{
1327 ARG_UNUSED(pkt);
1328 ARG_UNUSED(timestamp);
1329}
1330#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1331
1332#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1333 defined(CONFIG_TRACING_NET_CORE)
1334
1335static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1336{
1337 return pkt->create_time;
1338}
1339
1340static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1341 uint32_t create_time)
1342{
1343 pkt->create_time = create_time;
1344}
1345#else
1346static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1347{
1348 ARG_UNUSED(pkt);
1349
1350 return 0U;
1351}
1352
1353static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1354 uint32_t create_time)
1355{
1356 ARG_UNUSED(pkt);
1357 ARG_UNUSED(create_time);
1358}
1359#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1360 * CONFIG_TRACING_NET_CORE
1361 */
1362
1363#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1364 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1365static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1366{
1367 return pkt->detail.stat;
1368}
1369
1370static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1371{
1372 return pkt->detail.count;
1373}
1374
1375static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1376{
1377 memset(&pkt->detail, 0, sizeof(pkt->detail));
1378}
1379
1380static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1381 uint32_t tick)
1382{
1383 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1384 printk("ERROR: Detail stats count overflow (%d >= %d)",
1385 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1386 return;
1387 }
1388
1389 pkt->detail.stat[pkt->detail.count++] = tick;
1390}
1391
1392#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1393#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1394#else
1395static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1396{
1397 ARG_UNUSED(pkt);
1398
1399 return NULL;
1400}
1401
1402static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1403{
1404 ARG_UNUSED(pkt);
1405
1406 return 0;
1407}
1408
1409static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1410{
1411 ARG_UNUSED(pkt);
1412}
1413
1414static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1415{
1416 ARG_UNUSED(pkt);
1417 ARG_UNUSED(tick);
1418}
1419
1420#define net_pkt_set_tx_stats_tick(pkt, tick)
1421#define net_pkt_set_rx_stats_tick(pkt, tick)
1422#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1423 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1424
1425static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1426{
1427 return pkt->frags->data;
1428}
1429
1430static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1431{
1432 return pkt->frags->data;
1433}
1434
1435static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1436{
1437 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1438}
1439
1440static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1441{
1442 return &pkt->lladdr_src;
1443}
1444
1445static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1446{
1447 return &pkt->lladdr_dst;
1448}
1449
1450static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1451{
1452 struct net_linkaddr tmp;
1453
1454 memcpy(tmp.addr,
1455 net_pkt_lladdr_src(pkt)->addr,
1456 net_pkt_lladdr_src(pkt)->len);
1457 memcpy(net_pkt_lladdr_src(pkt)->addr,
1458 net_pkt_lladdr_dst(pkt)->addr,
1459 net_pkt_lladdr_dst(pkt)->len);
1460 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1461 tmp.addr,
1462 net_pkt_lladdr_src(pkt)->len);
1463}
1464
1465static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1466{
1467 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1468 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1469}
1470
1471static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1472{
1473 return pkt->ll_proto_type;
1474}
1475
1476static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1477{
1478 pkt->ll_proto_type = type;
1479}
1480
1481#if defined(CONFIG_NET_IPV4_ACD)
1482static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1483{
1484 return !!(pkt->ipv4_acd_arp_msg);
1485}
1486
1487static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1488 bool is_acd_arp_msg)
1489{
1490 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1491}
1492#else /* CONFIG_NET_IPV4_ACD */
1493static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1494{
1495 ARG_UNUSED(pkt);
1496
1497 return false;
1498}
1499
1500static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1501 bool is_acd_arp_msg)
1502{
1503 ARG_UNUSED(pkt);
1504 ARG_UNUSED(is_acd_arp_msg);
1505}
1506#endif /* CONFIG_NET_IPV4_ACD */
1507
1508#if defined(CONFIG_NET_L2_PPP)
1509static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1510{
1511 return !!(pkt->ppp_msg);
1512}
1513
1514static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1515 bool is_ppp_msg)
1516{
1517 pkt->ppp_msg = is_ppp_msg;
1518}
1519#else /* CONFIG_NET_L2_PPP */
1520static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1521{
1522 ARG_UNUSED(pkt);
1523
1524 return false;
1525}
1526
1527static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1528 bool is_ppp_msg)
1529{
1530 ARG_UNUSED(pkt);
1531 ARG_UNUSED(is_ppp_msg);
1532}
1533#endif /* CONFIG_NET_L2_PPP */
1534
1535#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1536static inline void *net_pkt_cb(struct net_pkt *pkt)
1537{
1538 return &pkt->cb;
1539}
1540#else
1541static inline void *net_pkt_cb(struct net_pkt *pkt)
1542{
1543 ARG_UNUSED(pkt);
1544
1545 return NULL;
1546}
1547#endif
1548
1549#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1550#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1551
1552static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1553{
1555 net_pkt_context(pkt)),
1556 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1557}
1558
1559static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1560{
1561 pkt->overwrite = overwrite;
1562}
1563
1564static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1565{
1566 return !!(pkt->overwrite);
1567}
1568
1569#ifdef CONFIG_NET_PKT_FILTER
1570
1571bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1572bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1573
1574#else
1575
1576static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1577{
1578 ARG_UNUSED(pkt);
1579
1580 return true;
1581}
1582
1583static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1584{
1585 ARG_UNUSED(pkt);
1586
1587 return true;
1588}
1589
1590#endif /* CONFIG_NET_PKT_FILTER */
1591
1592#if defined(CONFIG_NET_PKT_FILTER) && \
1593 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1594
1595bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1596
1597#else
1598
1599static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1600{
1601 ARG_UNUSED(pkt);
1602
1603 return true;
1604}
1605
1606#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1607
1608#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1609
1610bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1611
1612#else
1613
1614static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1615{
1616 ARG_UNUSED(pkt);
1617
1618 return true;
1619}
1620
1621#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1622
1623#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1624static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1625{
1626 return &pkt->remote;
1627}
1628
1629static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1630 struct net_sockaddr *address,
1631 net_socklen_t len)
1632{
1633 memcpy(&pkt->remote, address, len);
1634}
1635#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1636
1637/* @endcond */
1638
1652#define NET_PKT_SLAB_DEFINE(name, count) \
1653 K_MEM_SLAB_DEFINE_TYPE(name, struct net_pkt, count); \
1654 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1655
1657
1658/* Backward compatibility macro */
1659#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1660
1662
1676#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1677 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1678 0, NULL)
1679
1681
1682#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1683 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1684#define NET_PKT_DEBUG_ENABLED
1685#endif
1686
1687#if defined(NET_PKT_DEBUG_ENABLED)
1688
1689/* Debug versions of the net_pkt functions that are used when tracking
1690 * buffer usage.
1691 */
1692
1693struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1694 size_t min_len,
1695 k_timeout_t timeout,
1696 const char *caller,
1697 int line);
1698
1699#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1700 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1701
1702struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1703 k_timeout_t timeout,
1704 const char *caller,
1705 int line);
1706#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1707 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1708
1709struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1710 k_timeout_t timeout,
1711 const char *caller,
1712 int line);
1713#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1714 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1715
1716struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1717 k_timeout_t timeout,
1718 const char *caller, int line);
1719#define net_pkt_get_frag(pkt, min_len, timeout) \
1720 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1721
1722void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1723#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1724
1725struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1726 int line);
1727#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1728
1729struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1730 const char *caller, int line);
1731#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1732
1733void net_pkt_frag_unref_debug(struct net_buf *frag,
1734 const char *caller, int line);
1735#define net_pkt_frag_unref(frag) \
1736 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1737
1738struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1739 struct net_buf *parent,
1740 struct net_buf *frag,
1741 const char *caller, int line);
1742#define net_pkt_frag_del(pkt, parent, frag) \
1743 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1744
1745void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1746 const char *caller, int line);
1747#define net_pkt_frag_add(pkt, frag) \
1748 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1749
1750void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1751 const char *caller, int line);
1752#define net_pkt_frag_insert(pkt, frag) \
1753 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1754#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1755 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1756 */
1758
1759#if defined(NET_PKT_DEBUG_ENABLED)
1767void net_pkt_print_frags(struct net_pkt *pkt);
1768#else
1769#define net_pkt_print_frags(pkt)
1770#endif
1771
1772#if !defined(NET_PKT_DEBUG_ENABLED)
1788 size_t min_len, k_timeout_t timeout);
1789#endif
1790
1791#if !defined(NET_PKT_DEBUG_ENABLED)
1806struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1807#endif
1808
1809#if !defined(NET_PKT_DEBUG_ENABLED)
1824struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1825#endif
1826
1827#if !defined(NET_PKT_DEBUG_ENABLED)
1840struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1841 k_timeout_t timeout);
1842#endif
1843
1844#if !defined(NET_PKT_DEBUG_ENABLED)
1854void net_pkt_unref(struct net_pkt *pkt);
1855#endif
1856
1857#if !defined(NET_PKT_DEBUG_ENABLED)
1867struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1868#endif
1869
1870#if !defined(NET_PKT_DEBUG_ENABLED)
1880struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1881#endif
1882
1883#if !defined(NET_PKT_DEBUG_ENABLED)
1889void net_pkt_frag_unref(struct net_buf *frag);
1890#endif
1891
1892#if !defined(NET_PKT_DEBUG_ENABLED)
1904 struct net_buf *parent,
1905 struct net_buf *frag);
1906#endif
1907
1908#if !defined(NET_PKT_DEBUG_ENABLED)
1915void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1916#endif
1917
1918#if !defined(NET_PKT_DEBUG_ENABLED)
1925void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1926#endif
1927
1934void net_pkt_compact(struct net_pkt *pkt);
1935
1944void net_pkt_get_info(struct k_mem_slab **rx,
1945 struct k_mem_slab **tx,
1946 struct net_buf_pool **rx_data,
1947 struct net_buf_pool **tx_data);
1948
1950
1951#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1955void net_pkt_print(void);
1956
1957typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1958 struct net_buf *buf,
1959 const char *func_alloc,
1960 int line_alloc,
1961 const char *func_free,
1962 int line_free,
1963 bool in_use,
1964 void *user_data);
1965
1966void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1967
1968const char *net_pkt_slab2str(struct k_mem_slab *slab);
1969const char *net_pkt_pool2str(struct net_buf_pool *pool);
1970
1971#else
1972#define net_pkt_print(...)
1973#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1974
1975/* New allocator, and API are defined below.
1976 * This will be simpler when time will come to get rid of former API above.
1977 */
1978#if defined(NET_PKT_DEBUG_ENABLED)
1979
1980struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1981 const char *caller, int line);
1982#define net_pkt_alloc(_timeout) \
1983 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1984
1985struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1986 k_timeout_t timeout,
1987 const char *caller, int line);
1988#define net_pkt_alloc_from_slab(_slab, _timeout) \
1989 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1990
1991struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1992 const char *caller, int line);
1993#define net_pkt_rx_alloc(_timeout) \
1994 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1995
1996struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1997 k_timeout_t timeout,
1998 const char *caller,
1999 int line);
2000#define net_pkt_alloc_on_iface(_iface, _timeout) \
2001 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
2002
2003struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
2004 k_timeout_t timeout,
2005 const char *caller,
2006 int line);
2007#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
2008 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
2009 __func__, __LINE__)
2010
2011int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
2012 size_t size,
2013 enum net_ip_protocol proto,
2014 k_timeout_t timeout,
2015 const char *caller, int line);
2016#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
2017 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
2018 __func__, __LINE__)
2019
2020int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
2021 k_timeout_t timeout,
2022 const char *caller, int line);
2023#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
2024 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
2025 __func__, __LINE__)
2026
2027struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
2028 size_t size,
2029 net_sa_family_t family,
2030 enum net_ip_protocol proto,
2031 k_timeout_t timeout,
2032 const char *caller,
2033 int line);
2034#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
2035 _proto, _timeout) \
2036 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
2037 _proto, _timeout, \
2038 __func__, __LINE__)
2039
2040struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
2041 size_t size,
2042 net_sa_family_t family,
2043 enum net_ip_protocol proto,
2044 k_timeout_t timeout,
2045 const char *caller,
2046 int line);
2047#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
2048 _proto, _timeout) \
2049 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
2050 _proto, _timeout, \
2051 __func__, __LINE__)
2052
2053int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
2054 size_t size,
2055 size_t reserve,
2056 enum net_ip_protocol proto,
2057 k_timeout_t timeout,
2058 const char *caller,
2059 int line);
2060#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
2061 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
2062 _timeout, __func__, __LINE__)
2063
2064#endif /* NET_PKT_DEBUG_ENABLED */
2066
2067#if !defined(NET_PKT_DEBUG_ENABLED)
2079#endif
2080
2081#if !defined(NET_PKT_DEBUG_ENABLED)
2096struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2097 k_timeout_t timeout);
2098#endif
2099
2100#if !defined(NET_PKT_DEBUG_ENABLED)
2112#endif
2113
2114#if !defined(NET_PKT_DEBUG_ENABLED)
2124 k_timeout_t timeout);
2125
2127
2128/* Same as above but specifically for RX packet */
2129struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2130 k_timeout_t timeout);
2132
2133#endif
2134
2135#if !defined(NET_PKT_DEBUG_ENABLED)
2152 size_t size,
2153 enum net_ip_protocol proto,
2154 k_timeout_t timeout);
2155#endif
2156
2157#if !defined(NET_PKT_DEBUG_ENABLED)
2175#if !defined(NET_PKT_DEBUG_ENABLED)
2177 size_t size,
2178 size_t reserve,
2179 enum net_ip_protocol proto,
2180 k_timeout_t timeout);
2181#endif
2182
2196int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2197 k_timeout_t timeout);
2198#endif
2199
2200#if !defined(NET_PKT_DEBUG_ENABLED)
2213 size_t size,
2214 net_sa_family_t family,
2215 enum net_ip_protocol proto,
2216 k_timeout_t timeout);
2217
2219
2220/* Same as above but specifically for RX packet */
2221struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2222 size_t size,
2223 net_sa_family_t family,
2224 enum net_ip_protocol proto,
2225 k_timeout_t timeout);
2226
2228
2229#endif
2230
2237void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2238
2250
2267 enum net_ip_protocol proto);
2268
2278
2293int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2294
2303
2310static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2311 struct net_pkt_cursor *backup)
2312{
2313 backup->buf = pkt->cursor.buf;
2314 backup->pos = pkt->cursor.pos;
2315}
2316
2323static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2324 struct net_pkt_cursor *backup)
2325{
2326 pkt->cursor.buf = backup->buf;
2327 pkt->cursor.pos = backup->pos;
2328}
2329
2337static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2338{
2339 return pkt->cursor.pos;
2340}
2341
2359int net_pkt_skip(struct net_pkt *pkt, size_t length);
2360
2375int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2376
2390int net_pkt_copy(struct net_pkt *pkt_dst,
2391 struct net_pkt *pkt_src,
2392 size_t length);
2393
2403struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2404
2414struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2415
2425 k_timeout_t timeout);
2426
2440int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2441
2454static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2455{
2456 return net_pkt_read(pkt, data, 1);
2457}
2458
2471int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2472
2485int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2486
2499int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2500
2513int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2514
2527int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2528
2541int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2542
2556int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2557
2570static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2571{
2572 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2573}
2574
2587static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2588{
2589 uint16_t data_be16 = net_htons(data);
2590
2591 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2592}
2593
2606static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2607{
2608 uint32_t data_be32 = net_htonl(data);
2609
2610 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2611}
2612
2625static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2626{
2627 uint32_t data_le32 = sys_cpu_to_le32(data);
2628
2629 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2630}
2631
2644static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2645{
2646 uint16_t data_le16 = sys_cpu_to_le16(data);
2647
2648 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2649}
2650
2659
2667static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2668{
2669 return net_buf_frags_len(pkt->frags);
2670}
2671
2684int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2685
2699int net_pkt_pull(struct net_pkt *pkt, size_t length);
2700
2710
2722bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2723
2733
2735
2736struct net_pkt_data_access {
2737#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2738 void *data;
2739#endif
2740 const size_t size;
2741};
2742
2743#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2744#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2745 struct net_pkt_data_access _name = { \
2746 .size = sizeof(_type), \
2747 }
2748
2749#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2750 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2751
2752#else
2753#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2754 _type _hdr_##_name; \
2755 struct net_pkt_data_access _name = { \
2756 .data = &_hdr_##_name, \
2757 .size = sizeof(_type), \
2758 }
2759
2760#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2761 struct net_pkt_data_access _name = { \
2762 .data = NULL, \
2763 .size = sizeof(_type), \
2764 }
2765
2766#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2767
2769
2783void *net_pkt_get_data(struct net_pkt *pkt,
2784 struct net_pkt_data_access *access);
2785
2800 struct net_pkt_data_access *access);
2801
2806static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2807 struct net_pkt_data_access *access)
2808{
2809 return net_pkt_skip(pkt, access->size);
2810}
2811
2815
2816#ifdef __cplusplus
2817}
2818#endif
2819
2820#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:1093
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:750
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1280
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:2305
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:2606
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:1769
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:2587
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:2667
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:2570
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:2337
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:2310
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:2806
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:2644
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:2323
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:2625
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:2454
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
#define NULL
Definition iar_missing_defs.h:20
Packet data common to all IEEE 802.15.4 L2 layers.
#define ALWAYS_INLINE
Definition common.h:161
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:204
Network Interface structure.
Definition net_if.h:744
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
#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