blob: 72216164a11f1bdf8826cfa7c1a26b8dfebe6fec [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
94 zapi_ipv6_route (cmd, zclient,
95 (struct prefix_ipv6 *)&rp->p, &api);
96
97 if (IS_RIPNG_DEBUG_ZEBRA)
Feng Lu72855b12015-05-22 11:39:54 +020098 {
99 if (ripng->ecmp)
100 zlog_debug ("%s: %s/%d nexthops %d",
101 (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
102 "Install into zebra" : "Delete from zebra",
103 inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen, count);
104 else
105 zlog_debug ("%s: %s/%d",
106 (cmd == ZEBRA_IPV6_ROUTE_ADD) ? \
107 "Install into zebra" : "Delete from zebra",
108 inet6_ntoa (rp->p.u.prefix6), rp->p.prefixlen);
109 }
paul718e3742002-12-13 20:15:29 +0000110 }
111}
112
Feng Lue97c31a2015-05-22 11:39:53 +0200113/* Add/update ECMP routes to zebra. */
paul718e3742002-12-13 20:15:29 +0000114void
Feng Lue97c31a2015-05-22 11:39:53 +0200115ripng_zebra_ipv6_add (struct route_node *rp)
paul718e3742002-12-13 20:15:29 +0000116{
Feng Lue97c31a2015-05-22 11:39:53 +0200117 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_ADD);
118}
paul718e3742002-12-13 20:15:29 +0000119
Feng Lue97c31a2015-05-22 11:39:53 +0200120/* Delete ECMP routes from zebra. */
121void
122ripng_zebra_ipv6_delete (struct route_node *rp)
123{
124 ripng_zebra_ipv6_send (rp, ZEBRA_IPV6_ROUTE_DELETE);
paul718e3742002-12-13 20:15:29 +0000125}
126
127/* Zebra route add and delete treatment. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100128static int
paul718e3742002-12-13 20:15:29 +0000129ripng_zebra_read_ipv6 (int command, struct zclient *zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800130 zebra_size_t length, vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000131{
132 struct stream *s;
133 struct zapi_ipv6 api;
134 unsigned long ifindex;
135 struct in6_addr nexthop;
136 struct prefix_ipv6 p;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500137 unsigned char plength = 0;
paul718e3742002-12-13 20:15:29 +0000138
139 s = zclient->ibuf;
140 ifindex = 0;
141 memset (&nexthop, 0, sizeof (struct in6_addr));
142
143 /* Type, flags, message. */
144 api.type = stream_getc (s);
145 api.flags = stream_getc (s);
146 api.message = stream_getc (s);
147
148 /* IPv6 prefix. */
149 memset (&p, 0, sizeof (struct prefix_ipv6));
150 p.family = AF_INET6;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500151 plength = stream_getc (s);
152 p.prefixlen = MIN(IPV6_MAX_PREFIXLEN, plength);
paul718e3742002-12-13 20:15:29 +0000153 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
154
155 /* Nexthop, ifindex, distance, metric. */
156 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
157 {
158 api.nexthop_num = stream_getc (s);
159 stream_get (&nexthop, s, 16);
160 }
161 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
162 {
163 api.ifindex_num = stream_getc (s);
164 ifindex = stream_getl (s);
165 }
166 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
167 api.distance = stream_getc (s);
168 else
169 api.distance = 0;
170 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
171 api.metric = stream_getl (s);
172 else
173 api.metric = 0;
174
175 if (command == ZEBRA_IPV6_ROUTE_ADD)
hassoa94434b2003-05-25 17:10:12 +0000176 ripng_redistribute_add (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex, &nexthop);
paul718e3742002-12-13 20:15:29 +0000177 else
hassoa94434b2003-05-25 17:10:12 +0000178 ripng_redistribute_delete (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex);
paul718e3742002-12-13 20:15:29 +0000179
180 return 0;
181}
182
hassoa94434b2003-05-25 17:10:12 +0000183void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100184ripng_zclient_reset (void)
hassoa94434b2003-05-25 17:10:12 +0000185{
186 zclient_reset (zclient);
187}
188
Paul Jakma6ac29a52008-08-15 13:45:30 +0100189static int
paul718e3742002-12-13 20:15:29 +0000190ripng_redistribute_unset (int type)
191{
Feng Luc99f3482014-10-16 09:52:36 +0800192 if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000193 return CMD_SUCCESS;
194
Feng Luc99f3482014-10-16 09:52:36 +0800195 vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000196
197 if (zclient->sock > 0)
Feng Luc99f3482014-10-16 09:52:36 +0800198 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type,
199 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000200
201 ripng_redistribute_withdraw (type);
202
203 return CMD_SUCCESS;
204}
205
hassoa94434b2003-05-25 17:10:12 +0000206int
207ripng_redistribute_check (int type)
208{
Feng Luc99f3482014-10-16 09:52:36 +0800209 return vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000210}
211
Paul Jakma6ac29a52008-08-15 13:45:30 +0100212static void
paul718e3742002-12-13 20:15:29 +0000213ripng_redistribute_metric_set (int type, int metric)
214{
215 ripng->route_map[type].metric_config = 1;
216 ripng->route_map[type].metric = metric;
217}
218
Paul Jakma6ac29a52008-08-15 13:45:30 +0100219static int
paul718e3742002-12-13 20:15:29 +0000220ripng_redistribute_metric_unset (int type)
221{
222 ripng->route_map[type].metric_config = 0;
223 ripng->route_map[type].metric = 0;
hassoa94434b2003-05-25 17:10:12 +0000224 return 0;
paul718e3742002-12-13 20:15:29 +0000225}
226
Paul Jakma6ac29a52008-08-15 13:45:30 +0100227static void
hasso98b718a2004-10-11 12:57:57 +0000228ripng_redistribute_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000229{
230 if (ripng->route_map[type].name)
231 free (ripng->route_map[type].name);
232
233 ripng->route_map[type].name = strdup (name);
234 ripng->route_map[type].map = route_map_lookup_by_name (name);
235}
236
Paul Jakma6ac29a52008-08-15 13:45:30 +0100237static void
paul718e3742002-12-13 20:15:29 +0000238ripng_redistribute_routemap_unset (int type)
239{
240 if (ripng->route_map[type].name)
241 free (ripng->route_map[type].name);
242
243 ripng->route_map[type].name = NULL;
244 ripng->route_map[type].map = NULL;
245}
David Lamparter6b0655a2014-06-04 06:53:35 +0200246
hassoa94434b2003-05-25 17:10:12 +0000247/* Redistribution types */
248static struct {
249 int type;
250 int str_min_len;
hasso7a1d5832004-10-08 06:32:23 +0000251 const char *str;
hassoa94434b2003-05-25 17:10:12 +0000252} redist_type[] = {
253 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
254 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
255 {ZEBRA_ROUTE_STATIC, 1, "static"},
256 {ZEBRA_ROUTE_OSPF6, 1, "ospf6"},
Matthieu Boutier93079db2012-02-09 20:58:07 +0100257 {ZEBRA_ROUTE_BGP, 2, "bgp"},
258 {ZEBRA_ROUTE_BABEL, 2, "babel"},
hassoa94434b2003-05-25 17:10:12 +0000259 {0, 0, NULL}
260};
261
262void
263ripng_redistribute_clean ()
264{
265 int i;
266
267 for (i = 0; redist_type[i].str; i++)
268 {
Feng Luc99f3482014-10-16 09:52:36 +0800269 if (vrf_bitmap_check (zclient->redist[redist_type[i].type], VRF_DEFAULT))
hassoa94434b2003-05-25 17:10:12 +0000270 {
271 if (zclient->sock > 0)
272 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
Feng Luc99f3482014-10-16 09:52:36 +0800273 zclient, redist_type[i].type,
274 VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000275
Feng Luc99f3482014-10-16 09:52:36 +0800276 vrf_bitmap_unset (zclient->redist[redist_type[i].type], VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000277
278 /* Remove the routes from RIPng table. */
279 ripng_redistribute_withdraw (redist_type[i].type);
280 }
281 }
282}
283
paul718e3742002-12-13 20:15:29 +0000284DEFUN (router_zebra,
285 router_zebra_cmd,
286 "router zebra",
287 "Enable a routing process\n"
288 "Make connection to zebra daemon\n")
289{
290 vty->node = ZEBRA_NODE;
291 zclient->enable = 1;
292 zclient_start (zclient);
293 return CMD_SUCCESS;
294}
295
296DEFUN (no_router_zebra,
297 no_router_zebra_cmd,
298 "no router zebra",
299 NO_STR
300 "Disable a routing process\n"
301 "Stop connection to zebra daemon\n")
302{
303 zclient->enable = 0;
304 zclient_stop (zclient);
305 return CMD_SUCCESS;
306}
307
308DEFUN (ripng_redistribute_ripng,
309 ripng_redistribute_ripng_cmd,
310 "redistribute ripng",
311 "Redistribute information from another routing protocol\n"
312 "RIPng route\n")
313{
Feng Luc99f3482014-10-16 09:52:36 +0800314 vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000315 return CMD_SUCCESS;
316}
317
318DEFUN (no_ripng_redistribute_ripng,
319 no_ripng_redistribute_ripng_cmd,
320 "no redistribute ripng",
321 NO_STR
322 "Redistribute information from another routing protocol\n"
323 "RIPng route\n")
324{
Feng Luc99f3482014-10-16 09:52:36 +0800325 vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000326 return CMD_SUCCESS;
327}
328
hassoa94434b2003-05-25 17:10:12 +0000329DEFUN (ripng_redistribute_type,
330 ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100331 "redistribute " QUAGGA_REDIST_STR_RIPNGD,
332 "Redistribute\n"
333 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000334{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100335 int type;
hassoa94434b2003-05-25 17:10:12 +0000336
Matthieu Boutier93079db2012-02-09 20:58:07 +0100337 type = proto_redistnum(AFI_IP6, argv[0]);
338
339 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000340 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100341 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
342 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000343 }
344
Feng Luc99f3482014-10-16 09:52:36 +0800345 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100346 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000347}
348
hassoa94434b2003-05-25 17:10:12 +0000349DEFUN (no_ripng_redistribute_type,
350 no_ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100351 "no redistribute " QUAGGA_REDIST_STR_RIPNGD,
paul718e3742002-12-13 20:15:29 +0000352 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100353 "Redistribute\n"
354 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000355{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100356 int type;
hassoa94434b2003-05-25 17:10:12 +0000357
Matthieu Boutier93079db2012-02-09 20:58:07 +0100358 type = proto_redistnum(AFI_IP6, argv[0]);
359
360 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000361 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100362 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
363 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000364 }
365
Matthieu Boutier93079db2012-02-09 20:58:07 +0100366 ripng_redistribute_metric_unset (type);
367 ripng_redistribute_routemap_unset (type);
368 return ripng_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000369}
370
paul718e3742002-12-13 20:15:29 +0000371
hassoa94434b2003-05-25 17:10:12 +0000372DEFUN (ripng_redistribute_type_metric,
373 ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100374 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
375 "Redistribute\n"
376 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000377 "Metric\n"
378 "Metric value\n")
379{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100380 int type;
hassoa94434b2003-05-25 17:10:12 +0000381 int metric;
382
383 metric = atoi (argv[1]);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100384 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000385
Matthieu Boutier93079db2012-02-09 20:58:07 +0100386 if (type < 0)
387 {
388 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
389 return CMD_WARNING;
390 }
hassoa94434b2003-05-25 17:10:12 +0000391
Matthieu Boutier93079db2012-02-09 20:58:07 +0100392 ripng_redistribute_metric_set (type, metric);
Feng Luc99f3482014-10-16 09:52:36 +0800393 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100394 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000395}
396
hassoa94434b2003-05-25 17:10:12 +0000397ALIAS (no_ripng_redistribute_type,
398 no_ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100399 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000400 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100401 "Redistribute\n"
402 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000403 "Metric\n"
404 "Metric value\n")
405
hassoa94434b2003-05-25 17:10:12 +0000406DEFUN (ripng_redistribute_type_routemap,
407 ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100408 "redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
409 "Redistribute\n"
410 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000411 "Route map reference\n"
412 "Pointer to route-map entries\n")
413{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100414 int type;
hassoa94434b2003-05-25 17:10:12 +0000415
Matthieu Boutier93079db2012-02-09 20:58:07 +0100416 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000417
Matthieu Boutier93079db2012-02-09 20:58:07 +0100418 if (type < 0)
419 {
420 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
421 return CMD_WARNING;
422 }
hassoa94434b2003-05-25 17:10:12 +0000423
Matthieu Boutier93079db2012-02-09 20:58:07 +0100424 ripng_redistribute_routemap_set (type, argv[1]);
Feng Luc99f3482014-10-16 09:52:36 +0800425 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100426 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000427}
428
hassoa94434b2003-05-25 17:10:12 +0000429ALIAS (no_ripng_redistribute_type,
430 no_ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100431 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000432 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100433 "Redistribute\n"
434 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000435 "Route map reference\n"
436 "Pointer to route-map entries\n")
437
hassoa94434b2003-05-25 17:10:12 +0000438DEFUN (ripng_redistribute_type_metric_routemap,
439 ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100440 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
441 "Redistribute\n"
442 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000443 "Metric\n"
444 "Metric value\n"
445 "Route map reference\n"
446 "Pointer to route-map entries\n")
447{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100448 int type;
hassoa94434b2003-05-25 17:10:12 +0000449 int metric;
450
Matthieu Boutier93079db2012-02-09 20:58:07 +0100451 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000452 metric = atoi (argv[1]);
453
Matthieu Boutier93079db2012-02-09 20:58:07 +0100454 if (type < 0)
455 {
456 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
457 return CMD_WARNING;
458 }
hassoa94434b2003-05-25 17:10:12 +0000459
Matthieu Boutier93079db2012-02-09 20:58:07 +0100460 ripng_redistribute_metric_set (type, metric);
461 ripng_redistribute_routemap_set (type, argv[2]);
Feng Luc99f3482014-10-16 09:52:36 +0800462 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100463 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000464}
465
hassoa94434b2003-05-25 17:10:12 +0000466ALIAS (no_ripng_redistribute_type,
467 no_ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100468 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000469 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100470 "Redistribute\n"
471 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000472 "Route map reference\n"
473 "Pointer to route-map entries\n")
474
475void
hassoa94434b2003-05-25 17:10:12 +0000476ripng_redistribute_write (struct vty *vty, int config_mode)
paul718e3742002-12-13 20:15:29 +0000477{
478 int i;
paul718e3742002-12-13 20:15:29 +0000479
480 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
Feng Luc99f3482014-10-16 09:52:36 +0800481 if (i != zclient->redist_default &&
482 vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000483 {
hassoa94434b2003-05-25 17:10:12 +0000484 if (config_mode)
485 {
486 if (ripng->route_map[i].metric_config)
487 {
488 if (ripng->route_map[i].name)
489 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000490 zebra_route_string(i), ripng->route_map[i].metric,
hassoa94434b2003-05-25 17:10:12 +0000491 ripng->route_map[i].name, VTY_NEWLINE);
492 else
493 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000494 zebra_route_string(i), ripng->route_map[i].metric,
495 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000496 }
497 else
498 {
499 if (ripng->route_map[i].name)
500 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000501 zebra_route_string(i), ripng->route_map[i].name,
502 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000503 else
ajsf52d13c2005-10-01 17:38:06 +0000504 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
505 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000506 }
507 }
508 else
ajsf52d13c2005-10-01 17:38:06 +0000509 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000510 }
511}
512
513/* RIPng configuration write function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100514static int
paul718e3742002-12-13 20:15:29 +0000515zebra_config_write (struct vty *vty)
516{
517 if (! zclient->enable)
518 {
519 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
520 return 1;
521 }
Feng Luc99f3482014-10-16 09:52:36 +0800522 else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000523 {
524 vty_out (vty, "router zebra%s", VTY_NEWLINE);
525 vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE);
526 return 1;
527 }
528 return 0;
529}
530
531/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800532static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000533{
534 ZEBRA_NODE,
535 "%s(config-router)# ",
536};
537
Feng Luc99f3482014-10-16 09:52:36 +0800538static void
539ripng_zebra_connected (struct zclient *zclient)
540{
541 zclient_send_requests (zclient, VRF_DEFAULT);
542}
543
paul718e3742002-12-13 20:15:29 +0000544/* Initialize zebra structure and it's commands. */
545void
Donald Sharp71252932015-09-24 09:25:19 -0400546zebra_init (struct thread_master *master)
paul718e3742002-12-13 20:15:29 +0000547{
548 /* Allocate zebra structure. */
Donald Sharp71252932015-09-24 09:25:19 -0400549 zclient = zclient_new (master);
paul718e3742002-12-13 20:15:29 +0000550 zclient_init (zclient, ZEBRA_ROUTE_RIPNG);
551
Feng Luc99f3482014-10-16 09:52:36 +0800552 zclient->zebra_connected = ripng_zebra_connected;
paul718e3742002-12-13 20:15:29 +0000553 zclient->interface_up = ripng_interface_up;
554 zclient->interface_down = ripng_interface_down;
555 zclient->interface_add = ripng_interface_add;
556 zclient->interface_delete = ripng_interface_delete;
557 zclient->interface_address_add = ripng_interface_address_add;
558 zclient->interface_address_delete = ripng_interface_address_delete;
559 zclient->ipv6_route_add = ripng_zebra_read_ipv6;
560 zclient->ipv6_route_delete = ripng_zebra_read_ipv6;
561
562 /* Install zebra node. */
563 install_node (&zebra_node, zebra_config_write);
564
565 /* Install command element for zebra node. */
566 install_element (CONFIG_NODE, &router_zebra_cmd);
567 install_element (CONFIG_NODE, &no_router_zebra_cmd);
568 install_default (ZEBRA_NODE);
569 install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd);
570 install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd);
hassoa94434b2003-05-25 17:10:12 +0000571
572 /* Install command elements to ripng node */
573 install_element (RIPNG_NODE, &ripng_redistribute_type_cmd);
574 install_element (RIPNG_NODE, &ripng_redistribute_type_routemap_cmd);
575 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_cmd);
576 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_routemap_cmd);
577 install_element (RIPNG_NODE, &no_ripng_redistribute_type_cmd);
578 install_element (RIPNG_NODE, &no_ripng_redistribute_type_routemap_cmd);
579 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_cmd);
580 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000581}