blob: b622086651229dad0c0412b60b42e4dab8a343e5 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
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
hasso508e53e2004-05-18 18:57:06 +000022#include <zebra.h>
23
24#include "log.h"
25#include "vty.h"
26#include "command.h"
27#include "prefix.h"
28#include "stream.h"
29#include "zclient.h"
30#include "memory.h"
31
paul718e3742002-12-13 20:15:29 +000032#include "ospf6d.h"
hasso508e53e2004-05-18 18:57:06 +000033#include "ospf6_proto.h"
34#include "ospf6_top.h"
paul718e3742002-12-13 20:15:29 +000035#include "ospf6_interface.h"
hasso508e53e2004-05-18 18:57:06 +000036#include "ospf6_route.h"
37#include "ospf6_lsa.h"
paul718e3742002-12-13 20:15:29 +000038#include "ospf6_asbr.h"
hasso508e53e2004-05-18 18:57:06 +000039#include "ospf6_zebra.h"
paul718e3742002-12-13 20:15:29 +000040
hasso508e53e2004-05-18 18:57:06 +000041unsigned char conf_debug_ospf6_zebra = 0;
paul718e3742002-12-13 20:15:29 +000042
43/* information about zebra. */
44struct zclient *zclient = NULL;
45
46/* redistribute function */
47void
48ospf6_zebra_redistribute (int type)
49{
paul718e3742002-12-13 20:15:29 +000050 if (zclient->redist[type])
51 return;
paul718e3742002-12-13 20:15:29 +000052 zclient->redist[type] = 1;
paul718e3742002-12-13 20:15:29 +000053 if (zclient->sock > 0)
54 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000055}
56
57void
58ospf6_zebra_no_redistribute (int type)
59{
hasso508e53e2004-05-18 18:57:06 +000060 if (! zclient->redist[type])
paul718e3742002-12-13 20:15:29 +000061 return;
paul718e3742002-12-13 20:15:29 +000062 zclient->redist[type] = 0;
paul718e3742002-12-13 20:15:29 +000063 if (zclient->sock > 0)
64 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000065}
66
paul718e3742002-12-13 20:15:29 +000067/* Inteface addition message from zebra. */
68int
69ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
70{
71 struct interface *ifp;
72
73 ifp = zebra_interface_add_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +000074 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
75 zlog_info ("Zebra Interface add: %s index %d mtu %d",
paul718e3742002-12-13 20:15:29 +000076 ifp->name, ifp->ifindex, ifp->mtu);
paul718e3742002-12-13 20:15:29 +000077 ospf6_interface_if_add (ifp);
paul718e3742002-12-13 20:15:29 +000078 return 0;
79}
80
81int
82ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
83{
84#if 0
hasso508e53e2004-05-18 18:57:06 +000085 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +000086
87 ifp = zebra_interface_delete_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +000088 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
89 zlog_info ("Zebra Interface delete: %s index %d mtu %d",
paul718e3742002-12-13 20:15:29 +000090 ifp->name, ifp->ifindex, ifp->mtu);
91
92 ospf6_interface_if_del (ifp);
hasso508e53e2004-05-18 18:57:06 +000093#endif /*0*/
paul718e3742002-12-13 20:15:29 +000094 return 0;
95}
96
97int
98ospf6_zebra_if_state_update (int command, struct zclient *zclient,
99 zebra_size_t length)
100{
101 struct interface *ifp;
102
103 ifp = zebra_interface_state_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +0000104 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
105 zlog_info ("Zebra Interface state change: "
106 "%s index %d flags %ld metric %d mtu %d",
paul718e3742002-12-13 20:15:29 +0000107 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu);
108
109 ospf6_interface_state_update (ifp);
110 return 0;
111}
112
113int
114ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
hasso508e53e2004-05-18 18:57:06 +0000115 zebra_size_t length)
paul718e3742002-12-13 20:15:29 +0000116{
117 struct connected *c;
118 char buf[128];
119
paul0a589352004-05-08 11:48:26 +0000120 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000121 if (c == NULL)
122 return 0;
123
hasso508e53e2004-05-18 18:57:06 +0000124 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
125 zlog_info ("Zebra Interface address add: %s %5s %s/%d",
paul718e3742002-12-13 20:15:29 +0000126 c->ifp->name, prefix_family_str (c->address),
127 inet_ntop (c->address->family, &c->address->u.prefix,
128 buf, sizeof (buf)), c->address->prefixlen);
129
130 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000131 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000132
133 return 0;
134}
135
136int
137ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
138 zebra_size_t length)
139{
140 struct connected *c;
141 char buf[128];
142
paul0a589352004-05-08 11:48:26 +0000143 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000144 if (c == NULL)
145 return 0;
146
hasso508e53e2004-05-18 18:57:06 +0000147 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
148 zlog_info ("Zebra Interface address delete: %s %5s %s/%d",
paul718e3742002-12-13 20:15:29 +0000149 c->ifp->name, prefix_family_str (c->address),
150 inet_ntop (c->address->family, &c->address->u.prefix,
151 buf, sizeof (buf)), c->address->prefixlen);
152
153 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000154 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000155
156 return 0;
157}
158
159
160
161const char *zebra_route_name[ZEBRA_ROUTE_MAX] =
hasso508e53e2004-05-18 18:57:06 +0000162 { "System", "Kernel", "Connect", "Static", "RIP", "RIPng", "OSPF",
163 "OSPF6", "BGP" };
paul718e3742002-12-13 20:15:29 +0000164
165const char *zebra_route_abname[ZEBRA_ROUTE_MAX] =
166 { "X", "K", "C", "S", "r", "R", "o", "O", "B" };
167
168int
169ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
170 zebra_size_t length)
171{
172 struct stream *s;
173 struct zapi_ipv6 api;
174 unsigned long ifindex;
175 struct prefix_ipv6 p;
176 struct in6_addr *nexthop;
paul718e3742002-12-13 20:15:29 +0000177
178 s = zclient->ibuf;
179 ifindex = 0;
180 nexthop = NULL;
181 memset (&api, 0, sizeof (api));
182
183 /* Type, flags, message. */
184 api.type = stream_getc (s);
185 api.flags = stream_getc (s);
186 api.message = stream_getc (s);
187
188 /* IPv6 prefix. */
189 memset (&p, 0, sizeof (struct prefix_ipv6));
190 p.family = AF_INET6;
191 p.prefixlen = stream_getc (s);
192 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
193
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
hasso508e53e2004-05-18 18:57:06 +0000216 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
paul718e3742002-12-13 20:15:29 +0000217 {
hasso508e53e2004-05-18 18:57:06 +0000218 char prefixstr[128], nexthopstr[128];
paul718e3742002-12-13 20:15:29 +0000219 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
hasso508e53e2004-05-18 18:57:06 +0000220 if (nexthop)
221 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
paul718e3742002-12-13 20:15:29 +0000222 else
hasso508e53e2004-05-18 18:57:06 +0000223 snprintf (nexthopstr, sizeof (nexthopstr), "::");
224
225 zlog_info ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
226 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
227 zebra_route_name[api.type], prefixstr, nexthopstr, ifindex);
paul718e3742002-12-13 20:15:29 +0000228 }
229
230 if (command == ZEBRA_IPV6_ROUTE_ADD)
hasso508e53e2004-05-18 18:57:06 +0000231 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
232 api.nexthop_num, nexthop);
paul718e3742002-12-13 20:15:29 +0000233 else
hasso508e53e2004-05-18 18:57:06 +0000234 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000235
236 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
237 free (nexthop);
238
239 return 0;
240}
241
hasso508e53e2004-05-18 18:57:06 +0000242
243
paul718e3742002-12-13 20:15:29 +0000244
245DEFUN (show_zebra,
246 show_zebra_cmd,
247 "show zebra",
248 SHOW_STR
249 "Zebra information\n")
250{
251 int i;
hasso508e53e2004-05-18 18:57:06 +0000252 if (zclient == NULL)
253 {
254 vty_out (vty, "Not connected to zebra%s", VTY_NEWLINE);
255 return CMD_SUCCESS;
256 }
paul718e3742002-12-13 20:15:29 +0000257
258 vty_out (vty, "Zebra Infomation%s", VTY_NEWLINE);
hasso508e53e2004-05-18 18:57:06 +0000259 vty_out (vty, " enable: %d fail: %d%s",
260 zclient->enable, zclient->fail, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000261 vty_out (vty, " redistribute default: %d%s", zclient->redist_default,
262 VTY_NEWLINE);
hasso508e53e2004-05-18 18:57:06 +0000263 vty_out (vty, " redistribute:");
paul718e3742002-12-13 20:15:29 +0000264 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
hasso508e53e2004-05-18 18:57:06 +0000265 {
266 if (zclient->redist[i])
267 vty_out (vty, " %s", zebra_route_name[i]);
268 }
269 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000270 return CMD_SUCCESS;
271}
272
273DEFUN (router_zebra,
274 router_zebra_cmd,
275 "router zebra",
276 "Enable a routing process\n"
277 "Make connection to zebra daemon\n")
278{
paul718e3742002-12-13 20:15:29 +0000279 vty->node = ZEBRA_NODE;
280 zclient->enable = 1;
281 zclient_start (zclient);
282 return CMD_SUCCESS;
283}
284
285DEFUN (no_router_zebra,
286 no_router_zebra_cmd,
287 "no router zebra",
288 NO_STR
289 "Configure routing process\n"
290 "Disable connection to zebra daemon\n")
291{
paul718e3742002-12-13 20:15:29 +0000292 zclient->enable = 0;
293 zclient_stop (zclient);
294 return CMD_SUCCESS;
295}
296
297/* Zebra configuration write function. */
298int
hasso508e53e2004-05-18 18:57:06 +0000299config_write_ospf6_zebra (struct vty *vty)
paul718e3742002-12-13 20:15:29 +0000300{
301 if (! zclient->enable)
302 {
303 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
hasso508e53e2004-05-18 18:57:06 +0000304 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000305 }
306 else if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
307 {
308 vty_out (vty, "router zebra%s", VTY_NEWLINE);
309 vty_out (vty, " no redistribute ospf6%s", VTY_NEWLINE);
hasso508e53e2004-05-18 18:57:06 +0000310 vty_out (vty, "!%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +0000311 }
312 return 0;
313}
314
315/* Zebra node structure. */
316struct cmd_node zebra_node =
317{
318 ZEBRA_NODE,
319 "%s(config-zebra)# ",
paul718e3742002-12-13 20:15:29 +0000320};
321
322#define ADD 0
hasso508e53e2004-05-18 18:57:06 +0000323#define REM 1
paul718e3742002-12-13 20:15:29 +0000324static void
hasso508e53e2004-05-18 18:57:06 +0000325ospf6_zebra_route_update (int type, struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000326{
paul718e3742002-12-13 20:15:29 +0000327 struct zapi_ipv6 api;
hasso508e53e2004-05-18 18:57:06 +0000328 char buf[64], ifname[IFNAMSIZ];
329 int nhcount;
paul718e3742002-12-13 20:15:29 +0000330 struct in6_addr **nexthops;
331 unsigned int *ifindexes;
paul718e3742002-12-13 20:15:29 +0000332 int i, ret = 0;
hasso508e53e2004-05-18 18:57:06 +0000333 struct prefix_ipv6 *dest;
paul718e3742002-12-13 20:15:29 +0000334
hasso508e53e2004-05-18 18:57:06 +0000335 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000336 {
hasso508e53e2004-05-18 18:57:06 +0000337 prefix2str (&request->prefix, buf, sizeof (buf));
338 zlog_info ("Send %s route: %s",
339 (type == REM ? "remove" : "add"), buf);
paul718e3742002-12-13 20:15:29 +0000340 }
341
342 if (zclient->sock < 0)
343 {
hasso508e53e2004-05-18 18:57:06 +0000344 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
345 zlog_info (" Not connected to Zebra");
paul718e3742002-12-13 20:15:29 +0000346 return;
347 }
348
349 if (request->path.origin.adv_router == ospf6->router_id &&
350 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
351 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
352 {
hasso508e53e2004-05-18 18:57:06 +0000353 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
354 zlog_info (" Ignore self-originated external route");
paul718e3742002-12-13 20:15:29 +0000355 return;
356 }
357
hasso508e53e2004-05-18 18:57:06 +0000358 /* If removing is the best path and if there's another path,
359 treat this request as add the secondary path */
360 if (type == REM && ospf6_route_is_best (request) &&
361 request->next && ospf6_route_is_same (request, request->next))
362 {
363 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
364 zlog_info (" Best-path removal resulted Sencondary addition");
365 type = ADD;
366 request = request->next;
367 }
368
369 /* Only the best path will be sent to zebra. */
370 if (! ospf6_route_is_best (request))
paul718e3742002-12-13 20:15:29 +0000371 {
372 /* this is not preferred best route, ignore */
hasso508e53e2004-05-18 18:57:06 +0000373 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
374 zlog_info (" Ignore non-best route");
paul718e3742002-12-13 20:15:29 +0000375 return;
376 }
377
hasso508e53e2004-05-18 18:57:06 +0000378 nhcount = 0;
379 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
380 if (ospf6_nexthop_is_set (&request->nexthop[i]))
381 nhcount++;
paul718e3742002-12-13 20:15:29 +0000382
hasso508e53e2004-05-18 18:57:06 +0000383 if (nhcount == 0)
paul718e3742002-12-13 20:15:29 +0000384 {
hasso508e53e2004-05-18 18:57:06 +0000385 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
386 zlog_info (" No nexthop, ignore");
paul718e3742002-12-13 20:15:29 +0000387 return;
388 }
389
390 /* allocate memory for nexthop_list */
391 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000392 nhcount * sizeof (struct in6_addr *));
393 if (nexthops == NULL)
paul718e3742002-12-13 20:15:29 +0000394 {
hasso508e53e2004-05-18 18:57:06 +0000395 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000396 return;
397 }
398
399 /* allocate memory for ifindex_list */
400 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000401 nhcount * sizeof (unsigned int));
402 if (ifindexes == NULL)
paul718e3742002-12-13 20:15:29 +0000403 {
hasso508e53e2004-05-18 18:57:06 +0000404 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000405 XFREE (MTYPE_OSPF6_OTHER, nexthops);
406 return;
407 }
408
hasso508e53e2004-05-18 18:57:06 +0000409 for (i = 0; i < nhcount; i++)
paul718e3742002-12-13 20:15:29 +0000410 {
hasso508e53e2004-05-18 18:57:06 +0000411 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000412 {
hasso508e53e2004-05-18 18:57:06 +0000413 inet_ntop (AF_INET6, &request->nexthop[i].address,
414 buf, sizeof (buf));
415 if_indextoname (request->nexthop[i].ifindex, ifname);
416 zlog_info (" nexthop: %s%%%s(%d)", buf, ifname,
417 request->nexthop[i].ifindex);
paul718e3742002-12-13 20:15:29 +0000418 }
hasso508e53e2004-05-18 18:57:06 +0000419 nexthops[i] = &request->nexthop[i].address;
420 ifindexes[i] = request->nexthop[i].ifindex;
paul718e3742002-12-13 20:15:29 +0000421 }
422
423 api.type = ZEBRA_ROUTE_OSPF6;
424 api.flags = 0;
425 api.message = 0;
426 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
hasso508e53e2004-05-18 18:57:06 +0000427 api.nexthop_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000428 api.nexthop = nexthops;
hasso508e53e2004-05-18 18:57:06 +0000429 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
430 api.ifindex_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000431 api.ifindex = ifindexes;
hasso508e53e2004-05-18 18:57:06 +0000432 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
433 api.metric = (request->path.metric_type == 2 ?
434 request->path.cost_e2 : request->path.cost);
paul718e3742002-12-13 20:15:29 +0000435
hasso508e53e2004-05-18 18:57:06 +0000436 dest = (struct prefix_ipv6 *) &request->prefix;
437 if (type == REM)
438 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000439 else
hasso508e53e2004-05-18 18:57:06 +0000440 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000441
442 if (ret < 0)
hasso508e53e2004-05-18 18:57:06 +0000443 zlog_err ("zapi_ipv6_route() %s failed: %s",
444 (type == REM ? "delete" : "add"), strerror (errno));
paul718e3742002-12-13 20:15:29 +0000445
paul718e3742002-12-13 20:15:29 +0000446 XFREE (MTYPE_OSPF6_OTHER, nexthops);
447 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
448
449 return;
450}
451
452void
hasso508e53e2004-05-18 18:57:06 +0000453ospf6_zebra_route_update_add (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000454{
hasso508e53e2004-05-18 18:57:06 +0000455 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
456 {
457 ospf6->route_table->hook_add = NULL;
458 ospf6->route_table->hook_remove = NULL;
459 return;
460 }
paul718e3742002-12-13 20:15:29 +0000461 ospf6_zebra_route_update (ADD, request);
462}
463
464void
hasso508e53e2004-05-18 18:57:06 +0000465ospf6_zebra_route_update_remove (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000466{
hasso508e53e2004-05-18 18:57:06 +0000467 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
paul718e3742002-12-13 20:15:29 +0000468 {
hasso508e53e2004-05-18 18:57:06 +0000469 ospf6->route_table->hook_add = NULL;
470 ospf6->route_table->hook_remove = NULL;
471 return;
paul718e3742002-12-13 20:15:29 +0000472 }
hasso508e53e2004-05-18 18:57:06 +0000473 ospf6_zebra_route_update (REM, request);
paul718e3742002-12-13 20:15:29 +0000474}
475
paul718e3742002-12-13 20:15:29 +0000476DEFUN (redistribute_ospf6,
477 redistribute_ospf6_cmd,
478 "redistribute ospf6",
479 "Redistribute control\n"
480 "OSPF6 route\n")
481{
hasso508e53e2004-05-18 18:57:06 +0000482 struct ospf6_route *route;
483
484 if (zclient->redist[ZEBRA_ROUTE_OSPF6])
485 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000486
487 zclient->redist[ZEBRA_ROUTE_OSPF6] = 1;
488
hasso508e53e2004-05-18 18:57:06 +0000489 if (ospf6 == NULL)
490 return CMD_SUCCESS;
491
492 /* send ospf6 route to zebra route table */
493 for (route = ospf6_route_head (ospf6->route_table); route;
494 route = ospf6_route_next (route))
495 ospf6_zebra_route_update_add (route);
496
497 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
498 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
paul718e3742002-12-13 20:15:29 +0000499
500 return CMD_SUCCESS;
501}
502
503DEFUN (no_redistribute_ospf6,
504 no_redistribute_ospf6_cmd,
505 "no redistribute ospf6",
506 NO_STR
507 "Redistribute control\n"
508 "OSPF6 route\n")
509{
hasso508e53e2004-05-18 18:57:06 +0000510 struct ospf6_route *route;
511
512 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
513 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000514
515 zclient->redist[ZEBRA_ROUTE_OSPF6] = 0;
516
hasso508e53e2004-05-18 18:57:06 +0000517 if (ospf6 == NULL)
paul718e3742002-12-13 20:15:29 +0000518 return CMD_SUCCESS;
519
hasso508e53e2004-05-18 18:57:06 +0000520 ospf6->route_table->hook_add = NULL;
521 ospf6->route_table->hook_remove = NULL;
paul718e3742002-12-13 20:15:29 +0000522
hasso508e53e2004-05-18 18:57:06 +0000523 /* withdraw ospf6 route from zebra route table */
524 for (route = ospf6_route_head (ospf6->route_table); route;
525 route = ospf6_route_next (route))
526 ospf6_zebra_route_update_remove (route);
paul718e3742002-12-13 20:15:29 +0000527
528 return CMD_SUCCESS;
529}
530
531void
532ospf6_zebra_init ()
533{
534 /* Allocate zebra structure. */
535 zclient = zclient_new ();
536 zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
537 zclient->interface_add = ospf6_zebra_if_add;
538 zclient->interface_delete = ospf6_zebra_if_del;
539 zclient->interface_up = ospf6_zebra_if_state_update;
540 zclient->interface_down = ospf6_zebra_if_state_update;
541 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
542 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
543 zclient->ipv4_route_add = NULL;
544 zclient->ipv4_route_delete = NULL;
545 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
546 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
547
548 /* redistribute connected route by default */
549 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
550
551 /* Install zebra node. */
hasso508e53e2004-05-18 18:57:06 +0000552 install_node (&zebra_node, config_write_ospf6_zebra);
paul718e3742002-12-13 20:15:29 +0000553
554 /* Install command element for zebra node. */
555 install_element (VIEW_NODE, &show_zebra_cmd);
556 install_element (ENABLE_NODE, &show_zebra_cmd);
557 install_element (CONFIG_NODE, &router_zebra_cmd);
558 install_element (CONFIG_NODE, &no_router_zebra_cmd);
hasso508e53e2004-05-18 18:57:06 +0000559
paul718e3742002-12-13 20:15:29 +0000560 install_default (ZEBRA_NODE);
561 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
562 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
563
paul718e3742002-12-13 20:15:29 +0000564 return;
565}
566
hasso508e53e2004-05-18 18:57:06 +0000567/* Debug */
568
569DEFUN (debug_ospf6_zebra_sendrecv,
570 debug_ospf6_zebra_sendrecv_cmd,
571 "debug ospf6 zebra (send|recv)",
572 DEBUG_STR
573 OSPF6_STR
574 "Debug connection between zebra\n"
575 "Debug Sending zebra\n"
576 "Debug Receiving zebra\n"
577 )
paul718e3742002-12-13 20:15:29 +0000578{
hasso508e53e2004-05-18 18:57:06 +0000579 unsigned char level = 0;
580
581 if (argc)
582 {
583 if (! strncmp (argv[0], "s", 1))
584 level = OSPF6_DEBUG_ZEBRA_SEND;
585 else if (! strncmp (argv[0], "r", 1))
586 level = OSPF6_DEBUG_ZEBRA_RECV;
587 }
588 else
589 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
590
591 OSPF6_DEBUG_ZEBRA_ON (level);
592 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000593}
594
hasso508e53e2004-05-18 18:57:06 +0000595ALIAS (debug_ospf6_zebra_sendrecv,
596 debug_ospf6_zebra_cmd,
597 "debug ospf6 zebra",
598 DEBUG_STR
599 OSPF6_STR
600 "Debug connection between zebra\n"
601 );
602
603
604DEFUN (no_debug_ospf6_zebra_sendrecv,
605 no_debug_ospf6_zebra_sendrecv_cmd,
606 "no debug ospf6 zebra (send|recv)",
607 NO_STR
608 DEBUG_STR
609 OSPF6_STR
610 "Debug connection between zebra\n"
611 "Debug Sending zebra\n"
612 "Debug Receiving zebra\n"
613 )
614{
615 unsigned char level = 0;
616
617 if (argc)
618 {
619 if (! strncmp (argv[0], "s", 1))
620 level = OSPF6_DEBUG_ZEBRA_SEND;
621 else if (! strncmp (argv[0], "r", 1))
622 level = OSPF6_DEBUG_ZEBRA_RECV;
623 }
624 else
625 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
626
627 OSPF6_DEBUG_ZEBRA_OFF (level);
628 return CMD_SUCCESS;
629}
630
631ALIAS (no_debug_ospf6_zebra_sendrecv,
632 no_debug_ospf6_zebra_cmd,
633 "no debug ospf6 zebra",
634 NO_STR
635 DEBUG_STR
636 OSPF6_STR
637 "Debug connection between zebra\n"
638 );
639
640int
641config_write_ospf6_debug_zebra (struct vty *vty)
642{
643 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
644 vty_out (vty, "debug ospf6 zebra%s", VTY_NEWLINE);
645 else
646 {
647 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
648 vty_out (vty, "debug ospf6 zebra send%s", VTY_NEWLINE);
649 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
650 vty_out (vty, "debug ospf6 zebra recv%s", VTY_NEWLINE);
651 }
652 return 0;
653}
654
655void
656install_element_ospf6_debug_zebra ()
657{
658 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
659 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
660 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
661 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
662 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
663 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
664 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
665 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
666}
667
668