bgp_encap.c 28 KB

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