blob: 6e205e640fa985a116f4f28af887ec95d4eb4cc4 [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);
paulcb3f37d2003-02-18 23:26:37 +0000475 ospf_opaque_type10_lsa_term (area);
paul718e3742002-12-13 20:15:29 +0000476#endif /* HAVE_OPAQUE_LSA */
477
478 ospf_lsdb_delete_all (area->lsdb);
479 ospf_lsdb_free (area->lsdb);
480
paul718e3742002-12-13 20:15:29 +0000481 ospf_lsa_unlock (area->router_lsa_self);
482
483 route_table_finish (area->ranges);
484 list_delete (area->oiflist);
485
486 if (EXPORT_NAME (area))
487 free (EXPORT_NAME (area));
488
489 if (IMPORT_NAME (area))
490 free (IMPORT_NAME (area));
491
492 /* Cancel timer. */
493 OSPF_TIMER_OFF (area->t_router_lsa_self);
494
495 if (OSPF_IS_AREA_BACKBONE (area))
496 ospf_top->backbone = NULL;
497
498 XFREE (MTYPE_OSPF_AREA, area);
499}
500
501void
502ospf_area_check_free (struct in_addr area_id)
503{
504 struct ospf_area *area;
505
506 area = ospf_area_lookup_by_area_id (area_id);
507 if (area &&
508 listcount (area->oiflist) == 0 &&
509 area->ranges->top == NULL &&
510 area->shortcut_configured == OSPF_SHORTCUT_DEFAULT &&
511 area->external_routing == OSPF_AREA_DEFAULT &&
512 area->no_summary == 0 &&
513 area->default_cost == 1 &&
514 EXPORT_NAME (area) == NULL &&
515 IMPORT_NAME (area) == NULL &&
516 area->auth_type == OSPF_AUTH_NULL)
517 {
518 listnode_delete (ospf_top->areas, area);
519 ospf_area_free (area);
520 }
521}
522
523struct ospf_area *
524ospf_area_get (struct in_addr area_id, int format)
525{
526 struct ospf_area *area;
527
528 area = ospf_area_lookup_by_area_id (area_id);
529 if (!area)
530 {
531 area = ospf_area_new (area_id);
532 area->format = format;
533 listnode_add_sort (ospf_top->areas, area);
534 ospf_check_abr_status ();
535 }
536
537 return area;
538}
539
540struct ospf_area *
541ospf_area_lookup_by_area_id (struct in_addr area_id)
542{
543 struct ospf_area *area;
544 listnode node;
545
546 for (node = listhead (ospf_top->areas); node; nextnode (node))
547 {
548 area = getdata (node);
549
550 if (IPV4_ADDR_SAME (&area->area_id, &area_id))
551 return area;
552 }
553
554 return NULL;
555}
556
557void
558ospf_area_add_if (struct ospf_area *area, struct ospf_interface *oi)
559{
560 listnode_add (area->oiflist, oi);
561}
562
563void
564ospf_area_del_if (struct ospf_area *area, struct ospf_interface *oi)
565{
566 listnode_delete (area->oiflist, oi);
567}
568
569
570/* Config network statement related functions. */
571struct ospf_network *
572ospf_network_new (struct in_addr area_id, int format)
573{
574 struct ospf_network *new;
575 new = XCALLOC (MTYPE_OSPF_NETWORK, sizeof (struct ospf_network));
576
577 new->area_id = area_id;
578 new->format = format;
579
580 return new;
581}
582
583void
584ospf_network_free (struct ospf_network *network)
585{
586 ospf_area_check_free (network->area_id);
587 ospf_schedule_abr_task ();
588 XFREE (MTYPE_OSPF_NETWORK, network);
589}
590
591int
592ospf_network_set (struct ospf *ospf, struct prefix_ipv4 *p,
593 struct in_addr area_id)
594{
595 struct ospf_network *network;
596 struct ospf_area *area;
597 struct route_node *rn;
598 struct external_info *ei;
599 int ret = OSPF_AREA_ID_FORMAT_DECIMAL;
600
601 rn = route_node_get (ospf->networks, (struct prefix *)p);
602 if (rn->info)
603 {
604 /* There is already same network statement. */
605 route_unlock_node (rn);
606 return 0;
607 }
608
609 rn->info = network = ospf_network_new (area_id, ret);
610 area = ospf_area_get (area_id, ret);
611
612 /* Run network config now. */
613 ospf_network_run (ospf, (struct prefix *)p, area);
614
615 /* Update connected redistribute. */
616 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
617 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
618 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
619 rn; rn = route_next (rn))
620 if ((ei = rn->info) != NULL)
621 if (ospf_external_info_find_lsa (&ei->p))
622 if (!ospf_distribute_check_connected (ei))
623 ospf_external_lsa_flush (ei->type, &ei->p,
624 ei->ifindex, ei->nexthop);
625
626 ospf_area_check_free (area_id);
627
628 return 1;
629}
630
631int
632ospf_network_unset (struct ospf *ospf, struct prefix_ipv4 *p,
633 struct in_addr area_id)
634{
635 struct route_node *rn;
636 struct ospf_network *network;
637 struct external_info *ei;
638
639 rn = route_node_lookup (ospf->networks, (struct prefix *)p);
640 if (rn == NULL)
641 return 0;
642
643 network = rn->info;
644 if (!IPV4_ADDR_SAME (&area_id, &network->area_id))
645 return 0;
646
647 ospf_network_free (rn->info);
648 rn->info = NULL;
649 route_unlock_node (rn);
650
651 ospf_if_update ();
652
653 /* Update connected redistribute. */
654 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT))
655 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT))
656 for (rn = route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT));
657 rn; rn = route_next (rn))
658 if ((ei = rn->info) != NULL)
659 if (!ospf_external_info_find_lsa (&ei->p))
660 if (ospf_distribute_check_connected (ei))
661 ospf_external_lsa_originate (ei);
662
663 return 1;
664}
665
paul570f7592003-01-25 06:47:41 +0000666/* Check whether interface matches given network
667 * returns: 1, true. 0, false
668 */
669int
670ospf_network_match_iface(struct connected *co, struct prefix *net)
671{
672 /* Behaviour to match both Cisco where:
673 * iface address lies within network specified -> ospf
674 * and zebra 0.9[2ish-3]:
675 * PtP special case: network specified == iface peer addr -> ospf
676 */
677 return (
678 ((ifc_pointopoint (co) &&
679 IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
680 || prefix_match (net, co->address))
681 ? 1 : 0
682 );
683}
684
paul718e3742002-12-13 20:15:29 +0000685void
686ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area)
687{
688 struct interface *ifp;
689 listnode node;
690
691 /* Schedule Router ID Update. */
692 if (ospf->router_id_static.s_addr == 0)
693 if (ospf->t_router_id_update == NULL)
694 {
695 ospf->t_router_id_update =
696 thread_add_timer (master, ospf_router_id_update_timer, ospf,
697 OSPF_ROUTER_ID_UPDATE_DELAY);
698 }
699
700 /* Get target interface. */
701 for (node = listhead (ospf->iflist); node; nextnode (node))
702 {
703 listnode cn;
704
705 if ((ifp = getdata (node)) == NULL)
706 continue;
707
708 if (memcmp (ifp->name, "VLINK", 5) == 0)
709 continue;
710
711 /* if interface prefix is match specified prefix,
712 then create socket and join multicast group. */
713 for (cn = listhead (ifp->connected); cn; nextnode (cn))
714 {
715 struct connected *co = getdata (cn);
716 struct prefix *addr;
717
paul00df0c12002-12-13 21:07:36 +0000718 if (ifc_pointopoint (co))
paul718e3742002-12-13 20:15:29 +0000719 addr = co->destination;
720 else
721 addr = co->address;
722
paulcb3f37d2003-02-18 23:26:37 +0000723 if (p->family == co->address->family
724 && ! ospf_if_is_configured (&(addr->u.prefix4))
725 && ospf_network_match_iface(co,p))
paul570f7592003-01-25 06:47:41 +0000726 {
paul487a5912003-02-19 02:54:57 +0000727 struct ospf_interface *oi;
728 assert(co);
paul718e3742002-12-13 20:15:29 +0000729
730 oi = ospf_if_new (ifp, co->address);
731 oi->connected = co;
732
733 oi->nbr_self->address = *oi->address;
734
735 area->act_ints++;
736 oi->area = area;
737
738 oi->params = ospf_lookup_if_params (ifp, oi->address->u.prefix4);
739 oi->output_cost = ospf_if_get_output_cost (oi);
740
741 if (area->external_routing != OSPF_AREA_DEFAULT)
742 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
743 oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
744
745 /* Add pseudo neighbor. */
746 ospf_nbr_add_self (oi);
747
748 /* Make sure pseudo neighbor's router_id. */
749 oi->nbr_self->router_id = ospf_top->router_id;
750 oi->nbr_self->src = oi->address->u.prefix4;
751
752 /* Relate ospf interface to ospf instance. */
753 oi->ospf = ospf_top;
754
755 /* update network type as interface flag */
756 /* If network type is specified previously,
757 skip network type setting. */
758 oi->type = IF_DEF_PARAMS (ifp)->type;
759
760 /* Set area flag. */
761 switch (area->external_routing)
762 {
763 case OSPF_AREA_DEFAULT:
764 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
765 break;
766 case OSPF_AREA_STUB:
767 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
768 break;
769#ifdef HAVE_NSSA
770 case OSPF_AREA_NSSA:
771 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
772 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
773 break;
774#endif /* HAVE_NSSA */
775 }
776
777 ospf_area_add_if (oi->area, oi);
778
paul2e3b2e42002-12-13 21:03:13 +0000779 if (if_is_operative (ifp))
paul718e3742002-12-13 20:15:29 +0000780 ospf_if_up (oi);
781
782 break;
783 }
784 }
785 }
786}
787
788void
789ospf_ls_upd_queue_empty (struct ospf_interface *oi)
790{
791 struct route_node *rn;
792 listnode node;
793 list lst;
794 struct ospf_lsa *lsa;
795
796 /* empty ls update queue */
797 for (rn = route_top (oi->ls_upd_queue); rn;
798 rn = route_next (rn))
799 if ((lst = (list) rn->info))
800 {
801 for (node = listhead (lst); node; nextnode (node))
802 if ((lsa = getdata (node)))
803 ospf_lsa_unlock (lsa);
804 list_free (lst);
805 rn->info = NULL;
806 }
807
808 /* remove update event */
809 if (oi->t_ls_upd_event)
810 {
811 thread_cancel (oi->t_ls_upd_event);
812 oi->t_ls_upd_event = NULL;
813 }
814}
815
816void
817ospf_if_update ()
818{
819 struct route_node *rn;
820 listnode node;
821 listnode next;
822 struct ospf_network *network;
823 struct ospf_area *area;
824
825 if (ospf_top != NULL)
826 {
827 /* Update Router ID scheduled. */
828 if (ospf_top->router_id_static.s_addr == 0)
829 if (ospf_top->t_router_id_update == NULL)
830 {
831 ospf_top->t_router_id_update =
832 thread_add_timer (master, ospf_router_id_update_timer, NULL,
833 OSPF_ROUTER_ID_UPDATE_DELAY);
834 }
835
836 /* Find interfaces that not configured already. */
837 for (node = listhead (ospf_top->oiflist); node; node = next)
838 {
839 int found = 0;
840 struct ospf_interface *oi = getdata (node);
841 struct connected *co = oi->connected;
842
843 next = nextnode (node);
844
845 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
846 continue;
847
848 for (rn = route_top (ospf_top->networks); rn; rn = route_next (rn))
849 {
850 if (rn->info == NULL)
851 continue;
852
paul570f7592003-01-25 06:47:41 +0000853 if (ospf_network_match_iface(co,&rn->p))
paul718e3742002-12-13 20:15:29 +0000854 {
855 found = 1;
856 route_unlock_node (rn);
857 break;
858 }
859 }
860
861 if (found == 0)
862 ospf_if_free (oi);
863 }
864
865 /* Run each interface. */
866 for (rn = route_top (ospf_top->networks); rn; rn = route_next (rn))
867 if (rn->info != NULL)
868 {
869 network = (struct ospf_network *) rn->info;
870 area = ospf_area_get (network->area_id, network->format);
871 ospf_network_run (ospf_top, &rn->p, area);
872 }
873 }
874}
875
876void
877ospf_remove_vls_through_area (struct ospf_area *area)
878{
879 listnode node, next;
880 struct ospf_vl_data *vl_data;
881
882 for (node = listhead (ospf_top->vlinks); node; node = next)
883 {
884 next = node->next;
885 if ((vl_data = getdata (node)) != NULL)
886 if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
887 ospf_vl_delete (vl_data);
888 }
889}
890
891
892struct message ospf_area_type_msg[] =
893{
894 { OSPF_AREA_DEFAULT, "Default" },
895 { OSPF_AREA_STUB, "Stub" },
896 { OSPF_AREA_NSSA, "NSSA" },
897};
898int ospf_area_type_msg_max = OSPF_AREA_TYPE_MAX;
899
900void
901ospf_area_type_set (struct ospf_area *area, int type)
902{
903 listnode node;
904 struct ospf_interface *oi;
905
906 if (area->external_routing == type)
907 {
908 if (IS_DEBUG_OSPF_EVENT)
909 zlog_info ("Area[%s]: Types are the same, ignored.",
910 inet_ntoa (area->area_id));
911 return;
912 }
913
914 area->external_routing = type;
915
916 if (IS_DEBUG_OSPF_EVENT)
917 zlog_info ("Area[%s]: Configured as %s", inet_ntoa (area->area_id),
918 LOOKUP (ospf_area_type_msg, type));
919
920 switch (area->external_routing)
921 {
922 case OSPF_AREA_DEFAULT:
923 for (node = listhead (area->oiflist); node; nextnode (node))
924 if ((oi = getdata (node)) != NULL)
925 if (oi->nbr_self != NULL)
926 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
927 break;
928 case OSPF_AREA_STUB:
929 for (node = listhead (area->oiflist); node; nextnode (node))
930 if ((oi = getdata (node)) != NULL)
931 if (oi->nbr_self != NULL)
932 {
933 if (IS_DEBUG_OSPF_EVENT)
934 zlog_info ("setting options on %s accordingly", IF_NAME (oi));
935 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
936 if (IS_DEBUG_OSPF_EVENT)
937 zlog_info ("options set on %s: %x",
938 IF_NAME (oi), OPTIONS (oi));
939 }
940 break;
941 case OSPF_AREA_NSSA:
942#ifdef HAVE_NSSA
943 for (node = listhead (area->oiflist); node; nextnode (node))
944 if ((oi = getdata (node)) != NULL)
945 if (oi->nbr_self != NULL)
946 {
947 zlog_info ("setting nssa options on %s accordingly", IF_NAME (oi));
948 UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
949 SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
950 zlog_info ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi));
951 }
952#endif /* HAVE_NSSA */
953 break;
954 default:
955 break;
956 }
957
958 ospf_router_lsa_timer_add (area);
959 ospf_schedule_abr_task ();
960}
961
962int
963ospf_area_shortcut_set (struct ospf_area *area, int mode)
964{
965 if (area->shortcut_configured == mode)
966 return 0;
967
968 area->shortcut_configured = mode;
969 ospf_router_lsa_timer_add (area);
970 ospf_schedule_abr_task ();
971
972 ospf_area_check_free (area->area_id);
973
974 return 1;
975}
976
977int
978ospf_area_shortcut_unset (struct ospf_area *area)
979{
980 area->shortcut_configured = OSPF_SHORTCUT_DEFAULT;
981 ospf_router_lsa_timer_add (area);
982 ospf_area_check_free (area->area_id);
983 ospf_schedule_abr_task ();
984
985 return 1;
986}
987
988int
989ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area)
990{
991 struct ospf_vl_data *vl;
992 listnode node;
993 int count = 0;
994
995 for (node = listhead (ospf->vlinks); node; nextnode (node))
996 {
997 vl = getdata (node);
998 if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id))
999 count++;
1000 }
1001
1002 return count;
1003}
1004
1005int
1006ospf_area_stub_set (struct ospf *ospf, struct in_addr area_id)
1007{
1008 struct ospf_area *area;
1009 int format = OSPF_AREA_ID_FORMAT_DECIMAL;
1010
1011 area = ospf_area_get (area_id, format);
1012 if (ospf_area_vlink_count (ospf, area))
1013 return 0;
1014
1015 if (area->external_routing != OSPF_AREA_STUB)
1016 ospf_area_type_set (area, OSPF_AREA_STUB);
1017
1018 return 1;
1019}
1020
1021int
1022ospf_area_stub_unset (struct ospf *ospf, struct in_addr area_id)
1023{
1024 struct ospf_area *area;
1025
1026 area = ospf_area_lookup_by_area_id (area_id);
1027 if (area == NULL)
1028 return 1;
1029
1030 if (area->external_routing == OSPF_AREA_STUB)
1031 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1032
1033 ospf_area_check_free (area_id);
1034
1035 return 1;
1036}
1037
1038int
1039ospf_area_no_summary_set (struct ospf *ospf, struct in_addr area_id)
1040{
1041 struct ospf_area *area;
1042 int format = OSPF_AREA_ID_FORMAT_DECIMAL;
1043
1044 area = ospf_area_get (area_id, format);
1045 area->no_summary = 1;
1046
1047 return 1;
1048}
1049
1050int
1051ospf_area_no_summary_unset (struct ospf *ospf, struct in_addr area_id)
1052{
1053 struct ospf_area *area;
1054
1055 area = ospf_area_lookup_by_area_id (area_id);
1056 if (area == NULL)
1057 return 0;
1058
1059 area->no_summary = 0;
1060 ospf_area_check_free (area_id);
1061
1062 return 1;
1063}
1064
1065int
1066ospf_area_nssa_set (struct ospf *ospf, struct in_addr area_id)
1067{
1068 struct ospf_area *area;
1069 int format = OSPF_AREA_ID_FORMAT_DECIMAL;
1070
1071 area = ospf_area_get (area_id, format);
1072 if (ospf_area_vlink_count (ospf, area))
1073 return 0;
1074
1075 if (area->external_routing != OSPF_AREA_NSSA)
1076 {
1077 ospf_area_type_set (area, OSPF_AREA_NSSA);
1078 ospf->anyNSSA++;
1079 }
1080
1081 return 1;
1082}
1083
1084int
1085ospf_area_nssa_unset (struct ospf *ospf, struct in_addr area_id)
1086{
1087 struct ospf_area *area;
1088
1089 area = ospf_area_lookup_by_area_id (area_id);
1090 if (area == NULL)
1091 return 0;
1092
1093 if (area->external_routing == OSPF_AREA_NSSA)
1094 {
1095 ospf->anyNSSA--;
1096 ospf_area_type_set (area, OSPF_AREA_DEFAULT);
1097 }
1098
1099 ospf_area_check_free (area_id);
1100
1101 return 1;
1102}
1103
1104int
1105ospf_area_nssa_translator_role_set (struct ospf *ospf, struct in_addr area_id,
1106 int role)
1107{
1108 struct ospf_area *area;
1109
1110 area = ospf_area_lookup_by_area_id (area_id);
1111 if (area == NULL)
1112 return 0;
1113
1114 area->NSSATranslator = role;
1115
1116 return 1;
1117}
1118
1119int
1120ospf_area_nssa_translator_role_unset (struct ospf *ospf,
1121 struct in_addr area_id)
1122{
1123 struct ospf_area *area;
1124
1125 area = ospf_area_lookup_by_area_id (area_id);
1126 if (area == NULL)
1127 return 0;
1128
1129 area->NSSATranslator = OSPF_NSSA_ROLE_CANDIDATE;
1130
1131 ospf_area_check_free (area_id);
1132
1133 return 1;
1134}
1135
1136int
1137ospf_area_export_list_set (struct ospf_area *area, char *list_name)
1138{
1139 struct access_list *list;
1140 list = access_list_lookup (AFI_IP, list_name);
1141
1142 EXPORT_LIST (area) = list;
1143
1144 if (EXPORT_NAME (area))
1145 free (EXPORT_NAME (area));
1146
1147 EXPORT_NAME (area) = strdup (list_name);
1148 ospf_schedule_abr_task ();
1149
1150 return 1;
1151}
1152
1153int
1154ospf_area_export_list_unset (struct ospf_area * area)
1155{
1156
1157 EXPORT_LIST (area) = 0;
1158
1159 if (EXPORT_NAME (area))
1160 free (EXPORT_NAME (area));
1161
1162 EXPORT_NAME (area) = NULL;
1163
1164 ospf_area_check_free (area->area_id);
1165
1166 ospf_schedule_abr_task ();
1167
1168 return 1;
1169}
1170
1171int
1172ospf_area_import_list_set (struct ospf_area *area, char *name)
1173{
1174 struct access_list *list;
1175 list = access_list_lookup (AFI_IP, name);
1176
1177 IMPORT_LIST (area) = list;
1178
1179 if (IMPORT_NAME (area))
1180 free (IMPORT_NAME (area));
1181
1182 IMPORT_NAME (area) = strdup (name);
1183 ospf_schedule_abr_task ();
1184
1185 return 1;
1186}
1187
1188int
1189ospf_area_import_list_unset (struct ospf_area * area)
1190{
1191 IMPORT_LIST (area) = 0;
1192
1193 if (IMPORT_NAME (area))
1194 free (IMPORT_NAME (area));
1195
1196 IMPORT_NAME (area) = NULL;
1197 ospf_area_check_free (area->area_id);
1198
1199 ospf_schedule_abr_task ();
1200
1201 return 1;
1202}
1203
1204int
1205ospf_timers_spf_set (struct ospf *ospf, u_int32_t delay, u_int32_t hold)
1206{
1207 ospf->spf_delay = delay;
1208 ospf->spf_holdtime = hold;
1209
1210 return 1;
1211}
1212
1213int
1214ospf_timers_spf_unset (struct ospf *ospf)
1215{
1216 ospf->spf_delay = OSPF_SPF_DELAY_DEFAULT;
1217 ospf->spf_holdtime = OSPF_SPF_HOLDTIME_DEFAULT;
1218
1219 return 1;
1220}
1221
1222int
1223ospf_timers_refresh_set (struct ospf *ospf, int interval)
1224{
1225 int time_left;
1226
1227 if (ospf->lsa_refresh_interval == interval)
1228 return 1;
1229
1230 time_left = ospf->lsa_refresh_interval -
1231 (time (NULL) - ospf->lsa_refresher_started);
1232
1233 if (time_left > interval)
1234 {
1235 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1236 ospf->t_lsa_refresher =
1237 thread_add_timer (master, ospf_lsa_refresh_walker, ospf, interval);
1238 }
1239 ospf->lsa_refresh_interval = interval;
1240
1241 return 1;
1242}
1243
1244int
1245ospf_timers_refresh_unset (struct ospf *ospf)
1246{
1247 int time_left;
1248
1249 time_left = ospf->lsa_refresh_interval -
1250 (time (NULL) - ospf->lsa_refresher_started);
1251
1252 if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
1253 {
1254 OSPF_TIMER_OFF (ospf->t_lsa_refresher);
1255 ospf->t_lsa_refresher =
1256 thread_add_timer (master, ospf_lsa_refresh_walker, ospf,
1257 OSPF_LSA_REFRESH_INTERVAL_DEFAULT);
1258 }
1259
1260 ospf->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
1261
1262 return 1;
1263}
1264
1265
1266struct ospf_nbr_nbma *
1267ospf_nbr_nbma_new ()
1268{
1269 struct ospf_nbr_nbma *nbr_nbma;
1270
1271 nbr_nbma = XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC,
1272 sizeof (struct ospf_nbr_nbma));
1273 memset (nbr_nbma, 0, sizeof (struct ospf_nbr_nbma));
1274
1275 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1276 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1277
1278 return nbr_nbma;
1279}
1280
1281void
1282ospf_nbr_nbma_free (struct ospf_nbr_nbma *nbr_nbma)
1283{
1284 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC, nbr_nbma);
1285}
1286
1287void
1288ospf_nbr_nbma_delete (struct ospf *ospf, struct ospf_nbr_nbma *nbr_nbma)
1289{
1290 struct route_node *rn;
1291 struct prefix_ipv4 p;
1292
1293 p.family = AF_INET;
1294 p.prefix = nbr_nbma->addr;
1295 p.prefixlen = IPV4_MAX_BITLEN;
1296
1297 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1298 if (rn)
1299 {
1300 ospf_nbr_nbma_free (rn->info);
1301 rn->info = NULL;
1302 route_unlock_node (rn);
1303 route_unlock_node (rn);
1304 }
1305}
1306
1307void
1308ospf_nbr_nbma_down (struct ospf_nbr_nbma *nbr_nbma)
1309{
1310 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1311
1312 if (nbr_nbma->nbr)
1313 {
1314 nbr_nbma->nbr->nbr_nbma = NULL;
1315 OSPF_NSM_EVENT_EXECUTE (nbr_nbma->nbr, NSM_KillNbr);
1316 }
1317
1318 if (nbr_nbma->oi)
1319 listnode_delete (nbr_nbma->oi->nbr_nbma, nbr_nbma);
1320}
1321
1322void
1323ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma,
1324 struct ospf_interface *oi)
1325{
1326 struct ospf_neighbor *nbr;
1327 struct route_node *rn;
1328 struct prefix p;
1329
1330 if (oi->type != OSPF_IFTYPE_NBMA)
1331 return;
1332
1333 if (nbr_nbma->nbr != NULL)
1334 return;
1335
1336 if (IPV4_ADDR_SAME (&oi->nbr_self->address.u.prefix4, &nbr_nbma->addr))
1337 return;
1338
1339 nbr_nbma->oi = oi;
1340 listnode_add (oi->nbr_nbma, nbr_nbma);
1341
1342 /* Get neighbor information from table. */
1343 p.family = AF_INET;
1344 p.prefixlen = IPV4_MAX_BITLEN;
1345 p.u.prefix4 = nbr_nbma->addr;
1346
1347 rn = route_node_get (oi->nbrs, (struct prefix *)&p);
1348 if (rn->info)
1349 {
1350 nbr = rn->info;
1351 nbr->nbr_nbma = nbr_nbma;
1352 nbr_nbma->nbr = nbr;
1353
1354 route_unlock_node (rn);
1355 }
1356 else
1357 {
1358 nbr = rn->info = ospf_nbr_new (oi);
1359 nbr->state = NSM_Down;
1360 nbr->src = nbr_nbma->addr;
1361 nbr->nbr_nbma = nbr_nbma;
1362 nbr->priority = nbr_nbma->priority;
1363 nbr->address = p;
1364
1365 nbr_nbma->nbr = nbr;
1366
1367 OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start);
1368 }
1369}
1370
1371void
1372ospf_nbr_nbma_if_update (struct ospf_interface *oi)
1373{
1374 struct ospf_nbr_nbma *nbr_nbma;
1375 struct route_node *rn;
1376 struct prefix_ipv4 p;
1377
1378 if (oi->type != OSPF_IFTYPE_NBMA)
1379 return;
1380
1381 for (rn = route_top (ospf_top->nbr_nbma); rn; rn = route_next (rn))
1382 if ((nbr_nbma = rn->info))
1383 if (nbr_nbma->oi == NULL && nbr_nbma->nbr == NULL)
1384 {
1385 p.family = AF_INET;
1386 p.prefix = nbr_nbma->addr;
1387 p.prefixlen = IPV4_MAX_BITLEN;
1388
1389 if (prefix_match (oi->address, (struct prefix *)&p))
1390 ospf_nbr_nbma_add (nbr_nbma, oi);
1391 }
1392}
1393
1394struct ospf_nbr_nbma *
1395ospf_nbr_nbma_lookup (struct ospf *ospf, struct in_addr nbr_addr)
1396{
1397 struct route_node *rn;
1398 struct prefix_ipv4 p;
1399
1400 p.family = AF_INET;
1401 p.prefix = nbr_addr;
1402 p.prefixlen = IPV4_MAX_BITLEN;
1403
1404 rn = route_node_lookup (ospf->nbr_nbma, (struct prefix *)&p);
1405 if (rn)
1406 {
1407 route_unlock_node (rn);
1408 return rn->info;
1409 }
1410 return NULL;
1411}
1412
1413struct ospf_nbr_nbma *
1414ospf_nbr_nbma_lookup_next (struct in_addr *addr, int first)
1415{
1416#if 0
1417 struct ospf_nbr_nbma *nbr_nbma;
1418 listnode node;
1419#endif
1420
1421 if (! ospf_top)
1422 return NULL;
1423
1424#if 0
1425 for (node = listhead (ospf_top->nbr_nbma); node; nextnode (node))
1426 {
1427 nbr_nbma = getdata (node);
1428
1429 if (first)
1430 {
1431 *addr = nbr_nbma->addr;
1432 return nbr_nbma;
1433 }
1434 else if (ntohl (nbr_nbma->addr.s_addr) > ntohl (addr->s_addr))
1435 {
1436 *addr = nbr_nbma->addr;
1437 return nbr_nbma;
1438 }
1439 }
1440#endif
1441 return NULL;
1442}
1443
1444int
1445ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr)
1446{
1447 struct ospf_nbr_nbma *nbr_nbma;
1448 struct ospf_interface *oi;
1449 struct prefix_ipv4 p;
1450 struct route_node *rn;
1451 listnode node;
1452
1453 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1454 if (nbr_nbma)
1455 return 0;
1456
1457 nbr_nbma = ospf_nbr_nbma_new ();
1458 nbr_nbma->addr = nbr_addr;
1459
1460 p.family = AF_INET;
1461 p.prefix = nbr_addr;
1462 p.prefixlen = IPV4_MAX_BITLEN;
1463
1464 rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p);
1465 rn->info = nbr_nbma;
1466
1467 for (node = listhead (ospf->oiflist); node; nextnode (node))
1468 {
1469 oi = getdata (node);
1470 if (oi->type == OSPF_IFTYPE_NBMA)
1471 if (prefix_match (oi->address, (struct prefix *)&p))
1472 {
1473 ospf_nbr_nbma_add (nbr_nbma, oi);
1474 break;
1475 }
1476 }
1477
1478 return 1;
1479}
1480
1481int
1482ospf_nbr_nbma_unset (struct ospf *ospf, struct in_addr nbr_addr)
1483{
1484 struct ospf_nbr_nbma *nbr_nbma;
1485
1486 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1487 if (nbr_nbma == NULL)
1488 return 0;
1489
1490 ospf_nbr_nbma_down (nbr_nbma);
1491 ospf_nbr_nbma_delete (ospf, nbr_nbma);
1492
1493 return 1;
1494}
1495
1496int
1497ospf_nbr_nbma_priority_set (struct ospf *ospf, struct in_addr nbr_addr,
1498 u_char priority)
1499{
1500 struct ospf_nbr_nbma *nbr_nbma;
1501
1502 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1503 if (nbr_nbma == NULL)
1504 return 0;
1505
1506 if (nbr_nbma->priority != priority)
1507 nbr_nbma->priority = priority;
1508
1509 return 1;
1510}
1511
1512int
1513ospf_nbr_nbma_priority_unset (struct ospf *ospf, struct in_addr nbr_addr)
1514{
1515 struct ospf_nbr_nbma *nbr_nbma;
1516
1517 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1518 if (nbr_nbma == NULL)
1519 return 0;
1520
1521 if (nbr_nbma != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
1522 nbr_nbma->priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
1523
1524 return 1;
1525}
1526
1527int
1528ospf_nbr_nbma_poll_interval_set (struct ospf *ospf, struct in_addr nbr_addr,
1529 int interval)
1530{
1531 struct ospf_nbr_nbma *nbr_nbma;
1532
1533 nbr_nbma = ospf_nbr_nbma_lookup (ospf, nbr_addr);
1534 if (nbr_nbma == NULL)
1535 return 0;
1536
1537 if (nbr_nbma->v_poll != interval)
1538 {
1539 nbr_nbma->v_poll = interval;
1540 if (nbr_nbma->oi && ospf_if_is_up (nbr_nbma->oi))
1541 {
1542 OSPF_TIMER_OFF (nbr_nbma->t_poll);
1543 OSPF_POLL_TIMER_ON (nbr_nbma->t_poll, ospf_poll_timer,
1544 nbr_nbma->v_poll);
1545 }
1546 }
1547
1548 return 1;
1549}
1550
1551int
1552ospf_nbr_nbma_poll_interval_unset (struct ospf *ospf, struct in_addr addr)
1553{
1554 struct ospf_nbr_nbma *nbr_nbma;
1555
1556 nbr_nbma = ospf_nbr_nbma_lookup (ospf, addr);
1557 if (nbr_nbma == NULL)
1558 return 0;
1559
1560 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
1561 nbr_nbma->v_poll = OSPF_POLL_INTERVAL_DEFAULT;
1562
1563 return 1;
1564}
1565
1566
1567void
1568ospf_prefix_list_update (struct prefix_list *plist)
1569{
1570 struct ospf_area *area;
1571 listnode node;
1572 int abr_inv = 0;
1573
1574 /* If OSPF instatnce does not exist, return right now. */
1575 if (!ospf_top)
1576 return;
1577
1578 /* Update Area prefix-list. */
1579 for (node = listhead (ospf_top->areas); node; nextnode (node))
1580 {
1581 area = getdata (node);
1582
1583 /* Update filter-list in. */
1584 if (PREFIX_NAME_IN (area))
1585 if (strcmp (PREFIX_NAME_IN (area), plist->name) == 0)
1586 {
1587 PREFIX_LIST_IN (area) =
1588 prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area));
1589 abr_inv++;
1590 }
1591
1592 /* Update filter-list out. */
1593 if (PREFIX_NAME_OUT (area))
1594 if (strcmp (PREFIX_NAME_OUT (area), plist->name) == 0)
1595 {
1596 PREFIX_LIST_IN (area) =
1597 prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area));
1598 abr_inv++;
1599 }
1600 }
1601
1602 /* Schedule ABR tasks. */
1603 if (OSPF_IS_ABR && abr_inv)
1604 ospf_schedule_abr_task ();
1605}
1606
1607void
1608ospf_init ()
1609{
1610 /* Make empty list of ospf list. */
1611 ospf_top = NULL;
1612
1613 prefix_list_add_hook (ospf_prefix_list_update);
1614 prefix_list_delete_hook (ospf_prefix_list_update);
1615}