David Lamparter | 3732cba | 2016-07-29 16:19:40 +0200 | [diff] [blame] | 1 | /* |
| 2 | * IS-IS Rout(e)ing protocol - isis_circuit.h |
| 3 | * |
| 4 | * Copyright (C) 2001,2002 Sampo Saaristo |
| 5 | * Tampere University of Technology |
| 6 | * Institute of Communications Engineering |
| 7 | * Copyright (C) 2016 David Lamparter, for NetDEF, Inc. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public Licenseas published by the Free |
| 11 | * Software Foundation; either version 2 of the License, or (at your option) |
| 12 | * any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful,but WITHOUT |
| 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 17 | * more details. |
| 18 | |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | |
| 24 | #include <zebra.h> |
| 25 | #include <command.h> |
| 26 | |
| 27 | #include "isis_circuit.h" |
| 28 | #include "isis_csm.h" |
| 29 | #include "isis_misc.h" |
| 30 | #include "isisd.h" |
| 31 | |
| 32 | static struct isis_circuit * |
| 33 | isis_circuit_lookup (struct vty *vty) |
| 34 | { |
| 35 | struct interface *ifp; |
| 36 | struct isis_circuit *circuit; |
| 37 | |
| 38 | ifp = (struct interface *) vty->index; |
| 39 | if (!ifp) |
| 40 | { |
| 41 | vty_out (vty, "Invalid interface %s", VTY_NEWLINE); |
| 42 | return NULL; |
| 43 | } |
| 44 | |
| 45 | circuit = circuit_scan_by_ifp (ifp); |
| 46 | if (!circuit) |
| 47 | { |
| 48 | vty_out (vty, "ISIS is not enabled on circuit %s%s", |
| 49 | ifp->name, VTY_NEWLINE); |
| 50 | return NULL; |
| 51 | } |
| 52 | |
| 53 | return circuit; |
| 54 | } |
| 55 | |
| 56 | DEFUN (ip_router_isis, |
| 57 | ip_router_isis_cmd, |
| 58 | "(ip|ipv6) router isis WORD", |
| 59 | "Interface Internet Protocol config commands\n" |
| 60 | "IP router interface commands\n" |
| 61 | "IS-IS Routing for IP\n" |
| 62 | "Routing process tag\n") |
| 63 | { |
| 64 | struct interface *ifp; |
| 65 | struct isis_circuit *circuit; |
| 66 | struct isis_area *area; |
| 67 | const char *af = argv[0]; |
| 68 | const char *area_tag = argv[1]; |
| 69 | |
| 70 | ifp = (struct interface *) vty->index; |
| 71 | assert (ifp); |
| 72 | |
| 73 | /* Prevent more than one area per circuit */ |
| 74 | circuit = circuit_scan_by_ifp (ifp); |
| 75 | if (circuit) |
| 76 | { |
| 77 | if (circuit->ip_router == 1) |
| 78 | { |
| 79 | if (strcmp (circuit->area->area_tag, area_tag)) |
| 80 | { |
| 81 | vty_out (vty, "ISIS circuit is already defined on %s%s", |
| 82 | circuit->area->area_tag, VTY_NEWLINE); |
| 83 | return CMD_ERR_NOTHING_TODO; |
| 84 | } |
| 85 | return CMD_SUCCESS; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | area = isis_area_lookup (area_tag); |
| 90 | if (!area) |
| 91 | area = isis_area_create (area_tag); |
| 92 | |
| 93 | if (!circuit) |
| 94 | circuit = isis_circuit_create (area, ifp); |
| 95 | |
| 96 | bool ip = circuit->ip_router, ipv6 = circuit->ipv6_router; |
| 97 | if (af[2] != '\0') |
| 98 | ipv6 = true; |
| 99 | else |
| 100 | ip = true; |
| 101 | |
| 102 | isis_circuit_af_set (circuit, ip, ipv6); |
| 103 | return CMD_SUCCESS; |
| 104 | } |
| 105 | |
| 106 | DEFUN (no_ip_router_isis, |
| 107 | no_ip_router_isis_cmd, |
| 108 | "no (ip|ipv6) router isis WORD", |
| 109 | NO_STR |
| 110 | "Interface Internet Protocol config commands\n" |
| 111 | "IP router interface commands\n" |
| 112 | "IS-IS Routing for IP\n" |
| 113 | "Routing process tag\n") |
| 114 | { |
| 115 | struct interface *ifp; |
| 116 | struct isis_area *area; |
| 117 | struct isis_circuit *circuit; |
| 118 | const char *af = argv[0]; |
| 119 | const char *area_tag = argv[1]; |
| 120 | |
| 121 | ifp = (struct interface *) vty->index; |
| 122 | if (!ifp) |
| 123 | { |
| 124 | vty_out (vty, "Invalid interface %s", VTY_NEWLINE); |
| 125 | return CMD_ERR_NO_MATCH; |
| 126 | } |
| 127 | |
| 128 | area = isis_area_lookup (area_tag); |
| 129 | if (!area) |
| 130 | { |
| 131 | vty_out (vty, "Can't find ISIS instance %s%s", |
| 132 | argv[0], VTY_NEWLINE); |
| 133 | return CMD_ERR_NO_MATCH; |
| 134 | } |
| 135 | |
| 136 | circuit = circuit_lookup_by_ifp (ifp, area->circuit_list); |
| 137 | if (!circuit) |
| 138 | { |
| 139 | vty_out (vty, "ISIS is not enabled on circuit %s%s", |
| 140 | ifp->name, VTY_NEWLINE); |
| 141 | return CMD_ERR_NO_MATCH; |
| 142 | } |
| 143 | |
| 144 | bool ip = circuit->ip_router, ipv6 = circuit->ipv6_router; |
| 145 | if (af[2] != '\0') |
| 146 | ipv6 = false; |
| 147 | else |
| 148 | ip = false; |
| 149 | |
| 150 | isis_circuit_af_set (circuit, ip, ipv6); |
| 151 | return CMD_SUCCESS; |
| 152 | } |
| 153 | |
| 154 | DEFUN (isis_passive, |
| 155 | isis_passive_cmd, |
| 156 | "isis passive", |
| 157 | "IS-IS commands\n" |
| 158 | "Configure the passive mode for interface\n") |
| 159 | { |
| 160 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 161 | if (!circuit) |
| 162 | return CMD_ERR_NO_MATCH; |
| 163 | |
| 164 | isis_circuit_passive_set (circuit, 1); |
| 165 | return CMD_SUCCESS; |
| 166 | } |
| 167 | |
| 168 | DEFUN (no_isis_passive, |
| 169 | no_isis_passive_cmd, |
| 170 | "no isis passive", |
| 171 | NO_STR |
| 172 | "IS-IS commands\n" |
| 173 | "Configure the passive mode for interface\n") |
| 174 | { |
| 175 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 176 | if (!circuit) |
| 177 | return CMD_ERR_NO_MATCH; |
| 178 | |
| 179 | if (if_is_loopback (circuit->interface)) |
| 180 | { |
| 181 | vty_out (vty, "Can't set no passive for loopback interface%s", |
| 182 | VTY_NEWLINE); |
| 183 | return CMD_ERR_AMBIGUOUS; |
| 184 | } |
| 185 | |
| 186 | isis_circuit_passive_set (circuit, 0); |
| 187 | return CMD_SUCCESS; |
| 188 | } |
| 189 | |
| 190 | DEFUN (isis_circuit_type, |
| 191 | isis_circuit_type_cmd, |
| 192 | "isis circuit-type (level-1|level-1-2|level-2-only)", |
| 193 | "IS-IS commands\n" |
| 194 | "Configure circuit type for interface\n" |
| 195 | "Level-1 only adjacencies are formed\n" |
| 196 | "Level-1-2 adjacencies are formed\n" |
| 197 | "Level-2 only adjacencies are formed\n") |
| 198 | { |
| 199 | int is_type; |
| 200 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 201 | if (!circuit) |
| 202 | return CMD_ERR_NO_MATCH; |
| 203 | |
| 204 | is_type = string2circuit_t (argv[0]); |
| 205 | if (!is_type) |
| 206 | { |
| 207 | vty_out (vty, "Unknown circuit-type %s", VTY_NEWLINE); |
| 208 | return CMD_ERR_AMBIGUOUS; |
| 209 | } |
| 210 | |
| 211 | if (circuit->state == C_STATE_UP && |
| 212 | circuit->area->is_type != IS_LEVEL_1_AND_2 && |
| 213 | circuit->area->is_type != is_type) |
| 214 | { |
| 215 | vty_out (vty, "Invalid circuit level for area %s.%s", |
| 216 | circuit->area->area_tag, VTY_NEWLINE); |
| 217 | return CMD_ERR_AMBIGUOUS; |
| 218 | } |
| 219 | isis_circuit_is_type_set (circuit, is_type); |
| 220 | |
| 221 | return CMD_SUCCESS; |
| 222 | } |
| 223 | |
| 224 | DEFUN (no_isis_circuit_type, |
| 225 | no_isis_circuit_type_cmd, |
| 226 | "no isis circuit-type (level-1|level-1-2|level-2-only)", |
| 227 | NO_STR |
| 228 | "IS-IS commands\n" |
| 229 | "Configure circuit type for interface\n" |
| 230 | "Level-1 only adjacencies are formed\n" |
| 231 | "Level-1-2 adjacencies are formed\n" |
| 232 | "Level-2 only adjacencies are formed\n") |
| 233 | { |
| 234 | int is_type; |
| 235 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 236 | if (!circuit) |
| 237 | return CMD_ERR_NO_MATCH; |
| 238 | |
| 239 | /* |
| 240 | * Set the circuits level to its default value |
| 241 | */ |
| 242 | if (circuit->state == C_STATE_UP) |
| 243 | is_type = circuit->area->is_type; |
| 244 | else |
| 245 | is_type = IS_LEVEL_1_AND_2; |
| 246 | isis_circuit_is_type_set (circuit, is_type); |
| 247 | |
| 248 | return CMD_SUCCESS; |
| 249 | } |
| 250 | |
| 251 | DEFUN (isis_network, |
| 252 | isis_network_cmd, |
| 253 | "isis network point-to-point", |
| 254 | "IS-IS commands\n" |
| 255 | "Set network type\n" |
| 256 | "point-to-point network type\n") |
| 257 | { |
| 258 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 259 | if (!circuit) |
| 260 | return CMD_ERR_NO_MATCH; |
| 261 | |
| 262 | if (!isis_circuit_circ_type_set(circuit, CIRCUIT_T_P2P)) |
| 263 | { |
| 264 | vty_out (vty, "isis network point-to-point " |
| 265 | "is valid only on broadcast interfaces%s", |
| 266 | VTY_NEWLINE); |
| 267 | return CMD_ERR_AMBIGUOUS; |
| 268 | } |
| 269 | |
| 270 | return CMD_SUCCESS; |
| 271 | } |
| 272 | |
| 273 | DEFUN (no_isis_network, |
| 274 | no_isis_network_cmd, |
| 275 | "no isis network point-to-point", |
| 276 | NO_STR |
| 277 | "IS-IS commands\n" |
| 278 | "Set network type for circuit\n" |
| 279 | "point-to-point network type\n") |
| 280 | { |
| 281 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 282 | if (!circuit) |
| 283 | return CMD_ERR_NO_MATCH; |
| 284 | |
| 285 | if (!isis_circuit_circ_type_set(circuit, CIRCUIT_T_BROADCAST)) |
| 286 | { |
| 287 | vty_out (vty, "isis network point-to-point " |
| 288 | "is valid only on broadcast interfaces%s", |
| 289 | VTY_NEWLINE); |
| 290 | return CMD_ERR_AMBIGUOUS; |
| 291 | } |
| 292 | |
| 293 | return CMD_SUCCESS; |
| 294 | } |
| 295 | |
Christian Franke | f5fbfb2 | 2016-07-28 17:23:27 +0200 | [diff] [blame^] | 296 | DEFUN (isis_passwd, |
| 297 | isis_passwd_cmd, |
| 298 | "isis password (md5|clear) WORD", |
| 299 | "IS-IS commands\n" |
| 300 | "Configure the authentication password for a circuit\n" |
| 301 | "HMAC-MD5 authentication\n" |
| 302 | "Cleartext password\n" |
| 303 | "Circuit password\n") |
| 304 | { |
| 305 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 306 | int rv; |
| 307 | if (!circuit) |
| 308 | return CMD_ERR_NO_MATCH; |
| 309 | |
| 310 | if (argv[0][0] == 'm') |
| 311 | rv = isis_circuit_passwd_hmac_md5_set(circuit, argv[1]); |
| 312 | else |
| 313 | rv = isis_circuit_passwd_cleartext_set(circuit, argv[1]); |
| 314 | if (rv) |
| 315 | { |
| 316 | vty_out (vty, "Too long circuit password (>254)%s", VTY_NEWLINE); |
| 317 | return CMD_ERR_AMBIGUOUS; |
| 318 | } |
| 319 | |
| 320 | return CMD_SUCCESS; |
| 321 | } |
| 322 | |
| 323 | DEFUN (no_isis_passwd, |
| 324 | no_isis_passwd_cmd, |
| 325 | "no isis password", |
| 326 | NO_STR |
| 327 | "IS-IS commands\n" |
| 328 | "Configure the authentication password for a circuit\n") |
| 329 | { |
| 330 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 331 | if (!circuit) |
| 332 | return CMD_ERR_NO_MATCH; |
| 333 | |
| 334 | isis_circuit_passwd_unset(circuit); |
| 335 | |
| 336 | return CMD_SUCCESS; |
| 337 | } |
| 338 | |
| 339 | ALIAS (no_isis_passwd, |
| 340 | no_isis_passwd_arg_cmd, |
| 341 | "no isis password (md5|clear) WORD", |
| 342 | NO_STR |
| 343 | "IS-IS commands\n" |
| 344 | "Configure the authentication password for a circuit\n" |
| 345 | "HMAC-MD5 authentication\n" |
| 346 | "Cleartext password\n" |
| 347 | "Circuit password\n") |
| 348 | |
David Lamparter | 3732cba | 2016-07-29 16:19:40 +0200 | [diff] [blame] | 349 | DEFUN (isis_priority, |
| 350 | isis_priority_cmd, |
| 351 | "isis priority <0-127>", |
| 352 | "IS-IS commands\n" |
| 353 | "Set priority for Designated Router election\n" |
| 354 | "Priority value\n") |
| 355 | { |
| 356 | int prio; |
| 357 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 358 | if (!circuit) |
| 359 | return CMD_ERR_NO_MATCH; |
| 360 | |
| 361 | prio = atoi (argv[0]); |
| 362 | if (prio < MIN_PRIORITY || prio > MAX_PRIORITY) |
| 363 | { |
| 364 | vty_out (vty, "Invalid priority %d - should be <0-127>%s", |
| 365 | prio, VTY_NEWLINE); |
| 366 | return CMD_ERR_AMBIGUOUS; |
| 367 | } |
| 368 | |
| 369 | circuit->priority[0] = prio; |
| 370 | circuit->priority[1] = prio; |
| 371 | |
| 372 | return CMD_SUCCESS; |
| 373 | } |
| 374 | |
| 375 | DEFUN (no_isis_priority, |
| 376 | no_isis_priority_cmd, |
| 377 | "no isis priority", |
| 378 | NO_STR |
| 379 | "IS-IS commands\n" |
| 380 | "Set priority for Designated Router election\n") |
| 381 | { |
| 382 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 383 | if (!circuit) |
| 384 | return CMD_ERR_NO_MATCH; |
| 385 | |
| 386 | circuit->priority[0] = DEFAULT_PRIORITY; |
| 387 | circuit->priority[1] = DEFAULT_PRIORITY; |
| 388 | |
| 389 | return CMD_SUCCESS; |
| 390 | } |
| 391 | |
| 392 | ALIAS (no_isis_priority, |
| 393 | no_isis_priority_arg_cmd, |
| 394 | "no isis priority <0-127>", |
| 395 | NO_STR |
| 396 | "IS-IS commands\n" |
| 397 | "Set priority for Designated Router election\n" |
| 398 | "Priority value\n") |
| 399 | |
| 400 | DEFUN (isis_priority_l1, |
| 401 | isis_priority_l1_cmd, |
| 402 | "isis priority <0-127> level-1", |
| 403 | "IS-IS commands\n" |
| 404 | "Set priority for Designated Router election\n" |
| 405 | "Priority value\n" |
| 406 | "Specify priority for level-1 routing\n") |
| 407 | { |
| 408 | int prio; |
| 409 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 410 | if (!circuit) |
| 411 | return CMD_ERR_NO_MATCH; |
| 412 | |
| 413 | prio = atoi (argv[0]); |
| 414 | if (prio < MIN_PRIORITY || prio > MAX_PRIORITY) |
| 415 | { |
| 416 | vty_out (vty, "Invalid priority %d - should be <0-127>%s", |
| 417 | prio, VTY_NEWLINE); |
| 418 | return CMD_ERR_AMBIGUOUS; |
| 419 | } |
| 420 | |
| 421 | circuit->priority[0] = prio; |
| 422 | |
| 423 | return CMD_SUCCESS; |
| 424 | } |
| 425 | |
| 426 | DEFUN (no_isis_priority_l1, |
| 427 | no_isis_priority_l1_cmd, |
| 428 | "no isis priority level-1", |
| 429 | NO_STR |
| 430 | "IS-IS commands\n" |
| 431 | "Set priority for Designated Router election\n" |
| 432 | "Specify priority for level-1 routing\n") |
| 433 | { |
| 434 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 435 | if (!circuit) |
| 436 | return CMD_ERR_NO_MATCH; |
| 437 | |
| 438 | circuit->priority[0] = DEFAULT_PRIORITY; |
| 439 | |
| 440 | return CMD_SUCCESS; |
| 441 | } |
| 442 | |
| 443 | ALIAS (no_isis_priority_l1, |
| 444 | no_isis_priority_l1_arg_cmd, |
| 445 | "no isis priority <0-127> level-1", |
| 446 | NO_STR |
| 447 | "IS-IS commands\n" |
| 448 | "Set priority for Designated Router election\n" |
| 449 | "Priority value\n" |
| 450 | "Specify priority for level-1 routing\n") |
| 451 | |
| 452 | DEFUN (isis_priority_l2, |
| 453 | isis_priority_l2_cmd, |
| 454 | "isis priority <0-127> level-2", |
| 455 | "IS-IS commands\n" |
| 456 | "Set priority for Designated Router election\n" |
| 457 | "Priority value\n" |
| 458 | "Specify priority for level-2 routing\n") |
| 459 | { |
| 460 | int prio; |
| 461 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 462 | if (!circuit) |
| 463 | return CMD_ERR_NO_MATCH; |
| 464 | |
| 465 | prio = atoi (argv[0]); |
| 466 | if (prio < MIN_PRIORITY || prio > MAX_PRIORITY) |
| 467 | { |
| 468 | vty_out (vty, "Invalid priority %d - should be <0-127>%s", |
| 469 | prio, VTY_NEWLINE); |
| 470 | return CMD_ERR_AMBIGUOUS; |
| 471 | } |
| 472 | |
| 473 | circuit->priority[1] = prio; |
| 474 | |
| 475 | return CMD_SUCCESS; |
| 476 | } |
| 477 | |
| 478 | DEFUN (no_isis_priority_l2, |
| 479 | no_isis_priority_l2_cmd, |
| 480 | "no isis priority level-2", |
| 481 | NO_STR |
| 482 | "IS-IS commands\n" |
| 483 | "Set priority for Designated Router election\n" |
| 484 | "Specify priority for level-2 routing\n") |
| 485 | { |
| 486 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 487 | if (!circuit) |
| 488 | return CMD_ERR_NO_MATCH; |
| 489 | |
| 490 | circuit->priority[1] = DEFAULT_PRIORITY; |
| 491 | |
| 492 | return CMD_SUCCESS; |
| 493 | } |
| 494 | |
| 495 | ALIAS (no_isis_priority_l2, |
| 496 | no_isis_priority_l2_arg_cmd, |
| 497 | "no isis priority <0-127> level-2", |
| 498 | NO_STR |
| 499 | "IS-IS commands\n" |
| 500 | "Set priority for Designated Router election\n" |
| 501 | "Priority value\n" |
| 502 | "Specify priority for level-2 routing\n") |
| 503 | |
| 504 | /* Metric command */ |
| 505 | DEFUN (isis_metric, |
| 506 | isis_metric_cmd, |
| 507 | "isis metric <0-16777215>", |
| 508 | "IS-IS commands\n" |
| 509 | "Set default metric for circuit\n" |
| 510 | "Default metric value\n") |
| 511 | { |
| 512 | int met; |
| 513 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 514 | if (!circuit) |
| 515 | return CMD_ERR_NO_MATCH; |
| 516 | |
| 517 | met = atoi (argv[0]); |
| 518 | |
| 519 | /* RFC3787 section 5.1 */ |
| 520 | if (circuit->area && circuit->area->oldmetric == 1 && |
| 521 | met > MAX_NARROW_LINK_METRIC) |
| 522 | { |
| 523 | vty_out (vty, "Invalid metric %d - should be <0-63> " |
| 524 | "when narrow metric type enabled%s", |
| 525 | met, VTY_NEWLINE); |
| 526 | return CMD_ERR_AMBIGUOUS; |
| 527 | } |
| 528 | |
| 529 | /* RFC4444 */ |
| 530 | if (circuit->area && circuit->area->newmetric == 1 && |
| 531 | met > MAX_WIDE_LINK_METRIC) |
| 532 | { |
| 533 | vty_out (vty, "Invalid metric %d - should be <0-16777215> " |
| 534 | "when wide metric type enabled%s", |
| 535 | met, VTY_NEWLINE); |
| 536 | return CMD_ERR_AMBIGUOUS; |
| 537 | } |
| 538 | |
| 539 | isis_circuit_metric_set (circuit, IS_LEVEL_1, met); |
| 540 | isis_circuit_metric_set (circuit, IS_LEVEL_2, met); |
| 541 | return CMD_SUCCESS; |
| 542 | } |
| 543 | |
| 544 | DEFUN (no_isis_metric, |
| 545 | no_isis_metric_cmd, |
| 546 | "no isis metric", |
| 547 | NO_STR |
| 548 | "IS-IS commands\n" |
| 549 | "Set default metric for circuit\n") |
| 550 | { |
| 551 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 552 | if (!circuit) |
| 553 | return CMD_ERR_NO_MATCH; |
| 554 | |
| 555 | isis_circuit_metric_set (circuit, IS_LEVEL_1, DEFAULT_CIRCUIT_METRIC); |
| 556 | isis_circuit_metric_set (circuit, IS_LEVEL_2, DEFAULT_CIRCUIT_METRIC); |
| 557 | return CMD_SUCCESS; |
| 558 | } |
| 559 | |
| 560 | ALIAS (no_isis_metric, |
| 561 | no_isis_metric_arg_cmd, |
| 562 | "no isis metric <0-16777215>", |
| 563 | NO_STR |
| 564 | "IS-IS commands\n" |
| 565 | "Set default metric for circuit\n" |
| 566 | "Default metric value\n") |
| 567 | |
| 568 | DEFUN (isis_metric_l1, |
| 569 | isis_metric_l1_cmd, |
| 570 | "isis metric <0-16777215> level-1", |
| 571 | "IS-IS commands\n" |
| 572 | "Set default metric for circuit\n" |
| 573 | "Default metric value\n" |
| 574 | "Specify metric for level-1 routing\n") |
| 575 | { |
| 576 | int met; |
| 577 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 578 | if (!circuit) |
| 579 | return CMD_ERR_NO_MATCH; |
| 580 | |
| 581 | met = atoi (argv[0]); |
| 582 | |
| 583 | /* RFC3787 section 5.1 */ |
| 584 | if (circuit->area && circuit->area->oldmetric == 1 && |
| 585 | met > MAX_NARROW_LINK_METRIC) |
| 586 | { |
| 587 | vty_out (vty, "Invalid metric %d - should be <0-63> " |
| 588 | "when narrow metric type enabled%s", |
| 589 | met, VTY_NEWLINE); |
| 590 | return CMD_ERR_AMBIGUOUS; |
| 591 | } |
| 592 | |
| 593 | /* RFC4444 */ |
| 594 | if (circuit->area && circuit->area->newmetric == 1 && |
| 595 | met > MAX_WIDE_LINK_METRIC) |
| 596 | { |
| 597 | vty_out (vty, "Invalid metric %d - should be <0-16777215> " |
| 598 | "when wide metric type enabled%s", |
| 599 | met, VTY_NEWLINE); |
| 600 | return CMD_ERR_AMBIGUOUS; |
| 601 | } |
| 602 | |
| 603 | isis_circuit_metric_set (circuit, IS_LEVEL_1, met); |
| 604 | return CMD_SUCCESS; |
| 605 | } |
| 606 | |
| 607 | DEFUN (no_isis_metric_l1, |
| 608 | no_isis_metric_l1_cmd, |
| 609 | "no isis metric level-1", |
| 610 | NO_STR |
| 611 | "IS-IS commands\n" |
| 612 | "Set default metric for circuit\n" |
| 613 | "Specify metric for level-1 routing\n") |
| 614 | { |
| 615 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 616 | if (!circuit) |
| 617 | return CMD_ERR_NO_MATCH; |
| 618 | |
| 619 | isis_circuit_metric_set (circuit, IS_LEVEL_1, DEFAULT_CIRCUIT_METRIC); |
| 620 | return CMD_SUCCESS; |
| 621 | } |
| 622 | |
| 623 | ALIAS (no_isis_metric_l1, |
| 624 | no_isis_metric_l1_arg_cmd, |
| 625 | "no isis metric <0-16777215> level-1", |
| 626 | NO_STR |
| 627 | "IS-IS commands\n" |
| 628 | "Set default metric for circuit\n" |
| 629 | "Default metric value\n" |
| 630 | "Specify metric for level-1 routing\n") |
| 631 | |
| 632 | DEFUN (isis_metric_l2, |
| 633 | isis_metric_l2_cmd, |
| 634 | "isis metric <0-16777215> level-2", |
| 635 | "IS-IS commands\n" |
| 636 | "Set default metric for circuit\n" |
| 637 | "Default metric value\n" |
| 638 | "Specify metric for level-2 routing\n") |
| 639 | { |
| 640 | int met; |
| 641 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 642 | if (!circuit) |
| 643 | return CMD_ERR_NO_MATCH; |
| 644 | |
| 645 | met = atoi (argv[0]); |
| 646 | |
| 647 | /* RFC3787 section 5.1 */ |
| 648 | if (circuit->area && circuit->area->oldmetric == 1 && |
| 649 | met > MAX_NARROW_LINK_METRIC) |
| 650 | { |
| 651 | vty_out (vty, "Invalid metric %d - should be <0-63> " |
| 652 | "when narrow metric type enabled%s", |
| 653 | met, VTY_NEWLINE); |
| 654 | return CMD_ERR_AMBIGUOUS; |
| 655 | } |
| 656 | |
| 657 | /* RFC4444 */ |
| 658 | if (circuit->area && circuit->area->newmetric == 1 && |
| 659 | met > MAX_WIDE_LINK_METRIC) |
| 660 | { |
| 661 | vty_out (vty, "Invalid metric %d - should be <0-16777215> " |
| 662 | "when wide metric type enabled%s", |
| 663 | met, VTY_NEWLINE); |
| 664 | return CMD_ERR_AMBIGUOUS; |
| 665 | } |
| 666 | |
| 667 | isis_circuit_metric_set (circuit, IS_LEVEL_2, met); |
| 668 | return CMD_SUCCESS; |
| 669 | } |
| 670 | |
| 671 | DEFUN (no_isis_metric_l2, |
| 672 | no_isis_metric_l2_cmd, |
| 673 | "no isis metric level-2", |
| 674 | NO_STR |
| 675 | "IS-IS commands\n" |
| 676 | "Set default metric for circuit\n" |
| 677 | "Specify metric for level-2 routing\n") |
| 678 | { |
| 679 | struct isis_circuit *circuit = isis_circuit_lookup (vty); |
| 680 | if (!circuit) |
| 681 | return CMD_ERR_NO_MATCH; |
| 682 | |
| 683 | isis_circuit_metric_set (circuit, IS_LEVEL_2, DEFAULT_CIRCUIT_METRIC); |
| 684 | return CMD_SUCCESS; |
| 685 | } |
| 686 | |
| 687 | ALIAS (no_isis_metric_l2, |
| 688 | no_isis_metric_l2_arg_cmd, |
| 689 | "no isis metric <0-16777215> level-2", |
| 690 | NO_STR |
| 691 | "IS-IS commands\n" |
| 692 | "Set default metric for circuit\n" |
| 693 | "Default metric value\n" |
| 694 | "Specify metric for level-2 routing\n") |
| 695 | /* end of metrics */ |
| 696 | |
Christian Franke | ccd485d | 2016-07-28 17:23:26 +0200 | [diff] [blame] | 697 | static int |
| 698 | validate_metric_style_narrow (struct vty *vty, struct isis_area *area) |
| 699 | { |
| 700 | struct isis_circuit *circuit; |
| 701 | struct listnode *node; |
| 702 | |
| 703 | if (! vty) |
| 704 | return CMD_ERR_AMBIGUOUS; |
| 705 | |
| 706 | if (! area) |
| 707 | { |
| 708 | vty_out (vty, "ISIS area is invalid%s", VTY_NEWLINE); |
| 709 | return CMD_ERR_AMBIGUOUS; |
| 710 | } |
| 711 | |
| 712 | for (ALL_LIST_ELEMENTS_RO (area->circuit_list, node, circuit)) |
| 713 | { |
| 714 | if ((area->is_type & IS_LEVEL_1) && |
| 715 | (circuit->is_type & IS_LEVEL_1) && |
| 716 | (circuit->te_metric[0] > MAX_NARROW_LINK_METRIC)) |
| 717 | { |
| 718 | vty_out (vty, "ISIS circuit %s metric is invalid%s", |
| 719 | circuit->interface->name, VTY_NEWLINE); |
| 720 | return CMD_ERR_AMBIGUOUS; |
| 721 | } |
| 722 | if ((area->is_type & IS_LEVEL_2) && |
| 723 | (circuit->is_type & IS_LEVEL_2) && |
| 724 | (circuit->te_metric[1] > MAX_NARROW_LINK_METRIC)) |
| 725 | { |
| 726 | vty_out (vty, "ISIS circuit %s metric is invalid%s", |
| 727 | circuit->interface->name, VTY_NEWLINE); |
| 728 | return CMD_ERR_AMBIGUOUS; |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | return CMD_SUCCESS; |
| 733 | } |
| 734 | |
| 735 | DEFUN (metric_style, |
| 736 | metric_style_cmd, |
| 737 | "metric-style (narrow|transition|wide)", |
| 738 | "Use old-style (ISO 10589) or new-style packet formats\n" |
| 739 | "Use old style of TLVs with narrow metric\n" |
| 740 | "Send and accept both styles of TLVs during transition\n" |
| 741 | "Use new style of TLVs to carry wider metric\n") |
| 742 | { |
| 743 | struct isis_area *area = vty->index; |
| 744 | int ret; |
| 745 | |
| 746 | assert(area); |
| 747 | |
| 748 | if (strncmp (argv[0], "w", 1) == 0) |
| 749 | { |
| 750 | isis_area_metricstyle_set(area, false, true); |
| 751 | return CMD_SUCCESS; |
| 752 | } |
| 753 | |
| 754 | ret = validate_metric_style_narrow (vty, area); |
| 755 | if (ret != CMD_SUCCESS) |
| 756 | return ret; |
| 757 | |
| 758 | if (strncmp (argv[0], "t", 1) == 0) |
| 759 | isis_area_metricstyle_set(area, true, true); |
| 760 | else if (strncmp (argv[0], "n", 1) == 0) |
| 761 | isis_area_metricstyle_set(area, true, false); |
| 762 | return CMD_SUCCESS; |
| 763 | |
| 764 | return CMD_SUCCESS; |
| 765 | } |
| 766 | |
| 767 | DEFUN (no_metric_style, |
| 768 | no_metric_style_cmd, |
| 769 | "no metric-style", |
| 770 | NO_STR |
| 771 | "Use old-style (ISO 10589) or new-style packet formats\n") |
| 772 | { |
| 773 | struct isis_area *area = vty->index; |
| 774 | int ret; |
| 775 | |
| 776 | assert (area); |
| 777 | ret = validate_metric_style_narrow (vty, area); |
| 778 | if (ret != CMD_SUCCESS) |
| 779 | return ret; |
| 780 | |
| 781 | isis_area_metricstyle_set(area, true, false); |
| 782 | return CMD_SUCCESS; |
| 783 | } |
| 784 | |
| 785 | DEFUN (set_overload_bit, |
| 786 | set_overload_bit_cmd, |
| 787 | "set-overload-bit", |
| 788 | "Set overload bit to avoid any transit traffic\n" |
| 789 | "Set overload bit\n") |
| 790 | { |
| 791 | struct isis_area *area = vty->index; |
| 792 | assert (area); |
| 793 | |
| 794 | isis_area_overload_bit_set(area, true); |
| 795 | return CMD_SUCCESS; |
| 796 | } |
| 797 | |
| 798 | DEFUN (no_set_overload_bit, |
| 799 | no_set_overload_bit_cmd, |
| 800 | "no set-overload-bit", |
| 801 | "Reset overload bit to accept transit traffic\n" |
| 802 | "Reset overload bit\n") |
| 803 | { |
| 804 | struct isis_area *area = vty->index; |
| 805 | assert (area); |
| 806 | |
| 807 | isis_area_overload_bit_set(area, false); |
| 808 | return CMD_SUCCESS; |
| 809 | } |
| 810 | |
| 811 | DEFUN (set_attached_bit, |
| 812 | set_attached_bit_cmd, |
| 813 | "set-attached-bit", |
| 814 | "Set attached bit to identify as L1/L2 router for inter-area traffic\n" |
| 815 | "Set attached bit\n") |
| 816 | { |
| 817 | struct isis_area *area = vty->index; |
| 818 | assert (area); |
| 819 | |
| 820 | isis_area_attached_bit_set(area, true); |
| 821 | return CMD_SUCCESS; |
| 822 | } |
| 823 | |
| 824 | DEFUN (no_set_attached_bit, |
| 825 | no_set_attached_bit_cmd, |
| 826 | "no set-attached-bit", |
| 827 | "Reset attached bit\n") |
| 828 | { |
| 829 | struct isis_area *area = vty->index; |
| 830 | assert (area); |
| 831 | |
| 832 | isis_area_attached_bit_set(area, false); |
| 833 | return CMD_SUCCESS; |
| 834 | } |
| 835 | |
| 836 | DEFUN (dynamic_hostname, |
| 837 | dynamic_hostname_cmd, |
| 838 | "hostname dynamic", |
| 839 | "Dynamic hostname for IS-IS\n" |
| 840 | "Dynamic hostname\n") |
| 841 | { |
| 842 | struct isis_area *area = vty->index; |
| 843 | assert(area); |
| 844 | |
| 845 | isis_area_dynhostname_set(area, true); |
| 846 | return CMD_SUCCESS; |
| 847 | } |
| 848 | |
| 849 | DEFUN (no_dynamic_hostname, |
| 850 | no_dynamic_hostname_cmd, |
| 851 | "no hostname dynamic", |
| 852 | NO_STR |
| 853 | "Dynamic hostname for IS-IS\n" |
| 854 | "Dynamic hostname\n") |
| 855 | { |
| 856 | struct isis_area *area = vty->index; |
| 857 | assert(area); |
| 858 | |
| 859 | isis_area_dynhostname_set(area, false); |
| 860 | return CMD_SUCCESS; |
| 861 | } |
| 862 | |
David Lamparter | 3732cba | 2016-07-29 16:19:40 +0200 | [diff] [blame] | 863 | void |
| 864 | isis_vty_init (void) |
| 865 | { |
| 866 | install_element (INTERFACE_NODE, &ip_router_isis_cmd); |
| 867 | install_element (INTERFACE_NODE, &no_ip_router_isis_cmd); |
| 868 | |
| 869 | install_element (INTERFACE_NODE, &isis_passive_cmd); |
| 870 | install_element (INTERFACE_NODE, &no_isis_passive_cmd); |
| 871 | |
| 872 | install_element (INTERFACE_NODE, &isis_circuit_type_cmd); |
| 873 | install_element (INTERFACE_NODE, &no_isis_circuit_type_cmd); |
| 874 | |
| 875 | install_element (INTERFACE_NODE, &isis_network_cmd); |
| 876 | install_element (INTERFACE_NODE, &no_isis_network_cmd); |
| 877 | |
Christian Franke | f5fbfb2 | 2016-07-28 17:23:27 +0200 | [diff] [blame^] | 878 | install_element (INTERFACE_NODE, &isis_passwd_cmd); |
| 879 | install_element (INTERFACE_NODE, &no_isis_passwd_cmd); |
| 880 | install_element (INTERFACE_NODE, &no_isis_passwd_arg_cmd); |
| 881 | |
David Lamparter | 3732cba | 2016-07-29 16:19:40 +0200 | [diff] [blame] | 882 | install_element (INTERFACE_NODE, &isis_priority_cmd); |
| 883 | install_element (INTERFACE_NODE, &no_isis_priority_cmd); |
| 884 | install_element (INTERFACE_NODE, &no_isis_priority_arg_cmd); |
| 885 | install_element (INTERFACE_NODE, &isis_priority_l1_cmd); |
| 886 | install_element (INTERFACE_NODE, &no_isis_priority_l1_cmd); |
| 887 | install_element (INTERFACE_NODE, &no_isis_priority_l1_arg_cmd); |
| 888 | install_element (INTERFACE_NODE, &isis_priority_l2_cmd); |
| 889 | install_element (INTERFACE_NODE, &no_isis_priority_l2_cmd); |
| 890 | install_element (INTERFACE_NODE, &no_isis_priority_l2_arg_cmd); |
| 891 | |
| 892 | install_element (INTERFACE_NODE, &isis_metric_cmd); |
| 893 | install_element (INTERFACE_NODE, &no_isis_metric_cmd); |
| 894 | install_element (INTERFACE_NODE, &no_isis_metric_arg_cmd); |
| 895 | install_element (INTERFACE_NODE, &isis_metric_l1_cmd); |
| 896 | install_element (INTERFACE_NODE, &no_isis_metric_l1_cmd); |
| 897 | install_element (INTERFACE_NODE, &no_isis_metric_l1_arg_cmd); |
| 898 | install_element (INTERFACE_NODE, &isis_metric_l2_cmd); |
| 899 | install_element (INTERFACE_NODE, &no_isis_metric_l2_cmd); |
| 900 | install_element (INTERFACE_NODE, &no_isis_metric_l2_arg_cmd); |
Christian Franke | ccd485d | 2016-07-28 17:23:26 +0200 | [diff] [blame] | 901 | |
| 902 | install_element (ISIS_NODE, &metric_style_cmd); |
| 903 | install_element (ISIS_NODE, &no_metric_style_cmd); |
| 904 | |
| 905 | install_element (ISIS_NODE, &set_overload_bit_cmd); |
| 906 | install_element (ISIS_NODE, &no_set_overload_bit_cmd); |
| 907 | |
| 908 | install_element (ISIS_NODE, &set_attached_bit_cmd); |
| 909 | install_element (ISIS_NODE, &no_set_attached_bit_cmd); |
| 910 | |
| 911 | install_element (ISIS_NODE, &dynamic_hostname_cmd); |
| 912 | install_element (ISIS_NODE, &no_dynamic_hostname_cmd); |
David Lamparter | 3732cba | 2016-07-29 16:19:40 +0200 | [diff] [blame] | 913 | } |