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