]>
Commit | Line | Data |
---|---|---|
587ff0fd LB |
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_mplsvpn.h" | |
45 | #include "bgpd/bgp_vty.h" | |
46 | #include "bgpd/bgp_encap.h" | |
47 | ||
65efcfce LB |
48 | #if ENABLE_BGP_VNC |
49 | #include "rfapi_backend.h" | |
50 | #endif | |
51 | ||
587ff0fd LB |
52 | static void |
53 | ecom2prd(struct ecommunity *ecom, struct prefix_rd *prd) | |
54 | { | |
55 | int i; | |
56 | ||
57 | memset(prd, 0, sizeof(struct prefix_rd)); | |
58 | prd->family = AF_UNSPEC; | |
59 | prd->prefixlen = 64; | |
60 | ||
61 | if (!ecom) | |
62 | return; | |
63 | ||
64 | for (i = 0; i < (ecom->size * ECOMMUNITY_SIZE); i += ECOMMUNITY_SIZE) { | |
65 | ||
66 | uint8_t *ep; | |
67 | ||
68 | ep = ecom->val + i; | |
69 | ||
70 | switch (ep[0]) { | |
71 | default: | |
72 | continue; | |
73 | ||
74 | case 0x80: | |
75 | case 0x81: | |
76 | case 0x82: | |
77 | if (ep[1] == 0x0) { | |
78 | prd->val[1] = ep[0] & 0x03; | |
79 | memcpy(prd->val + 2, ep + 2, 6); | |
80 | return; | |
81 | } | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
86 | int | |
87 | bgp_nlri_parse_encap( | |
88 | afi_t afi, | |
89 | struct peer *peer, | |
90 | struct attr *attr, /* Need even for withdraw */ | |
91 | struct bgp_nlri *packet, | |
92 | int withdraw) /* 0=update, !0 = withdraw */ | |
93 | { | |
94 | u_char *pnt; | |
95 | u_char *lim; | |
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 (!withdraw) { | |
190 | bgp_update (peer, &p, 0, attr, afi, SAFI_ENCAP, | |
191 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL, 0); | |
65efcfce LB |
192 | #if ENABLE_BGP_VNC |
193 | rfapiProcessUpdate(peer, NULL, &p, &prd, attr, afi, SAFI_ENCAP, | |
194 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL); | |
195 | #endif | |
587ff0fd | 196 | } else { |
65efcfce LB |
197 | #if ENABLE_BGP_VNC |
198 | rfapiProcessWithdraw(peer, NULL, &p, &prd, attr, afi, SAFI_ENCAP, | |
199 | ZEBRA_ROUTE_BGP, 0); | |
200 | #endif | |
587ff0fd LB |
201 | bgp_withdraw (peer, &p, 0, attr, afi, SAFI_ENCAP, |
202 | ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, NULL); | |
203 | } | |
204 | } | |
205 | ||
206 | /* Packet length consistency check. */ | |
207 | if (pnt != lim) | |
208 | return -1; | |
209 | ||
210 | return 0; | |
211 | } | |
212 | ||
213 | ||
214 | /* TBD: these routes should probably all be host routes */ | |
215 | ||
216 | /* For testing purpose, static route of ENCAP. */ | |
217 | DEFUN (encap_network, | |
218 | encap_network_cmd, | |
219 | "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD", | |
220 | "Specify a network to announce via BGP\n" | |
221 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
222 | "Specify Route Distinguisher\n" | |
223 | "ENCAP Route Distinguisher\n" | |
224 | "BGP tag\n" | |
225 | "tag value\n") | |
226 | { | |
227 | return bgp_static_set_safi (SAFI_ENCAP, vty, argv[0], argv[1], argv[2], NULL); | |
228 | } | |
229 | ||
230 | /* For testing purpose, static route of ENCAP. */ | |
231 | DEFUN (no_encap_network, | |
232 | no_encap_network_cmd, | |
233 | "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD", | |
234 | NO_STR | |
235 | "Specify a network to announce via BGP\n" | |
236 | "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n" | |
237 | "Specify Route Distinguisher\n" | |
238 | "ENCAP Route Distinguisher\n" | |
239 | "BGP tag\n" | |
240 | "tag value\n") | |
241 | { | |
242 | return bgp_static_unset_safi (SAFI_ENCAP, vty, argv[0], argv[1], argv[2]); | |
243 | } | |
244 | ||
245 | static int | |
246 | show_adj_route_encap (struct vty *vty, struct peer *peer, struct prefix_rd *prd) | |
247 | { | |
248 | struct bgp *bgp; | |
249 | struct bgp_table *table; | |
250 | struct bgp_node *rn; | |
251 | struct bgp_node *rm; | |
252 | struct attr *attr; | |
253 | int rd_header; | |
254 | int header = 1; | |
255 | char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s"; | |
256 | ||
257 | bgp = bgp_get_default (); | |
258 | if (bgp == NULL) | |
259 | { | |
260 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
261 | return CMD_WARNING; | |
262 | } | |
263 | ||
264 | for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_ENCAP]); rn; | |
265 | rn = bgp_route_next (rn)) | |
266 | { | |
267 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) | |
268 | continue; | |
269 | ||
270 | if ((table = rn->info) != NULL) | |
271 | { | |
272 | rd_header = 1; | |
273 | ||
274 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) | |
275 | if ((attr = rm->info) != NULL) | |
276 | { | |
277 | if (header) | |
278 | { | |
279 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", | |
280 | inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
281 | vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", | |
282 | VTY_NEWLINE); | |
283 | vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", | |
284 | VTY_NEWLINE, VTY_NEWLINE); | |
285 | vty_out (vty, v4_header, VTY_NEWLINE); | |
286 | header = 0; | |
287 | } | |
288 | ||
289 | if (rd_header) | |
290 | { | |
291 | u_int16_t type; | |
292 | struct rd_as rd_as; | |
293 | struct rd_ip rd_ip; | |
294 | u_char *pnt; | |
295 | ||
296 | pnt = rn->p.u.val; | |
297 | ||
298 | vty_out (vty, "Route Distinguisher: "); | |
299 | ||
300 | /* Decode RD type. */ | |
301 | type = decode_rd_type (pnt); | |
302 | ||
303 | switch (type) { | |
304 | ||
305 | case RD_TYPE_AS: | |
306 | decode_rd_as (pnt + 2, &rd_as); | |
307 | vty_out (vty, "%u:%d", rd_as.as, rd_as.val); | |
308 | break; | |
309 | ||
310 | case RD_TYPE_IP: | |
311 | decode_rd_ip (pnt + 2, &rd_ip); | |
312 | vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val); | |
313 | break; | |
314 | ||
315 | default: | |
316 | vty_out (vty, "unknown RD type"); | |
317 | } | |
318 | ||
319 | ||
320 | vty_out (vty, "%s", VTY_NEWLINE); | |
321 | rd_header = 0; | |
322 | } | |
323 | route_vty_out_tmp (vty, &rm->p, attr, SAFI_ENCAP, 0, NULL); | |
324 | } | |
325 | } | |
326 | } | |
327 | return CMD_SUCCESS; | |
328 | } | |
329 | ||
330 | enum bgp_show_type | |
331 | { | |
332 | bgp_show_type_normal, | |
333 | bgp_show_type_regexp, | |
334 | bgp_show_type_prefix_list, | |
335 | bgp_show_type_filter_list, | |
336 | bgp_show_type_neighbor, | |
337 | bgp_show_type_cidr_only, | |
338 | bgp_show_type_prefix_longer, | |
339 | bgp_show_type_community_all, | |
340 | bgp_show_type_community, | |
341 | bgp_show_type_community_exact, | |
342 | bgp_show_type_community_list, | |
343 | bgp_show_type_community_list_exact | |
344 | }; | |
345 | ||
346 | static int | |
347 | bgp_show_encap ( | |
348 | struct vty *vty, | |
349 | afi_t afi, | |
350 | struct prefix_rd *prd, | |
351 | enum bgp_show_type type, | |
352 | void *output_arg, | |
353 | int tags) | |
354 | { | |
355 | struct bgp *bgp; | |
356 | struct bgp_table *table; | |
357 | struct bgp_node *rn; | |
358 | struct bgp_node *rm; | |
359 | struct bgp_info *ri; | |
360 | int rd_header; | |
361 | int header = 1; | |
362 | char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s"; | |
363 | char v4_header_tag[] = " Network Next Hop In tag/Out tag%s"; | |
364 | ||
365 | unsigned long output_count = 0; | |
366 | unsigned long total_count = 0; | |
367 | ||
368 | bgp = bgp_get_default (); | |
369 | if (bgp == NULL) | |
370 | { | |
371 | vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE); | |
372 | return CMD_WARNING; | |
373 | } | |
374 | ||
375 | if ((afi != AFI_IP) && (afi != AFI_IP6)) { | |
376 | vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE); | |
377 | return CMD_WARNING; | |
378 | } | |
379 | ||
380 | for (rn = bgp_table_top (bgp->rib[afi][SAFI_ENCAP]); rn; rn = bgp_route_next (rn)) | |
381 | { | |
382 | if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0) | |
383 | continue; | |
384 | ||
385 | if ((table = rn->info) != NULL) | |
386 | { | |
387 | rd_header = 1; | |
388 | ||
389 | for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm)) | |
390 | for (ri = rm->info; ri; ri = ri->next) | |
391 | { | |
392 | total_count++; | |
393 | if (type == bgp_show_type_neighbor) | |
394 | { | |
395 | union sockunion *su = output_arg; | |
396 | ||
397 | if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su)) | |
398 | continue; | |
399 | } | |
400 | if (header) | |
401 | { | |
402 | if (tags) | |
403 | vty_out (vty, v4_header_tag, VTY_NEWLINE); | |
404 | else | |
405 | { | |
406 | vty_out (vty, "BGP table version is 0, local router ID is %s%s", | |
407 | inet_ntoa (bgp->router_id), VTY_NEWLINE); | |
408 | vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s", | |
409 | VTY_NEWLINE); | |
410 | vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s", | |
411 | VTY_NEWLINE, VTY_NEWLINE); | |
412 | vty_out (vty, v4_header, VTY_NEWLINE); | |
413 | } | |
414 | header = 0; | |
415 | } | |
416 | ||
417 | if (rd_header) | |
418 | { | |
419 | u_int16_t type; | |
420 | struct rd_as rd_as; | |
421 | struct rd_ip rd_ip; | |
422 | u_char *pnt; | |
423 | ||
424 | pnt = rn->p.u.val; | |
425 | ||
426 | /* Decode RD type. */ | |
427 | type = decode_rd_type (pnt); | |
428 | ||
429 | vty_out (vty, "Route Distinguisher: "); | |
430 | ||
431 | switch (type) { | |
432 | ||
433 | case RD_TYPE_AS: | |
434 | decode_rd_as (pnt + 2, &rd_as); | |
435 | vty_out (vty, "%u:%d", rd_as.as, rd_as.val); | |
436 | break; | |
437 | ||
438 | case RD_TYPE_IP: | |
439 | decode_rd_ip (pnt + 2, &rd_ip); | |
440 | vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val); | |
441 | break; | |
442 | ||
443 | default: | |
444 | vty_out (vty, "Unknown RD type"); | |
445 | break; | |
446 | } | |
447 | ||
448 | vty_out (vty, "%s", VTY_NEWLINE); | |
449 | rd_header = 0; | |
450 | } | |
451 | if (tags) | |
452 | route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_ENCAP, NULL); | |
453 | else | |
454 | route_vty_out (vty, &rm->p, ri, 0, SAFI_ENCAP, NULL); | |
455 | output_count++; | |
456 | } | |
457 | } | |
458 | } | |
459 | ||
460 | if (output_count == 0) | |
461 | { | |
462 | vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE); | |
463 | } | |
464 | else | |
465 | vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s", | |
466 | VTY_NEWLINE, output_count, total_count, VTY_NEWLINE); | |
467 | ||
468 | return CMD_SUCCESS; | |
469 | } | |
470 | ||
471 | DEFUN (show_bgp_ipv4_encap, | |
472 | show_bgp_ipv4_encap_cmd, | |
473 | "show bgp ipv4 encap", | |
474 | SHOW_STR | |
475 | BGP_STR | |
476 | "Address Family\n" | |
477 | "Display ENCAP NLRI specific information\n") | |
478 | { | |
479 | return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0); | |
480 | } | |
481 | #ifdef HAVE_IPV6 | |
482 | DEFUN (show_bgp_ipv6_encap, | |
483 | show_bgp_ipv6_encap_cmd, | |
484 | "show bgp ipv6 encap", | |
485 | SHOW_STR | |
486 | BGP_STR | |
487 | "Address Family\n" | |
488 | "Display ENCAP NLRI specific information\n") | |
489 | { | |
490 | return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 0); | |
491 | } | |
492 | #endif | |
493 | ||
494 | DEFUN (show_bgp_ipv4_encap_rd, | |
495 | show_bgp_ipv4_encap_rd_cmd, | |
496 | "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn", | |
497 | SHOW_STR | |
498 | BGP_STR | |
499 | "Address Family\n" | |
500 | "Display ENCAP NLRI specific information\n" | |
501 | "Display information for a route distinguisher\n" | |
502 | "ENCAP Route Distinguisher\n") | |
503 | { | |
504 | int ret; | |
505 | struct prefix_rd prd; | |
506 | ||
507 | ret = str2prefix_rd (argv[0], &prd); | |
508 | if (! ret) | |
509 | { | |
510 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
511 | return CMD_WARNING; | |
512 | } | |
513 | return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0); | |
514 | } | |
515 | #ifdef HAVE_IPV6 | |
516 | DEFUN (show_bgp_ipv6_encap_rd, | |
517 | show_bgp_ipv6_encap_rd_cmd, | |
518 | "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn", | |
519 | SHOW_STR | |
520 | BGP_STR | |
521 | "Address Family\n" | |
522 | "Display ENCAP NLRI specific information\n" | |
523 | "Display information for a route distinguisher\n" | |
524 | "ENCAP Route Distinguisher\n" | |
525 | "Display BGP tags for prefixes\n") | |
526 | { | |
527 | int ret; | |
528 | struct prefix_rd prd; | |
529 | ||
530 | ret = str2prefix_rd (argv[0], &prd); | |
531 | if (! ret) | |
532 | { | |
533 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
534 | return CMD_WARNING; | |
535 | } | |
536 | return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0); | |
537 | } | |
538 | #endif | |
539 | ||
540 | DEFUN (show_bgp_ipv4_encap_tags, | |
541 | show_bgp_ipv4_encap_tags_cmd, | |
542 | "show bgp ipv4 encap tags", | |
543 | SHOW_STR | |
544 | BGP_STR | |
545 | "Address Family\n" | |
546 | "Display ENCAP NLRI specific information\n" | |
547 | "Display BGP tags for prefixes\n") | |
548 | { | |
549 | return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1); | |
550 | } | |
551 | #ifdef HAVE_IPV6 | |
552 | DEFUN (show_bgp_ipv6_encap_tags, | |
553 | show_bgp_ipv6_encap_tags_cmd, | |
554 | "show bgp ipv6 encap tags", | |
555 | SHOW_STR | |
556 | BGP_STR | |
557 | "Address Family\n" | |
558 | "Display ENCAP NLRI specific information\n" | |
559 | "Display BGP tags for prefixes\n") | |
560 | { | |
561 | return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1); | |
562 | } | |
563 | #endif | |
564 | ||
565 | DEFUN (show_bgp_ipv4_encap_rd_tags, | |
566 | show_bgp_ipv4_encap_rd_tags_cmd, | |
567 | "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn tags", | |
568 | SHOW_STR | |
569 | BGP_STR | |
570 | "Address Family\n" | |
571 | "Display ENCAP NLRI specific information\n" | |
572 | "Display information for a route distinguisher\n" | |
573 | "ENCAP Route Distinguisher\n" | |
574 | "Display BGP tags for prefixes\n") | |
575 | { | |
576 | int ret; | |
577 | struct prefix_rd prd; | |
578 | ||
579 | ret = str2prefix_rd (argv[0], &prd); | |
580 | if (! ret) | |
581 | { | |
582 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
583 | return CMD_WARNING; | |
584 | } | |
585 | return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1); | |
586 | } | |
587 | #ifdef HAVE_IPV6 | |
588 | DEFUN (show_bgp_ipv6_encap_rd_tags, | |
589 | show_bgp_ipv6_encap_rd_tags_cmd, | |
590 | "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn tags", | |
591 | SHOW_STR | |
592 | BGP_STR | |
593 | "Address Family\n" | |
594 | "Display ENCAP NLRI specific information\n" | |
595 | "Display information for a route distinguisher\n" | |
596 | "ENCAP Route Distinguisher\n" | |
597 | "Display BGP tags for prefixes\n") | |
598 | { | |
599 | int ret; | |
600 | struct prefix_rd prd; | |
601 | ||
602 | ret = str2prefix_rd (argv[0], &prd); | |
603 | if (! ret) | |
604 | { | |
605 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
606 | return CMD_WARNING; | |
607 | } | |
608 | return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1); | |
609 | } | |
610 | #endif | |
611 | ||
612 | DEFUN (show_bgp_ipv4_encap_neighbor_routes, | |
613 | show_bgp_ipv4_encap_neighbor_routes_cmd, | |
614 | "show bgp ipv4 encap neighbors A.B.C.D routes", | |
615 | SHOW_STR | |
616 | BGP_STR | |
617 | "Address Family\n" | |
618 | "Display ENCAP NLRI specific information\n" | |
619 | "Detailed information on TCP and BGP neighbor connections\n" | |
620 | "Neighbor to display information about\n" | |
621 | "Display routes learned from neighbor\n") | |
622 | { | |
623 | union sockunion *su; | |
624 | struct peer *peer; | |
625 | ||
626 | su = sockunion_str2su (argv[0]); | |
627 | if (su == NULL) | |
628 | { | |
629 | vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); | |
630 | return CMD_WARNING; | |
631 | } | |
632 | ||
633 | peer = peer_lookup (NULL, su); | |
634 | if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP]) | |
635 | { | |
636 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
637 | return CMD_WARNING; | |
638 | } | |
639 | ||
640 | return bgp_show_encap (vty, AFI_IP, NULL, bgp_show_type_neighbor, su, 0); | |
641 | } | |
642 | #ifdef HAVE_IPV6 | |
643 | DEFUN (show_bgp_ipv6_encap_neighbor_routes, | |
644 | show_bgp_ipv6_encap_neighbor_routes_cmd, | |
645 | "show bgp ipv6 encap neighbors A.B.C.D routes", | |
646 | SHOW_STR | |
647 | BGP_STR | |
648 | "Address Family\n" | |
649 | "Display ENCAP NLRI specific information\n" | |
650 | "Detailed information on TCP and BGP neighbor connections\n" | |
651 | "Neighbor to display information about\n" | |
652 | "Display routes learned from neighbor\n") | |
653 | { | |
654 | union sockunion *su; | |
655 | struct peer *peer; | |
656 | ||
657 | su = sockunion_str2su (argv[0]); | |
658 | if (su == NULL) | |
659 | { | |
660 | vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE); | |
661 | return CMD_WARNING; | |
662 | } | |
663 | ||
664 | peer = peer_lookup (NULL, su); | |
665 | if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP]) | |
666 | { | |
667 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
668 | return CMD_WARNING; | |
669 | } | |
670 | ||
671 | return bgp_show_encap (vty, AFI_IP6, NULL, bgp_show_type_neighbor, su, 0); | |
672 | } | |
673 | #endif | |
674 | ||
675 | DEFUN (show_bgp_ipv4_encap_rd_neighbor_routes, | |
676 | show_bgp_ipv4_encap_rd_neighbor_routes_cmd, | |
677 | "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes", | |
678 | SHOW_STR | |
679 | BGP_STR | |
680 | "Address Family\n" | |
681 | "Display ENCAP NLRI specific information\n" | |
682 | "Display information for a route distinguisher\n" | |
683 | "ENCAP Route Distinguisher\n" | |
684 | "Detailed information on TCP and BGP neighbor connections\n" | |
685 | "Neighbor to display information about\n" | |
686 | "Neighbor to display information about\n" | |
687 | "Display routes learned from neighbor\n") | |
688 | { | |
689 | int ret; | |
690 | union sockunion *su; | |
691 | struct peer *peer; | |
692 | struct prefix_rd prd; | |
693 | ||
694 | ret = str2prefix_rd (argv[0], &prd); | |
695 | if (! ret) | |
696 | { | |
697 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
698 | return CMD_WARNING; | |
699 | } | |
700 | ||
701 | su = sockunion_str2su (argv[1]); | |
702 | if (su == NULL) | |
703 | { | |
704 | vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); | |
705 | return CMD_WARNING; | |
706 | } | |
707 | ||
708 | peer = peer_lookup (NULL, su); | |
709 | if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP]) | |
710 | { | |
711 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
712 | return CMD_WARNING; | |
713 | } | |
714 | ||
715 | return bgp_show_encap (vty, AFI_IP, &prd, bgp_show_type_neighbor, su, 0); | |
716 | } | |
717 | #ifdef HAVE_IPV6 | |
718 | DEFUN (show_bgp_ipv6_encap_rd_neighbor_routes, | |
719 | show_bgp_ipv6_encap_rd_neighbor_routes_cmd, | |
720 | "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes", | |
721 | SHOW_STR | |
722 | BGP_STR | |
723 | "Address Family\n" | |
724 | "Display ENCAP NLRI specific information\n" | |
725 | "Display information for a route distinguisher\n" | |
726 | "ENCAP Route Distinguisher\n" | |
727 | "Detailed information on TCP and BGP neighbor connections\n" | |
728 | "Neighbor to display information about\n" | |
729 | "Neighbor to display information about\n" | |
730 | "Display routes learned from neighbor\n") | |
731 | { | |
732 | int ret; | |
733 | union sockunion *su; | |
734 | struct peer *peer; | |
735 | struct prefix_rd prd; | |
736 | ||
737 | ret = str2prefix_rd (argv[0], &prd); | |
738 | if (! ret) | |
739 | { | |
740 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
741 | return CMD_WARNING; | |
742 | } | |
743 | ||
744 | su = sockunion_str2su (argv[1]); | |
745 | if (su == NULL) | |
746 | { | |
747 | vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE); | |
748 | return CMD_WARNING; | |
749 | } | |
750 | ||
751 | peer = peer_lookup (NULL, su); | |
752 | if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP]) | |
753 | { | |
754 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
755 | return CMD_WARNING; | |
756 | } | |
757 | ||
758 | return bgp_show_encap (vty, AFI_IP6, &prd, bgp_show_type_neighbor, su, 0); | |
759 | } | |
760 | #endif | |
761 | ||
762 | DEFUN (show_bgp_ipv4_encap_neighbor_advertised_routes, | |
763 | show_bgp_ipv4_encap_neighbor_advertised_routes_cmd, | |
764 | "show bgp ipv4 encap neighbors A.B.C.D advertised-routes", | |
765 | SHOW_STR | |
766 | BGP_STR | |
767 | "Address Family\n" | |
768 | "Display ENCAP NLRI specific information\n" | |
769 | "Detailed information on TCP and BGP neighbor connections\n" | |
770 | "Neighbor to display information about\n" | |
771 | "Display the routes advertised to a BGP neighbor\n") | |
772 | { | |
773 | int ret; | |
774 | struct peer *peer; | |
775 | union sockunion su; | |
776 | ||
777 | ret = str2sockunion (argv[0], &su); | |
778 | if (ret < 0) | |
779 | { | |
780 | vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE); | |
781 | return CMD_WARNING; | |
782 | } | |
783 | peer = peer_lookup (NULL, &su); | |
784 | if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP]) | |
785 | { | |
786 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
787 | return CMD_WARNING; | |
788 | } | |
789 | ||
790 | return show_adj_route_encap (vty, peer, NULL); | |
791 | } | |
792 | #ifdef HAVE_IPV6 | |
793 | DEFUN (show_bgp_ipv6_encap_neighbor_advertised_routes, | |
794 | show_bgp_ipv6_encap_neighbor_advertised_routes_cmd, | |
795 | "show bgp ipv6 encap neighbors A.B.C.D advertised-routes", | |
796 | SHOW_STR | |
797 | BGP_STR | |
798 | "Address Family\n" | |
799 | "Display ENCAP NLRI specific information\n" | |
800 | "Detailed information on TCP and BGP neighbor connections\n" | |
801 | "Neighbor to display information about\n" | |
802 | "Display the routes advertised to a BGP neighbor\n") | |
803 | { | |
804 | int ret; | |
805 | struct peer *peer; | |
806 | union sockunion su; | |
807 | ||
808 | ret = str2sockunion (argv[0], &su); | |
809 | if (ret < 0) | |
810 | { | |
811 | vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE); | |
812 | return CMD_WARNING; | |
813 | } | |
814 | peer = peer_lookup (NULL, &su); | |
815 | if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP]) | |
816 | { | |
817 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
818 | return CMD_WARNING; | |
819 | } | |
820 | ||
821 | return show_adj_route_encap (vty, peer, NULL); | |
822 | } | |
823 | #endif | |
824 | ||
825 | DEFUN (show_bgp_ipv4_encap_rd_neighbor_advertised_routes, | |
826 | show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd, | |
827 | "show bgp ipv4 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes", | |
828 | SHOW_STR | |
829 | BGP_STR | |
830 | "Address Family\n" | |
831 | "Display ENCAP NLRI specific information\n" | |
832 | "Display information for a route distinguisher\n" | |
833 | "ENCAP Route Distinguisher\n" | |
834 | "Detailed information on TCP and BGP neighbor connections\n" | |
835 | "Neighbor to display information about\n" | |
836 | "Neighbor to display information about\n" | |
837 | "Display the routes advertised to a BGP neighbor\n") | |
838 | { | |
839 | int ret; | |
840 | struct peer *peer; | |
841 | struct prefix_rd prd; | |
842 | union sockunion su; | |
843 | ||
844 | ret = str2sockunion (argv[1], &su); | |
845 | if (ret < 0) | |
846 | { | |
847 | vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE); | |
848 | return CMD_WARNING; | |
849 | } | |
850 | peer = peer_lookup (NULL, &su); | |
851 | if (! peer || ! peer->afc[AFI_IP][SAFI_ENCAP]) | |
852 | { | |
853 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
854 | return CMD_WARNING; | |
855 | } | |
856 | ||
857 | ret = str2prefix_rd (argv[0], &prd); | |
858 | if (! ret) | |
859 | { | |
860 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
861 | return CMD_WARNING; | |
862 | } | |
863 | ||
864 | return show_adj_route_encap (vty, peer, &prd); | |
865 | } | |
866 | #ifdef HAVE_IPV6 | |
867 | DEFUN (show_bgp_ipv6_encap_rd_neighbor_advertised_routes, | |
868 | show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd, | |
869 | "show bgp ipv6 encap rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes", | |
870 | SHOW_STR | |
871 | BGP_STR | |
872 | "Address Family\n" | |
873 | "Display ENCAP NLRI specific information\n" | |
874 | "Display information for a route distinguisher\n" | |
875 | "ENCAP Route Distinguisher\n" | |
876 | "Detailed information on TCP and BGP neighbor connections\n" | |
877 | "Neighbor to display information about\n" | |
878 | "Neighbor to display information about\n" | |
879 | "Display the routes advertised to a BGP neighbor\n") | |
880 | { | |
881 | int ret; | |
882 | struct peer *peer; | |
883 | struct prefix_rd prd; | |
884 | union sockunion su; | |
885 | ||
886 | ret = str2sockunion (argv[1], &su); | |
887 | if (ret < 0) | |
888 | { | |
889 | vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE); | |
890 | return CMD_WARNING; | |
891 | } | |
892 | peer = peer_lookup (NULL, &su); | |
893 | if (! peer || ! peer->afc[AFI_IP6][SAFI_ENCAP]) | |
894 | { | |
895 | vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE); | |
896 | return CMD_WARNING; | |
897 | } | |
898 | ||
899 | ret = str2prefix_rd (argv[0], &prd); | |
900 | if (! ret) | |
901 | { | |
902 | vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE); | |
903 | return CMD_WARNING; | |
904 | } | |
905 | ||
906 | return show_adj_route_encap (vty, peer, &prd); | |
907 | } | |
908 | #endif | |
909 | ||
910 | void | |
911 | bgp_encap_init (void) | |
912 | { | |
8b1fb8be LB |
913 | install_element (BGP_ENCAP_NODE, &encap_network_cmd); |
914 | install_element (BGP_ENCAP_NODE, &no_encap_network_cmd); | |
587ff0fd LB |
915 | |
916 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_cmd); | |
917 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_cmd); | |
918 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_tags_cmd); | |
919 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_tags_cmd); | |
920 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_neighbor_routes_cmd); | |
921 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd); | |
922 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_neighbor_advertised_routes_cmd); | |
923 | install_element (VIEW_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd); | |
924 | ||
925 | #ifdef HAVE_IPV6 | |
926 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_cmd); | |
927 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_cmd); | |
928 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_tags_cmd); | |
929 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_tags_cmd); | |
930 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_neighbor_routes_cmd); | |
931 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd); | |
932 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd); | |
933 | install_element (VIEW_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd); | |
934 | #endif | |
935 | ||
936 | ||
937 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_cmd); | |
938 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_cmd); | |
939 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_tags_cmd); | |
940 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_tags_cmd); | |
941 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_routes_cmd); | |
942 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_routes_cmd); | |
943 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_neighbor_advertised_routes_cmd); | |
944 | install_element (ENABLE_NODE, &show_bgp_ipv4_encap_rd_neighbor_advertised_routes_cmd); | |
945 | ||
946 | #ifdef HAVE_IPV6 | |
947 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_cmd); | |
948 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_cmd); | |
949 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_tags_cmd); | |
950 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_tags_cmd); | |
951 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_routes_cmd); | |
952 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_routes_cmd); | |
953 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_neighbor_advertised_routes_cmd); | |
954 | install_element (ENABLE_NODE, &show_bgp_ipv6_encap_rd_neighbor_advertised_routes_cmd); | |
955 | #endif | |
956 | ||
957 | ||
958 | } |