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