]> git.proxmox.com Git - mirror_frr.git/blob - ripd/rip_zebra.c
3596938bbf10a5fc9e42ba4e1ac878ce2972c915
[mirror_frr.git] / ripd / rip_zebra.c
1 /* 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 "table.h"
27 #include "stream.h"
28 #include "memory.h"
29 #include "routemap.h"
30 #include "zclient.h"
31 #include "log.h"
32 #include "vrf.h"
33 #include "ripd/ripd.h"
34 #include "ripd/rip_debug.h"
35 #include "ripd/rip_interface.h"
36
37 /* All information about zebra. */
38 struct zclient *zclient = NULL;
39
40 /* Send ECMP routes to zebra. */
41 static void
42 rip_zebra_ipv4_send (struct route_node *rp, u_char cmd)
43 {
44 static struct in_addr **nexthops = NULL;
45 static unsigned int nexthops_len = 0;
46
47 struct list *list = (struct list *)rp->info;
48 struct zapi_ipv4 api;
49 struct listnode *listnode = NULL;
50 struct rip_info *rinfo = NULL;
51 int count = 0;
52
53 if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT))
54 {
55 api.vrf_id = VRF_DEFAULT;
56 api.type = ZEBRA_ROUTE_RIP;
57 api.instance = 0;
58 api.flags = 0;
59 api.message = 0;
60 api.safi = SAFI_UNICAST;
61
62 if (nexthops_len < listcount (list))
63 {
64 nexthops_len = listcount (list);
65 nexthops = XREALLOC (MTYPE_TMP, nexthops,
66 nexthops_len * sizeof (struct in_addr *));
67 }
68
69 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
70 for (ALL_LIST_ELEMENTS_RO (list, listnode, rinfo))
71 {
72 nexthops[count++] = &rinfo->nexthop;
73 if (cmd == ZEBRA_IPV4_ROUTE_ADD)
74 SET_FLAG (rinfo->flags, RIP_RTF_FIB);
75 else
76 UNSET_FLAG (rinfo->flags, RIP_RTF_FIB);
77 }
78
79 api.nexthop = nexthops;
80 api.nexthop_num = count;
81 api.ifindex_num = 0;
82
83 rinfo = listgetdata (listhead (list));
84
85 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
86 api.metric = rinfo->metric;
87
88 if (rinfo->distance && rinfo->distance != ZEBRA_RIP_DISTANCE_DEFAULT)
89 {
90 SET_FLAG (api.message, ZAPI_MESSAGE_DISTANCE);
91 api.distance = rinfo->distance;
92 }
93
94 zapi_ipv4_route (cmd, zclient,
95 (struct prefix_ipv4 *)&rp->p, &api);
96
97 if (IS_RIP_DEBUG_ZEBRA)
98 {
99 if (rip->ecmp)
100 zlog_debug ("%s: %s/%d nexthops %d",
101 (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \
102 "Install into zebra" : "Delete from zebra",
103 inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen, count);
104 else
105 zlog_debug ("%s: %s/%d",
106 (cmd == ZEBRA_IPV4_ROUTE_ADD) ? \
107 "Install into zebra" : "Delete from zebra",
108 inet_ntoa (rp->p.u.prefix4), rp->p.prefixlen);
109 }
110
111 rip_global_route_changes++;
112 }
113 }
114
115 /* Add/update ECMP routes to zebra. */
116 void
117 rip_zebra_ipv4_add (struct route_node *rp)
118 {
119 rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_ADD);
120 }
121
122 /* Delete ECMP routes from zebra. */
123 void
124 rip_zebra_ipv4_delete (struct route_node *rp)
125 {
126 rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_DELETE);
127 }
128
129 /* Zebra route add and delete treatment. */
130 static int
131 rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
132 vrf_id_t vrf_id)
133 {
134 struct stream *s;
135 struct zapi_ipv4 api;
136 unsigned long ifindex;
137 struct in_addr nexthop;
138 struct prefix_ipv4 p;
139
140 if (!rip)
141 return 0;
142
143 s = zclient->ibuf;
144 ifindex = 0;
145 nexthop.s_addr = 0;
146
147 /* Type, flags, message. */
148 api.type = stream_getc (s);
149 api.instance = stream_getw (s);
150 api.flags = stream_getc (s);
151 api.message = stream_getc (s);
152
153 /* IPv4 prefix. */
154 memset (&p, 0, sizeof (struct prefix_ipv4));
155 p.family = AF_INET;
156 p.prefixlen = stream_getc (s);
157 stream_get (&p.prefix, s, PSIZE (p.prefixlen));
158
159 /* Nexthop, ifindex, distance, metric. */
160 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
161 {
162 api.nexthop_num = stream_getc (s);
163 nexthop.s_addr = stream_get_ipv4 (s);
164 }
165 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX))
166 {
167 api.ifindex_num = stream_getc (s);
168 ifindex = stream_getl (s);
169 }
170 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
171 api.distance = stream_getc (s);
172 else
173 api.distance = 255;
174 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
175 api.metric = stream_getl (s);
176 else
177 api.metric = 0;
178
179 /* Then fetch IPv4 prefixes. */
180 if (command == ZEBRA_REDISTRIBUTE_IPV4_ADD)
181 rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
182 &nexthop, api.metric, api.distance);
183 else if (command == ZEBRA_REDISTRIBUTE_IPV4_DEL)
184 rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
185
186 return 0;
187 }
188
189 void
190 rip_zclient_reset (void)
191 {
192 zclient_reset (zclient);
193 }
194
195 /* RIP route-map set for redistribution */
196 static void
197 rip_routemap_set (int type, const char *name)
198 {
199 if (rip->route_map[type].name)
200 free(rip->route_map[type].name);
201
202 rip->route_map[type].name = strdup (name);
203 rip->route_map[type].map = route_map_lookup_by_name (name);
204 }
205
206 static void
207 rip_redistribute_metric_set (int type, unsigned int metric)
208 {
209 rip->route_map[type].metric_config = 1;
210 rip->route_map[type].metric = metric;
211 }
212
213 static int
214 rip_metric_unset (int type, unsigned int metric)
215 {
216 #define DONT_CARE_METRIC_RIP 17
217 if (metric != DONT_CARE_METRIC_RIP &&
218 rip->route_map[type].metric != metric)
219 return 1;
220 rip->route_map[type].metric_config = 0;
221 rip->route_map[type].metric = 0;
222 return 0;
223 }
224
225 /* RIP route-map unset for redistribution */
226 static int
227 rip_routemap_unset (int type, const char *name)
228 {
229 if (! rip->route_map[type].name ||
230 (name != NULL && strcmp(rip->route_map[type].name,name)))
231 return 1;
232
233 free (rip->route_map[type].name);
234 rip->route_map[type].name = NULL;
235 rip->route_map[type].map = NULL;
236
237 return 0;
238 }
239
240 /* Redistribution types */
241 static struct {
242 int type;
243 int str_min_len;
244 const char *str;
245 } redist_type[] = {
246 {ZEBRA_ROUTE_KERNEL, 1, "kernel"},
247 {ZEBRA_ROUTE_CONNECT, 1, "connected"},
248 {ZEBRA_ROUTE_STATIC, 1, "static"},
249 {ZEBRA_ROUTE_OSPF, 1, "ospf"},
250 {ZEBRA_ROUTE_BGP, 2, "bgp"},
251 {0, 0, NULL}
252 };
253
254 DEFUN (router_zebra,
255 router_zebra_cmd,
256 "router zebra",
257 "Enable a routing process\n"
258 "Make connection to zebra daemon\n")
259 {
260 vty->node = ZEBRA_NODE;
261 zclient->enable = 1;
262 zclient_start (zclient);
263 return CMD_SUCCESS;
264 }
265
266 DEFUN (no_router_zebra,
267 no_router_zebra_cmd,
268 "no router zebra",
269 NO_STR
270 "Enable a routing process\n"
271 "Make connection to zebra daemon\n")
272 {
273 zclient->enable = 0;
274 zclient_stop (zclient);
275 return CMD_SUCCESS;
276 }
277
278 #if 0
279 static int
280 rip_redistribute_set (int type)
281 {
282 if (vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT))
283 return CMD_SUCCESS;
284
285 vrf_bitmap_set (zclient->redist[AFI_IP][type], VRF_DEFAULT);
286
287 if (zclient->sock > 0)
288 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, API_IP, type);
289
290 return CMD_SUCCESS;
291 }
292 #endif
293
294 static int
295 rip_redistribute_unset (int type)
296 {
297 if (! vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT))
298 return CMD_SUCCESS;
299
300 vrf_bitmap_unset (zclient->redist[AFI_IP][type], VRF_DEFAULT);
301
302 if (zclient->sock > 0)
303 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0, VRF_DEFAULT);
304
305 /* Remove the routes from RIP table. */
306 rip_redistribute_withdraw (type);
307
308 return CMD_SUCCESS;
309 }
310
311 int
312 rip_redistribute_check (int type)
313 {
314 return vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT);
315 }
316
317 void
318 rip_redistribute_clean (void)
319 {
320 int i;
321
322 for (i = 0; redist_type[i].str; i++)
323 {
324 if (vrf_bitmap_check (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT))
325 {
326 if (zclient->sock > 0)
327 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
328 zclient, AFI_IP, redist_type[i].type, 0,
329 VRF_DEFAULT);
330
331 vrf_bitmap_unset (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT);
332
333 /* Remove the routes from RIP table. */
334 rip_redistribute_withdraw (redist_type[i].type);
335 }
336 }
337 }
338
339 DEFUN (rip_redistribute_rip,
340 rip_redistribute_rip_cmd,
341 "redistribute rip",
342 "Redistribute information from another routing protocol\n"
343 "Routing Information Protocol (RIP)\n")
344 {
345 vrf_bitmap_set (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT);
346 return CMD_SUCCESS;
347 }
348
349 DEFUN (no_rip_redistribute_rip,
350 no_rip_redistribute_rip_cmd,
351 "no redistribute rip",
352 NO_STR
353 "Redistribute information from another routing protocol\n"
354 "Routing Information Protocol (RIP)\n")
355 {
356 vrf_bitmap_unset (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT);
357 return CMD_SUCCESS;
358 }
359
360 DEFUN (rip_redistribute_type,
361 rip_redistribute_type_cmd,
362 "redistribute " QUAGGA_REDIST_STR_RIPD,
363 REDIST_STR
364 QUAGGA_REDIST_HELP_STR_RIPD)
365 {
366 int i;
367
368 for(i = 0; redist_type[i].str; i++)
369 {
370 if (strncmp (redist_type[i].str, argv[2]->arg,
371 redist_type[i].str_min_len) == 0)
372 {
373 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
374 AFI_IP, redist_type[i].type, 0, VRF_DEFAULT);
375 return CMD_SUCCESS;
376 }
377 }
378
379 vty_out(vty, "Invalid type %s%s", argv[2]->arg,
380 VTY_NEWLINE);
381
382 return CMD_WARNING;
383 }
384
385 DEFUN (no_rip_redistribute_type,
386 no_rip_redistribute_type_cmd,
387 "no redistribute " QUAGGA_REDIST_STR_RIPD,
388 NO_STR
389 REDIST_STR
390 QUAGGA_REDIST_HELP_STR_RIPD)
391 {
392 int i;
393
394 for (i = 0; redist_type[i].str; i++)
395 {
396 if (strncmp(redist_type[i].str, argv[3]->arg,
397 redist_type[i].str_min_len) == 0)
398 {
399 rip_metric_unset (redist_type[i].type, DONT_CARE_METRIC_RIP);
400 rip_routemap_unset (redist_type[i].type,NULL);
401 rip_redistribute_unset (redist_type[i].type);
402 return CMD_SUCCESS;
403 }
404 }
405
406 vty_out(vty, "Invalid type %s%s", argv[3]->arg,
407 VTY_NEWLINE);
408
409 return CMD_WARNING;
410 }
411
412 DEFUN (rip_redistribute_type_routemap,
413 rip_redistribute_type_routemap_cmd,
414 "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
415 REDIST_STR
416 QUAGGA_REDIST_HELP_STR_RIPD
417 "Route map reference\n"
418 "Pointer to route-map entries\n")
419 {
420 int idx_protocol = 1;
421 int idx_word = 3;
422 int i;
423
424 for (i = 0; redist_type[i].str; i++) {
425 if (strncmp(redist_type[i].str, argv[idx_protocol]->arg,
426 redist_type[i].str_min_len) == 0)
427 {
428 rip_routemap_set (redist_type[i].type, argv[idx_word]->arg);
429 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
430 redist_type[i].type, 0, VRF_DEFAULT);
431 return CMD_SUCCESS;
432 }
433 }
434
435 vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->arg,
436 VTY_NEWLINE);
437
438 return CMD_WARNING;
439 }
440
441 DEFUN (no_rip_redistribute_type_routemap,
442 no_rip_redistribute_type_routemap_cmd,
443 "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
444 NO_STR
445 REDIST_STR
446 QUAGGA_REDIST_HELP_STR_RIPD
447 "Route map reference\n"
448 "Pointer to route-map entries\n")
449 {
450 int idx_protocol = 2;
451 int idx_word = 4;
452 int i;
453
454 for (i = 0; redist_type[i].str; i++)
455 {
456 if (strncmp(redist_type[i].str, argv[idx_protocol]->arg,
457 redist_type[i].str_min_len) == 0)
458 {
459 if (rip_routemap_unset (redist_type[i].type,argv[idx_word]->arg))
460 return CMD_WARNING;
461 rip_redistribute_unset (redist_type[i].type);
462 return CMD_SUCCESS;
463 }
464 }
465
466 vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->arg,
467 VTY_NEWLINE);
468
469 return CMD_WARNING;
470 }
471
472 DEFUN (rip_redistribute_type_metric,
473 rip_redistribute_type_metric_cmd,
474 "redistribute " QUAGGA_REDIST_STR_RIPD " metric (0-16)",
475 REDIST_STR
476 QUAGGA_REDIST_HELP_STR_RIPD
477 "Metric\n"
478 "Metric value\n")
479 {
480 int idx_protocol = 1;
481 int idx_number = 3;
482 int i;
483 int metric;
484
485 metric = atoi (argv[idx_number]->arg);
486
487 for (i = 0; redist_type[i].str; i++) {
488 if (strncmp(redist_type[i].str, argv[idx_protocol]->arg,
489 redist_type[i].str_min_len) == 0)
490 {
491 rip_redistribute_metric_set (redist_type[i].type, metric);
492 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
493 redist_type[i].type, 0, VRF_DEFAULT);
494 return CMD_SUCCESS;
495 }
496 }
497
498 vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->arg,
499 VTY_NEWLINE);
500
501 return CMD_WARNING;
502 }
503
504 DEFUN (no_rip_redistribute_type_metric,
505 no_rip_redistribute_type_metric_cmd,
506 "no redistribute " QUAGGA_REDIST_STR_RIPD " metric (0-16)",
507 NO_STR
508 REDIST_STR
509 QUAGGA_REDIST_HELP_STR_RIPD
510 "Metric\n"
511 "Metric value\n")
512 {
513 int idx_protocol = 2;
514 int idx_number = 4;
515 int i;
516
517 for (i = 0; redist_type[i].str; i++)
518 {
519 if (strncmp(redist_type[i].str, argv[idx_protocol]->arg,
520 redist_type[i].str_min_len) == 0)
521 {
522 if (rip_metric_unset (redist_type[i].type, atoi(argv[idx_number]->arg)))
523 return CMD_WARNING;
524 rip_redistribute_unset (redist_type[i].type);
525 return CMD_SUCCESS;
526 }
527 }
528
529 vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->arg,
530 VTY_NEWLINE);
531
532 return CMD_WARNING;
533 }
534
535 DEFUN (rip_redistribute_type_metric_routemap,
536 rip_redistribute_type_metric_routemap_cmd,
537 "redistribute " QUAGGA_REDIST_STR_RIPD " metric (0-16) route-map WORD",
538 REDIST_STR
539 QUAGGA_REDIST_HELP_STR_RIPD
540 "Metric\n"
541 "Metric value\n"
542 "Route map reference\n"
543 "Pointer to route-map entries\n")
544 {
545 int idx_protocol = 1;
546 int idx_number = 3;
547 int idx_word = 5;
548 int i;
549 int metric;
550
551 metric = atoi (argv[idx_number]->arg);
552
553 for (i = 0; redist_type[i].str; i++) {
554 if (strncmp(redist_type[i].str, argv[idx_protocol]->arg,
555 redist_type[i].str_min_len) == 0)
556 {
557 rip_redistribute_metric_set (redist_type[i].type, metric);
558 rip_routemap_set (redist_type[i].type, argv[idx_word]->arg);
559 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
560 redist_type[i].type, 0, VRF_DEFAULT);
561 return CMD_SUCCESS;
562 }
563 }
564
565 vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->arg,
566 VTY_NEWLINE);
567
568 return CMD_WARNING;
569 }
570
571
572 DEFUN (no_rip_redistribute_type_metric_routemap,
573 no_rip_redistribute_type_metric_routemap_cmd,
574 "no redistribute " QUAGGA_REDIST_STR_RIPD " metric (0-16) route-map WORD",
575 NO_STR
576 REDIST_STR
577 QUAGGA_REDIST_HELP_STR_RIPD
578 "Metric\n"
579 "Metric value\n"
580 "Route map reference\n"
581 "Pointer to route-map entries\n")
582 {
583 int idx_protocol = 2;
584 int idx_number = 4;
585 int idx_word = 6;
586 int i;
587
588 for (i = 0; redist_type[i].str; i++)
589 {
590 if (strncmp(redist_type[i].str, argv[idx_protocol]->arg,
591 redist_type[i].str_min_len) == 0)
592 {
593 if (rip_metric_unset (redist_type[i].type, atoi(argv[idx_number]->arg)))
594 return CMD_WARNING;
595 if (rip_routemap_unset (redist_type[i].type, argv[idx_word]->arg))
596 {
597 rip_redistribute_metric_set(redist_type[i].type, atoi(argv[idx_number]->arg));
598 return CMD_WARNING;
599 }
600 rip_redistribute_unset (redist_type[i].type);
601 return CMD_SUCCESS;
602 }
603 }
604
605 vty_out(vty, "Invalid type %s%s", argv[idx_protocol]->arg,
606 VTY_NEWLINE);
607
608 return CMD_WARNING;
609 }
610
611 /* Default information originate. */
612
613 DEFUN (rip_default_information_originate,
614 rip_default_information_originate_cmd,
615 "default-information originate",
616 "Control distribution of default route\n"
617 "Distribute a default route\n")
618 {
619 struct prefix_ipv4 p;
620
621 if (! rip->default_information)
622 {
623 memset (&p, 0, sizeof (struct prefix_ipv4));
624 p.family = AF_INET;
625
626 rip->default_information = 1;
627
628 rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
629 NULL, 0, 0);
630 }
631
632 return CMD_SUCCESS;
633 }
634
635 DEFUN (no_rip_default_information_originate,
636 no_rip_default_information_originate_cmd,
637 "no default-information originate",
638 NO_STR
639 "Control distribution of default route\n"
640 "Distribute a default route\n")
641 {
642 struct prefix_ipv4 p;
643
644 if (rip->default_information)
645 {
646 memset (&p, 0, sizeof (struct prefix_ipv4));
647 p.family = AF_INET;
648
649 rip->default_information = 0;
650
651 rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
652 }
653
654 return CMD_SUCCESS;
655 }
656
657 /* RIP configuration write function. */
658 static int
659 config_write_zebra (struct vty *vty)
660 {
661 if (! zclient->enable)
662 {
663 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
664 return 1;
665 }
666 else if (! vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT))
667 {
668 vty_out (vty, "router zebra%s", VTY_NEWLINE);
669 vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
670 return 1;
671 }
672 return 0;
673 }
674
675 int
676 config_write_rip_redistribute (struct vty *vty, int config_mode)
677 {
678 int i;
679
680 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
681 if (i != zclient->redist_default &&
682 vrf_bitmap_check (zclient->redist[AFI_IP][i], VRF_DEFAULT))
683 {
684 if (config_mode)
685 {
686 if (rip->route_map[i].metric_config)
687 {
688 if (rip->route_map[i].name)
689 vty_out (vty, " redistribute %s metric %d route-map %s%s",
690 zebra_route_string(i), rip->route_map[i].metric,
691 rip->route_map[i].name,
692 VTY_NEWLINE);
693 else
694 vty_out (vty, " redistribute %s metric %d%s",
695 zebra_route_string(i), rip->route_map[i].metric,
696 VTY_NEWLINE);
697 }
698 else
699 {
700 if (rip->route_map[i].name)
701 vty_out (vty, " redistribute %s route-map %s%s",
702 zebra_route_string(i), rip->route_map[i].name,
703 VTY_NEWLINE);
704 else
705 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
706 VTY_NEWLINE);
707 }
708 }
709 else
710 vty_out (vty, " %s", zebra_route_string(i));
711 }
712 return 0;
713 }
714
715 /* Zebra node structure. */
716 static struct cmd_node zebra_node =
717 {
718 ZEBRA_NODE,
719 "%s(config-router)# ",
720 };
721
722 static void
723 rip_zebra_connected (struct zclient *zclient)
724 {
725 zclient_send_reg_requests (zclient, VRF_DEFAULT);
726 }
727
728 void
729 rip_zclient_init (struct thread_master *master)
730 {
731 /* Set default value to the zebra client structure. */
732 zclient = zclient_new(master);
733 zclient_init (zclient, ZEBRA_ROUTE_RIP, 0);
734 zclient->zebra_connected = rip_zebra_connected;
735 zclient->interface_add = rip_interface_add;
736 zclient->interface_delete = rip_interface_delete;
737 zclient->interface_address_add = rip_interface_address_add;
738 zclient->interface_address_delete = rip_interface_address_delete;
739 zclient->ipv4_route_add = rip_zebra_read_ipv4;
740 zclient->ipv4_route_delete = rip_zebra_read_ipv4;
741 zclient->interface_up = rip_interface_up;
742 zclient->interface_down = rip_interface_down;
743 zclient->redistribute_route_ipv4_add = rip_zebra_read_ipv4;
744 zclient->redistribute_route_ipv4_del = rip_zebra_read_ipv4;
745
746 /* Install zebra node. */
747 install_node (&zebra_node, config_write_zebra);
748
749 /* Install command elements to zebra node. */
750 install_element (CONFIG_NODE, &router_zebra_cmd);
751 install_element (CONFIG_NODE, &no_router_zebra_cmd);
752 install_default (ZEBRA_NODE);
753 install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
754 install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
755
756 /* Install command elements to rip node. */
757 install_element (RIP_NODE, &rip_redistribute_type_cmd);
758 install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
759 install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
760 install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
761 install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
762 install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
763 install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
764 install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
765 install_element (RIP_NODE, &rip_default_information_originate_cmd);
766 install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
767 }