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