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