blob: 79c4543f4757423b1edad462ec51c2464c776281 [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))
Paul Jakma4021b602006-05-12 22:55:41 +0000114 thread_add_event (master, ospf_default_originate_timer, ospf, 0);
paul718e3742002-12-13 20:15:29 +0000115
paul68980082003-03-25 05:07:42 +0000116 ospf->external_origin = 0;
paul718e3742002-12-13 20:15:29 +0000117 }
118
paul68980082003-03-25 05:07:42 +0000119 OSPF_TIMER_ON (ospf->t_router_lsa_update,
paul718e3742002-12-13 20:15:29 +0000120 ospf_router_lsa_update_timer, OSPF_LSA_UPDATE_DELAY);
paulb29800a2005-11-20 14:50:45 +0000121
122 /* update ospf_interface's */
123 ospf_if_update (ospf);
paul718e3742002-12-13 20:15:29 +0000124 }
125}
paul718e3742002-12-13 20:15:29 +0000126
127/* For OSPF area sort by area id. */
paul4dadc292005-05-06 21:37:42 +0000128static int
paul718e3742002-12-13 20:15:29 +0000129ospf_area_id_cmp (struct ospf_area *a1, struct ospf_area *a2)
130{
131 if (ntohl (a1->area_id.s_addr) > ntohl (a2->area_id.s_addr))
132 return 1;
133 if (ntohl (a1->area_id.s_addr) < ntohl (a2->area_id.s_addr))
134 return -1;
135 return 0;
136}
137
138/* Allocate new ospf structure. */
paul4dadc292005-05-06 21:37:42 +0000139static struct ospf *
140ospf_new (void)
paul718e3742002-12-13 20:15:29 +0000141{
142 int i;
143
144 struct ospf *new = XCALLOC (MTYPE_OSPF_TOP, sizeof (struct ospf));
145
146 new->router_id.s_addr = htonl (0);
147 new->router_id_static.s_addr = htonl (0);
148
pauld57834f2005-07-12 20:04:22 +0000149 new->abr_type = OSPF_ABR_DEFAULT;
paul718e3742002-12-13 20:15:29 +0000150 new->oiflist = list_new ();
151 new->vlinks = list_new ();
152 new->areas = list_new ();
153 new->areas->cmp = (int (*)(void *, void *)) ospf_area_id_cmp;
154 new->networks = route_table_init ();
155 new->nbr_nbma = route_table_init ();
156
157 new->lsdb = ospf_lsdb_new ();
158
159 new->default_originate = DEFAULT_ORIGINATE_NONE;
160
161 new->new_external_route = route_table_init ();
162 new->old_external_route = route_table_init ();
163 new->external_lsas = route_table_init ();
paul88d6cf32005-10-29 12:50:09 +0000164
165 new->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paul31a59762005-11-14 11:11:11 +0000166 new->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paul88d6cf32005-10-29 12:50:09 +0000167
paul718e3742002-12-13 20:15:29 +0000168 /* Distribute parameter init. */
169 for (i = 0; i <= ZEBRA_ROUTE_MAX; i++)
170 {
171 new->dmetric[i].type = -1;
172 new->dmetric[i].value = -1;
173 }
174 new->default_metric = -1;
175 new->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
176
177 /* SPF timer value init. */
178 new->spf_delay = OSPF_SPF_DELAY_DEFAULT;
179 new->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
pauld24f6e22005-10-21 09:23:12 +0000180 new->spf_max_holdtime = OSPF_SPF_MAX_HOLDTIME_DEFAULT;
181 new->spf_hold_multiplier = 1;
paul718e3742002-12-13 20:15:29 +0000182
183 /* MaxAge init. */
184 new->maxage_lsa = list_new ();
185 new->t_maxage_walker =
186 thread_add_timer (master, ospf_lsa_maxage_walker,
paul68980082003-03-25 05:07:42 +0000187 new, OSPF_LSA_MAXAGE_CHECK_INTERVAL);
paul718e3742002-12-13 20:15:29 +0000188
189 /* Distance table init. */
190 new->distance_table = route_table_init ();
191
192 new->lsa_refresh_queue.index = 0;
193 new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
194 new->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker,
195 new, new->lsa_refresh_interval);
196 new->lsa_refresher_started = time (NULL);
197
ajs5c333492005-02-23 15:43:01 +0000198 if ((new->fd = ospf_sock_init()) < 0)
199 {
200 zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
201 "a socket");
202 exit(1);
203 }
204 if ((new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE+1)) == NULL)
205 {
206 zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
207 OSPF_MAX_PACKET_SIZE+1);
208 exit(1);
209 }
210 new->t_read = thread_add_read (master, ospf_read, new, new->fd);
paul718e3742002-12-13 20:15:29 +0000211 new->oi_write_q = list_new ();
212
213 return new;
214}
215
216struct ospf *
paul020709f2003-04-04 02:44:16 +0000217ospf_lookup ()
218{
219 if (listcount (om->ospf) == 0)
220 return NULL;
221
paul1eb8ef22005-04-07 07:30:20 +0000222 return listgetdata (listhead (om->ospf));
paul020709f2003-04-04 02:44:16 +0000223}
224
paul4dadc292005-05-06 21:37:42 +0000225static void
paul020709f2003-04-04 02:44:16 +0000226ospf_add (struct ospf *ospf)
227{
228 listnode_add (om->ospf, ospf);
229}
230
paul4dadc292005-05-06 21:37:42 +0000231static void
paul020709f2003-04-04 02:44:16 +0000232ospf_delete (struct ospf *ospf)
233{
234 listnode_delete (om->ospf, ospf);
235}
236
237struct ospf *
paul718e3742002-12-13 20:15:29 +0000238ospf_get ()
239{
paul020709f2003-04-04 02:44:16 +0000240 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000241
paul020709f2003-04-04 02:44:16 +0000242 ospf = ospf_lookup ();
243 if (ospf == NULL)
244 {
245 ospf = ospf_new ();
246 ospf_add (ospf);
paul718e3742002-12-13 20:15:29 +0000247
paul020709f2003-04-04 02:44:16 +0000248 if (ospf->router_id_static.s_addr == 0)
249 ospf_router_id_update (ospf);
paul718e3742002-12-13 20:15:29 +0000250
251#ifdef HAVE_OPAQUE_LSA
paul020709f2003-04-04 02:44:16 +0000252 ospf_opaque_type11_lsa_init (ospf);
paul718e3742002-12-13 20:15:29 +0000253#endif /* HAVE_OPAQUE_LSA */
paul020709f2003-04-04 02:44:16 +0000254 }
paul68980082003-03-25 05:07:42 +0000255
256 return ospf;
paul718e3742002-12-13 20:15:29 +0000257}
paul88d6cf32005-10-29 12:50:09 +0000258
paulc9c93d52005-11-26 13:31:11 +0000259/* Handle the second half of deferred shutdown. This is called either
260 * from the deferred-shutdown timer thread, or directly through
261 * ospf_deferred_shutdown_check.
paul88d6cf32005-10-29 12:50:09 +0000262 *
263 * Function is to cleanup G-R state, if required then call ospf_finish_final
264 * to complete shutdown of this ospf instance. Possibly exit if the
265 * whole process is being shutdown and this was the last OSPF instance.
266 */
267static void
paulc9c93d52005-11-26 13:31:11 +0000268ospf_deferred_shutdown_finish (struct ospf *ospf)
paul88d6cf32005-10-29 12:50:09 +0000269{
270 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
paulc9c93d52005-11-26 13:31:11 +0000271 OSPF_TIMER_OFF (ospf->t_deferred_shutdown);
paul88d6cf32005-10-29 12:50:09 +0000272
273 ospf_finish_final (ospf);
274
275 /* *ospf is now invalid */
276
277 /* ospfd being shut-down? If so, was this the last ospf instance? */
278 if (CHECK_FLAG (om->options, OSPF_MASTER_SHUTDOWN)
279 && (listcount (om->ospf) == 0))
280 exit (0);
281
282 return;
283}
284
285/* Timer thread for G-R */
286static int
paulc9c93d52005-11-26 13:31:11 +0000287ospf_deferred_shutdown_timer (struct thread *t)
paul88d6cf32005-10-29 12:50:09 +0000288{
289 struct ospf *ospf = THREAD_ARG(t);
290
paulc9c93d52005-11-26 13:31:11 +0000291 ospf_deferred_shutdown_finish (ospf);
paul88d6cf32005-10-29 12:50:09 +0000292
293 return 0;
294}
295
paulc9c93d52005-11-26 13:31:11 +0000296/* Check whether deferred-shutdown must be scheduled, otherwise call
paul88d6cf32005-10-29 12:50:09 +0000297 * down directly into second-half of instance shutdown.
298 */
299static void
paulc9c93d52005-11-26 13:31:11 +0000300ospf_deferred_shutdown_check (struct ospf *ospf)
paul88d6cf32005-10-29 12:50:09 +0000301{
302 unsigned long timeout;
303 struct listnode *ln;
304 struct ospf_area *area;
305
paulc9c93d52005-11-26 13:31:11 +0000306 /* deferred shutdown already running? */
307 if (ospf->t_deferred_shutdown)
paul88d6cf32005-10-29 12:50:09 +0000308 return;
309
310 /* Should we try push out max-metric LSAs? */
311 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
312 {
313 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
314 {
315 SET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
316
317 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
318 ospf_router_lsa_timer_add (area);
319 }
320 timeout = ospf->stub_router_shutdown_time;
321 }
322 else
paulc9c93d52005-11-26 13:31:11 +0000323 {
324 /* No timer needed */
325 ospf_deferred_shutdown_finish (ospf);
326 return;
327 }
paul88d6cf32005-10-29 12:50:09 +0000328
paulc9c93d52005-11-26 13:31:11 +0000329 OSPF_TIMER_ON (ospf->t_deferred_shutdown, ospf_deferred_shutdown_timer,
paul88d6cf32005-10-29 12:50:09 +0000330 timeout);
331 return;
332}
333
334/* Shut down the entire process */
335void
336ospf_terminate (void)
337{
338 struct ospf *ospf;
339 struct listnode *node, *nnode;
340
341 /* shutdown already in progress */
342 if (CHECK_FLAG (om->options, OSPF_MASTER_SHUTDOWN))
343 return;
344
345 SET_FLAG (om->options, OSPF_MASTER_SHUTDOWN);
346
347 for (ALL_LIST_ELEMENTS (om->ospf, node, nnode, ospf))
348 ospf_finish (ospf);
349
350 /* Deliberately go back up, hopefully to thread scheduler, as
351 * One or more ospf_finish()'s may have deferred shutdown to a timer
352 * thread
353 */
354}
paul718e3742002-12-13 20:15:29 +0000355
356void
357ospf_finish (struct ospf *ospf)
358{
paulc9c93d52005-11-26 13:31:11 +0000359 /* let deferred shutdown decide */
360 ospf_deferred_shutdown_check (ospf);
paul88d6cf32005-10-29 12:50:09 +0000361
paulc9c93d52005-11-26 13:31:11 +0000362 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
paul88d6cf32005-10-29 12:50:09 +0000363 * deferred to expiry of G-S timer thread. Return back up, hopefully
364 * to thread scheduler.
365 */
paulc9c93d52005-11-26 13:31:11 +0000366 return;
paul88d6cf32005-10-29 12:50:09 +0000367}
368
369/* Final cleanup of ospf instance */
370static void
371ospf_finish_final (struct ospf *ospf)
372{
paul718e3742002-12-13 20:15:29 +0000373 struct route_node *rn;
374 struct ospf_nbr_nbma *nbr_nbma;
paul68980082003-03-25 05:07:42 +0000375 struct ospf_lsa *lsa;
paul1eb8ef22005-04-07 07:30:20 +0000376 struct ospf_interface *oi;
377 struct ospf_area *area;
378 struct ospf_vl_data *vl_data;
379 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000380 int i;
381
382#ifdef HAVE_OPAQUE_LSA
383 ospf_opaque_type11_lsa_term (ospf);
384#endif /* HAVE_OPAQUE_LSA */
paul88d6cf32005-10-29 12:50:09 +0000385
386 /* be nice if this worked, but it doesn't */
387 /*ospf_flush_self_originated_lsas_now (ospf);*/
388
389 /* Unregister redistribution */
paul718e3742002-12-13 20:15:29 +0000390 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
paul020709f2003-04-04 02:44:16 +0000391 ospf_redistribute_unset (ospf, i);
paul718e3742002-12-13 20:15:29 +0000392
paul1eb8ef22005-04-07 07:30:20 +0000393 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
394 ospf_remove_vls_through_area (ospf, area);
paul718e3742002-12-13 20:15:29 +0000395
paul1eb8ef22005-04-07 07:30:20 +0000396 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
397 ospf_vl_delete (ospf, vl_data);
paul718e3742002-12-13 20:15:29 +0000398
399 list_delete (ospf->vlinks);
400
401 /* Reset interface. */
paul1eb8ef22005-04-07 07:30:20 +0000402 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
403 ospf_if_free (oi);
paul718e3742002-12-13 20:15:29 +0000404
405 /* Clear static neighbors */
406 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
407 if ((nbr_nbma = rn->info))
408 {
409 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
410
411 if (nbr_nbma->nbr)
412 {
413 nbr_nbma->nbr->nbr_nbma = NULL;
414 nbr_nbma->nbr = NULL;
415 }
416
417 if (nbr_nbma->oi)
418 {
419 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
420 nbr_nbma->oi = NULL;
421 }
422
423 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
424 }
425
426 route_table_finish (ospf->nbr_nbma);
427
428 /* Clear networks and Areas. */
429 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
430 {
431 struct ospf_network *network;
432
433 if ((network = rn->info) != NULL)
434 {
paul68980082003-03-25 05:07:42 +0000435 ospf_network_free (ospf, network);
paul718e3742002-12-13 20:15:29 +0000436 rn->info = NULL;
437 route_unlock_node (rn);
438 }
439 }
440
paul1eb8ef22005-04-07 07:30:20 +0000441 for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
paul718e3742002-12-13 20:15:29 +0000442 {
paul718e3742002-12-13 20:15:29 +0000443 listnode_delete (ospf->areas, area);
444 ospf_area_free (area);
445 }
446
447 /* Cancel all timers. */
448 OSPF_TIMER_OFF (ospf->t_external_lsa);
paul718e3742002-12-13 20:15:29 +0000449 OSPF_TIMER_OFF (ospf->t_router_lsa_update);
450 OSPF_TIMER_OFF (ospf->t_spf_calc);
451 OSPF_TIMER_OFF (ospf->t_ase_calc);
452 OSPF_TIMER_OFF (ospf->t_maxage);
453 OSPF_TIMER_OFF (ospf->t_maxage_walker);
454 OSPF_TIMER_OFF (ospf->t_abr_task);
paul88d6cf32005-10-29 12:50:09 +0000455 OSPF_TIMER_OFF (ospf->t_asbr_check);
paul718e3742002-12-13 20:15:29 +0000456 OSPF_TIMER_OFF (ospf->t_distribute_update);
457 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
458 OSPF_TIMER_OFF (ospf->t_read);
459 OSPF_TIMER_OFF (ospf->t_write);
paul31a59762005-11-14 11:11:11 +0000460#ifdef HAVE_OPAQUE_LSA
paul88d6cf32005-10-29 12:50:09 +0000461 OSPF_TIMER_OFF (ospf->t_opaque_lsa_self);
paul31a59762005-11-14 11:11:11 +0000462#endif
paul718e3742002-12-13 20:15:29 +0000463
464 close (ospf->fd);
ajs5c333492005-02-23 15:43:01 +0000465 stream_free(ospf->ibuf);
paul718e3742002-12-13 20:15:29 +0000466
467#ifdef HAVE_OPAQUE_LSA
paul68980082003-03-25 05:07:42 +0000468 LSDB_LOOP (OPAQUE_AS_LSDB (ospf), rn, lsa)
469 ospf_discard_from_db (ospf, ospf->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000470#endif /* HAVE_OPAQUE_LSA */
paul68980082003-03-25 05:07:42 +0000471 LSDB_LOOP (EXTERNAL_LSDB (ospf), rn, lsa)
472 ospf_discard_from_db (ospf, ospf->lsdb, lsa);
473
paul718e3742002-12-13 20:15:29 +0000474 ospf_lsdb_delete_all (ospf->lsdb);
475 ospf_lsdb_free (ospf->lsdb);
476
paul1eb8ef22005-04-07 07:30:20 +0000477 for (ALL_LIST_ELEMENTS (ospf->maxage_lsa, node, nnode, lsa))
478 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000479
480 list_delete (ospf->maxage_lsa);
481
482 if (ospf->old_table)
483 ospf_route_table_free (ospf->old_table);
484 if (ospf->new_table)
485 {
486 ospf_route_delete (ospf->new_table);
487 ospf_route_table_free (ospf->new_table);
488 }
489 if (ospf->old_rtrs)
490 ospf_rtrs_free (ospf->old_rtrs);
491 if (ospf->new_rtrs)
492 ospf_rtrs_free (ospf->new_rtrs);
493 if (ospf->new_external_route)
494 {
495 ospf_route_delete (ospf->new_external_route);
496 ospf_route_table_free (ospf->new_external_route);
497 }
498 if (ospf->old_external_route)
499 {
500 ospf_route_delete (ospf->old_external_route);
501 ospf_route_table_free (ospf->old_external_route);
502 }
503 if (ospf->external_lsas)
504 {
505 ospf_ase_external_lsas_finish (ospf->external_lsas);
506 }
507
508 list_delete (ospf->areas);
509
510 for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++)
511 if (EXTERNAL_INFO (i) != NULL)
512 for (rn = route_top (EXTERNAL_INFO (i)); rn; rn = route_next (rn))
513 {
514 if (rn->info == NULL)
515 continue;
516
517 XFREE (MTYPE_OSPF_EXTERNAL_INFO, rn->info);
518 rn->info = NULL;
519 route_unlock_node (rn);
520 }
521
paul68980082003-03-25 05:07:42 +0000522 ospf_distance_reset (ospf);
paul718e3742002-12-13 20:15:29 +0000523 route_table_finish (ospf->distance_table);
524
paul020709f2003-04-04 02:44:16 +0000525 ospf_delete (ospf);
paul718e3742002-12-13 20:15:29 +0000526
paul020709f2003-04-04 02:44:16 +0000527 XFREE (MTYPE_OSPF_TOP, ospf);
paul718e3742002-12-13 20:15:29 +0000528}
529
530
531/* allocate new OSPF Area object */
paul4dadc292005-05-06 21:37:42 +0000532static struct ospf_area *
paul68980082003-03-25 05:07:42 +0000533ospf_area_new (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000534{
535 struct ospf_area *new;
536
537 /* Allocate new config_network. */
538 new = XCALLOC (MTYPE_OSPF_AREA, sizeof (struct ospf_area));
539
paul68980082003-03-25 05:07:42 +0000540 new->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000541
542 new->area_id = area_id;
543
544 new->external_routing = OSPF_AREA_DEFAULT;
545 new->default_cost = 1;
546 new->auth_type = OSPF_AUTH_NULL;
paul88d6cf32005-10-29 12:50:09 +0000547
paul718e3742002-12-13 20:15:29 +0000548 /* New LSDB init. */
549 new->lsdb = ospf_lsdb_new ();
550
551 /* Self-originated LSAs initialize. */
552 new->router_lsa_self = NULL;
553
554#ifdef HAVE_OPAQUE_LSA
555 ospf_opaque_type10_lsa_init (new);
556#endif /* HAVE_OPAQUE_LSA */
557
558 new->oiflist = list_new ();
559 new->ranges = route_table_init ();
560
561 if (area_id.s_addr == OSPF_AREA_BACKBONE)
paul68980082003-03-25 05:07:42 +0000562 ospf->backbone = new;
paul718e3742002-12-13 20:15:29 +0000563
564 return new;
565}
566
567void
568ospf_area_free (struct ospf_area *area)
569{
paul68980082003-03-25 05:07:42 +0000570 struct route_node *rn;
571 struct ospf_lsa *lsa;
572
paul718e3742002-12-13 20:15:29 +0000573 /* Free LSDBs. */
paul68980082003-03-25 05:07:42 +0000574 LSDB_LOOP (ROUTER_LSDB (area), rn, lsa)
575 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
576 LSDB_LOOP (NETWORK_LSDB (area), rn, lsa)
577 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
578 LSDB_LOOP (SUMMARY_LSDB (area), rn, lsa)
579 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
580 LSDB_LOOP (ASBR_SUMMARY_LSDB (area), rn, lsa)
581 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000582
paul68980082003-03-25 05:07:42 +0000583 LSDB_LOOP (NSSA_LSDB (area), rn, lsa)
584 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000585#ifdef HAVE_OPAQUE_LSA
paul68980082003-03-25 05:07:42 +0000586 LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa)
587 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
588 LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa)
589 ospf_discard_from_db (area->ospf, area->lsdb, lsa);
paul718e3742002-12-13 20:15:29 +0000590#endif /* HAVE_OPAQUE_LSA */
591
592 ospf_lsdb_delete_all (area->lsdb);
593 ospf_lsdb_free (area->lsdb);
594
paul718e3742002-12-13 20:15:29 +0000595 ospf_lsa_unlock (area->router_lsa_self);
596
597 route_table_finish (area->ranges);
598 list_delete (area->oiflist);
599
600 if (EXPORT_NAME (area))
601 free (EXPORT_NAME (area));
602
603 if (IMPORT_NAME (area))
604 free (IMPORT_NAME (area));
605
606 /* Cancel timer. */
607 OSPF_TIMER_OFF (area->t_router_lsa_self);
paul88d6cf32005-10-29 12:50:09 +0000608 OSPF_TIMER_OFF (area->t_stub_router);
609#ifdef HAVE_OPAQUE_LSA
610 OSPF_TIMER_OFF (area->t_opaque_lsa_self);
611#endif /* HAVE_OPAQUE_LSA */
612
paul718e3742002-12-13 20:15:29 +0000613 if (OSPF_IS_AREA_BACKBONE (area))
paul68980082003-03-25 05:07:42 +0000614 area->ospf->backbone = NULL;
paul718e3742002-12-13 20:15:29 +0000615
616 XFREE (MTYPE_OSPF_AREA, area);
617}
618
619void
paul68980082003-03-25 05:07:42 +0000620ospf_area_check_free (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000621{
622 struct ospf_area *area;
623
paul68980082003-03-25 05:07:42 +0000624 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000625 if (area &&
626 listcount (area->oiflist) == 0 &&
627 area->ranges->top == NULL &&
628 area->shortcut_configured == OSPF_SHORTCUT_DEFAULT &&
629 area->external_routing == OSPF_AREA_DEFAULT &&
630 area->no_summary == 0 &&
631 area->default_cost == 1 &&
632 EXPORT_NAME (area) == NULL &&
633 IMPORT_NAME (area) == NULL &&
634 area->auth_type == OSPF_AUTH_NULL)
635 {
paul68980082003-03-25 05:07:42 +0000636 listnode_delete (ospf->areas, area);
paul718e3742002-12-13 20:15:29 +0000637 ospf_area_free (area);
638 }
639}
640
641struct ospf_area *
paul68980082003-03-25 05:07:42 +0000642ospf_area_get (struct ospf *ospf, struct in_addr area_id, int format)
paul718e3742002-12-13 20:15:29 +0000643{
644 struct ospf_area *area;
645
paul68980082003-03-25 05:07:42 +0000646 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000647 if (!area)
648 {
paul68980082003-03-25 05:07:42 +0000649 area = ospf_area_new (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000650 area->format = format;
paul68980082003-03-25 05:07:42 +0000651 listnode_add_sort (ospf->areas, area);
652 ospf_check_abr_status (ospf);
paul718e3742002-12-13 20:15:29 +0000653 }
654
655 return area;
656}
657
658struct ospf_area *
paul68980082003-03-25 05:07:42 +0000659ospf_area_lookup_by_area_id (struct ospf *ospf, struct in_addr area_id)
paul718e3742002-12-13 20:15:29 +0000660{
661 struct ospf_area *area;
hasso52dc7ee2004-09-23 19:18:23 +0000662 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000663
paul1eb8ef22005-04-07 07:30:20 +0000664 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
665 if (IPV4_ADDR_SAME (&area->area_id, &area_id))
666 return area;
paul718e3742002-12-13 20:15:29 +0000667
668 return NULL;
669}
670
671void
672ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi)
673{
674 listnode_add (area->oiflist, oi);
675}
676
677void
678ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi)
679{
680 listnode_delete (area->oiflist, oi);
681}
682
683
684/* Config network statement related functions. */
paul4dadc292005-05-06 21:37:42 +0000685static struct ospf_network *
paul718e3742002-12-13 20:15:29 +0000686ospf_network_new (struct in_addr area_id, int format)
687{
688 struct ospf_network *new;
689 new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network));
690
691 new->area_id = area_id;
692 new->format = format;
693
694 return new;
695}
696
697void
paul68980082003-03-25 05:07:42 +0000698ospf_network_free (struct ospf *ospf, struct ospf_network *network)
paul718e3742002-12-13 20:15:29 +0000699{
paul68980082003-03-25 05:07:42 +0000700 ospf_area_check_free (ospf, network->area_id);
701 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +0000702 XFREE (MTYPE_OSPF_NETWORK, network);
703}
704
705int
706ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p,
707 struct in_addr area_id)
708{
709 struct ospf_network *network;
710 struct ospf_area *area;
711 struct route_node *rn;
712 struct external_info *ei;
paul147193a2003-04-19 00:31:59 +0000713 int ret = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +0000714
715 rn = route_node_get (ospf->networks, (struct prefix *)p);
716 if (rn->info)
717 {
718 /* There is already same network statement. */
719 route_unlock_node (rn);
720 return 0;
721 }
722
723 rn->info = network = ospf_network_new (area_id, ret);
paul68980082003-03-25 05:07:42 +0000724 area = ospf_area_get (ospf, area_id, ret);
paul718e3742002-12-13 20:15:29 +0000725
726 /* Run network config now. */
727 ospf_network_run (ospf, (struct prefix *)p, area);
728
729 /* Update connected redistribute. */
730 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
731 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
732 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
733 rn; rn = route_next (rn))
734 if ((ei = rn->info) != NULL)
paul68980082003-03-25 05:07:42 +0000735 if (ospf_external_info_find_lsa (ospf, &ei->p))
736 if (!ospf_distribute_check_connected (ospf, ei))
737 ospf_external_lsa_flush (ospf, ei->type, &ei->p,
ajs5339cfd2005-09-19 13:28:05 +0000738 ei->ifindex /*, ei->nexthop */);
paul718e3742002-12-13 20:15:29 +0000739
paul68980082003-03-25 05:07:42 +0000740 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +0000741
742 return 1;
743}
744
745int
746ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
747 struct in_addr area_id)
748{
749 struct route_node *rn;
750 struct ospf_network *network;
751 struct external_info *ei;
752
753 rn = route_node_lookup (ospf->networks, (struct prefix *)p);
754 if (rn == NULL)
755 return 0;
756
757 network = rn->info;
758 if (!IPV4_ADDR_SAME (&area_id, &network->area_id))
759 return 0;
760
paul68980082003-03-25 05:07:42 +0000761 ospf_network_free (ospf, rn->info);
paul718e3742002-12-13 20:15:29 +0000762 rn->info = NULL;
763 route_unlock_node (rn);
764
paul68980082003-03-25 05:07:42 +0000765 ospf_if_update (ospf);
paul718e3742002-12-13 20:15:29 +0000766
767 /* Update connected redistribute. */
768 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
769 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
770 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
771 rn; rn = route_next (rn))
772 if ((ei = rn->info) != NULL)
paul68980082003-03-25 05:07:42 +0000773 if (!ospf_external_info_find_lsa (ospf, &ei->p))
774 if (ospf_distribute_check_connected (ospf, ei))
775 ospf_external_lsa_originate (ospf, ei);
paul718e3742002-12-13 20:15:29 +0000776
777 return 1;
778}
779
paul570f7592003-01-25 06:47:41 +0000780/* Check whether interface matches given network
781 * returns: 1, true. 0, false
782 */
783int
784ospf_network_match_iface(struct connected *co, struct prefix *net)
785{
786 /* Behaviour to match both Cisco where:
787 * iface address lies within network specified -> ospf
788 * and zebra 0.9[2ish-3]:
789 * PtP special case: network specified == iface peer addr -> ospf
790 */
gdt8f40e892003-12-05 14:01:43 +0000791
paulf3ae74c2004-11-04 20:35:31 +0000792 /* For PtP, match if peer address matches network address exactly.
793 * This can be addr/32 or addr/p for p < 32, but the addr must match
794 * exactly; this is not a test for falling within the prefix. This
gdt8f40e892003-12-05 14:01:43 +0000795 * test is solely for compatibility with zebra.
gdt8f40e892003-12-05 14:01:43 +0000796 */
paulf3ae74c2004-11-04 20:35:31 +0000797 if (if_is_pointopoint (co->ifp) && co->destination &&
798 IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
799 return 1;
800
801#if 0
802 /* Decline to accept PtP if dst address does not match the
803 * prefix. (ifdefed out because this is a workaround, not the
804 * desired behavior.) */
805 if (if_is_pointopoint (co->ifp) &&
806 ! prefix_match (net, co->destination))
807 return 0;
808#endif
809
810 /* If the address is within the prefix, accept. Note that this
811 * applies to PtP as well as other types.
812 */
813 if (prefix_match (net, co->address))
814 return 1;
815
816 return 0; /* no match */
paul570f7592003-01-25 06:47:41 +0000817}
818
paul718e3742002-12-13 20:15:29 +0000819void
820ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area)
821{
822 struct interface *ifp;
paul1eb8ef22005-04-07 07:30:20 +0000823 struct connected *co;
hasso52dc7ee2004-09-23 19:18:23 +0000824 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000825
826 /* Schedule Router ID Update. */
paul86752842006-01-10 20:34:46 +0000827 if (ospf->router_id.s_addr == 0)
paulb29800a2005-11-20 14:50:45 +0000828 ospf_router_id_update (ospf);
829
paul718e3742002-12-13 20:15:29 +0000830 /* Get target interface. */
paul1eb8ef22005-04-07 07:30:20 +0000831 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
paul718e3742002-12-13 20:15:29 +0000832 {
paul1eb8ef22005-04-07 07:30:20 +0000833 struct listnode *cnode;
paul718e3742002-12-13 20:15:29 +0000834
paul718e3742002-12-13 20:15:29 +0000835 if (memcmp (ifp->name, "VLINK", 5) == 0)
836 continue;
837
838 /* if interface prefix is match specified prefix,
839 then create socket and join multicast group. */
paul1eb8ef22005-04-07 07:30:20 +0000840 for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, co))
paul718e3742002-12-13 20:15:29 +0000841 {
paul718e3742002-12-13 20:15:29 +0000842 struct prefix *addr;
paul800dc102003-03-28 01:51:40 +0000843
paule7b050c2003-04-07 06:38:02 +0000844 if (CHECK_FLAG(co->flags,ZEBRA_IFA_SECONDARY))
845 continue;
paul718e3742002-12-13 20:15:29 +0000846
hasso3fb9cd62004-10-19 19:44:43 +0000847 if (CONNECTED_POINTOPOINT_HOST(co))
paul718e3742002-12-13 20:15:29 +0000848 addr = co->destination;
849 else
850 addr = co->address;
851
paulcb3f37d2003-02-18 23:26:37 +0000852 if (p->family == co->address->family
paul68980082003-03-25 05:07:42 +0000853 && ! ospf_if_is_configured (ospf, &(addr->u.prefix4))
paulcb3f37d2003-02-18 23:26:37 +0000854 && ospf_network_match_iface(co,p))
paul570f7592003-01-25 06:47:41 +0000855 {
paul1eb8ef22005-04-07 07:30:20 +0000856 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000857
paul68980082003-03-25 05:07:42 +0000858 oi = ospf_if_new (ospf, ifp, co->address);
paul718e3742002-12-13 20:15:29 +0000859 oi->connected = co;
860
paul718e3742002-12-13 20:15:29 +0000861 oi->area = area;
862
863 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
864 oi->output_cost = ospf_if_get_output_cost (oi);
865
paul718e3742002-12-13 20:15:29 +0000866 /* Add pseudo neighbor. */
867 ospf_nbr_add_self (oi);
868
paul718e3742002-12-13 20:15:29 +0000869 /* Relate ospf interface to ospf instance. */
paul68980082003-03-25 05:07:42 +0000870 oi->ospf = ospf;
paul718e3742002-12-13 20:15:29 +0000871
872 /* update network type as interface flag */
873 /* If network type is specified previously,
874 skip network type setting. */
875 oi->type = IF_DEF_PARAMS (ifp)->type;
876
paul718e3742002-12-13 20:15:29 +0000877 ospf_area_add_if (oi->area, oi);
paulb29800a2005-11-20 14:50:45 +0000878
879 /* if router_id is not configured, dont bring up
880 * interfaces.
881 * ospf_router_id_update() will call ospf_if_update
882 * whenever r-id is configured instead.
883 */
paul86752842006-01-10 20:34:46 +0000884 if ((ospf->router_id.s_addr != 0)
paulb29800a2005-11-20 14:50:45 +0000885 && if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000886 ospf_if_up (oi);
887
888 break;
889 }
890 }
891 }
892}
893
894void
895ospf_ls_upd_queue_empty (struct ospf_interface *oi)
896{
897 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000898 struct listnode *node, *nnode;
hasso52dc7ee2004-09-23 19:18:23 +0000899 struct list *lst;
paul718e3742002-12-13 20:15:29 +0000900 struct ospf_lsa *lsa;
901
902 /* empty ls update queue */
903 for (rn = route_top (oi->ls_upd_queue); rn;
904 rn = route_next (rn))
hasso52dc7ee2004-09-23 19:18:23 +0000905 if ((lst = (struct list *) rn->info))
paul718e3742002-12-13 20:15:29 +0000906 {
paul1eb8ef22005-04-07 07:30:20 +0000907 for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa))
908 ospf_lsa_unlock (lsa);
paul718e3742002-12-13 20:15:29 +0000909 list_free (lst);
910 rn->info = NULL;
911 }
912
913 /* remove update event */
914 if (oi->t_ls_upd_event)
915 {
916 thread_cancel (oi->t_ls_upd_event);
917 oi->t_ls_upd_event = NULL;
918 }
919}
920
921void
paul68980082003-03-25 05:07:42 +0000922ospf_if_update (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000923{
924 struct route_node *rn;
paul1eb8ef22005-04-07 07:30:20 +0000925 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000926 struct ospf_network *network;
927 struct ospf_area *area;
paul1eb8ef22005-04-07 07:30:20 +0000928 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000929
paul68980082003-03-25 05:07:42 +0000930 if (ospf != NULL)
paul718e3742002-12-13 20:15:29 +0000931 {
paulb29800a2005-11-20 14:50:45 +0000932 /* Router-ID must be configured. */
paul86752842006-01-10 20:34:46 +0000933 if (ospf->router_id.s_addr == 0)
paulb29800a2005-11-20 14:50:45 +0000934 return;
935
paul718e3742002-12-13 20:15:29 +0000936 /* Find interfaces that not configured already. */
paul1eb8ef22005-04-07 07:30:20 +0000937 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +0000938 {
939 int found = 0;
paul718e3742002-12-13 20:15:29 +0000940 struct connected *co = oi->connected;
941
paul718e3742002-12-13 20:15:29 +0000942 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
943 continue;
944
paul68980082003-03-25 05:07:42 +0000945 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000946 {
947 if (rn->info == NULL)
948 continue;
949
paul570f7592003-01-25 06:47:41 +0000950 if (ospf_network_match_iface(co,&rn->p))
paul718e3742002-12-13 20:15:29 +0000951 {
952 found = 1;
953 route_unlock_node (rn);
954 break;
955 }
956 }
957
958 if (found == 0)
959 ospf_if_free (oi);
960 }
961
962 /* Run each interface. */
paul68980082003-03-25 05:07:42 +0000963 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +0000964 if (rn->info != NULL)
965 {
966 network = (struct ospf_network *) rn->info;
paul68980082003-03-25 05:07:42 +0000967 area = ospf_area_get (ospf, network->area_id, network->format);
968 ospf_network_run (ospf, &rn->p, area);
paul718e3742002-12-13 20:15:29 +0000969 }
970 }
971}
972
973void
paul68980082003-03-25 05:07:42 +0000974ospf_remove_vls_through_area (struct ospf *ospf, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +0000975{
paul1eb8ef22005-04-07 07:30:20 +0000976 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +0000977 struct ospf_vl_data *vl_data;
978
paul1eb8ef22005-04-07 07:30:20 +0000979 for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
980 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
981 ospf_vl_delete (ospf, vl_data);
paul718e3742002-12-13 20:15:29 +0000982}
983
984
985struct message ospf_area_type_msg[] =
986{
987 { OSPF_AREA_DEFAULT, "Default" },
988 { OSPF_AREA_STUB, "Stub" },
989 { OSPF_AREA_NSSA, "NSSA" },
990};
991int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX;
992
paul4dadc292005-05-06 21:37:42 +0000993static void
paul718e3742002-12-13 20:15:29 +0000994ospf_area_type_set (struct ospf_area *area, int type)
995{
hasso52dc7ee2004-09-23 19:18:23 +0000996 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000997 struct ospf_interface *oi;
998
999 if (area->external_routing == type)
1000 {
1001 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +00001002 zlog_debug ("Area[%s]: Types are the same, ignored.",
paul718e3742002-12-13 20:15:29 +00001003 inet_ntoa (area->area_id));
1004 return;
1005 }
1006
1007 area->external_routing = type;
1008
1009 if (IS_DEBUG_OSPF_EVENT)
ajs9b0e25c2004-12-08 19:06:51 +00001010 zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area->area_id),
paul718e3742002-12-13 20:15:29 +00001011 LOOKUP (ospf_area_type_msg, type));
1012
1013 switch (area->external_routing)
1014 {
1015 case OSPF_AREA_DEFAULT:
paul1eb8ef22005-04-07 07:30:20 +00001016 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1017 if (oi->nbr_self != NULL)
1018 {
1019 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1020 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1021 }
paul718e3742002-12-13 20:15:29 +00001022 break;
1023 case OSPF_AREA_STUB:
paul1eb8ef22005-04-07 07:30:20 +00001024 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1025 if (oi->nbr_self != NULL)
1026 {
1027 if (IS_DEBUG_OSPF_EVENT)
1028 zlog_debug ("setting options on %s accordingly", IF_NAME (oi));
1029 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1030 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1031 if (IS_DEBUG_OSPF_EVENT)
1032 zlog_debug ("options set on %s: %x",
1033 IF_NAME (oi), OPTIONS (oi));
1034 }
paul718e3742002-12-13 20:15:29 +00001035 break;
1036 case OSPF_AREA_NSSA:
paul1eb8ef22005-04-07 07:30:20 +00001037 for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
1038 if (oi->nbr_self != NULL)
1039 {
1040 zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi));
1041 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
1042 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
1043 zlog_debug ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi));
1044 }
paul718e3742002-12-13 20:15:29 +00001045 break;
1046 default:
1047 break;
1048 }
1049
1050 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001051 ospf_schedule_abr_task (area->ospf);
paul718e3742002-12-13 20:15:29 +00001052}
1053
1054int
paul68980082003-03-25 05:07:42 +00001055ospf_area_shortcut_set (struct ospf *ospf, struct ospf_area *area, int mode)
paul718e3742002-12-13 20:15:29 +00001056{
1057 if (area->shortcut_configured == mode)
1058 return 0;
1059
1060 area->shortcut_configured = mode;
1061 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001062 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001063
paul68980082003-03-25 05:07:42 +00001064 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001065
1066 return 1;
1067}
1068
1069int
paul68980082003-03-25 05:07:42 +00001070ospf_area_shortcut_unset (struct ospf *ospf, struct ospf_area *area)
paul718e3742002-12-13 20:15:29 +00001071{
1072 area->shortcut_configured = OSPF_SHORTCUT_DEFAULT;
1073 ospf_router_lsa_timer_add (area);
paul68980082003-03-25 05:07:42 +00001074 ospf_area_check_free (ospf, area->area_id);
1075 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001076
1077 return 1;
1078}
1079
paul4dadc292005-05-06 21:37:42 +00001080static int
paul718e3742002-12-13 20:15:29 +00001081ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area)
1082{
1083 struct ospf_vl_data *vl;
hasso52dc7ee2004-09-23 19:18:23 +00001084 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001085 int count = 0;
1086
paul1eb8ef22005-04-07 07:30:20 +00001087 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl))
1088 if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id))
1089 count++;
paul718e3742002-12-13 20:15:29 +00001090
1091 return count;
1092}
1093
1094int
1095ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id)
1096{
1097 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001098 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001099
paul68980082003-03-25 05:07:42 +00001100 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001101 if (ospf_area_vlink_count (ospf, area))
1102 return 0;
1103
1104 if (area->external_routing != OSPF_AREA_STUB)
1105 ospf_area_type_set (area, OSPF_AREA_STUB);
1106
1107 return 1;
1108}
1109
1110int
1111ospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id)
1112{
1113 struct ospf_area *area;
1114
paul68980082003-03-25 05:07:42 +00001115 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001116 if (area == NULL)
1117 return 1;
1118
1119 if (area->external_routing == OSPF_AREA_STUB)
1120 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1121
paul68980082003-03-25 05:07:42 +00001122 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001123
1124 return 1;
1125}
1126
1127int
1128ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id)
1129{
1130 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001131 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001132
paul68980082003-03-25 05:07:42 +00001133 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001134 area->no_summary = 1;
1135
1136 return 1;
1137}
1138
1139int
1140ospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id)
1141{
1142 struct ospf_area *area;
1143
paul68980082003-03-25 05:07:42 +00001144 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001145 if (area == NULL)
1146 return 0;
1147
1148 area->no_summary = 0;
paul68980082003-03-25 05:07:42 +00001149 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001150
1151 return 1;
1152}
1153
1154int
1155ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id)
1156{
1157 struct ospf_area *area;
paul147193a2003-04-19 00:31:59 +00001158 int format = OSPF_AREA_ID_FORMAT_ADDRESS;
paul718e3742002-12-13 20:15:29 +00001159
paul68980082003-03-25 05:07:42 +00001160 area = ospf_area_get (ospf, area_id, format);
paul718e3742002-12-13 20:15:29 +00001161 if (ospf_area_vlink_count (ospf, area))
1162 return 0;
1163
1164 if (area->external_routing != OSPF_AREA_NSSA)
1165 {
1166 ospf_area_type_set (area, OSPF_AREA_NSSA);
1167 ospf->anyNSSA++;
1168 }
1169
paul084c7842003-06-22 08:35:18 +00001170 /* set NSSA area defaults */
1171 area->no_summary = 0;
1172 area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
pauld4a53d52003-07-12 21:30:57 +00001173 area->NSSATranslatorState = OSPF_NSSA_TRANSLATE_DISABLED;
paul084c7842003-06-22 08:35:18 +00001174 area->NSSATranslatorStabilityInterval = OSPF_NSSA_TRANS_STABLE_DEFAULT;
1175
paul718e3742002-12-13 20:15:29 +00001176 return 1;
1177}
1178
1179int
1180ospf_area_nssa_unset (struct ospf *ospf, struct in_addr area_id)
1181{
1182 struct ospf_area *area;
1183
paul68980082003-03-25 05:07:42 +00001184 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001185 if (area == NULL)
1186 return 0;
1187
1188 if (area->external_routing == OSPF_AREA_NSSA)
1189 {
1190 ospf->anyNSSA--;
1191 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1192 }
1193
paul68980082003-03-25 05:07:42 +00001194 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001195
1196 return 1;
1197}
1198
1199int
1200ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id,
1201 int role)
1202{
1203 struct ospf_area *area;
1204
paul68980082003-03-25 05:07:42 +00001205 area = ospf_area_lookup_by_area_id (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001206 if (area == NULL)
1207 return 0;
1208
paul084c7842003-06-22 08:35:18 +00001209 area->NSSATranslatorRole = role;
paul718e3742002-12-13 20:15:29 +00001210
1211 return 1;
1212}
1213
paul4dadc292005-05-06 21:37:42 +00001214/* XXX: unused? Leave for symmetry? */
1215static int
paul718e3742002-12-13 20:15:29 +00001216ospf_area_nssa_translator_role_unset (struct ospf *ospf,
1217 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
paul084c7842003-06-22 08:35:18 +00001225 area->NSSATranslatorRole = OSPF_NSSA_ROLE_CANDIDATE;
paul718e3742002-12-13 20:15:29 +00001226
paul68980082003-03-25 05:07:42 +00001227 ospf_area_check_free (ospf, area_id);
paul718e3742002-12-13 20:15:29 +00001228
1229 return 1;
1230}
1231
1232int
paul68980082003-03-25 05:07:42 +00001233ospf_area_export_list_set (struct ospf *ospf,
paul6c835672004-10-11 11:00:30 +00001234 struct ospf_area *area, const char *list_name)
paul718e3742002-12-13 20:15:29 +00001235{
1236 struct access_list *list;
1237 list = access_list_lookup (AFI_IP, list_name);
1238
1239 EXPORT_LIST (area) = list;
1240
1241 if (EXPORT_NAME (area))
1242 free (EXPORT_NAME (area));
1243
1244 EXPORT_NAME (area) = strdup (list_name);
paul68980082003-03-25 05:07:42 +00001245 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001246
1247 return 1;
1248}
1249
1250int
paul68980082003-03-25 05:07:42 +00001251ospf_area_export_list_unset (struct ospf *ospf, struct ospf_area * area)
paul718e3742002-12-13 20:15:29 +00001252{
1253
1254 EXPORT_LIST (area) = 0;
1255
1256 if (EXPORT_NAME (area))
1257 free (EXPORT_NAME (area));
1258
1259 EXPORT_NAME (area) = NULL;
1260
paul68980082003-03-25 05:07:42 +00001261 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001262
paul68980082003-03-25 05:07:42 +00001263 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001264
1265 return 1;
1266}
1267
1268int
paul6c835672004-10-11 11:00:30 +00001269ospf_area_import_list_set (struct ospf *ospf, struct ospf_area *area,
1270 const char *name)
paul718e3742002-12-13 20:15:29 +00001271{
1272 struct access_list *list;
1273 list = access_list_lookup (AFI_IP, name);
1274
1275 IMPORT_LIST (area) = list;
1276
1277 if (IMPORT_NAME (area))
1278 free (IMPORT_NAME (area));
1279
1280 IMPORT_NAME (area) = strdup (name);
paul68980082003-03-25 05:07:42 +00001281 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001282
1283 return 1;
1284}
1285
1286int
paul68980082003-03-25 05:07:42 +00001287ospf_area_import_list_unset (struct ospf *ospf, struct ospf_area * area)
paul718e3742002-12-13 20:15:29 +00001288{
1289 IMPORT_LIST (area) = 0;
1290
1291 if (IMPORT_NAME (area))
1292 free (IMPORT_NAME (area));
1293
1294 IMPORT_NAME (area) = NULL;
paul68980082003-03-25 05:07:42 +00001295 ospf_area_check_free (ospf, area->area_id);
paul718e3742002-12-13 20:15:29 +00001296
paul68980082003-03-25 05:07:42 +00001297 ospf_schedule_abr_task (ospf);
paul718e3742002-12-13 20:15:29 +00001298
1299 return 1;
1300}
1301
1302int
paul718e3742002-12-13 20:15:29 +00001303ospf_timers_refresh_set (struct ospf *ospf, int interval)
1304{
1305 int time_left;
1306
1307 if (ospf->lsa_refresh_interval == interval)
1308 return 1;
1309
1310 time_left = ospf->lsa_refresh_interval -
1311 (time (NULL) - ospf->lsa_refresher_started);
1312
1313 if (time_left > interval)
1314 {
1315 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1316 ospf->t_lsa_refresher =
1317 thread_add_timer (master, ospf_lsa_refresh_walker, ospf, interval);
1318 }
1319 ospf->lsa_refresh_interval = interval;
1320
1321 return 1;
1322}
1323
1324int
1325ospf_timers_refresh_unset (struct ospf *ospf)
1326{
1327 int time_left;
1328
1329 time_left = ospf->lsa_refresh_interval -
1330 (time (NULL) - ospf->lsa_refresher_started);
1331
1332 if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
1333 {
1334 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1335 ospf->t_lsa_refresher =
1336 thread_add_timer (master, ospf_lsa_refresh_walker, ospf,
1337 OSPF_LSA_REFRESH_INTERVAL_DEFAULT);
1338 }
1339
1340 ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
1341
1342 return 1;
1343}
1344
1345
paul4dadc292005-05-06 21:37:42 +00001346static struct ospf_nbr_nbma *
1347ospf_nbr_nbma_new (void)
paul718e3742002-12-13 20:15:29 +00001348{
1349 struct ospf_nbr_nbma *nbr_nbma;
1350
1351 nbr_nbma = XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC,
1352 sizeof (struct ospf_nbr_nbma));
1353 memset (nbr_nbma, 0, sizeof (struct ospf_nbr_nbma));
1354
1355 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1356 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1357
1358 return nbr_nbma;
1359}
1360
paul4dadc292005-05-06 21:37:42 +00001361static void
paul718e3742002-12-13 20:15:29 +00001362ospf_nbr_nbma_free (struct ospf_nbr_nbma *nbr_nbma)
1363{
1364 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
1365}
1366
paul4dadc292005-05-06 21:37:42 +00001367static void
paul718e3742002-12-13 20:15:29 +00001368ospf_nbr_nbma_delete (struct ospf *ospf, struct ospf_nbr_nbma *nbr_nbma)
1369{
1370 struct route_node *rn;
1371 struct prefix_ipv4 p;
1372
1373 p.family = AF_INET;
1374 p.prefix = nbr_nbma->addr;
1375 p.prefixlen = IPV4_MAX_BITLEN;
1376
1377 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1378 if (rn)
1379 {
1380 ospf_nbr_nbma_free (rn->info);
1381 rn->info = NULL;
1382 route_unlock_node (rn);
1383 route_unlock_node (rn);
1384 }
1385}
1386
paul4dadc292005-05-06 21:37:42 +00001387static void
paul718e3742002-12-13 20:15:29 +00001388ospf_nbr_nbma_down (struct ospf_nbr_nbma *nbr_nbma)
1389{
1390 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1391
1392 if (nbr_nbma->nbr)
1393 {
1394 nbr_nbma->nbr->nbr_nbma = NULL;
1395 OSPF_NSM_EVENT_EXECUTE (nbr_nbma->nbr, NSM_KillNbr);
1396 }
1397
1398 if (nbr_nbma->oi)
1399 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
1400}
1401
paul4dadc292005-05-06 21:37:42 +00001402static void
paul718e3742002-12-13 20:15:29 +00001403ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma,
1404 struct ospf_interface *oi)
1405{
1406 struct ospf_neighbor *nbr;
1407 struct route_node *rn;
1408 struct prefix p;
1409
1410 if (oi->type != OSPF_IFTYPE_NBMA)
1411 return;
1412
1413 if (nbr_nbma->nbr != NULL)
1414 return;
1415
1416 if (IPV4_ADDR_SAME (&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr))
1417 return;
1418
1419 nbr_nbma->oi = oi;
1420 listnode_add (oi->nbr_nbma, nbr_nbma);
1421
1422 /* Get neighbor information from table. */
1423 p.family = AF_INET;
1424 p.prefixlen = IPV4_MAX_BITLEN;
1425 p.u.prefix4 = nbr_nbma->addr;
1426
1427 rn = route_node_get (oi->nbrs, (struct prefix *)&p);
1428 if (rn->info)
1429 {
1430 nbr = rn->info;
1431 nbr->nbr_nbma = nbr_nbma;
1432 nbr_nbma->nbr = nbr;
1433
1434 route_unlock_node (rn);
1435 }
1436 else
1437 {
1438 nbr = rn->info = ospf_nbr_new (oi);
1439 nbr->state = NSM_Down;
1440 nbr->src = nbr_nbma->addr;
1441 nbr->nbr_nbma = nbr_nbma;
1442 nbr->priority = nbr_nbma->priority;
1443 nbr->address = p;
1444
1445 nbr_nbma->nbr = nbr;
1446
1447 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start);
1448 }
1449}
1450
1451void
paul68980082003-03-25 05:07:42 +00001452ospf_nbr_nbma_if_update (struct ospf *ospf, struct ospf_interface *oi)
paul718e3742002-12-13 20:15:29 +00001453{
1454 struct ospf_nbr_nbma *nbr_nbma;
1455 struct route_node *rn;
1456 struct prefix_ipv4 p;
1457
1458 if (oi->type != OSPF_IFTYPE_NBMA)
1459 return;
1460
paul68980082003-03-25 05:07:42 +00001461 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
paul718e3742002-12-13 20:15:29 +00001462 if ((nbr_nbma = rn->info))
1463 if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL)
1464 {
1465 p.family = AF_INET;
1466 p.prefix = nbr_nbma->addr;
1467 p.prefixlen = IPV4_MAX_BITLEN;
1468
1469 if (prefix_match (oi->address, (struct prefix *)&p))
1470 ospf_nbr_nbma_add (nbr_nbma, oi);
1471 }
1472}
1473
1474struct ospf_nbr_nbma *
1475ospf_nbr_nbma_lookup (struct ospf *ospf, struct in_addr nbr_addr)
1476{
1477 struct route_node *rn;
1478 struct prefix_ipv4 p;
1479
1480 p.family = AF_INET;
1481 p.prefix = nbr_addr;
1482 p.prefixlen = IPV4_MAX_BITLEN;
1483
1484 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1485 if (rn)
1486 {
1487 route_unlock_node (rn);
1488 return rn->info;
1489 }
1490 return NULL;
1491}
1492
1493struct ospf_nbr_nbma *
paul68980082003-03-25 05:07:42 +00001494ospf_nbr_nbma_lookup_next (struct ospf *ospf, struct in_addr *addr, int first)
paul718e3742002-12-13 20:15:29 +00001495{
1496#if 0
1497 struct ospf_nbr_nbma *nbr_nbma;
hasso52dc7ee2004-09-23 19:18:23 +00001498 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001499#endif
1500
paul68980082003-03-25 05:07:42 +00001501 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001502 return NULL;
1503
1504#if 0
paul1eb8ef22005-04-07 07:30:20 +00001505 for (ALL_LIST_ELEMENTS_RO (ospf->nbr_nbma, node, nbr_nbma))
paul718e3742002-12-13 20:15:29 +00001506 {
paul718e3742002-12-13 20:15:29 +00001507 if (first)
1508 {
1509 *addr = nbr_nbma->addr;
1510 return nbr_nbma;
1511 }
1512 else if (ntohl (nbr_nbma->addr.s_addr) > ntohl (addr->s_addr))
1513 {
1514 *addr = nbr_nbma->addr;
1515 return nbr_nbma;
1516 }
1517 }
1518#endif
1519 return NULL;
1520}
1521
1522int
1523ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr)
1524{
1525 struct ospf_nbr_nbma *nbr_nbma;
1526 struct ospf_interface *oi;
1527 struct prefix_ipv4 p;
1528 struct route_node *rn;
hasso52dc7ee2004-09-23 19:18:23 +00001529 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001530
1531 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1532 if (nbr_nbma)
1533 return 0;
1534
1535 nbr_nbma = ospf_nbr_nbma_new ();
1536 nbr_nbma->addr = nbr_addr;
1537
1538 p.family = AF_INET;
1539 p.prefix = nbr_addr;
1540 p.prefixlen = IPV4_MAX_BITLEN;
1541
1542 rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p);
1543 rn->info = nbr_nbma;
1544
paul1eb8ef22005-04-07 07:30:20 +00001545 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
paul718e3742002-12-13 20:15:29 +00001546 {
paul718e3742002-12-13 20:15:29 +00001547 if (oi->type == OSPF_IFTYPE_NBMA)
1548 if (prefix_match (oi->address, (struct prefix *)&p))
1549 {
1550 ospf_nbr_nbma_add (nbr_nbma, oi);
1551 break;
1552 }
1553 }
1554
1555 return 1;
1556}
1557
1558int
1559ospf_nbr_nbma_unset (struct ospf *ospf, struct in_addr nbr_addr)
1560{
1561 struct ospf_nbr_nbma *nbr_nbma;
1562
1563 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1564 if (nbr_nbma == NULL)
1565 return 0;
1566
1567 ospf_nbr_nbma_down (nbr_nbma);
1568 ospf_nbr_nbma_delete (ospf, nbr_nbma);
1569
1570 return 1;
1571}
1572
1573int
1574ospf_nbr_nbma_priority_set (struct ospf *ospf, struct in_addr nbr_addr,
1575 u_char priority)
1576{
1577 struct ospf_nbr_nbma *nbr_nbma;
1578
1579 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1580 if (nbr_nbma == NULL)
1581 return 0;
1582
1583 if (nbr_nbma->priority != priority)
1584 nbr_nbma->priority = priority;
1585
1586 return 1;
1587}
1588
1589int
1590ospf_nbr_nbma_priority_unset (struct ospf *ospf, struct in_addr nbr_addr)
1591{
1592 struct ospf_nbr_nbma *nbr_nbma;
1593
1594 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1595 if (nbr_nbma == NULL)
1596 return 0;
1597
1598 if (nbr_nbma != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
1599 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1600
1601 return 1;
1602}
1603
1604int
1605ospf_nbr_nbma_poll_interval_set (struct ospf *ospf, struct in_addr nbr_addr,
paul6c835672004-10-11 11:00:30 +00001606 unsigned int interval)
paul718e3742002-12-13 20:15:29 +00001607{
1608 struct ospf_nbr_nbma *nbr_nbma;
1609
1610 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1611 if (nbr_nbma == NULL)
1612 return 0;
1613
1614 if (nbr_nbma->v_poll != interval)
1615 {
1616 nbr_nbma->v_poll = interval;
1617 if (nbr_nbma->oi && ospf_if_is_up (nbr_nbma->oi))
1618 {
1619 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1620 OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer,
1621 nbr_nbma->v_poll);
1622 }
1623 }
1624
1625 return 1;
1626}
1627
1628int
1629ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr)
1630{
1631 struct ospf_nbr_nbma *nbr_nbma;
1632
1633 nbr_nbma = ospf_nbr_nbma_lookup (ospf, addr);
1634 if (nbr_nbma == NULL)
1635 return 0;
1636
1637 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
1638 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1639
1640 return 1;
1641}
1642
paul718e3742002-12-13 20:15:29 +00001643void
paul020709f2003-04-04 02:44:16 +00001644ospf_master_init ()
1645{
1646 memset (&ospf_master, 0, sizeof (struct ospf_master));
1647
1648 om = &ospf_master;
1649 om->ospf = list_new ();
1650 om->master = thread_master_create ();
1651 om->start_time = time (NULL);
1652}