blob: 5d383fa2a0f69b3c2125d5a4dc017a017214050b [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)
Feng Lu72855b12015-05-22 11:39:54 +0200105 {
106 if (ripng->ecmp)
107 zlog_debug ("%s: %s/%d nexthops %d",
108 (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
109 "Install into zebra" : "Delete from zebra",
110 inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen, count);
111 else
112 zlog_debug ("%s: %s/%d",
113 (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
114 "Install into zebra" : "Delete from zebra",
115 inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen);
116 }
paul718e3742002-12-13 20:15:29 +0000117 }
118}
119
Feng Lue97c31a2015-05-22 11:39:53 +0200120/* Add/update ECMP routes to zebra. */
paul718e3742002-12-13 20:15:29 +0000121void
Feng Lue97c31a2015-05-22 11:39:53 +0200122ripng_zebra_ipv6_add (struct route_node *rp)
paul718e3742002-12-13 20:15:29 +0000123{
Feng Lue97c31a2015-05-22 11:39:53 +0200124 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_ADD);
125}
paul718e3742002-12-13 20:15:29 +0000126
Feng Lue97c31a2015-05-22 11:39:53 +0200127/* Delete ECMP routes from zebra. */
128void
129ripng_zebra_ipv6_delete (struct route_node *rp)
130{
131 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_DELETE);
paul718e3742002-12-13 20:15:29 +0000132}
133
134/* Zebra route add and delete treatment. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100135static int
paul718e3742002-12-13 20:15:29 +0000136ripng_zebra_read_ipv6 (int command, struct zclient *zclient,
137 zebra_size_t length)
138{
139 struct stream *s;
140 struct zapi_ipv6 api;
141 unsigned long ifindex;
142 struct in6_addr nexthop;
143 struct prefix_ipv6 p;
144
145 s = zclient->ibuf;
146 ifindex = 0;
147 memset (&nexthop, 0, sizeof (struct in6_addr));
148
149 /* Type, flags, message. */
150 api.type = stream_getc (s);
151 api.flags = stream_getc (s);
152 api.message = stream_getc (s);
153
154 /* IPv6 prefix. */
155 memset (&p, 0, sizeof (struct prefix_ipv6));
156 p.family = AF_INET6;
157 p.prefixlen = stream_getc (s);
158 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
159
160 /* Nexthop, ifindex, distance, metric. */
161 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
162 {
163 api.nexthop_num = stream_getc (s);
164 stream_get (&nexthop, s, 16);
165 }
166 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
167 {
168 api.ifindex_num = stream_getc (s);
169 ifindex = stream_getl (s);
170 }
171 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
172 api.distance = stream_getc (s);
173 else
174 api.distance = 0;
175 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
176 api.metric = stream_getl (s);
177 else
178 api.metric = 0;
179
180 if (command == ZEBRA_IPV6_ROUTE_ADD)
hassoa94434b2003-05-25 17:10:12 +0000181 ripng_redistribute_add (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex, &nexthop);
paul718e3742002-12-13 20:15:29 +0000182 else
hassoa94434b2003-05-25 17:10:12 +0000183 ripng_redistribute_delete (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex);
paul718e3742002-12-13 20:15:29 +0000184
185 return 0;
186}
187
hassoa94434b2003-05-25 17:10:12 +0000188void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100189ripng_zclient_reset (void)
hassoa94434b2003-05-25 17:10:12 +0000190{
191 zclient_reset (zclient);
192}
193
Paul Jakma6ac29a52008-08-15 13:45:30 +0100194static int
paul718e3742002-12-13 20:15:29 +0000195ripng_redistribute_unset (int type)
196{
197 if (! zclient->redist[type])
198 return CMD_SUCCESS;
199
200 zclient->redist[type] = 0;
201
202 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000203 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
paul718e3742002-12-13 20:15:29 +0000204
205 ripng_redistribute_withdraw (type);
206
207 return CMD_SUCCESS;
208}
209
hassoa94434b2003-05-25 17:10:12 +0000210int
211ripng_redistribute_check (int type)
212{
213 return (zclient->redist[type]);
214}
215
Paul Jakma6ac29a52008-08-15 13:45:30 +0100216static void
paul718e3742002-12-13 20:15:29 +0000217ripng_redistribute_metric_set (int type, int metric)
218{
219 ripng->route_map[type].metric_config = 1;
220 ripng->route_map[type].metric = metric;
221}
222
Paul Jakma6ac29a52008-08-15 13:45:30 +0100223static int
paul718e3742002-12-13 20:15:29 +0000224ripng_redistribute_metric_unset (int type)
225{
226 ripng->route_map[type].metric_config = 0;
227 ripng->route_map[type].metric = 0;
hassoa94434b2003-05-25 17:10:12 +0000228 return 0;
paul718e3742002-12-13 20:15:29 +0000229}
230
Paul Jakma6ac29a52008-08-15 13:45:30 +0100231static void
hasso98b718a2004-10-11 12:57:57 +0000232ripng_redistribute_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000233{
234 if (ripng->route_map[type].name)
235 free (ripng->route_map[type].name);
236
237 ripng->route_map[type].name = strdup (name);
238 ripng->route_map[type].map = route_map_lookup_by_name (name);
239}
240
Paul Jakma6ac29a52008-08-15 13:45:30 +0100241static void
paul718e3742002-12-13 20:15:29 +0000242ripng_redistribute_routemap_unset (int type)
243{
244 if (ripng->route_map[type].name)
245 free (ripng->route_map[type].name);
246
247 ripng->route_map[type].name = NULL;
248 ripng->route_map[type].map = NULL;
249}
David Lamparter6b0655a2014-06-04 06:53:35 +0200250
hassoa94434b2003-05-25 17:10:12 +0000251/* Redistribution types */
252static struct {
253 int type;
254 int str_min_len;
hasso7a1d5832004-10-08 06:32:23 +0000255 const char *str;
hassoa94434b2003-05-25 17:10:12 +0000256} redist_type[] = {
257 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
258 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
259 {ZEBRA_ROUTE_STATIC, 1, "static"},
260 {ZEBRA_ROUTE_OSPF6, 1, "ospf6"},
Matthieu Boutier93079db2012-02-09 20:58:07 +0100261 {ZEBRA_ROUTE_BGP, 2, "bgp"},
262 {ZEBRA_ROUTE_BABEL, 2, "babel"},
hassoa94434b2003-05-25 17:10:12 +0000263 {0, 0, NULL}
264};
265
266void
267ripng_redistribute_clean ()
268{
269 int i;
270
271 for (i = 0; redist_type[i].str; i++)
272 {
273 if (zclient->redist[redist_type[i].type])
274 {
275 if (zclient->sock > 0)
276 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
ajs634f9ea2005-04-11 15:51:40 +0000277 zclient, redist_type[i].type);
hassoa94434b2003-05-25 17:10:12 +0000278
279 zclient->redist[redist_type[i].type] = 0;
280
281 /* Remove the routes from RIPng table. */
282 ripng_redistribute_withdraw (redist_type[i].type);
283 }
284 }
285}
286
paul718e3742002-12-13 20:15:29 +0000287DEFUN (router_zebra,
288 router_zebra_cmd,
289 "router zebra",
290 "Enable a routing process\n"
291 "Make connection to zebra daemon\n")
292{
293 vty->node = ZEBRA_NODE;
294 zclient->enable = 1;
295 zclient_start (zclient);
296 return CMD_SUCCESS;
297}
298
299DEFUN (no_router_zebra,
300 no_router_zebra_cmd,
301 "no router zebra",
302 NO_STR
303 "Disable a routing process\n"
304 "Stop connection to zebra daemon\n")
305{
306 zclient->enable = 0;
307 zclient_stop (zclient);
308 return CMD_SUCCESS;
309}
310
311DEFUN (ripng_redistribute_ripng,
312 ripng_redistribute_ripng_cmd,
313 "redistribute ripng",
314 "Redistribute information from another routing protocol\n"
315 "RIPng route\n")
316{
317 zclient->redist[ZEBRA_ROUTE_RIPNG] = 1;
318 return CMD_SUCCESS;
319}
320
321DEFUN (no_ripng_redistribute_ripng,
322 no_ripng_redistribute_ripng_cmd,
323 "no redistribute ripng",
324 NO_STR
325 "Redistribute information from another routing protocol\n"
326 "RIPng route\n")
327{
328 zclient->redist[ZEBRA_ROUTE_RIPNG] = 0;
329 return CMD_SUCCESS;
330}
331
hassoa94434b2003-05-25 17:10:12 +0000332DEFUN (ripng_redistribute_type,
333 ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100334 "redistribute " QUAGGA_REDIST_STR_RIPNGD,
335 "Redistribute\n"
336 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000337{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100338 int type;
hassoa94434b2003-05-25 17:10:12 +0000339
Matthieu Boutier93079db2012-02-09 20:58:07 +0100340 type = proto_redistnum(AFI_IP6, argv[0]);
341
342 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000343 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100344 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
345 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000346 }
347
Matthieu Boutier93079db2012-02-09 20:58:07 +0100348 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
349 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000350}
351
hassoa94434b2003-05-25 17:10:12 +0000352DEFUN (no_ripng_redistribute_type,
353 no_ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100354 "no redistribute " QUAGGA_REDIST_STR_RIPNGD,
paul718e3742002-12-13 20:15:29 +0000355 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100356 "Redistribute\n"
357 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000358{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100359 int type;
hassoa94434b2003-05-25 17:10:12 +0000360
Matthieu Boutier93079db2012-02-09 20:58:07 +0100361 type = proto_redistnum(AFI_IP6, argv[0]);
362
363 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000364 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100365 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
366 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000367 }
368
Matthieu Boutier93079db2012-02-09 20:58:07 +0100369 ripng_redistribute_metric_unset (type);
370 ripng_redistribute_routemap_unset (type);
371 return ripng_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000372}
373
paul718e3742002-12-13 20:15:29 +0000374
hassoa94434b2003-05-25 17:10:12 +0000375DEFUN (ripng_redistribute_type_metric,
376 ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100377 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
378 "Redistribute\n"
379 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000380 "Metric\n"
381 "Metric value\n")
382{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100383 int type;
hassoa94434b2003-05-25 17:10:12 +0000384 int metric;
385
386 metric = atoi (argv[1]);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100387 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000388
Matthieu Boutier93079db2012-02-09 20:58:07 +0100389 if (type < 0)
390 {
391 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
392 return CMD_WARNING;
393 }
hassoa94434b2003-05-25 17:10:12 +0000394
Matthieu Boutier93079db2012-02-09 20:58:07 +0100395 ripng_redistribute_metric_set (type, metric);
396 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
397 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000398}
399
hassoa94434b2003-05-25 17:10:12 +0000400ALIAS (no_ripng_redistribute_type,
401 no_ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100402 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000403 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100404 "Redistribute\n"
405 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000406 "Metric\n"
407 "Metric value\n")
408
hassoa94434b2003-05-25 17:10:12 +0000409DEFUN (ripng_redistribute_type_routemap,
410 ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100411 "redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
412 "Redistribute\n"
413 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000414 "Route map reference\n"
415 "Pointer to route-map entries\n")
416{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100417 int type;
hassoa94434b2003-05-25 17:10:12 +0000418
Matthieu Boutier93079db2012-02-09 20:58:07 +0100419 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000420
Matthieu Boutier93079db2012-02-09 20:58:07 +0100421 if (type < 0)
422 {
423 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
424 return CMD_WARNING;
425 }
hassoa94434b2003-05-25 17:10:12 +0000426
Matthieu Boutier93079db2012-02-09 20:58:07 +0100427 ripng_redistribute_routemap_set (type, argv[1]);
428 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
429 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000430}
431
hassoa94434b2003-05-25 17:10:12 +0000432ALIAS (no_ripng_redistribute_type,
433 no_ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100434 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000435 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100436 "Redistribute\n"
437 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000438 "Route map reference\n"
439 "Pointer to route-map entries\n")
440
hassoa94434b2003-05-25 17:10:12 +0000441DEFUN (ripng_redistribute_type_metric_routemap,
442 ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100443 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
444 "Redistribute\n"
445 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000446 "Metric\n"
447 "Metric value\n"
448 "Route map reference\n"
449 "Pointer to route-map entries\n")
450{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100451 int type;
hassoa94434b2003-05-25 17:10:12 +0000452 int metric;
453
Matthieu Boutier93079db2012-02-09 20:58:07 +0100454 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000455 metric = atoi (argv[1]);
456
Matthieu Boutier93079db2012-02-09 20:58:07 +0100457 if (type < 0)
458 {
459 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
460 return CMD_WARNING;
461 }
hassoa94434b2003-05-25 17:10:12 +0000462
Matthieu Boutier93079db2012-02-09 20:58:07 +0100463 ripng_redistribute_metric_set (type, metric);
464 ripng_redistribute_routemap_set (type, argv[2]);
465 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
466 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000467}
468
hassoa94434b2003-05-25 17:10:12 +0000469ALIAS (no_ripng_redistribute_type,
470 no_ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100471 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000472 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100473 "Redistribute\n"
474 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000475 "Route map reference\n"
476 "Pointer to route-map entries\n")
477
478void
hassoa94434b2003-05-25 17:10:12 +0000479ripng_redistribute_write (struct vty *vty, int config_mode)
paul718e3742002-12-13 20:15:29 +0000480{
481 int i;
paul718e3742002-12-13 20:15:29 +0000482
483 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
484 if (i != zclient->redist_default && zclient->redist[i])
485 {
hassoa94434b2003-05-25 17:10:12 +0000486 if (config_mode)
487 {
488 if (ripng->route_map[i].metric_config)
489 {
490 if (ripng->route_map[i].name)
491 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000492 zebra_route_string(i), ripng->route_map[i].metric,
hassoa94434b2003-05-25 17:10:12 +0000493 ripng->route_map[i].name, VTY_NEWLINE);
494 else
495 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000496 zebra_route_string(i), ripng->route_map[i].metric,
497 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000498 }
499 else
500 {
501 if (ripng->route_map[i].name)
502 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000503 zebra_route_string(i), ripng->route_map[i].name,
504 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000505 else
ajsf52d13c2005-10-01 17:38:06 +0000506 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
507 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000508 }
509 }
510 else
ajsf52d13c2005-10-01 17:38:06 +0000511 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000512 }
513}
514
515/* RIPng configuration write function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100516static int
paul718e3742002-12-13 20:15:29 +0000517zebra_config_write (struct vty *vty)
518{
519 if (! zclient->enable)
520 {
521 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
522 return 1;
523 }
524 else if (! zclient->redist[ZEBRA_ROUTE_RIPNG])
525 {
526 vty_out (vty, "router zebra%s", VTY_NEWLINE);
527 vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE);
528 return 1;
529 }
530 return 0;
531}
532
533/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800534static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000535{
536 ZEBRA_NODE,
537 "%s(config-router)# ",
538};
539
540/* Initialize zebra structure and it's commands. */
541void
542zebra_init ()
543{
544 /* Allocate zebra structure. */
545 zclient = zclient_new ();
546 zclient_init (zclient, ZEBRA_ROUTE_RIPNG);
547
548 zclient->interface_up = ripng_interface_up;
549 zclient->interface_down = ripng_interface_down;
550 zclient->interface_add = ripng_interface_add;
551 zclient->interface_delete = ripng_interface_delete;
552 zclient->interface_address_add = ripng_interface_address_add;
553 zclient->interface_address_delete = ripng_interface_address_delete;
554 zclient->ipv6_route_add = ripng_zebra_read_ipv6;
555 zclient->ipv6_route_delete = ripng_zebra_read_ipv6;
556
557 /* Install zebra node. */
558 install_node (&zebra_node, zebra_config_write);
559
560 /* Install command element for zebra node. */
561 install_element (CONFIG_NODE, &router_zebra_cmd);
562 install_element (CONFIG_NODE, &no_router_zebra_cmd);
563 install_default (ZEBRA_NODE);
564 install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd);
565 install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd);
hassoa94434b2003-05-25 17:10:12 +0000566
567 /* Install command elements to ripng node */
568 install_element (RIPNG_NODE, &ripng_redistribute_type_cmd);
569 install_element (RIPNG_NODE, &ripng_redistribute_type_routemap_cmd);
570 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_cmd);
571 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_routemap_cmd);
572 install_element (RIPNG_NODE, &no_ripng_redistribute_type_cmd);
573 install_element (RIPNG_NODE, &no_ripng_redistribute_type_routemap_cmd);
574 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_cmd);
575 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000576}