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); |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 137 | else |
| 138 | api.distance = 255; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 139 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 140 | api.metric = stream_getl (s); |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 141 | else |
| 142 | api.metric = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 143 | |
| 144 | /* Then fetch IPv4 prefixes. */ |
| 145 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 146 | rip_redistribute_add (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex, |
| 147 | &nexthop, api.metric, api.distance); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 148 | else |
| 149 | rip_redistribute_delete (api.type, RIP_ROUTE_REDISTRIBUTE, &p, ifindex); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | void |
| 155 | rip_zclient_reset () |
| 156 | { |
| 157 | zclient_reset (zclient); |
| 158 | } |
| 159 | |
| 160 | /* RIP route-map set for redistribution */ |
| 161 | void |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 162 | rip_routemap_set (int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 163 | { |
| 164 | if (rip->route_map[type].name) |
| 165 | free(rip->route_map[type].name); |
| 166 | |
| 167 | rip->route_map[type].name = strdup (name); |
| 168 | rip->route_map[type].map = route_map_lookup_by_name (name); |
| 169 | } |
| 170 | |
| 171 | void |
hasso | 8a676be | 2004-10-08 06:36:38 +0000 | [diff] [blame] | 172 | rip_redistribute_metric_set (int type, unsigned int metric) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 173 | { |
| 174 | rip->route_map[type].metric_config = 1; |
| 175 | rip->route_map[type].metric = metric; |
| 176 | } |
| 177 | |
| 178 | int |
hasso | 8a676be | 2004-10-08 06:36:38 +0000 | [diff] [blame] | 179 | rip_metric_unset (int type, unsigned int metric) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 180 | { |
| 181 | #define DONT_CARE_METRIC_RIP 17 |
| 182 | if (metric != DONT_CARE_METRIC_RIP && |
| 183 | rip->route_map[type].metric != metric) |
| 184 | return 1; |
| 185 | rip->route_map[type].metric_config = 0; |
| 186 | rip->route_map[type].metric = 0; |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | /* RIP route-map unset for redistribution */ |
| 191 | int |
hasso | 98b718a | 2004-10-11 12:57:57 +0000 | [diff] [blame] | 192 | rip_routemap_unset (int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 193 | { |
| 194 | if (! rip->route_map[type].name || |
| 195 | (name != NULL && strcmp(rip->route_map[type].name,name))) |
| 196 | return 1; |
| 197 | |
| 198 | free (rip->route_map[type].name); |
| 199 | rip->route_map[type].name = NULL; |
| 200 | rip->route_map[type].map = NULL; |
| 201 | |
| 202 | return 0; |
| 203 | } |
| 204 | |
| 205 | /* Redistribution types */ |
| 206 | static struct { |
| 207 | int type; |
| 208 | int str_min_len; |
hasso | 8a676be | 2004-10-08 06:36:38 +0000 | [diff] [blame] | 209 | const char *str; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 210 | } redist_type[] = { |
| 211 | {ZEBRA_ROUTE_KERNEL, 1, "kernel"}, |
| 212 | {ZEBRA_ROUTE_CONNECT, 1, "connected"}, |
| 213 | {ZEBRA_ROUTE_STATIC, 1, "static"}, |
| 214 | {ZEBRA_ROUTE_OSPF, 1, "ospf"}, |
| 215 | {ZEBRA_ROUTE_BGP, 1, "bgp"}, |
| 216 | {0, 0, NULL} |
| 217 | }; |
| 218 | |
| 219 | DEFUN (router_zebra, |
| 220 | router_zebra_cmd, |
| 221 | "router zebra", |
| 222 | "Enable a routing process\n" |
| 223 | "Make connection to zebra daemon\n") |
| 224 | { |
| 225 | vty->node = ZEBRA_NODE; |
| 226 | zclient->enable = 1; |
| 227 | zclient_start (zclient); |
| 228 | return CMD_SUCCESS; |
| 229 | } |
| 230 | |
| 231 | DEFUN (no_router_zebra, |
| 232 | no_router_zebra_cmd, |
| 233 | "no router zebra", |
| 234 | NO_STR |
| 235 | "Enable a routing process\n" |
| 236 | "Make connection to zebra daemon\n") |
| 237 | { |
| 238 | zclient->enable = 0; |
| 239 | zclient_stop (zclient); |
| 240 | return CMD_SUCCESS; |
| 241 | } |
| 242 | |
| 243 | int |
| 244 | rip_redistribute_set (int type) |
| 245 | { |
| 246 | if (zclient->redist[type]) |
| 247 | return CMD_SUCCESS; |
| 248 | |
| 249 | zclient->redist[type] = 1; |
| 250 | |
| 251 | if (zclient->sock > 0) |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 252 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 253 | |
| 254 | return CMD_SUCCESS; |
| 255 | } |
| 256 | |
| 257 | int |
| 258 | rip_redistribute_unset (int type) |
| 259 | { |
| 260 | if (! zclient->redist[type]) |
| 261 | return CMD_SUCCESS; |
| 262 | |
| 263 | zclient->redist[type] = 0; |
| 264 | |
| 265 | if (zclient->sock > 0) |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 266 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, zclient, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 267 | |
| 268 | /* Remove the routes from RIP table. */ |
| 269 | rip_redistribute_withdraw (type); |
| 270 | |
| 271 | return CMD_SUCCESS; |
| 272 | } |
| 273 | |
| 274 | int |
| 275 | rip_redistribute_check (int type) |
| 276 | { |
| 277 | return (zclient->redist[type]); |
| 278 | } |
| 279 | |
| 280 | void |
| 281 | rip_redistribute_clean () |
| 282 | { |
| 283 | int i; |
| 284 | |
| 285 | for (i = 0; redist_type[i].str; i++) |
| 286 | { |
| 287 | if (zclient->redist[redist_type[i].type]) |
| 288 | { |
| 289 | if (zclient->sock > 0) |
| 290 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_DELETE, |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 291 | zclient, redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 292 | |
| 293 | zclient->redist[redist_type[i].type] = 0; |
| 294 | |
| 295 | /* Remove the routes from RIP table. */ |
| 296 | rip_redistribute_withdraw (redist_type[i].type); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | DEFUN (rip_redistribute_rip, |
| 302 | rip_redistribute_rip_cmd, |
| 303 | "redistribute rip", |
| 304 | "Redistribute information from another routing protocol\n" |
| 305 | "Routing Information Protocol (RIP)\n") |
| 306 | { |
| 307 | zclient->redist[ZEBRA_ROUTE_RIP] = 1; |
| 308 | return CMD_SUCCESS; |
| 309 | } |
| 310 | |
| 311 | DEFUN (no_rip_redistribute_rip, |
| 312 | no_rip_redistribute_rip_cmd, |
| 313 | "no redistribute rip", |
| 314 | NO_STR |
| 315 | "Redistribute information from another routing protocol\n" |
| 316 | "Routing Information Protocol (RIP)\n") |
| 317 | { |
| 318 | zclient->redist[ZEBRA_ROUTE_RIP] = 0; |
| 319 | return CMD_SUCCESS; |
| 320 | } |
| 321 | |
| 322 | DEFUN (rip_redistribute_type, |
| 323 | rip_redistribute_type_cmd, |
| 324 | "redistribute (kernel|connected|static|ospf|bgp)", |
| 325 | "Redistribute information from another routing protocol\n" |
| 326 | "Kernel routes\n" |
| 327 | "Connected\n" |
| 328 | "Static routes\n" |
| 329 | "Open Shortest Path First (OSPF)\n" |
| 330 | "Border Gateway Protocol (BGP)\n") |
| 331 | { |
| 332 | int i; |
| 333 | |
| 334 | for(i = 0; redist_type[i].str; i++) |
| 335 | { |
| 336 | if (strncmp (redist_type[i].str, argv[0], |
| 337 | redist_type[i].str_min_len) == 0) |
| 338 | { |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 339 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, |
| 340 | redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | return CMD_SUCCESS; |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 346 | VTY_NEWLINE); |
| 347 | |
| 348 | return CMD_WARNING; |
| 349 | } |
| 350 | |
| 351 | DEFUN (no_rip_redistribute_type, |
| 352 | no_rip_redistribute_type_cmd, |
| 353 | "no redistribute (kernel|connected|static|ospf|bgp)", |
| 354 | NO_STR |
| 355 | "Redistribute information from another routing protocol\n" |
| 356 | "Kernel routes\n" |
| 357 | "Connected\n" |
| 358 | "Static routes\n" |
| 359 | "Open Shortest Path First (OSPF)\n" |
| 360 | "Border Gateway Protocol (BGP)\n") |
| 361 | { |
| 362 | int i; |
| 363 | |
| 364 | for (i = 0; redist_type[i].str; i++) |
| 365 | { |
| 366 | if (strncmp(redist_type[i].str, argv[0], |
| 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 | |
| 376 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 377 | VTY_NEWLINE); |
| 378 | |
| 379 | return CMD_WARNING; |
| 380 | } |
| 381 | |
| 382 | DEFUN (rip_redistribute_type_routemap, |
| 383 | rip_redistribute_type_routemap_cmd, |
| 384 | "redistribute (kernel|connected|static|ospf|bgp) route-map WORD", |
| 385 | "Redistribute information from another routing protocol\n" |
| 386 | "Kernel routes\n" |
| 387 | "Connected\n" |
| 388 | "Static routes\n" |
| 389 | "Open Shortest Path First (OSPF)\n" |
| 390 | "Border Gateway Protocol (BGP)\n" |
| 391 | "Route map reference\n" |
| 392 | "Pointer to route-map entries\n") |
| 393 | { |
| 394 | int i; |
| 395 | |
| 396 | for (i = 0; redist_type[i].str; i++) { |
| 397 | if (strncmp(redist_type[i].str, argv[0], |
| 398 | redist_type[i].str_min_len) == 0) |
| 399 | { |
| 400 | rip_routemap_set (redist_type[i].type, argv[1]); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 401 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
| 412 | DEFUN (no_rip_redistribute_type_routemap, |
| 413 | no_rip_redistribute_type_routemap_cmd, |
| 414 | "no redistribute (kernel|connected|static|ospf|bgp) route-map WORD", |
| 415 | NO_STR |
| 416 | "Redistribute information from another routing protocol\n" |
| 417 | "Kernel routes\n" |
| 418 | "Connected\n" |
| 419 | "Static routes\n" |
| 420 | "Open Shortest Path First (OSPF)\n" |
| 421 | "Border Gateway Protocol (BGP)\n" |
| 422 | "Route map reference\n" |
| 423 | "Pointer to route-map entries\n") |
| 424 | { |
| 425 | int i; |
| 426 | |
| 427 | for (i = 0; redist_type[i].str; i++) |
| 428 | { |
| 429 | if (strncmp(redist_type[i].str, argv[0], |
| 430 | redist_type[i].str_min_len) == 0) |
| 431 | { |
| 432 | if (rip_routemap_unset (redist_type[i].type,argv[1])) |
| 433 | return CMD_WARNING; |
| 434 | rip_redistribute_unset (redist_type[i].type); |
| 435 | return CMD_SUCCESS; |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 440 | VTY_NEWLINE); |
| 441 | |
| 442 | return CMD_WARNING; |
| 443 | } |
| 444 | |
| 445 | DEFUN (rip_redistribute_type_metric, |
| 446 | rip_redistribute_type_metric_cmd, |
| 447 | "redistribute (kernel|connected|static|ospf|bgp) metric <0-16>", |
| 448 | "Redistribute information from another routing protocol\n" |
| 449 | "Kernel routes\n" |
| 450 | "Connected\n" |
| 451 | "Static routes\n" |
| 452 | "Open Shortest Path First (OSPF)\n" |
| 453 | "Border Gateway Protocol (BGP)\n" |
| 454 | "Metric\n" |
| 455 | "Metric value\n") |
| 456 | { |
| 457 | int i; |
| 458 | int metric; |
| 459 | |
| 460 | metric = atoi (argv[1]); |
| 461 | |
| 462 | for (i = 0; redist_type[i].str; i++) { |
| 463 | if (strncmp(redist_type[i].str, argv[0], |
| 464 | redist_type[i].str_min_len) == 0) |
| 465 | { |
| 466 | rip_redistribute_metric_set (redist_type[i].type, metric); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 467 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 468 | return CMD_SUCCESS; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 473 | VTY_NEWLINE); |
| 474 | |
| 475 | return CMD_WARNING; |
| 476 | } |
| 477 | |
| 478 | DEFUN (no_rip_redistribute_type_metric, |
| 479 | no_rip_redistribute_type_metric_cmd, |
| 480 | "no redistribute (kernel|connected|static|ospf|bgp) metric <0-16>", |
| 481 | NO_STR |
| 482 | "Redistribute information from another routing protocol\n" |
| 483 | "Kernel routes\n" |
| 484 | "Connected\n" |
| 485 | "Static routes\n" |
| 486 | "Open Shortest Path First (OSPF)\n" |
| 487 | "Border Gateway Protocol (BGP)\n" |
| 488 | "Metric\n" |
| 489 | "Metric value\n") |
| 490 | { |
| 491 | int i; |
| 492 | |
| 493 | for (i = 0; redist_type[i].str; i++) |
| 494 | { |
| 495 | if (strncmp(redist_type[i].str, argv[0], |
| 496 | redist_type[i].str_min_len) == 0) |
| 497 | { |
| 498 | if (rip_metric_unset (redist_type[i].type, atoi(argv[1]))) |
| 499 | return CMD_WARNING; |
| 500 | rip_redistribute_unset (redist_type[i].type); |
| 501 | return CMD_SUCCESS; |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 506 | VTY_NEWLINE); |
| 507 | |
| 508 | return CMD_WARNING; |
| 509 | } |
| 510 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 511 | DEFUN (rip_redistribute_type_metric_routemap, |
| 512 | rip_redistribute_type_metric_routemap_cmd, |
| 513 | "redistribute (kernel|connected|static|ospf|bgp) metric <0-16> route-map WORD", |
| 514 | "Redistribute information from another routing protocol\n" |
| 515 | "Kernel routes\n" |
| 516 | "Connected\n" |
| 517 | "Static routes\n" |
| 518 | "Open Shortest Path First (OSPF)\n" |
| 519 | "Border Gateway Protocol (BGP)\n" |
| 520 | "Metric\n" |
| 521 | "Metric value\n" |
| 522 | "Route map reference\n" |
| 523 | "Pointer to route-map entries\n") |
| 524 | { |
| 525 | int i; |
| 526 | int metric; |
| 527 | |
| 528 | metric = atoi (argv[1]); |
| 529 | |
| 530 | for (i = 0; redist_type[i].str; i++) { |
| 531 | if (strncmp(redist_type[i].str, argv[0], |
| 532 | redist_type[i].str_min_len) == 0) |
| 533 | { |
| 534 | rip_redistribute_metric_set (redist_type[i].type, metric); |
| 535 | rip_routemap_set (redist_type[i].type, argv[2]); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 536 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, redist_type[i].type); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 537 | return CMD_SUCCESS; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 542 | VTY_NEWLINE); |
| 543 | |
| 544 | return CMD_WARNING; |
| 545 | } |
| 546 | |
| 547 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 548 | DEFUN (no_rip_redistribute_type_metric_routemap, |
| 549 | no_rip_redistribute_type_metric_routemap_cmd, |
| 550 | "no redistribute (kernel|connected|static|ospf|bgp) metric <0-16> route-map WORD", |
| 551 | NO_STR |
| 552 | "Redistribute information from another routing protocol\n" |
| 553 | "Kernel routes\n" |
| 554 | "Connected\n" |
| 555 | "Static routes\n" |
| 556 | "Open Shortest Path First (OSPF)\n" |
| 557 | "Border Gateway Protocol (BGP)\n" |
| 558 | "Metric\n" |
| 559 | "Metric value\n" |
| 560 | "Route map reference\n" |
| 561 | "Pointer to route-map entries\n") |
| 562 | { |
| 563 | int i; |
| 564 | |
| 565 | for (i = 0; redist_type[i].str; i++) |
| 566 | { |
| 567 | if (strncmp(redist_type[i].str, argv[0], |
| 568 | redist_type[i].str_min_len) == 0) |
| 569 | { |
| 570 | if (rip_metric_unset (redist_type[i].type, atoi(argv[1]))) |
| 571 | return CMD_WARNING; |
| 572 | if (rip_routemap_unset (redist_type[i].type, argv[2])) |
| 573 | { |
| 574 | rip_redistribute_metric_set(redist_type[i].type, atoi(argv[1])); |
| 575 | return CMD_WARNING; |
| 576 | } |
| 577 | rip_redistribute_unset (redist_type[i].type); |
| 578 | return CMD_SUCCESS; |
| 579 | } |
| 580 | } |
| 581 | |
| 582 | vty_out(vty, "Invalid type %s%s", argv[0], |
| 583 | VTY_NEWLINE); |
| 584 | |
| 585 | return CMD_WARNING; |
| 586 | } |
| 587 | |
| 588 | /* Default information originate. */ |
| 589 | |
| 590 | DEFUN (rip_default_information_originate, |
| 591 | rip_default_information_originate_cmd, |
| 592 | "default-information originate", |
| 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 = 1; |
| 604 | |
vincent | fbf5d03 | 2005-09-29 11:25:50 +0000 | [diff] [blame] | 605 | rip_redistribute_add (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0, |
| 606 | NULL, 0, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | return CMD_SUCCESS; |
| 610 | } |
| 611 | |
| 612 | DEFUN (no_rip_default_information_originate, |
| 613 | no_rip_default_information_originate_cmd, |
| 614 | "no default-information originate", |
| 615 | NO_STR |
| 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 = 0; |
| 627 | |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 628 | rip_redistribute_delete (ZEBRA_ROUTE_RIP, RIP_ROUTE_DEFAULT, &p, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | return CMD_SUCCESS; |
| 632 | } |
| 633 | |
| 634 | /* RIP configuration write function. */ |
| 635 | int |
| 636 | config_write_zebra (struct vty *vty) |
| 637 | { |
| 638 | if (! zclient->enable) |
| 639 | { |
| 640 | vty_out (vty, "no router zebra%s", VTY_NEWLINE); |
| 641 | return 1; |
| 642 | } |
| 643 | else if (! zclient->redist[ZEBRA_ROUTE_RIP]) |
| 644 | { |
| 645 | vty_out (vty, "router zebra%s", VTY_NEWLINE); |
| 646 | vty_out (vty, " no redistribute rip%s", VTY_NEWLINE); |
| 647 | return 1; |
| 648 | } |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | int |
| 653 | config_write_rip_redistribute (struct vty *vty, int config_mode) |
| 654 | { |
| 655 | int i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 656 | |
| 657 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 658 | if (i != zclient->redist_default && zclient->redist[i]) |
| 659 | { |
| 660 | if (config_mode) |
| 661 | { |
| 662 | if (rip->route_map[i].metric_config) |
| 663 | { |
| 664 | if (rip->route_map[i].name) |
| 665 | vty_out (vty, " redistribute %s metric %d route-map %s%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame^] | 666 | zebra_route_string(i), rip->route_map[i].metric, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 667 | rip->route_map[i].name, |
| 668 | VTY_NEWLINE); |
| 669 | else |
| 670 | vty_out (vty, " redistribute %s metric %d%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame^] | 671 | zebra_route_string(i), rip->route_map[i].metric, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 672 | VTY_NEWLINE); |
| 673 | } |
| 674 | else |
| 675 | { |
| 676 | if (rip->route_map[i].name) |
| 677 | vty_out (vty, " redistribute %s route-map %s%s", |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame^] | 678 | zebra_route_string(i), rip->route_map[i].name, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | VTY_NEWLINE); |
| 680 | else |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame^] | 681 | vty_out (vty, " redistribute %s%s", zebra_route_string(i), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 682 | VTY_NEWLINE); |
| 683 | } |
| 684 | } |
| 685 | else |
ajs | f52d13c | 2005-10-01 17:38:06 +0000 | [diff] [blame^] | 686 | vty_out (vty, " %s", zebra_route_string(i)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | } |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | /* Zebra node structure. */ |
| 692 | struct cmd_node zebra_node = |
| 693 | { |
| 694 | ZEBRA_NODE, |
| 695 | "%s(config-router)# ", |
| 696 | }; |
| 697 | |
| 698 | void |
| 699 | rip_zclient_init () |
| 700 | { |
| 701 | /* Set default value to the zebra client structure. */ |
| 702 | zclient = zclient_new (); |
| 703 | zclient_init (zclient, ZEBRA_ROUTE_RIP); |
| 704 | zclient->interface_add = rip_interface_add; |
| 705 | zclient->interface_delete = rip_interface_delete; |
| 706 | zclient->interface_address_add = rip_interface_address_add; |
| 707 | zclient->interface_address_delete = rip_interface_address_delete; |
| 708 | zclient->ipv4_route_add = rip_zebra_read_ipv4; |
| 709 | zclient->ipv4_route_delete = rip_zebra_read_ipv4; |
| 710 | zclient->interface_up = rip_interface_up; |
| 711 | zclient->interface_down = rip_interface_down; |
| 712 | |
| 713 | /* Install zebra node. */ |
| 714 | install_node (&zebra_node, config_write_zebra); |
| 715 | |
| 716 | /* Install command elements to zebra node. */ |
| 717 | install_element (CONFIG_NODE, &router_zebra_cmd); |
| 718 | install_element (CONFIG_NODE, &no_router_zebra_cmd); |
| 719 | install_default (ZEBRA_NODE); |
| 720 | install_element (ZEBRA_NODE, &rip_redistribute_rip_cmd); |
| 721 | install_element (ZEBRA_NODE, &no_rip_redistribute_rip_cmd); |
| 722 | |
| 723 | /* Install command elements to rip node. */ |
| 724 | install_element (RIP_NODE, &rip_redistribute_type_cmd); |
| 725 | install_element (RIP_NODE, &rip_redistribute_type_routemap_cmd); |
| 726 | install_element (RIP_NODE, &rip_redistribute_type_metric_cmd); |
hasso | 1670513 | 2003-05-25 14:49:19 +0000 | [diff] [blame] | 727 | install_element (RIP_NODE, &rip_redistribute_type_metric_routemap_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 728 | install_element (RIP_NODE, &no_rip_redistribute_type_cmd); |
| 729 | install_element (RIP_NODE, &no_rip_redistribute_type_routemap_cmd); |
| 730 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_cmd); |
| 731 | install_element (RIP_NODE, &no_rip_redistribute_type_metric_routemap_cmd); |
| 732 | install_element (RIP_NODE, &rip_default_information_originate_cmd); |
| 733 | install_element (RIP_NODE, &no_rip_default_information_originate_cmd); |
| 734 | } |