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