paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* OSPF version 2 daemon program. |
| 2 | Copyright (C) 1999, 2000 Toshiaki Takada |
| 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 Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-1307, USA. */ |
| 20 | |
| 21 | #include <zebra.h> |
| 22 | |
| 23 | #include "thread.h" |
| 24 | #include "vty.h" |
| 25 | #include "command.h" |
| 26 | #include "linklist.h" |
| 27 | #include "prefix.h" |
| 28 | #include "table.h" |
| 29 | #include "if.h" |
| 30 | #include "memory.h" |
| 31 | #include "stream.h" |
| 32 | #include "log.h" |
| 33 | #include "sockunion.h" /* for inet_aton () */ |
| 34 | #include "zclient.h" |
| 35 | #include "plist.h" |
| 36 | |
| 37 | #include "ospfd/ospfd.h" |
| 38 | #include "ospfd/ospf_network.h" |
| 39 | #include "ospfd/ospf_interface.h" |
| 40 | #include "ospfd/ospf_ism.h" |
| 41 | #include "ospfd/ospf_asbr.h" |
| 42 | #include "ospfd/ospf_lsa.h" |
| 43 | #include "ospfd/ospf_lsdb.h" |
| 44 | #include "ospfd/ospf_neighbor.h" |
| 45 | #include "ospfd/ospf_nsm.h" |
| 46 | #include "ospfd/ospf_spf.h" |
| 47 | #include "ospfd/ospf_packet.h" |
| 48 | #include "ospfd/ospf_dump.h" |
| 49 | #include "ospfd/ospf_zebra.h" |
| 50 | #include "ospfd/ospf_abr.h" |
| 51 | #include "ospfd/ospf_flood.h" |
| 52 | #include "ospfd/ospf_route.h" |
| 53 | #include "ospfd/ospf_ase.h" |
| 54 | |
| 55 | /* OSPF instance top. */ |
| 56 | struct ospf *ospf_top; |
| 57 | |
| 58 | extern struct zclient *zclient; |
| 59 | |
| 60 | |
| 61 | void ospf_remove_vls_through_area (struct ospf_area *); |
| 62 | void ospf_network_free (struct ospf_network *); |
| 63 | void ospf_area_free (struct ospf_area *); |
| 64 | void ospf_network_run (struct ospf *, struct prefix *, struct ospf_area *); |
| 65 | |
| 66 | /* Get Router ID from ospf interface list. */ |
| 67 | struct in_addr |
| 68 | ospf_router_id_get (list if_list) |
| 69 | { |
| 70 | listnode node; |
| 71 | struct in_addr router_id; |
| 72 | |
| 73 | memset (&router_id, 0, sizeof (struct in_addr)); |
| 74 | |
| 75 | for (node = listhead (if_list); node; nextnode (node)) |
| 76 | { |
| 77 | struct ospf_interface *oi = getdata (node); |
| 78 | |
| 79 | if (!if_is_up (oi->ifp) || |
| 80 | OSPF_IF_PARAM (oi, passive_interface) == OSPF_IF_PASSIVE) |
| 81 | continue; |
| 82 | |
| 83 | /* Ignore virtual link interface. */ |
| 84 | if (oi->type != OSPF_IFTYPE_VIRTUALLINK && |
| 85 | oi->type != OSPF_IFTYPE_LOOPBACK) |
| 86 | if (IPV4_ADDR_CMP (&router_id, &oi->address->u.prefix4) < 0) |
| 87 | router_id = oi->address->u.prefix4; |
| 88 | } |
| 89 | |
| 90 | return router_id; |
| 91 | } |
| 92 | |
| 93 | #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1 |
| 94 | |
| 95 | void |
| 96 | ospf_router_id_update () |
| 97 | { |
| 98 | listnode node; |
| 99 | struct in_addr router_id, router_id_old; |
| 100 | |
| 101 | if (IS_DEBUG_OSPF_EVENT) |
| 102 | zlog_info ("Router-ID[OLD:%s]: Update",inet_ntoa (ospf_top->router_id)); |
| 103 | |
| 104 | router_id_old = ospf_top->router_id; |
| 105 | |
| 106 | if (ospf_top->router_id_static.s_addr != 0) |
| 107 | router_id = ospf_top->router_id_static; |
| 108 | else |
| 109 | router_id = ospf_router_id_get (ospf_top->oiflist); |
| 110 | |
| 111 | ospf_top->router_id = router_id; |
| 112 | |
| 113 | if (IS_DEBUG_OSPF_EVENT) |
| 114 | zlog_info ("Router-ID[NEW:%s]: Update", inet_ntoa (ospf_top->router_id)); |
| 115 | |
| 116 | if (!IPV4_ADDR_SAME (&router_id_old, &router_id)) |
| 117 | { |
| 118 | for (node = listhead (ospf_top->oiflist); node; nextnode (node)) |
| 119 | { |
| 120 | struct ospf_interface *oi = getdata (node); |
| 121 | |
| 122 | /* Update self-neighbor's router_id. */ |
| 123 | oi->nbr_self->router_id = router_id; |
| 124 | } |
| 125 | |
| 126 | /* If AS-external-LSA is queued, then flush those LSAs. */ |
| 127 | if (router_id_old.s_addr == 0 && ospf_top->external_origin) |
| 128 | { |
| 129 | int type; |
| 130 | /* Originate each redistributed external route. */ |
| 131 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
| 132 | if (ospf_top->external_origin & (1 << type)) |
| 133 | thread_add_event (master, ospf_external_lsa_originate_timer, |
| 134 | NULL, type); |
| 135 | /* Originate Deafult. */ |
| 136 | if (ospf_top->external_origin & (1 << ZEBRA_ROUTE_MAX)) |
| 137 | thread_add_event (master, ospf_default_originate_timer, |
| 138 | &ospf_top->default_originate, 0); |
| 139 | |
| 140 | ospf_top->external_origin = 0; |
| 141 | } |
| 142 | |
| 143 | OSPF_TIMER_ON (ospf_top->t_router_lsa_update, |
| 144 | ospf_router_lsa_update_timer, OSPF_LSA_UPDATE_DELAY); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | int |
| 149 | ospf_router_id_update_timer (struct thread *thread) |
| 150 | { |
| 151 | if (IS_DEBUG_OSPF_EVENT) |
| 152 | zlog_info ("Router-ID: Update timer fired!"); |
| 153 | |
| 154 | ospf_top->t_router_id_update = NULL; |
| 155 | ospf_router_id_update (); |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /* For OSPF area sort by area id. */ |
| 161 | int |
| 162 | ospf_area_id_cmp (struct ospf_area *a1, struct ospf_area *a2) |
| 163 | { |
| 164 | if (ntohl (a1->area_id.s_addr) > ntohl (a2->area_id.s_addr)) |
| 165 | return 1; |
| 166 | if (ntohl (a1->area_id.s_addr) < ntohl (a2->area_id.s_addr)) |
| 167 | return -1; |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | /* Allocate new ospf structure. */ |
| 172 | struct ospf * |
| 173 | ospf_new () |
| 174 | { |
| 175 | int i; |
| 176 | |
| 177 | struct ospf *new = XCALLOC (MTYPE_OSPF_TOP, sizeof (struct ospf)); |
| 178 | |
| 179 | new->router_id.s_addr = htonl (0); |
| 180 | new->router_id_static.s_addr = htonl (0); |
| 181 | |
| 182 | new->abr_type = OSPF_ABR_STAND; |
| 183 | new->iflist = iflist; |
| 184 | new->oiflist = list_new (); |
| 185 | new->vlinks = list_new (); |
| 186 | new->areas = list_new (); |
| 187 | new->areas->cmp = (int (*)(void *, void *)) ospf_area_id_cmp; |
| 188 | new->networks = route_table_init (); |
| 189 | new->nbr_nbma = route_table_init (); |
| 190 | |
| 191 | new->lsdb = ospf_lsdb_new (); |
| 192 | |
| 193 | new->default_originate = DEFAULT_ORIGINATE_NONE; |
| 194 | |
| 195 | new->new_external_route = route_table_init (); |
| 196 | new->old_external_route = route_table_init (); |
| 197 | new->external_lsas = route_table_init (); |
| 198 | |
| 199 | /* Distribute parameter init. */ |
| 200 | for (i = 0; i <= ZEBRA_ROUTE_MAX; i++) |
| 201 | { |
| 202 | new->dmetric[i].type = -1; |
| 203 | new->dmetric[i].value = -1; |
| 204 | } |
| 205 | new->default_metric = -1; |
| 206 | new->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; |
| 207 | |
| 208 | /* SPF timer value init. */ |
| 209 | new->spf_delay = OSPF_SPF_DELAY_DEFAULT; |
| 210 | new->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT; |
| 211 | |
| 212 | /* MaxAge init. */ |
| 213 | new->maxage_lsa = list_new (); |
| 214 | new->t_maxage_walker = |
| 215 | thread_add_timer (master, ospf_lsa_maxage_walker, |
| 216 | NULL, OSPF_LSA_MAXAGE_CHECK_INTERVAL); |
| 217 | |
| 218 | /* Distance table init. */ |
| 219 | new->distance_table = route_table_init (); |
| 220 | |
| 221 | new->lsa_refresh_queue.index = 0; |
| 222 | new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT; |
| 223 | new->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker, |
| 224 | new, new->lsa_refresh_interval); |
| 225 | new->lsa_refresher_started = time (NULL); |
| 226 | |
| 227 | new->fd = ospf_sock_init (); |
| 228 | if (new->fd >= 0) |
| 229 | new->t_read = thread_add_read (master, ospf_read, new, new->fd); |
| 230 | new->oi_write_q = list_new (); |
| 231 | |
| 232 | return new; |
| 233 | } |
| 234 | |
| 235 | struct ospf * |
| 236 | ospf_get () |
| 237 | { |
| 238 | if (ospf_top != NULL) |
| 239 | return ospf_top; |
| 240 | |
| 241 | ospf_top = ospf_new (); |
| 242 | |
| 243 | if (ospf_top->router_id_static.s_addr == 0) |
| 244 | ospf_router_id_update (); |
| 245 | |
| 246 | #ifdef HAVE_OPAQUE_LSA |
| 247 | ospf_opaque_type11_lsa_init (ospf_top); |
| 248 | #endif /* HAVE_OPAQUE_LSA */ |
| 249 | |
| 250 | return ospf_top; |
| 251 | } |
| 252 | |
| 253 | void |
| 254 | ospf_finish (struct ospf *ospf) |
| 255 | { |
| 256 | struct route_node *rn; |
| 257 | struct ospf_nbr_nbma *nbr_nbma; |
| 258 | listnode node; |
| 259 | int i; |
| 260 | |
| 261 | #ifdef HAVE_OPAQUE_LSA |
| 262 | ospf_opaque_type11_lsa_term (ospf); |
| 263 | #endif /* HAVE_OPAQUE_LSA */ |
| 264 | |
| 265 | /* Unredister redistribution */ |
| 266 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 267 | ospf_redistribute_unset (i); |
| 268 | |
| 269 | for (node = listhead (ospf->areas); node;) |
| 270 | { |
| 271 | struct ospf_area *area = getdata (node); |
| 272 | nextnode (node); |
| 273 | |
| 274 | ospf_remove_vls_through_area (area); |
| 275 | } |
| 276 | |
| 277 | for (node = listhead (ospf->vlinks); node; ) |
| 278 | { |
| 279 | struct ospf_vl_data *vl_data = node->data; |
| 280 | nextnode (node); |
| 281 | |
| 282 | ospf_vl_delete (vl_data); |
| 283 | } |
| 284 | |
| 285 | list_delete (ospf->vlinks); |
| 286 | |
| 287 | /* Reset interface. */ |
| 288 | for (node = listhead (ospf->oiflist); node;) |
| 289 | { |
| 290 | struct ospf_interface *oi = getdata (node); |
| 291 | nextnode (node); |
| 292 | |
| 293 | if (oi) |
| 294 | ospf_if_free (oi); |
| 295 | } |
| 296 | |
| 297 | /* Clear static neighbors */ |
| 298 | for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn)) |
| 299 | if ((nbr_nbma = rn->info)) |
| 300 | { |
| 301 | OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll); |
| 302 | |
| 303 | if (nbr_nbma->nbr) |
| 304 | { |
| 305 | nbr_nbma->nbr->nbr_nbma = NULL; |
| 306 | nbr_nbma->nbr = NULL; |
| 307 | } |
| 308 | |
| 309 | if (nbr_nbma->oi) |
| 310 | { |
| 311 | listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma); |
| 312 | nbr_nbma->oi = NULL; |
| 313 | } |
| 314 | |
| 315 | XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma); |
| 316 | } |
| 317 | |
| 318 | route_table_finish (ospf->nbr_nbma); |
| 319 | |
| 320 | /* Clear networks and Areas. */ |
| 321 | for (rn = route_top (ospf->networks); rn; rn = route_next (rn)) |
| 322 | { |
| 323 | struct ospf_network *network; |
| 324 | |
| 325 | if ((network = rn->info) != NULL) |
| 326 | { |
| 327 | ospf_network_free (network); |
| 328 | rn->info = NULL; |
| 329 | route_unlock_node (rn); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | for (node = listhead (ospf->areas); node;) |
| 334 | { |
| 335 | struct ospf_area *area = getdata (node); |
| 336 | nextnode (node); |
| 337 | |
| 338 | listnode_delete (ospf->areas, area); |
| 339 | ospf_area_free (area); |
| 340 | } |
| 341 | |
| 342 | /* Cancel all timers. */ |
| 343 | OSPF_TIMER_OFF (ospf->t_external_lsa); |
| 344 | OSPF_TIMER_OFF (ospf->t_router_id_update); |
| 345 | OSPF_TIMER_OFF (ospf->t_router_lsa_update); |
| 346 | OSPF_TIMER_OFF (ospf->t_spf_calc); |
| 347 | OSPF_TIMER_OFF (ospf->t_ase_calc); |
| 348 | OSPF_TIMER_OFF (ospf->t_maxage); |
| 349 | OSPF_TIMER_OFF (ospf->t_maxage_walker); |
| 350 | OSPF_TIMER_OFF (ospf->t_abr_task); |
| 351 | OSPF_TIMER_OFF (ospf->t_distribute_update); |
| 352 | OSPF_TIMER_OFF (ospf->t_lsa_refresher); |
| 353 | OSPF_TIMER_OFF (ospf->t_read); |
| 354 | OSPF_TIMER_OFF (ospf->t_write); |
| 355 | |
| 356 | close (ospf->fd); |
| 357 | |
| 358 | #ifdef HAVE_OPAQUE_LSA |
| 359 | foreach_lsa (OPAQUE_AS_LSDB (ospf), ospf_top->lsdb, 0, |
| 360 | ospf_lsa_discard_callback); |
| 361 | #endif /* HAVE_OPAQUE_LSA */ |
| 362 | foreach_lsa (EXTERNAL_LSDB (ospf), ospf->lsdb, 0, |
| 363 | ospf_lsa_discard_callback); |
| 364 | ospf_lsdb_delete_all (ospf->lsdb); |
| 365 | ospf_lsdb_free (ospf->lsdb); |
| 366 | |
| 367 | for (node = listhead (ospf->maxage_lsa); node; nextnode (node)) |
| 368 | ospf_lsa_unlock (getdata (node)); |
| 369 | |
| 370 | list_delete (ospf->maxage_lsa); |
| 371 | |
| 372 | if (ospf->old_table) |
| 373 | ospf_route_table_free (ospf->old_table); |
| 374 | if (ospf->new_table) |
| 375 | { |
| 376 | ospf_route_delete (ospf->new_table); |
| 377 | ospf_route_table_free (ospf->new_table); |
| 378 | } |
| 379 | if (ospf->old_rtrs) |
| 380 | ospf_rtrs_free (ospf->old_rtrs); |
| 381 | if (ospf->new_rtrs) |
| 382 | ospf_rtrs_free (ospf->new_rtrs); |
| 383 | if (ospf->new_external_route) |
| 384 | { |
| 385 | ospf_route_delete (ospf->new_external_route); |
| 386 | ospf_route_table_free (ospf->new_external_route); |
| 387 | } |
| 388 | if (ospf->old_external_route) |
| 389 | { |
| 390 | ospf_route_delete (ospf->old_external_route); |
| 391 | ospf_route_table_free (ospf->old_external_route); |
| 392 | } |
| 393 | if (ospf->external_lsas) |
| 394 | { |
| 395 | ospf_ase_external_lsas_finish (ospf->external_lsas); |
| 396 | } |
| 397 | |
| 398 | list_delete (ospf->areas); |
| 399 | |
| 400 | for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++) |
| 401 | if (EXTERNAL_INFO (i) != NULL) |
| 402 | for (rn = route_top (EXTERNAL_INFO (i)); rn; rn = route_next (rn)) |
| 403 | { |
| 404 | if (rn->info == NULL) |
| 405 | continue; |
| 406 | |
| 407 | XFREE (MTYPE_OSPF_EXTERNAL_INFO, rn->info); |
| 408 | rn->info = NULL; |
| 409 | route_unlock_node (rn); |
| 410 | } |
| 411 | |
| 412 | ospf_distance_reset (); |
| 413 | route_table_finish (ospf->distance_table); |
| 414 | |
| 415 | XFREE (MTYPE_OSPF_TOP, ospf); |
| 416 | |
| 417 | ospf_top = NULL; |
| 418 | } |
| 419 | |
| 420 | |
| 421 | /* allocate new OSPF Area object */ |
| 422 | struct ospf_area * |
| 423 | ospf_area_new (struct in_addr area_id) |
| 424 | { |
| 425 | struct ospf_area *new; |
| 426 | |
| 427 | /* Allocate new config_network. */ |
| 428 | new = XCALLOC (MTYPE_OSPF_AREA, sizeof (struct ospf_area)); |
| 429 | |
| 430 | new->top = ospf_top; |
| 431 | |
| 432 | new->area_id = area_id; |
| 433 | |
| 434 | new->external_routing = OSPF_AREA_DEFAULT; |
| 435 | new->default_cost = 1; |
| 436 | new->auth_type = OSPF_AUTH_NULL; |
| 437 | |
| 438 | /* New LSDB init. */ |
| 439 | new->lsdb = ospf_lsdb_new (); |
| 440 | |
| 441 | /* Self-originated LSAs initialize. */ |
| 442 | new->router_lsa_self = NULL; |
| 443 | |
| 444 | #ifdef HAVE_OPAQUE_LSA |
| 445 | ospf_opaque_type10_lsa_init (new); |
| 446 | #endif /* HAVE_OPAQUE_LSA */ |
| 447 | |
| 448 | new->oiflist = list_new (); |
| 449 | new->ranges = route_table_init (); |
| 450 | |
| 451 | if (area_id.s_addr == OSPF_AREA_BACKBONE) |
| 452 | ospf_top->backbone = new; |
| 453 | |
| 454 | return new; |
| 455 | } |
| 456 | |
| 457 | void |
| 458 | ospf_area_free (struct ospf_area *area) |
| 459 | { |
| 460 | /* Free LSDBs. */ |
| 461 | foreach_lsa (ROUTER_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback); |
| 462 | foreach_lsa (NETWORK_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback); |
| 463 | foreach_lsa (SUMMARY_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback); |
| 464 | foreach_lsa (ASBR_SUMMARY_LSDB (area), area->lsdb, 0, |
| 465 | ospf_lsa_discard_callback); |
| 466 | |
| 467 | #ifdef HAVE_NSSA |
| 468 | foreach_lsa (NSSA_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback); |
| 469 | #endif /* HAVE_NSSA */ |
| 470 | #ifdef HAVE_OPAQUE_LSA |
| 471 | foreach_lsa (OPAQUE_AREA_LSDB (area), area->lsdb, 0, |
| 472 | ospf_lsa_discard_callback); |
| 473 | foreach_lsa (OPAQUE_LINK_LSDB (area), area->lsdb, 0, |
| 474 | ospf_lsa_discard_callback); |
| 475 | #endif /* HAVE_OPAQUE_LSA */ |
| 476 | |
| 477 | ospf_lsdb_delete_all (area->lsdb); |
| 478 | ospf_lsdb_free (area->lsdb); |
| 479 | |
| 480 | #ifdef HAVE_OPAQUE_LSA |
| 481 | ospf_opaque_type10_lsa_term (area); |
| 482 | #endif /* HAVE_OPAQUE_LSA */ |
| 483 | ospf_lsa_unlock (area->router_lsa_self); |
| 484 | |
| 485 | route_table_finish (area->ranges); |
| 486 | list_delete (area->oiflist); |
| 487 | |
| 488 | if (EXPORT_NAME (area)) |
| 489 | free (EXPORT_NAME (area)); |
| 490 | |
| 491 | if (IMPORT_NAME (area)) |
| 492 | free (IMPORT_NAME (area)); |
| 493 | |
| 494 | /* Cancel timer. */ |
| 495 | OSPF_TIMER_OFF (area->t_router_lsa_self); |
| 496 | |
| 497 | if (OSPF_IS_AREA_BACKBONE (area)) |
| 498 | ospf_top->backbone = NULL; |
| 499 | |
| 500 | XFREE (MTYPE_OSPF_AREA, area); |
| 501 | } |
| 502 | |
| 503 | void |
| 504 | ospf_area_check_free (struct in_addr area_id) |
| 505 | { |
| 506 | struct ospf_area *area; |
| 507 | |
| 508 | area = ospf_area_lookup_by_area_id (area_id); |
| 509 | if (area && |
| 510 | listcount (area->oiflist) == 0 && |
| 511 | area->ranges->top == NULL && |
| 512 | area->shortcut_configured == OSPF_SHORTCUT_DEFAULT && |
| 513 | area->external_routing == OSPF_AREA_DEFAULT && |
| 514 | area->no_summary == 0 && |
| 515 | area->default_cost == 1 && |
| 516 | EXPORT_NAME (area) == NULL && |
| 517 | IMPORT_NAME (area) == NULL && |
| 518 | area->auth_type == OSPF_AUTH_NULL) |
| 519 | { |
| 520 | listnode_delete (ospf_top->areas, area); |
| 521 | ospf_area_free (area); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | struct ospf_area * |
| 526 | ospf_area_get (struct in_addr area_id, int format) |
| 527 | { |
| 528 | struct ospf_area *area; |
| 529 | |
| 530 | area = ospf_area_lookup_by_area_id (area_id); |
| 531 | if (!area) |
| 532 | { |
| 533 | area = ospf_area_new (area_id); |
| 534 | area->format = format; |
| 535 | listnode_add_sort (ospf_top->areas, area); |
| 536 | ospf_check_abr_status (); |
| 537 | } |
| 538 | |
| 539 | return area; |
| 540 | } |
| 541 | |
| 542 | struct ospf_area * |
| 543 | ospf_area_lookup_by_area_id (struct in_addr area_id) |
| 544 | { |
| 545 | struct ospf_area *area; |
| 546 | listnode node; |
| 547 | |
| 548 | for (node = listhead (ospf_top->areas); node; nextnode (node)) |
| 549 | { |
| 550 | area = getdata (node); |
| 551 | |
| 552 | if (IPV4_ADDR_SAME (&area->area_id, &area_id)) |
| 553 | return area; |
| 554 | } |
| 555 | |
| 556 | return NULL; |
| 557 | } |
| 558 | |
| 559 | void |
| 560 | ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi) |
| 561 | { |
| 562 | listnode_add (area->oiflist, oi); |
| 563 | } |
| 564 | |
| 565 | void |
| 566 | ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi) |
| 567 | { |
| 568 | listnode_delete (area->oiflist, oi); |
| 569 | } |
| 570 | |
| 571 | |
| 572 | /* Config network statement related functions. */ |
| 573 | struct ospf_network * |
| 574 | ospf_network_new (struct in_addr area_id, int format) |
| 575 | { |
| 576 | struct ospf_network *new; |
| 577 | new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network)); |
| 578 | |
| 579 | new->area_id = area_id; |
| 580 | new->format = format; |
| 581 | |
| 582 | return new; |
| 583 | } |
| 584 | |
| 585 | void |
| 586 | ospf_network_free (struct ospf_network *network) |
| 587 | { |
| 588 | ospf_area_check_free (network->area_id); |
| 589 | ospf_schedule_abr_task (); |
| 590 | XFREE (MTYPE_OSPF_NETWORK, network); |
| 591 | } |
| 592 | |
| 593 | int |
| 594 | ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p, |
| 595 | struct in_addr area_id) |
| 596 | { |
| 597 | struct ospf_network *network; |
| 598 | struct ospf_area *area; |
| 599 | struct route_node *rn; |
| 600 | struct external_info *ei; |
| 601 | int ret = OSPF_AREA_ID_FORMAT_DECIMAL; |
| 602 | |
| 603 | rn = route_node_get (ospf->networks, (struct prefix *)p); |
| 604 | if (rn->info) |
| 605 | { |
| 606 | /* There is already same network statement. */ |
| 607 | route_unlock_node (rn); |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | rn->info = network = ospf_network_new (area_id, ret); |
| 612 | area = ospf_area_get (area_id, ret); |
| 613 | |
| 614 | /* Run network config now. */ |
| 615 | ospf_network_run (ospf, (struct prefix *)p, area); |
| 616 | |
| 617 | /* Update connected redistribute. */ |
| 618 | if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT)) |
| 619 | if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)) |
| 620 | for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)); |
| 621 | rn; rn = route_next (rn)) |
| 622 | if ((ei = rn->info) != NULL) |
| 623 | if (ospf_external_info_find_lsa (&ei->p)) |
| 624 | if (!ospf_distribute_check_connected (ei)) |
| 625 | ospf_external_lsa_flush (ei->type, &ei->p, |
| 626 | ei->ifindex, ei->nexthop); |
| 627 | |
| 628 | ospf_area_check_free (area_id); |
| 629 | |
| 630 | return 1; |
| 631 | } |
| 632 | |
| 633 | int |
| 634 | ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p, |
| 635 | struct in_addr area_id) |
| 636 | { |
| 637 | struct route_node *rn; |
| 638 | struct ospf_network *network; |
| 639 | struct external_info *ei; |
| 640 | |
| 641 | rn = route_node_lookup (ospf->networks, (struct prefix *)p); |
| 642 | if (rn == NULL) |
| 643 | return 0; |
| 644 | |
| 645 | network = rn->info; |
| 646 | if (!IPV4_ADDR_SAME (&area_id, &network->area_id)) |
| 647 | return 0; |
| 648 | |
| 649 | ospf_network_free (rn->info); |
| 650 | rn->info = NULL; |
| 651 | route_unlock_node (rn); |
| 652 | |
| 653 | ospf_if_update (); |
| 654 | |
| 655 | /* Update connected redistribute. */ |
| 656 | if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT)) |
| 657 | if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)) |
| 658 | for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)); |
| 659 | rn; rn = route_next (rn)) |
| 660 | if ((ei = rn->info) != NULL) |
| 661 | if (!ospf_external_info_find_lsa (&ei->p)) |
| 662 | if (ospf_distribute_check_connected (ei)) |
| 663 | ospf_external_lsa_originate (ei); |
| 664 | |
| 665 | return 1; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | void |
| 670 | ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area) |
| 671 | { |
| 672 | struct interface *ifp; |
| 673 | listnode node; |
| 674 | |
| 675 | /* Schedule Router ID Update. */ |
| 676 | if (ospf->router_id_static.s_addr == 0) |
| 677 | if (ospf->t_router_id_update == NULL) |
| 678 | { |
| 679 | ospf->t_router_id_update = |
| 680 | thread_add_timer (master, ospf_router_id_update_timer, ospf, |
| 681 | OSPF_ROUTER_ID_UPDATE_DELAY); |
| 682 | } |
| 683 | |
| 684 | /* Get target interface. */ |
| 685 | for (node = listhead (ospf->iflist); node; nextnode (node)) |
| 686 | { |
| 687 | listnode cn; |
| 688 | |
| 689 | if ((ifp = getdata (node)) == NULL) |
| 690 | continue; |
| 691 | |
| 692 | if (memcmp (ifp->name, "VLINK", 5) == 0) |
| 693 | continue; |
| 694 | |
| 695 | /* if interface prefix is match specified prefix, |
| 696 | then create socket and join multicast group. */ |
| 697 | for (cn = listhead (ifp->connected); cn; nextnode (cn)) |
| 698 | { |
| 699 | struct connected *co = getdata (cn); |
| 700 | struct prefix *addr; |
| 701 | |
| 702 | if (if_is_pointopoint (ifp)) |
| 703 | addr = co->destination; |
| 704 | else |
| 705 | addr = co->address; |
| 706 | |
| 707 | if (p->family == co->address->family && |
| 708 | ! ospf_if_is_configured (&(addr->u.prefix4))) |
| 709 | if ((if_is_pointopoint (ifp) && |
| 710 | IPV4_ADDR_SAME (&(addr->u.prefix4), &(p->u.prefix4))) || |
| 711 | prefix_match (p, addr)) |
| 712 | { |
| 713 | struct ospf_interface *oi; |
| 714 | |
| 715 | oi = ospf_if_new (ifp, co->address); |
| 716 | oi->connected = co; |
| 717 | |
| 718 | oi->nbr_self->address = *oi->address; |
| 719 | |
| 720 | area->act_ints++; |
| 721 | oi->area = area; |
| 722 | |
| 723 | oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4); |
| 724 | oi->output_cost = ospf_if_get_output_cost (oi); |
| 725 | |
| 726 | if (area->external_routing != OSPF_AREA_DEFAULT) |
| 727 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 728 | oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority); |
| 729 | |
| 730 | /* Add pseudo neighbor. */ |
| 731 | ospf_nbr_add_self (oi); |
| 732 | |
| 733 | /* Make sure pseudo neighbor's router_id. */ |
| 734 | oi->nbr_self->router_id = ospf_top->router_id; |
| 735 | oi->nbr_self->src = oi->address->u.prefix4; |
| 736 | |
| 737 | /* Relate ospf interface to ospf instance. */ |
| 738 | oi->ospf = ospf_top; |
| 739 | |
| 740 | /* update network type as interface flag */ |
| 741 | /* If network type is specified previously, |
| 742 | skip network type setting. */ |
| 743 | oi->type = IF_DEF_PARAMS (ifp)->type; |
| 744 | |
| 745 | /* Set area flag. */ |
| 746 | switch (area->external_routing) |
| 747 | { |
| 748 | case OSPF_AREA_DEFAULT: |
| 749 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 750 | break; |
| 751 | case OSPF_AREA_STUB: |
| 752 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 753 | break; |
| 754 | #ifdef HAVE_NSSA |
| 755 | case OSPF_AREA_NSSA: |
| 756 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 757 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
| 758 | break; |
| 759 | #endif /* HAVE_NSSA */ |
| 760 | } |
| 761 | |
| 762 | ospf_area_add_if (oi->area, oi); |
| 763 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 764 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 765 | ospf_if_up (oi); |
| 766 | |
| 767 | break; |
| 768 | } |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | void |
| 774 | ospf_ls_upd_queue_empty (struct ospf_interface *oi) |
| 775 | { |
| 776 | struct route_node *rn; |
| 777 | listnode node; |
| 778 | list lst; |
| 779 | struct ospf_lsa *lsa; |
| 780 | |
| 781 | /* empty ls update queue */ |
| 782 | for (rn = route_top (oi->ls_upd_queue); rn; |
| 783 | rn = route_next (rn)) |
| 784 | if ((lst = (list) rn->info)) |
| 785 | { |
| 786 | for (node = listhead (lst); node; nextnode (node)) |
| 787 | if ((lsa = getdata (node))) |
| 788 | ospf_lsa_unlock (lsa); |
| 789 | list_free (lst); |
| 790 | rn->info = NULL; |
| 791 | } |
| 792 | |
| 793 | /* remove update event */ |
| 794 | if (oi->t_ls_upd_event) |
| 795 | { |
| 796 | thread_cancel (oi->t_ls_upd_event); |
| 797 | oi->t_ls_upd_event = NULL; |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | void |
| 802 | ospf_if_update () |
| 803 | { |
| 804 | struct route_node *rn; |
| 805 | listnode node; |
| 806 | listnode next; |
| 807 | struct ospf_network *network; |
| 808 | struct ospf_area *area; |
| 809 | |
| 810 | if (ospf_top != NULL) |
| 811 | { |
| 812 | /* Update Router ID scheduled. */ |
| 813 | if (ospf_top->router_id_static.s_addr == 0) |
| 814 | if (ospf_top->t_router_id_update == NULL) |
| 815 | { |
| 816 | ospf_top->t_router_id_update = |
| 817 | thread_add_timer (master, ospf_router_id_update_timer, NULL, |
| 818 | OSPF_ROUTER_ID_UPDATE_DELAY); |
| 819 | } |
| 820 | |
| 821 | /* Find interfaces that not configured already. */ |
| 822 | for (node = listhead (ospf_top->oiflist); node; node = next) |
| 823 | { |
| 824 | int found = 0; |
| 825 | struct ospf_interface *oi = getdata (node); |
| 826 | struct connected *co = oi->connected; |
| 827 | |
| 828 | next = nextnode (node); |
| 829 | |
| 830 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 831 | continue; |
| 832 | |
| 833 | for (rn = route_top (ospf_top->networks); rn; rn = route_next (rn)) |
| 834 | { |
| 835 | if (rn->info == NULL) |
| 836 | continue; |
| 837 | |
| 838 | if ((oi->type == OSPF_IFTYPE_POINTOPOINT |
| 839 | && IPV4_ADDR_SAME (&(co->destination->u.prefix4), |
| 840 | &(rn->p.u.prefix4))) |
| 841 | || prefix_match (&(rn->p), co->address)) |
| 842 | { |
| 843 | found = 1; |
| 844 | route_unlock_node (rn); |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | if (found == 0) |
| 850 | ospf_if_free (oi); |
| 851 | } |
| 852 | |
| 853 | /* Run each interface. */ |
| 854 | for (rn = route_top (ospf_top->networks); rn; rn = route_next (rn)) |
| 855 | if (rn->info != NULL) |
| 856 | { |
| 857 | network = (struct ospf_network *) rn->info; |
| 858 | area = ospf_area_get (network->area_id, network->format); |
| 859 | ospf_network_run (ospf_top, &rn->p, area); |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | void |
| 865 | ospf_remove_vls_through_area (struct ospf_area *area) |
| 866 | { |
| 867 | listnode node, next; |
| 868 | struct ospf_vl_data *vl_data; |
| 869 | |
| 870 | for (node = listhead (ospf_top->vlinks); node; node = next) |
| 871 | { |
| 872 | next = node->next; |
| 873 | if ((vl_data = getdata (node)) != NULL) |
| 874 | if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
| 875 | ospf_vl_delete (vl_data); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | |
| 880 | struct message ospf_area_type_msg[] = |
| 881 | { |
| 882 | { OSPF_AREA_DEFAULT, "Default" }, |
| 883 | { OSPF_AREA_STUB, "Stub" }, |
| 884 | { OSPF_AREA_NSSA, "NSSA" }, |
| 885 | }; |
| 886 | int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX; |
| 887 | |
| 888 | void |
| 889 | ospf_area_type_set (struct ospf_area *area, int type) |
| 890 | { |
| 891 | listnode node; |
| 892 | struct ospf_interface *oi; |
| 893 | |
| 894 | if (area->external_routing == type) |
| 895 | { |
| 896 | if (IS_DEBUG_OSPF_EVENT) |
| 897 | zlog_info ("Area[%s]: Types are the same, ignored.", |
| 898 | inet_ntoa (area->area_id)); |
| 899 | return; |
| 900 | } |
| 901 | |
| 902 | area->external_routing = type; |
| 903 | |
| 904 | if (IS_DEBUG_OSPF_EVENT) |
| 905 | zlog_info ("Area[%s]: Configured as %s", inet_ntoa (area->area_id), |
| 906 | LOOKUP (ospf_area_type_msg, type)); |
| 907 | |
| 908 | switch (area->external_routing) |
| 909 | { |
| 910 | case OSPF_AREA_DEFAULT: |
| 911 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 912 | if ((oi = getdata (node)) != NULL) |
| 913 | if (oi->nbr_self != NULL) |
| 914 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 915 | break; |
| 916 | case OSPF_AREA_STUB: |
| 917 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 918 | if ((oi = getdata (node)) != NULL) |
| 919 | if (oi->nbr_self != NULL) |
| 920 | { |
| 921 | if (IS_DEBUG_OSPF_EVENT) |
| 922 | zlog_info ("setting options on %s accordingly", IF_NAME (oi)); |
| 923 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 924 | if (IS_DEBUG_OSPF_EVENT) |
| 925 | zlog_info ("options set on %s: %x", |
| 926 | IF_NAME (oi), OPTIONS (oi)); |
| 927 | } |
| 928 | break; |
| 929 | case OSPF_AREA_NSSA: |
| 930 | #ifdef HAVE_NSSA |
| 931 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 932 | if ((oi = getdata (node)) != NULL) |
| 933 | if (oi->nbr_self != NULL) |
| 934 | { |
| 935 | zlog_info ("setting nssa options on %s accordingly", IF_NAME (oi)); |
| 936 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 937 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
| 938 | zlog_info ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi)); |
| 939 | } |
| 940 | #endif /* HAVE_NSSA */ |
| 941 | break; |
| 942 | default: |
| 943 | break; |
| 944 | } |
| 945 | |
| 946 | ospf_router_lsa_timer_add (area); |
| 947 | ospf_schedule_abr_task (); |
| 948 | } |
| 949 | |
| 950 | int |
| 951 | ospf_area_shortcut_set (struct ospf_area *area, int mode) |
| 952 | { |
| 953 | if (area->shortcut_configured == mode) |
| 954 | return 0; |
| 955 | |
| 956 | area->shortcut_configured = mode; |
| 957 | ospf_router_lsa_timer_add (area); |
| 958 | ospf_schedule_abr_task (); |
| 959 | |
| 960 | ospf_area_check_free (area->area_id); |
| 961 | |
| 962 | return 1; |
| 963 | } |
| 964 | |
| 965 | int |
| 966 | ospf_area_shortcut_unset (struct ospf_area *area) |
| 967 | { |
| 968 | area->shortcut_configured = OSPF_SHORTCUT_DEFAULT; |
| 969 | ospf_router_lsa_timer_add (area); |
| 970 | ospf_area_check_free (area->area_id); |
| 971 | ospf_schedule_abr_task (); |
| 972 | |
| 973 | return 1; |
| 974 | } |
| 975 | |
| 976 | int |
| 977 | ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area) |
| 978 | { |
| 979 | struct ospf_vl_data *vl; |
| 980 | listnode node; |
| 981 | int count = 0; |
| 982 | |
| 983 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
| 984 | { |
| 985 | vl = getdata (node); |
| 986 | if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id)) |
| 987 | count++; |
| 988 | } |
| 989 | |
| 990 | return count; |
| 991 | } |
| 992 | |
| 993 | int |
| 994 | ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id) |
| 995 | { |
| 996 | struct ospf_area *area; |
| 997 | int format = OSPF_AREA_ID_FORMAT_DECIMAL; |
| 998 | |
| 999 | area = ospf_area_get (area_id, format); |
| 1000 | if (ospf_area_vlink_count (ospf, area)) |
| 1001 | return 0; |
| 1002 | |
| 1003 | if (area->external_routing != OSPF_AREA_STUB) |
| 1004 | ospf_area_type_set (area, OSPF_AREA_STUB); |
| 1005 | |
| 1006 | return 1; |
| 1007 | } |
| 1008 | |
| 1009 | int |
| 1010 | ospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id) |
| 1011 | { |
| 1012 | struct ospf_area *area; |
| 1013 | |
| 1014 | area = ospf_area_lookup_by_area_id (area_id); |
| 1015 | if (area == NULL) |
| 1016 | return 1; |
| 1017 | |
| 1018 | if (area->external_routing == OSPF_AREA_STUB) |
| 1019 | ospf_area_type_set (area, OSPF_AREA_DEFAULT); |
| 1020 | |
| 1021 | ospf_area_check_free (area_id); |
| 1022 | |
| 1023 | return 1; |
| 1024 | } |
| 1025 | |
| 1026 | int |
| 1027 | ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id) |
| 1028 | { |
| 1029 | struct ospf_area *area; |
| 1030 | int format = OSPF_AREA_ID_FORMAT_DECIMAL; |
| 1031 | |
| 1032 | area = ospf_area_get (area_id, format); |
| 1033 | area->no_summary = 1; |
| 1034 | |
| 1035 | return 1; |
| 1036 | } |
| 1037 | |
| 1038 | int |
| 1039 | ospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id) |
| 1040 | { |
| 1041 | struct ospf_area *area; |
| 1042 | |
| 1043 | area = ospf_area_lookup_by_area_id (area_id); |
| 1044 | if (area == NULL) |
| 1045 | return 0; |
| 1046 | |
| 1047 | area->no_summary = 0; |
| 1048 | ospf_area_check_free (area_id); |
| 1049 | |
| 1050 | return 1; |
| 1051 | } |
| 1052 | |
| 1053 | int |
| 1054 | ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id) |
| 1055 | { |
| 1056 | struct ospf_area *area; |
| 1057 | int format = OSPF_AREA_ID_FORMAT_DECIMAL; |
| 1058 | |
| 1059 | area = ospf_area_get (area_id, format); |
| 1060 | if (ospf_area_vlink_count (ospf, area)) |
| 1061 | return 0; |
| 1062 | |
| 1063 | if (area->external_routing != OSPF_AREA_NSSA) |
| 1064 | { |
| 1065 | ospf_area_type_set (area, OSPF_AREA_NSSA); |
| 1066 | ospf->anyNSSA++; |
| 1067 | } |
| 1068 | |
| 1069 | return 1; |
| 1070 | } |
| 1071 | |
| 1072 | int |
| 1073 | ospf_area_nssa_unset (struct ospf *ospf, struct in_addr area_id) |
| 1074 | { |
| 1075 | struct ospf_area *area; |
| 1076 | |
| 1077 | area = ospf_area_lookup_by_area_id (area_id); |
| 1078 | if (area == NULL) |
| 1079 | return 0; |
| 1080 | |
| 1081 | if (area->external_routing == OSPF_AREA_NSSA) |
| 1082 | { |
| 1083 | ospf->anyNSSA--; |
| 1084 | ospf_area_type_set (area, OSPF_AREA_DEFAULT); |
| 1085 | } |
| 1086 | |
| 1087 | ospf_area_check_free (area_id); |
| 1088 | |
| 1089 | return 1; |
| 1090 | } |
| 1091 | |
| 1092 | int |
| 1093 | ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id, |
| 1094 | int role) |
| 1095 | { |
| 1096 | struct ospf_area *area; |
| 1097 | |
| 1098 | area = ospf_area_lookup_by_area_id (area_id); |
| 1099 | if (area == NULL) |
| 1100 | return 0; |
| 1101 | |
| 1102 | area->NSSATranslator = role; |
| 1103 | |
| 1104 | return 1; |
| 1105 | } |
| 1106 | |
| 1107 | int |
| 1108 | ospf_area_nssa_translator_role_unset (struct ospf *ospf, |
| 1109 | struct in_addr area_id) |
| 1110 | { |
| 1111 | struct ospf_area *area; |
| 1112 | |
| 1113 | area = ospf_area_lookup_by_area_id (area_id); |
| 1114 | if (area == NULL) |
| 1115 | return 0; |
| 1116 | |
| 1117 | area->NSSATranslator = OSPF_NSSA_ROLE_CANDIDATE; |
| 1118 | |
| 1119 | ospf_area_check_free (area_id); |
| 1120 | |
| 1121 | return 1; |
| 1122 | } |
| 1123 | |
| 1124 | int |
| 1125 | ospf_area_export_list_set (struct ospf_area *area, char *list_name) |
| 1126 | { |
| 1127 | struct access_list *list; |
| 1128 | list = access_list_lookup (AFI_IP, list_name); |
| 1129 | |
| 1130 | EXPORT_LIST (area) = list; |
| 1131 | |
| 1132 | if (EXPORT_NAME (area)) |
| 1133 | free (EXPORT_NAME (area)); |
| 1134 | |
| 1135 | EXPORT_NAME (area) = strdup (list_name); |
| 1136 | ospf_schedule_abr_task (); |
| 1137 | |
| 1138 | return 1; |
| 1139 | } |
| 1140 | |
| 1141 | int |
| 1142 | ospf_area_export_list_unset (struct ospf_area * area) |
| 1143 | { |
| 1144 | |
| 1145 | EXPORT_LIST (area) = 0; |
| 1146 | |
| 1147 | if (EXPORT_NAME (area)) |
| 1148 | free (EXPORT_NAME (area)); |
| 1149 | |
| 1150 | EXPORT_NAME (area) = NULL; |
| 1151 | |
| 1152 | ospf_area_check_free (area->area_id); |
| 1153 | |
| 1154 | ospf_schedule_abr_task (); |
| 1155 | |
| 1156 | return 1; |
| 1157 | } |
| 1158 | |
| 1159 | int |
| 1160 | ospf_area_import_list_set (struct ospf_area *area, char *name) |
| 1161 | { |
| 1162 | struct access_list *list; |
| 1163 | list = access_list_lookup (AFI_IP, name); |
| 1164 | |
| 1165 | IMPORT_LIST (area) = list; |
| 1166 | |
| 1167 | if (IMPORT_NAME (area)) |
| 1168 | free (IMPORT_NAME (area)); |
| 1169 | |
| 1170 | IMPORT_NAME (area) = strdup (name); |
| 1171 | ospf_schedule_abr_task (); |
| 1172 | |
| 1173 | return 1; |
| 1174 | } |
| 1175 | |
| 1176 | int |
| 1177 | ospf_area_import_list_unset (struct ospf_area * area) |
| 1178 | { |
| 1179 | IMPORT_LIST (area) = 0; |
| 1180 | |
| 1181 | if (IMPORT_NAME (area)) |
| 1182 | free (IMPORT_NAME (area)); |
| 1183 | |
| 1184 | IMPORT_NAME (area) = NULL; |
| 1185 | ospf_area_check_free (area->area_id); |
| 1186 | |
| 1187 | ospf_schedule_abr_task (); |
| 1188 | |
| 1189 | return 1; |
| 1190 | } |
| 1191 | |
| 1192 | int |
| 1193 | ospf_timers_spf_set (struct ospf *ospf, u_int32_t delay, u_int32_t hold) |
| 1194 | { |
| 1195 | ospf->spf_delay = delay; |
| 1196 | ospf->spf_holdtime = hold; |
| 1197 | |
| 1198 | return 1; |
| 1199 | } |
| 1200 | |
| 1201 | int |
| 1202 | ospf_timers_spf_unset (struct ospf *ospf) |
| 1203 | { |
| 1204 | ospf->spf_delay = OSPF_SPF_DELAY_DEFAULT; |
| 1205 | ospf->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT; |
| 1206 | |
| 1207 | return 1; |
| 1208 | } |
| 1209 | |
| 1210 | int |
| 1211 | ospf_timers_refresh_set (struct ospf *ospf, int interval) |
| 1212 | { |
| 1213 | int time_left; |
| 1214 | |
| 1215 | if (ospf->lsa_refresh_interval == interval) |
| 1216 | return 1; |
| 1217 | |
| 1218 | time_left = ospf->lsa_refresh_interval - |
| 1219 | (time (NULL) - ospf->lsa_refresher_started); |
| 1220 | |
| 1221 | if (time_left > interval) |
| 1222 | { |
| 1223 | OSPF_TIMER_OFF (ospf->t_lsa_refresher); |
| 1224 | ospf->t_lsa_refresher = |
| 1225 | thread_add_timer (master, ospf_lsa_refresh_walker, ospf, interval); |
| 1226 | } |
| 1227 | ospf->lsa_refresh_interval = interval; |
| 1228 | |
| 1229 | return 1; |
| 1230 | } |
| 1231 | |
| 1232 | int |
| 1233 | ospf_timers_refresh_unset (struct ospf *ospf) |
| 1234 | { |
| 1235 | int time_left; |
| 1236 | |
| 1237 | time_left = ospf->lsa_refresh_interval - |
| 1238 | (time (NULL) - ospf->lsa_refresher_started); |
| 1239 | |
| 1240 | if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
| 1241 | { |
| 1242 | OSPF_TIMER_OFF (ospf->t_lsa_refresher); |
| 1243 | ospf->t_lsa_refresher = |
| 1244 | thread_add_timer (master, ospf_lsa_refresh_walker, ospf, |
| 1245 | OSPF_LSA_REFRESH_INTERVAL_DEFAULT); |
| 1246 | } |
| 1247 | |
| 1248 | ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT; |
| 1249 | |
| 1250 | return 1; |
| 1251 | } |
| 1252 | |
| 1253 | |
| 1254 | struct ospf_nbr_nbma * |
| 1255 | ospf_nbr_nbma_new () |
| 1256 | { |
| 1257 | struct ospf_nbr_nbma *nbr_nbma; |
| 1258 | |
| 1259 | nbr_nbma = XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC, |
| 1260 | sizeof (struct ospf_nbr_nbma)); |
| 1261 | memset (nbr_nbma, 0, sizeof (struct ospf_nbr_nbma)); |
| 1262 | |
| 1263 | nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; |
| 1264 | nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT; |
| 1265 | |
| 1266 | return nbr_nbma; |
| 1267 | } |
| 1268 | |
| 1269 | void |
| 1270 | ospf_nbr_nbma_free (struct ospf_nbr_nbma *nbr_nbma) |
| 1271 | { |
| 1272 | XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma); |
| 1273 | } |
| 1274 | |
| 1275 | void |
| 1276 | ospf_nbr_nbma_delete (struct ospf *ospf, struct ospf_nbr_nbma *nbr_nbma) |
| 1277 | { |
| 1278 | struct route_node *rn; |
| 1279 | struct prefix_ipv4 p; |
| 1280 | |
| 1281 | p.family = AF_INET; |
| 1282 | p.prefix = nbr_nbma->addr; |
| 1283 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1284 | |
| 1285 | rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p); |
| 1286 | if (rn) |
| 1287 | { |
| 1288 | ospf_nbr_nbma_free (rn->info); |
| 1289 | rn->info = NULL; |
| 1290 | route_unlock_node (rn); |
| 1291 | route_unlock_node (rn); |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | void |
| 1296 | ospf_nbr_nbma_down (struct ospf_nbr_nbma *nbr_nbma) |
| 1297 | { |
| 1298 | OSPF_TIMER_OFF (nbr_nbma->t_poll); |
| 1299 | |
| 1300 | if (nbr_nbma->nbr) |
| 1301 | { |
| 1302 | nbr_nbma->nbr->nbr_nbma = NULL; |
| 1303 | OSPF_NSM_EVENT_EXECUTE (nbr_nbma->nbr, NSM_KillNbr); |
| 1304 | } |
| 1305 | |
| 1306 | if (nbr_nbma->oi) |
| 1307 | listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma); |
| 1308 | } |
| 1309 | |
| 1310 | void |
| 1311 | ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma, |
| 1312 | struct ospf_interface *oi) |
| 1313 | { |
| 1314 | struct ospf_neighbor *nbr; |
| 1315 | struct route_node *rn; |
| 1316 | struct prefix p; |
| 1317 | |
| 1318 | if (oi->type != OSPF_IFTYPE_NBMA) |
| 1319 | return; |
| 1320 | |
| 1321 | if (nbr_nbma->nbr != NULL) |
| 1322 | return; |
| 1323 | |
| 1324 | if (IPV4_ADDR_SAME (&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr)) |
| 1325 | return; |
| 1326 | |
| 1327 | nbr_nbma->oi = oi; |
| 1328 | listnode_add (oi->nbr_nbma, nbr_nbma); |
| 1329 | |
| 1330 | /* Get neighbor information from table. */ |
| 1331 | p.family = AF_INET; |
| 1332 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1333 | p.u.prefix4 = nbr_nbma->addr; |
| 1334 | |
| 1335 | rn = route_node_get (oi->nbrs, (struct prefix *)&p); |
| 1336 | if (rn->info) |
| 1337 | { |
| 1338 | nbr = rn->info; |
| 1339 | nbr->nbr_nbma = nbr_nbma; |
| 1340 | nbr_nbma->nbr = nbr; |
| 1341 | |
| 1342 | route_unlock_node (rn); |
| 1343 | } |
| 1344 | else |
| 1345 | { |
| 1346 | nbr = rn->info = ospf_nbr_new (oi); |
| 1347 | nbr->state = NSM_Down; |
| 1348 | nbr->src = nbr_nbma->addr; |
| 1349 | nbr->nbr_nbma = nbr_nbma; |
| 1350 | nbr->priority = nbr_nbma->priority; |
| 1351 | nbr->address = p; |
| 1352 | |
| 1353 | nbr_nbma->nbr = nbr; |
| 1354 | |
| 1355 | OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start); |
| 1356 | } |
| 1357 | } |
| 1358 | |
| 1359 | void |
| 1360 | ospf_nbr_nbma_if_update (struct ospf_interface *oi) |
| 1361 | { |
| 1362 | struct ospf_nbr_nbma *nbr_nbma; |
| 1363 | struct route_node *rn; |
| 1364 | struct prefix_ipv4 p; |
| 1365 | |
| 1366 | if (oi->type != OSPF_IFTYPE_NBMA) |
| 1367 | return; |
| 1368 | |
| 1369 | for (rn = route_top (ospf_top->nbr_nbma); rn; rn = route_next (rn)) |
| 1370 | if ((nbr_nbma = rn->info)) |
| 1371 | if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL) |
| 1372 | { |
| 1373 | p.family = AF_INET; |
| 1374 | p.prefix = nbr_nbma->addr; |
| 1375 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1376 | |
| 1377 | if (prefix_match (oi->address, (struct prefix *)&p)) |
| 1378 | ospf_nbr_nbma_add (nbr_nbma, oi); |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | struct ospf_nbr_nbma * |
| 1383 | ospf_nbr_nbma_lookup (struct ospf *ospf, struct in_addr nbr_addr) |
| 1384 | { |
| 1385 | struct route_node *rn; |
| 1386 | struct prefix_ipv4 p; |
| 1387 | |
| 1388 | p.family = AF_INET; |
| 1389 | p.prefix = nbr_addr; |
| 1390 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1391 | |
| 1392 | rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p); |
| 1393 | if (rn) |
| 1394 | { |
| 1395 | route_unlock_node (rn); |
| 1396 | return rn->info; |
| 1397 | } |
| 1398 | return NULL; |
| 1399 | } |
| 1400 | |
| 1401 | struct ospf_nbr_nbma * |
| 1402 | ospf_nbr_nbma_lookup_next (struct in_addr *addr, int first) |
| 1403 | { |
| 1404 | #if 0 |
| 1405 | struct ospf_nbr_nbma *nbr_nbma; |
| 1406 | listnode node; |
| 1407 | #endif |
| 1408 | |
| 1409 | if (! ospf_top) |
| 1410 | return NULL; |
| 1411 | |
| 1412 | #if 0 |
| 1413 | for (node = listhead (ospf_top->nbr_nbma); node; nextnode (node)) |
| 1414 | { |
| 1415 | nbr_nbma = getdata (node); |
| 1416 | |
| 1417 | if (first) |
| 1418 | { |
| 1419 | *addr = nbr_nbma->addr; |
| 1420 | return nbr_nbma; |
| 1421 | } |
| 1422 | else if (ntohl (nbr_nbma->addr.s_addr) > ntohl (addr->s_addr)) |
| 1423 | { |
| 1424 | *addr = nbr_nbma->addr; |
| 1425 | return nbr_nbma; |
| 1426 | } |
| 1427 | } |
| 1428 | #endif |
| 1429 | return NULL; |
| 1430 | } |
| 1431 | |
| 1432 | int |
| 1433 | ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr) |
| 1434 | { |
| 1435 | struct ospf_nbr_nbma *nbr_nbma; |
| 1436 | struct ospf_interface *oi; |
| 1437 | struct prefix_ipv4 p; |
| 1438 | struct route_node *rn; |
| 1439 | listnode node; |
| 1440 | |
| 1441 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1442 | if (nbr_nbma) |
| 1443 | return 0; |
| 1444 | |
| 1445 | nbr_nbma = ospf_nbr_nbma_new (); |
| 1446 | nbr_nbma->addr = nbr_addr; |
| 1447 | |
| 1448 | p.family = AF_INET; |
| 1449 | p.prefix = nbr_addr; |
| 1450 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1451 | |
| 1452 | rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p); |
| 1453 | rn->info = nbr_nbma; |
| 1454 | |
| 1455 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
| 1456 | { |
| 1457 | oi = getdata (node); |
| 1458 | if (oi->type == OSPF_IFTYPE_NBMA) |
| 1459 | if (prefix_match (oi->address, (struct prefix *)&p)) |
| 1460 | { |
| 1461 | ospf_nbr_nbma_add (nbr_nbma, oi); |
| 1462 | break; |
| 1463 | } |
| 1464 | } |
| 1465 | |
| 1466 | return 1; |
| 1467 | } |
| 1468 | |
| 1469 | int |
| 1470 | ospf_nbr_nbma_unset (struct ospf *ospf, struct in_addr nbr_addr) |
| 1471 | { |
| 1472 | struct ospf_nbr_nbma *nbr_nbma; |
| 1473 | |
| 1474 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1475 | if (nbr_nbma == NULL) |
| 1476 | return 0; |
| 1477 | |
| 1478 | ospf_nbr_nbma_down (nbr_nbma); |
| 1479 | ospf_nbr_nbma_delete (ospf, nbr_nbma); |
| 1480 | |
| 1481 | return 1; |
| 1482 | } |
| 1483 | |
| 1484 | int |
| 1485 | ospf_nbr_nbma_priority_set (struct ospf *ospf, struct in_addr nbr_addr, |
| 1486 | u_char priority) |
| 1487 | { |
| 1488 | struct ospf_nbr_nbma *nbr_nbma; |
| 1489 | |
| 1490 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1491 | if (nbr_nbma == NULL) |
| 1492 | return 0; |
| 1493 | |
| 1494 | if (nbr_nbma->priority != priority) |
| 1495 | nbr_nbma->priority = priority; |
| 1496 | |
| 1497 | return 1; |
| 1498 | } |
| 1499 | |
| 1500 | int |
| 1501 | ospf_nbr_nbma_priority_unset (struct ospf *ospf, struct in_addr nbr_addr) |
| 1502 | { |
| 1503 | struct ospf_nbr_nbma *nbr_nbma; |
| 1504 | |
| 1505 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1506 | if (nbr_nbma == NULL) |
| 1507 | return 0; |
| 1508 | |
| 1509 | if (nbr_nbma != OSPF_NEIGHBOR_PRIORITY_DEFAULT) |
| 1510 | nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; |
| 1511 | |
| 1512 | return 1; |
| 1513 | } |
| 1514 | |
| 1515 | int |
| 1516 | ospf_nbr_nbma_poll_interval_set (struct ospf *ospf, struct in_addr nbr_addr, |
| 1517 | int interval) |
| 1518 | { |
| 1519 | struct ospf_nbr_nbma *nbr_nbma; |
| 1520 | |
| 1521 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1522 | if (nbr_nbma == NULL) |
| 1523 | return 0; |
| 1524 | |
| 1525 | if (nbr_nbma->v_poll != interval) |
| 1526 | { |
| 1527 | nbr_nbma->v_poll = interval; |
| 1528 | if (nbr_nbma->oi && ospf_if_is_up (nbr_nbma->oi)) |
| 1529 | { |
| 1530 | OSPF_TIMER_OFF (nbr_nbma->t_poll); |
| 1531 | OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer, |
| 1532 | nbr_nbma->v_poll); |
| 1533 | } |
| 1534 | } |
| 1535 | |
| 1536 | return 1; |
| 1537 | } |
| 1538 | |
| 1539 | int |
| 1540 | ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr) |
| 1541 | { |
| 1542 | struct ospf_nbr_nbma *nbr_nbma; |
| 1543 | |
| 1544 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, addr); |
| 1545 | if (nbr_nbma == NULL) |
| 1546 | return 0; |
| 1547 | |
| 1548 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
| 1549 | nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT; |
| 1550 | |
| 1551 | return 1; |
| 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | void |
| 1556 | ospf_prefix_list_update (struct prefix_list *plist) |
| 1557 | { |
| 1558 | struct ospf_area *area; |
| 1559 | listnode node; |
| 1560 | int abr_inv = 0; |
| 1561 | |
| 1562 | /* If OSPF instatnce does not exist, return right now. */ |
| 1563 | if (!ospf_top) |
| 1564 | return; |
| 1565 | |
| 1566 | /* Update Area prefix-list. */ |
| 1567 | for (node = listhead (ospf_top->areas); node; nextnode (node)) |
| 1568 | { |
| 1569 | area = getdata (node); |
| 1570 | |
| 1571 | /* Update filter-list in. */ |
| 1572 | if (PREFIX_NAME_IN (area)) |
| 1573 | if (strcmp (PREFIX_NAME_IN (area), plist->name) == 0) |
| 1574 | { |
| 1575 | PREFIX_LIST_IN (area) = |
| 1576 | prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area)); |
| 1577 | abr_inv++; |
| 1578 | } |
| 1579 | |
| 1580 | /* Update filter-list out. */ |
| 1581 | if (PREFIX_NAME_OUT (area)) |
| 1582 | if (strcmp (PREFIX_NAME_OUT (area), plist->name) == 0) |
| 1583 | { |
| 1584 | PREFIX_LIST_IN (area) = |
| 1585 | prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area)); |
| 1586 | abr_inv++; |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | /* Schedule ABR tasks. */ |
| 1591 | if (OSPF_IS_ABR && abr_inv) |
| 1592 | ospf_schedule_abr_task (); |
| 1593 | } |
| 1594 | |
| 1595 | void |
| 1596 | ospf_init () |
| 1597 | { |
| 1598 | /* Make empty list of ospf list. */ |
| 1599 | ospf_top = NULL; |
| 1600 | |
| 1601 | prefix_list_add_hook (ospf_prefix_list_update); |
| 1602 | prefix_list_delete_hook (ospf_prefix_list_update); |
| 1603 | } |