Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_redist.c |
| 3 | * |
| 4 | * Copyright (C) 2013-2015 Christian Franke <chris@opensourcerouting.org> |
| 5 | * |
| 6 | * This program 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 Free |
| 8 | * Software Foundation; either version 2 of the License, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <zebra.h> |
| 22 | |
| 23 | #include "command.h" |
| 24 | #include "if.h" |
| 25 | #include "linklist.h" |
| 26 | #include "memory.h" |
| 27 | #include "memtypes.h" |
| 28 | #include "prefix.h" |
| 29 | #include "routemap.h" |
| 30 | #include "stream.h" |
| 31 | #include "table.h" |
| 32 | #include "vty.h" |
| 33 | |
| 34 | #include "isisd/dict.h" |
| 35 | #include "isisd/isis_constants.h" |
| 36 | #include "isisd/isis_common.h" |
| 37 | #include "isisd/isis_flags.h" |
| 38 | #include "isisd/isis_misc.h" |
| 39 | #include "isisd/isis_circuit.h" |
| 40 | #include "isisd/isis_tlv.h" |
| 41 | #include "isisd/isisd.h" |
| 42 | #include "isisd/isis_lsp.h" |
| 43 | #include "isisd/isis_route.h" |
| 44 | #include "isisd/isis_zebra.h" |
| 45 | |
| 46 | static int |
| 47 | redist_protocol(int family) |
| 48 | { |
| 49 | if (family == AF_INET) |
| 50 | return 0; |
| 51 | if (family == AF_INET6) |
| 52 | return 1; |
| 53 | |
| 54 | assert(!"Unsupported address family!"); |
| 55 | } |
| 56 | |
| 57 | static int |
| 58 | is_default(struct prefix *p) |
| 59 | { |
| 60 | if (p->family == AF_INET) |
| 61 | if (p->u.prefix4.s_addr == 0 && p->prefixlen == 0) |
| 62 | return 1; |
| 63 | if (p->family == AF_INET6) |
| 64 | if (IN6_IS_ADDR_UNSPECIFIED(&p->u.prefix6) && p->prefixlen == 0) |
| 65 | return 1; |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static struct route_table* |
| 70 | get_ext_info(struct isis *i, int family) |
| 71 | { |
| 72 | int protocol = redist_protocol(family); |
| 73 | |
| 74 | return i->ext_info[protocol]; |
| 75 | } |
| 76 | |
| 77 | static struct isis_redist* |
| 78 | get_redist_settings(struct isis_area *area, int family, int type, int level) |
| 79 | { |
| 80 | int protocol = redist_protocol(family); |
| 81 | |
| 82 | return &area->redist_settings[protocol][type][level-1]; |
| 83 | } |
| 84 | |
| 85 | struct route_table* |
| 86 | get_ext_reach(struct isis_area *area, int family, int level) |
| 87 | { |
| 88 | int protocol = redist_protocol(family); |
| 89 | |
| 90 | return area->ext_reach[protocol][level-1]; |
| 91 | } |
| 92 | |
| 93 | static struct route_node * |
| 94 | isis_redist_route_node_create(route_table_delegate_t *delegate, |
| 95 | struct route_table *table) |
| 96 | { |
| 97 | struct route_node *node; |
| 98 | node = XCALLOC(MTYPE_ROUTE_NODE, sizeof(*node)); |
| 99 | return node; |
| 100 | } |
| 101 | |
| 102 | static void |
| 103 | isis_redist_route_node_destroy(route_table_delegate_t *delegate, |
| 104 | struct route_table *table, |
| 105 | struct route_node *node) |
| 106 | { |
| 107 | if (node->info) |
| 108 | XFREE(MTYPE_ISIS, node->info); |
| 109 | XFREE (MTYPE_ROUTE_NODE, node); |
| 110 | } |
| 111 | |
| 112 | static route_table_delegate_t isis_redist_rt_delegate = { |
| 113 | .create_node = isis_redist_route_node_create, |
| 114 | .destroy_node = isis_redist_route_node_destroy |
| 115 | }; |
| 116 | |
| 117 | /* Install external reachability information into a |
| 118 | * specific area for a specific level. |
| 119 | * Schedule an lsp regenerate if necessary */ |
| 120 | static void |
| 121 | isis_redist_install(struct isis_area *area, int level, |
| 122 | struct prefix *p, struct isis_ext_info *info) |
| 123 | { |
| 124 | int family = p->family; |
| 125 | struct route_table *er_table = get_ext_reach(area, family, level); |
| 126 | struct route_node *er_node; |
| 127 | |
| 128 | if (!er_table) |
| 129 | { |
| 130 | zlog_warn("%s: External reachability table of area %s" |
| 131 | " is not initialized.", __func__, area->area_tag); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | er_node = route_node_get(er_table, p); |
| 136 | if (er_node->info) |
| 137 | { |
| 138 | route_unlock_node(er_node); |
| 139 | |
| 140 | /* Don't update/reschedule lsp generation if nothing changed. */ |
| 141 | if (!memcmp(er_node->info, info, sizeof(*info))) |
| 142 | return; |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | er_node->info = XMALLOC(MTYPE_ISIS, sizeof(*info)); |
| 147 | } |
| 148 | |
| 149 | memcpy(er_node->info, info, sizeof(*info)); |
| 150 | lsp_regenerate_schedule(area, level, 0); |
| 151 | } |
| 152 | |
| 153 | /* Remove external reachability information from a |
| 154 | * specific area for a specific level. |
| 155 | * Schedule an lsp regenerate if necessary. */ |
| 156 | static void |
| 157 | isis_redist_uninstall(struct isis_area *area, int level, struct prefix *p) |
| 158 | { |
| 159 | int family = p->family; |
| 160 | struct route_table *er_table = get_ext_reach(area, family, level); |
| 161 | struct route_node *er_node; |
| 162 | |
| 163 | if (!er_table) |
| 164 | { |
| 165 | zlog_warn("%s: External reachability table of area %s" |
| 166 | " is not initialized.", __func__, area->area_tag); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | er_node = route_node_lookup(er_table, p); |
| 171 | if (!er_node) |
| 172 | return; |
| 173 | else |
| 174 | route_unlock_node(er_node); |
| 175 | |
| 176 | if (!er_node->info) |
| 177 | return; |
| 178 | |
Christian Franke | 106e38e | 2016-04-03 12:46:25 -0300 | [diff] [blame] | 179 | XFREE(MTYPE_ISIS, er_node->info); |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 180 | route_unlock_node(er_node); |
| 181 | lsp_regenerate_schedule(area, level, 0); |
| 182 | } |
| 183 | |
| 184 | /* Update external reachability info of area for a given level |
| 185 | * and prefix, using the given redistribution settings. */ |
| 186 | static void |
| 187 | isis_redist_update_ext_reach(struct isis_area *area, int level, |
| 188 | struct isis_redist *redist, struct prefix *p, |
| 189 | struct isis_ext_info *info) |
| 190 | { |
| 191 | struct isis_ext_info area_info; |
| 192 | route_map_result_t map_ret; |
| 193 | |
| 194 | memcpy(&area_info, info, sizeof(area_info)); |
| 195 | if (redist->metric != 0xffffffff) |
| 196 | area_info.metric = redist->metric; |
| 197 | |
| 198 | if (redist->map_name) |
| 199 | { |
| 200 | map_ret = route_map_apply(redist->map, p, RMAP_ISIS, &area_info); |
| 201 | if (map_ret == RMAP_DENYMATCH) |
| 202 | area_info.distance = 255; |
| 203 | } |
| 204 | |
| 205 | /* Allow synthesized default routes only on always orignate */ |
| 206 | if (area_info.origin == DEFAULT_ROUTE |
| 207 | && redist->redist != DEFAULT_ORIGINATE_ALWAYS) |
| 208 | area_info.distance = 255; |
| 209 | |
| 210 | if (area_info.distance < 255) |
| 211 | isis_redist_install(area, level, p, &area_info); |
| 212 | else |
| 213 | isis_redist_uninstall(area, level, p); |
| 214 | } |
| 215 | |
| 216 | static void |
| 217 | isis_redist_ensure_default(struct isis *isis, int family) |
| 218 | { |
| 219 | struct prefix p; |
| 220 | struct route_table *ei_table = get_ext_info(isis, family); |
| 221 | struct route_node *ei_node; |
| 222 | struct isis_ext_info *info; |
| 223 | |
| 224 | if (family == AF_INET) |
| 225 | { |
| 226 | p.family = AF_INET; |
| 227 | p.prefixlen = 0; |
| 228 | memset(&p.u.prefix4, 0, sizeof(p.u.prefix4)); |
| 229 | } |
| 230 | else if (family == AF_INET6) |
| 231 | { |
| 232 | p.family = AF_INET6; |
| 233 | p.prefixlen = 0; |
| 234 | memset(&p.u.prefix6, 0, sizeof(p.u.prefix6)); |
| 235 | } |
| 236 | else |
| 237 | assert(!"Unknown family!"); |
| 238 | |
| 239 | ei_node = route_node_get(ei_table, &p); |
| 240 | if (ei_node->info) |
| 241 | { |
| 242 | route_unlock_node(ei_node); |
| 243 | return; |
| 244 | } |
| 245 | |
| 246 | ei_node->info = XCALLOC(MTYPE_ISIS, sizeof(struct isis_ext_info)); |
| 247 | |
| 248 | info = ei_node->info; |
| 249 | info->origin = DEFAULT_ROUTE; |
| 250 | info->distance = 254; |
| 251 | info->metric = MAX_WIDE_PATH_METRIC; |
| 252 | } |
| 253 | |
| 254 | /* Handle notification about route being added */ |
| 255 | void |
| 256 | isis_redist_add(int type, struct prefix *p, u_char distance, uint32_t metric) |
| 257 | { |
| 258 | int family = p->family; |
| 259 | struct route_table *ei_table = get_ext_info(isis, family); |
| 260 | struct route_node *ei_node; |
| 261 | struct isis_ext_info *info; |
| 262 | struct listnode *node; |
| 263 | struct isis_area *area; |
| 264 | int level; |
| 265 | struct isis_redist *redist; |
| 266 | |
| 267 | char debug_buf[BUFSIZ]; |
| 268 | prefix2str(p, debug_buf, sizeof(debug_buf)); |
| 269 | |
| 270 | zlog_debug("%s: New route %s from %s.", __func__, debug_buf, |
| 271 | zebra_route_string(type)); |
| 272 | |
| 273 | if (!ei_table) |
| 274 | { |
| 275 | zlog_warn("%s: External information table not initialized.", |
| 276 | __func__); |
| 277 | return; |
| 278 | } |
| 279 | |
| 280 | ei_node = route_node_get(ei_table, p); |
| 281 | if (ei_node->info) |
| 282 | route_unlock_node(ei_node); |
| 283 | else |
| 284 | ei_node->info = XCALLOC(MTYPE_ISIS, sizeof(struct isis_ext_info)); |
| 285 | |
| 286 | info = ei_node->info; |
| 287 | info->origin = type; |
| 288 | info->distance = distance; |
| 289 | info->metric = metric; |
| 290 | |
| 291 | if (is_default(p)) |
| 292 | type = DEFAULT_ROUTE; |
| 293 | |
| 294 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) |
| 295 | for (level = 1; level <= ISIS_LEVELS; level++) |
| 296 | { |
| 297 | redist = get_redist_settings(area, family, type, level); |
| 298 | if (!redist->redist) |
| 299 | continue; |
| 300 | |
| 301 | isis_redist_update_ext_reach(area, level, redist, p, info); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | void |
| 306 | isis_redist_delete(int type, struct prefix *p) |
| 307 | { |
| 308 | int family = p->family; |
| 309 | struct route_table *ei_table = get_ext_info(isis, family); |
| 310 | struct route_node *ei_node; |
| 311 | struct listnode *node; |
| 312 | struct isis_area *area; |
| 313 | int level; |
| 314 | struct isis_redist *redist; |
| 315 | |
| 316 | char debug_buf[BUFSIZ]; |
| 317 | prefix2str(p, debug_buf, sizeof(debug_buf)); |
| 318 | |
| 319 | zlog_debug("%s: Removing route %s from %s.", __func__, debug_buf, |
| 320 | zebra_route_string(type)); |
| 321 | |
| 322 | if (is_default(p)) |
| 323 | { |
| 324 | /* Don't remove default route but add synthetic route for use |
| 325 | * by "default-information originate always". Areas without the |
| 326 | * "always" setting will ignore routes with origin DEFAULT_ROUTE. */ |
| 327 | isis_redist_add(DEFAULT_ROUTE, p, 254, MAX_WIDE_PATH_METRIC); |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | if (!ei_table) |
| 332 | { |
| 333 | zlog_warn("%s: External information table not initialized.", |
| 334 | __func__); |
| 335 | return; |
| 336 | } |
| 337 | |
| 338 | ei_node = route_node_lookup(ei_table, p); |
| 339 | if (!ei_node || !ei_node->info) |
| 340 | { |
| 341 | char buf[BUFSIZ]; |
| 342 | prefix2str(p, buf, sizeof(buf)); |
| 343 | zlog_warn("%s: Got a delete for %s route %s, but that route" |
| 344 | " was never added.", __func__, zebra_route_string(type), |
| 345 | buf); |
| 346 | if (ei_node) |
| 347 | route_unlock_node(ei_node); |
| 348 | return; |
| 349 | } |
| 350 | route_unlock_node(ei_node); |
| 351 | |
| 352 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) |
| 353 | for (level = 1; level < ISIS_LEVELS; level++) |
| 354 | { |
| 355 | redist = get_redist_settings(area, family, type, level); |
| 356 | if (!redist->redist) |
| 357 | continue; |
| 358 | |
| 359 | isis_redist_uninstall(area, level, p); |
| 360 | } |
| 361 | |
Christian Franke | 106e38e | 2016-04-03 12:46:25 -0300 | [diff] [blame] | 362 | XFREE(MTYPE_ISIS, ei_node->info); |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 363 | route_unlock_node(ei_node); |
| 364 | } |
| 365 | |
| 366 | static void |
| 367 | isis_redist_routemap_set(struct isis_redist *redist, const char *routemap) |
| 368 | { |
| 369 | if (redist->map_name) { |
| 370 | XFREE(MTYPE_ISIS, redist->map_name); |
| 371 | redist->map = NULL; |
| 372 | } |
| 373 | |
| 374 | if (routemap && strlen(routemap)) { |
| 375 | redist->map_name = XSTRDUP(MTYPE_ISIS, routemap); |
| 376 | redist->map = route_map_lookup_by_name(routemap); |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | static void |
| 381 | isis_redist_update_zebra_subscriptions(struct isis *isis) |
| 382 | { |
| 383 | struct listnode *node; |
| 384 | struct isis_area *area; |
| 385 | int type; |
| 386 | int level; |
| 387 | int protocol; |
| 388 | |
| 389 | char do_subscribe[ZEBRA_ROUTE_MAX + 1]; |
| 390 | |
| 391 | memset(do_subscribe, 0, sizeof(do_subscribe)); |
| 392 | |
| 393 | for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) |
| 394 | for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++) |
| 395 | for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) |
| 396 | for (level = 0; level < ISIS_LEVELS; level++) |
| 397 | if (area->redist_settings[protocol][type][level].redist) |
| 398 | do_subscribe[type] = 1; |
| 399 | |
| 400 | for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) |
| 401 | { |
| 402 | /* This field is actually controlling transmission of the IS-IS |
| 403 | * routes to Zebra and has nothing to do with redistribution, |
| 404 | * so skip it. */ |
| 405 | if (type == ZEBRA_ROUTE_ISIS) |
| 406 | continue; |
| 407 | |
| 408 | if (do_subscribe[type]) |
| 409 | isis_zebra_redistribute_set(type); |
| 410 | else |
| 411 | isis_zebra_redistribute_unset(type); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | static void |
| 416 | isis_redist_set(struct isis_area *area, int level, |
| 417 | int family, int type, uint32_t metric, |
| 418 | const char *routemap, int originate_type) |
| 419 | { |
| 420 | int protocol = redist_protocol(family); |
| 421 | struct isis_redist *redist = get_redist_settings(area, family, type, level); |
| 422 | int i; |
| 423 | struct route_table *ei_table; |
| 424 | struct route_node *rn; |
| 425 | struct isis_ext_info *info; |
| 426 | |
| 427 | redist->redist = (type == DEFAULT_ROUTE) ? originate_type : 1; |
| 428 | redist->metric = metric; |
| 429 | isis_redist_routemap_set(redist, routemap); |
| 430 | |
| 431 | if (!area->ext_reach[protocol][level-1]) |
| 432 | { |
| 433 | area->ext_reach[protocol][level-1] = |
| 434 | route_table_init_with_delegate(&isis_redist_rt_delegate); |
| 435 | } |
| 436 | |
| 437 | for (i = 0; i < REDIST_PROTOCOL_COUNT; i++) |
| 438 | if (!area->isis->ext_info[i]) |
| 439 | { |
| 440 | area->isis->ext_info[i] = |
| 441 | route_table_init_with_delegate(&isis_redist_rt_delegate); |
| 442 | } |
| 443 | |
| 444 | isis_redist_update_zebra_subscriptions(area->isis); |
| 445 | |
| 446 | if (type == DEFAULT_ROUTE && originate_type == DEFAULT_ORIGINATE_ALWAYS) |
| 447 | isis_redist_ensure_default(area->isis, family); |
| 448 | |
| 449 | ei_table = get_ext_info(area->isis, family); |
| 450 | for (rn = route_top(ei_table); rn; rn = route_next(rn)) |
| 451 | { |
| 452 | if (!rn->info) |
| 453 | continue; |
| 454 | info = rn->info; |
| 455 | |
| 456 | if (type == DEFAULT_ROUTE) |
| 457 | { |
| 458 | if (!is_default(&rn->p)) |
| 459 | continue; |
| 460 | } |
| 461 | else |
| 462 | { |
| 463 | if (info->origin != type) |
| 464 | continue; |
| 465 | } |
| 466 | |
| 467 | isis_redist_update_ext_reach(area, level, redist, &rn->p, info); |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | static void |
| 472 | isis_redist_unset(struct isis_area *area, int level, |
| 473 | int family, int type) |
| 474 | { |
| 475 | struct isis_redist *redist = get_redist_settings(area, family, type, level); |
| 476 | struct route_table *er_table = get_ext_reach(area, family, level); |
| 477 | struct route_node *rn; |
| 478 | struct isis_ext_info *info; |
| 479 | |
| 480 | if (!redist->redist) |
| 481 | return; |
| 482 | |
| 483 | redist->redist = 0; |
| 484 | if (!er_table) |
| 485 | { |
| 486 | zlog_warn("%s: External reachability table uninitialized.", __func__); |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | for (rn = route_top(er_table); rn; rn = route_next(rn)) |
| 491 | { |
| 492 | if (!rn->info) |
| 493 | continue; |
| 494 | info = rn->info; |
| 495 | |
| 496 | if (type == DEFAULT_ROUTE) |
| 497 | { |
| 498 | if (!is_default(&rn->p)) |
| 499 | continue; |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | if (info->origin != type) |
| 504 | continue; |
| 505 | } |
| 506 | |
Christian Franke | 106e38e | 2016-04-03 12:46:25 -0300 | [diff] [blame] | 507 | XFREE(MTYPE_ISIS, rn->info); |
Christian Franke | acf9865 | 2015-11-12 14:24:22 +0100 | [diff] [blame] | 508 | route_unlock_node(rn); |
| 509 | } |
| 510 | |
| 511 | lsp_regenerate_schedule(area, level, 0); |
| 512 | isis_redist_update_zebra_subscriptions(area->isis); |
| 513 | } |
| 514 | |
| 515 | void |
| 516 | isis_redist_area_finish(struct isis_area *area) |
| 517 | { |
| 518 | int protocol; |
| 519 | int level; |
| 520 | int type; |
| 521 | |
| 522 | for (protocol = 0; protocol < REDIST_PROTOCOL_COUNT; protocol++) |
| 523 | for (level = 0; level < ISIS_LEVELS; level++) |
| 524 | { |
| 525 | for (type = 0; type < ZEBRA_ROUTE_MAX + 1; type++) |
| 526 | { |
| 527 | struct isis_redist *redist; |
| 528 | |
| 529 | redist = &area->redist_settings[protocol][type][level]; |
| 530 | redist->redist = 0; |
| 531 | if (redist->map_name) |
| 532 | XFREE(MTYPE_ISIS, redist->map_name); |
| 533 | } |
| 534 | route_table_finish(area->ext_reach[protocol][level]); |
| 535 | } |
| 536 | |
| 537 | isis_redist_update_zebra_subscriptions(area->isis); |
| 538 | } |
| 539 | |
| 540 | DEFUN(isis_redistribute, |
| 541 | isis_redistribute_cmd, |
| 542 | "redistribute (ipv4|ipv6) " QUAGGA_REDIST_STR_ISISD |
| 543 | " (level-1|level-2) {metric <0-16777215>|route-map WORD}", |
| 544 | REDIST_STR |
| 545 | "Redistribute IPv4 routes\n" |
| 546 | "Redistribute IPv6 routes\n" |
| 547 | QUAGGA_REDIST_HELP_STR_ISISD |
| 548 | "Redistribute into level-1\n" |
| 549 | "Redistribute into level-2\n" |
| 550 | "Metric for redistributed routes\n" |
| 551 | "ISIS default metric\n" |
| 552 | "Route map reference\n" |
| 553 | "Pointer to route-map entries\n") |
| 554 | { |
| 555 | struct isis_area *area = vty->index; |
| 556 | int family; |
| 557 | int afi; |
| 558 | int type; |
| 559 | int level; |
| 560 | unsigned long metric; |
| 561 | const char *routemap; |
| 562 | |
| 563 | if (argc < 5) |
| 564 | return CMD_WARNING; |
| 565 | |
| 566 | family = str2family(argv[0]); |
| 567 | if (family < 0) |
| 568 | return CMD_WARNING; |
| 569 | |
| 570 | afi = family2afi(family); |
| 571 | if (!afi) |
| 572 | return CMD_WARNING; |
| 573 | |
| 574 | type = proto_redistnum(afi, argv[1]); |
| 575 | if (type < 0 || type == ZEBRA_ROUTE_ISIS) |
| 576 | return CMD_WARNING; |
| 577 | |
| 578 | if (!strcmp("level-1", argv[2])) |
| 579 | level = 1; |
| 580 | else if (!strcmp("level-2", argv[2])) |
| 581 | level = 2; |
| 582 | else |
| 583 | return CMD_WARNING; |
| 584 | |
| 585 | if ((area->is_type & level) != level) |
| 586 | { |
| 587 | vty_out(vty, "Node is not a level-%d IS%s", level, VTY_NEWLINE); |
| 588 | return CMD_WARNING; |
| 589 | } |
| 590 | |
| 591 | if (argv[3]) |
| 592 | { |
| 593 | char *endp; |
| 594 | metric = strtoul(argv[3], &endp, 10); |
| 595 | if (argv[3][0] == '\0' || *endp != '\0') |
| 596 | return CMD_WARNING; |
| 597 | } |
| 598 | else |
| 599 | { |
| 600 | metric = 0xffffffff; |
| 601 | } |
| 602 | |
| 603 | routemap = argv[4]; |
| 604 | |
| 605 | isis_redist_set(area, level, family, type, metric, routemap, 0); |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | DEFUN(no_isis_redistribute, |
| 610 | no_isis_redistribute_cmd, |
| 611 | "no redistribute (ipv4|ipv6) " QUAGGA_REDIST_STR_ISISD |
| 612 | " (level-1|level-2)", |
| 613 | NO_STR |
| 614 | REDIST_STR |
| 615 | "Redistribute IPv4 routes\n" |
| 616 | "Redistribute IPv6 routes\n" |
| 617 | QUAGGA_REDIST_HELP_STR_ISISD |
| 618 | "Redistribute into level-1\n" |
| 619 | "Redistribute into level-2\n") |
| 620 | { |
| 621 | struct isis_area *area = vty->index; |
| 622 | int type; |
| 623 | int level; |
| 624 | int family; |
| 625 | int afi; |
| 626 | |
| 627 | if (argc < 3) |
| 628 | return CMD_WARNING; |
| 629 | |
| 630 | family = str2family(argv[0]); |
| 631 | if (family < 0) |
| 632 | return CMD_WARNING; |
| 633 | |
| 634 | afi = family2afi(family); |
| 635 | if (!afi) |
| 636 | return CMD_WARNING; |
| 637 | |
| 638 | type = proto_redistnum(afi, argv[1]); |
| 639 | if (type < 0 || type == ZEBRA_ROUTE_ISIS) |
| 640 | return CMD_WARNING; |
| 641 | |
| 642 | if (!strcmp("level-1", argv[2])) |
| 643 | level = 1; |
| 644 | else if (!strcmp("level-2", argv[2])) |
| 645 | level = 2; |
| 646 | else |
| 647 | return CMD_WARNING; |
| 648 | |
| 649 | isis_redist_unset(area, level, family, type); |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | DEFUN(isis_default_originate, |
| 654 | isis_default_originate_cmd, |
| 655 | "default-information originate (ipv4|ipv6) (level-1|level-2) " |
| 656 | "{always|metric <0-16777215>|route-map WORD}", |
| 657 | "Control distribution of default information\n" |
| 658 | "Distribute a default route\n" |
| 659 | "Distribute default route for IPv4\n" |
| 660 | "Distribute default route for IPv6\n" |
| 661 | "Distribute default route into level-1\n" |
| 662 | "Distribute default route into level-2\n" |
| 663 | "Always advertise default route\n" |
| 664 | "Metric for default route\n" |
| 665 | "ISIS default metric\n" |
| 666 | "Route map reference\n" |
| 667 | "Pointer to route-map entries\n") |
| 668 | { |
| 669 | struct isis_area *area = vty->index; |
| 670 | int family; |
| 671 | int originate_type; |
| 672 | int level; |
| 673 | unsigned long metric; |
| 674 | const char *routemap; |
| 675 | |
| 676 | if (argc < 5) |
| 677 | return CMD_WARNING; |
| 678 | |
| 679 | family = str2family(argv[0]); |
| 680 | if (family < 0) |
| 681 | return CMD_WARNING; |
| 682 | |
| 683 | if (!strcmp("level-1", argv[1])) |
| 684 | level = 1; |
| 685 | else if (!strcmp("level-2", argv[1])) |
| 686 | level = 2; |
| 687 | else |
| 688 | return CMD_WARNING; |
| 689 | |
| 690 | if ((area->is_type & level) != level) |
| 691 | { |
| 692 | vty_out(vty, "Node is not a level-%d IS%s", level, VTY_NEWLINE); |
| 693 | return CMD_WARNING; |
| 694 | } |
| 695 | |
| 696 | if (argv[2] && *argv[2] != '\0') |
| 697 | originate_type = DEFAULT_ORIGINATE_ALWAYS; |
| 698 | else |
| 699 | originate_type = DEFAULT_ORIGINATE; |
| 700 | |
| 701 | if (family == AF_INET6 && originate_type != DEFAULT_ORIGINATE_ALWAYS) |
| 702 | { |
| 703 | vty_out(vty, "Zebra doesn't implement default-originate for IPv6 yet%s", VTY_NEWLINE); |
| 704 | vty_out(vty, "so use with care or use default-originate always.%s", VTY_NEWLINE); |
| 705 | } |
| 706 | |
| 707 | if (argv[3]) |
| 708 | { |
| 709 | char *endp; |
| 710 | metric = strtoul(argv[3], &endp, 10); |
| 711 | if (argv[3][0] == '\0' || *endp != '\0') |
| 712 | return CMD_WARNING; |
| 713 | } |
| 714 | else |
| 715 | { |
| 716 | metric = 0xffffffff; |
| 717 | } |
| 718 | |
| 719 | routemap = argv[4]; |
| 720 | |
| 721 | isis_redist_set(area, level, family, DEFAULT_ROUTE, metric, routemap, originate_type); |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | DEFUN(no_isis_default_originate, |
| 726 | no_isis_default_originate_cmd, |
| 727 | "no default-information originate (ipv4|ipv6) (level-1|level-2)", |
| 728 | NO_STR |
| 729 | "Control distribution of default information\n" |
| 730 | "Distribute a default route\n" |
| 731 | "Distribute default route for IPv4\n" |
| 732 | "Distribute default route for IPv6\n" |
| 733 | "Distribute default route into level-1\n" |
| 734 | "Distribute default route into level-2\n") |
| 735 | { |
| 736 | struct isis_area *area = vty->index; |
| 737 | |
| 738 | int family; |
| 739 | int level; |
| 740 | |
| 741 | if (argc < 2) |
| 742 | return CMD_WARNING; |
| 743 | |
| 744 | family = str2family(argv[0]); |
| 745 | if (family < 0) |
| 746 | return CMD_WARNING; |
| 747 | |
| 748 | if (!strcmp("level-1", argv[1])) |
| 749 | level = 1; |
| 750 | else if (!strcmp("level-2", argv[1])) |
| 751 | level = 2; |
| 752 | else |
| 753 | return CMD_WARNING; |
| 754 | |
| 755 | isis_redist_unset(area, level, family, DEFAULT_ROUTE); |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | int |
| 760 | isis_redist_config_write(struct vty *vty, struct isis_area *area, |
| 761 | int family) |
| 762 | { |
| 763 | int type; |
| 764 | int level; |
| 765 | int write = 0; |
| 766 | struct isis_redist *redist; |
| 767 | const char *family_str; |
| 768 | |
| 769 | if (family == AF_INET) |
| 770 | family_str = "ipv4"; |
| 771 | else if (family == AF_INET6) |
| 772 | family_str = "ipv6"; |
| 773 | else |
| 774 | return 0; |
| 775 | |
| 776 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
| 777 | { |
| 778 | if (type == ZEBRA_ROUTE_ISIS) |
| 779 | continue; |
| 780 | |
| 781 | for (level = 1; level <= ISIS_LEVELS; level++) |
| 782 | { |
| 783 | redist = get_redist_settings(area, family, type, level); |
| 784 | if (!redist->redist) |
| 785 | continue; |
| 786 | vty_out(vty, " redistribute %s %s level-%d", |
| 787 | family_str, zebra_route_string(type), level); |
| 788 | if (redist->metric != 0xffffffff) |
| 789 | vty_out(vty, " metric %u", redist->metric); |
| 790 | if (redist->map_name) |
| 791 | vty_out(vty, " route-map %s", redist->map_name); |
| 792 | vty_out(vty, "%s", VTY_NEWLINE); |
| 793 | write++; |
| 794 | } |
| 795 | } |
| 796 | |
| 797 | for (level = 1; level <= ISIS_LEVELS; level++) |
| 798 | { |
| 799 | redist = get_redist_settings(area, family, DEFAULT_ROUTE, level); |
| 800 | if (!redist->redist) |
| 801 | continue; |
| 802 | vty_out(vty, " default-information originate %s level-%d", |
| 803 | family_str, level); |
| 804 | if (redist->redist == DEFAULT_ORIGINATE_ALWAYS) |
| 805 | vty_out(vty, " always"); |
| 806 | if (redist->metric != 0xffffffff) |
| 807 | vty_out(vty, " metric %u", redist->metric); |
| 808 | if (redist->map_name) |
| 809 | vty_out(vty, " route-map %s", redist->map_name); |
| 810 | vty_out(vty, "%s", VTY_NEWLINE); |
| 811 | write++; |
| 812 | } |
| 813 | |
| 814 | return write; |
| 815 | } |
| 816 | |
| 817 | void |
| 818 | isis_redist_init(void) |
| 819 | { |
| 820 | install_element(ISIS_NODE, &isis_redistribute_cmd); |
| 821 | install_element(ISIS_NODE, &no_isis_redistribute_cmd); |
| 822 | install_element(ISIS_NODE, &isis_default_originate_cmd); |
| 823 | install_element(ISIS_NODE, &no_isis_default_originate_cmd); |
| 824 | } |