rip_zebra.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /* RIPd and zebra interface.
  2. * Copyright (C) 1997, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  18. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  19. * 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "command.h"
  23. #include "prefix.h"
  24. #include "stream.h"
  25. #include "routemap.h"
  26. #include "zclient.h"
  27. #include "log.h"
  28. #include "ripd/ripd.h"
  29. #include "ripd/rip_debug.h"
  30. #include "ripd/rip_interface.h"
  31. /* All information about zebra. */
  32. struct zclient *zclient = NULL;
  33. /* RIPd to zebra command interface. */
  34. void
  35. rip_zebra_ipv4_add (struct prefix_ipv4 *p, struct in_addr *nexthop,
  36. u_int32_t metric, u_char distance)
  37. {
  38. struct zapi_ipv4 api;
  39. if (zclient->redist[ZEBRA_ROUTE_RIP])
  40. {
  41. api.type = ZEBRA_ROUTE_RIP;
  42. api.flags = 0;
  43. api.message = 0;
  44. SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
  45. api.nexthop_num = 1;
  46. api.nexthop = &nexthop;
  47. api.ifindex_num = 0;
  48. SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
  49. api.metric = metric;
  50. if (distance && distance != ZEBRA_RIP_DISTANCE_DEFAULT)
  51. {
  52. SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
  53. api.distance = distance;
  54. }
  55. zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api);
  56. rip_global_route_changes++;
  57. }
  58. }
  59. void
  60. rip_zebra_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *nexthop,
  61. u_int32_t metric)
  62. {
  63. struct zapi_ipv4 api;
  64. if (zclient->redist[ZEBRA_ROUTE_RIP])
  65. {
  66. api.type = ZEBRA_ROUTE_RIP;
  67. api.flags = 0;
  68. api.message = 0;
  69. SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
  70. api.nexthop_num = 1;
  71. api.nexthop = &nexthop;
  72. api.ifindex_num = 0;
  73. SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
  74. api.metric = metric;
  75. zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api);
  76. rip_global_route_changes++;
  77. }
  78. }
  79. /* Zebra route add and delete treatment. */
  80. static int
  81. rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length)
  82. {
  83. struct stream *s;
  84. struct zapi_ipv4 api;
  85. unsigned long ifindex;
  86. struct in_addr nexthop;
  87. struct prefix_ipv4 p;
  88. s = zclient->ibuf;
  89. ifindex = 0;
  90. nexthop.s_addr = 0;
  91. /* Type, flags, message. */
  92. api.type = stream_getc (s);
  93. api.flags = stream_getc (s);
  94. api.message = stream_getc (s);
  95. /* IPv4 prefix. */
  96. memset (&p, 0, sizeof (struct prefix_ipv4));
  97. p.family = AF_INET;
  98. p.prefixlen = stream_getc (s);
  99. stream_get (&p.prefix, s, PSIZE (p.prefixlen));
  100. /* Nexthop, ifindex, distance, metric. */
  101. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
  102. {
  103. api.nexthop_num = stream_getc (s);
  104. nexthop.s_addr = stream_get_ipv4 (s);
  105. }
  106. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
  107. {
  108. api.ifindex_num = stream_getc (s);
  109. ifindex = stream_getl (s);
  110. }
  111. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
  112. api.distance = stream_getc (s);
  113. else
  114. api.distance = 255;
  115. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
  116. api.metric = stream_getl (s);
  117. else
  118. api.metric = 0;
  119. /* Then fetch IPv4 prefixes. */
  120. if (command == ZEBRA_IPV4_ROUTE_ADD)
  121. rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
  122. &nexthop, api.metric, api.distance);
  123. else
  124. rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
  125. return 0;
  126. }
  127. void
  128. rip_zclient_reset (void)
  129. {
  130. zclient_reset (zclient);
  131. }
  132. /* RIP route-map set for redistribution */
  133. static void
  134. rip_routemap_set (int type, const char *name)
  135. {
  136. if (rip->route_map[type].name)
  137. free(rip->route_map[type].name);
  138. rip->route_map[type].name = strdup (name);
  139. rip->route_map[type].map = route_map_lookup_by_name (name);
  140. }
  141. static void
  142. rip_redistribute_metric_set (int type, unsigned int metric)
  143. {
  144. rip->route_map[type].metric_config = 1;
  145. rip->route_map[type].metric = metric;
  146. }
  147. static int
  148. rip_metric_unset (int type, unsigned int metric)
  149. {
  150. #define DONT_CARE_METRIC_RIP 17
  151. if (metric != DONT_CARE_METRIC_RIP &&
  152. rip->route_map[type].metric != metric)
  153. return 1;
  154. rip->route_map[type].metric_config = 0;
  155. rip->route_map[type].metric = 0;
  156. return 0;
  157. }
  158. /* RIP route-map unset for redistribution */
  159. static int
  160. rip_routemap_unset (int type, const char *name)
  161. {
  162. if (! rip->route_map[type].name ||
  163. (name != NULL && strcmp(rip->route_map[type].name,name)))
  164. return 1;
  165. free (rip->route_map[type].name);
  166. rip->route_map[type].name = NULL;
  167. rip->route_map[type].map = NULL;
  168. return 0;
  169. }
  170. /* Redistribution types */
  171. static struct {
  172. int type;
  173. int str_min_len;
  174. const char *str;
  175. } redist_type[] = {
  176. {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
  177. {ZEBRA_ROUTE_CONNECT, 1, "connected"},
  178. {ZEBRA_ROUTE_STATIC, 1, "static"},
  179. {ZEBRA_ROUTE_OSPF, 1, "ospf"},
  180. {ZEBRA_ROUTE_BGP, 1, "bgp"},
  181. {0, 0, NULL}
  182. };
  183. DEFUN (router_zebra,
  184. router_zebra_cmd,
  185. "router zebra",
  186. "Enable a routing process\n"
  187. "Make connection to zebra daemon\n")
  188. {
  189. vty->node = ZEBRA_NODE;
  190. zclient->enable = 1;
  191. zclient_start (zclient);
  192. return CMD_SUCCESS;
  193. }
  194. DEFUN (no_router_zebra,
  195. no_router_zebra_cmd,
  196. "no router zebra",
  197. NO_STR
  198. "Enable a routing process\n"
  199. "Make connection to zebra daemon\n")
  200. {
  201. zclient->enable = 0;
  202. zclient_stop (zclient);
  203. return CMD_SUCCESS;
  204. }
  205. static int
  206. rip_redistribute_set (int type)
  207. {
  208. if (zclient->redist[type])
  209. return CMD_SUCCESS;
  210. zclient->redist[type] = 1;
  211. if (zclient->sock > 0)
  212. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
  213. return CMD_SUCCESS;
  214. }
  215. static int
  216. rip_redistribute_unset (int type)
  217. {
  218. if (! zclient->redist[type])
  219. return CMD_SUCCESS;
  220. zclient->redist[type] = 0;
  221. if (zclient->sock > 0)
  222. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
  223. /* Remove the routes from RIP table. */
  224. rip_redistribute_withdraw (type);
  225. return CMD_SUCCESS;
  226. }
  227. int
  228. rip_redistribute_check (int type)
  229. {
  230. return (zclient->redist[type]);
  231. }
  232. void
  233. rip_redistribute_clean (void)
  234. {
  235. int i;
  236. for (i = 0; redist_type[i].str; i++)
  237. {
  238. if (zclient->redist[redist_type[i].type])
  239. {
  240. if (zclient->sock > 0)
  241. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
  242. zclient, redist_type[i].type);
  243. zclient->redist[redist_type[i].type] = 0;
  244. /* Remove the routes from RIP table. */
  245. rip_redistribute_withdraw (redist_type[i].type);
  246. }
  247. }
  248. }
  249. DEFUN (rip_redistribute_rip,
  250. rip_redistribute_rip_cmd,
  251. "redistribute rip",
  252. "Redistribute information from another routing protocol\n"
  253. "Routing Information Protocol (RIP)\n")
  254. {
  255. zclient->redist[ZEBRA_ROUTE_RIP] = 1;
  256. return CMD_SUCCESS;
  257. }
  258. DEFUN (no_rip_redistribute_rip,
  259. no_rip_redistribute_rip_cmd,
  260. "no redistribute rip",
  261. NO_STR
  262. "Redistribute information from another routing protocol\n"
  263. "Routing Information Protocol (RIP)\n")
  264. {
  265. zclient->redist[ZEBRA_ROUTE_RIP] = 0;
  266. return CMD_SUCCESS;
  267. }
  268. DEFUN (rip_redistribute_type,
  269. rip_redistribute_type_cmd,
  270. "redistribute (kernel|connected|static|ospf|bgp)",
  271. "Redistribute information from another routing protocol\n"
  272. "Kernel routes\n"
  273. "Connected\n"
  274. "Static routes\n"
  275. "Open Shortest Path First (OSPF)\n"
  276. "Border Gateway Protocol (BGP)\n")
  277. {
  278. int i;
  279. for(i = 0; redist_type[i].str; i++)
  280. {
  281. if (strncmp (redist_type[i].str, argv[0],
  282. redist_type[i].str_min_len) == 0)
  283. {
  284. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
  285. redist_type[i].type);
  286. return CMD_SUCCESS;
  287. }
  288. }
  289. vty_out(vty, "Invalid type %s%s", argv[0],
  290. VTY_NEWLINE);
  291. return CMD_WARNING;
  292. }
  293. DEFUN (no_rip_redistribute_type,
  294. no_rip_redistribute_type_cmd,
  295. "no redistribute (kernel|connected|static|ospf|bgp)",
  296. NO_STR
  297. "Redistribute information from another routing protocol\n"
  298. "Kernel routes\n"
  299. "Connected\n"
  300. "Static routes\n"
  301. "Open Shortest Path First (OSPF)\n"
  302. "Border Gateway Protocol (BGP)\n")
  303. {
  304. int i;
  305. for (i = 0; redist_type[i].str; i++)
  306. {
  307. if (strncmp(redist_type[i].str, argv[0],
  308. redist_type[i].str_min_len) == 0)
  309. {
  310. rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP);
  311. rip_routemap_unset (redist_type[i].type,NULL);
  312. rip_redistribute_unset (redist_type[i].type);
  313. return CMD_SUCCESS;
  314. }
  315. }
  316. vty_out(vty, "Invalid type %s%s", argv[0],
  317. VTY_NEWLINE);
  318. return CMD_WARNING;
  319. }
  320. DEFUN (rip_redistribute_type_routemap,
  321. rip_redistribute_type_routemap_cmd,
  322. "redistribute (kernel|connected|static|ospf|bgp) route-map WORD",
  323. "Redistribute information from another routing protocol\n"
  324. "Kernel routes\n"
  325. "Connected\n"
  326. "Static routes\n"
  327. "Open Shortest Path First (OSPF)\n"
  328. "Border Gateway Protocol (BGP)\n"
  329. "Route map reference\n"
  330. "Pointer to route-map entries\n")
  331. {
  332. int i;
  333. for (i = 0; redist_type[i].str; i++) {
  334. if (strncmp(redist_type[i].str, argv[0],
  335. redist_type[i].str_min_len) == 0)
  336. {
  337. rip_routemap_set (redist_type[i].type, argv[1]);
  338. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
  339. return CMD_SUCCESS;
  340. }
  341. }
  342. vty_out(vty, "Invalid type %s%s", argv[0],
  343. VTY_NEWLINE);
  344. return CMD_WARNING;
  345. }
  346. DEFUN (no_rip_redistribute_type_routemap,
  347. no_rip_redistribute_type_routemap_cmd,
  348. "no redistribute (kernel|connected|static|ospf|bgp) route-map WORD",
  349. NO_STR
  350. "Redistribute information from another routing protocol\n"
  351. "Kernel routes\n"
  352. "Connected\n"
  353. "Static routes\n"
  354. "Open Shortest Path First (OSPF)\n"
  355. "Border Gateway Protocol (BGP)\n"
  356. "Route map reference\n"
  357. "Pointer to route-map entries\n")
  358. {
  359. int i;
  360. for (i = 0; redist_type[i].str; i++)
  361. {
  362. if (strncmp(redist_type[i].str, argv[0],
  363. redist_type[i].str_min_len) == 0)
  364. {
  365. if (rip_routemap_unset (redist_type[i].type,argv[1]))
  366. return CMD_WARNING;
  367. rip_redistribute_unset (redist_type[i].type);
  368. return CMD_SUCCESS;
  369. }
  370. }
  371. vty_out(vty, "Invalid type %s%s", argv[0],
  372. VTY_NEWLINE);
  373. return CMD_WARNING;
  374. }
  375. DEFUN (rip_redistribute_type_metric,
  376. rip_redistribute_type_metric_cmd,
  377. "redistribute (kernel|connected|static|ospf|bgp) metric <0-16>",
  378. "Redistribute information from another routing protocol\n"
  379. "Kernel routes\n"
  380. "Connected\n"
  381. "Static routes\n"
  382. "Open Shortest Path First (OSPF)\n"
  383. "Border Gateway Protocol (BGP)\n"
  384. "Metric\n"
  385. "Metric value\n")
  386. {
  387. int i;
  388. int metric;
  389. metric = atoi (argv[1]);
  390. for (i = 0; redist_type[i].str; i++) {
  391. if (strncmp(redist_type[i].str, argv[0],
  392. redist_type[i].str_min_len) == 0)
  393. {
  394. rip_redistribute_metric_set (redist_type[i].type, metric);
  395. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
  396. return CMD_SUCCESS;
  397. }
  398. }
  399. vty_out(vty, "Invalid type %s%s", argv[0],
  400. VTY_NEWLINE);
  401. return CMD_WARNING;
  402. }
  403. DEFUN (no_rip_redistribute_type_metric,
  404. no_rip_redistribute_type_metric_cmd,
  405. "no redistribute (kernel|connected|static|ospf|bgp) metric <0-16>",
  406. NO_STR
  407. "Redistribute information from another routing protocol\n"
  408. "Kernel routes\n"
  409. "Connected\n"
  410. "Static routes\n"
  411. "Open Shortest Path First (OSPF)\n"
  412. "Border Gateway Protocol (BGP)\n"
  413. "Metric\n"
  414. "Metric value\n")
  415. {
  416. int i;
  417. for (i = 0; redist_type[i].str; i++)
  418. {
  419. if (strncmp(redist_type[i].str, argv[0],
  420. redist_type[i].str_min_len) == 0)
  421. {
  422. if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
  423. return CMD_WARNING;
  424. rip_redistribute_unset (redist_type[i].type);
  425. return CMD_SUCCESS;
  426. }
  427. }
  428. vty_out(vty, "Invalid type %s%s", argv[0],
  429. VTY_NEWLINE);
  430. return CMD_WARNING;
  431. }
  432. DEFUN (rip_redistribute_type_metric_routemap,
  433. rip_redistribute_type_metric_routemap_cmd,
  434. "redistribute (kernel|connected|static|ospf|bgp) metric <0-16> route-map WORD",
  435. "Redistribute information from another routing protocol\n"
  436. "Kernel routes\n"
  437. "Connected\n"
  438. "Static routes\n"
  439. "Open Shortest Path First (OSPF)\n"
  440. "Border Gateway Protocol (BGP)\n"
  441. "Metric\n"
  442. "Metric value\n"
  443. "Route map reference\n"
  444. "Pointer to route-map entries\n")
  445. {
  446. int i;
  447. int metric;
  448. metric = atoi (argv[1]);
  449. for (i = 0; redist_type[i].str; i++) {
  450. if (strncmp(redist_type[i].str, argv[0],
  451. redist_type[i].str_min_len) == 0)
  452. {
  453. rip_redistribute_metric_set (redist_type[i].type, metric);
  454. rip_routemap_set (redist_type[i].type, argv[2]);
  455. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
  456. return CMD_SUCCESS;
  457. }
  458. }
  459. vty_out(vty, "Invalid type %s%s", argv[0],
  460. VTY_NEWLINE);
  461. return CMD_WARNING;
  462. }
  463. DEFUN (no_rip_redistribute_type_metric_routemap,
  464. no_rip_redistribute_type_metric_routemap_cmd,
  465. "no redistribute (kernel|connected|static|ospf|bgp) metric <0-16> route-map WORD",
  466. NO_STR
  467. "Redistribute information from another routing protocol\n"
  468. "Kernel routes\n"
  469. "Connected\n"
  470. "Static routes\n"
  471. "Open Shortest Path First (OSPF)\n"
  472. "Border Gateway Protocol (BGP)\n"
  473. "Metric\n"
  474. "Metric value\n"
  475. "Route map reference\n"
  476. "Pointer to route-map entries\n")
  477. {
  478. int i;
  479. for (i = 0; redist_type[i].str; i++)
  480. {
  481. if (strncmp(redist_type[i].str, argv[0],
  482. redist_type[i].str_min_len) == 0)
  483. {
  484. if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
  485. return CMD_WARNING;
  486. if (rip_routemap_unset (redist_type[i].type, argv[2]))
  487. {
  488. rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1]));
  489. return CMD_WARNING;
  490. }
  491. rip_redistribute_unset (redist_type[i].type);
  492. return CMD_SUCCESS;
  493. }
  494. }
  495. vty_out(vty, "Invalid type %s%s", argv[0],
  496. VTY_NEWLINE);
  497. return CMD_WARNING;
  498. }
  499. /* Default information originate. */
  500. DEFUN (rip_default_information_originate,
  501. rip_default_information_originate_cmd,
  502. "default-information originate",
  503. "Control distribution of default route\n"
  504. "Distribute a default route\n")
  505. {
  506. struct prefix_ipv4 p;
  507. if (! rip->default_information)
  508. {
  509. memset (&p, 0, sizeof (struct prefix_ipv4));
  510. p.family = AF_INET;
  511. rip->default_information = 1;
  512. rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
  513. NULL, 0, 0);
  514. }
  515. return CMD_SUCCESS;
  516. }
  517. DEFUN (no_rip_default_information_originate,
  518. no_rip_default_information_originate_cmd,
  519. "no default-information originate",
  520. NO_STR
  521. "Control distribution of default route\n"
  522. "Distribute a default route\n")
  523. {
  524. struct prefix_ipv4 p;
  525. if (rip->default_information)
  526. {
  527. memset (&p, 0, sizeof (struct prefix_ipv4));
  528. p.family = AF_INET;
  529. rip->default_information = 0;
  530. rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
  531. }
  532. return CMD_SUCCESS;
  533. }
  534. /* RIP configuration write function. */
  535. static int
  536. config_write_zebra (struct vty *vty)
  537. {
  538. if (! zclient->enable)
  539. {
  540. vty_out (vty, "no router zebra%s", VTY_NEWLINE);
  541. return 1;
  542. }
  543. else if (! zclient->redist[ZEBRA_ROUTE_RIP])
  544. {
  545. vty_out (vty, "router zebra%s", VTY_NEWLINE);
  546. vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
  547. return 1;
  548. }
  549. return 0;
  550. }
  551. int
  552. config_write_rip_redistribute (struct vty *vty, int config_mode)
  553. {
  554. int i;
  555. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  556. if (i != zclient->redist_default && zclient->redist[i])
  557. {
  558. if (config_mode)
  559. {
  560. if (rip->route_map[i].metric_config)
  561. {
  562. if (rip->route_map[i].name)
  563. vty_out (vty, " redistribute %s metric %d route-map %s%s",
  564. zebra_route_string(i), rip->route_map[i].metric,
  565. rip->route_map[i].name,
  566. VTY_NEWLINE);
  567. else
  568. vty_out (vty, " redistribute %s metric %d%s",
  569. zebra_route_string(i), rip->route_map[i].metric,
  570. VTY_NEWLINE);
  571. }
  572. else
  573. {
  574. if (rip->route_map[i].name)
  575. vty_out (vty, " redistribute %s route-map %s%s",
  576. zebra_route_string(i), rip->route_map[i].name,
  577. VTY_NEWLINE);
  578. else
  579. vty_out (vty, " redistribute %s%s", zebra_route_string(i),
  580. VTY_NEWLINE);
  581. }
  582. }
  583. else
  584. vty_out (vty, " %s", zebra_route_string(i));
  585. }
  586. return 0;
  587. }
  588. /* Zebra node structure. */
  589. struct cmd_node zebra_node =
  590. {
  591. ZEBRA_NODE,
  592. "%s(config-router)# ",
  593. };
  594. void
  595. rip_zclient_init ()
  596. {
  597. /* Set default value to the zebra client structure. */
  598. zclient = zclient_new ();
  599. zclient_init (zclient, ZEBRA_ROUTE_RIP);
  600. zclient->interface_add = rip_interface_add;
  601. zclient->interface_delete = rip_interface_delete;
  602. zclient->interface_address_add = rip_interface_address_add;
  603. zclient->interface_address_delete = rip_interface_address_delete;
  604. zclient->ipv4_route_add = rip_zebra_read_ipv4;
  605. zclient->ipv4_route_delete = rip_zebra_read_ipv4;
  606. zclient->interface_up = rip_interface_up;
  607. zclient->interface_down = rip_interface_down;
  608. /* Install zebra node. */
  609. install_node (&zebra_node, config_write_zebra);
  610. /* Install command elements to zebra node. */
  611. install_element (CONFIG_NODE, &router_zebra_cmd);
  612. install_element (CONFIG_NODE, &no_router_zebra_cmd);
  613. install_default (ZEBRA_NODE);
  614. install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
  615. install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
  616. /* Install command elements to rip node. */
  617. install_element (RIP_NODE, &rip_redistribute_type_cmd);
  618. install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
  619. install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
  620. install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
  621. install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
  622. install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
  623. install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
  624. install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
  625. install_element (RIP_NODE, &rip_default_information_originate_cmd);
  626. install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
  627. }