blob: a35bc990f57020145c1c0a294a9a23986b8616ef [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
Feng Lue97c31a2015-05-22 11:39:53 +020040/* Send ECMP routes to zebra. */
41static void
42ripng_zebra_ipv6_send (struct route_node *rp, u_char cmd)
paul718e3742002-12-13 20:15:29 +000043{
Feng Lue97c31a2015-05-22 11:39:53 +020044 static struct in6_addr **nexthops = NULL;
Paul Jakma9099f9b2016-01-18 10:12:10 +000045 static ifindex_t *ifindexes = NULL;
Feng Lue97c31a2015-05-22 11:39:53 +020046 static unsigned int nexthops_len = 0;
47
48 struct list *list = (struct list *)rp->info;
paul718e3742002-12-13 20:15:29 +000049 struct zapi_ipv6 api;
Feng Lue97c31a2015-05-22 11:39:53 +020050 struct listnode *listnode = NULL;
51 struct ripng_info *rinfo = NULL;
52 int count = 0;
paul718e3742002-12-13 20:15:29 +000053
Feng Luc99f3482014-10-16 09:52:36 +080054 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +000055 {
Feng Luc99f3482014-10-16 09:52:36 +080056 api.vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +000057 api.type = ZEBRA_ROUTE_RIPNG;
58 api.flags = 0;
59 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +040060 api.safi = SAFI_UNICAST;
Feng Lue97c31a2015-05-22 11:39:53 +020061
62 if (nexthops_len < listcount (list))
63 {
64 nexthops_len = listcount (list);
65 nexthops = XREALLOC (MTYPE_TMP, nexthops,
66 nexthops_len * sizeof (struct in6_addr *));
67 ifindexes = XREALLOC (MTYPE_TMP, ifindexes,
68 nexthops_len * sizeof (unsigned int));
69 }
70
paul718e3742002-12-13 20:15:29 +000071 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
paul718e3742002-12-13 20:15:29 +000072 SET_FLAG (api.message, ZAPI_MESSAGE_IFINDEX);
Feng Lue97c31a2015-05-22 11:39:53 +020073 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
74 {
75 nexthops[count] = &rinfo->nexthop;
76 ifindexes[count] = rinfo->ifindex;
77 count++;
78 if (cmd == ZEBRA_IPV6_ROUTE_ADD)
79 SET_FLAG (rinfo->flags, RIPNG_RTF_FIB);
80 else
81 UNSET_FLAG (rinfo->flags, RIPNG_RTF_FIB);
82 }
83
84 api.nexthop = nexthops;
85 api.nexthop_num = count;
86 api.ifindex = ifindexes;
87 api.ifindex_num = count;
88
89 rinfo = listgetdata (listhead (list));
90
hassodeba3552005-08-27 06:19:39 +000091 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
Feng Lue97c31a2015-05-22 11:39:53 +020092 api.metric = rinfo->metric;
93
Christian Franke5bb328e2016-10-01 22:35:32 +020094 if (rinfo->tag)
95 {
96 SET_FLAG (api.message, ZAPI_MESSAGE_TAG);
97 api.tag = rinfo->tag;
98 }
99
Feng Lue97c31a2015-05-22 11:39:53 +0200100 zapi_ipv6_route (cmd, zclient,
101 (struct prefix_ipv6 *)&rp->p, &api);
102
103 if (IS_RIPNG_DEBUG_ZEBRA)
Feng Lu72855b12015-05-22 11:39:54 +0200104 {
105 if (ripng->ecmp)
106 zlog_debug ("%s: %s/%d nexthops %d",
107 (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
108 "Install into zebra" : "Delete from zebra",
109 inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen, count);
110 else
111 zlog_debug ("%s: %s/%d",
112 (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
113 "Install into zebra" : "Delete from zebra",
114 inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen);
115 }
paul718e3742002-12-13 20:15:29 +0000116 }
117}
118
Feng Lue97c31a2015-05-22 11:39:53 +0200119/* Add/update ECMP routes to zebra. */
paul718e3742002-12-13 20:15:29 +0000120void
Feng Lue97c31a2015-05-22 11:39:53 +0200121ripng_zebra_ipv6_add (struct route_node *rp)
paul718e3742002-12-13 20:15:29 +0000122{
Feng Lue97c31a2015-05-22 11:39:53 +0200123 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_ADD);
124}
paul718e3742002-12-13 20:15:29 +0000125
Feng Lue97c31a2015-05-22 11:39:53 +0200126/* Delete ECMP routes from zebra. */
127void
128ripng_zebra_ipv6_delete (struct route_node *rp)
129{
130 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_DELETE);
paul718e3742002-12-13 20:15:29 +0000131}
132
133/* Zebra route add and delete treatment. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100134static int
paul718e3742002-12-13 20:15:29 +0000135ripng_zebra_read_ipv6 (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800136 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000137{
138 struct stream *s;
139 struct zapi_ipv6 api;
140 unsigned long ifindex;
141 struct in6_addr nexthop;
142 struct prefix_ipv6 p;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500143 unsigned char plength = 0;
paul718e3742002-12-13 20:15:29 +0000144
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;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500157 plength = stream_getc (s);
158 p.prefixlen = MIN(IPV6_MAX_PREFIXLEN, plength);
paul718e3742002-12-13 20:15:29 +0000159 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
160
161 /* Nexthop, ifindex, distance, metric. */
162 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
163 {
164 api.nexthop_num = stream_getc (s);
165 stream_get (&nexthop, s, 16);
166 }
167 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
168 {
169 api.ifindex_num = stream_getc (s);
170 ifindex = stream_getl (s);
171 }
172 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
173 api.distance = stream_getc (s);
174 else
175 api.distance = 0;
176 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
177 api.metric = stream_getl (s);
178 else
179 api.metric = 0;
180
Christian Franke5bb328e2016-10-01 22:35:32 +0200181 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
182 api.tag = stream_getl (s);
183 else
184 api.tag = 0;
185
paul718e3742002-12-13 20:15:29 +0000186 if (command == ZEBRA_IPV6_ROUTE_ADD)
Christian Franke5bb328e2016-10-01 22:35:32 +0200187 ripng_redistribute_add (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p,
188 ifindex, &nexthop, api.tag);
paul718e3742002-12-13 20:15:29 +0000189 else
hassoa94434b2003-05-25 17:10:12 +0000190 ripng_redistribute_delete (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex);
paul718e3742002-12-13 20:15:29 +0000191
192 return 0;
193}
194
hassoa94434b2003-05-25 17:10:12 +0000195void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100196ripng_zclient_reset (void)
hassoa94434b2003-05-25 17:10:12 +0000197{
198 zclient_reset (zclient);
199}
200
Paul Jakma6ac29a52008-08-15 13:45:30 +0100201static int
paul718e3742002-12-13 20:15:29 +0000202ripng_redistribute_unset (int type)
203{
Feng Luc99f3482014-10-16 09:52:36 +0800204 if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000205 return CMD_SUCCESS;
206
Feng Luc99f3482014-10-16 09:52:36 +0800207 vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000208
209 if (zclient->sock > 0)
Feng Luc99f3482014-10-16 09:52:36 +0800210 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type,
211 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000212
213 ripng_redistribute_withdraw (type);
214
215 return CMD_SUCCESS;
216}
217
hassoa94434b2003-05-25 17:10:12 +0000218int
219ripng_redistribute_check (int type)
220{
Feng Luc99f3482014-10-16 09:52:36 +0800221 return vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000222}
223
Paul Jakma6ac29a52008-08-15 13:45:30 +0100224static void
paul718e3742002-12-13 20:15:29 +0000225ripng_redistribute_metric_set (int type, int metric)
226{
227 ripng->route_map[type].metric_config = 1;
228 ripng->route_map[type].metric = metric;
229}
230
Paul Jakma6ac29a52008-08-15 13:45:30 +0100231static int
paul718e3742002-12-13 20:15:29 +0000232ripng_redistribute_metric_unset (int type)
233{
234 ripng->route_map[type].metric_config = 0;
235 ripng->route_map[type].metric = 0;
hassoa94434b2003-05-25 17:10:12 +0000236 return 0;
paul718e3742002-12-13 20:15:29 +0000237}
238
Paul Jakma6ac29a52008-08-15 13:45:30 +0100239static void
hasso98b718a2004-10-11 12:57:57 +0000240ripng_redistribute_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000241{
242 if (ripng->route_map[type].name)
243 free (ripng->route_map[type].name);
244
245 ripng->route_map[type].name = strdup (name);
246 ripng->route_map[type].map = route_map_lookup_by_name (name);
247}
248
Paul Jakma6ac29a52008-08-15 13:45:30 +0100249static void
paul718e3742002-12-13 20:15:29 +0000250ripng_redistribute_routemap_unset (int type)
251{
252 if (ripng->route_map[type].name)
253 free (ripng->route_map[type].name);
254
255 ripng->route_map[type].name = NULL;
256 ripng->route_map[type].map = NULL;
257}
David Lamparter6b0655a2014-06-04 06:53:35 +0200258
hassoa94434b2003-05-25 17:10:12 +0000259/* Redistribution types */
260static struct {
261 int type;
262 int str_min_len;
hasso7a1d5832004-10-08 06:32:23 +0000263 const char *str;
hassoa94434b2003-05-25 17:10:12 +0000264} redist_type[] = {
265 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
266 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
267 {ZEBRA_ROUTE_STATIC, 1, "static"},
268 {ZEBRA_ROUTE_OSPF6, 1, "ospf6"},
Matthieu Boutier93079db2012-02-09 20:58:07 +0100269 {ZEBRA_ROUTE_BGP, 2, "bgp"},
270 {ZEBRA_ROUTE_BABEL, 2, "babel"},
hassoa94434b2003-05-25 17:10:12 +0000271 {0, 0, NULL}
272};
273
274void
275ripng_redistribute_clean ()
276{
277 int i;
278
279 for (i = 0; redist_type[i].str; i++)
280 {
Feng Luc99f3482014-10-16 09:52:36 +0800281 if (vrf_bitmap_check (zclient->redist[redist_type[i].type], VRF_DEFAULT))
hassoa94434b2003-05-25 17:10:12 +0000282 {
283 if (zclient->sock > 0)
284 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
Feng Luc99f3482014-10-16 09:52:36 +0800285 zclient, redist_type[i].type,
286 VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000287
Feng Luc99f3482014-10-16 09:52:36 +0800288 vrf_bitmap_unset (zclient->redist[redist_type[i].type], VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000289
290 /* Remove the routes from RIPng table. */
291 ripng_redistribute_withdraw (redist_type[i].type);
292 }
293 }
294}
295
paul718e3742002-12-13 20:15:29 +0000296DEFUN (router_zebra,
297 router_zebra_cmd,
298 "router zebra",
299 "Enable a routing process\n"
300 "Make connection to zebra daemon\n")
301{
302 vty->node = ZEBRA_NODE;
303 zclient->enable = 1;
304 zclient_start (zclient);
305 return CMD_SUCCESS;
306}
307
308DEFUN (no_router_zebra,
309 no_router_zebra_cmd,
310 "no router zebra",
311 NO_STR
312 "Disable a routing process\n"
313 "Stop connection to zebra daemon\n")
314{
315 zclient->enable = 0;
316 zclient_stop (zclient);
317 return CMD_SUCCESS;
318}
319
320DEFUN (ripng_redistribute_ripng,
321 ripng_redistribute_ripng_cmd,
322 "redistribute ripng",
323 "Redistribute information from another routing protocol\n"
324 "RIPng route\n")
325{
Feng Luc99f3482014-10-16 09:52:36 +0800326 vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000327 return CMD_SUCCESS;
328}
329
330DEFUN (no_ripng_redistribute_ripng,
331 no_ripng_redistribute_ripng_cmd,
332 "no redistribute ripng",
333 NO_STR
334 "Redistribute information from another routing protocol\n"
335 "RIPng route\n")
336{
Feng Luc99f3482014-10-16 09:52:36 +0800337 vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000338 return CMD_SUCCESS;
339}
340
hassoa94434b2003-05-25 17:10:12 +0000341DEFUN (ripng_redistribute_type,
342 ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100343 "redistribute " QUAGGA_REDIST_STR_RIPNGD,
344 "Redistribute\n"
345 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000346{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100347 int type;
hassoa94434b2003-05-25 17:10:12 +0000348
Matthieu Boutier93079db2012-02-09 20:58:07 +0100349 type = proto_redistnum(AFI_IP6, argv[0]);
350
351 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000352 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100353 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
354 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000355 }
356
Feng Luc99f3482014-10-16 09:52:36 +0800357 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100358 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000359}
360
hassoa94434b2003-05-25 17:10:12 +0000361DEFUN (no_ripng_redistribute_type,
362 no_ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100363 "no redistribute " QUAGGA_REDIST_STR_RIPNGD,
paul718e3742002-12-13 20:15:29 +0000364 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100365 "Redistribute\n"
366 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000367{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100368 int type;
hassoa94434b2003-05-25 17:10:12 +0000369
Matthieu Boutier93079db2012-02-09 20:58:07 +0100370 type = proto_redistnum(AFI_IP6, argv[0]);
371
372 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000373 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100374 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
375 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000376 }
377
Matthieu Boutier93079db2012-02-09 20:58:07 +0100378 ripng_redistribute_metric_unset (type);
379 ripng_redistribute_routemap_unset (type);
380 return ripng_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000381}
382
paul718e3742002-12-13 20:15:29 +0000383
hassoa94434b2003-05-25 17:10:12 +0000384DEFUN (ripng_redistribute_type_metric,
385 ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100386 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
387 "Redistribute\n"
388 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000389 "Metric\n"
390 "Metric value\n")
391{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100392 int type;
hassoa94434b2003-05-25 17:10:12 +0000393 int metric;
394
395 metric = atoi (argv[1]);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100396 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000397
Matthieu Boutier93079db2012-02-09 20:58:07 +0100398 if (type < 0)
399 {
400 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
401 return CMD_WARNING;
402 }
hassoa94434b2003-05-25 17:10:12 +0000403
Matthieu Boutier93079db2012-02-09 20:58:07 +0100404 ripng_redistribute_metric_set (type, metric);
Feng Luc99f3482014-10-16 09:52:36 +0800405 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100406 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000407}
408
hassoa94434b2003-05-25 17:10:12 +0000409ALIAS (no_ripng_redistribute_type,
410 no_ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100411 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000412 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100413 "Redistribute\n"
414 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000415 "Metric\n"
416 "Metric value\n")
417
hassoa94434b2003-05-25 17:10:12 +0000418DEFUN (ripng_redistribute_type_routemap,
419 ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100420 "redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
421 "Redistribute\n"
422 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000423 "Route map reference\n"
424 "Pointer to route-map entries\n")
425{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100426 int type;
hassoa94434b2003-05-25 17:10:12 +0000427
Matthieu Boutier93079db2012-02-09 20:58:07 +0100428 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000429
Matthieu Boutier93079db2012-02-09 20:58:07 +0100430 if (type < 0)
431 {
432 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
433 return CMD_WARNING;
434 }
hassoa94434b2003-05-25 17:10:12 +0000435
Matthieu Boutier93079db2012-02-09 20:58:07 +0100436 ripng_redistribute_routemap_set (type, argv[1]);
Feng Luc99f3482014-10-16 09:52:36 +0800437 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100438 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000439}
440
hassoa94434b2003-05-25 17:10:12 +0000441ALIAS (no_ripng_redistribute_type,
442 no_ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100443 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000444 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100445 "Redistribute\n"
446 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000447 "Route map reference\n"
448 "Pointer to route-map entries\n")
449
hassoa94434b2003-05-25 17:10:12 +0000450DEFUN (ripng_redistribute_type_metric_routemap,
451 ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100452 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
453 "Redistribute\n"
454 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000455 "Metric\n"
456 "Metric value\n"
457 "Route map reference\n"
458 "Pointer to route-map entries\n")
459{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100460 int type;
hassoa94434b2003-05-25 17:10:12 +0000461 int metric;
462
Matthieu Boutier93079db2012-02-09 20:58:07 +0100463 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000464 metric = atoi (argv[1]);
465
Matthieu Boutier93079db2012-02-09 20:58:07 +0100466 if (type < 0)
467 {
468 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
469 return CMD_WARNING;
470 }
hassoa94434b2003-05-25 17:10:12 +0000471
Matthieu Boutier93079db2012-02-09 20:58:07 +0100472 ripng_redistribute_metric_set (type, metric);
473 ripng_redistribute_routemap_set (type, argv[2]);
Feng Luc99f3482014-10-16 09:52:36 +0800474 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100475 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000476}
477
hassoa94434b2003-05-25 17:10:12 +0000478ALIAS (no_ripng_redistribute_type,
479 no_ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100480 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000481 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100482 "Redistribute\n"
483 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000484 "Route map reference\n"
485 "Pointer to route-map entries\n")
486
487void
hassoa94434b2003-05-25 17:10:12 +0000488ripng_redistribute_write (struct vty *vty, int config_mode)
paul718e3742002-12-13 20:15:29 +0000489{
490 int i;
paul718e3742002-12-13 20:15:29 +0000491
492 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
Feng Luc99f3482014-10-16 09:52:36 +0800493 if (i != zclient->redist_default &&
494 vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000495 {
hassoa94434b2003-05-25 17:10:12 +0000496 if (config_mode)
497 {
498 if (ripng->route_map[i].metric_config)
499 {
500 if (ripng->route_map[i].name)
501 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000502 zebra_route_string(i), ripng->route_map[i].metric,
hassoa94434b2003-05-25 17:10:12 +0000503 ripng->route_map[i].name, VTY_NEWLINE);
504 else
505 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000506 zebra_route_string(i), ripng->route_map[i].metric,
507 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000508 }
509 else
510 {
511 if (ripng->route_map[i].name)
512 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000513 zebra_route_string(i), ripng->route_map[i].name,
514 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000515 else
ajsf52d13c2005-10-01 17:38:06 +0000516 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
517 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000518 }
519 }
520 else
ajsf52d13c2005-10-01 17:38:06 +0000521 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000522 }
523}
524
525/* RIPng configuration write function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100526static int
paul718e3742002-12-13 20:15:29 +0000527zebra_config_write (struct vty *vty)
528{
529 if (! zclient->enable)
530 {
531 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
532 return 1;
533 }
Feng Luc99f3482014-10-16 09:52:36 +0800534 else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000535 {
536 vty_out (vty, "router zebra%s", VTY_NEWLINE);
537 vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE);
538 return 1;
539 }
540 return 0;
541}
542
543/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800544static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000545{
546 ZEBRA_NODE,
547 "%s(config-router)# ",
548};
549
Feng Luc99f3482014-10-16 09:52:36 +0800550static void
551ripng_zebra_connected (struct zclient *zclient)
552{
553 zclient_send_requests (zclient, VRF_DEFAULT);
554}
555
paul718e3742002-12-13 20:15:29 +0000556/* Initialize zebra structure and it's commands. */
557void
Donald Sharp71252932015-09-24 09:25:19 -0400558zebra_init (struct thread_master *master)
paul718e3742002-12-13 20:15:29 +0000559{
560 /* Allocate zebra structure. */
Donald Sharp71252932015-09-24 09:25:19 -0400561 zclient = zclient_new (master);
paul718e3742002-12-13 20:15:29 +0000562 zclient_init (zclient, ZEBRA_ROUTE_RIPNG);
563
Feng Luc99f3482014-10-16 09:52:36 +0800564 zclient->zebra_connected = ripng_zebra_connected;
paul718e3742002-12-13 20:15:29 +0000565 zclient->interface_up = ripng_interface_up;
566 zclient->interface_down = ripng_interface_down;
567 zclient->interface_add = ripng_interface_add;
568 zclient->interface_delete = ripng_interface_delete;
569 zclient->interface_address_add = ripng_interface_address_add;
570 zclient->interface_address_delete = ripng_interface_address_delete;
571 zclient->ipv6_route_add = ripng_zebra_read_ipv6;
572 zclient->ipv6_route_delete = ripng_zebra_read_ipv6;
573
574 /* Install zebra node. */
575 install_node (&zebra_node, zebra_config_write);
576
577 /* Install command element for zebra node. */
578 install_element (CONFIG_NODE, &router_zebra_cmd);
579 install_element (CONFIG_NODE, &no_router_zebra_cmd);
580 install_default (ZEBRA_NODE);
581 install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd);
582 install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd);
hassoa94434b2003-05-25 17:10:12 +0000583
584 /* Install command elements to ripng node */
585 install_element (RIPNG_NODE, &ripng_redistribute_type_cmd);
586 install_element (RIPNG_NODE, &ripng_redistribute_type_routemap_cmd);
587 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_cmd);
588 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_routemap_cmd);
589 install_element (RIPNG_NODE, &no_ripng_redistribute_type_cmd);
590 install_element (RIPNG_NODE, &no_ripng_redistribute_type_routemap_cmd);
591 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_cmd);
592 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000593}