rip_zebra.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. else
  120. api.distance = 255;
  121. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
  122. api.metric = stream_getl (s);
  123. else
  124. api.metric = 0;
  125. /* Then fetch IPv4 prefixes. */
  126. if (command == ZEBRA_IPV4_ROUTE_ADD)
  127. rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
  128. &nexthop, api.metric, api.distance);
  129. else
  130. rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
  131. return 0;
  132. }
  133. void
  134. rip_zclient_reset ()
  135. {
  136. zclient_reset (zclient);
  137. }
  138. /* RIP route-map set for redistribution */
  139. void
  140. rip_routemap_set (int type, const char *name)
  141. {
  142. if (rip->route_map[type].name)
  143. free(rip->route_map[type].name);
  144. rip->route_map[type].name = strdup (name);
  145. rip->route_map[type].map = route_map_lookup_by_name (name);
  146. }
  147. void
  148. rip_redistribute_metric_set (int type, unsigned int metric)
  149. {
  150. rip->route_map[type].metric_config = 1;
  151. rip->route_map[type].metric = metric;
  152. }
  153. int
  154. rip_metric_unset (int type, unsigned int metric)
  155. {
  156. #define DONT_CARE_METRIC_RIP 17
  157. if (metric != DONT_CARE_METRIC_RIP &&
  158. rip->route_map[type].metric != metric)
  159. return 1;
  160. rip->route_map[type].metric_config = 0;
  161. rip->route_map[type].metric = 0;
  162. return 0;
  163. }
  164. /* RIP route-map unset for redistribution */
  165. int
  166. rip_routemap_unset (int type, const char *name)
  167. {
  168. if (! rip->route_map[type].name ||
  169. (name != NULL && strcmp(rip->route_map[type].name,name)))
  170. return 1;
  171. free (rip->route_map[type].name);
  172. rip->route_map[type].name = NULL;
  173. rip->route_map[type].map = NULL;
  174. return 0;
  175. }
  176. /* Redistribution types */
  177. static struct {
  178. int type;
  179. int str_min_len;
  180. const char *str;
  181. } redist_type[] = {
  182. {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
  183. {ZEBRA_ROUTE_CONNECT, 1, "connected"},
  184. {ZEBRA_ROUTE_STATIC, 1, "static"},
  185. {ZEBRA_ROUTE_OSPF, 1, "ospf"},
  186. {ZEBRA_ROUTE_BGP, 1, "bgp"},
  187. {0, 0, NULL}
  188. };
  189. DEFUN (router_zebra,
  190. router_zebra_cmd,
  191. "router zebra",
  192. "Enable a routing process\n"
  193. "Make connection to zebra daemon\n")
  194. {
  195. vty->node = ZEBRA_NODE;
  196. zclient->enable = 1;
  197. zclient_start (zclient);
  198. return CMD_SUCCESS;
  199. }
  200. DEFUN (no_router_zebra,
  201. no_router_zebra_cmd,
  202. "no router zebra",
  203. NO_STR
  204. "Enable a routing process\n"
  205. "Make connection to zebra daemon\n")
  206. {
  207. zclient->enable = 0;
  208. zclient_stop (zclient);
  209. return CMD_SUCCESS;
  210. }
  211. int
  212. rip_redistribute_set (int type)
  213. {
  214. if (zclient->redist[type])
  215. return CMD_SUCCESS;
  216. zclient->redist[type] = 1;
  217. if (zclient->sock > 0)
  218. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
  219. return CMD_SUCCESS;
  220. }
  221. int
  222. rip_redistribute_unset (int type)
  223. {
  224. if (! zclient->redist[type])
  225. return CMD_SUCCESS;
  226. zclient->redist[type] = 0;
  227. if (zclient->sock > 0)
  228. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
  229. /* Remove the routes from RIP table. */
  230. rip_redistribute_withdraw (type);
  231. return CMD_SUCCESS;
  232. }
  233. int
  234. rip_redistribute_check (int type)
  235. {
  236. return (zclient->redist[type]);
  237. }
  238. void
  239. rip_redistribute_clean ()
  240. {
  241. int i;
  242. for (i = 0; redist_type[i].str; i++)
  243. {
  244. if (zclient->redist[redist_type[i].type])
  245. {
  246. if (zclient->sock > 0)
  247. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
  248. zclient, redist_type[i].type);
  249. zclient->redist[redist_type[i].type] = 0;
  250. /* Remove the routes from RIP table. */
  251. rip_redistribute_withdraw (redist_type[i].type);
  252. }
  253. }
  254. }
  255. DEFUN (rip_redistribute_rip,
  256. rip_redistribute_rip_cmd,
  257. "redistribute rip",
  258. "Redistribute information from another routing protocol\n"
  259. "Routing Information Protocol (RIP)\n")
  260. {
  261. zclient->redist[ZEBRA_ROUTE_RIP] = 1;
  262. return CMD_SUCCESS;
  263. }
  264. DEFUN (no_rip_redistribute_rip,
  265. no_rip_redistribute_rip_cmd,
  266. "no redistribute rip",
  267. NO_STR
  268. "Redistribute information from another routing protocol\n"
  269. "Routing Information Protocol (RIP)\n")
  270. {
  271. zclient->redist[ZEBRA_ROUTE_RIP] = 0;
  272. return CMD_SUCCESS;
  273. }
  274. DEFUN (rip_redistribute_type,
  275. rip_redistribute_type_cmd,
  276. "redistribute (kernel|connected|static|ospf|bgp)",
  277. "Redistribute information from another routing protocol\n"
  278. "Kernel routes\n"
  279. "Connected\n"
  280. "Static routes\n"
  281. "Open Shortest Path First (OSPF)\n"
  282. "Border Gateway Protocol (BGP)\n")
  283. {
  284. int i;
  285. for(i = 0; redist_type[i].str; i++)
  286. {
  287. if (strncmp (redist_type[i].str, argv[0],
  288. redist_type[i].str_min_len) == 0)
  289. {
  290. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
  291. redist_type[i].type);
  292. return CMD_SUCCESS;
  293. }
  294. }
  295. vty_out(vty, "Invalid type %s%s", argv[0],
  296. VTY_NEWLINE);
  297. return CMD_WARNING;
  298. }
  299. DEFUN (no_rip_redistribute_type,
  300. no_rip_redistribute_type_cmd,
  301. "no redistribute (kernel|connected|static|ospf|bgp)",
  302. NO_STR
  303. "Redistribute information from another routing protocol\n"
  304. "Kernel routes\n"
  305. "Connected\n"
  306. "Static routes\n"
  307. "Open Shortest Path First (OSPF)\n"
  308. "Border Gateway Protocol (BGP)\n")
  309. {
  310. int i;
  311. for (i = 0; redist_type[i].str; i++)
  312. {
  313. if (strncmp(redist_type[i].str, argv[0],
  314. redist_type[i].str_min_len) == 0)
  315. {
  316. rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP);
  317. rip_routemap_unset (redist_type[i].type,NULL);
  318. rip_redistribute_unset (redist_type[i].type);
  319. return CMD_SUCCESS;
  320. }
  321. }
  322. vty_out(vty, "Invalid type %s%s", argv[0],
  323. VTY_NEWLINE);
  324. return CMD_WARNING;
  325. }
  326. DEFUN (rip_redistribute_type_routemap,
  327. rip_redistribute_type_routemap_cmd,
  328. "redistribute (kernel|connected|static|ospf|bgp) route-map WORD",
  329. "Redistribute information from another routing protocol\n"
  330. "Kernel routes\n"
  331. "Connected\n"
  332. "Static routes\n"
  333. "Open Shortest Path First (OSPF)\n"
  334. "Border Gateway Protocol (BGP)\n"
  335. "Route map reference\n"
  336. "Pointer to route-map entries\n")
  337. {
  338. int i;
  339. for (i = 0; redist_type[i].str; i++) {
  340. if (strncmp(redist_type[i].str, argv[0],
  341. redist_type[i].str_min_len) == 0)
  342. {
  343. rip_routemap_set (redist_type[i].type, argv[1]);
  344. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
  345. return CMD_SUCCESS;
  346. }
  347. }
  348. vty_out(vty, "Invalid type %s%s", argv[0],
  349. VTY_NEWLINE);
  350. return CMD_WARNING;
  351. }
  352. DEFUN (no_rip_redistribute_type_routemap,
  353. no_rip_redistribute_type_routemap_cmd,
  354. "no redistribute (kernel|connected|static|ospf|bgp) route-map WORD",
  355. NO_STR
  356. "Redistribute information from another routing protocol\n"
  357. "Kernel routes\n"
  358. "Connected\n"
  359. "Static routes\n"
  360. "Open Shortest Path First (OSPF)\n"
  361. "Border Gateway Protocol (BGP)\n"
  362. "Route map reference\n"
  363. "Pointer to route-map entries\n")
  364. {
  365. int i;
  366. for (i = 0; redist_type[i].str; i++)
  367. {
  368. if (strncmp(redist_type[i].str, argv[0],
  369. redist_type[i].str_min_len) == 0)
  370. {
  371. if (rip_routemap_unset (redist_type[i].type,argv[1]))
  372. return CMD_WARNING;
  373. rip_redistribute_unset (redist_type[i].type);
  374. return CMD_SUCCESS;
  375. }
  376. }
  377. vty_out(vty, "Invalid type %s%s", argv[0],
  378. VTY_NEWLINE);
  379. return CMD_WARNING;
  380. }
  381. DEFUN (rip_redistribute_type_metric,
  382. rip_redistribute_type_metric_cmd,
  383. "redistribute (kernel|connected|static|ospf|bgp) metric <0-16>",
  384. "Redistribute information from another routing protocol\n"
  385. "Kernel routes\n"
  386. "Connected\n"
  387. "Static routes\n"
  388. "Open Shortest Path First (OSPF)\n"
  389. "Border Gateway Protocol (BGP)\n"
  390. "Metric\n"
  391. "Metric value\n")
  392. {
  393. int i;
  394. int metric;
  395. metric = atoi (argv[1]);
  396. for (i = 0; redist_type[i].str; i++) {
  397. if (strncmp(redist_type[i].str, argv[0],
  398. redist_type[i].str_min_len) == 0)
  399. {
  400. rip_redistribute_metric_set (redist_type[i].type, metric);
  401. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
  402. return CMD_SUCCESS;
  403. }
  404. }
  405. vty_out(vty, "Invalid type %s%s", argv[0],
  406. VTY_NEWLINE);
  407. return CMD_WARNING;
  408. }
  409. DEFUN (no_rip_redistribute_type_metric,
  410. no_rip_redistribute_type_metric_cmd,
  411. "no redistribute (kernel|connected|static|ospf|bgp) metric <0-16>",
  412. NO_STR
  413. "Redistribute information from another routing protocol\n"
  414. "Kernel routes\n"
  415. "Connected\n"
  416. "Static routes\n"
  417. "Open Shortest Path First (OSPF)\n"
  418. "Border Gateway Protocol (BGP)\n"
  419. "Metric\n"
  420. "Metric value\n")
  421. {
  422. int i;
  423. for (i = 0; redist_type[i].str; i++)
  424. {
  425. if (strncmp(redist_type[i].str, argv[0],
  426. redist_type[i].str_min_len) == 0)
  427. {
  428. if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
  429. return CMD_WARNING;
  430. rip_redistribute_unset (redist_type[i].type);
  431. return CMD_SUCCESS;
  432. }
  433. }
  434. vty_out(vty, "Invalid type %s%s", argv[0],
  435. VTY_NEWLINE);
  436. return CMD_WARNING;
  437. }
  438. DEFUN (rip_redistribute_type_metric_routemap,
  439. rip_redistribute_type_metric_routemap_cmd,
  440. "redistribute (kernel|connected|static|ospf|bgp) metric <0-16> route-map WORD",
  441. "Redistribute information from another routing protocol\n"
  442. "Kernel routes\n"
  443. "Connected\n"
  444. "Static routes\n"
  445. "Open Shortest Path First (OSPF)\n"
  446. "Border Gateway Protocol (BGP)\n"
  447. "Metric\n"
  448. "Metric value\n"
  449. "Route map reference\n"
  450. "Pointer to route-map entries\n")
  451. {
  452. int i;
  453. int metric;
  454. metric = atoi (argv[1]);
  455. for (i = 0; redist_type[i].str; i++) {
  456. if (strncmp(redist_type[i].str, argv[0],
  457. redist_type[i].str_min_len) == 0)
  458. {
  459. rip_redistribute_metric_set (redist_type[i].type, metric);
  460. rip_routemap_set (redist_type[i].type, argv[2]);
  461. zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
  462. return CMD_SUCCESS;
  463. }
  464. }
  465. vty_out(vty, "Invalid type %s%s", argv[0],
  466. VTY_NEWLINE);
  467. return CMD_WARNING;
  468. }
  469. DEFUN (no_rip_redistribute_type_metric_routemap,
  470. no_rip_redistribute_type_metric_routemap_cmd,
  471. "no redistribute (kernel|connected|static|ospf|bgp) metric <0-16> route-map WORD",
  472. NO_STR
  473. "Redistribute information from another routing protocol\n"
  474. "Kernel routes\n"
  475. "Connected\n"
  476. "Static routes\n"
  477. "Open Shortest Path First (OSPF)\n"
  478. "Border Gateway Protocol (BGP)\n"
  479. "Metric\n"
  480. "Metric value\n"
  481. "Route map reference\n"
  482. "Pointer to route-map entries\n")
  483. {
  484. int i;
  485. for (i = 0; redist_type[i].str; i++)
  486. {
  487. if (strncmp(redist_type[i].str, argv[0],
  488. redist_type[i].str_min_len) == 0)
  489. {
  490. if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
  491. return CMD_WARNING;
  492. if (rip_routemap_unset (redist_type[i].type, argv[2]))
  493. {
  494. rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1]));
  495. return CMD_WARNING;
  496. }
  497. rip_redistribute_unset (redist_type[i].type);
  498. return CMD_SUCCESS;
  499. }
  500. }
  501. vty_out(vty, "Invalid type %s%s", argv[0],
  502. VTY_NEWLINE);
  503. return CMD_WARNING;
  504. }
  505. /* Default information originate. */
  506. DEFUN (rip_default_information_originate,
  507. rip_default_information_originate_cmd,
  508. "default-information originate",
  509. "Control distribution of default route\n"
  510. "Distribute a default route\n")
  511. {
  512. struct prefix_ipv4 p;
  513. if (! rip->default_information)
  514. {
  515. memset (&p, 0, sizeof (struct prefix_ipv4));
  516. p.family = AF_INET;
  517. rip->default_information = 1;
  518. rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
  519. NULL, 0, 0);
  520. }
  521. return CMD_SUCCESS;
  522. }
  523. DEFUN (no_rip_default_information_originate,
  524. no_rip_default_information_originate_cmd,
  525. "no default-information originate",
  526. NO_STR
  527. "Control distribution of default route\n"
  528. "Distribute a default route\n")
  529. {
  530. struct prefix_ipv4 p;
  531. if (rip->default_information)
  532. {
  533. memset (&p, 0, sizeof (struct prefix_ipv4));
  534. p.family = AF_INET;
  535. rip->default_information = 0;
  536. rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
  537. }
  538. return CMD_SUCCESS;
  539. }
  540. /* RIP configuration write function. */
  541. int
  542. config_write_zebra (struct vty *vty)
  543. {
  544. if (! zclient->enable)
  545. {
  546. vty_out (vty, "no router zebra%s", VTY_NEWLINE);
  547. return 1;
  548. }
  549. else if (! zclient->redist[ZEBRA_ROUTE_RIP])
  550. {
  551. vty_out (vty, "router zebra%s", VTY_NEWLINE);
  552. vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
  553. return 1;
  554. }
  555. return 0;
  556. }
  557. int
  558. config_write_rip_redistribute (struct vty *vty, int config_mode)
  559. {
  560. int i;
  561. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  562. if (i != zclient->redist_default && zclient->redist[i])
  563. {
  564. if (config_mode)
  565. {
  566. if (rip->route_map[i].metric_config)
  567. {
  568. if (rip->route_map[i].name)
  569. vty_out (vty, " redistribute %s metric %d route-map %s%s",
  570. zebra_route_string(i), rip->route_map[i].metric,
  571. rip->route_map[i].name,
  572. VTY_NEWLINE);
  573. else
  574. vty_out (vty, " redistribute %s metric %d%s",
  575. zebra_route_string(i), rip->route_map[i].metric,
  576. VTY_NEWLINE);
  577. }
  578. else
  579. {
  580. if (rip->route_map[i].name)
  581. vty_out (vty, " redistribute %s route-map %s%s",
  582. zebra_route_string(i), rip->route_map[i].name,
  583. VTY_NEWLINE);
  584. else
  585. vty_out (vty, " redistribute %s%s", zebra_route_string(i),
  586. VTY_NEWLINE);
  587. }
  588. }
  589. else
  590. vty_out (vty, " %s", zebra_route_string(i));
  591. }
  592. return 0;
  593. }
  594. /* Zebra node structure. */
  595. struct cmd_node zebra_node =
  596. {
  597. ZEBRA_NODE,
  598. "%s(config-router)# ",
  599. };
  600. void
  601. rip_zclient_init ()
  602. {
  603. /* Set default value to the zebra client structure. */
  604. zclient = zclient_new ();
  605. zclient_init (zclient, ZEBRA_ROUTE_RIP);
  606. zclient->interface_add = rip_interface_add;
  607. zclient->interface_delete = rip_interface_delete;
  608. zclient->interface_address_add = rip_interface_address_add;
  609. zclient->interface_address_delete = rip_interface_address_delete;
  610. zclient->ipv4_route_add = rip_zebra_read_ipv4;
  611. zclient->ipv4_route_delete = rip_zebra_read_ipv4;
  612. zclient->interface_up = rip_interface_up;
  613. zclient->interface_down = rip_interface_down;
  614. /* Install zebra node. */
  615. install_node (&zebra_node, config_write_zebra);
  616. /* Install command elements to zebra node. */
  617. install_element (CONFIG_NODE, &router_zebra_cmd);
  618. install_element (CONFIG_NODE, &no_router_zebra_cmd);
  619. install_default (ZEBRA_NODE);
  620. install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
  621. install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
  622. /* Install command elements to rip node. */
  623. install_element (RIP_NODE, &rip_redistribute_type_cmd);
  624. install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
  625. install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
  626. install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
  627. install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
  628. install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
  629. install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
  630. install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
  631. install_element (RIP_NODE, &rip_default_information_originate_cmd);
  632. install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
  633. }