blob: 7729d9b472679e7261cc51df362627ef4b4853e1 [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;
49 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
50 api.nexthop_num = 1;
51 api.nexthop = &nexthop;
52 api.ifindex_num = 0;
53 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
54 api.metric = metric;
55
56 if (distance && distance != ZEBRA_RIP_DISTANCE_DEFAULT)
57 {
58 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
59 api.distance = distance;
60 }
61
paul0a589352004-05-08 11:48:26 +000062 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api);
paul718e3742002-12-13 20:15:29 +000063
64 rip_global_route_changes++;
65 }
66}
67
68void
69rip_zebra_ipv4_delete (struct prefix_ipv4 *p, struct in_addr *nexthop,
70 u_int32_t metric)
71{
72 struct zapi_ipv4 api;
73
74 if (zclient->redist[ZEBRA_ROUTE_RIP])
75 {
76 api.type = ZEBRA_ROUTE_RIP;
77 api.flags = 0;
78 api.message = 0;
79 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
80 api.nexthop_num = 1;
81 api.nexthop = &nexthop;
82 api.ifindex_num = 0;
83 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
84 api.metric = metric;
85
paul0a589352004-05-08 11:48:26 +000086 zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api);
paul718e3742002-12-13 20:15:29 +000087
88 rip_global_route_changes++;
89 }
90}
91
92/* Zebra route add and delete treatment. */
pauldc63bfd2005-10-25 23:31:05 +000093static int
paul718e3742002-12-13 20:15:29 +000094rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length)
95{
96 struct stream *s;
97 struct zapi_ipv4 api;
98 unsigned long ifindex;
99 struct in_addr nexthop;
100 struct prefix_ipv4 p;
101
102 s = zclient->ibuf;
103 ifindex = 0;
104 nexthop.s_addr = 0;
105
106 /* Type, flags, message. */
107 api.type = stream_getc (s);
108 api.flags = stream_getc (s);
109 api.message = stream_getc (s);
110
111 /* IPv4 prefix. */
112 memset (&p, 0, sizeof (struct prefix_ipv4));
113 p.family = AF_INET;
114 p.prefixlen = stream_getc (s);
115 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
116
117 /* Nexthop, ifindex, distance, metric. */
118 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
119 {
120 api.nexthop_num = stream_getc (s);
121 nexthop.s_addr = stream_get_ipv4 (s);
122 }
123 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
124 {
125 api.ifindex_num = stream_getc (s);
126 ifindex = stream_getl (s);
127 }
128 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
129 api.distance = stream_getc (s);
vincentfbf5d032005-09-29 11:25:50 +0000130 else
131 api.distance = 255;
paul718e3742002-12-13 20:15:29 +0000132 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
133 api.metric = stream_getl (s);
vincentfbf5d032005-09-29 11:25:50 +0000134 else
135 api.metric = 0;
paul718e3742002-12-13 20:15:29 +0000136
137 /* Then fetch IPv4 prefixes. */
138 if (command == ZEBRA_IPV4_ROUTE_ADD)
vincentfbf5d032005-09-29 11:25:50 +0000139 rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
140 &nexthop, api.metric, api.distance);
paul718e3742002-12-13 20:15:29 +0000141 else
142 rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
143
144 return 0;
145}
146
147void
pauldc63bfd2005-10-25 23:31:05 +0000148rip_zclient_reset (void)
paul718e3742002-12-13 20:15:29 +0000149{
150 zclient_reset (zclient);
151}
152
153/* RIP route-map set for redistribution */
pauldc63bfd2005-10-25 23:31:05 +0000154static void
hasso98b718a2004-10-11 12:57:57 +0000155rip_routemap_set (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000156{
157 if (rip->route_map[type].name)
158 free(rip->route_map[type].name);
159
160 rip->route_map[type].name = strdup (name);
161 rip->route_map[type].map = route_map_lookup_by_name (name);
162}
163
pauldc63bfd2005-10-25 23:31:05 +0000164static void
hasso8a676be2004-10-08 06:36:38 +0000165rip_redistribute_metric_set (int type, unsigned int metric)
paul718e3742002-12-13 20:15:29 +0000166{
167 rip->route_map[type].metric_config = 1;
168 rip->route_map[type].metric = metric;
169}
170
pauldc63bfd2005-10-25 23:31:05 +0000171static int
hasso8a676be2004-10-08 06:36:38 +0000172rip_metric_unset (int type, unsigned int metric)
paul718e3742002-12-13 20:15:29 +0000173{
174#define DONT_CARE_METRIC_RIP 17
175 if (metric != DONT_CARE_METRIC_RIP &&
176 rip->route_map[type].metric != metric)
177 return 1;
178 rip->route_map[type].metric_config = 0;
179 rip->route_map[type].metric = 0;
180 return 0;
181}
182
183/* RIP route-map unset for redistribution */
pauldc63bfd2005-10-25 23:31:05 +0000184static int
hasso98b718a2004-10-11 12:57:57 +0000185rip_routemap_unset (int type, const char *name)
paul718e3742002-12-13 20:15:29 +0000186{
187 if (! rip->route_map[type].name ||
188 (name != NULL && strcmp(rip->route_map[type].name,name)))
189 return 1;
190
191 free (rip->route_map[type].name);
192 rip->route_map[type].name = NULL;
193 rip->route_map[type].map = NULL;
194
195 return 0;
196}
197
198/* Redistribution types */
199static struct {
200 int type;
201 int str_min_len;
hasso8a676be2004-10-08 06:36:38 +0000202 const char *str;
paul718e3742002-12-13 20:15:29 +0000203} redist_type[] = {
204 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
205 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
206 {ZEBRA_ROUTE_STATIC, 1, "static"},
207 {ZEBRA_ROUTE_OSPF, 1, "ospf"},
208 {ZEBRA_ROUTE_BGP, 1, "bgp"},
209 {0, 0, NULL}
210};
211
212DEFUN (router_zebra,
213 router_zebra_cmd,
214 "router zebra",
215 "Enable a routing process\n"
216 "Make connection to zebra daemon\n")
217{
218 vty->node = ZEBRA_NODE;
219 zclient->enable = 1;
220 zclient_start (zclient);
221 return CMD_SUCCESS;
222}
223
224DEFUN (no_router_zebra,
225 no_router_zebra_cmd,
226 "no router zebra",
227 NO_STR
228 "Enable a routing process\n"
229 "Make connection to zebra daemon\n")
230{
231 zclient->enable = 0;
232 zclient_stop (zclient);
233 return CMD_SUCCESS;
234}
235
pauldc63bfd2005-10-25 23:31:05 +0000236static int
paul718e3742002-12-13 20:15:29 +0000237rip_redistribute_set (int type)
238{
239 if (zclient->redist[type])
240 return CMD_SUCCESS;
241
242 zclient->redist[type] = 1;
243
244 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000245 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
paul718e3742002-12-13 20:15:29 +0000246
247 return CMD_SUCCESS;
248}
249
pauldc63bfd2005-10-25 23:31:05 +0000250static int
paul718e3742002-12-13 20:15:29 +0000251rip_redistribute_unset (int type)
252{
253 if (! zclient->redist[type])
254 return CMD_SUCCESS;
255
256 zclient->redist[type] = 0;
257
258 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000259 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
paul718e3742002-12-13 20:15:29 +0000260
261 /* Remove the routes from RIP table. */
262 rip_redistribute_withdraw (type);
263
264 return CMD_SUCCESS;
265}
266
267int
268rip_redistribute_check (int type)
269{
270 return (zclient->redist[type]);
271}
272
273void
pauldc63bfd2005-10-25 23:31:05 +0000274rip_redistribute_clean (void)
paul718e3742002-12-13 20:15:29 +0000275{
276 int i;
277
278 for (i = 0; redist_type[i].str; i++)
279 {
280 if (zclient->redist[redist_type[i].type])
281 {
282 if (zclient->sock > 0)
283 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
ajs634f9ea2005-04-11 15:51:40 +0000284 zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000285
286 zclient->redist[redist_type[i].type] = 0;
287
288 /* Remove the routes from RIP table. */
289 rip_redistribute_withdraw (redist_type[i].type);
290 }
291 }
292}
293
294DEFUN (rip_redistribute_rip,
295 rip_redistribute_rip_cmd,
296 "redistribute rip",
297 "Redistribute information from another routing protocol\n"
298 "Routing Information Protocol (RIP)\n")
299{
300 zclient->redist[ZEBRA_ROUTE_RIP] = 1;
301 return CMD_SUCCESS;
302}
303
304DEFUN (no_rip_redistribute_rip,
305 no_rip_redistribute_rip_cmd,
306 "no redistribute rip",
307 NO_STR
308 "Redistribute information from another routing protocol\n"
309 "Routing Information Protocol (RIP)\n")
310{
311 zclient->redist[ZEBRA_ROUTE_RIP] = 0;
312 return CMD_SUCCESS;
313}
314
315DEFUN (rip_redistribute_type,
316 rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000317 "redistribute " QUAGGA_REDIST_STR_RIPD,
318 REDIST_STR
319 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000320{
321 int i;
322
323 for(i = 0; redist_type[i].str; i++)
324 {
325 if (strncmp (redist_type[i].str, argv[0],
326 redist_type[i].str_min_len) == 0)
327 {
paul0a589352004-05-08 11:48:26 +0000328 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
329 redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000330 return CMD_SUCCESS;
331 }
332 }
333
334 vty_out(vty, "Invalid type %s%s", argv[0],
335 VTY_NEWLINE);
336
337 return CMD_WARNING;
338}
339
340DEFUN (no_rip_redistribute_type,
341 no_rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000342 "no redistribute " QUAGGA_REDIST_STR_RIPD,
paul718e3742002-12-13 20:15:29 +0000343 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000344 REDIST_STR
345 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000346{
347 int i;
348
349 for (i = 0; redist_type[i].str; i++)
350 {
351 if (strncmp(redist_type[i].str, argv[0],
352 redist_type[i].str_min_len) == 0)
353 {
354 rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP);
355 rip_routemap_unset (redist_type[i].type,NULL);
356 rip_redistribute_unset (redist_type[i].type);
357 return CMD_SUCCESS;
358 }
359 }
360
361 vty_out(vty, "Invalid type %s%s", argv[0],
362 VTY_NEWLINE);
363
364 return CMD_WARNING;
365}
366
367DEFUN (rip_redistribute_type_routemap,
368 rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000369 "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
370 REDIST_STR
371 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000372 "Route map reference\n"
373 "Pointer to route-map entries\n")
374{
375 int i;
376
377 for (i = 0; redist_type[i].str; i++) {
378 if (strncmp(redist_type[i].str, argv[0],
379 redist_type[i].str_min_len) == 0)
380 {
381 rip_routemap_set (redist_type[i].type, argv[1]);
paul0a589352004-05-08 11:48:26 +0000382 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000383 return CMD_SUCCESS;
384 }
385 }
386
387 vty_out(vty, "Invalid type %s%s", argv[0],
388 VTY_NEWLINE);
389
390 return CMD_WARNING;
391}
392
393DEFUN (no_rip_redistribute_type_routemap,
394 no_rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000395 "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000396 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000397 REDIST_STR
398 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000399 "Route map reference\n"
400 "Pointer to route-map entries\n")
401{
402 int i;
403
404 for (i = 0; redist_type[i].str; i++)
405 {
406 if (strncmp(redist_type[i].str, argv[0],
407 redist_type[i].str_min_len) == 0)
408 {
409 if (rip_routemap_unset (redist_type[i].type,argv[1]))
410 return CMD_WARNING;
411 rip_redistribute_unset (redist_type[i].type);
412 return CMD_SUCCESS;
413 }
414 }
415
416 vty_out(vty, "Invalid type %s%s", argv[0],
417 VTY_NEWLINE);
418
419 return CMD_WARNING;
420}
421
422DEFUN (rip_redistribute_type_metric,
423 rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000424 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
425 REDIST_STR
426 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000427 "Metric\n"
428 "Metric value\n")
429{
430 int i;
431 int metric;
432
433 metric = atoi (argv[1]);
434
435 for (i = 0; redist_type[i].str; i++) {
436 if (strncmp(redist_type[i].str, argv[0],
437 redist_type[i].str_min_len) == 0)
438 {
439 rip_redistribute_metric_set (redist_type[i].type, metric);
paul0a589352004-05-08 11:48:26 +0000440 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000441 return CMD_SUCCESS;
442 }
443 }
444
445 vty_out(vty, "Invalid type %s%s", argv[0],
446 VTY_NEWLINE);
447
448 return CMD_WARNING;
449}
450
451DEFUN (no_rip_redistribute_type_metric,
452 no_rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000453 "no redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000454 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000455 REDIST_STR
456 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000457 "Metric\n"
458 "Metric value\n")
459{
460 int i;
461
462 for (i = 0; redist_type[i].str; i++)
463 {
464 if (strncmp(redist_type[i].str, argv[0],
465 redist_type[i].str_min_len) == 0)
466 {
467 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
468 return CMD_WARNING;
469 rip_redistribute_unset (redist_type[i].type);
470 return CMD_SUCCESS;
471 }
472 }
473
474 vty_out(vty, "Invalid type %s%s", argv[0],
475 VTY_NEWLINE);
476
477 return CMD_WARNING;
478}
479
hasso16705132003-05-25 14:49:19 +0000480DEFUN (rip_redistribute_type_metric_routemap,
481 rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000482 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16> route-map WORD",
483 REDIST_STR
484 QUAGGA_REDIST_HELP_STR_RIPD
hasso16705132003-05-25 14:49:19 +0000485 "Metric\n"
486 "Metric value\n"
487 "Route map reference\n"
488 "Pointer to route-map entries\n")
489{
490 int i;
491 int metric;
492
493 metric = atoi (argv[1]);
494
495 for (i = 0; redist_type[i].str; i++) {
496 if (strncmp(redist_type[i].str, argv[0],
497 redist_type[i].str_min_len) == 0)
498 {
499 rip_redistribute_metric_set (redist_type[i].type, metric);
500 rip_routemap_set (redist_type[i].type, argv[2]);
paul0a589352004-05-08 11:48:26 +0000501 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
hasso16705132003-05-25 14:49:19 +0000502 return CMD_SUCCESS;
503 }
504 }
505
506 vty_out(vty, "Invalid type %s%s", argv[0],
507 VTY_NEWLINE);
508
509 return CMD_WARNING;
510}
511
512
paul718e3742002-12-13 20:15:29 +0000513DEFUN (no_rip_redistribute_type_metric_routemap,
514 no_rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000515 "no redistribute " QUAGGA_REDIST_STR_RIPD
516 " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000517 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000518 REDIST_STR
519 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000520 "Metric\n"
521 "Metric value\n"
522 "Route map reference\n"
523 "Pointer to route-map entries\n")
524{
525 int i;
526
527 for (i = 0; redist_type[i].str; i++)
528 {
529 if (strncmp(redist_type[i].str, argv[0],
530 redist_type[i].str_min_len) == 0)
531 {
532 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
533 return CMD_WARNING;
534 if (rip_routemap_unset (redist_type[i].type, argv[2]))
535 {
536 rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1]));
537 return CMD_WARNING;
538 }
539 rip_redistribute_unset (redist_type[i].type);
540 return CMD_SUCCESS;
541 }
542 }
543
544 vty_out(vty, "Invalid type %s%s", argv[0],
545 VTY_NEWLINE);
546
547 return CMD_WARNING;
548}
549
550/* Default information originate. */
551
552DEFUN (rip_default_information_originate,
553 rip_default_information_originate_cmd,
554 "default-information originate",
555 "Control distribution of default route\n"
556 "Distribute a default route\n")
557{
558 struct prefix_ipv4 p;
559
560 if (! rip->default_information)
561 {
562 memset (&p, 0, sizeof (struct prefix_ipv4));
563 p.family = AF_INET;
564
565 rip->default_information = 1;
566
vincentfbf5d032005-09-29 11:25:50 +0000567 rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
568 NULL, 0, 0);
paul718e3742002-12-13 20:15:29 +0000569 }
570
571 return CMD_SUCCESS;
572}
573
574DEFUN (no_rip_default_information_originate,
575 no_rip_default_information_originate_cmd,
576 "no default-information originate",
577 NO_STR
578 "Control distribution of default route\n"
579 "Distribute a default route\n")
580{
581 struct prefix_ipv4 p;
582
583 if (rip->default_information)
584 {
585 memset (&p, 0, sizeof (struct prefix_ipv4));
586 p.family = AF_INET;
587
588 rip->default_information = 0;
589
hasso16705132003-05-25 14:49:19 +0000590 rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
paul718e3742002-12-13 20:15:29 +0000591 }
592
593 return CMD_SUCCESS;
594}
595
596/* RIP configuration write function. */
pauldc63bfd2005-10-25 23:31:05 +0000597static int
paul718e3742002-12-13 20:15:29 +0000598config_write_zebra (struct vty *vty)
599{
600 if (! zclient->enable)
601 {
602 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
603 return 1;
604 }
605 else if (! zclient->redist[ZEBRA_ROUTE_RIP])
606 {
607 vty_out (vty, "router zebra%s", VTY_NEWLINE);
608 vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
609 return 1;
610 }
611 return 0;
612}
613
614int
615config_write_rip_redistribute (struct vty *vty, int config_mode)
616{
617 int i;
paul718e3742002-12-13 20:15:29 +0000618
619 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
620 if (i != zclient->redist_default && zclient->redist[i])
621 {
622 if (config_mode)
623 {
624 if (rip->route_map[i].metric_config)
625 {
626 if (rip->route_map[i].name)
627 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000628 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000629 rip->route_map[i].name,
630 VTY_NEWLINE);
631 else
632 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000633 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000634 VTY_NEWLINE);
635 }
636 else
637 {
638 if (rip->route_map[i].name)
639 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000640 zebra_route_string(i), rip->route_map[i].name,
paul718e3742002-12-13 20:15:29 +0000641 VTY_NEWLINE);
642 else
ajsf52d13c2005-10-01 17:38:06 +0000643 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
paul718e3742002-12-13 20:15:29 +0000644 VTY_NEWLINE);
645 }
646 }
647 else
ajsf52d13c2005-10-01 17:38:06 +0000648 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000649 }
650 return 0;
651}
652
653/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800654static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000655{
656 ZEBRA_NODE,
657 "%s(config-router)# ",
658};
659
660void
661rip_zclient_init ()
662{
663 /* Set default value to the zebra client structure. */
664 zclient = zclient_new ();
665 zclient_init (zclient, ZEBRA_ROUTE_RIP);
666 zclient->interface_add = rip_interface_add;
667 zclient->interface_delete = rip_interface_delete;
668 zclient->interface_address_add = rip_interface_address_add;
669 zclient->interface_address_delete = rip_interface_address_delete;
670 zclient->ipv4_route_add = rip_zebra_read_ipv4;
671 zclient->ipv4_route_delete = rip_zebra_read_ipv4;
672 zclient->interface_up = rip_interface_up;
673 zclient->interface_down = rip_interface_down;
674
675 /* Install zebra node. */
676 install_node (&zebra_node, config_write_zebra);
677
678 /* Install command elements to zebra node. */
679 install_element (CONFIG_NODE, &router_zebra_cmd);
680 install_element (CONFIG_NODE, &no_router_zebra_cmd);
681 install_default (ZEBRA_NODE);
682 install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
683 install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
684
685 /* Install command elements to rip node. */
686 install_element (RIP_NODE, &rip_redistribute_type_cmd);
687 install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
688 install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
hasso16705132003-05-25 14:49:19 +0000689 install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000690 install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
691 install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
692 install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
693 install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
694 install_element (RIP_NODE, &rip_default_information_originate_cmd);
695 install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
696}