rip_zebra.c 19 KB

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