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