blob: e38e03d85f80e828248a9a869c3d08f63a788c69 [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
hasso508e53e2004-05-18 18:57:06 +000032#include "ospf6_proto.h"
33#include "ospf6_top.h"
paul718e3742002-12-13 20:15:29 +000034#include "ospf6_interface.h"
hasso508e53e2004-05-18 18:57:06 +000035#include "ospf6_route.h"
36#include "ospf6_lsa.h"
hasso049207c2004-08-04 20:02:13 +000037#include "ospf6_lsdb.h"
paul718e3742002-12-13 20:15:29 +000038#include "ospf6_asbr.h"
hasso508e53e2004-05-18 18:57:06 +000039#include "ospf6_zebra.h"
hasso049207c2004-08-04 20:02:13 +000040#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000041
hasso508e53e2004-05-18 18:57:06 +000042unsigned char conf_debug_ospf6_zebra = 0;
paul718e3742002-12-13 20:15:29 +000043
44/* information about zebra. */
45struct zclient *zclient = NULL;
46
47/* redistribute function */
48void
49ospf6_zebra_redistribute (int type)
50{
paul718e3742002-12-13 20:15:29 +000051 if (zclient->redist[type])
52 return;
paul718e3742002-12-13 20:15:29 +000053 zclient->redist[type] = 1;
paul718e3742002-12-13 20:15:29 +000054 if (zclient->sock > 0)
55 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000056}
57
58void
59ospf6_zebra_no_redistribute (int type)
60{
hasso508e53e2004-05-18 18:57:06 +000061 if (! zclient->redist[type])
paul718e3742002-12-13 20:15:29 +000062 return;
paul718e3742002-12-13 20:15:29 +000063 zclient->redist[type] = 0;
paul718e3742002-12-13 20:15:29 +000064 if (zclient->sock > 0)
65 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000066}
67
paul718e3742002-12-13 20:15:29 +000068/* Inteface addition message from zebra. */
69int
70ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
71{
72 struct interface *ifp;
73
74 ifp = zebra_interface_add_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +000075 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
76 zlog_info ("Zebra Interface add: %s index %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +000077 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +000078 ospf6_interface_if_add (ifp);
paul718e3742002-12-13 20:15:29 +000079 return 0;
80}
81
82int
83ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
84{
85#if 0
hasso508e53e2004-05-18 18:57:06 +000086 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +000087
88 ifp = zebra_interface_delete_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +000089 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
90 zlog_info ("Zebra Interface delete: %s index %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +000091 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +000092
93 ospf6_interface_if_del (ifp);
hasso508e53e2004-05-18 18:57:06 +000094#endif /*0*/
paul718e3742002-12-13 20:15:29 +000095 return 0;
96}
97
98int
99ospf6_zebra_if_state_update (int command, struct zclient *zclient,
100 zebra_size_t length)
101{
102 struct interface *ifp;
103
104 ifp = zebra_interface_state_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +0000105 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
106 zlog_info ("Zebra Interface state change: "
107 "%s index %d flags %ld metric %d mtu %d",
hasso1203e1c2004-07-23 21:34:27 +0000108 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000109
110 ospf6_interface_state_update (ifp);
111 return 0;
112}
113
114int
115ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
hasso508e53e2004-05-18 18:57:06 +0000116 zebra_size_t length)
paul718e3742002-12-13 20:15:29 +0000117{
118 struct connected *c;
119 char buf[128];
120
paul0a589352004-05-08 11:48:26 +0000121 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000122 if (c == NULL)
123 return 0;
124
hasso508e53e2004-05-18 18:57:06 +0000125 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
126 zlog_info ("Zebra Interface address add: %s %5s %s/%d",
paul718e3742002-12-13 20:15:29 +0000127 c->ifp->name, prefix_family_str (c->address),
128 inet_ntop (c->address->family, &c->address->u.prefix,
129 buf, sizeof (buf)), c->address->prefixlen);
130
131 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000132 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000133
134 return 0;
135}
136
137int
138ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
139 zebra_size_t length)
140{
141 struct connected *c;
142 char buf[128];
143
paul0a589352004-05-08 11:48:26 +0000144 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000145 if (c == NULL)
146 return 0;
147
hasso508e53e2004-05-18 18:57:06 +0000148 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
149 zlog_info ("Zebra Interface address delete: %s %5s %s/%d",
paul718e3742002-12-13 20:15:29 +0000150 c->ifp->name, prefix_family_str (c->address),
151 inet_ntop (c->address->family, &c->address->u.prefix,
152 buf, sizeof (buf)), c->address->prefixlen);
153
154 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000155 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000156
157 return 0;
158}
159
160
161
162const char *zebra_route_name[ZEBRA_ROUTE_MAX] =
hasso508e53e2004-05-18 18:57:06 +0000163 { "System", "Kernel", "Connect", "Static", "RIP", "RIPng", "OSPF",
164 "OSPF6", "BGP" };
paul718e3742002-12-13 20:15:29 +0000165
166const char *zebra_route_abname[ZEBRA_ROUTE_MAX] =
167 { "X", "K", "C", "S", "r", "R", "o", "O", "B" };
168
169int
170ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
171 zebra_size_t length)
172{
173 struct stream *s;
174 struct zapi_ipv6 api;
175 unsigned long ifindex;
176 struct prefix_ipv6 p;
177 struct in6_addr *nexthop;
paul718e3742002-12-13 20:15:29 +0000178
179 s = zclient->ibuf;
180 ifindex = 0;
181 nexthop = NULL;
182 memset (&api, 0, sizeof (api));
183
184 /* Type, flags, message. */
185 api.type = stream_getc (s);
186 api.flags = stream_getc (s);
187 api.message = stream_getc (s);
188
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
195 /* Nexthop, ifindex, distance, metric. */
196 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
197 {
198 api.nexthop_num = stream_getc (s);
199 nexthop = (struct in6_addr *)
200 malloc (api.nexthop_num * sizeof (struct in6_addr));
201 stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
202 }
203 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
204 {
205 api.ifindex_num = stream_getc (s);
206 ifindex = stream_getl (s);
207 }
208 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
209 api.distance = stream_getc (s);
210 else
211 api.distance = 0;
212 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
213 api.metric = stream_getl (s);
214 else
215 api.metric = 0;
216
hasso508e53e2004-05-18 18:57:06 +0000217 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
paul718e3742002-12-13 20:15:29 +0000218 {
hasso508e53e2004-05-18 18:57:06 +0000219 char prefixstr[128], nexthopstr[128];
paul718e3742002-12-13 20:15:29 +0000220 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
hasso508e53e2004-05-18 18:57:06 +0000221 if (nexthop)
222 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
paul718e3742002-12-13 20:15:29 +0000223 else
hasso508e53e2004-05-18 18:57:06 +0000224 snprintf (nexthopstr, sizeof (nexthopstr), "::");
225
226 zlog_info ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
227 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
228 zebra_route_name[api.type], prefixstr, nexthopstr, ifindex);
paul718e3742002-12-13 20:15:29 +0000229 }
230
231 if (command == ZEBRA_IPV6_ROUTE_ADD)
hasso508e53e2004-05-18 18:57:06 +0000232 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
233 api.nexthop_num, nexthop);
paul718e3742002-12-13 20:15:29 +0000234 else
hasso508e53e2004-05-18 18:57:06 +0000235 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000236
237 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
238 free (nexthop);
239
240 return 0;
241}
242
hasso508e53e2004-05-18 18:57:06 +0000243
244
paul718e3742002-12-13 20:15:29 +0000245
246DEFUN (show_zebra,
247 show_zebra_cmd,
248 "show zebra",
249 SHOW_STR
250 "Zebra information\n")
251{
252 int i;
hasso508e53e2004-05-18 18:57:06 +0000253 if (zclient == NULL)
254 {
hasso049207c2004-08-04 20:02:13 +0000255 vty_out (vty, "Not connected to zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000256 return CMD_SUCCESS;
257 }
paul718e3742002-12-13 20:15:29 +0000258
hasso049207c2004-08-04 20:02:13 +0000259 vty_out (vty, "Zebra Infomation%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000260 vty_out (vty, " enable: %d fail: %d%s",
hasso049207c2004-08-04 20:02:13 +0000261 zclient->enable, zclient->fail, VNL);
paul718e3742002-12-13 20:15:29 +0000262 vty_out (vty, " redistribute default: %d%s", zclient->redist_default,
hasso049207c2004-08-04 20:02:13 +0000263 VNL);
hasso508e53e2004-05-18 18:57:06 +0000264 vty_out (vty, " redistribute:");
paul718e3742002-12-13 20:15:29 +0000265 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
hasso508e53e2004-05-18 18:57:06 +0000266 {
267 if (zclient->redist[i])
268 vty_out (vty, " %s", zebra_route_name[i]);
269 }
hasso049207c2004-08-04 20:02:13 +0000270 vty_out (vty, "%s", VNL);
paul718e3742002-12-13 20:15:29 +0000271 return CMD_SUCCESS;
272}
273
274DEFUN (router_zebra,
275 router_zebra_cmd,
276 "router zebra",
277 "Enable a routing process\n"
278 "Make connection to zebra daemon\n")
279{
paul718e3742002-12-13 20:15:29 +0000280 vty->node = ZEBRA_NODE;
281 zclient->enable = 1;
282 zclient_start (zclient);
283 return CMD_SUCCESS;
284}
285
286DEFUN (no_router_zebra,
287 no_router_zebra_cmd,
288 "no router zebra",
289 NO_STR
290 "Configure routing process\n"
291 "Disable connection to zebra daemon\n")
292{
paul718e3742002-12-13 20:15:29 +0000293 zclient->enable = 0;
294 zclient_stop (zclient);
295 return CMD_SUCCESS;
296}
297
298/* Zebra configuration write function. */
299int
hasso508e53e2004-05-18 18:57:06 +0000300config_write_ospf6_zebra (struct vty *vty)
paul718e3742002-12-13 20:15:29 +0000301{
302 if (! zclient->enable)
303 {
hasso049207c2004-08-04 20:02:13 +0000304 vty_out (vty, "no router zebra%s", VNL);
305 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000306 }
307 else if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
308 {
hasso049207c2004-08-04 20:02:13 +0000309 vty_out (vty, "router zebra%s", VNL);
310 vty_out (vty, " no redistribute ospf6%s", VNL);
311 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000312 }
313 return 0;
314}
315
316/* Zebra node structure. */
317struct cmd_node zebra_node =
318{
319 ZEBRA_NODE,
320 "%s(config-zebra)# ",
paul718e3742002-12-13 20:15:29 +0000321};
322
323#define ADD 0
hasso508e53e2004-05-18 18:57:06 +0000324#define REM 1
paul718e3742002-12-13 20:15:29 +0000325static void
hasso508e53e2004-05-18 18:57:06 +0000326ospf6_zebra_route_update (int type, struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000327{
paul718e3742002-12-13 20:15:29 +0000328 struct zapi_ipv6 api;
hasso508e53e2004-05-18 18:57:06 +0000329 char buf[64], ifname[IFNAMSIZ];
330 int nhcount;
paul718e3742002-12-13 20:15:29 +0000331 struct in6_addr **nexthops;
332 unsigned int *ifindexes;
paul718e3742002-12-13 20:15:29 +0000333 int i, ret = 0;
hasso508e53e2004-05-18 18:57:06 +0000334 struct prefix_ipv6 *dest;
paul718e3742002-12-13 20:15:29 +0000335
hasso508e53e2004-05-18 18:57:06 +0000336 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000337 {
hasso508e53e2004-05-18 18:57:06 +0000338 prefix2str (&request->prefix, buf, sizeof (buf));
339 zlog_info ("Send %s route: %s",
340 (type == REM ? "remove" : "add"), buf);
paul718e3742002-12-13 20:15:29 +0000341 }
342
343 if (zclient->sock < 0)
344 {
hasso508e53e2004-05-18 18:57:06 +0000345 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
346 zlog_info (" Not connected to Zebra");
paul718e3742002-12-13 20:15:29 +0000347 return;
348 }
349
350 if (request->path.origin.adv_router == ospf6->router_id &&
351 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
352 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
353 {
hasso508e53e2004-05-18 18:57:06 +0000354 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
355 zlog_info (" Ignore self-originated external route");
paul718e3742002-12-13 20:15:29 +0000356 return;
357 }
358
hasso508e53e2004-05-18 18:57:06 +0000359 /* If removing is the best path and if there's another path,
360 treat this request as add the secondary path */
361 if (type == REM && ospf6_route_is_best (request) &&
362 request->next && ospf6_route_is_same (request, request->next))
363 {
364 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
365 zlog_info (" Best-path removal resulted Sencondary addition");
366 type = ADD;
367 request = request->next;
368 }
369
370 /* Only the best path will be sent to zebra. */
371 if (! ospf6_route_is_best (request))
paul718e3742002-12-13 20:15:29 +0000372 {
373 /* this is not preferred best route, ignore */
hasso508e53e2004-05-18 18:57:06 +0000374 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
375 zlog_info (" Ignore non-best route");
paul718e3742002-12-13 20:15:29 +0000376 return;
377 }
378
hasso508e53e2004-05-18 18:57:06 +0000379 nhcount = 0;
380 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
381 if (ospf6_nexthop_is_set (&request->nexthop[i]))
382 nhcount++;
paul718e3742002-12-13 20:15:29 +0000383
hasso508e53e2004-05-18 18:57:06 +0000384 if (nhcount == 0)
paul718e3742002-12-13 20:15:29 +0000385 {
hasso508e53e2004-05-18 18:57:06 +0000386 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
387 zlog_info (" No nexthop, ignore");
paul718e3742002-12-13 20:15:29 +0000388 return;
389 }
390
391 /* allocate memory for nexthop_list */
392 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000393 nhcount * sizeof (struct in6_addr *));
394 if (nexthops == NULL)
paul718e3742002-12-13 20:15:29 +0000395 {
hasso508e53e2004-05-18 18:57:06 +0000396 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000397 return;
398 }
399
400 /* allocate memory for ifindex_list */
401 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000402 nhcount * sizeof (unsigned int));
403 if (ifindexes == NULL)
paul718e3742002-12-13 20:15:29 +0000404 {
hasso508e53e2004-05-18 18:57:06 +0000405 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000406 XFREE (MTYPE_OSPF6_OTHER, nexthops);
407 return;
408 }
409
hasso508e53e2004-05-18 18:57:06 +0000410 for (i = 0; i < nhcount; i++)
paul718e3742002-12-13 20:15:29 +0000411 {
hasso508e53e2004-05-18 18:57:06 +0000412 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000413 {
hasso508e53e2004-05-18 18:57:06 +0000414 inet_ntop (AF_INET6, &request->nexthop[i].address,
415 buf, sizeof (buf));
416 if_indextoname (request->nexthop[i].ifindex, ifname);
417 zlog_info (" nexthop: %s%%%s(%d)", buf, ifname,
418 request->nexthop[i].ifindex);
paul718e3742002-12-13 20:15:29 +0000419 }
hasso508e53e2004-05-18 18:57:06 +0000420 nexthops[i] = &request->nexthop[i].address;
421 ifindexes[i] = request->nexthop[i].ifindex;
paul718e3742002-12-13 20:15:29 +0000422 }
423
424 api.type = ZEBRA_ROUTE_OSPF6;
425 api.flags = 0;
426 api.message = 0;
427 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
hasso508e53e2004-05-18 18:57:06 +0000428 api.nexthop_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000429 api.nexthop = nexthops;
hasso508e53e2004-05-18 18:57:06 +0000430 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
431 api.ifindex_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000432 api.ifindex = ifindexes;
hasso508e53e2004-05-18 18:57:06 +0000433 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
434 api.metric = (request->path.metric_type == 2 ?
435 request->path.cost_e2 : request->path.cost);
paul718e3742002-12-13 20:15:29 +0000436
hasso508e53e2004-05-18 18:57:06 +0000437 dest = (struct prefix_ipv6 *) &request->prefix;
438 if (type == REM)
439 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000440 else
hasso508e53e2004-05-18 18:57:06 +0000441 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000442
443 if (ret < 0)
hasso508e53e2004-05-18 18:57:06 +0000444 zlog_err ("zapi_ipv6_route() %s failed: %s",
445 (type == REM ? "delete" : "add"), strerror (errno));
paul718e3742002-12-13 20:15:29 +0000446
paul718e3742002-12-13 20:15:29 +0000447 XFREE (MTYPE_OSPF6_OTHER, nexthops);
448 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
449
450 return;
451}
452
453void
hasso508e53e2004-05-18 18:57:06 +0000454ospf6_zebra_route_update_add (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000455{
hasso508e53e2004-05-18 18:57:06 +0000456 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
457 {
458 ospf6->route_table->hook_add = NULL;
459 ospf6->route_table->hook_remove = NULL;
460 return;
461 }
paul718e3742002-12-13 20:15:29 +0000462 ospf6_zebra_route_update (ADD, request);
463}
464
465void
hasso508e53e2004-05-18 18:57:06 +0000466ospf6_zebra_route_update_remove (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000467{
hasso508e53e2004-05-18 18:57:06 +0000468 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
paul718e3742002-12-13 20:15:29 +0000469 {
hasso508e53e2004-05-18 18:57:06 +0000470 ospf6->route_table->hook_add = NULL;
471 ospf6->route_table->hook_remove = NULL;
472 return;
paul718e3742002-12-13 20:15:29 +0000473 }
hasso508e53e2004-05-18 18:57:06 +0000474 ospf6_zebra_route_update (REM, request);
paul718e3742002-12-13 20:15:29 +0000475}
476
paul718e3742002-12-13 20:15:29 +0000477DEFUN (redistribute_ospf6,
478 redistribute_ospf6_cmd,
479 "redistribute ospf6",
480 "Redistribute control\n"
481 "OSPF6 route\n")
482{
hasso508e53e2004-05-18 18:57:06 +0000483 struct ospf6_route *route;
484
485 if (zclient->redist[ZEBRA_ROUTE_OSPF6])
486 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000487
488 zclient->redist[ZEBRA_ROUTE_OSPF6] = 1;
489
hasso508e53e2004-05-18 18:57:06 +0000490 if (ospf6 == NULL)
491 return CMD_SUCCESS;
492
493 /* send ospf6 route to zebra route table */
494 for (route = ospf6_route_head (ospf6->route_table); route;
495 route = ospf6_route_next (route))
496 ospf6_zebra_route_update_add (route);
497
498 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
499 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
paul718e3742002-12-13 20:15:29 +0000500
501 return CMD_SUCCESS;
502}
503
504DEFUN (no_redistribute_ospf6,
505 no_redistribute_ospf6_cmd,
506 "no redistribute ospf6",
507 NO_STR
508 "Redistribute control\n"
509 "OSPF6 route\n")
510{
hasso508e53e2004-05-18 18:57:06 +0000511 struct ospf6_route *route;
512
513 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
514 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000515
516 zclient->redist[ZEBRA_ROUTE_OSPF6] = 0;
517
hasso508e53e2004-05-18 18:57:06 +0000518 if (ospf6 == NULL)
paul718e3742002-12-13 20:15:29 +0000519 return CMD_SUCCESS;
520
hasso508e53e2004-05-18 18:57:06 +0000521 ospf6->route_table->hook_add = NULL;
522 ospf6->route_table->hook_remove = NULL;
paul718e3742002-12-13 20:15:29 +0000523
hasso508e53e2004-05-18 18:57:06 +0000524 /* withdraw ospf6 route from zebra route table */
525 for (route = ospf6_route_head (ospf6->route_table); route;
526 route = ospf6_route_next (route))
527 ospf6_zebra_route_update_remove (route);
paul718e3742002-12-13 20:15:29 +0000528
529 return CMD_SUCCESS;
530}
531
532void
533ospf6_zebra_init ()
534{
535 /* Allocate zebra structure. */
536 zclient = zclient_new ();
537 zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
538 zclient->interface_add = ospf6_zebra_if_add;
539 zclient->interface_delete = ospf6_zebra_if_del;
540 zclient->interface_up = ospf6_zebra_if_state_update;
541 zclient->interface_down = ospf6_zebra_if_state_update;
542 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
543 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
544 zclient->ipv4_route_add = NULL;
545 zclient->ipv4_route_delete = NULL;
546 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
547 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
548
549 /* redistribute connected route by default */
550 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
551
552 /* Install zebra node. */
hasso508e53e2004-05-18 18:57:06 +0000553 install_node (&zebra_node, config_write_ospf6_zebra);
paul718e3742002-12-13 20:15:29 +0000554
555 /* Install command element for zebra node. */
556 install_element (VIEW_NODE, &show_zebra_cmd);
557 install_element (ENABLE_NODE, &show_zebra_cmd);
558 install_element (CONFIG_NODE, &router_zebra_cmd);
559 install_element (CONFIG_NODE, &no_router_zebra_cmd);
hasso508e53e2004-05-18 18:57:06 +0000560
paul718e3742002-12-13 20:15:29 +0000561 install_default (ZEBRA_NODE);
562 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
563 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
564
paul718e3742002-12-13 20:15:29 +0000565 return;
566}
567
hasso508e53e2004-05-18 18:57:06 +0000568/* Debug */
569
570DEFUN (debug_ospf6_zebra_sendrecv,
571 debug_ospf6_zebra_sendrecv_cmd,
572 "debug ospf6 zebra (send|recv)",
573 DEBUG_STR
574 OSPF6_STR
575 "Debug connection between zebra\n"
576 "Debug Sending zebra\n"
577 "Debug Receiving zebra\n"
578 )
paul718e3742002-12-13 20:15:29 +0000579{
hasso508e53e2004-05-18 18:57:06 +0000580 unsigned char level = 0;
581
582 if (argc)
583 {
584 if (! strncmp (argv[0], "s", 1))
585 level = OSPF6_DEBUG_ZEBRA_SEND;
586 else if (! strncmp (argv[0], "r", 1))
587 level = OSPF6_DEBUG_ZEBRA_RECV;
588 }
589 else
590 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
591
592 OSPF6_DEBUG_ZEBRA_ON (level);
593 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000594}
595
hasso508e53e2004-05-18 18:57:06 +0000596ALIAS (debug_ospf6_zebra_sendrecv,
597 debug_ospf6_zebra_cmd,
598 "debug ospf6 zebra",
599 DEBUG_STR
600 OSPF6_STR
601 "Debug connection between zebra\n"
602 );
603
604
605DEFUN (no_debug_ospf6_zebra_sendrecv,
606 no_debug_ospf6_zebra_sendrecv_cmd,
607 "no debug ospf6 zebra (send|recv)",
608 NO_STR
609 DEBUG_STR
610 OSPF6_STR
611 "Debug connection between zebra\n"
612 "Debug Sending zebra\n"
613 "Debug Receiving zebra\n"
614 )
615{
616 unsigned char level = 0;
617
618 if (argc)
619 {
620 if (! strncmp (argv[0], "s", 1))
621 level = OSPF6_DEBUG_ZEBRA_SEND;
622 else if (! strncmp (argv[0], "r", 1))
623 level = OSPF6_DEBUG_ZEBRA_RECV;
624 }
625 else
626 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
627
628 OSPF6_DEBUG_ZEBRA_OFF (level);
629 return CMD_SUCCESS;
630}
631
632ALIAS (no_debug_ospf6_zebra_sendrecv,
633 no_debug_ospf6_zebra_cmd,
634 "no debug ospf6 zebra",
635 NO_STR
636 DEBUG_STR
637 OSPF6_STR
638 "Debug connection between zebra\n"
639 );
640
641int
642config_write_ospf6_debug_zebra (struct vty *vty)
643{
644 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000645 vty_out (vty, "debug ospf6 zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000646 else
647 {
648 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hasso049207c2004-08-04 20:02:13 +0000649 vty_out (vty, "debug ospf6 zebra send%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000650 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000651 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000652 }
653 return 0;
654}
655
656void
657install_element_ospf6_debug_zebra ()
658{
659 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
660 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
661 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
662 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
663 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
664 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
665 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
666 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
667}
668
669