Zephyr API Documentation 4.4.0-rc1
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>
38#include <zephyr/logging/log.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
52
53struct net_context;
54
56
57#if defined(CONFIG_NET_PKT_ALLOC_STATS)
58struct net_pkt_alloc_stats {
59 uint64_t alloc_sum;
60 uint64_t time_sum;
61 uint32_t count;
62};
63
64struct net_pkt_alloc_stats_slab {
65 struct net_pkt_alloc_stats ok;
66 struct net_pkt_alloc_stats fail;
67 struct k_mem_slab *slab;
68};
69
70#define NET_PKT_ALLOC_STATS_DEFINE(alloc_name, slab_name) \
71 STRUCT_SECTION_ITERABLE(net_pkt_alloc_stats_slab, alloc_name) = { \
72 .slab = &slab_name, \
73 }
74
75#else
76#define NET_PKT_ALLOC_STATS_DEFINE(name, slab)
77#endif /* CONFIG_NET_PKT_ALLOC_STATS */
78
79/* buffer cursor used in net_pkt */
80struct net_pkt_cursor {
82 struct net_buf *buf;
84 uint8_t *pos;
85};
86
88
95struct net_pkt {
101
103 struct k_mem_slab *slab;
104
106 union {
107 struct net_buf *frags;
108 struct net_buf *buffer;
109 };
110
112 struct net_pkt_cursor cursor;
113
116
118 struct net_if *iface;
119
121
122#if defined(CONFIG_NET_TCP)
124 sys_snode_t next;
125#endif
126#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
127 struct net_if *orig_iface; /* Original network interface */
128#endif
129
130#if defined(CONFIG_NET_VPN)
131 struct {
133 struct net_if *iface;
135 union net_ip_header ip_hdr;
137 union net_proto_header proto_hdr;
139 int peer_id;
140 } vpn;
141#endif
142
143#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
162 struct net_ptp_time timestamp;
163#endif
164
165#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
166 defined(CONFIG_TRACING_NET_CORE)
167 struct {
169 uint32_t create_time;
170
171#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
172 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
178 struct {
179 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
180 int count;
181 } detail;
182#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
183 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
184 };
185#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
186
187#if defined(CONFIG_NET_PKT_ALLOC_STATS)
188 struct net_pkt_alloc_stats_slab *alloc_stats;
189#endif /* CONFIG_NET_PKT_ALLOC_STATS */
190
192 atomic_t atomic_ref;
193
194 /* Filled by layer 2 when network packet is received. */
195 struct net_linkaddr lladdr_src;
196 struct net_linkaddr lladdr_dst;
197 uint16_t ll_proto_type;
198
199#if defined(CONFIG_NET_IP)
200 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
201#endif
202
203 uint8_t overwrite : 1; /* Is packet content being overwritten? */
204 uint8_t eof : 1; /* Last packet before EOF */
205 uint8_t ptp_pkt : 1; /* For outgoing packet: is this packet
206 * a L2 PTP packet.
207 * Used only if defined (CONFIG_NET_L2_PTP)
208 */
209 uint8_t forwarding : 1; /* Are we forwarding this pkt
210 * Used only if defined(CONFIG_NET_ROUTE)
211 */
212 uint8_t family : 3; /* Address family, see net_ip.h */
213
214 /* bitfield byte alignment boundary */
215
216#if defined(CONFIG_NET_IPV4_ACD)
217 uint8_t ipv4_acd_arp_msg : 1; /* Is this pkt IPv4 conflict detection ARP
218 * message.
219 * Note: family needs to be
220 * NET_AF_INET.
221 */
222#endif
223#if defined(CONFIG_NET_LLDP)
224 uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
225 * Note: family needs to be
226 * NET_AF_UNSPEC.
227 */
228#endif
229 uint8_t ppp_msg : 1; /* This is a PPP message */
230 uint8_t captured : 1; /* Set to 1 if this packet is already being
231 * captured
232 */
233 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
234 * and already contains its L2 header to be
235 * preserved. Useful only if
236 * defined(CONFIG_NET_ETHERNET_BRIDGE).
237 */
238 uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
239 * processed by the L2
240 */
241 uint8_t chksum_done : 1; /* Checksum has already been computed for
242 * the packet.
243 */
244 uint8_t loopback : 1; /* Packet is a loop back packet. */
245#if defined(CONFIG_NET_IP_FRAGMENT)
246 uint8_t ip_reassembled : 1; /* Packet is a reassembled IP packet. */
247#endif
248#if defined(CONFIG_NET_PKT_TIMESTAMP)
249 uint8_t tx_timestamping : 1;
250 uint8_t rx_timestamping : 1;
251#endif
252 /* bitfield byte alignment boundary */
253
254#if defined(CONFIG_NET_IP)
255 union {
256 /* IPv6 hop limit or IPv4 ttl for this network packet.
257 * The value is shared between IPv6 and IPv4.
258 */
259#if defined(CONFIG_NET_IPV6)
260 uint8_t ipv6_hop_limit;
261#endif
262#if defined(CONFIG_NET_IPV4)
263 uint8_t ipv4_ttl;
264#endif
265 };
266
267 union {
268#if defined(CONFIG_NET_IPV4)
269 uint8_t ipv4_opts_len; /* length of IPv4 header options */
270#endif
271#if defined(CONFIG_NET_IPV6)
272 uint16_t ipv6_ext_len; /* length of extension headers */
273#endif
274 };
275
276#if defined(CONFIG_NET_IP_FRAGMENT)
277 union {
278#if defined(CONFIG_NET_IPV4_FRAGMENT)
279 struct {
280 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
281 uint16_t id; /* Fragment ID */
282 } ipv4_fragment;
283#endif /* CONFIG_NET_IPV4_FRAGMENT */
284#if defined(CONFIG_NET_IPV6_FRAGMENT)
285 struct {
286 uint16_t flags; /* Fragment offset and M (More Fragment) flag */
287 uint32_t id; /* Fragment id */
288 uint16_t hdr_start; /* Where starts the fragment header */
289 } ipv6_fragment;
290#endif /* CONFIG_NET_IPV6_FRAGMENT */
291 };
292#endif /* CONFIG_NET_IP_FRAGMENT */
293
294#if defined(CONFIG_NET_IPV6)
295 /* Where is the start of the last header before payload data
296 * in IPv6 packet. This is offset value from start of the IPv6
297 * packet. Note that this value should be updated by who ever
298 * adds IPv6 extension headers to the network packet.
299 */
300 uint16_t ipv6_prev_hdr_start;
301
302 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
303 uint8_t ipv6_next_hdr; /* What is the very first next header */
304#endif /* CONFIG_NET_IPV6 */
305
306#if defined(CONFIG_NET_IP_DSCP_ECN)
308 uint8_t ip_dscp : 6;
309
311 uint8_t ip_ecn : 2;
312#endif /* CONFIG_NET_IP_DSCP_ECN */
313#endif /* CONFIG_NET_IP */
314
315#if defined(CONFIG_NET_VLAN)
316 /* VLAN TCI (Tag Control Information). This contains the Priority
317 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
318 * Identifier (VID, called more commonly VLAN tag). This value is
319 * kept in host byte order.
320 */
321 uint16_t vlan_tci;
322#endif /* CONFIG_NET_VLAN */
323
324#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
325 /* Control block which could be used by any layer */
326 union {
327 uint8_t cb[CONFIG_NET_PKT_CONTROL_BLOCK_SIZE];
328#if defined(CONFIG_IEEE802154)
329 /* The following structure requires a 4-byte alignment
330 * boundary to avoid padding.
331 */
332 struct net_pkt_cb_ieee802154 cb_ieee802154;
333#endif /* CONFIG_IEEE802154 */
334 } cb;
335#endif /* CONFIG_NET_PKT_CONTROL_BLOCK */
336
340 uint8_t priority;
341
342#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
343 /* Remote address of the received packet. This is only used by
344 * network interfaces with an offloaded TCP/IP stack, or if we
345 * have network tunneling in use.
346 */
347 union {
348 struct net_sockaddr remote;
349
350 /* This will make sure that there is enough storage to store
351 * the address struct. The access to value is via remote
352 * address.
353 */
354 struct net_sockaddr_storage remote_storage;
355 };
356#endif /* CONFIG_NET_OFFLOAD */
357
358#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
359 /* Tell the capture api that this is a captured packet */
360 uint8_t cooked_mode_pkt : 1;
361#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
362
363#if defined(CONFIG_NET_IPV4_PMTU)
364 /* Path MTU needed for this destination address */
365 uint8_t ipv4_pmtu : 1;
366#endif /* CONFIG_NET_IPV4_PMTU */
367
368 /* @endcond */
369};
370
372
373/* The interface real ll address */
374static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
375{
376 return net_if_get_link_addr(pkt->iface);
377}
378
379static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
380{
381 return pkt->context;
382}
383
384static inline void net_pkt_set_context(struct net_pkt *pkt,
385 struct net_context *ctx)
386{
387 pkt->context = ctx;
388}
389
390static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
391{
392 return pkt->iface;
393}
394
395static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
396{
397 pkt->iface = iface;
398
399 /* If the network interface is set in pkt, then also set the type of
400 * the network address that is stored in pkt. This is done here so
401 * that the address type is properly set and is not forgotten.
402 */
403 if (iface) {
404 uint8_t type = net_if_get_link_addr(iface)->type;
405
406 pkt->lladdr_src.type = type;
407 pkt->lladdr_dst.type = type;
408 }
409}
410
411static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
412{
413#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
414 return pkt->orig_iface;
415#else
416 return pkt->iface;
417#endif
418}
419
420static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
421 struct net_if *iface)
422{
423#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
424 pkt->orig_iface = iface;
425#else
426 ARG_UNUSED(pkt);
427 ARG_UNUSED(iface);
428#endif
429}
430
431#if defined(CONFIG_NET_VPN)
432static inline struct net_if *net_pkt_vpn_iface(struct net_pkt *pkt)
433{
434 return pkt->vpn.iface;
435}
436
437static inline void net_pkt_set_vpn_iface(struct net_pkt *pkt,
438 struct net_if *iface)
439{
440 pkt->vpn.iface = iface;
441}
442
443static inline union net_ip_header *net_pkt_vpn_ip_hdr(struct net_pkt *pkt)
444{
445 return &pkt->vpn.ip_hdr;
446}
447
448static inline void net_pkt_set_vpn_ip_hdr(struct net_pkt *pkt,
449 union net_ip_header *ip_hdr)
450{
451 pkt->vpn.ip_hdr = *ip_hdr;
452}
453
454static inline union net_proto_header *net_pkt_vpn_udp_hdr(struct net_pkt *pkt)
455{
456 return &pkt->vpn.proto_hdr;
457}
458
459static inline void net_pkt_set_vpn_udp_hdr(struct net_pkt *pkt,
460 union net_proto_header *proto_hdr)
461{
462 pkt->vpn.proto_hdr = *proto_hdr;
463}
464
465static inline int net_pkt_vpn_peer_id(struct net_pkt *pkt)
466{
467 return pkt->vpn.peer_id;
468}
469
470static inline void net_pkt_set_vpn_peer_id(struct net_pkt *pkt,
471 int peer_id)
472{
473 pkt->vpn.peer_id = peer_id;
474}
475#endif /* CONFIG_NET_VPN */
476
477static inline uint8_t net_pkt_family(struct net_pkt *pkt)
478{
479 return pkt->family;
480}
481
482static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
483{
484 pkt->family = family;
485}
486
487static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
488{
489 return !!(pkt->ptp_pkt);
490}
491
492static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
493{
494 pkt->ptp_pkt = is_ptp;
495}
496
497static inline bool net_pkt_is_tx_timestamping(struct net_pkt *pkt)
498{
499#if defined(CONFIG_NET_PKT_TIMESTAMP)
500 return !!(pkt->tx_timestamping);
501#else
502 ARG_UNUSED(pkt);
503
504 return false;
505#endif
506}
507
508static inline void net_pkt_set_tx_timestamping(struct net_pkt *pkt, bool is_timestamping)
509{
510#if defined(CONFIG_NET_PKT_TIMESTAMP)
511 pkt->tx_timestamping = is_timestamping;
512#else
513 ARG_UNUSED(pkt);
514 ARG_UNUSED(is_timestamping);
515#endif
516}
517
518static inline bool net_pkt_is_rx_timestamping(struct net_pkt *pkt)
519{
520#if defined(CONFIG_NET_PKT_TIMESTAMP)
521 return !!(pkt->rx_timestamping);
522#else
523 ARG_UNUSED(pkt);
524
525 return false;
526#endif
527}
528
529static inline void net_pkt_set_rx_timestamping(struct net_pkt *pkt, bool is_timestamping)
530{
531#if defined(CONFIG_NET_PKT_TIMESTAMP)
532 pkt->rx_timestamping = is_timestamping;
533#else
534 ARG_UNUSED(pkt);
535 ARG_UNUSED(is_timestamping);
536#endif
537}
538
539static inline bool net_pkt_is_captured(struct net_pkt *pkt)
540{
541 return !!(pkt->captured);
542}
543
544static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
545{
546 pkt->captured = is_captured;
547}
548
549static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
550{
551 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
552}
553
554static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
555{
556 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
557 pkt->l2_bridged = is_l2_bridged;
558 }
559}
560
561static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
562{
563 return !!(pkt->l2_processed);
564}
565
566static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
567 bool is_l2_processed)
568{
569 pkt->l2_processed = is_l2_processed;
570}
571
572static inline bool net_pkt_is_chksum_done(struct net_pkt *pkt)
573{
574 return !!(pkt->chksum_done);
575}
576
577static inline void net_pkt_set_chksum_done(struct net_pkt *pkt,
578 bool is_chksum_done)
579{
580 pkt->chksum_done = is_chksum_done;
581}
582
583static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
584{
585#if defined(CONFIG_NET_IP)
586 return pkt->ip_hdr_len;
587#else
588 ARG_UNUSED(pkt);
589
590 return 0;
591#endif
592}
593
594static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
595{
596#if defined(CONFIG_NET_IP)
597 pkt->ip_hdr_len = len;
598#else
599 ARG_UNUSED(pkt);
600 ARG_UNUSED(len);
601#endif
602}
603
604static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
605{
606#if defined(CONFIG_NET_IP_DSCP_ECN)
607 return pkt->ip_dscp;
608#else
609 ARG_UNUSED(pkt);
610
611 return 0;
612#endif
613}
614
615static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
616{
617#if defined(CONFIG_NET_IP_DSCP_ECN)
618 pkt->ip_dscp = dscp;
619#else
620 ARG_UNUSED(pkt);
621 ARG_UNUSED(dscp);
622#endif
623}
624
625static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
626{
627#if defined(CONFIG_NET_IP_DSCP_ECN)
628 return pkt->ip_ecn;
629#else
630 ARG_UNUSED(pkt);
631
632 return 0;
633#endif
634}
635
636static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
637{
638#if defined(CONFIG_NET_IP_DSCP_ECN)
639 pkt->ip_ecn = ecn;
640#else
641 ARG_UNUSED(pkt);
642 ARG_UNUSED(ecn);
643#endif
644}
645
646static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
647{
648 return pkt->eof;
649}
650
651static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
652{
653 pkt->eof = eof;
654}
655
656static inline bool net_pkt_forwarding(struct net_pkt *pkt)
657{
658 return !!(pkt->forwarding);
659}
660
661static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
662{
663 pkt->forwarding = forward;
664}
665
666#if defined(CONFIG_NET_IPV4)
667static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
668{
669 return pkt->ipv4_ttl;
670}
671
672static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
673 uint8_t ttl)
674{
675 pkt->ipv4_ttl = ttl;
676}
677
678static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
679{
680 return pkt->ipv4_opts_len;
681}
682
683static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
684 uint8_t opts_len)
685{
686 pkt->ipv4_opts_len = opts_len;
687}
688#else
689static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
690{
691 ARG_UNUSED(pkt);
692
693 return 0;
694}
695
696static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
697 uint8_t ttl)
698{
699 ARG_UNUSED(pkt);
700 ARG_UNUSED(ttl);
701}
702
703static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
704{
705 ARG_UNUSED(pkt);
706 return 0;
707}
708
709static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
710 uint8_t opts_len)
711{
712 ARG_UNUSED(pkt);
713 ARG_UNUSED(opts_len);
714}
715#endif
716
717#if defined(CONFIG_NET_IPV6)
718static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
719{
720 return pkt->ipv6_ext_opt_len;
721}
722
723static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
724 uint8_t len)
725{
726 pkt->ipv6_ext_opt_len = len;
727}
728
729static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
730{
731 return pkt->ipv6_next_hdr;
732}
733
734static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
735 uint8_t next_hdr)
736{
737 pkt->ipv6_next_hdr = next_hdr;
738}
739
740static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
741{
742 return pkt->ipv6_ext_len;
743}
744
745static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
746{
747 pkt->ipv6_ext_len = len;
748}
749
750static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
751{
752 return pkt->ipv6_prev_hdr_start;
753}
754
755static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
756 uint16_t offset)
757{
758 pkt->ipv6_prev_hdr_start = offset;
759}
760
761static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
762{
763 return pkt->ipv6_hop_limit;
764}
765
766static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
767 uint8_t hop_limit)
768{
769 pkt->ipv6_hop_limit = hop_limit;
770}
771#else /* CONFIG_NET_IPV6 */
772static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
773{
774 ARG_UNUSED(pkt);
775
776 return 0;
777}
778
779static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
780 uint8_t len)
781{
782 ARG_UNUSED(pkt);
783 ARG_UNUSED(len);
784}
785
786static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
787{
788 ARG_UNUSED(pkt);
789
790 return 0;
791}
792
793static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
794 uint8_t next_hdr)
795{
796 ARG_UNUSED(pkt);
797 ARG_UNUSED(next_hdr);
798}
799
800static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
801{
802 ARG_UNUSED(pkt);
803
804 return 0;
805}
806
807static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
808{
809 ARG_UNUSED(pkt);
810 ARG_UNUSED(len);
811}
812
813static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
814{
815 ARG_UNUSED(pkt);
816
817 return 0;
818}
819
820static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
821 uint16_t offset)
822{
823 ARG_UNUSED(pkt);
824 ARG_UNUSED(offset);
825}
826
827static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
828{
829 ARG_UNUSED(pkt);
830
831 return 0;
832}
833
834static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
835 uint8_t hop_limit)
836{
837 ARG_UNUSED(pkt);
838 ARG_UNUSED(hop_limit);
839}
840#endif /* CONFIG_NET_IPV6 */
841
842static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
843{
844#if defined(CONFIG_NET_IPV6)
845 return pkt->ipv6_ext_len;
846#elif defined(CONFIG_NET_IPV4)
847 return pkt->ipv4_opts_len;
848#else
849 ARG_UNUSED(pkt);
850
851 return 0;
852#endif
853}
854
855#if defined(CONFIG_NET_IPV4_PMTU)
856static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
857{
858 return !!pkt->ipv4_pmtu;
859}
860
861static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
862{
863 pkt->ipv4_pmtu = value;
864}
865#else
866static inline bool net_pkt_ipv4_pmtu(struct net_pkt *pkt)
867{
868 ARG_UNUSED(pkt);
869
870 return false;
871}
872
873static inline void net_pkt_set_ipv4_pmtu(struct net_pkt *pkt, bool value)
874{
875 ARG_UNUSED(pkt);
876 ARG_UNUSED(value);
877}
878#endif /* CONFIG_NET_IPV4_PMTU */
879
880#if defined(CONFIG_NET_IPV4_FRAGMENT)
881static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
882{
883 return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
884}
885
886static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
887{
888 return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
889}
890
891static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
892{
893 pkt->ipv4_fragment.flags = flags;
894}
895
896static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
897{
898 return pkt->ipv4_fragment.id;
899}
900
901static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
902{
903 pkt->ipv4_fragment.id = id;
904}
905#else /* CONFIG_NET_IPV4_FRAGMENT */
906static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
907{
908 ARG_UNUSED(pkt);
909
910 return 0;
911}
912
913static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
914{
915 ARG_UNUSED(pkt);
916
917 return 0;
918}
919
920static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
921{
922 ARG_UNUSED(pkt);
923 ARG_UNUSED(flags);
924}
925
926static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
927{
928 ARG_UNUSED(pkt);
929
930 return 0;
931}
932
933static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
934{
935 ARG_UNUSED(pkt);
936 ARG_UNUSED(id);
937}
938#endif /* CONFIG_NET_IPV4_FRAGMENT */
939
940#if defined(CONFIG_NET_IPV6_FRAGMENT)
941static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
942{
943 return pkt->ipv6_fragment.hdr_start;
944}
945
946static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
947 uint16_t start)
948{
949 pkt->ipv6_fragment.hdr_start = start;
950}
951
952static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
953{
954 return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
955}
956static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
957{
958 return (pkt->ipv6_fragment.flags & 0x01) != 0;
959}
960
961static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
963{
964 pkt->ipv6_fragment.flags = flags;
965}
966
967static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
968{
969 return pkt->ipv6_fragment.id;
970}
971
972static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
973 uint32_t id)
974{
975 pkt->ipv6_fragment.id = id;
976}
977#else /* CONFIG_NET_IPV6_FRAGMENT */
978static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
979{
980 ARG_UNUSED(pkt);
981
982 return 0;
983}
984
985static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
986 uint16_t start)
987{
988 ARG_UNUSED(pkt);
989 ARG_UNUSED(start);
990}
991
992static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
993{
994 ARG_UNUSED(pkt);
995
996 return 0;
997}
998
999static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
1000{
1001 ARG_UNUSED(pkt);
1002
1003 return 0;
1004}
1005
1006static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
1008{
1009 ARG_UNUSED(pkt);
1010 ARG_UNUSED(flags);
1011}
1012
1013static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
1014{
1015 ARG_UNUSED(pkt);
1016
1017 return 0;
1018}
1019
1020static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
1021 uint32_t id)
1022{
1023 ARG_UNUSED(pkt);
1024 ARG_UNUSED(id);
1025}
1026#endif /* CONFIG_NET_IPV6_FRAGMENT */
1027
1028static inline bool net_pkt_is_loopback(struct net_pkt *pkt)
1029{
1030 return !!(pkt->loopback);
1031}
1032
1033static inline void net_pkt_set_loopback(struct net_pkt *pkt,
1034 bool loopback)
1035{
1036 pkt->loopback = loopback;
1037}
1038
1039#if defined(CONFIG_NET_IP_FRAGMENT)
1040static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1041{
1042 return !!(pkt->ip_reassembled);
1043}
1044
1045static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1046 bool reassembled)
1047{
1048 pkt->ip_reassembled = reassembled;
1049}
1050#else /* CONFIG_NET_IP_FRAGMENT */
1051static inline bool net_pkt_is_ip_reassembled(struct net_pkt *pkt)
1052{
1053 ARG_UNUSED(pkt);
1054
1055 return false;
1056}
1057
1058static inline void net_pkt_set_ip_reassembled(struct net_pkt *pkt,
1059 bool reassembled)
1060{
1061 ARG_UNUSED(pkt);
1062 ARG_UNUSED(reassembled);
1063}
1064#endif /* CONFIG_NET_IP_FRAGMENT */
1065
1066static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
1067{
1068 return pkt->priority;
1069}
1070
1071static inline void net_pkt_set_priority(struct net_pkt *pkt,
1072 uint8_t priority)
1073{
1074 pkt->priority = priority;
1075}
1076
1077#if defined(CONFIG_NET_CAPTURE_COOKED_MODE)
1078static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1079{
1080 return pkt->cooked_mode_pkt;
1081}
1082
1083static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1084{
1085 pkt->cooked_mode_pkt = value;
1086}
1087#else
1088static inline bool net_pkt_is_cooked_mode(struct net_pkt *pkt)
1089{
1090 ARG_UNUSED(pkt);
1091
1092 return false;
1093}
1094
1095static inline void net_pkt_set_cooked_mode(struct net_pkt *pkt, bool value)
1096{
1097 ARG_UNUSED(pkt);
1098 ARG_UNUSED(value);
1099}
1100#endif /* CONFIG_NET_CAPTURE_COOKED_MODE */
1101
1102#if defined(CONFIG_NET_VLAN)
1103static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1104{
1105 return net_eth_vlan_get_vid(pkt->vlan_tci);
1106}
1107
1108static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1109{
1110 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
1111}
1112
1113static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1114{
1115 return net_eth_vlan_get_pcp(pkt->vlan_tci);
1116}
1117
1118static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
1119 uint8_t priority)
1120{
1121 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
1122}
1123
1124static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1125{
1126 return net_eth_vlan_get_dei(pkt->vlan_tci);
1127}
1128
1129static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1130{
1131 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
1132}
1133
1134static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1135{
1136 pkt->vlan_tci = tci;
1137}
1138
1139static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1140{
1141 return pkt->vlan_tci;
1142}
1143#else
1144static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
1145{
1146 ARG_UNUSED(pkt);
1147
1148 return NET_VLAN_TAG_UNSPEC;
1149}
1150
1151static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
1152{
1153 ARG_UNUSED(pkt);
1154 ARG_UNUSED(tag);
1155}
1156
1157static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
1158{
1159 ARG_UNUSED(pkt);
1160
1161 return 0;
1162}
1163
1164static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
1165{
1166 ARG_UNUSED(pkt);
1167
1168 return false;
1169}
1170
1171static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
1172{
1173 ARG_UNUSED(pkt);
1174 ARG_UNUSED(dei);
1175}
1176
1177static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
1178{
1179 ARG_UNUSED(pkt);
1180
1181 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
1182}
1183
1184static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
1185{
1186 ARG_UNUSED(pkt);
1187 ARG_UNUSED(tci);
1188}
1189#endif
1190
1191#if defined(CONFIG_NET_PKT_TIMESTAMP) || defined(CONFIG_NET_PKT_TXTIME)
1192static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1193{
1194 return &pkt->timestamp;
1195}
1196
1197static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1198 struct net_ptp_time *timestamp)
1199{
1200 pkt->timestamp.second = timestamp->second;
1201 pkt->timestamp.nanosecond = timestamp->nanosecond;
1202}
1203
1204static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1205{
1206 return net_ptp_time_to_ns(&pkt->timestamp);
1207}
1208
1209static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1210{
1211 pkt->timestamp = ns_to_net_ptp_time(timestamp);
1212}
1213#else
1214static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
1215{
1216 ARG_UNUSED(pkt);
1217
1218 return NULL;
1219}
1220
1221static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
1222 struct net_ptp_time *timestamp)
1223{
1224 ARG_UNUSED(pkt);
1225 ARG_UNUSED(timestamp);
1226}
1227
1228static inline net_time_t net_pkt_timestamp_ns(struct net_pkt *pkt)
1229{
1230 ARG_UNUSED(pkt);
1231
1232 return 0;
1233}
1234
1235static inline void net_pkt_set_timestamp_ns(struct net_pkt *pkt, net_time_t timestamp)
1236{
1237 ARG_UNUSED(pkt);
1238 ARG_UNUSED(timestamp);
1239}
1240#endif /* CONFIG_NET_PKT_TIMESTAMP || CONFIG_NET_PKT_TXTIME */
1241
1242#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS) || \
1243 defined(CONFIG_TRACING_NET_CORE)
1244
1245static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1246{
1247 return pkt->create_time;
1248}
1249
1250static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1251 uint32_t create_time)
1252{
1253 pkt->create_time = create_time;
1254}
1255#else
1256static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
1257{
1258 ARG_UNUSED(pkt);
1259
1260 return 0U;
1261}
1262
1263static inline void net_pkt_set_create_time(struct net_pkt *pkt,
1264 uint32_t create_time)
1265{
1266 ARG_UNUSED(pkt);
1267 ARG_UNUSED(create_time);
1268}
1269#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS ||
1270 * CONFIG_TRACING_NET_CORE
1271 */
1272
1273#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
1274 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
1275static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1276{
1277 return pkt->detail.stat;
1278}
1279
1280static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1281{
1282 return pkt->detail.count;
1283}
1284
1285static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1286{
1287 memset(&pkt->detail, 0, sizeof(pkt->detail));
1288}
1289
1290static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
1291 uint32_t tick)
1292{
1293 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
1294 LOG_ERR("Detail stats count overflow (%d >= %d)",
1295 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
1296 return;
1297 }
1298
1299 pkt->detail.stat[pkt->detail.count++] = tick;
1300}
1301
1302#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1303#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
1304#else
1305static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
1306{
1307 ARG_UNUSED(pkt);
1308
1309 return NULL;
1310}
1311
1312static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
1313{
1314 ARG_UNUSED(pkt);
1315
1316 return 0;
1317}
1318
1319static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
1320{
1321 ARG_UNUSED(pkt);
1322}
1323
1324static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
1325{
1326 ARG_UNUSED(pkt);
1327 ARG_UNUSED(tick);
1328}
1329
1330#define net_pkt_set_tx_stats_tick(pkt, tick)
1331#define net_pkt_set_rx_stats_tick(pkt, tick)
1332#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
1333 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
1334
1335static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
1336{
1337 return pkt->frags->data;
1338}
1339
1340static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
1341{
1342 return pkt->frags->data;
1343}
1344
1345static inline bool net_pkt_is_empty(struct net_pkt *pkt)
1346{
1347 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
1348}
1349
1350static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
1351{
1352 return &pkt->lladdr_src;
1353}
1354
1355static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
1356{
1357 return &pkt->lladdr_dst;
1358}
1359
1360static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
1361{
1362 struct net_linkaddr tmp;
1363
1364 memcpy(tmp.addr,
1365 net_pkt_lladdr_src(pkt)->addr,
1366 net_pkt_lladdr_src(pkt)->len);
1367 memcpy(net_pkt_lladdr_src(pkt)->addr,
1368 net_pkt_lladdr_dst(pkt)->addr,
1369 net_pkt_lladdr_dst(pkt)->len);
1370 memcpy(net_pkt_lladdr_dst(pkt)->addr,
1371 tmp.addr,
1372 net_pkt_lladdr_src(pkt)->len);
1373}
1374
1375static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1376{
1377 (void)net_linkaddr_clear(net_pkt_lladdr_src(pkt));
1378 (void)net_linkaddr_clear(net_pkt_lladdr_dst(pkt));
1379}
1380
1381static inline uint16_t net_pkt_ll_proto_type(struct net_pkt *pkt)
1382{
1383 return pkt->ll_proto_type;
1384}
1385
1386static inline void net_pkt_set_ll_proto_type(struct net_pkt *pkt, uint16_t type)
1387{
1388 pkt->ll_proto_type = type;
1389}
1390
1391#if defined(CONFIG_NET_IPV4_ACD)
1392static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1393{
1394 return !!(pkt->ipv4_acd_arp_msg);
1395}
1396
1397static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1398 bool is_acd_arp_msg)
1399{
1400 pkt->ipv4_acd_arp_msg = is_acd_arp_msg;
1401}
1402#else /* CONFIG_NET_IPV4_ACD */
1403static inline bool net_pkt_ipv4_acd(struct net_pkt *pkt)
1404{
1405 ARG_UNUSED(pkt);
1406
1407 return false;
1408}
1409
1410static inline void net_pkt_set_ipv4_acd(struct net_pkt *pkt,
1411 bool is_acd_arp_msg)
1412{
1413 ARG_UNUSED(pkt);
1414 ARG_UNUSED(is_acd_arp_msg);
1415}
1416#endif /* CONFIG_NET_IPV4_ACD */
1417
1418#if defined(CONFIG_NET_LLDP)
1419static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1420{
1421 return !!(pkt->lldp_pkt);
1422}
1423
1424static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1425{
1426 pkt->lldp_pkt = is_lldp;
1427}
1428#else
1429static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1430{
1431 ARG_UNUSED(pkt);
1432
1433 return false;
1434}
1435
1436static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1437{
1438 ARG_UNUSED(pkt);
1439 ARG_UNUSED(is_lldp);
1440}
1441#endif /* CONFIG_NET_LLDP */
1442
1443#if defined(CONFIG_NET_L2_PPP)
1444static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1445{
1446 return !!(pkt->ppp_msg);
1447}
1448
1449static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1450 bool is_ppp_msg)
1451{
1452 pkt->ppp_msg = is_ppp_msg;
1453}
1454#else /* CONFIG_NET_L2_PPP */
1455static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1456{
1457 ARG_UNUSED(pkt);
1458
1459 return false;
1460}
1461
1462static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1463 bool is_ppp_msg)
1464{
1465 ARG_UNUSED(pkt);
1466 ARG_UNUSED(is_ppp_msg);
1467}
1468#endif /* CONFIG_NET_L2_PPP */
1469
1470#if defined(CONFIG_NET_PKT_CONTROL_BLOCK)
1471static inline void *net_pkt_cb(struct net_pkt *pkt)
1472{
1473 return &pkt->cb;
1474}
1475#else
1476static inline void *net_pkt_cb(struct net_pkt *pkt)
1477{
1478 ARG_UNUSED(pkt);
1479
1480 return NULL;
1481}
1482#endif
1483
1484#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1485#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1486
1487static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1488{
1490 net_pkt_context(pkt)),
1491 (struct net_in6_addr *)NET_IPV6_HDR(pkt)->src);
1492}
1493
1494static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1495{
1496 pkt->overwrite = overwrite;
1497}
1498
1499static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1500{
1501 return !!(pkt->overwrite);
1502}
1503
1504#ifdef CONFIG_NET_PKT_FILTER
1505
1506bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1507bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1508
1509#else
1510
1511static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1512{
1513 ARG_UNUSED(pkt);
1514
1515 return true;
1516}
1517
1518static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1519{
1520 ARG_UNUSED(pkt);
1521
1522 return true;
1523}
1524
1525#endif /* CONFIG_NET_PKT_FILTER */
1526
1527#if defined(CONFIG_NET_PKT_FILTER) && \
1528 (defined(CONFIG_NET_PKT_FILTER_IPV4_HOOK) || defined(CONFIG_NET_PKT_FILTER_IPV6_HOOK))
1529
1530bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt);
1531
1532#else
1533
1534static inline bool net_pkt_filter_ip_recv_ok(struct net_pkt *pkt)
1535{
1536 ARG_UNUSED(pkt);
1537
1538 return true;
1539}
1540
1541#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK || CONFIG_NET_PKT_FILTER_IPV6_HOOK */
1542
1543#if defined(CONFIG_NET_PKT_FILTER) && defined(CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK)
1544
1545bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt);
1546
1547#else
1548
1549static inline bool net_pkt_filter_local_in_recv_ok(struct net_pkt *pkt)
1550{
1551 ARG_UNUSED(pkt);
1552
1553 return true;
1554}
1555
1556#endif /* CONFIG_NET_PKT_FILTER && CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
1557
1558#if defined(CONFIG_NET_OFFLOAD) || defined(CONFIG_NET_L2_IPIP)
1559static inline struct net_sockaddr *net_pkt_remote_address(struct net_pkt *pkt)
1560{
1561 return &pkt->remote;
1562}
1563
1564static inline void net_pkt_set_remote_address(struct net_pkt *pkt,
1565 struct net_sockaddr *address,
1566 net_socklen_t len)
1567{
1568 memcpy(&pkt->remote, address, len);
1569}
1570#endif /* CONFIG_NET_OFFLOAD || CONFIG_NET_L2_IPIP */
1571
1572/* @endcond */
1573
1587#define NET_PKT_SLAB_DEFINE(name, count) \
1588 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4); \
1589 NET_PKT_ALLOC_STATS_DEFINE(pkt_alloc_stats_##name, name)
1590
1592
1593/* Backward compatibility macro */
1594#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1595
1597
1611#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1612 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1613 0, NULL)
1614
1616
1617#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1618 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1619#define NET_PKT_DEBUG_ENABLED
1620#endif
1621
1622#if defined(NET_PKT_DEBUG_ENABLED)
1623
1624/* Debug versions of the net_pkt functions that are used when tracking
1625 * buffer usage.
1626 */
1627
1628struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1629 size_t min_len,
1630 k_timeout_t timeout,
1631 const char *caller,
1632 int line);
1633
1634#define net_pkt_get_reserve_data(pool, min_len, timeout) \
1635 net_pkt_get_reserve_data_debug(pool, min_len, timeout, __func__, __LINE__)
1636
1637struct net_buf *net_pkt_get_reserve_rx_data_debug(size_t min_len,
1638 k_timeout_t timeout,
1639 const char *caller,
1640 int line);
1641#define net_pkt_get_reserve_rx_data(min_len, timeout) \
1642 net_pkt_get_reserve_rx_data_debug(min_len, timeout, __func__, __LINE__)
1643
1644struct net_buf *net_pkt_get_reserve_tx_data_debug(size_t min_len,
1645 k_timeout_t timeout,
1646 const char *caller,
1647 int line);
1648#define net_pkt_get_reserve_tx_data(min_len, timeout) \
1649 net_pkt_get_reserve_tx_data_debug(min_len, timeout, __func__, __LINE__)
1650
1651struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt, size_t min_len,
1652 k_timeout_t timeout,
1653 const char *caller, int line);
1654#define net_pkt_get_frag(pkt, min_len, timeout) \
1655 net_pkt_get_frag_debug(pkt, min_len, timeout, __func__, __LINE__)
1656
1657void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1658#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1659
1660struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1661 int line);
1662#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1663
1664struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1665 const char *caller, int line);
1666#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1667
1668void net_pkt_frag_unref_debug(struct net_buf *frag,
1669 const char *caller, int line);
1670#define net_pkt_frag_unref(frag) \
1671 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1672
1673struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1674 struct net_buf *parent,
1675 struct net_buf *frag,
1676 const char *caller, int line);
1677#define net_pkt_frag_del(pkt, parent, frag) \
1678 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1679
1680void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1681 const char *caller, int line);
1682#define net_pkt_frag_add(pkt, frag) \
1683 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1684
1685void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1686 const char *caller, int line);
1687#define net_pkt_frag_insert(pkt, frag) \
1688 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1689#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1690 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1691 */
1693
1694#if defined(NET_PKT_DEBUG_ENABLED)
1702void net_pkt_print_frags(struct net_pkt *pkt);
1703#else
1704#define net_pkt_print_frags(pkt)
1705#endif
1706
1707#if !defined(NET_PKT_DEBUG_ENABLED)
1723 size_t min_len, k_timeout_t timeout);
1724#endif
1725
1726#if !defined(NET_PKT_DEBUG_ENABLED)
1741struct net_buf *net_pkt_get_reserve_rx_data(size_t min_len, k_timeout_t timeout);
1742#endif
1743
1744#if !defined(NET_PKT_DEBUG_ENABLED)
1759struct net_buf *net_pkt_get_reserve_tx_data(size_t min_len, k_timeout_t timeout);
1760#endif
1761
1762#if !defined(NET_PKT_DEBUG_ENABLED)
1775struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, size_t min_len,
1776 k_timeout_t timeout);
1777#endif
1778
1779#if !defined(NET_PKT_DEBUG_ENABLED)
1789void net_pkt_unref(struct net_pkt *pkt);
1790#endif
1791
1792#if !defined(NET_PKT_DEBUG_ENABLED)
1802struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1803#endif
1804
1805#if !defined(NET_PKT_DEBUG_ENABLED)
1815struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1816#endif
1817
1818#if !defined(NET_PKT_DEBUG_ENABLED)
1824void net_pkt_frag_unref(struct net_buf *frag);
1825#endif
1826
1827#if !defined(NET_PKT_DEBUG_ENABLED)
1839 struct net_buf *parent,
1840 struct net_buf *frag);
1841#endif
1842
1843#if !defined(NET_PKT_DEBUG_ENABLED)
1850void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1851#endif
1852
1853#if !defined(NET_PKT_DEBUG_ENABLED)
1860void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1861#endif
1862
1869void net_pkt_compact(struct net_pkt *pkt);
1870
1879void net_pkt_get_info(struct k_mem_slab **rx,
1880 struct k_mem_slab **tx,
1881 struct net_buf_pool **rx_data,
1882 struct net_buf_pool **tx_data);
1883
1885
1886#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1890void net_pkt_print(void);
1891
1892typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1893 struct net_buf *buf,
1894 const char *func_alloc,
1895 int line_alloc,
1896 const char *func_free,
1897 int line_free,
1898 bool in_use,
1899 void *user_data);
1900
1901void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1902
1903const char *net_pkt_slab2str(struct k_mem_slab *slab);
1904const char *net_pkt_pool2str(struct net_buf_pool *pool);
1905
1906#else
1907#define net_pkt_print(...)
1908#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1909
1910/* New allocator, and API are defined below.
1911 * This will be simpler when time will come to get rid of former API above.
1912 */
1913#if defined(NET_PKT_DEBUG_ENABLED)
1914
1915struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1916 const char *caller, int line);
1917#define net_pkt_alloc(_timeout) \
1918 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1919
1920struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1921 k_timeout_t timeout,
1922 const char *caller, int line);
1923#define net_pkt_alloc_from_slab(_slab, _timeout) \
1924 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1925
1926struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1927 const char *caller, int line);
1928#define net_pkt_rx_alloc(_timeout) \
1929 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1930
1931struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1932 k_timeout_t timeout,
1933 const char *caller,
1934 int line);
1935#define net_pkt_alloc_on_iface(_iface, _timeout) \
1936 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1937
1938struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1939 k_timeout_t timeout,
1940 const char *caller,
1941 int line);
1942#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1943 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1944 __func__, __LINE__)
1945
1946int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1947 size_t size,
1948 enum net_ip_protocol proto,
1949 k_timeout_t timeout,
1950 const char *caller, int line);
1951#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1952 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1953 __func__, __LINE__)
1954
1955int net_pkt_alloc_buffer_raw_debug(struct net_pkt *pkt, size_t size,
1956 k_timeout_t timeout,
1957 const char *caller, int line);
1958#define net_pkt_alloc_buffer_raw(_pkt, _size, _timeout) \
1959 net_pkt_alloc_buffer_raw_debug(_pkt, _size, _timeout, \
1960 __func__, __LINE__)
1961
1962struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1963 size_t size,
1964 net_sa_family_t family,
1965 enum net_ip_protocol proto,
1966 k_timeout_t timeout,
1967 const char *caller,
1968 int line);
1969#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1970 _proto, _timeout) \
1971 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1972 _proto, _timeout, \
1973 __func__, __LINE__)
1974
1975struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1976 size_t size,
1977 net_sa_family_t family,
1978 enum net_ip_protocol proto,
1979 k_timeout_t timeout,
1980 const char *caller,
1981 int line);
1982#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1983 _proto, _timeout) \
1984 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1985 _proto, _timeout, \
1986 __func__, __LINE__)
1987
1988int net_pkt_alloc_buffer_with_reserve_debug(struct net_pkt *pkt,
1989 size_t size,
1990 size_t reserve,
1991 enum net_ip_protocol proto,
1992 k_timeout_t timeout,
1993 const char *caller,
1994 int line);
1995#define net_pkt_alloc_buffer_with_reserve(_pkt, _size, _reserve, _proto, _timeout) \
1996 net_pkt_alloc_buffer_with_reserve_debug(_pkt, _size, _reserve, _proto, \
1997 _timeout, __func__, __LINE__)
1998
1999#endif /* NET_PKT_DEBUG_ENABLED */
2001
2002#if !defined(NET_PKT_DEBUG_ENABLED)
2014#endif
2015
2016#if !defined(NET_PKT_DEBUG_ENABLED)
2031struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
2032 k_timeout_t timeout);
2033#endif
2034
2035#if !defined(NET_PKT_DEBUG_ENABLED)
2047#endif
2048
2049#if !defined(NET_PKT_DEBUG_ENABLED)
2059 k_timeout_t timeout);
2060
2062
2063/* Same as above but specifically for RX packet */
2064struct net_pkt *net_pkt_rx_alloc_on_iface(struct net_if *iface,
2065 k_timeout_t timeout);
2067
2068#endif
2069
2070#if !defined(NET_PKT_DEBUG_ENABLED)
2087 size_t size,
2088 enum net_ip_protocol proto,
2089 k_timeout_t timeout);
2090#endif
2091
2092#if !defined(NET_PKT_DEBUG_ENABLED)
2110#if !defined(NET_PKT_DEBUG_ENABLED)
2112 size_t size,
2113 size_t reserve,
2114 enum net_ip_protocol proto,
2115 k_timeout_t timeout);
2116#endif
2117
2131int net_pkt_alloc_buffer_raw(struct net_pkt *pkt, size_t size,
2132 k_timeout_t timeout);
2133#endif
2134
2135#if !defined(NET_PKT_DEBUG_ENABLED)
2148 size_t size,
2149 net_sa_family_t family,
2150 enum net_ip_protocol proto,
2151 k_timeout_t timeout);
2152
2154
2155/* Same as above but specifically for RX packet */
2156struct net_pkt *net_pkt_rx_alloc_with_buffer(struct net_if *iface,
2157 size_t size,
2158 net_sa_family_t family,
2159 enum net_ip_protocol proto,
2160 k_timeout_t timeout);
2161
2163
2164#endif
2165
2172void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
2173
2185
2202 enum net_ip_protocol proto);
2203
2213
2228int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
2229
2238
2245static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
2246 struct net_pkt_cursor *backup)
2247{
2248 backup->buf = pkt->cursor.buf;
2249 backup->pos = pkt->cursor.pos;
2250}
2251
2258static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
2259 struct net_pkt_cursor *backup)
2260{
2261 pkt->cursor.buf = backup->buf;
2262 pkt->cursor.pos = backup->pos;
2263}
2264
2272static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
2273{
2274 return pkt->cursor.pos;
2275}
2276
2294int net_pkt_skip(struct net_pkt *pkt, size_t length);
2295
2310int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
2311
2325int net_pkt_copy(struct net_pkt *pkt_dst,
2326 struct net_pkt *pkt_src,
2327 size_t length);
2328
2338struct net_pkt *net_pkt_clone(struct net_pkt *pkt, k_timeout_t timeout);
2339
2349struct net_pkt *net_pkt_rx_clone(struct net_pkt *pkt, k_timeout_t timeout);
2350
2360 k_timeout_t timeout);
2361
2375int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
2376
2389static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
2390{
2391 return net_pkt_read(pkt, data, 1);
2392}
2393
2406int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data);
2407
2420int net_pkt_read_le16(struct net_pkt *pkt, uint16_t *data);
2421
2434int net_pkt_read_be32(struct net_pkt *pkt, uint32_t *data);
2435
2448int net_pkt_read_le32(struct net_pkt *pkt, uint32_t *data);
2449
2462int net_pkt_read_be64(struct net_pkt *pkt, uint64_t *data);
2463
2476int net_pkt_read_le64(struct net_pkt *pkt, uint64_t *data);
2477
2491int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
2492
2505static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
2506{
2507 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2508}
2509
2522static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2523{
2524 uint16_t data_be16 = net_htons(data);
2525
2526 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2527}
2528
2541static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2542{
2543 uint32_t data_be32 = net_htonl(data);
2544
2545 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2546}
2547
2560static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2561{
2562 uint32_t data_le32 = sys_cpu_to_le32(data);
2563
2564 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2565}
2566
2579static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2580{
2581 uint16_t data_le16 = sys_cpu_to_le16(data);
2582
2583 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2584}
2585
2594
2602static inline size_t net_pkt_get_len(struct net_pkt *pkt)
2603{
2604 return net_buf_frags_len(pkt->frags);
2605}
2606
2619int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2620
2634int net_pkt_pull(struct net_pkt *pkt, size_t length);
2635
2645
2657bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2658
2668
2670
2671struct net_pkt_data_access {
2672#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2673 void *data;
2674#endif
2675 const size_t size;
2676};
2677
2678#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2679#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2680 struct net_pkt_data_access _name = { \
2681 .size = sizeof(_type), \
2682 }
2683
2684#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2685 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2686
2687#else
2688#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2689 _type _hdr_##_name; \
2690 struct net_pkt_data_access _name = { \
2691 .data = &_hdr_##_name, \
2692 .size = sizeof(_type), \
2693 }
2694
2695#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2696 struct net_pkt_data_access _name = { \
2697 .data = NULL, \
2698 .size = sizeof(_type), \
2699 }
2700
2701#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2702
2704
2718void *net_pkt_get_data(struct net_pkt *pkt,
2719 struct net_pkt_data_access *access);
2720
2735 struct net_pkt_data_access *access);
2736
2741static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2742 struct net_pkt_data_access *access)
2743{
2744 return net_pkt_skip(pkt, access->size);
2745}
2746
2750
2751#ifdef __cplusplus
2752}
2753#endif
2754
2755#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
long atomic_t
Definition atomic_types.h:15
VLAN specific definitions.
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:171
#define net_htonl(x)
Convert 32-bit value from host to network byte order.
Definition net_ip.h:132
unsigned short int net_sa_family_t
Socket address family type.
Definition net_ip.h:168
#define net_htons(x)
Convert 16-bit value from host to network byte order.
Definition net_ip.h:124
net_ip_protocol
Protocol numbers from IANA/BSD.
Definition net_ip.h:64
#define LOG_ERR(...)
Writes an ERROR level message to the log.
Definition log.h:62
static size_t net_buf_frags_len(const struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition net_buf.h:2756
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition net_context.h:752
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition net_if.h:1229
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:2238
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:2541
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:1704
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:2522
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:2602
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:2505
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:2272
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:2245
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:2741
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:2579
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:2258
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:2560
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:2389
struct net_buf * net_pkt_get_frag(struct net_pkt *pkt, size_t min_len, k_timeout_t timeout)
Get a data fragment that might be from user specific buffer pool or from global DATA pool.
size_t net_pkt_get_contiguous_len(struct net_pkt *pkt)
Get the contiguous buffer space.
int64_t net_time_t
Any occurrence of net_time_t specifies a concept of nanosecond resolution scalar time span,...
Definition net_time.h:103
static net_time_t net_ptp_time_to_ns(struct net_ptp_time *ts)
Convert a PTP timestamp to a nanosecond precision timestamp, both related to the local network refere...
Definition ptp_time.h:210
static struct net_ptp_time ns_to_net_ptp_time(net_time_t nsec)
Convert a nanosecond precision timestamp to a PTP timestamp, both related to the local network refere...
Definition ptp_time.h:231
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:39
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition util_macro.h:154
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition ethernet_vlan.h:81
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition ethernet_vlan.h:56
#define NET_VLAN_TAG_UNSPEC
Unspecified VLAN tag value.
Definition ethernet_vlan.h:32
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition ethernet_vlan.h:94
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition ethernet_vlan.h:44
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition ethernet_vlan.h:107
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition ethernet_vlan.h:68
#define NULL
Definition iar_missing_defs.h:20
Packet data common to all IEEE 802.15.4 L2 layers.
#define ALWAYS_INLINE
Definition common.h:161
Buffer management.
Network context definitions.
Network core definitions.
Public API for network interface.
IPv6 and IPv4 definitions.
Public API for network link address.
Representation of nanosecond resolution elapsed time and timestamps in the network stack.
flags
Definition parser.h:97
Public functions for the Precision Time Protocol time specification.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INTPTR_TYPE__ intptr_t
Definition stdint.h:104
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
void * memset(void *buf, int c, size_t n)
void * memcpy(void *ZRESTRICT d, const void *ZRESTRICT s, size_t n)
Kernel timeout type.
Definition clock.h:65
Network buffer pool representation.
Definition net_buf.h:1088
Network buffer representation.
Definition net_buf.h:1015
uint8_t * data
Pointer to the start of data in the buffer.
Definition net_buf.h:1041
uint8_t user_data[]
System metadata for this buffer.
Definition net_buf.h:1062
uint16_t len
Length of the data behind the data pointer.
Definition net_buf.h:1044
Note that we do not store the actual source IP address in the context because the address is already ...
Definition net_context.h:209
Network Interface structure.
Definition net_if.h:731
IPv6 address struct.
Definition net_ip.h:143
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:95
struct net_buf * frags
buffer fragment
Definition net_pkt.h:107
struct net_context * context
Network connection context.
Definition net_pkt.h:115
struct net_pkt_cursor cursor
Internal buffer iterator used for reading/writing.
Definition net_pkt.h:112
struct net_if * iface
Network interface.
Definition net_pkt.h:118
intptr_t fifo
The fifo is used by RX/TX threads and by socket layer.
Definition net_pkt.h:100
struct net_buf * buffer
alias to a buffer fragment
Definition net_pkt.h:108
struct k_mem_slab * slab
Slab pointer from where it belongs to.
Definition net_pkt.h:103
(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:448
Definition stat.h:57
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition byteorder.h:272
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition byteorder.h:268