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