rip_zebra.c 19 KB

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