bgp_mplsvpn.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  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_packet.h"
  27. #include "bgpd/bgp_attr.h"
  28. #include "bgpd/bgp_mplsvpn.h"
  29. #include "bgpd/bgp_packet.h"
  30. static u_int16_t
  31. decode_rd_type (u_char *pnt)
  32. {
  33. u_int16_t v;
  34. v = ((u_int16_t) *pnt++ << 8);
  35. v |= (u_int16_t) *pnt;
  36. return v;
  37. }
  38. u_int32_t
  39. decode_label (u_char *pnt)
  40. {
  41. u_int32_t l;
  42. l = ((u_int32_t) *pnt++ << 12);
  43. l |= (u_int32_t) *pnt++ << 4;
  44. l |= (u_int32_t) ((*pnt & 0xf0) >> 4);
  45. return l;
  46. }
  47. /* type == RD_TYPE_AS */
  48. static void
  49. decode_rd_as (u_char *pnt, struct rd_as *rd_as)
  50. {
  51. rd_as->as = (u_int16_t) *pnt++ << 8;
  52. rd_as->as |= (u_int16_t) *pnt++;
  53. rd_as->val = ((u_int32_t) *pnt++ << 24);
  54. rd_as->val |= ((u_int32_t) *pnt++ << 16);
  55. rd_as->val |= ((u_int32_t) *pnt++ << 8);
  56. rd_as->val |= (u_int32_t) *pnt;
  57. }
  58. /* type == RD_TYPE_AS4 */
  59. static void
  60. decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
  61. {
  62. rd_as->as = (u_int32_t) *pnt++ << 24;
  63. rd_as->as |= (u_int32_t) *pnt++ << 16;
  64. rd_as->as |= (u_int32_t) *pnt++ << 8;
  65. rd_as->as |= (u_int32_t) *pnt++;
  66. rd_as->val = ((u_int16_t) *pnt++ << 8);
  67. rd_as->val |= (u_int16_t) *pnt;
  68. }
  69. /* type == RD_TYPE_IP */
  70. static void
  71. decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
  72. {
  73. memcpy (&rd_ip->ip, pnt, 4);
  74. pnt += 4;
  75. rd_ip->val = ((u_int16_t) *pnt++ << 8);
  76. rd_ip->val |= (u_int16_t) *pnt;
  77. }
  78. int
  79. bgp_nlri_parse_vpn (struct peer *peer, struct attr *attr,
  80. struct bgp_nlri *packet)
  81. {
  82. u_char *pnt;
  83. u_char *lim;
  84. struct prefix p;
  85. int psize = 0;
  86. int prefixlen;
  87. u_int16_t type;
  88. struct rd_as rd_as;
  89. struct rd_ip rd_ip;
  90. struct prefix_rd prd;
  91. u_char *tagpnt;
  92. /* Check peer status. */
  93. if (peer->status != Established)
  94. return 0;
  95. /* Make prefix_rd */
  96. prd.family = AF_UNSPEC;
  97. prd.prefixlen = 64;
  98. pnt = packet->nlri;
  99. lim = pnt + packet->length;
  100. #define VPN_PREFIXLEN_MIN_BYTES (3 + 8) /* label + RD */
  101. for (; pnt < lim; pnt += psize)
  102. {
  103. /* Clear prefix structure. */
  104. memset (&p, 0, sizeof (struct prefix));
  105. /* Fetch prefix length. */
  106. prefixlen = *pnt++;
  107. p.family = afi2family (packet->afi);
  108. psize = PSIZE (prefixlen);
  109. /* sanity check against packet data */
  110. if (prefixlen < VPN_PREFIXLEN_MIN_BYTES*8)
  111. {
  112. plog_err (peer->log,
  113. "%s [Error] Update packet error / VPNv4"
  114. " (prefix length %d less than VPNv4 min length)",
  115. peer->host, prefixlen);
  116. return -1;
  117. }
  118. if ((pnt + psize) > lim)
  119. {
  120. plog_err (peer->log,
  121. "%s [Error] Update packet error / VPNv4"
  122. " (psize %u exceeds packet size (%u)",
  123. peer->host,
  124. prefixlen, (uint)(lim-pnt));
  125. return -1;
  126. }
  127. /* sanity check against storage for the IP address portion */
  128. if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t) sizeof(p.u))
  129. {
  130. plog_err (peer->log,
  131. "%s [Error] Update packet error / VPNv4"
  132. " (psize %u exceeds storage size (%zu)",
  133. peer->host,
  134. prefixlen - VPN_PREFIXLEN_MIN_BYTES*8, sizeof(p.u));
  135. return -1;
  136. }
  137. /* Sanity check against max bitlen of the address family */
  138. if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen (&p))
  139. {
  140. plog_err (peer->log,
  141. "%s [Error] Update packet error / VPNv4"
  142. " (psize %u exceeds family (%u) max byte len %u)",
  143. peer->host,
  144. prefixlen - VPN_PREFIXLEN_MIN_BYTES*8,
  145. p.family, prefix_blen (&p));
  146. return -1;
  147. }
  148. /* Copyr label to prefix. */
  149. tagpnt = pnt;
  150. /* Copy routing distinguisher to rd. */
  151. memcpy (&prd.val, pnt + 3, 8);
  152. /* Decode RD type. */
  153. type = decode_rd_type (pnt + 3);
  154. switch (type)
  155. {
  156. case RD_TYPE_AS:
  157. decode_rd_as (pnt + 5, &rd_as);
  158. break;
  159. case RD_TYPE_AS4:
  160. decode_rd_as4 (pnt + 5, &rd_as);
  161. break;
  162. case RD_TYPE_IP:
  163. decode_rd_ip (pnt + 5, &rd_ip);
  164. break;
  165. default:
  166. zlog_err ("Unknown RD type %d", type);
  167. break; /* just report */
  168. }
  169. p.prefixlen = prefixlen - VPN_PREFIXLEN_MIN_BYTES*8;
  170. memcpy (&p.u.prefix, pnt + VPN_PREFIXLEN_MIN_BYTES,
  171. psize - VPN_PREFIXLEN_MIN_BYTES);
  172. if (attr)
  173. bgp_update (peer, &p, attr, packet->afi, SAFI_MPLS_VPN,
  174. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt, 0);
  175. else
  176. bgp_withdraw (peer, &p, attr, packet->afi, SAFI_MPLS_VPN,
  177. ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, &prd, tagpnt);
  178. }
  179. /* Packet length consistency check. */
  180. if (pnt != lim)
  181. {
  182. plog_err (peer->log,
  183. "%s [Error] Update packet error / VPNv4"
  184. " (%zu data remaining after parsing)",
  185. peer->host, lim - pnt);
  186. return -1;
  187. }
  188. return 0;
  189. #undef VPN_PREFIXLEN_MIN_BYTES
  190. }
  191. int
  192. str2prefix_rd (const char *str, struct prefix_rd *prd)
  193. {
  194. int ret; /* ret of called functions */
  195. int lret; /* local ret, of this func */
  196. char *p;
  197. char *p2;
  198. struct stream *s = NULL;
  199. char *half = NULL;
  200. struct in_addr addr;
  201. s = stream_new (8);
  202. prd->family = AF_UNSPEC;
  203. prd->prefixlen = 64;
  204. lret = 0;
  205. p = strchr (str, ':');
  206. if (! p)
  207. goto out;
  208. if (! all_digit (p + 1))
  209. goto out;
  210. half = XMALLOC (MTYPE_TMP, (p - str) + 1);
  211. memcpy (half, str, (p - str));
  212. half[p - str] = '\0';
  213. p2 = strchr (str, '.');
  214. if (! p2)
  215. {
  216. if (! all_digit (half))
  217. goto out;
  218. stream_putw (s, RD_TYPE_AS);
  219. stream_putw (s, atoi (half));
  220. stream_putl (s, atol (p + 1));
  221. }
  222. else
  223. {
  224. ret = inet_aton (half, &addr);
  225. if (! ret)
  226. goto out;
  227. stream_putw (s, RD_TYPE_IP);
  228. stream_put_in_addr (s, &addr);
  229. stream_putw (s, atol (p + 1));
  230. }
  231. memcpy (prd->val, s->data, 8);
  232. lret = 1;
  233. out:
  234. if (s)
  235. stream_free (s);
  236. if (half)
  237. XFREE(MTYPE_TMP, half);
  238. return lret;
  239. }
  240. int
  241. str2tag (const char *str, u_char *tag)
  242. {
  243. unsigned long l;
  244. char *endptr;
  245. u_int32_t t;
  246. if (*str == '-')
  247. return 0;
  248. errno = 0;
  249. l = strtoul (str, &endptr, 10);
  250. if (*endptr != '\0' || errno || l > UINT32_MAX)
  251. return 0;
  252. t = (u_int32_t) l;
  253. tag[0] = (u_char)(t >> 12);
  254. tag[1] = (u_char)(t >> 4);
  255. tag[2] = (u_char)(t << 4);
  256. return 1;
  257. }
  258. char *
  259. prefix_rd2str (struct prefix_rd *prd, char *buf, size_t size)
  260. {
  261. u_char *pnt;
  262. u_int16_t type;
  263. struct rd_as rd_as;
  264. struct rd_ip rd_ip;
  265. if (size < RD_ADDRSTRLEN)
  266. return NULL;
  267. pnt = prd->val;
  268. type = decode_rd_type (pnt);
  269. if (type == RD_TYPE_AS)
  270. {
  271. decode_rd_as (pnt + 2, &rd_as);
  272. snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
  273. return buf;
  274. }
  275. else if (type == RD_TYPE_AS4)
  276. {
  277. decode_rd_as4 (pnt + 2, &rd_as);
  278. snprintf (buf, size, "%u:%d", rd_as.as, rd_as.val);
  279. return buf;
  280. }
  281. else if (type == RD_TYPE_IP)
  282. {
  283. decode_rd_ip (pnt + 2, &rd_ip);
  284. snprintf (buf, size, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
  285. return buf;
  286. }
  287. return NULL;
  288. }
  289. /* For testing purpose, static route of MPLS-VPN. */
  290. DEFUN (vpnv4_network,
  291. vpnv4_network_cmd,
  292. "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
  293. "Specify a network to announce via BGP\n"
  294. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  295. "Specify Route Distinguisher\n"
  296. "VPN Route Distinguisher\n"
  297. "BGP tag\n"
  298. "tag value\n")
  299. {
  300. return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], NULL);
  301. }
  302. DEFUN (vpnv4_network_route_map,
  303. vpnv4_network_route_map_cmd,
  304. "network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD route-map WORD",
  305. "Specify a network to announce via BGP\n"
  306. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  307. "Specify Route Distinguisher\n"
  308. "VPN Route Distinguisher\n"
  309. "BGP tag\n"
  310. "tag value\n"
  311. "route map\n"
  312. "route map name\n")
  313. {
  314. return bgp_static_set_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2], argv[3]);
  315. }
  316. /* For testing purpose, static route of MPLS-VPN. */
  317. DEFUN (no_vpnv4_network,
  318. no_vpnv4_network_cmd,
  319. "no network A.B.C.D/M rd ASN:nn_or_IP-address:nn tag WORD",
  320. NO_STR
  321. "Specify a network to announce via BGP\n"
  322. "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
  323. "Specify Route Distinguisher\n"
  324. "VPN Route Distinguisher\n"
  325. "BGP tag\n"
  326. "tag value\n")
  327. {
  328. return bgp_static_unset_safi (SAFI_MPLS_VPN, vty, argv[0], argv[1], argv[2]);
  329. }
  330. static int
  331. show_adj_route_vpn (struct vty *vty, struct peer *peer, struct prefix_rd *prd)
  332. {
  333. struct bgp *bgp;
  334. struct bgp_table *table;
  335. struct bgp_node *rn;
  336. struct bgp_node *rm;
  337. struct attr *attr;
  338. int rd_header;
  339. int header = 1;
  340. char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
  341. bgp = bgp_get_default ();
  342. if (bgp == NULL)
  343. {
  344. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  345. return CMD_WARNING;
  346. }
  347. for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn;
  348. rn = bgp_route_next (rn))
  349. {
  350. if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
  351. continue;
  352. if ((table = rn->info) != NULL)
  353. {
  354. rd_header = 1;
  355. for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
  356. if ((attr = rm->info) != NULL)
  357. {
  358. if (header)
  359. {
  360. vty_out (vty, "BGP table version is 0, local router ID is %s%s",
  361. inet_ntoa (bgp->router_id), VTY_NEWLINE);
  362. vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
  363. VTY_NEWLINE);
  364. vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
  365. VTY_NEWLINE, VTY_NEWLINE);
  366. vty_out (vty, v4_header, VTY_NEWLINE);
  367. header = 0;
  368. }
  369. if (rd_header)
  370. {
  371. u_int16_t type;
  372. struct rd_as rd_as;
  373. struct rd_ip rd_ip;
  374. u_char *pnt;
  375. pnt = rn->p.u.val;
  376. /* Decode RD type. */
  377. type = decode_rd_type (pnt);
  378. /* Decode RD value. */
  379. if (type == RD_TYPE_AS)
  380. decode_rd_as (pnt + 2, &rd_as);
  381. else if (type == RD_TYPE_AS4)
  382. decode_rd_as4 (pnt + 2, &rd_as);
  383. else if (type == RD_TYPE_IP)
  384. decode_rd_ip (pnt + 2, &rd_ip);
  385. vty_out (vty, "Route Distinguisher: ");
  386. if (type == RD_TYPE_AS)
  387. vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
  388. else if (type == RD_TYPE_AS4)
  389. vty_out (vty, "%u:%d", rd_as.as, rd_as.val);
  390. else if (type == RD_TYPE_IP)
  391. vty_out (vty, "%s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
  392. vty_out (vty, "%s", VTY_NEWLINE);
  393. rd_header = 0;
  394. }
  395. route_vty_out_tmp (vty, &rm->p, attr, SAFI_MPLS_VPN);
  396. }
  397. }
  398. }
  399. return CMD_SUCCESS;
  400. }
  401. enum bgp_show_type
  402. {
  403. bgp_show_type_normal,
  404. bgp_show_type_regexp,
  405. bgp_show_type_prefix_list,
  406. bgp_show_type_filter_list,
  407. bgp_show_type_neighbor,
  408. bgp_show_type_cidr_only,
  409. bgp_show_type_prefix_longer,
  410. bgp_show_type_community_all,
  411. bgp_show_type_community,
  412. bgp_show_type_community_exact,
  413. bgp_show_type_community_list,
  414. bgp_show_type_community_list_exact
  415. };
  416. static int
  417. bgp_show_mpls_vpn(
  418. struct vty *vty,
  419. afi_t afi,
  420. struct prefix_rd *prd,
  421. enum bgp_show_type type,
  422. void *output_arg,
  423. int tags)
  424. {
  425. struct bgp *bgp;
  426. struct bgp_table *table;
  427. struct bgp_node *rn;
  428. struct bgp_node *rm;
  429. struct bgp_info *ri;
  430. int rd_header;
  431. int header = 1;
  432. char v4_header[] = " Network Next Hop Metric LocPrf Weight Path%s";
  433. char v4_header_tag[] = " Network Next Hop In tag/Out tag%s";
  434. unsigned long output_count = 0;
  435. unsigned long total_count = 0;
  436. bgp = bgp_get_default ();
  437. if (bgp == NULL)
  438. {
  439. vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
  440. return CMD_WARNING;
  441. }
  442. if ((afi != AFI_IP) && (afi != AFI_IP6))
  443. {
  444. vty_out (vty, "Afi %d not supported%s", afi, VTY_NEWLINE);
  445. return CMD_WARNING;
  446. }
  447. for (rn = bgp_table_top (bgp->rib[afi][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
  448. {
  449. if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
  450. continue;
  451. if ((table = rn->info) != NULL)
  452. {
  453. rd_header = 1;
  454. for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
  455. for (ri = rm->info; ri; ri = ri->next)
  456. {
  457. total_count++;
  458. if (type == bgp_show_type_neighbor)
  459. {
  460. union sockunion *su = output_arg;
  461. if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
  462. continue;
  463. }
  464. if (header)
  465. {
  466. if (tags)
  467. vty_out (vty, v4_header_tag, VTY_NEWLINE);
  468. else
  469. {
  470. vty_out (vty, "BGP table version is 0, local router ID is %s%s",
  471. inet_ntoa (bgp->router_id), VTY_NEWLINE);
  472. vty_out (vty, "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal%s",
  473. VTY_NEWLINE);
  474. vty_out (vty, "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s",
  475. VTY_NEWLINE, VTY_NEWLINE);
  476. vty_out (vty, v4_header, VTY_NEWLINE);
  477. }
  478. header = 0;
  479. }
  480. if (rd_header)
  481. {
  482. u_int16_t type;
  483. struct rd_as rd_as;
  484. struct rd_ip rd_ip;
  485. u_char *pnt;
  486. pnt = rn->p.u.val;
  487. /* Decode RD type. */
  488. type = decode_rd_type (pnt);
  489. /* Decode RD value. */
  490. if (type == RD_TYPE_AS)
  491. decode_rd_as (pnt + 2, &rd_as);
  492. else if (type == RD_TYPE_AS4)
  493. decode_rd_as4 (pnt + 2, &rd_as);
  494. else if (type == RD_TYPE_IP)
  495. decode_rd_ip (pnt + 2, &rd_ip);
  496. vty_out (vty, "Route Distinguisher: ");
  497. if (type == RD_TYPE_AS)
  498. vty_out (vty, "as2 %u:%d", rd_as.as, rd_as.val);
  499. else if (type == RD_TYPE_AS4)
  500. vty_out (vty, "as4 %u:%d", rd_as.as, rd_as.val);
  501. else if (type == RD_TYPE_IP)
  502. vty_out (vty, "ip %s:%d", inet_ntoa (rd_ip.ip), rd_ip.val);
  503. vty_out (vty, "%s", VTY_NEWLINE);
  504. rd_header = 0;
  505. }
  506. if (tags)
  507. route_vty_out_tag (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
  508. else
  509. route_vty_out (vty, &rm->p, ri, 0, SAFI_MPLS_VPN);
  510. output_count++;
  511. }
  512. }
  513. }
  514. if (output_count == 0)
  515. {
  516. vty_out (vty, "No prefixes displayed, %ld exist%s", total_count, VTY_NEWLINE);
  517. }
  518. else
  519. vty_out (vty, "%sDisplayed %ld out of %ld total prefixes%s",
  520. VTY_NEWLINE, output_count, total_count, VTY_NEWLINE);
  521. return CMD_SUCCESS;
  522. }
  523. DEFUN (show_bgp_ipv4_vpn,
  524. show_bgp_ipv4_vpn_cmd,
  525. "show bgp ipv4 vpn",
  526. SHOW_STR
  527. BGP_STR
  528. "Address Family\n"
  529. "Display VPN NLRI specific information\n")
  530. {
  531. return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 0);
  532. }
  533. DEFUN (show_bgp_ipv6_vpn,
  534. show_bgp_ipv6_vpn_cmd,
  535. "show bgp ipv6 vpn",
  536. SHOW_STR
  537. BGP_STR
  538. "Address Family\n"
  539. "Display VPN NLRI specific information\n")
  540. {
  541. return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 0);
  542. }
  543. DEFUN (show_bgp_ipv4_vpn_rd,
  544. show_bgp_ipv4_vpn_rd_cmd,
  545. "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn",
  546. SHOW_STR
  547. BGP_STR
  548. "Address Family\n"
  549. "Display VPN NLRI specific information\n"
  550. "Display information for a route distinguisher\n"
  551. "VPN Route Distinguisher\n")
  552. {
  553. int ret;
  554. struct prefix_rd prd;
  555. ret = str2prefix_rd (argv[0], &prd);
  556. if (! ret)
  557. {
  558. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  559. return CMD_WARNING;
  560. }
  561. return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 0);
  562. }
  563. DEFUN (show_bgp_ipv6_vpn_rd,
  564. show_bgp_ipv6_vpn_rd_cmd,
  565. "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn",
  566. SHOW_STR
  567. BGP_STR
  568. "Address Family\n"
  569. "Display VPN NLRI specific information\n"
  570. "Display information for a route distinguisher\n"
  571. "VPN Route Distinguisher\n")
  572. {
  573. int ret;
  574. struct prefix_rd prd;
  575. ret = str2prefix_rd (argv[0], &prd);
  576. if (! ret)
  577. {
  578. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  579. return CMD_WARNING;
  580. }
  581. return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 0);
  582. }
  583. DEFUN (show_bgp_ipv4_vpn_tags,
  584. show_bgp_ipv4_vpn_tags_cmd,
  585. "show bgp ipv4 vpn tags",
  586. SHOW_STR
  587. BGP_STR
  588. "Address Family\n"
  589. "Display VPN NLRI specific information\n"
  590. "Display BGP tags for prefixes\n")
  591. {
  592. return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_normal, NULL, 1);
  593. }
  594. DEFUN (show_bgp_ipv6_vpn_tags,
  595. show_bgp_ipv6_vpn_tags_cmd,
  596. "show bgp ipv6 vpn tags",
  597. SHOW_STR
  598. BGP_STR
  599. "Address Family\n"
  600. "Display VPN NLRI specific information\n"
  601. "Display BGP tags for prefixes\n")
  602. {
  603. return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_normal, NULL, 1);
  604. }
  605. DEFUN (show_bgp_ipv4_vpn_rd_tags,
  606. show_bgp_ipv4_vpn_rd_tags_cmd,
  607. "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn tags",
  608. SHOW_STR
  609. BGP_STR
  610. "Address Family\n"
  611. "Display VPN NLRI specific information\n"
  612. "Display information for a route distinguisher\n"
  613. "VPN Route Distinguisher\n"
  614. "Display BGP tags for prefixes\n")
  615. {
  616. int ret;
  617. struct prefix_rd prd;
  618. ret = str2prefix_rd (argv[0], &prd);
  619. if (! ret)
  620. {
  621. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  622. return CMD_WARNING;
  623. }
  624. return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_normal, NULL, 1);
  625. }
  626. DEFUN (show_bgp_ipv6_vpn_rd_tags,
  627. show_bgp_ipv6_vpn_rd_tags_cmd,
  628. "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn tags",
  629. SHOW_STR
  630. BGP_STR
  631. "Address Family\n"
  632. "Display VPN NLRI specific information\n"
  633. "Display information for a route distinguisher\n"
  634. "VPN Route Distinguisher\n"
  635. "Display BGP tags for prefixes\n")
  636. {
  637. int ret;
  638. struct prefix_rd prd;
  639. ret = str2prefix_rd (argv[0], &prd);
  640. if (! ret)
  641. {
  642. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  643. return CMD_WARNING;
  644. }
  645. return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_normal, NULL, 1);
  646. }
  647. DEFUN (show_bgp_ipv4_vpn_neighbor_routes,
  648. show_bgp_ipv4_vpn_neighbor_routes_cmd,
  649. "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) routes",
  650. SHOW_STR
  651. BGP_STR
  652. "Address Family\n"
  653. "Display VPN NLRI specific information\n"
  654. "Detailed information on TCP and BGP neighbor connections\n"
  655. "Neighbor to display information about\n"
  656. "Neighbor to display information about\n"
  657. "Display routes learned from neighbor\n")
  658. {
  659. union sockunion su;
  660. struct peer *peer;
  661. int ret;
  662. ret = str2sockunion (argv[0], &su);
  663. if (ret < 0)
  664. {
  665. vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
  666. return CMD_WARNING;
  667. }
  668. peer = peer_lookup (NULL, &su);
  669. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  670. {
  671. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  672. return CMD_WARNING;
  673. }
  674. return bgp_show_mpls_vpn (vty, AFI_IP, NULL, bgp_show_type_neighbor, &su, 0);
  675. }
  676. DEFUN (show_bgp_ipv6_vpn_neighbor_routes,
  677. show_bgp_ipv6_vpn_neighbor_routes_cmd,
  678. "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) routes",
  679. SHOW_STR
  680. BGP_STR
  681. "Address Family\n"
  682. "Display VPN NLRI specific information\n"
  683. "Detailed information on TCP and BGP neighbor connections\n"
  684. "Neighbor to display information about\n"
  685. "Neighbor to display information about\n"
  686. "Display routes learned from neighbor\n")
  687. {
  688. union sockunion su;
  689. struct peer *peer;
  690. int ret;
  691. ret = str2sockunion (argv[0], &su);
  692. if (ret < 0)
  693. {
  694. vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
  695. return CMD_WARNING;
  696. }
  697. peer = peer_lookup (NULL, &su);
  698. if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
  699. {
  700. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  701. return CMD_WARNING;
  702. }
  703. return bgp_show_mpls_vpn (vty, AFI_IP6, NULL, bgp_show_type_neighbor, &su, 0);
  704. }
  705. DEFUN (show_bgp_ipv4_vpn_neighbor_advertised_routes,
  706. show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd,
  707. "show bgp ipv4 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
  708. SHOW_STR
  709. BGP_STR
  710. "Address Family\n"
  711. "Display VPN NLRI specific information\n"
  712. "Detailed information on TCP and BGP neighbor connections\n"
  713. "Neighbor to display information about\n"
  714. "Display the routes advertised to a BGP neighbor\n")
  715. {
  716. int ret;
  717. struct peer *peer;
  718. union sockunion su;
  719. ret = str2sockunion (argv[0], &su);
  720. if (ret < 0)
  721. {
  722. vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
  723. return CMD_WARNING;
  724. }
  725. peer = peer_lookup (NULL, &su);
  726. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  727. {
  728. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  729. return CMD_WARNING;
  730. }
  731. return show_adj_route_vpn (vty, peer, NULL);
  732. }
  733. DEFUN (show_bgp_ipv6_vpn_neighbor_advertised_routes,
  734. show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd,
  735. "show bgp ipv6 vpn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
  736. SHOW_STR
  737. BGP_STR
  738. "Address Family\n"
  739. "Display VPN NLRI specific information\n"
  740. "Detailed information on TCP and BGP neighbor connections\n"
  741. "Neighbor to display information about\n"
  742. "Display the routes advertised to a BGP neighbor\n")
  743. {
  744. int ret;
  745. struct peer *peer;
  746. union sockunion su;
  747. ret = str2sockunion (argv[0], &su);
  748. if (ret < 0)
  749. {
  750. vty_out (vty, "%% Malformed address: %s%s", argv[0], VTY_NEWLINE);
  751. return CMD_WARNING;
  752. }
  753. peer = peer_lookup (NULL, &su);
  754. if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
  755. {
  756. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  757. return CMD_WARNING;
  758. }
  759. return show_adj_route_vpn (vty, peer, NULL);
  760. }
  761. DEFUN (show_ip_bgp_vpnv4_rd_neighbor_advertised_routes,
  762. show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd,
  763. "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
  764. SHOW_STR
  765. BGP_STR
  766. "Address Family\n"
  767. "Display VPN NLRI specific information\n"
  768. "Display information for a route distinguisher\n"
  769. "VPN Route Distinguisher\n"
  770. "Detailed information on TCP and BGP neighbor connections\n"
  771. "Neighbor to display information about\n"
  772. "Neighbor to display information about\n"
  773. "Display the routes advertised to a BGP neighbor\n")
  774. {
  775. int ret;
  776. struct peer *peer;
  777. struct prefix_rd prd;
  778. union sockunion su;
  779. ret = str2sockunion (argv[1], &su);
  780. if (ret < 0)
  781. {
  782. vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
  783. return CMD_WARNING;
  784. }
  785. peer = peer_lookup (NULL, &su);
  786. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  787. {
  788. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  789. return CMD_WARNING;
  790. }
  791. ret = str2prefix_rd (argv[0], &prd);
  792. if (! ret)
  793. {
  794. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  795. return CMD_WARNING;
  796. }
  797. return show_adj_route_vpn (vty, peer, &prd);
  798. }
  799. DEFUN (show_ip_bgp_vpnv6_rd_neighbor_advertised_routes,
  800. show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd,
  801. "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) advertised-routes",
  802. SHOW_STR
  803. BGP_STR
  804. "Address Family\n"
  805. "Display VPN NLRI specific information\n"
  806. "Display information for a route distinguisher\n"
  807. "VPN Route Distinguisher\n"
  808. "Detailed information on TCP and BGP neighbor connections\n"
  809. "Neighbor to display information about\n"
  810. "Neighbor to display information about\n"
  811. "Display the routes advertised to a BGP neighbor\n")
  812. {
  813. int ret;
  814. struct peer *peer;
  815. struct prefix_rd prd;
  816. union sockunion su;
  817. ret = str2sockunion (argv[1], &su);
  818. if (ret < 0)
  819. {
  820. vty_out (vty, "%% Malformed address: %s%s", argv[1], VTY_NEWLINE);
  821. return CMD_WARNING;
  822. }
  823. peer = peer_lookup (NULL, &su);
  824. if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
  825. {
  826. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  827. return CMD_WARNING;
  828. }
  829. ret = str2prefix_rd (argv[0], &prd);
  830. if (! ret)
  831. {
  832. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  833. return CMD_WARNING;
  834. }
  835. return show_adj_route_vpn (vty, peer, &prd);
  836. }
  837. DEFUN (show_bgp_ipv4_vpn_rd_neighbor_routes,
  838. show_bgp_ipv4_vpn_rd_neighbor_routes_cmd,
  839. "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
  840. SHOW_STR
  841. BGP_STR
  842. "Address Family\n"
  843. "Address Family modifier\n"
  844. "Display information for a route distinguisher\n"
  845. "VPN Route Distinguisher\n"
  846. "Detailed information on TCP and BGP neighbor connections\n"
  847. "Neighbor to display information about\n"
  848. "Display routes learned from neighbor\n")
  849. {
  850. int ret;
  851. union sockunion su;
  852. struct peer *peer;
  853. struct prefix_rd prd;
  854. ret = str2prefix_rd (argv[0], &prd);
  855. if (! ret)
  856. {
  857. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  858. return CMD_WARNING;
  859. }
  860. if (str2sockunion(argv[1], &su))
  861. {
  862. vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
  863. return CMD_WARNING;
  864. }
  865. peer = peer_lookup (NULL, &su);
  866. if (! peer || ! peer->afc[AFI_IP][SAFI_MPLS_VPN])
  867. {
  868. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  869. return CMD_WARNING;
  870. }
  871. return bgp_show_mpls_vpn (vty, AFI_IP, &prd, bgp_show_type_neighbor, &su, 0);
  872. }
  873. DEFUN (show_bgp_ipv6_vpn_rd_neighbor_routes,
  874. show_bgp_ipv6_vpn_rd_neighbor_routes_cmd,
  875. "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn neighbors (A.B.C.D|X:X::X:X) routes",
  876. SHOW_STR
  877. BGP_STR
  878. "Address Family\n"
  879. "Address Family modifier\n"
  880. "Display information for a route distinguisher\n"
  881. "VPN Route Distinguisher\n"
  882. "Detailed information on TCP and BGP neighbor connections\n"
  883. "Neighbor to display information about\n"
  884. "Display routes learned from neighbor\n")
  885. {
  886. int ret;
  887. union sockunion su;
  888. struct peer *peer;
  889. struct prefix_rd prd;
  890. ret = str2prefix_rd (argv[0], &prd);
  891. if (! ret)
  892. {
  893. vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
  894. return CMD_WARNING;
  895. }
  896. if (str2sockunion(argv[1], &su))
  897. {
  898. vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
  899. return CMD_WARNING;
  900. }
  901. peer = peer_lookup (NULL, &su);
  902. if (! peer || ! peer->afc[AFI_IP6][SAFI_MPLS_VPN])
  903. {
  904. vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
  905. return CMD_WARNING;
  906. }
  907. return bgp_show_mpls_vpn (vty, AFI_IP6, &prd, bgp_show_type_neighbor, &su, 0);
  908. }
  909. void
  910. bgp_mplsvpn_init (void)
  911. {
  912. install_element (BGP_VPNV4_NODE, &vpnv4_network_cmd);
  913. install_element (BGP_VPNV4_NODE, &vpnv4_network_route_map_cmd);
  914. install_element (BGP_VPNV4_NODE, &no_vpnv4_network_cmd);
  915. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_cmd);
  916. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_cmd);
  917. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_tags_cmd);
  918. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_tags_cmd);
  919. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_routes_cmd);
  920. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_neighbor_advertised_routes_cmd);
  921. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_advertised_routes_cmd);
  922. install_element (VIEW_NODE, &show_bgp_ipv4_vpn_rd_neighbor_routes_cmd);
  923. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_cmd);
  924. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_cmd);
  925. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_tags_cmd);
  926. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_tags_cmd);
  927. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_routes_cmd);
  928. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_neighbor_advertised_routes_cmd);
  929. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_advertised_routes_cmd);
  930. install_element (VIEW_NODE, &show_bgp_ipv6_vpn_rd_neighbor_routes_cmd);
  931. }