blob: b5cf445dd01520ff200c250e8e95f2bcf90eb53f [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
2 * RIPngd and zebra interface.
3 * Copyright (C) 1998, 1999 Kunihiro Ishiguro
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "command.h"
26#include "prefix.h"
Feng Lue97c31a2015-05-22 11:39:53 +020027#include "table.h"
paul718e3742002-12-13 20:15:29 +000028#include "stream.h"
Feng Lue97c31a2015-05-22 11:39:53 +020029#include "memory.h"
paul718e3742002-12-13 20:15:29 +000030#include "routemap.h"
31#include "zclient.h"
32#include "log.h"
33
34#include "ripngd/ripngd.h"
Feng Lue97c31a2015-05-22 11:39:53 +020035#include "ripngd/ripng_debug.h"
paul718e3742002-12-13 20:15:29 +000036
37/* All information about zebra. */
38struct zclient *zclient = NULL;
39
40/* Callback prototypes for zebra client service. */
41int ripng_interface_up (int, struct zclient *, zebra_size_t);
42int ripng_interface_down (int, struct zclient *, zebra_size_t);
43int ripng_interface_add (int, struct zclient *, zebra_size_t);
44int ripng_interface_delete (int, struct zclient *, zebra_size_t);
45int ripng_interface_address_add (int, struct zclient *, zebra_size_t);
46int ripng_interface_address_delete (int, struct zclient *, zebra_size_t);
David Lamparter6b0655a2014-06-04 06:53:35 +020047
Feng Lue97c31a2015-05-22 11:39:53 +020048/* Send ECMP routes to zebra. */
49static void
50ripng_zebra_ipv6_send (struct route_node *rp, u_char cmd)
paul718e3742002-12-13 20:15:29 +000051{
Feng Lue97c31a2015-05-22 11:39:53 +020052 static struct in6_addr **nexthops = NULL;
53 static unsigned int *ifindexes = NULL;
54 static unsigned int nexthops_len = 0;
55
56 struct list *list = (struct list *)rp->info;
paul718e3742002-12-13 20:15:29 +000057 struct zapi_ipv6 api;
Feng Lue97c31a2015-05-22 11:39:53 +020058 struct listnode *listnode = NULL;
59 struct ripng_info *rinfo = NULL;
60 int count = 0;
paul718e3742002-12-13 20:15:29 +000061
62 if (zclient->redist[ZEBRA_ROUTE_RIPNG])
63 {
64 api.type = ZEBRA_ROUTE_RIPNG;
65 api.flags = 0;
66 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +040067 api.safi = SAFI_UNICAST;
Feng Lue97c31a2015-05-22 11:39:53 +020068
69 if (nexthops_len < listcount (list))
70 {
71 nexthops_len = listcount (list);
72 nexthops = XREALLOC (MTYPE_TMP, nexthops,
73 nexthops_len * sizeof (struct in6_addr *));
74 ifindexes = XREALLOC (MTYPE_TMP, ifindexes,
75 nexthops_len * sizeof (unsigned int));
76 }
77
paul718e3742002-12-13 20:15:29 +000078 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
paul718e3742002-12-13 20:15:29 +000079 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
Feng Lue97c31a2015-05-22 11:39:53 +020080 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
81 {
82 nexthops[count] = &rinfo->nexthop;
83 ifindexes[count] = rinfo->ifindex;
84 count++;
85 if (cmd == ZEBRA_IPV6_ROUTE_ADD)
86 SET_FLAG (rinfo->flags, RIPNG_RTF_FIB);
87 else
88 UNSET_FLAG (rinfo->flags, RIPNG_RTF_FIB);
89 }
90
91 api.nexthop = nexthops;
92 api.nexthop_num = count;
93 api.ifindex = ifindexes;
94 api.ifindex_num = count;
95
96 rinfo = listgetdata (listhead (list));
97
hassodeba3552005-08-27 06:19:39 +000098 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
Feng Lue97c31a2015-05-22 11:39:53 +020099 api.metric = rinfo->metric;
100
101 zapi_ipv6_route (cmd, zclient,
102 (struct prefix_ipv6 *)&rp->p, &api);
103
104 if (IS_RIPNG_DEBUG_ZEBRA)
105 zlog_debug ("%s: %s/%d nexthops %d",
106 (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
107 "Install into zebra" : "Delete from zebra",
108 inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen, count);
paul718e3742002-12-13 20:15:29 +0000109 }
110}
111
Feng Lue97c31a2015-05-22 11:39:53 +0200112/* Add/update ECMP routes to zebra. */
paul718e3742002-12-13 20:15:29 +0000113void
Feng Lue97c31a2015-05-22 11:39:53 +0200114ripng_zebra_ipv6_add (struct route_node *rp)
paul718e3742002-12-13 20:15:29 +0000115{
Feng Lue97c31a2015-05-22 11:39:53 +0200116 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_ADD);
117}
paul718e3742002-12-13 20:15:29 +0000118
Feng Lue97c31a2015-05-22 11:39:53 +0200119/* Delete ECMP routes from zebra. */
120void
121ripng_zebra_ipv6_delete (struct route_node *rp)
122{
123 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_DELETE);
paul718e3742002-12-13 20:15:29 +0000124}
125
126/* Zebra route add and delete treatment. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100127static int
paul718e3742002-12-13 20:15:29 +0000128ripng_zebra_read_ipv6 (int command, struct zclient *zclient,
129 zebra_size_t length)
130{
131 struct stream *s;
132 struct zapi_ipv6 api;
133 unsigned long ifindex;
134 struct in6_addr nexthop;
135 struct prefix_ipv6 p;
136
137 s = zclient->ibuf;
138 ifindex = 0;
139 memset (&nexthop, 0, sizeof (struct in6_addr));
140
141 /* Type, flags, message. */
142 api.type = stream_getc (s);
143 api.flags = stream_getc (s);
144 api.message = stream_getc (s);
145
146 /* IPv6 prefix. */
147 memset (&p, 0, sizeof (struct prefix_ipv6));
148 p.family = AF_INET6;
149 p.prefixlen = stream_getc (s);
150 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
151
152 /* Nexthop, ifindex, distance, metric. */
153 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
154 {
155 api.nexthop_num = stream_getc (s);
156 stream_get (&nexthop, s, 16);
157 }
158 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
159 {
160 api.ifindex_num = stream_getc (s);
161 ifindex = stream_getl (s);
162 }
163 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
164 api.distance = stream_getc (s);
165 else
166 api.distance = 0;
167 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
168 api.metric = stream_getl (s);
169 else
170 api.metric = 0;
171
172 if (command == ZEBRA_IPV6_ROUTE_ADD)
hassoa94434b2003-05-25 17:10:12 +0000173 ripng_redistribute_add (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex, &nexthop);
paul718e3742002-12-13 20:15:29 +0000174 else
hassoa94434b2003-05-25 17:10:12 +0000175 ripng_redistribute_delete (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex);
paul718e3742002-12-13 20:15:29 +0000176
177 return 0;
178}
179
hassoa94434b2003-05-25 17:10:12 +0000180void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100181ripng_zclient_reset (void)
hassoa94434b2003-05-25 17:10:12 +0000182{
183 zclient_reset (zclient);
184}
185
Paul Jakma6ac29a52008-08-15 13:45:30 +0100186static int
paul718e3742002-12-13 20:15:29 +0000187ripng_redistribute_unset (int type)
188{
189 if (! zclient->redist[type])
190 return CMD_SUCCESS;
191
192 zclient->redist[type] = 0;
193
194 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000195 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
paul718e3742002-12-13 20:15:29 +0000196
197 ripng_redistribute_withdraw (type);
198
199 return CMD_SUCCESS;
200}
201
hassoa94434b2003-05-25 17:10:12 +0000202int
203ripng_redistribute_check (int type)
204{
205 return (zclient->redist[type]);
206}
207
Paul Jakma6ac29a52008-08-15 13:45:30 +0100208static void
paul718e3742002-12-13 20:15:29 +0000209ripng_redistribute_metric_set (int type, int metric)
210{
211 ripng->route_map[type].metric_config = 1;
212 ripng->route_map[type].metric = metric;
213}
214
Paul Jakma6ac29a52008-08-15 13:45:30 +0100215static int
paul718e3742002-12-13 20:15:29 +0000216ripng_redistribute_metric_unset (int type)
217{
218 ripng->route_map[type].metric_config = 0;
219 ripng->route_map[type].metric = 0;
hassoa94434b2003-05-25 17:10:12 +0000220 return 0;
paul718e3742002-12-13 20:15:29 +0000221}
222
Paul Jakma6ac29a52008-08-15 13:45:30 +0100223static void
hasso98b718a2004-10-11 12:57:57 +0000224ripng_redistribute_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000225{
226 if (ripng->route_map[type].name)
227 free (ripng->route_map[type].name);
228
229 ripng->route_map[type].name = strdup (name);
230 ripng->route_map[type].map = route_map_lookup_by_name (name);
231}
232
Paul Jakma6ac29a52008-08-15 13:45:30 +0100233static void
paul718e3742002-12-13 20:15:29 +0000234ripng_redistribute_routemap_unset (int type)
235{
236 if (ripng->route_map[type].name)
237 free (ripng->route_map[type].name);
238
239 ripng->route_map[type].name = NULL;
240 ripng->route_map[type].map = NULL;
241}
David Lamparter6b0655a2014-06-04 06:53:35 +0200242
hassoa94434b2003-05-25 17:10:12 +0000243/* Redistribution types */
244static struct {
245 int type;
246 int str_min_len;
hasso7a1d5832004-10-08 06:32:23 +0000247 const char *str;
hassoa94434b2003-05-25 17:10:12 +0000248} redist_type[] = {
249 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
250 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
251 {ZEBRA_ROUTE_STATIC, 1, "static"},
252 {ZEBRA_ROUTE_OSPF6, 1, "ospf6"},
Matthieu Boutier93079db2012-02-09 20:58:07 +0100253 {ZEBRA_ROUTE_BGP, 2, "bgp"},
254 {ZEBRA_ROUTE_BABEL, 2, "babel"},
hassoa94434b2003-05-25 17:10:12 +0000255 {0, 0, NULL}
256};
257
258void
259ripng_redistribute_clean ()
260{
261 int i;
262
263 for (i = 0; redist_type[i].str; i++)
264 {
265 if (zclient->redist[redist_type[i].type])
266 {
267 if (zclient->sock > 0)
268 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
ajs634f9ea2005-04-11 15:51:40 +0000269 zclient, redist_type[i].type);
hassoa94434b2003-05-25 17:10:12 +0000270
271 zclient->redist[redist_type[i].type] = 0;
272
273 /* Remove the routes from RIPng table. */
274 ripng_redistribute_withdraw (redist_type[i].type);
275 }
276 }
277}
278
paul718e3742002-12-13 20:15:29 +0000279DEFUN (router_zebra,
280 router_zebra_cmd,
281 "router zebra",
282 "Enable a routing process\n"
283 "Make connection to zebra daemon\n")
284{
285 vty->node = ZEBRA_NODE;
286 zclient->enable = 1;
287 zclient_start (zclient);
288 return CMD_SUCCESS;
289}
290
291DEFUN (no_router_zebra,
292 no_router_zebra_cmd,
293 "no router zebra",
294 NO_STR
295 "Disable a routing process\n"
296 "Stop connection to zebra daemon\n")
297{
298 zclient->enable = 0;
299 zclient_stop (zclient);
300 return CMD_SUCCESS;
301}
302
303DEFUN (ripng_redistribute_ripng,
304 ripng_redistribute_ripng_cmd,
305 "redistribute ripng",
306 "Redistribute information from another routing protocol\n"
307 "RIPng route\n")
308{
309 zclient->redist[ZEBRA_ROUTE_RIPNG] = 1;
310 return CMD_SUCCESS;
311}
312
313DEFUN (no_ripng_redistribute_ripng,
314 no_ripng_redistribute_ripng_cmd,
315 "no redistribute ripng",
316 NO_STR
317 "Redistribute information from another routing protocol\n"
318 "RIPng route\n")
319{
320 zclient->redist[ZEBRA_ROUTE_RIPNG] = 0;
321 return CMD_SUCCESS;
322}
323
hassoa94434b2003-05-25 17:10:12 +0000324DEFUN (ripng_redistribute_type,
325 ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100326 "redistribute " QUAGGA_REDIST_STR_RIPNGD,
327 "Redistribute\n"
328 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000329{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100330 int type;
hassoa94434b2003-05-25 17:10:12 +0000331
Matthieu Boutier93079db2012-02-09 20:58:07 +0100332 type = proto_redistnum(AFI_IP6, argv[0]);
333
334 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000335 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100336 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
337 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000338 }
339
Matthieu Boutier93079db2012-02-09 20:58:07 +0100340 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
341 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000342}
343
hassoa94434b2003-05-25 17:10:12 +0000344DEFUN (no_ripng_redistribute_type,
345 no_ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100346 "no redistribute " QUAGGA_REDIST_STR_RIPNGD,
paul718e3742002-12-13 20:15:29 +0000347 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100348 "Redistribute\n"
349 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000350{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100351 int type;
hassoa94434b2003-05-25 17:10:12 +0000352
Matthieu Boutier93079db2012-02-09 20:58:07 +0100353 type = proto_redistnum(AFI_IP6, argv[0]);
354
355 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000356 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100357 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
358 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000359 }
360
Matthieu Boutier93079db2012-02-09 20:58:07 +0100361 ripng_redistribute_metric_unset (type);
362 ripng_redistribute_routemap_unset (type);
363 return ripng_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000364}
365
paul718e3742002-12-13 20:15:29 +0000366
hassoa94434b2003-05-25 17:10:12 +0000367DEFUN (ripng_redistribute_type_metric,
368 ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100369 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
370 "Redistribute\n"
371 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000372 "Metric\n"
373 "Metric value\n")
374{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100375 int type;
hassoa94434b2003-05-25 17:10:12 +0000376 int metric;
377
378 metric = atoi (argv[1]);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100379 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000380
Matthieu Boutier93079db2012-02-09 20:58:07 +0100381 if (type < 0)
382 {
383 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
384 return CMD_WARNING;
385 }
hassoa94434b2003-05-25 17:10:12 +0000386
Matthieu Boutier93079db2012-02-09 20:58:07 +0100387 ripng_redistribute_metric_set (type, metric);
388 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
389 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000390}
391
hassoa94434b2003-05-25 17:10:12 +0000392ALIAS (no_ripng_redistribute_type,
393 no_ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100394 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000395 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100396 "Redistribute\n"
397 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000398 "Metric\n"
399 "Metric value\n")
400
hassoa94434b2003-05-25 17:10:12 +0000401DEFUN (ripng_redistribute_type_routemap,
402 ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100403 "redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
404 "Redistribute\n"
405 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000406 "Route map reference\n"
407 "Pointer to route-map entries\n")
408{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100409 int type;
hassoa94434b2003-05-25 17:10:12 +0000410
Matthieu Boutier93079db2012-02-09 20:58:07 +0100411 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000412
Matthieu Boutier93079db2012-02-09 20:58:07 +0100413 if (type < 0)
414 {
415 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
416 return CMD_WARNING;
417 }
hassoa94434b2003-05-25 17:10:12 +0000418
Matthieu Boutier93079db2012-02-09 20:58:07 +0100419 ripng_redistribute_routemap_set (type, argv[1]);
420 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
421 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000422}
423
hassoa94434b2003-05-25 17:10:12 +0000424ALIAS (no_ripng_redistribute_type,
425 no_ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100426 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000427 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100428 "Redistribute\n"
429 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000430 "Route map reference\n"
431 "Pointer to route-map entries\n")
432
hassoa94434b2003-05-25 17:10:12 +0000433DEFUN (ripng_redistribute_type_metric_routemap,
434 ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100435 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
436 "Redistribute\n"
437 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000438 "Metric\n"
439 "Metric value\n"
440 "Route map reference\n"
441 "Pointer to route-map entries\n")
442{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100443 int type;
hassoa94434b2003-05-25 17:10:12 +0000444 int metric;
445
Matthieu Boutier93079db2012-02-09 20:58:07 +0100446 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000447 metric = atoi (argv[1]);
448
Matthieu Boutier93079db2012-02-09 20:58:07 +0100449 if (type < 0)
450 {
451 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
452 return CMD_WARNING;
453 }
hassoa94434b2003-05-25 17:10:12 +0000454
Matthieu Boutier93079db2012-02-09 20:58:07 +0100455 ripng_redistribute_metric_set (type, metric);
456 ripng_redistribute_routemap_set (type, argv[2]);
457 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
458 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000459}
460
hassoa94434b2003-05-25 17:10:12 +0000461ALIAS (no_ripng_redistribute_type,
462 no_ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100463 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000464 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100465 "Redistribute\n"
466 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000467 "Route map reference\n"
468 "Pointer to route-map entries\n")
469
470void
hassoa94434b2003-05-25 17:10:12 +0000471ripng_redistribute_write (struct vty *vty, int config_mode)
paul718e3742002-12-13 20:15:29 +0000472{
473 int i;
paul718e3742002-12-13 20:15:29 +0000474
475 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
476 if (i != zclient->redist_default && zclient->redist[i])
477 {
hassoa94434b2003-05-25 17:10:12 +0000478 if (config_mode)
479 {
480 if (ripng->route_map[i].metric_config)
481 {
482 if (ripng->route_map[i].name)
483 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000484 zebra_route_string(i), ripng->route_map[i].metric,
hassoa94434b2003-05-25 17:10:12 +0000485 ripng->route_map[i].name, VTY_NEWLINE);
486 else
487 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000488 zebra_route_string(i), ripng->route_map[i].metric,
489 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000490 }
491 else
492 {
493 if (ripng->route_map[i].name)
494 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000495 zebra_route_string(i), ripng->route_map[i].name,
496 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000497 else
ajsf52d13c2005-10-01 17:38:06 +0000498 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
499 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000500 }
501 }
502 else
ajsf52d13c2005-10-01 17:38:06 +0000503 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000504 }
505}
506
507/* RIPng configuration write function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100508static int
paul718e3742002-12-13 20:15:29 +0000509zebra_config_write (struct vty *vty)
510{
511 if (! zclient->enable)
512 {
513 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
514 return 1;
515 }
516 else if (! zclient->redist[ZEBRA_ROUTE_RIPNG])
517 {
518 vty_out (vty, "router zebra%s", VTY_NEWLINE);
519 vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE);
520 return 1;
521 }
522 return 0;
523}
524
525/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800526static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000527{
528 ZEBRA_NODE,
529 "%s(config-router)# ",
530};
531
532/* Initialize zebra structure and it's commands. */
533void
534zebra_init ()
535{
536 /* Allocate zebra structure. */
537 zclient = zclient_new ();
538 zclient_init (zclient, ZEBRA_ROUTE_RIPNG);
539
540 zclient->interface_up = ripng_interface_up;
541 zclient->interface_down = ripng_interface_down;
542 zclient->interface_add = ripng_interface_add;
543 zclient->interface_delete = ripng_interface_delete;
544 zclient->interface_address_add = ripng_interface_address_add;
545 zclient->interface_address_delete = ripng_interface_address_delete;
546 zclient->ipv6_route_add = ripng_zebra_read_ipv6;
547 zclient->ipv6_route_delete = ripng_zebra_read_ipv6;
548
549 /* Install zebra node. */
550 install_node (&zebra_node, zebra_config_write);
551
552 /* Install command element for zebra node. */
553 install_element (CONFIG_NODE, &router_zebra_cmd);
554 install_element (CONFIG_NODE, &no_router_zebra_cmd);
555 install_default (ZEBRA_NODE);
556 install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd);
557 install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd);
hassoa94434b2003-05-25 17:10:12 +0000558
559 /* Install command elements to ripng node */
560 install_element (RIPNG_NODE, &ripng_redistribute_type_cmd);
561 install_element (RIPNG_NODE, &ripng_redistribute_type_routemap_cmd);
562 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_cmd);
563 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_routemap_cmd);
564 install_element (RIPNG_NODE, &no_ripng_redistribute_type_cmd);
565 install_element (RIPNG_NODE, &no_ripng_redistribute_type_routemap_cmd);
566 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_cmd);
567 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000568}