rip_zebra.c 19 KB

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