blob: bdd3babcc708190aa918f04eac3acfd715813ab1 [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
60 if (o->router_id == 0)
61 o->router_id = (u_int32_t) router_id_zebra.s_addr;
62
63 return 0;
64}
65
paul718e3742002-12-13 20:15:29 +000066/* redistribute function */
67void
68ospf6_zebra_redistribute (int type)
69{
paul718e3742002-12-13 20:15:29 +000070 if (zclient->redist[type])
71 return;
paul718e3742002-12-13 20:15:29 +000072 zclient->redist[type] = 1;
paul718e3742002-12-13 20:15:29 +000073 if (zclient->sock > 0)
74 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000075}
76
77void
78ospf6_zebra_no_redistribute (int type)
79{
hasso508e53e2004-05-18 18:57:06 +000080 if (! zclient->redist[type])
paul718e3742002-12-13 20:15:29 +000081 return;
paul718e3742002-12-13 20:15:29 +000082 zclient->redist[type] = 0;
paul718e3742002-12-13 20:15:29 +000083 if (zclient->sock > 0)
84 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient->sock, type);
paul718e3742002-12-13 20:15:29 +000085}
86
paul718e3742002-12-13 20:15:29 +000087/* Inteface addition message from zebra. */
88int
89ospf6_zebra_if_add (int command, struct zclient *zclient, zebra_size_t length)
90{
91 struct interface *ifp;
92
93 ifp = zebra_interface_add_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +000094 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +000095 zlog_debug ("Zebra Interface add: %s index %d mtu %d",
96 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +000097 ospf6_interface_if_add (ifp);
paul718e3742002-12-13 20:15:29 +000098 return 0;
99}
100
101int
102ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
103{
104#if 0
hasso508e53e2004-05-18 18:57:06 +0000105 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +0000106
107 ifp = zebra_interface_delete_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +0000108 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000109 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
110 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000111
112 ospf6_interface_if_del (ifp);
hasso508e53e2004-05-18 18:57:06 +0000113#endif /*0*/
paul718e3742002-12-13 20:15:29 +0000114 return 0;
115}
116
117int
118ospf6_zebra_if_state_update (int command, struct zclient *zclient,
119 zebra_size_t length)
120{
121 struct interface *ifp;
122
123 ifp = zebra_interface_state_read (zclient->ibuf);
hasso508e53e2004-05-18 18:57:06 +0000124 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000125 zlog_debug ("Zebra Interface state change: "
126 "%s index %d flags %ld metric %d mtu %d",
127 ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000128
129 ospf6_interface_state_update (ifp);
130 return 0;
131}
132
133int
134ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
hasso508e53e2004-05-18 18:57:06 +0000135 zebra_size_t length)
paul718e3742002-12-13 20:15:29 +0000136{
137 struct connected *c;
138 char buf[128];
139
paul0a589352004-05-08 11:48:26 +0000140 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000141 if (c == NULL)
142 return 0;
143
hasso508e53e2004-05-18 18:57:06 +0000144 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000145 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
146 c->ifp->name, prefix_family_str (c->address),
147 inet_ntop (c->address->family, &c->address->u.prefix,
148 buf, sizeof (buf)), c->address->prefixlen);
paul718e3742002-12-13 20:15:29 +0000149
150 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000151 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000152
153 return 0;
154}
155
156int
157ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
158 zebra_size_t length)
159{
160 struct connected *c;
161 char buf[128];
162
paul0a589352004-05-08 11:48:26 +0000163 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000164 if (c == NULL)
165 return 0;
166
hasso508e53e2004-05-18 18:57:06 +0000167 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000168 zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
169 c->ifp->name, prefix_family_str (c->address),
170 inet_ntop (c->address->family, &c->address->u.prefix,
171 buf, sizeof (buf)), c->address->prefixlen);
paul718e3742002-12-13 20:15:29 +0000172
173 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000174 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000175
176 return 0;
177}
178
179
180
181const char *zebra_route_name[ZEBRA_ROUTE_MAX] =
hasso508e53e2004-05-18 18:57:06 +0000182 { "System", "Kernel", "Connect", "Static", "RIP", "RIPng", "OSPF",
hassof3f27f62004-09-10 18:07:57 +0000183 "OSPF6", "ISIS", "BGP" };
paul718e3742002-12-13 20:15:29 +0000184
185const char *zebra_route_abname[ZEBRA_ROUTE_MAX] =
hassof3f27f62004-09-10 18:07:57 +0000186 { "X", "K", "C", "S", "r", "R", "o", "O", "I", "B" };
paul718e3742002-12-13 20:15:29 +0000187
188int
189ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
190 zebra_size_t length)
191{
192 struct stream *s;
193 struct zapi_ipv6 api;
194 unsigned long ifindex;
195 struct prefix_ipv6 p;
196 struct in6_addr *nexthop;
paul718e3742002-12-13 20:15:29 +0000197
198 s = zclient->ibuf;
199 ifindex = 0;
200 nexthop = NULL;
201 memset (&api, 0, sizeof (api));
202
203 /* Type, flags, message. */
204 api.type = stream_getc (s);
205 api.flags = stream_getc (s);
206 api.message = stream_getc (s);
207
208 /* IPv6 prefix. */
209 memset (&p, 0, sizeof (struct prefix_ipv6));
210 p.family = AF_INET6;
211 p.prefixlen = stream_getc (s);
212 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
213
214 /* Nexthop, ifindex, distance, metric. */
215 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
216 {
217 api.nexthop_num = stream_getc (s);
218 nexthop = (struct in6_addr *)
219 malloc (api.nexthop_num * sizeof (struct in6_addr));
220 stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
221 }
222 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
223 {
224 api.ifindex_num = stream_getc (s);
225 ifindex = stream_getl (s);
226 }
227 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
228 api.distance = stream_getc (s);
229 else
230 api.distance = 0;
231 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
232 api.metric = stream_getl (s);
233 else
234 api.metric = 0;
235
hasso508e53e2004-05-18 18:57:06 +0000236 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
paul718e3742002-12-13 20:15:29 +0000237 {
hasso508e53e2004-05-18 18:57:06 +0000238 char prefixstr[128], nexthopstr[128];
paul718e3742002-12-13 20:15:29 +0000239 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
hasso508e53e2004-05-18 18:57:06 +0000240 if (nexthop)
241 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
paul718e3742002-12-13 20:15:29 +0000242 else
hasso508e53e2004-05-18 18:57:06 +0000243 snprintf (nexthopstr, sizeof (nexthopstr), "::");
244
hassoc6487d62004-12-24 06:00:11 +0000245 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
246 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
247 zebra_route_name[api.type], prefixstr, nexthopstr, ifindex);
paul718e3742002-12-13 20:15:29 +0000248 }
249
250 if (command == ZEBRA_IPV6_ROUTE_ADD)
hasso508e53e2004-05-18 18:57:06 +0000251 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
252 api.nexthop_num, nexthop);
paul718e3742002-12-13 20:15:29 +0000253 else
hasso508e53e2004-05-18 18:57:06 +0000254 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000255
256 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
257 free (nexthop);
258
259 return 0;
260}
261
hasso508e53e2004-05-18 18:57:06 +0000262
263
paul718e3742002-12-13 20:15:29 +0000264
265DEFUN (show_zebra,
266 show_zebra_cmd,
267 "show zebra",
268 SHOW_STR
269 "Zebra information\n")
270{
271 int i;
hasso508e53e2004-05-18 18:57:06 +0000272 if (zclient == NULL)
273 {
hasso049207c2004-08-04 20:02:13 +0000274 vty_out (vty, "Not connected to zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000275 return CMD_SUCCESS;
276 }
paul718e3742002-12-13 20:15:29 +0000277
hasso049207c2004-08-04 20:02:13 +0000278 vty_out (vty, "Zebra Infomation%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000279 vty_out (vty, " enable: %d fail: %d%s",
hasso049207c2004-08-04 20:02:13 +0000280 zclient->enable, zclient->fail, VNL);
paul718e3742002-12-13 20:15:29 +0000281 vty_out (vty, " redistribute default: %d%s", zclient->redist_default,
hasso049207c2004-08-04 20:02:13 +0000282 VNL);
hasso508e53e2004-05-18 18:57:06 +0000283 vty_out (vty, " redistribute:");
paul718e3742002-12-13 20:15:29 +0000284 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
hasso508e53e2004-05-18 18:57:06 +0000285 {
286 if (zclient->redist[i])
287 vty_out (vty, " %s", zebra_route_name[i]);
288 }
hasso049207c2004-08-04 20:02:13 +0000289 vty_out (vty, "%s", VNL);
paul718e3742002-12-13 20:15:29 +0000290 return CMD_SUCCESS;
291}
292
293DEFUN (router_zebra,
294 router_zebra_cmd,
295 "router zebra",
296 "Enable a routing process\n"
297 "Make connection to zebra daemon\n")
298{
paul718e3742002-12-13 20:15:29 +0000299 vty->node = ZEBRA_NODE;
300 zclient->enable = 1;
301 zclient_start (zclient);
302 return CMD_SUCCESS;
303}
304
305DEFUN (no_router_zebra,
306 no_router_zebra_cmd,
307 "no router zebra",
308 NO_STR
309 "Configure routing process\n"
310 "Disable connection to zebra daemon\n")
311{
paul718e3742002-12-13 20:15:29 +0000312 zclient->enable = 0;
313 zclient_stop (zclient);
314 return CMD_SUCCESS;
315}
316
317/* Zebra configuration write function. */
318int
hasso508e53e2004-05-18 18:57:06 +0000319config_write_ospf6_zebra (struct vty *vty)
paul718e3742002-12-13 20:15:29 +0000320{
321 if (! zclient->enable)
322 {
hasso049207c2004-08-04 20:02:13 +0000323 vty_out (vty, "no router zebra%s", VNL);
324 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000325 }
326 else if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
327 {
hasso049207c2004-08-04 20:02:13 +0000328 vty_out (vty, "router zebra%s", VNL);
329 vty_out (vty, " no redistribute ospf6%s", VNL);
330 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000331 }
332 return 0;
333}
334
335/* Zebra node structure. */
336struct cmd_node zebra_node =
337{
338 ZEBRA_NODE,
339 "%s(config-zebra)# ",
paul718e3742002-12-13 20:15:29 +0000340};
341
342#define ADD 0
hasso508e53e2004-05-18 18:57:06 +0000343#define REM 1
paul718e3742002-12-13 20:15:29 +0000344static void
hasso508e53e2004-05-18 18:57:06 +0000345ospf6_zebra_route_update (int type, struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000346{
paul718e3742002-12-13 20:15:29 +0000347 struct zapi_ipv6 api;
hasso508e53e2004-05-18 18:57:06 +0000348 char buf[64], ifname[IFNAMSIZ];
349 int nhcount;
paul718e3742002-12-13 20:15:29 +0000350 struct in6_addr **nexthops;
351 unsigned int *ifindexes;
paul718e3742002-12-13 20:15:29 +0000352 int i, ret = 0;
hasso508e53e2004-05-18 18:57:06 +0000353 struct prefix_ipv6 *dest;
paul718e3742002-12-13 20:15:29 +0000354
hasso508e53e2004-05-18 18:57:06 +0000355 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000356 {
hasso508e53e2004-05-18 18:57:06 +0000357 prefix2str (&request->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000358 zlog_debug ("Send %s route: %s",
359 (type == REM ? "remove" : "add"), buf);
paul718e3742002-12-13 20:15:29 +0000360 }
361
362 if (zclient->sock < 0)
363 {
hasso508e53e2004-05-18 18:57:06 +0000364 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000365 zlog_debug (" Not connected to Zebra");
paul718e3742002-12-13 20:15:29 +0000366 return;
367 }
368
369 if (request->path.origin.adv_router == ospf6->router_id &&
370 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
371 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
372 {
hasso508e53e2004-05-18 18:57:06 +0000373 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000374 zlog_debug (" Ignore self-originated external route");
paul718e3742002-12-13 20:15:29 +0000375 return;
376 }
377
hasso508e53e2004-05-18 18:57:06 +0000378 /* If removing is the best path and if there's another path,
379 treat this request as add the secondary path */
380 if (type == REM && ospf6_route_is_best (request) &&
381 request->next && ospf6_route_is_same (request, request->next))
382 {
383 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000384 zlog_debug (" Best-path removal resulted Sencondary addition");
hasso508e53e2004-05-18 18:57:06 +0000385 type = ADD;
386 request = request->next;
387 }
388
389 /* Only the best path will be sent to zebra. */
390 if (! ospf6_route_is_best (request))
paul718e3742002-12-13 20:15:29 +0000391 {
392 /* this is not preferred best route, ignore */
hasso508e53e2004-05-18 18:57:06 +0000393 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000394 zlog_debug (" Ignore non-best route");
paul718e3742002-12-13 20:15:29 +0000395 return;
396 }
397
hasso508e53e2004-05-18 18:57:06 +0000398 nhcount = 0;
399 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
400 if (ospf6_nexthop_is_set (&request->nexthop[i]))
401 nhcount++;
paul718e3742002-12-13 20:15:29 +0000402
hasso508e53e2004-05-18 18:57:06 +0000403 if (nhcount == 0)
paul718e3742002-12-13 20:15:29 +0000404 {
hasso508e53e2004-05-18 18:57:06 +0000405 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000406 zlog_debug (" No nexthop, ignore");
paul718e3742002-12-13 20:15:29 +0000407 return;
408 }
409
410 /* allocate memory for nexthop_list */
411 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000412 nhcount * sizeof (struct in6_addr *));
413 if (nexthops == NULL)
paul718e3742002-12-13 20:15:29 +0000414 {
hasso508e53e2004-05-18 18:57:06 +0000415 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000416 return;
417 }
418
419 /* allocate memory for ifindex_list */
420 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000421 nhcount * sizeof (unsigned int));
422 if (ifindexes == NULL)
paul718e3742002-12-13 20:15:29 +0000423 {
hasso508e53e2004-05-18 18:57:06 +0000424 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000425 XFREE (MTYPE_OSPF6_OTHER, nexthops);
426 return;
427 }
428
hasso508e53e2004-05-18 18:57:06 +0000429 for (i = 0; i < nhcount; i++)
paul718e3742002-12-13 20:15:29 +0000430 {
hasso508e53e2004-05-18 18:57:06 +0000431 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000432 {
hasso508e53e2004-05-18 18:57:06 +0000433 inet_ntop (AF_INET6, &request->nexthop[i].address,
434 buf, sizeof (buf));
435 if_indextoname (request->nexthop[i].ifindex, ifname);
hassoc6487d62004-12-24 06:00:11 +0000436 zlog_debug (" nexthop: %s%%%s(%d)", buf, ifname,
437 request->nexthop[i].ifindex);
paul718e3742002-12-13 20:15:29 +0000438 }
hasso508e53e2004-05-18 18:57:06 +0000439 nexthops[i] = &request->nexthop[i].address;
440 ifindexes[i] = request->nexthop[i].ifindex;
paul718e3742002-12-13 20:15:29 +0000441 }
442
443 api.type = ZEBRA_ROUTE_OSPF6;
444 api.flags = 0;
445 api.message = 0;
446 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
hasso508e53e2004-05-18 18:57:06 +0000447 api.nexthop_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000448 api.nexthop = nexthops;
hasso508e53e2004-05-18 18:57:06 +0000449 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
450 api.ifindex_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000451 api.ifindex = ifindexes;
hasso508e53e2004-05-18 18:57:06 +0000452 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
453 api.metric = (request->path.metric_type == 2 ?
454 request->path.cost_e2 : request->path.cost);
paul718e3742002-12-13 20:15:29 +0000455
hasso508e53e2004-05-18 18:57:06 +0000456 dest = (struct prefix_ipv6 *) &request->prefix;
457 if (type == REM)
458 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000459 else
hasso508e53e2004-05-18 18:57:06 +0000460 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000461
462 if (ret < 0)
hasso508e53e2004-05-18 18:57:06 +0000463 zlog_err ("zapi_ipv6_route() %s failed: %s",
ajs6099b3b2004-11-20 02:06:59 +0000464 (type == REM ? "delete" : "add"), safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000465
paul718e3742002-12-13 20:15:29 +0000466 XFREE (MTYPE_OSPF6_OTHER, nexthops);
467 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
468
469 return;
470}
471
472void
hasso508e53e2004-05-18 18:57:06 +0000473ospf6_zebra_route_update_add (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000474{
hasso508e53e2004-05-18 18:57:06 +0000475 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
476 {
477 ospf6->route_table->hook_add = NULL;
478 ospf6->route_table->hook_remove = NULL;
479 return;
480 }
paul718e3742002-12-13 20:15:29 +0000481 ospf6_zebra_route_update (ADD, request);
482}
483
484void
hasso508e53e2004-05-18 18:57:06 +0000485ospf6_zebra_route_update_remove (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000486{
hasso508e53e2004-05-18 18:57:06 +0000487 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
paul718e3742002-12-13 20:15:29 +0000488 {
hasso508e53e2004-05-18 18:57:06 +0000489 ospf6->route_table->hook_add = NULL;
490 ospf6->route_table->hook_remove = NULL;
491 return;
paul718e3742002-12-13 20:15:29 +0000492 }
hasso508e53e2004-05-18 18:57:06 +0000493 ospf6_zebra_route_update (REM, request);
paul718e3742002-12-13 20:15:29 +0000494}
495
paul718e3742002-12-13 20:15:29 +0000496DEFUN (redistribute_ospf6,
497 redistribute_ospf6_cmd,
498 "redistribute ospf6",
499 "Redistribute control\n"
500 "OSPF6 route\n")
501{
hasso508e53e2004-05-18 18:57:06 +0000502 struct ospf6_route *route;
503
504 if (zclient->redist[ZEBRA_ROUTE_OSPF6])
505 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000506
507 zclient->redist[ZEBRA_ROUTE_OSPF6] = 1;
508
hasso508e53e2004-05-18 18:57:06 +0000509 if (ospf6 == NULL)
510 return CMD_SUCCESS;
511
512 /* send ospf6 route to zebra route table */
513 for (route = ospf6_route_head (ospf6->route_table); route;
514 route = ospf6_route_next (route))
515 ospf6_zebra_route_update_add (route);
516
517 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
518 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
paul718e3742002-12-13 20:15:29 +0000519
520 return CMD_SUCCESS;
521}
522
523DEFUN (no_redistribute_ospf6,
524 no_redistribute_ospf6_cmd,
525 "no redistribute ospf6",
526 NO_STR
527 "Redistribute control\n"
528 "OSPF6 route\n")
529{
hasso508e53e2004-05-18 18:57:06 +0000530 struct ospf6_route *route;
531
532 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
533 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000534
535 zclient->redist[ZEBRA_ROUTE_OSPF6] = 0;
536
hasso508e53e2004-05-18 18:57:06 +0000537 if (ospf6 == NULL)
paul718e3742002-12-13 20:15:29 +0000538 return CMD_SUCCESS;
539
hasso508e53e2004-05-18 18:57:06 +0000540 ospf6->route_table->hook_add = NULL;
541 ospf6->route_table->hook_remove = NULL;
paul718e3742002-12-13 20:15:29 +0000542
hasso508e53e2004-05-18 18:57:06 +0000543 /* withdraw ospf6 route from zebra route table */
544 for (route = ospf6_route_head (ospf6->route_table); route;
545 route = ospf6_route_next (route))
546 ospf6_zebra_route_update_remove (route);
paul718e3742002-12-13 20:15:29 +0000547
548 return CMD_SUCCESS;
549}
550
551void
552ospf6_zebra_init ()
553{
554 /* Allocate zebra structure. */
555 zclient = zclient_new ();
556 zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
hasso18a6dce2004-10-03 18:18:34 +0000557 zclient->router_id_update = ospf6_router_id_update_zebra;
paul718e3742002-12-13 20:15:29 +0000558 zclient->interface_add = ospf6_zebra_if_add;
559 zclient->interface_delete = ospf6_zebra_if_del;
560 zclient->interface_up = ospf6_zebra_if_state_update;
561 zclient->interface_down = ospf6_zebra_if_state_update;
562 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
563 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
564 zclient->ipv4_route_add = NULL;
565 zclient->ipv4_route_delete = NULL;
566 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
567 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
568
569 /* redistribute connected route by default */
570 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
571
572 /* Install zebra node. */
hasso508e53e2004-05-18 18:57:06 +0000573 install_node (&zebra_node, config_write_ospf6_zebra);
paul718e3742002-12-13 20:15:29 +0000574
575 /* Install command element for zebra node. */
576 install_element (VIEW_NODE, &show_zebra_cmd);
577 install_element (ENABLE_NODE, &show_zebra_cmd);
578 install_element (CONFIG_NODE, &router_zebra_cmd);
579 install_element (CONFIG_NODE, &no_router_zebra_cmd);
hasso508e53e2004-05-18 18:57:06 +0000580
paul718e3742002-12-13 20:15:29 +0000581 install_default (ZEBRA_NODE);
582 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
583 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
584
paul718e3742002-12-13 20:15:29 +0000585 return;
586}
587
hasso508e53e2004-05-18 18:57:06 +0000588/* Debug */
589
590DEFUN (debug_ospf6_zebra_sendrecv,
591 debug_ospf6_zebra_sendrecv_cmd,
592 "debug ospf6 zebra (send|recv)",
593 DEBUG_STR
594 OSPF6_STR
595 "Debug connection between zebra\n"
596 "Debug Sending zebra\n"
597 "Debug Receiving zebra\n"
598 )
paul718e3742002-12-13 20:15:29 +0000599{
hasso508e53e2004-05-18 18:57:06 +0000600 unsigned char level = 0;
601
602 if (argc)
603 {
604 if (! strncmp (argv[0], "s", 1))
605 level = OSPF6_DEBUG_ZEBRA_SEND;
606 else if (! strncmp (argv[0], "r", 1))
607 level = OSPF6_DEBUG_ZEBRA_RECV;
608 }
609 else
610 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
611
612 OSPF6_DEBUG_ZEBRA_ON (level);
613 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000614}
615
hasso508e53e2004-05-18 18:57:06 +0000616ALIAS (debug_ospf6_zebra_sendrecv,
617 debug_ospf6_zebra_cmd,
618 "debug ospf6 zebra",
619 DEBUG_STR
620 OSPF6_STR
621 "Debug connection between zebra\n"
622 );
623
624
625DEFUN (no_debug_ospf6_zebra_sendrecv,
626 no_debug_ospf6_zebra_sendrecv_cmd,
627 "no debug ospf6 zebra (send|recv)",
628 NO_STR
629 DEBUG_STR
630 OSPF6_STR
631 "Debug connection between zebra\n"
632 "Debug Sending zebra\n"
633 "Debug Receiving zebra\n"
634 )
635{
636 unsigned char level = 0;
637
638 if (argc)
639 {
640 if (! strncmp (argv[0], "s", 1))
641 level = OSPF6_DEBUG_ZEBRA_SEND;
642 else if (! strncmp (argv[0], "r", 1))
643 level = OSPF6_DEBUG_ZEBRA_RECV;
644 }
645 else
646 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
647
648 OSPF6_DEBUG_ZEBRA_OFF (level);
649 return CMD_SUCCESS;
650}
651
652ALIAS (no_debug_ospf6_zebra_sendrecv,
653 no_debug_ospf6_zebra_cmd,
654 "no debug ospf6 zebra",
655 NO_STR
656 DEBUG_STR
657 OSPF6_STR
658 "Debug connection between zebra\n"
659 );
660
661int
662config_write_ospf6_debug_zebra (struct vty *vty)
663{
664 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000665 vty_out (vty, "debug ospf6 zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000666 else
667 {
668 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hasso049207c2004-08-04 20:02:13 +0000669 vty_out (vty, "debug ospf6 zebra send%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000670 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000671 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000672 }
673 return 0;
674}
675
676void
677install_element_ospf6_debug_zebra ()
678{
679 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
680 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
681 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
682 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
683 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
684 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
685 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
686 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
687}
688
689