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