1 /* OSPF version 2 daemon program.
2 Copyright (C) 1999, 2000 Toshiaki Takada
4 This file is part of GNU Zebra.
6 GNU Zebra is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 GNU Zebra is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
33 #include "sockunion.h" /* for inet_aton () */
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"
57 /* OSPF process wide configuration. */
58 static struct ospf_master ospf_master
;
60 /* OSPF process wide configuration pointer to export. */
61 struct ospf_master
*om
;
63 extern struct zclient
*zclient
;
64 extern struct in_addr router_id_zebra
;
67 static void ospf_remove_vls_through_area (struct ospf
*, struct ospf_area
*);
68 static void ospf_network_free (struct ospf
*, struct ospf_network
*);
69 static void ospf_area_free (struct ospf_area
*);
70 static void ospf_network_run (struct ospf
*, struct prefix
*, struct ospf_area
*);
71 static void ospf_finish_final (struct ospf
*);
73 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
76 ospf_router_id_update (struct ospf
*ospf
)
78 struct in_addr router_id
, router_id_old
;
79 struct ospf_interface
*oi
;
80 struct listnode
*node
;
82 if (IS_DEBUG_OSPF_EVENT
)
83 zlog_debug ("Router-ID[OLD:%s]: Update", inet_ntoa (ospf
->router_id
));
85 router_id_old
= ospf
->router_id
;
87 /* Select the router ID based on these priorities:
88 1. Statically assigned router ID is always the first choice.
89 2. If there is no statically assigned router ID, then try to stick
90 with the most recent value, since changing router ID's is very
92 3. Last choice: just go with whatever the zebra daemon recommends.
94 if (ospf
->router_id_static
.s_addr
!= 0)
95 router_id
= ospf
->router_id_static
;
96 else if (ospf
->router_id
.s_addr
!= 0)
97 router_id
= ospf
->router_id
;
99 router_id
= router_id_zebra
;
101 ospf
->router_id
= router_id
;
103 if (IS_DEBUG_OSPF_EVENT
)
104 zlog_debug ("Router-ID[NEW:%s]: Update", inet_ntoa (ospf
->router_id
));
106 if (!IPV4_ADDR_SAME (&router_id_old
, &router_id
))
108 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
109 /* Update self-neighbor's router_id. */
110 oi
->nbr_self
->router_id
= router_id
;
112 /* If AS-external-LSA is queued, then flush those LSAs. */
113 if (router_id_old
.s_addr
== 0 && ospf
->external_origin
)
116 /* Originate each redistributed external route. */
117 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
118 if (ospf
->external_origin
& (1 << type
))
119 thread_add_event (master
, ospf_external_lsa_originate_timer
,
121 /* Originate Deafult. */
122 if (ospf
->external_origin
& (1 << ZEBRA_ROUTE_MAX
))
123 thread_add_event (master
, ospf_default_originate_timer
, ospf
, 0);
125 ospf
->external_origin
= 0;
128 OSPF_TIMER_ON (ospf
->t_router_lsa_update
,
129 ospf_router_lsa_update_timer
, OSPF_LSA_UPDATE_DELAY
);
131 /* update ospf_interface's */
132 ospf_if_update (ospf
);
136 /* For OSPF area sort by area id. */
138 ospf_area_id_cmp (struct ospf_area
*a1
, struct ospf_area
*a2
)
140 if (ntohl (a1
->area_id
.s_addr
) > ntohl (a2
->area_id
.s_addr
))
142 if (ntohl (a1
->area_id
.s_addr
) < ntohl (a2
->area_id
.s_addr
))
147 /* Allocate new ospf structure. */
153 struct ospf
*new = XCALLOC (MTYPE_OSPF_TOP
, sizeof (struct ospf
));
155 new->router_id
.s_addr
= htonl (0);
156 new->router_id_static
.s_addr
= htonl (0);
158 new->abr_type
= OSPF_ABR_DEFAULT
;
159 new->oiflist
= list_new ();
160 new->vlinks
= list_new ();
161 new->areas
= list_new ();
162 new->areas
->cmp
= (int (*)(void *, void *)) ospf_area_id_cmp
;
163 new->networks
= route_table_init ();
164 new->nbr_nbma
= route_table_init ();
166 new->lsdb
= ospf_lsdb_new ();
168 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
170 new->passive_interface_default
= OSPF_IF_ACTIVE
;
172 new->new_external_route
= route_table_init ();
173 new->old_external_route
= route_table_init ();
174 new->external_lsas
= route_table_init ();
176 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
177 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
179 /* Distribute parameter init. */
180 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++)
182 new->dmetric
[i
].type
= -1;
183 new->dmetric
[i
].value
= -1;
185 new->default_metric
= -1;
186 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
188 /* SPF timer value init. */
189 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
190 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
191 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
192 new->spf_hold_multiplier
= 1;
195 new->maxage_lsa
= list_new ();
196 new->t_maxage_walker
=
197 thread_add_timer (master
, ospf_lsa_maxage_walker
,
198 new, OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
200 /* Distance table init. */
201 new->distance_table
= route_table_init ();
203 new->lsa_refresh_queue
.index
= 0;
204 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
205 new->t_lsa_refresher
= thread_add_timer (master
, ospf_lsa_refresh_walker
,
206 new, new->lsa_refresh_interval
);
207 new->lsa_refresher_started
= quagga_time (NULL
);
209 if ((new->fd
= ospf_sock_init()) < 0)
211 zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
215 if ((new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+1)) == NULL
)
217 zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
218 OSPF_MAX_PACKET_SIZE
+1);
221 new->t_read
= thread_add_read (master
, ospf_read
, new, new->fd
);
222 new->oi_write_q
= list_new ();
230 if (listcount (om
->ospf
) == 0)
233 return listgetdata (listhead (om
->ospf
));
237 ospf_add (struct ospf
*ospf
)
239 listnode_add (om
->ospf
, ospf
);
243 ospf_delete (struct ospf
*ospf
)
245 listnode_delete (om
->ospf
, ospf
);
253 ospf
= ospf_lookup ();
259 if (ospf
->router_id_static
.s_addr
== 0)
260 ospf_router_id_update (ospf
);
262 #ifdef HAVE_OPAQUE_LSA
263 ospf_opaque_type11_lsa_init (ospf
);
264 #endif /* HAVE_OPAQUE_LSA */
270 /* Handle the second half of deferred shutdown. This is called either
271 * from the deferred-shutdown timer thread, or directly through
272 * ospf_deferred_shutdown_check.
274 * Function is to cleanup G-R state, if required then call ospf_finish_final
275 * to complete shutdown of this ospf instance. Possibly exit if the
276 * whole process is being shutdown and this was the last OSPF instance.
279 ospf_deferred_shutdown_finish (struct ospf
*ospf
)
281 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
282 OSPF_TIMER_OFF (ospf
->t_deferred_shutdown
);
284 ospf_finish_final (ospf
);
286 /* *ospf is now invalid */
288 /* ospfd being shut-down? If so, was this the last ospf instance? */
289 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
)
290 && (listcount (om
->ospf
) == 0))
296 /* Timer thread for G-R */
298 ospf_deferred_shutdown_timer (struct thread
*t
)
300 struct ospf
*ospf
= THREAD_ARG(t
);
302 ospf_deferred_shutdown_finish (ospf
);
307 /* Check whether deferred-shutdown must be scheduled, otherwise call
308 * down directly into second-half of instance shutdown.
311 ospf_deferred_shutdown_check (struct ospf
*ospf
)
313 unsigned long timeout
;
315 struct ospf_area
*area
;
317 /* deferred shutdown already running? */
318 if (ospf
->t_deferred_shutdown
)
321 /* Should we try push out max-metric LSAs? */
322 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
324 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, ln
, area
))
326 SET_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
328 if (!CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
329 ospf_router_lsa_timer_add (area
);
331 timeout
= ospf
->stub_router_shutdown_time
;
335 /* No timer needed */
336 ospf_deferred_shutdown_finish (ospf
);
340 OSPF_TIMER_ON (ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
345 /* Shut down the entire process */
347 ospf_terminate (void)
350 struct listnode
*node
, *nnode
;
352 /* shutdown already in progress */
353 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
356 SET_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
);
358 for (ALL_LIST_ELEMENTS (om
->ospf
, node
, nnode
, ospf
))
361 /* Deliberately go back up, hopefully to thread scheduler, as
362 * One or more ospf_finish()'s may have deferred shutdown to a timer
368 ospf_finish (struct ospf
*ospf
)
370 /* let deferred shutdown decide */
371 ospf_deferred_shutdown_check (ospf
);
373 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
374 * deferred to expiry of G-S timer thread. Return back up, hopefully
375 * to thread scheduler.
380 /* Final cleanup of ospf instance */
382 ospf_finish_final (struct ospf
*ospf
)
384 struct route_node
*rn
;
385 struct ospf_nbr_nbma
*nbr_nbma
;
386 struct ospf_lsa
*lsa
;
387 struct ospf_interface
*oi
;
388 struct ospf_area
*area
;
389 struct ospf_vl_data
*vl_data
;
390 struct listnode
*node
, *nnode
;
393 #ifdef HAVE_OPAQUE_LSA
394 ospf_opaque_type11_lsa_term (ospf
);
395 #endif /* HAVE_OPAQUE_LSA */
397 /* be nice if this worked, but it doesn't */
398 /*ospf_flush_self_originated_lsas_now (ospf);*/
400 /* Unregister redistribution */
401 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
402 ospf_redistribute_unset (ospf
, i
);
403 ospf_redistribute_default_unset (ospf
);
405 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
406 ospf_remove_vls_through_area (ospf
, area
);
408 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
409 ospf_vl_delete (ospf
, vl_data
);
411 list_delete (ospf
->vlinks
);
413 /* Reset interface. */
414 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
417 /* Clear static neighbors */
418 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
419 if ((nbr_nbma
= rn
->info
))
421 OSPF_POLL_TIMER_OFF (nbr_nbma
->t_poll
);
425 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
426 nbr_nbma
->nbr
= NULL
;
431 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
435 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
438 route_table_finish (ospf
->nbr_nbma
);
440 /* Clear networks and Areas. */
441 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
443 struct ospf_network
*network
;
445 if ((network
= rn
->info
) != NULL
)
447 ospf_network_free (ospf
, network
);
449 route_unlock_node (rn
);
453 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
455 listnode_delete (ospf
->areas
, area
);
456 ospf_area_free (area
);
459 /* Cancel all timers. */
460 OSPF_TIMER_OFF (ospf
->t_external_lsa
);
461 OSPF_TIMER_OFF (ospf
->t_router_lsa_update
);
462 OSPF_TIMER_OFF (ospf
->t_spf_calc
);
463 OSPF_TIMER_OFF (ospf
->t_ase_calc
);
464 OSPF_TIMER_OFF (ospf
->t_maxage
);
465 OSPF_TIMER_OFF (ospf
->t_maxage_walker
);
466 OSPF_TIMER_OFF (ospf
->t_abr_task
);
467 OSPF_TIMER_OFF (ospf
->t_asbr_check
);
468 OSPF_TIMER_OFF (ospf
->t_distribute_update
);
469 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
470 OSPF_TIMER_OFF (ospf
->t_read
);
471 OSPF_TIMER_OFF (ospf
->t_write
);
472 #ifdef HAVE_OPAQUE_LSA
473 OSPF_TIMER_OFF (ospf
->t_opaque_lsa_self
);
477 stream_free(ospf
->ibuf
);
479 #ifdef HAVE_OPAQUE_LSA
480 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
481 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
482 #endif /* HAVE_OPAQUE_LSA */
483 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
484 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
486 ospf_lsdb_delete_all (ospf
->lsdb
);
487 ospf_lsdb_free (ospf
->lsdb
);
489 for (ALL_LIST_ELEMENTS (ospf
->maxage_lsa
, node
, nnode
, lsa
))
490 ospf_lsa_unlock (&lsa
); /* maxage_lsa */
492 list_delete (ospf
->maxage_lsa
);
495 ospf_route_table_free (ospf
->old_table
);
498 ospf_route_delete (ospf
->new_table
);
499 ospf_route_table_free (ospf
->new_table
);
502 ospf_rtrs_free (ospf
->old_rtrs
);
504 ospf_rtrs_free (ospf
->new_rtrs
);
505 if (ospf
->new_external_route
)
507 ospf_route_delete (ospf
->new_external_route
);
508 ospf_route_table_free (ospf
->new_external_route
);
510 if (ospf
->old_external_route
)
512 ospf_route_delete (ospf
->old_external_route
);
513 ospf_route_table_free (ospf
->old_external_route
);
515 if (ospf
->external_lsas
)
517 ospf_ase_external_lsas_finish (ospf
->external_lsas
);
520 list_delete (ospf
->areas
);
522 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++)
523 if (EXTERNAL_INFO (i
) != NULL
)
524 for (rn
= route_top (EXTERNAL_INFO (i
)); rn
; rn
= route_next (rn
))
526 if (rn
->info
== NULL
)
529 XFREE (MTYPE_OSPF_EXTERNAL_INFO
, rn
->info
);
531 route_unlock_node (rn
);
534 ospf_distance_reset (ospf
);
535 route_table_finish (ospf
->distance_table
);
539 XFREE (MTYPE_OSPF_TOP
, ospf
);
543 /* allocate new OSPF Area object */
544 static struct ospf_area
*
545 ospf_area_new (struct ospf
*ospf
, struct in_addr area_id
)
547 struct ospf_area
*new;
549 /* Allocate new config_network. */
550 new = XCALLOC (MTYPE_OSPF_AREA
, sizeof (struct ospf_area
));
554 new->area_id
= area_id
;
556 new->external_routing
= OSPF_AREA_DEFAULT
;
557 new->default_cost
= 1;
558 new->auth_type
= OSPF_AUTH_NULL
;
561 new->lsdb
= ospf_lsdb_new ();
563 /* Self-originated LSAs initialize. */
564 new->router_lsa_self
= NULL
;
566 #ifdef HAVE_OPAQUE_LSA
567 ospf_opaque_type10_lsa_init (new);
568 #endif /* HAVE_OPAQUE_LSA */
570 new->oiflist
= list_new ();
571 new->ranges
= route_table_init ();
573 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
574 ospf
->backbone
= new;
580 ospf_area_free (struct ospf_area
*area
)
582 struct route_node
*rn
;
583 struct ospf_lsa
*lsa
;
586 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
587 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
588 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
589 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
590 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
591 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
592 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
593 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
595 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
596 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
597 #ifdef HAVE_OPAQUE_LSA
598 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
599 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
600 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
601 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
602 #endif /* HAVE_OPAQUE_LSA */
604 ospf_lsdb_delete_all (area
->lsdb
);
605 ospf_lsdb_free (area
->lsdb
);
607 ospf_lsa_unlock (&area
->router_lsa_self
);
609 route_table_finish (area
->ranges
);
610 list_delete (area
->oiflist
);
612 if (EXPORT_NAME (area
))
613 free (EXPORT_NAME (area
));
615 if (IMPORT_NAME (area
))
616 free (IMPORT_NAME (area
));
619 OSPF_TIMER_OFF (area
->t_router_lsa_self
);
620 OSPF_TIMER_OFF (area
->t_stub_router
);
621 #ifdef HAVE_OPAQUE_LSA
622 OSPF_TIMER_OFF (area
->t_opaque_lsa_self
);
623 #endif /* HAVE_OPAQUE_LSA */
625 if (OSPF_IS_AREA_BACKBONE (area
))
626 area
->ospf
->backbone
= NULL
;
628 XFREE (MTYPE_OSPF_AREA
, area
);
632 ospf_area_check_free (struct ospf
*ospf
, struct in_addr area_id
)
634 struct ospf_area
*area
;
636 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
638 listcount (area
->oiflist
) == 0 &&
639 area
->ranges
->top
== NULL
&&
640 area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
&&
641 area
->external_routing
== OSPF_AREA_DEFAULT
&&
642 area
->no_summary
== 0 &&
643 area
->default_cost
== 1 &&
644 EXPORT_NAME (area
) == NULL
&&
645 IMPORT_NAME (area
) == NULL
&&
646 area
->auth_type
== OSPF_AUTH_NULL
)
648 listnode_delete (ospf
->areas
, area
);
649 ospf_area_free (area
);
654 ospf_area_get (struct ospf
*ospf
, struct in_addr area_id
, int format
)
656 struct ospf_area
*area
;
658 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
661 area
= ospf_area_new (ospf
, area_id
);
662 area
->format
= format
;
663 listnode_add_sort (ospf
->areas
, area
);
664 ospf_check_abr_status (ospf
);
671 ospf_area_lookup_by_area_id (struct ospf
*ospf
, struct in_addr area_id
)
673 struct ospf_area
*area
;
674 struct listnode
*node
;
676 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
677 if (IPV4_ADDR_SAME (&area
->area_id
, &area_id
))
684 ospf_area_add_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
686 listnode_add (area
->oiflist
, oi
);
690 ospf_area_del_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
692 listnode_delete (area
->oiflist
, oi
);
696 /* Config network statement related functions. */
697 static struct ospf_network
*
698 ospf_network_new (struct in_addr area_id
, int format
)
700 struct ospf_network
*new;
701 new = XCALLOC (MTYPE_OSPF_NETWORK
, sizeof (struct ospf_network
));
703 new->area_id
= area_id
;
704 new->format
= format
;
710 ospf_network_free (struct ospf
*ospf
, struct ospf_network
*network
)
712 ospf_area_check_free (ospf
, network
->area_id
);
713 ospf_schedule_abr_task (ospf
);
714 XFREE (MTYPE_OSPF_NETWORK
, network
);
718 ospf_network_set (struct ospf
*ospf
, struct prefix_ipv4
*p
,
719 struct in_addr area_id
)
721 struct ospf_network
*network
;
722 struct ospf_area
*area
;
723 struct route_node
*rn
;
724 struct external_info
*ei
;
725 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
727 rn
= route_node_get (ospf
->networks
, (struct prefix
*)p
);
730 /* There is already same network statement. */
731 route_unlock_node (rn
);
735 rn
->info
= network
= ospf_network_new (area_id
, ret
);
736 area
= ospf_area_get (ospf
, area_id
, ret
);
738 /* Run network config now. */
739 ospf_network_run (ospf
, (struct prefix
*)p
, area
);
741 /* Update connected redistribute. */
742 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT
))
743 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
))
744 for (rn
= route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
));
745 rn
; rn
= route_next (rn
))
746 if ((ei
= rn
->info
) != NULL
)
747 if (ospf_external_info_find_lsa (ospf
, &ei
->p
))
748 if (!ospf_distribute_check_connected (ospf
, ei
))
749 ospf_external_lsa_flush (ospf
, ei
->type
, &ei
->p
,
750 ei
->ifindex
/*, ei->nexthop */);
752 ospf_area_check_free (ospf
, area_id
);
758 ospf_network_unset (struct ospf
*ospf
, struct prefix_ipv4
*p
,
759 struct in_addr area_id
)
761 struct route_node
*rn
;
762 struct ospf_network
*network
;
763 struct external_info
*ei
;
765 rn
= route_node_lookup (ospf
->networks
, (struct prefix
*)p
);
770 if (!IPV4_ADDR_SAME (&area_id
, &network
->area_id
))
773 ospf_network_free (ospf
, rn
->info
);
775 route_unlock_node (rn
);
777 ospf_if_update (ospf
);
779 /* Update connected redistribute. */
780 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT
))
781 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
))
782 for (rn
= route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
));
783 rn
; rn
= route_next (rn
))
784 if ((ei
= rn
->info
) != NULL
)
785 if (!ospf_external_info_find_lsa (ospf
, &ei
->p
))
786 if (ospf_distribute_check_connected (ospf
, ei
))
787 ospf_external_lsa_originate (ospf
, ei
);
792 /* Check whether interface matches given network
793 * returns: 1, true. 0, false
796 ospf_network_match_iface(struct connected
*co
, struct prefix
*net
)
798 #define COMPATIBILITY_MODE
799 /* The old code used to have a special case for PtP interfaces:
801 if (if_is_pointopoint (co->ifp) && co->destination &&
802 IPV4_ADDR_SAME ( &(co->destination->u.prefix4), &(net->u.prefix4)))
805 The new approach is much more general. If a peer address is supplied,
806 then we are routing to that prefix, so that's the address to compare
807 against (not the local address, which may not be unique).
809 #ifndef COMPATIBILITY_MODE
810 /* new approach: more elegant and conceptually clean */
811 return prefix_match(net
, CONNECTED_PREFIX(co
));
812 #else /* COMPATIBILITY_MODE */
813 /* match old (strange?) behavior */
815 /* Behaviour to match both Cisco where:
816 * iface address lies within network specified -> ospf
817 * and zebra 0.9[2ish-3]:
818 * PtP special case: network specified == iface peer addr -> ospf
821 /* For PtP, match if peer address matches network address exactly.
822 * This can be addr/32 or addr/p for p < 32, but the addr must match
823 * exactly; this is not a test for falling within the prefix. This
824 * test is solely for compatibility with zebra.
826 if (CONNECTED_PEER(co
) &&
827 IPV4_ADDR_SAME ( &(co
->destination
->u
.prefix4
), &(net
->u
.prefix4
)))
831 /* Decline to accept PtP if dst address does not match the
832 * prefix. (ifdefed out because this is a workaround, not the
833 * desired behavior.) */
834 if (if_is_pointopoint (co
->ifp
) &&
835 ! prefix_match (net
, co
->destination
))
839 /* If the address is within the prefix, accept. Note that this
840 * applies to PtP as well as other types.
842 if (prefix_match (net
, co
->address
))
845 return 0; /* no match */
847 #endif /* COMPATIBILITY_MODE */
851 ospf_network_run (struct ospf
*ospf
, struct prefix
*p
, struct ospf_area
*area
)
853 struct interface
*ifp
;
854 struct connected
*co
;
855 struct listnode
*node
;
857 /* Schedule Router ID Update. */
858 if (ospf
->router_id
.s_addr
== 0)
859 ospf_router_id_update (ospf
);
861 /* Get target interface. */
862 for (ALL_LIST_ELEMENTS_RO (om
->iflist
, node
, ifp
))
864 struct listnode
*cnode
;
866 if (memcmp (ifp
->name
, "VLINK", 5) == 0)
869 /* if interface prefix is match specified prefix,
870 then create socket and join multicast group. */
871 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, co
))
875 if (CHECK_FLAG(co
->flags
,ZEBRA_IFA_SECONDARY
))
878 addr
= CONNECTED_ID(co
);
880 if (p
->family
== co
->address
->family
881 && ! ospf_if_is_configured (ospf
, &(addr
->u
.prefix4
))
882 && ospf_network_match_iface(co
,p
))
884 struct ospf_interface
*oi
;
886 oi
= ospf_if_new (ospf
, ifp
, co
->address
);
891 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
892 oi
->output_cost
= ospf_if_get_output_cost (oi
);
894 /* Add pseudo neighbor. */
895 ospf_nbr_add_self (oi
);
897 /* Relate ospf interface to ospf instance. */
900 /* update network type as interface flag */
901 /* If network type is specified previously,
902 skip network type setting. */
903 oi
->type
= IF_DEF_PARAMS (ifp
)->type
;
905 ospf_area_add_if (oi
->area
, oi
);
907 /* if router_id is not configured, dont bring up
909 * ospf_router_id_update() will call ospf_if_update
910 * whenever r-id is configured instead.
912 if ((ospf
->router_id
.s_addr
!= 0)
913 && if_is_operative (ifp
))
921 ospf_ls_upd_queue_empty (struct ospf_interface
*oi
)
923 struct route_node
*rn
;
924 struct listnode
*node
, *nnode
;
926 struct ospf_lsa
*lsa
;
928 /* empty ls update queue */
929 for (rn
= route_top (oi
->ls_upd_queue
); rn
;
930 rn
= route_next (rn
))
931 if ((lst
= (struct list
*) rn
->info
))
933 for (ALL_LIST_ELEMENTS (lst
, node
, nnode
, lsa
))
934 ospf_lsa_unlock (&lsa
); /* oi->ls_upd_queue */
939 /* remove update event */
940 if (oi
->t_ls_upd_event
)
942 thread_cancel (oi
->t_ls_upd_event
);
943 oi
->t_ls_upd_event
= NULL
;
948 ospf_if_update (struct ospf
*ospf
)
950 struct route_node
*rn
;
951 struct listnode
*node
, *nnode
;
952 struct ospf_network
*network
;
953 struct ospf_area
*area
;
954 struct ospf_interface
*oi
;
958 /* Router-ID must be configured. */
959 if (ospf
->router_id
.s_addr
== 0)
962 /* Find interfaces that not configured already. */
963 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
966 struct connected
*co
= oi
->connected
;
968 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
971 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
973 if (rn
->info
== NULL
)
976 if (ospf_network_match_iface(co
,&rn
->p
))
979 route_unlock_node (rn
);
988 /* Run each interface. */
989 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
990 if (rn
->info
!= NULL
)
992 network
= (struct ospf_network
*) rn
->info
;
993 area
= ospf_area_get (ospf
, network
->area_id
, network
->format
);
994 ospf_network_run (ospf
, &rn
->p
, area
);
1000 ospf_remove_vls_through_area (struct ospf
*ospf
, struct ospf_area
*area
)
1002 struct listnode
*node
, *nnode
;
1003 struct ospf_vl_data
*vl_data
;
1005 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
1006 if (IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
1007 ospf_vl_delete (ospf
, vl_data
);
1011 struct message ospf_area_type_msg
[] =
1013 { OSPF_AREA_DEFAULT
, "Default" },
1014 { OSPF_AREA_STUB
, "Stub" },
1015 { OSPF_AREA_NSSA
, "NSSA" },
1017 int ospf_area_type_msg_max
= OSPF_AREA_TYPE_MAX
;
1020 ospf_area_type_set (struct ospf_area
*area
, int type
)
1022 struct listnode
*node
;
1023 struct ospf_interface
*oi
;
1025 if (area
->external_routing
== type
)
1027 if (IS_DEBUG_OSPF_EVENT
)
1028 zlog_debug ("Area[%s]: Types are the same, ignored.",
1029 inet_ntoa (area
->area_id
));
1033 area
->external_routing
= type
;
1035 if (IS_DEBUG_OSPF_EVENT
)
1036 zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area
->area_id
),
1037 LOOKUP (ospf_area_type_msg
, type
));
1039 switch (area
->external_routing
)
1041 case OSPF_AREA_DEFAULT
:
1042 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1043 if (oi
->nbr_self
!= NULL
)
1045 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1046 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1049 case OSPF_AREA_STUB
:
1050 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1051 if (oi
->nbr_self
!= NULL
)
1053 if (IS_DEBUG_OSPF_EVENT
)
1054 zlog_debug ("setting options on %s accordingly", IF_NAME (oi
));
1055 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1056 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1057 if (IS_DEBUG_OSPF_EVENT
)
1058 zlog_debug ("options set on %s: %x",
1059 IF_NAME (oi
), OPTIONS (oi
));
1062 case OSPF_AREA_NSSA
:
1063 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1064 if (oi
->nbr_self
!= NULL
)
1066 zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi
));
1067 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1068 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1069 zlog_debug ("options set on %s: %x", IF_NAME (oi
), OPTIONS (oi
));
1076 ospf_router_lsa_timer_add (area
);
1077 ospf_schedule_abr_task (area
->ospf
);
1081 ospf_area_shortcut_set (struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1083 if (area
->shortcut_configured
== mode
)
1086 area
->shortcut_configured
= mode
;
1087 ospf_router_lsa_timer_add (area
);
1088 ospf_schedule_abr_task (ospf
);
1090 ospf_area_check_free (ospf
, area
->area_id
);
1096 ospf_area_shortcut_unset (struct ospf
*ospf
, struct ospf_area
*area
)
1098 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1099 ospf_router_lsa_timer_add (area
);
1100 ospf_area_check_free (ospf
, area
->area_id
);
1101 ospf_schedule_abr_task (ospf
);
1107 ospf_area_vlink_count (struct ospf
*ospf
, struct ospf_area
*area
)
1109 struct ospf_vl_data
*vl
;
1110 struct listnode
*node
;
1113 for (ALL_LIST_ELEMENTS_RO (ospf
->vlinks
, node
, vl
))
1114 if (IPV4_ADDR_SAME (&vl
->vl_area_id
, &area
->area_id
))
1121 ospf_area_stub_set (struct ospf
*ospf
, struct in_addr area_id
)
1123 struct ospf_area
*area
;
1124 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1126 area
= ospf_area_get (ospf
, area_id
, format
);
1127 if (ospf_area_vlink_count (ospf
, area
))
1130 if (area
->external_routing
!= OSPF_AREA_STUB
)
1131 ospf_area_type_set (area
, OSPF_AREA_STUB
);
1137 ospf_area_stub_unset (struct ospf
*ospf
, struct in_addr area_id
)
1139 struct ospf_area
*area
;
1141 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1145 if (area
->external_routing
== OSPF_AREA_STUB
)
1146 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1148 ospf_area_check_free (ospf
, area_id
);
1154 ospf_area_no_summary_set (struct ospf
*ospf
, struct in_addr area_id
)
1156 struct ospf_area
*area
;
1157 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1159 area
= ospf_area_get (ospf
, area_id
, format
);
1160 area
->no_summary
= 1;
1166 ospf_area_no_summary_unset (struct ospf
*ospf
, struct in_addr area_id
)
1168 struct ospf_area
*area
;
1170 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1174 area
->no_summary
= 0;
1175 ospf_area_check_free (ospf
, area_id
);
1181 ospf_area_nssa_set (struct ospf
*ospf
, struct in_addr area_id
)
1183 struct ospf_area
*area
;
1184 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1186 area
= ospf_area_get (ospf
, area_id
, format
);
1187 if (ospf_area_vlink_count (ospf
, area
))
1190 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1192 ospf_area_type_set (area
, OSPF_AREA_NSSA
);
1196 /* set NSSA area defaults */
1197 area
->no_summary
= 0;
1198 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1199 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1200 area
->NSSATranslatorStabilityInterval
= OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1206 ospf_area_nssa_unset (struct ospf
*ospf
, struct in_addr area_id
)
1208 struct ospf_area
*area
;
1210 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1214 if (area
->external_routing
== OSPF_AREA_NSSA
)
1217 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1220 ospf_area_check_free (ospf
, area_id
);
1226 ospf_area_nssa_translator_role_set (struct ospf
*ospf
, struct in_addr area_id
,
1229 struct ospf_area
*area
;
1231 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1235 area
->NSSATranslatorRole
= role
;
1240 /* XXX: unused? Leave for symmetry? */
1242 ospf_area_nssa_translator_role_unset (struct ospf
*ospf
,
1243 struct in_addr area_id
)
1245 struct ospf_area
*area
;
1247 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1251 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1253 ospf_area_check_free (ospf
, area_id
);
1259 ospf_area_export_list_set (struct ospf
*ospf
,
1260 struct ospf_area
*area
, const char *list_name
)
1262 struct access_list
*list
;
1263 list
= access_list_lookup (AFI_IP
, list_name
);
1265 EXPORT_LIST (area
) = list
;
1267 if (EXPORT_NAME (area
))
1268 free (EXPORT_NAME (area
));
1270 EXPORT_NAME (area
) = strdup (list_name
);
1271 ospf_schedule_abr_task (ospf
);
1277 ospf_area_export_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1280 EXPORT_LIST (area
) = 0;
1282 if (EXPORT_NAME (area
))
1283 free (EXPORT_NAME (area
));
1285 EXPORT_NAME (area
) = NULL
;
1287 ospf_area_check_free (ospf
, area
->area_id
);
1289 ospf_schedule_abr_task (ospf
);
1295 ospf_area_import_list_set (struct ospf
*ospf
, struct ospf_area
*area
,
1298 struct access_list
*list
;
1299 list
= access_list_lookup (AFI_IP
, name
);
1301 IMPORT_LIST (area
) = list
;
1303 if (IMPORT_NAME (area
))
1304 free (IMPORT_NAME (area
));
1306 IMPORT_NAME (area
) = strdup (name
);
1307 ospf_schedule_abr_task (ospf
);
1313 ospf_area_import_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1315 IMPORT_LIST (area
) = 0;
1317 if (IMPORT_NAME (area
))
1318 free (IMPORT_NAME (area
));
1320 IMPORT_NAME (area
) = NULL
;
1321 ospf_area_check_free (ospf
, area
->area_id
);
1323 ospf_schedule_abr_task (ospf
);
1329 ospf_timers_refresh_set (struct ospf
*ospf
, int interval
)
1333 if (ospf
->lsa_refresh_interval
== interval
)
1336 time_left
= ospf
->lsa_refresh_interval
-
1337 (quagga_time (NULL
) - ospf
->lsa_refresher_started
);
1339 if (time_left
> interval
)
1341 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1342 ospf
->t_lsa_refresher
=
1343 thread_add_timer (master
, ospf_lsa_refresh_walker
, ospf
, interval
);
1345 ospf
->lsa_refresh_interval
= interval
;
1351 ospf_timers_refresh_unset (struct ospf
*ospf
)
1355 time_left
= ospf
->lsa_refresh_interval
-
1356 (quagga_time (NULL
) - ospf
->lsa_refresher_started
);
1358 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
1360 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1361 ospf
->t_lsa_refresher
=
1362 thread_add_timer (master
, ospf_lsa_refresh_walker
, ospf
,
1363 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
);
1366 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1372 static struct ospf_nbr_nbma
*
1373 ospf_nbr_nbma_new (void)
1375 struct ospf_nbr_nbma
*nbr_nbma
;
1377 nbr_nbma
= XMALLOC (MTYPE_OSPF_NEIGHBOR_STATIC
,
1378 sizeof (struct ospf_nbr_nbma
));
1379 memset (nbr_nbma
, 0, sizeof (struct ospf_nbr_nbma
));
1381 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1382 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1388 ospf_nbr_nbma_free (struct ospf_nbr_nbma
*nbr_nbma
)
1390 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1394 ospf_nbr_nbma_delete (struct ospf
*ospf
, struct ospf_nbr_nbma
*nbr_nbma
)
1396 struct route_node
*rn
;
1397 struct prefix_ipv4 p
;
1400 p
.prefix
= nbr_nbma
->addr
;
1401 p
.prefixlen
= IPV4_MAX_BITLEN
;
1403 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1406 ospf_nbr_nbma_free (rn
->info
);
1408 route_unlock_node (rn
);
1409 route_unlock_node (rn
);
1414 ospf_nbr_nbma_down (struct ospf_nbr_nbma
*nbr_nbma
)
1416 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1420 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1421 OSPF_NSM_EVENT_EXECUTE (nbr_nbma
->nbr
, NSM_KillNbr
);
1425 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1429 ospf_nbr_nbma_add (struct ospf_nbr_nbma
*nbr_nbma
,
1430 struct ospf_interface
*oi
)
1432 struct ospf_neighbor
*nbr
;
1433 struct route_node
*rn
;
1436 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1439 if (nbr_nbma
->nbr
!= NULL
)
1442 if (IPV4_ADDR_SAME (&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1446 listnode_add (oi
->nbr_nbma
, nbr_nbma
);
1448 /* Get neighbor information from table. */
1450 p
.prefixlen
= IPV4_MAX_BITLEN
;
1451 p
.u
.prefix4
= nbr_nbma
->addr
;
1453 rn
= route_node_get (oi
->nbrs
, (struct prefix
*)&p
);
1457 nbr
->nbr_nbma
= nbr_nbma
;
1458 nbr_nbma
->nbr
= nbr
;
1460 route_unlock_node (rn
);
1464 nbr
= rn
->info
= ospf_nbr_new (oi
);
1465 nbr
->state
= NSM_Down
;
1466 nbr
->src
= nbr_nbma
->addr
;
1467 nbr
->nbr_nbma
= nbr_nbma
;
1468 nbr
->priority
= nbr_nbma
->priority
;
1471 nbr_nbma
->nbr
= nbr
;
1473 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_Start
);
1478 ospf_nbr_nbma_if_update (struct ospf
*ospf
, struct ospf_interface
*oi
)
1480 struct ospf_nbr_nbma
*nbr_nbma
;
1481 struct route_node
*rn
;
1482 struct prefix_ipv4 p
;
1484 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1487 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
1488 if ((nbr_nbma
= rn
->info
))
1489 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
)
1492 p
.prefix
= nbr_nbma
->addr
;
1493 p
.prefixlen
= IPV4_MAX_BITLEN
;
1495 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1496 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1500 struct ospf_nbr_nbma
*
1501 ospf_nbr_nbma_lookup (struct ospf
*ospf
, struct in_addr nbr_addr
)
1503 struct route_node
*rn
;
1504 struct prefix_ipv4 p
;
1507 p
.prefix
= nbr_addr
;
1508 p
.prefixlen
= IPV4_MAX_BITLEN
;
1510 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1513 route_unlock_node (rn
);
1519 struct ospf_nbr_nbma
*
1520 ospf_nbr_nbma_lookup_next (struct ospf
*ospf
, struct in_addr
*addr
, int first
)
1523 struct ospf_nbr_nbma
*nbr_nbma
;
1524 struct listnode
*node
;
1531 for (ALL_LIST_ELEMENTS_RO (ospf
->nbr_nbma
, node
, nbr_nbma
))
1535 *addr
= nbr_nbma
->addr
;
1538 else if (ntohl (nbr_nbma
->addr
.s_addr
) > ntohl (addr
->s_addr
))
1540 *addr
= nbr_nbma
->addr
;
1549 ospf_nbr_nbma_set (struct ospf
*ospf
, struct in_addr nbr_addr
)
1551 struct ospf_nbr_nbma
*nbr_nbma
;
1552 struct ospf_interface
*oi
;
1553 struct prefix_ipv4 p
;
1554 struct route_node
*rn
;
1555 struct listnode
*node
;
1557 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1561 nbr_nbma
= ospf_nbr_nbma_new ();
1562 nbr_nbma
->addr
= nbr_addr
;
1565 p
.prefix
= nbr_addr
;
1566 p
.prefixlen
= IPV4_MAX_BITLEN
;
1568 rn
= route_node_get (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1569 rn
->info
= nbr_nbma
;
1571 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
1573 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1574 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1576 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1585 ospf_nbr_nbma_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1587 struct ospf_nbr_nbma
*nbr_nbma
;
1589 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1590 if (nbr_nbma
== NULL
)
1593 ospf_nbr_nbma_down (nbr_nbma
);
1594 ospf_nbr_nbma_delete (ospf
, nbr_nbma
);
1600 ospf_nbr_nbma_priority_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1603 struct ospf_nbr_nbma
*nbr_nbma
;
1605 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1606 if (nbr_nbma
== NULL
)
1609 if (nbr_nbma
->priority
!= priority
)
1610 nbr_nbma
->priority
= priority
;
1616 ospf_nbr_nbma_priority_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1618 struct ospf_nbr_nbma
*nbr_nbma
;
1620 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1621 if (nbr_nbma
== NULL
)
1624 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
1625 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1631 ospf_nbr_nbma_poll_interval_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1632 unsigned int interval
)
1634 struct ospf_nbr_nbma
*nbr_nbma
;
1636 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1637 if (nbr_nbma
== NULL
)
1640 if (nbr_nbma
->v_poll
!= interval
)
1642 nbr_nbma
->v_poll
= interval
;
1643 if (nbr_nbma
->oi
&& ospf_if_is_up (nbr_nbma
->oi
))
1645 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1646 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
1655 ospf_nbr_nbma_poll_interval_unset (struct ospf
*ospf
, struct in_addr addr
)
1657 struct ospf_nbr_nbma
*nbr_nbma
;
1659 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, addr
);
1660 if (nbr_nbma
== NULL
)
1663 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
1664 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1672 memset (&ospf_master
, 0, sizeof (struct ospf_master
));
1675 om
->ospf
= list_new ();
1676 om
->master
= thread_master_create ();
1677 om
->start_time
= quagga_time (NULL
);