blob: 1d10b10372ef9663833ef7ee09f31189ec63941a [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"
26#include "stream.h"
27#include "routemap.h"
28#include "zclient.h"
29#include "log.h"
30#include "ripd/ripd.h"
31#include "ripd/rip_debug.h"
pauldc63bfd2005-10-25 23:31:05 +000032#include "ripd/rip_interface.h"
paul718e3742002-12-13 20:15:29 +000033
34/* All information about zebra. */
35struct zclient *zclient = NULL;
paul718e3742002-12-13 20:15:29 +000036
37/* RIPd to zebra command interface. */
38void
39rip_zebra_ipv4_add (struct prefix_ipv4 *p, struct in_addr *nexthop,
40 u_int32_t metric, u_char distance)
41{
42 struct zapi_ipv4 api;
43
44 if (zclient->redist[ZEBRA_ROUTE_RIP])
45 {
46 api.type = ZEBRA_ROUTE_RIP;
47 api.flags = 0;
48 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +040049 api.safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +000050 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
51 api.nexthop_num = 1;
52 api.nexthop = &nexthop;
53 api.ifindex_num = 0;
54 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
55 api.metric = metric;
56
57 if (distance && distance != ZEBRA_RIP_DISTANCE_DEFAULT)
58 {
59 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
60 api.distance = distance;
61 }
62
paul0a589352004-05-08 11:48:26 +000063 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api);
paul718e3742002-12-13 20:15:29 +000064
65 rip_global_route_changes++;
66 }
67}
68
69void
70rip_zebra_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *nexthop,
71 u_int32_t metric)
72{
73 struct zapi_ipv4 api;
74
75 if (zclient->redist[ZEBRA_ROUTE_RIP])
76 {
77 api.type = ZEBRA_ROUTE_RIP;
78 api.flags = 0;
79 api.message = 0;
Denis Ovsienkob4e45f62011-12-05 16:35:14 +040080 api.safi = SAFI_UNICAST;
paul718e3742002-12-13 20:15:29 +000081 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
82 api.nexthop_num = 1;
83 api.nexthop = &nexthop;
84 api.ifindex_num = 0;
85 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
86 api.metric = metric;
87
paul0a589352004-05-08 11:48:26 +000088 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api);
paul718e3742002-12-13 20:15:29 +000089
90 rip_global_route_changes++;
91 }
92}
93
94/* Zebra route add and delete treatment. */
pauldc63bfd2005-10-25 23:31:05 +000095static int
paul718e3742002-12-13 20:15:29 +000096rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length)
97{
98 struct stream *s;
99 struct zapi_ipv4 api;
100 unsigned long ifindex;
101 struct in_addr nexthop;
102 struct prefix_ipv4 p;
103
104 s = zclient->ibuf;
105 ifindex = 0;
106 nexthop.s_addr = 0;
107
108 /* Type, flags, message. */
109 api.type = stream_getc (s);
110 api.flags = stream_getc (s);
111 api.message = stream_getc (s);
112
113 /* IPv4 prefix. */
114 memset (&p, 0, sizeof (struct prefix_ipv4));
115 p.family = AF_INET;
116 p.prefixlen = stream_getc (s);
117 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
118
119 /* Nexthop, ifindex, distance, metric. */
120 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
121 {
122 api.nexthop_num = stream_getc (s);
123 nexthop.s_addr = stream_get_ipv4 (s);
124 }
125 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
126 {
127 api.ifindex_num = stream_getc (s);
128 ifindex = stream_getl (s);
129 }
130 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
131 api.distance = stream_getc (s);
vincentfbf5d032005-09-29 11:25:50 +0000132 else
133 api.distance = 255;
paul718e3742002-12-13 20:15:29 +0000134 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
135 api.metric = stream_getl (s);
vincentfbf5d032005-09-29 11:25:50 +0000136 else
137 api.metric = 0;
paul718e3742002-12-13 20:15:29 +0000138
139 /* Then fetch IPv4 prefixes. */
140 if (command == ZEBRA_IPV4_ROUTE_ADD)
vincentfbf5d032005-09-29 11:25:50 +0000141 rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
142 &nexthop, api.metric, api.distance);
paul718e3742002-12-13 20:15:29 +0000143 else
144 rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
145
146 return 0;
147}
148
149void
pauldc63bfd2005-10-25 23:31:05 +0000150rip_zclient_reset (void)
paul718e3742002-12-13 20:15:29 +0000151{
152 zclient_reset (zclient);
153}
154
155/* RIP route-map set for redistribution */
pauldc63bfd2005-10-25 23:31:05 +0000156static void
hasso98b718a2004-10-11 12:57:57 +0000157rip_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000158{
159 if (rip->route_map[type].name)
160 free(rip->route_map[type].name);
161
162 rip->route_map[type].name = strdup (name);
163 rip->route_map[type].map = route_map_lookup_by_name (name);
164}
165
pauldc63bfd2005-10-25 23:31:05 +0000166static void
hasso8a676be2004-10-08 06:36:38 +0000167rip_redistribute_metric_set (int type, unsigned int metric)
paul718e3742002-12-13 20:15:29 +0000168{
169 rip->route_map[type].metric_config = 1;
170 rip->route_map[type].metric = metric;
171}
172
pauldc63bfd2005-10-25 23:31:05 +0000173static int
hasso8a676be2004-10-08 06:36:38 +0000174rip_metric_unset (int type, unsigned int metric)
paul718e3742002-12-13 20:15:29 +0000175{
176#define DONT_CARE_METRIC_RIP 17
177 if (metric != DONT_CARE_METRIC_RIP &&
178 rip->route_map[type].metric != metric)
179 return 1;
180 rip->route_map[type].metric_config = 0;
181 rip->route_map[type].metric = 0;
182 return 0;
183}
184
185/* RIP route-map unset for redistribution */
pauldc63bfd2005-10-25 23:31:05 +0000186static int
hasso98b718a2004-10-11 12:57:57 +0000187rip_routemap_unset (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000188{
189 if (! rip->route_map[type].name ||
190 (name != NULL && strcmp(rip->route_map[type].name,name)))
191 return 1;
192
193 free (rip->route_map[type].name);
194 rip->route_map[type].name = NULL;
195 rip->route_map[type].map = NULL;
196
197 return 0;
198}
199
200/* Redistribution types */
201static struct {
202 int type;
203 int str_min_len;
hasso8a676be2004-10-08 06:36:38 +0000204 const char *str;
paul718e3742002-12-13 20:15:29 +0000205} redist_type[] = {
206 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
207 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
208 {ZEBRA_ROUTE_STATIC, 1, "static"},
209 {ZEBRA_ROUTE_OSPF, 1, "ospf"},
210 {ZEBRA_ROUTE_BGP, 1, "bgp"},
211 {0, 0, NULL}
212};
213
214DEFUN (router_zebra,
215 router_zebra_cmd,
216 "router zebra",
217 "Enable a routing process\n"
218 "Make connection to zebra daemon\n")
219{
220 vty->node = ZEBRA_NODE;
221 zclient->enable = 1;
222 zclient_start (zclient);
223 return CMD_SUCCESS;
224}
225
226DEFUN (no_router_zebra,
227 no_router_zebra_cmd,
228 "no router zebra",
229 NO_STR
230 "Enable a routing process\n"
231 "Make connection to zebra daemon\n")
232{
233 zclient->enable = 0;
234 zclient_stop (zclient);
235 return CMD_SUCCESS;
236}
237
Stephen Hemminger2c239702009-12-10 19:16:05 +0300238#if 0
pauldc63bfd2005-10-25 23:31:05 +0000239static int
paul718e3742002-12-13 20:15:29 +0000240rip_redistribute_set (int type)
241{
242 if (zclient->redist[type])
243 return CMD_SUCCESS;
244
245 zclient->redist[type] = 1;
246
247 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000248 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
paul718e3742002-12-13 20:15:29 +0000249
250 return CMD_SUCCESS;
251}
Stephen Hemminger2c239702009-12-10 19:16:05 +0300252#endif
paul718e3742002-12-13 20:15:29 +0000253
pauldc63bfd2005-10-25 23:31:05 +0000254static int
paul718e3742002-12-13 20:15:29 +0000255rip_redistribute_unset (int type)
256{
257 if (! zclient->redist[type])
258 return CMD_SUCCESS;
259
260 zclient->redist[type] = 0;
261
262 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000263 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
paul718e3742002-12-13 20:15:29 +0000264
265 /* Remove the routes from RIP table. */
266 rip_redistribute_withdraw (type);
267
268 return CMD_SUCCESS;
269}
270
271int
272rip_redistribute_check (int type)
273{
274 return (zclient->redist[type]);
275}
276
277void
pauldc63bfd2005-10-25 23:31:05 +0000278rip_redistribute_clean (void)
paul718e3742002-12-13 20:15:29 +0000279{
280 int i;
281
282 for (i = 0; redist_type[i].str; i++)
283 {
284 if (zclient->redist[redist_type[i].type])
285 {
286 if (zclient->sock > 0)
287 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
ajs634f9ea2005-04-11 15:51:40 +0000288 zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000289
290 zclient->redist[redist_type[i].type] = 0;
291
292 /* Remove the routes from RIP table. */
293 rip_redistribute_withdraw (redist_type[i].type);
294 }
295 }
296}
297
298DEFUN (rip_redistribute_rip,
299 rip_redistribute_rip_cmd,
300 "redistribute rip",
301 "Redistribute information from another routing protocol\n"
302 "Routing Information Protocol (RIP)\n")
303{
304 zclient->redist[ZEBRA_ROUTE_RIP] = 1;
305 return CMD_SUCCESS;
306}
307
308DEFUN (no_rip_redistribute_rip,
309 no_rip_redistribute_rip_cmd,
310 "no redistribute rip",
311 NO_STR
312 "Redistribute information from another routing protocol\n"
313 "Routing Information Protocol (RIP)\n")
314{
315 zclient->redist[ZEBRA_ROUTE_RIP] = 0;
316 return CMD_SUCCESS;
317}
318
319DEFUN (rip_redistribute_type,
320 rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000321 "redistribute " QUAGGA_REDIST_STR_RIPD,
322 REDIST_STR
323 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000324{
325 int i;
326
327 for(i = 0; redist_type[i].str; i++)
328 {
329 if (strncmp (redist_type[i].str, argv[0],
330 redist_type[i].str_min_len) == 0)
331 {
paul0a589352004-05-08 11:48:26 +0000332 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
333 redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000334 return CMD_SUCCESS;
335 }
336 }
337
338 vty_out(vty, "Invalid type %s%s", argv[0],
339 VTY_NEWLINE);
340
341 return CMD_WARNING;
342}
343
344DEFUN (no_rip_redistribute_type,
345 no_rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000346 "no redistribute " QUAGGA_REDIST_STR_RIPD,
paul718e3742002-12-13 20:15:29 +0000347 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000348 REDIST_STR
349 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000350{
351 int i;
352
353 for (i = 0; redist_type[i].str; i++)
354 {
355 if (strncmp(redist_type[i].str, argv[0],
356 redist_type[i].str_min_len) == 0)
357 {
358 rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP);
359 rip_routemap_unset (redist_type[i].type,NULL);
360 rip_redistribute_unset (redist_type[i].type);
361 return CMD_SUCCESS;
362 }
363 }
364
365 vty_out(vty, "Invalid type %s%s", argv[0],
366 VTY_NEWLINE);
367
368 return CMD_WARNING;
369}
370
371DEFUN (rip_redistribute_type_routemap,
372 rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000373 "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
374 REDIST_STR
375 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000376 "Route map reference\n"
377 "Pointer to route-map entries\n")
378{
379 int i;
380
381 for (i = 0; redist_type[i].str; i++) {
382 if (strncmp(redist_type[i].str, argv[0],
383 redist_type[i].str_min_len) == 0)
384 {
385 rip_routemap_set (redist_type[i].type, argv[1]);
paul0a589352004-05-08 11:48:26 +0000386 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000387 return CMD_SUCCESS;
388 }
389 }
390
391 vty_out(vty, "Invalid type %s%s", argv[0],
392 VTY_NEWLINE);
393
394 return CMD_WARNING;
395}
396
397DEFUN (no_rip_redistribute_type_routemap,
398 no_rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000399 "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000400 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000401 REDIST_STR
402 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000403 "Route map reference\n"
404 "Pointer to route-map entries\n")
405{
406 int i;
407
408 for (i = 0; redist_type[i].str; i++)
409 {
410 if (strncmp(redist_type[i].str, argv[0],
411 redist_type[i].str_min_len) == 0)
412 {
413 if (rip_routemap_unset (redist_type[i].type,argv[1]))
414 return CMD_WARNING;
415 rip_redistribute_unset (redist_type[i].type);
416 return CMD_SUCCESS;
417 }
418 }
419
420 vty_out(vty, "Invalid type %s%s", argv[0],
421 VTY_NEWLINE);
422
423 return CMD_WARNING;
424}
425
426DEFUN (rip_redistribute_type_metric,
427 rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000428 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
429 REDIST_STR
430 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000431 "Metric\n"
432 "Metric value\n")
433{
434 int i;
435 int metric;
436
437 metric = atoi (argv[1]);
438
439 for (i = 0; redist_type[i].str; i++) {
440 if (strncmp(redist_type[i].str, argv[0],
441 redist_type[i].str_min_len) == 0)
442 {
443 rip_redistribute_metric_set (redist_type[i].type, metric);
paul0a589352004-05-08 11:48:26 +0000444 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000445 return CMD_SUCCESS;
446 }
447 }
448
449 vty_out(vty, "Invalid type %s%s", argv[0],
450 VTY_NEWLINE);
451
452 return CMD_WARNING;
453}
454
455DEFUN (no_rip_redistribute_type_metric,
456 no_rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000457 "no redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000458 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000459 REDIST_STR
460 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000461 "Metric\n"
462 "Metric value\n")
463{
464 int i;
465
466 for (i = 0; redist_type[i].str; i++)
467 {
468 if (strncmp(redist_type[i].str, argv[0],
469 redist_type[i].str_min_len) == 0)
470 {
471 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
472 return CMD_WARNING;
473 rip_redistribute_unset (redist_type[i].type);
474 return CMD_SUCCESS;
475 }
476 }
477
478 vty_out(vty, "Invalid type %s%s", argv[0],
479 VTY_NEWLINE);
480
481 return CMD_WARNING;
482}
483
hasso16705132003-05-25 14:49:19 +0000484DEFUN (rip_redistribute_type_metric_routemap,
485 rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000486 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16> route-map WORD",
487 REDIST_STR
488 QUAGGA_REDIST_HELP_STR_RIPD
hasso16705132003-05-25 14:49:19 +0000489 "Metric\n"
490 "Metric value\n"
491 "Route map reference\n"
492 "Pointer to route-map entries\n")
493{
494 int i;
495 int metric;
496
497 metric = atoi (argv[1]);
498
499 for (i = 0; redist_type[i].str; i++) {
500 if (strncmp(redist_type[i].str, argv[0],
501 redist_type[i].str_min_len) == 0)
502 {
503 rip_redistribute_metric_set (redist_type[i].type, metric);
504 rip_routemap_set (redist_type[i].type, argv[2]);
paul0a589352004-05-08 11:48:26 +0000505 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
hasso16705132003-05-25 14:49:19 +0000506 return CMD_SUCCESS;
507 }
508 }
509
510 vty_out(vty, "Invalid type %s%s", argv[0],
511 VTY_NEWLINE);
512
513 return CMD_WARNING;
514}
515
516
paul718e3742002-12-13 20:15:29 +0000517DEFUN (no_rip_redistribute_type_metric_routemap,
518 no_rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000519 "no redistribute " QUAGGA_REDIST_STR_RIPD
520 " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000521 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000522 REDIST_STR
523 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000524 "Metric\n"
525 "Metric value\n"
526 "Route map reference\n"
527 "Pointer to route-map entries\n")
528{
529 int i;
530
531 for (i = 0; redist_type[i].str; i++)
532 {
533 if (strncmp(redist_type[i].str, argv[0],
534 redist_type[i].str_min_len) == 0)
535 {
536 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
537 return CMD_WARNING;
538 if (rip_routemap_unset (redist_type[i].type, argv[2]))
539 {
540 rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1]));
541 return CMD_WARNING;
542 }
543 rip_redistribute_unset (redist_type[i].type);
544 return CMD_SUCCESS;
545 }
546 }
547
548 vty_out(vty, "Invalid type %s%s", argv[0],
549 VTY_NEWLINE);
550
551 return CMD_WARNING;
552}
553
554/* Default information originate. */
555
556DEFUN (rip_default_information_originate,
557 rip_default_information_originate_cmd,
558 "default-information originate",
559 "Control distribution of default route\n"
560 "Distribute a default route\n")
561{
562 struct prefix_ipv4 p;
563
564 if (! rip->default_information)
565 {
566 memset (&p, 0, sizeof (struct prefix_ipv4));
567 p.family = AF_INET;
568
569 rip->default_information = 1;
570
vincentfbf5d032005-09-29 11:25:50 +0000571 rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
572 NULL, 0, 0);
paul718e3742002-12-13 20:15:29 +0000573 }
574
575 return CMD_SUCCESS;
576}
577
578DEFUN (no_rip_default_information_originate,
579 no_rip_default_information_originate_cmd,
580 "no default-information originate",
581 NO_STR
582 "Control distribution of default route\n"
583 "Distribute a default route\n")
584{
585 struct prefix_ipv4 p;
586
587 if (rip->default_information)
588 {
589 memset (&p, 0, sizeof (struct prefix_ipv4));
590 p.family = AF_INET;
591
592 rip->default_information = 0;
593
hasso16705132003-05-25 14:49:19 +0000594 rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
paul718e3742002-12-13 20:15:29 +0000595 }
596
597 return CMD_SUCCESS;
598}
599
600/* RIP configuration write function. */
pauldc63bfd2005-10-25 23:31:05 +0000601static int
paul718e3742002-12-13 20:15:29 +0000602config_write_zebra (struct vty *vty)
603{
604 if (! zclient->enable)
605 {
606 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
607 return 1;
608 }
609 else if (! zclient->redist[ZEBRA_ROUTE_RIP])
610 {
611 vty_out (vty, "router zebra%s", VTY_NEWLINE);
612 vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
613 return 1;
614 }
615 return 0;
616}
617
618int
619config_write_rip_redistribute (struct vty *vty, int config_mode)
620{
621 int i;
paul718e3742002-12-13 20:15:29 +0000622
623 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
624 if (i != zclient->redist_default && zclient->redist[i])
625 {
626 if (config_mode)
627 {
628 if (rip->route_map[i].metric_config)
629 {
630 if (rip->route_map[i].name)
631 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000632 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000633 rip->route_map[i].name,
634 VTY_NEWLINE);
635 else
636 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000637 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000638 VTY_NEWLINE);
639 }
640 else
641 {
642 if (rip->route_map[i].name)
643 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000644 zebra_route_string(i), rip->route_map[i].name,
paul718e3742002-12-13 20:15:29 +0000645 VTY_NEWLINE);
646 else
ajsf52d13c2005-10-01 17:38:06 +0000647 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
paul718e3742002-12-13 20:15:29 +0000648 VTY_NEWLINE);
649 }
650 }
651 else
ajsf52d13c2005-10-01 17:38:06 +0000652 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000653 }
654 return 0;
655}
656
657/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800658static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000659{
660 ZEBRA_NODE,
661 "%s(config-router)# ",
662};
663
664void
665rip_zclient_init ()
666{
667 /* Set default value to the zebra client structure. */
668 zclient = zclient_new ();
669 zclient_init (zclient, ZEBRA_ROUTE_RIP);
670 zclient->interface_add = rip_interface_add;
671 zclient->interface_delete = rip_interface_delete;
672 zclient->interface_address_add = rip_interface_address_add;
673 zclient->interface_address_delete = rip_interface_address_delete;
674 zclient->ipv4_route_add = rip_zebra_read_ipv4;
675 zclient->ipv4_route_delete = rip_zebra_read_ipv4;
676 zclient->interface_up = rip_interface_up;
677 zclient->interface_down = rip_interface_down;
678
679 /* Install zebra node. */
680 install_node (&zebra_node, config_write_zebra);
681
682 /* Install command elements to zebra node. */
683 install_element (CONFIG_NODE, &router_zebra_cmd);
684 install_element (CONFIG_NODE, &no_router_zebra_cmd);
685 install_default (ZEBRA_NODE);
686 install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
687 install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
688
689 /* Install command elements to rip node. */
690 install_element (RIP_NODE, &rip_redistribute_type_cmd);
691 install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
692 install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
hasso16705132003-05-25 14:49:19 +0000693 install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000694 install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
695 install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
696 install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
697 install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
698 install_element (RIP_NODE, &rip_default_information_originate_cmd);
699 install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
700}