blob: bc15dff661f7e7ea6f20368ae372bf2969395508 [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
hasso18a6dce2004-10-03 18:18:34 +000047struct in_addr router_id_zebra;
48
49/* Router-id update message from zebra. */
50int
51ospf6_router_id_update_zebra (int command, struct zclient *zclient,
52 zebra_size_t length)
53{
54 struct prefix router_id;
55 struct ospf6 *o = ospf6;
56
57 zebra_router_id_update_read(zclient->ibuf,&router_id);
58 router_id_zebra = router_id.u.prefix4;
59
jardinc1ba9e82005-03-02 22:43:26 +000060 if (o == NULL)
61 return 0;
62
hasso18a6dce2004-10-03 18:18:34 +000063 if (o->router_id == 0)
64 o->router_id = (u_int32_t) router_id_zebra.s_addr;
65
66 return 0;
67}
68
paul718e3742002-12-13 20:15:29 +000069/* redistribute function */
70void
71ospf6_zebra_redistribute (int type)
72{
paul718e3742002-12-13 20:15:29 +000073 if (zclient->redist[type])
74 return;
paul718e3742002-12-13 20:15:29 +000075 zclient->redist[type] = 1;
paul718e3742002-12-13 20:15:29 +000076 if (zclient->sock > 0)
77 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000078}
79
80void
81ospf6_zebra_no_redistribute (int type)
82{
hasso508e53e2004-05-18 18:57:06 +000083 if (! zclient->redist[type])
paul718e3742002-12-13 20:15:29 +000084 return;
paul718e3742002-12-13 20:15:29 +000085 zclient->redist[type] = 0;
paul718e3742002-12-13 20:15:29 +000086 if (zclient->sock > 0)
87 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000088}
89
paul718e3742002-12-13 20:15:29 +000090/* Inteface addition message from zebra. */
91int
92ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
93{
94 struct interface *ifp;
95
96 ifp = zebra_interface_add_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +000097 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +000098 zlog_debug ("Zebra Interface add: %s index %d mtu %d",
99 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000100 ospf6_interface_if_add (ifp);
paul718e3742002-12-13 20:15:29 +0000101 return 0;
102}
103
104int
105ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
106{
107#if 0
hasso508e53e2004-05-18 18:57:06 +0000108 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +0000109
110 ifp = zebra_interface_delete_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +0000111 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000112 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
113 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000114
115 ospf6_interface_if_del (ifp);
hasso508e53e2004-05-18 18:57:06 +0000116#endif /*0*/
paul718e3742002-12-13 20:15:29 +0000117 return 0;
118}
119
120int
121ospf6_zebra_if_state_update (int command, struct zclient *zclient,
122 zebra_size_t length)
123{
124 struct interface *ifp;
125
126 ifp = zebra_interface_state_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +0000127 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000128 zlog_debug ("Zebra Interface state change: "
129 "%s index %d flags %ld metric %d mtu %d",
130 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000131
132 ospf6_interface_state_update (ifp);
133 return 0;
134}
135
136int
137ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
hasso508e53e2004-05-18 18:57:06 +0000138 zebra_size_t length)
paul718e3742002-12-13 20:15:29 +0000139{
140 struct connected *c;
141 char buf[128];
142
paul0a589352004-05-08 11:48:26 +0000143 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, 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))
hassoc6487d62004-12-24 06:00:11 +0000148 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
149 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);
paul718e3742002-12-13 20:15:29 +0000152
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
159int
160ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
161 zebra_size_t length)
162{
163 struct connected *c;
164 char buf[128];
165
paul0a589352004-05-08 11:48:26 +0000166 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000167 if (c == NULL)
168 return 0;
169
hasso508e53e2004-05-18 18:57:06 +0000170 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000171 zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
172 c->ifp->name, prefix_family_str (c->address),
173 inet_ntop (c->address->family, &c->address->u.prefix,
174 buf, sizeof (buf)), c->address->prefixlen);
paul718e3742002-12-13 20:15:29 +0000175
176 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000177 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000178
179 return 0;
180}
181
182
183
184const char *zebra_route_name[ZEBRA_ROUTE_MAX] =
hasso508e53e2004-05-18 18:57:06 +0000185 { "System", "Kernel", "Connect", "Static", "RIP", "RIPng", "OSPF",
hassof3f27f62004-09-10 18:07:57 +0000186 "OSPF6", "ISIS", "BGP" };
paul718e3742002-12-13 20:15:29 +0000187
188const char *zebra_route_abname[ZEBRA_ROUTE_MAX] =
hassof3f27f62004-09-10 18:07:57 +0000189 { "X", "K", "C", "S", "r", "R", "o", "O", "I", "B" };
paul718e3742002-12-13 20:15:29 +0000190
191int
192ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
193 zebra_size_t length)
194{
195 struct stream *s;
196 struct zapi_ipv6 api;
197 unsigned long ifindex;
198 struct prefix_ipv6 p;
199 struct in6_addr *nexthop;
paul718e3742002-12-13 20:15:29 +0000200
201 s = zclient->ibuf;
202 ifindex = 0;
203 nexthop = NULL;
204 memset (&api, 0, sizeof (api));
205
206 /* Type, flags, message. */
207 api.type = stream_getc (s);
208 api.flags = stream_getc (s);
209 api.message = stream_getc (s);
210
211 /* IPv6 prefix. */
212 memset (&p, 0, sizeof (struct prefix_ipv6));
213 p.family = AF_INET6;
214 p.prefixlen = stream_getc (s);
215 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
216
217 /* Nexthop, ifindex, distance, metric. */
218 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
219 {
220 api.nexthop_num = stream_getc (s);
221 nexthop = (struct in6_addr *)
222 malloc (api.nexthop_num * sizeof (struct in6_addr));
223 stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
224 }
225 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
226 {
227 api.ifindex_num = stream_getc (s);
228 ifindex = stream_getl (s);
229 }
230 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
231 api.distance = stream_getc (s);
232 else
233 api.distance = 0;
234 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
235 api.metric = stream_getl (s);
236 else
237 api.metric = 0;
238
hasso508e53e2004-05-18 18:57:06 +0000239 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
paul718e3742002-12-13 20:15:29 +0000240 {
hasso508e53e2004-05-18 18:57:06 +0000241 char prefixstr[128], nexthopstr[128];
paul718e3742002-12-13 20:15:29 +0000242 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
hasso508e53e2004-05-18 18:57:06 +0000243 if (nexthop)
244 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
paul718e3742002-12-13 20:15:29 +0000245 else
hasso508e53e2004-05-18 18:57:06 +0000246 snprintf (nexthopstr, sizeof (nexthopstr), "::");
247
hassoc6487d62004-12-24 06:00:11 +0000248 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
249 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
250 zebra_route_name[api.type], prefixstr, nexthopstr, ifindex);
paul718e3742002-12-13 20:15:29 +0000251 }
252
253 if (command == ZEBRA_IPV6_ROUTE_ADD)
hasso508e53e2004-05-18 18:57:06 +0000254 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
255 api.nexthop_num, nexthop);
paul718e3742002-12-13 20:15:29 +0000256 else
hasso508e53e2004-05-18 18:57:06 +0000257 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000258
259 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
260 free (nexthop);
261
262 return 0;
263}
264
hasso508e53e2004-05-18 18:57:06 +0000265
266
paul718e3742002-12-13 20:15:29 +0000267
268DEFUN (show_zebra,
269 show_zebra_cmd,
270 "show zebra",
271 SHOW_STR
272 "Zebra information\n")
273{
274 int i;
hasso508e53e2004-05-18 18:57:06 +0000275 if (zclient == NULL)
276 {
hasso049207c2004-08-04 20:02:13 +0000277 vty_out (vty, "Not connected to zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000278 return CMD_SUCCESS;
279 }
paul718e3742002-12-13 20:15:29 +0000280
hasso049207c2004-08-04 20:02:13 +0000281 vty_out (vty, "Zebra Infomation%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000282 vty_out (vty, " enable: %d fail: %d%s",
hasso049207c2004-08-04 20:02:13 +0000283 zclient->enable, zclient->fail, VNL);
paul718e3742002-12-13 20:15:29 +0000284 vty_out (vty, " redistribute default: %d%s", zclient->redist_default,
hasso049207c2004-08-04 20:02:13 +0000285 VNL);
hasso508e53e2004-05-18 18:57:06 +0000286 vty_out (vty, " redistribute:");
paul718e3742002-12-13 20:15:29 +0000287 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
hasso508e53e2004-05-18 18:57:06 +0000288 {
289 if (zclient->redist[i])
290 vty_out (vty, " %s", zebra_route_name[i]);
291 }
hasso049207c2004-08-04 20:02:13 +0000292 vty_out (vty, "%s", VNL);
paul718e3742002-12-13 20:15:29 +0000293 return CMD_SUCCESS;
294}
295
296DEFUN (router_zebra,
297 router_zebra_cmd,
298 "router zebra",
299 "Enable a routing process\n"
300 "Make connection to zebra daemon\n")
301{
paul718e3742002-12-13 20:15:29 +0000302 vty->node = ZEBRA_NODE;
303 zclient->enable = 1;
304 zclient_start (zclient);
305 return CMD_SUCCESS;
306}
307
308DEFUN (no_router_zebra,
309 no_router_zebra_cmd,
310 "no router zebra",
311 NO_STR
312 "Configure routing process\n"
313 "Disable connection to zebra daemon\n")
314{
paul718e3742002-12-13 20:15:29 +0000315 zclient->enable = 0;
316 zclient_stop (zclient);
317 return CMD_SUCCESS;
318}
319
320/* Zebra configuration write function. */
321int
hasso508e53e2004-05-18 18:57:06 +0000322config_write_ospf6_zebra (struct vty *vty)
paul718e3742002-12-13 20:15:29 +0000323{
324 if (! zclient->enable)
325 {
hasso049207c2004-08-04 20:02:13 +0000326 vty_out (vty, "no router zebra%s", VNL);
327 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000328 }
329 else if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
330 {
hasso049207c2004-08-04 20:02:13 +0000331 vty_out (vty, "router zebra%s", VNL);
332 vty_out (vty, " no redistribute ospf6%s", VNL);
333 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000334 }
335 return 0;
336}
337
338/* Zebra node structure. */
339struct cmd_node zebra_node =
340{
341 ZEBRA_NODE,
342 "%s(config-zebra)# ",
paul718e3742002-12-13 20:15:29 +0000343};
344
345#define ADD 0
hasso508e53e2004-05-18 18:57:06 +0000346#define REM 1
paul718e3742002-12-13 20:15:29 +0000347static void
hasso508e53e2004-05-18 18:57:06 +0000348ospf6_zebra_route_update (int type, struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000349{
paul718e3742002-12-13 20:15:29 +0000350 struct zapi_ipv6 api;
hasso508e53e2004-05-18 18:57:06 +0000351 char buf[64], ifname[IFNAMSIZ];
352 int nhcount;
paul718e3742002-12-13 20:15:29 +0000353 struct in6_addr **nexthops;
354 unsigned int *ifindexes;
paul718e3742002-12-13 20:15:29 +0000355 int i, ret = 0;
hasso508e53e2004-05-18 18:57:06 +0000356 struct prefix_ipv6 *dest;
paul718e3742002-12-13 20:15:29 +0000357
hasso508e53e2004-05-18 18:57:06 +0000358 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000359 {
hasso508e53e2004-05-18 18:57:06 +0000360 prefix2str (&request->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000361 zlog_debug ("Send %s route: %s",
362 (type == REM ? "remove" : "add"), buf);
paul718e3742002-12-13 20:15:29 +0000363 }
364
365 if (zclient->sock < 0)
366 {
hasso508e53e2004-05-18 18:57:06 +0000367 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000368 zlog_debug (" Not connected to Zebra");
paul718e3742002-12-13 20:15:29 +0000369 return;
370 }
371
372 if (request->path.origin.adv_router == ospf6->router_id &&
373 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
374 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
375 {
hasso508e53e2004-05-18 18:57:06 +0000376 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000377 zlog_debug (" Ignore self-originated external route");
paul718e3742002-12-13 20:15:29 +0000378 return;
379 }
380
hasso508e53e2004-05-18 18:57:06 +0000381 /* If removing is the best path and if there's another path,
382 treat this request as add the secondary path */
383 if (type == REM && ospf6_route_is_best (request) &&
384 request->next && ospf6_route_is_same (request, request->next))
385 {
386 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000387 zlog_debug (" Best-path removal resulted Sencondary addition");
hasso508e53e2004-05-18 18:57:06 +0000388 type = ADD;
389 request = request->next;
390 }
391
392 /* Only the best path will be sent to zebra. */
393 if (! ospf6_route_is_best (request))
paul718e3742002-12-13 20:15:29 +0000394 {
395 /* this is not preferred best route, ignore */
hasso508e53e2004-05-18 18:57:06 +0000396 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000397 zlog_debug (" Ignore non-best route");
paul718e3742002-12-13 20:15:29 +0000398 return;
399 }
400
hasso508e53e2004-05-18 18:57:06 +0000401 nhcount = 0;
402 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
403 if (ospf6_nexthop_is_set (&request->nexthop[i]))
404 nhcount++;
paul718e3742002-12-13 20:15:29 +0000405
hasso508e53e2004-05-18 18:57:06 +0000406 if (nhcount == 0)
paul718e3742002-12-13 20:15:29 +0000407 {
hasso508e53e2004-05-18 18:57:06 +0000408 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000409 zlog_debug (" No nexthop, ignore");
paul718e3742002-12-13 20:15:29 +0000410 return;
411 }
412
413 /* allocate memory for nexthop_list */
414 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000415 nhcount * sizeof (struct in6_addr *));
416 if (nexthops == NULL)
paul718e3742002-12-13 20:15:29 +0000417 {
hasso508e53e2004-05-18 18:57:06 +0000418 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000419 return;
420 }
421
422 /* allocate memory for ifindex_list */
423 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000424 nhcount * sizeof (unsigned int));
425 if (ifindexes == NULL)
paul718e3742002-12-13 20:15:29 +0000426 {
hasso508e53e2004-05-18 18:57:06 +0000427 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000428 XFREE (MTYPE_OSPF6_OTHER, nexthops);
429 return;
430 }
431
hasso508e53e2004-05-18 18:57:06 +0000432 for (i = 0; i < nhcount; i++)
paul718e3742002-12-13 20:15:29 +0000433 {
hasso508e53e2004-05-18 18:57:06 +0000434 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000435 {
hasso508e53e2004-05-18 18:57:06 +0000436 inet_ntop (AF_INET6, &request->nexthop[i].address,
437 buf, sizeof (buf));
438 if_indextoname (request->nexthop[i].ifindex, ifname);
hassoc6487d62004-12-24 06:00:11 +0000439 zlog_debug (" nexthop: %s%%%s(%d)", buf, ifname,
440 request->nexthop[i].ifindex);
paul718e3742002-12-13 20:15:29 +0000441 }
hasso508e53e2004-05-18 18:57:06 +0000442 nexthops[i] = &request->nexthop[i].address;
443 ifindexes[i] = request->nexthop[i].ifindex;
paul718e3742002-12-13 20:15:29 +0000444 }
445
446 api.type = ZEBRA_ROUTE_OSPF6;
447 api.flags = 0;
448 api.message = 0;
449 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
hasso508e53e2004-05-18 18:57:06 +0000450 api.nexthop_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000451 api.nexthop = nexthops;
hasso508e53e2004-05-18 18:57:06 +0000452 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
453 api.ifindex_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000454 api.ifindex = ifindexes;
hasso508e53e2004-05-18 18:57:06 +0000455 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
456 api.metric = (request->path.metric_type == 2 ?
457 request->path.cost_e2 : request->path.cost);
paul718e3742002-12-13 20:15:29 +0000458
hasso508e53e2004-05-18 18:57:06 +0000459 dest = (struct prefix_ipv6 *) &request->prefix;
460 if (type == REM)
461 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000462 else
hasso508e53e2004-05-18 18:57:06 +0000463 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000464
465 if (ret < 0)
hasso508e53e2004-05-18 18:57:06 +0000466 zlog_err ("zapi_ipv6_route() %s failed: %s",
ajs6099b3b2004-11-20 02:06:59 +0000467 (type == REM ? "delete" : "add"), safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000468
paul718e3742002-12-13 20:15:29 +0000469 XFREE (MTYPE_OSPF6_OTHER, nexthops);
470 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
471
472 return;
473}
474
475void
hasso508e53e2004-05-18 18:57:06 +0000476ospf6_zebra_route_update_add (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000477{
hasso508e53e2004-05-18 18:57:06 +0000478 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
479 {
480 ospf6->route_table->hook_add = NULL;
481 ospf6->route_table->hook_remove = NULL;
482 return;
483 }
paul718e3742002-12-13 20:15:29 +0000484 ospf6_zebra_route_update (ADD, request);
485}
486
487void
hasso508e53e2004-05-18 18:57:06 +0000488ospf6_zebra_route_update_remove (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000489{
hasso508e53e2004-05-18 18:57:06 +0000490 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
paul718e3742002-12-13 20:15:29 +0000491 {
hasso508e53e2004-05-18 18:57:06 +0000492 ospf6->route_table->hook_add = NULL;
493 ospf6->route_table->hook_remove = NULL;
494 return;
paul718e3742002-12-13 20:15:29 +0000495 }
hasso508e53e2004-05-18 18:57:06 +0000496 ospf6_zebra_route_update (REM, request);
paul718e3742002-12-13 20:15:29 +0000497}
498
paul718e3742002-12-13 20:15:29 +0000499DEFUN (redistribute_ospf6,
500 redistribute_ospf6_cmd,
501 "redistribute ospf6",
502 "Redistribute control\n"
503 "OSPF6 route\n")
504{
hasso508e53e2004-05-18 18:57:06 +0000505 struct ospf6_route *route;
506
507 if (zclient->redist[ZEBRA_ROUTE_OSPF6])
508 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000509
510 zclient->redist[ZEBRA_ROUTE_OSPF6] = 1;
511
hasso508e53e2004-05-18 18:57:06 +0000512 if (ospf6 == NULL)
513 return CMD_SUCCESS;
514
515 /* send ospf6 route to zebra route table */
516 for (route = ospf6_route_head (ospf6->route_table); route;
517 route = ospf6_route_next (route))
518 ospf6_zebra_route_update_add (route);
519
520 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
521 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
paul718e3742002-12-13 20:15:29 +0000522
523 return CMD_SUCCESS;
524}
525
526DEFUN (no_redistribute_ospf6,
527 no_redistribute_ospf6_cmd,
528 "no redistribute ospf6",
529 NO_STR
530 "Redistribute control\n"
531 "OSPF6 route\n")
532{
hasso508e53e2004-05-18 18:57:06 +0000533 struct ospf6_route *route;
534
535 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
536 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000537
538 zclient->redist[ZEBRA_ROUTE_OSPF6] = 0;
539
hasso508e53e2004-05-18 18:57:06 +0000540 if (ospf6 == NULL)
paul718e3742002-12-13 20:15:29 +0000541 return CMD_SUCCESS;
542
hasso508e53e2004-05-18 18:57:06 +0000543 ospf6->route_table->hook_add = NULL;
544 ospf6->route_table->hook_remove = NULL;
paul718e3742002-12-13 20:15:29 +0000545
hasso508e53e2004-05-18 18:57:06 +0000546 /* withdraw ospf6 route from zebra route table */
547 for (route = ospf6_route_head (ospf6->route_table); route;
548 route = ospf6_route_next (route))
549 ospf6_zebra_route_update_remove (route);
paul718e3742002-12-13 20:15:29 +0000550
551 return CMD_SUCCESS;
552}
553
554void
555ospf6_zebra_init ()
556{
557 /* Allocate zebra structure. */
558 zclient = zclient_new ();
559 zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
hasso18a6dce2004-10-03 18:18:34 +0000560 zclient->router_id_update = ospf6_router_id_update_zebra;
paul718e3742002-12-13 20:15:29 +0000561 zclient->interface_add = ospf6_zebra_if_add;
562 zclient->interface_delete = ospf6_zebra_if_del;
563 zclient->interface_up = ospf6_zebra_if_state_update;
564 zclient->interface_down = ospf6_zebra_if_state_update;
565 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
566 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
567 zclient->ipv4_route_add = NULL;
568 zclient->ipv4_route_delete = NULL;
569 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
570 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
571
572 /* redistribute connected route by default */
573 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
574
575 /* Install zebra node. */
hasso508e53e2004-05-18 18:57:06 +0000576 install_node (&zebra_node, config_write_ospf6_zebra);
paul718e3742002-12-13 20:15:29 +0000577
578 /* Install command element for zebra node. */
579 install_element (VIEW_NODE, &show_zebra_cmd);
580 install_element (ENABLE_NODE, &show_zebra_cmd);
581 install_element (CONFIG_NODE, &router_zebra_cmd);
582 install_element (CONFIG_NODE, &no_router_zebra_cmd);
hasso508e53e2004-05-18 18:57:06 +0000583
paul718e3742002-12-13 20:15:29 +0000584 install_default (ZEBRA_NODE);
585 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
586 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
587
paul718e3742002-12-13 20:15:29 +0000588 return;
589}
590
hasso508e53e2004-05-18 18:57:06 +0000591/* Debug */
592
593DEFUN (debug_ospf6_zebra_sendrecv,
594 debug_ospf6_zebra_sendrecv_cmd,
595 "debug ospf6 zebra (send|recv)",
596 DEBUG_STR
597 OSPF6_STR
598 "Debug connection between zebra\n"
599 "Debug Sending zebra\n"
600 "Debug Receiving zebra\n"
601 )
paul718e3742002-12-13 20:15:29 +0000602{
hasso508e53e2004-05-18 18:57:06 +0000603 unsigned char level = 0;
604
605 if (argc)
606 {
607 if (! strncmp (argv[0], "s", 1))
608 level = OSPF6_DEBUG_ZEBRA_SEND;
609 else if (! strncmp (argv[0], "r", 1))
610 level = OSPF6_DEBUG_ZEBRA_RECV;
611 }
612 else
613 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
614
615 OSPF6_DEBUG_ZEBRA_ON (level);
616 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000617}
618
hasso508e53e2004-05-18 18:57:06 +0000619ALIAS (debug_ospf6_zebra_sendrecv,
620 debug_ospf6_zebra_cmd,
621 "debug ospf6 zebra",
622 DEBUG_STR
623 OSPF6_STR
624 "Debug connection between zebra\n"
625 );
626
627
628DEFUN (no_debug_ospf6_zebra_sendrecv,
629 no_debug_ospf6_zebra_sendrecv_cmd,
630 "no debug ospf6 zebra (send|recv)",
631 NO_STR
632 DEBUG_STR
633 OSPF6_STR
634 "Debug connection between zebra\n"
635 "Debug Sending zebra\n"
636 "Debug Receiving zebra\n"
637 )
638{
639 unsigned char level = 0;
640
641 if (argc)
642 {
643 if (! strncmp (argv[0], "s", 1))
644 level = OSPF6_DEBUG_ZEBRA_SEND;
645 else if (! strncmp (argv[0], "r", 1))
646 level = OSPF6_DEBUG_ZEBRA_RECV;
647 }
648 else
649 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
650
651 OSPF6_DEBUG_ZEBRA_OFF (level);
652 return CMD_SUCCESS;
653}
654
655ALIAS (no_debug_ospf6_zebra_sendrecv,
656 no_debug_ospf6_zebra_cmd,
657 "no debug ospf6 zebra",
658 NO_STR
659 DEBUG_STR
660 OSPF6_STR
661 "Debug connection between zebra\n"
662 );
663
664int
665config_write_ospf6_debug_zebra (struct vty *vty)
666{
667 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000668 vty_out (vty, "debug ospf6 zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000669 else
670 {
671 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hasso049207c2004-08-04 20:02:13 +0000672 vty_out (vty, "debug ospf6 zebra send%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000673 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000674 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000675 }
676 return 0;
677}
678
679void
680install_element_ospf6_debug_zebra ()
681{
682 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
683 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
684 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
685 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
686 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
687 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
688 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
689 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
690}
691
692