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