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 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 506 | LSDB_LOOP (NSSA_LSDB (area), rn, lsa) |
| 507 | ospf_discard_from_db (area->ospf, area->lsdb, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 508 | #ifdef HAVE_OPAQUE_LSA |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 509 | LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) |
| 510 | ospf_discard_from_db (area->ospf, area->lsdb, lsa); |
| 511 | LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) |
| 512 | ospf_discard_from_db (area->ospf, area->lsdb, lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 513 | #endif /* HAVE_OPAQUE_LSA */ |
| 514 | |
| 515 | ospf_lsdb_delete_all (area->lsdb); |
| 516 | ospf_lsdb_free (area->lsdb); |
| 517 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 518 | ospf_lsa_unlock (area->router_lsa_self); |
| 519 | |
| 520 | route_table_finish (area->ranges); |
| 521 | list_delete (area->oiflist); |
| 522 | |
| 523 | if (EXPORT_NAME (area)) |
| 524 | free (EXPORT_NAME (area)); |
| 525 | |
| 526 | if (IMPORT_NAME (area)) |
| 527 | free (IMPORT_NAME (area)); |
| 528 | |
| 529 | /* Cancel timer. */ |
| 530 | OSPF_TIMER_OFF (area->t_router_lsa_self); |
| 531 | |
| 532 | if (OSPF_IS_AREA_BACKBONE (area)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 533 | area->ospf->backbone = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 534 | |
| 535 | XFREE (MTYPE_OSPF_AREA, area); |
| 536 | } |
| 537 | |
| 538 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 539 | ospf_area_check_free (struct ospf *ospf, struct in_addr area_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 540 | { |
| 541 | struct ospf_area *area; |
| 542 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 543 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 544 | if (area && |
| 545 | listcount (area->oiflist) == 0 && |
| 546 | area->ranges->top == NULL && |
| 547 | area->shortcut_configured == OSPF_SHORTCUT_DEFAULT && |
| 548 | area->external_routing == OSPF_AREA_DEFAULT && |
| 549 | area->no_summary == 0 && |
| 550 | area->default_cost == 1 && |
| 551 | EXPORT_NAME (area) == NULL && |
| 552 | IMPORT_NAME (area) == NULL && |
| 553 | area->auth_type == OSPF_AUTH_NULL) |
| 554 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 555 | listnode_delete (ospf->areas, area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 556 | ospf_area_free (area); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | struct ospf_area * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 561 | ospf_area_get (struct ospf *ospf, struct in_addr area_id, int format) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 562 | { |
| 563 | struct ospf_area *area; |
| 564 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 565 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 566 | if (!area) |
| 567 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 568 | area = ospf_area_new (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 569 | area->format = format; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 570 | listnode_add_sort (ospf->areas, area); |
| 571 | ospf_check_abr_status (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | return area; |
| 575 | } |
| 576 | |
| 577 | struct ospf_area * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 578 | 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] | 579 | { |
| 580 | struct ospf_area *area; |
| 581 | listnode node; |
| 582 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 583 | for (node = listhead (ospf->areas); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 584 | { |
| 585 | area = getdata (node); |
| 586 | |
| 587 | if (IPV4_ADDR_SAME (&area->area_id, &area_id)) |
| 588 | return area; |
| 589 | } |
| 590 | |
| 591 | return NULL; |
| 592 | } |
| 593 | |
| 594 | void |
| 595 | ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi) |
| 596 | { |
| 597 | listnode_add (area->oiflist, oi); |
| 598 | } |
| 599 | |
| 600 | void |
| 601 | ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi) |
| 602 | { |
| 603 | listnode_delete (area->oiflist, oi); |
| 604 | } |
| 605 | |
| 606 | |
| 607 | /* Config network statement related functions. */ |
| 608 | struct ospf_network * |
| 609 | ospf_network_new (struct in_addr area_id, int format) |
| 610 | { |
| 611 | struct ospf_network *new; |
| 612 | new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network)); |
| 613 | |
| 614 | new->area_id = area_id; |
| 615 | new->format = format; |
| 616 | |
| 617 | return new; |
| 618 | } |
| 619 | |
| 620 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 621 | ospf_network_free (struct ospf *ospf, struct ospf_network *network) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 622 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 623 | ospf_area_check_free (ospf, network->area_id); |
| 624 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 625 | XFREE (MTYPE_OSPF_NETWORK, network); |
| 626 | } |
| 627 | |
| 628 | int |
| 629 | ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p, |
| 630 | struct in_addr area_id) |
| 631 | { |
| 632 | struct ospf_network *network; |
| 633 | struct ospf_area *area; |
| 634 | struct route_node *rn; |
| 635 | struct external_info *ei; |
paul | 147193a | 2003-04-19 00:31:59 +0000 | [diff] [blame] | 636 | int ret = OSPF_AREA_ID_FORMAT_ADDRESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 637 | |
| 638 | rn = route_node_get (ospf->networks, (struct prefix *)p); |
| 639 | if (rn->info) |
| 640 | { |
| 641 | /* There is already same network statement. */ |
| 642 | route_unlock_node (rn); |
| 643 | return 0; |
| 644 | } |
| 645 | |
| 646 | rn->info = network = ospf_network_new (area_id, ret); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 647 | area = ospf_area_get (ospf, area_id, ret); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 648 | |
| 649 | /* Run network config now. */ |
| 650 | ospf_network_run (ospf, (struct prefix *)p, area); |
| 651 | |
| 652 | /* Update connected redistribute. */ |
| 653 | if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT)) |
| 654 | if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)) |
| 655 | for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)); |
| 656 | rn; rn = route_next (rn)) |
| 657 | if ((ei = rn->info) != NULL) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 658 | if (ospf_external_info_find_lsa (ospf, &ei->p)) |
| 659 | if (!ospf_distribute_check_connected (ospf, ei)) |
| 660 | ospf_external_lsa_flush (ospf, ei->type, &ei->p, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 661 | ei->ifindex, ei->nexthop); |
| 662 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 663 | ospf_area_check_free (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 664 | |
| 665 | return 1; |
| 666 | } |
| 667 | |
| 668 | int |
| 669 | ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p, |
| 670 | struct in_addr area_id) |
| 671 | { |
| 672 | struct route_node *rn; |
| 673 | struct ospf_network *network; |
| 674 | struct external_info *ei; |
| 675 | |
| 676 | rn = route_node_lookup (ospf->networks, (struct prefix *)p); |
| 677 | if (rn == NULL) |
| 678 | return 0; |
| 679 | |
| 680 | network = rn->info; |
| 681 | if (!IPV4_ADDR_SAME (&area_id, &network->area_id)) |
| 682 | return 0; |
| 683 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 684 | ospf_network_free (ospf, rn->info); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 685 | rn->info = NULL; |
| 686 | route_unlock_node (rn); |
| 687 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 688 | ospf_if_update (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 689 | |
| 690 | /* Update connected redistribute. */ |
| 691 | if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT)) |
| 692 | if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)) |
| 693 | for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT)); |
| 694 | rn; rn = route_next (rn)) |
| 695 | if ((ei = rn->info) != NULL) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 696 | if (!ospf_external_info_find_lsa (ospf, &ei->p)) |
| 697 | if (ospf_distribute_check_connected (ospf, ei)) |
| 698 | ospf_external_lsa_originate (ospf, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 699 | |
| 700 | return 1; |
| 701 | } |
| 702 | |
paul | 570f759 | 2003-01-25 06:47:41 +0000 | [diff] [blame] | 703 | /* Check whether interface matches given network |
| 704 | * returns: 1, true. 0, false |
| 705 | */ |
| 706 | int |
| 707 | ospf_network_match_iface(struct connected *co, struct prefix *net) |
| 708 | { |
| 709 | /* Behaviour to match both Cisco where: |
| 710 | * iface address lies within network specified -> ospf |
| 711 | * and zebra 0.9[2ish-3]: |
| 712 | * PtP special case: network specified == iface peer addr -> ospf |
| 713 | */ |
gdt | 8f40e89 | 2003-12-05 14:01:43 +0000 | [diff] [blame] | 714 | |
| 715 | /* For PtP, match if peer address matches network address exactly. |
| 716 | * This can be addr/32 or addr/p for p < 32, but the addr must match |
| 717 | * exactly; this is not a test for falling within the prefix. This |
| 718 | * test is solely for compatibility with zebra. |
| 719 | */ |
| 720 | if (if_is_pointopoint (co->ifp) && |
| 721 | IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4))) |
| 722 | return 1; |
| 723 | |
| 724 | #if 0 |
| 725 | /* Decline to accept PtP if dst address does not match the |
| 726 | * prefix. (ifdefed out because this is a workaround, not the |
| 727 | * desired behavior.) */ |
| 728 | if (if_is_pointopoint (co->ifp) && |
| 729 | ! prefix_match (net, co->destination)) |
| 730 | return 0; |
| 731 | #endif |
| 732 | |
| 733 | /* If the address is within the prefix, accept. Note that this |
| 734 | * applies to PtP as well as other types. |
| 735 | */ |
| 736 | if (prefix_match (net, co->address)) |
| 737 | return 1; |
| 738 | |
| 739 | return 0; /* no match */ |
paul | 570f759 | 2003-01-25 06:47:41 +0000 | [diff] [blame] | 740 | } |
| 741 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 742 | void |
| 743 | ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area) |
| 744 | { |
| 745 | struct interface *ifp; |
| 746 | listnode node; |
| 747 | |
| 748 | /* Schedule Router ID Update. */ |
| 749 | if (ospf->router_id_static.s_addr == 0) |
| 750 | if (ospf->t_router_id_update == NULL) |
| 751 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 752 | OSPF_TIMER_ON (ospf->t_router_id_update, ospf_router_id_update_timer, |
| 753 | OSPF_ROUTER_ID_UPDATE_DELAY); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | /* Get target interface. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 757 | for (node = listhead (om->iflist); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 758 | { |
| 759 | listnode cn; |
| 760 | |
| 761 | if ((ifp = getdata (node)) == NULL) |
| 762 | continue; |
| 763 | |
| 764 | if (memcmp (ifp->name, "VLINK", 5) == 0) |
| 765 | continue; |
| 766 | |
| 767 | /* if interface prefix is match specified prefix, |
| 768 | then create socket and join multicast group. */ |
| 769 | for (cn = listhead (ifp->connected); cn; nextnode (cn)) |
| 770 | { |
| 771 | struct connected *co = getdata (cn); |
| 772 | struct prefix *addr; |
paul | 800dc10 | 2003-03-28 01:51:40 +0000 | [diff] [blame] | 773 | |
paul | e7b050c | 2003-04-07 06:38:02 +0000 | [diff] [blame] | 774 | if (CHECK_FLAG(co->flags,ZEBRA_IFA_SECONDARY)) |
| 775 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 776 | |
paul | 3738d8c | 2003-10-27 22:02:00 +0000 | [diff] [blame] | 777 | if (if_is_pointopoint (co->ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 778 | addr = co->destination; |
| 779 | else |
| 780 | addr = co->address; |
| 781 | |
paul | cb3f37d | 2003-02-18 23:26:37 +0000 | [diff] [blame] | 782 | if (p->family == co->address->family |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 783 | && ! ospf_if_is_configured (ospf, &(addr->u.prefix4)) |
paul | cb3f37d | 2003-02-18 23:26:37 +0000 | [diff] [blame] | 784 | && ospf_network_match_iface(co,p)) |
paul | 570f759 | 2003-01-25 06:47:41 +0000 | [diff] [blame] | 785 | { |
paul | 537d8ea | 2003-08-27 06:45:32 +0000 | [diff] [blame] | 786 | struct ospf_interface *oi; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 787 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 788 | oi = ospf_if_new (ospf, ifp, co->address); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 789 | oi->connected = co; |
| 790 | |
| 791 | oi->nbr_self->address = *oi->address; |
| 792 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 793 | oi->area = area; |
| 794 | |
| 795 | oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4); |
| 796 | oi->output_cost = ospf_if_get_output_cost (oi); |
| 797 | |
| 798 | if (area->external_routing != OSPF_AREA_DEFAULT) |
| 799 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 800 | oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority); |
| 801 | |
| 802 | /* Add pseudo neighbor. */ |
| 803 | ospf_nbr_add_self (oi); |
| 804 | |
| 805 | /* Make sure pseudo neighbor's router_id. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 806 | oi->nbr_self->router_id = ospf->router_id; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 807 | oi->nbr_self->src = oi->address->u.prefix4; |
| 808 | |
| 809 | /* Relate ospf interface to ospf instance. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 810 | oi->ospf = ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 811 | |
| 812 | /* update network type as interface flag */ |
| 813 | /* If network type is specified previously, |
| 814 | skip network type setting. */ |
| 815 | oi->type = IF_DEF_PARAMS (ifp)->type; |
| 816 | |
| 817 | /* Set area flag. */ |
| 818 | switch (area->external_routing) |
| 819 | { |
| 820 | case OSPF_AREA_DEFAULT: |
| 821 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 822 | break; |
| 823 | case OSPF_AREA_STUB: |
| 824 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 825 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 826 | case OSPF_AREA_NSSA: |
| 827 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 828 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
| 829 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | ospf_area_add_if (oi->area, oi); |
| 833 | |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 834 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 835 | ospf_if_up (oi); |
| 836 | |
| 837 | break; |
| 838 | } |
| 839 | } |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | void |
| 844 | ospf_ls_upd_queue_empty (struct ospf_interface *oi) |
| 845 | { |
| 846 | struct route_node *rn; |
| 847 | listnode node; |
| 848 | list lst; |
| 849 | struct ospf_lsa *lsa; |
| 850 | |
| 851 | /* empty ls update queue */ |
| 852 | for (rn = route_top (oi->ls_upd_queue); rn; |
| 853 | rn = route_next (rn)) |
| 854 | if ((lst = (list) rn->info)) |
| 855 | { |
| 856 | for (node = listhead (lst); node; nextnode (node)) |
| 857 | if ((lsa = getdata (node))) |
| 858 | ospf_lsa_unlock (lsa); |
| 859 | list_free (lst); |
| 860 | rn->info = NULL; |
| 861 | } |
| 862 | |
| 863 | /* remove update event */ |
| 864 | if (oi->t_ls_upd_event) |
| 865 | { |
| 866 | thread_cancel (oi->t_ls_upd_event); |
| 867 | oi->t_ls_upd_event = NULL; |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 872 | ospf_if_update (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 873 | { |
| 874 | struct route_node *rn; |
| 875 | listnode node; |
| 876 | listnode next; |
| 877 | struct ospf_network *network; |
| 878 | struct ospf_area *area; |
| 879 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 880 | if (ospf != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 881 | { |
| 882 | /* Update Router ID scheduled. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 883 | if (ospf->router_id_static.s_addr == 0) |
| 884 | if (ospf->t_router_id_update == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 885 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 886 | OSPF_TIMER_ON (ospf->t_router_id_update, |
| 887 | ospf_router_id_update_timer, |
| 888 | OSPF_ROUTER_ID_UPDATE_DELAY); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | /* Find interfaces that not configured already. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 892 | for (node = listhead (ospf->oiflist); node; node = next) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 893 | { |
| 894 | int found = 0; |
| 895 | struct ospf_interface *oi = getdata (node); |
| 896 | struct connected *co = oi->connected; |
| 897 | |
| 898 | next = nextnode (node); |
| 899 | |
| 900 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
| 901 | continue; |
| 902 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 903 | for (rn = route_top (ospf->networks); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 904 | { |
| 905 | if (rn->info == NULL) |
| 906 | continue; |
| 907 | |
paul | 570f759 | 2003-01-25 06:47:41 +0000 | [diff] [blame] | 908 | if (ospf_network_match_iface(co,&rn->p)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 909 | { |
| 910 | found = 1; |
| 911 | route_unlock_node (rn); |
| 912 | break; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | if (found == 0) |
| 917 | ospf_if_free (oi); |
| 918 | } |
| 919 | |
| 920 | /* Run each interface. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 921 | for (rn = route_top (ospf->networks); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 922 | if (rn->info != NULL) |
| 923 | { |
| 924 | network = (struct ospf_network *) rn->info; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 925 | area = ospf_area_get (ospf, network->area_id, network->format); |
| 926 | ospf_network_run (ospf, &rn->p, area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | } |
| 930 | |
| 931 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 932 | ospf_remove_vls_through_area (struct ospf *ospf, struct ospf_area *area) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 933 | { |
| 934 | listnode node, next; |
| 935 | struct ospf_vl_data *vl_data; |
| 936 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 937 | for (node = listhead (ospf->vlinks); node; node = next) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 938 | { |
| 939 | next = node->next; |
| 940 | if ((vl_data = getdata (node)) != NULL) |
| 941 | if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 942 | ospf_vl_delete (ospf, vl_data); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 943 | } |
| 944 | } |
| 945 | |
| 946 | |
| 947 | struct message ospf_area_type_msg[] = |
| 948 | { |
| 949 | { OSPF_AREA_DEFAULT, "Default" }, |
| 950 | { OSPF_AREA_STUB, "Stub" }, |
| 951 | { OSPF_AREA_NSSA, "NSSA" }, |
| 952 | }; |
| 953 | int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX; |
| 954 | |
| 955 | void |
| 956 | ospf_area_type_set (struct ospf_area *area, int type) |
| 957 | { |
| 958 | listnode node; |
| 959 | struct ospf_interface *oi; |
| 960 | |
| 961 | if (area->external_routing == type) |
| 962 | { |
| 963 | if (IS_DEBUG_OSPF_EVENT) |
| 964 | zlog_info ("Area[%s]: Types are the same, ignored.", |
| 965 | inet_ntoa (area->area_id)); |
| 966 | return; |
| 967 | } |
| 968 | |
| 969 | area->external_routing = type; |
| 970 | |
| 971 | if (IS_DEBUG_OSPF_EVENT) |
| 972 | zlog_info ("Area[%s]: Configured as %s", inet_ntoa (area->area_id), |
| 973 | LOOKUP (ospf_area_type_msg, type)); |
| 974 | |
| 975 | switch (area->external_routing) |
| 976 | { |
| 977 | case OSPF_AREA_DEFAULT: |
| 978 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 979 | if ((oi = getdata (node)) != NULL) |
| 980 | if (oi->nbr_self != NULL) |
hasso | 8585d4e | 2004-04-20 17:25:12 +0000 | [diff] [blame] | 981 | { |
hasso | 8585d4e | 2004-04-20 17:25:12 +0000 | [diff] [blame] | 982 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
hasso | 8585d4e | 2004-04-20 17:25:12 +0000 | [diff] [blame] | 983 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 984 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 985 | break; |
| 986 | case OSPF_AREA_STUB: |
| 987 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 988 | if ((oi = getdata (node)) != NULL) |
| 989 | if (oi->nbr_self != NULL) |
| 990 | { |
| 991 | if (IS_DEBUG_OSPF_EVENT) |
| 992 | zlog_info ("setting options on %s accordingly", IF_NAME (oi)); |
hasso | 8585d4e | 2004-04-20 17:25:12 +0000 | [diff] [blame] | 993 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 994 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 995 | if (IS_DEBUG_OSPF_EVENT) |
| 996 | zlog_info ("options set on %s: %x", |
| 997 | IF_NAME (oi), OPTIONS (oi)); |
| 998 | } |
| 999 | break; |
| 1000 | case OSPF_AREA_NSSA: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1001 | for (node = listhead (area->oiflist); node; nextnode (node)) |
| 1002 | if ((oi = getdata (node)) != NULL) |
| 1003 | if (oi->nbr_self != NULL) |
| 1004 | { |
| 1005 | zlog_info ("setting nssa options on %s accordingly", IF_NAME (oi)); |
| 1006 | UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); |
| 1007 | SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); |
| 1008 | zlog_info ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi)); |
| 1009 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1010 | break; |
| 1011 | default: |
| 1012 | break; |
| 1013 | } |
| 1014 | |
| 1015 | ospf_router_lsa_timer_add (area); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1016 | ospf_schedule_abr_task (area->ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1020 | ospf_area_shortcut_set (struct ospf *ospf, struct ospf_area *area, int mode) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1021 | { |
| 1022 | if (area->shortcut_configured == mode) |
| 1023 | return 0; |
| 1024 | |
| 1025 | area->shortcut_configured = mode; |
| 1026 | ospf_router_lsa_timer_add (area); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1027 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1028 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1029 | ospf_area_check_free (ospf, area->area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1030 | |
| 1031 | return 1; |
| 1032 | } |
| 1033 | |
| 1034 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1035 | ospf_area_shortcut_unset (struct ospf *ospf, struct ospf_area *area) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1036 | { |
| 1037 | area->shortcut_configured = OSPF_SHORTCUT_DEFAULT; |
| 1038 | ospf_router_lsa_timer_add (area); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1039 | ospf_area_check_free (ospf, area->area_id); |
| 1040 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1041 | |
| 1042 | return 1; |
| 1043 | } |
| 1044 | |
| 1045 | int |
| 1046 | ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area) |
| 1047 | { |
| 1048 | struct ospf_vl_data *vl; |
| 1049 | listnode node; |
| 1050 | int count = 0; |
| 1051 | |
| 1052 | for (node = listhead (ospf->vlinks); node; nextnode (node)) |
| 1053 | { |
| 1054 | vl = getdata (node); |
| 1055 | if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id)) |
| 1056 | count++; |
| 1057 | } |
| 1058 | |
| 1059 | return count; |
| 1060 | } |
| 1061 | |
| 1062 | int |
| 1063 | ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id) |
| 1064 | { |
| 1065 | struct ospf_area *area; |
paul | 147193a | 2003-04-19 00:31:59 +0000 | [diff] [blame] | 1066 | int format = OSPF_AREA_ID_FORMAT_ADDRESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1067 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1068 | area = ospf_area_get (ospf, area_id, format); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1069 | if (ospf_area_vlink_count (ospf, area)) |
| 1070 | return 0; |
| 1071 | |
| 1072 | if (area->external_routing != OSPF_AREA_STUB) |
| 1073 | ospf_area_type_set (area, OSPF_AREA_STUB); |
| 1074 | |
| 1075 | return 1; |
| 1076 | } |
| 1077 | |
| 1078 | int |
| 1079 | ospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id) |
| 1080 | { |
| 1081 | struct ospf_area *area; |
| 1082 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1083 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1084 | if (area == NULL) |
| 1085 | return 1; |
| 1086 | |
| 1087 | if (area->external_routing == OSPF_AREA_STUB) |
| 1088 | ospf_area_type_set (area, OSPF_AREA_DEFAULT); |
| 1089 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1090 | ospf_area_check_free (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1091 | |
| 1092 | return 1; |
| 1093 | } |
| 1094 | |
| 1095 | int |
| 1096 | ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id) |
| 1097 | { |
| 1098 | struct ospf_area *area; |
paul | 147193a | 2003-04-19 00:31:59 +0000 | [diff] [blame] | 1099 | int format = OSPF_AREA_ID_FORMAT_ADDRESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1100 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1101 | area = ospf_area_get (ospf, area_id, format); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1102 | area->no_summary = 1; |
| 1103 | |
| 1104 | return 1; |
| 1105 | } |
| 1106 | |
| 1107 | int |
| 1108 | ospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id) |
| 1109 | { |
| 1110 | struct ospf_area *area; |
| 1111 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1112 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1113 | if (area == NULL) |
| 1114 | return 0; |
| 1115 | |
| 1116 | area->no_summary = 0; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1117 | ospf_area_check_free (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1118 | |
| 1119 | return 1; |
| 1120 | } |
| 1121 | |
| 1122 | int |
| 1123 | ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id) |
| 1124 | { |
| 1125 | struct ospf_area *area; |
paul | 147193a | 2003-04-19 00:31:59 +0000 | [diff] [blame] | 1126 | int format = OSPF_AREA_ID_FORMAT_ADDRESS; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1127 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1128 | area = ospf_area_get (ospf, area_id, format); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1129 | if (ospf_area_vlink_count (ospf, area)) |
| 1130 | return 0; |
| 1131 | |
| 1132 | if (area->external_routing != OSPF_AREA_NSSA) |
| 1133 | { |
| 1134 | ospf_area_type_set (area, OSPF_AREA_NSSA); |
| 1135 | ospf->anyNSSA++; |
| 1136 | } |
| 1137 | |
paul | 084c784 | 2003-06-22 08:35:18 +0000 | [diff] [blame] | 1138 | /* set NSSA area defaults */ |
| 1139 | area->no_summary = 0; |
| 1140 | area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE; |
paul | d4a53d5 | 2003-07-12 21:30:57 +0000 | [diff] [blame] | 1141 | area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED; |
paul | 084c784 | 2003-06-22 08:35:18 +0000 | [diff] [blame] | 1142 | area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT; |
| 1143 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1144 | return 1; |
| 1145 | } |
| 1146 | |
| 1147 | int |
| 1148 | ospf_area_nssa_unset (struct ospf *ospf, struct in_addr area_id) |
| 1149 | { |
| 1150 | struct ospf_area *area; |
| 1151 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1152 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1153 | if (area == NULL) |
| 1154 | return 0; |
| 1155 | |
| 1156 | if (area->external_routing == OSPF_AREA_NSSA) |
| 1157 | { |
| 1158 | ospf->anyNSSA--; |
| 1159 | ospf_area_type_set (area, OSPF_AREA_DEFAULT); |
| 1160 | } |
| 1161 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1162 | ospf_area_check_free (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1163 | |
| 1164 | return 1; |
| 1165 | } |
| 1166 | |
| 1167 | int |
| 1168 | ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id, |
| 1169 | int role) |
| 1170 | { |
| 1171 | struct ospf_area *area; |
| 1172 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1173 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1174 | if (area == NULL) |
| 1175 | return 0; |
| 1176 | |
paul | 084c784 | 2003-06-22 08:35:18 +0000 | [diff] [blame] | 1177 | area->NSSATranslatorRole = role; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1178 | |
| 1179 | return 1; |
| 1180 | } |
| 1181 | |
| 1182 | int |
| 1183 | ospf_area_nssa_translator_role_unset (struct ospf *ospf, |
| 1184 | struct in_addr area_id) |
| 1185 | { |
| 1186 | struct ospf_area *area; |
| 1187 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1188 | area = ospf_area_lookup_by_area_id (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1189 | if (area == NULL) |
| 1190 | return 0; |
| 1191 | |
paul | 084c784 | 2003-06-22 08:35:18 +0000 | [diff] [blame] | 1192 | area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1193 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1194 | ospf_area_check_free (ospf, area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1195 | |
| 1196 | return 1; |
| 1197 | } |
| 1198 | |
| 1199 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1200 | ospf_area_export_list_set (struct ospf *ospf, |
| 1201 | struct ospf_area *area, char *list_name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1202 | { |
| 1203 | struct access_list *list; |
| 1204 | list = access_list_lookup (AFI_IP, list_name); |
| 1205 | |
| 1206 | EXPORT_LIST (area) = list; |
| 1207 | |
| 1208 | if (EXPORT_NAME (area)) |
| 1209 | free (EXPORT_NAME (area)); |
| 1210 | |
| 1211 | EXPORT_NAME (area) = strdup (list_name); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1212 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1213 | |
| 1214 | return 1; |
| 1215 | } |
| 1216 | |
| 1217 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1218 | ospf_area_export_list_unset (struct ospf *ospf, struct ospf_area * area) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1219 | { |
| 1220 | |
| 1221 | EXPORT_LIST (area) = 0; |
| 1222 | |
| 1223 | if (EXPORT_NAME (area)) |
| 1224 | free (EXPORT_NAME (area)); |
| 1225 | |
| 1226 | EXPORT_NAME (area) = NULL; |
| 1227 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1228 | ospf_area_check_free (ospf, area->area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1229 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1230 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1231 | |
| 1232 | return 1; |
| 1233 | } |
| 1234 | |
| 1235 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1236 | ospf_area_import_list_set (struct ospf *ospf, |
| 1237 | struct ospf_area *area, char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1238 | { |
| 1239 | struct access_list *list; |
| 1240 | list = access_list_lookup (AFI_IP, name); |
| 1241 | |
| 1242 | IMPORT_LIST (area) = list; |
| 1243 | |
| 1244 | if (IMPORT_NAME (area)) |
| 1245 | free (IMPORT_NAME (area)); |
| 1246 | |
| 1247 | IMPORT_NAME (area) = strdup (name); |
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 |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1254 | ospf_area_import_list_unset (struct ospf *ospf, struct ospf_area * area) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1255 | { |
| 1256 | IMPORT_LIST (area) = 0; |
| 1257 | |
| 1258 | if (IMPORT_NAME (area)) |
| 1259 | free (IMPORT_NAME (area)); |
| 1260 | |
| 1261 | IMPORT_NAME (area) = NULL; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1262 | ospf_area_check_free (ospf, area->area_id); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1263 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1264 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1265 | |
| 1266 | return 1; |
| 1267 | } |
| 1268 | |
| 1269 | int |
| 1270 | ospf_timers_spf_set (struct ospf *ospf, u_int32_t delay, u_int32_t hold) |
| 1271 | { |
| 1272 | ospf->spf_delay = delay; |
| 1273 | ospf->spf_holdtime = hold; |
| 1274 | |
| 1275 | return 1; |
| 1276 | } |
| 1277 | |
| 1278 | int |
| 1279 | ospf_timers_spf_unset (struct ospf *ospf) |
| 1280 | { |
| 1281 | ospf->spf_delay = OSPF_SPF_DELAY_DEFAULT; |
| 1282 | ospf->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT; |
| 1283 | |
| 1284 | return 1; |
| 1285 | } |
| 1286 | |
| 1287 | int |
| 1288 | ospf_timers_refresh_set (struct ospf *ospf, int interval) |
| 1289 | { |
| 1290 | int time_left; |
| 1291 | |
| 1292 | if (ospf->lsa_refresh_interval == interval) |
| 1293 | return 1; |
| 1294 | |
| 1295 | time_left = ospf->lsa_refresh_interval - |
| 1296 | (time (NULL) - ospf->lsa_refresher_started); |
| 1297 | |
| 1298 | if (time_left > interval) |
| 1299 | { |
| 1300 | OSPF_TIMER_OFF (ospf->t_lsa_refresher); |
| 1301 | ospf->t_lsa_refresher = |
| 1302 | thread_add_timer (master, ospf_lsa_refresh_walker, ospf, interval); |
| 1303 | } |
| 1304 | ospf->lsa_refresh_interval = interval; |
| 1305 | |
| 1306 | return 1; |
| 1307 | } |
| 1308 | |
| 1309 | int |
| 1310 | ospf_timers_refresh_unset (struct ospf *ospf) |
| 1311 | { |
| 1312 | int time_left; |
| 1313 | |
| 1314 | time_left = ospf->lsa_refresh_interval - |
| 1315 | (time (NULL) - ospf->lsa_refresher_started); |
| 1316 | |
| 1317 | if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
| 1318 | { |
| 1319 | OSPF_TIMER_OFF (ospf->t_lsa_refresher); |
| 1320 | ospf->t_lsa_refresher = |
| 1321 | thread_add_timer (master, ospf_lsa_refresh_walker, ospf, |
| 1322 | OSPF_LSA_REFRESH_INTERVAL_DEFAULT); |
| 1323 | } |
| 1324 | |
| 1325 | ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT; |
| 1326 | |
| 1327 | return 1; |
| 1328 | } |
| 1329 | |
| 1330 | |
| 1331 | struct ospf_nbr_nbma * |
| 1332 | ospf_nbr_nbma_new () |
| 1333 | { |
| 1334 | struct ospf_nbr_nbma *nbr_nbma; |
| 1335 | |
| 1336 | nbr_nbma = XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC, |
| 1337 | sizeof (struct ospf_nbr_nbma)); |
| 1338 | memset (nbr_nbma, 0, sizeof (struct ospf_nbr_nbma)); |
| 1339 | |
| 1340 | nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; |
| 1341 | nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT; |
| 1342 | |
| 1343 | return nbr_nbma; |
| 1344 | } |
| 1345 | |
| 1346 | void |
| 1347 | ospf_nbr_nbma_free (struct ospf_nbr_nbma *nbr_nbma) |
| 1348 | { |
| 1349 | XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma); |
| 1350 | } |
| 1351 | |
| 1352 | void |
| 1353 | ospf_nbr_nbma_delete (struct ospf *ospf, struct ospf_nbr_nbma *nbr_nbma) |
| 1354 | { |
| 1355 | struct route_node *rn; |
| 1356 | struct prefix_ipv4 p; |
| 1357 | |
| 1358 | p.family = AF_INET; |
| 1359 | p.prefix = nbr_nbma->addr; |
| 1360 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1361 | |
| 1362 | rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p); |
| 1363 | if (rn) |
| 1364 | { |
| 1365 | ospf_nbr_nbma_free (rn->info); |
| 1366 | rn->info = NULL; |
| 1367 | route_unlock_node (rn); |
| 1368 | route_unlock_node (rn); |
| 1369 | } |
| 1370 | } |
| 1371 | |
| 1372 | void |
| 1373 | ospf_nbr_nbma_down (struct ospf_nbr_nbma *nbr_nbma) |
| 1374 | { |
| 1375 | OSPF_TIMER_OFF (nbr_nbma->t_poll); |
| 1376 | |
| 1377 | if (nbr_nbma->nbr) |
| 1378 | { |
| 1379 | nbr_nbma->nbr->nbr_nbma = NULL; |
| 1380 | OSPF_NSM_EVENT_EXECUTE (nbr_nbma->nbr, NSM_KillNbr); |
| 1381 | } |
| 1382 | |
| 1383 | if (nbr_nbma->oi) |
| 1384 | listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma); |
| 1385 | } |
| 1386 | |
| 1387 | void |
| 1388 | ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma, |
| 1389 | struct ospf_interface *oi) |
| 1390 | { |
| 1391 | struct ospf_neighbor *nbr; |
| 1392 | struct route_node *rn; |
| 1393 | struct prefix p; |
| 1394 | |
| 1395 | if (oi->type != OSPF_IFTYPE_NBMA) |
| 1396 | return; |
| 1397 | |
| 1398 | if (nbr_nbma->nbr != NULL) |
| 1399 | return; |
| 1400 | |
| 1401 | if (IPV4_ADDR_SAME (&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr)) |
| 1402 | return; |
| 1403 | |
| 1404 | nbr_nbma->oi = oi; |
| 1405 | listnode_add (oi->nbr_nbma, nbr_nbma); |
| 1406 | |
| 1407 | /* Get neighbor information from table. */ |
| 1408 | p.family = AF_INET; |
| 1409 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1410 | p.u.prefix4 = nbr_nbma->addr; |
| 1411 | |
| 1412 | rn = route_node_get (oi->nbrs, (struct prefix *)&p); |
| 1413 | if (rn->info) |
| 1414 | { |
| 1415 | nbr = rn->info; |
| 1416 | nbr->nbr_nbma = nbr_nbma; |
| 1417 | nbr_nbma->nbr = nbr; |
| 1418 | |
| 1419 | route_unlock_node (rn); |
| 1420 | } |
| 1421 | else |
| 1422 | { |
| 1423 | nbr = rn->info = ospf_nbr_new (oi); |
| 1424 | nbr->state = NSM_Down; |
| 1425 | nbr->src = nbr_nbma->addr; |
| 1426 | nbr->nbr_nbma = nbr_nbma; |
| 1427 | nbr->priority = nbr_nbma->priority; |
| 1428 | nbr->address = p; |
| 1429 | |
| 1430 | nbr_nbma->nbr = nbr; |
| 1431 | |
| 1432 | OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start); |
| 1433 | } |
| 1434 | } |
| 1435 | |
| 1436 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1437 | ospf_nbr_nbma_if_update (struct ospf *ospf, struct ospf_interface *oi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1438 | { |
| 1439 | struct ospf_nbr_nbma *nbr_nbma; |
| 1440 | struct route_node *rn; |
| 1441 | struct prefix_ipv4 p; |
| 1442 | |
| 1443 | if (oi->type != OSPF_IFTYPE_NBMA) |
| 1444 | return; |
| 1445 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1446 | for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1447 | if ((nbr_nbma = rn->info)) |
| 1448 | if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL) |
| 1449 | { |
| 1450 | p.family = AF_INET; |
| 1451 | p.prefix = nbr_nbma->addr; |
| 1452 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1453 | |
| 1454 | if (prefix_match (oi->address, (struct prefix *)&p)) |
| 1455 | ospf_nbr_nbma_add (nbr_nbma, oi); |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | struct ospf_nbr_nbma * |
| 1460 | ospf_nbr_nbma_lookup (struct ospf *ospf, struct in_addr nbr_addr) |
| 1461 | { |
| 1462 | struct route_node *rn; |
| 1463 | struct prefix_ipv4 p; |
| 1464 | |
| 1465 | p.family = AF_INET; |
| 1466 | p.prefix = nbr_addr; |
| 1467 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1468 | |
| 1469 | rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p); |
| 1470 | if (rn) |
| 1471 | { |
| 1472 | route_unlock_node (rn); |
| 1473 | return rn->info; |
| 1474 | } |
| 1475 | return NULL; |
| 1476 | } |
| 1477 | |
| 1478 | struct ospf_nbr_nbma * |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1479 | 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] | 1480 | { |
| 1481 | #if 0 |
| 1482 | struct ospf_nbr_nbma *nbr_nbma; |
| 1483 | listnode node; |
| 1484 | #endif |
| 1485 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1486 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1487 | return NULL; |
| 1488 | |
| 1489 | #if 0 |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1490 | for (node = listhead (ospf->nbr_nbma); node; nextnode (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1491 | { |
| 1492 | nbr_nbma = getdata (node); |
| 1493 | |
| 1494 | if (first) |
| 1495 | { |
| 1496 | *addr = nbr_nbma->addr; |
| 1497 | return nbr_nbma; |
| 1498 | } |
| 1499 | else if (ntohl (nbr_nbma->addr.s_addr) > ntohl (addr->s_addr)) |
| 1500 | { |
| 1501 | *addr = nbr_nbma->addr; |
| 1502 | return nbr_nbma; |
| 1503 | } |
| 1504 | } |
| 1505 | #endif |
| 1506 | return NULL; |
| 1507 | } |
| 1508 | |
| 1509 | int |
| 1510 | ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr) |
| 1511 | { |
| 1512 | struct ospf_nbr_nbma *nbr_nbma; |
| 1513 | struct ospf_interface *oi; |
| 1514 | struct prefix_ipv4 p; |
| 1515 | struct route_node *rn; |
| 1516 | listnode node; |
| 1517 | |
| 1518 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1519 | if (nbr_nbma) |
| 1520 | return 0; |
| 1521 | |
| 1522 | nbr_nbma = ospf_nbr_nbma_new (); |
| 1523 | nbr_nbma->addr = nbr_addr; |
| 1524 | |
| 1525 | p.family = AF_INET; |
| 1526 | p.prefix = nbr_addr; |
| 1527 | p.prefixlen = IPV4_MAX_BITLEN; |
| 1528 | |
| 1529 | rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p); |
| 1530 | rn->info = nbr_nbma; |
| 1531 | |
| 1532 | for (node = listhead (ospf->oiflist); node; nextnode (node)) |
| 1533 | { |
| 1534 | oi = getdata (node); |
| 1535 | if (oi->type == OSPF_IFTYPE_NBMA) |
| 1536 | if (prefix_match (oi->address, (struct prefix *)&p)) |
| 1537 | { |
| 1538 | ospf_nbr_nbma_add (nbr_nbma, oi); |
| 1539 | break; |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | return 1; |
| 1544 | } |
| 1545 | |
| 1546 | int |
| 1547 | ospf_nbr_nbma_unset (struct ospf *ospf, struct in_addr nbr_addr) |
| 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 | ospf_nbr_nbma_down (nbr_nbma); |
| 1556 | ospf_nbr_nbma_delete (ospf, nbr_nbma); |
| 1557 | |
| 1558 | return 1; |
| 1559 | } |
| 1560 | |
| 1561 | int |
| 1562 | ospf_nbr_nbma_priority_set (struct ospf *ospf, struct in_addr nbr_addr, |
| 1563 | u_char priority) |
| 1564 | { |
| 1565 | struct ospf_nbr_nbma *nbr_nbma; |
| 1566 | |
| 1567 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1568 | if (nbr_nbma == NULL) |
| 1569 | return 0; |
| 1570 | |
| 1571 | if (nbr_nbma->priority != priority) |
| 1572 | nbr_nbma->priority = priority; |
| 1573 | |
| 1574 | return 1; |
| 1575 | } |
| 1576 | |
| 1577 | int |
| 1578 | ospf_nbr_nbma_priority_unset (struct ospf *ospf, struct in_addr nbr_addr) |
| 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 != OSPF_NEIGHBOR_PRIORITY_DEFAULT) |
| 1587 | nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; |
| 1588 | |
| 1589 | return 1; |
| 1590 | } |
| 1591 | |
| 1592 | int |
| 1593 | ospf_nbr_nbma_poll_interval_set (struct ospf *ospf, struct in_addr nbr_addr, |
| 1594 | int interval) |
| 1595 | { |
| 1596 | struct ospf_nbr_nbma *nbr_nbma; |
| 1597 | |
| 1598 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr); |
| 1599 | if (nbr_nbma == NULL) |
| 1600 | return 0; |
| 1601 | |
| 1602 | if (nbr_nbma->v_poll != interval) |
| 1603 | { |
| 1604 | nbr_nbma->v_poll = interval; |
| 1605 | if (nbr_nbma->oi && ospf_if_is_up (nbr_nbma->oi)) |
| 1606 | { |
| 1607 | OSPF_TIMER_OFF (nbr_nbma->t_poll); |
| 1608 | OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer, |
| 1609 | nbr_nbma->v_poll); |
| 1610 | } |
| 1611 | } |
| 1612 | |
| 1613 | return 1; |
| 1614 | } |
| 1615 | |
| 1616 | int |
| 1617 | ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr) |
| 1618 | { |
| 1619 | struct ospf_nbr_nbma *nbr_nbma; |
| 1620 | |
| 1621 | nbr_nbma = ospf_nbr_nbma_lookup (ospf, addr); |
| 1622 | if (nbr_nbma == NULL) |
| 1623 | return 0; |
| 1624 | |
| 1625 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
| 1626 | nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT; |
| 1627 | |
| 1628 | return 1; |
| 1629 | } |
| 1630 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1631 | void |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1632 | ospf_master_init () |
| 1633 | { |
| 1634 | memset (&ospf_master, 0, sizeof (struct ospf_master)); |
| 1635 | |
| 1636 | om = &ospf_master; |
| 1637 | om->ospf = list_new (); |
| 1638 | om->master = thread_master_create (); |
| 1639 | om->start_time = time (NULL); |
| 1640 | } |