blob: 58f88606c5108d7565ee009912ef06ff6833301b [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;
45 static unsigned int *ifindexes = NULL;
46 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;
137
138 s = zclient->ibuf;
139 ifindex = 0;
140 memset (&nexthop, 0, sizeof (struct in6_addr));
141
142 /* Type, flags, message. */
143 api.type = stream_getc (s);
144 api.flags = stream_getc (s);
145 api.message = stream_getc (s);
146
147 /* IPv6 prefix. */
148 memset (&p, 0, sizeof (struct prefix_ipv6));
149 p.family = AF_INET6;
150 p.prefixlen = stream_getc (s);
151 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
152
153 /* Nexthop, ifindex, distance, metric. */
154 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
155 {
156 api.nexthop_num = stream_getc (s);
157 stream_get (&nexthop, s, 16);
158 }
159 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
160 {
161 api.ifindex_num = stream_getc (s);
162 ifindex = stream_getl (s);
163 }
164 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
165 api.distance = stream_getc (s);
166 else
167 api.distance = 0;
168 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
169 api.metric = stream_getl (s);
170 else
171 api.metric = 0;
172
173 if (command == ZEBRA_IPV6_ROUTE_ADD)
hassoa94434b2003-05-25 17:10:12 +0000174 ripng_redistribute_add (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex, &nexthop);
paul718e3742002-12-13 20:15:29 +0000175 else
hassoa94434b2003-05-25 17:10:12 +0000176 ripng_redistribute_delete (api.type, RIPNG_ROUTE_REDISTRIBUTE, &p, ifindex);
paul718e3742002-12-13 20:15:29 +0000177
178 return 0;
179}
180
hassoa94434b2003-05-25 17:10:12 +0000181void
Paul Jakma6ac29a52008-08-15 13:45:30 +0100182ripng_zclient_reset (void)
hassoa94434b2003-05-25 17:10:12 +0000183{
184 zclient_reset (zclient);
185}
186
Paul Jakma6ac29a52008-08-15 13:45:30 +0100187static int
paul718e3742002-12-13 20:15:29 +0000188ripng_redistribute_unset (int type)
189{
Feng Luc99f3482014-10-16 09:52:36 +0800190 if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000191 return CMD_SUCCESS;
192
Feng Luc99f3482014-10-16 09:52:36 +0800193 vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000194
195 if (zclient->sock > 0)
Feng Luc99f3482014-10-16 09:52:36 +0800196 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type,
197 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000198
199 ripng_redistribute_withdraw (type);
200
201 return CMD_SUCCESS;
202}
203
hassoa94434b2003-05-25 17:10:12 +0000204int
205ripng_redistribute_check (int type)
206{
Feng Luc99f3482014-10-16 09:52:36 +0800207 return vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000208}
209
Paul Jakma6ac29a52008-08-15 13:45:30 +0100210static void
paul718e3742002-12-13 20:15:29 +0000211ripng_redistribute_metric_set (int type, int metric)
212{
213 ripng->route_map[type].metric_config = 1;
214 ripng->route_map[type].metric = metric;
215}
216
Paul Jakma6ac29a52008-08-15 13:45:30 +0100217static int
paul718e3742002-12-13 20:15:29 +0000218ripng_redistribute_metric_unset (int type)
219{
220 ripng->route_map[type].metric_config = 0;
221 ripng->route_map[type].metric = 0;
hassoa94434b2003-05-25 17:10:12 +0000222 return 0;
paul718e3742002-12-13 20:15:29 +0000223}
224
Paul Jakma6ac29a52008-08-15 13:45:30 +0100225static void
hasso98b718a2004-10-11 12:57:57 +0000226ripng_redistribute_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000227{
228 if (ripng->route_map[type].name)
229 free (ripng->route_map[type].name);
230
231 ripng->route_map[type].name = strdup (name);
232 ripng->route_map[type].map = route_map_lookup_by_name (name);
233}
234
Paul Jakma6ac29a52008-08-15 13:45:30 +0100235static void
paul718e3742002-12-13 20:15:29 +0000236ripng_redistribute_routemap_unset (int type)
237{
238 if (ripng->route_map[type].name)
239 free (ripng->route_map[type].name);
240
241 ripng->route_map[type].name = NULL;
242 ripng->route_map[type].map = NULL;
243}
David Lamparter6b0655a2014-06-04 06:53:35 +0200244
hassoa94434b2003-05-25 17:10:12 +0000245/* Redistribution types */
246static struct {
247 int type;
248 int str_min_len;
hasso7a1d5832004-10-08 06:32:23 +0000249 const char *str;
hassoa94434b2003-05-25 17:10:12 +0000250} redist_type[] = {
251 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
252 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
253 {ZEBRA_ROUTE_STATIC, 1, "static"},
254 {ZEBRA_ROUTE_OSPF6, 1, "ospf6"},
Matthieu Boutier93079db2012-02-09 20:58:07 +0100255 {ZEBRA_ROUTE_BGP, 2, "bgp"},
256 {ZEBRA_ROUTE_BABEL, 2, "babel"},
hassoa94434b2003-05-25 17:10:12 +0000257 {0, 0, NULL}
258};
259
260void
261ripng_redistribute_clean ()
262{
263 int i;
264
265 for (i = 0; redist_type[i].str; i++)
266 {
Feng Luc99f3482014-10-16 09:52:36 +0800267 if (vrf_bitmap_check (zclient->redist[redist_type[i].type], VRF_DEFAULT))
hassoa94434b2003-05-25 17:10:12 +0000268 {
269 if (zclient->sock > 0)
270 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
Feng Luc99f3482014-10-16 09:52:36 +0800271 zclient, redist_type[i].type,
272 VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000273
Feng Luc99f3482014-10-16 09:52:36 +0800274 vrf_bitmap_unset (zclient->redist[redist_type[i].type], VRF_DEFAULT);
hassoa94434b2003-05-25 17:10:12 +0000275
276 /* Remove the routes from RIPng table. */
277 ripng_redistribute_withdraw (redist_type[i].type);
278 }
279 }
280}
281
paul718e3742002-12-13 20:15:29 +0000282DEFUN (router_zebra,
283 router_zebra_cmd,
284 "router zebra",
285 "Enable a routing process\n"
286 "Make connection to zebra daemon\n")
287{
288 vty->node = ZEBRA_NODE;
289 zclient->enable = 1;
290 zclient_start (zclient);
291 return CMD_SUCCESS;
292}
293
294DEFUN (no_router_zebra,
295 no_router_zebra_cmd,
296 "no router zebra",
297 NO_STR
298 "Disable a routing process\n"
299 "Stop connection to zebra daemon\n")
300{
301 zclient->enable = 0;
302 zclient_stop (zclient);
303 return CMD_SUCCESS;
304}
305
306DEFUN (ripng_redistribute_ripng,
307 ripng_redistribute_ripng_cmd,
308 "redistribute ripng",
309 "Redistribute information from another routing protocol\n"
310 "RIPng route\n")
311{
Feng Luc99f3482014-10-16 09:52:36 +0800312 vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000313 return CMD_SUCCESS;
314}
315
316DEFUN (no_ripng_redistribute_ripng,
317 no_ripng_redistribute_ripng_cmd,
318 "no redistribute ripng",
319 NO_STR
320 "Redistribute information from another routing protocol\n"
321 "RIPng route\n")
322{
Feng Luc99f3482014-10-16 09:52:36 +0800323 vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000324 return CMD_SUCCESS;
325}
326
hassoa94434b2003-05-25 17:10:12 +0000327DEFUN (ripng_redistribute_type,
328 ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100329 "redistribute " QUAGGA_REDIST_STR_RIPNGD,
330 "Redistribute\n"
331 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000332{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100333 int type;
hassoa94434b2003-05-25 17:10:12 +0000334
Matthieu Boutier93079db2012-02-09 20:58:07 +0100335 type = proto_redistnum(AFI_IP6, argv[0]);
336
337 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000338 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100339 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
340 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000341 }
342
Feng Luc99f3482014-10-16 09:52:36 +0800343 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100344 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000345}
346
hassoa94434b2003-05-25 17:10:12 +0000347DEFUN (no_ripng_redistribute_type,
348 no_ripng_redistribute_type_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100349 "no redistribute " QUAGGA_REDIST_STR_RIPNGD,
paul718e3742002-12-13 20:15:29 +0000350 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100351 "Redistribute\n"
352 QUAGGA_REDIST_HELP_STR_RIPNGD)
paul718e3742002-12-13 20:15:29 +0000353{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100354 int type;
hassoa94434b2003-05-25 17:10:12 +0000355
Matthieu Boutier93079db2012-02-09 20:58:07 +0100356 type = proto_redistnum(AFI_IP6, argv[0]);
357
358 if (type < 0)
hassoa94434b2003-05-25 17:10:12 +0000359 {
Matthieu Boutier93079db2012-02-09 20:58:07 +0100360 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
361 return CMD_WARNING;
hassoa94434b2003-05-25 17:10:12 +0000362 }
363
Matthieu Boutier93079db2012-02-09 20:58:07 +0100364 ripng_redistribute_metric_unset (type);
365 ripng_redistribute_routemap_unset (type);
366 return ripng_redistribute_unset (type);
paul718e3742002-12-13 20:15:29 +0000367}
368
paul718e3742002-12-13 20:15:29 +0000369
hassoa94434b2003-05-25 17:10:12 +0000370DEFUN (ripng_redistribute_type_metric,
371 ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100372 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
373 "Redistribute\n"
374 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000375 "Metric\n"
376 "Metric value\n")
377{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100378 int type;
hassoa94434b2003-05-25 17:10:12 +0000379 int metric;
380
381 metric = atoi (argv[1]);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100382 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000383
Matthieu Boutier93079db2012-02-09 20:58:07 +0100384 if (type < 0)
385 {
386 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
387 return CMD_WARNING;
388 }
hassoa94434b2003-05-25 17:10:12 +0000389
Matthieu Boutier93079db2012-02-09 20:58:07 +0100390 ripng_redistribute_metric_set (type, metric);
Feng Luc99f3482014-10-16 09:52:36 +0800391 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100392 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000393}
394
hassoa94434b2003-05-25 17:10:12 +0000395ALIAS (no_ripng_redistribute_type,
396 no_ripng_redistribute_type_metric_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100397 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000398 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100399 "Redistribute\n"
400 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000401 "Metric\n"
402 "Metric value\n")
403
hassoa94434b2003-05-25 17:10:12 +0000404DEFUN (ripng_redistribute_type_routemap,
405 ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100406 "redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
407 "Redistribute\n"
408 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000409 "Route map reference\n"
410 "Pointer to route-map entries\n")
411{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100412 int type;
hassoa94434b2003-05-25 17:10:12 +0000413
Matthieu Boutier93079db2012-02-09 20:58:07 +0100414 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000415
Matthieu Boutier93079db2012-02-09 20:58:07 +0100416 if (type < 0)
417 {
418 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
419 return CMD_WARNING;
420 }
hassoa94434b2003-05-25 17:10:12 +0000421
Matthieu Boutier93079db2012-02-09 20:58:07 +0100422 ripng_redistribute_routemap_set (type, argv[1]);
Feng Luc99f3482014-10-16 09:52:36 +0800423 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100424 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000425}
426
hassoa94434b2003-05-25 17:10:12 +0000427ALIAS (no_ripng_redistribute_type,
428 no_ripng_redistribute_type_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100429 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000430 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100431 "Redistribute\n"
432 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000433 "Route map reference\n"
434 "Pointer to route-map entries\n")
435
hassoa94434b2003-05-25 17:10:12 +0000436DEFUN (ripng_redistribute_type_metric_routemap,
437 ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100438 "redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
439 "Redistribute\n"
440 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000441 "Metric\n"
442 "Metric value\n"
443 "Route map reference\n"
444 "Pointer to route-map entries\n")
445{
Matthieu Boutier93079db2012-02-09 20:58:07 +0100446 int type;
hassoa94434b2003-05-25 17:10:12 +0000447 int metric;
448
Matthieu Boutier93079db2012-02-09 20:58:07 +0100449 type = proto_redistnum(AFI_IP6, argv[0]);
hassoa94434b2003-05-25 17:10:12 +0000450 metric = atoi (argv[1]);
451
Matthieu Boutier93079db2012-02-09 20:58:07 +0100452 if (type < 0)
453 {
454 vty_out(vty, "Invalid type %s%s", argv[0], VTY_NEWLINE);
455 return CMD_WARNING;
456 }
hassoa94434b2003-05-25 17:10:12 +0000457
Matthieu Boutier93079db2012-02-09 20:58:07 +0100458 ripng_redistribute_metric_set (type, metric);
459 ripng_redistribute_routemap_set (type, argv[2]);
Feng Luc99f3482014-10-16 09:52:36 +0800460 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type, VRF_DEFAULT);
Matthieu Boutier93079db2012-02-09 20:58:07 +0100461 return CMD_SUCCESS;
paul718e3742002-12-13 20:15:29 +0000462}
463
hassoa94434b2003-05-25 17:10:12 +0000464ALIAS (no_ripng_redistribute_type,
465 no_ripng_redistribute_type_metric_routemap_cmd,
Matthieu Boutier93079db2012-02-09 20:58:07 +0100466 "no redistribute " QUAGGA_REDIST_STR_RIPNGD " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000467 NO_STR
Matthieu Boutier93079db2012-02-09 20:58:07 +0100468 "Redistribute\n"
469 QUAGGA_REDIST_HELP_STR_RIPNGD
paul718e3742002-12-13 20:15:29 +0000470 "Route map reference\n"
471 "Pointer to route-map entries\n")
472
473void
hassoa94434b2003-05-25 17:10:12 +0000474ripng_redistribute_write (struct vty *vty, int config_mode)
paul718e3742002-12-13 20:15:29 +0000475{
476 int i;
paul718e3742002-12-13 20:15:29 +0000477
478 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
Feng Luc99f3482014-10-16 09:52:36 +0800479 if (i != zclient->redist_default &&
480 vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000481 {
hassoa94434b2003-05-25 17:10:12 +0000482 if (config_mode)
483 {
484 if (ripng->route_map[i].metric_config)
485 {
486 if (ripng->route_map[i].name)
487 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000488 zebra_route_string(i), ripng->route_map[i].metric,
hassoa94434b2003-05-25 17:10:12 +0000489 ripng->route_map[i].name, VTY_NEWLINE);
490 else
491 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000492 zebra_route_string(i), ripng->route_map[i].metric,
493 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000494 }
495 else
496 {
497 if (ripng->route_map[i].name)
498 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000499 zebra_route_string(i), ripng->route_map[i].name,
500 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000501 else
ajsf52d13c2005-10-01 17:38:06 +0000502 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
503 VTY_NEWLINE);
hassoa94434b2003-05-25 17:10:12 +0000504 }
505 }
506 else
ajsf52d13c2005-10-01 17:38:06 +0000507 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000508 }
509}
510
511/* RIPng configuration write function. */
Paul Jakma6ac29a52008-08-15 13:45:30 +0100512static int
paul718e3742002-12-13 20:15:29 +0000513zebra_config_write (struct vty *vty)
514{
515 if (! zclient->enable)
516 {
517 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
518 return 1;
519 }
Feng Luc99f3482014-10-16 09:52:36 +0800520 else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIPNG], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000521 {
522 vty_out (vty, "router zebra%s", VTY_NEWLINE);
523 vty_out (vty, " no redistribute ripng%s", VTY_NEWLINE);
524 return 1;
525 }
526 return 0;
527}
528
529/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800530static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000531{
532 ZEBRA_NODE,
533 "%s(config-router)# ",
534};
535
Feng Luc99f3482014-10-16 09:52:36 +0800536static void
537ripng_zebra_connected (struct zclient *zclient)
538{
539 zclient_send_requests (zclient, VRF_DEFAULT);
540}
541
paul718e3742002-12-13 20:15:29 +0000542/* Initialize zebra structure and it's commands. */
543void
544zebra_init ()
545{
546 /* Allocate zebra structure. */
547 zclient = zclient_new ();
548 zclient_init (zclient, ZEBRA_ROUTE_RIPNG);
549
Feng Luc99f3482014-10-16 09:52:36 +0800550 zclient->zebra_connected = ripng_zebra_connected;
paul718e3742002-12-13 20:15:29 +0000551 zclient->interface_up = ripng_interface_up;
552 zclient->interface_down = ripng_interface_down;
553 zclient->interface_add = ripng_interface_add;
554 zclient->interface_delete = ripng_interface_delete;
555 zclient->interface_address_add = ripng_interface_address_add;
556 zclient->interface_address_delete = ripng_interface_address_delete;
557 zclient->ipv6_route_add = ripng_zebra_read_ipv6;
558 zclient->ipv6_route_delete = ripng_zebra_read_ipv6;
559
560 /* Install zebra node. */
561 install_node (&zebra_node, zebra_config_write);
562
563 /* Install command element for zebra node. */
564 install_element (CONFIG_NODE, &router_zebra_cmd);
565 install_element (CONFIG_NODE, &no_router_zebra_cmd);
566 install_default (ZEBRA_NODE);
567 install_element (ZEBRA_NODE, &ripng_redistribute_ripng_cmd);
568 install_element (ZEBRA_NODE, &no_ripng_redistribute_ripng_cmd);
hassoa94434b2003-05-25 17:10:12 +0000569
570 /* Install command elements to ripng node */
571 install_element (RIPNG_NODE, &ripng_redistribute_type_cmd);
572 install_element (RIPNG_NODE, &ripng_redistribute_type_routemap_cmd);
573 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_cmd);
574 install_element (RIPNG_NODE, &ripng_redistribute_type_metric_routemap_cmd);
575 install_element (RIPNG_NODE, &no_ripng_redistribute_type_cmd);
576 install_element (RIPNG_NODE, &no_ripng_redistribute_type_routemap_cmd);
577 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_cmd);
578 install_element (RIPNG_NODE, &no_ripng_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000579}