blob: 3cc0202013687b4c9c568796fe3054c3692e2afe [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);
122 }
123}
124
125int
126ospf_router_id_update_timer (struct thread *thread)
127{
paul020709f2003-04-04 02:44:16 +0000128 struct ospf *ospf = THREAD_ARG (thread);
paul68980082003-03-25 05:07:42 +0000129
paul718e3742002-12-13 20:15:29 +0000130 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +0000131 zlog_debug ("Router-ID: Update timer fired!");
paul718e3742002-12-13 20:15:29 +0000132
paul68980082003-03-25 05:07:42 +0000133 ospf->t_router_id_update = NULL;
134 ospf_router_id_update (ospf);
paul718e3742002-12-13 20:15:29 +0000135
136 return 0;
137}
138
139/* For OSPF area sort by area id. */
paul4dadc292005-05-06 21:37:42 +0000140static int
paul718e3742002-12-13 20:15:29 +0000141ospf_area_id_cmp (struct ospf_area *a1, struct ospf_area *a2)
142{
143 if (ntohl (a1->area_id.s_addr) > ntohl (a2->area_id.s_addr))
144 return 1;
145 if (ntohl (a1->area_id.s_addr) < ntohl (a2->area_id.s_addr))
146 return -1;
147 return 0;
148}
149
150/* Allocate new ospf structure. */
paul4dadc292005-05-06 21:37:42 +0000151static struct ospf *
152ospf_new (void)
paul718e3742002-12-13 20:15:29 +0000153{
154 int i;
155
156 struct ospf *new = XCALLOC (MTYPE_OSPF_TOP, sizeof (struct ospf));
157
158 new->router_id.s_addr = htonl (0);
159 new->router_id_static.s_addr = htonl (0);
160
pauld57834f2005-07-12 20:04:22 +0000161 new->abr_type = OSPF_ABR_DEFAULT;
paul718e3742002-12-13 20:15:29 +0000162 new->oiflist = list_new ();
163 new->vlinks = list_new ();
164 new->areas = list_new ();
165 new->areas->cmp = (int (*)(void *, void *)) ospf_area_id_cmp;
166 new->networks = route_table_init ();
167 new->nbr_nbma = route_table_init ();
168
169 new->lsdb = ospf_lsdb_new ();
170
171 new->default_originate = DEFAULT_ORIGINATE_NONE;
172
173 new->new_external_route = route_table_init ();
174 new->old_external_route = route_table_init ();
175 new->external_lsas = route_table_init ();
paul88d6cf32005-10-29 12:50:09 +0000176
177 new->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paul31a59762005-11-14 11:11:11 +0000178 new->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paul88d6cf32005-10-29 12:50:09 +0000179
paul718e3742002-12-13 20:15:29 +0000180 /* Distribute parameter init. */
181 for (i = 0; i <= ZEBRA_ROUTE_MAX; i++)
182 {
183 new->dmetric[i].type = -1;
184 new->dmetric[i].value = -1;
185 }
186 new->default_metric = -1;
187 new->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
188
189 /* SPF timer value init. */
190 new->spf_delay = OSPF_SPF_DELAY_DEFAULT;
191 new->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
pauld24f6e22005-10-21 09:23:12 +0000192 new->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT;
193 new->spf_hold_multiplier = 1;
paul718e3742002-12-13 20:15:29 +0000194
195 /* MaxAge init. */
196 new->maxage_lsa = list_new ();
197 new->t_maxage_walker =
198 thread_add_timer (master, ospf_lsa_maxage_walker,
paul68980082003-03-25 05:07:42 +0000199 new, OSPF_LSA_MAXAGE_CHECK_INTERVAL);
paul718e3742002-12-13 20:15:29 +0000200
201 /* Distance table init. */
202 new->distance_table = route_table_init ();
203
204 new->lsa_refresh_queue.index = 0;
205 new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
206 new->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker,
207 new, new->lsa_refresh_interval);
208 new->lsa_refresher_started = time (NULL);
209
ajs5c333492005-02-23 15:43:01 +0000210 if ((new->fd = ospf_sock_init()) < 0)
211 {
212 zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
213 "a socket");
214 exit(1);
215 }
216 if ((new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE+1)) == NULL)
217 {
218 zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
219 OSPF_MAX_PACKET_SIZE+1);
220 exit(1);
221 }
222 new->t_read = thread_add_read (master, ospf_read, new, new->fd);
paul718e3742002-12-13 20:15:29 +0000223 new->oi_write_q = list_new ();
224
225 return new;
226}
227
228struct ospf *
paul020709f2003-04-04 02:44:16 +0000229ospf_lookup ()
230{
231 if (listcount (om->ospf) == 0)
232 return NULL;
233
paul1eb8ef22005-04-07 07:30:20 +0000234 return listgetdata (listhead (om->ospf));
paul020709f2003-04-04 02:44:16 +0000235}
236
paul4dadc292005-05-06 21:37:42 +0000237static void
paul020709f2003-04-04 02:44:16 +0000238ospf_add (struct ospf *ospf)
239{
240 listnode_add (om->ospf, ospf);
241}
242
paul4dadc292005-05-06 21:37:42 +0000243static void
paul020709f2003-04-04 02:44:16 +0000244ospf_delete (struct ospf *ospf)
245{
246 listnode_delete (om->ospf, ospf);
247}
248
249struct ospf *
paul718e3742002-12-13 20:15:29 +0000250ospf_get ()
251{
paul020709f2003-04-04 02:44:16 +0000252 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000253
paul020709f2003-04-04 02:44:16 +0000254 ospf = ospf_lookup ();
255 if (ospf == NULL)
256 {
257 ospf = ospf_new ();
258 ospf_add (ospf);
paul718e3742002-12-13 20:15:29 +0000259
paul020709f2003-04-04 02:44:16 +0000260 if (ospf->router_id_static.s_addr == 0)
261 ospf_router_id_update (ospf);
paul718e3742002-12-13 20:15:29 +0000262
263#ifdef HAVE_OPAQUE_LSA
paul020709f2003-04-04 02:44:16 +0000264 ospf_opaque_type11_lsa_init (ospf);
paul718e3742002-12-13 20:15:29 +0000265#endif /* HAVE_OPAQUE_LSA */
paul020709f2003-04-04 02:44:16 +0000266 }
paul68980082003-03-25 05:07:42 +0000267
268 return ospf;
paul718e3742002-12-13 20:15:29 +0000269}
paul88d6cf32005-10-29 12:50:09 +0000270
271/* Handle the second half of graceful shutdown. This is called either
272 * from the graceful-shutdown timer thread, or directly through
273 * ospf_graceful_shutdown_check.
274 *
275 * Function is to cleanup G-R state, if required then call ospf_finish_final
276 * to complete shutdown of this ospf instance. Possibly exit if the
277 * whole process is being shutdown and this was the last OSPF instance.
278 */
279static void
280ospf_graceful_shutdown_finish (struct ospf *ospf)
281{
282 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
283 OSPF_TIMER_OFF (ospf->t_graceful_shutdown);
284
285 ospf_finish_final (ospf);
286
287 /* *ospf is now invalid */
288
289 /* ospfd being shut-down? If so, was this the last ospf instance? */
290 if (CHECK_FLAG (om->options, OSPF_MASTER_SHUTDOWN)
291 && (listcount (om->ospf) == 0))
292 exit (0);
293
294 return;
295}
296
297/* Timer thread for G-R */
298static int
299ospf_graceful_shutdown_timer (struct thread *t)
300{
301 struct ospf *ospf = THREAD_ARG(t);
302
303 ospf_graceful_shutdown_finish (ospf);
304
305 return 0;
306}
307
308/* Check whether graceful-shutdown must be scheduled, otherwise call
309 * down directly into second-half of instance shutdown.
310 */
311static void
312ospf_graceful_shutdown_check (struct ospf *ospf)
313{
314 unsigned long timeout;
315 struct listnode *ln;
316 struct ospf_area *area;
317
318 /* graceful shutdown already running? */
319 if (ospf->t_graceful_shutdown)
320 return;
321
322 /* Should we try push out max-metric LSAs? */
323 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
324 {
325 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
326 {
327 SET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
328
329 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
330 ospf_router_lsa_timer_add (area);
331 }
332 timeout = ospf->stub_router_shutdown_time;
333 }
334 else
335 /* No timer needed */
336 return ospf_graceful_shutdown_finish (ospf);
337
338 OSPF_TIMER_ON (ospf->t_graceful_shutdown, ospf_graceful_shutdown_timer,
339 timeout);
340 return;
341}
342
343/* Shut down the entire process */
344void
345ospf_terminate (void)
346{
347 struct ospf *ospf;
348 struct listnode *node, *nnode;
349
350 /* shutdown already in progress */
351 if (CHECK_FLAG (om->options, OSPF_MASTER_SHUTDOWN))
352 return;
353
354 SET_FLAG (om->options, OSPF_MASTER_SHUTDOWN);
355
356 for (ALL_LIST_ELEMENTS (om->ospf, node, nnode, ospf))
357 ospf_finish (ospf);
358
359 /* Deliberately go back up, hopefully to thread scheduler, as
360 * One or more ospf_finish()'s may have deferred shutdown to a timer
361 * thread
362 */
363}
paul718e3742002-12-13 20:15:29 +0000364
365void
366ospf_finish (struct ospf *ospf)
367{
paul88d6cf32005-10-29 12:50:09 +0000368 /* let graceful shutdown decide */
369 return ospf_graceful_shutdown_check (ospf);
370
371 /* if ospf_graceful_shutdown returns, then ospf_finish_final is
372 * deferred to expiry of G-S timer thread. Return back up, hopefully
373 * to thread scheduler.
374 */
375}
376
377/* Final cleanup of ospf instance */
378static void
379ospf_finish_final (struct ospf *ospf)
380{
paul718e3742002-12-13 20:15:29 +0000381 struct route_node *rn;
382 struct ospf_nbr_nbma *nbr_nbma;
paul68980082003-03-25 05:07:42 +0000383 struct ospf_lsa *lsa;
paul1eb8ef22005-04-07 07:30:20 +0000384 struct ospf_interface *oi;
385 struct ospf_area *area;
386 struct ospf_vl_data *vl_data;
387 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000388 int i;
389
390#ifdef HAVE_OPAQUE_LSA
391 ospf_opaque_type11_lsa_term (ospf);
392#endif /* HAVE_OPAQUE_LSA */
paul88d6cf32005-10-29 12:50:09 +0000393
394 /* be nice if this worked, but it doesn't */
395 /*ospf_flush_self_originated_lsas_now (ospf);*/
396
397 /* Unregister redistribution */
paul718e3742002-12-13 20:15:29 +0000398 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
paul020709f2003-04-04 02:44:16 +0000399 ospf_redistribute_unset (ospf, i);
paul718e3742002-12-13 20:15:29 +0000400
paul1eb8ef22005-04-07 07:30:20 +0000401 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
402 ospf_remove_vls_through_area (ospf, area);
paul718e3742002-12-13 20:15:29 +0000403
paul1eb8ef22005-04-07 07:30:20 +0000404 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
405 ospf_vl_delete (ospf, vl_data);
paul718e3742002-12-13 20:15:29 +0000406
407 list_delete (ospf->vlinks);
408
409 /* Reset interface. */
paul1eb8ef22005-04-07 07:30:20 +0000410 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
411 ospf_if_free (oi);
paul718e3742002-12-13 20:15:29 +0000412
413 /* Clear static neighbors */
414 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
415 if ((nbr_nbma = rn->info))
416 {
417 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
418
419 if (nbr_nbma->nbr)
420 {
421 nbr_nbma->nbr->nbr_nbma = NULL;
422 nbr_nbma->nbr = NULL;
423 }
424
425 if (nbr_nbma->oi)
426 {
427 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
428 nbr_nbma->oi = NULL;
429 }
430
431 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
432 }
433
434 route_table_finish (ospf->nbr_nbma);
435
436 /* Clear networks and Areas. */
437 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
438 {
439 struct ospf_network *network;
440
441 if ((network = rn->info) != NULL)
442 {
paul68980082003-03-25 05:07:42 +0000443 ospf_network_free (ospf, network);
paul718e3742002-12-13 20:15:29 +0000444 rn->info = NULL;
445 route_unlock_node (rn);
446 }
447 }
448
paul1eb8ef22005-04-07 07:30:20 +0000449 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000450 {
paul718e3742002-12-13 20:15:29 +0000451 listnode_delete (ospf->areas, area);
452 ospf_area_free (area);
453 }
454
455 /* Cancel all timers. */
456 OSPF_TIMER_OFF (ospf->t_external_lsa);
457 OSPF_TIMER_OFF (ospf->t_router_id_update);
458 OSPF_TIMER_OFF (ospf->t_router_lsa_update);
459 OSPF_TIMER_OFF (ospf->t_spf_calc);
460 OSPF_TIMER_OFF (ospf->t_ase_calc);
461 OSPF_TIMER_OFF (ospf->t_maxage);
462 OSPF_TIMER_OFF (ospf->t_maxage_walker);
463 OSPF_TIMER_OFF (ospf->t_abr_task);
paul88d6cf32005-10-29 12:50:09 +0000464 OSPF_TIMER_OFF (ospf->t_asbr_check);
paul718e3742002-12-13 20:15:29 +0000465 OSPF_TIMER_OFF (ospf->t_distribute_update);
466 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
467 OSPF_TIMER_OFF (ospf->t_read);
468 OSPF_TIMER_OFF (ospf->t_write);
paul31a59762005-11-14 11:11:11 +0000469#ifdef HAVE_OPAQUE_LSA
paul88d6cf32005-10-29 12:50:09 +0000470 OSPF_TIMER_OFF (ospf->t_opaque_lsa_self);
paul31a59762005-11-14 11:11:11 +0000471#endif
paul718e3742002-12-13 20:15:29 +0000472
473 close (ospf->fd);
ajs5c333492005-02-23 15:43:01 +0000474 stream_free(ospf->ibuf);
paul718e3742002-12-13 20:15:29 +0000475
476#ifdef HAVE_OPAQUE_LSA
paul68980082003-03-25 05:07:42 +0000477 LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa)
478 ospf_discard_from_db (ospf, ospf->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000479#endif /* HAVE_OPAQUE_LSA */
paul68980082003-03-25 05:07:42 +0000480 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
481 ospf_discard_from_db (ospf, ospf->lsdb, lsa);
482
paul718e3742002-12-13 20:15:29 +0000483 ospf_lsdb_delete_all (ospf->lsdb);
484 ospf_lsdb_free (ospf->lsdb);
485
paul1eb8ef22005-04-07 07:30:20 +0000486 for (ALL_LIST_ELEMENTS (ospf->maxage_lsa, node, nnode, lsa))
487 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000488
489 list_delete (ospf->maxage_lsa);
490
491 if (ospf->old_table)
492 ospf_route_table_free (ospf->old_table);
493 if (ospf->new_table)
494 {
495 ospf_route_delete (ospf->new_table);
496 ospf_route_table_free (ospf->new_table);
497 }
498 if (ospf->old_rtrs)
499 ospf_rtrs_free (ospf->old_rtrs);
500 if (ospf->new_rtrs)
501 ospf_rtrs_free (ospf->new_rtrs);
502 if (ospf->new_external_route)
503 {
504 ospf_route_delete (ospf->new_external_route);
505 ospf_route_table_free (ospf->new_external_route);
506 }
507 if (ospf->old_external_route)
508 {
509 ospf_route_delete (ospf->old_external_route);
510 ospf_route_table_free (ospf->old_external_route);
511 }
512 if (ospf->external_lsas)
513 {
514 ospf_ase_external_lsas_finish (ospf->external_lsas);
515 }
516
517 list_delete (ospf->areas);
518
519 for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++)
520 if (EXTERNAL_INFO (i) != NULL)
521 for (rn = route_top (EXTERNAL_INFO (i)); rn; rn = route_next (rn))
522 {
523 if (rn->info == NULL)
524 continue;
525
526 XFREE (MTYPE_OSPF_EXTERNAL_INFO, rn->info);
527 rn->info = NULL;
528 route_unlock_node (rn);
529 }
530
paul68980082003-03-25 05:07:42 +0000531 ospf_distance_reset (ospf);
paul718e3742002-12-13 20:15:29 +0000532 route_table_finish (ospf->distance_table);
533
paul020709f2003-04-04 02:44:16 +0000534 ospf_delete (ospf);
paul718e3742002-12-13 20:15:29 +0000535
paul020709f2003-04-04 02:44:16 +0000536 XFREE (MTYPE_OSPF_TOP, ospf);
paul718e3742002-12-13 20:15:29 +0000537}
538
539
540/* allocate new OSPF Area object */
paul4dadc292005-05-06 21:37:42 +0000541static struct ospf_area *
paul68980082003-03-25 05:07:42 +0000542ospf_area_new (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000543{
544 struct ospf_area *new;
545
546 /* Allocate new config_network. */
547 new = XCALLOC (MTYPE_OSPF_AREA, sizeof (struct ospf_area));
548
paul68980082003-03-25 05:07:42 +0000549 new->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000550
551 new->area_id = area_id;
552
553 new->external_routing = OSPF_AREA_DEFAULT;
554 new->default_cost = 1;
555 new->auth_type = OSPF_AUTH_NULL;
paul88d6cf32005-10-29 12:50:09 +0000556
paul718e3742002-12-13 20:15:29 +0000557 /* New LSDB init. */
558 new->lsdb = ospf_lsdb_new ();
559
560 /* Self-originated LSAs initialize. */
561 new->router_lsa_self = NULL;
562
563#ifdef HAVE_OPAQUE_LSA
564 ospf_opaque_type10_lsa_init (new);
565#endif /* HAVE_OPAQUE_LSA */
566
567 new->oiflist = list_new ();
568 new->ranges = route_table_init ();
569
570 if (area_id.s_addr == OSPF_AREA_BACKBONE)
paul68980082003-03-25 05:07:42 +0000571 ospf->backbone = new;
paul718e3742002-12-13 20:15:29 +0000572
573 return new;
574}
575
576void
577ospf_area_free (struct ospf_area *area)
578{
paul68980082003-03-25 05:07:42 +0000579 struct route_node *rn;
580 struct ospf_lsa *lsa;
581
paul718e3742002-12-13 20:15:29 +0000582 /* Free LSDBs. */
paul68980082003-03-25 05:07:42 +0000583 LSDB_LOOP (ROUTER_LSDB (area), rn, lsa)
584 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
585 LSDB_LOOP (NETWORK_LSDB (area), rn, lsa)
586 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
587 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
588 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
589 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
590 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000591
paul68980082003-03-25 05:07:42 +0000592 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
593 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000594#ifdef HAVE_OPAQUE_LSA
paul68980082003-03-25 05:07:42 +0000595 LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa)
596 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
597 LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa)
598 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000599#endif /* HAVE_OPAQUE_LSA */
600
601 ospf_lsdb_delete_all (area->lsdb);
602 ospf_lsdb_free (area->lsdb);
603
paul718e3742002-12-13 20:15:29 +0000604 ospf_lsa_unlock (area->router_lsa_self);
605
606 route_table_finish (area->ranges);
607 list_delete (area->oiflist);
608
609 if (EXPORT_NAME (area))
610 free (EXPORT_NAME (area));
611
612 if (IMPORT_NAME (area))
613 free (IMPORT_NAME (area));
614
615 /* Cancel timer. */
616 OSPF_TIMER_OFF (area->t_router_lsa_self);
paul88d6cf32005-10-29 12:50:09 +0000617 OSPF_TIMER_OFF (area->t_stub_router);
618#ifdef HAVE_OPAQUE_LSA
619 OSPF_TIMER_OFF (area->t_opaque_lsa_self);
620#endif /* HAVE_OPAQUE_LSA */
621
paul718e3742002-12-13 20:15:29 +0000622 if (OSPF_IS_AREA_BACKBONE (area))
paul68980082003-03-25 05:07:42 +0000623 area->ospf->backbone = NULL;
paul718e3742002-12-13 20:15:29 +0000624
625 XFREE (MTYPE_OSPF_AREA, area);
626}
627
628void
paul68980082003-03-25 05:07:42 +0000629ospf_area_check_free (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000630{
631 struct ospf_area *area;
632
paul68980082003-03-25 05:07:42 +0000633 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000634 if (area &&
635 listcount (area->oiflist) == 0 &&
636 area->ranges->top == NULL &&
637 area->shortcut_configured == OSPF_SHORTCUT_DEFAULT &&
638 area->external_routing == OSPF_AREA_DEFAULT &&
639 area->no_summary == 0 &&
640 area->default_cost == 1 &&
641 EXPORT_NAME (area) == NULL &&
642 IMPORT_NAME (area) == NULL &&
643 area->auth_type == OSPF_AUTH_NULL)
644 {
paul68980082003-03-25 05:07:42 +0000645 listnode_delete (ospf->areas, area);
paul718e3742002-12-13 20:15:29 +0000646 ospf_area_free (area);
647 }
648}
649
650struct ospf_area *
paul68980082003-03-25 05:07:42 +0000651ospf_area_get (struct ospf *ospf, struct in_addr area_id, int format)
paul718e3742002-12-13 20:15:29 +0000652{
653 struct ospf_area *area;
654
paul68980082003-03-25 05:07:42 +0000655 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000656 if (!area)
657 {
paul68980082003-03-25 05:07:42 +0000658 area = ospf_area_new (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000659 area->format = format;
paul68980082003-03-25 05:07:42 +0000660 listnode_add_sort (ospf->areas, area);
661 ospf_check_abr_status (ospf);
paul718e3742002-12-13 20:15:29 +0000662 }
663
664 return area;
665}
666
667struct ospf_area *
paul68980082003-03-25 05:07:42 +0000668ospf_area_lookup_by_area_id (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000669{
670 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +0000671 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000672
paul1eb8ef22005-04-07 07:30:20 +0000673 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
674 if (IPV4_ADDR_SAME (&area->area_id, &area_id))
675 return area;
paul718e3742002-12-13 20:15:29 +0000676
677 return NULL;
678}
679
680void
681ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi)
682{
683 listnode_add (area->oiflist, oi);
684}
685
686void
687ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi)
688{
689 listnode_delete (area->oiflist, oi);
690}
691
692
693/* Config network statement related functions. */
paul4dadc292005-05-06 21:37:42 +0000694static struct ospf_network *
paul718e3742002-12-13 20:15:29 +0000695ospf_network_new (struct in_addr area_id, int format)
696{
697 struct ospf_network *new;
698 new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network));
699
700 new->area_id = area_id;
701 new->format = format;
702
703 return new;
704}
705
706void
paul68980082003-03-25 05:07:42 +0000707ospf_network_free (struct ospf *ospf, struct ospf_network *network)
paul718e3742002-12-13 20:15:29 +0000708{
paul68980082003-03-25 05:07:42 +0000709 ospf_area_check_free (ospf, network->area_id);
710 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000711 XFREE (MTYPE_OSPF_NETWORK, network);
712}
713
714int
715ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p,
716 struct in_addr area_id)
717{
718 struct ospf_network *network;
719 struct ospf_area *area;
720 struct route_node *rn;
721 struct external_info *ei;
paul147193a2003-04-19 00:31:59 +0000722 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000723
724 rn = route_node_get (ospf->networks, (struct prefix *)p);
725 if (rn->info)
726 {
727 /* There is already same network statement. */
728 route_unlock_node (rn);
729 return 0;
730 }
731
732 rn->info = network = ospf_network_new (area_id, ret);
paul68980082003-03-25 05:07:42 +0000733 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000734
735 /* Run network config now. */
736 ospf_network_run (ospf, (struct prefix *)p, area);
737
738 /* Update connected redistribute. */
739 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
740 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
741 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
742 rn; rn = route_next (rn))
743 if ((ei = rn->info) != NULL)
paul68980082003-03-25 05:07:42 +0000744 if (ospf_external_info_find_lsa (ospf, &ei->p))
745 if (!ospf_distribute_check_connected (ospf, ei))
746 ospf_external_lsa_flush (ospf, ei->type, &ei->p,
ajs5339cfd2005-09-19 13:28:05 +0000747 ei->ifindex /*, ei->nexthop */);
paul718e3742002-12-13 20:15:29 +0000748
paul68980082003-03-25 05:07:42 +0000749 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000750
751 return 1;
752}
753
754int
755ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
756 struct in_addr area_id)
757{
758 struct route_node *rn;
759 struct ospf_network *network;
760 struct external_info *ei;
761
762 rn = route_node_lookup (ospf->networks, (struct prefix *)p);
763 if (rn == NULL)
764 return 0;
765
766 network = rn->info;
767 if (!IPV4_ADDR_SAME (&area_id, &network->area_id))
768 return 0;
769
paul68980082003-03-25 05:07:42 +0000770 ospf_network_free (ospf, rn->info);
paul718e3742002-12-13 20:15:29 +0000771 rn->info = NULL;
772 route_unlock_node (rn);
773
paul68980082003-03-25 05:07:42 +0000774 ospf_if_update (ospf);
paul718e3742002-12-13 20:15:29 +0000775
776 /* Update connected redistribute. */
777 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
778 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
779 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
780 rn; rn = route_next (rn))
781 if ((ei = rn->info) != NULL)
paul68980082003-03-25 05:07:42 +0000782 if (!ospf_external_info_find_lsa (ospf, &ei->p))
783 if (ospf_distribute_check_connected (ospf, ei))
784 ospf_external_lsa_originate (ospf, ei);
paul718e3742002-12-13 20:15:29 +0000785
786 return 1;
787}
788
paul570f7592003-01-25 06:47:41 +0000789/* Check whether interface matches given network
790 * returns: 1, true. 0, false
791 */
792int
793ospf_network_match_iface(struct connected *co, struct prefix *net)
794{
795 /* Behaviour to match both Cisco where:
796 * iface address lies within network specified -> ospf
797 * and zebra 0.9[2ish-3]:
798 * PtP special case: network specified == iface peer addr -> ospf
799 */
gdt8f40e892003-12-05 14:01:43 +0000800
paulf3ae74c2004-11-04 20:35:31 +0000801 /* For PtP, match if peer address matches network address exactly.
802 * This can be addr/32 or addr/p for p < 32, but the addr must match
803 * exactly; this is not a test for falling within the prefix. This
gdt8f40e892003-12-05 14:01:43 +0000804 * test is solely for compatibility with zebra.
gdt8f40e892003-12-05 14:01:43 +0000805 */
paulf3ae74c2004-11-04 20:35:31 +0000806 if (if_is_pointopoint (co->ifp) && co->destination &&
807 IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
808 return 1;
809
810#if 0
811 /* Decline to accept PtP if dst address does not match the
812 * prefix. (ifdefed out because this is a workaround, not the
813 * desired behavior.) */
814 if (if_is_pointopoint (co->ifp) &&
815 ! prefix_match (net, co->destination))
816 return 0;
817#endif
818
819 /* If the address is within the prefix, accept. Note that this
820 * applies to PtP as well as other types.
821 */
822 if (prefix_match (net, co->address))
823 return 1;
824
825 return 0; /* no match */
paul570f7592003-01-25 06:47:41 +0000826}
827
paul718e3742002-12-13 20:15:29 +0000828void
829ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area)
830{
831 struct interface *ifp;
paul1eb8ef22005-04-07 07:30:20 +0000832 struct connected *co;
hasso52dc7ee2004-09-23 19:18:23 +0000833 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000834
835 /* Schedule Router ID Update. */
836 if (ospf->router_id_static.s_addr == 0)
837 if (ospf->t_router_id_update == NULL)
838 {
paul020709f2003-04-04 02:44:16 +0000839 OSPF_TIMER_ON (ospf->t_router_id_update, ospf_router_id_update_timer,
840 OSPF_ROUTER_ID_UPDATE_DELAY);
paul718e3742002-12-13 20:15:29 +0000841 }
842
843 /* Get target interface. */
paul1eb8ef22005-04-07 07:30:20 +0000844 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
paul718e3742002-12-13 20:15:29 +0000845 {
paul1eb8ef22005-04-07 07:30:20 +0000846 struct listnode *cnode;
paul718e3742002-12-13 20:15:29 +0000847
paul718e3742002-12-13 20:15:29 +0000848 if (memcmp (ifp->name, "VLINK", 5) == 0)
849 continue;
850
851 /* if interface prefix is match specified prefix,
852 then create socket and join multicast group. */
paul1eb8ef22005-04-07 07:30:20 +0000853 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, co))
paul718e3742002-12-13 20:15:29 +0000854 {
paul718e3742002-12-13 20:15:29 +0000855 struct prefix *addr;
paul800dc102003-03-28 01:51:40 +0000856
paule7b050c2003-04-07 06:38:02 +0000857 if (CHECK_FLAG(co->flags,ZEBRA_IFA_SECONDARY))
858 continue;
paul718e3742002-12-13 20:15:29 +0000859
hasso3fb9cd62004-10-19 19:44:43 +0000860 if (CONNECTED_POINTOPOINT_HOST(co))
paul718e3742002-12-13 20:15:29 +0000861 addr = co->destination;
862 else
863 addr = co->address;
864
paulcb3f37d2003-02-18 23:26:37 +0000865 if (p->family == co->address->family
paul68980082003-03-25 05:07:42 +0000866 && ! ospf_if_is_configured (ospf, &(addr->u.prefix4))
paulcb3f37d2003-02-18 23:26:37 +0000867 && ospf_network_match_iface(co,p))
paul570f7592003-01-25 06:47:41 +0000868 {
paul1eb8ef22005-04-07 07:30:20 +0000869 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000870
paul68980082003-03-25 05:07:42 +0000871 oi = ospf_if_new (ospf, ifp, co->address);
paul718e3742002-12-13 20:15:29 +0000872 oi->connected = co;
873
874 oi->nbr_self->address = *oi->address;
875
paul718e3742002-12-13 20:15:29 +0000876 oi->area = area;
877
878 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
879 oi->output_cost = ospf_if_get_output_cost (oi);
880
881 if (area->external_routing != OSPF_AREA_DEFAULT)
882 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
883 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
884
885 /* Add pseudo neighbor. */
886 ospf_nbr_add_self (oi);
887
888 /* Make sure pseudo neighbor's router_id. */
paul68980082003-03-25 05:07:42 +0000889 oi->nbr_self->router_id = ospf->router_id;
paul718e3742002-12-13 20:15:29 +0000890 oi->nbr_self->src = oi->address->u.prefix4;
891
892 /* Relate ospf interface to ospf instance. */
paul68980082003-03-25 05:07:42 +0000893 oi->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000894
895 /* update network type as interface flag */
896 /* If network type is specified previously,
897 skip network type setting. */
898 oi->type = IF_DEF_PARAMS (ifp)->type;
899
900 /* Set area flag. */
901 switch (area->external_routing)
902 {
903 case OSPF_AREA_DEFAULT:
904 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
905 break;
906 case OSPF_AREA_STUB:
907 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
908 break;
paul718e3742002-12-13 20:15:29 +0000909 case OSPF_AREA_NSSA:
910 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
911 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
912 break;
paul718e3742002-12-13 20:15:29 +0000913 }
914
915 ospf_area_add_if (oi->area, oi);
916
paul2e3b2e42002-12-13 21:03:13 +0000917 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000918 ospf_if_up (oi);
919
920 break;
921 }
922 }
923 }
924}
925
926void
927ospf_ls_upd_queue_empty (struct ospf_interface *oi)
928{
929 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000930 struct listnode *node, *nnode;
hasso52dc7ee2004-09-23 19:18:23 +0000931 struct list *lst;
paul718e3742002-12-13 20:15:29 +0000932 struct ospf_lsa *lsa;
933
934 /* empty ls update queue */
935 for (rn = route_top (oi->ls_upd_queue); rn;
936 rn = route_next (rn))
hasso52dc7ee2004-09-23 19:18:23 +0000937 if ((lst = (struct list *) rn->info))
paul718e3742002-12-13 20:15:29 +0000938 {
paul1eb8ef22005-04-07 07:30:20 +0000939 for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa))
940 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000941 list_free (lst);
942 rn->info = NULL;
943 }
944
945 /* remove update event */
946 if (oi->t_ls_upd_event)
947 {
948 thread_cancel (oi->t_ls_upd_event);
949 oi->t_ls_upd_event = NULL;
950 }
951}
952
953void
paul68980082003-03-25 05:07:42 +0000954ospf_if_update (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000955{
956 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000957 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000958 struct ospf_network *network;
959 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000960 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000961
paul68980082003-03-25 05:07:42 +0000962 if (ospf != NULL)
paul718e3742002-12-13 20:15:29 +0000963 {
964 /* Update Router ID scheduled. */
paul68980082003-03-25 05:07:42 +0000965 if (ospf->router_id_static.s_addr == 0)
966 if (ospf->t_router_id_update == NULL)
paul718e3742002-12-13 20:15:29 +0000967 {
paul020709f2003-04-04 02:44:16 +0000968 OSPF_TIMER_ON (ospf->t_router_id_update,
969 ospf_router_id_update_timer,
970 OSPF_ROUTER_ID_UPDATE_DELAY);
paul718e3742002-12-13 20:15:29 +0000971 }
972
973 /* Find interfaces that not configured already. */
paul1eb8ef22005-04-07 07:30:20 +0000974 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +0000975 {
976 int found = 0;
paul718e3742002-12-13 20:15:29 +0000977 struct connected *co = oi->connected;
978
paul718e3742002-12-13 20:15:29 +0000979 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
980 continue;
981
paul68980082003-03-25 05:07:42 +0000982 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000983 {
984 if (rn->info == NULL)
985 continue;
986
paul570f7592003-01-25 06:47:41 +0000987 if (ospf_network_match_iface(co,&rn->p))
paul718e3742002-12-13 20:15:29 +0000988 {
989 found = 1;
990 route_unlock_node (rn);
991 break;
992 }
993 }
994
995 if (found == 0)
996 ospf_if_free (oi);
997 }
998
999 /* Run each interface. */
paul68980082003-03-25 05:07:42 +00001000 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +00001001 if (rn->info != NULL)
1002 {
1003 network = (struct ospf_network *) rn->info;
paul68980082003-03-25 05:07:42 +00001004 area = ospf_area_get (ospf, network->area_id, network->format);
1005 ospf_network_run (ospf, &rn->p, area);
paul718e3742002-12-13 20:15:29 +00001006 }
1007 }
1008}
1009
1010void
paul68980082003-03-25 05:07:42 +00001011ospf_remove_vls_through_area (struct ospf *ospf, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +00001012{
paul1eb8ef22005-04-07 07:30:20 +00001013 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001014 struct ospf_vl_data *vl_data;
1015
paul1eb8ef22005-04-07 07:30:20 +00001016 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
1017 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
1018 ospf_vl_delete (ospf, vl_data);
paul718e3742002-12-13 20:15:29 +00001019}
1020
1021
1022struct message ospf_area_type_msg[] =
1023{
1024 { OSPF_AREA_DEFAULT, "Default" },
1025 { OSPF_AREA_STUB, "Stub" },
1026 { OSPF_AREA_NSSA, "NSSA" },
1027};
1028int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX;
1029
paul4dadc292005-05-06 21:37:42 +00001030static void
paul718e3742002-12-13 20:15:29 +00001031ospf_area_type_set (struct ospf_area *area, int type)
1032{
hasso52dc7ee2004-09-23 19:18:23 +00001033 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001034 struct ospf_interface *oi;
1035
1036 if (area->external_routing == type)
1037 {
1038 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +00001039 zlog_debug ("Area[%s]: Types are the same, ignored.",
paul718e3742002-12-13 20:15:29 +00001040 inet_ntoa (area->area_id));
1041 return;
1042 }
1043
1044 area->external_routing = type;
1045
1046 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +00001047 zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area->area_id),
paul718e3742002-12-13 20:15:29 +00001048 LOOKUP (ospf_area_type_msg, type));
1049
1050 switch (area->external_routing)
1051 {
1052 case OSPF_AREA_DEFAULT:
paul1eb8ef22005-04-07 07:30:20 +00001053 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1054 if (oi->nbr_self != NULL)
1055 {
1056 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1057 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1058 }
paul718e3742002-12-13 20:15:29 +00001059 break;
1060 case OSPF_AREA_STUB:
paul1eb8ef22005-04-07 07:30:20 +00001061 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1062 if (oi->nbr_self != NULL)
1063 {
1064 if (IS_DEBUG_OSPF_EVENT)
1065 zlog_debug ("setting options on %s accordingly", IF_NAME (oi));
1066 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1067 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1068 if (IS_DEBUG_OSPF_EVENT)
1069 zlog_debug ("options set on %s: %x",
1070 IF_NAME (oi), OPTIONS (oi));
1071 }
paul718e3742002-12-13 20:15:29 +00001072 break;
1073 case OSPF_AREA_NSSA:
paul1eb8ef22005-04-07 07:30:20 +00001074 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1075 if (oi->nbr_self != NULL)
1076 {
1077 zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi));
1078 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1079 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1080 zlog_debug ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi));
1081 }
paul718e3742002-12-13 20:15:29 +00001082 break;
1083 default:
1084 break;
1085 }
1086
1087 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001088 ospf_schedule_abr_task (area->ospf);
paul718e3742002-12-13 20:15:29 +00001089}
1090
1091int
paul68980082003-03-25 05:07:42 +00001092ospf_area_shortcut_set (struct ospf *ospf, struct ospf_area *area, int mode)
paul718e3742002-12-13 20:15:29 +00001093{
1094 if (area->shortcut_configured == mode)
1095 return 0;
1096
1097 area->shortcut_configured = mode;
1098 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001099 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001100
paul68980082003-03-25 05:07:42 +00001101 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001102
1103 return 1;
1104}
1105
1106int
paul68980082003-03-25 05:07:42 +00001107ospf_area_shortcut_unset (struct ospf *ospf, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +00001108{
1109 area->shortcut_configured = OSPF_SHORTCUT_DEFAULT;
1110 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001111 ospf_area_check_free (ospf, area->area_id);
1112 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001113
1114 return 1;
1115}
1116
paul4dadc292005-05-06 21:37:42 +00001117static int
paul718e3742002-12-13 20:15:29 +00001118ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area)
1119{
1120 struct ospf_vl_data *vl;
hasso52dc7ee2004-09-23 19:18:23 +00001121 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001122 int count = 0;
1123
paul1eb8ef22005-04-07 07:30:20 +00001124 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl))
1125 if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id))
1126 count++;
paul718e3742002-12-13 20:15:29 +00001127
1128 return count;
1129}
1130
1131int
1132ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id)
1133{
1134 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001135 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001136
paul68980082003-03-25 05:07:42 +00001137 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001138 if (ospf_area_vlink_count (ospf, area))
1139 return 0;
1140
1141 if (area->external_routing != OSPF_AREA_STUB)
1142 ospf_area_type_set (area, OSPF_AREA_STUB);
1143
1144 return 1;
1145}
1146
1147int
1148ospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id)
1149{
1150 struct ospf_area *area;
1151
paul68980082003-03-25 05:07:42 +00001152 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001153 if (area == NULL)
1154 return 1;
1155
1156 if (area->external_routing == OSPF_AREA_STUB)
1157 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1158
paul68980082003-03-25 05:07:42 +00001159 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001160
1161 return 1;
1162}
1163
1164int
1165ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id)
1166{
1167 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001168 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001169
paul68980082003-03-25 05:07:42 +00001170 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001171 area->no_summary = 1;
1172
1173 return 1;
1174}
1175
1176int
1177ospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id)
1178{
1179 struct ospf_area *area;
1180
paul68980082003-03-25 05:07:42 +00001181 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001182 if (area == NULL)
1183 return 0;
1184
1185 area->no_summary = 0;
paul68980082003-03-25 05:07:42 +00001186 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001187
1188 return 1;
1189}
1190
1191int
1192ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id)
1193{
1194 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001195 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001196
paul68980082003-03-25 05:07:42 +00001197 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001198 if (ospf_area_vlink_count (ospf, area))
1199 return 0;
1200
1201 if (area->external_routing != OSPF_AREA_NSSA)
1202 {
1203 ospf_area_type_set (area, OSPF_AREA_NSSA);
1204 ospf->anyNSSA++;
1205 }
1206
paul084c7842003-06-22 08:35:18 +00001207 /* set NSSA area defaults */
1208 area->no_summary = 0;
1209 area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
pauld4a53d52003-07-12 21:30:57 +00001210 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paul084c7842003-06-22 08:35:18 +00001211 area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT;
1212
paul718e3742002-12-13 20:15:29 +00001213 return 1;
1214}
1215
1216int
1217ospf_area_nssa_unset (struct ospf *ospf, struct in_addr area_id)
1218{
1219 struct ospf_area *area;
1220
paul68980082003-03-25 05:07:42 +00001221 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001222 if (area == NULL)
1223 return 0;
1224
1225 if (area->external_routing == OSPF_AREA_NSSA)
1226 {
1227 ospf->anyNSSA--;
1228 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1229 }
1230
paul68980082003-03-25 05:07:42 +00001231 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001232
1233 return 1;
1234}
1235
1236int
1237ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id,
1238 int role)
1239{
1240 struct ospf_area *area;
1241
paul68980082003-03-25 05:07:42 +00001242 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001243 if (area == NULL)
1244 return 0;
1245
paul084c7842003-06-22 08:35:18 +00001246 area->NSSATranslatorRole = role;
paul718e3742002-12-13 20:15:29 +00001247
1248 return 1;
1249}
1250
paul4dadc292005-05-06 21:37:42 +00001251/* XXX: unused? Leave for symmetry? */
1252static int
paul718e3742002-12-13 20:15:29 +00001253ospf_area_nssa_translator_role_unset (struct ospf *ospf,
1254 struct in_addr area_id)
1255{
1256 struct ospf_area *area;
1257
paul68980082003-03-25 05:07:42 +00001258 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001259 if (area == NULL)
1260 return 0;
1261
paul084c7842003-06-22 08:35:18 +00001262 area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
paul718e3742002-12-13 20:15:29 +00001263
paul68980082003-03-25 05:07:42 +00001264 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001265
1266 return 1;
1267}
1268
1269int
paul68980082003-03-25 05:07:42 +00001270ospf_area_export_list_set (struct ospf *ospf,
paul6c835672004-10-11 11:00:30 +00001271 struct ospf_area *area, const char *list_name)
paul718e3742002-12-13 20:15:29 +00001272{
1273 struct access_list *list;
1274 list = access_list_lookup (AFI_IP, list_name);
1275
1276 EXPORT_LIST (area) = list;
1277
1278 if (EXPORT_NAME (area))
1279 free (EXPORT_NAME (area));
1280
1281 EXPORT_NAME (area) = strdup (list_name);
paul68980082003-03-25 05:07:42 +00001282 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001283
1284 return 1;
1285}
1286
1287int
paul68980082003-03-25 05:07:42 +00001288ospf_area_export_list_unset (struct ospf *ospf, struct ospf_area * area)
paul718e3742002-12-13 20:15:29 +00001289{
1290
1291 EXPORT_LIST (area) = 0;
1292
1293 if (EXPORT_NAME (area))
1294 free (EXPORT_NAME (area));
1295
1296 EXPORT_NAME (area) = NULL;
1297
paul68980082003-03-25 05:07:42 +00001298 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001299
paul68980082003-03-25 05:07:42 +00001300 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001301
1302 return 1;
1303}
1304
1305int
paul6c835672004-10-11 11:00:30 +00001306ospf_area_import_list_set (struct ospf *ospf, struct ospf_area *area,
1307 const char *name)
paul718e3742002-12-13 20:15:29 +00001308{
1309 struct access_list *list;
1310 list = access_list_lookup (AFI_IP, name);
1311
1312 IMPORT_LIST (area) = list;
1313
1314 if (IMPORT_NAME (area))
1315 free (IMPORT_NAME (area));
1316
1317 IMPORT_NAME (area) = strdup (name);
paul68980082003-03-25 05:07:42 +00001318 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001319
1320 return 1;
1321}
1322
1323int
paul68980082003-03-25 05:07:42 +00001324ospf_area_import_list_unset (struct ospf *ospf, struct ospf_area * area)
paul718e3742002-12-13 20:15:29 +00001325{
1326 IMPORT_LIST (area) = 0;
1327
1328 if (IMPORT_NAME (area))
1329 free (IMPORT_NAME (area));
1330
1331 IMPORT_NAME (area) = NULL;
paul68980082003-03-25 05:07:42 +00001332 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001333
paul68980082003-03-25 05:07:42 +00001334 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001335
1336 return 1;
1337}
1338
1339int
paul718e3742002-12-13 20:15:29 +00001340ospf_timers_refresh_set (struct ospf *ospf, int interval)
1341{
1342 int time_left;
1343
1344 if (ospf->lsa_refresh_interval == interval)
1345 return 1;
1346
1347 time_left = ospf->lsa_refresh_interval -
1348 (time (NULL) - ospf->lsa_refresher_started);
1349
1350 if (time_left > interval)
1351 {
1352 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1353 ospf->t_lsa_refresher =
1354 thread_add_timer (master, ospf_lsa_refresh_walker, ospf, interval);
1355 }
1356 ospf->lsa_refresh_interval = interval;
1357
1358 return 1;
1359}
1360
1361int
1362ospf_timers_refresh_unset (struct ospf *ospf)
1363{
1364 int time_left;
1365
1366 time_left = ospf->lsa_refresh_interval -
1367 (time (NULL) - ospf->lsa_refresher_started);
1368
1369 if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
1370 {
1371 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1372 ospf->t_lsa_refresher =
1373 thread_add_timer (master, ospf_lsa_refresh_walker, ospf,
1374 OSPF_LSA_REFRESH_INTERVAL_DEFAULT);
1375 }
1376
1377 ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
1378
1379 return 1;
1380}
1381
1382
paul4dadc292005-05-06 21:37:42 +00001383static struct ospf_nbr_nbma *
1384ospf_nbr_nbma_new (void)
paul718e3742002-12-13 20:15:29 +00001385{
1386 struct ospf_nbr_nbma *nbr_nbma;
1387
1388 nbr_nbma = XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC,
1389 sizeof (struct ospf_nbr_nbma));
1390 memset (nbr_nbma, 0, sizeof (struct ospf_nbr_nbma));
1391
1392 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1393 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1394
1395 return nbr_nbma;
1396}
1397
paul4dadc292005-05-06 21:37:42 +00001398static void
paul718e3742002-12-13 20:15:29 +00001399ospf_nbr_nbma_free (struct ospf_nbr_nbma *nbr_nbma)
1400{
1401 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
1402}
1403
paul4dadc292005-05-06 21:37:42 +00001404static void
paul718e3742002-12-13 20:15:29 +00001405ospf_nbr_nbma_delete (struct ospf *ospf, struct ospf_nbr_nbma *nbr_nbma)
1406{
1407 struct route_node *rn;
1408 struct prefix_ipv4 p;
1409
1410 p.family = AF_INET;
1411 p.prefix = nbr_nbma->addr;
1412 p.prefixlen = IPV4_MAX_BITLEN;
1413
1414 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1415 if (rn)
1416 {
1417 ospf_nbr_nbma_free (rn->info);
1418 rn->info = NULL;
1419 route_unlock_node (rn);
1420 route_unlock_node (rn);
1421 }
1422}
1423
paul4dadc292005-05-06 21:37:42 +00001424static void
paul718e3742002-12-13 20:15:29 +00001425ospf_nbr_nbma_down (struct ospf_nbr_nbma *nbr_nbma)
1426{
1427 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1428
1429 if (nbr_nbma->nbr)
1430 {
1431 nbr_nbma->nbr->nbr_nbma = NULL;
1432 OSPF_NSM_EVENT_EXECUTE (nbr_nbma->nbr, NSM_KillNbr);
1433 }
1434
1435 if (nbr_nbma->oi)
1436 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
1437}
1438
paul4dadc292005-05-06 21:37:42 +00001439static void
paul718e3742002-12-13 20:15:29 +00001440ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma,
1441 struct ospf_interface *oi)
1442{
1443 struct ospf_neighbor *nbr;
1444 struct route_node *rn;
1445 struct prefix p;
1446
1447 if (oi->type != OSPF_IFTYPE_NBMA)
1448 return;
1449
1450 if (nbr_nbma->nbr != NULL)
1451 return;
1452
1453 if (IPV4_ADDR_SAME (&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr))
1454 return;
1455
1456 nbr_nbma->oi = oi;
1457 listnode_add (oi->nbr_nbma, nbr_nbma);
1458
1459 /* Get neighbor information from table. */
1460 p.family = AF_INET;
1461 p.prefixlen = IPV4_MAX_BITLEN;
1462 p.u.prefix4 = nbr_nbma->addr;
1463
1464 rn = route_node_get (oi->nbrs, (struct prefix *)&p);
1465 if (rn->info)
1466 {
1467 nbr = rn->info;
1468 nbr->nbr_nbma = nbr_nbma;
1469 nbr_nbma->nbr = nbr;
1470
1471 route_unlock_node (rn);
1472 }
1473 else
1474 {
1475 nbr = rn->info = ospf_nbr_new (oi);
1476 nbr->state = NSM_Down;
1477 nbr->src = nbr_nbma->addr;
1478 nbr->nbr_nbma = nbr_nbma;
1479 nbr->priority = nbr_nbma->priority;
1480 nbr->address = p;
1481
1482 nbr_nbma->nbr = nbr;
1483
1484 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start);
1485 }
1486}
1487
1488void
paul68980082003-03-25 05:07:42 +00001489ospf_nbr_nbma_if_update (struct ospf *ospf, struct ospf_interface *oi)
paul718e3742002-12-13 20:15:29 +00001490{
1491 struct ospf_nbr_nbma *nbr_nbma;
1492 struct route_node *rn;
1493 struct prefix_ipv4 p;
1494
1495 if (oi->type != OSPF_IFTYPE_NBMA)
1496 return;
1497
paul68980082003-03-25 05:07:42 +00001498 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +00001499 if ((nbr_nbma = rn->info))
1500 if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL)
1501 {
1502 p.family = AF_INET;
1503 p.prefix = nbr_nbma->addr;
1504 p.prefixlen = IPV4_MAX_BITLEN;
1505
1506 if (prefix_match (oi->address, (struct prefix *)&p))
1507 ospf_nbr_nbma_add (nbr_nbma, oi);
1508 }
1509}
1510
1511struct ospf_nbr_nbma *
1512ospf_nbr_nbma_lookup (struct ospf *ospf, struct in_addr nbr_addr)
1513{
1514 struct route_node *rn;
1515 struct prefix_ipv4 p;
1516
1517 p.family = AF_INET;
1518 p.prefix = nbr_addr;
1519 p.prefixlen = IPV4_MAX_BITLEN;
1520
1521 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1522 if (rn)
1523 {
1524 route_unlock_node (rn);
1525 return rn->info;
1526 }
1527 return NULL;
1528}
1529
1530struct ospf_nbr_nbma *
paul68980082003-03-25 05:07:42 +00001531ospf_nbr_nbma_lookup_next (struct ospf *ospf, struct in_addr *addr, int first)
paul718e3742002-12-13 20:15:29 +00001532{
1533#if 0
1534 struct ospf_nbr_nbma *nbr_nbma;
hasso52dc7ee2004-09-23 19:18:23 +00001535 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001536#endif
1537
paul68980082003-03-25 05:07:42 +00001538 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001539 return NULL;
1540
1541#if 0
paul1eb8ef22005-04-07 07:30:20 +00001542 for (ALL_LIST_ELEMENTS_RO (ospf->nbr_nbma, node, nbr_nbma))
paul718e3742002-12-13 20:15:29 +00001543 {
paul718e3742002-12-13 20:15:29 +00001544 if (first)
1545 {
1546 *addr = nbr_nbma->addr;
1547 return nbr_nbma;
1548 }
1549 else if (ntohl (nbr_nbma->addr.s_addr) > ntohl (addr->s_addr))
1550 {
1551 *addr = nbr_nbma->addr;
1552 return nbr_nbma;
1553 }
1554 }
1555#endif
1556 return NULL;
1557}
1558
1559int
1560ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr)
1561{
1562 struct ospf_nbr_nbma *nbr_nbma;
1563 struct ospf_interface *oi;
1564 struct prefix_ipv4 p;
1565 struct route_node *rn;
hasso52dc7ee2004-09-23 19:18:23 +00001566 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001567
1568 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1569 if (nbr_nbma)
1570 return 0;
1571
1572 nbr_nbma = ospf_nbr_nbma_new ();
1573 nbr_nbma->addr = nbr_addr;
1574
1575 p.family = AF_INET;
1576 p.prefix = nbr_addr;
1577 p.prefixlen = IPV4_MAX_BITLEN;
1578
1579 rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p);
1580 rn->info = nbr_nbma;
1581
paul1eb8ef22005-04-07 07:30:20 +00001582 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul718e3742002-12-13 20:15:29 +00001583 {
paul718e3742002-12-13 20:15:29 +00001584 if (oi->type == OSPF_IFTYPE_NBMA)
1585 if (prefix_match (oi->address, (struct prefix *)&p))
1586 {
1587 ospf_nbr_nbma_add (nbr_nbma, oi);
1588 break;
1589 }
1590 }
1591
1592 return 1;
1593}
1594
1595int
1596ospf_nbr_nbma_unset (struct ospf *ospf, struct in_addr nbr_addr)
1597{
1598 struct ospf_nbr_nbma *nbr_nbma;
1599
1600 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1601 if (nbr_nbma == NULL)
1602 return 0;
1603
1604 ospf_nbr_nbma_down (nbr_nbma);
1605 ospf_nbr_nbma_delete (ospf, nbr_nbma);
1606
1607 return 1;
1608}
1609
1610int
1611ospf_nbr_nbma_priority_set (struct ospf *ospf, struct in_addr nbr_addr,
1612 u_char priority)
1613{
1614 struct ospf_nbr_nbma *nbr_nbma;
1615
1616 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1617 if (nbr_nbma == NULL)
1618 return 0;
1619
1620 if (nbr_nbma->priority != priority)
1621 nbr_nbma->priority = priority;
1622
1623 return 1;
1624}
1625
1626int
1627ospf_nbr_nbma_priority_unset (struct ospf *ospf, struct in_addr nbr_addr)
1628{
1629 struct ospf_nbr_nbma *nbr_nbma;
1630
1631 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1632 if (nbr_nbma == NULL)
1633 return 0;
1634
1635 if (nbr_nbma != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
1636 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1637
1638 return 1;
1639}
1640
1641int
1642ospf_nbr_nbma_poll_interval_set (struct ospf *ospf, struct in_addr nbr_addr,
paul6c835672004-10-11 11:00:30 +00001643 unsigned int interval)
paul718e3742002-12-13 20:15:29 +00001644{
1645 struct ospf_nbr_nbma *nbr_nbma;
1646
1647 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1648 if (nbr_nbma == NULL)
1649 return 0;
1650
1651 if (nbr_nbma->v_poll != interval)
1652 {
1653 nbr_nbma->v_poll = interval;
1654 if (nbr_nbma->oi && ospf_if_is_up (nbr_nbma->oi))
1655 {
1656 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1657 OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer,
1658 nbr_nbma->v_poll);
1659 }
1660 }
1661
1662 return 1;
1663}
1664
1665int
1666ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr)
1667{
1668 struct ospf_nbr_nbma *nbr_nbma;
1669
1670 nbr_nbma = ospf_nbr_nbma_lookup (ospf, addr);
1671 if (nbr_nbma == NULL)
1672 return 0;
1673
1674 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
1675 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1676
1677 return 1;
1678}
1679
paul718e3742002-12-13 20:15:29 +00001680void
paul020709f2003-04-04 02:44:16 +00001681ospf_master_init ()
1682{
1683 memset (&ospf_master, 0, sizeof (struct ospf_master));
1684
1685 om = &ospf_master;
1686 om->ospf = list_new ();
1687 om->master = thread_master_create ();
1688 om->start_time = time (NULL);
1689}