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 | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 338 | struct ospf6_area *oa, *area; |
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; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 342 | listnode node; |
| 343 | struct ospf6_route *ro; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 344 | |
| 345 | o = (struct ospf6 *) vty->index; |
| 346 | |
| 347 | /* find/create ospf6 interface */ |
| 348 | ifp = if_get_by_name (argv[0]); |
| 349 | oi = (struct ospf6_interface *) ifp->info; |
| 350 | if (oi == NULL) |
| 351 | oi = ospf6_interface_create (ifp); |
| 352 | if (oi->area) |
| 353 | { |
| 354 | vty_out (vty, "%s already attached to Area %s%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 355 | oi->interface->name, oi->area->name, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 356 | return CMD_SUCCESS; |
| 357 | } |
| 358 | |
| 359 | /* parse Area-ID */ |
| 360 | if (inet_pton (AF_INET, argv[1], &area_id) != 1) |
| 361 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 362 | vty_out (vty, "Invalid Area-ID: %s%s", argv[1], VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 363 | return CMD_SUCCESS; |
| 364 | } |
| 365 | |
| 366 | /* find/create ospf6 area */ |
| 367 | oa = ospf6_area_lookup (area_id, o); |
| 368 | if (oa == NULL) |
| 369 | oa = ospf6_area_create (area_id, o); |
| 370 | |
| 371 | /* attach interface to area */ |
| 372 | listnode_add (oa->if_list, oi); /* sort ?? */ |
| 373 | oi->area = oa; |
| 374 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 375 | SET_FLAG (oa->flag, OSPF6_AREA_ENABLE); |
| 376 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 377 | /* start up */ |
| 378 | thread_add_event (master, interface_up, oi, 0); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 379 | |
| 380 | /* ABR stuff, redistribute inter-area LSAs and |
| 381 | re-originate Router-LSA (B-bit may have been changed) */ |
| 382 | for (node = listhead (o->area_list); node; nextnode (node)) |
| 383 | { |
| 384 | area = OSPF6_AREA (getdata (node)); |
| 385 | OSPF6_ROUTER_LSA_SCHEDULE (area); |
| 386 | |
| 387 | for (ro = ospf6_route_head (area->range_table); ro; |
| 388 | ro = ospf6_route_next (ro)) |
| 389 | ospf6_abr_originate_summary_to_area (ro, oa); |
| 390 | } |
| 391 | |
| 392 | for (ro = ospf6_route_head (o->brouter_table); ro; |
| 393 | ro = ospf6_route_next (ro)) |
| 394 | ospf6_abr_originate_summary_to_area (ro, oa); |
| 395 | |
| 396 | for (ro = ospf6_route_head (o->route_table); ro; |
| 397 | ro = ospf6_route_next (ro)) |
| 398 | ospf6_abr_originate_summary_to_area (ro, oa); |
| 399 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 400 | return CMD_SUCCESS; |
| 401 | } |
| 402 | |
| 403 | DEFUN (no_ospf6_interface_area, |
| 404 | no_ospf6_interface_area_cmd, |
| 405 | "no interface IFNAME area A.B.C.D", |
| 406 | NO_STR |
| 407 | "Disable routing on an IPv6 interface\n" |
| 408 | IFNAME_STR |
| 409 | "Specify the OSPF6 area ID\n" |
| 410 | "OSPF6 area ID in IPv4 address notation\n" |
| 411 | ) |
| 412 | { |
| 413 | struct ospf6 *o; |
| 414 | struct ospf6_interface *oi; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 415 | struct ospf6_area *oa, *area; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 416 | struct interface *ifp; |
| 417 | u_int32_t area_id; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 418 | listnode node; |
| 419 | struct ospf6_route *ro; |
| 420 | struct ospf6_lsa *old; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 421 | |
| 422 | o = (struct ospf6 *) vty->index; |
| 423 | |
| 424 | ifp = if_lookup_by_name (argv[0]); |
| 425 | if (ifp == NULL) |
| 426 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 427 | vty_out (vty, "No such interface %s%s", argv[0], VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 428 | return CMD_SUCCESS; |
| 429 | } |
| 430 | |
| 431 | oi = (struct ospf6_interface *) ifp->info; |
| 432 | if (oi == NULL) |
| 433 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 434 | vty_out (vty, "Interface %s not enabled%s", ifp->name, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 435 | return CMD_SUCCESS; |
| 436 | } |
| 437 | |
| 438 | /* parse Area-ID */ |
| 439 | if (inet_pton (AF_INET, argv[1], &area_id) != 1) |
| 440 | { |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 441 | vty_out (vty, "Invalid Area-ID: %s%s", argv[1], VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 442 | return CMD_SUCCESS; |
| 443 | } |
| 444 | |
| 445 | if (oi->area->area_id != area_id) |
| 446 | { |
| 447 | vty_out (vty, "Wrong Area-ID: %s is attached to area %s%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 448 | oi->interface->name, oi->area->name, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 449 | return CMD_SUCCESS; |
| 450 | } |
| 451 | |
| 452 | thread_execute (master, interface_down, oi, 0); |
| 453 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 454 | oa = oi->area; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 455 | listnode_delete (oi->area->if_list, oi); |
| 456 | oi->area = (struct ospf6_area *) NULL; |
| 457 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 458 | /* Withdraw inter-area routes from this area, if necessary */ |
| 459 | if (oa->if_list->count == 0) |
| 460 | { |
| 461 | UNSET_FLAG (oa->flag, OSPF6_AREA_ENABLE); |
| 462 | |
| 463 | for (ro = ospf6_route_head (oa->summary_prefix); ro; |
| 464 | ro = ospf6_route_next (ro)) |
| 465 | { |
| 466 | old = ospf6_lsdb_lookup (ro->path.origin.type, |
| 467 | ro->path.origin.id, |
| 468 | oa->ospf6->router_id, oa->lsdb); |
| 469 | if (old) |
| 470 | ospf6_lsa_purge (old); |
| 471 | ospf6_route_remove (ro, oa->summary_prefix); |
| 472 | } |
| 473 | for (ro = ospf6_route_head (oa->summary_router); ro; |
| 474 | ro = ospf6_route_next (ro)) |
| 475 | { |
| 476 | old = ospf6_lsdb_lookup (ro->path.origin.type, |
| 477 | ro->path.origin.id, |
| 478 | oa->ospf6->router_id, oa->lsdb); |
| 479 | if (old) |
| 480 | ospf6_lsa_purge (old); |
| 481 | ospf6_route_remove (ro, oa->summary_router); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | /* Schedule Refreshment of Router-LSA for each area |
| 486 | (ABR status may change) */ |
| 487 | for (node = listhead (o->area_list); node; nextnode (node)) |
| 488 | { |
| 489 | area = OSPF6_AREA (getdata (node)); |
| 490 | OSPF6_ROUTER_LSA_SCHEDULE (area); |
| 491 | } |
| 492 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 493 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 497 | ospf6_show (struct vty *vty, struct ospf6 *o) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 498 | { |
| 499 | listnode n; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 500 | struct ospf6_area *oa; |
| 501 | char router_id[16], duration[32]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 502 | struct timeval now, running; |
| 503 | |
| 504 | /* process id, router id */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 505 | inet_ntop (AF_INET, &o->router_id, router_id, sizeof (router_id)); |
| 506 | vty_out (vty, " OSPFv3 Routing Process (0) with Router-ID %s%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 507 | router_id, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | |
| 509 | /* running time */ |
| 510 | gettimeofday (&now, (struct timezone *)NULL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 511 | timersub (&now, &o->starttime, &running); |
| 512 | timerstring (&running, duration, sizeof (duration)); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 513 | vty_out (vty, " Running %s%s", duration, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 514 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 515 | /* Redistribute configuration */ |
| 516 | /* XXX */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 517 | |
| 518 | /* LSAs */ |
| 519 | vty_out (vty, " Number of AS scoped LSAs is %u%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 520 | o->lsdb->count, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 521 | |
| 522 | /* Areas */ |
| 523 | vty_out (vty, " Number of areas in this router is %u%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 524 | listcount (o->area_list), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 525 | for (n = listhead (o->area_list); n; nextnode (n)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 527 | oa = (struct ospf6_area *) getdata (n); |
| 528 | ospf6_area_show (vty, oa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 529 | } |
| 530 | } |
| 531 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 532 | /* show top level structures */ |
| 533 | DEFUN (show_ipv6_ospf6, |
| 534 | show_ipv6_ospf6_cmd, |
| 535 | "show ipv6 ospf6", |
| 536 | SHOW_STR |
| 537 | IP6_STR |
| 538 | OSPF6_STR) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 539 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 540 | OSPF6_CMD_CHECK_RUNNING (); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 541 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 542 | ospf6_show (vty, ospf6); |
| 543 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | DEFUN (show_ipv6_ospf6_route, |
| 547 | show_ipv6_ospf6_route_cmd, |
| 548 | "show ipv6 ospf6 route", |
| 549 | SHOW_STR |
| 550 | IP6_STR |
| 551 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 552 | ROUTE_STR |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | ) |
| 554 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 555 | ospf6_route_table_show (vty, argc, argv, ospf6->route_table); |
| 556 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | ALIAS (show_ipv6_ospf6_route, |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 560 | show_ipv6_ospf6_route_detail_cmd, |
| 561 | "show ipv6 ospf6 route (X::X|X::X/M|detail|summary)", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 562 | SHOW_STR |
| 563 | IP6_STR |
| 564 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 565 | ROUTE_STR |
| 566 | "Specify IPv6 address\n" |
| 567 | "Specify IPv6 prefix\n" |
| 568 | "Detailed information\n" |
| 569 | "Summary of route table\n" |
| 570 | ); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 571 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 572 | DEFUN (show_ipv6_ospf6_route_match, |
| 573 | show_ipv6_ospf6_route_match_cmd, |
| 574 | "show ipv6 ospf6 route X::X/M match", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 575 | SHOW_STR |
| 576 | IP6_STR |
| 577 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 578 | ROUTE_STR |
| 579 | "Specify IPv6 prefix\n" |
| 580 | "Display routes which match the specified route\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 581 | ) |
| 582 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 583 | char *sargv[CMD_ARGC_MAX]; |
| 584 | int i, sargc; |
| 585 | |
| 586 | /* copy argv to sargv and then append "match" */ |
| 587 | for (i = 0; i < argc; i++) |
| 588 | sargv[i] = argv[i]; |
| 589 | sargc = argc; |
| 590 | sargv[sargc++] = "match"; |
| 591 | sargv[sargc] = NULL; |
| 592 | |
| 593 | ospf6_route_table_show (vty, sargc, sargv, ospf6->route_table); |
| 594 | return CMD_SUCCESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 595 | } |
| 596 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 597 | DEFUN (show_ipv6_ospf6_route_match_detail, |
| 598 | show_ipv6_ospf6_route_match_detail_cmd, |
| 599 | "show ipv6 ospf6 route X::X/M match detail", |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 600 | SHOW_STR |
| 601 | IP6_STR |
| 602 | OSPF6_STR |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 603 | ROUTE_STR |
| 604 | "Specify IPv6 prefix\n" |
| 605 | "Display routes which match the specified route\n" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 606 | "Detailed information\n" |
| 607 | ) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 608 | { |
| 609 | char *sargv[CMD_ARGC_MAX]; |
| 610 | int i, sargc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 611 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 612 | /* copy argv to sargv and then append "match" and "detail" */ |
| 613 | for (i = 0; i < argc; i++) |
| 614 | sargv[i] = argv[i]; |
| 615 | sargc = argc; |
| 616 | sargv[sargc++] = "match"; |
| 617 | sargv[sargc++] = "detail"; |
| 618 | sargv[sargc] = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 619 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 620 | ospf6_route_table_show (vty, sargc, sargv, ospf6->route_table); |
| 621 | return CMD_SUCCESS; |
| 622 | } |
| 623 | |
| 624 | |
| 625 | /* OSPF configuration write function. */ |
| 626 | int |
| 627 | config_write_ospf6 (struct vty *vty) |
| 628 | { |
| 629 | char router_id[16]; |
| 630 | listnode j, k; |
| 631 | struct ospf6_area *oa; |
| 632 | struct ospf6_interface *oi; |
| 633 | |
| 634 | /* OSPFv6 configuration. */ |
| 635 | if (ospf6 == NULL) |
| 636 | return CMD_SUCCESS; |
| 637 | if (CHECK_FLAG (ospf6->flag, OSPF6_DISABLED)) |
| 638 | return CMD_SUCCESS; |
| 639 | |
| 640 | inet_ntop (AF_INET, &ospf6->router_id, router_id, sizeof (router_id)); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 641 | vty_out (vty, "router ospf6%s", VNL); |
| 642 | vty_out (vty, " router-id %s%s", router_id, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 643 | |
| 644 | ospf6_redistribute_config_write (vty); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame^] | 645 | ospf6_area_config_write (vty); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 646 | |
| 647 | for (j = listhead (ospf6->area_list); j; nextnode (j)) |
| 648 | { |
| 649 | oa = (struct ospf6_area *) getdata (j); |
| 650 | for (k = listhead (oa->if_list); k; nextnode (k)) |
| 651 | { |
| 652 | oi = (struct ospf6_interface *) getdata (k); |
| 653 | vty_out (vty, " interface %s area %s%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 654 | oi->interface->name, oa->name, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 655 | } |
| 656 | } |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 657 | vty_out (vty, "!%s", VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 658 | return 0; |
| 659 | } |
| 660 | |
| 661 | /* OSPF6 node structure. */ |
| 662 | struct cmd_node ospf6_node = |
| 663 | { |
| 664 | OSPF6_NODE, |
| 665 | "%s(config-ospf6)# ", |
| 666 | }; |
| 667 | |
| 668 | /* Install ospf related commands. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 669 | void |
| 670 | ospf6_top_init () |
| 671 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 672 | /* Install ospf6 top node. */ |
| 673 | install_node (&ospf6_node, config_write_ospf6); |
| 674 | |
| 675 | install_element (VIEW_NODE, &show_ipv6_ospf6_cmd); |
| 676 | install_element (ENABLE_NODE, &show_ipv6_ospf6_cmd); |
| 677 | install_element (CONFIG_NODE, &router_ospf6_cmd); |
| 678 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_cmd); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 680 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_detail_cmd); |
| 681 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_match_cmd); |
| 682 | install_element (VIEW_NODE, &show_ipv6_ospf6_route_match_detail_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 683 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_cmd); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 684 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_detail_cmd); |
| 685 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_match_cmd); |
| 686 | install_element (ENABLE_NODE, &show_ipv6_ospf6_route_match_detail_cmd); |
| 687 | |
| 688 | install_default (OSPF6_NODE); |
| 689 | install_element (OSPF6_NODE, &ospf6_router_id_cmd); |
| 690 | install_element (OSPF6_NODE, &ospf6_interface_area_cmd); |
| 691 | install_element (OSPF6_NODE, &no_ospf6_interface_area_cmd); |
| 692 | install_element (OSPF6_NODE, &no_router_ospf6_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 693 | } |
| 694 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 695 | |