Zephyr API Documentation  3.0.0
A Scalable Open Source RTOS
3.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
net_pkt.h
Go to the documentation of this file.
1
8/*
9 * Copyright (c) 2016 Intel Corporation
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13
14/* Data buffer API - used for all data to/from net */
15
16#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
17#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
18
19#include <zephyr/types.h>
20#include <stdbool.h>
21
22#include <net/buf.h>
23
24#include <net/net_core.h>
25#include <net/net_linkaddr.h>
26#include <net/net_ip.h>
27#include <net/net_if.h>
28#include <net/net_context.h>
29#include <net/ethernet_vlan.h>
30#include <net/ptp_time.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
43struct net_context;
44struct canbus_net_isotp_tx_ctx;
45struct canbus_net_isotp_rx_ctx;
46
47
48/* buffer cursor used in net_pkt */
51 struct net_buf *buf;
54};
55
62struct net_pkt {
68
70 struct k_mem_slab *slab;
71
73 union {
74 struct net_buf *frags;
75 struct net_buf *buffer;
76 };
77
80
83
85 struct net_if *iface;
86
89#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
90 struct net_if *orig_iface; /* Original network interface */
91#endif
92
93#if defined(CONFIG_NET_PKT_TIMESTAMP)
95 struct net_ptp_time timestamp;
96#endif
97
98#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
99 struct {
101 uint32_t create_time;
102
103#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
104 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
110 struct {
111 uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
112 int count;
113 } detail;
114#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
115 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
116 };
117#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
118
119#if defined(CONFIG_NET_PKT_TXTIME)
121 uint64_t txtime;
122#endif /* CONFIG_NET_PKT_TXTIME */
123
125 atomic_t atomic_ref;
126
127 /* Filled by layer 2 when network packet is received. */
128 struct net_linkaddr lladdr_src;
129 struct net_linkaddr lladdr_dst;
130
131#if defined(CONFIG_NET_TCP)
133 sys_snode_t next;
134#endif
135
136 uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
137
138 uint8_t overwrite : 1; /* Is packet content being overwritten? */
139
140 uint8_t sent_or_eof: 1; /* For outgoing packet: is this sent or not
141 * For incoming packet of a socket: last
142 * packet before EOF
143 * Used only if defined(CONFIG_NET_TCP)
144 */
145 union {
146 uint8_t pkt_queued: 1; /* For outgoing packet: is this packet
147 * queued to be sent but has not reached
148 * the driver yet.
149 * Used only if defined(CONFIG_NET_TCP)
150 */
151 uint8_t ptp_pkt: 1; /* For outgoing packet: is this packet
152 * a L2 PTP packet.
153 * Used only if defined (CONFIG_NET_L2_PTP)
154 */
155 };
156
157 uint8_t forwarding : 1; /* Are we forwarding this pkt
158 * Used only if defined(CONFIG_NET_ROUTE)
159 */
160 uint8_t family : 3; /* IPv4 vs IPv6 */
161
162 union {
163 uint8_t ipv4_auto_arp_msg : 1; /* Is this pkt IPv4 autoconf ARP
164 * message. Used only if
165 * defined(CONFIG_NET_IPV4_AUTO).
166 * Note: family needs to be
167 * AF_INET.
168 */
169 uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
170 * Used only if
171 * defined(CONFIG_NET_LLDP).
172 * Note: family needs to be
173 * AF_UNSPEC.
174 */
175 uint8_t ppp_msg : 1; /* This is a PPP message */
176 };
177
178#if defined(CONFIG_NET_TCP)
179 uint8_t tcp_first_msg : 1; /* Is this the first time this pkt is
180 * sent, or is this a resend of a TCP
181 * segment.
182 */
183#endif
184
185 uint8_t captured : 1; /* Set to 1 if this packet is already being
186 * captured
187 */
188
189 uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
190 * and already contains its L2 header to be
191 * preserved. Useful only if
192 * defined(CONFIG_NET_ETHERNET_BRIDGE).
193 */
194
195 union {
196 /* IPv6 hop limit or IPv4 ttl for this network packet.
197 * The value is shared between IPv6 and IPv4.
198 */
199 uint8_t ipv6_hop_limit;
200 uint8_t ipv4_ttl;
201 };
202
203 union {
204#if defined(CONFIG_NET_IPV4)
205 uint8_t ipv4_opts_len; /* Length if IPv4 Header Options */
206#endif
207#if defined(CONFIG_NET_IPV6)
208 uint16_t ipv6_ext_len; /* length of extension headers */
209#endif
210 };
211
215 uint8_t priority;
216
217#if defined(CONFIG_NET_VLAN)
218 /* VLAN TCI (Tag Control Information). This contains the Priority
219 * Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
220 * Identifier (VID, called more commonly VLAN tag). This value is
221 * kept in host byte order.
222 */
223 uint16_t vlan_tci;
224#endif /* CONFIG_NET_VLAN */
225
226#if defined(CONFIG_NET_IPV6)
227 /* Where is the start of the last header before payload data
228 * in IPv6 packet. This is offset value from start of the IPv6
229 * packet. Note that this value should be updated by who ever
230 * adds IPv6 extension headers to the network packet.
231 */
232 uint16_t ipv6_prev_hdr_start;
233
234#if defined(CONFIG_NET_IPV6_FRAGMENT)
235 uint16_t ipv6_fragment_flags; /* Fragment offset and M (More Fragment) flag */
236 uint32_t ipv6_fragment_id; /* Fragment id */
237 uint16_t ipv6_frag_hdr_start; /* Where starts the fragment header */
238#endif /* CONFIG_NET_IPV6_FRAGMENT */
239
240 uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
241 uint8_t ipv6_next_hdr; /* What is the very first next header */
242#endif /* CONFIG_NET_IPV6 */
243
244#if defined(CONFIG_IEEE802154)
245 uint8_t ieee802154_rssi; /* Received Signal Strength Indication */
246 uint8_t ieee802154_lqi; /* Link Quality Indicator */
247 uint8_t ieee802154_arb : 1; /* ACK Request Bit is set in the frame */
248 uint8_t ieee802154_ack_fpb : 1; /* Frame Pending Bit was set in the ACK */
249 uint8_t ieee802154_frame_secured : 1; /* Frame is authenticated and
250 * encrypted according to its
251 * Auxiliary Security Header
252 */
253 uint8_t ieee802154_mac_hdr_rdy : 1; /* Indicates if frame's MAC header
254 * is ready to be transmitted or if
255 * it requires further modifications,
256 * e.g. Frame Counter injection.
257 */
258#if defined(CONFIG_IEEE802154_2015)
259 uint8_t ieee802154_fv2015 : 1; /* Frame version is IEEE 802.15.4-2015 */
260 uint8_t ieee802154_ack_seb : 1; /* Security Enabled Bit was set in the ACK */
261 uint32_t ieee802154_ack_fc; /* Frame counter set in the ACK */
262 uint8_t ieee802154_ack_keyid; /* Key index set in the ACK */
263#endif
264#endif
265#if defined(CONFIG_NET_L2_CANBUS)
266 union {
267 struct canbus_isotp_tx_ctx *canbus_tx_ctx;
268 struct canbus_isotp_rx_ctx *canbus_rx_ctx;
269 };
270#endif
271 /* @endcond */
272};
273
276/* The interface real ll address */
277static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
278{
279 return net_if_get_link_addr(pkt->iface);
280}
281
282static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
283{
284 return pkt->context;
285}
286
287static inline void net_pkt_set_context(struct net_pkt *pkt,
288 struct net_context *ctx)
289{
290 pkt->context = ctx;
291}
292
293static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
294{
295 return pkt->iface;
296}
297
298static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
299{
300 pkt->iface = iface;
301
302 /* If the network interface is set in pkt, then also set the type of
303 * the network address that is stored in pkt. This is done here so
304 * that the address type is properly set and is not forgotten.
305 */
306 if (iface) {
307 pkt->lladdr_src.type = net_if_get_link_addr(iface)->type;
308 pkt->lladdr_dst.type = net_if_get_link_addr(iface)->type;
309 }
310}
311
312static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
313{
314#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
315 return pkt->orig_iface;
316#else
317 return pkt->iface;
318#endif
319}
320
321static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
322 struct net_if *iface)
323{
324#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
325 pkt->orig_iface = iface;
326#endif
327}
328
329static inline uint8_t net_pkt_family(struct net_pkt *pkt)
330{
331 return pkt->family;
332}
333
334static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
335{
336 pkt->family = family;
337}
338
339static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
340{
341 return !!(pkt->ptp_pkt);
342}
343
344static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
345{
346 pkt->ptp_pkt = is_ptp;
347}
348
349static inline bool net_pkt_is_captured(struct net_pkt *pkt)
350{
351 return !!(pkt->captured);
352}
353
354static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
355{
356 pkt->captured = is_captured;
357}
358
359static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
360{
361 return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
362}
363
364static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
365{
366 if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
367 pkt->l2_bridged = is_l2_bridged;
368 }
369}
370
371static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
372{
373 return pkt->ip_hdr_len;
374}
375
376static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
377{
378 pkt->ip_hdr_len = len;
379}
380
381static inline uint8_t net_pkt_sent(struct net_pkt *pkt)
382{
383 return pkt->sent_or_eof;
384}
385
386static inline void net_pkt_set_sent(struct net_pkt *pkt, bool sent)
387{
388 pkt->sent_or_eof = sent;
389}
390
391static inline uint8_t net_pkt_queued(struct net_pkt *pkt)
392{
393 return pkt->pkt_queued;
394}
395
396static inline void net_pkt_set_queued(struct net_pkt *pkt, bool send)
397{
398 pkt->pkt_queued = send;
399}
400
401static inline uint8_t net_pkt_tcp_1st_msg(struct net_pkt *pkt)
402{
403#if defined(CONFIG_NET_TCP)
404 return pkt->tcp_first_msg;
405#else
406 return true;
407#endif
408}
409
410static inline void net_pkt_set_tcp_1st_msg(struct net_pkt *pkt, bool is_1st)
411{
412#if defined(CONFIG_NET_TCP)
413 pkt->tcp_first_msg = is_1st;
414#else
415 ARG_UNUSED(pkt);
416 ARG_UNUSED(is_1st);
417#endif
418}
419
420#if defined(CONFIG_NET_SOCKETS)
421static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
422{
423 return pkt->sent_or_eof;
424}
425
426static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
427{
428 pkt->sent_or_eof = eof;
429}
430#endif
431
432#if defined(CONFIG_NET_ROUTE)
433static inline bool net_pkt_forwarding(struct net_pkt *pkt)
434{
435 return pkt->forwarding;
436}
437
438static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
439{
440 pkt->forwarding = forward;
441}
442#else
443static inline bool net_pkt_forwarding(struct net_pkt *pkt)
444{
445 return false;
446}
447#endif
448
449#if defined(CONFIG_NET_IPV4)
450static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
451{
452 return pkt->ipv4_ttl;
453}
454
455static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
456 uint8_t ttl)
457{
458 pkt->ipv4_ttl = ttl;
459}
460
461static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
462{
463 return pkt->ipv4_opts_len;
464}
465
466static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
467 uint8_t opts_len)
468{
469 pkt->ipv4_opts_len = opts_len;
470}
471#else
472static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
473{
474 ARG_UNUSED(pkt);
475
476 return 0;
477}
478
479static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
480 uint8_t ttl)
481{
482 ARG_UNUSED(pkt);
483 ARG_UNUSED(ttl);
484}
485
486static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
487{
488 ARG_UNUSED(pkt);
489 return 0;
490}
491
492static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
493 uint8_t opts_len)
494{
495 ARG_UNUSED(pkt);
496 ARG_UNUSED(opts_len);
497}
498#endif
499
500#if defined(CONFIG_NET_IPV6)
501static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
502{
503 return pkt->ipv6_ext_opt_len;
504}
505
506static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
507 uint8_t len)
508{
509 pkt->ipv6_ext_opt_len = len;
510}
511
512static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
513{
514 return pkt->ipv6_next_hdr;
515}
516
517static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
518 uint8_t next_hdr)
519{
520 pkt->ipv6_next_hdr = next_hdr;
521}
522
523static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
524{
525 return pkt->ipv6_ext_len;
526}
527
528static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
529{
530 pkt->ipv6_ext_len = len;
531}
532
533static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
534{
535 return pkt->ipv6_prev_hdr_start;
536}
537
538static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
539 uint16_t offset)
540{
541 pkt->ipv6_prev_hdr_start = offset;
542}
543
544static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
545{
546 return pkt->ipv6_hop_limit;
547}
548
549static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
550 uint8_t hop_limit)
551{
552 pkt->ipv6_hop_limit = hop_limit;
553}
554#else /* CONFIG_NET_IPV6 */
555static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
556{
557 ARG_UNUSED(pkt);
558
559 return 0;
560}
561
562static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
563 uint8_t len)
564{
565 ARG_UNUSED(pkt);
566 ARG_UNUSED(len);
567}
568
569static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
570{
571 ARG_UNUSED(pkt);
572
573 return 0;
574}
575
576static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
577 uint8_t next_hdr)
578{
579 ARG_UNUSED(pkt);
580 ARG_UNUSED(next_hdr);
581}
582
583static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
584{
585 ARG_UNUSED(pkt);
586
587 return 0;
588}
589
590static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
591{
592 ARG_UNUSED(pkt);
593 ARG_UNUSED(len);
594}
595
596static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
597{
598 ARG_UNUSED(pkt);
599
600 return 0;
601}
602
603static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
604 uint16_t offset)
605{
606 ARG_UNUSED(pkt);
607 ARG_UNUSED(offset);
608}
609
610static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
611{
612 ARG_UNUSED(pkt);
613
614 return 0;
615}
616
617static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
618 uint8_t hop_limit)
619{
620 ARG_UNUSED(pkt);
621 ARG_UNUSED(hop_limit);
622}
623#endif /* CONFIG_NET_IPV6 */
624
625static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
626{
627#if defined(CONFIG_NET_IPV6)
628 return pkt->ipv6_ext_len;
629#elif defined(CONFIG_NET_IPV4)
630 return pkt->ipv4_opts_len;
631#else
632 ARG_UNUSED(pkt);
633
634 return 0;
635#endif
636}
637
638#if defined(CONFIG_NET_IPV6_FRAGMENT)
639static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
640{
641 return pkt->ipv6_frag_hdr_start;
642}
643
644static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
645 uint16_t start)
646{
647 pkt->ipv6_frag_hdr_start = start;
648}
649
650static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
651{
652 return pkt->ipv6_fragment_flags & NET_IPV6_FRAGH_OFFSET_MASK;
653}
654static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
655{
656 return (pkt->ipv6_fragment_flags & 0x01) != 0;
657}
658
659static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
661{
662 pkt->ipv6_fragment_flags = flags;
663}
664
665static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
666{
667 return pkt->ipv6_fragment_id;
668}
669
670static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
671 uint32_t id)
672{
673 pkt->ipv6_fragment_id = id;
674}
675#else /* CONFIG_NET_IPV6_FRAGMENT */
676static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
677{
678 ARG_UNUSED(pkt);
679
680 return 0;
681}
682
683static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
684 uint16_t start)
685{
686 ARG_UNUSED(pkt);
687 ARG_UNUSED(start);
688}
689
690static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
691{
692 ARG_UNUSED(pkt);
693
694 return 0;
695}
696
697static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
698{
699 ARG_UNUSED(pkt);
700
701 return 0;
702}
703
704static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
706{
707 ARG_UNUSED(pkt);
708 ARG_UNUSED(flags);
709}
710
711static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
712{
713 ARG_UNUSED(pkt);
714
715 return 0;
716}
717
718static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
719 uint32_t id)
720{
721 ARG_UNUSED(pkt);
722 ARG_UNUSED(id);
723}
724#endif /* CONFIG_NET_IPV6_FRAGMENT */
725
726static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
727{
728 return pkt->priority;
729}
730
731static inline void net_pkt_set_priority(struct net_pkt *pkt,
732 uint8_t priority)
733{
734 pkt->priority = priority;
735}
736
737#if defined(CONFIG_NET_VLAN)
738static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
739{
740 return net_eth_vlan_get_vid(pkt->vlan_tci);
741}
742
743static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
744{
745 pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
746}
747
748static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
749{
750 return net_eth_vlan_get_pcp(pkt->vlan_tci);
751}
752
753static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
754 uint8_t priority)
755{
756 pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
757}
758
759static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
760{
761 return net_eth_vlan_get_dei(pkt->vlan_tci);
762}
763
764static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
765{
766 pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
767}
768
769static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
770{
771 pkt->vlan_tci = tci;
772}
773
774static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
775{
776 return pkt->vlan_tci;
777}
778#else
779static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
780{
781 return NET_VLAN_TAG_UNSPEC;
782}
783
784static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
785{
786 ARG_UNUSED(pkt);
787 ARG_UNUSED(tag);
788}
789
790static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
791{
792 ARG_UNUSED(pkt);
793 return 0;
794}
795
796static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
797{
798 return false;
799}
800
801static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
802{
803 ARG_UNUSED(pkt);
804 ARG_UNUSED(dei);
805}
806
807static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
808{
809 return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
810}
811
812static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
813{
814 ARG_UNUSED(pkt);
815 ARG_UNUSED(tci);
816}
817#endif
818
819#if defined(CONFIG_NET_PKT_TIMESTAMP)
820static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
821{
822 return &pkt->timestamp;
823}
824
825static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
826 struct net_ptp_time *timestamp)
827{
828 pkt->timestamp.second = timestamp->second;
829 pkt->timestamp.nanosecond = timestamp->nanosecond;
830}
831#else
832static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
833{
834 ARG_UNUSED(pkt);
835
836 return NULL;
837}
838
839static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
840 struct net_ptp_time *timestamp)
841{
842 ARG_UNUSED(pkt);
843 ARG_UNUSED(timestamp);
844}
845#endif /* CONFIG_NET_PKT_TIMESTAMP */
846
847#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
848static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
849{
850 return pkt->create_time;
851}
852
853static inline void net_pkt_set_create_time(struct net_pkt *pkt,
854 uint32_t create_time)
855{
856 pkt->create_time = create_time;
857}
858#else
859static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
860{
861 ARG_UNUSED(pkt);
862
863 return 0U;
864}
865
866static inline void net_pkt_set_create_time(struct net_pkt *pkt,
867 uint32_t create_time)
868{
869 ARG_UNUSED(pkt);
870 ARG_UNUSED(create_time);
871}
872#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
873
874#if defined(CONFIG_NET_PKT_TXTIME)
875static inline uint64_t net_pkt_txtime(struct net_pkt *pkt)
876{
877 return pkt->txtime;
878}
879
880static inline void net_pkt_set_txtime(struct net_pkt *pkt, uint64_t txtime)
881{
882 pkt->txtime = txtime;
883}
884#else
885static inline uint64_t net_pkt_txtime(struct net_pkt *pkt)
886{
887 ARG_UNUSED(pkt);
888
889 return 0;
890}
891
892static inline void net_pkt_set_txtime(struct net_pkt *pkt, uint64_t txtime)
893{
894 ARG_UNUSED(pkt);
895 ARG_UNUSED(txtime);
896}
897#endif /* CONFIG_NET_PKT_TXTIME */
898
899#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
900 defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
901static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
902{
903 return pkt->detail.stat;
904}
905
906static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
907{
908 return pkt->detail.count;
909}
910
911static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
912{
913 memset(&pkt->detail, 0, sizeof(pkt->detail));
914}
915
916static ALWAYS_INLINE void net_pkt_set_stats_tick(struct net_pkt *pkt,
917 uint32_t tick)
918{
919 if (pkt->detail.count >= NET_PKT_DETAIL_STATS_COUNT) {
920 NET_ERR("Detail stats count overflow (%d >= %d)",
921 pkt->detail.count, NET_PKT_DETAIL_STATS_COUNT);
922 return;
923 }
924
925 pkt->detail.stat[pkt->detail.count++] = tick;
926}
927
928#define net_pkt_set_tx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
929#define net_pkt_set_rx_stats_tick(pkt, tick) net_pkt_set_stats_tick(pkt, tick)
930#else
931static inline uint32_t *net_pkt_stats_tick(struct net_pkt *pkt)
932{
933 ARG_UNUSED(pkt);
934
935 return NULL;
936}
937
938static inline int net_pkt_stats_tick_count(struct net_pkt *pkt)
939{
940 ARG_UNUSED(pkt);
941
942 return 0;
943}
944
945static inline void net_pkt_stats_tick_reset(struct net_pkt *pkt)
946{
947 ARG_UNUSED(pkt);
948}
949
950static inline void net_pkt_set_stats_tick(struct net_pkt *pkt, uint32_t tick)
951{
952 ARG_UNUSED(pkt);
953 ARG_UNUSED(tick);
954}
955
956#define net_pkt_set_tx_stats_tick(pkt, tick)
957#define net_pkt_set_rx_stats_tick(pkt, tick)
958#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
959 CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
960
961static inline size_t net_pkt_get_len(struct net_pkt *pkt)
962{
963 return net_buf_frags_len(pkt->frags);
964}
965
966static inline uint8_t *net_pkt_data(struct net_pkt *pkt)
967{
968 return pkt->frags->data;
969}
970
971static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
972{
973 return pkt->frags->data;
974}
975
976static inline bool net_pkt_is_empty(struct net_pkt *pkt)
977{
978 return !pkt->buffer || !net_pkt_data(pkt) || pkt->buffer->len == 0;
979}
980
981static inline struct net_linkaddr *net_pkt_lladdr_src(struct net_pkt *pkt)
982{
983 return &pkt->lladdr_src;
984}
985
986static inline struct net_linkaddr *net_pkt_lladdr_dst(struct net_pkt *pkt)
987{
988 return &pkt->lladdr_dst;
989}
990
991static inline void net_pkt_lladdr_swap(struct net_pkt *pkt)
992{
993 uint8_t *addr = net_pkt_lladdr_src(pkt)->addr;
994
995 net_pkt_lladdr_src(pkt)->addr = net_pkt_lladdr_dst(pkt)->addr;
996 net_pkt_lladdr_dst(pkt)->addr = addr;
997}
998
999static inline void net_pkt_lladdr_clear(struct net_pkt *pkt)
1000{
1001 net_pkt_lladdr_src(pkt)->addr = NULL;
1002 net_pkt_lladdr_src(pkt)->len = 0U;
1003}
1004
1005#if defined(CONFIG_IEEE802154) || defined(CONFIG_IEEE802154_RAW_MODE)
1006static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
1007{
1008 return pkt->ieee802154_rssi;
1009}
1010
1011static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt,
1012 uint8_t rssi)
1013{
1014 pkt->ieee802154_rssi = rssi;
1015}
1016
1017static inline uint8_t net_pkt_ieee802154_lqi(struct net_pkt *pkt)
1018{
1019 return pkt->ieee802154_lqi;
1020}
1021
1022static inline void net_pkt_set_ieee802154_lqi(struct net_pkt *pkt,
1023 uint8_t lqi)
1024{
1025 pkt->ieee802154_lqi = lqi;
1026}
1027
1028static inline bool net_pkt_ieee802154_arb(struct net_pkt *pkt)
1029{
1030 return pkt->ieee802154_arb;
1031}
1032
1033static inline void net_pkt_set_ieee802154_arb(struct net_pkt *pkt, bool arb)
1034{
1035 pkt->ieee802154_arb = arb;
1036}
1037
1038static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt)
1039{
1040 return pkt->ieee802154_ack_fpb;
1041}
1042
1043static inline void net_pkt_set_ieee802154_ack_fpb(struct net_pkt *pkt,
1044 bool fpb)
1045{
1046 pkt->ieee802154_ack_fpb = fpb;
1047}
1048
1049static inline bool net_pkt_ieee802154_frame_secured(struct net_pkt *pkt)
1050{
1051 return pkt->ieee802154_frame_secured;
1052}
1053
1054static inline void net_pkt_set_ieee802154_frame_secured(struct net_pkt *pkt,
1055 bool secured)
1056{
1057 pkt->ieee802154_frame_secured = secured;
1058}
1059
1060static inline bool net_pkt_ieee802154_mac_hdr_rdy(struct net_pkt *pkt)
1061{
1062 return pkt->ieee802154_mac_hdr_rdy;
1063}
1064
1065static inline void net_pkt_set_ieee802154_mac_hdr_rdy(struct net_pkt *pkt,
1066 bool rdy)
1067{
1068 pkt->ieee802154_mac_hdr_rdy = rdy;
1069}
1070
1071#if defined(CONFIG_IEEE802154_2015)
1072static inline bool net_pkt_ieee802154_fv2015(struct net_pkt *pkt)
1073{
1074 return pkt->ieee802154_fv2015;
1075}
1076
1077static inline void net_pkt_set_ieee802154_fv2015(struct net_pkt *pkt, bool fv2015)
1078{
1079 pkt->ieee802154_fv2015 = fv2015;
1080}
1081
1082static inline bool net_pkt_ieee802154_ack_seb(struct net_pkt *pkt)
1083{
1084 return pkt->ieee802154_ack_seb;
1085}
1086
1087static inline void net_pkt_set_ieee802154_ack_seb(struct net_pkt *pkt, bool seb)
1088{
1089 pkt->ieee802154_ack_seb = seb;
1090}
1091
1092static inline uint32_t net_pkt_ieee802154_ack_fc(struct net_pkt *pkt)
1093{
1094 return pkt->ieee802154_ack_fc;
1095}
1096
1097static inline void net_pkt_set_ieee802154_ack_fc(struct net_pkt *pkt,
1098 uint32_t fc)
1099{
1100 pkt->ieee802154_ack_fc = fc;
1101}
1102
1103static inline uint8_t net_pkt_ieee802154_ack_keyid(struct net_pkt *pkt)
1104{
1105 return pkt->ieee802154_ack_keyid;
1106}
1107
1108static inline void net_pkt_set_ieee802154_ack_keyid(struct net_pkt *pkt,
1109 uint8_t keyid)
1110{
1111 pkt->ieee802154_ack_keyid = keyid;
1112}
1113#endif /* CONFIG_IEEE802154_2015 */
1114#endif /* CONFIG_IEEE802154 || CONFIG_IEEE802154_RAW_MODE */
1115
1116#if defined(CONFIG_NET_IPV4_AUTO)
1117static inline bool net_pkt_ipv4_auto(struct net_pkt *pkt)
1118{
1119 return pkt->ipv4_auto_arp_msg;
1120}
1121
1122static inline void net_pkt_set_ipv4_auto(struct net_pkt *pkt,
1123 bool is_auto_arp_msg)
1124{
1125 pkt->ipv4_auto_arp_msg = is_auto_arp_msg;
1126}
1127#else /* CONFIG_NET_IPV4_AUTO */
1128static inline bool net_pkt_ipv4_auto(struct net_pkt *pkt)
1129{
1130 ARG_UNUSED(pkt);
1131
1132 return false;
1133}
1134
1135static inline void net_pkt_set_ipv4_auto(struct net_pkt *pkt,
1136 bool is_auto_arp_msg)
1137{
1138 ARG_UNUSED(pkt);
1139 ARG_UNUSED(is_auto_arp_msg);
1140}
1141#endif /* CONFIG_NET_IPV4_AUTO */
1142
1143#if defined(CONFIG_NET_LLDP)
1144static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1145{
1146 return pkt->lldp_pkt;
1147}
1148
1149static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1150{
1151 pkt->lldp_pkt = is_lldp;
1152}
1153#else
1154static inline bool net_pkt_is_lldp(struct net_pkt *pkt)
1155{
1156 ARG_UNUSED(pkt);
1157
1158 return false;
1159}
1160
1161static inline void net_pkt_set_lldp(struct net_pkt *pkt, bool is_lldp)
1162{
1163 ARG_UNUSED(pkt);
1164 ARG_UNUSED(is_lldp);
1165}
1166#endif /* CONFIG_NET_LLDP */
1167
1168#if defined(CONFIG_NET_PPP)
1169static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1170{
1171 return pkt->ppp_msg;
1172}
1173
1174static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1175 bool is_ppp_msg)
1176{
1177 pkt->ppp_msg = is_ppp_msg;
1178}
1179#else /* CONFIG_NET_PPP */
1180static inline bool net_pkt_is_ppp(struct net_pkt *pkt)
1181{
1182 ARG_UNUSED(pkt);
1183
1184 return false;
1185}
1186
1187static inline void net_pkt_set_ppp(struct net_pkt *pkt,
1188 bool is_ppp_msg)
1189{
1190 ARG_UNUSED(pkt);
1191 ARG_UNUSED(is_ppp_msg);
1192}
1193#endif /* CONFIG_NET_PPP */
1194
1195#define NET_IPV6_HDR(pkt) ((struct net_ipv6_hdr *)net_pkt_ip_data(pkt))
1196#define NET_IPV4_HDR(pkt) ((struct net_ipv4_hdr *)net_pkt_ip_data(pkt))
1197
1198static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
1199{
1201 net_pkt_context(pkt)),
1202 (struct in6_addr *)NET_IPV6_HDR(pkt)->src);
1203}
1204
1205static inline void net_pkt_set_overwrite(struct net_pkt *pkt, bool overwrite)
1206{
1207 pkt->overwrite = overwrite;
1208}
1209
1210static inline bool net_pkt_is_being_overwritten(struct net_pkt *pkt)
1211{
1212 return pkt->overwrite;
1213}
1214
1215#ifdef CONFIG_NET_PKT_FILTER
1216
1217bool net_pkt_filter_send_ok(struct net_pkt *pkt);
1218bool net_pkt_filter_recv_ok(struct net_pkt *pkt);
1219
1220#else
1221
1222static inline bool net_pkt_filter_send_ok(struct net_pkt *pkt)
1223{
1224 ARG_UNUSED(pkt);
1225
1226 return true;
1227}
1228
1229static inline bool net_pkt_filter_recv_ok(struct net_pkt *pkt)
1230{
1231 ARG_UNUSED(pkt);
1232
1233 return true;
1234}
1235
1236#endif /* CONFIG_NET_PKT_FILTER */
1237
1238/* @endcond */
1239
1253#define NET_PKT_SLAB_DEFINE(name, count) \
1254 K_MEM_SLAB_DEFINE(name, sizeof(struct net_pkt), count, 4)
1255
1256/* Backward compatibility macro */
1257#define NET_PKT_TX_SLAB_DEFINE(name, count) NET_PKT_SLAB_DEFINE(name, count)
1258
1272#define NET_PKT_DATA_POOL_DEFINE(name, count) \
1273 NET_BUF_POOL_DEFINE(name, count, CONFIG_NET_BUF_DATA_SIZE, \
1274 0, NULL)
1275
1278#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC) || \
1279 (CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG)
1280#define NET_PKT_DEBUG_ENABLED
1281#endif
1282
1283#if defined(NET_PKT_DEBUG_ENABLED)
1284
1285/* Debug versions of the net_pkt functions that are used when tracking
1286 * buffer usage.
1287 */
1288
1289struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
1291 const char *caller,
1292 int line);
1293
1294#define net_pkt_get_reserve_data(pool, timeout) \
1295 net_pkt_get_reserve_data_debug(pool, timeout, __func__, __LINE__)
1296
1297struct net_buf *net_pkt_get_reserve_rx_data_debug(k_timeout_t timeout,
1298 const char *caller,
1299 int line);
1300#define net_pkt_get_reserve_rx_data(timeout) \
1301 net_pkt_get_reserve_rx_data_debug(timeout, __func__, __LINE__)
1302
1303struct net_buf *net_pkt_get_reserve_tx_data_debug(k_timeout_t timeout,
1304 const char *caller,
1305 int line);
1306#define net_pkt_get_reserve_tx_data(timeout) \
1307 net_pkt_get_reserve_tx_data_debug(timeout, __func__, __LINE__)
1308
1309struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt,
1311 const char *caller, int line);
1312#define net_pkt_get_frag(pkt, timeout) \
1313 net_pkt_get_frag_debug(pkt, timeout, __func__, __LINE__)
1314
1315void net_pkt_unref_debug(struct net_pkt *pkt, const char *caller, int line);
1316#define net_pkt_unref(pkt) net_pkt_unref_debug(pkt, __func__, __LINE__)
1317
1318struct net_pkt *net_pkt_ref_debug(struct net_pkt *pkt, const char *caller,
1319 int line);
1320#define net_pkt_ref(pkt) net_pkt_ref_debug(pkt, __func__, __LINE__)
1321
1322struct net_buf *net_pkt_frag_ref_debug(struct net_buf *frag,
1323 const char *caller, int line);
1324#define net_pkt_frag_ref(frag) net_pkt_frag_ref_debug(frag, __func__, __LINE__)
1325
1326void net_pkt_frag_unref_debug(struct net_buf *frag,
1327 const char *caller, int line);
1328#define net_pkt_frag_unref(frag) \
1329 net_pkt_frag_unref_debug(frag, __func__, __LINE__)
1330
1331struct net_buf *net_pkt_frag_del_debug(struct net_pkt *pkt,
1332 struct net_buf *parent,
1333 struct net_buf *frag,
1334 const char *caller, int line);
1335#define net_pkt_frag_del(pkt, parent, frag) \
1336 net_pkt_frag_del_debug(pkt, parent, frag, __func__, __LINE__)
1337
1338void net_pkt_frag_add_debug(struct net_pkt *pkt, struct net_buf *frag,
1339 const char *caller, int line);
1340#define net_pkt_frag_add(pkt, frag) \
1341 net_pkt_frag_add_debug(pkt, frag, __func__, __LINE__)
1342
1343void net_pkt_frag_insert_debug(struct net_pkt *pkt, struct net_buf *frag,
1344 const char *caller, int line);
1345#define net_pkt_frag_insert(pkt, frag) \
1346 net_pkt_frag_insert_debug(pkt, frag, __func__, __LINE__)
1347#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC ||
1348 * CONFIG_NET_PKT_LOG_LEVEL >= LOG_LEVEL_DBG
1349 */
1359#if defined(NET_PKT_DEBUG_ENABLED)
1360void net_pkt_print_frags(struct net_pkt *pkt);
1361#else
1362#define net_pkt_print_frags(pkt)
1363#endif
1364
1378#if !defined(NET_PKT_DEBUG_ENABLED)
1380#endif
1381
1395#if !defined(NET_PKT_DEBUG_ENABLED)
1397#endif
1398
1410#if !defined(NET_PKT_DEBUG_ENABLED)
1412#endif
1413
1423#if !defined(NET_PKT_DEBUG_ENABLED)
1424void net_pkt_unref(struct net_pkt *pkt);
1425#endif
1426
1436#if !defined(NET_PKT_DEBUG_ENABLED)
1437struct net_pkt *net_pkt_ref(struct net_pkt *pkt);
1438#endif
1439
1449#if !defined(NET_PKT_DEBUG_ENABLED)
1450struct net_buf *net_pkt_frag_ref(struct net_buf *frag);
1451#endif
1452
1458#if !defined(NET_PKT_DEBUG_ENABLED)
1459void net_pkt_frag_unref(struct net_buf *frag);
1460#endif
1461
1472#if !defined(NET_PKT_DEBUG_ENABLED)
1474 struct net_buf *parent,
1475 struct net_buf *frag);
1476#endif
1477
1484#if !defined(NET_PKT_DEBUG_ENABLED)
1485void net_pkt_frag_add(struct net_pkt *pkt, struct net_buf *frag);
1486#endif
1487
1494#if !defined(NET_PKT_DEBUG_ENABLED)
1495void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
1496#endif
1497
1506bool net_pkt_compact(struct net_pkt *pkt);
1507
1516void net_pkt_get_info(struct k_mem_slab **rx,
1517 struct k_mem_slab **tx,
1518 struct net_buf_pool **rx_data,
1519 struct net_buf_pool **tx_data);
1520
1523#if defined(CONFIG_NET_DEBUG_NET_PKT_ALLOC)
1527void net_pkt_print(void);
1528
1529typedef void (*net_pkt_allocs_cb_t)(struct net_pkt *pkt,
1530 struct net_buf *buf,
1531 const char *func_alloc,
1532 int line_alloc,
1533 const char *func_free,
1534 int line_free,
1535 bool in_use,
1536 void *user_data);
1537
1538void net_pkt_allocs_foreach(net_pkt_allocs_cb_t cb, void *user_data);
1539
1540const char *net_pkt_slab2str(struct k_mem_slab *slab);
1541const char *net_pkt_pool2str(struct net_buf_pool *pool);
1542
1543#else
1544#define net_pkt_print(...)
1545#endif /* CONFIG_NET_DEBUG_NET_PKT_ALLOC */
1546
1547/* New allocator, and API are defined below.
1548 * This will be simpler when time will come to get rid of former API above.
1549 */
1550#if defined(NET_PKT_DEBUG_ENABLED)
1551
1552struct net_pkt *net_pkt_alloc_debug(k_timeout_t timeout,
1553 const char *caller, int line);
1554#define net_pkt_alloc(_timeout) \
1555 net_pkt_alloc_debug(_timeout, __func__, __LINE__)
1556
1557struct net_pkt *net_pkt_alloc_from_slab_debug(struct k_mem_slab *slab,
1559 const char *caller, int line);
1560#define net_pkt_alloc_from_slab(_slab, _timeout) \
1561 net_pkt_alloc_from_slab_debug(_slab, _timeout, __func__, __LINE__)
1562
1563struct net_pkt *net_pkt_rx_alloc_debug(k_timeout_t timeout,
1564 const char *caller, int line);
1565#define net_pkt_rx_alloc(_timeout) \
1566 net_pkt_rx_alloc_debug(_timeout, __func__, __LINE__)
1567
1568struct net_pkt *net_pkt_alloc_on_iface_debug(struct net_if *iface,
1570 const char *caller,
1571 int line);
1572#define net_pkt_alloc_on_iface(_iface, _timeout) \
1573 net_pkt_alloc_on_iface_debug(_iface, _timeout, __func__, __LINE__)
1574
1575struct net_pkt *net_pkt_rx_alloc_on_iface_debug(struct net_if *iface,
1577 const char *caller,
1578 int line);
1579#define net_pkt_rx_alloc_on_iface(_iface, _timeout) \
1580 net_pkt_rx_alloc_on_iface_debug(_iface, _timeout, \
1581 __func__, __LINE__)
1582
1583int net_pkt_alloc_buffer_debug(struct net_pkt *pkt,
1584 size_t size,
1585 enum net_ip_protocol proto,
1587 const char *caller, int line);
1588#define net_pkt_alloc_buffer(_pkt, _size, _proto, _timeout) \
1589 net_pkt_alloc_buffer_debug(_pkt, _size, _proto, _timeout, \
1590 __func__, __LINE__)
1591
1592struct net_pkt *net_pkt_alloc_with_buffer_debug(struct net_if *iface,
1593 size_t size,
1594 sa_family_t family,
1595 enum net_ip_protocol proto,
1597 const char *caller,
1598 int line);
1599#define net_pkt_alloc_with_buffer(_iface, _size, _family, \
1600 _proto, _timeout) \
1601 net_pkt_alloc_with_buffer_debug(_iface, _size, _family, \
1602 _proto, _timeout, \
1603 __func__, __LINE__)
1604
1605struct net_pkt *net_pkt_rx_alloc_with_buffer_debug(struct net_if *iface,
1606 size_t size,
1607 sa_family_t family,
1608 enum net_ip_protocol proto,
1610 const char *caller,
1611 int line);
1612#define net_pkt_rx_alloc_with_buffer(_iface, _size, _family, \
1613 _proto, _timeout) \
1614 net_pkt_rx_alloc_with_buffer_debug(_iface, _size, _family, \
1615 _proto, _timeout, \
1616 __func__, __LINE__)
1617#endif /* NET_PKT_DEBUG_ENABLED */
1630#if !defined(NET_PKT_DEBUG_ENABLED)
1632#endif
1633
1648#if !defined(NET_PKT_DEBUG_ENABLED)
1649struct net_pkt *net_pkt_alloc_from_slab(struct k_mem_slab *slab,
1651#endif
1652
1663#if !defined(NET_PKT_DEBUG_ENABLED)
1665#endif
1666
1675#if !defined(NET_PKT_DEBUG_ENABLED)
1678
1679/* Same as above but specifically for RX packet */
1682#endif
1683
1699#if !defined(NET_PKT_DEBUG_ENABLED)
1701 size_t size,
1702 enum net_ip_protocol proto,
1704#endif
1705
1717#if !defined(NET_PKT_DEBUG_ENABLED)
1719 size_t size,
1720 sa_family_t family,
1721 enum net_ip_protocol proto,
1723
1724/* Same as above but specifically for RX packet */
1726 size_t size,
1727 sa_family_t family,
1728 enum net_ip_protocol proto,
1730#endif
1731
1738void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer);
1739
1751
1768 enum net_ip_protocol proto);
1769
1779
1794int net_pkt_remove_tail(struct net_pkt *pkt, size_t length);
1795
1804
1811static inline void net_pkt_cursor_backup(struct net_pkt *pkt,
1812 struct net_pkt_cursor *backup)
1813{
1814 backup->buf = pkt->cursor.buf;
1815 backup->pos = pkt->cursor.pos;
1816}
1817
1824static inline void net_pkt_cursor_restore(struct net_pkt *pkt,
1825 struct net_pkt_cursor *backup)
1826{
1827 pkt->cursor.buf = backup->buf;
1828 pkt->cursor.pos = backup->pos;
1829}
1830
1838static inline void *net_pkt_cursor_get_pos(struct net_pkt *pkt)
1839{
1840 return pkt->cursor.pos;
1841}
1842
1863int net_pkt_skip(struct net_pkt *pkt, size_t length);
1864
1879int net_pkt_memset(struct net_pkt *pkt, int byte, size_t length);
1880
1894int net_pkt_copy(struct net_pkt *pkt_dst,
1895 struct net_pkt *pkt_src,
1896 size_t length);
1897
1907
1918
1932int net_pkt_read(struct net_pkt *pkt, void *data, size_t length);
1933
1934/* Read uint8_t data data a net_pkt */
1935static inline int net_pkt_read_u8(struct net_pkt *pkt, uint8_t *data)
1936{
1937 return net_pkt_read(pkt, data, 1);
1938}
1939
1953
1967
1981
1995int net_pkt_write(struct net_pkt *pkt, const void *data, size_t length);
1996
1997/* Write uint8_t data into a net_pkt. */
1998static inline int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
1999{
2000 return net_pkt_write(pkt, &data, sizeof(uint8_t));
2001}
2002
2003/* Write uint16_t big endian data into a net_pkt. */
2004static inline int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
2005{
2006 uint16_t data_be16 = htons(data);
2007
2008 return net_pkt_write(pkt, &data_be16, sizeof(uint16_t));
2009}
2010
2011/* Write uint32_t big endian data into a net_pkt. */
2012static inline int net_pkt_write_be32(struct net_pkt *pkt, uint32_t data)
2013{
2014 uint32_t data_be32 = htonl(data);
2015
2016 return net_pkt_write(pkt, &data_be32, sizeof(uint32_t));
2017}
2018
2019/* Write uint32_t little endian data into a net_pkt. */
2020static inline int net_pkt_write_le32(struct net_pkt *pkt, uint32_t data)
2021{
2022 uint32_t data_le32 = sys_cpu_to_le32(data);
2023
2024 return net_pkt_write(pkt, &data_le32, sizeof(uint32_t));
2025}
2026
2027/* Write uint16_t little endian data into a net_pkt. */
2028static inline int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
2029{
2030 uint16_t data_le16 = sys_cpu_to_le16(data);
2031
2032 return net_pkt_write(pkt, &data_le16, sizeof(uint16_t));
2033}
2034
2043
2056int net_pkt_update_length(struct net_pkt *pkt, size_t length);
2057
2070int net_pkt_pull(struct net_pkt *pkt, size_t length);
2071
2081
2093bool net_pkt_is_contiguous(struct net_pkt *pkt, size_t size);
2094
2104
2106#if !defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2107 void *data;
2108#endif
2109 const size_t size;
2110};
2111
2112#if defined(CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS)
2113#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2114 struct net_pkt_data_access _name = { \
2115 .size = sizeof(_type), \
2116 }
2117
2118#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2119 NET_PKT_DATA_ACCESS_DEFINE(_name, _type)
2120
2121#else
2122#define NET_PKT_DATA_ACCESS_DEFINE(_name, _type) \
2123 _type _hdr_##_name; \
2124 struct net_pkt_data_access _name = { \
2125 .data = &_hdr_##_name, \
2126 .size = sizeof(_type), \
2127 }
2128
2129#define NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(_name, _type) \
2130 struct net_pkt_data_access _name = { \
2131 .data = NULL, \
2132 .size = sizeof(_type), \
2133 }
2134
2135#endif /* CONFIG_NET_HEADERS_ALWAYS_CONTIGUOUS */
2136
2150void *net_pkt_get_data(struct net_pkt *pkt,
2151 struct net_pkt_data_access *access);
2152
2167 struct net_pkt_data_access *access);
2168
2173static inline int net_pkt_acknowledge_data(struct net_pkt *pkt,
2174 struct net_pkt_data_access *access)
2175{
2176 return net_pkt_skip(pkt, access->size);
2177}
2178
2183#ifdef __cplusplus
2184}
2185#endif
2186
2187#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_H_ */
long atomic_t
Definition: atomic.h:22
#define sys_cpu_to_le32(val)
Convert 32-bit integer from host endianness to little-endian.
Definition: byteorder.h:177
#define sys_cpu_to_le16(val)
Convert 16-bit integer from host endianness to little-endian.
Definition: byteorder.h:173
#define ALWAYS_INLINE
Definition: common.h:124
ZTEST_BMEM int timeout
Definition: main.c:31
ZTEST_BMEM int count
Definition: main.c:33
VLAN specific definitions.
unsigned short int sa_family_t
Definition: net_ip.h:164
#define htons(x)
Convert 16-bit value from host to network byte order.
Definition: net_ip.h:120
#define htonl(x)
Convert 32-bit value from host to network byte order.
Definition: net_ip.h:128
net_ip_protocol
Definition: net_ip.h:62
static ZTEST_BMEM char buffer[8]
Test mailbox enhance capabilities.
Definition: test_mbox_api.c:566
static size_t net_buf_frags_len(struct net_buf *buf)
Calculate amount of bytes stored in fragments.
Definition: buf.h:2465
static struct net_if * net_context_get_iface(struct net_context *context)
Get network interface for this context.
Definition: net_context.h:633
static struct net_linkaddr * net_if_get_link_addr(struct net_if *iface)
Get an network interface's link address.
Definition: net_if.h:680
static const struct in6_addr * net_if_ipv6_select_src_addr(struct net_if *iface, const struct in6_addr *dst)
Get a IPv6 source address that should be used when sending network data to destination.
Definition: net_if.h:1428
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)
Definition: net_pkt.h:2012
void net_pkt_cursor_init(struct net_pkt *pkt)
Initialize net_pkt cursor.
int net_pkt_skip(struct net_pkt *pkt, size_t length)
Skip some data from a net_pkt.
struct net_pkt * net_pkt_shallow_clone(struct net_pkt *pkt, k_timeout_t timeout)
Clone pkt and increase the refcount of its buffer.
void net_pkt_append_buffer(struct net_pkt *pkt, struct net_buf *buffer)
Append a buffer in packet.
#define net_pkt_print_frags(pkt)
Print fragment list and the fragment sizes.
Definition: net_pkt.h:1362
int net_pkt_update_length(struct net_pkt *pkt, size_t length)
Update the overall length of a packet.
struct net_buf * net_pkt_get_reserve_rx_data(k_timeout_t timeout)
Get RX DATA buffer from pool. Normally you should use net_pkt_get_frag() instead.
int net_pkt_pull(struct net_pkt *pkt, size_t length)
Remove data from the packet at current location.
int net_pkt_copy(struct net_pkt *pkt_dst, struct net_pkt *pkt_src, size_t length)
Copy data from a packet into another one.
struct net_pkt * net_pkt_rx_alloc(k_timeout_t timeout)
Allocate an initialized net_pkt for RX.
struct net_pkt * net_pkt_ref(struct net_pkt *pkt)
Increase the packet ref count.
int net_pkt_read_be16(struct net_pkt *pkt, uint16_t *data)
Read uint16_t big endian data from a net_pkt.
struct net_pkt * net_pkt_alloc_with_buffer(struct net_if *iface, size_t size, sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout)
Allocate a network packet and buffer at once.
void net_pkt_frag_unref(struct net_buf *frag)
Decrease the packet fragment ref count.
struct net_pkt * net_pkt_rx_alloc_with_buffer(struct net_if *iface, size_t size, sa_family_t family, enum net_ip_protocol proto, k_timeout_t timeout)
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.
bool net_pkt_compact(struct net_pkt *pkt)
Compact the fragment list of a packet.
static int net_pkt_write_be16(struct net_pkt *pkt, uint16_t data)
Definition: net_pkt.h:2004
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.
struct net_buf * net_pkt_frag_del(struct net_pkt *pkt, struct net_buf *parent, struct net_buf *frag)
Delete existing fragment from a packet.
int net_pkt_set_data(struct net_pkt *pkt, struct net_pkt_data_access *access)
Set contiguous data into a network packet.
void * net_pkt_get_data(struct net_pkt *pkt, struct net_pkt_data_access *access)
Get data from a network packet in a contiguous way.
static int net_pkt_write_u8(struct net_pkt *pkt, uint8_t data)
Definition: net_pkt.h:1998
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.
struct net_pkt * net_pkt_rx_alloc_on_iface(struct net_if *iface, k_timeout_t timeout)
int net_pkt_remove_tail(struct net_pkt *pkt, size_t length)
Remove length bytes from tail of packet.
static void * net_pkt_cursor_get_pos(struct net_pkt *pkt)
Returns current position of the cursor.
Definition: net_pkt.h:1838
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:1811
static int net_pkt_acknowledge_data(struct net_pkt *pkt, struct net_pkt_data_access *access)
Definition: net_pkt.h:2173
static int net_pkt_write_le16(struct net_pkt *pkt, uint16_t data)
Definition: net_pkt.h:2028
struct net_buf * net_pkt_get_reserve_tx_data(k_timeout_t timeout)
Get TX DATA buffer from pool. Normally you should use net_pkt_get_frag() instead.
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:1824
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.
struct net_buf * net_pkt_get_frag(struct net_pkt *pkt, k_timeout_t timeout)
Get a data fragment that might be from user specific buffer pool or from global DATA pool.
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)
Definition: net_pkt.h:2020
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)
Definition: net_pkt.h:1935
size_t net_pkt_get_contiguous_len(struct net_pkt *pkt)
#define IS_ENABLED(config_macro)
Check for macro definition in compiler-visible expressions.
Definition: util_macro.h:101
static uint16_t net_eth_vlan_set_vid(uint16_t tci, uint16_t vid)
Set VLAN identifier to TCI.
Definition: ethernet_vlan.h:76
static uint8_t net_eth_vlan_get_dei(uint16_t tci)
Get Drop Eligible Indicator from TCI.
Definition: ethernet_vlan.h:51
#define NET_VLAN_TAG_UNSPEC
Definition: ethernet_vlan.h:30
static uint16_t net_eth_vlan_set_dei(uint16_t tci, bool dei)
Set Drop Eligible Indicator to TCI.
Definition: ethernet_vlan.h:89
static uint16_t net_eth_vlan_get_vid(uint16_t tci)
Get VLAN identifier from TCI.
Definition: ethernet_vlan.h:39
static uint16_t net_eth_vlan_set_pcp(uint16_t tci, uint8_t pcp)
Set Priority Code Point to TCI.
Definition: ethernet_vlan.h:102
static uint8_t net_eth_vlan_get_pcp(uint16_t tci)
Get Priority Code Point from TCI.
Definition: ethernet_vlan.h:63
flags
Definition: http_parser.h:131
Buffer management.
Network context definitions.
Network core definitions.
Public API for network interface.
IPv6 and IPv4 definitions.
Public API for network link address.
static ssize_t send(int sock, const void *buf, size_t len, int flags)
Definition: socket.h:61
Public functions for the Precision Time Protocol time specification.
struct _snode sys_snode_t
Definition: slist.h:33
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__INTPTR_TYPE__ intptr_t
Definition: stdint.h:74
__UINT64_TYPE__ uint64_t
Definition: stdint.h:61
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
void * memset(void *buf, int c, size_t n)
Definition: net_ip.h:139
Kernel timeout type.
Definition: sys_clock.h:65
Network buffer pool representation.
Definition: buf.h:982
Network buffer representation.
Definition: buf.h:915
uint8_t * data
Definition: buf.h:943
uint16_t len
Definition: buf.h:946
Definition: net_context.h:201
Network Interface structure.
Definition: net_if.h:468
Hardware link address structure.
Definition: net_linkaddr.h:69
uint8_t * addr
Definition: net_linkaddr.h:71
uint8_t type
Definition: net_linkaddr.h:77
Definition: net_pkt.h:49
uint8_t * pos
Definition: net_pkt.h:53
struct net_buf * buf
Definition: net_pkt.h:51
Definition: net_pkt.h:2105
const size_t size
Definition: net_pkt.h:2109
void * data
Definition: net_pkt.h:2107
Network packet.
Definition: net_pkt.h:62
struct net_buf * frags
Definition: net_pkt.h:74
struct net_context * context
Definition: net_pkt.h:82
struct net_pkt_cursor cursor
Definition: net_pkt.h:79
struct net_if * iface
Definition: net_pkt.h:85
intptr_t fifo
Definition: net_pkt.h:67
struct net_buf * buffer
Definition: net_pkt.h:75
struct k_mem_slab * slab
Definition: net_pkt.h:70
Precision Time Protocol Timestamp format.
Definition: ptp_time.h:39
uint32_t nanosecond
Definition: ptp_time.h:59
uint64_t second
Definition: ptp_time.h:55
Definition: stat.h:39
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static const char * tag(void)
Definition: main.c:27
static const intptr_t user_data[5]
Definition: main.c:590