]> git.proxmox.com Git - mirror_frr.git/blame - ripd/rip_zebra.c
lib: Check prefix length from zebra is sensible
[mirror_frr.git] / ripd / rip_zebra.c
CommitLineData
718e3744 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"
bce8e868 26#include "table.h"
718e3744 27#include "stream.h"
bce8e868 28#include "memory.h"
718e3744 29#include "routemap.h"
30#include "zclient.h"
31#include "log.h"
7076bb2f 32#include "vrf.h"
718e3744 33#include "ripd/ripd.h"
34#include "ripd/rip_debug.h"
dc63bfd4 35#include "ripd/rip_interface.h"
718e3744 36
37/* All information about zebra. */
38struct zclient *zclient = NULL;
6b0655a2 39
bce8e868
LF
40/* Send ECMP routes to zebra. */
41static void
42rip_zebra_ipv4_send (struct route_node *rp, u_char cmd)
718e3744 43{
bce8e868
LF
44 static struct in_addr **nexthops = NULL;
45 static unsigned int nexthops_len = 0;
46
47 struct list *list = (struct list *)rp->info;
718e3744 48 struct zapi_ipv4 api;
bce8e868
LF
49 struct listnode *listnode = NULL;
50 struct rip_info *rinfo = NULL;
51 int count = 0;
718e3744 52
7076bb2f 53 if (vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT))
718e3744 54 {
7076bb2f 55 api.vrf_id = VRF_DEFAULT;
718e3744 56 api.type = ZEBRA_ROUTE_RIP;
7c8ff89e 57 api.instance = 0;
718e3744 58 api.flags = 0;
59 api.message = 0;
b4e45f67 60 api.safi = SAFI_UNICAST;
bce8e868
LF
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
718e3744 69 SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
bce8e868
LF
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;
718e3744 81 api.ifindex_num = 0;
bce8e868
LF
82
83 rinfo = listgetdata (listhead (list));
84
718e3744 85 SET_FLAG (api.message, ZAPI_MESSAGE_METRIC);
bce8e868
LF
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 }
718e3744 93
bce8e868
LF
94 zapi_ipv4_route (cmd, zclient,
95 (struct prefix_ipv4 *)&rp->p, &api);
718e3744 96
bce8e868 97 if (IS_RIP_DEBUG_ZEBRA)
8478ae7e
LF
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 }
718e3744 110
111 rip_global_route_changes++;
112 }
113}
114
bce8e868 115/* Add/update ECMP routes to zebra. */
718e3744 116void
bce8e868 117rip_zebra_ipv4_add (struct route_node *rp)
718e3744 118{
bce8e868
LF
119 rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_ADD);
120}
718e3744 121
bce8e868
LF
122/* Delete ECMP routes from zebra. */
123void
124rip_zebra_ipv4_delete (struct route_node *rp)
125{
126 rip_zebra_ipv4_send (rp, ZEBRA_IPV4_ROUTE_DELETE);
718e3744 127}
128
129/* Zebra route add and delete treatment. */
dc63bfd4 130static int
7076bb2f
FL
131rip_zebra_read_ipv4 (int command, struct zclient *zclient, zebra_size_t length,
132 vrf_id_t vrf_id)
718e3744 133{
134 struct stream *s;
135 struct zapi_ipv4 api;
136 unsigned long ifindex;
137 struct in_addr nexthop;
138 struct prefix_ipv4 p;
b3556ea3
DS
139
140 if (!rip)
141 return 0;
142
718e3744 143 s = zclient->ibuf;
144 ifindex = 0;
145 nexthop.s_addr = 0;
146
147 /* Type, flags, message. */
148 api.type = stream_getc (s);
7c8ff89e 149 api.instance = stream_getw (s);
b99c3821 150 api.flags = stream_getc (s);
718e3744 151 api.message = stream_getc (s);
152
153 /* IPv4 prefix. */
154 memset (&p, 0, sizeof (struct prefix_ipv4));
155 p.family = AF_INET;
d9178828 156 p.prefixlen = MIN(IPV4_MAX_PREFIXLEN, stream_getc (s));
718e3744 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);
fbf5d033 172 else
173 api.distance = 255;
718e3744 174 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
175 api.metric = stream_getl (s);
fbf5d033 176 else
177 api.metric = 0;
718e3744 178
179 /* Then fetch IPv4 prefixes. */
5048fe14 180 if (command == ZEBRA_REDISTRIBUTE_IPV4_ADD)
fbf5d033 181 rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex,
182 &nexthop, api.metric, api.distance);
5048fe14 183 else if (command == ZEBRA_REDISTRIBUTE_IPV4_DEL)
718e3744 184 rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex);
185
186 return 0;
187}
188
189void
dc63bfd4 190rip_zclient_reset (void)
718e3744 191{
192 zclient_reset (zclient);
193}
194
195/* RIP route-map set for redistribution */
dc63bfd4 196static void
98b718a9 197rip_routemap_set (int type, const char *name)
718e3744 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
dc63bfd4 206static void
8a676be3 207rip_redistribute_metric_set (int type, unsigned int metric)
718e3744 208{
209 rip->route_map[type].metric_config = 1;
210 rip->route_map[type].metric = metric;
211}
212
dc63bfd4 213static int
8a676be3 214rip_metric_unset (int type, unsigned int metric)
718e3744 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 */
dc63bfd4 226static int
98b718a9 227rip_routemap_unset (int type, const char *name)
718e3744 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}
6b0655a2 239
718e3744 240/* Redistribution types */
241static struct {
242 int type;
243 int str_min_len;
8a676be3 244 const char *str;
718e3744 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"},
9c58fbd7 250 {ZEBRA_ROUTE_BGP, 2, "bgp"},
718e3744 251 {0, 0, NULL}
252};
253
254DEFUN (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
266DEFUN (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
2c239705 278#if 0
dc63bfd4 279static int
718e3744 280rip_redistribute_set (int type)
281{
7076bb2f 282 if (vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT))
718e3744 283 return CMD_SUCCESS;
284
7076bb2f 285 vrf_bitmap_set (zclient->redist[AFI_IP][type], VRF_DEFAULT);
718e3744 286
287 if (zclient->sock > 0)
8bb0831e 288 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, API_IP, type);
718e3744 289
290 return CMD_SUCCESS;
291}
2c239705 292#endif
718e3744 293
dc63bfd4 294static int
718e3744 295rip_redistribute_unset (int type)
296{
7076bb2f 297 if (! vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT))
718e3744 298 return CMD_SUCCESS;
299
7076bb2f 300 vrf_bitmap_unset (zclient->redist[AFI_IP][type], VRF_DEFAULT);
718e3744 301
302 if (zclient->sock > 0)
7076bb2f 303 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0, VRF_DEFAULT);
718e3744 304
305 /* Remove the routes from RIP table. */
306 rip_redistribute_withdraw (type);
307
308 return CMD_SUCCESS;
309}
310
311int
312rip_redistribute_check (int type)
313{
7076bb2f 314 return vrf_bitmap_check (zclient->redist[AFI_IP][type], VRF_DEFAULT);
718e3744 315}
316
317void
dc63bfd4 318rip_redistribute_clean (void)
718e3744 319{
320 int i;
321
322 for (i = 0; redist_type[i].str; i++)
323 {
7076bb2f 324 if (vrf_bitmap_check (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT))
718e3744 325 {
326 if (zclient->sock > 0)
327 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE,
7076bb2f
FL
328 zclient, AFI_IP, redist_type[i].type, 0,
329 VRF_DEFAULT);
718e3744 330
7076bb2f 331 vrf_bitmap_unset (zclient->redist[AFI_IP][redist_type[i].type], VRF_DEFAULT);
718e3744 332
333 /* Remove the routes from RIP table. */
334 rip_redistribute_withdraw (redist_type[i].type);
335 }
336 }
337}
338
339DEFUN (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{
7076bb2f 345 vrf_bitmap_set (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT);
718e3744 346 return CMD_SUCCESS;
347}
348
349DEFUN (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{
7076bb2f 356 vrf_bitmap_unset (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT);
718e3744 357 return CMD_SUCCESS;
358}
359
360DEFUN (rip_redistribute_type,
361 rip_redistribute_type_cmd,
9a57dc69
PJ
362 "redistribute " QUAGGA_REDIST_STR_RIPD,
363 REDIST_STR
364 QUAGGA_REDIST_HELP_STR_RIPD)
718e3744 365{
366 int i;
367
368 for(i = 0; redist_type[i].str; i++)
369 {
370 if (strncmp (redist_type[i].str, argv[0],
371 redist_type[i].str_min_len) == 0)
372 {
0a589359 373 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient,
7076bb2f 374 AFI_IP, redist_type[i].type, 0, VRF_DEFAULT);
718e3744 375 return CMD_SUCCESS;
376 }
377 }
378
379 vty_out(vty, "Invalid type %s%s", argv[0],
380 VTY_NEWLINE);
381
382 return CMD_WARNING;
383}
384
385DEFUN (no_rip_redistribute_type,
386 no_rip_redistribute_type_cmd,
9a57dc69 387 "no redistribute " QUAGGA_REDIST_STR_RIPD,
718e3744 388 NO_STR
9a57dc69
PJ
389 REDIST_STR
390 QUAGGA_REDIST_HELP_STR_RIPD)
718e3744 391{
392 int i;
393
394 for (i = 0; redist_type[i].str; i++)
395 {
396 if (strncmp(redist_type[i].str, argv[0],
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[0],
407 VTY_NEWLINE);
408
409 return CMD_WARNING;
410}
411
412DEFUN (rip_redistribute_type_routemap,
413 rip_redistribute_type_routemap_cmd,
9a57dc69
PJ
414 "redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
415 REDIST_STR
416 QUAGGA_REDIST_HELP_STR_RIPD
718e3744 417 "Route map reference\n"
418 "Pointer to route-map entries\n")
419{
420 int i;
421
422 for (i = 0; redist_type[i].str; i++) {
423 if (strncmp(redist_type[i].str, argv[0],
424 redist_type[i].str_min_len) == 0)
425 {
426 rip_routemap_set (redist_type[i].type, argv[1]);
8bb0831e 427 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
7076bb2f 428 redist_type[i].type, 0, VRF_DEFAULT);
718e3744 429 return CMD_SUCCESS;
430 }
431 }
432
433 vty_out(vty, "Invalid type %s%s", argv[0],
434 VTY_NEWLINE);
435
436 return CMD_WARNING;
437}
438
439DEFUN (no_rip_redistribute_type_routemap,
440 no_rip_redistribute_type_routemap_cmd,
9a57dc69 441 "no redistribute " QUAGGA_REDIST_STR_RIPD " route-map WORD",
718e3744 442 NO_STR
9a57dc69
PJ
443 REDIST_STR
444 QUAGGA_REDIST_HELP_STR_RIPD
718e3744 445 "Route map reference\n"
446 "Pointer to route-map entries\n")
447{
448 int i;
449
450 for (i = 0; redist_type[i].str; i++)
451 {
452 if (strncmp(redist_type[i].str, argv[0],
453 redist_type[i].str_min_len) == 0)
454 {
455 if (rip_routemap_unset (redist_type[i].type,argv[1]))
456 return CMD_WARNING;
457 rip_redistribute_unset (redist_type[i].type);
458 return CMD_SUCCESS;
459 }
460 }
461
462 vty_out(vty, "Invalid type %s%s", argv[0],
463 VTY_NEWLINE);
464
465 return CMD_WARNING;
466}
467
468DEFUN (rip_redistribute_type_metric,
469 rip_redistribute_type_metric_cmd,
9a57dc69
PJ
470 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
471 REDIST_STR
472 QUAGGA_REDIST_HELP_STR_RIPD
718e3744 473 "Metric\n"
474 "Metric value\n")
475{
476 int i;
477 int metric;
478
479 metric = atoi (argv[1]);
480
481 for (i = 0; redist_type[i].str; i++) {
482 if (strncmp(redist_type[i].str, argv[0],
483 redist_type[i].str_min_len) == 0)
484 {
485 rip_redistribute_metric_set (redist_type[i].type, metric);
8bb0831e 486 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
7076bb2f 487 redist_type[i].type, 0, VRF_DEFAULT);
718e3744 488 return CMD_SUCCESS;
489 }
490 }
491
492 vty_out(vty, "Invalid type %s%s", argv[0],
493 VTY_NEWLINE);
494
495 return CMD_WARNING;
496}
497
498DEFUN (no_rip_redistribute_type_metric,
499 no_rip_redistribute_type_metric_cmd,
9a57dc69 500 "no redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16>",
718e3744 501 NO_STR
9a57dc69
PJ
502 REDIST_STR
503 QUAGGA_REDIST_HELP_STR_RIPD
718e3744 504 "Metric\n"
505 "Metric value\n")
506{
507 int i;
508
509 for (i = 0; redist_type[i].str; i++)
510 {
511 if (strncmp(redist_type[i].str, argv[0],
512 redist_type[i].str_min_len) == 0)
513 {
514 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
515 return CMD_WARNING;
516 rip_redistribute_unset (redist_type[i].type);
517 return CMD_SUCCESS;
518 }
519 }
520
521 vty_out(vty, "Invalid type %s%s", argv[0],
522 VTY_NEWLINE);
523
524 return CMD_WARNING;
525}
526
16705130 527DEFUN (rip_redistribute_type_metric_routemap,
528 rip_redistribute_type_metric_routemap_cmd,
9a57dc69
PJ
529 "redistribute " QUAGGA_REDIST_STR_RIPD " metric <0-16> route-map WORD",
530 REDIST_STR
531 QUAGGA_REDIST_HELP_STR_RIPD
16705130 532 "Metric\n"
533 "Metric value\n"
534 "Route map reference\n"
535 "Pointer to route-map entries\n")
536{
537 int i;
538 int metric;
539
540 metric = atoi (argv[1]);
541
542 for (i = 0; redist_type[i].str; i++) {
543 if (strncmp(redist_type[i].str, argv[0],
544 redist_type[i].str_min_len) == 0)
545 {
546 rip_redistribute_metric_set (redist_type[i].type, metric);
547 rip_routemap_set (redist_type[i].type, argv[2]);
8bb0831e 548 zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP,
7076bb2f 549 redist_type[i].type, 0, VRF_DEFAULT);
16705130 550 return CMD_SUCCESS;
551 }
552 }
553
554 vty_out(vty, "Invalid type %s%s", argv[0],
555 VTY_NEWLINE);
556
557 return CMD_WARNING;
558}
559
560
718e3744 561DEFUN (no_rip_redistribute_type_metric_routemap,
562 no_rip_redistribute_type_metric_routemap_cmd,
9a57dc69
PJ
563 "no redistribute " QUAGGA_REDIST_STR_RIPD
564 " metric <0-16> route-map WORD",
718e3744 565 NO_STR
9a57dc69
PJ
566 REDIST_STR
567 QUAGGA_REDIST_HELP_STR_RIPD
718e3744 568 "Metric\n"
569 "Metric value\n"
570 "Route map reference\n"
571 "Pointer to route-map entries\n")
572{
573 int i;
574
575 for (i = 0; redist_type[i].str; i++)
576 {
577 if (strncmp(redist_type[i].str, argv[0],
578 redist_type[i].str_min_len) == 0)
579 {
580 if (rip_metric_unset (redist_type[i].type, atoi(argv[1])))
581 return CMD_WARNING;
582 if (rip_routemap_unset (redist_type[i].type, argv[2]))
583 {
584 rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1]));
585 return CMD_WARNING;
586 }
587 rip_redistribute_unset (redist_type[i].type);
588 return CMD_SUCCESS;
589 }
590 }
591
592 vty_out(vty, "Invalid type %s%s", argv[0],
593 VTY_NEWLINE);
594
595 return CMD_WARNING;
596}
6b0655a2 597
718e3744 598/* Default information originate. */
599
600DEFUN (rip_default_information_originate,
601 rip_default_information_originate_cmd,
602 "default-information originate",
603 "Control distribution of default route\n"
604 "Distribute a default route\n")
605{
606 struct prefix_ipv4 p;
607
608 if (! rip->default_information)
609 {
610 memset (&p, 0, sizeof (struct prefix_ipv4));
611 p.family = AF_INET;
612
613 rip->default_information = 1;
614
fbf5d033 615 rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0,
616 NULL, 0, 0);
718e3744 617 }
618
619 return CMD_SUCCESS;
620}
621
622DEFUN (no_rip_default_information_originate,
623 no_rip_default_information_originate_cmd,
624 "no default-information originate",
625 NO_STR
626 "Control distribution of default route\n"
627 "Distribute a default route\n")
628{
629 struct prefix_ipv4 p;
630
631 if (rip->default_information)
632 {
633 memset (&p, 0, sizeof (struct prefix_ipv4));
634 p.family = AF_INET;
635
636 rip->default_information = 0;
637
16705130 638 rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0);
718e3744 639 }
640
641 return CMD_SUCCESS;
642}
6b0655a2 643
718e3744 644/* RIP configuration write function. */
dc63bfd4 645static int
718e3744 646config_write_zebra (struct vty *vty)
647{
648 if (! zclient->enable)
649 {
650 vty_out (vty, "no router zebra%s", VTY_NEWLINE);
651 return 1;
652 }
7076bb2f 653 else if (! vrf_bitmap_check (zclient->redist[AFI_IP][ZEBRA_ROUTE_RIP], VRF_DEFAULT))
718e3744 654 {
655 vty_out (vty, "router zebra%s", VTY_NEWLINE);
656 vty_out (vty, " no redistribute rip%s", VTY_NEWLINE);
657 return 1;
658 }
659 return 0;
660}
661
662int
663config_write_rip_redistribute (struct vty *vty, int config_mode)
664{
665 int i;
718e3744 666
667 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
7c8ff89e 668 if (i != zclient->redist_default &&
7076bb2f 669 vrf_bitmap_check (zclient->redist[AFI_IP][i], VRF_DEFAULT))
718e3744 670 {
671 if (config_mode)
672 {
673 if (rip->route_map[i].metric_config)
674 {
675 if (rip->route_map[i].name)
676 vty_out (vty, " redistribute %s metric %d route-map %s%s",
f52d13cb 677 zebra_route_string(i), rip->route_map[i].metric,
718e3744 678 rip->route_map[i].name,
679 VTY_NEWLINE);
680 else
681 vty_out (vty, " redistribute %s metric %d%s",
f52d13cb 682 zebra_route_string(i), rip->route_map[i].metric,
718e3744 683 VTY_NEWLINE);
684 }
685 else
686 {
687 if (rip->route_map[i].name)
688 vty_out (vty, " redistribute %s route-map %s%s",
f52d13cb 689 zebra_route_string(i), rip->route_map[i].name,
718e3744 690 VTY_NEWLINE);
691 else
f52d13cb 692 vty_out (vty, " redistribute %s%s", zebra_route_string(i),
718e3744 693 VTY_NEWLINE);
694 }
695 }
696 else
f52d13cb 697 vty_out (vty, " %s", zebra_route_string(i));
718e3744 698 }
699 return 0;
700}
701
702/* Zebra node structure. */
7fc626de 703static struct cmd_node zebra_node =
718e3744 704{
705 ZEBRA_NODE,
706 "%s(config-router)# ",
707};
708
7076bb2f
FL
709static void
710rip_zebra_connected (struct zclient *zclient)
711{
0e5223e7 712 zclient_send_reg_requests (zclient, VRF_DEFAULT);
7076bb2f
FL
713}
714
718e3744 715void
4140ca4d 716rip_zclient_init (struct thread_master *master)
718e3744 717{
718 /* Set default value to the zebra client structure. */
4140ca4d 719 zclient = zclient_new(master);
7c8ff89e 720 zclient_init (zclient, ZEBRA_ROUTE_RIP, 0);
7076bb2f 721 zclient->zebra_connected = rip_zebra_connected;
718e3744 722 zclient->interface_add = rip_interface_add;
723 zclient->interface_delete = rip_interface_delete;
724 zclient->interface_address_add = rip_interface_address_add;
725 zclient->interface_address_delete = rip_interface_address_delete;
718e3744 726 zclient->interface_up = rip_interface_up;
727 zclient->interface_down = rip_interface_down;
5048fe14 728 zclient->redistribute_route_ipv4_add = rip_zebra_read_ipv4;
729 zclient->redistribute_route_ipv4_del = rip_zebra_read_ipv4;
718e3744 730
731 /* Install zebra node. */
732 install_node (&zebra_node, config_write_zebra);
733
734 /* Install command elements to zebra node. */
735 install_element (CONFIG_NODE, &router_zebra_cmd);
736 install_element (CONFIG_NODE, &no_router_zebra_cmd);
737 install_default (ZEBRA_NODE);
738 install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd);
739 install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd);
740
741 /* Install command elements to rip node. */
742 install_element (RIP_NODE, &rip_redistribute_type_cmd);
743 install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd);
744 install_element (RIP_NODE, &rip_redistribute_type_metric_cmd);
16705130 745 install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd);
718e3744 746 install_element (RIP_NODE, &no_rip_redistribute_type_cmd);
747 install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd);
748 install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd);
749 install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd);
750 install_element (RIP_NODE, &rip_default_information_originate_cmd);
751 install_element (RIP_NODE, &no_rip_default_information_originate_cmd);
752}