forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbgp_linkstate_tlv.c
1750 lines (1562 loc) · 51.6 KB
/
bgp_linkstate_tlv.c
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
// SPDX-License-Identifier: GPL-2.0-or-later
/* BGP Link-State TLV Serializer/Deserializer
* Copyright 2023 6WIND S.A.
*/
#include <zebra.h>
#include "iso.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_debug.h"
#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_linkstate_tlv.h"
static bool bgp_linkstate_nlri_value_display(char *buf, size_t size,
uint8_t *pnt, uint16_t nlri_type,
uint16_t type, uint16_t length,
bool first, json_object *json);
struct bgp_linkstate_tlv_info {
const char *descr;
uint8_t min_size;
uint16_t max_size;
uint8_t multiple;
};
#define UNDEF_MIN_SZ 0xFF
#define MAX_SZ 0xFFFF
#define UNDEF_MULTPL 1
/* clang-format off */
struct bgp_linkstate_tlv_info bgp_linkstate_tlv_infos[BGP_LS_TLV_MAX] = {
/* NLRI TLV */
[BGP_LS_TLV_LOCAL_NODE_DESCRIPTORS] = {"Local Node Descriptors", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_REMOTE_NODE_DESCRIPTORS] = {"Remote Node Descriptors", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_LINK_LOCAL_REMOTE_IDENTIFIERS] = {"Link Local/Remote Identifiers", 2, 2, UNDEF_MULTPL},
[BGP_LS_TLV_IPV4_INTERFACE_ADDRESS] = {"IPv4 interface address", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_IPV4_NEIGHBOR_ADDRESS] = {"IPv4 neighbor address", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_IPV6_INTERFACE_ADDRESS] = {"IPv6 interface address", 16, 16, UNDEF_MULTPL},
[BGP_LS_TLV_IPV6_NEIGHBOR_ADDRESS] = {"IPv6 neighbor address", 16, 16, UNDEF_MULTPL},
[BGP_LS_TLV_OSPF_ROUTE_TYPE] = {"OSPF Route Type", 1, 1, UNDEF_MULTPL},
[BGP_LS_TLV_IP_REACHABILITY_INFORMATION] = {"IP Reachability Information", 2, 17, UNDEF_MULTPL},
[BGP_LS_TLV_AUTONOMOUS_SYSTEM] = {"Autonomous System", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_BGP_LS_IDENTIFIER] = {"BGP-LS Identifier", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_OSPF_AREA_ID] = {"OSPF Area-ID", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_IGP_ROUTER_ID] = {"IGP Router-ID", 4, 8, UNDEF_MULTPL},
/* NRLI & BGP-LS Attributes */
[BGP_LS_TLV_MULTI_TOPOLOGY_ID] = {"Multi-Topology ID", 2, MAX_SZ, 2},
/* BGP-LS Attributes */
[BGP_LS_TLV_NODE_MSD] = {"Node MSD", 2, MAX_SZ, 2},
[BGP_LS_TLV_LINK_MSD] = {"Link MSD", 2, MAX_SZ, 2},
[BGP_LS_TLV_BGP_ROUTER_ID] = {"BGP Router-ID", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_BGP_CONFEDERATION_MEMBER] = {"BGP Confederation Member", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_NODE_FLAG_BITS] = {"Node Flag Bits", 1, 1, UNDEF_MULTPL},
[BGP_LS_TLV_OPAQUE_NODE_ATTRIBUTE] = {"Opaque Node Attribute", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_NODE_NAME] = {"Node Name", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_IS_IS_AREA_IDENTIFIER] = {"IS-IS Area Identifier", 1, 13, UNDEF_MULTPL},
[BGP_LS_TLV_IPV4_ROUTER_ID_OF_LOCAL_NODE] = {"IPv4 Router-ID of Local Node", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_IPV6_ROUTER_ID_OF_LOCAL_NODE] = {"IPv6 Router-ID of Local Node", 16, 16, UNDEF_MULTPL},
[BGP_LS_TLV_IPV4_ROUTER_ID_OF_REMOTE_NODE] = {"IPv4 Router-ID of Remote Node", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_IPV6_ROUTER_ID_OF_REMOTE_NODE] = {"IPv6 Router-ID of Remote Node", 16, 16, UNDEF_MULTPL},
[BGP_LS_TLV_S_BFD_DISCRIMINATORS] = {"S-BFD Discriminators", 4, MAX_SZ, 4},
[BGP_LS_TLV_SR_CAPABILITIES] = {"SR Capabilities", 12, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_ALGORITHM] = {"SR Algorithm", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_LOCAL_BLOCK] = {"SR Local Block", 12, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRMS_PREFERENCE] = {"SRMS Preference", 1, 1, UNDEF_MULTPL},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_DEFINITION] = {"Flexible Algorithm Definition", 4, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_EXCLUDE_ANY_AFFINITY] = {"Flexible Algorithm Exclude Any Affinity", 4, MAX_SZ, 4},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_INCLUDE_ANY_AFFINITY] = {"Flexible Algorithm Include Any Affinity", 4, MAX_SZ, 4},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_INCLUDE_ALL_AFFINITY] = {"Flexible Algorithm Include All Affinity", 4, MAX_SZ, 4},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_DEFINITION_FLAGS] = {"Flexible Algorithm Definition Flags", 4, MAX_SZ, 4},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_PREFIX_METRIC] = {"Flexible Algorithm Prefix Metric", 8, 8, UNDEF_MULTPL},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_EXCLUDE_SRLG] = {"Flexible Algorithm Exclude SRLG", 4, MAX_SZ, 4},
[BGP_LS_TLV_ADMINISTRATIVE_GROUP] = {"Administrative group", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_MAXIMUM_LINK_BANDWIDTH] = {"Maximum link bandwidth", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_MAX_RESERVABLE_LINK_BANDWIDTH] = {"Max. reservable link bandwidth", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_UNRESERVED_BANDWIDTH] = {"Unreserved bandwidth", 32, 32, UNDEF_MULTPL},
[BGP_LS_TLV_TE_DEFAULT_METRIC] = {"TE Default Metric", 3, 4, UNDEF_MULTPL},
[BGP_LS_TLV_LINK_PROTECTION_TYPE] = {"Link Protection Type", 2, 2, UNDEF_MULTPL},
[BGP_LS_TLV_MPLS_PROTOCOL_MASK] = {"MPLS Protocol Mask", 1, 1, UNDEF_MULTPL},
[BGP_LS_TLV_IGP_METRIC] = {"IGP Metric", 1, 3, UNDEF_MULTPL},
[BGP_LS_TLV_SHARED_RISK_LINK_GROUP] = {"Shared Risk Link Group", 4, MAX_SZ, 4},
[BGP_LS_TLV_OPAQUE_LINK_ATTRIBUTE] = {"Opaque Link Attribute", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_LINK_NAME] = {"Link Name", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_ADJACENCY_SID] = {"Adjacency SID", 7, 8, UNDEF_MULTPL},
[BGP_LS_TLV_LAN_ADJACENCY_SID] = {"LAN Adjacency SID", 11, 14, UNDEF_MULTPL},
[BGP_LS_TLV_PEERNODE_SID] = {"PeerNode SID", 7, 8, UNDEF_MULTPL},
[BGP_LS_TLV_PEERADJ_SID] = {"PeerAdj SID", 7, 8, UNDEF_MULTPL},
[BGP_LS_TLV_PEERSET_SID] = {"PeerSet SID", 7, 8, UNDEF_MULTPL},
[BGP_LS_TLV_RTM_CAPABILITY] = {"RTM Capability", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_UNIDIRECTIONAL_LINK_DELAY] = {"Unidirectional Link Delay", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_MIN_MAX_UNIDIRECTIONAL_LINK_DELAY] = {"Min/Max Unidirectional Link Delay", 8, 8, UNDEF_MULTPL},
[BGP_LS_TLV_UNIDIRECTIONAL_DELAY_VARIATION] = {"Unidirectional Delay Variation", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_UNIDIRECTIONAL_LINK_LOSS] = {"Unidirectional Link Loss", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_UNIDIRECTIONAL_RESIDUAL_BANDWIDTH] = {"Unidirectional Residual Bandwidth", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_UNIDIRECTIONAL_AVAILABLE_BANDWIDTH] = {"Unidirectional Available Bandwidth", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_UNIDIRECTIONAL_UTILIZED_BANDWIDTH] = {"Unidirectional Utilized Bandwidth", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_GRACEFUL_LINK_SHUTDOWN_TLV] = {"Graceful-Link-Shutdown TLV", 0, 0, UNDEF_MULTPL},
[BGP_LS_TLV_APPLICATION_SPECIFIC_LINK_ATTRIBUTES] = {"Application-Specific Link Attributes", 11, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_IGP_FLAGS] = {"IGP Flags", 1, 1, UNDEF_MULTPL},
[BGP_LS_TLV_IGP_ROUTE_TAG] = {"IGP Route Tag", 4, MAX_SZ, 4},
[BGP_LS_TLV_IGP_EXTENDED_ROUTE_TAG] = {"IGP Extended Route Tag", 8, MAX_SZ, 8},
[BGP_LS_TLV_PREFIX_METRIC] = {"Prefix Metric", 3, 4, UNDEF_MULTPL},
[BGP_LS_TLV_OSPF_FORWARDING_ADDRESS] = {"OSPF Forwarding Address", 4, 4, UNDEF_MULTPL},
[BGP_LS_TLV_OPAQUE_PREFIX_ATTRIBUTE] = {"Opaque Prefix Attribute", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_PREFIX_SID] = {"Prefix-SID", 7, 8, UNDEF_MULTPL},
[BGP_LS_TLV_RANGE] = {"Range", 11, 12, UNDEF_MULTPL},
[BGP_LS_TLV_SID_LABEL] = {"SID/Label", 3, 4, UNDEF_MULTPL},
[BGP_LS_TLV_PREFIX_ATTRIBUTES_FLAGS] = {"Prefix Attributes Flags", 1, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SOURCE_ROUTER_IDENTIFIER] = {"Source Router Identifier", 4, 16, UNDEF_MULTPL},
[BGP_LS_TLV_L2_BUNDLE_MEMBER_ATTRIBUTES] = {"L2 Bundle Member Attributes", 4, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_EXTENDED_ADMINISTRATIVE_GROUP] = {"Extended Administrative Group", 4, MAX_SZ, 4},
[BGP_LS_TLV_SOURCE_OSPF_ROUTER_ID] = {"Source OSPF Router-ID", 4, 4, UNDEF_MULTPL},
/* display not yet supported */
[BGP_LS_TLV_SRV6_SID_INFORMATION_TLV] = {"SRv6 SID Information TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_TUNNEL_ID_TLV] = {"Tunnel ID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_LSP_ID_TLV] = {"LSP ID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_IPV4_6_TUNNEL_HEAD_END_ADDRESS_TLV] = {"IPv4/6 Tunnel Head-end address TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_IPV4_6_TUNNEL_TAIL_END_ADDRESS_TLV] = {"IPv4/6 Tunnel Tail-end address TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_POLICY_CP_DESCRIPTOR_TLV] = {"SR Policy CP Descriptor TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_MPLS_LOCAL_CROSS_CONNECT_TLV] = {"MPLS Local Cross Connect TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_MPLS_CROSS_CONNECT_INTERFACE_TLV] = {"MPLS Cross Connect Interface TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_MPLS_CROSS_CONNECT_FEC_TLV] = {"MPLS Cross Connect FEC TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRV6_CAPABILITIES_TLV] = {"SRv6 Capabilities TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_FLEXIBLE_ALGORITHM_UNSUPPORTED] = {"Flexible Algorithm Unsupported", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRV6_END_X_SID_TLV] = {"SRv6 End.X SID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_IS_IS_SRV6_LAN_END_X_SID_TLV] = {"IS-IS SRv6 LAN End.X SID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_OSPFV3_SRV6_LAN_END_X_SID_TLV] = {"OSPFv3 SRv6 LAN End.X SID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_IS_IS_FLOOD_REFLECTION] = {"IS-IS Flood Reflection", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRV6_LOCATOR_TLV] = {"SRv6 Locator TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_MPLS_TE_POLICY_STATE_TLV] = {"MPLS-TE Policy State TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_BSID_TLV] = {"SR BSID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_CP_STATE_TLV] = {"SR CP State TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_CP_NAME_TLV] = {"SR CP Name TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_CP_CONSTRAINTS_TLV] = {"SR CP Constraints TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_SEGMENT_LIST_TLV] = {"SR Segment List TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_SEGMENT_SUB_TLV] = {"SR Segment sub-TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_SEGMENT_LIST_METRIC_SUB_TLV] = {"SR Segment List Metric sub-TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_AFFINITY_CONSTRAINT_SUB_TLV] = {"SR Affinity Constraint sub-TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_SRLG_CONSTRAINT_SUB_TLV] = {"SR SRLG Constraint sub-TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_BANDWIDTH_CONSTRAINT_SUB_TLV] = {"SR Bandwidth Constraint sub-TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_DISJOINT_GROUP_CONSTRAINT_SUB_TLV] = {"SR Disjoint Group Constraint sub-TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRV6_BSID_TLV] = {"SRv6 BSID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SR_POLICY_NAME_TLV] = {"SR Policy Name TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRV6_ENDPOINT_FUNCTION_TLV] = {"SRv6 Endpoint Function TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRV6_BGP_PEER_NODE_SID_TLV] = {"SRv6 BGP Peer Node SID TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
[BGP_LS_TLV_SRV6_SID_STRUCTURE_TLV] = {"SRv6 SID Structure TLV", UNDEF_MIN_SZ, MAX_SZ, UNDEF_MULTPL},
};
/* clang-format on */
/* Return the TLV length is valid for the TLV type */
static bool bgp_ls_tlv_check_size(enum bgp_linkstate_tlv type, size_t length)
{
if (type > BGP_LS_TLV_MAX ||
bgp_linkstate_tlv_infos[type].descr == NULL)
/* TLV type is not defined. Cannot check size */
return false;
if (bgp_linkstate_tlv_infos[type].min_size > length)
return false;
if (bgp_linkstate_tlv_infos[type].max_size < length)
return false;
if (length % bgp_linkstate_tlv_infos[type].multiple != 0)
return false;
return true;
}
static uint8_t pnt_decode8(uint8_t **pnt)
{
uint8_t data;
data = **pnt;
*pnt += 1;
return data;
}
static uint16_t pnt_decode16(uint8_t **pnt)
{
uint16_t data;
*pnt = ptr_get_be16(*pnt, &data);
return data;
}
static uint32_t pnt_decode24(uint8_t **pnt)
{
uint8_t tmp1;
uint16_t tmp2;
memcpy(&tmp1, *pnt, sizeof(uint8_t));
memcpy(&tmp2, *pnt + sizeof(uint8_t), sizeof(uint16_t));
*pnt += 3;
return (tmp1 << 16) | ntohs(tmp2);
}
static uint32_t pnt_decode32(uint8_t **pnt)
{
uint32_t data;
*pnt = (uint8_t *)ptr_get_be32(*pnt, &data);
return data;
}
static uint64_t pnt_decode64(uint8_t **pnt)
{
uint64_t data;
*pnt = (uint8_t *)ptr_get_be64(*pnt, &data);
return data;
}
static const char *bgp_ls_print_nlri_proto(enum bgp_ls_nlri_proto proto)
{
switch (proto) {
case BGP_LS_NLRI_PROTO_ID_IS_IS_LEVEL_1:
return "ISIS-L1";
case BGP_LS_NLRI_PROTO_ID_IS_IS_LEVEL_2:
return "ISIS-L2";
case BGP_LS_NLRI_PROTO_ID_OSPF:
return "OSPFv2";
case BGP_LS_NLRI_PROTO_ID_DIRECT:
return "Direct";
case BGP_LS_NLRI_PROTO_ID_STATIC:
return "Static";
case BGP_LS_NLRI_PROTO_ID_OSPFv3:
return "OSPFv3";
case BGP_LS_NLRI_PROTO_ID_UNKNOWN:
return "Unknown";
}
return "Unknown";
}
int bgp_nlri_parse_linkstate(struct peer *peer, struct attr *attr,
struct bgp_nlri *packet, int withdraw)
{
uint8_t *pnt;
uint8_t *lim;
afi_t afi;
safi_t safi;
uint16_t length = 0;
struct prefix p;
/* Start processing the NLRI - there may be multiple in the MP_REACH */
pnt = packet->nlri;
lim = pnt + packet->length;
afi = packet->afi;
safi = packet->safi;
for (; pnt < lim; pnt += length) {
/* Clear prefix structure. */
memset(&p, 0, sizeof(p));
/* All linkstate NLRI begin with NRLI type and length. */
if (pnt + 4 > lim)
return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW;
p.u.prefix_linkstate.nlri_type = pnt_decode16(&pnt);
length = pnt_decode16(&pnt);
/* When packet overflow occur return immediately. */
if (pnt + length > lim) {
flog_err(
EC_BGP_LINKSTATE_PACKET,
"Link-State NLRI length inconsistent (size %u seen)",
length);
return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW;
}
p.family = AF_LINKSTATE;
p.u.prefix_linkstate.ptr = (uintptr_t)pnt;
p.prefixlen = length;
if (BGP_DEBUG(linkstate, LINKSTATE)) {
zlog_debug("LS Rx %s %s %pFX",
withdraw ? "Withdraw" : "Update",
afi2str(afi), &p);
}
/* Process the route. */
if (withdraw)
bgp_withdraw(peer, &p, 0, afi, safi, ZEBRA_ROUTE_BGP,
BGP_ROUTE_NORMAL, NULL, NULL, 0, NULL);
else
bgp_update(peer, &p, 0, attr, afi, safi,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL,
NULL, 0, 0, NULL);
}
return BGP_NLRI_PARSE_OK;
}
/*
* Encode Link-State prefix in Update (MP_REACH)
*/
void bgp_nlri_encode_linkstate(struct stream *s, const struct prefix *p)
{
/* NLRI type */
stream_putw(s, p->u.prefix_linkstate.nlri_type);
/* Size */
stream_putw(s, p->prefixlen);
stream_put(s, (const void *)p->u.prefix_linkstate.ptr, p->prefixlen);
}
static size_t bgp_linkstate_nlri_hexa_display(char *buf, size_t size,
uint8_t *pnt, uint16_t type,
uint16_t length, bool first,
json_object *json)
{
json_object *json_array = NULL;
uint8_t *lim = pnt + length;
char json_buf[19];
int i;
if (json) {
snprintf(json_buf, sizeof(json_buf), "%u", type);
json_array = json_object_new_array();
json_object_object_add(json, json_buf, json_array);
for (i = 0; pnt < lim; pnt++, i++) {
if (i % 8 == 0) {
if (i != 0)
json_object_array_add(
json_array,
json_object_new_string(
json_buf));
snprintf(json_buf, sizeof(buf), "0x");
}
snprintf(json_buf + strlen(json_buf),
sizeof(json_buf) - strlen(json_buf), "%02x",
*pnt);
}
if (strlen(json_buf) > 2) /* do not only contain 0x */
json_object_array_add(json_array,
json_object_new_string(json_buf));
return size;
}
snprintf(buf, size, "%s%u:", first ? "" : " ", type);
size -= strlen(buf);
buf += strlen(buf);
snprintf(buf, size, "0x");
size -= strlen(buf);
buf += strlen(buf);
for (i = 0; pnt < lim; pnt++, i++) {
snprintf(buf, size, "%02x", *pnt);
size -= strlen(buf);
buf += strlen(buf);
}
return size;
}
static void bgp_linkstate_nlri_mtid_display(char *buf, size_t size,
uint8_t *pnt, uint16_t type,
uint16_t length, bool first,
json_object *json)
{
json_object *json_array = NULL;
if (json) {
json_array = json_object_new_array();
json_object_object_add(json, "mtID", json_array);
for (int i = 0; i < (length / 2); i++) {
json_object_array_add(
json_array,
json_object_new_int(pnt_decode16(&pnt)));
}
return;
}
for (int i = 0; i < (length / 2); i++) {
if (i == 0)
snprintf(buf, size, "%sMT:%hu", first ? "" : " ",
pnt_decode16(&pnt));
else
snprintf(buf, size, ",%hu", pnt_decode16(&pnt));
size -= strlen(buf);
buf += strlen(buf);
}
}
static bool bgp_linkstate_nlri_node_descriptor_display(
char *buf, size_t size, uint8_t *pnt, uint16_t nlri_type, uint16_t type,
uint16_t length, bool first, json_object *json)
{
json_object *json_node = NULL;
bool sub_first = true;
uint8_t *lim = pnt + length;
uint16_t sub_type, sub_length;
if (json) {
json_node = json_object_new_object();
if (type == BGP_LS_TLV_LOCAL_NODE_DESCRIPTORS)
json_object_object_add(json, "localNode", json_node);
else
json_object_object_add(json, "remoteNode", json_node);
} else {
if (type == BGP_LS_TLV_LOCAL_NODE_DESCRIPTORS)
snprintf(buf, size, "%sLocal {", first ? "" : " ");
else
snprintf(buf, size, "%sRemote {", first ? "" : " ");
size -= strlen(buf);
buf += strlen(buf);
}
for (; pnt < lim; pnt += sub_length) {
sub_type = pnt_decode16(&pnt);
sub_length = pnt_decode16(&pnt);
if (pnt + sub_length > lim)
/* bad length */
return false;
bgp_linkstate_nlri_value_display(buf, size, pnt, nlri_type,
sub_type, sub_length,
sub_first, json_node);
if (!json) {
size -= strlen(buf);
buf += strlen(buf);
sub_first = false;
}
}
if (!json)
snprintf(buf, size, "}");
return true;
}
static bool bgp_linkstate_nlri_value_display(char *buf, size_t size,
uint8_t *pnt, uint16_t nlri_type,
uint16_t type, uint16_t length,
bool first, json_object *json)
{
struct in_addr ipv4 = {0};
struct in6_addr ipv6 = {0};
uint8_t mask_length;
if (!bgp_ls_tlv_check_size(type, length) && !json) {
bgp_linkstate_nlri_hexa_display(buf, size, pnt, type, length,
first, json);
return true;
}
switch (type) {
case BGP_LS_TLV_LOCAL_NODE_DESCRIPTORS:
case BGP_LS_TLV_REMOTE_NODE_DESCRIPTORS:
return bgp_linkstate_nlri_node_descriptor_display(
buf, size, pnt, nlri_type, type, length, first, json);
case BGP_LS_TLV_AUTONOMOUS_SYSTEM:
if (json)
json_object_int_add(json, "as", pnt_decode32(&pnt));
else
snprintf(buf, size, "%sAS:%u", first ? "" : " ",
pnt_decode32(&pnt));
break;
case BGP_LS_TLV_BGP_LS_IDENTIFIER:
if (json)
json_object_int_add(json, "identifier",
pnt_decode32(&pnt));
else
snprintf(buf, size, "%sID:%u", first ? "" : " ",
pnt_decode32(&pnt));
break;
case BGP_LS_TLV_OSPF_AREA_ID:
if (json)
json_object_int_add(json, "area", pnt_decode32(&pnt));
else
snprintf(buf, size, "%sArea:%u", first ? "" : " ",
pnt_decode32(&pnt));
break;
case BGP_LS_TLV_IGP_ROUTER_ID:
switch (length) {
case BGP_LS_TLV_IGP_ROUTER_ID_ISIS_NON_PSEUDOWIRE_SIZE:
if (json)
json_object_string_addf(json, "routerID",
"%pSY", pnt);
else
snprintfrr(buf, size, "%sRtr:%pSY",
first ? "" : " ", pnt);
break;
case BGP_LS_TLV_IGP_ROUTER_ID_ISIS_PSEUDOWIRE_SIZE:
if (json)
json_object_string_addf(json, "routerID",
"%pPN", pnt);
else
snprintfrr(buf, size, "%sRtr:%pPN",
first ? "" : " ", pnt);
break;
case BGP_LS_TLV_IGP_ROUTER_ID_OSPF_NON_PSEUDOWIRE_SIZE:
if (json)
json_object_string_addf(json, "routerID",
"%pI4",
(in_addr_t *)pnt);
else
snprintfrr(buf, size, "%sRtr:%pI4",
first ? "" : " ", (in_addr_t *)pnt);
break;
case BGP_LS_TLV_IGP_ROUTER_ID_OSPF_PSEUDOWIRE_SIZE:
if (json)
json_object_string_addf(json, "routerID",
"%pI4:%pI4",
(in_addr_t *)pnt,
((in_addr_t *)pnt + 1));
else
snprintfrr(buf, size, "%sRtr:%pI4:%pI4",
first ? "" : " ", (in_addr_t *)pnt,
((in_addr_t *)pnt + 1));
break;
default:
bgp_linkstate_nlri_hexa_display(buf, size, pnt, type,
length, first, json);
}
break;
case BGP_LS_TLV_LINK_LOCAL_REMOTE_IDENTIFIERS:
if (json)
json_object_int_add(json, "localRemoteID",
pnt_decode16(&pnt));
else
snprintf(buf, size, "%sLocal/remote:%hu",
first ? "" : " ", pnt_decode16(&pnt));
break;
case BGP_LS_TLV_IPV4_INTERFACE_ADDRESS:
if (json)
json_object_string_addf(json, "interfaceIPv4", "%pI4",
(in_addr_t *)pnt);
else
snprintfrr(buf, size, "%sIPv4:%pI4", first ? "" : " ",
(in_addr_t *)pnt);
break;
case BGP_LS_TLV_IPV4_NEIGHBOR_ADDRESS:
if (json)
json_object_string_addf(json, "neighborIPv4", "%pI4",
(in_addr_t *)pnt);
else
snprintfrr(buf, size, "%sNeigh-IPv4:%pI4",
first ? "" : " ", (in_addr_t *)pnt);
break;
case BGP_LS_TLV_IPV6_INTERFACE_ADDRESS:
if (json)
json_object_string_addf(json, "interfaceIPv6", "%pI6",
(struct in6_addr *)pnt);
else
snprintfrr(buf, size, "%sIPv6:%pI6", first ? "" : " ",
(struct in6_addr *)pnt);
break;
case BGP_LS_TLV_IPV6_NEIGHBOR_ADDRESS:
if (json)
json_object_string_addf(json, "neighborIPv6", "%pI6",
(struct in6_addr *)pnt);
else
snprintfrr(buf, size, "%sNeigh-IPv6:%pI6",
first ? "" : " ", (struct in6_addr *)pnt);
break;
case BGP_LS_TLV_MULTI_TOPOLOGY_ID:
bgp_linkstate_nlri_mtid_display(buf, size, pnt, type, length,
first, json);
break;
case BGP_LS_TLV_OSPF_ROUTE_TYPE:
if (json)
json_object_int_add(json, "ospfRouteType",
pnt_decode8(&pnt));
else
snprintf(buf, size, "%sOSPF-Route-Type:%u",
first ? "" : " ", pnt_decode8(&pnt));
break;
case BGP_LS_TLV_IP_REACHABILITY_INFORMATION:
mask_length = pnt_decode8(&pnt);
if (nlri_type == BGP_LINKSTATE_PREFIX4) {
memcpy(&ipv4.s_addr, pnt, length - sizeof(mask_length));
if (json)
json_object_string_addf(json, "ipReachability",
"%pI4/%u", &ipv4,
mask_length);
else
snprintfrr(buf, size, "%sIPv4:%pI4/%u",
first ? "" : " ", &ipv4,
mask_length);
} else if (nlri_type == BGP_LINKSTATE_PREFIX6) {
memcpy(&ipv6, pnt, length - sizeof(mask_length));
if (json)
json_object_string_addf(json, "ipReachability",
"%pI6/%u", &ipv6,
mask_length);
else
snprintfrr(buf, size, "%sIPv6:%pI6/%u",
first ? "" : " ", &ipv6,
mask_length);
} else
bgp_linkstate_nlri_hexa_display(buf, size, pnt, type,
length, first, json);
break;
default:
bgp_linkstate_nlri_hexa_display(buf, size, pnt, type, length,
first, json);
}
return true;
}
char *bgp_linkstate_nlri_prefix_display(char *buf, size_t size,
uint16_t nlri_type, uintptr_t ptr,
uint16_t len)
{
uint8_t *pnt = (uint8_t *)ptr;
uint8_t *lim = pnt + len;
uint16_t type, length;
char *cbuf = buf, *cbuf2;
uint8_t proto;
bool ret;
bool first = true;
proto = pnt_decode8(&pnt);
snprintfrr(buf, size, "%s %s ID:0x%" PRIx64 " {",
bgp_linkstate_nlri_type_2str(nlri_type),
bgp_ls_print_nlri_proto(proto), pnt_decode64(&pnt));
size -= strlen(buf);
buf += strlen(buf);
cbuf2 = buf;
for (; pnt < lim; pnt += length) {
type = pnt_decode16(&pnt);
length = pnt_decode16(&pnt);
if (pnt + length > lim) {
/* bad length */
snprintf(cbuf2, size, "Bad format}");
return cbuf;
}
ret = bgp_linkstate_nlri_value_display(
buf, size, pnt, nlri_type, type, length, first, NULL);
if (!ret) {
/* bad length */
snprintf(cbuf2, size, "Bad format}");
return cbuf;
}
size -= strlen(buf);
buf += strlen(buf);
first = false;
}
snprintf(buf, size, "}");
return cbuf;
}
void bgp_linkstate_nlri_prefix_json(json_object *json, uint16_t nlri_type,
uintptr_t ptr, uint16_t len)
{
json_object *json_nlri = json_object_new_object();
uint8_t *pnt = (uint8_t *)ptr;
uint8_t *lim = pnt + len;
uint16_t type, length;
uint8_t proto;
bool ret;
proto = pnt_decode8(&pnt);
json_object_object_add(json, "linkStateNLRI", json_nlri);
json_object_string_add(json_nlri, "nlriType",
bgp_linkstate_nlri_type_2str(nlri_type));
json_object_string_add(json_nlri, "protocol",
bgp_ls_print_nlri_proto(proto));
json_object_string_addf(json_nlri, "identifier", "0x%" PRIx64,
pnt_decode64(&pnt));
for (; pnt < lim; pnt += length) {
type = pnt_decode16(&pnt);
length = pnt_decode16(&pnt);
if (pnt + length > lim)
/* bad length */
return;
ret = bgp_linkstate_nlri_value_display(NULL, 0, pnt, nlri_type,
type, length, false,
json_nlri);
if (!ret)
/* bad length */
return;
}
}
static uint8_t *bgp_linkstate_tlv_binary_string(char *buf, size_t buf_sz,
uint8_t *pnt, uint16_t length)
{
uint8_t tmp;
int i, j;
for (i = 0; i < length; i++) {
if (i == 0)
snprintf(buf, buf_sz, "0b");
else
snprintf(buf + strlen(buf), buf_sz - strlen(buf), " ");
tmp = pnt_decode8(&pnt);
for (j = 7; j >= 0; j--)
snprintf(buf + strlen(buf), buf_sz - strlen(buf), "%d",
(tmp >> j) & 1);
}
return pnt;
}
/* dump bits. Their meaning is not decoded */
static uint8_t *bgp_linkstate_tlv_binary_display(struct vty *vty, uint8_t *pnt,
uint16_t length,
json_object *json)
{
char buf[290];
uint8_t tmp;
int i, j;
if (json) {
pnt = bgp_linkstate_tlv_binary_string(buf, sizeof(buf), pnt,
length);
json_object_string_add(json, "data", buf);
return pnt;
}
for (i = 0; i < length; i++) {
if (i == 0)
vty_out(vty, "0b");
else
vty_out(vty, " ");
tmp = pnt_decode8(&pnt);
for (j = 7; j >= 0; j--)
vty_out(vty, "%d", (tmp >> j) & 1);
}
vty_out(vty, "\n");
return pnt;
}
static void bgp_linkstate_tlv_hexa_display(struct vty *vty, uint8_t *pnt,
uint16_t length, json_object *json)
{
uint8_t *lim = pnt + length;
char buf[290];
int i;
if (json) {
snprintf(buf, sizeof(buf), "0x");
for (; pnt < lim; pnt++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
"%02x", *pnt);
json_object_string_add(json, "data", buf);
return;
}
vty_out(vty, "0x");
for (i = 0; pnt < lim; pnt++, i++) {
if (i != 0 && i % 8 == 0)
vty_out(vty, " ");
vty_out(vty, "%02x", *pnt);
}
vty_out(vty, "\n");
}
static void bgp_linkstate_tlv_integer_list_display(struct vty *vty,
uint8_t *pnt,
uint16_t length,
uint8_t integer_sz,
json_object *json)
{
json_object *json_array = NULL;
int i;
if (json) {
json_array = json_object_new_array();
json_object_object_add(json, "data", json_array);
}
for (i = 0; i < (length / integer_sz); i++) {
switch (integer_sz) {
case 1:
if (json) {
json_object_array_add(
json_array,
json_object_new_int(pnt_decode8(&pnt)));
break;
}
vty_out(vty, "%s%u", i == 0 ? "" : ", ",
pnt_decode8(&pnt));
break;
case 2:
if (json) {
json_object_array_add(
json_array,
json_object_new_int(
pnt_decode16(&pnt)));
break;
}
vty_out(vty, "%s%u", i == 0 ? "" : ", ",
pnt_decode16(&pnt));
break;
case 4:
if (json) {
json_object_array_add(
json_array,
json_object_new_int(
pnt_decode32(&pnt)));
break;
}
vty_out(vty, "%s%u", i == 0 ? "" : ", ",
pnt_decode32(&pnt));
break;
case 8:
if (json) {
json_object_array_add(
json_array,
json_object_new_int64(
pnt_decode64(&pnt)));
break;
}
vty_out(vty, "%s%" PRIu64, i == 0 ? "" : ", ",
pnt_decode64(&pnt));
break;
}
}
vty_out(vty, "\n");
}
static void bgp_linkstate_tlv_integer_display(struct vty *vty, uint8_t *pnt,
uint16_t length,
json_object *json)
{
switch (length) {
case 1:
if (json) {
json_object_int_add(json, "data", pnt_decode8(&pnt));
break;
}
vty_out(vty, "%u\n", pnt_decode8(&pnt));
break;
case 2:
if (json) {
json_object_int_add(json, "data", pnt_decode16(&pnt));
break;
}
vty_out(vty, "%u\n", pnt_decode16(&pnt));
break;
case 3:
if (json) {
json_object_int_add(json, "data", pnt_decode24(&pnt));
break;
}
vty_out(vty, "%u\n", pnt_decode24(&pnt));
break;
case 4:
if (json) {
json_object_int_add(json, "data", pnt_decode32(&pnt));
break;
}
vty_out(vty, "%u\n", pnt_decode32(&pnt));
break;
case 8:
if (json) {
json_object_int_add(json, "data", pnt_decode64(&pnt));
break;
}
vty_out(vty, "%" PRIu64 "\n", pnt_decode64(&pnt));
break;
}
}
static void bgp_linkstate_tlv_ipv4_6_address_display(struct vty *vty,
uint8_t *pnt,
uint16_t length,
json_object *json)
{
if (length == IPV4_MAX_BYTELEN) {
if (json) {
json_object_string_addf(json, "data", "%pI4",
(in_addr_t *)pnt);
return;
}
vty_out(vty, "%pI4\n", (in_addr_t *)pnt);
} else if (length == IPV6_MAX_BYTELEN) {
if (json) {
json_object_string_addf(json, "data", "%pI6",
(struct in6_addr *)pnt);
return;
}
vty_out(vty, "%pI6\n", (struct in6_addr *)pnt);
} else
bgp_linkstate_tlv_hexa_display(vty, pnt, length, json);
}
static void bgp_linkstate_tlv_name_display(struct vty *vty, uint8_t *pnt,
uint16_t length, json_object *json)
{
char buf[length + 1];
int i;
buf[0] = '\0';
for (i = 0; i < length; i++)
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c",
pnt_decode8(&pnt));
if (json)
json_object_string_add(json, "data", buf);
else
vty_out(vty, "%s\n", buf);
}
static void bgp_linkstate_tlv_msd_display(struct vty *vty, uint8_t *pnt,
uint16_t length, int indent,
json_object *json)
{
json_object *json_array = NULL;
json_object *json_data = NULL;
int i;
if (json) {
json_array = json_object_new_array();
json_object_object_add(json, "data", json_array);
}
for (i = 0; i < (length / 2); i++) {
if (json) {
json_data = json_object_new_object();
json_object_array_add(json_array, json_data);
json_object_int_add(json_data, "type",
pnt_decode8(&pnt));
json_object_int_add(json_data, "value",
pnt_decode8(&pnt));
continue;
}
vty_out(vty, "\n%*sType: %u Value: %u", indent, "",
pnt_decode8(&pnt), pnt_decode8(&pnt));
}
if (!json)
vty_out(vty, "\n");
}
static void bgp_linkstate_tlv_bandwidth_display(struct vty *vty, uint8_t *pnt,
uint16_t length,
json_object *json)
{
union {
float r;
uint32_t d;
} float_uint32;
float_uint32.d = pnt_decode32(&pnt);
if (json) {
json_object_double_add(json, "data", float_uint32.r);
json_object_string_add(json, "dataUnit", "bps");
return;
}
vty_out(vty, "%g Mbps\n", float_uint32.r / 1000 / 1000 * 8);
}
static void bgp_linkstate_tlv_unreserved_bandwidth_display(struct vty *vty,
uint8_t *pnt,
uint16_t length,
int indent,
json_object *json)
{
json_object *json_data = NULL;
union {
float r;
uint32_t d;
} float_uint32;
char buf[3];
int i;
if (json) {
json_data = json_object_new_object();
json_object_object_add(json, "data", json_data);
for (i = 0; i < MAX_CLASS_TYPE; i++) {
float_uint32.d = pnt_decode32(&pnt);
snprintf(buf, sizeof(buf), "%d", i);
json_object_double_add(json_data, buf, float_uint32.r);
}
json_object_string_add(json, "dataUnit", "bps");
return;
}