ospf6_zebra.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /*
  2. * Copyright (C) 2003 Yasuhiro Ohara
  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
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #include "log.h"
  23. #include "vty.h"
  24. #include "command.h"
  25. #include "prefix.h"
  26. #include "stream.h"
  27. #include "zclient.h"
  28. #include "memory.h"
  29. #include "ospf6_proto.h"
  30. #include "ospf6_top.h"
  31. #include "ospf6_interface.h"
  32. #include "ospf6_route.h"
  33. #include "ospf6_lsa.h"
  34. #include "ospf6_lsdb.h"
  35. #include "ospf6_asbr.h"
  36. #include "ospf6_zebra.h"
  37. #include "ospf6d.h"
  38. unsigned char conf_debug_ospf6_zebra = 0;
  39. /* information about zebra. */
  40. struct zclient *zclient = NULL;
  41. struct in_addr router_id_zebra;
  42. /* Router-id update message from zebra. */
  43. static int
  44. ospf6_router_id_update_zebra (int command, struct zclient *zclient,
  45. zebra_size_t length, vrf_id_t vrf_id)
  46. {
  47. struct prefix router_id;
  48. struct ospf6 *o = ospf6;
  49. zebra_router_id_update_read(zclient->ibuf,&router_id);
  50. router_id_zebra = router_id.u.prefix4;
  51. if (o == NULL)
  52. return 0;
  53. if (o->router_id == 0)
  54. o->router_id = (u_int32_t) router_id_zebra.s_addr;
  55. return 0;
  56. }
  57. /* redistribute function */
  58. void
  59. ospf6_zebra_redistribute (int type)
  60. {
  61. if (vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
  62. return;
  63. vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT);
  64. if (zclient->sock > 0)
  65. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type,
  66. VRF_DEFAULT);
  67. }
  68. void
  69. ospf6_zebra_no_redistribute (int type)
  70. {
  71. if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
  72. return;
  73. vrf_bitmap_unset (zclient->redist[type], VRF_DEFAULT);
  74. if (zclient->sock > 0)
  75. zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type,
  76. VRF_DEFAULT);
  77. }
  78. /* Inteface addition message from zebra. */
  79. static int
  80. ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length,
  81. vrf_id_t vrf_id)
  82. {
  83. struct interface *ifp;
  84. ifp = zebra_interface_add_read (zclient->ibuf, vrf_id);
  85. if (IS_OSPF6_DEBUG_ZEBRA (RECV))
  86. zlog_debug ("Zebra Interface add: %s index %d mtu %d",
  87. ifp->name, ifp->ifindex, ifp->mtu6);
  88. ospf6_interface_if_add (ifp);
  89. return 0;
  90. }
  91. static int
  92. ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length,
  93. vrf_id_t vrf_id)
  94. {
  95. struct interface *ifp;
  96. if (!(ifp = zebra_interface_state_read (zclient->ibuf, vrf_id)))
  97. return 0;
  98. if (if_is_up (ifp))
  99. zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name);
  100. if (IS_OSPF6_DEBUG_ZEBRA (RECV))
  101. zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
  102. ifp->name, ifp->ifindex, ifp->mtu6);
  103. #if 0
  104. /* XXX: ospf6_interface_if_del is not the right way to handle this,
  105. * because among other thinkable issues, it will also clear all
  106. * settings as they are contained in the struct ospf6_interface. */
  107. ospf6_interface_if_del (ifp);
  108. #endif /*0*/
  109. ifp->ifindex = IFINDEX_INTERNAL;
  110. return 0;
  111. }
  112. static int
  113. ospf6_zebra_if_state_update (int command, struct zclient *zclient,
  114. zebra_size_t length, vrf_id_t vrf_id)
  115. {
  116. struct interface *ifp;
  117. ifp = zebra_interface_state_read (zclient->ibuf, vrf_id);
  118. if (ifp == NULL)
  119. return 0;
  120. if (IS_OSPF6_DEBUG_ZEBRA (RECV))
  121. zlog_debug ("Zebra Interface state change: "
  122. "%s index %d flags %llx metric %d mtu %d bandwidth %d",
  123. ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
  124. ifp->metric, ifp->mtu6, ifp->bandwidth);
  125. ospf6_interface_state_update (ifp);
  126. return 0;
  127. }
  128. static int
  129. ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
  130. zebra_size_t length, vrf_id_t vrf_id)
  131. {
  132. struct connected *c;
  133. char buf[128];
  134. c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf,
  135. vrf_id);
  136. if (c == NULL)
  137. return 0;
  138. if (IS_OSPF6_DEBUG_ZEBRA (RECV))
  139. zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
  140. c->ifp->name, prefix_family_str (c->address),
  141. inet_ntop (c->address->family, &c->address->u.prefix,
  142. buf, sizeof (buf)), c->address->prefixlen);
  143. if (c->address->family == AF_INET6)
  144. {
  145. ospf6_interface_state_update (c->ifp);
  146. ospf6_interface_connected_route_update (c->ifp);
  147. }
  148. return 0;
  149. }
  150. static int
  151. ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
  152. zebra_size_t length, vrf_id_t vrf_id)
  153. {
  154. struct connected *c;
  155. char buf[128];
  156. c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf,
  157. vrf_id);
  158. if (c == NULL)
  159. return 0;
  160. if (IS_OSPF6_DEBUG_ZEBRA (RECV))
  161. zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
  162. c->ifp->name, prefix_family_str (c->address),
  163. inet_ntop (c->address->family, &c->address->u.prefix,
  164. buf, sizeof (buf)), c->address->prefixlen);
  165. if (c->address->family == AF_INET6)
  166. {
  167. ospf6_interface_connected_route_update (c->ifp);
  168. ospf6_interface_state_update (c->ifp);
  169. }
  170. return 0;
  171. }
  172. static int
  173. ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
  174. zebra_size_t length, vrf_id_t vrf_id)
  175. {
  176. struct stream *s;
  177. struct zapi_ipv6 api;
  178. unsigned long ifindex;
  179. struct prefix_ipv6 p;
  180. struct in6_addr *nexthop;
  181. s = zclient->ibuf;
  182. ifindex = 0;
  183. nexthop = NULL;
  184. memset (&api, 0, sizeof (api));
  185. /* Type, flags, message. */
  186. api.type = stream_getc (s);
  187. api.flags = stream_getc (s);
  188. api.message = stream_getc (s);
  189. /* IPv6 prefix. */
  190. memset (&p, 0, sizeof (struct prefix_ipv6));
  191. p.family = AF_INET6;
  192. p.prefixlen = stream_getc (s);
  193. stream_get (&p.prefix, s, PSIZE (p.prefixlen));
  194. /* Nexthop, ifindex, distance, metric. */
  195. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
  196. {
  197. api.nexthop_num = stream_getc (s);
  198. nexthop = (struct in6_addr *)
  199. malloc (api.nexthop_num * sizeof (struct in6_addr));
  200. stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
  201. }
  202. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
  203. {
  204. api.ifindex_num = stream_getc (s);
  205. ifindex = stream_getl (s);
  206. }
  207. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
  208. api.distance = stream_getc (s);
  209. else
  210. api.distance = 0;
  211. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
  212. api.metric = stream_getl (s);
  213. else
  214. api.metric = 0;
  215. if (IS_OSPF6_DEBUG_ZEBRA (RECV))
  216. {
  217. char prefixstr[128], nexthopstr[128];
  218. prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
  219. if (nexthop)
  220. inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
  221. else
  222. snprintf (nexthopstr, sizeof (nexthopstr), "::");
  223. zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
  224. (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
  225. zebra_route_string(api.type), prefixstr, nexthopstr, ifindex);
  226. }
  227. if (command == ZEBRA_IPV6_ROUTE_ADD)
  228. ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
  229. api.nexthop_num, nexthop);
  230. else
  231. ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
  232. if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
  233. free (nexthop);
  234. return 0;
  235. }
  236. DEFUN (show_zebra,
  237. show_zebra_cmd,
  238. "show zebra",
  239. SHOW_STR
  240. "Zebra information\n")
  241. {
  242. int i;
  243. if (zclient == NULL)
  244. {
  245. vty_out (vty, "Not connected to zebra%s", VNL);
  246. return CMD_SUCCESS;
  247. }
  248. vty_out (vty, "Zebra Infomation%s", VNL);
  249. vty_out (vty, " enable: %d fail: %d%s",
  250. zclient->enable, zclient->fail, VNL);
  251. vty_out (vty, " redistribute default: %d%s",
  252. vrf_bitmap_check (zclient->default_information, VRF_DEFAULT),
  253. VNL);
  254. vty_out (vty, " redistribute:");
  255. for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
  256. {
  257. if (vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT))
  258. vty_out (vty, " %s", zebra_route_string(i));
  259. }
  260. vty_out (vty, "%s", VNL);
  261. return CMD_SUCCESS;
  262. }
  263. DEFUN (router_zebra,
  264. router_zebra_cmd,
  265. "router zebra",
  266. "Enable a routing process\n"
  267. "Make connection to zebra daemon\n")
  268. {
  269. vty->node = ZEBRA_NODE;
  270. zclient->enable = 1;
  271. zclient_start (zclient);
  272. return CMD_SUCCESS;
  273. }
  274. DEFUN (no_router_zebra,
  275. no_router_zebra_cmd,
  276. "no router zebra",
  277. NO_STR
  278. "Configure routing process\n"
  279. "Disable connection to zebra daemon\n")
  280. {
  281. zclient->enable = 0;
  282. zclient_stop (zclient);
  283. return CMD_SUCCESS;
  284. }
  285. /* Zebra configuration write function. */
  286. static int
  287. config_write_ospf6_zebra (struct vty *vty)
  288. {
  289. if (! zclient->enable)
  290. {
  291. vty_out (vty, "no router zebra%s", VNL);
  292. vty_out (vty, "!%s", VNL);
  293. }
  294. else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
  295. {
  296. vty_out (vty, "router zebra%s", VNL);
  297. vty_out (vty, " no redistribute ospf6%s", VNL);
  298. vty_out (vty, "!%s", VNL);
  299. }
  300. return 0;
  301. }
  302. /* Zebra node structure. */
  303. static struct cmd_node zebra_node =
  304. {
  305. ZEBRA_NODE,
  306. "%s(config-zebra)# ",
  307. };
  308. #define ADD 0
  309. #define REM 1
  310. static void
  311. ospf6_zebra_route_update (int type, struct ospf6_route *request)
  312. {
  313. struct zapi_ipv6 api;
  314. char buf[64];
  315. int nhcount;
  316. struct in6_addr **nexthops;
  317. unsigned int *ifindexes;
  318. int i, ret = 0;
  319. struct prefix_ipv6 *dest;
  320. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  321. {
  322. prefix2str (&request->prefix, buf, sizeof (buf));
  323. zlog_debug ("Send %s route: %s",
  324. (type == REM ? "remove" : "add"), buf);
  325. }
  326. if (zclient->sock < 0)
  327. {
  328. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  329. zlog_debug (" Not connected to Zebra");
  330. return;
  331. }
  332. if (request->path.origin.adv_router == ospf6->router_id &&
  333. (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
  334. request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
  335. {
  336. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  337. zlog_debug (" Ignore self-originated external route");
  338. return;
  339. }
  340. /* If removing is the best path and if there's another path,
  341. treat this request as add the secondary path */
  342. if (type == REM && ospf6_route_is_best (request) &&
  343. request->next && ospf6_route_is_same (request, request->next))
  344. {
  345. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  346. zlog_debug (" Best-path removal resulted Sencondary addition");
  347. type = ADD;
  348. request = request->next;
  349. }
  350. /* Only the best path will be sent to zebra. */
  351. if (! ospf6_route_is_best (request))
  352. {
  353. /* this is not preferred best route, ignore */
  354. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  355. zlog_debug (" Ignore non-best route");
  356. return;
  357. }
  358. nhcount = 0;
  359. for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
  360. if (ospf6_nexthop_is_set (&request->nexthop[i]))
  361. nhcount++;
  362. if (nhcount == 0)
  363. {
  364. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  365. zlog_debug (" No nexthop, ignore");
  366. return;
  367. }
  368. /* allocate memory for nexthop_list */
  369. nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
  370. nhcount * sizeof (struct in6_addr *));
  371. if (nexthops == NULL)
  372. {
  373. zlog_warn ("Can't send route to zebra: malloc failed");
  374. return;
  375. }
  376. /* allocate memory for ifindex_list */
  377. ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
  378. nhcount * sizeof (unsigned int));
  379. if (ifindexes == NULL)
  380. {
  381. zlog_warn ("Can't send route to zebra: malloc failed");
  382. XFREE (MTYPE_OSPF6_OTHER, nexthops);
  383. return;
  384. }
  385. for (i = 0; i < nhcount; i++)
  386. {
  387. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  388. {
  389. const char *ifname;
  390. inet_ntop (AF_INET6, &request->nexthop[i].address,
  391. buf, sizeof (buf));
  392. ifname = ifindex2ifname (request->nexthop[i].ifindex);
  393. zlog_debug (" nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname,
  394. request->nexthop[i].ifindex);
  395. }
  396. nexthops[i] = &request->nexthop[i].address;
  397. ifindexes[i] = request->nexthop[i].ifindex;
  398. }
  399. api.vrf_id = VRF_DEFAULT;
  400. api.type = ZEBRA_ROUTE_OSPF6;
  401. api.flags = 0;
  402. api.message = 0;
  403. api.safi = SAFI_UNICAST;
  404. SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
  405. api.nexthop_num = nhcount;
  406. api.nexthop = nexthops;
  407. SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
  408. api.ifindex_num = nhcount;
  409. api.ifindex = ifindexes;
  410. SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
  411. api.metric = (request->path.metric_type == 2 ?
  412. request->path.cost_e2 : request->path.cost);
  413. dest = (struct prefix_ipv6 *) &request->prefix;
  414. if (type == REM)
  415. ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
  416. else
  417. ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
  418. if (ret < 0)
  419. zlog_err ("zapi_ipv6_route() %s failed: %s",
  420. (type == REM ? "delete" : "add"), safe_strerror (errno));
  421. XFREE (MTYPE_OSPF6_OTHER, nexthops);
  422. XFREE (MTYPE_OSPF6_OTHER, ifindexes);
  423. return;
  424. }
  425. void
  426. ospf6_zebra_route_update_add (struct ospf6_route *request)
  427. {
  428. if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
  429. {
  430. ospf6->route_table->hook_add = NULL;
  431. ospf6->route_table->hook_remove = NULL;
  432. return;
  433. }
  434. ospf6_zebra_route_update (ADD, request);
  435. }
  436. void
  437. ospf6_zebra_route_update_remove (struct ospf6_route *request)
  438. {
  439. if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
  440. {
  441. ospf6->route_table->hook_add = NULL;
  442. ospf6->route_table->hook_remove = NULL;
  443. return;
  444. }
  445. ospf6_zebra_route_update (REM, request);
  446. }
  447. DEFUN (redistribute_ospf6,
  448. redistribute_ospf6_cmd,
  449. "redistribute ospf6",
  450. "Redistribute control\n"
  451. "OSPF6 route\n")
  452. {
  453. struct ospf6_route *route;
  454. if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
  455. return CMD_SUCCESS;
  456. vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
  457. if (ospf6 == NULL)
  458. return CMD_SUCCESS;
  459. /* send ospf6 route to zebra route table */
  460. for (route = ospf6_route_head (ospf6->route_table); route;
  461. route = ospf6_route_next (route))
  462. ospf6_zebra_route_update_add (route);
  463. ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
  464. ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
  465. return CMD_SUCCESS;
  466. }
  467. DEFUN (no_redistribute_ospf6,
  468. no_redistribute_ospf6_cmd,
  469. "no redistribute ospf6",
  470. NO_STR
  471. "Redistribute control\n"
  472. "OSPF6 route\n")
  473. {
  474. struct ospf6_route *route;
  475. if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT))
  476. return CMD_SUCCESS;
  477. vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_OSPF6], VRF_DEFAULT);
  478. if (ospf6 == NULL)
  479. return CMD_SUCCESS;
  480. ospf6->route_table->hook_add = NULL;
  481. ospf6->route_table->hook_remove = NULL;
  482. /* withdraw ospf6 route from zebra route table */
  483. for (route = ospf6_route_head (ospf6->route_table); route;
  484. route = ospf6_route_next (route))
  485. ospf6_zebra_route_update_remove (route);
  486. return CMD_SUCCESS;
  487. }
  488. static void
  489. ospf6_zebra_connected (struct zclient *zclient)
  490. {
  491. zclient_send_requests (zclient, VRF_DEFAULT);
  492. }
  493. void
  494. ospf6_zebra_init (struct thread_master *master)
  495. {
  496. /* Allocate zebra structure. */
  497. zclient = zclient_new (master);
  498. zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
  499. zclient->zebra_connected = ospf6_zebra_connected;
  500. zclient->router_id_update = ospf6_router_id_update_zebra;
  501. zclient->interface_add = ospf6_zebra_if_add;
  502. zclient->interface_delete = ospf6_zebra_if_del;
  503. zclient->interface_up = ospf6_zebra_if_state_update;
  504. zclient->interface_down = ospf6_zebra_if_state_update;
  505. zclient->interface_address_add = ospf6_zebra_if_address_update_add;
  506. zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
  507. zclient->ipv4_route_add = NULL;
  508. zclient->ipv4_route_delete = NULL;
  509. zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
  510. zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
  511. /* redistribute connected route by default */
  512. /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
  513. /* Install zebra node. */
  514. install_node (&zebra_node, config_write_ospf6_zebra);
  515. /* Install command element for zebra node. */
  516. install_element (VIEW_NODE, &show_zebra_cmd);
  517. install_element (ENABLE_NODE, &show_zebra_cmd);
  518. install_element (CONFIG_NODE, &router_zebra_cmd);
  519. install_element (CONFIG_NODE, &no_router_zebra_cmd);
  520. install_default (ZEBRA_NODE);
  521. install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
  522. install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
  523. return;
  524. }
  525. /* Debug */
  526. DEFUN (debug_ospf6_zebra_sendrecv,
  527. debug_ospf6_zebra_sendrecv_cmd,
  528. "debug ospf6 zebra (send|recv)",
  529. DEBUG_STR
  530. OSPF6_STR
  531. "Debug connection between zebra\n"
  532. "Debug Sending zebra\n"
  533. "Debug Receiving zebra\n"
  534. )
  535. {
  536. unsigned char level = 0;
  537. if (argc)
  538. {
  539. if (! strncmp (argv[0], "s", 1))
  540. level = OSPF6_DEBUG_ZEBRA_SEND;
  541. else if (! strncmp (argv[0], "r", 1))
  542. level = OSPF6_DEBUG_ZEBRA_RECV;
  543. }
  544. else
  545. level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
  546. OSPF6_DEBUG_ZEBRA_ON (level);
  547. return CMD_SUCCESS;
  548. }
  549. ALIAS (debug_ospf6_zebra_sendrecv,
  550. debug_ospf6_zebra_cmd,
  551. "debug ospf6 zebra",
  552. DEBUG_STR
  553. OSPF6_STR
  554. "Debug connection between zebra\n"
  555. )
  556. DEFUN (no_debug_ospf6_zebra_sendrecv,
  557. no_debug_ospf6_zebra_sendrecv_cmd,
  558. "no debug ospf6 zebra (send|recv)",
  559. NO_STR
  560. DEBUG_STR
  561. OSPF6_STR
  562. "Debug connection between zebra\n"
  563. "Debug Sending zebra\n"
  564. "Debug Receiving zebra\n"
  565. )
  566. {
  567. unsigned char level = 0;
  568. if (argc)
  569. {
  570. if (! strncmp (argv[0], "s", 1))
  571. level = OSPF6_DEBUG_ZEBRA_SEND;
  572. else if (! strncmp (argv[0], "r", 1))
  573. level = OSPF6_DEBUG_ZEBRA_RECV;
  574. }
  575. else
  576. level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
  577. OSPF6_DEBUG_ZEBRA_OFF (level);
  578. return CMD_SUCCESS;
  579. }
  580. ALIAS (no_debug_ospf6_zebra_sendrecv,
  581. no_debug_ospf6_zebra_cmd,
  582. "no debug ospf6 zebra",
  583. NO_STR
  584. DEBUG_STR
  585. OSPF6_STR
  586. "Debug connection between zebra\n"
  587. )
  588. int
  589. config_write_ospf6_debug_zebra (struct vty *vty)
  590. {
  591. if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
  592. vty_out (vty, "debug ospf6 zebra%s", VNL);
  593. else
  594. {
  595. if (IS_OSPF6_DEBUG_ZEBRA (SEND))
  596. vty_out (vty, "debug ospf6 zebra send%s", VNL);
  597. if (IS_OSPF6_DEBUG_ZEBRA (RECV))
  598. vty_out (vty, "debug ospf6 zebra recv%s", VNL);
  599. }
  600. return 0;
  601. }
  602. void
  603. install_element_ospf6_debug_zebra (void)
  604. {
  605. install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
  606. install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
  607. install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
  608. install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
  609. install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
  610. install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
  611. install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
  612. install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
  613. }