| 1 | /* |
|---|
| 2 | * Copyright (C) 2003 Yasuhiro Ohara |
|---|
| 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 |
|---|
| 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|---|
| 19 | * Boston, MA 02111-1307, USA. |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #include <zebra.h> |
|---|
| 23 | |
|---|
| 24 | #include "log.h" |
|---|
| 25 | #include "memory.h" |
|---|
| 26 | #include "vty.h" |
|---|
| 27 | #include "linklist.h" |
|---|
| 28 | #include "prefix.h" |
|---|
| 29 | #include "table.h" |
|---|
| 30 | #include "thread.h" |
|---|
| 31 | #include "command.h" |
|---|
| 32 | |
|---|
| 33 | #include "ospf6_proto.h" |
|---|
| 34 | #include "ospf6_message.h" |
|---|
| 35 | #include "ospf6_lsa.h" |
|---|
| 36 | #include "ospf6_lsdb.h" |
|---|
| 37 | #include "ospf6_route.h" |
|---|
| 38 | #include "ospf6_zebra.h" |
|---|
| 39 | |
|---|
| 40 | #include "ospf6_top.h" |
|---|
| 41 | #include "ospf6_area.h" |
|---|
| 42 | #include "ospf6_interface.h" |
|---|
| 43 | #include "ospf6_neighbor.h" |
|---|
| 44 | |
|---|
| 45 | #include "ospf6_flood.h" |
|---|
| 46 | #include "ospf6_asbr.h" |
|---|
| 47 | #include "ospf6_abr.h" |
|---|
| 48 | #include "ospf6_intra.h" |
|---|
| 49 | #include "ospf6d.h" |
|---|
| 50 | |
|---|
| 51 | /* global ospf6d variable */ |
|---|
| 52 | struct ospf6 *ospf6; |
|---|
| 53 | |
|---|
| 54 | static void |
|---|
| 55 | ospf6_top_lsdb_hook_add (struct ospf6_lsa *lsa) |
|---|
| 56 | { |
|---|
| 57 | switch (ntohs (lsa->header->type)) |
|---|
| 58 | { |
|---|
| 59 | case OSPF6_LSTYPE_AS_EXTERNAL: |
|---|
| 60 | ospf6_asbr_lsa_add (lsa); |
|---|
| 61 | break; |
|---|
| 62 | |
|---|
| 63 | default: |
|---|
| 64 | break; |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | static void |
|---|
| 69 | ospf6_top_lsdb_hook_remove (struct ospf6_lsa *lsa) |
|---|
| 70 | { |
|---|
| 71 | switch (ntohs (lsa->header->type)) |
|---|
| 72 | { |
|---|
| 73 | case OSPF6_LSTYPE_AS_EXTERNAL: |
|---|
| 74 | ospf6_asbr_lsa_remove (lsa); |
|---|
| 75 | break; |
|---|
| 76 | |
|---|
| 77 | default: |
|---|
| 78 | break; |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | static void |
|---|
| 83 | ospf6_top_route_hook_add (struct ospf6_route *route) |
|---|
| 84 | { |
|---|
| 85 | ospf6_abr_originate_summary (route); |
|---|
| 86 | ospf6_zebra_route_update_add (route); |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | static void |
|---|
| 90 | ospf6_top_route_hook_remove (struct ospf6_route *route) |
|---|
| 91 | { |
|---|
| 92 | ospf6_abr_originate_summary (route); |
|---|
| 93 | ospf6_zebra_route_update_remove (route); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | static void |
|---|
| 97 | ospf6_top_brouter_hook_add (struct ospf6_route *route) |
|---|
| 98 | { |
|---|
| 99 | ospf6_abr_examin_brouter (ADV_ROUTER_IN_PREFIX (&route->prefix)); |
|---|
| 100 | ospf6_asbr_lsentry_add (route); |
|---|
| 101 | ospf6_abr_originate_summary (route); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | static void |
|---|
| 105 | ospf6_top_brouter_hook_remove (struct ospf6_route *route) |
|---|
| 106 | { |
|---|
| 107 | ospf6_abr_examin_brouter (ADV_ROUTER_IN_PREFIX (&route->prefix)); |
|---|
| 108 | ospf6_asbr_lsentry_remove (route); |
|---|
| 109 | ospf6_abr_originate_summary (route); |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | static struct ospf6 * |
|---|
| 113 | ospf6_create (void) |
|---|
| 114 | { |
|---|
| 115 | struct ospf6 *o; |
|---|
| 116 | |
|---|
| 117 | o = XCALLOC (MTYPE_OSPF6_TOP, sizeof (struct ospf6)); |
|---|
| 118 | |
|---|
| 119 | /* initialize */ |
|---|
| 120 | quagga_gettime (QUAGGA_CLK_MONOTONIC, &o->starttime); |
|---|
| 121 | o->area_list = list_new (); |
|---|
| 122 | o->area_list->cmp = ospf6_area_cmp; |
|---|
| 123 | o->lsdb = ospf6_lsdb_create (o); |
|---|
| 124 | o->lsdb_self = ospf6_lsdb_create (o); |
|---|
| 125 | o->lsdb->hook_add = ospf6_top_lsdb_hook_add; |
|---|
| 126 | o->lsdb->hook_remove = ospf6_top_lsdb_hook_remove; |
|---|
| 127 | |
|---|
| 128 | o->route_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, ROUTES); |
|---|
| 129 | o->route_table->scope = o; |
|---|
| 130 | o->route_table->hook_add = ospf6_top_route_hook_add; |
|---|
| 131 | o->route_table->hook_remove = ospf6_top_route_hook_remove; |
|---|
| 132 | |
|---|
| 133 | o->brouter_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, BORDER_ROUTERS); |
|---|
| 134 | o->brouter_table->scope = o; |
|---|
| 135 | o->brouter_table->hook_add = ospf6_top_brouter_hook_add; |
|---|
| 136 | o->brouter_table->hook_remove = ospf6_top_brouter_hook_remove; |
|---|
| 137 | |
|---|
| 138 | o->external_table = OSPF6_ROUTE_TABLE_CREATE (GLOBAL, EXTERNAL_ROUTES); |
|---|
| 139 | o->external_table->scope = o; |
|---|
| 140 | |
|---|
| 141 | o->external_id_table = route_table_init (); |
|---|
| 142 | |
|---|
| 143 | return o; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | #if 0 |
|---|
| 147 | static void |
|---|
| 148 | ospf6_delete (struct ospf6 *o) |
|---|
| 149 | { |
|---|
| 150 | struct listnode *node, *nnode; |
|---|
| 151 | struct ospf6_area *oa; |
|---|
| 152 | |
|---|
| 153 | for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa)) |
|---|
| 154 | ospf6_area_delete (oa); |
|---|
| 155 | |
|---|
| 156 | ospf6_lsdb_delete (o->lsdb); |
|---|
| 157 | ospf6_lsdb_delete (o->lsdb_self); |
|---|
| 158 | |
|---|
| 159 | ospf6_route_table_delete (o->route_table); |
|---|
| 160 | ospf6_route_table_delete (o->brouter_table); |
|---|
| 161 | |
|---|
| 162 | ospf6_route_table_delete (o->external_table); |
|---|
| 163 | route_table_finish (o->external_id_table); |
|---|
| 164 | |
|---|
| 165 | XFREE (MTYPE_OSPF6_TOP, o); |
|---|
| 166 | } |
|---|
| 167 | #endif |
|---|
| 168 | |
|---|
| 169 | static void |
|---|
| 170 | ospf6_enable (struct ospf6 *o) |
|---|
| 171 | { |
|---|
| 172 | struct listnode *node, *nnode; |
|---|
| 173 | struct ospf6_area *oa; |
|---|
| 174 | |
|---|
| 175 | if (CHECK_FLAG (o->flag, OSPF6_DISABLED)) |
|---|
| 176 | { |
|---|
| 177 | UNSET_FLAG (o->flag, OSPF6_DISABLED); |
|---|
| 178 | for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa)) |
|---|
| 179 | ospf6_area_enable (oa); |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | static void |
|---|
| 184 | ospf6_disable (struct ospf6 *o) |
|---|
| 185 | { |
|---|
| 186 | struct listnode *node, *nnode; |
|---|
| 187 | struct ospf6_area *oa; |
|---|
| 188 | |
|---|
| 189 | if (! CHECK_FLAG (o->flag, OSPF6_DISABLED)) |
|---|
| 190 | { |
|---|
| 191 | SET_FLAG (o->flag, OSPF6_DISABLED); |
|---|
| 192 | |
|---|
| 193 | for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa)) |
|---|
| 194 | ospf6_area_disable (oa); |
|---|
| 195 | |
|---|
| 196 | ospf6_lsdb_remove_all (o->lsdb); |
|---|
| 197 | ospf6_route_remove_all (o->route_table); |
|---|
| 198 | ospf6_route_remove_all (o->brouter_table); |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | static int |
|---|
| 203 | ospf6_maxage_remover (struct thread *thread) |
|---|
| 204 | { |
|---|
| 205 | struct ospf6 *o = (struct ospf6 *) THREAD_ARG (thread); |
|---|
| 206 | struct ospf6_area *oa; |
|---|
| 207 | struct ospf6_interface *oi; |
|---|
| 208 | struct ospf6_neighbor *on; |
|---|
| 209 | struct listnode *i, *j, *k; |
|---|
| 210 | |
|---|
| 211 | o->maxage_remover = (struct thread *) NULL; |
|---|
| 212 | |
|---|
| 213 | for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) |
|---|
| 214 | { |
|---|
| 215 | for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) |
|---|
| 216 | { |
|---|
| 217 | for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on)) |
|---|
| 218 | { |
|---|
| 219 | if (on->state != OSPF6_NEIGHBOR_EXCHANGE && |
|---|
| 220 | on->state != OSPF6_NEIGHBOR_LOADING) |
|---|
| 221 | continue; |
|---|
| 222 | |
|---|
| 223 | return 0; |
|---|
| 224 | } |
|---|
| 225 | } |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) |
|---|
| 229 | { |
|---|
| 230 | for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) |
|---|
| 231 | OSPF6_LSDB_MAXAGE_REMOVER (oi->lsdb); |
|---|
| 232 | |
|---|
| 233 | OSPF6_LSDB_MAXAGE_REMOVER (oa->lsdb); |
|---|
| 234 | } |
|---|
| 235 | OSPF6_LSDB_MAXAGE_REMOVER (o->lsdb); |
|---|
| 236 | |
|---|
| 237 | return 0; |
|---|
| 238 | } |
|---|
| 239 | |
|---|
| 240 | void |
|---|
| 241 | ospf6_maxage_remove (struct ospf6 *o) |
|---|
| 242 | { |
|---|
| 243 | if (o && ! o->maxage_remover) |
|---|
| 244 | o->maxage_remover = thread_add_event (master, ospf6_maxage_remover, o, 0); |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | /* start ospf6 */ |
|---|
| 248 | DEFUN (router_ospf6, |
|---|
| 249 | router_ospf6_cmd, |
|---|
| 250 | "router ospf6", |
|---|
| 251 | ROUTER_STR |
|---|
| 252 | OSPF6_STR) |
|---|
| 253 | { |
|---|
| 254 | if (ospf6 == NULL) |
|---|
| 255 | ospf6 = ospf6_create (); |
|---|
| 256 | if (CHECK_FLAG (ospf6->flag, OSPF6_DISABLED)) |
|---|
| 257 | ospf6_enable (ospf6); |
|---|
| 258 | |
|---|
| 259 | /* set current ospf point. */ |
|---|
| 260 | vty->node = OSPF6_NODE; |
|---|
| 261 | vty->index = ospf6; |
|---|
| 262 | |
|---|
| 263 | return CMD_SUCCESS; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | /* stop ospf6 */ |
|---|
| 267 | DEFUN (no_router_ospf6, |
|---|
| 268 | no_router_ospf6_cmd, |
|---|
| 269 | "no router ospf6", |
|---|
| 270 | NO_STR |
|---|
| 271 | OSPF6_ROUTER_STR) |
|---|
| 272 | { |
|---|
| 273 | if (ospf6 == NULL || CHECK_FLAG (ospf6->flag, OSPF6_DISABLED)) |
|---|
| 274 | vty_out (vty, "OSPFv3 is not running%s", VNL); |
|---|
| 275 | else |
|---|
| 276 | ospf6_disable (ospf6); |
|---|
| 277 | |
|---|
| 278 | /* return to config node . */ |
|---|
| 279 | vty->node = CONFIG_NODE; |
|---|
| 280 | vty->index = NULL; |
|---|
| 281 | |
|---|
| 282 | return CMD_SUCCESS; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | /* change Router_ID commands. */ |
|---|
| 286 | DEFUN (ospf6_router_id, |
|---|
| 287 | ospf6_router_id_cmd, |
|---|
| 288 | "router-id A.B.C.D", |
|---|
| 289 | "Configure OSPF Router-ID\n" |
|---|
| 290 | V4NOTATION_STR) |
|---|
| 291 | { |
|---|
| 292 | int ret; |
|---|
| 293 | u_int32_t router_id; |
|---|
| 294 | struct ospf6 *o; |
|---|
| 295 | |
|---|
| 296 | o = (struct ospf6 *) vty->index; |
|---|
| 297 | |
|---|
| 298 | ret = inet_pton (AF_INET, argv[0], &router_id); |
|---|
| 299 | if (ret == 0) |
|---|
| 300 | { |
|---|
| 301 | vty_out (vty, "malformed OSPF Router-ID: %s%s", argv[0], VNL); |
|---|
| 302 | return CMD_SUCCESS; |
|---|
| 303 | } |
|---|
| 304 | |
|---|
| 305 | o->router_id_static = router_id; |
|---|
| 306 | if (o->router_id == 0) |
|---|
| 307 | o->router_id = router_id; |
|---|
| 308 | |
|---|
| 309 | return CMD_SUCCESS; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | DEFUN (ospf6_interface_area, |
|---|
| 313 | ospf6_interface_area_cmd, |
|---|
| 314 | "interface IFNAME area A.B.C.D", |
|---|
| 315 | "Enable routing on an IPv6 interface\n" |
|---|
| 316 | IFNAME_STR |
|---|
| 317 | "Specify the OSPF6 area ID\n" |
|---|
| 318 | "OSPF6 area ID in IPv4 address notation\n" |
|---|
| 319 | ) |
|---|
| 320 | { |
|---|
| 321 | struct ospf6 *o; |
|---|
| 322 | struct ospf6_area *oa; |
|---|
| 323 | struct ospf6_interface *oi; |
|---|
| 324 | struct interface *ifp; |
|---|
| 325 | u_int32_t area_id; |
|---|
| 326 | |
|---|
| 327 | o = (struct ospf6 *) vty->index; |
|---|
| 328 | |
|---|
| 329 | /* find/create ospf6 interface */ |
|---|
| 330 | ifp = if_get_by_name (argv[0]); |
|---|
| 331 | oi = (struct ospf6_interface *) ifp->info; |
|---|
| 332 | if (oi == NULL) |
|---|
| 333 | oi = ospf6_interface_create (ifp); |
|---|
| 334 | if (oi->area) |
|---|
| 335 | { |
|---|
| 336 | vty_out (vty, "%s already attached to Area %s%s", |
|---|
| 337 | oi->interface->name, oi->area->name, VNL); |
|---|
| 338 | return CMD_SUCCESS; |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | /* parse Area-ID */ |
|---|
| 342 | if (inet_pton (AF_INET, argv[1], &area_id) != 1) |
|---|
| 343 | { |
|---|
| 344 | vty_out (vty, "Invalid Area-ID: %s%s", argv[1], VNL); |
|---|
| 345 | return CMD_SUCCESS; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | /* find/create ospf6 area */ |
|---|
| 349 | oa = ospf6_area_lookup (area_id, o); |
|---|
| 350 | if (oa == NULL) |
|---|
| 351 | oa = ospf6_area_create (area_id, o); |
|---|
| 352 | |
|---|
| 353 | /* attach interface to area */ |
|---|
| 354 | listnode_add (oa->if_list, oi); /* sort ?? */ |
|---|
| 355 | oi->area = oa; |
|---|
| 356 | |
|---|
| 357 | SET_FLAG (oa->flag, OSPF6_AREA_ENABLE); |
|---|
| 358 | |
|---|
| 359 | /* start up */ |
|---|
| 360 | thread_add_event (master, interface_up, oi, 0); |
|---|
| 361 | |
|---|
| 362 | /* If the router is ABR, originate summary routes */ |
|---|
| 363 | if (ospf6_is_router_abr (o)) |
|---|
| 364 | ospf6_abr_enable_area (oa); |
|---|
| 365 | |
|---|
| 366 | return CMD_SUCCESS; |
|---|
| 367 | } |
|---|
| 368 | |
|---|
| 369 | DEFUN (no_ospf6_interface_area, |
|---|
| 370 | no_ospf6_interface_area_cmd, |
|---|
| 371 | "no interface IFNAME area A.B.C.D", |
|---|
| 372 | NO_STR |
|---|
| 373 | "Disable routing on an IPv6 interface\n" |
|---|
| 374 | IFNAME_STR |
|---|
| 375 | "Specify the OSPF6 area ID\n" |
|---|
| 376 | "OSPF6 area ID in IPv4 address notation\n" |
|---|
| 377 | ) |
|---|
| 378 | { |
|---|
| 379 | struct ospf6 *o; |
|---|
| 380 | struct ospf6_interface *oi; |
|---|
| 381 | struct ospf6_area *oa; |
|---|
| 382 | struct interface *ifp; |
|---|
| 383 | u_int32_t area_id; |
|---|
| 384 | |
|---|
| 385 | o = (struct ospf6 *) vty->index; |
|---|
| 386 | |
|---|
| 387 | ifp = if_lookup_by_name (argv[0]); |
|---|
| 388 | if (ifp == NULL) |
|---|
| 389 | { |
|---|
| 390 | vty_out (vty, "No such interface %s%s", argv[0], VNL); |
|---|
| 391 | return CMD_SUCCESS; |
|---|
| 392 | } |
|---|
| 393 | |
|---|
| 394 | oi = (struct ospf6_interface *) ifp->info; |
|---|
| 395 | if (oi == NULL) |
|---|
| 396 | { |
|---|
| 397 | vty_out (vty, "Interface %s not enabled%s", ifp->name, VNL); |
|---|
| 398 | return CMD_SUCCESS; |
|---|
| 399 | } |
|---|
| 400 | |
|---|
| 401 | /* parse Area-ID */ |
|---|
| 402 | if (inet_pton (AF_INET, argv[1], &area_id) != 1) |
|---|
| 403 | { |
|---|
| 404 | vty_out (vty, "Invalid Area-ID: %s%s", argv[1], VNL); |
|---|
| 405 | return CMD_SUCCESS; |
|---|
| 406 | } |
|---|
| 407 | |
|---|
| 408 | /* Verify Area */ |
|---|
| 409 | if (oi->area == NULL) |
|---|
| 410 | { |
|---|
| 411 | vty_out (vty, "No such Area-ID: %s%s", argv[1], VNL); |
|---|
| 412 | return CMD_SUCCESS; |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | if (oi->area->area_id != area_id) |
|---|
| 416 | { |
|---|
| 417 | vty_out (vty, "Wrong Area-ID: %s is attached to area %s%s", |
|---|
| 418 | oi->interface->name, oi->area->name, VNL); |
|---|
| 419 | return CMD_SUCCESS; |
|---|
| 420 | } |
|---|
| 421 | |
|---|
| 422 | thread_execute (master, interface_down, oi, 0); |
|---|
| 423 | |
|---|
| 424 | oa = oi->area; |
|---|
| 425 | listnode_delete (oi->area->if_list, oi); |
|---|
| 426 | oi->area = (struct ospf6_area *) NULL; |
|---|
| 427 | |
|---|
| 428 | /* Withdraw inter-area routes from this area, if necessary */ |
|---|
| 429 | if (oa->if_list->count == 0) |
|---|
| 430 | { |
|---|
| 431 | UNSET_FLAG (oa->flag, OSPF6_AREA_ENABLE); |
|---|
| 432 | ospf6_abr_disable_area (oa); |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | return CMD_SUCCESS; |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | static void |
|---|
| 439 | ospf6_show (struct vty *vty, struct ospf6 *o) |
|---|
| 440 | { |
|---|
| 441 | struct listnode *n; |
|---|
| 442 | struct ospf6_area *oa; |
|---|
| 443 | char router_id[16], duration[32]; |
|---|
| 444 | struct timeval now, running; |
|---|
| 445 | |
|---|
| 446 | /* process id, router id */ |
|---|
| 447 | inet_ntop (AF_INET, &o->router_id, router_id, sizeof (router_id)); |
|---|
| 448 | vty_out (vty, " OSPFv3 Routing Process (0) with Router-ID %s%s", |
|---|
| 449 | router_id, VNL); |
|---|
| 450 | |
|---|
| 451 | /* running time */ |
|---|
| 452 | quagga_gettime (QUAGGA_CLK_MONOTONIC, &now); |
|---|
| 453 | timersub (&now, &o->starttime, &running); |
|---|
| 454 | timerstring (&running, duration, sizeof (duration)); |
|---|
| 455 | vty_out (vty, " Running %s%s", duration, VNL); |
|---|
| 456 | |
|---|
| 457 | /* Redistribute configuration */ |
|---|
| 458 | /* XXX */ |
|---|
| 459 | |
|---|
| 460 | /* LSAs */ |
|---|
| 461 | vty_out (vty, " Number of AS scoped LSAs is %u%s", |
|---|
| 462 | o->lsdb->count, VNL); |
|---|
| 463 | |
|---|
| 464 | /* Areas */ |
|---|
| 465 | vty_out (vty, " Number of areas in this router is %u%s", |
|---|
| 466 | listcount (o->area_list), VNL); |
|---|
| 467 | |
|---|
| 468 | for (ALL_LIST_ELEMENTS_RO (o->area_list, n, oa)) |
|---|
| 469 | ospf6_area_show (vty, oa); |
|---|
| 470 | } |
|---|
| 471 | |
|---|
| 472 | /* show top level structures */ |
|---|
| 473 | DEFUN (show_ipv6_ospf6, |
|---|
| 474 | show_ipv6_ospf6_cmd, |
|---|
| 475 | "show ipv6 ospf6", |
|---|
| 476 | SHOW_STR |
|---|
| 477 | IP6_STR |
|---|
| 478 | OSPF6_STR) |
|---|
| 479 | { |
|---|
| 480 | OSPF6_CMD_CHECK_RUNNING (); |
|---|
| 481 | |
|---|
| 482 | ospf6_show (vty, ospf6); |
|---|
| 483 | return CMD_SUCCESS; |
|---|
| 484 | } |
|---|
| 485 | |
|---|
| 486 | DEFUN (show_ipv6_ospf6_route, |
|---|
| 487 | show_ipv6_ospf6_route_cmd, |
|---|
| 488 | "show ipv6 ospf6 route", |
|---|
| 489 | SHOW_STR |
|---|
| 490 | IP6_STR |
|---|
| 491 | OSPF6_STR |
|---|
| 492 | ROUTE_STR |
|---|
| 493 | ) |
|---|
| 494 | { |
|---|
| 495 | ospf6_route_table_show (vty, argc, argv, ospf6->route_table); |
|---|
| 496 | return CMD_SUCCESS; |
|---|
| 497 | } |
|---|
| 498 | |
|---|
| 499 | ALIAS (show_ipv6_ospf6_route, |
|---|
| 500 | show_ipv6_ospf6_route_detail_cmd, |
|---|
| 501 | "show ipv6 ospf6 route (X:X::X:X|X:X::X:X/M|detail|summary)", |
|---|
| 502 | SHOW_STR |
|---|
| 503 | IP6_STR |
|---|
| 504 | OSPF6_STR |
|---|
| 505 | ROUTE_STR |
|---|
| 506 | "Specify IPv6 address\n" |
|---|
| 507 | "Specify IPv6 prefix\n" |
|---|
| 508 | "Detailed information\n" |
|---|
| 509 | "Summary of route table\n" |
|---|
| 510 | ) |
|---|
| 511 | |
|---|
| 512 | DEFUN (show_ipv6_ospf6_route_match, |
|---|
| 513 | show_ipv6_ospf6_route_match_cmd, |
|---|
| 514 | "show ipv6 ospf6 route X:X::X:X/M match", |
|---|
| 515 | SHOW_STR |
|---|
| 516 | IP6_STR |
|---|
| 517 | OSPF6_STR |
|---|
| 518 | ROUTE_STR |
|---|
| 519 | "Specify IPv6 prefix\n" |
|---|
| 520 | "Display routes which match the specified route\n" |
|---|
| 521 | ) |
|---|
| 522 | { |
|---|
| 523 | const char *sargv[CMD_ARGC_MAX]; |
|---|
| 524 | int i, sargc; |
|---|
| 525 | |
|---|
| 526 | /* copy argv to sargv and then append "match" */ |
|---|
| 527 | for (i = 0; i < argc; i++) |
|---|
| 528 | sargv[i] = argv[i]; |
|---|
| 529 | sargc = argc; |
|---|
| 530 | sargv[sargc++] = "match"; |
|---|
| 531 | sargv[sargc] = NULL; |
|---|
| 532 | |
|---|
| 533 | ospf6_route_table_show (vty, sargc, sargv, ospf6->route_table); |
|---|
| 534 | return CMD_SUCCESS; |
|---|
| 535 | } |
|---|
| 536 | |
|---|
| 537 | DEFUN (show_ipv6_ospf6_route_match_detail, |
|---|
| 538 | show_ipv6_ospf6_route_match_detail_cmd, |
|---|
| 539 | "show ipv6 ospf6 route X:X::X:X/M match detail", |
|---|
| 540 | SHOW_STR |
|---|
| 541 | IP6_STR |
|---|
| 542 | OSPF6_STR |
|---|
| 543 | ROUTE_STR |
|---|
| 544 | "Specify IPv6 prefix\n" |
|---|
| 545 | "Display routes which match the specified route\n" |
|---|
| 546 | "Detailed information\n" |
|---|
| 547 | ) |
|---|
| 548 | { |
|---|
| 549 | const char *sargv[CMD_ARGC_MAX]; |
|---|
| 550 | int i, sargc; |
|---|
| 551 | |
|---|
| 552 | /* copy argv to sargv and then append "match" and "detail" */ |
|---|
| 553 | for (i = 0; i < argc; i++) |
|---|
| 554 | sargv[i] = argv[i]; |
|---|
| 555 | sargc = argc; |
|---|
| 556 | sargv[sargc++] = "match"; |
|---|
| 557 | sargv[sargc++] = "detail"; |
|---|
| 558 | sargv[sargc] = NULL; |
|---|
| 559 | |
|---|
| 560 | ospf6_route_table_show (vty, sargc, sargv, ospf6->route_table); |
|---|
| 561 | return CMD_SUCCESS; |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | ALIAS (show_ipv6_ospf6_route_match, |
|---|
| 565 | show_ipv6_ospf6_route_longer_cmd, |
|---|
| 566 | "show ipv6 ospf6 route X:X::X:X/M longer", |
|---|
| 567 | SHOW_STR |
|---|
| 568 | IP6_STR |
|---|
| 569 | OSPF6_STR |
|---|
| 570 | ROUTE_STR |
|---|
| 571 | "Specify IPv6 prefix\n" |
|---|
| 572 | "Display routes longer than the specified route\n" |
|---|
| 573 | ) |
|---|
| 574 | |
|---|
| 575 | DEFUN (show_ipv6_ospf6_route_match_detail, |
|---|
| 576 | show_ipv6_ospf6_route_longer_detail_cmd, |
|---|
| 577 | "show ipv6 ospf6 route X:X::X:X/M longer detail", |
|---|
| 578 | SHOW_STR |
|---|
| 579 | IP6_STR |
|---|
| 580 | OSPF6_STR |
|---|
| 581 | ROUTE_STR |
|---|
| 582 | "Specify IPv6 prefix\n" |
|---|
| 583 | "Display routes longer than the specified route\n" |
|---|
| 584 | "Detailed information\n" |
|---|
| 585 | ); |
|---|
| 586 | |
|---|
| 587 | ALIAS (show_ipv6_ospf6_route, |
|---|
| 588 | show_ipv6_ospf6_route_type_cmd, |
|---|
| 589 | "show ipv6 ospf6 route (intra-area|inter-area|external-1|external-2)", |
|---|
| 590 | SHOW_STR |
|---|
| 591 | IP6_STR |
|---|
| 592 | OSPF6_STR |
|---|
| 593 | ROUTE_STR |
|---|
| 594 | "Dispaly Intra-Area routes\n" |
|---|
| 595 | "Dispaly Inter-Area routes\n" |
|---|
| 596 | "Dispaly Type-1 External routes\n" |
|---|
| 597 | "Dispaly Type-2 External routes\n" |
|---|
| 598 | ) |
|---|
| 599 | |
|---|
| 600 | DEFUN (show_ipv6_ospf6_route_type_detail, |
|---|
| 601 | show_ipv6_ospf6_route_type_detail_cmd, |
|---|
| 602 | "show ipv6 ospf6 route (intra-area|inter-area|external-1|external-2) detail", |
|---|
| 603 | SHOW_STR |
|---|
| 604 | IP6_STR |
|---|
| 605 | OSPF6_STR |
|---|
| 606 | ROUTE_STR |
|---|
| 607 | "Dispaly Intra-Area routes\n" |
|---|
| 608 | "Dispaly Inter-Area routes\n" |
|---|
| 609 | "Dispaly Type-1 External routes\n" |
|---|
| 610 | "Dispaly Type-2 External routes\n" |
|---|
| 611 | "Detailed information\n" |
|---|
| 612 | ) |
|---|
| 613 | { |
|---|
| 614 | const char *sargv[CMD_ARGC_MAX]; |
|---|
| 615 | int i, sargc; |
|---|
| 616 | |
|---|
| 617 | /* copy argv to sargv and then append "detail" */ |
|---|
| 618 | for (i = 0; i < argc; i++) |
|---|
| 619 | sargv[i] = argv[i]; |
|---|
| 620 | sargc = argc; |
|---|
| 621 | sargv[sargc++] = "detail"; |
|---|
| 622 | sargv[sargc] = NULL; |
|---|
| 623 | |
|---|
| 624 | ospf6_route_table_show (vty, sargc, sargv, ospf6->route_table); |
|---|
| 625 | return CMD_SUCCESS; |
|---|
| 626 | } |
|---|
| 627 | |
|---|
| 628 | /* OSPF configuration write function. */ |
|---|
| 629 | static int |
|---|
| 630 | config_write_ospf6 (struct vty *vty) |
|---|
| 631 | { |
|---|
| 632 | char router_id[16]; |
|---|
| 633 | struct listnode *j, *k; |
|---|
| 634 | struct ospf6_area *oa; |
|---|
| 635 | struct ospf6_interface *oi; |
|---|
| 636 | |
|---|
| 637 | /* OSPFv6 configuration. */ |
|---|
| 638 | if (ospf6 == NULL) |
|---|
| 639 | return CMD_SUCCESS; |
|---|
| 640 | if (CHECK_FLAG (ospf6->flag, OSPF6_DISABLED)) |
|---|
| 641 | return CMD_SUCCESS; |
|---|
| 642 | |
|---|
| 643 | inet_ntop (AF_INET, &ospf6->router_id_static, router_id, sizeof (router_id)); |
|---|
| 644 | vty_out (vty, "router ospf6%s", VNL); |
|---|
| 645 | if (ospf6->router_id_static != 0) |
|---|
| 646 | vty_out (vty, " router-id %s%s", router_id, VNL); |
|---|
| 647 | |
|---|
| 648 | ospf6_redistribute_config_write (vty); |
|---|
| 649 | ospf6_area_config_write (vty); |
|---|
| 650 | |
|---|
| 651 | for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, j, oa)) |
|---|
| 652 | { |
|---|
| 653 | for (ALL_LIST_ELEMENTS_RO (oa->if_list, k, oi)) |
|---|
| 654 | vty_out (vty, " interface %s area %s%s", |
|---|
| 655 | oi->interface->name, oa->name, VNL); |
|---|
| 656 | } |
|---|
| 657 | vty_out (vty, "!%s", VNL); |
|---|
| 658 | return 0; |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | /* OSPF6 node structure. */ |
|---|
| 662 | static struct cmd_node ospf6_node = |
|---|
| 663 | { |
|---|
| 664 | OSPF6_NODE, |
|---|
| 665 | "%s(config-ospf6)# ", |
|---|
| 666 | 1 /* VTYSH */ |
|---|
| 667 | }; |
|---|
| 668 | |
|---|
| 669 | /* Install ospf related commands. */ |
|---|
| 670 | void |
|---|
| 671 | ospf6_top_init (void) |
|---|
| 672 | { |
|---|
| 673 | /* Install ospf6 top node. */ |
|---|
| 674 | install_node (&ospf6_node, config_write_ospf6); |
|---|
| 675 | |
|---|
| 676 | install_element (VIEW_NODE, &show_ipv6_ospf6_cmd); |
|---|
| 677 | install_element (ENABLE_NODE, &show_ipv6_ospf6_cmd); |
|---|
| 678 | install_element (CONFIG_NODE, &router_ospf6_cmd); |
|---|
| 679 | install_element (CONFIG_NODE, &no_router_ospf6_cmd); |
|---|
| 680 | |
|---|
| 681 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_cmd); |
|---|
| 682 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_detail_cmd); |
|---|
| 683 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_match_cmd); |
|---|
| 684 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_match_detail_cmd); |
|---|
| 685 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_longer_cmd); |
|---|
| 686 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_longer_detail_cmd); |
|---|
| 687 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_type_cmd); |
|---|
| 688 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_type_detail_cmd); |
|---|
| 689 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_cmd); |
|---|
| 690 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_detail_cmd); |
|---|
| 691 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_match_cmd); |
|---|
| 692 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_match_detail_cmd); |
|---|
| 693 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_longer_cmd); |
|---|
| 694 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_longer_detail_cmd); |
|---|
| 695 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_type_cmd); |
|---|
| 696 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_type_detail_cmd); |
|---|
| 697 | |
|---|
| 698 | install_default (OSPF6_NODE); |
|---|
| 699 | install_element (OSPF6_NODE, &ospf6_router_id_cmd); |
|---|
| 700 | install_element (OSPF6_NODE, &ospf6_interface_area_cmd); |
|---|
| 701 | install_element (OSPF6_NODE, &no_ospf6_interface_area_cmd); |
|---|
| 702 | } |
|---|
| 703 | |
|---|
| 704 | |
|---|