blob: a1ad929d81f51782ebd98219ca77521c2bbb54b4 [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
55/* OSPF instance top. */
56struct ospf *ospf_top;
57
58extern struct zclient *zclient;
59
60
61void ospf_remove_vls_through_area (struct ospf_area *);
62void ospf_network_free (struct ospf_network *);
63void ospf_area_free (struct ospf_area *);
64void ospf_network_run (struct ospf *, struct prefix *, struct ospf_area *);
65
66/* Get Router ID from ospf interface list. */
67struct in_addr
68ospf_router_id_get (list if_list)
69{
70 listnode node;
71 struct in_addr router_id;
72
73 memset (&router_id, 0, sizeof (struct in_addr));
74
75 for (node = listhead (if_list); node; nextnode (node))
76 {
77 struct ospf_interface *oi = getdata (node);
78
79 if (!if_is_up (oi->ifp) ||
80 OSPF_IF_PARAM (oi, passive_interface) == OSPF_IF_PASSIVE)
81 continue;
82
83 /* Ignore virtual link interface. */
84 if (oi->type != OSPF_IFTYPE_VIRTUALLINK &&
85 oi->type != OSPF_IFTYPE_LOOPBACK)
86 if (IPV4_ADDR_CMP (&router_id, &oi->address->u.prefix4) < 0)
87 router_id = oi->address->u.prefix4;
88 }
89
90 return router_id;
91}
92
93#define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
94
95void
96ospf_router_id_update ()
97{
98 listnode node;
99 struct in_addr router_id, router_id_old;
100
101 if (IS_DEBUG_OSPF_EVENT)
102 zlog_info ("Router-ID[OLD:%s]: Update",inet_ntoa (ospf_top->router_id));
103
104 router_id_old = ospf_top->router_id;
105
106 if (ospf_top->router_id_static.s_addr != 0)
107 router_id = ospf_top->router_id_static;
108 else
109 router_id = ospf_router_id_get (ospf_top->oiflist);
110
111 ospf_top->router_id = router_id;
112
113 if (IS_DEBUG_OSPF_EVENT)
114 zlog_info ("Router-ID[NEW:%s]: Update", inet_ntoa (ospf_top->router_id));
115
116 if (!IPV4_ADDR_SAME (&router_id_old, &router_id))
117 {
118 for (node = listhead (ospf_top->oiflist); node; nextnode (node))
119 {
120 struct ospf_interface *oi = getdata (node);
121
122 /* Update self-neighbor's router_id. */
123 oi->nbr_self->router_id = router_id;
124 }
125
126 /* If AS-external-LSA is queued, then flush those LSAs. */
127 if (router_id_old.s_addr == 0 && ospf_top->external_origin)
128 {
129 int type;
130 /* Originate each redistributed external route. */
131 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
132 if (ospf_top->external_origin & (1 << type))
133 thread_add_event (master, ospf_external_lsa_originate_timer,
134 NULL, type);
135 /* Originate Deafult. */
136 if (ospf_top->external_origin & (1 << ZEBRA_ROUTE_MAX))
137 thread_add_event (master, ospf_default_originate_timer,
138 &ospf_top->default_originate, 0);
139
140 ospf_top->external_origin = 0;
141 }
142
143 OSPF_TIMER_ON (ospf_top->t_router_lsa_update,
144 ospf_router_lsa_update_timer, OSPF_LSA_UPDATE_DELAY);
145 }
146}
147
148int
149ospf_router_id_update_timer (struct thread *thread)
150{
151 if (IS_DEBUG_OSPF_EVENT)
152 zlog_info ("Router-ID: Update timer fired!");
153
154 ospf_top->t_router_id_update = NULL;
155 ospf_router_id_update ();
156
157 return 0;
158}
159
160/* For OSPF area sort by area id. */
161int
162ospf_area_id_cmp (struct ospf_area *a1, struct ospf_area *a2)
163{
164 if (ntohl (a1->area_id.s_addr) > ntohl (a2->area_id.s_addr))
165 return 1;
166 if (ntohl (a1->area_id.s_addr) < ntohl (a2->area_id.s_addr))
167 return -1;
168 return 0;
169}
170
171/* Allocate new ospf structure. */
172struct ospf *
173ospf_new ()
174{
175 int i;
176
177 struct ospf *new = XCALLOC (MTYPE_OSPF_TOP, sizeof (struct ospf));
178
179 new->router_id.s_addr = htonl (0);
180 new->router_id_static.s_addr = htonl (0);
181
182 new->abr_type = OSPF_ABR_STAND;
183 new->iflist = iflist;
184 new->oiflist = list_new ();
185 new->vlinks = list_new ();
186 new->areas = list_new ();
187 new->areas->cmp = (int (*)(void *, void *)) ospf_area_id_cmp;
188 new->networks = route_table_init ();
189 new->nbr_nbma = route_table_init ();
190
191 new->lsdb = ospf_lsdb_new ();
192
193 new->default_originate = DEFAULT_ORIGINATE_NONE;
194
195 new->new_external_route = route_table_init ();
196 new->old_external_route = route_table_init ();
197 new->external_lsas = route_table_init ();
198
199 /* Distribute parameter init. */
200 for (i = 0; i <= ZEBRA_ROUTE_MAX; i++)
201 {
202 new->dmetric[i].type = -1;
203 new->dmetric[i].value = -1;
204 }
205 new->default_metric = -1;
206 new->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
207
208 /* SPF timer value init. */
209 new->spf_delay = OSPF_SPF_DELAY_DEFAULT;
210 new->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
211
212 /* MaxAge init. */
213 new->maxage_lsa = list_new ();
214 new->t_maxage_walker =
215 thread_add_timer (master, ospf_lsa_maxage_walker,
216 NULL, OSPF_LSA_MAXAGE_CHECK_INTERVAL);
217
218 /* Distance table init. */
219 new->distance_table = route_table_init ();
220
221 new->lsa_refresh_queue.index = 0;
222 new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
223 new->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker,
224 new, new->lsa_refresh_interval);
225 new->lsa_refresher_started = time (NULL);
226
227 new->fd = ospf_sock_init ();
228 if (new->fd >= 0)
229 new->t_read = thread_add_read (master, ospf_read, new, new->fd);
230 new->oi_write_q = list_new ();
231
232 return new;
233}
234
235struct ospf *
236ospf_get ()
237{
238 if (ospf_top != NULL)
239 return ospf_top;
240
241 ospf_top = ospf_new ();
242
243 if (ospf_top->router_id_static.s_addr == 0)
244 ospf_router_id_update ();
245
246#ifdef HAVE_OPAQUE_LSA
247 ospf_opaque_type11_lsa_init (ospf_top);
248#endif /* HAVE_OPAQUE_LSA */
249
250 return ospf_top;
251}
252
253void
254ospf_finish (struct ospf *ospf)
255{
256 struct route_node *rn;
257 struct ospf_nbr_nbma *nbr_nbma;
258 listnode node;
259 int i;
260
261#ifdef HAVE_OPAQUE_LSA
262 ospf_opaque_type11_lsa_term (ospf);
263#endif /* HAVE_OPAQUE_LSA */
264
265 /* Unredister redistribution */
266 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
267 ospf_redistribute_unset (i);
268
269 for (node = listhead (ospf->areas); node;)
270 {
271 struct ospf_area *area = getdata (node);
272 nextnode (node);
273
274 ospf_remove_vls_through_area (area);
275 }
276
277 for (node = listhead (ospf->vlinks); node; )
278 {
279 struct ospf_vl_data *vl_data = node->data;
280 nextnode (node);
281
282 ospf_vl_delete (vl_data);
283 }
284
285 list_delete (ospf->vlinks);
286
287 /* Reset interface. */
288 for (node = listhead (ospf->oiflist); node;)
289 {
290 struct ospf_interface *oi = getdata (node);
291 nextnode (node);
292
293 if (oi)
294 ospf_if_free (oi);
295 }
296
297 /* Clear static neighbors */
298 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
299 if ((nbr_nbma = rn->info))
300 {
301 OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
302
303 if (nbr_nbma->nbr)
304 {
305 nbr_nbma->nbr->nbr_nbma = NULL;
306 nbr_nbma->nbr = NULL;
307 }
308
309 if (nbr_nbma->oi)
310 {
311 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
312 nbr_nbma->oi = NULL;
313 }
314
315 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
316 }
317
318 route_table_finish (ospf->nbr_nbma);
319
320 /* Clear networks and Areas. */
321 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
322 {
323 struct ospf_network *network;
324
325 if ((network = rn->info) != NULL)
326 {
327 ospf_network_free (network);
328 rn->info = NULL;
329 route_unlock_node (rn);
330 }
331 }
332
333 for (node = listhead (ospf->areas); node;)
334 {
335 struct ospf_area *area = getdata (node);
336 nextnode (node);
337
338 listnode_delete (ospf->areas, area);
339 ospf_area_free (area);
340 }
341
342 /* Cancel all timers. */
343 OSPF_TIMER_OFF (ospf->t_external_lsa);
344 OSPF_TIMER_OFF (ospf->t_router_id_update);
345 OSPF_TIMER_OFF (ospf->t_router_lsa_update);
346 OSPF_TIMER_OFF (ospf->t_spf_calc);
347 OSPF_TIMER_OFF (ospf->t_ase_calc);
348 OSPF_TIMER_OFF (ospf->t_maxage);
349 OSPF_TIMER_OFF (ospf->t_maxage_walker);
350 OSPF_TIMER_OFF (ospf->t_abr_task);
351 OSPF_TIMER_OFF (ospf->t_distribute_update);
352 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
353 OSPF_TIMER_OFF (ospf->t_read);
354 OSPF_TIMER_OFF (ospf->t_write);
355
356 close (ospf->fd);
357
358#ifdef HAVE_OPAQUE_LSA
359 foreach_lsa (OPAQUE_AS_LSDB (ospf), ospf_top->lsdb, 0,
360 ospf_lsa_discard_callback);
361#endif /* HAVE_OPAQUE_LSA */
362 foreach_lsa (EXTERNAL_LSDB (ospf), ospf->lsdb, 0,
363 ospf_lsa_discard_callback);
364 ospf_lsdb_delete_all (ospf->lsdb);
365 ospf_lsdb_free (ospf->lsdb);
366
367 for (node = listhead (ospf->maxage_lsa); node; nextnode (node))
368 ospf_lsa_unlock (getdata (node));
369
370 list_delete (ospf->maxage_lsa);
371
372 if (ospf->old_table)
373 ospf_route_table_free (ospf->old_table);
374 if (ospf->new_table)
375 {
376 ospf_route_delete (ospf->new_table);
377 ospf_route_table_free (ospf->new_table);
378 }
379 if (ospf->old_rtrs)
380 ospf_rtrs_free (ospf->old_rtrs);
381 if (ospf->new_rtrs)
382 ospf_rtrs_free (ospf->new_rtrs);
383 if (ospf->new_external_route)
384 {
385 ospf_route_delete (ospf->new_external_route);
386 ospf_route_table_free (ospf->new_external_route);
387 }
388 if (ospf->old_external_route)
389 {
390 ospf_route_delete (ospf->old_external_route);
391 ospf_route_table_free (ospf->old_external_route);
392 }
393 if (ospf->external_lsas)
394 {
395 ospf_ase_external_lsas_finish (ospf->external_lsas);
396 }
397
398 list_delete (ospf->areas);
399
400 for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++)
401 if (EXTERNAL_INFO (i) != NULL)
402 for (rn = route_top (EXTERNAL_INFO (i)); rn; rn = route_next (rn))
403 {
404 if (rn->info == NULL)
405 continue;
406
407 XFREE (MTYPE_OSPF_EXTERNAL_INFO, rn->info);
408 rn->info = NULL;
409 route_unlock_node (rn);
410 }
411
412 ospf_distance_reset ();
413 route_table_finish (ospf->distance_table);
414
415 XFREE (MTYPE_OSPF_TOP, ospf);
416
417 ospf_top = NULL;
418}
419
420
421/* allocate new OSPF Area object */
422struct ospf_area *
423ospf_area_new (struct in_addr area_id)
424{
425 struct ospf_area *new;
426
427 /* Allocate new config_network. */
428 new = XCALLOC (MTYPE_OSPF_AREA, sizeof (struct ospf_area));
429
430 new->top = ospf_top;
431
432 new->area_id = area_id;
433
434 new->external_routing = OSPF_AREA_DEFAULT;
435 new->default_cost = 1;
436 new->auth_type = OSPF_AUTH_NULL;
437
438 /* New LSDB init. */
439 new->lsdb = ospf_lsdb_new ();
440
441 /* Self-originated LSAs initialize. */
442 new->router_lsa_self = NULL;
443
444#ifdef HAVE_OPAQUE_LSA
445 ospf_opaque_type10_lsa_init (new);
446#endif /* HAVE_OPAQUE_LSA */
447
448 new->oiflist = list_new ();
449 new->ranges = route_table_init ();
450
451 if (area_id.s_addr == OSPF_AREA_BACKBONE)
452 ospf_top->backbone = new;
453
454 return new;
455}
456
457void
458ospf_area_free (struct ospf_area *area)
459{
460 /* Free LSDBs. */
461 foreach_lsa (ROUTER_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback);
462 foreach_lsa (NETWORK_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback);
463 foreach_lsa (SUMMARY_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback);
464 foreach_lsa (ASBR_SUMMARY_LSDB (area), area->lsdb, 0,
465 ospf_lsa_discard_callback);
466
467#ifdef HAVE_NSSA
468 foreach_lsa (NSSA_LSDB (area), area->lsdb, 0, ospf_lsa_discard_callback);
469#endif /* HAVE_NSSA */
470#ifdef HAVE_OPAQUE_LSA
471 foreach_lsa (OPAQUE_AREA_LSDB (area), area->lsdb, 0,
472 ospf_lsa_discard_callback);
473 foreach_lsa (OPAQUE_LINK_LSDB (area), area->lsdb, 0,
474 ospf_lsa_discard_callback);
475#endif /* HAVE_OPAQUE_LSA */
476
477 ospf_lsdb_delete_all (area->lsdb);
478 ospf_lsdb_free (area->lsdb);
479
480#ifdef HAVE_OPAQUE_LSA
481 ospf_opaque_type10_lsa_term (area);
482#endif /* HAVE_OPAQUE_LSA */
483 ospf_lsa_unlock (area->router_lsa_self);
484
485 route_table_finish (area->ranges);
486 list_delete (area->oiflist);
487
488 if (EXPORT_NAME (area))
489 free (EXPORT_NAME (area));
490
491 if (IMPORT_NAME (area))
492 free (IMPORT_NAME (area));
493
494 /* Cancel timer. */
495 OSPF_TIMER_OFF (area->t_router_lsa_self);
496
497 if (OSPF_IS_AREA_BACKBONE (area))
498 ospf_top->backbone = NULL;
499
500 XFREE (MTYPE_OSPF_AREA, area);
501}
502
503void
504ospf_area_check_free (struct in_addr area_id)
505{
506 struct ospf_area *area;
507
508 area = ospf_area_lookup_by_area_id (area_id);
509 if (area &&
510 listcount (area->oiflist) == 0 &&
511 area->ranges->top == NULL &&
512 area->shortcut_configured == OSPF_SHORTCUT_DEFAULT &&
513 area->external_routing == OSPF_AREA_DEFAULT &&
514 area->no_summary == 0 &&
515 area->default_cost == 1 &&
516 EXPORT_NAME (area) == NULL &&
517 IMPORT_NAME (area) == NULL &&
518 area->auth_type == OSPF_AUTH_NULL)
519 {
520 listnode_delete (ospf_top->areas, area);
521 ospf_area_free (area);
522 }
523}
524
525struct ospf_area *
526ospf_area_get (struct in_addr area_id, int format)
527{
528 struct ospf_area *area;
529
530 area = ospf_area_lookup_by_area_id (area_id);
531 if (!area)
532 {
533 area = ospf_area_new (area_id);
534 area->format = format;
535 listnode_add_sort (ospf_top->areas, area);
536 ospf_check_abr_status ();
537 }
538
539 return area;
540}
541
542struct ospf_area *
543ospf_area_lookup_by_area_id (struct in_addr area_id)
544{
545 struct ospf_area *area;
546 listnode node;
547
548 for (node = listhead (ospf_top->areas); node; nextnode (node))
549 {
550 area = getdata (node);
551
552 if (IPV4_ADDR_SAME (&area->area_id, &area_id))
553 return area;
554 }
555
556 return NULL;
557}
558
559void
560ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi)
561{
562 listnode_add (area->oiflist, oi);
563}
564
565void
566ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi)
567{
568 listnode_delete (area->oiflist, oi);
569}
570
571
572/* Config network statement related functions. */
573struct ospf_network *
574ospf_network_new (struct in_addr area_id, int format)
575{
576 struct ospf_network *new;
577 new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network));
578
579 new->area_id = area_id;
580 new->format = format;
581
582 return new;
583}
584
585void
586ospf_network_free (struct ospf_network *network)
587{
588 ospf_area_check_free (network->area_id);
589 ospf_schedule_abr_task ();
590 XFREE (MTYPE_OSPF_NETWORK, network);
591}
592
593int
594ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p,
595 struct in_addr area_id)
596{
597 struct ospf_network *network;
598 struct ospf_area *area;
599 struct route_node *rn;
600 struct external_info *ei;
601 int ret = OSPF_AREA_ID_FORMAT_DECIMAL;
602
603 rn = route_node_get (ospf->networks, (struct prefix *)p);
604 if (rn->info)
605 {
606 /* There is already same network statement. */
607 route_unlock_node (rn);
608 return 0;
609 }
610
611 rn->info = network = ospf_network_new (area_id, ret);
612 area = ospf_area_get (area_id, ret);
613
614 /* Run network config now. */
615 ospf_network_run (ospf, (struct prefix *)p, area);
616
617 /* Update connected redistribute. */
618 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
619 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
620 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
621 rn; rn = route_next (rn))
622 if ((ei = rn->info) != NULL)
623 if (ospf_external_info_find_lsa (&ei->p))
624 if (!ospf_distribute_check_connected (ei))
625 ospf_external_lsa_flush (ei->type, &ei->p,
626 ei->ifindex, ei->nexthop);
627
628 ospf_area_check_free (area_id);
629
630 return 1;
631}
632
633int
634ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
635 struct in_addr area_id)
636{
637 struct route_node *rn;
638 struct ospf_network *network;
639 struct external_info *ei;
640
641 rn = route_node_lookup (ospf->networks, (struct prefix *)p);
642 if (rn == NULL)
643 return 0;
644
645 network = rn->info;
646 if (!IPV4_ADDR_SAME (&area_id, &network->area_id))
647 return 0;
648
649 ospf_network_free (rn->info);
650 rn->info = NULL;
651 route_unlock_node (rn);
652
653 ospf_if_update ();
654
655 /* Update connected redistribute. */
656 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
657 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
658 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
659 rn; rn = route_next (rn))
660 if ((ei = rn->info) != NULL)
661 if (!ospf_external_info_find_lsa (&ei->p))
662 if (ospf_distribute_check_connected (ei))
663 ospf_external_lsa_originate (ei);
664
665 return 1;
666}
667
paul570f7592003-01-25 06:47:41 +0000668/* Check whether interface matches given network
669 * returns: 1, true. 0, false
670 */
671int
672ospf_network_match_iface(struct connected *co, struct prefix *net)
673{
674 /* Behaviour to match both Cisco where:
675 * iface address lies within network specified -> ospf
676 * and zebra 0.9[2ish-3]:
677 * PtP special case: network specified == iface peer addr -> ospf
678 */
679 return (
680 ((ifc_pointopoint (co) &&
681 IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
682 || prefix_match (net, co->address))
683 ? 1 : 0
684 );
685}
686
paul718e3742002-12-13 20:15:29 +0000687void
688ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area)
689{
690 struct interface *ifp;
691 listnode node;
692
693 /* Schedule Router ID Update. */
694 if (ospf->router_id_static.s_addr == 0)
695 if (ospf->t_router_id_update == NULL)
696 {
697 ospf->t_router_id_update =
698 thread_add_timer (master, ospf_router_id_update_timer, ospf,
699 OSPF_ROUTER_ID_UPDATE_DELAY);
700 }
701
702 /* Get target interface. */
703 for (node = listhead (ospf->iflist); node; nextnode (node))
704 {
705 listnode cn;
706
707 if ((ifp = getdata (node)) == NULL)
708 continue;
709
710 if (memcmp (ifp->name, "VLINK", 5) == 0)
711 continue;
712
713 /* if interface prefix is match specified prefix,
714 then create socket and join multicast group. */
715 for (cn = listhead (ifp->connected); cn; nextnode (cn))
716 {
717 struct connected *co = getdata (cn);
718 struct prefix *addr;
719
paul00df0c12002-12-13 21:07:36 +0000720 if (ifc_pointopoint (co))
paul718e3742002-12-13 20:15:29 +0000721 addr = co->destination;
722 else
723 addr = co->address;
724
paul570f7592003-01-25 06:47:41 +0000725 if (ospf_network_match_iface(co,p))
726 {
727 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +0000728
729 oi = ospf_if_new (ifp, co->address);
730 oi->connected = co;
731
732 oi->nbr_self->address = *oi->address;
733
734 area->act_ints++;
735 oi->area = area;
736
737 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
738 oi->output_cost = ospf_if_get_output_cost (oi);
739
740 if (area->external_routing != OSPF_AREA_DEFAULT)
741 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
742 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
743
744 /* Add pseudo neighbor. */
745 ospf_nbr_add_self (oi);
746
747 /* Make sure pseudo neighbor's router_id. */
748 oi->nbr_self->router_id = ospf_top->router_id;
749 oi->nbr_self->src = oi->address->u.prefix4;
750
751 /* Relate ospf interface to ospf instance. */
752 oi->ospf = ospf_top;
753
754 /* update network type as interface flag */
755 /* If network type is specified previously,
756 skip network type setting. */
757 oi->type = IF_DEF_PARAMS (ifp)->type;
758
759 /* Set area flag. */
760 switch (area->external_routing)
761 {
762 case OSPF_AREA_DEFAULT:
763 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
764 break;
765 case OSPF_AREA_STUB:
766 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
767 break;
768#ifdef HAVE_NSSA
769 case OSPF_AREA_NSSA:
770 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
771 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
772 break;
773#endif /* HAVE_NSSA */
774 }
775
776 ospf_area_add_if (oi->area, oi);
777
paul2e3b2e42002-12-13 21:03:13 +0000778 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000779 ospf_if_up (oi);
780
781 break;
782 }
783 }
784 }
785}
786
787void
788ospf_ls_upd_queue_empty (struct ospf_interface *oi)
789{
790 struct route_node *rn;
791 listnode node;
792 list lst;
793 struct ospf_lsa *lsa;
794
795 /* empty ls update queue */
796 for (rn = route_top (oi->ls_upd_queue); rn;
797 rn = route_next (rn))
798 if ((lst = (list) rn->info))
799 {
800 for (node = listhead (lst); node; nextnode (node))
801 if ((lsa = getdata (node)))
802 ospf_lsa_unlock (lsa);
803 list_free (lst);
804 rn->info = NULL;
805 }
806
807 /* remove update event */
808 if (oi->t_ls_upd_event)
809 {
810 thread_cancel (oi->t_ls_upd_event);
811 oi->t_ls_upd_event = NULL;
812 }
813}
814
815void
816ospf_if_update ()
817{
818 struct route_node *rn;
819 listnode node;
820 listnode next;
821 struct ospf_network *network;
822 struct ospf_area *area;
823
824 if (ospf_top != NULL)
825 {
826 /* Update Router ID scheduled. */
827 if (ospf_top->router_id_static.s_addr == 0)
828 if (ospf_top->t_router_id_update == NULL)
829 {
830 ospf_top->t_router_id_update =
831 thread_add_timer (master, ospf_router_id_update_timer, NULL,
832 OSPF_ROUTER_ID_UPDATE_DELAY);
833 }
834
835 /* Find interfaces that not configured already. */
836 for (node = listhead (ospf_top->oiflist); node; node = next)
837 {
838 int found = 0;
839 struct ospf_interface *oi = getdata (node);
840 struct connected *co = oi->connected;
841
842 next = nextnode (node);
843
844 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
845 continue;
846
847 for (rn = route_top (ospf_top->networks); rn; rn = route_next (rn))
848 {
849 if (rn->info == NULL)
850 continue;
851
paul570f7592003-01-25 06:47:41 +0000852 if (ospf_network_match_iface(co,&rn->p))
paul718e3742002-12-13 20:15:29 +0000853 {
854 found = 1;
855 route_unlock_node (rn);
856 break;
857 }
858 }
859
860 if (found == 0)
861 ospf_if_free (oi);
862 }
863
864 /* Run each interface. */
865 for (rn = route_top (ospf_top->networks); rn; rn = route_next (rn))
866 if (rn->info != NULL)
867 {
868 network = (struct ospf_network *) rn->info;
869 area = ospf_area_get (network->area_id, network->format);
870 ospf_network_run (ospf_top, &rn->p, area);
871 }
872 }
873}
874
875void
876ospf_remove_vls_through_area (struct ospf_area *area)
877{
878 listnode node, next;
879 struct ospf_vl_data *vl_data;
880
881 for (node = listhead (ospf_top->vlinks); node; node = next)
882 {
883 next = node->next;
884 if ((vl_data = getdata (node)) != NULL)
885 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
886 ospf_vl_delete (vl_data);
887 }
888}
889
890
891struct message ospf_area_type_msg[] =
892{
893 { OSPF_AREA_DEFAULT, "Default" },
894 { OSPF_AREA_STUB, "Stub" },
895 { OSPF_AREA_NSSA, "NSSA" },
896};
897int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX;
898
899void
900ospf_area_type_set (struct ospf_area *area, int type)
901{
902 listnode node;
903 struct ospf_interface *oi;
904
905 if (area->external_routing == type)
906 {
907 if (IS_DEBUG_OSPF_EVENT)
908 zlog_info ("Area[%s]: Types are the same, ignored.",
909 inet_ntoa (area->area_id));
910 return;
911 }
912
913 area->external_routing = type;
914
915 if (IS_DEBUG_OSPF_EVENT)
916 zlog_info ("Area[%s]: Configured as %s", inet_ntoa (area->area_id),
917 LOOKUP (ospf_area_type_msg, type));
918
919 switch (area->external_routing)
920 {
921 case OSPF_AREA_DEFAULT:
922 for (node = listhead (area->oiflist); node; nextnode (node))
923 if ((oi = getdata (node)) != NULL)
924 if (oi->nbr_self != NULL)
925 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
926 break;
927 case OSPF_AREA_STUB:
928 for (node = listhead (area->oiflist); node; nextnode (node))
929 if ((oi = getdata (node)) != NULL)
930 if (oi->nbr_self != NULL)
931 {
932 if (IS_DEBUG_OSPF_EVENT)
933 zlog_info ("setting options on %s accordingly", IF_NAME (oi));
934 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
935 if (IS_DEBUG_OSPF_EVENT)
936 zlog_info ("options set on %s: %x",
937 IF_NAME (oi), OPTIONS (oi));
938 }
939 break;
940 case OSPF_AREA_NSSA:
941#ifdef HAVE_NSSA
942 for (node = listhead (area->oiflist); node; nextnode (node))
943 if ((oi = getdata (node)) != NULL)
944 if (oi->nbr_self != NULL)
945 {
946 zlog_info ("setting nssa options on %s accordingly", IF_NAME (oi));
947 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
948 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
949 zlog_info ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi));
950 }
951#endif /* HAVE_NSSA */
952 break;
953 default:
954 break;
955 }
956
957 ospf_router_lsa_timer_add (area);
958 ospf_schedule_abr_task ();
959}
960
961int
962ospf_area_shortcut_set (struct ospf_area *area, int mode)
963{
964 if (area->shortcut_configured == mode)
965 return 0;
966
967 area->shortcut_configured = mode;
968 ospf_router_lsa_timer_add (area);
969 ospf_schedule_abr_task ();
970
971 ospf_area_check_free (area->area_id);
972
973 return 1;
974}
975
976int
977ospf_area_shortcut_unset (struct ospf_area *area)
978{
979 area->shortcut_configured = OSPF_SHORTCUT_DEFAULT;
980 ospf_router_lsa_timer_add (area);
981 ospf_area_check_free (area->area_id);
982 ospf_schedule_abr_task ();
983
984 return 1;
985}
986
987int
988ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area)
989{
990 struct ospf_vl_data *vl;
991 listnode node;
992 int count = 0;
993
994 for (node = listhead (ospf->vlinks); node; nextnode (node))
995 {
996 vl = getdata (node);
997 if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id))
998 count++;
999 }
1000
1001 return count;
1002}
1003
1004int
1005ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id)
1006{
1007 struct ospf_area *area;
1008 int format = OSPF_AREA_ID_FORMAT_DECIMAL;
1009
1010 area = ospf_area_get (area_id, format);
1011 if (ospf_area_vlink_count (ospf, area))
1012 return 0;
1013
1014 if (area->external_routing != OSPF_AREA_STUB)
1015 ospf_area_type_set (area, OSPF_AREA_STUB);
1016
1017 return 1;
1018}
1019
1020int
1021ospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id)
1022{
1023 struct ospf_area *area;
1024
1025 area = ospf_area_lookup_by_area_id (area_id);
1026 if (area == NULL)
1027 return 1;
1028
1029 if (area->external_routing == OSPF_AREA_STUB)
1030 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1031
1032 ospf_area_check_free (area_id);
1033
1034 return 1;
1035}
1036
1037int
1038ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id)
1039{
1040 struct ospf_area *area;
1041 int format = OSPF_AREA_ID_FORMAT_DECIMAL;
1042
1043 area = ospf_area_get (area_id, format);
1044 area->no_summary = 1;
1045
1046 return 1;
1047}
1048
1049int
1050ospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id)
1051{
1052 struct ospf_area *area;
1053
1054 area = ospf_area_lookup_by_area_id (area_id);
1055 if (area == NULL)
1056 return 0;
1057
1058 area->no_summary = 0;
1059 ospf_area_check_free (area_id);
1060
1061 return 1;
1062}
1063
1064int
1065ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id)
1066{
1067 struct ospf_area *area;
1068 int format = OSPF_AREA_ID_FORMAT_DECIMAL;
1069
1070 area = ospf_area_get (area_id, format);
1071 if (ospf_area_vlink_count (ospf, area))
1072 return 0;
1073
1074 if (area->external_routing != OSPF_AREA_NSSA)
1075 {
1076 ospf_area_type_set (area, OSPF_AREA_NSSA);
1077 ospf->anyNSSA++;
1078 }
1079
1080 return 1;
1081}
1082
1083int
1084ospf_area_nssa_unset (struct ospf *ospf, struct in_addr area_id)
1085{
1086 struct ospf_area *area;
1087
1088 area = ospf_area_lookup_by_area_id (area_id);
1089 if (area == NULL)
1090 return 0;
1091
1092 if (area->external_routing == OSPF_AREA_NSSA)
1093 {
1094 ospf->anyNSSA--;
1095 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1096 }
1097
1098 ospf_area_check_free (area_id);
1099
1100 return 1;
1101}
1102
1103int
1104ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id,
1105 int role)
1106{
1107 struct ospf_area *area;
1108
1109 area = ospf_area_lookup_by_area_id (area_id);
1110 if (area == NULL)
1111 return 0;
1112
1113 area->NSSATranslator = role;
1114
1115 return 1;
1116}
1117
1118int
1119ospf_area_nssa_translator_role_unset (struct ospf *ospf,
1120 struct in_addr area_id)
1121{
1122 struct ospf_area *area;
1123
1124 area = ospf_area_lookup_by_area_id (area_id);
1125 if (area == NULL)
1126 return 0;
1127
1128 area->NSSATranslator = OSPF_NSSA_ROLE_CANDIDATE;
1129
1130 ospf_area_check_free (area_id);
1131
1132 return 1;
1133}
1134
1135int
1136ospf_area_export_list_set (struct ospf_area *area, char *list_name)
1137{
1138 struct access_list *list;
1139 list = access_list_lookup (AFI_IP, list_name);
1140
1141 EXPORT_LIST (area) = list;
1142
1143 if (EXPORT_NAME (area))
1144 free (EXPORT_NAME (area));
1145
1146 EXPORT_NAME (area) = strdup (list_name);
1147 ospf_schedule_abr_task ();
1148
1149 return 1;
1150}
1151
1152int
1153ospf_area_export_list_unset (struct ospf_area * area)
1154{
1155
1156 EXPORT_LIST (area) = 0;
1157
1158 if (EXPORT_NAME (area))
1159 free (EXPORT_NAME (area));
1160
1161 EXPORT_NAME (area) = NULL;
1162
1163 ospf_area_check_free (area->area_id);
1164
1165 ospf_schedule_abr_task ();
1166
1167 return 1;
1168}
1169
1170int
1171ospf_area_import_list_set (struct ospf_area *area, char *name)
1172{
1173 struct access_list *list;
1174 list = access_list_lookup (AFI_IP, name);
1175
1176 IMPORT_LIST (area) = list;
1177
1178 if (IMPORT_NAME (area))
1179 free (IMPORT_NAME (area));
1180
1181 IMPORT_NAME (area) = strdup (name);
1182 ospf_schedule_abr_task ();
1183
1184 return 1;
1185}
1186
1187int
1188ospf_area_import_list_unset (struct ospf_area * area)
1189{
1190 IMPORT_LIST (area) = 0;
1191
1192 if (IMPORT_NAME (area))
1193 free (IMPORT_NAME (area));
1194
1195 IMPORT_NAME (area) = NULL;
1196 ospf_area_check_free (area->area_id);
1197
1198 ospf_schedule_abr_task ();
1199
1200 return 1;
1201}
1202
1203int
1204ospf_timers_spf_set (struct ospf *ospf, u_int32_t delay, u_int32_t hold)
1205{
1206 ospf->spf_delay = delay;
1207 ospf->spf_holdtime = hold;
1208
1209 return 1;
1210}
1211
1212int
1213ospf_timers_spf_unset (struct ospf *ospf)
1214{
1215 ospf->spf_delay = OSPF_SPF_DELAY_DEFAULT;
1216 ospf->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
1217
1218 return 1;
1219}
1220
1221int
1222ospf_timers_refresh_set (struct ospf *ospf, int interval)
1223{
1224 int time_left;
1225
1226 if (ospf->lsa_refresh_interval == interval)
1227 return 1;
1228
1229 time_left = ospf->lsa_refresh_interval -
1230 (time (NULL) - ospf->lsa_refresher_started);
1231
1232 if (time_left > interval)
1233 {
1234 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1235 ospf->t_lsa_refresher =
1236 thread_add_timer (master, ospf_lsa_refresh_walker, ospf, interval);
1237 }
1238 ospf->lsa_refresh_interval = interval;
1239
1240 return 1;
1241}
1242
1243int
1244ospf_timers_refresh_unset (struct ospf *ospf)
1245{
1246 int time_left;
1247
1248 time_left = ospf->lsa_refresh_interval -
1249 (time (NULL) - ospf->lsa_refresher_started);
1250
1251 if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
1252 {
1253 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1254 ospf->t_lsa_refresher =
1255 thread_add_timer (master, ospf_lsa_refresh_walker, ospf,
1256 OSPF_LSA_REFRESH_INTERVAL_DEFAULT);
1257 }
1258
1259 ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
1260
1261 return 1;
1262}
1263
1264
1265struct ospf_nbr_nbma *
1266ospf_nbr_nbma_new ()
1267{
1268 struct ospf_nbr_nbma *nbr_nbma;
1269
1270 nbr_nbma = XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC,
1271 sizeof (struct ospf_nbr_nbma));
1272 memset (nbr_nbma, 0, sizeof (struct ospf_nbr_nbma));
1273
1274 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1275 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1276
1277 return nbr_nbma;
1278}
1279
1280void
1281ospf_nbr_nbma_free (struct ospf_nbr_nbma *nbr_nbma)
1282{
1283 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
1284}
1285
1286void
1287ospf_nbr_nbma_delete (struct ospf *ospf, struct ospf_nbr_nbma *nbr_nbma)
1288{
1289 struct route_node *rn;
1290 struct prefix_ipv4 p;
1291
1292 p.family = AF_INET;
1293 p.prefix = nbr_nbma->addr;
1294 p.prefixlen = IPV4_MAX_BITLEN;
1295
1296 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1297 if (rn)
1298 {
1299 ospf_nbr_nbma_free (rn->info);
1300 rn->info = NULL;
1301 route_unlock_node (rn);
1302 route_unlock_node (rn);
1303 }
1304}
1305
1306void
1307ospf_nbr_nbma_down (struct ospf_nbr_nbma *nbr_nbma)
1308{
1309 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1310
1311 if (nbr_nbma->nbr)
1312 {
1313 nbr_nbma->nbr->nbr_nbma = NULL;
1314 OSPF_NSM_EVENT_EXECUTE (nbr_nbma->nbr, NSM_KillNbr);
1315 }
1316
1317 if (nbr_nbma->oi)
1318 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
1319}
1320
1321void
1322ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma,
1323 struct ospf_interface *oi)
1324{
1325 struct ospf_neighbor *nbr;
1326 struct route_node *rn;
1327 struct prefix p;
1328
1329 if (oi->type != OSPF_IFTYPE_NBMA)
1330 return;
1331
1332 if (nbr_nbma->nbr != NULL)
1333 return;
1334
1335 if (IPV4_ADDR_SAME (&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr))
1336 return;
1337
1338 nbr_nbma->oi = oi;
1339 listnode_add (oi->nbr_nbma, nbr_nbma);
1340
1341 /* Get neighbor information from table. */
1342 p.family = AF_INET;
1343 p.prefixlen = IPV4_MAX_BITLEN;
1344 p.u.prefix4 = nbr_nbma->addr;
1345
1346 rn = route_node_get (oi->nbrs, (struct prefix *)&p);
1347 if (rn->info)
1348 {
1349 nbr = rn->info;
1350 nbr->nbr_nbma = nbr_nbma;
1351 nbr_nbma->nbr = nbr;
1352
1353 route_unlock_node (rn);
1354 }
1355 else
1356 {
1357 nbr = rn->info = ospf_nbr_new (oi);
1358 nbr->state = NSM_Down;
1359 nbr->src = nbr_nbma->addr;
1360 nbr->nbr_nbma = nbr_nbma;
1361 nbr->priority = nbr_nbma->priority;
1362 nbr->address = p;
1363
1364 nbr_nbma->nbr = nbr;
1365
1366 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start);
1367 }
1368}
1369
1370void
1371ospf_nbr_nbma_if_update (struct ospf_interface *oi)
1372{
1373 struct ospf_nbr_nbma *nbr_nbma;
1374 struct route_node *rn;
1375 struct prefix_ipv4 p;
1376
1377 if (oi->type != OSPF_IFTYPE_NBMA)
1378 return;
1379
1380 for (rn = route_top (ospf_top->nbr_nbma); rn; rn = route_next (rn))
1381 if ((nbr_nbma = rn->info))
1382 if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL)
1383 {
1384 p.family = AF_INET;
1385 p.prefix = nbr_nbma->addr;
1386 p.prefixlen = IPV4_MAX_BITLEN;
1387
1388 if (prefix_match (oi->address, (struct prefix *)&p))
1389 ospf_nbr_nbma_add (nbr_nbma, oi);
1390 }
1391}
1392
1393struct ospf_nbr_nbma *
1394ospf_nbr_nbma_lookup (struct ospf *ospf, struct in_addr nbr_addr)
1395{
1396 struct route_node *rn;
1397 struct prefix_ipv4 p;
1398
1399 p.family = AF_INET;
1400 p.prefix = nbr_addr;
1401 p.prefixlen = IPV4_MAX_BITLEN;
1402
1403 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1404 if (rn)
1405 {
1406 route_unlock_node (rn);
1407 return rn->info;
1408 }
1409 return NULL;
1410}
1411
1412struct ospf_nbr_nbma *
1413ospf_nbr_nbma_lookup_next (struct in_addr *addr, int first)
1414{
1415#if 0
1416 struct ospf_nbr_nbma *nbr_nbma;
1417 listnode node;
1418#endif
1419
1420 if (! ospf_top)
1421 return NULL;
1422
1423#if 0
1424 for (node = listhead (ospf_top->nbr_nbma); node; nextnode (node))
1425 {
1426 nbr_nbma = getdata (node);
1427
1428 if (first)
1429 {
1430 *addr = nbr_nbma->addr;
1431 return nbr_nbma;
1432 }
1433 else if (ntohl (nbr_nbma->addr.s_addr) > ntohl (addr->s_addr))
1434 {
1435 *addr = nbr_nbma->addr;
1436 return nbr_nbma;
1437 }
1438 }
1439#endif
1440 return NULL;
1441}
1442
1443int
1444ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr)
1445{
1446 struct ospf_nbr_nbma *nbr_nbma;
1447 struct ospf_interface *oi;
1448 struct prefix_ipv4 p;
1449 struct route_node *rn;
1450 listnode node;
1451
1452 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1453 if (nbr_nbma)
1454 return 0;
1455
1456 nbr_nbma = ospf_nbr_nbma_new ();
1457 nbr_nbma->addr = nbr_addr;
1458
1459 p.family = AF_INET;
1460 p.prefix = nbr_addr;
1461 p.prefixlen = IPV4_MAX_BITLEN;
1462
1463 rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p);
1464 rn->info = nbr_nbma;
1465
1466 for (node = listhead (ospf->oiflist); node; nextnode (node))
1467 {
1468 oi = getdata (node);
1469 if (oi->type == OSPF_IFTYPE_NBMA)
1470 if (prefix_match (oi->address, (struct prefix *)&p))
1471 {
1472 ospf_nbr_nbma_add (nbr_nbma, oi);
1473 break;
1474 }
1475 }
1476
1477 return 1;
1478}
1479
1480int
1481ospf_nbr_nbma_unset (struct ospf *ospf, struct in_addr nbr_addr)
1482{
1483 struct ospf_nbr_nbma *nbr_nbma;
1484
1485 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1486 if (nbr_nbma == NULL)
1487 return 0;
1488
1489 ospf_nbr_nbma_down (nbr_nbma);
1490 ospf_nbr_nbma_delete (ospf, nbr_nbma);
1491
1492 return 1;
1493}
1494
1495int
1496ospf_nbr_nbma_priority_set (struct ospf *ospf, struct in_addr nbr_addr,
1497 u_char priority)
1498{
1499 struct ospf_nbr_nbma *nbr_nbma;
1500
1501 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1502 if (nbr_nbma == NULL)
1503 return 0;
1504
1505 if (nbr_nbma->priority != priority)
1506 nbr_nbma->priority = priority;
1507
1508 return 1;
1509}
1510
1511int
1512ospf_nbr_nbma_priority_unset (struct ospf *ospf, struct in_addr nbr_addr)
1513{
1514 struct ospf_nbr_nbma *nbr_nbma;
1515
1516 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1517 if (nbr_nbma == NULL)
1518 return 0;
1519
1520 if (nbr_nbma != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
1521 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1522
1523 return 1;
1524}
1525
1526int
1527ospf_nbr_nbma_poll_interval_set (struct ospf *ospf, struct in_addr nbr_addr,
1528 int interval)
1529{
1530 struct ospf_nbr_nbma *nbr_nbma;
1531
1532 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1533 if (nbr_nbma == NULL)
1534 return 0;
1535
1536 if (nbr_nbma->v_poll != interval)
1537 {
1538 nbr_nbma->v_poll = interval;
1539 if (nbr_nbma->oi && ospf_if_is_up (nbr_nbma->oi))
1540 {
1541 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1542 OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer,
1543 nbr_nbma->v_poll);
1544 }
1545 }
1546
1547 return 1;
1548}
1549
1550int
1551ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr)
1552{
1553 struct ospf_nbr_nbma *nbr_nbma;
1554
1555 nbr_nbma = ospf_nbr_nbma_lookup (ospf, addr);
1556 if (nbr_nbma == NULL)
1557 return 0;
1558
1559 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
1560 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1561
1562 return 1;
1563}
1564
1565
1566void
1567ospf_prefix_list_update (struct prefix_list *plist)
1568{
1569 struct ospf_area *area;
1570 listnode node;
1571 int abr_inv = 0;
1572
1573 /* If OSPF instatnce does not exist, return right now. */
1574 if (!ospf_top)
1575 return;
1576
1577 /* Update Area prefix-list. */
1578 for (node = listhead (ospf_top->areas); node; nextnode (node))
1579 {
1580 area = getdata (node);
1581
1582 /* Update filter-list in. */
1583 if (PREFIX_NAME_IN (area))
1584 if (strcmp (PREFIX_NAME_IN (area), plist->name) == 0)
1585 {
1586 PREFIX_LIST_IN (area) =
1587 prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area));
1588 abr_inv++;
1589 }
1590
1591 /* Update filter-list out. */
1592 if (PREFIX_NAME_OUT (area))
1593 if (strcmp (PREFIX_NAME_OUT (area), plist->name) == 0)
1594 {
1595 PREFIX_LIST_IN (area) =
1596 prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area));
1597 abr_inv++;
1598 }
1599 }
1600
1601 /* Schedule ABR tasks. */
1602 if (OSPF_IS_ABR && abr_inv)
1603 ospf_schedule_abr_task ();
1604}
1605
1606void
1607ospf_init ()
1608{
1609 /* Make empty list of ospf list. */
1610 ospf_top = NULL;
1611
1612 prefix_list_add_hook (ospf_prefix_list_update);
1613 prefix_list_delete_hook (ospf_prefix_list_update);
1614}