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