blob: 2670ff7ee3663630ad351225fe2d888bb658c8b9 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* RIPd and zebra interface.
2 * Copyright (C) 1997, 1999 Kunihiro Ishiguro <kunihiro@zebra.org>
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#include "command.h"
25#include "prefix.h"
Lu Fengb397cf42014-07-18 06:13:18 +000026#include "table.h"
paul718e3742002-12-13 20:15:29 +000027#include "stream.h"
Lu Fengb397cf42014-07-18 06:13:18 +000028#include "memory.h"
paul718e3742002-12-13 20:15:29 +000029#include "routemap.h"
30#include "zclient.h"
31#include "log.h"
Feng Luc99f3482014-10-16 09:52:36 +080032#include "vrf.h"
paul718e3742002-12-13 20:15:29 +000033#include "ripd/ripd.h"
34#include "ripd/rip_debug.h"
pauldc63bfd2005-10-25 23:31:05 +000035#include "ripd/rip_interface.h"
paul718e3742002-12-13 20:15:29 +000036
37/* All information about zebra. */
38struct zclient *zclient = NULL;
David Lamparter6b0655a2014-06-04 06:53:35 +020039
Lu Fengb397cf42014-07-18 06:13:18 +000040/* Send ECMP routes to zebra. */
41static void
42rip_zebra_ipv4_send (struct route_node *rp, u_char cmd)
paul718e3742002-12-13 20:15:29 +000043{
Lu Fengb397cf42014-07-18 06:13:18 +000044 static struct in_addr **nexthops = NULL;
45 static unsigned int nexthops_len = 0;
46
47 struct list *list = (struct list *)rp->info;
paul718e3742002-12-13 20:15:29 +000048 struct zapi_ipv4 api;
Lu Fengb397cf42014-07-18 06:13:18 +000049 struct listnode *listnode = NULL;
50 struct rip_info *rinfo = NULL;
51 int count = 0;
paul718e3742002-12-13 20:15:29 +000052
Feng Luc99f3482014-10-16 09:52:36 +080053 if (vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +000054 {
Feng Luc99f3482014-10-16 09:52:36 +080055 api.vrf_id = VRF_DEFAULT;
paul718e3742002-12-13 20:15:29 +000056 api.type = ZEBRA_ROUTE_RIP;
57 api.flags = 0;
58 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +040059 api.safi = SAFI_UNICAST;
Lu Fengb397cf42014-07-18 06:13:18 +000060
61 if (nexthops_len < listcount (list))
62 {
63 nexthops_len = listcount (list);
64 nexthops = XREALLOC (MTYPE_TMP, nexthops,
65 nexthops_len * sizeof (struct in_addr *));
66 }
67
paul718e3742002-12-13 20:15:29 +000068 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
Lu Fengb397cf42014-07-18 06:13:18 +000069 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
70 {
71 nexthops[count++] = &rinfo->nexthop;
72 if (cmd == ZEBRA_IPV4_ROUTE_ADD)
73 SET_FLAG (rinfo->flags, RIP_RTF_FIB);
74 else
75 UNSET_FLAG (rinfo->flags, RIP_RTF_FIB);
76 }
77
78 api.nexthop = nexthops;
79 api.nexthop_num = count;
paul718e3742002-12-13 20:15:29 +000080 api.ifindex_num = 0;
Lu Fengb397cf42014-07-18 06:13:18 +000081
82 rinfo = listgetdata (listhead (list));
83
paul718e3742002-12-13 20:15:29 +000084 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
Lu Fengb397cf42014-07-18 06:13:18 +000085 api.metric = rinfo->metric;
paul718e3742002-12-13 20:15:29 +000086
Lu Fengb397cf42014-07-18 06:13:18 +000087 if (rinfo->distance && rinfo->distance != ZEBRA_RIP_DISTANCE_DEFAULT)
88 {
89 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
90 api.distance = rinfo->distance;
91 }
paul718e3742002-12-13 20:15:29 +000092
Lu Fengb397cf42014-07-18 06:13:18 +000093 zapi_ipv4_route (cmd, zclient,
94 (struct prefix_ipv4 *)&rp->p, &api);
95
96 if (IS_RIP_DEBUG_ZEBRA)
Lu Feng0b74a0a2014-07-18 06:13:19 +000097 {
98 if (rip->ecmp)
99 zlog_debug ("%s: %s/%d nexthops %d",
100 (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \
101 "Install into zebra" : "Delete from zebra",
102 inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen, count);
103 else
104 zlog_debug ("%s: %s/%d",
105 (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \
106 "Install into zebra" : "Delete from zebra",
107 inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen);
108 }
paul718e3742002-12-13 20:15:29 +0000109
110 rip_global_route_changes++;
111 }
112}
113
Lu Fengb397cf42014-07-18 06:13:18 +0000114/* Add/update ECMP routes to zebra. */
paul718e3742002-12-13 20:15:29 +0000115void
Lu Fengb397cf42014-07-18 06:13:18 +0000116rip_zebra_ipv4_add (struct route_node *rp)
paul718e3742002-12-13 20:15:29 +0000117{
Lu Fengb397cf42014-07-18 06:13:18 +0000118 rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_ADD);
119}
paul718e3742002-12-13 20:15:29 +0000120
Lu Fengb397cf42014-07-18 06:13:18 +0000121/* Delete ECMP routes from zebra. */
122void
123rip_zebra_ipv4_delete (struct route_node *rp)
124{
125 rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_DELETE);
paul718e3742002-12-13 20:15:29 +0000126}
127
128/* Zebra route add and delete treatment. */
pauldc63bfd2005-10-25 23:31:05 +0000129static int
Feng Luc99f3482014-10-16 09:52:36 +0800130rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
131 vrf_id_t vrf_id)
paul718e3742002-12-13 20:15:29 +0000132{
133 struct stream *s;
134 struct zapi_ipv4 api;
135 unsigned long ifindex;
136 struct in_addr nexthop;
137 struct prefix_ipv4 p;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500138 unsigned char plength = 0;
139
paul718e3742002-12-13 20:15:29 +0000140 s = zclient->ibuf;
141 ifindex = 0;
142 nexthop.s_addr = 0;
143
144 /* Type, flags, message. */
145 api.type = stream_getc (s);
146 api.flags = stream_getc (s);
147 api.message = stream_getc (s);
148
149 /* IPv4 prefix. */
150 memset (&p, 0, sizeof (struct prefix_ipv4));
151 p.family = AF_INET;
Donald Sharp5e57b5f2016-03-11 16:28:34 -0500152 plength = stream_getc (s);
153 p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, plength);
paul718e3742002-12-13 20:15:29 +0000154 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
155
156 /* Nexthop, ifindex, distance, metric. */
157 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
158 {
159 api.nexthop_num = stream_getc (s);
160 nexthop.s_addr = stream_get_ipv4 (s);
161 }
162 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
163 {
164 api.ifindex_num = stream_getc (s);
165 ifindex = stream_getl (s);
166 }
167 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
168 api.distance = stream_getc (s);
vincentfbf5d032005-09-29 11:25:50 +0000169 else
170 api.distance = 255;
paul718e3742002-12-13 20:15:29 +0000171 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
172 api.metric = stream_getl (s);
vincentfbf5d032005-09-29 11:25:50 +0000173 else
174 api.metric = 0;
paul718e3742002-12-13 20:15:29 +0000175
176 /* Then fetch IPv4 prefixes. */
177 if (command == ZEBRA_IPV4_ROUTE_ADD)
vincentfbf5d032005-09-29 11:25:50 +0000178 rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
179 &nexthop, api.metric, api.distance);
paul718e3742002-12-13 20:15:29 +0000180 else
181 rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
182
183 return 0;
184}
185
186void
pauldc63bfd2005-10-25 23:31:05 +0000187rip_zclient_reset (void)
paul718e3742002-12-13 20:15:29 +0000188{
189 zclient_reset (zclient);
190}
191
192/* RIP route-map set for redistribution */
pauldc63bfd2005-10-25 23:31:05 +0000193static void
hasso98b718a2004-10-11 12:57:57 +0000194rip_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000195{
196 if (rip->route_map[type].name)
197 free(rip->route_map[type].name);
198
199 rip->route_map[type].name = strdup (name);
200 rip->route_map[type].map = route_map_lookup_by_name (name);
201}
202
pauldc63bfd2005-10-25 23:31:05 +0000203static void
hasso8a676be2004-10-08 06:36:38 +0000204rip_redistribute_metric_set (int type, unsigned int metric)
paul718e3742002-12-13 20:15:29 +0000205{
206 rip->route_map[type].metric_config = 1;
207 rip->route_map[type].metric = metric;
208}
209
pauldc63bfd2005-10-25 23:31:05 +0000210static int
hasso8a676be2004-10-08 06:36:38 +0000211rip_metric_unset (int type, unsigned int metric)
paul718e3742002-12-13 20:15:29 +0000212{
213#define DONT_CARE_METRIC_RIP 17
214 if (metric != DONT_CARE_METRIC_RIP &&
215 rip->route_map[type].metric != metric)
216 return 1;
217 rip->route_map[type].metric_config = 0;
218 rip->route_map[type].metric = 0;
219 return 0;
220}
221
222/* RIP route-map unset for redistribution */
pauldc63bfd2005-10-25 23:31:05 +0000223static int
hasso98b718a2004-10-11 12:57:57 +0000224rip_routemap_unset (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000225{
226 if (! rip->route_map[type].name ||
227 (name != NULL && strcmp(rip->route_map[type].name,name)))
228 return 1;
229
230 free (rip->route_map[type].name);
231 rip->route_map[type].name = NULL;
232 rip->route_map[type].map = NULL;
233
234 return 0;
235}
David Lamparter6b0655a2014-06-04 06:53:35 +0200236
paul718e3742002-12-13 20:15:29 +0000237/* Redistribution types */
238static struct {
239 int type;
240 int str_min_len;
hasso8a676be2004-10-08 06:36:38 +0000241 const char *str;
paul718e3742002-12-13 20:15:29 +0000242} redist_type[] = {
243 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
244 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
245 {ZEBRA_ROUTE_STATIC, 1, "static"},
246 {ZEBRA_ROUTE_OSPF, 1, "ospf"},
Matthieu Boutier9c58fbd2012-02-09 21:51:17 +0100247 {ZEBRA_ROUTE_BGP, 2, "bgp"},
248 {ZEBRA_ROUTE_BABEL, 2, "babel"},
paul718e3742002-12-13 20:15:29 +0000249 {0, 0, NULL}
250};
251
252DEFUN (router_zebra,
253 router_zebra_cmd,
254 "router zebra",
255 "Enable a routing process\n"
256 "Make connection to zebra daemon\n")
257{
258 vty->node = ZEBRA_NODE;
259 zclient->enable = 1;
260 zclient_start (zclient);
261 return CMD_SUCCESS;
262}
263
264DEFUN (no_router_zebra,
265 no_router_zebra_cmd,
266 "no router zebra",
267 NO_STR
268 "Enable a routing process\n"
269 "Make connection to zebra daemon\n")
270{
271 zclient->enable = 0;
272 zclient_stop (zclient);
273 return CMD_SUCCESS;
274}
275
Stephen Hemminger2c239702009-12-10 19:16:05 +0300276#if 0
pauldc63bfd2005-10-25 23:31:05 +0000277static int
paul718e3742002-12-13 20:15:29 +0000278rip_redistribute_set (int type)
279{
Feng Luc99f3482014-10-16 09:52:36 +0800280 if (vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000281 return CMD_SUCCESS;
282
Feng Luc99f3482014-10-16 09:52:36 +0800283 vrf_bitmap_set (zclient->redist[type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000284
285 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000286 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
paul718e3742002-12-13 20:15:29 +0000287
288 return CMD_SUCCESS;
289}
Stephen Hemminger2c239702009-12-10 19:16:05 +0300290#endif
paul718e3742002-12-13 20:15:29 +0000291
pauldc63bfd2005-10-25 23:31:05 +0000292static int
paul718e3742002-12-13 20:15:29 +0000293rip_redistribute_unset (int type)
294{
Feng Luc99f3482014-10-16 09:52:36 +0800295 if (! vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000296 return CMD_SUCCESS;
297
Feng Luc99f3482014-10-16 09:52:36 +0800298 vrf_bitmap_unset (zclient->redist[type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000299
300 if (zclient->sock > 0)
Feng Luc99f3482014-10-16 09:52:36 +0800301 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type,
302 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000303
304 /* Remove the routes from RIP table. */
305 rip_redistribute_withdraw (type);
306
307 return CMD_SUCCESS;
308}
309
310int
311rip_redistribute_check (int type)
312{
Feng Luc99f3482014-10-16 09:52:36 +0800313 return vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000314}
315
316void
pauldc63bfd2005-10-25 23:31:05 +0000317rip_redistribute_clean (void)
paul718e3742002-12-13 20:15:29 +0000318{
319 int i;
320
321 for (i = 0; redist_type[i].str; i++)
322 {
Feng Luc99f3482014-10-16 09:52:36 +0800323 if (vrf_bitmap_check (zclient->redist[redist_type[i].type], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000324 {
325 if (zclient->sock > 0)
326 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
Feng Luc99f3482014-10-16 09:52:36 +0800327 zclient, redist_type[i].type,
328 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000329
Feng Luc99f3482014-10-16 09:52:36 +0800330 vrf_bitmap_unset (zclient->redist[redist_type[i].type], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000331
332 /* Remove the routes from RIP table. */
333 rip_redistribute_withdraw (redist_type[i].type);
334 }
335 }
336}
337
338DEFUN (rip_redistribute_rip,
339 rip_redistribute_rip_cmd,
340 "redistribute rip",
341 "Redistribute information from another routing protocol\n"
342 "Routing Information Protocol (RIP)\n")
343{
Feng Luc99f3482014-10-16 09:52:36 +0800344 vrf_bitmap_set (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000345 return CMD_SUCCESS;
346}
347
348DEFUN (no_rip_redistribute_rip,
349 no_rip_redistribute_rip_cmd,
350 "no redistribute rip",
351 NO_STR
352 "Redistribute information from another routing protocol\n"
353 "Routing Information Protocol (RIP)\n")
354{
Feng Luc99f3482014-10-16 09:52:36 +0800355 vrf_bitmap_unset (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000356 return CMD_SUCCESS;
357}
358
359DEFUN (rip_redistribute_type,
360 rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000361 "redistribute " QUAGGA_REDIST_STR_RIPD,
362 REDIST_STR
363 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000364{
365 int i;
366
367 for(i = 0; redist_type[i].str; i++)
368 {
369 if (strncmp (redist_type[i].str, argv[0],
370 redist_type[i].str_min_len) == 0)
371 {
paul0a589352004-05-08 11:48:26 +0000372 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
Feng Luc99f3482014-10-16 09:52:36 +0800373 redist_type[i].type, VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000374 return CMD_SUCCESS;
375 }
376 }
377
378 vty_out(vty, "Invalid type %s%s", argv[0],
379 VTY_NEWLINE);
380
381 return CMD_WARNING;
382}
383
384DEFUN (no_rip_redistribute_type,
385 no_rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000386 "no redistribute " QUAGGA_REDIST_STR_RIPD,
paul718e3742002-12-13 20:15:29 +0000387 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000388 REDIST_STR
389 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000390{
391 int i;
392
393 for (i = 0; redist_type[i].str; i++)
394 {
395 if (strncmp(redist_type[i].str, argv[0],
396 redist_type[i].str_min_len) == 0)
397 {
398 rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP);
399 rip_routemap_unset (redist_type[i].type,NULL);
400 rip_redistribute_unset (redist_type[i].type);
401 return CMD_SUCCESS;
402 }
403 }
404
405 vty_out(vty, "Invalid type %s%s", argv[0],
406 VTY_NEWLINE);
407
408 return CMD_WARNING;
409}
410
411DEFUN (rip_redistribute_type_routemap,
412 rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000413 "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
414 REDIST_STR
415 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000416 "Route map reference\n"
417 "Pointer to route-map entries\n")
418{
419 int i;
420
421 for (i = 0; redist_type[i].str; i++) {
422 if (strncmp(redist_type[i].str, argv[0],
423 redist_type[i].str_min_len) == 0)
424 {
425 rip_routemap_set (redist_type[i].type, argv[1]);
Feng Luc99f3482014-10-16 09:52:36 +0800426 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type,
427 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000428 return CMD_SUCCESS;
429 }
430 }
431
432 vty_out(vty, "Invalid type %s%s", argv[0],
433 VTY_NEWLINE);
434
435 return CMD_WARNING;
436}
437
438DEFUN (no_rip_redistribute_type_routemap,
439 no_rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000440 "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000441 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000442 REDIST_STR
443 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000444 "Route map reference\n"
445 "Pointer to route-map entries\n")
446{
447 int i;
448
449 for (i = 0; redist_type[i].str; i++)
450 {
451 if (strncmp(redist_type[i].str, argv[0],
452 redist_type[i].str_min_len) == 0)
453 {
454 if (rip_routemap_unset (redist_type[i].type,argv[1]))
455 return CMD_WARNING;
456 rip_redistribute_unset (redist_type[i].type);
457 return CMD_SUCCESS;
458 }
459 }
460
461 vty_out(vty, "Invalid type %s%s", argv[0],
462 VTY_NEWLINE);
463
464 return CMD_WARNING;
465}
466
467DEFUN (rip_redistribute_type_metric,
468 rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000469 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
470 REDIST_STR
471 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000472 "Metric\n"
473 "Metric value\n")
474{
475 int i;
476 int metric;
477
478 metric = atoi (argv[1]);
479
480 for (i = 0; redist_type[i].str; i++) {
481 if (strncmp(redist_type[i].str, argv[0],
482 redist_type[i].str_min_len) == 0)
483 {
484 rip_redistribute_metric_set (redist_type[i].type, metric);
Feng Luc99f3482014-10-16 09:52:36 +0800485 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type,
486 VRF_DEFAULT);
paul718e3742002-12-13 20:15:29 +0000487 return CMD_SUCCESS;
488 }
489 }
490
491 vty_out(vty, "Invalid type %s%s", argv[0],
492 VTY_NEWLINE);
493
494 return CMD_WARNING;
495}
496
497DEFUN (no_rip_redistribute_type_metric,
498 no_rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000499 "no redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000500 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000501 REDIST_STR
502 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000503 "Metric\n"
504 "Metric value\n")
505{
506 int i;
507
508 for (i = 0; redist_type[i].str; i++)
509 {
510 if (strncmp(redist_type[i].str, argv[0],
511 redist_type[i].str_min_len) == 0)
512 {
513 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
514 return CMD_WARNING;
515 rip_redistribute_unset (redist_type[i].type);
516 return CMD_SUCCESS;
517 }
518 }
519
520 vty_out(vty, "Invalid type %s%s", argv[0],
521 VTY_NEWLINE);
522
523 return CMD_WARNING;
524}
525
hasso16705132003-05-25 14:49:19 +0000526DEFUN (rip_redistribute_type_metric_routemap,
527 rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000528 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16> route-map WORD",
529 REDIST_STR
530 QUAGGA_REDIST_HELP_STR_RIPD
hasso16705132003-05-25 14:49:19 +0000531 "Metric\n"
532 "Metric value\n"
533 "Route map reference\n"
534 "Pointer to route-map entries\n")
535{
536 int i;
537 int metric;
538
539 metric = atoi (argv[1]);
540
541 for (i = 0; redist_type[i].str; i++) {
542 if (strncmp(redist_type[i].str, argv[0],
543 redist_type[i].str_min_len) == 0)
544 {
545 rip_redistribute_metric_set (redist_type[i].type, metric);
546 rip_routemap_set (redist_type[i].type, argv[2]);
Feng Luc99f3482014-10-16 09:52:36 +0800547 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type,
548 VRF_DEFAULT);
hasso16705132003-05-25 14:49:19 +0000549 return CMD_SUCCESS;
550 }
551 }
552
553 vty_out(vty, "Invalid type %s%s", argv[0],
554 VTY_NEWLINE);
555
556 return CMD_WARNING;
557}
558
559
paul718e3742002-12-13 20:15:29 +0000560DEFUN (no_rip_redistribute_type_metric_routemap,
561 no_rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000562 "no redistribute " QUAGGA_REDIST_STR_RIPD
563 " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000564 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000565 REDIST_STR
566 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000567 "Metric\n"
568 "Metric value\n"
569 "Route map reference\n"
570 "Pointer to route-map entries\n")
571{
572 int i;
573
574 for (i = 0; redist_type[i].str; i++)
575 {
576 if (strncmp(redist_type[i].str, argv[0],
577 redist_type[i].str_min_len) == 0)
578 {
579 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
580 return CMD_WARNING;
581 if (rip_routemap_unset (redist_type[i].type, argv[2]))
582 {
583 rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1]));
584 return CMD_WARNING;
585 }
586 rip_redistribute_unset (redist_type[i].type);
587 return CMD_SUCCESS;
588 }
589 }
590
591 vty_out(vty, "Invalid type %s%s", argv[0],
592 VTY_NEWLINE);
593
594 return CMD_WARNING;
595}
David Lamparter6b0655a2014-06-04 06:53:35 +0200596
paul718e3742002-12-13 20:15:29 +0000597/* Default information originate. */
598
599DEFUN (rip_default_information_originate,
600 rip_default_information_originate_cmd,
601 "default-information originate",
602 "Control distribution of default route\n"
603 "Distribute a default route\n")
604{
605 struct prefix_ipv4 p;
606
607 if (! rip->default_information)
608 {
609 memset (&p, 0, sizeof (struct prefix_ipv4));
610 p.family = AF_INET;
611
612 rip->default_information = 1;
613
vincentfbf5d032005-09-29 11:25:50 +0000614 rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
615 NULL, 0, 0);
paul718e3742002-12-13 20:15:29 +0000616 }
617
618 return CMD_SUCCESS;
619}
620
621DEFUN (no_rip_default_information_originate,
622 no_rip_default_information_originate_cmd,
623 "no default-information originate",
624 NO_STR
625 "Control distribution of default route\n"
626 "Distribute a default route\n")
627{
628 struct prefix_ipv4 p;
629
630 if (rip->default_information)
631 {
632 memset (&p, 0, sizeof (struct prefix_ipv4));
633 p.family = AF_INET;
634
635 rip->default_information = 0;
636
hasso16705132003-05-25 14:49:19 +0000637 rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
paul718e3742002-12-13 20:15:29 +0000638 }
639
640 return CMD_SUCCESS;
641}
David Lamparter6b0655a2014-06-04 06:53:35 +0200642
paul718e3742002-12-13 20:15:29 +0000643/* RIP configuration write function. */
pauldc63bfd2005-10-25 23:31:05 +0000644static int
paul718e3742002-12-13 20:15:29 +0000645config_write_zebra (struct vty *vty)
646{
647 if (! zclient->enable)
648 {
649 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
650 return 1;
651 }
Feng Luc99f3482014-10-16 09:52:36 +0800652 else if (! vrf_bitmap_check (zclient->redist[ZEBRA_ROUTE_RIP], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000653 {
654 vty_out (vty, "router zebra%s", VTY_NEWLINE);
655 vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
656 return 1;
657 }
658 return 0;
659}
660
661int
662config_write_rip_redistribute (struct vty *vty, int config_mode)
663{
664 int i;
paul718e3742002-12-13 20:15:29 +0000665
666 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
Feng Luc99f3482014-10-16 09:52:36 +0800667 if (i != zclient->redist_default &&
668 vrf_bitmap_check (zclient->redist[i], VRF_DEFAULT))
paul718e3742002-12-13 20:15:29 +0000669 {
670 if (config_mode)
671 {
672 if (rip->route_map[i].metric_config)
673 {
674 if (rip->route_map[i].name)
675 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000676 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000677 rip->route_map[i].name,
678 VTY_NEWLINE);
679 else
680 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000681 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000682 VTY_NEWLINE);
683 }
684 else
685 {
686 if (rip->route_map[i].name)
687 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000688 zebra_route_string(i), rip->route_map[i].name,
paul718e3742002-12-13 20:15:29 +0000689 VTY_NEWLINE);
690 else
ajsf52d13c2005-10-01 17:38:06 +0000691 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
paul718e3742002-12-13 20:15:29 +0000692 VTY_NEWLINE);
693 }
694 }
695 else
ajsf52d13c2005-10-01 17:38:06 +0000696 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000697 }
698 return 0;
699}
700
701/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800702static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000703{
704 ZEBRA_NODE,
705 "%s(config-router)# ",
706};
707
Feng Luc99f3482014-10-16 09:52:36 +0800708static void
709rip_zebra_connected (struct zclient *zclient)
710{
711 zclient_send_requests (zclient, VRF_DEFAULT);
712}
713
paul718e3742002-12-13 20:15:29 +0000714void
Donald Sharp71252932015-09-24 09:25:19 -0400715rip_zclient_init (struct thread_master *master)
paul718e3742002-12-13 20:15:29 +0000716{
717 /* Set default value to the zebra client structure. */
Donald Sharp71252932015-09-24 09:25:19 -0400718 zclient = zclient_new (master);
paul718e3742002-12-13 20:15:29 +0000719 zclient_init (zclient, ZEBRA_ROUTE_RIP);
Feng Luc99f3482014-10-16 09:52:36 +0800720 zclient->zebra_connected = rip_zebra_connected;
paul718e3742002-12-13 20:15:29 +0000721 zclient->interface_add = rip_interface_add;
722 zclient->interface_delete = rip_interface_delete;
723 zclient->interface_address_add = rip_interface_address_add;
724 zclient->interface_address_delete = rip_interface_address_delete;
725 zclient->ipv4_route_add = rip_zebra_read_ipv4;
726 zclient->ipv4_route_delete = rip_zebra_read_ipv4;
727 zclient->interface_up = rip_interface_up;
728 zclient->interface_down = rip_interface_down;
729
730 /* Install zebra node. */
731 install_node (&zebra_node, config_write_zebra);
732
733 /* Install command elements to zebra node. */
734 install_element (CONFIG_NODE, &router_zebra_cmd);
735 install_element (CONFIG_NODE, &no_router_zebra_cmd);
736 install_default (ZEBRA_NODE);
737 install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
738 install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
739
740 /* Install command elements to rip node. */
741 install_element (RIP_NODE, &rip_redistribute_type_cmd);
742 install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
743 install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
hasso16705132003-05-25 14:49:19 +0000744 install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000745 install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
746 install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
747 install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
748 install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
749 install_element (RIP_NODE, &rip_default_information_originate_cmd);
750 install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
751}