blob: 50ecc170093178e2535409b02c2ef01f5d4e8eea [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. */
Paul Jakma6ac29a52008-08-15 13:45:30 +010050static int
hasso18a6dce2004-10-03 18:18:34 +000051ospf6_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)
ajs634f9ea2005-04-11 15:51:40 +000077 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, 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)
ajs634f9ea2005-04-11 15:51:40 +000087 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
paul718e3742002-12-13 20:15:29 +000088}
89
paul718e3742002-12-13 20:15:29 +000090/* Inteface addition message from zebra. */
Paul Jakma6ac29a52008-08-15 13:45:30 +010091static int
paul718e3742002-12-13 20:15:29 +000092ospf6_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
Paul Jakma6ac29a52008-08-15 13:45:30 +0100104static int
paul718e3742002-12-13 20:15:29 +0000105ospf6_zebra_if_del (int command, struct zclient *zclient, zebra_size_t length)
106{
hasso508e53e2004-05-18 18:57:06 +0000107 struct interface *ifp;
paul718e3742002-12-13 20:15:29 +0000108
ajsd2fc8892005-04-02 18:38:43 +0000109 if (!(ifp = zebra_interface_state_read(zclient->ibuf)))
110 return 0;
111
112 if (if_is_up (ifp))
113 zlog_warn ("Zebra: got delete of %s, but interface is still up", ifp->name);
114
hasso508e53e2004-05-18 18:57:06 +0000115 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000116 zlog_debug ("Zebra Interface delete: %s index %d mtu %d",
117 ifp->name, ifp->ifindex, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000118
ajsd2fc8892005-04-02 18:38:43 +0000119#if 0
Christian Franked9628722013-03-08 21:47:35 +0100120 /* XXX: ospf6_interface_if_del is not the right way to handle this,
121 * because among other thinkable issues, it will also clear all
122 * settings as they are contained in the struct ospf6_interface. */
paul718e3742002-12-13 20:15:29 +0000123 ospf6_interface_if_del (ifp);
hasso508e53e2004-05-18 18:57:06 +0000124#endif /*0*/
ajsd2fc8892005-04-02 18:38:43 +0000125
126 ifp->ifindex = IFINDEX_INTERNAL;
paul718e3742002-12-13 20:15:29 +0000127 return 0;
128}
129
Paul Jakma6ac29a52008-08-15 13:45:30 +0100130static int
paul718e3742002-12-13 20:15:29 +0000131ospf6_zebra_if_state_update (int command, struct zclient *zclient,
132 zebra_size_t length)
133{
134 struct interface *ifp;
135
136 ifp = zebra_interface_state_read (zclient->ibuf);
Ingo Flaschberger57c4f4f2011-04-04 11:17:45 +0100137 if (ifp == NULL)
138 return 0;
139
hasso508e53e2004-05-18 18:57:06 +0000140 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000141 zlog_debug ("Zebra Interface state change: "
Stephen Hemminger30d20592009-07-28 11:58:51 +0100142 "%s index %d flags %llx metric %d mtu %d",
143 ifp->name, ifp->ifindex, (unsigned long long)ifp->flags,
144 ifp->metric, ifp->mtu6);
paul718e3742002-12-13 20:15:29 +0000145
146 ospf6_interface_state_update (ifp);
147 return 0;
148}
149
Paul Jakma6ac29a52008-08-15 13:45:30 +0100150static int
paul718e3742002-12-13 20:15:29 +0000151ospf6_zebra_if_address_update_add (int command, struct zclient *zclient,
hasso508e53e2004-05-18 18:57:06 +0000152 zebra_size_t length)
paul718e3742002-12-13 20:15:29 +0000153{
154 struct connected *c;
155 char buf[128];
156
paul0a589352004-05-08 11:48:26 +0000157 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_ADD, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000158 if (c == NULL)
159 return 0;
160
hasso508e53e2004-05-18 18:57:06 +0000161 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000162 zlog_debug ("Zebra Interface address add: %s %5s %s/%d",
163 c->ifp->name, prefix_family_str (c->address),
164 inet_ntop (c->address->family, &c->address->u.prefix,
165 buf, sizeof (buf)), c->address->prefixlen);
paul718e3742002-12-13 20:15:29 +0000166
167 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000168 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000169
170 return 0;
171}
172
Paul Jakma6ac29a52008-08-15 13:45:30 +0100173static int
paul718e3742002-12-13 20:15:29 +0000174ospf6_zebra_if_address_update_delete (int command, struct zclient *zclient,
175 zebra_size_t length)
176{
177 struct connected *c;
178 char buf[128];
179
paul0a589352004-05-08 11:48:26 +0000180 c = zebra_interface_address_read (ZEBRA_INTERFACE_ADDRESS_DELETE, zclient->ibuf);
paul718e3742002-12-13 20:15:29 +0000181 if (c == NULL)
182 return 0;
183
hasso508e53e2004-05-18 18:57:06 +0000184 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hassoc6487d62004-12-24 06:00:11 +0000185 zlog_debug ("Zebra Interface address delete: %s %5s %s/%d",
186 c->ifp->name, prefix_family_str (c->address),
187 inet_ntop (c->address->family, &c->address->u.prefix,
188 buf, sizeof (buf)), c->address->prefixlen);
paul718e3742002-12-13 20:15:29 +0000189
190 if (c->address->family == AF_INET6)
hasso508e53e2004-05-18 18:57:06 +0000191 ospf6_interface_connected_route_update (c->ifp);
paul718e3742002-12-13 20:15:29 +0000192
193 return 0;
194}
195
Paul Jakma6ac29a52008-08-15 13:45:30 +0100196static int
paul718e3742002-12-13 20:15:29 +0000197ospf6_zebra_read_ipv6 (int command, struct zclient *zclient,
198 zebra_size_t length)
199{
200 struct stream *s;
201 struct zapi_ipv6 api;
202 unsigned long ifindex;
203 struct prefix_ipv6 p;
204 struct in6_addr *nexthop;
paul718e3742002-12-13 20:15:29 +0000205
206 s = zclient->ibuf;
207 ifindex = 0;
208 nexthop = NULL;
209 memset (&api, 0, sizeof (api));
210
211 /* Type, flags, message. */
212 api.type = stream_getc (s);
213 api.flags = stream_getc (s);
214 api.message = stream_getc (s);
215
216 /* IPv6 prefix. */
217 memset (&p, 0, sizeof (struct prefix_ipv6));
218 p.family = AF_INET6;
219 p.prefixlen = stream_getc (s);
220 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
221
222 /* Nexthop, ifindex, distance, metric. */
223 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
224 {
225 api.nexthop_num = stream_getc (s);
226 nexthop = (struct in6_addr *)
227 malloc (api.nexthop_num * sizeof (struct in6_addr));
228 stream_get (nexthop, s, api.nexthop_num * sizeof (struct in6_addr));
229 }
230 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
231 {
232 api.ifindex_num = stream_getc (s);
233 ifindex = stream_getl (s);
234 }
235 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
236 api.distance = stream_getc (s);
237 else
238 api.distance = 0;
239 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
240 api.metric = stream_getl (s);
241 else
242 api.metric = 0;
243
hasso508e53e2004-05-18 18:57:06 +0000244 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
paul718e3742002-12-13 20:15:29 +0000245 {
hasso508e53e2004-05-18 18:57:06 +0000246 char prefixstr[128], nexthopstr[128];
paul718e3742002-12-13 20:15:29 +0000247 prefix2str ((struct prefix *)&p, prefixstr, sizeof (prefixstr));
hasso508e53e2004-05-18 18:57:06 +0000248 if (nexthop)
249 inet_ntop (AF_INET6, nexthop, nexthopstr, sizeof (nexthopstr));
paul718e3742002-12-13 20:15:29 +0000250 else
hasso508e53e2004-05-18 18:57:06 +0000251 snprintf (nexthopstr, sizeof (nexthopstr), "::");
252
hassoc6487d62004-12-24 06:00:11 +0000253 zlog_debug ("Zebra Receive route %s: %s %s nexthop %s ifindex %ld",
254 (command == ZEBRA_IPV6_ROUTE_ADD ? "add" : "delete"),
ajsf52d13c2005-10-01 17:38:06 +0000255 zebra_route_string(api.type), prefixstr, nexthopstr, ifindex);
paul718e3742002-12-13 20:15:29 +0000256 }
257
258 if (command == ZEBRA_IPV6_ROUTE_ADD)
hasso508e53e2004-05-18 18:57:06 +0000259 ospf6_asbr_redistribute_add (api.type, ifindex, (struct prefix *) &p,
260 api.nexthop_num, nexthop);
paul718e3742002-12-13 20:15:29 +0000261 else
hasso508e53e2004-05-18 18:57:06 +0000262 ospf6_asbr_redistribute_remove (api.type, ifindex, (struct prefix *) &p);
paul718e3742002-12-13 20:15:29 +0000263
264 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
265 free (nexthop);
266
267 return 0;
268}
269
hasso508e53e2004-05-18 18:57:06 +0000270
271
paul718e3742002-12-13 20:15:29 +0000272
273DEFUN (show_zebra,
274 show_zebra_cmd,
275 "show zebra",
276 SHOW_STR
277 "Zebra information\n")
278{
279 int i;
hasso508e53e2004-05-18 18:57:06 +0000280 if (zclient == NULL)
281 {
hasso049207c2004-08-04 20:02:13 +0000282 vty_out (vty, "Not connected to zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000283 return CMD_SUCCESS;
284 }
paul718e3742002-12-13 20:15:29 +0000285
hasso049207c2004-08-04 20:02:13 +0000286 vty_out (vty, "Zebra Infomation%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000287 vty_out (vty, " enable: %d fail: %d%s",
hasso049207c2004-08-04 20:02:13 +0000288 zclient->enable, zclient->fail, VNL);
paul718e3742002-12-13 20:15:29 +0000289 vty_out (vty, " redistribute default: %d%s", zclient->redist_default,
hasso049207c2004-08-04 20:02:13 +0000290 VNL);
hasso508e53e2004-05-18 18:57:06 +0000291 vty_out (vty, " redistribute:");
paul718e3742002-12-13 20:15:29 +0000292 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
hasso508e53e2004-05-18 18:57:06 +0000293 {
294 if (zclient->redist[i])
ajsf52d13c2005-10-01 17:38:06 +0000295 vty_out (vty, " %s", zebra_route_string(i));
hasso508e53e2004-05-18 18:57:06 +0000296 }
hasso049207c2004-08-04 20:02:13 +0000297 vty_out (vty, "%s", VNL);
paul718e3742002-12-13 20:15:29 +0000298 return CMD_SUCCESS;
299}
300
301DEFUN (router_zebra,
302 router_zebra_cmd,
303 "router zebra",
304 "Enable a routing process\n"
305 "Make connection to zebra daemon\n")
306{
paul718e3742002-12-13 20:15:29 +0000307 vty->node = ZEBRA_NODE;
308 zclient->enable = 1;
309 zclient_start (zclient);
310 return CMD_SUCCESS;
311}
312
313DEFUN (no_router_zebra,
314 no_router_zebra_cmd,
315 "no router zebra",
316 NO_STR
317 "Configure routing process\n"
318 "Disable connection to zebra daemon\n")
319{
paul718e3742002-12-13 20:15:29 +0000320 zclient->enable = 0;
321 zclient_stop (zclient);
322 return CMD_SUCCESS;
323}
324
325/* Zebra configuration write function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100326static int
hasso508e53e2004-05-18 18:57:06 +0000327config_write_ospf6_zebra (struct vty *vty)
paul718e3742002-12-13 20:15:29 +0000328{
329 if (! zclient->enable)
330 {
hasso049207c2004-08-04 20:02:13 +0000331 vty_out (vty, "no router zebra%s", VNL);
332 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000333 }
334 else if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
335 {
hasso049207c2004-08-04 20:02:13 +0000336 vty_out (vty, "router zebra%s", VNL);
337 vty_out (vty, " no redistribute ospf6%s", VNL);
338 vty_out (vty, "!%s", VNL);
paul718e3742002-12-13 20:15:29 +0000339 }
340 return 0;
341}
342
343/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800344static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000345{
346 ZEBRA_NODE,
347 "%s(config-zebra)# ",
paul718e3742002-12-13 20:15:29 +0000348};
349
350#define ADD 0
hasso508e53e2004-05-18 18:57:06 +0000351#define REM 1
paul718e3742002-12-13 20:15:29 +0000352static void
hasso508e53e2004-05-18 18:57:06 +0000353ospf6_zebra_route_update (int type, struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000354{
paul718e3742002-12-13 20:15:29 +0000355 struct zapi_ipv6 api;
ajsd2fc8892005-04-02 18:38:43 +0000356 char buf[64];
hasso508e53e2004-05-18 18:57:06 +0000357 int nhcount;
paul718e3742002-12-13 20:15:29 +0000358 struct in6_addr **nexthops;
359 unsigned int *ifindexes;
paul718e3742002-12-13 20:15:29 +0000360 int i, ret = 0;
hasso508e53e2004-05-18 18:57:06 +0000361 struct prefix_ipv6 *dest;
paul718e3742002-12-13 20:15:29 +0000362
hasso508e53e2004-05-18 18:57:06 +0000363 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
paul718e3742002-12-13 20:15:29 +0000364 {
hasso508e53e2004-05-18 18:57:06 +0000365 prefix2str (&request->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000366 zlog_debug ("Send %s route: %s",
367 (type == REM ? "remove" : "add"), buf);
paul718e3742002-12-13 20:15:29 +0000368 }
369
370 if (zclient->sock < 0)
371 {
hasso508e53e2004-05-18 18:57:06 +0000372 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000373 zlog_debug (" Not connected to Zebra");
paul718e3742002-12-13 20:15:29 +0000374 return;
375 }
376
377 if (request->path.origin.adv_router == ospf6->router_id &&
378 (request->path.type == OSPF6_PATH_TYPE_EXTERNAL1 ||
379 request->path.type == OSPF6_PATH_TYPE_EXTERNAL2))
380 {
hasso508e53e2004-05-18 18:57:06 +0000381 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000382 zlog_debug (" Ignore self-originated external route");
paul718e3742002-12-13 20:15:29 +0000383 return;
384 }
385
hasso508e53e2004-05-18 18:57:06 +0000386 /* If removing is the best path and if there's another path,
387 treat this request as add the secondary path */
388 if (type == REM && ospf6_route_is_best (request) &&
389 request->next && ospf6_route_is_same (request, request->next))
390 {
391 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000392 zlog_debug (" Best-path removal resulted Sencondary addition");
hasso508e53e2004-05-18 18:57:06 +0000393 type = ADD;
394 request = request->next;
395 }
396
397 /* Only the best path will be sent to zebra. */
398 if (! ospf6_route_is_best (request))
paul718e3742002-12-13 20:15:29 +0000399 {
400 /* this is not preferred best route, ignore */
hasso508e53e2004-05-18 18:57:06 +0000401 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000402 zlog_debug (" Ignore non-best route");
paul718e3742002-12-13 20:15:29 +0000403 return;
404 }
405
hasso508e53e2004-05-18 18:57:06 +0000406 nhcount = 0;
407 for (i = 0; i < OSPF6_MULTI_PATH_LIMIT; i++)
408 if (ospf6_nexthop_is_set (&request->nexthop[i]))
409 nhcount++;
paul718e3742002-12-13 20:15:29 +0000410
hasso508e53e2004-05-18 18:57:06 +0000411 if (nhcount == 0)
paul718e3742002-12-13 20:15:29 +0000412 {
hasso508e53e2004-05-18 18:57:06 +0000413 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hassoc6487d62004-12-24 06:00:11 +0000414 zlog_debug (" No nexthop, ignore");
paul718e3742002-12-13 20:15:29 +0000415 return;
416 }
417
418 /* allocate memory for nexthop_list */
419 nexthops = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000420 nhcount * sizeof (struct in6_addr *));
421 if (nexthops == NULL)
paul718e3742002-12-13 20:15:29 +0000422 {
hasso508e53e2004-05-18 18:57:06 +0000423 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000424 return;
425 }
426
427 /* allocate memory for ifindex_list */
428 ifindexes = XCALLOC (MTYPE_OSPF6_OTHER,
hasso508e53e2004-05-18 18:57:06 +0000429 nhcount * sizeof (unsigned int));
430 if (ifindexes == NULL)
paul718e3742002-12-13 20:15:29 +0000431 {
hasso508e53e2004-05-18 18:57:06 +0000432 zlog_warn ("Can't send route to zebra: malloc failed");
paul718e3742002-12-13 20:15:29 +0000433 XFREE (MTYPE_OSPF6_OTHER, nexthops);
434 return;
435 }
436
hasso508e53e2004-05-18 18:57:06 +0000437 for (i = 0; i < nhcount; i++)
paul718e3742002-12-13 20:15:29 +0000438 {
hasso508e53e2004-05-18 18:57:06 +0000439 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
ajsd2fc8892005-04-02 18:38:43 +0000440 {
441 char ifname[IFNAMSIZ];
442 inet_ntop (AF_INET6, &request->nexthop[i].address,
443 buf, sizeof (buf));
444 if (!if_indextoname(request->nexthop[i].ifindex, ifname))
445 strlcpy(ifname, "unknown", sizeof(ifname));
446 zlog_debug (" nexthop: %s%%%.*s(%d)", buf, IFNAMSIZ, ifname,
hassoc6487d62004-12-24 06:00:11 +0000447 request->nexthop[i].ifindex);
ajsd2fc8892005-04-02 18:38:43 +0000448 }
hasso508e53e2004-05-18 18:57:06 +0000449 nexthops[i] = &request->nexthop[i].address;
450 ifindexes[i] = request->nexthop[i].ifindex;
paul718e3742002-12-13 20:15:29 +0000451 }
452
453 api.type = ZEBRA_ROUTE_OSPF6;
454 api.flags = 0;
455 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +0400456 api.safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +0000457 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
hasso508e53e2004-05-18 18:57:06 +0000458 api.nexthop_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000459 api.nexthop = nexthops;
hasso508e53e2004-05-18 18:57:06 +0000460 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
461 api.ifindex_num = nhcount;
paul718e3742002-12-13 20:15:29 +0000462 api.ifindex = ifindexes;
hasso508e53e2004-05-18 18:57:06 +0000463 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
464 api.metric = (request->path.metric_type == 2 ?
465 request->path.cost_e2 : request->path.cost);
paul718e3742002-12-13 20:15:29 +0000466
hasso508e53e2004-05-18 18:57:06 +0000467 dest = (struct prefix_ipv6 *) &request->prefix;
468 if (type == REM)
469 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_DELETE, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000470 else
hasso508e53e2004-05-18 18:57:06 +0000471 ret = zapi_ipv6_route (ZEBRA_IPV6_ROUTE_ADD, zclient, dest, &api);
paul718e3742002-12-13 20:15:29 +0000472
473 if (ret < 0)
hasso508e53e2004-05-18 18:57:06 +0000474 zlog_err ("zapi_ipv6_route() %s failed: %s",
ajs6099b3b2004-11-20 02:06:59 +0000475 (type == REM ? "delete" : "add"), safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000476
paul718e3742002-12-13 20:15:29 +0000477 XFREE (MTYPE_OSPF6_OTHER, nexthops);
478 XFREE (MTYPE_OSPF6_OTHER, ifindexes);
479
480 return;
481}
482
483void
hasso508e53e2004-05-18 18:57:06 +0000484ospf6_zebra_route_update_add (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000485{
hasso508e53e2004-05-18 18:57:06 +0000486 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
487 {
488 ospf6->route_table->hook_add = NULL;
489 ospf6->route_table->hook_remove = NULL;
490 return;
491 }
paul718e3742002-12-13 20:15:29 +0000492 ospf6_zebra_route_update (ADD, request);
493}
494
495void
hasso508e53e2004-05-18 18:57:06 +0000496ospf6_zebra_route_update_remove (struct ospf6_route *request)
paul718e3742002-12-13 20:15:29 +0000497{
hasso508e53e2004-05-18 18:57:06 +0000498 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
paul718e3742002-12-13 20:15:29 +0000499 {
hasso508e53e2004-05-18 18:57:06 +0000500 ospf6->route_table->hook_add = NULL;
501 ospf6->route_table->hook_remove = NULL;
502 return;
paul718e3742002-12-13 20:15:29 +0000503 }
hasso508e53e2004-05-18 18:57:06 +0000504 ospf6_zebra_route_update (REM, request);
paul718e3742002-12-13 20:15:29 +0000505}
506
paul718e3742002-12-13 20:15:29 +0000507DEFUN (redistribute_ospf6,
508 redistribute_ospf6_cmd,
509 "redistribute ospf6",
510 "Redistribute control\n"
511 "OSPF6 route\n")
512{
hasso508e53e2004-05-18 18:57:06 +0000513 struct ospf6_route *route;
514
515 if (zclient->redist[ZEBRA_ROUTE_OSPF6])
516 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000517
518 zclient->redist[ZEBRA_ROUTE_OSPF6] = 1;
519
hasso508e53e2004-05-18 18:57:06 +0000520 if (ospf6 == NULL)
521 return CMD_SUCCESS;
522
523 /* send ospf6 route to zebra route table */
524 for (route = ospf6_route_head (ospf6->route_table); route;
525 route = ospf6_route_next (route))
526 ospf6_zebra_route_update_add (route);
527
528 ospf6->route_table->hook_add = ospf6_zebra_route_update_add;
529 ospf6->route_table->hook_remove = ospf6_zebra_route_update_remove;
paul718e3742002-12-13 20:15:29 +0000530
531 return CMD_SUCCESS;
532}
533
534DEFUN (no_redistribute_ospf6,
535 no_redistribute_ospf6_cmd,
536 "no redistribute ospf6",
537 NO_STR
538 "Redistribute control\n"
539 "OSPF6 route\n")
540{
hasso508e53e2004-05-18 18:57:06 +0000541 struct ospf6_route *route;
542
543 if (! zclient->redist[ZEBRA_ROUTE_OSPF6])
544 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000545
546 zclient->redist[ZEBRA_ROUTE_OSPF6] = 0;
547
hasso508e53e2004-05-18 18:57:06 +0000548 if (ospf6 == NULL)
paul718e3742002-12-13 20:15:29 +0000549 return CMD_SUCCESS;
550
hasso508e53e2004-05-18 18:57:06 +0000551 ospf6->route_table->hook_add = NULL;
552 ospf6->route_table->hook_remove = NULL;
paul718e3742002-12-13 20:15:29 +0000553
hasso508e53e2004-05-18 18:57:06 +0000554 /* withdraw ospf6 route from zebra route table */
555 for (route = ospf6_route_head (ospf6->route_table); route;
556 route = ospf6_route_next (route))
557 ospf6_zebra_route_update_remove (route);
paul718e3742002-12-13 20:15:29 +0000558
559 return CMD_SUCCESS;
560}
561
562void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100563ospf6_zebra_init (void)
paul718e3742002-12-13 20:15:29 +0000564{
565 /* Allocate zebra structure. */
566 zclient = zclient_new ();
567 zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
hasso18a6dce2004-10-03 18:18:34 +0000568 zclient->router_id_update = ospf6_router_id_update_zebra;
paul718e3742002-12-13 20:15:29 +0000569 zclient->interface_add = ospf6_zebra_if_add;
570 zclient->interface_delete = ospf6_zebra_if_del;
571 zclient->interface_up = ospf6_zebra_if_state_update;
572 zclient->interface_down = ospf6_zebra_if_state_update;
573 zclient->interface_address_add = ospf6_zebra_if_address_update_add;
574 zclient->interface_address_delete = ospf6_zebra_if_address_update_delete;
575 zclient->ipv4_route_add = NULL;
576 zclient->ipv4_route_delete = NULL;
577 zclient->ipv6_route_add = ospf6_zebra_read_ipv6;
578 zclient->ipv6_route_delete = ospf6_zebra_read_ipv6;
579
580 /* redistribute connected route by default */
581 /* ospf6_zebra_redistribute (ZEBRA_ROUTE_CONNECT); */
582
583 /* Install zebra node. */
hasso508e53e2004-05-18 18:57:06 +0000584 install_node (&zebra_node, config_write_ospf6_zebra);
paul718e3742002-12-13 20:15:29 +0000585
586 /* Install command element for zebra node. */
587 install_element (VIEW_NODE, &show_zebra_cmd);
588 install_element (ENABLE_NODE, &show_zebra_cmd);
589 install_element (CONFIG_NODE, &router_zebra_cmd);
590 install_element (CONFIG_NODE, &no_router_zebra_cmd);
hasso508e53e2004-05-18 18:57:06 +0000591
paul718e3742002-12-13 20:15:29 +0000592 install_default (ZEBRA_NODE);
593 install_element (ZEBRA_NODE, &redistribute_ospf6_cmd);
594 install_element (ZEBRA_NODE, &no_redistribute_ospf6_cmd);
595
paul718e3742002-12-13 20:15:29 +0000596 return;
597}
598
hasso508e53e2004-05-18 18:57:06 +0000599/* Debug */
600
601DEFUN (debug_ospf6_zebra_sendrecv,
602 debug_ospf6_zebra_sendrecv_cmd,
603 "debug ospf6 zebra (send|recv)",
604 DEBUG_STR
605 OSPF6_STR
606 "Debug connection between zebra\n"
607 "Debug Sending zebra\n"
608 "Debug Receiving zebra\n"
609 )
paul718e3742002-12-13 20:15:29 +0000610{
hasso508e53e2004-05-18 18:57:06 +0000611 unsigned char level = 0;
612
613 if (argc)
614 {
615 if (! strncmp (argv[0], "s", 1))
616 level = OSPF6_DEBUG_ZEBRA_SEND;
617 else if (! strncmp (argv[0], "r", 1))
618 level = OSPF6_DEBUG_ZEBRA_RECV;
619 }
620 else
621 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
622
623 OSPF6_DEBUG_ZEBRA_ON (level);
624 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000625}
626
hasso508e53e2004-05-18 18:57:06 +0000627ALIAS (debug_ospf6_zebra_sendrecv,
628 debug_ospf6_zebra_cmd,
629 "debug ospf6 zebra",
630 DEBUG_STR
631 OSPF6_STR
632 "Debug connection between zebra\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100633 )
hasso508e53e2004-05-18 18:57:06 +0000634
635
636DEFUN (no_debug_ospf6_zebra_sendrecv,
637 no_debug_ospf6_zebra_sendrecv_cmd,
638 "no debug ospf6 zebra (send|recv)",
639 NO_STR
640 DEBUG_STR
641 OSPF6_STR
642 "Debug connection between zebra\n"
643 "Debug Sending zebra\n"
644 "Debug Receiving zebra\n"
645 )
646{
647 unsigned char level = 0;
648
649 if (argc)
650 {
651 if (! strncmp (argv[0], "s", 1))
652 level = OSPF6_DEBUG_ZEBRA_SEND;
653 else if (! strncmp (argv[0], "r", 1))
654 level = OSPF6_DEBUG_ZEBRA_RECV;
655 }
656 else
657 level = OSPF6_DEBUG_ZEBRA_SEND | OSPF6_DEBUG_ZEBRA_RECV;
658
659 OSPF6_DEBUG_ZEBRA_OFF (level);
660 return CMD_SUCCESS;
661}
662
663ALIAS (no_debug_ospf6_zebra_sendrecv,
664 no_debug_ospf6_zebra_cmd,
665 "no debug ospf6 zebra",
666 NO_STR
667 DEBUG_STR
668 OSPF6_STR
669 "Debug connection between zebra\n"
Paul Jakma6ac29a52008-08-15 13:45:30 +0100670 )
hasso508e53e2004-05-18 18:57:06 +0000671
672int
673config_write_ospf6_debug_zebra (struct vty *vty)
674{
675 if (IS_OSPF6_DEBUG_ZEBRA (SEND) && IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000676 vty_out (vty, "debug ospf6 zebra%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000677 else
678 {
679 if (IS_OSPF6_DEBUG_ZEBRA (SEND))
hasso049207c2004-08-04 20:02:13 +0000680 vty_out (vty, "debug ospf6 zebra send%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000681 if (IS_OSPF6_DEBUG_ZEBRA (RECV))
hasso049207c2004-08-04 20:02:13 +0000682 vty_out (vty, "debug ospf6 zebra recv%s", VNL);
hasso508e53e2004-05-18 18:57:06 +0000683 }
684 return 0;
685}
686
687void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100688install_element_ospf6_debug_zebra (void)
hasso508e53e2004-05-18 18:57:06 +0000689{
690 install_element (ENABLE_NODE, &debug_ospf6_zebra_cmd);
691 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_cmd);
692 install_element (ENABLE_NODE, &debug_ospf6_zebra_sendrecv_cmd);
693 install_element (ENABLE_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
694 install_element (CONFIG_NODE, &debug_ospf6_zebra_cmd);
695 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_cmd);
696 install_element (CONFIG_NODE, &debug_ospf6_zebra_sendrecv_cmd);
697 install_element (CONFIG_NODE, &no_debug_ospf6_zebra_sendrecv_cmd);
698}
699
700