forked from FRRouting/frr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbgp_evpn_vty.c
7647 lines (6586 loc) · 195 KB
/
bgp_evpn_vty.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
/* Ethernet-VPN Packet and vty Processing File
* Copyright (C) 2017 6WIND
*
* This file is part of FRRouting
*/
#include <zebra.h>
#include "command.h"
#include "prefix.h"
#include "lib/json.h"
#include "lib/printfrr.h"
#include "lib/vxlan.h"
#include "stream.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_vpn.h"
#include "bgpd/bgp_evpn_vty.h"
#include "bgpd/bgp_evpn.h"
#include "bgpd/bgp_evpn_private.h"
#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_vty.h"
#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_ecommunity.h"
#include "bgpd/bgp_lcommunity.h"
#include "bgpd/bgp_community.h"
#define SHOW_DISPLAY_STANDARD 0
#define SHOW_DISPLAY_TAGS 1
#define SHOW_DISPLAY_OVERLAY 2
#define VNI_STR_LEN 32
/*
* Context for VNI hash walk - used by callbacks.
*/
struct vni_walk_ctx {
struct bgp *bgp;
struct vty *vty;
struct in_addr vtep_ip;
json_object *json;
int detail;
int type;
bool mac_table;
};
int argv_find_and_parse_oly_idx(struct cmd_token **argv, int argc, int *oly_idx,
enum overlay_index_type *oly)
{
*oly = OVERLAY_INDEX_TYPE_NONE;
if (argv_find(argv, argc, "gateway-ip", oly_idx))
*oly = OVERLAY_INDEX_GATEWAY_IP;
return 1;
}
static void display_vrf_import_rt(struct vty *vty, struct vrf_irt_node *irt,
json_object *json)
{
const uint8_t *pnt;
uint8_t type, sub_type;
struct ecommunity_as eas;
struct ecommunity_ip eip;
struct listnode *node, *nnode;
struct bgp *tmp_bgp_vrf = NULL;
json_object *json_rt = NULL;
json_object *json_vrfs = NULL;
char rt_buf[RT_ADDRSTRLEN];
if (json) {
json_rt = json_object_new_object();
json_vrfs = json_object_new_array();
}
pnt = (uint8_t *)&irt->rt.val;
type = *pnt++;
sub_type = *pnt++;
if (sub_type != ECOMMUNITY_ROUTE_TARGET)
return;
memset(&eas, 0, sizeof(eas));
switch (type) {
case ECOMMUNITY_ENCODE_AS:
eas.as = (*pnt++ << 8);
eas.as |= (*pnt++);
ptr_get_be32(pnt, &eas.val);
snprintf(rt_buf, sizeof(rt_buf), "%u:%u", eas.as, eas.val);
if (json)
json_object_string_add(json_rt, "rt", rt_buf);
else
vty_out(vty, "Route-target: %s", rt_buf);
break;
case ECOMMUNITY_ENCODE_IP:
memcpy(&eip.ip, pnt, 4);
pnt += 4;
eip.val = (*pnt++ << 8);
eip.val |= (*pnt++);
snprintfrr(rt_buf, sizeof(rt_buf), "%pI4:%u", &eip.ip, eip.val);
if (json)
json_object_string_add(json_rt, "rt", rt_buf);
else
vty_out(vty, "Route-target: %s", rt_buf);
break;
case ECOMMUNITY_ENCODE_AS4:
pnt = ptr_get_be32(pnt, &eas.val);
eas.val = (*pnt++ << 8);
eas.val |= (*pnt++);
snprintf(rt_buf, sizeof(rt_buf), "%u:%u", eas.as, eas.val);
if (json)
json_object_string_add(json_rt, "rt", rt_buf);
else
vty_out(vty, "Route-target: %s", rt_buf);
break;
default:
return;
}
if (!json) {
vty_out(vty,
"\nList of VRFs importing routes with this route-target:\n");
}
for (ALL_LIST_ELEMENTS(irt->vrfs, node, nnode, tmp_bgp_vrf)) {
if (json)
json_object_array_add(
json_vrfs,
json_object_new_string(
vrf_id_to_name(tmp_bgp_vrf->vrf_id)));
else
vty_out(vty, " %s\n",
vrf_id_to_name(tmp_bgp_vrf->vrf_id));
}
if (json) {
json_object_object_add(json_rt, "vrfs", json_vrfs);
json_object_object_add(json, rt_buf, json_rt);
}
}
static void show_vrf_import_rt_entry(struct hash_bucket *bucket, void *args[])
{
json_object *json = NULL;
struct vty *vty = NULL;
struct vrf_irt_node *irt = (struct vrf_irt_node *)bucket->data;
vty = (struct vty *)args[0];
json = (struct json_object *)args[1];
display_vrf_import_rt(vty, irt, json);
}
static void display_import_rt(struct vty *vty, struct irt_node *irt,
json_object *json)
{
const uint8_t *pnt;
uint8_t type, sub_type;
struct ecommunity_as eas;
struct ecommunity_ip eip;
struct listnode *node, *nnode;
struct bgpevpn *tmp_vpn;
json_object *json_rt = NULL;
json_object *json_vnis = NULL;
char rt_buf[RT_ADDRSTRLEN];
if (json) {
json_rt = json_object_new_object();
json_vnis = json_object_new_array();
}
/* TODO: This needs to go into a function */
pnt = (uint8_t *)&irt->rt.val;
type = *pnt++;
sub_type = *pnt++;
if (sub_type != ECOMMUNITY_ROUTE_TARGET)
return;
memset(&eas, 0, sizeof(eas));
switch (type) {
case ECOMMUNITY_ENCODE_AS:
eas.as = (*pnt++ << 8);
eas.as |= (*pnt++);
ptr_get_be32(pnt, &eas.val);
snprintf(rt_buf, sizeof(rt_buf), "%u:%u", eas.as, eas.val);
if (json)
json_object_string_add(json_rt, "rt", rt_buf);
else
vty_out(vty, "Route-target: %s", rt_buf);
break;
case ECOMMUNITY_ENCODE_IP:
memcpy(&eip.ip, pnt, 4);
pnt += 4;
eip.val = (*pnt++ << 8);
eip.val |= (*pnt++);
snprintfrr(rt_buf, sizeof(rt_buf), "%pI4:%u", &eip.ip, eip.val);
if (json)
json_object_string_add(json_rt, "rt", rt_buf);
else
vty_out(vty, "Route-target: %s", rt_buf);
break;
case ECOMMUNITY_ENCODE_AS4:
pnt = ptr_get_be32(pnt, &eas.val);
eas.val = (*pnt++ << 8);
eas.val |= (*pnt++);
snprintf(rt_buf, sizeof(rt_buf), "%u:%u", eas.as, eas.val);
if (json)
json_object_string_add(json_rt, "rt", rt_buf);
else
vty_out(vty, "Route-target: %s", rt_buf);
break;
default:
return;
}
if (!json) {
vty_out(vty,
"\nList of VNIs importing routes with this route-target:\n");
}
for (ALL_LIST_ELEMENTS(irt->vnis, node, nnode, tmp_vpn)) {
if (json)
json_object_array_add(
json_vnis, json_object_new_int(tmp_vpn->vni));
else
vty_out(vty, " %u\n", tmp_vpn->vni);
}
if (json) {
json_object_object_add(json_rt, "vnis", json_vnis);
json_object_object_add(json, rt_buf, json_rt);
}
}
static void show_import_rt_entry(struct hash_bucket *bucket, void *args[])
{
json_object *json = NULL;
struct vty *vty = NULL;
struct irt_node *irt = (struct irt_node *)bucket->data;
vty = args[0];
json = args[1];
display_import_rt(vty, irt, json);
return;
}
static void bgp_evpn_show_route_rd_header(struct vty *vty,
struct bgp_dest *rd_dest,
json_object *json, char *rd_str,
int len)
{
uint16_t type;
struct rd_as rd_as;
struct rd_ip rd_ip;
const uint8_t *pnt;
const struct prefix *p = bgp_dest_get_prefix(rd_dest);
pnt = p->u.val;
/* Decode RD type. */
type = decode_rd_type(pnt);
if (!json)
vty_out(vty, "Route Distinguisher: ");
switch (type) {
case RD_TYPE_AS:
decode_rd_as(pnt + 2, &rd_as);
snprintf(rd_str, len, "%u:%d", rd_as.as, rd_as.val);
if (json)
json_object_string_add(json, "rd", rd_str);
else
vty_out(vty, "%s\n", rd_str);
break;
case RD_TYPE_AS4:
decode_rd_as4(pnt + 2, &rd_as);
snprintf(rd_str, len, "%u:%d", rd_as.as, rd_as.val);
if (json)
json_object_string_add(json, "rd", rd_str);
else
vty_out(vty, "%s\n", rd_str);
break;
case RD_TYPE_IP:
decode_rd_ip(pnt + 2, &rd_ip);
snprintfrr(rd_str, len, "%pI4:%d", &rd_ip.ip, rd_ip.val);
if (json)
json_object_string_add(json, "rd", rd_str);
else
vty_out(vty, "%s\n", rd_str);
break;
default:
if (json) {
snprintf(rd_str, len, "Unknown");
json_object_string_add(json, "rd", rd_str);
} else {
snprintf(rd_str, len, "Unknown RD type");
vty_out(vty, "%s\n", rd_str);
}
break;
}
}
static void bgp_evpn_show_route_header(struct vty *vty, struct bgp *bgp,
uint64_t tbl_ver, json_object *json)
{
char ri_header[] =
" Network Next Hop Metric LocPrf Weight Path\n";
if (json)
return;
vty_out(vty,
"BGP table version is %" PRIu64 ", local router ID is %pI4\n",
tbl_ver, &bgp->router_id);
vty_out(vty,
"Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n");
vty_out(vty, "Origin codes: i - IGP, e - EGP, ? - incomplete\n");
vty_out(vty,
"EVPN type-1 prefix: [1]:[EthTag]:[ESI]:[IPlen]:[VTEP-IP]:[Frag-id]\n");
vty_out(vty,
"EVPN type-2 prefix: [2]:[EthTag]:[MAClen]:[MAC]:[IPlen]:[IP]\n");
vty_out(vty, "EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP]\n");
vty_out(vty, "EVPN type-4 prefix: [4]:[ESI]:[IPlen]:[OrigIP]\n");
vty_out(vty, "EVPN type-5 prefix: [5]:[EthTag]:[IPlen]:[IP]\n\n");
vty_out(vty, "%s", ri_header);
}
static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf,
json_object *json)
{
char *ecom_str;
struct listnode *node, *nnode;
struct vrf_route_target *l3rt;
struct bgp *bgp_evpn = NULL;
json_object *json_import_rtl = NULL;
json_object *json_export_rtl = NULL;
bgp_evpn = bgp_get_evpn();
json_import_rtl = json_export_rtl = 0;
if (json) {
json_import_rtl = json_object_new_array();
json_export_rtl = json_object_new_array();
json_object_int_add(json, "vni", bgp_vrf->l3vni);
json_object_string_add(json, "type", "L3");
json_object_string_add(json, "inKernel", "True");
json_object_string_addf(json, "rd",
BGP_RD_AS_FORMAT(bgp_vrf->asnotation),
&bgp_vrf->vrf_prd);
json_object_string_addf(json, "originatorIp", "%pI4",
&bgp_vrf->originator_ip);
if (bgp_evpn && bgp_evpn->evpn_info) {
ecom_str = ecommunity_ecom2str(
bgp_evpn->evpn_info->soo,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
json_object_string_add(json, "siteOfOrigin", ecom_str);
ecommunity_strfree(&ecom_str);
}
json_object_string_add(json, "advertiseGatewayMacip", "n/a");
json_object_string_add(json, "advertiseSviMacIp", "n/a");
if (bgp_vrf->evpn_info) {
json_object_string_add(json, "advertisePip",
bgp_vrf->evpn_info->advertise_pip
? "Enabled"
: "Disabled");
json_object_string_addf(json, "sysIP", "%pI4",
&bgp_vrf->evpn_info->pip_ip);
json_object_string_addf(json, "sysMac", "%pEA",
&bgp_vrf->evpn_info->pip_rmac);
}
json_object_string_addf(json, "rmac", "%pEA", &bgp_vrf->rmac);
} else {
vty_out(vty, "VNI: %d", bgp_vrf->l3vni);
vty_out(vty, " (known to the kernel)");
vty_out(vty, "\n");
vty_out(vty, " Type: %s\n", "L3");
vty_out(vty, " Tenant VRF: %s\n",
vrf_id_to_name(bgp_vrf->vrf_id));
vty_out(vty, " RD: ");
vty_out(vty, BGP_RD_AS_FORMAT(bgp_vrf->asnotation),
&bgp_vrf->vrf_prd);
vty_out(vty, "\n");
vty_out(vty, " Originator IP: %pI4\n",
&bgp_vrf->originator_ip);
if (bgp_evpn && bgp_evpn->evpn_info) {
ecom_str = ecommunity_ecom2str(
bgp_evpn->evpn_info->soo,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
vty_out(vty, " MAC-VRF Site-of-Origin: %s\n",
ecom_str);
ecommunity_strfree(&ecom_str);
}
vty_out(vty, " Advertise-gw-macip : %s\n", "n/a");
vty_out(vty, " Advertise-svi-macip : %s\n", "n/a");
if (bgp_vrf->evpn_info) {
vty_out(vty, " Advertise-pip: %s\n",
bgp_vrf->evpn_info->advertise_pip ? "Yes"
: "No");
vty_out(vty, " System-IP: %pI4\n",
&bgp_vrf->evpn_info->pip_ip);
vty_out(vty, " System-MAC: %pEA\n",
&bgp_vrf->evpn_info->pip_rmac);
}
vty_out(vty, " Router-MAC: %pEA\n", &bgp_vrf->rmac);
}
if (!json)
vty_out(vty, " Import Route Target:\n");
for (ALL_LIST_ELEMENTS(bgp_vrf->vrf_import_rtl, node, nnode, l3rt)) {
ecom_str = ecommunity_ecom2str(l3rt->ecom,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (json)
json_object_array_add(json_import_rtl,
json_object_new_string(ecom_str));
else
vty_out(vty, " %s\n", ecom_str);
ecommunity_strfree(&ecom_str);
}
if (json)
json_object_object_add(json, "importRts", json_import_rtl);
else
vty_out(vty, " Export Route Target:\n");
for (ALL_LIST_ELEMENTS(bgp_vrf->vrf_export_rtl, node, nnode, l3rt)) {
ecom_str = ecommunity_ecom2str(l3rt->ecom,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (json)
json_object_array_add(json_export_rtl,
json_object_new_string(ecom_str));
else
vty_out(vty, " %s\n", ecom_str);
ecommunity_strfree(&ecom_str);
}
if (json)
json_object_object_add(json, "exportRts", json_export_rtl);
}
static void display_vni(struct vty *vty, struct bgpevpn *vpn, json_object *json)
{
char *ecom_str;
struct listnode *node, *nnode;
struct ecommunity *ecom;
json_object *json_import_rtl = NULL;
json_object *json_export_rtl = NULL;
struct bgp *bgp_evpn;
enum asnotation_mode asnotation;
bgp_evpn = bgp_get_evpn();
asnotation = bgp_get_asnotation(bgp_evpn);
if (json) {
json_import_rtl = json_object_new_array();
json_export_rtl = json_object_new_array();
json_object_int_add(json, "vni", vpn->vni);
json_object_string_add(json, "type", "L2");
json_object_string_add(json, "inKernel",
is_vni_live(vpn) ? "True" : "False");
json_object_string_addf(
json, "rd", BGP_RD_AS_FORMAT(asnotation), &vpn->prd);
json_object_string_addf(json, "originatorIp", "%pI4",
&vpn->originator_ip);
json_object_string_addf(json, "mcastGroup", "%pI4",
&vpn->mcast_grp);
if (bgp_evpn && bgp_evpn->evpn_info) {
ecom_str = ecommunity_ecom2str(
bgp_evpn->evpn_info->soo,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
json_object_string_add(json, "siteOfOrigin", ecom_str);
ecommunity_strfree(&ecom_str);
}
/* per vni knob is enabled -- Enabled
* Global knob is enabled -- Active
* default -- Disabled
*/
if (!vpn->advertise_gw_macip &&
bgp_evpn && bgp_evpn->advertise_gw_macip)
json_object_string_add(json, "advertiseGatewayMacip",
"Active");
else if (vpn->advertise_gw_macip)
json_object_string_add(json, "advertiseGatewayMacip",
"Enabled");
else
json_object_string_add(json, "advertiseGatewayMacip",
"Disabled");
if (!vpn->advertise_svi_macip && bgp_evpn &&
bgp_evpn->evpn_info &&
bgp_evpn->evpn_info->advertise_svi_macip)
json_object_string_add(json, "advertiseSviMacIp",
"Active");
else if (vpn->advertise_svi_macip)
json_object_string_add(json, "advertiseSviMacIp",
"Enabled");
else
json_object_string_add(json, "advertiseSviMacIp",
"Disabled");
json_object_string_add(
json, "sviInterface",
ifindex2ifname(vpn->svi_ifindex, vpn->tenant_vrf_id));
} else {
vty_out(vty, "VNI: %u", vpn->vni);
if (is_vni_live(vpn))
vty_out(vty, " (known to the kernel)");
vty_out(vty, "\n");
vty_out(vty, " Type: %s\n", "L2");
vty_out(vty, " Tenant-Vrf: %s\n",
vrf_id_to_name(vpn->tenant_vrf_id));
vty_out(vty, " RD: ");
vty_out(vty, BGP_RD_AS_FORMAT(asnotation), &vpn->prd);
vty_out(vty, "\n");
vty_out(vty, " Originator IP: %pI4\n", &vpn->originator_ip);
vty_out(vty, " Mcast group: %pI4\n", &vpn->mcast_grp);
if (bgp_evpn && bgp_evpn->evpn_info) {
ecom_str = ecommunity_ecom2str(
bgp_evpn->evpn_info->soo,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
vty_out(vty, " MAC-VRF Site-of-Origin: %s\n",
ecom_str);
ecommunity_strfree(&ecom_str);
}
if (!vpn->advertise_gw_macip &&
bgp_evpn && bgp_evpn->advertise_gw_macip)
vty_out(vty, " Advertise-gw-macip : %s\n",
"Active");
else if (vpn->advertise_gw_macip)
vty_out(vty, " Advertise-gw-macip : %s\n",
"Enabled");
else
vty_out(vty, " Advertise-gw-macip : %s\n",
"Disabled");
if (!vpn->advertise_svi_macip && bgp_evpn &&
bgp_evpn->evpn_info &&
bgp_evpn->evpn_info->advertise_svi_macip)
vty_out(vty, " Advertise-svi-macip : %s\n",
"Active");
else if (vpn->advertise_svi_macip)
vty_out(vty, " Advertise-svi-macip : %s\n",
"Enabled");
else
vty_out(vty, " Advertise-svi-macip : %s\n",
"Disabled");
vty_out(vty, " SVI interface : %s\n",
ifindex2ifname(vpn->svi_ifindex, vpn->tenant_vrf_id));
}
if (!json)
vty_out(vty, " Import Route Target:\n");
for (ALL_LIST_ELEMENTS(vpn->import_rtl, node, nnode, ecom)) {
ecom_str = ecommunity_ecom2str(ecom,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (json)
json_object_array_add(json_import_rtl,
json_object_new_string(ecom_str));
else
vty_out(vty, " %s\n", ecom_str);
ecommunity_strfree(&ecom_str);
}
if (json)
json_object_object_add(json, "importRts", json_import_rtl);
else
vty_out(vty, " Export Route Target:\n");
for (ALL_LIST_ELEMENTS(vpn->export_rtl, node, nnode, ecom)) {
ecom_str = ecommunity_ecom2str(ecom,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (json)
json_object_array_add(json_export_rtl,
json_object_new_string(ecom_str));
else
vty_out(vty, " %s\n", ecom_str);
ecommunity_strfree(&ecom_str);
}
if (json)
json_object_object_add(json, "exportRts", json_export_rtl);
}
static void show_esi_routes(struct bgp *bgp,
struct bgp_evpn_es *es,
struct vty *vty,
json_object *json)
{
int header = 1;
struct bgp_dest *dest;
struct bgp_path_info *pi;
uint32_t prefix_cnt, path_cnt;
uint64_t tbl_ver;
prefix_cnt = path_cnt = 0;
tbl_ver = es->route_table->version;
for (dest = bgp_table_top(es->route_table); dest;
dest = bgp_route_next(dest)) {
int add_prefix_to_json = 0;
json_object *json_paths = NULL;
json_object *json_prefix = NULL;
const struct prefix *p = bgp_dest_get_prefix(dest);
if (json)
json_prefix = json_object_new_object();
pi = bgp_dest_get_bgp_path_info(dest);
if (pi) {
/* Overall header/legend displayed once. */
if (header) {
bgp_evpn_show_route_header(vty, bgp,
tbl_ver, json);
header = 0;
}
prefix_cnt++;
}
if (json)
json_paths = json_object_new_array();
/* For EVPN, the prefix is displayed for each path (to fit in
* with code that already exists).
*/
for (; pi; pi = pi->next) {
json_object *json_path = NULL;
if (json)
json_path = json_object_new_array();
route_vty_out(vty, p, pi, 0, SAFI_EVPN, json_path,
false);
if (json)
json_object_array_add(json_paths, json_path);
path_cnt++;
add_prefix_to_json = 1;
}
if (json) {
if (add_prefix_to_json) {
json_object_string_addf(json_prefix, "prefix",
"%pFX", p);
json_object_int_add(json_prefix, "prefixLen",
p->prefixlen);
json_object_object_add(json_prefix, "paths",
json_paths);
json_object_object_addf(json, json_prefix,
"%pFX", p);
} else {
json_object_free(json_paths);
json_object_free(json_prefix);
json_paths = NULL;
json_prefix = NULL;
}
}
}
if (json) {
json_object_int_add(json, "numPrefix", prefix_cnt);
json_object_int_add(json, "numPaths", path_cnt);
} else {
if (prefix_cnt == 0)
vty_out(vty, "No EVPN prefixes exist for this ESI\n");
else
vty_out(vty, "\nDisplayed %u prefixes (%u paths)\n",
prefix_cnt, path_cnt);
}
}
/* Display all MAC-IP VNI routes linked to an ES */
static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi,
json_object *json, int detail,
bool global_table)
{
struct bgp_dest *bd;
struct bgp_path_info *pi;
int header = detail ? 0 : 1;
uint32_t path_cnt;
struct listnode *node;
struct bgp_evpn_es *es;
struct bgp_path_es_info *es_info;
struct bgp *bgp = bgp_get_evpn();
json_object *json_paths = NULL;
if (!bgp)
return;
path_cnt = 0;
if (json)
json_paths = json_object_new_array();
RB_FOREACH (es, bgp_es_rb_head, &bgp_mh_info->es_rb_tree) {
struct list *es_list;
if (esi && memcmp(esi, &es->esi, sizeof(*esi)))
continue;
if (global_table)
es_list = es->macip_global_path_list;
else
es_list = es->macip_evi_path_list;
for (ALL_LIST_ELEMENTS_RO(es_list, node, es_info)) {
json_object *json_path = NULL;
pi = es_info->pi;
bd = pi->net;
if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID))
continue;
/* Overall header/legend displayed once. */
if (header) {
bgp_evpn_show_route_header(vty, bgp, 0, json);
header = 0;
}
path_cnt++;
if (json)
json_path = json_object_new_array();
if (detail)
route_vty_out_detail(vty, bgp, bd, bgp_dest_get_prefix(bd), pi,
AFI_L2VPN, SAFI_EVPN, RPKI_NOT_BEING_USED,
json_path, NULL, 0);
else
route_vty_out(vty, &bd->rn->p, pi, 0, SAFI_EVPN,
json_path, false);
if (json)
json_object_array_add(json_paths, json_path);
}
}
if (json) {
json_object_object_add(json, "paths", json_paths);
json_object_int_add(json, "numPaths", path_cnt);
} else {
if (path_cnt == 0)
vty_out(vty, "There are no MAC-IP ES paths");
else
vty_out(vty, "\nDisplayed %u paths\n", path_cnt);
vty_out(vty, "\n");
}
}
static void bgp_evpn_show_routes_mac_ip_evi_es(struct vty *vty, esi_t *esi,
json_object *json, int detail)
{
bgp_evpn_show_routes_mac_ip_es(vty, esi, json, detail, false);
}
static void bgp_evpn_show_routes_mac_ip_global_es(struct vty *vty, esi_t *esi,
json_object *json, int detail)
{
bgp_evpn_show_routes_mac_ip_es(vty, esi, json, detail, true);
}
static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn,
struct vty *vty, int type, bool mac_table,
struct in_addr vtep_ip, json_object *json,
int detail)
{
struct bgp_dest *dest;
struct bgp_path_info *pi;
struct bgp_table *table;
int header = detail ? 0 : 1;
uint64_t tbl_ver;
uint32_t prefix_cnt, path_cnt;
prefix_cnt = path_cnt = 0;
if (mac_table)
table = vpn->mac_table;
else
table = vpn->ip_table;
tbl_ver = table->version;
for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) {
const struct prefix_evpn *evp =
(const struct prefix_evpn *)bgp_dest_get_prefix(dest);
int add_prefix_to_json = 0;
json_object *json_paths = NULL;
json_object *json_prefix = NULL;
const struct prefix *p = bgp_dest_get_prefix(dest);
if (type && evp->prefix.route_type != type)
continue;
if (json)
json_prefix = json_object_new_object();
pi = bgp_dest_get_bgp_path_info(dest);
if (pi) {
/* Overall header/legend displayed once. */
if (header) {
bgp_evpn_show_route_header(vty, bgp,
tbl_ver, json);
header = 0;
}
prefix_cnt++;
}
if (json)
json_paths = json_object_new_array();
/* For EVPN, the prefix is displayed for each path (to fit in
* with code that already exists).
*/
for (; pi; pi = pi->next) {
struct prefix tmp_p;
json_object *json_path = NULL;
if (vtep_ip.s_addr != INADDR_ANY
&& !IPV4_ADDR_SAME(&(vtep_ip),
&(pi->attr->nexthop)))
continue;
if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE) {
/*
* VNI IP/MAC table prefixes don't have MAC/IP
* respectively so make sure it's set from path
* info here.
*/
if (is_evpn_prefix_ipaddr_none(evp)) {
/* VNI MAC -> Global */
evpn_type2_prefix_global_copy(
(struct prefix_evpn *)&tmp_p,
evp, NULL /* mac */,
evpn_type2_path_info_get_ip(
pi));
} else {
/* VNI IP -> Global */
evpn_type2_prefix_global_copy(
(struct prefix_evpn *)&tmp_p,
evp,
evpn_type2_path_info_get_mac(
pi),
NULL /* ip */);
}
} else
memcpy(&tmp_p, p, sizeof(tmp_p));
if (json)
json_path = json_object_new_array();
if (detail)
route_vty_out_detail(vty, bgp, dest, &tmp_p, pi, AFI_L2VPN,
SAFI_EVPN, RPKI_NOT_BEING_USED, json_path,
NULL, 0);
else
route_vty_out(vty, &tmp_p, pi, 0, SAFI_EVPN,
json_path, false);
if (json)
json_object_array_add(json_paths, json_path);
path_cnt++;
add_prefix_to_json = 1;
}
if (json) {
if (add_prefix_to_json) {
json_object_string_addf(json_prefix, "prefix",
"%pFX", p);
json_object_int_add(json_prefix, "prefixLen",
p->prefixlen);
json_object_object_add(json_prefix, "paths",
json_paths);
json_object_object_addf(json, json_prefix,
"%pFX", p);
} else {
json_object_free(json_paths);
json_object_free(json_prefix);
json_paths = NULL;
json_prefix = NULL;
}
}
}
if (json) {
json_object_int_add(json, "numPrefix", prefix_cnt);
json_object_int_add(json, "numPaths", path_cnt);
} else {
if (prefix_cnt == 0)
vty_out(vty, "No EVPN prefixes %sexist for this VNI",
type ? "(of requested type) " : "");
else
vty_out(vty, "\nDisplayed %u prefixes (%u paths)%s\n",
prefix_cnt, path_cnt,
type ? " (of requested type)" : "");
vty_out(vty, "\n");
}
}
static void show_vni_routes_hash(struct hash_bucket *bucket, void *arg)
{
struct bgpevpn *vpn = (struct bgpevpn *)bucket->data;
struct vni_walk_ctx *wctx = arg;
struct vty *vty = wctx->vty;
json_object *json = wctx->json;
json_object *json_vni = NULL;
char vni_str[VNI_STR_LEN];
snprintf(vni_str, sizeof(vni_str), "%u", vpn->vni);
if (json) {
json_vni = json_object_new_object();
json_object_int_add(json_vni, "vni", vpn->vni);
} else {
vty_out(vty, "\nVNI: %u\n\n", vpn->vni);
}
show_vni_routes(wctx->bgp, vpn, wctx->vty, wctx->type, wctx->mac_table,
wctx->vtep_ip, json_vni, wctx->detail);
if (json)
json_object_object_add(json, vni_str, json_vni);
}
static void show_vni_routes_all_hash(struct hash_bucket *bucket, void *arg)
{
struct bgpevpn *vpn = (struct bgpevpn *)bucket->data;
struct vni_walk_ctx *wctx = arg;
struct vty *vty = wctx->vty;
json_object *json = wctx->json;
json_object *json_vni = NULL;
json_object *json_vni_mac = NULL;
char vni_str[VNI_STR_LEN];
snprintf(vni_str, sizeof(vni_str), "%u", vpn->vni);
if (json) {
json_vni = json_object_new_object();
json_object_int_add(json_vni, "vni", vpn->vni);
} else {
vty_out(vty, "\nVNI: %u\n\n", vpn->vni);
}
show_vni_routes(wctx->bgp, vpn, wctx->vty, 0, false, wctx->vtep_ip,
json_vni, wctx->detail);
if (json)
json_object_object_add(json, vni_str, json_vni);
if (json)
json_vni_mac = json_object_new_object();
else
vty_out(vty, "\nVNI: %u MAC Table\n\n", vpn->vni);
show_vni_routes(wctx->bgp, vpn, wctx->vty, 0, true, wctx->vtep_ip,
json_vni_mac, wctx->detail);
if (json)
json_object_object_add(json_vni, "macTable", json_vni_mac);