bgp_mplsvpn.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /* MPLS-VPN
  2. Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #include <zebra.h>
  17. #include "command.h"
  18. #include "prefix.h"
  19. #include "log.h"
  20. #include "memory.h"
  21. #include "stream.h"
  22. #include "filter.h"
  23. #include "bgpd/bgpd.h"
  24. #include "bgpd/bgp_table.h"
  25. #include "bgpd/bgp_route.h"
  26. #include "bgpd/bgp_attr.h"
  27. #include "bgpd/bgp_mplsvpn.h"
  28. static u_int16_t
  29. decode_rd_type (u_char *pnt)
  30. {
  31. u_int16_t v;
  32. v = ((u_int16_t) *pnt++ << 8);
  33. v |= (u_int16_t) *pnt;
  34. return v;
  35. }
  36. u_int32_t
  37. decode_label (u_char *pnt)
  38. {
  39. u_int32_t l;
  40. l = ((u_int32_t) *pnt++ << 12);
  41. l |= (u_int32_t) *pnt++ << 4;
  42. l |= (u_int32_t) ((*pnt & 0xf0) >> 4);
  43. return l;
  44. }
  45. static void
  46. decode_rd_as (u_char *pnt, struct rd_as *rd_as)
  47. {
  48. rd_as->as = (u_int16_t) *pnt++ << 8;
  49. rd_as->as |= (u_int16_t) *pnt++;
  50. rd_as->val = ((u_int32_t) *pnt++ << 24);
  51. rd_as->val |= ((u_int32_t) *pnt++ << 16);
  52. rd_as->val |= ((u_int32_t) *pnt++ << 8);
  53. rd_as->val |= (u_int32_t) *pnt;
  54. }
  55. static void
  56. decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
  57. {
  58. memcpy (&rd_ip->ip, pnt, 4);
  59. pnt += 4;
  60. rd_ip->val = ((u_int16_t) *pnt++ << 8);
  61. rd_ip->val |= (u_int16_t) *pnt;
  62. }
  63. int
  64. bgp_nlri_parse_vpnv4 (struct peer *peer, struct attr *attr,
  65. struct bgp_nlri *packet)
  66. {
  67. u_char *pnt;
  68. u_char *lim;
  69. struct prefix p;
  70. int psize;
  71. int prefixlen;
  72. u_int16_t type;
  73. struct rd_as rd_as;
  74. struct rd_ip rd_ip;
  75. struct prefix_rd prd;
  76. u_char *tagpnt;
  77. /* Check peer status. */
  78. if (peer->status != Established)
  79. return 0;
  80. /* Make prefix_rd */
  81. prd.family = AF_UNSPEC;
  82. prd.prefixlen = 64;
  83. pnt = packet->nlri;
  84. lim = pnt + packet->length;
  85. #define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
  86. for (; pnt < lim; pnt += psize)
  87. {
  88. /* Clear prefix structure. */
  89. memset (&p, 0, sizeof (struct prefix));
  90. /* Fetch prefix length. */
  91. prefixlen = *pnt++;
  92. p.family = afi2family (packet->afi);
  93. psize = PSIZE (prefixlen);
  94. /* sanity check against packet data */
  95. if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8 || (pnt + psize) > lim)
  96. {
  97. zlog_err ("prefix length (%d) is less than 88"
  98. " or larger than received (%u)",
  99. prefixlen, (uint)(lim-pnt));
  100. return -1;
  101. }
  102. /* sanity check against storage for the IP address portion */
  103. if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
  104. {
  105. zlog_err ("prefix length (%d) exceeds prefix storage (%zu)",
  106. prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
  107. return -1;
  108. }
  109. /* Sanity check against max bitlen of the address family */
  110. if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
  111. {
  112. zlog_err ("prefix length (%d) exceeds family (%u) max byte length (%u)",
  113. prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
  114. p.family, prefix_blen (&p));
  115. return -1;
  116. }
  117. /* Copyr label to prefix. */
  118. tagpnt = pnt;
  119. /* Copy routing distinguisher to rd. */
  120. memcpy (&prd.val, pnt + 3, 8);
  121. /* Decode RD type. */
  122. type = decode_rd_type (pnt + 3);
  123. /* Decode RD value. */
  124. if (type == RD_TYPE_AS)
  125. decode_rd_as (pnt + 5, &rd_as);
  126. else if (type == RD_TYPE_IP)
  127. decode_rd_ip (pnt + 5, &rd_ip);
  128. else
  129. {
  130. zlog_err ("Invalid RD type %d", type);
  131. return -1;
  132. }
  133. p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
  134. memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
  135. psize - VPN_PREFIXLEN_MIN_BYTES);
  136. #if 0
  137. if (type == RD_TYPE_AS)
  138. zlog_info ("prefix %ld:%ld:%ld:%s/%d", label, rd_as.as, rd_as.val,
  139. inet_ntoa (p.u.prefix4), p.prefixlen);
  140. else if (type == RD_TYPE_IP)
  141. zlog_info ("prefix %ld:%s:%ld:%s/%d", label, inet_ntoa (rd_ip.ip),
  142. rd_ip.val, inet_ntoa (p.u.prefix4), p.prefixlen);
  143. #endif /* 0 */
  144. if (attr)
  145. bgp_update (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
  146. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
  147. else
  148. bgp_withdraw (peer, &p, attr, AFI_IP, SAFI_MPLS_VPN,
  149. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
  150. }
  151. /* Packet length consistency check. */
  152. if (pnt != lim)
  153. return -1;
  154. return 0;
  155. #undef VPN_PREFIXLEN_MIN_BYTES
  156. }
  157. int
  158. str2prefix_rd (const char *str, struct prefix_rd *prd)
  159. {
  160. int ret; /* ret of called functions */
  161. int lret; /* local ret, of this func */
  162. char *p;
  163. char *p2;
  164. struct stream *s = NULL;
  165. char *half = NULL;
  166. struct in_addr addr;
  167. s = stream_new (8);
  168. prd->family = AF_UNSPEC;
  169. prd->prefixlen = 64;
  170. lret = 0;
  171. p = strchr (str, ':');
  172. if (! p)
  173. goto out;
  174. if (! all_digit (p + 1))
  175. goto out;
  176. half = XMALLOC (MTYPE_TMP, (p - str) + 1);
  177. memcpy (half, str, (p - str));
  178. half[p - str] = '\0';
  179. p2 = strchr (str, '.');
  180. if (! p2)
  181. {
  182. if (! all_digit (half))
  183. goto out;
  184. stream_putw (s, RD_TYPE_AS);
  185. stream_putw (s, atoi (half));
  186. stream_putl (s, atol (p + 1));
  187. }
  188. else
  189. {
  190. ret = inet_aton (half, &addr);
  191. if (! ret)
  192. goto out;
  193. stream_putw (s, RD_TYPE_IP);
  194. stream_put_in_addr (s, &addr);
  195. stream_putw (s, atol (p + 1));
  196. }
  197. memcpy (prd->val, s->data, 8);
  198. lret = 1;
  199. out:
  200. if (s)
  201. stream_free (s);
  202. if (half)
  203. XFREE(MTYPE_TMP, half);
  204. return lret;
  205. }
  206. int
  207. str2tag (const char *str, u_char *tag)
  208. {
  209. unsigned long l;
  210. char *endptr;
  211. u_int32_t t;
  212. if (*str == '-')
  213. return 0;
  214. errno = 0;
  215. l = strtoul (str, &endptr, 10);
  216. if (*endptr != '\0' || errno || l > UINT32_MAX)
  217. return 0;
  218. t = (u_int32_t) l;
  219. tag[0] = (u_char)(t >> 12);
  220. tag[1] = (u_char)(t >> 4);
  221. tag[2] = (u_char)(t << 4);
  222. return 1;
  223. }
  224. char *
  225. prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
  226. {
  227. u_char *pnt;
  228. u_int16_t type;
  229. struct rd_as rd_as;
  230. struct rd_ip rd_ip;
  231. if (size < RD_ADDRSTRLEN)
  232. return NULL;
  233. pnt = prd->val;
  234. type = decode_rd_type (pnt);
  235. if (type == RD_TYPE_AS)
  236. {
  237. decode_rd_as (pnt + 2, &rd_as);
  238. snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
  239. return buf;
  240. }
  241. else if (type == RD_TYPE_IP)
  242. {
  243. decode_rd_ip (pnt + 2, &rd_ip);
  244. snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
  245. return buf;
  246. }
  247. return NULL;
  248. }
  249. /* For testing purpose, static route of MPLS-VPN. */
  250. DEFUN (vpnv4_network,
  251. vpnv4_network_cmd,
  252. "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
  253. "Specify a network to announce via BGP\n"
  254. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  255. "Specify Route Distinguisher\n"
  256. "VPN Route Distinguisher\n"
  257. "BGP tag\n"
  258. "tag value\n")
  259. {
  260. return bgp_static_set_vpnv4 (vty, argv[0], argv[1], argv[2]);
  261. }
  262. /* For testing purpose, static route of MPLS-VPN. */
  263. DEFUN (no_vpnv4_network,
  264. no_vpnv4_network_cmd,
  265. "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
  266. NO_STR
  267. "Specify a network to announce via BGP\n"
  268. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  269. "Specify Route Distinguisher\n"
  270. "VPN Route Distinguisher\n"
  271. "BGP tag\n"
  272. "tag value\n")
  273. {
  274. return bgp_static_unset_vpnv4 (vty, argv[0], argv[1], argv[2]);
  275. }
  276. static int
  277. show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
  278. {
  279. struct bgp *bgp;
  280. struct bgp_table *table;
  281. struct bgp_node *rn;
  282. struct bgp_node *rm;
  283. struct attr *attr;
  284. int rd_header;
  285. int header = 1;
  286. char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
  287. bgp = bgp_get_default ();
  288. if (bgp == NULL)
  289. {
  290. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  291. return CMD_WARNING;
  292. }
  293. for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn;
  294. rn = bgp_route_next (rn))
  295. {
  296. if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
  297. continue;
  298. if ((table = rn->info) != NULL)
  299. {
  300. rd_header = 1;
  301. for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
  302. if ((attr = rm->info) != NULL)
  303. {
  304. if (header)
  305. {
  306. vty_out (vty, "BGP table version is 0, local router ID is %s%s",
  307. inet_ntoa (bgp->router_id), VTY_NEWLINE);
  308. vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
  309. VTY_NEWLINE);
  310. vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
  311. VTY_NEWLINE, VTY_NEWLINE);
  312. vty_out (vty, v4_header, VTY_NEWLINE);
  313. header = 0;
  314. }
  315. if (rd_header)
  316. {
  317. u_int16_t type;
  318. struct rd_as rd_as;
  319. struct rd_ip rd_ip;
  320. u_char *pnt;
  321. pnt = rn->p.u.val;
  322. /* Decode RD type. */
  323. type = decode_rd_type (pnt);
  324. /* Decode RD value. */
  325. if (type == RD_TYPE_AS)
  326. decode_rd_as (pnt + 2, &rd_as);
  327. else if (type == RD_TYPE_IP)
  328. decode_rd_ip (pnt + 2, &rd_ip);
  329. vty_out (vty, "Route Distinguisher: ");
  330. if (type == RD_TYPE_AS)
  331. vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
  332. else if (type == RD_TYPE_IP)
  333. vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
  334. vty_out (vty, "%s", VTY_NEWLINE);
  335. rd_header = 0;
  336. }
  337. route_vty_out_tmp (vty, &rm->p, attr, SAFI_MPLS_VPN);
  338. }
  339. }
  340. }
  341. return CMD_SUCCESS;
  342. }
  343. enum bgp_show_type
  344. {
  345. bgp_show_type_normal,
  346. bgp_show_type_regexp,
  347. bgp_show_type_prefix_list,
  348. bgp_show_type_filter_list,
  349. bgp_show_type_neighbor,
  350. bgp_show_type_cidr_only,
  351. bgp_show_type_prefix_longer,
  352. bgp_show_type_community_all,
  353. bgp_show_type_community,
  354. bgp_show_type_community_exact,
  355. bgp_show_type_community_list,
  356. bgp_show_type_community_list_exact
  357. };
  358. static int
  359. bgp_show_mpls_vpn (struct vty *vty, struct prefix_rd *prd, enum bgp_show_type type,
  360. void *output_arg, int tags)
  361. {
  362. struct bgp *bgp;
  363. struct bgp_table *table;
  364. struct bgp_node *rn;
  365. struct bgp_node *rm;
  366. struct bgp_info *ri;
  367. int rd_header;
  368. int header = 1;
  369. char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
  370. char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
  371. bgp = bgp_get_default ();
  372. if (bgp == NULL)
  373. {
  374. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  375. return CMD_WARNING;
  376. }
  377. for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
  378. {
  379. if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
  380. continue;
  381. if ((table = rn->info) != NULL)
  382. {
  383. rd_header = 1;
  384. for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
  385. for (ri = rm->info; ri; ri = ri->next)
  386. {
  387. if (type == bgp_show_type_neighbor)
  388. {
  389. union sockunion *su = output_arg;
  390. if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
  391. continue;
  392. }
  393. if (header)
  394. {
  395. if (tags)
  396. vty_out (vty, v4_header_tag, VTY_NEWLINE);
  397. else
  398. {
  399. vty_out (vty, "BGP table version is 0, local router ID is %s%s",
  400. inet_ntoa (bgp->router_id), VTY_NEWLINE);
  401. vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
  402. VTY_NEWLINE);
  403. vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
  404. VTY_NEWLINE, VTY_NEWLINE);
  405. vty_out (vty, v4_header, VTY_NEWLINE);
  406. }
  407. header = 0;
  408. }
  409. if (rd_header)
  410. {
  411. u_int16_t type;
  412. struct rd_as rd_as;
  413. struct rd_ip rd_ip;
  414. u_char *pnt;
  415. pnt = rn->p.u.val;
  416. /* Decode RD type. */
  417. type = decode_rd_type (pnt);
  418. /* Decode RD value. */
  419. if (type == RD_TYPE_AS)
  420. decode_rd_as (pnt + 2, &rd_as);
  421. else if (type == RD_TYPE_IP)
  422. decode_rd_ip (pnt + 2, &rd_ip);
  423. vty_out (vty, "Route Distinguisher: ");
  424. if (type == RD_TYPE_AS)
  425. vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
  426. else if (type == RD_TYPE_IP)
  427. vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
  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_MPLS_VPN);
  433. else
  434. route_vty_out (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
  435. }
  436. }
  437. }
  438. return CMD_SUCCESS;
  439. }
  440. DEFUN (show_ip_bgp_vpnv4_all,
  441. show_ip_bgp_vpnv4_all_cmd,
  442. "show ip bgp vpnv4 all",
  443. SHOW_STR
  444. IP_STR
  445. BGP_STR
  446. "Display VPNv4 NLRI specific information\n"
  447. "Display information about all VPNv4 NLRIs\n")
  448. {
  449. return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 0);
  450. }
  451. DEFUN (show_ip_bgp_vpnv4_rd,
  452. show_ip_bgp_vpnv4_rd_cmd,
  453. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn",
  454. SHOW_STR
  455. IP_STR
  456. BGP_STR
  457. "Display VPNv4 NLRI specific information\n"
  458. "Display information for a route distinguisher\n"
  459. "VPN Route Distinguisher\n")
  460. {
  461. int ret;
  462. struct prefix_rd prd;
  463. ret = str2prefix_rd (argv[0], &prd);
  464. if (! ret)
  465. {
  466. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  467. return CMD_WARNING;
  468. }
  469. return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 0);
  470. }
  471. DEFUN (show_ip_bgp_vpnv4_all_tags,
  472. show_ip_bgp_vpnv4_all_tags_cmd,
  473. "show ip bgp vpnv4 all tags",
  474. SHOW_STR
  475. IP_STR
  476. BGP_STR
  477. "Display VPNv4 NLRI specific information\n"
  478. "Display information about all VPNv4 NLRIs\n"
  479. "Display BGP tags for prefixes\n")
  480. {
  481. return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_normal, NULL, 1);
  482. }
  483. DEFUN (show_ip_bgp_vpnv4_rd_tags,
  484. show_ip_bgp_vpnv4_rd_tags_cmd,
  485. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn tags",
  486. SHOW_STR
  487. IP_STR
  488. BGP_STR
  489. "Display VPNv4 NLRI specific information\n"
  490. "Display information for a route distinguisher\n"
  491. "VPN Route Distinguisher\n"
  492. "Display BGP tags for prefixes\n")
  493. {
  494. int ret;
  495. struct prefix_rd prd;
  496. ret = str2prefix_rd (argv[0], &prd);
  497. if (! ret)
  498. {
  499. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  500. return CMD_WARNING;
  501. }
  502. return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_normal, NULL, 1);
  503. }
  504. DEFUN (show_ip_bgp_vpnv4_all_neighbor_routes,
  505. show_ip_bgp_vpnv4_all_neighbor_routes_cmd,
  506. "show ip bgp vpnv4 all neighbors A.B.C.D routes",
  507. SHOW_STR
  508. IP_STR
  509. BGP_STR
  510. "Display VPNv4 NLRI specific information\n"
  511. "Display information about all VPNv4 NLRIs\n"
  512. "Detailed information on TCP and BGP neighbor connections\n"
  513. "Neighbor to display information about\n"
  514. "Display routes learned from neighbor\n")
  515. {
  516. union sockunion su;
  517. struct peer *peer;
  518. int ret;
  519. ret = str2sockunion (argv[0], &su);
  520. if (ret < 0)
  521. {
  522. vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
  523. return CMD_WARNING;
  524. }
  525. peer = peer_lookup (NULL, &su);
  526. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  527. {
  528. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  529. return CMD_WARNING;
  530. }
  531. return bgp_show_mpls_vpn (vty, NULL, bgp_show_type_neighbor, &su, 0);
  532. }
  533. DEFUN (show_ip_bgp_vpnv4_rd_neighbor_routes,
  534. show_ip_bgp_vpnv4_rd_neighbor_routes_cmd,
  535. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D routes",
  536. SHOW_STR
  537. IP_STR
  538. BGP_STR
  539. "Display VPNv4 NLRI specific information\n"
  540. "Display information for a route distinguisher\n"
  541. "VPN Route Distinguisher\n"
  542. "Detailed information on TCP and BGP neighbor connections\n"
  543. "Neighbor to display information about\n"
  544. "Display routes learned from neighbor\n")
  545. {
  546. int ret;
  547. union sockunion su;
  548. struct peer *peer;
  549. struct prefix_rd prd;
  550. ret = str2prefix_rd (argv[0], &prd);
  551. if (! ret)
  552. {
  553. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  554. return CMD_WARNING;
  555. }
  556. ret = str2sockunion (argv[1], &su);
  557. if (ret < 0)
  558. {
  559. vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
  560. return CMD_WARNING;
  561. }
  562. peer = peer_lookup (NULL, &su);
  563. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  564. {
  565. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  566. return CMD_WARNING;
  567. }
  568. return bgp_show_mpls_vpn (vty, &prd, bgp_show_type_neighbor, &su, 0);
  569. }
  570. DEFUN (show_ip_bgp_vpnv4_all_neighbor_advertised_routes,
  571. show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd,
  572. "show ip bgp vpnv4 all neighbors A.B.C.D advertised-routes",
  573. SHOW_STR
  574. IP_STR
  575. BGP_STR
  576. "Display VPNv4 NLRI specific information\n"
  577. "Display information about all VPNv4 NLRIs\n"
  578. "Detailed information on TCP and BGP neighbor connections\n"
  579. "Neighbor to display information about\n"
  580. "Display the routes advertised to a BGP neighbor\n")
  581. {
  582. int ret;
  583. struct peer *peer;
  584. union sockunion su;
  585. ret = str2sockunion (argv[0], &su);
  586. if (ret < 0)
  587. {
  588. vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
  589. return CMD_WARNING;
  590. }
  591. peer = peer_lookup (NULL, &su);
  592. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  593. {
  594. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  595. return CMD_WARNING;
  596. }
  597. return show_adj_route_vpn (vty, peer, NULL);
  598. }
  599. DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
  600. show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd,
  601. "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn neighbors A.B.C.D advertised-routes",
  602. SHOW_STR
  603. IP_STR
  604. BGP_STR
  605. "Display VPNv4 NLRI specific information\n"
  606. "Display information for a route distinguisher\n"
  607. "VPN Route Distinguisher\n"
  608. "Detailed information on TCP and BGP neighbor connections\n"
  609. "Neighbor to display information about\n"
  610. "Display the routes advertised to a BGP neighbor\n")
  611. {
  612. int ret;
  613. struct peer *peer;
  614. struct prefix_rd prd;
  615. union sockunion su;
  616. ret = str2sockunion (argv[1], &su);
  617. if (ret < 0)
  618. {
  619. vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
  620. return CMD_WARNING;
  621. }
  622. peer = peer_lookup (NULL, &su);
  623. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  624. {
  625. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  626. return CMD_WARNING;
  627. }
  628. ret = str2prefix_rd (argv[0], &prd);
  629. if (! ret)
  630. {
  631. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  632. return CMD_WARNING;
  633. }
  634. return show_adj_route_vpn (vty, peer, &prd);
  635. }
  636. void
  637. bgp_mplsvpn_init (void)
  638. {
  639. install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
  640. install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
  641. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_cmd);
  642. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_cmd);
  643. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
  644. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
  645. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
  646. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
  647. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
  648. install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
  649. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_cmd);
  650. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_cmd);
  651. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_tags_cmd);
  652. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_tags_cmd);
  653. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_routes_cmd);
  654. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_routes_cmd);
  655. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_neighbor_advertised_routes_cmd);
  656. install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_neighbor_advertised_routes_cmd);
  657. }