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