blob: 199e85e8c2605362380714cf0d5ffa05cfce7785 [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"},
Matthieu Boutier9c58fbd2012-02-09 21:51:17 +0100210 {ZEBRA_ROUTE_BGP, 2, "bgp"},
211 {ZEBRA_ROUTE_BABEL, 2, "babel"},
paul718e3742002-12-13 20:15:29 +0000212 {0, 0, NULL}
213};
214
215DEFUN (router_zebra,
216 router_zebra_cmd,
217 "router zebra",
218 "Enable a routing process\n"
219 "Make connection to zebra daemon\n")
220{
221 vty->node = ZEBRA_NODE;
222 zclient->enable = 1;
223 zclient_start (zclient);
224 return CMD_SUCCESS;
225}
226
227DEFUN (no_router_zebra,
228 no_router_zebra_cmd,
229 "no router zebra",
230 NO_STR
231 "Enable a routing process\n"
232 "Make connection to zebra daemon\n")
233{
234 zclient->enable = 0;
235 zclient_stop (zclient);
236 return CMD_SUCCESS;
237}
238
Stephen Hemminger2c239702009-12-10 19:16:05 +0300239#if 0
pauldc63bfd2005-10-25 23:31:05 +0000240static int
paul718e3742002-12-13 20:15:29 +0000241rip_redistribute_set (int type)
242{
243 if (zclient->redist[type])
244 return CMD_SUCCESS;
245
246 zclient->redist[type] = 1;
247
248 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000249 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type);
paul718e3742002-12-13 20:15:29 +0000250
251 return CMD_SUCCESS;
252}
Stephen Hemminger2c239702009-12-10 19:16:05 +0300253#endif
paul718e3742002-12-13 20:15:29 +0000254
pauldc63bfd2005-10-25 23:31:05 +0000255static int
paul718e3742002-12-13 20:15:29 +0000256rip_redistribute_unset (int type)
257{
258 if (! zclient->redist[type])
259 return CMD_SUCCESS;
260
261 zclient->redist[type] = 0;
262
263 if (zclient->sock > 0)
ajs634f9ea2005-04-11 15:51:40 +0000264 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type);
paul718e3742002-12-13 20:15:29 +0000265
266 /* Remove the routes from RIP table. */
267 rip_redistribute_withdraw (type);
268
269 return CMD_SUCCESS;
270}
271
272int
273rip_redistribute_check (int type)
274{
275 return (zclient->redist[type]);
276}
277
278void
pauldc63bfd2005-10-25 23:31:05 +0000279rip_redistribute_clean (void)
paul718e3742002-12-13 20:15:29 +0000280{
281 int i;
282
283 for (i = 0; redist_type[i].str; i++)
284 {
285 if (zclient->redist[redist_type[i].type])
286 {
287 if (zclient->sock > 0)
288 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
ajs634f9ea2005-04-11 15:51:40 +0000289 zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000290
291 zclient->redist[redist_type[i].type] = 0;
292
293 /* Remove the routes from RIP table. */
294 rip_redistribute_withdraw (redist_type[i].type);
295 }
296 }
297}
298
299DEFUN (rip_redistribute_rip,
300 rip_redistribute_rip_cmd,
301 "redistribute rip",
302 "Redistribute information from another routing protocol\n"
303 "Routing Information Protocol (RIP)\n")
304{
305 zclient->redist[ZEBRA_ROUTE_RIP] = 1;
306 return CMD_SUCCESS;
307}
308
309DEFUN (no_rip_redistribute_rip,
310 no_rip_redistribute_rip_cmd,
311 "no redistribute rip",
312 NO_STR
313 "Redistribute information from another routing protocol\n"
314 "Routing Information Protocol (RIP)\n")
315{
316 zclient->redist[ZEBRA_ROUTE_RIP] = 0;
317 return CMD_SUCCESS;
318}
319
320DEFUN (rip_redistribute_type,
321 rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000322 "redistribute " QUAGGA_REDIST_STR_RIPD,
323 REDIST_STR
324 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000325{
326 int i;
327
328 for(i = 0; redist_type[i].str; i++)
329 {
330 if (strncmp (redist_type[i].str, argv[0],
331 redist_type[i].str_min_len) == 0)
332 {
paul0a589352004-05-08 11:48:26 +0000333 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
334 redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000335 return CMD_SUCCESS;
336 }
337 }
338
339 vty_out(vty, "Invalid type %s%s", argv[0],
340 VTY_NEWLINE);
341
342 return CMD_WARNING;
343}
344
345DEFUN (no_rip_redistribute_type,
346 no_rip_redistribute_type_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000347 "no redistribute " QUAGGA_REDIST_STR_RIPD,
paul718e3742002-12-13 20:15:29 +0000348 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000349 REDIST_STR
350 QUAGGA_REDIST_HELP_STR_RIPD)
paul718e3742002-12-13 20:15:29 +0000351{
352 int i;
353
354 for (i = 0; redist_type[i].str; i++)
355 {
356 if (strncmp(redist_type[i].str, argv[0],
357 redist_type[i].str_min_len) == 0)
358 {
359 rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP);
360 rip_routemap_unset (redist_type[i].type,NULL);
361 rip_redistribute_unset (redist_type[i].type);
362 return CMD_SUCCESS;
363 }
364 }
365
366 vty_out(vty, "Invalid type %s%s", argv[0],
367 VTY_NEWLINE);
368
369 return CMD_WARNING;
370}
371
372DEFUN (rip_redistribute_type_routemap,
373 rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000374 "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
375 REDIST_STR
376 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000377 "Route map reference\n"
378 "Pointer to route-map entries\n")
379{
380 int i;
381
382 for (i = 0; redist_type[i].str; i++) {
383 if (strncmp(redist_type[i].str, argv[0],
384 redist_type[i].str_min_len) == 0)
385 {
386 rip_routemap_set (redist_type[i].type, argv[1]);
paul0a589352004-05-08 11:48:26 +0000387 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000388 return CMD_SUCCESS;
389 }
390 }
391
392 vty_out(vty, "Invalid type %s%s", argv[0],
393 VTY_NEWLINE);
394
395 return CMD_WARNING;
396}
397
398DEFUN (no_rip_redistribute_type_routemap,
399 no_rip_redistribute_type_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000400 "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
paul718e3742002-12-13 20:15:29 +0000401 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000402 REDIST_STR
403 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000404 "Route map reference\n"
405 "Pointer to route-map entries\n")
406{
407 int i;
408
409 for (i = 0; redist_type[i].str; i++)
410 {
411 if (strncmp(redist_type[i].str, argv[0],
412 redist_type[i].str_min_len) == 0)
413 {
414 if (rip_routemap_unset (redist_type[i].type,argv[1]))
415 return CMD_WARNING;
416 rip_redistribute_unset (redist_type[i].type);
417 return CMD_SUCCESS;
418 }
419 }
420
421 vty_out(vty, "Invalid type %s%s", argv[0],
422 VTY_NEWLINE);
423
424 return CMD_WARNING;
425}
426
427DEFUN (rip_redistribute_type_metric,
428 rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000429 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
430 REDIST_STR
431 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000432 "Metric\n"
433 "Metric value\n")
434{
435 int i;
436 int metric;
437
438 metric = atoi (argv[1]);
439
440 for (i = 0; redist_type[i].str; i++) {
441 if (strncmp(redist_type[i].str, argv[0],
442 redist_type[i].str_min_len) == 0)
443 {
444 rip_redistribute_metric_set (redist_type[i].type, metric);
paul0a589352004-05-08 11:48:26 +0000445 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
paul718e3742002-12-13 20:15:29 +0000446 return CMD_SUCCESS;
447 }
448 }
449
450 vty_out(vty, "Invalid type %s%s", argv[0],
451 VTY_NEWLINE);
452
453 return CMD_WARNING;
454}
455
456DEFUN (no_rip_redistribute_type_metric,
457 no_rip_redistribute_type_metric_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000458 "no redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
paul718e3742002-12-13 20:15:29 +0000459 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000460 REDIST_STR
461 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000462 "Metric\n"
463 "Metric value\n")
464{
465 int i;
466
467 for (i = 0; redist_type[i].str; i++)
468 {
469 if (strncmp(redist_type[i].str, argv[0],
470 redist_type[i].str_min_len) == 0)
471 {
472 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
473 return CMD_WARNING;
474 rip_redistribute_unset (redist_type[i].type);
475 return CMD_SUCCESS;
476 }
477 }
478
479 vty_out(vty, "Invalid type %s%s", argv[0],
480 VTY_NEWLINE);
481
482 return CMD_WARNING;
483}
484
hasso16705132003-05-25 14:49:19 +0000485DEFUN (rip_redistribute_type_metric_routemap,
486 rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000487 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16> route-map WORD",
488 REDIST_STR
489 QUAGGA_REDIST_HELP_STR_RIPD
hasso16705132003-05-25 14:49:19 +0000490 "Metric\n"
491 "Metric value\n"
492 "Route map reference\n"
493 "Pointer to route-map entries\n")
494{
495 int i;
496 int metric;
497
498 metric = atoi (argv[1]);
499
500 for (i = 0; redist_type[i].str; i++) {
501 if (strncmp(redist_type[i].str, argv[0],
502 redist_type[i].str_min_len) == 0)
503 {
504 rip_redistribute_metric_set (redist_type[i].type, metric);
505 rip_routemap_set (redist_type[i].type, argv[2]);
paul0a589352004-05-08 11:48:26 +0000506 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type);
hasso16705132003-05-25 14:49:19 +0000507 return CMD_SUCCESS;
508 }
509 }
510
511 vty_out(vty, "Invalid type %s%s", argv[0],
512 VTY_NEWLINE);
513
514 return CMD_WARNING;
515}
516
517
paul718e3742002-12-13 20:15:29 +0000518DEFUN (no_rip_redistribute_type_metric_routemap,
519 no_rip_redistribute_type_metric_routemap_cmd,
Paul Jakma9a57dc62006-06-30 16:58:53 +0000520 "no redistribute " QUAGGA_REDIST_STR_RIPD
521 " metric <0-16> route-map WORD",
paul718e3742002-12-13 20:15:29 +0000522 NO_STR
Paul Jakma9a57dc62006-06-30 16:58:53 +0000523 REDIST_STR
524 QUAGGA_REDIST_HELP_STR_RIPD
paul718e3742002-12-13 20:15:29 +0000525 "Metric\n"
526 "Metric value\n"
527 "Route map reference\n"
528 "Pointer to route-map entries\n")
529{
530 int i;
531
532 for (i = 0; redist_type[i].str; i++)
533 {
534 if (strncmp(redist_type[i].str, argv[0],
535 redist_type[i].str_min_len) == 0)
536 {
537 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
538 return CMD_WARNING;
539 if (rip_routemap_unset (redist_type[i].type, argv[2]))
540 {
541 rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1]));
542 return CMD_WARNING;
543 }
544 rip_redistribute_unset (redist_type[i].type);
545 return CMD_SUCCESS;
546 }
547 }
548
549 vty_out(vty, "Invalid type %s%s", argv[0],
550 VTY_NEWLINE);
551
552 return CMD_WARNING;
553}
554
555/* Default information originate. */
556
557DEFUN (rip_default_information_originate,
558 rip_default_information_originate_cmd,
559 "default-information originate",
560 "Control distribution of default route\n"
561 "Distribute a default route\n")
562{
563 struct prefix_ipv4 p;
564
565 if (! rip->default_information)
566 {
567 memset (&p, 0, sizeof (struct prefix_ipv4));
568 p.family = AF_INET;
569
570 rip->default_information = 1;
571
vincentfbf5d032005-09-29 11:25:50 +0000572 rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
573 NULL, 0, 0);
paul718e3742002-12-13 20:15:29 +0000574 }
575
576 return CMD_SUCCESS;
577}
578
579DEFUN (no_rip_default_information_originate,
580 no_rip_default_information_originate_cmd,
581 "no default-information originate",
582 NO_STR
583 "Control distribution of default route\n"
584 "Distribute a default route\n")
585{
586 struct prefix_ipv4 p;
587
588 if (rip->default_information)
589 {
590 memset (&p, 0, sizeof (struct prefix_ipv4));
591 p.family = AF_INET;
592
593 rip->default_information = 0;
594
hasso16705132003-05-25 14:49:19 +0000595 rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
paul718e3742002-12-13 20:15:29 +0000596 }
597
598 return CMD_SUCCESS;
599}
600
601/* RIP configuration write function. */
pauldc63bfd2005-10-25 23:31:05 +0000602static int
paul718e3742002-12-13 20:15:29 +0000603config_write_zebra (struct vty *vty)
604{
605 if (! zclient->enable)
606 {
607 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
608 return 1;
609 }
610 else if (! zclient->redist[ZEBRA_ROUTE_RIP])
611 {
612 vty_out (vty, "router zebra%s", VTY_NEWLINE);
613 vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
614 return 1;
615 }
616 return 0;
617}
618
619int
620config_write_rip_redistribute (struct vty *vty, int config_mode)
621{
622 int i;
paul718e3742002-12-13 20:15:29 +0000623
624 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
625 if (i != zclient->redist_default && zclient->redist[i])
626 {
627 if (config_mode)
628 {
629 if (rip->route_map[i].metric_config)
630 {
631 if (rip->route_map[i].name)
632 vty_out (vty, " redistribute %s metric %d route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000633 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000634 rip->route_map[i].name,
635 VTY_NEWLINE);
636 else
637 vty_out (vty, " redistribute %s metric %d%s",
ajsf52d13c2005-10-01 17:38:06 +0000638 zebra_route_string(i), rip->route_map[i].metric,
paul718e3742002-12-13 20:15:29 +0000639 VTY_NEWLINE);
640 }
641 else
642 {
643 if (rip->route_map[i].name)
644 vty_out (vty, " redistribute %s route-map %s%s",
ajsf52d13c2005-10-01 17:38:06 +0000645 zebra_route_string(i), rip->route_map[i].name,
paul718e3742002-12-13 20:15:29 +0000646 VTY_NEWLINE);
647 else
ajsf52d13c2005-10-01 17:38:06 +0000648 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
paul718e3742002-12-13 20:15:29 +0000649 VTY_NEWLINE);
650 }
651 }
652 else
ajsf52d13c2005-10-01 17:38:06 +0000653 vty_out (vty, " %s", zebra_route_string(i));
paul718e3742002-12-13 20:15:29 +0000654 }
655 return 0;
656}
657
658/* Zebra node structure. */
Stephen Hemminger7fc626d2008-12-01 11:10:34 -0800659static struct cmd_node zebra_node =
paul718e3742002-12-13 20:15:29 +0000660{
661 ZEBRA_NODE,
662 "%s(config-router)# ",
663};
664
665void
666rip_zclient_init ()
667{
668 /* Set default value to the zebra client structure. */
669 zclient = zclient_new ();
670 zclient_init (zclient, ZEBRA_ROUTE_RIP);
671 zclient->interface_add = rip_interface_add;
672 zclient->interface_delete = rip_interface_delete;
673 zclient->interface_address_add = rip_interface_address_add;
674 zclient->interface_address_delete = rip_interface_address_delete;
675 zclient->ipv4_route_add = rip_zebra_read_ipv4;
676 zclient->ipv4_route_delete = rip_zebra_read_ipv4;
677 zclient->interface_up = rip_interface_up;
678 zclient->interface_down = rip_interface_down;
679
680 /* Install zebra node. */
681 install_node (&zebra_node, config_write_zebra);
682
683 /* Install command elements to zebra node. */
684 install_element (CONFIG_NODE, &router_zebra_cmd);
685 install_element (CONFIG_NODE, &no_router_zebra_cmd);
686 install_default (ZEBRA_NODE);
687 install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
688 install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
689
690 /* Install command elements to rip node. */
691 install_element (RIP_NODE, &rip_redistribute_type_cmd);
692 install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
693 install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
hasso16705132003-05-25 14:49:19 +0000694 install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
paul718e3742002-12-13 20:15:29 +0000695 install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
696 install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
697 install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
698 install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
699 install_element (RIP_NODE, &rip_default_information_originate_cmd);
700 install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
701}