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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
|
/* MPLS-VPN
Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
This file is part of GNU Zebra.
GNU Zebra is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
GNU Zebra is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Zebra; see the file COPYING. If not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
#include <zebra.h>
#include "command.h"
#include "prefix.h"
#include "log.h"
#include "memory.h"
#include "stream.h"
#include "queue.h"
#include "lib/json.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_mplsvpn.h"
static u_int16_t
decode_rd_type (u_char *pnt)
{
u_int16_t v;
v = ((u_int16_t) *pnt++ << 8);
v |= (u_int16_t) *pnt;
return v;
}
u_int32_t
decode_label (u_char *pnt)
{
u_int32_t l;
l = ((u_int32_t) *pnt++ << 12);
l |= (u_int32_t) *pnt++ << 4;
l |= (u_int32_t) ((*pnt & 0xf0) >> 4);
return l;
}
static void
decode_rd_as (u_char *pnt, struct rd_as *rd_as)
{
rd_as->as = (u_int16_t) *pnt++ << 8;
rd_as->as |= (u_int16_t) *pnt++;
rd_as->val = ((u_int32_t) *pnt++ << 24);
rd_as->val |= ((u_int32_t) *pnt++ << 16);
rd_as->val |= ((u_int32_t) *pnt++ << 8);
rd_as->val |= (u_int32_t) *pnt;
}
static void
decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
{
memcpy (&rd_ip->ip, pnt, 4);
pnt += 4;
rd_ip->val = ((u_int16_t) *pnt++ << 8);
rd_ip->val |= (u_int16_t) *pnt;
}
int
bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
struct bgp_nlri *packet)
{
u_char *pnt;
u_char *lim;
struct prefix p;
int psize;
int prefixlen;
u_int16_t type;
struct rd_as rd_as;
struct rd_ip rd_ip;
struct prefix_rd prd;
u_char *tagpnt;
afi_t afi;
safi_t safi;
u_char addpath_encoded;
u_int32_t addpath_id;
/* Check peer status. */
if (peer->status != Established)
return 0;
/* Make prefix_rd */
prd.family = AF_UNSPEC;
prd.prefixlen = 64;
pnt = packet->nlri;
lim = pnt + packet->length;
afi = packet->afi;
safi = packet->safi;
addpath_id = 0;
addpath_encoded = (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_RX_ADV) &&
CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ADDPATH_AF_TX_RCV));
for (; pnt < lim; pnt += psize)
{
/* Clear prefix structure. */
memset (&p, 0, sizeof (struct prefix));
if (addpath_encoded)
{
/* When packet overflow occurs return immediately. */
if (pnt + BGP_ADDPATH_ID_LEN > lim)
return -1;
addpath_id = ntohl(*((uint32_t*) pnt));
pnt += BGP_ADDPATH_ID_LEN;
}
/* Fetch prefix length. */
prefixlen = *pnt++;
p.family = AF_INET;
psize = PSIZE (prefixlen);
if (prefixlen < 88)
{
zlog_err ("prefix length is less than 88: %d", prefixlen);
return -1;
}
/* Copyr label to prefix. */
tagpnt = pnt;;
/* Copy routing distinguisher to rd. */
memcpy (&prd.val, pnt + 3, 8);
/* Decode RD type. */
type = decode_rd_type (pnt + 3);
/* Decode RD value. */
if (type == RD_TYPE_AS)
decode_rd_as (pnt + 5, &rd_as);
else if (type == RD_TYPE_IP)
decode_rd_ip (pnt + 5, &rd_ip);
else
{
zlog_err ("Invalid RD type %d", type);
return -1;
}
p.prefixlen = prefixlen - 88;
memcpy (&p.u.prefix, pnt + 11, psize - 11);
#if 0
if (type == RD_TYPE_AS)
zlog_info ("prefix %ld:%ld:%ld:%s/%d", label, rd_as.as, rd_as.val,
inet_ntoa (p.u.prefix4), p.prefixlen);
else if (type == RD_TYPE_IP)
zlog_info ("prefix %ld:%s:%ld:%s/%d", label, inet_ntoa (rd_ip.ip),
rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
#endif /* 0 */
if (pnt + psize > lim)
return -1;
if (attr)
bgp_update (peer, &p, addpath_id, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
else
bgp_withdraw (peer, &p, addpath_id, attr, AFI_IP, SAFI_MPLS_VPN,
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
}
/* Packet length consistency check. */
if (pnt != lim)
return -1;
return 0;
}
int
str2prefix_rd (const char *str, struct prefix_rd *prd)
{
int ret;
char *p;
char *p2;
struct stream *s;
char *half;
struct in_addr addr;
s = stream_new (8);
prd->family = AF_UNSPEC;
prd->prefixlen = 64;
p = strchr (str, ':');
if (! p)
return 0;
if (! all_digit (p + 1))
return 0;
half = XMALLOC (MTYPE_TMP, (p - str) + 1);
memcpy (half, str, (p - str));
half[p - str] = '\0';
p2 = strchr (str, '.');
if (! p2)
{
if (! all_digit (half))
{
XFREE (MTYPE_TMP, half);
return 0;
}
stream_putw (s, RD_TYPE_AS);
stream_putw (s, atoi (half));
stream_putl (s, atol (p + 1));
}
else
{
ret = inet_aton (half, &addr);
if (! ret)
{
XFREE (MTYPE_TMP, half);
return 0;
}
stream_putw (s, RD_TYPE_IP);
stream_put_in_addr (s, &addr);
stream_putw (s, atol (p + 1));
}
memcpy (prd->val, s->data, 8);
XFREE(MTYPE_TMP, half);
return 1;
}
int
str2tag (const char *str, u_char *tag)
{
unsigned long l;
char *endptr;
u_int32_t t;
if (*str == '-')
return 0;
errno = 0;
l = strtoul (str, &endptr, 10);
if (*endptr != '\0' || errno || l > UINT32_MAX)
return 0;
t = (u_int32_t) l;
tag[0] = (u_char)(t >> 12);
tag[1] = (u_char)(t >> 4);
tag[2] = (u_char)(t << 4);
return 1;
}
char *
prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
{
u_char *pnt;
u_int16_t type;
struct rd_as rd_as;
struct rd_ip rd_ip;
if (size < RD_ADDRSTRLEN)
return NULL;
pnt = prd->val;
type = decode_rd_type (pnt);
if (type == RD_TYPE_AS)
{
decode_rd_as (pnt + 2, &rd_as);
snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
return buf;
}
else if (type == RD_TYPE_IP)
{
decode_rd_ip (pnt + 2, &rd_ip);
snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
return buf;
}
return NULL;
}
/* For testing purpose, static route of MPLS-VPN. */
DEFUN (vpnv4_network,
vpnv4_network_cmd,
"network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
"Specify a network to announce via BGP\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
"BGP tag\n"
"tag value\n")
{
return bgp_static_set_vpnv4 (vty, argv[0], argv[1], argv[2]);
}
/* For testing purpose, static route of MPLS-VPN. */
DEFUN (no_vpnv4_network,
no_vpnv4_network_cmd,
"no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
NO_STR
"Specify a network to announce via BGP\n"
"IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
"Specify Route Distinguisher\n"
"VPN Route Distinguisher\n"
"BGP tag\n"
"tag value\n")
{
return bgp_static_unset_vpnv4 (vty, argv[0], argv[1], argv[2]);
}
static int
show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd, u_char use_json)
{
struct bgp *bgp;
struct bgp_table *table;
struct bgp_node *rn;
struct bgp_node *rm;
struct attr *attr;
int rd_header;
int header = 1;
char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
json_object *json = NULL;
json_object *json_scode = NULL;
json_object *json_ocode = NULL;
json_object *json_routes = NULL;
json_object *json_array = NULL;
bgp = bgp_get_default ();
if (bgp == NULL)
{
if (!use_json)
vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (use_json)
{
json_scode = json_object_new_object();
json_ocode = json_object_new_object();
json_routes = json_object_new_object();
json = json_object_new_object();
json_object_string_add(json_scode, "suppressed", "s");
json_object_string_add(json_scode, "damped", "d");
json_object_string_add(json_scode, "history", "h");
json_object_string_add(json_scode, "valid", "*");
json_object_string_add(json_scode, "best", ">");
json_object_string_add(json_scode, "internal", "i");
json_object_string_add(json_ocode, "igp", "i");
json_object_string_add(json_ocode, "egp", "e");
json_object_string_add(json_ocode, "incomplete", "?");
}
for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn;
rn = bgp_route_next (rn))
{
if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
continue;
if ((table = rn->info) != NULL)
{
if (use_json)
json_array = json_object_new_array();
else
json_array = NULL;
rd_header = 1;
for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
{
if ((attr = rm->info) != NULL)
{
if (header)
{
if (use_json)
{
json_object_int_add(json, "bgpTableVersion", 0);
json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
json_object_object_add(json, "bgpStatusCodes", json_scode);
json_object_object_add(json, "bgpOriginCodes", json_ocode);
}
else
{
vty_out (vty, "BGP table version is 0, local router ID is %s%s",
inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
VTY_NEWLINE);
vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
VTY_NEWLINE, VTY_NEWLINE);
vty_out (vty, v4_header, VTY_NEWLINE);
}
header = 0;
}
if (rd_header)
{
u_int16_t type;
struct rd_as rd_as;
struct rd_ip rd_ip;
u_char *pnt;
pnt = rn->p.u.val;
/* Decode RD type. */
type = decode_rd_type (pnt);
/* Decode RD value. */
if (type == RD_TYPE_AS)
decode_rd_as (pnt + 2, &rd_as);
else if (type == RD_TYPE_IP)
decode_rd_ip (pnt + 2, &rd_ip);
if (use_json)
{
char buffer[BUFSIZ];
if (type == RD_TYPE_AS)
sprintf (buffer, "%u:%d", rd_as.as, rd_as.val);
else if (type == RD_TYPE_IP)
sprintf (buffer, "%u:%d", rd_as.as, rd_as.val);
json_object_string_add(json_routes, "routeDistinguisher", buffer);
}
else
{
vty_out (vty, "Route Distinguisher: ");
if (type == RD_TYPE_AS)
vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
else if (type == RD_TYPE_IP)
vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
vty_out (vty, "%s", VTY_NEWLINE);
}
rd_header = 0;
}
route_vty_out_tmp (vty, &rm->p, attr, SAFI_MPLS_VPN, use_json, json_array);
}
}
if (use_json)
{
struct prefix *p;
char buf_a[BUFSIZ];
char buf_b[BUFSIZ];
p = &rm->p;
sprintf(buf_a, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf_b, BUFSIZ), p->prefixlen);
json_object_object_add(json_routes, buf_a, json_array);
}
}
}
if (use_json)
{
json_object_object_add(json, "routes", json_routes);
vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
json_object_free(json);
}
return CMD_SUCCESS;
}
enum bgp_show_type
{
bgp_show_type_normal,
bgp_show_type_regexp,
bgp_show_type_prefix_list,
bgp_show_type_filter_list,
bgp_show_type_neighbor,
bgp_show_type_cidr_only,
bgp_show_type_prefix_longer,
bgp_show_type_community_all,
bgp_show_type_community,
bgp_show_type_community_exact,
bgp_show_type_community_list,
bgp_show_type_community_list_exact
};
static int
bgp_show_mpls_vpn (struct vty *vty, struct prefix_rd *prd, enum bgp_show_type type,
void *output_arg, int tags, u_char use_json)
{
struct bgp *bgp;
struct bgp_table *table;
struct bgp_node *rn;
struct bgp_node *rm;
struct bgp_info *ri;
int rd_header;
int header = 1;
char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
json_object *json = NULL;
json_object *json_mroute = NULL;
json_object *json_nroute = NULL;
json_object *json_array = NULL;
json_object *json_scode = NULL;
json_object *json_ocode = NULL;
bgp = bgp_get_default ();
if (bgp == NULL)
{
if (!use_json)
vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
return CMD_WARNING;
}
if (use_json)
{
json_scode = json_object_new_object();
json_ocode = json_object_new_object();
json = json_object_new_object();
json_mroute = json_object_new_object();
json_nroute = json_object_new_object();
json_object_string_add(json_scode, "suppressed", "s");
json_object_string_add(json_scode, "damped", "d");
json_object_string_add(json_scode, "history", "h");
json_object_string_add(json_scode, "valid", "*");
json_object_string_add(json_scode, "best", ">");
json_object_string_add(json_scode, "internal", "i");
json_object_string_add(json_ocode, "igp", "i");
json_object_string_add(json_ocode, "egp", "e");
json_object_string_add(json_ocode, "incomplete", "?");
}
for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
{
if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
continue;
if ((table = rn->info) != NULL)
{
rd_header = 1;
for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
{
if (use_json)
json_array = json_object_new_array();
else
json_array = NULL;
for (ri = rm->info; ri; ri = ri->next)
{
if (type == bgp_show_type_neighbor)
{
union sockunion *su = output_arg;
if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
continue;
}
if (header)
{
if (use_json)
{
if (!tags)
{
json_object_int_add(json, "bgpTableVersion", 0);
json_object_string_add(json, "bgpLocalRouterId", inet_ntoa (bgp->router_id));
json_object_object_add(json, "bgpStatusCodes", json_scode);
json_object_object_add(json, "bgpOriginCodes", json_ocode);
}
}
else
{
if (tags)
vty_out (vty, v4_header_tag, VTY_NEWLINE);
else
{
vty_out (vty, "BGP table version is 0, local router ID is %s%s",
inet_ntoa (bgp->router_id), VTY_NEWLINE);
vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
VTY_NEWLINE);
vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
VTY_NEWLINE, VTY_NEWLINE);
vty_out (vty, v4_header, VTY_NEWLINE);
}
}
header = 0;
}
if (rd_header)
{
u_int16_t type;
struct rd_as rd_as;
struct rd_ip rd_ip;
u_char *pnt;
pnt = rn->p.u.val;
/* Decode RD type. */
type = decode_rd_type (pnt);
/* Decode RD value. */
if (type == RD_TYPE_AS)
decode_rd_as (pnt + 2, &rd_as);
else if (type == RD_TYPE_IP)
decode_rd_ip (pnt + 2, &rd_ip);
if (use_json)
{
char buffer[BUFSIZ];
if (type == RD_TYPE_AS)
sprintf (buffer, "%u:%d", rd_as.as, rd_as.val);
else if (type == RD_TYPE_IP)
sprintf (buffer, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
json_object_string_add(json_nroute, "routeDistinguisher", buffer);
}
else
{
vty_out (vty, "Route Distinguisher: ");
if (type == RD_TYPE_AS)
vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
else if (type == RD_TYPE_IP)
vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
vty_out (vty, "%s", VTY_NEWLINE);
}
rd_header = 0;
}
if (tags)
route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_MPLS_VPN, json_array);
else
route_vty_out (vty, &rm->p, ri, 0, SAFI_MPLS_VPN, json_array);
}
if (use_json)
{
struct prefix *p;
char buf_a[BUFSIZ];
char buf_b[BUFSIZ];
p = &rm->p;
sprintf(buf_a, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf_b, BUFSIZ), p->prefixlen);
json_object_object_add(json_mroute, buf_a, json_array);
}
}
if (use_json)
{
struct prefix *p;
char buf_a[BUFSIZ];
char buf_b[BUFSIZ];
p = &rn->p;
sprintf(buf_a, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf_b, BUFSIZ), p->prefixlen);
json_object_object_add(json_nroute, buf_a, json_mroute);
}
}
}
if (use_json)
{
json_object_object_add(json, "routes", json_nroute);
vty_out (vty, "%s%s", json_object_to_json_string(json), VTY_NEWLINE);
json_object_free(json);
}
return CMD_SUCCESS;
}
DEFUN (show_ip_bgp_vpnv4_all,
show_ip_bgp_vpnv4_all_cmd,
"show ip bgp vpnv4 all",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n")
{
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 0, 0);
}
DEFUN (show_ip_bgp_vpnv4_rd,
show_ip_bgp_vpnv4_rd_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n")
{
int ret;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 0, 0);
}
DEFUN (show_ip_bgp_vpnv4_all_tags,
show_ip_bgp_vpnv4_all_tags_cmd,
"show ip bgp vpnv4 all tags",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Display BGP tags for prefixes\n")
{
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 1, 0);
}
DEFUN (show_ip_bgp_vpnv4_rd_tags,
show_ip_bgp_vpnv4_rd_tags_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn tags",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Display BGP tags for prefixes\n")
{
int ret;
struct prefix_rd prd;
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 1, 0);
}
DEFUN (show_ip_bgp_vpnv4_all_neighbor_routes,
show_ip_bgp_vpnv4_all_neighbor_routes_cmd,
"show ip bgp vpnv4 all neighbors A.B.C.D routes {json}",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display routes learned from neighbor\n"
"JavaScript Object Notation\n")
{
union sockunion su;
struct peer *peer;
int ret;
u_char use_json = (argv[1] != NULL);
ret = str2sockunion (argv[0], &su);
if (ret < 0)
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_neighbor, &su, 0, use_json);
}
DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes,
show_ip_bgp_vpnv4_rd_neighbor_routes_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes {json}",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display routes learned from neighbor\n"
"JavaScript Object Notation\n")
{
int ret;
union sockunion su;
struct peer *peer;
struct prefix_rd prd;
u_char use_json = (argv[2] != NULL);
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed Route Distinguisher");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
ret = str2sockunion (argv[1], &su);
if (ret < 0)
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_neighbor, &su, 0, use_json);
}
DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes,
show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd,
"show ip bgp vpnv4 all neighbors A.B.C.D advertised-routes {json}",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information about all VPNv4 NLRIs\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display the routes advertised to a BGP neighbor\n"
"JavaScript Object Notation\n")
{
int ret;
struct peer *peer;
union sockunion su;
u_char use_json = (argv[1] != NULL);
ret = str2sockunion (argv[0], &su);
if (ret < 0)
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
return show_adj_route_vpn (vty, peer, NULL, use_json);
}
DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd,
"show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes {json}",
SHOW_STR
IP_STR
BGP_STR
"Display VPNv4 NLRI specific information\n"
"Display information for a route distinguisher\n"
"VPN Route Distinguisher\n"
"Detailed information on TCP and BGP neighbor connections\n"
"Neighbor to display information about\n"
"Display the routes advertised to a BGP neighbor\n"
"JavaScript Object Notation\n")
{
int ret;
struct peer *peer;
struct prefix_rd prd;
union sockunion su;
u_char use_json = (argv[2] != NULL);
ret = str2sockunion (argv[1], &su);
if (ret < 0)
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed address");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
peer = peer_lookup (NULL, &su);
if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "No such neighbor or address family");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
return CMD_WARNING;
}
ret = str2prefix_rd (argv[0], &prd);
if (! ret)
{
if (use_json)
{
json_object *json_no = NULL;
json_no = json_object_new_object();
json_object_string_add(json_no, "warning", "Malformed Route Distinguisher");
vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
json_object_free(json_no);
}
else
vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
return CMD_WARNING;
}
return show_adj_route_vpn (vty, peer, &prd, use_json);
}
void
bgp_mplsvpn_init (void)
{
install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
}
|