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