bgp_encap.c 26 KB

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