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