-
Notifications
You must be signed in to change notification settings - Fork 578
/
net_pkt.h
2239 lines (1921 loc) · 57.9 KB
/
net_pkt.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file
* @brief Network packet buffer descriptor API
*
* Network data is passed between different parts of the stack via
* net_buf struct.
*/
/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/* Data buffer API - used for all data to/from net */
#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_H_
#define ZEPHYR_INCLUDE_NET_NET_PKT_H_
#include <zephyr/types.h>
#include <stdbool.h>
#include <zephyr/net/buf.h>
#if defined(CONFIG_IEEE802154)
#include <zephyr/net/ieee802154_pkt.h>
#endif
#include <zephyr/net/net_core.h>
#include <zephyr/net/net_linkaddr.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/net/net_if.h>
#include <zephyr/net/net_context.h>
#include <zephyr/net/ethernet_vlan.h>
#include <zephyr/net/ptp_time.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Network packet management library
* @defgroup net_pkt Network Packet Library
* @ingroup networking
* @{
*/
struct net_context;
/* buffer cursor used in net_pkt */
struct net_pkt_cursor {
/** Current net_buf pointer by the cursor */
struct net_buf *buf;
/** Current position in the data buffer of the net_buf */
uint8_t *pos;
};
/**
* @brief Network packet.
*
* Note that if you add new fields into net_pkt, remember to update
* net_pkt_clone() function.
*/
struct net_pkt {
/**
* The fifo is used by RX/TX threads and by socket layer. The net_pkt
* is queued via fifo to the processing thread.
*/
intptr_t fifo;
/** Slab pointer from where it belongs to */
struct k_mem_slab *slab;
/** buffer holding the packet */
union {
struct net_buf *frags;
struct net_buf *buffer;
};
/** Internal buffer iterator used for reading/writing */
struct net_pkt_cursor cursor;
/** Network connection context */
struct net_context *context;
/** Network interface */
struct net_if *iface;
/** @cond ignore */
#if defined(CONFIG_NET_TCP)
/** Allow placing the packet into sys_slist_t */
sys_snode_t next;
#endif
#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
struct net_if *orig_iface; /* Original network interface */
#endif
#if defined(CONFIG_NET_PKT_TIMESTAMP)
/** Timestamp if available. */
struct net_ptp_time timestamp;
#endif
#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
struct {
/** Create time in cycles */
uint32_t create_time;
#if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL) || \
defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
/** Collect extra statistics for net_pkt processing
* from various points in the IP stack. See networking
* documentation where these points are located and how
* to interpret the results.
*/
struct {
uint32_t stat[NET_PKT_DETAIL_STATS_COUNT];
int count;
} detail;
#endif /* CONFIG_NET_PKT_TXTIME_STATS_DETAIL ||
CONFIG_NET_PKT_RXTIME_STATS_DETAIL */
};
#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
#if defined(CONFIG_NET_PKT_TXTIME)
/** Network packet TX time in the future (in nanoseconds) */
uint64_t txtime;
#endif /* CONFIG_NET_PKT_TXTIME */
/** Reference counter */
atomic_t atomic_ref;
/* Filled by layer 2 when network packet is received. */
struct net_linkaddr lladdr_src;
struct net_linkaddr lladdr_dst;
uint16_t ll_proto_type;
#if defined(CONFIG_NET_IP)
uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
#endif
uint8_t overwrite : 1; /* Is packet content being overwritten? */
uint8_t sent_or_eof : 1; /* For outgoing packet: is this sent or not
* For incoming packet of a socket: last
* packet before EOF
* Used only if defined(CONFIG_NET_TCP)
*/
uint8_t pkt_queued : 1; /* For outgoing packet: is this packet
* queued to be sent but has not reached
* the driver yet.
* Used only if defined(CONFIG_NET_TCP)
*/
uint8_t ptp_pkt : 1; /* For outgoing packet: is this packet
* a L2 PTP packet.
* Used only if defined (CONFIG_NET_L2_PTP)
*/
uint8_t forwarding : 1; /* Are we forwarding this pkt
* Used only if defined(CONFIG_NET_ROUTE)
*/
uint8_t family : 3; /* Address family, see net_ip.h */
/* bitfield byte alignment boundary */
#if defined(CONFIG_NET_IPV4_AUTO)
uint8_t ipv4_auto_arp_msg : 1; /* Is this pkt IPv4 autoconf ARP
* message.
* Note: family needs to be
* AF_INET.
*/
#endif
#if defined(CONFIG_NET_LLDP)
uint8_t lldp_pkt : 1; /* Is this pkt an LLDP message.
* Note: family needs to be
* AF_UNSPEC.
*/
#endif
uint8_t ppp_msg : 1; /* This is a PPP message */
#if defined(CONFIG_NET_TCP)
uint8_t tcp_first_msg : 1; /* Is this the first time this pkt is
* sent, or is this a resend of a TCP
* segment.
*/
#endif
uint8_t captured : 1; /* Set to 1 if this packet is already being
* captured
*/
uint8_t l2_bridged : 1; /* set to 1 if this packet comes from a bridge
* and already contains its L2 header to be
* preserved. Useful only if
* defined(CONFIG_NET_ETHERNET_BRIDGE).
*/
uint8_t l2_processed : 1; /* Set to 1 if this packet has already been
* processed by the L2
*/
/* bitfield byte alignment boundary */
#if defined(CONFIG_NET_IP)
union {
/* IPv6 hop limit or IPv4 ttl for this network packet.
* The value is shared between IPv6 and IPv4.
*/
#if defined(CONFIG_NET_IPV6)
uint8_t ipv6_hop_limit;
#endif
#if defined(CONFIG_NET_IPV4)
uint8_t ipv4_ttl;
#endif
};
union {
#if defined(CONFIG_NET_IPV4)
uint8_t ipv4_opts_len; /* length of IPv4 header options */
#endif
#if defined(CONFIG_NET_IPV6)
uint16_t ipv6_ext_len; /* length of extension headers */
#endif
};
#if defined(CONFIG_NET_IPV4_FRAGMENT) || defined(CONFIG_NET_IPV6_FRAGMENT)
union {
#if defined(CONFIG_NET_IPV4_FRAGMENT)
struct {
uint16_t flags; /* Fragment offset and M (More Fragment) flag */
uint16_t id; /* Fragment ID */
} ipv4_fragment;
#endif /* CONFIG_NET_IPV4_FRAGMENT */
#if defined(CONFIG_NET_IPV6_FRAGMENT)
struct {
uint16_t flags; /* Fragment offset and M (More Fragment) flag */
uint32_t id; /* Fragment id */
uint16_t hdr_start; /* Where starts the fragment header */
} ipv6_fragment;
#endif /* CONFIG_NET_IPV6_FRAGMENT */
};
#endif /* CONFIG_NET_IPV4_FRAGMENT || CONFIG_NET_IPV6_FRAGMENT */
#if defined(CONFIG_NET_IPV6)
/* Where is the start of the last header before payload data
* in IPv6 packet. This is offset value from start of the IPv6
* packet. Note that this value should be updated by who ever
* adds IPv6 extension headers to the network packet.
*/
uint16_t ipv6_prev_hdr_start;
uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
uint8_t ipv6_next_hdr; /* What is the very first next header */
#endif /* CONFIG_NET_IPV6 */
#if defined(CONFIG_NET_IP_DSCP_ECN)
/** IPv4/IPv6 Differentiated Services Code Point value. */
uint8_t ip_dscp : 6;
/** IPv4/IPv6 Explicit Congestion Notification value. */
uint8_t ip_ecn : 2;
#endif /* CONFIG_NET_IP_DSCP_ECN */
#endif /* CONFIG_NET_IP */
#if defined(CONFIG_NET_VLAN)
/* VLAN TCI (Tag Control Information). This contains the Priority
* Code Point (PCP), Drop Eligible Indicator (DEI) and VLAN
* Identifier (VID, called more commonly VLAN tag). This value is
* kept in host byte order.
*/
uint16_t vlan_tci;
#endif /* CONFIG_NET_VLAN */
#if defined(NET_PKT_HAS_CONTROL_BLOCK)
/* TODO: Evolve this into a union of orthogonal
* control block declarations if further L2
* stacks require L2-specific attributes.
*/
#if defined(CONFIG_IEEE802154)
/* The following structure requires a 4-byte alignment
* boundary to avoid padding.
*/
struct net_pkt_cb_ieee802154 cb;
#endif /* CONFIG_IEEE802154 */
#endif /* NET_PKT_HAS_CONTROL_BLOCK */
/** Network packet priority, can be left out in which case packet
* is not prioritised.
*/
uint8_t priority;
/* @endcond */
};
/** @cond ignore */
/* The interface real ll address */
static inline struct net_linkaddr *net_pkt_lladdr_if(struct net_pkt *pkt)
{
return net_if_get_link_addr(pkt->iface);
}
static inline struct net_context *net_pkt_context(struct net_pkt *pkt)
{
return pkt->context;
}
static inline void net_pkt_set_context(struct net_pkt *pkt,
struct net_context *ctx)
{
pkt->context = ctx;
}
static inline struct net_if *net_pkt_iface(struct net_pkt *pkt)
{
return pkt->iface;
}
static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
{
pkt->iface = iface;
/* If the network interface is set in pkt, then also set the type of
* the network address that is stored in pkt. This is done here so
* that the address type is properly set and is not forgotten.
*/
if (iface) {
pkt->lladdr_src.type = net_if_get_link_addr(iface)->type;
pkt->lladdr_dst.type = net_if_get_link_addr(iface)->type;
}
}
static inline struct net_if *net_pkt_orig_iface(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
return pkt->orig_iface;
#else
return pkt->iface;
#endif
}
static inline void net_pkt_set_orig_iface(struct net_pkt *pkt,
struct net_if *iface)
{
#if defined(CONFIG_NET_ROUTING) || defined(CONFIG_NET_ETHERNET_BRIDGE)
pkt->orig_iface = iface;
#endif
}
static inline uint8_t net_pkt_family(struct net_pkt *pkt)
{
return pkt->family;
}
static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
{
pkt->family = family;
}
static inline bool net_pkt_is_ptp(struct net_pkt *pkt)
{
return !!(pkt->ptp_pkt);
}
static inline void net_pkt_set_ptp(struct net_pkt *pkt, bool is_ptp)
{
pkt->ptp_pkt = is_ptp;
}
static inline bool net_pkt_is_captured(struct net_pkt *pkt)
{
return !!(pkt->captured);
}
static inline void net_pkt_set_captured(struct net_pkt *pkt, bool is_captured)
{
pkt->captured = is_captured;
}
static inline bool net_pkt_is_l2_bridged(struct net_pkt *pkt)
{
return IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE) ? !!(pkt->l2_bridged) : 0;
}
static inline void net_pkt_set_l2_bridged(struct net_pkt *pkt, bool is_l2_bridged)
{
if (IS_ENABLED(CONFIG_NET_ETHERNET_BRIDGE)) {
pkt->l2_bridged = is_l2_bridged;
}
}
static inline bool net_pkt_is_l2_processed(struct net_pkt *pkt)
{
return !!(pkt->l2_processed);
}
static inline void net_pkt_set_l2_processed(struct net_pkt *pkt,
bool is_l2_processed)
{
pkt->l2_processed = is_l2_processed;
}
static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_IP)
return pkt->ip_hdr_len;
#else
return 0;
#endif
}
static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
{
#if defined(CONFIG_NET_IP)
pkt->ip_hdr_len = len;
#endif
}
static inline uint8_t net_pkt_ip_dscp(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_IP_DSCP_ECN)
return pkt->ip_dscp;
#else
return 0;
#endif
}
static inline void net_pkt_set_ip_dscp(struct net_pkt *pkt, uint8_t dscp)
{
#if defined(CONFIG_NET_IP_DSCP_ECN)
pkt->ip_dscp = dscp;
#endif
}
static inline uint8_t net_pkt_ip_ecn(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_IP_DSCP_ECN)
return pkt->ip_ecn;
#else
return 0;
#endif
}
static inline void net_pkt_set_ip_ecn(struct net_pkt *pkt, uint8_t ecn)
{
#if defined(CONFIG_NET_IP_DSCP_ECN)
pkt->ip_ecn = ecn;
#endif
}
static inline uint8_t net_pkt_sent(struct net_pkt *pkt)
{
return pkt->sent_or_eof;
}
static inline void net_pkt_set_sent(struct net_pkt *pkt, bool sent)
{
pkt->sent_or_eof = sent;
}
static inline uint8_t net_pkt_queued(struct net_pkt *pkt)
{
return pkt->pkt_queued;
}
static inline void net_pkt_set_queued(struct net_pkt *pkt, bool send)
{
pkt->pkt_queued = send;
}
static inline uint8_t net_pkt_tcp_1st_msg(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_TCP)
return pkt->tcp_first_msg;
#else
return true;
#endif
}
static inline void net_pkt_set_tcp_1st_msg(struct net_pkt *pkt, bool is_1st)
{
#if defined(CONFIG_NET_TCP)
pkt->tcp_first_msg = is_1st;
#else
ARG_UNUSED(pkt);
ARG_UNUSED(is_1st);
#endif
}
#if defined(CONFIG_NET_SOCKETS)
static inline uint8_t net_pkt_eof(struct net_pkt *pkt)
{
return pkt->sent_or_eof;
}
static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof)
{
pkt->sent_or_eof = eof;
}
#endif
#if defined(CONFIG_NET_ROUTE)
static inline bool net_pkt_forwarding(struct net_pkt *pkt)
{
return pkt->forwarding;
}
static inline void net_pkt_set_forwarding(struct net_pkt *pkt, bool forward)
{
pkt->forwarding = forward;
}
#else
static inline bool net_pkt_forwarding(struct net_pkt *pkt)
{
return false;
}
#endif
#if defined(CONFIG_NET_IPV4)
static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
{
return pkt->ipv4_ttl;
}
static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
uint8_t ttl)
{
pkt->ipv4_ttl = ttl;
}
static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
{
return pkt->ipv4_opts_len;
}
static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
uint8_t opts_len)
{
pkt->ipv4_opts_len = opts_len;
}
#else
static inline uint8_t net_pkt_ipv4_ttl(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv4_ttl(struct net_pkt *pkt,
uint8_t ttl)
{
ARG_UNUSED(pkt);
ARG_UNUSED(ttl);
}
static inline uint8_t net_pkt_ipv4_opts_len(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv4_opts_len(struct net_pkt *pkt,
uint8_t opts_len)
{
ARG_UNUSED(pkt);
ARG_UNUSED(opts_len);
}
#endif
#if defined(CONFIG_NET_IPV6)
static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
{
return pkt->ipv6_ext_opt_len;
}
static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
uint8_t len)
{
pkt->ipv6_ext_opt_len = len;
}
static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
{
return pkt->ipv6_next_hdr;
}
static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
uint8_t next_hdr)
{
pkt->ipv6_next_hdr = next_hdr;
}
static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
{
return pkt->ipv6_ext_len;
}
static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
{
pkt->ipv6_ext_len = len;
}
static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
{
return pkt->ipv6_prev_hdr_start;
}
static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
uint16_t offset)
{
pkt->ipv6_prev_hdr_start = offset;
}
static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
{
return pkt->ipv6_hop_limit;
}
static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
uint8_t hop_limit)
{
pkt->ipv6_hop_limit = hop_limit;
}
#else /* CONFIG_NET_IPV6 */
static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
uint8_t len)
{
ARG_UNUSED(pkt);
ARG_UNUSED(len);
}
static inline uint8_t net_pkt_ipv6_next_hdr(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_next_hdr(struct net_pkt *pkt,
uint8_t next_hdr)
{
ARG_UNUSED(pkt);
ARG_UNUSED(next_hdr);
}
static inline uint16_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint16_t len)
{
ARG_UNUSED(pkt);
ARG_UNUSED(len);
}
static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
uint16_t offset)
{
ARG_UNUSED(pkt);
ARG_UNUSED(offset);
}
static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
uint8_t hop_limit)
{
ARG_UNUSED(pkt);
ARG_UNUSED(hop_limit);
}
#endif /* CONFIG_NET_IPV6 */
static inline uint16_t net_pkt_ip_opts_len(struct net_pkt *pkt)
{
#if defined(CONFIG_NET_IPV6)
return pkt->ipv6_ext_len;
#elif defined(CONFIG_NET_IPV4)
return pkt->ipv4_opts_len;
#else
ARG_UNUSED(pkt);
return 0;
#endif
}
#if defined(CONFIG_NET_IPV4_FRAGMENT)
static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
{
return (pkt->ipv4_fragment.flags & NET_IPV4_FRAGH_OFFSET_MASK) * 8;
}
static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
{
return (pkt->ipv4_fragment.flags & NET_IPV4_MORE_FRAG_MASK) != 0;
}
static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
{
pkt->ipv4_fragment.flags = flags;
}
static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
{
return pkt->ipv4_fragment.id;
}
static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
{
pkt->ipv4_fragment.id = id;
}
#else /* CONFIG_NET_IPV4_FRAGMENT */
static inline uint16_t net_pkt_ipv4_fragment_offset(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline bool net_pkt_ipv4_fragment_more(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv4_fragment_flags(struct net_pkt *pkt, uint16_t flags)
{
ARG_UNUSED(pkt);
ARG_UNUSED(flags);
}
static inline uint32_t net_pkt_ipv4_fragment_id(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv4_fragment_id(struct net_pkt *pkt, uint32_t id)
{
ARG_UNUSED(pkt);
ARG_UNUSED(id);
}
#endif /* CONFIG_NET_IPV4_FRAGMENT */
#if defined(CONFIG_NET_IPV6_FRAGMENT)
static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
{
return pkt->ipv6_fragment.hdr_start;
}
static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
uint16_t start)
{
pkt->ipv6_fragment.hdr_start = start;
}
static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
{
return pkt->ipv6_fragment.flags & NET_IPV6_FRAGH_OFFSET_MASK;
}
static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
{
return (pkt->ipv6_fragment.flags & 0x01) != 0;
}
static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
uint16_t flags)
{
pkt->ipv6_fragment.flags = flags;
}
static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
{
return pkt->ipv6_fragment.id;
}
static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
uint32_t id)
{
pkt->ipv6_fragment.id = id;
}
#else /* CONFIG_NET_IPV6_FRAGMENT */
static inline uint16_t net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
uint16_t start)
{
ARG_UNUSED(pkt);
ARG_UNUSED(start);
}
static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline bool net_pkt_ipv6_fragment_more(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_fragment_flags(struct net_pkt *pkt,
uint16_t flags)
{
ARG_UNUSED(pkt);
ARG_UNUSED(flags);
}
static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
uint32_t id)
{
ARG_UNUSED(pkt);
ARG_UNUSED(id);
}
#endif /* CONFIG_NET_IPV6_FRAGMENT */
static inline uint8_t net_pkt_priority(struct net_pkt *pkt)
{
return pkt->priority;
}
static inline void net_pkt_set_priority(struct net_pkt *pkt,
uint8_t priority)
{
pkt->priority = priority;
}
#if defined(CONFIG_NET_VLAN)
static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
{
return net_eth_vlan_get_vid(pkt->vlan_tci);
}
static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
{
pkt->vlan_tci = net_eth_vlan_set_vid(pkt->vlan_tci, tag);
}
static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
{
return net_eth_vlan_get_pcp(pkt->vlan_tci);
}
static inline void net_pkt_set_vlan_priority(struct net_pkt *pkt,
uint8_t priority)
{
pkt->vlan_tci = net_eth_vlan_set_pcp(pkt->vlan_tci, priority);
}
static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
{
return net_eth_vlan_get_dei(pkt->vlan_tci);
}
static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
{
pkt->vlan_tci = net_eth_vlan_set_dei(pkt->vlan_tci, dei);
}
static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
{
pkt->vlan_tci = tci;
}
static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
{
return pkt->vlan_tci;
}
#else
static inline uint16_t net_pkt_vlan_tag(struct net_pkt *pkt)
{
return NET_VLAN_TAG_UNSPEC;
}
static inline void net_pkt_set_vlan_tag(struct net_pkt *pkt, uint16_t tag)
{
ARG_UNUSED(pkt);
ARG_UNUSED(tag);
}
static inline uint8_t net_pkt_vlan_priority(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0;
}
static inline bool net_pkt_vlan_dei(struct net_pkt *pkt)
{
return false;
}
static inline void net_pkt_set_vlan_dei(struct net_pkt *pkt, bool dei)
{
ARG_UNUSED(pkt);
ARG_UNUSED(dei);
}
static inline uint16_t net_pkt_vlan_tci(struct net_pkt *pkt)
{
return NET_VLAN_TAG_UNSPEC; /* assumes priority is 0 */
}
static inline void net_pkt_set_vlan_tci(struct net_pkt *pkt, uint16_t tci)
{
ARG_UNUSED(pkt);
ARG_UNUSED(tci);
}
#endif
#if defined(CONFIG_NET_PKT_TIMESTAMP)
static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
{
return &pkt->timestamp;
}
static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
struct net_ptp_time *timestamp)
{
pkt->timestamp.second = timestamp->second;
pkt->timestamp.nanosecond = timestamp->nanosecond;
}
#else
static inline struct net_ptp_time *net_pkt_timestamp(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return NULL;
}
static inline void net_pkt_set_timestamp(struct net_pkt *pkt,
struct net_ptp_time *timestamp)
{
ARG_UNUSED(pkt);
ARG_UNUSED(timestamp);
}
#endif /* CONFIG_NET_PKT_TIMESTAMP */
#if defined(CONFIG_NET_PKT_RXTIME_STATS) || defined(CONFIG_NET_PKT_TXTIME_STATS)
static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
{
return pkt->create_time;
}
static inline void net_pkt_set_create_time(struct net_pkt *pkt,
uint32_t create_time)
{
pkt->create_time = create_time;
}
#else
static inline uint32_t net_pkt_create_time(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);
return 0U;
}
static inline void net_pkt_set_create_time(struct net_pkt *pkt,
uint32_t create_time)
{
ARG_UNUSED(pkt);
ARG_UNUSED(create_time);
}
#endif /* CONFIG_NET_PKT_RXTIME_STATS || CONFIG_NET_PKT_TXTIME_STATS */
#if defined(CONFIG_NET_PKT_TXTIME)
static inline uint64_t net_pkt_txtime(struct net_pkt *pkt)
{
return pkt->txtime;
}