]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_encap.c
Merge pull request #584 from LabNConsulting/working/3.0/patch/configVpnTags-v2
[mirror_frr.git] / bgpd / bgp_encap.c
1
2 /*
3 * This file created by LabN Consulting, L.L.C.
4 *
5 *
6 * This file is based on bgp_mplsvpn.c which is Copyright (C) 2000
7 * Kunihiro Ishiguro <kunihiro@zebra.org>
8 *
9 */
10
11 /*
12
13 This file is part of GNU Zebra.
14
15 GNU Zebra is free software; you can redistribute it and/or modify it
16 under the terms of the GNU General Public License as published by the
17 Free Software Foundation; either version 2, or (at your option) any
18 later version.
19
20 GNU Zebra is distributed in the hope that it will be useful, but
21 WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with GNU Zebra; see the file COPYING. If not, write to the Free
27 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 02111-1307, USA. */
29
30 #include <zebra.h>
31
32 #include "command.h"
33 #include "prefix.h"
34 #include "log.h"
35 #include "memory.h"
36 #include "stream.h"
37 #include "filter.h"
38
39 #include "bgpd/bgpd.h"
40 #include "bgpd/bgp_table.h"
41 #include "bgpd/bgp_route.h"
42 #include "bgpd/bgp_attr.h"
43 #include "bgpd/bgp_ecommunity.h"
44 #include "bgpd/bgp_lcommunity.h"
45 #include "bgpd/bgp_mplsvpn.h"
46 #include "bgpd/bgp_vty.h"
47 #include "bgpd/bgp_encap.h"
48
49 #if ENABLE_BGP_VNC
50 #include "bgpd/rfapi/rfapi_backend.h"
51 #endif
52
53 static void
54 ecom2prd(struct ecommunity *ecom, struct prefix_rd *prd)
55 {
56 int i;
57
58 memset(prd, 0, sizeof(struct prefix_rd));
59 prd->family = AF_UNSPEC;
60 prd->prefixlen = 64;
61
62 if (!ecom)
63 return;
64
65 for (i = 0; i < (ecom->size * ECOMMUNITY_SIZE); i += ECOMMUNITY_SIZE) {
66
67 uint8_t *ep;
68
69 ep = ecom->val + i;
70
71 switch (ep[0]) {
72 default:
73 continue;
74
75 case 0x80:
76 case 0x81:
77 case 0x82:
78 if (ep[1] == 0x0) {
79 prd->val[1] = ep[0] & 0x03;
80 memcpy(prd->val + 2, ep + 2, 6);
81 return;
82 }
83 }
84 }
85 }
86
87 int
88 bgp_nlri_parse_encap(
89 struct peer *peer,
90 struct attr *attr,
91 struct bgp_nlri *packet)
92 {
93 u_char *pnt;
94 u_char *lim;
95 afi_t afi = packet->afi;
96 struct prefix p;
97 int psize = 0;
98 int prefixlen;
99 struct rd_as rd_as;
100 struct rd_ip rd_ip;
101 struct prefix_rd prd;
102 struct ecommunity *pEcom = NULL;
103 u_int16_t rdtype = 0xffff;
104 char buf[BUFSIZ];
105
106 /* Check peer status. */
107 if (peer->status != Established)
108 return 0;
109
110 /* Make prefix_rd */
111 if (attr && attr->extra && attr->extra->ecommunity)
112 pEcom = attr->extra->ecommunity;
113
114 ecom2prd(pEcom, &prd);
115 memset(&rd_as, 0, sizeof(rd_as));
116 memset(&rd_ip, 0, sizeof(rd_ip));
117
118 if (pEcom) {
119
120 rdtype = (prd.val[0] << 8) | prd.val[1];
121
122 /* Decode RD value. */
123 if (rdtype == RD_TYPE_AS)
124 decode_rd_as (prd.val + 2, &rd_as);
125 else if (rdtype == RD_TYPE_IP)
126 decode_rd_ip (prd.val + 2, &rd_ip);
127 else if (rdtype == RD_TYPE_AS4)
128 decode_rd_as4 (prd.val + 2, &rd_as);
129 else
130 {
131 zlog_err ("Invalid RD type %d", rdtype);
132 }
133
134 }
135
136 /*
137 * NB: this code was based on the MPLS VPN code, which supported RDs.
138 * For the moment we are retaining the underlying RIB structure that
139 * keeps a per-RD radix tree, but since the RDs are not carried over
140 * the wire, we set the RD internally to 0.
141 */
142 prd.family = AF_UNSPEC;
143 prd.prefixlen = 64;
144 memset(prd.val, 0, sizeof(prd.val));
145
146 pnt = packet->nlri;
147 lim = pnt + packet->length;
148
149 for (; pnt < lim; pnt += psize)
150 {
151 /* Clear prefix structure. */
152 memset (&p, 0, sizeof (struct prefix));
153
154 /* Fetch prefix length. */
155 prefixlen = *pnt++;
156 p.family = afi2family(afi);
157 if (p.family == 0) {
158 /* bad afi, shouldn't happen */
159 zlog_warn("%s: bad afi %d, dropping incoming route", __func__, afi);
160 continue;
161 }
162 psize = PSIZE (prefixlen);
163
164 p.prefixlen = prefixlen;
165 memcpy (&p.u.prefix, pnt, psize);
166
167 if (pnt + psize > lim)
168 return -1;
169
170
171 if (rdtype == RD_TYPE_AS)
172 zlog_info ("rd-as %u:%u prefix %s/%d", rd_as.as, rd_as.val,
173 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
174 p.prefixlen);
175 else if (rdtype == RD_TYPE_IP)
176 zlog_info ("rd-ip %s:%u prefix %s/%d", inet_ntoa (rd_ip.ip),
177 rd_ip.val,
178 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
179 p.prefixlen);
180 else if (rdtype == RD_TYPE_AS4)
181 zlog_info ("rd-as4 %u:%u prefix %s/%d", rd_as.as, rd_as.val,
182 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
183 p.prefixlen);
184 else
185 zlog_info ("rd unknown, default to 0:0 prefix %s/%d",
186 inet_ntop (p.family, &p.u.prefix, buf, BUFSIZ),
187 p.prefixlen);
188
189 if (attr) {
190 bgp_update (peer, &p, 0, attr, afi, SAFI_ENCAP,
191 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL, 0, NULL);
192 } else {
193 bgp_withdraw (peer, &p, 0, attr, afi, SAFI_ENCAP,
194 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL, NULL);
195 }
196 }
197
198 /* Packet length consistency check. */
199 if (pnt != lim)
200 return -1;
201
202 return 0;
203 }
204
205
206 /* TBD: these routes should probably all be host routes */
207
208 /* For testing purpose, static route of ENCAP. */
209 DEFUN (encap_network,
210 encap_network_cmd,
211 "network A.B.C.D/M rd ASN:nn_or_IP-address:nn",
212 "Specify a network to announce via BGP\n"
213 "IPv4 prefix\n"
214 "Specify Route Distinguisher\n"
215 "ENCAP Route Distinguisher\n")
216 {
217 int idx_ipv4 = 1;
218 int idx_rd = 3;
219 return bgp_static_set_safi (AFI_IP, SAFI_ENCAP, vty, argv[idx_ipv4]->arg, argv[idx_rd]->arg, NULL,
220 NULL, 0, NULL, NULL, NULL, NULL);
221 }
222
223 /* For testing purpose, static route of ENCAP. */
224 DEFUN (no_encap_network,
225 no_encap_network_cmd,
226 "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn",
227 NO_STR
228 "Specify a network to announce via BGP\n"
229 "IPv4 prefix\n"
230 "Specify Route Distinguisher\n"
231 "ENCAP Route Distinguisher\n"
232 "BGP tag\n"
233 "tag value\n")
234 {
235 int idx_ipv4 = 2;
236 int idx_rd = 4;
237 return bgp_static_unset_safi (AFI_IP, SAFI_ENCAP, vty, argv[idx_ipv4]->arg, argv[idx_rd]->arg, NULL,
238 0, NULL, NULL, NULL);
239 }
240
241 static int
242 show_adj_route_encap (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
243 {
244 struct bgp *bgp;
245 struct bgp_table *table;
246 struct bgp_node *rn;
247 struct bgp_node *rm;
248 struct attr *attr;
249 int rd_header;
250 int header = 1;
251 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
252
253 bgp = bgp_get_default ();
254 if (bgp == NULL)
255 {
256 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
257 return CMD_WARNING;
258 }
259
260 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_ENCAP]); rn;
261 rn = bgp_route_next (rn))
262 {
263 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
264 continue;
265
266 if ((table = rn->info) != NULL)
267 {
268 rd_header = 1;
269
270 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
271 if ((attr = rm->info) != NULL)
272 {
273 if (header)
274 {
275 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
276 inet_ntoa (bgp->router_id), VTY_NEWLINE);
277 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
278 VTY_NEWLINE);
279 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
280 VTY_NEWLINE, VTY_NEWLINE);
281 vty_out (vty, v4_header, VTY_NEWLINE);
282 header = 0;
283 }
284
285 if (rd_header)
286 {
287 u_int16_t type;
288 struct rd_as rd_as;
289 struct rd_ip rd_ip;
290 u_char *pnt;
291
292 pnt = rn->p.u.val;
293
294 vty_out (vty, "Route Distinguisher: ");
295
296 /* Decode RD type. */
297 type = decode_rd_type (pnt);
298
299 switch (type) {
300
301 case RD_TYPE_AS:
302 decode_rd_as (pnt + 2, &rd_as);
303 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
304 break;
305
306 case RD_TYPE_IP:
307 decode_rd_ip (pnt + 2, &rd_ip);
308 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
309 break;
310
311 default:
312 vty_out (vty, "unknown RD type");
313 }
314
315
316 vty_out (vty, "%s", VTY_NEWLINE);
317 rd_header = 0;
318 }
319 route_vty_out_tmp (vty, &rm->p, attr, SAFI_ENCAP, 0, NULL);
320 }
321 }
322 }
323 return CMD_SUCCESS;
324 }
325
326 int
327 bgp_show_encap (
328 struct vty *vty,
329 afi_t afi,
330 struct prefix_rd *prd,
331 enum bgp_show_type type,
332 void *output_arg,
333 int tags)
334 {
335 struct bgp *bgp;
336 struct bgp_table *table;
337 struct bgp_node *rn;
338 struct bgp_node *rm;
339 struct bgp_info *ri;
340 int rd_header;
341 int header = 1;
342 char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
343 char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
344
345 unsigned long output_count = 0;
346 unsigned long total_count = 0;
347
348 bgp = bgp_get_default ();
349 if (bgp == NULL)
350 {
351 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
352 return CMD_WARNING;
353 }
354
355 if ((afi != AFI_IP) && (afi != AFI_IP6)) {
356 vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE);
357 return CMD_WARNING;
358 }
359
360 for (rn = bgp_table_top (bgp->rib[afi][SAFI_ENCAP]); rn; rn = bgp_route_next (rn))
361 {
362 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
363 continue;
364
365 if ((table = rn->info) != NULL)
366 {
367 rd_header = 1;
368
369 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
370 for (ri = rm->info; ri; ri = ri->next)
371 {
372 total_count++;
373 if (type == bgp_show_type_neighbor)
374 {
375 union sockunion *su = output_arg;
376
377 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
378 continue;
379 }
380 if (header)
381 {
382 if (tags)
383 vty_out (vty, v4_header_tag, VTY_NEWLINE);
384 else
385 {
386 vty_out (vty, "BGP table version is 0, local router ID is %s%s",
387 inet_ntoa (bgp->router_id), VTY_NEWLINE);
388 vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
389 VTY_NEWLINE);
390 vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
391 VTY_NEWLINE, VTY_NEWLINE);
392 vty_out (vty, v4_header, VTY_NEWLINE);
393 }
394 header = 0;
395 }
396
397 if (rd_header)
398 {
399 u_int16_t type;
400 struct rd_as rd_as;
401 struct rd_ip rd_ip;
402 u_char *pnt;
403
404 pnt = rn->p.u.val;
405
406 /* Decode RD type. */
407 type = decode_rd_type (pnt);
408
409 vty_out (vty, "Route Distinguisher: ");
410
411 switch (type) {
412
413 case RD_TYPE_AS:
414 decode_rd_as (pnt + 2, &rd_as);
415 vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
416 break;
417
418 case RD_TYPE_IP:
419 decode_rd_ip (pnt + 2, &rd_ip);
420 vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
421 break;
422
423 default:
424 vty_out (vty, "Unknown RD type");
425 break;
426 }
427
428 vty_out (vty, "%s", VTY_NEWLINE);
429 rd_header = 0;
430 }
431 if (tags)
432 route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_ENCAP, NULL);
433 else
434 route_vty_out (vty, &rm->p, ri, 0, SAFI_ENCAP, NULL);
435 output_count++;
436 }
437 }
438 }
439
440 if (output_count == 0)
441 {
442 vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
443 }
444 else
445 vty_out (vty, "%sDisplayed %ld routes and %ld total paths%s",
446 VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
447
448 return CMD_SUCCESS;
449 }
450
451 DEFUN (show_bgp_ipv4_encap_rd,
452 show_bgp_ipv4_encap_rd_cmd,
453 "show [ip] bgp ipv4 encap rd ASN:nn_or_IP-address:nn",
454 SHOW_STR
455 IP_STR
456 BGP_STR
457 "Address Family\n"
458 "Display ENCAP NLRI specific information\n"
459 "Display information for a route distinguisher\n"
460 "ENCAP Route Distinguisher\n")
461 {
462 int idx_rd = 5;
463 int ret;
464 struct prefix_rd prd;
465
466 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
467 if (! ret)
468 {
469 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
470 return CMD_WARNING;
471 }
472 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0);
473 }
474
475 DEFUN (show_bgp_ipv6_encap_rd,
476 show_bgp_ipv6_encap_rd_cmd,
477 "show [ip] bgp ipv6 encap rd ASN:nn_or_IP-address:nn",
478 SHOW_STR
479 IP_STR
480 BGP_STR
481 "Address Family\n"
482 "Display ENCAP NLRI specific information\n"
483 "Display information for a route distinguisher\n"
484 "ENCAP Route Distinguisher\n"
485 "Display BGP tags for prefixes\n")
486 {
487 int idx_rd = 5;
488 int ret;
489 struct prefix_rd prd;
490
491 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
492 if (! ret)
493 {
494 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
495 return CMD_WARNING;
496 }
497 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0);
498 }
499
500 DEFUN (show_bgp_ipv4_encap_tags,
501 show_bgp_ipv4_encap_tags_cmd,
502 "show [ip] bgp ipv4 encap tags",
503 SHOW_STR
504 IP_STR
505 BGP_STR
506 "Address Family\n"
507 "Display ENCAP NLRI specific information\n"
508 "Display BGP tags for prefixes\n")
509 {
510 return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1);
511 }
512
513 DEFUN (show_bgp_ipv6_encap_tags,
514 show_bgp_ipv6_encap_tags_cmd,
515 "show [ip] bgp ipv6 encap tags",
516 SHOW_STR
517 IP_STR
518 BGP_STR
519 "Address Family\n"
520 "Display ENCAP NLRI specific information\n"
521 "Display BGP tags for prefixes\n")
522 {
523 return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1);
524 }
525
526 DEFUN (show_bgp_ipv4_encap_rd_tags,
527 show_bgp_ipv4_encap_rd_tags_cmd,
528 "show [ip] bgp ipv4 encap rd ASN:nn_or_IP-address:nn tags",
529 SHOW_STR
530 IP_STR
531 BGP_STR
532 "Address Family\n"
533 "Display ENCAP NLRI specific information\n"
534 "Display information for a route distinguisher\n"
535 "ENCAP Route Distinguisher\n"
536 "Display BGP tags for prefixes\n")
537 {
538 int idx_rd = 5;
539 int ret;
540 struct prefix_rd prd;
541
542 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
543 if (! ret)
544 {
545 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
546 return CMD_WARNING;
547 }
548 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1);
549 }
550
551 DEFUN (show_bgp_ipv6_encap_rd_tags,
552 show_bgp_ipv6_encap_rd_tags_cmd,
553 "show [ip] bgp ipv6 encap rd ASN:nn_or_IP-address:nn tags",
554 SHOW_STR
555 IP_STR
556 BGP_STR
557 "Address Family\n"
558 "Display ENCAP NLRI specific information\n"
559 "Display information for a route distinguisher\n"
560 "ENCAP Route Distinguisher\n"
561 "Display BGP tags for prefixes\n")
562 {
563 int idx_rd = 5;
564 int ret;
565 struct prefix_rd prd;
566
567 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
568 if (! ret)
569 {
570 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
571 return CMD_WARNING;
572 }
573 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1);
574 }
575
576 DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes,
577 show_bgp_ipv4_encap_rd_neighbor_routes_cmd,
578 "show [ip] bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> routes",
579 SHOW_STR
580 IP_STR
581 BGP_STR
582 "Address Family\n"
583 "Display ENCAP NLRI specific information\n"
584 "Display information for a route distinguisher\n"
585 "ENCAP Route Distinguisher\n"
586 "Detailed information on TCP and BGP neighbor connections\n"
587 "Neighbor to display information about\n"
588 "Neighbor to display information about\n"
589 "Display routes learned from neighbor\n")
590 {
591 int idx_rd = 5;
592 int idx_peer = 7;
593 int ret;
594 union sockunion su;
595 struct peer *peer;
596 struct prefix_rd prd;
597
598 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
599 if (! ret)
600 {
601 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
602 return CMD_WARNING;
603 }
604
605 if (str2sockunion(argv[idx_peer]->arg, &su))
606 {
607 vty_out (vty, "Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
608 return CMD_WARNING;
609 }
610
611 peer = peer_lookup (NULL, &su);
612 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
613 {
614 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
615 return CMD_WARNING;
616 }
617
618 return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, &su, 0);
619 }
620
621 DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes,
622 show_bgp_ipv6_encap_rd_neighbor_routes_cmd,
623 "show [ip] bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> routes",
624 SHOW_STR
625 IP_STR
626 BGP_STR
627 "Address Family\n"
628 "Display ENCAP NLRI specific information\n"
629 "Display information for a route distinguisher\n"
630 "ENCAP Route Distinguisher\n"
631 "Detailed information on TCP and BGP neighbor connections\n"
632 "Neighbor to display information about\n"
633 "Neighbor to display information about\n"
634 "Display routes learned from neighbor\n")
635 {
636 int idx_rd = 5;
637 int idx_peer = 7;
638 int ret;
639 union sockunion su;
640 struct peer *peer;
641 struct prefix_rd prd;
642
643 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
644 if (! ret)
645 {
646 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
647 return CMD_WARNING;
648 }
649
650 if (str2sockunion(argv[idx_peer]->arg, &su))
651 {
652 vty_out (vty, "Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
653 return CMD_WARNING;
654 }
655
656 peer = peer_lookup (NULL, &su);
657 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
658 {
659 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
660 return CMD_WARNING;
661 }
662
663 return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, &su, 0);
664 }
665
666 DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes,
667 show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd,
668 "show [ip] bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> advertised-routes",
669 SHOW_STR
670 IP_STR
671 BGP_STR
672 "Address Family\n"
673 "Display ENCAP NLRI specific information\n"
674 "Display information for a route distinguisher\n"
675 "ENCAP Route Distinguisher\n"
676 "Detailed information on TCP and BGP neighbor connections\n"
677 "Neighbor to display information about\n"
678 "Neighbor to display information about\n"
679 "Display the routes advertised to a BGP neighbor\n")
680 {
681 int idx_rd = 5;
682 int idx_peer = 7;
683 int ret;
684 struct peer *peer;
685 struct prefix_rd prd;
686 union sockunion su;
687
688 ret = str2sockunion (argv[idx_peer]->arg, &su);
689 if (ret < 0)
690 {
691 vty_out (vty, "%% Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
692 return CMD_WARNING;
693 }
694 peer = peer_lookup (NULL, &su);
695 if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP])
696 {
697 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
698 return CMD_WARNING;
699 }
700
701 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
702 if (! ret)
703 {
704 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
705 return CMD_WARNING;
706 }
707
708 return show_adj_route_encap (vty, peer, &prd);
709 }
710
711 DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes,
712 show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd,
713 "show [ip] bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors <A.B.C.D|X:X::X:X> advertised-routes",
714 SHOW_STR
715 IP_STR
716 BGP_STR
717 "Address Family\n"
718 "Display ENCAP NLRI specific information\n"
719 "Display information for a route distinguisher\n"
720 "ENCAP Route Distinguisher\n"
721 "Detailed information on TCP and BGP neighbor connections\n"
722 "Neighbor to display information about\n"
723 "Neighbor to display information about\n"
724 "Display the routes advertised to a BGP neighbor\n")
725 {
726 int idx_rd = 5;
727 int idx_peer = 7;
728 int ret;
729 struct peer *peer;
730 struct prefix_rd prd;
731 union sockunion su;
732
733 ret = str2sockunion (argv[idx_peer]->arg, &su);
734 if (ret < 0)
735 {
736 vty_out (vty, "%% Malformed address: %s%s", argv[idx_peer]->arg, VTY_NEWLINE);
737 return CMD_WARNING;
738 }
739 peer = peer_lookup (NULL, &su);
740 if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP])
741 {
742 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
743 return CMD_WARNING;
744 }
745
746 ret = str2prefix_rd (argv[idx_rd]->arg, &prd);
747 if (! ret)
748 {
749 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
750 return CMD_WARNING;
751 }
752
753 return show_adj_route_encap (vty, peer, &prd);
754 }
755
756 void
757 bgp_encap_init (void)
758 {
759 install_element (BGP_ENCAP_NODE, &encap_network_cmd);
760 install_element (BGP_ENCAP_NODE, &no_encap_network_cmd);
761
762 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_cmd);
763 install_element (VIEW_NODE, &show_bgp_ipv4_encap_tags_cmd);
764 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_tags_cmd);
765 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd);
766 install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd);
767
768 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_cmd);
769 install_element (VIEW_NODE, &show_bgp_ipv6_encap_tags_cmd);
770 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_tags_cmd);
771 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd);
772 install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd);
773 }