-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinux.patch
1562 lines (1472 loc) · 42.1 KB
/
linux.patch
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
diff --git a/Makefile b/Makefile
index 68a8faff2..4a748c136 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
VERSION = 6
PATCHLEVEL = 12
SUBLEVEL = 0
-EXTRAVERSION =
+EXTRAVERSION = ioam-direct-export
NAME = Baby Opossum Posse
# *DOCUMENTATION*
diff --git a/include/net/ioam6.h b/include/net/ioam6.h
index 2cbbee6e8..fe7f68942 100644
--- a/include/net/ioam6.h
+++ b/include/net/ioam6.h
@@ -39,10 +39,19 @@ struct ioam6_schema {
u8 data[];
};
+struct ioam6_dex_flow {
+ struct rhash_head head;
+ struct rcu_head rcu;
+
+ __be32 flowID;
+ __be32 seqID;
+};
+
struct ioam6_pernet_data {
struct mutex lock;
struct rhashtable namespaces;
struct rhashtable schemas;
+ struct rhashtable dex_flows;
};
static inline struct ioam6_pernet_data *ioam6_pernet(struct net *net)
@@ -55,6 +64,10 @@ static inline struct ioam6_pernet_data *ioam6_pernet(struct net *net)
}
struct ioam6_namespace *ioam6_namespace(struct net *net, __be16 id);
+
+/* Insert flow with given id */
+struct ioam6_dex_flow *ioam6_dex_flow_insert(struct net *net, __be32 flowID);
+
void ioam6_fill_trace_data(struct sk_buff *skb,
struct ioam6_namespace *ns,
struct ioam6_trace_hdr *trace,
@@ -66,7 +79,8 @@ void ioam6_exit(void);
int ioam6_iptunnel_init(void);
void ioam6_iptunnel_exit(void);
-void ioam6_event(enum ioam6_event_type type, struct net *net, gfp_t gfp,
- void *opt, unsigned int opt_len);
+void ioam6_event(enum ioam6_event_type type, struct sk_buff *skb,
+ struct net *net, struct ioam6_namespace *ns,
+ gfp_t gfp, void *opt, unsigned int opt_len);
#endif /* _NET_IOAM6_H */
diff --git a/include/uapi/linux/ioam6.h b/include/uapi/linux/ioam6.h
index 8f72b24fe..4ee764979 100644
--- a/include/uapi/linux/ioam6.h
+++ b/include/uapi/linux/ioam6.h
@@ -29,6 +29,7 @@ struct ioam6_hdr {
__u8 opt_len;
__u8 :8; /* reserved */
#define IOAM6_TYPE_PREALLOC 0
+#define IOAM6_TYPE_DEX 4
__u8 type;
} __attribute__((packed));
@@ -130,4 +131,140 @@ struct ioam6_trace_hdr {
__u8 data[];
} __attribute__((packed));
+/*
+ * IOAM Direct EXporting (DEX) Header
+ */
+struct ioam6_dex_hdr {
+ __be16 namespace_id;
+
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+ /* Flags */
+ union {
+ __u8 flags;
+ struct {
+ __u8 :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1; /* unused */
+ };
+ };
+
+ /* Extension-Flags */
+ union {
+ __u8 extflags;
+ struct {
+ __u8 :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ seqNum:1, /* unused */
+ flowId:1; /* unused */
+ };
+ };
+
+ /* Trace Type and Reserved */
+ union {
+ __be32 type_be32;
+ struct {
+ __u32 bit7:1, /* must be 0 per RFC 9326 */
+ bit6:1,
+ bit5:1,
+ bit4:1,
+ bit3:1,
+ bit2:1,
+ bit1:1,
+ bit0:1,
+ bit15:1, /* unused */
+ bit14:1, /* unused */
+ bit13:1, /* unused */
+ bit12:1, /* unused */
+ bit11:1,
+ bit10:1,
+ bit9:1,
+ bit8:1,
+ bit23:1, /* reserved */
+ bit22:1,
+ bit21:1, /* unused */
+ bit20:1, /* unused */
+ bit19:1, /* unused */
+ bit18:1, /* unused */
+ bit17:1, /* unused */
+ bit16:1, /* unused */
+ :8; /* reserved */
+ } type;
+ };
+#elif defined(__BIG_ENDIAN_BITFIELD)
+ /* Flags */
+ union {
+ __u8 flags;
+ struct {
+ __u8 :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1; /* unused */
+ };
+ };
+
+ /* Extension-Flags */
+ union {
+ __u8 extflags;
+ struct {
+ __u8 flowId:1, /* unused */
+ seqNum:1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1, /* unused */
+ :1; /* unused */
+ };
+ };
+
+ /* Trace Type and Reserved */
+ union {
+ __be32 type_be32;
+ struct {
+ __u32 bit0:1,
+ bit1:1,
+ bit2:1,
+ bit3:1,
+ bit4:1,
+ bit5:1,
+ bit6:1,
+ bit7:1, /* must be 0 per RFC 9326 */
+ bit8:1,
+ bit9:1,
+ bit10:1,
+ bit11:1,
+ bit12:1, /* unused */
+ bit13:1, /* unused */
+ bit14:1, /* unused */
+ bit15:1, /* unused */
+ bit16:1, /* unused */
+ bit17:1, /* unused */
+ bit18:1, /* unused */
+ bit19:1, /* unused */
+ bit20:1, /* unused */
+ bit21:1, /* unused */
+ bit22:1,
+ bit23:1, /* reserved */
+ :8; /* reserved */
+ } type;
+ };
+#else
+#error "Please fix <asm/byteorder.h>"
+#endif
+ __u8 extflags_data[];
+} __attribute__((packed));
+
#endif /* _UAPI_LINUX_IOAM6_H */
diff --git a/include/uapi/linux/ioam6_genl.h b/include/uapi/linux/ioam6_genl.h
index 1733fbc51..56e8a65a9 100644
--- a/include/uapi/linux/ioam6_genl.h
+++ b/include/uapi/linux/ioam6_genl.h
@@ -54,6 +54,7 @@ enum {
enum ioam6_event_type {
IOAM6_EVENT_UNSPEC,
IOAM6_EVENT_TRACE,
+ IOAM6_EVENT_DEX,
};
enum ioam6_event_attr {
@@ -64,6 +65,38 @@ enum ioam6_event_attr {
IOAM6_EVENT_ATTR_TRACE_TYPE, /* u32 */
IOAM6_EVENT_ATTR_TRACE_DATA, /* Binary */
+ IOAM6_EVENT_ATTR_OPTION_TYPE, /* u8 */
+
+ IOAM6_EVENT_ATTR_DEX_NAMESPACE, /* u16 */
+ IOAM6_EVENT_ATTR_DEX_FLOW_ID, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_SEQ_NUM, /* u32 */
+
+ /* attr for ioam data */
+ IOAM6_EVENT_ATTR_DEX_DATA_HOP_LIM_NODE_ID, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_INGRESS_EGRESS_INTERFACES, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_TIMESTAMP, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_TIMESTAMP_FRAC, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_TRANSIT, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_NAMESPACE_SPECIFIC, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_QUEUE_DEPTH, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_CHECKSUM, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_DATA_HOP_LIM_NODE_ID_WIDE, /* u64 */
+ IOAM6_EVENT_ATTR_DEX_DATA_INGRESS_EGRESS_INTERFACES_WIDE,/* u64 */
+ IOAM6_EVENT_ATTR_DEX_DATA_NAMESPACE_SPECIFIC_WIDE, /* u64 */
+ IOAM6_EVENT_ATTR_DEX_DATA_BUFFER_OCCUPANCY, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_BIT_12, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_13, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_14, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_15, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_16, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_17, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_18, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_19, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_20, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_BIT_21, /* undefined */
+ IOAM6_EVENT_ATTR_DEX_OSS_SCID, /* u32 */
+ IOAM6_EVENT_ATTR_DEX_OSS_DATA, /* Binary */
+
__IOAM6_EVENT_ATTR_MAX
};
diff --git a/include/uapi/linux/ioam6_iptunnel.h b/include/uapi/linux/ioam6_iptunnel.h
index 8aef21e4a..b1c21e74c 100644
--- a/include/uapi/linux/ioam6_iptunnel.h
+++ b/include/uapi/linux/ioam6_iptunnel.h
@@ -9,6 +9,22 @@
#ifndef _UAPI_LINUX_IOAM6_IPTUNNEL_H
#define _UAPI_LINUX_IOAM6_IPTUNNEL_H
+/* Option types:
+ * - Pre-allocated Trace Option (PTO)
+ * - Direct EXport (DEX)
+ */
+enum {
+ __IOAM6_OPTION_TYPE_MIN,
+
+ IOAM6_OPTION_TYPE_PTO,
+ IOAM6_OPTION_TYPE_DEX,
+
+ __IOAM6_OPTION_TYPE_MAX,
+};
+
+#define IOAM6_OPTION_TYPE_MIN (__IOAM6_OPTION_TYPE_MIN + 1)
+#define IOAM6_OPTION_TYPE_MAX (__IOAM6_OPTION_TYPE_MAX - 1)
+
/* Encap modes:
* - inline: direct insertion
* - encap: ip6ip6 encapsulation
@@ -56,6 +72,12 @@ enum {
*/
IOAM6_IPTUNNEL_SRC, /* struct in6_addr */
+ /* Option Type */
+ IOAM6_OPTION_TYPE, /* u8 */
+
+ /* IOAM Direct Export Header */
+ IOAM6_IPTUNNEL_DEX, /* struct ioam6_dex_hdr */
+
__IOAM6_IPTUNNEL_MAX,
};
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 6789623b2..4f645e7f4 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -906,6 +906,7 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff)
{
struct ioam6_trace_hdr *trace;
struct ioam6_namespace *ns;
+ struct ioam6_dex_hdr *dex;
struct ioam6_hdr *hdr;
/* Bad alignment (must be 4n-aligned) */
@@ -950,9 +951,31 @@ static bool ipv6_hop_ioam(struct sk_buff *skb, int optoff)
ioam6_fill_trace_data(skb, ns, trace, true);
- ioam6_event(IOAM6_EVENT_TRACE, dev_net(skb->dev),
+ ioam6_event(IOAM6_EVENT_TRACE, skb, dev_net(skb->dev), ns,
GFP_ATOMIC, (void *)trace, hdr->opt_len - 2);
break;
+ case IOAM6_TYPE_DEX:
+ if (hdr->opt_len < 2 + sizeof(*dex))
+ goto drop;
+
+ dex = (struct ioam6_dex_hdr *)((u8 *)hdr + sizeof(*hdr));
+ if (!dex)
+ goto drop;
+
+ if (hdr->opt_len < 2 + sizeof(*dex) + hweight32(dex->extflags) * 4)
+ goto drop;
+
+ ns = ioam6_namespace(dev_net(skb->dev), dex->namespace_id);
+ if (!ns)
+ goto ignore;
+
+ if (!skb_valid_dst(skb))
+ ip6_route_input(skb);
+
+ ioam6_event(IOAM6_EVENT_DEX, skb, dev_net(skb->dev), ns,
+ GFP_ATOMIC, (void*)dex, hdr->opt_len - 2);
+
+ break;
default:
break;
}
diff --git a/net/ipv6/ioam6.c b/net/ipv6/ioam6.c
index 08c929513..c45c6977b 100644
--- a/net/ipv6/ioam6.c
+++ b/net/ipv6/ioam6.c
@@ -14,6 +14,7 @@
#include <linux/ioam6_genl.h>
#include <linux/rhashtable.h>
#include <linux/netdevice.h>
+#include <linux/bitops.h>
#include <net/addrconf.h>
#include <net/genetlink.h>
@@ -30,6 +31,11 @@ static void ioam6_sc_release(struct ioam6_schema *sc)
kfree_rcu(sc, rcu);
}
+static void ioam6_dex_release(struct ioam6_dex_flow *flow)
+{
+ kfree_rcu(flow, rcu);
+}
+
static void ioam6_free_ns(void *ptr, void *arg)
{
struct ioam6_namespace *ns = (struct ioam6_namespace *)ptr;
@@ -46,6 +52,14 @@ static void ioam6_free_sc(void *ptr, void *arg)
ioam6_sc_release(sc);
}
+static void ioam6_free_dex(void *ptr, void *arg)
+{
+ struct ioam6_dex_flow *flow = (struct ioam6_dex_flow*) ptr;
+
+ if (flow)
+ ioam6_dex_release(flow);
+}
+
static int ioam6_ns_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
{
const struct ioam6_namespace *ns = obj;
@@ -60,6 +74,13 @@ static int ioam6_sc_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
return (sc->id != *(u32 *)arg->key);
}
+static int ioam6_dex_cmpfn(struct rhashtable_compare_arg *arg, const void *obj)
+{
+ const struct ioam6_dex_flow *flow = obj;
+
+ return (flow->flowID != *(__be32 *)arg->key);
+}
+
static const struct rhashtable_params rht_ns_params = {
.key_len = sizeof(__be16),
.key_offset = offsetof(struct ioam6_namespace, id),
@@ -76,6 +97,14 @@ static const struct rhashtable_params rht_sc_params = {
.obj_cmpfn = ioam6_sc_cmpfn,
};
+static const struct rhashtable_params rht_dex_params = {
+ .key_len = sizeof(__be32),
+ .key_offset = offsetof(struct ioam6_dex_flow, flowID),
+ .head_offset = offsetof(struct ioam6_dex_flow, head),
+ .automatic_shrinking = true,
+ .obj_cmpfn = ioam6_dex_cmpfn,
+};
+
static struct genl_family ioam6_genl_family;
static const struct nla_policy ioam6_genl_policy_addns[] = {
@@ -619,6 +648,129 @@ static const struct genl_multicast_group ioam6_mcgrps[] = {
.flags = GENL_MCAST_CAP_NET_ADMIN },
};
+static u32 ioam6_get_bit_0(struct sk_buff *skb)
+{
+ u32 raw32;
+ u8 byte;
+
+ byte = ipv6_hdr(skb)->hop_limit;
+ raw32 = dev_net(skb_dst(skb)->dev)->ipv6.sysctl.ioam6_id;
+
+ return (byte << 24) | raw32;
+}
+
+static u32 ioam6_get_bit_1(struct sk_buff *skb)
+{
+ u16 raw16;
+ u32 raw32;
+
+ if (!skb->dev)
+ raw16 = IOAM6_U16_UNAVAILABLE;
+ else
+ raw16 = (__force u16)READ_ONCE(__in6_dev_get(skb->dev)->cnf.ioam6_id);
+
+ raw32 = raw16 << 16;
+
+ if (skb_dst(skb)->dev->flags & IFF_LOOPBACK)
+ raw16 = IOAM6_U16_UNAVAILABLE;
+ else
+ raw16 = (__force u16)READ_ONCE(__in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id);
+
+ return raw32 | raw16;
+}
+
+static u32 ioam6_get_bit_2(struct sk_buff *skb)
+{
+ struct timespec64 ts;
+ ktime_t tstamp;
+
+ if (!skb->dev) {
+ return IOAM6_U32_UNAVAILABLE;
+ } else {
+ tstamp = skb_tstamp_cond(skb, true);
+ ts = ktime_to_timespec64(tstamp);
+ return (u32)ts.tv_sec;
+ }
+}
+
+static u32 ioam6_get_bit_3(struct sk_buff *skb)
+{
+ struct timespec64 ts;
+ ktime_t tstamp;
+
+ if (!skb->dev) {
+ return IOAM6_U32_UNAVAILABLE;
+ } else {
+ tstamp = skb_tstamp_cond(skb, true);
+ ts = ktime_to_timespec64(tstamp);
+ return (u32)(ts.tv_nsec / NSEC_PER_USEC);
+ }
+}
+
+static u32 ioam6_get_bit_5(struct ioam6_namespace *ns)
+{
+ return be32_to_cpu(ns->data);
+}
+
+static u32 ioam6_get_bit_6(struct sk_buff *skb)
+{
+ struct netdev_queue *queue;
+ struct Qdisc *qdisc;
+ __u32 qlen, backlog;
+
+ if (skb_dst(skb)->dev->flags & IFF_LOOPBACK) {
+ return IOAM6_U32_UNAVAILABLE;
+ } else {
+ queue = skb_get_tx_queue(skb_dst(skb)->dev, skb);
+ qdisc = rcu_dereference(queue->qdisc);
+ qdisc_qstats_qlen_backlog(qdisc, &qlen, &backlog);
+ return backlog;
+ }
+}
+
+static u64 ioam6_get_bit_8(struct sk_buff *skb)
+{
+ u64 raw64;
+ u8 byte;
+
+ byte = ipv6_hdr(skb)->hop_limit;
+ raw64 = dev_net(skb_dst(skb)->dev)->ipv6.sysctl.ioam6_id_wide;
+
+ return ((u64)byte << 56) | raw64;
+}
+
+static u64 ioam6_get_bit_9(struct sk_buff *skb)
+{
+ u32 raw32;
+ u64 raw64;
+
+ if (!skb->dev)
+ raw32 = IOAM6_U32_UNAVAILABLE;
+ else
+ raw32 = READ_ONCE(__in6_dev_get(skb->dev)->cnf.ioam6_id_wide);
+
+ raw64 = (u64)raw32 << 32;
+
+ if (skb_dst(skb)->dev->flags & IFF_LOOPBACK)
+ raw32 = IOAM6_U32_UNAVAILABLE;
+ else
+ raw32 = READ_ONCE(__in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id_wide);
+
+ return raw64 | raw32;
+}
+
+static u64 ioam6_get_bit_10(struct ioam6_namespace *ns)
+{
+ return be64_to_cpu(ns->data_wide);
+}
+
+static void ioam6_get_bit_22(struct ioam6_schema *sc, u8 *buf)
+{
+ *(__be32 *)buf = sc->hdr;
+ memcpy(buf+sizeof(__be32), sc->data, sc->len);
+ return;
+}
+
static int ioam6_event_put_trace(struct sk_buff *skb,
struct ioam6_trace_hdr *trace,
unsigned int len)
@@ -636,21 +788,213 @@ static int ioam6_event_put_trace(struct sk_buff *skb,
return 0;
}
-void ioam6_event(enum ioam6_event_type type, struct net *net, gfp_t gfp,
- void *opt, unsigned int opt_len)
+static int ioam6_event_put_dex(struct sk_buff *skb, struct ioam6_namespace *ns,
+ struct sk_buff *nl_skb, struct ioam6_dex_hdr *hdr)
+{
+ struct ioam6_schema *sc = NULL;
+ u32 flow, seq, res;
+
+ if (nla_put_u8(nl_skb, IOAM6_EVENT_ATTR_OPTION_TYPE,
+ IOAM6_TYPE_DEX))
+ return -1;
+
+ if (nla_put_u16(nl_skb, IOAM6_EVENT_ATTR_DEX_NAMESPACE,
+ be16_to_cpu(hdr->namespace_id)))
+ return -1;
+
+ if (hdr->flowId) {
+ flow = ((u32*)(hdr->extflags_data))[0];
+ if (nla_put_u32(nl_skb, IOAM6_EVENT_ATTR_DEX_FLOW_ID,
+ be32_to_cpu(flow)))
+ return -1;
+ }
+
+ if (hdr->seqNum) {
+ seq = ((u32*)(hdr->extflags_data))[1];
+ if (nla_put_u32(nl_skb, IOAM6_EVENT_ATTR_DEX_SEQ_NUM,
+ be32_to_cpu(seq)))
+ return -1;
+ }
+
+ /* fill ioam data */
+ if (hdr->type.bit0 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_HOP_LIM_NODE_ID,
+ cpu_to_be32(ioam6_get_bit_0(skb))))
+ return -1;
+
+ if (hdr->type.bit1 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_INGRESS_EGRESS_INTERFACES,
+ cpu_to_be32(ioam6_get_bit_1(skb))))
+ return -1;
+
+ if (hdr->type.bit2 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_TIMESTAMP,
+ cpu_to_be32(ioam6_get_bit_2(skb))))
+ return -1;
+
+ if (hdr->type.bit3 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_TIMESTAMP_FRAC,
+ cpu_to_be32(ioam6_get_bit_3(skb))))
+ return -1;
+
+ if (hdr->type.bit4 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_TRANSIT,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit5 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_NAMESPACE_SPECIFIC,
+ cpu_to_be32(ioam6_get_bit_5(ns))))
+ return -1;
+
+ if (hdr->type.bit6 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_QUEUE_DEPTH,
+ cpu_to_be32(ioam6_get_bit_6(skb))))
+ return -1;
+
+ if (hdr->type.bit7 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_CHECKSUM,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit8 &&
+ nla_put_u64_64bit(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_HOP_LIM_NODE_ID_WIDE,
+ cpu_to_be64(ioam6_get_bit_8(skb)),
+ IOAM6_ATTR_PAD))
+ return -1;
+
+ if (hdr->type.bit9 &&
+ nla_put_u64_64bit(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_INGRESS_EGRESS_INTERFACES_WIDE,
+ cpu_to_be64(ioam6_get_bit_9(skb)),
+ IOAM6_ATTR_PAD))
+ return -1;
+
+ if (hdr->type.bit10 &&
+ nla_put_u64_64bit(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_NAMESPACE_SPECIFIC_WIDE,
+ cpu_to_be64(ioam6_get_bit_10(ns)),
+ IOAM6_ATTR_PAD))
+ return -1;
+
+ if (hdr->type.bit11 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_DATA_BUFFER_OCCUPANCY,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit12 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_12,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit13 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_13,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit14 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_14,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit15 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_15,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit16 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_16,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit17 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_17,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit18 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_18,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit19 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_19,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit20 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_20,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit21 &&
+ nla_put_u32(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_BIT_21,
+ cpu_to_be32(IOAM6_U32_UNAVAILABLE)))
+ return -1;
+
+ if (hdr->type.bit22) {
+ rcu_read_lock();
+ sc = rcu_dereference(ns->schema);
+ if (!sc) {
+ rcu_read_unlock();
+ goto no_schema;
+ }
+
+ if (nla_put_u32(nl_skb, IOAM6_EVENT_ATTR_DEX_OSS_SCID,
+ cpu_to_be32(sc->id))) {
+ rcu_read_unlock();
+ return -1;
+ }
+
+ res = nla_put(nl_skb,
+ IOAM6_EVENT_ATTR_DEX_OSS_DATA,
+ sc->len, sc->data);
+
+ rcu_read_unlock();
+
+ if (res)
+ return -1;
+ }
+no_schema:
+ return 0;
+}
+
+void ioam6_event(enum ioam6_event_type type, struct sk_buff *skb,
+ struct net *net, struct ioam6_namespace *ns,
+ gfp_t gfp, void *opt, unsigned int opt_len)
{
+ struct sk_buff *nl_skb;
struct nlmsghdr *nlh;
- struct sk_buff *skb;
if (!genl_has_listeners(&ioam6_genl_family, net,
IOAM6_GENL_EV_GRP_OFFSET))
return;
- skb = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
- if (!skb)
+ nl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
+ if (!nl_skb)
return;
- nlh = genlmsg_put(skb, 0, 0, &ioam6_genl_family, 0, type);
+ nlh = genlmsg_put(nl_skb, 0, 0, &ioam6_genl_family, 0, type);
if (!nlh)
goto nla_put_failure;
@@ -659,19 +1003,23 @@ void ioam6_event(enum ioam6_event_type type, struct net *net, gfp_t gfp,
WARN_ON_ONCE(1);
break;
case IOAM6_EVENT_TRACE:
- if (ioam6_event_put_trace(skb, (struct ioam6_trace_hdr *)opt,
+ if (ioam6_event_put_trace(nl_skb, (struct ioam6_trace_hdr *)opt,
opt_len))
goto nla_put_failure;
break;
+ case IOAM6_EVENT_DEX:
+ if (ioam6_event_put_dex(skb, ns, nl_skb, (struct ioam6_dex_hdr *)opt))
+ goto nla_put_failure;
+ break;
}
- genlmsg_end(skb, nlh);
- genlmsg_multicast_netns(&ioam6_genl_family, net, skb, 0,
+ genlmsg_end(nl_skb, nlh);
+ genlmsg_multicast_netns(&ioam6_genl_family, net, nl_skb, 0,
IOAM6_GENL_EV_GRP_OFFSET, gfp);
return;
nla_put_failure:
- nlmsg_free(skb);
+ nlmsg_free(nl_skb);
}
static struct genl_family ioam6_genl_family __ro_after_init = {
@@ -694,78 +1042,72 @@ struct ioam6_namespace *ioam6_namespace(struct net *net, __be16 id)
return rhashtable_lookup_fast(&nsdata->namespaces, &id, rht_ns_params);
}
+struct ioam6_dex_flow *ioam6_dex_flow_insert(struct net *net, __be32 flowID)
+{
+ struct ioam6_pernet_data *nsdata;
+ struct ioam6_dex_flow *flow;
+ u32 seq, err = 0;
+
+ nsdata = ioam6_pernet(net);
+ if (!nsdata)
+ return NULL;
+
+ mutex_lock(&nsdata->lock);
+
+ flow = rhashtable_lookup_fast(&nsdata->dex_flows,
+ &flowID, rht_dex_params);
+ if (flow) {
+ seq = be32_to_cpu(flow->seqID) + 1;
+ flow->seqID = cpu_to_be32(seq);
+ goto out_unlock;
+ }
+
+ flow = kzalloc(sizeof(*flow), GFP_ATOMIC);
+ if (!flow)
+ goto out_unlock;
+
+ flow->flowID = flowID;
+ flow->seqID = cpu_to_be32(0);
+
+ err = rhashtable_lookup_insert_fast(&nsdata->dex_flows,
+ &flow->head, rht_dex_params);
+
+out_unlock:
+ mutex_unlock(&nsdata->lock);
+ return err == 0 ? flow : NULL;
+}
+
static void __ioam6_fill_trace_data(struct sk_buff *skb,
struct ioam6_namespace *ns,
struct ioam6_trace_hdr *trace,
struct ioam6_schema *sc,
u8 sclen, bool is_input)
{
- struct timespec64 ts;
- ktime_t tstamp;
- u64 raw64;
- u32 raw32;
- u16 raw16;
u8 *data;
- u8 byte;
data = trace->data + trace->remlen * 4 - trace->nodelen * 4 - sclen * 4;
/* hop_lim and node_id */
if (trace->type.bit0) {
- byte = ipv6_hdr(skb)->hop_limit;
- if (is_input)
- byte--;
-
- raw32 = dev_net(skb_dst(skb)->dev)->ipv6.sysctl.ioam6_id;
-
- *(__be32 *)data = cpu_to_be32((byte << 24) | raw32);
+ *(__be32 *)data = cpu_to_be32(ioam6_get_bit_0(skb));
data += sizeof(__be32);
}
/* ingress_if_id and egress_if_id */
if (trace->type.bit1) {
- if (!skb->dev)
- raw16 = IOAM6_U16_UNAVAILABLE;
- else
- raw16 = (__force u16)READ_ONCE(__in6_dev_get(skb->dev)->cnf.ioam6_id);
-
- *(__be16 *)data = cpu_to_be16(raw16);
- data += sizeof(__be16);
-
- if (skb_dst(skb)->dev->flags & IFF_LOOPBACK)
- raw16 = IOAM6_U16_UNAVAILABLE;
- else
- raw16 = (__force u16)READ_ONCE(__in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id);
-
- *(__be16 *)data = cpu_to_be16(raw16);
- data += sizeof(__be16);
+ *(__be32 *)data = cpu_to_be32(ioam6_get_bit_1(skb));
+ data += sizeof(__be32);
}
/* timestamp seconds */
if (trace->type.bit2) {
- if (!skb->dev) {
- *(__be32 *)data = cpu_to_be32(IOAM6_U32_UNAVAILABLE);
- } else {
- tstamp = skb_tstamp_cond(skb, true);
- ts = ktime_to_timespec64(tstamp);
-
- *(__be32 *)data = cpu_to_be32((u32)ts.tv_sec);
- }
+ *(__be32 *)data = cpu_to_be32(ioam6_get_bit_2(skb));
data += sizeof(__be32);
}
/* timestamp subseconds */
if (trace->type.bit3) {
- if (!skb->dev) {
- *(__be32 *)data = cpu_to_be32(IOAM6_U32_UNAVAILABLE);
- } else {
- if (!trace->type.bit2) {
- tstamp = skb_tstamp_cond(skb, true);
- ts = ktime_to_timespec64(tstamp);
- }
-
- *(__be32 *)data = cpu_to_be32((u32)(ts.tv_nsec / NSEC_PER_USEC));
- }
+ *(__be32 *)data = cpu_to_be32(ioam6_get_bit_3(skb));
data += sizeof(__be32);
}
@@ -777,25 +1119,13 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb,
/* namespace data */
if (trace->type.bit5) {
- *(__be32 *)data = ns->data;
+ *(__be32 *)data = cpu_to_be32(ioam6_get_bit_5(ns));
data += sizeof(__be32);
}
/* queue depth */
if (trace->type.bit6) {
- struct netdev_queue *queue;
- struct Qdisc *qdisc;
- __u32 qlen, backlog;
-
- if (skb_dst(skb)->dev->flags & IFF_LOOPBACK) {
- *(__be32 *)data = cpu_to_be32(IOAM6_U32_UNAVAILABLE);
- } else {
- queue = skb_get_tx_queue(skb_dst(skb)->dev, skb);
- qdisc = rcu_dereference(queue->qdisc);
- qdisc_qstats_qlen_backlog(qdisc, &qlen, &backlog);
-
- *(__be32 *)data = cpu_to_be32(backlog);
- }
+ *(__be32 *)data = cpu_to_be32(ioam6_get_bit_6(skb));
data += sizeof(__be32);
}
@@ -807,38 +1137,19 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb,
/* hop_lim and node_id (wide) */
if (trace->type.bit8) {
- byte = ipv6_hdr(skb)->hop_limit;
- if (is_input)
- byte--;
-
- raw64 = dev_net(skb_dst(skb)->dev)->ipv6.sysctl.ioam6_id_wide;
-
- *(__be64 *)data = cpu_to_be64(((u64)byte << 56) | raw64);
+ *(__be64 *)data = cpu_to_be64(ioam6_get_bit_8(skb));
data += sizeof(__be64);
}
/* ingress_if_id and egress_if_id (wide) */
if (trace->type.bit9) {
- if (!skb->dev)
- raw32 = IOAM6_U32_UNAVAILABLE;
- else
- raw32 = READ_ONCE(__in6_dev_get(skb->dev)->cnf.ioam6_id_wide);
-
- *(__be32 *)data = cpu_to_be32(raw32);
- data += sizeof(__be32);
-
- if (skb_dst(skb)->dev->flags & IFF_LOOPBACK)
- raw32 = IOAM6_U32_UNAVAILABLE;
- else
- raw32 = READ_ONCE(__in6_dev_get(skb_dst(skb)->dev)->cnf.ioam6_id_wide);
-
- *(__be32 *)data = cpu_to_be32(raw32);
- data += sizeof(__be32);
+ *(__be64 *)data = cpu_to_be64(ioam6_get_bit_9(skb));
+ data += sizeof(__be64);
}
/* namespace data (wide) */
if (trace->type.bit10) {
- *(__be64 *)data = ns->data_wide;
+ *(__be64 *)data = cpu_to_be64(ioam6_get_bit_10(ns));
data += sizeof(__be64);
}
@@ -913,10 +1224,7 @@ static void __ioam6_fill_trace_data(struct sk_buff *skb,
if (!sc) {
*(__be32 *)data = cpu_to_be32(IOAM6_U32_UNAVAILABLE >> 8);
} else {
- *(__be32 *)data = sc->hdr;
- data += sizeof(__be32);
-
- memcpy(data, sc->data, sc->len);
+ ioam6_get_bit_22(sc, data);
}
}
}
@@ -979,8 +1287,14 @@ static int __net_init ioam6_net_init(struct net *net)
if (err)
goto free_rht_ns;