blob: d73d78362489841c460024e749bc95b7993e95e6 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* OSPF version 2 daemon program.
2 Copyright (C) 1999, 2000 Toshiaki Takada
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "thread.h"
24#include "vty.h"
25#include "command.h"
26#include "linklist.h"
27#include "prefix.h"
28#include "table.h"
29#include "if.h"
30#include "memory.h"
31#include "stream.h"
32#include "log.h"
33#include "sockunion.h" /* for inet_aton () */
34#include "zclient.h"
35#include "plist.h"
36
37#include "ospfd/ospfd.h"
38#include "ospfd/ospf_network.h"
39#include "ospfd/ospf_interface.h"
40#include "ospfd/ospf_ism.h"
41#include "ospfd/ospf_asbr.h"
42#include "ospfd/ospf_lsa.h"
43#include "ospfd/ospf_lsdb.h"
44#include "ospfd/ospf_neighbor.h"
45#include "ospfd/ospf_nsm.h"
46#include "ospfd/ospf_spf.h"
47#include "ospfd/ospf_packet.h"
48#include "ospfd/ospf_dump.h"
49#include "ospfd/ospf_zebra.h"
50#include "ospfd/ospf_abr.h"
51#include "ospfd/ospf_flood.h"
52#include "ospfd/ospf_route.h"
53#include "ospfd/ospf_ase.h"
54
paul020709f2003-04-04 02:44:16 +000055
pauledd7c242003-06-04 13:59:38 +000056
paul020709f2003-04-04 02:44:16 +000057/* OSPF process wide configuration. */
58static struct ospf_master ospf_master;
59
60/* OSPF process wide configuration pointer to export. */
61struct ospf_master *om;
paul718e3742002-12-13 20:15:29 +000062
63extern struct zclient *zclient;
hasso18a6dce2004-10-03 18:18:34 +000064extern struct in_addr router_id_zebra;
paul718e3742002-12-13 20:15:29 +000065
66
paul88d6cf32005-10-29 12:50:09 +000067static void ospf_remove_vls_through_area (struct ospf *, struct ospf_area *);
68static void ospf_network_free (struct ospf *, struct ospf_network *);
69static void ospf_area_free (struct ospf_area *);
70static void ospf_network_run (struct ospf *, struct prefix *, struct ospf_area *);
71static void ospf_finish_final (struct ospf *);
paul718e3742002-12-13 20:15:29 +000072
paul718e3742002-12-13 20:15:29 +000073#define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
paul88d6cf32005-10-29 12:50:09 +000074
paul718e3742002-12-13 20:15:29 +000075void
paul68980082003-03-25 05:07:42 +000076ospf_router_id_update (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +000077{
paul718e3742002-12-13 20:15:29 +000078 struct in_addr router_id, router_id_old;
paul1eb8ef22005-04-07 07:30:20 +000079 struct ospf_interface *oi;
hasso52dc7ee2004-09-23 19:18:23 +000080 struct listnode *node;
paul718e3742002-12-13 20:15:29 +000081
82 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +000083 zlog_debug ("Router-ID[OLD:%s]: Update", inet_ntoa (ospf->router_id));
paul718e3742002-12-13 20:15:29 +000084
paul68980082003-03-25 05:07:42 +000085 router_id_old = ospf->router_id;
paul718e3742002-12-13 20:15:29 +000086
paul68980082003-03-25 05:07:42 +000087 if (ospf->router_id_static.s_addr != 0)
88 router_id = ospf->router_id_static;
paul718e3742002-12-13 20:15:29 +000089 else
hasso18a6dce2004-10-03 18:18:34 +000090 router_id = router_id_zebra;
paul718e3742002-12-13 20:15:29 +000091
paul68980082003-03-25 05:07:42 +000092 ospf->router_id = router_id;
paul718e3742002-12-13 20:15:29 +000093
94 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +000095 zlog_debug ("Router-ID[NEW:%s]: Update", inet_ntoa (ospf->router_id));
paul718e3742002-12-13 20:15:29 +000096
97 if (!IPV4_ADDR_SAME (&router_id_old, &router_id))
98 {
paul1eb8ef22005-04-07 07:30:20 +000099 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
100 /* Update self-neighbor's router_id. */
101 oi->nbr_self->router_id = router_id;
paul718e3742002-12-13 20:15:29 +0000102
103 /* If AS-external-LSA is queued, then flush those LSAs. */
paul68980082003-03-25 05:07:42 +0000104 if (router_id_old.s_addr == 0 && ospf->external_origin)
paul718e3742002-12-13 20:15:29 +0000105 {
106 int type;
107 /* Originate each redistributed external route. */
108 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
paul68980082003-03-25 05:07:42 +0000109 if (ospf->external_origin & (1 << type))
paul718e3742002-12-13 20:15:29 +0000110 thread_add_event (master, ospf_external_lsa_originate_timer,
paul68980082003-03-25 05:07:42 +0000111 ospf, type);
paul718e3742002-12-13 20:15:29 +0000112 /* Originate Deafult. */
paul68980082003-03-25 05:07:42 +0000113 if (ospf->external_origin & (1 << ZEBRA_ROUTE_MAX))
paul718e3742002-12-13 20:15:29 +0000114 thread_add_event (master, ospf_default_originate_timer,
paul68980082003-03-25 05:07:42 +0000115 &ospf->default_originate, 0);
paul718e3742002-12-13 20:15:29 +0000116
paul68980082003-03-25 05:07:42 +0000117 ospf->external_origin = 0;
paul718e3742002-12-13 20:15:29 +0000118 }
119
paul68980082003-03-25 05:07:42 +0000120 OSPF_TIMER_ON (ospf->t_router_lsa_update,
paul718e3742002-12-13 20:15:29 +0000121 ospf_router_lsa_update_timer, OSPF_LSA_UPDATE_DELAY);
paulb29800a2005-11-20 14:50:45 +0000122
123 /* update ospf_interface's */
124 ospf_if_update (ospf);
paul718e3742002-12-13 20:15:29 +0000125 }
126}
paul718e3742002-12-13 20:15:29 +0000127
128/* For OSPF area sort by area id. */
paul4dadc292005-05-06 21:37:42 +0000129static int
paul718e3742002-12-13 20:15:29 +0000130ospf_area_id_cmp (struct ospf_area *a1, struct ospf_area *a2)
131{
132 if (ntohl (a1->area_id.s_addr) > ntohl (a2->area_id.s_addr))
133 return 1;
134 if (ntohl (a1->area_id.s_addr) < ntohl (a2->area_id.s_addr))
135 return -1;
136 return 0;
137}
138
139/* Allocate new ospf structure. */
paul4dadc292005-05-06 21:37:42 +0000140static struct ospf *
141ospf_new (void)
paul718e3742002-12-13 20:15:29 +0000142{
143 int i;
144
145 struct ospf *new = XCALLOC (MTYPE_OSPF_TOP, sizeof (struct ospf));
146
147 new->router_id.s_addr = htonl (0);
148 new->router_id_static.s_addr = htonl (0);
149
pauld57834f2005-07-12 20:04:22 +0000150 new->abr_type = OSPF_ABR_DEFAULT;
paul718e3742002-12-13 20:15:29 +0000151 new->oiflist = list_new ();
152 new->vlinks = list_new ();
153 new->areas = list_new ();
154 new->areas->cmp = (int (*)(void *, void *)) ospf_area_id_cmp;
155 new->networks = route_table_init ();
156 new->nbr_nbma = route_table_init ();
157
158 new->lsdb = ospf_lsdb_new ();
159
160 new->default_originate = DEFAULT_ORIGINATE_NONE;
161
162 new->new_external_route = route_table_init ();
163 new->old_external_route = route_table_init ();
164 new->external_lsas = route_table_init ();
paul88d6cf32005-10-29 12:50:09 +0000165
166 new->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paul31a59762005-11-14 11:11:11 +0000167 new->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paul88d6cf32005-10-29 12:50:09 +0000168
paul718e3742002-12-13 20:15:29 +0000169 /* Distribute parameter init. */
170 for (i = 0; i <= ZEBRA_ROUTE_MAX; i++)
171 {
172 new->dmetric[i].type = -1;
173 new->dmetric[i].value = -1;
174 }
175 new->default_metric = -1;
176 new->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
177
178 /* SPF timer value init. */
179 new->spf_delay = OSPF_SPF_DELAY_DEFAULT;
180 new->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
pauld24f6e22005-10-21 09:23:12 +0000181 new->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT;
182 new->spf_hold_multiplier = 1;
paul718e3742002-12-13 20:15:29 +0000183
184 /* MaxAge init. */
185 new->maxage_lsa = list_new ();
186 new->t_maxage_walker =
187 thread_add_timer (master, ospf_lsa_maxage_walker,
paul68980082003-03-25 05:07:42 +0000188 new, OSPF_LSA_MAXAGE_CHECK_INTERVAL);
paul718e3742002-12-13 20:15:29 +0000189
190 /* Distance table init. */
191 new->distance_table = route_table_init ();
192
193 new->lsa_refresh_queue.index = 0;
194 new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
195 new->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker,
196 new, new->lsa_refresh_interval);
197 new->lsa_refresher_started = time (NULL);
198
ajs5c333492005-02-23 15:43:01 +0000199 if ((new->fd = ospf_sock_init()) < 0)
200 {
201 zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
202 "a socket");
203 exit(1);
204 }
205 if ((new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE+1)) == NULL)
206 {
207 zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
208 OSPF_MAX_PACKET_SIZE+1);
209 exit(1);
210 }
211 new->t_read = thread_add_read (master, ospf_read, new, new->fd);
paul718e3742002-12-13 20:15:29 +0000212 new->oi_write_q = list_new ();
213
214 return new;
215}
216
217struct ospf *
paul020709f2003-04-04 02:44:16 +0000218ospf_lookup ()
219{
220 if (listcount (om->ospf) == 0)
221 return NULL;
222
paul1eb8ef22005-04-07 07:30:20 +0000223 return listgetdata (listhead (om->ospf));
paul020709f2003-04-04 02:44:16 +0000224}
225
paul4dadc292005-05-06 21:37:42 +0000226static void
paul020709f2003-04-04 02:44:16 +0000227ospf_add (struct ospf *ospf)
228{
229 listnode_add (om->ospf, ospf);
230}
231
paul4dadc292005-05-06 21:37:42 +0000232static void
paul020709f2003-04-04 02:44:16 +0000233ospf_delete (struct ospf *ospf)
234{
235 listnode_delete (om->ospf, ospf);
236}
237
238struct ospf *
paul718e3742002-12-13 20:15:29 +0000239ospf_get ()
240{
paul020709f2003-04-04 02:44:16 +0000241 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000242
paul020709f2003-04-04 02:44:16 +0000243 ospf = ospf_lookup ();
244 if (ospf == NULL)
245 {
246 ospf = ospf_new ();
247 ospf_add (ospf);
paul718e3742002-12-13 20:15:29 +0000248
paul020709f2003-04-04 02:44:16 +0000249 if (ospf->router_id_static.s_addr == 0)
250 ospf_router_id_update (ospf);
paul718e3742002-12-13 20:15:29 +0000251
252#ifdef HAVE_OPAQUE_LSA
paul020709f2003-04-04 02:44:16 +0000253 ospf_opaque_type11_lsa_init (ospf);
paul718e3742002-12-13 20:15:29 +0000254#endif /* HAVE_OPAQUE_LSA */
paul020709f2003-04-04 02:44:16 +0000255 }
paul68980082003-03-25 05:07:42 +0000256
257 return ospf;
paul718e3742002-12-13 20:15:29 +0000258}
paul88d6cf32005-10-29 12:50:09 +0000259
paulc9c93d52005-11-26 13:31:11 +0000260/* Handle the second half of deferred shutdown. This is called either
261 * from the deferred-shutdown timer thread, or directly through
262 * ospf_deferred_shutdown_check.
paul88d6cf32005-10-29 12:50:09 +0000263 *
264 * Function is to cleanup G-R state, if required then call ospf_finish_final
265 * to complete shutdown of this ospf instance. Possibly exit if the
266 * whole process is being shutdown and this was the last OSPF instance.
267 */
268static void
paulc9c93d52005-11-26 13:31:11 +0000269ospf_deferred_shutdown_finish (struct ospf *ospf)
paul88d6cf32005-10-29 12:50:09 +0000270{
271 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paulc9c93d52005-11-26 13:31:11 +0000272 OSPF_TIMER_OFF (ospf->t_deferred_shutdown);
paul88d6cf32005-10-29 12:50:09 +0000273
274 ospf_finish_final (ospf);
275
276 /* *ospf is now invalid */
277
278 /* ospfd being shut-down? If so, was this the last ospf instance? */
279 if (CHECK_FLAG (om->options, OSPF_MASTER_SHUTDOWN)
280 && (listcount (om->ospf) == 0))
281 exit (0);
282
283 return;
284}
285
286/* Timer thread for G-R */
287static int
paulc9c93d52005-11-26 13:31:11 +0000288ospf_deferred_shutdown_timer (struct thread *t)
paul88d6cf32005-10-29 12:50:09 +0000289{
290 struct ospf *ospf = THREAD_ARG(t);
291
paulc9c93d52005-11-26 13:31:11 +0000292 ospf_deferred_shutdown_finish (ospf);
paul88d6cf32005-10-29 12:50:09 +0000293
294 return 0;
295}
296
paulc9c93d52005-11-26 13:31:11 +0000297/* Check whether deferred-shutdown must be scheduled, otherwise call
paul88d6cf32005-10-29 12:50:09 +0000298 * down directly into second-half of instance shutdown.
299 */
300static void
paulc9c93d52005-11-26 13:31:11 +0000301ospf_deferred_shutdown_check (struct ospf *ospf)
paul88d6cf32005-10-29 12:50:09 +0000302{
303 unsigned long timeout;
304 struct listnode *ln;
305 struct ospf_area *area;
306
paulc9c93d52005-11-26 13:31:11 +0000307 /* deferred shutdown already running? */
308 if (ospf->t_deferred_shutdown)
paul88d6cf32005-10-29 12:50:09 +0000309 return;
310
311 /* Should we try push out max-metric LSAs? */
312 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
313 {
314 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
315 {
316 SET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
317
318 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
319 ospf_router_lsa_timer_add (area);
320 }
321 timeout = ospf->stub_router_shutdown_time;
322 }
323 else
paulc9c93d52005-11-26 13:31:11 +0000324 {
325 /* No timer needed */
326 ospf_deferred_shutdown_finish (ospf);
327 return;
328 }
paul88d6cf32005-10-29 12:50:09 +0000329
paulc9c93d52005-11-26 13:31:11 +0000330 OSPF_TIMER_ON (ospf->t_deferred_shutdown, ospf_deferred_shutdown_timer,
paul88d6cf32005-10-29 12:50:09 +0000331 timeout);
332 return;
333}
334
335/* Shut down the entire process */
336void
337ospf_terminate (void)
338{
339 struct ospf *ospf;
340 struct listnode *node, *nnode;
341
342 /* shutdown already in progress */
343 if (CHECK_FLAG (om->options, OSPF_MASTER_SHUTDOWN))
344 return;
345
346 SET_FLAG (om->options, OSPF_MASTER_SHUTDOWN);
347
348 for (ALL_LIST_ELEMENTS (om->ospf, node, nnode, ospf))
349 ospf_finish (ospf);
350
351 /* Deliberately go back up, hopefully to thread scheduler, as
352 * One or more ospf_finish()'s may have deferred shutdown to a timer
353 * thread
354 */
355}
paul718e3742002-12-13 20:15:29 +0000356
357void
358ospf_finish (struct ospf *ospf)
359{
paulc9c93d52005-11-26 13:31:11 +0000360 /* let deferred shutdown decide */
361 ospf_deferred_shutdown_check (ospf);
paul88d6cf32005-10-29 12:50:09 +0000362
paulc9c93d52005-11-26 13:31:11 +0000363 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
paul88d6cf32005-10-29 12:50:09 +0000364 * deferred to expiry of G-S timer thread. Return back up, hopefully
365 * to thread scheduler.
366 */
paulc9c93d52005-11-26 13:31:11 +0000367 return;
paul88d6cf32005-10-29 12:50:09 +0000368}
369
370/* Final cleanup of ospf instance */
371static void
372ospf_finish_final (struct ospf *ospf)
373{
paul718e3742002-12-13 20:15:29 +0000374 struct route_node *rn;
375 struct ospf_nbr_nbma *nbr_nbma;
paul68980082003-03-25 05:07:42 +0000376 struct ospf_lsa *lsa;
paul1eb8ef22005-04-07 07:30:20 +0000377 struct ospf_interface *oi;
378 struct ospf_area *area;
379 struct ospf_vl_data *vl_data;
380 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000381 int i;
382
383#ifdef HAVE_OPAQUE_LSA
384 ospf_opaque_type11_lsa_term (ospf);
385#endif /* HAVE_OPAQUE_LSA */
paul88d6cf32005-10-29 12:50:09 +0000386
387 /* be nice if this worked, but it doesn't */
388 /*ospf_flush_self_originated_lsas_now (ospf);*/
389
390 /* Unregister redistribution */
paul718e3742002-12-13 20:15:29 +0000391 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
paul020709f2003-04-04 02:44:16 +0000392 ospf_redistribute_unset (ospf, i);
paul718e3742002-12-13 20:15:29 +0000393
paul1eb8ef22005-04-07 07:30:20 +0000394 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
395 ospf_remove_vls_through_area (ospf, area);
paul718e3742002-12-13 20:15:29 +0000396
paul1eb8ef22005-04-07 07:30:20 +0000397 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
398 ospf_vl_delete (ospf, vl_data);
paul718e3742002-12-13 20:15:29 +0000399
400 list_delete (ospf->vlinks);
401
402 /* Reset interface. */
paul1eb8ef22005-04-07 07:30:20 +0000403 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
404 ospf_if_free (oi);
paul718e3742002-12-13 20:15:29 +0000405
406 /* Clear static neighbors */
407 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
408 if ((nbr_nbma = rn->info))
409 {
410 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
411
412 if (nbr_nbma->nbr)
413 {
414 nbr_nbma->nbr->nbr_nbma = NULL;
415 nbr_nbma->nbr = NULL;
416 }
417
418 if (nbr_nbma->oi)
419 {
420 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
421 nbr_nbma->oi = NULL;
422 }
423
424 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
425 }
426
427 route_table_finish (ospf->nbr_nbma);
428
429 /* Clear networks and Areas. */
430 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
431 {
432 struct ospf_network *network;
433
434 if ((network = rn->info) != NULL)
435 {
paul68980082003-03-25 05:07:42 +0000436 ospf_network_free (ospf, network);
paul718e3742002-12-13 20:15:29 +0000437 rn->info = NULL;
438 route_unlock_node (rn);
439 }
440 }
441
paul1eb8ef22005-04-07 07:30:20 +0000442 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000443 {
paul718e3742002-12-13 20:15:29 +0000444 listnode_delete (ospf->areas, area);
445 ospf_area_free (area);
446 }
447
448 /* Cancel all timers. */
449 OSPF_TIMER_OFF (ospf->t_external_lsa);
paul718e3742002-12-13 20:15:29 +0000450 OSPF_TIMER_OFF (ospf->t_router_lsa_update);
451 OSPF_TIMER_OFF (ospf->t_spf_calc);
452 OSPF_TIMER_OFF (ospf->t_ase_calc);
453 OSPF_TIMER_OFF (ospf->t_maxage);
454 OSPF_TIMER_OFF (ospf->t_maxage_walker);
455 OSPF_TIMER_OFF (ospf->t_abr_task);
paul88d6cf32005-10-29 12:50:09 +0000456 OSPF_TIMER_OFF (ospf->t_asbr_check);
paul718e3742002-12-13 20:15:29 +0000457 OSPF_TIMER_OFF (ospf->t_distribute_update);
458 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
459 OSPF_TIMER_OFF (ospf->t_read);
460 OSPF_TIMER_OFF (ospf->t_write);
paul31a59762005-11-14 11:11:11 +0000461#ifdef HAVE_OPAQUE_LSA
paul88d6cf32005-10-29 12:50:09 +0000462 OSPF_TIMER_OFF (ospf->t_opaque_lsa_self);
paul31a59762005-11-14 11:11:11 +0000463#endif
paul718e3742002-12-13 20:15:29 +0000464
465 close (ospf->fd);
ajs5c333492005-02-23 15:43:01 +0000466 stream_free(ospf->ibuf);
paul718e3742002-12-13 20:15:29 +0000467
468#ifdef HAVE_OPAQUE_LSA
paul68980082003-03-25 05:07:42 +0000469 LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa)
470 ospf_discard_from_db (ospf, ospf->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000471#endif /* HAVE_OPAQUE_LSA */
paul68980082003-03-25 05:07:42 +0000472 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
473 ospf_discard_from_db (ospf, ospf->lsdb, lsa);
474
paul718e3742002-12-13 20:15:29 +0000475 ospf_lsdb_delete_all (ospf->lsdb);
476 ospf_lsdb_free (ospf->lsdb);
477
paul1eb8ef22005-04-07 07:30:20 +0000478 for (ALL_LIST_ELEMENTS (ospf->maxage_lsa, node, nnode, lsa))
479 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000480
481 list_delete (ospf->maxage_lsa);
482
483 if (ospf->old_table)
484 ospf_route_table_free (ospf->old_table);
485 if (ospf->new_table)
486 {
487 ospf_route_delete (ospf->new_table);
488 ospf_route_table_free (ospf->new_table);
489 }
490 if (ospf->old_rtrs)
491 ospf_rtrs_free (ospf->old_rtrs);
492 if (ospf->new_rtrs)
493 ospf_rtrs_free (ospf->new_rtrs);
494 if (ospf->new_external_route)
495 {
496 ospf_route_delete (ospf->new_external_route);
497 ospf_route_table_free (ospf->new_external_route);
498 }
499 if (ospf->old_external_route)
500 {
501 ospf_route_delete (ospf->old_external_route);
502 ospf_route_table_free (ospf->old_external_route);
503 }
504 if (ospf->external_lsas)
505 {
506 ospf_ase_external_lsas_finish (ospf->external_lsas);
507 }
508
509 list_delete (ospf->areas);
510
511 for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++)
512 if (EXTERNAL_INFO (i) != NULL)
513 for (rn = route_top (EXTERNAL_INFO (i)); rn; rn = route_next (rn))
514 {
515 if (rn->info == NULL)
516 continue;
517
518 XFREE (MTYPE_OSPF_EXTERNAL_INFO, rn->info);
519 rn->info = NULL;
520 route_unlock_node (rn);
521 }
522
paul68980082003-03-25 05:07:42 +0000523 ospf_distance_reset (ospf);
paul718e3742002-12-13 20:15:29 +0000524 route_table_finish (ospf->distance_table);
525
paul020709f2003-04-04 02:44:16 +0000526 ospf_delete (ospf);
paul718e3742002-12-13 20:15:29 +0000527
paul020709f2003-04-04 02:44:16 +0000528 XFREE (MTYPE_OSPF_TOP, ospf);
paul718e3742002-12-13 20:15:29 +0000529}
530
531
532/* allocate new OSPF Area object */
paul4dadc292005-05-06 21:37:42 +0000533static struct ospf_area *
paul68980082003-03-25 05:07:42 +0000534ospf_area_new (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000535{
536 struct ospf_area *new;
537
538 /* Allocate new config_network. */
539 new = XCALLOC (MTYPE_OSPF_AREA, sizeof (struct ospf_area));
540
paul68980082003-03-25 05:07:42 +0000541 new->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000542
543 new->area_id = area_id;
544
545 new->external_routing = OSPF_AREA_DEFAULT;
546 new->default_cost = 1;
547 new->auth_type = OSPF_AUTH_NULL;
paul88d6cf32005-10-29 12:50:09 +0000548
paul718e3742002-12-13 20:15:29 +0000549 /* New LSDB init. */
550 new->lsdb = ospf_lsdb_new ();
551
552 /* Self-originated LSAs initialize. */
553 new->router_lsa_self = NULL;
554
555#ifdef HAVE_OPAQUE_LSA
556 ospf_opaque_type10_lsa_init (new);
557#endif /* HAVE_OPAQUE_LSA */
558
559 new->oiflist = list_new ();
560 new->ranges = route_table_init ();
561
562 if (area_id.s_addr == OSPF_AREA_BACKBONE)
paul68980082003-03-25 05:07:42 +0000563 ospf->backbone = new;
paul718e3742002-12-13 20:15:29 +0000564
565 return new;
566}
567
568void
569ospf_area_free (struct ospf_area *area)
570{
paul68980082003-03-25 05:07:42 +0000571 struct route_node *rn;
572 struct ospf_lsa *lsa;
573
paul718e3742002-12-13 20:15:29 +0000574 /* Free LSDBs. */
paul68980082003-03-25 05:07:42 +0000575 LSDB_LOOP (ROUTER_LSDB (area), rn, lsa)
576 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
577 LSDB_LOOP (NETWORK_LSDB (area), rn, lsa)
578 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
579 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
580 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
581 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
582 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000583
paul68980082003-03-25 05:07:42 +0000584 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
585 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000586#ifdef HAVE_OPAQUE_LSA
paul68980082003-03-25 05:07:42 +0000587 LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa)
588 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
589 LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa)
590 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000591#endif /* HAVE_OPAQUE_LSA */
592
593 ospf_lsdb_delete_all (area->lsdb);
594 ospf_lsdb_free (area->lsdb);
595
paul718e3742002-12-13 20:15:29 +0000596 ospf_lsa_unlock (area->router_lsa_self);
597
598 route_table_finish (area->ranges);
599 list_delete (area->oiflist);
600
601 if (EXPORT_NAME (area))
602 free (EXPORT_NAME (area));
603
604 if (IMPORT_NAME (area))
605 free (IMPORT_NAME (area));
606
607 /* Cancel timer. */
608 OSPF_TIMER_OFF (area->t_router_lsa_self);
paul88d6cf32005-10-29 12:50:09 +0000609 OSPF_TIMER_OFF (area->t_stub_router);
610#ifdef HAVE_OPAQUE_LSA
611 OSPF_TIMER_OFF (area->t_opaque_lsa_self);
612#endif /* HAVE_OPAQUE_LSA */
613
paul718e3742002-12-13 20:15:29 +0000614 if (OSPF_IS_AREA_BACKBONE (area))
paul68980082003-03-25 05:07:42 +0000615 area->ospf->backbone = NULL;
paul718e3742002-12-13 20:15:29 +0000616
617 XFREE (MTYPE_OSPF_AREA, area);
618}
619
620void
paul68980082003-03-25 05:07:42 +0000621ospf_area_check_free (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000622{
623 struct ospf_area *area;
624
paul68980082003-03-25 05:07:42 +0000625 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000626 if (area &&
627 listcount (area->oiflist) == 0 &&
628 area->ranges->top == NULL &&
629 area->shortcut_configured == OSPF_SHORTCUT_DEFAULT &&
630 area->external_routing == OSPF_AREA_DEFAULT &&
631 area->no_summary == 0 &&
632 area->default_cost == 1 &&
633 EXPORT_NAME (area) == NULL &&
634 IMPORT_NAME (area) == NULL &&
635 area->auth_type == OSPF_AUTH_NULL)
636 {
paul68980082003-03-25 05:07:42 +0000637 listnode_delete (ospf->areas, area);
paul718e3742002-12-13 20:15:29 +0000638 ospf_area_free (area);
639 }
640}
641
642struct ospf_area *
paul68980082003-03-25 05:07:42 +0000643ospf_area_get (struct ospf *ospf, struct in_addr area_id, int format)
paul718e3742002-12-13 20:15:29 +0000644{
645 struct ospf_area *area;
646
paul68980082003-03-25 05:07:42 +0000647 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000648 if (!area)
649 {
paul68980082003-03-25 05:07:42 +0000650 area = ospf_area_new (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000651 area->format = format;
paul68980082003-03-25 05:07:42 +0000652 listnode_add_sort (ospf->areas, area);
653 ospf_check_abr_status (ospf);
paul718e3742002-12-13 20:15:29 +0000654 }
655
656 return area;
657}
658
659struct ospf_area *
paul68980082003-03-25 05:07:42 +0000660ospf_area_lookup_by_area_id (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000661{
662 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +0000663 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000664
paul1eb8ef22005-04-07 07:30:20 +0000665 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
666 if (IPV4_ADDR_SAME (&area->area_id, &area_id))
667 return area;
paul718e3742002-12-13 20:15:29 +0000668
669 return NULL;
670}
671
672void
673ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi)
674{
675 listnode_add (area->oiflist, oi);
676}
677
678void
679ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi)
680{
681 listnode_delete (area->oiflist, oi);
682}
683
684
685/* Config network statement related functions. */
paul4dadc292005-05-06 21:37:42 +0000686static struct ospf_network *
paul718e3742002-12-13 20:15:29 +0000687ospf_network_new (struct in_addr area_id, int format)
688{
689 struct ospf_network *new;
690 new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network));
691
692 new->area_id = area_id;
693 new->format = format;
694
695 return new;
696}
697
698void
paul68980082003-03-25 05:07:42 +0000699ospf_network_free (struct ospf *ospf, struct ospf_network *network)
paul718e3742002-12-13 20:15:29 +0000700{
paul68980082003-03-25 05:07:42 +0000701 ospf_area_check_free (ospf, network->area_id);
702 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000703 XFREE (MTYPE_OSPF_NETWORK, network);
704}
705
706int
707ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p,
708 struct in_addr area_id)
709{
710 struct ospf_network *network;
711 struct ospf_area *area;
712 struct route_node *rn;
713 struct external_info *ei;
paul147193a2003-04-19 00:31:59 +0000714 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000715
716 rn = route_node_get (ospf->networks, (struct prefix *)p);
717 if (rn->info)
718 {
719 /* There is already same network statement. */
720 route_unlock_node (rn);
721 return 0;
722 }
723
724 rn->info = network = ospf_network_new (area_id, ret);
paul68980082003-03-25 05:07:42 +0000725 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000726
727 /* Run network config now. */
728 ospf_network_run (ospf, (struct prefix *)p, area);
729
730 /* Update connected redistribute. */
731 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
732 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
733 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
734 rn; rn = route_next (rn))
735 if ((ei = rn->info) != NULL)
paul68980082003-03-25 05:07:42 +0000736 if (ospf_external_info_find_lsa (ospf, &ei->p))
737 if (!ospf_distribute_check_connected (ospf, ei))
738 ospf_external_lsa_flush (ospf, ei->type, &ei->p,
ajs5339cfd2005-09-19 13:28:05 +0000739 ei->ifindex /*, ei->nexthop */);
paul718e3742002-12-13 20:15:29 +0000740
paul68980082003-03-25 05:07:42 +0000741 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000742
743 return 1;
744}
745
746int
747ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
748 struct in_addr area_id)
749{
750 struct route_node *rn;
751 struct ospf_network *network;
752 struct external_info *ei;
753
754 rn = route_node_lookup (ospf->networks, (struct prefix *)p);
755 if (rn == NULL)
756 return 0;
757
758 network = rn->info;
759 if (!IPV4_ADDR_SAME (&area_id, &network->area_id))
760 return 0;
761
paul68980082003-03-25 05:07:42 +0000762 ospf_network_free (ospf, rn->info);
paul718e3742002-12-13 20:15:29 +0000763 rn->info = NULL;
764 route_unlock_node (rn);
765
paul68980082003-03-25 05:07:42 +0000766 ospf_if_update (ospf);
paul718e3742002-12-13 20:15:29 +0000767
768 /* Update connected redistribute. */
769 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
770 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
771 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
772 rn; rn = route_next (rn))
773 if ((ei = rn->info) != NULL)
paul68980082003-03-25 05:07:42 +0000774 if (!ospf_external_info_find_lsa (ospf, &ei->p))
775 if (ospf_distribute_check_connected (ospf, ei))
776 ospf_external_lsa_originate (ospf, ei);
paul718e3742002-12-13 20:15:29 +0000777
778 return 1;
779}
780
paul570f7592003-01-25 06:47:41 +0000781/* Check whether interface matches given network
782 * returns: 1, true. 0, false
783 */
784int
785ospf_network_match_iface(struct connected *co, struct prefix *net)
786{
787 /* Behaviour to match both Cisco where:
788 * iface address lies within network specified -> ospf
789 * and zebra 0.9[2ish-3]:
790 * PtP special case: network specified == iface peer addr -> ospf
791 */
gdt8f40e892003-12-05 14:01:43 +0000792
paulf3ae74c2004-11-04 20:35:31 +0000793 /* For PtP, match if peer address matches network address exactly.
794 * This can be addr/32 or addr/p for p < 32, but the addr must match
795 * exactly; this is not a test for falling within the prefix. This
gdt8f40e892003-12-05 14:01:43 +0000796 * test is solely for compatibility with zebra.
gdt8f40e892003-12-05 14:01:43 +0000797 */
paulf3ae74c2004-11-04 20:35:31 +0000798 if (if_is_pointopoint (co->ifp) && co->destination &&
799 IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
800 return 1;
801
802#if 0
803 /* Decline to accept PtP if dst address does not match the
804 * prefix. (ifdefed out because this is a workaround, not the
805 * desired behavior.) */
806 if (if_is_pointopoint (co->ifp) &&
807 ! prefix_match (net, co->destination))
808 return 0;
809#endif
810
811 /* If the address is within the prefix, accept. Note that this
812 * applies to PtP as well as other types.
813 */
814 if (prefix_match (net, co->address))
815 return 1;
816
817 return 0; /* no match */
paul570f7592003-01-25 06:47:41 +0000818}
819
paul718e3742002-12-13 20:15:29 +0000820void
821ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area)
822{
823 struct interface *ifp;
paul1eb8ef22005-04-07 07:30:20 +0000824 struct connected *co;
hasso52dc7ee2004-09-23 19:18:23 +0000825 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000826
827 /* Schedule Router ID Update. */
828 if (ospf->router_id_static.s_addr == 0)
paulb29800a2005-11-20 14:50:45 +0000829 ospf_router_id_update (ospf);
830
paul718e3742002-12-13 20:15:29 +0000831 /* Get target interface. */
paul1eb8ef22005-04-07 07:30:20 +0000832 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
paul718e3742002-12-13 20:15:29 +0000833 {
paul1eb8ef22005-04-07 07:30:20 +0000834 struct listnode *cnode;
paul718e3742002-12-13 20:15:29 +0000835
paul718e3742002-12-13 20:15:29 +0000836 if (memcmp (ifp->name, "VLINK", 5) == 0)
837 continue;
838
839 /* if interface prefix is match specified prefix,
840 then create socket and join multicast group. */
paul1eb8ef22005-04-07 07:30:20 +0000841 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, co))
paul718e3742002-12-13 20:15:29 +0000842 {
paul718e3742002-12-13 20:15:29 +0000843 struct prefix *addr;
paul800dc102003-03-28 01:51:40 +0000844
paule7b050c2003-04-07 06:38:02 +0000845 if (CHECK_FLAG(co->flags,ZEBRA_IFA_SECONDARY))
846 continue;
paul718e3742002-12-13 20:15:29 +0000847
hasso3fb9cd62004-10-19 19:44:43 +0000848 if (CONNECTED_POINTOPOINT_HOST(co))
paul718e3742002-12-13 20:15:29 +0000849 addr = co->destination;
850 else
851 addr = co->address;
852
paulcb3f37d2003-02-18 23:26:37 +0000853 if (p->family == co->address->family
paul68980082003-03-25 05:07:42 +0000854 && ! ospf_if_is_configured (ospf, &(addr->u.prefix4))
paulcb3f37d2003-02-18 23:26:37 +0000855 && ospf_network_match_iface(co,p))
paul570f7592003-01-25 06:47:41 +0000856 {
paul1eb8ef22005-04-07 07:30:20 +0000857 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000858
paul68980082003-03-25 05:07:42 +0000859 oi = ospf_if_new (ospf, ifp, co->address);
paul718e3742002-12-13 20:15:29 +0000860 oi->connected = co;
861
862 oi->nbr_self->address = *oi->address;
863
paul718e3742002-12-13 20:15:29 +0000864 oi->area = area;
865
866 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
867 oi->output_cost = ospf_if_get_output_cost (oi);
868
869 if (area->external_routing != OSPF_AREA_DEFAULT)
870 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
871 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
872
873 /* Add pseudo neighbor. */
874 ospf_nbr_add_self (oi);
875
876 /* Make sure pseudo neighbor's router_id. */
paul68980082003-03-25 05:07:42 +0000877 oi->nbr_self->router_id = ospf->router_id;
paul718e3742002-12-13 20:15:29 +0000878 oi->nbr_self->src = oi->address->u.prefix4;
879
880 /* Relate ospf interface to ospf instance. */
paul68980082003-03-25 05:07:42 +0000881 oi->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000882
883 /* update network type as interface flag */
884 /* If network type is specified previously,
885 skip network type setting. */
886 oi->type = IF_DEF_PARAMS (ifp)->type;
887
888 /* Set area flag. */
889 switch (area->external_routing)
890 {
891 case OSPF_AREA_DEFAULT:
892 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
893 break;
894 case OSPF_AREA_STUB:
895 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
896 break;
paul718e3742002-12-13 20:15:29 +0000897 case OSPF_AREA_NSSA:
898 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
899 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
900 break;
paul718e3742002-12-13 20:15:29 +0000901 }
902
903 ospf_area_add_if (oi->area, oi);
paulb29800a2005-11-20 14:50:45 +0000904
905 /* if router_id is not configured, dont bring up
906 * interfaces.
907 * ospf_router_id_update() will call ospf_if_update
908 * whenever r-id is configured instead.
909 */
910 if ((ospf->router_id_static.s_addr != 0)
911 && if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000912 ospf_if_up (oi);
913
914 break;
915 }
916 }
917 }
918}
919
920void
921ospf_ls_upd_queue_empty (struct ospf_interface *oi)
922{
923 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000924 struct listnode *node, *nnode;
hasso52dc7ee2004-09-23 19:18:23 +0000925 struct list *lst;
paul718e3742002-12-13 20:15:29 +0000926 struct ospf_lsa *lsa;
927
928 /* empty ls update queue */
929 for (rn = route_top (oi->ls_upd_queue); rn;
930 rn = route_next (rn))
hasso52dc7ee2004-09-23 19:18:23 +0000931 if ((lst = (struct list *) rn->info))
paul718e3742002-12-13 20:15:29 +0000932 {
paul1eb8ef22005-04-07 07:30:20 +0000933 for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa))
934 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000935 list_free (lst);
936 rn->info = NULL;
937 }
938
939 /* remove update event */
940 if (oi->t_ls_upd_event)
941 {
942 thread_cancel (oi->t_ls_upd_event);
943 oi->t_ls_upd_event = NULL;
944 }
945}
946
947void
paul68980082003-03-25 05:07:42 +0000948ospf_if_update (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000949{
950 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000951 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000952 struct ospf_network *network;
953 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000954 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000955
paul68980082003-03-25 05:07:42 +0000956 if (ospf != NULL)
paul718e3742002-12-13 20:15:29 +0000957 {
paulb29800a2005-11-20 14:50:45 +0000958 /* Router-ID must be configured. */
paul68980082003-03-25 05:07:42 +0000959 if (ospf->router_id_static.s_addr == 0)
paulb29800a2005-11-20 14:50:45 +0000960 return;
961
paul718e3742002-12-13 20:15:29 +0000962 /* Find interfaces that not configured already. */
paul1eb8ef22005-04-07 07:30:20 +0000963 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +0000964 {
965 int found = 0;
paul718e3742002-12-13 20:15:29 +0000966 struct connected *co = oi->connected;
967
paul718e3742002-12-13 20:15:29 +0000968 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
969 continue;
970
paul68980082003-03-25 05:07:42 +0000971 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000972 {
973 if (rn->info == NULL)
974 continue;
975
paul570f7592003-01-25 06:47:41 +0000976 if (ospf_network_match_iface(co,&rn->p))
paul718e3742002-12-13 20:15:29 +0000977 {
978 found = 1;
979 route_unlock_node (rn);
980 break;
981 }
982 }
983
984 if (found == 0)
985 ospf_if_free (oi);
986 }
987
988 /* Run each interface. */
paul68980082003-03-25 05:07:42 +0000989 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000990 if (rn->info != NULL)
991 {
992 network = (struct ospf_network *) rn->info;
paul68980082003-03-25 05:07:42 +0000993 area = ospf_area_get (ospf, network->area_id, network->format);
994 ospf_network_run (ospf, &rn->p, area);
paul718e3742002-12-13 20:15:29 +0000995 }
996 }
997}
998
999void
paul68980082003-03-25 05:07:42 +00001000ospf_remove_vls_through_area (struct ospf *ospf, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +00001001{
paul1eb8ef22005-04-07 07:30:20 +00001002 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001003 struct ospf_vl_data *vl_data;
1004
paul1eb8ef22005-04-07 07:30:20 +00001005 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
1006 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1007 ospf_vl_delete (ospf, vl_data);
paul718e3742002-12-13 20:15:29 +00001008}
1009
1010
1011struct message ospf_area_type_msg[] =
1012{
1013 { OSPF_AREA_DEFAULT, "Default" },
1014 { OSPF_AREA_STUB, "Stub" },
1015 { OSPF_AREA_NSSA, "NSSA" },
1016};
1017int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX;
1018
paul4dadc292005-05-06 21:37:42 +00001019static void
paul718e3742002-12-13 20:15:29 +00001020ospf_area_type_set (struct ospf_area *area, int type)
1021{
hasso52dc7ee2004-09-23 19:18:23 +00001022 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001023 struct ospf_interface *oi;
1024
1025 if (area->external_routing == type)
1026 {
1027 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +00001028 zlog_debug ("Area[%s]: Types are the same, ignored.",
paul718e3742002-12-13 20:15:29 +00001029 inet_ntoa (area->area_id));
1030 return;
1031 }
1032
1033 area->external_routing = type;
1034
1035 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +00001036 zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area->area_id),
paul718e3742002-12-13 20:15:29 +00001037 LOOKUP (ospf_area_type_msg, type));
1038
1039 switch (area->external_routing)
1040 {
1041 case OSPF_AREA_DEFAULT:
paul1eb8ef22005-04-07 07:30:20 +00001042 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1043 if (oi->nbr_self != NULL)
1044 {
1045 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1046 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1047 }
paul718e3742002-12-13 20:15:29 +00001048 break;
1049 case OSPF_AREA_STUB:
paul1eb8ef22005-04-07 07:30:20 +00001050 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1051 if (oi->nbr_self != NULL)
1052 {
1053 if (IS_DEBUG_OSPF_EVENT)
1054 zlog_debug ("setting options on %s accordingly", IF_NAME (oi));
1055 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1056 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1057 if (IS_DEBUG_OSPF_EVENT)
1058 zlog_debug ("options set on %s: %x",
1059 IF_NAME (oi), OPTIONS (oi));
1060 }
paul718e3742002-12-13 20:15:29 +00001061 break;
1062 case OSPF_AREA_NSSA:
paul1eb8ef22005-04-07 07:30:20 +00001063 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1064 if (oi->nbr_self != NULL)
1065 {
1066 zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi));
1067 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1068 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1069 zlog_debug ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi));
1070 }
paul718e3742002-12-13 20:15:29 +00001071 break;
1072 default:
1073 break;
1074 }
1075
1076 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001077 ospf_schedule_abr_task (area->ospf);
paul718e3742002-12-13 20:15:29 +00001078}
1079
1080int
paul68980082003-03-25 05:07:42 +00001081ospf_area_shortcut_set (struct ospf *ospf, struct ospf_area *area, int mode)
paul718e3742002-12-13 20:15:29 +00001082{
1083 if (area->shortcut_configured == mode)
1084 return 0;
1085
1086 area->shortcut_configured = mode;
1087 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001088 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001089
paul68980082003-03-25 05:07:42 +00001090 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001091
1092 return 1;
1093}
1094
1095int
paul68980082003-03-25 05:07:42 +00001096ospf_area_shortcut_unset (struct ospf *ospf, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +00001097{
1098 area->shortcut_configured = OSPF_SHORTCUT_DEFAULT;
1099 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001100 ospf_area_check_free (ospf, area->area_id);
1101 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001102
1103 return 1;
1104}
1105
paul4dadc292005-05-06 21:37:42 +00001106static int
paul718e3742002-12-13 20:15:29 +00001107ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area)
1108{
1109 struct ospf_vl_data *vl;
hasso52dc7ee2004-09-23 19:18:23 +00001110 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001111 int count = 0;
1112
paul1eb8ef22005-04-07 07:30:20 +00001113 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl))
1114 if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id))
1115 count++;
paul718e3742002-12-13 20:15:29 +00001116
1117 return count;
1118}
1119
1120int
1121ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id)
1122{
1123 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001124 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001125
paul68980082003-03-25 05:07:42 +00001126 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001127 if (ospf_area_vlink_count (ospf, area))
1128 return 0;
1129
1130 if (area->external_routing != OSPF_AREA_STUB)
1131 ospf_area_type_set (area, OSPF_AREA_STUB);
1132
1133 return 1;
1134}
1135
1136int
1137ospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id)
1138{
1139 struct ospf_area *area;
1140
paul68980082003-03-25 05:07:42 +00001141 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001142 if (area == NULL)
1143 return 1;
1144
1145 if (area->external_routing == OSPF_AREA_STUB)
1146 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1147
paul68980082003-03-25 05:07:42 +00001148 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001149
1150 return 1;
1151}
1152
1153int
1154ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id)
1155{
1156 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001157 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001158
paul68980082003-03-25 05:07:42 +00001159 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001160 area->no_summary = 1;
1161
1162 return 1;
1163}
1164
1165int
1166ospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id)
1167{
1168 struct ospf_area *area;
1169
paul68980082003-03-25 05:07:42 +00001170 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001171 if (area == NULL)
1172 return 0;
1173
1174 area->no_summary = 0;
paul68980082003-03-25 05:07:42 +00001175 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001176
1177 return 1;
1178}
1179
1180int
1181ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id)
1182{
1183 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001184 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001185
paul68980082003-03-25 05:07:42 +00001186 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001187 if (ospf_area_vlink_count (ospf, area))
1188 return 0;
1189
1190 if (area->external_routing != OSPF_AREA_NSSA)
1191 {
1192 ospf_area_type_set (area, OSPF_AREA_NSSA);
1193 ospf->anyNSSA++;
1194 }
1195
paul084c7842003-06-22 08:35:18 +00001196 /* set NSSA area defaults */
1197 area->no_summary = 0;
1198 area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
pauld4a53d52003-07-12 21:30:57 +00001199 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paul084c7842003-06-22 08:35:18 +00001200 area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT;
1201
paul718e3742002-12-13 20:15:29 +00001202 return 1;
1203}
1204
1205int
1206ospf_area_nssa_unset (struct ospf *ospf, struct in_addr area_id)
1207{
1208 struct ospf_area *area;
1209
paul68980082003-03-25 05:07:42 +00001210 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001211 if (area == NULL)
1212 return 0;
1213
1214 if (area->external_routing == OSPF_AREA_NSSA)
1215 {
1216 ospf->anyNSSA--;
1217 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1218 }
1219
paul68980082003-03-25 05:07:42 +00001220 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001221
1222 return 1;
1223}
1224
1225int
1226ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id,
1227 int role)
1228{
1229 struct ospf_area *area;
1230
paul68980082003-03-25 05:07:42 +00001231 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001232 if (area == NULL)
1233 return 0;
1234
paul084c7842003-06-22 08:35:18 +00001235 area->NSSATranslatorRole = role;
paul718e3742002-12-13 20:15:29 +00001236
1237 return 1;
1238}
1239
paul4dadc292005-05-06 21:37:42 +00001240/* XXX: unused? Leave for symmetry? */
1241static int
paul718e3742002-12-13 20:15:29 +00001242ospf_area_nssa_translator_role_unset (struct ospf *ospf,
1243 struct in_addr area_id)
1244{
1245 struct ospf_area *area;
1246
paul68980082003-03-25 05:07:42 +00001247 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001248 if (area == NULL)
1249 return 0;
1250
paul084c7842003-06-22 08:35:18 +00001251 area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
paul718e3742002-12-13 20:15:29 +00001252
paul68980082003-03-25 05:07:42 +00001253 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001254
1255 return 1;
1256}
1257
1258int
paul68980082003-03-25 05:07:42 +00001259ospf_area_export_list_set (struct ospf *ospf,
paul6c835672004-10-11 11:00:30 +00001260 struct ospf_area *area, const char *list_name)
paul718e3742002-12-13 20:15:29 +00001261{
1262 struct access_list *list;
1263 list = access_list_lookup (AFI_IP, list_name);
1264
1265 EXPORT_LIST (area) = list;
1266
1267 if (EXPORT_NAME (area))
1268 free (EXPORT_NAME (area));
1269
1270 EXPORT_NAME (area) = strdup (list_name);
paul68980082003-03-25 05:07:42 +00001271 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001272
1273 return 1;
1274}
1275
1276int
paul68980082003-03-25 05:07:42 +00001277ospf_area_export_list_unset (struct ospf *ospf, struct ospf_area * area)
paul718e3742002-12-13 20:15:29 +00001278{
1279
1280 EXPORT_LIST (area) = 0;
1281
1282 if (EXPORT_NAME (area))
1283 free (EXPORT_NAME (area));
1284
1285 EXPORT_NAME (area) = NULL;
1286
paul68980082003-03-25 05:07:42 +00001287 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001288
paul68980082003-03-25 05:07:42 +00001289 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001290
1291 return 1;
1292}
1293
1294int
paul6c835672004-10-11 11:00:30 +00001295ospf_area_import_list_set (struct ospf *ospf, struct ospf_area *area,
1296 const char *name)
paul718e3742002-12-13 20:15:29 +00001297{
1298 struct access_list *list;
1299 list = access_list_lookup (AFI_IP, name);
1300
1301 IMPORT_LIST (area) = list;
1302
1303 if (IMPORT_NAME (area))
1304 free (IMPORT_NAME (area));
1305
1306 IMPORT_NAME (area) = strdup (name);
paul68980082003-03-25 05:07:42 +00001307 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001308
1309 return 1;
1310}
1311
1312int
paul68980082003-03-25 05:07:42 +00001313ospf_area_import_list_unset (struct ospf *ospf, struct ospf_area * area)
paul718e3742002-12-13 20:15:29 +00001314{
1315 IMPORT_LIST (area) = 0;
1316
1317 if (IMPORT_NAME (area))
1318 free (IMPORT_NAME (area));
1319
1320 IMPORT_NAME (area) = NULL;
paul68980082003-03-25 05:07:42 +00001321 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001322
paul68980082003-03-25 05:07:42 +00001323 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001324
1325 return 1;
1326}
1327
1328int
paul718e3742002-12-13 20:15:29 +00001329ospf_timers_refresh_set (struct ospf *ospf, int interval)
1330{
1331 int time_left;
1332
1333 if (ospf->lsa_refresh_interval == interval)
1334 return 1;
1335
1336 time_left = ospf->lsa_refresh_interval -
1337 (time (NULL) - ospf->lsa_refresher_started);
1338
1339 if (time_left > interval)
1340 {
1341 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1342 ospf->t_lsa_refresher =
1343 thread_add_timer (master, ospf_lsa_refresh_walker, ospf, interval);
1344 }
1345 ospf->lsa_refresh_interval = interval;
1346
1347 return 1;
1348}
1349
1350int
1351ospf_timers_refresh_unset (struct ospf *ospf)
1352{
1353 int time_left;
1354
1355 time_left = ospf->lsa_refresh_interval -
1356 (time (NULL) - ospf->lsa_refresher_started);
1357
1358 if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
1359 {
1360 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1361 ospf->t_lsa_refresher =
1362 thread_add_timer (master, ospf_lsa_refresh_walker, ospf,
1363 OSPF_LSA_REFRESH_INTERVAL_DEFAULT);
1364 }
1365
1366 ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
1367
1368 return 1;
1369}
1370
1371
paul4dadc292005-05-06 21:37:42 +00001372static struct ospf_nbr_nbma *
1373ospf_nbr_nbma_new (void)
paul718e3742002-12-13 20:15:29 +00001374{
1375 struct ospf_nbr_nbma *nbr_nbma;
1376
1377 nbr_nbma = XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC,
1378 sizeof (struct ospf_nbr_nbma));
1379 memset (nbr_nbma, 0, sizeof (struct ospf_nbr_nbma));
1380
1381 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1382 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1383
1384 return nbr_nbma;
1385}
1386
paul4dadc292005-05-06 21:37:42 +00001387static void
paul718e3742002-12-13 20:15:29 +00001388ospf_nbr_nbma_free (struct ospf_nbr_nbma *nbr_nbma)
1389{
1390 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
1391}
1392
paul4dadc292005-05-06 21:37:42 +00001393static void
paul718e3742002-12-13 20:15:29 +00001394ospf_nbr_nbma_delete (struct ospf *ospf, struct ospf_nbr_nbma *nbr_nbma)
1395{
1396 struct route_node *rn;
1397 struct prefix_ipv4 p;
1398
1399 p.family = AF_INET;
1400 p.prefix = nbr_nbma->addr;
1401 p.prefixlen = IPV4_MAX_BITLEN;
1402
1403 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1404 if (rn)
1405 {
1406 ospf_nbr_nbma_free (rn->info);
1407 rn->info = NULL;
1408 route_unlock_node (rn);
1409 route_unlock_node (rn);
1410 }
1411}
1412
paul4dadc292005-05-06 21:37:42 +00001413static void
paul718e3742002-12-13 20:15:29 +00001414ospf_nbr_nbma_down (struct ospf_nbr_nbma *nbr_nbma)
1415{
1416 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1417
1418 if (nbr_nbma->nbr)
1419 {
1420 nbr_nbma->nbr->nbr_nbma = NULL;
1421 OSPF_NSM_EVENT_EXECUTE (nbr_nbma->nbr, NSM_KillNbr);
1422 }
1423
1424 if (nbr_nbma->oi)
1425 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
1426}
1427
paul4dadc292005-05-06 21:37:42 +00001428static void
paul718e3742002-12-13 20:15:29 +00001429ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma,
1430 struct ospf_interface *oi)
1431{
1432 struct ospf_neighbor *nbr;
1433 struct route_node *rn;
1434 struct prefix p;
1435
1436 if (oi->type != OSPF_IFTYPE_NBMA)
1437 return;
1438
1439 if (nbr_nbma->nbr != NULL)
1440 return;
1441
1442 if (IPV4_ADDR_SAME (&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr))
1443 return;
1444
1445 nbr_nbma->oi = oi;
1446 listnode_add (oi->nbr_nbma, nbr_nbma);
1447
1448 /* Get neighbor information from table. */
1449 p.family = AF_INET;
1450 p.prefixlen = IPV4_MAX_BITLEN;
1451 p.u.prefix4 = nbr_nbma->addr;
1452
1453 rn = route_node_get (oi->nbrs, (struct prefix *)&p);
1454 if (rn->info)
1455 {
1456 nbr = rn->info;
1457 nbr->nbr_nbma = nbr_nbma;
1458 nbr_nbma->nbr = nbr;
1459
1460 route_unlock_node (rn);
1461 }
1462 else
1463 {
1464 nbr = rn->info = ospf_nbr_new (oi);
1465 nbr->state = NSM_Down;
1466 nbr->src = nbr_nbma->addr;
1467 nbr->nbr_nbma = nbr_nbma;
1468 nbr->priority = nbr_nbma->priority;
1469 nbr->address = p;
1470
1471 nbr_nbma->nbr = nbr;
1472
1473 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start);
1474 }
1475}
1476
1477void
paul68980082003-03-25 05:07:42 +00001478ospf_nbr_nbma_if_update (struct ospf *ospf, struct ospf_interface *oi)
paul718e3742002-12-13 20:15:29 +00001479{
1480 struct ospf_nbr_nbma *nbr_nbma;
1481 struct route_node *rn;
1482 struct prefix_ipv4 p;
1483
1484 if (oi->type != OSPF_IFTYPE_NBMA)
1485 return;
1486
paul68980082003-03-25 05:07:42 +00001487 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +00001488 if ((nbr_nbma = rn->info))
1489 if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL)
1490 {
1491 p.family = AF_INET;
1492 p.prefix = nbr_nbma->addr;
1493 p.prefixlen = IPV4_MAX_BITLEN;
1494
1495 if (prefix_match (oi->address, (struct prefix *)&p))
1496 ospf_nbr_nbma_add (nbr_nbma, oi);
1497 }
1498}
1499
1500struct ospf_nbr_nbma *
1501ospf_nbr_nbma_lookup (struct ospf *ospf, struct in_addr nbr_addr)
1502{
1503 struct route_node *rn;
1504 struct prefix_ipv4 p;
1505
1506 p.family = AF_INET;
1507 p.prefix = nbr_addr;
1508 p.prefixlen = IPV4_MAX_BITLEN;
1509
1510 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1511 if (rn)
1512 {
1513 route_unlock_node (rn);
1514 return rn->info;
1515 }
1516 return NULL;
1517}
1518
1519struct ospf_nbr_nbma *
paul68980082003-03-25 05:07:42 +00001520ospf_nbr_nbma_lookup_next (struct ospf *ospf, struct in_addr *addr, int first)
paul718e3742002-12-13 20:15:29 +00001521{
1522#if 0
1523 struct ospf_nbr_nbma *nbr_nbma;
hasso52dc7ee2004-09-23 19:18:23 +00001524 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001525#endif
1526
paul68980082003-03-25 05:07:42 +00001527 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001528 return NULL;
1529
1530#if 0
paul1eb8ef22005-04-07 07:30:20 +00001531 for (ALL_LIST_ELEMENTS_RO (ospf->nbr_nbma, node, nbr_nbma))
paul718e3742002-12-13 20:15:29 +00001532 {
paul718e3742002-12-13 20:15:29 +00001533 if (first)
1534 {
1535 *addr = nbr_nbma->addr;
1536 return nbr_nbma;
1537 }
1538 else if (ntohl (nbr_nbma->addr.s_addr) > ntohl (addr->s_addr))
1539 {
1540 *addr = nbr_nbma->addr;
1541 return nbr_nbma;
1542 }
1543 }
1544#endif
1545 return NULL;
1546}
1547
1548int
1549ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr)
1550{
1551 struct ospf_nbr_nbma *nbr_nbma;
1552 struct ospf_interface *oi;
1553 struct prefix_ipv4 p;
1554 struct route_node *rn;
hasso52dc7ee2004-09-23 19:18:23 +00001555 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001556
1557 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1558 if (nbr_nbma)
1559 return 0;
1560
1561 nbr_nbma = ospf_nbr_nbma_new ();
1562 nbr_nbma->addr = nbr_addr;
1563
1564 p.family = AF_INET;
1565 p.prefix = nbr_addr;
1566 p.prefixlen = IPV4_MAX_BITLEN;
1567
1568 rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p);
1569 rn->info = nbr_nbma;
1570
paul1eb8ef22005-04-07 07:30:20 +00001571 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul718e3742002-12-13 20:15:29 +00001572 {
paul718e3742002-12-13 20:15:29 +00001573 if (oi->type == OSPF_IFTYPE_NBMA)
1574 if (prefix_match (oi->address, (struct prefix *)&p))
1575 {
1576 ospf_nbr_nbma_add (nbr_nbma, oi);
1577 break;
1578 }
1579 }
1580
1581 return 1;
1582}
1583
1584int
1585ospf_nbr_nbma_unset (struct ospf *ospf, struct in_addr nbr_addr)
1586{
1587 struct ospf_nbr_nbma *nbr_nbma;
1588
1589 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1590 if (nbr_nbma == NULL)
1591 return 0;
1592
1593 ospf_nbr_nbma_down (nbr_nbma);
1594 ospf_nbr_nbma_delete (ospf, nbr_nbma);
1595
1596 return 1;
1597}
1598
1599int
1600ospf_nbr_nbma_priority_set (struct ospf *ospf, struct in_addr nbr_addr,
1601 u_char priority)
1602{
1603 struct ospf_nbr_nbma *nbr_nbma;
1604
1605 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1606 if (nbr_nbma == NULL)
1607 return 0;
1608
1609 if (nbr_nbma->priority != priority)
1610 nbr_nbma->priority = priority;
1611
1612 return 1;
1613}
1614
1615int
1616ospf_nbr_nbma_priority_unset (struct ospf *ospf, struct in_addr nbr_addr)
1617{
1618 struct ospf_nbr_nbma *nbr_nbma;
1619
1620 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1621 if (nbr_nbma == NULL)
1622 return 0;
1623
1624 if (nbr_nbma != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
1625 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1626
1627 return 1;
1628}
1629
1630int
1631ospf_nbr_nbma_poll_interval_set (struct ospf *ospf, struct in_addr nbr_addr,
paul6c835672004-10-11 11:00:30 +00001632 unsigned int interval)
paul718e3742002-12-13 20:15:29 +00001633{
1634 struct ospf_nbr_nbma *nbr_nbma;
1635
1636 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1637 if (nbr_nbma == NULL)
1638 return 0;
1639
1640 if (nbr_nbma->v_poll != interval)
1641 {
1642 nbr_nbma->v_poll = interval;
1643 if (nbr_nbma->oi && ospf_if_is_up (nbr_nbma->oi))
1644 {
1645 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1646 OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer,
1647 nbr_nbma->v_poll);
1648 }
1649 }
1650
1651 return 1;
1652}
1653
1654int
1655ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr)
1656{
1657 struct ospf_nbr_nbma *nbr_nbma;
1658
1659 nbr_nbma = ospf_nbr_nbma_lookup (ospf, addr);
1660 if (nbr_nbma == NULL)
1661 return 0;
1662
1663 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
1664 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1665
1666 return 1;
1667}
1668
paul718e3742002-12-13 20:15:29 +00001669void
paul020709f2003-04-04 02:44:16 +00001670ospf_master_init ()
1671{
1672 memset (&ospf_master, 0, sizeof (struct ospf_master));
1673
1674 om = &ospf_master;
1675 om->ospf = list_new ();
1676 om->master = thread_master_create ();
1677 om->start_time = time (NULL);
1678}