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