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 () */
38 #include "ospfd/ospfd.h"
39 #include "ospfd/ospf_network.h"
40 #include "ospfd/ospf_interface.h"
41 #include "ospfd/ospf_ism.h"
42 #include "ospfd/ospf_asbr.h"
43 #include "ospfd/ospf_lsa.h"
44 #include "ospfd/ospf_lsdb.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_nsm.h"
47 #include "ospfd/ospf_spf.h"
48 #include "ospfd/ospf_packet.h"
49 #include "ospfd/ospf_dump.h"
50 #include "ospfd/ospf_zebra.h"
51 #include "ospfd/ospf_abr.h"
52 #include "ospfd/ospf_flood.h"
53 #include "ospfd/ospf_route.h"
54 #include "ospfd/ospf_ase.h"
58 /* OSPF process wide configuration. */
59 static struct ospf_master ospf_master
;
61 /* OSPF process wide configuration pointer to export. */
62 struct ospf_master
*om
;
64 extern struct zclient
*zclient
;
65 extern struct in_addr router_id_zebra
;
68 static void ospf_remove_vls_through_area (struct ospf
*, struct ospf_area
*);
69 static void ospf_network_free (struct ospf
*, struct ospf_network
*);
70 static void ospf_area_free (struct ospf_area
*);
71 static void ospf_network_run (struct prefix
*, struct ospf_area
*);
72 static void ospf_network_run_interface (struct prefix
*, struct ospf_area
*,
74 static int ospf_network_match_iface (const struct connected
*,
75 const struct prefix
*);
76 static void ospf_finish_final (struct ospf
*);
78 #define OSPF_EXTERNAL_LSA_ORIGINATE_DELAY 1
81 ospf_router_id_update (struct ospf
*ospf
)
83 struct in_addr router_id
, router_id_old
;
84 struct ospf_interface
*oi
;
85 struct interface
*ifp
;
86 struct listnode
*node
;
88 if (IS_DEBUG_OSPF_EVENT
)
89 zlog_debug ("Router-ID[OLD:%s]: Update", inet_ntoa (ospf
->router_id
));
91 router_id_old
= ospf
->router_id
;
93 /* Select the router ID based on these priorities:
94 1. Statically assigned router ID is always the first choice.
95 2. If there is no statically assigned router ID, then try to stick
96 with the most recent value, since changing router ID's is very
98 3. Last choice: just go with whatever the zebra daemon recommends.
100 if (ospf
->router_id_static
.s_addr
!= 0)
101 router_id
= ospf
->router_id_static
;
102 else if (ospf
->router_id
.s_addr
!= 0)
103 router_id
= ospf
->router_id
;
105 router_id
= router_id_zebra
;
107 ospf
->router_id
= router_id
;
109 if (IS_DEBUG_OSPF_EVENT
)
110 zlog_debug ("Router-ID[NEW:%s]: Update", inet_ntoa (ospf
->router_id
));
112 if (!IPV4_ADDR_SAME (&router_id_old
, &router_id
))
114 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
115 /* Update self-neighbor's router_id. */
116 oi
->nbr_self
->router_id
= router_id
;
118 /* If AS-external-LSA is queued, then flush those LSAs. */
119 if (router_id_old
.s_addr
== 0 && ospf
->external_origin
)
122 /* Originate each redistributed external route. */
123 for (type
= 0; type
< ZEBRA_ROUTE_MAX
; type
++)
124 if (ospf
->external_origin
& (1 << type
))
125 thread_add_event (master
, ospf_external_lsa_originate_timer
,
127 /* Originate Deafult. */
128 if (ospf
->external_origin
& (1 << ZEBRA_ROUTE_MAX
))
129 thread_add_event (master
, ospf_default_originate_timer
, ospf
, 0);
131 ospf
->external_origin
= 0;
134 /* update router-lsa's for each area */
135 ospf_router_lsa_update (ospf
);
137 /* update ospf_interface's */
138 for (ALL_LIST_ELEMENTS_RO (om
->iflist
, node
, ifp
))
139 ospf_if_update (ospf
, ifp
);
143 /* For OSPF area sort by area id. */
145 ospf_area_id_cmp (struct ospf_area
*a1
, struct ospf_area
*a2
)
147 if (ntohl (a1
->area_id
.s_addr
) > ntohl (a2
->area_id
.s_addr
))
149 if (ntohl (a1
->area_id
.s_addr
) < ntohl (a2
->area_id
.s_addr
))
154 /* Allocate new ospf structure. */
160 struct ospf
*new = XCALLOC (MTYPE_OSPF_TOP
, sizeof (struct ospf
));
162 new->router_id
.s_addr
= htonl (0);
163 new->router_id_static
.s_addr
= htonl (0);
165 new->abr_type
= OSPF_ABR_DEFAULT
;
166 new->oiflist
= list_new ();
167 new->vlinks
= list_new ();
168 new->areas
= list_new ();
169 new->areas
->cmp
= (int (*)(void *, void *)) ospf_area_id_cmp
;
170 new->networks
= route_table_init ();
171 new->nbr_nbma
= route_table_init ();
173 new->lsdb
= ospf_lsdb_new ();
175 new->default_originate
= DEFAULT_ORIGINATE_NONE
;
177 new->passive_interface_default
= OSPF_IF_ACTIVE
;
179 new->new_external_route
= route_table_init ();
180 new->old_external_route
= route_table_init ();
181 new->external_lsas
= route_table_init ();
183 new->stub_router_startup_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
184 new->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
186 /* Distribute parameter init. */
187 for (i
= 0; i
<= ZEBRA_ROUTE_MAX
; i
++)
189 new->dmetric
[i
].type
= -1;
190 new->dmetric
[i
].value
= -1;
192 new->default_metric
= -1;
193 new->ref_bandwidth
= OSPF_DEFAULT_REF_BANDWIDTH
;
195 /* SPF timer value init. */
196 new->spf_delay
= OSPF_SPF_DELAY_DEFAULT
;
197 new->spf_holdtime
= OSPF_SPF_HOLDTIME_DEFAULT
;
198 new->spf_max_holdtime
= OSPF_SPF_MAX_HOLDTIME_DEFAULT
;
199 new->spf_hold_multiplier
= 1;
202 new->maxage_delay
= OSFP_LSA_MAXAGE_REMOVE_DELAY_DEFAULT
;
203 new->maxage_lsa
= list_new ();
204 new->t_maxage_walker
=
205 thread_add_timer (master
, ospf_lsa_maxage_walker
,
206 new, OSPF_LSA_MAXAGE_CHECK_INTERVAL
);
208 /* Distance table init. */
209 new->distance_table
= route_table_init ();
211 new->lsa_refresh_queue
.index
= 0;
212 new->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
213 new->t_lsa_refresher
= thread_add_timer (master
, ospf_lsa_refresh_walker
,
214 new, new->lsa_refresh_interval
);
215 new->lsa_refresher_started
= quagga_time (NULL
);
217 if ((new->fd
= ospf_sock_init()) < 0)
219 zlog_err("ospf_new: fatal error: ospf_sock_init was unable to open "
223 new->maxsndbuflen
= getsockopt_so_sendbuf (new->fd
);
224 if (IS_DEBUG_OSPF (zebra
, ZEBRA_INTERFACE
))
225 zlog_debug ("%s: starting with OSPF send buffer size %d",
226 __func__
, new->maxsndbuflen
);
227 if ((new->ibuf
= stream_new(OSPF_MAX_PACKET_SIZE
+1)) == NULL
)
229 zlog_err("ospf_new: fatal error: stream_new(%u) failed allocating ibuf",
230 OSPF_MAX_PACKET_SIZE
+1);
233 new->t_read
= thread_add_read (master
, ospf_read
, new, new->fd
);
234 new->oi_write_q
= list_new ();
242 if (listcount (om
->ospf
) == 0)
245 return listgetdata (listhead (om
->ospf
));
249 ospf_add (struct ospf
*ospf
)
251 listnode_add (om
->ospf
, ospf
);
255 ospf_delete (struct ospf
*ospf
)
257 listnode_delete (om
->ospf
, ospf
);
265 ospf
= ospf_lookup ();
271 if (ospf
->router_id_static
.s_addr
== 0)
272 ospf_router_id_update (ospf
);
274 #ifdef HAVE_OPAQUE_LSA
275 ospf_opaque_type11_lsa_init (ospf
);
276 #endif /* HAVE_OPAQUE_LSA */
282 /* Handle the second half of deferred shutdown. This is called either
283 * from the deferred-shutdown timer thread, or directly through
284 * ospf_deferred_shutdown_check.
286 * Function is to cleanup G-R state, if required then call ospf_finish_final
287 * to complete shutdown of this ospf instance. Possibly exit if the
288 * whole process is being shutdown and this was the last OSPF instance.
291 ospf_deferred_shutdown_finish (struct ospf
*ospf
)
293 ospf
->stub_router_shutdown_time
= OSPF_STUB_ROUTER_UNCONFIGURED
;
294 OSPF_TIMER_OFF (ospf
->t_deferred_shutdown
);
296 ospf_finish_final (ospf
);
298 /* *ospf is now invalid */
300 /* ospfd being shut-down? If so, was this the last ospf instance? */
301 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
)
302 && (listcount (om
->ospf
) == 0))
308 /* Timer thread for G-R */
310 ospf_deferred_shutdown_timer (struct thread
*t
)
312 struct ospf
*ospf
= THREAD_ARG(t
);
314 ospf_deferred_shutdown_finish (ospf
);
319 /* Check whether deferred-shutdown must be scheduled, otherwise call
320 * down directly into second-half of instance shutdown.
323 ospf_deferred_shutdown_check (struct ospf
*ospf
)
325 unsigned long timeout
;
327 struct ospf_area
*area
;
329 /* deferred shutdown already running? */
330 if (ospf
->t_deferred_shutdown
)
333 /* Should we try push out max-metric LSAs? */
334 if (ospf
->stub_router_shutdown_time
!= OSPF_STUB_ROUTER_UNCONFIGURED
)
336 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, ln
, area
))
338 SET_FLAG (area
->stub_router_state
, OSPF_AREA_ADMIN_STUB_ROUTED
);
340 if (!CHECK_FLAG (area
->stub_router_state
, OSPF_AREA_IS_STUB_ROUTED
))
341 ospf_router_lsa_update_area (area
);
343 timeout
= ospf
->stub_router_shutdown_time
;
347 /* No timer needed */
348 ospf_deferred_shutdown_finish (ospf
);
352 OSPF_TIMER_ON (ospf
->t_deferred_shutdown
, ospf_deferred_shutdown_timer
,
357 /* Shut down the entire process */
359 ospf_terminate (void)
362 struct listnode
*node
, *nnode
;
364 /* shutdown already in progress */
365 if (CHECK_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
))
368 SET_FLAG (om
->options
, OSPF_MASTER_SHUTDOWN
);
370 /* exit immediately if OSPF not actually running */
371 if (listcount(om
->ospf
) == 0)
374 for (ALL_LIST_ELEMENTS (om
->ospf
, node
, nnode
, ospf
))
377 /* Deliberately go back up, hopefully to thread scheduler, as
378 * One or more ospf_finish()'s may have deferred shutdown to a timer
384 ospf_finish (struct ospf
*ospf
)
386 /* let deferred shutdown decide */
387 ospf_deferred_shutdown_check (ospf
);
389 /* if ospf_deferred_shutdown returns, then ospf_finish_final is
390 * deferred to expiry of G-S timer thread. Return back up, hopefully
391 * to thread scheduler.
396 /* Final cleanup of ospf instance */
398 ospf_finish_final (struct ospf
*ospf
)
400 struct route_node
*rn
;
401 struct ospf_nbr_nbma
*nbr_nbma
;
402 struct ospf_lsa
*lsa
;
403 struct ospf_interface
*oi
;
404 struct ospf_area
*area
;
405 struct ospf_vl_data
*vl_data
;
406 struct listnode
*node
, *nnode
;
409 #ifdef HAVE_OPAQUE_LSA
410 ospf_opaque_type11_lsa_term (ospf
);
411 #endif /* HAVE_OPAQUE_LSA */
413 /* be nice if this worked, but it doesn't */
414 /*ospf_flush_self_originated_lsas_now (ospf);*/
416 /* Unregister redistribution */
417 for (i
= 0; i
< ZEBRA_ROUTE_MAX
; i
++)
418 ospf_redistribute_unset (ospf
, i
);
419 ospf_redistribute_default_unset (ospf
);
421 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
422 ospf_remove_vls_through_area (ospf
, area
);
424 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
425 ospf_vl_delete (ospf
, vl_data
);
427 list_delete (ospf
->vlinks
);
429 /* Reset interface. */
430 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
433 /* Clear static neighbors */
434 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
435 if ((nbr_nbma
= rn
->info
))
437 OSPF_POLL_TIMER_OFF (nbr_nbma
->t_poll
);
441 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
442 nbr_nbma
->nbr
= NULL
;
447 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
451 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
454 route_table_finish (ospf
->nbr_nbma
);
456 /* Clear networks and Areas. */
457 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
459 struct ospf_network
*network
;
461 if ((network
= rn
->info
) != NULL
)
463 ospf_network_free (ospf
, network
);
465 route_unlock_node (rn
);
469 for (ALL_LIST_ELEMENTS (ospf
->areas
, node
, nnode
, area
))
471 listnode_delete (ospf
->areas
, area
);
472 ospf_area_free (area
);
475 /* Cancel all timers. */
476 OSPF_TIMER_OFF (ospf
->t_external_lsa
);
477 OSPF_TIMER_OFF (ospf
->t_spf_calc
);
478 OSPF_TIMER_OFF (ospf
->t_ase_calc
);
479 OSPF_TIMER_OFF (ospf
->t_maxage
);
480 OSPF_TIMER_OFF (ospf
->t_maxage_walker
);
481 OSPF_TIMER_OFF (ospf
->t_abr_task
);
482 OSPF_TIMER_OFF (ospf
->t_asbr_check
);
483 OSPF_TIMER_OFF (ospf
->t_distribute_update
);
484 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
485 OSPF_TIMER_OFF (ospf
->t_read
);
486 OSPF_TIMER_OFF (ospf
->t_write
);
487 #ifdef HAVE_OPAQUE_LSA
488 OSPF_TIMER_OFF (ospf
->t_opaque_lsa_self
);
492 stream_free(ospf
->ibuf
);
494 #ifdef HAVE_OPAQUE_LSA
495 LSDB_LOOP (OPAQUE_AS_LSDB (ospf
), rn
, lsa
)
496 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
497 #endif /* HAVE_OPAQUE_LSA */
498 LSDB_LOOP (EXTERNAL_LSDB (ospf
), rn
, lsa
)
499 ospf_discard_from_db (ospf
, ospf
->lsdb
, lsa
);
501 ospf_lsdb_delete_all (ospf
->lsdb
);
502 ospf_lsdb_free (ospf
->lsdb
);
504 for (ALL_LIST_ELEMENTS (ospf
->maxage_lsa
, node
, nnode
, lsa
))
505 ospf_lsa_unlock (&lsa
); /* maxage_lsa */
507 list_delete (ospf
->maxage_lsa
);
510 ospf_route_table_free (ospf
->old_table
);
513 ospf_route_delete (ospf
->new_table
);
514 ospf_route_table_free (ospf
->new_table
);
517 ospf_rtrs_free (ospf
->old_rtrs
);
519 ospf_rtrs_free (ospf
->new_rtrs
);
520 if (ospf
->new_external_route
)
522 ospf_route_delete (ospf
->new_external_route
);
523 ospf_route_table_free (ospf
->new_external_route
);
525 if (ospf
->old_external_route
)
527 ospf_route_delete (ospf
->old_external_route
);
528 ospf_route_table_free (ospf
->old_external_route
);
530 if (ospf
->external_lsas
)
532 ospf_ase_external_lsas_finish (ospf
->external_lsas
);
535 list_delete (ospf
->areas
);
537 for (i
= ZEBRA_ROUTE_SYSTEM
; i
<= ZEBRA_ROUTE_MAX
; i
++)
538 if (EXTERNAL_INFO (i
) != NULL
)
539 for (rn
= route_top (EXTERNAL_INFO (i
)); rn
; rn
= route_next (rn
))
541 if (rn
->info
== NULL
)
544 XFREE (MTYPE_OSPF_EXTERNAL_INFO
, rn
->info
);
546 route_unlock_node (rn
);
549 ospf_distance_reset (ospf
);
550 route_table_finish (ospf
->distance_table
);
554 XFREE (MTYPE_OSPF_TOP
, ospf
);
558 /* allocate new OSPF Area object */
559 static struct ospf_area
*
560 ospf_area_new (struct ospf
*ospf
, struct in_addr area_id
)
562 struct ospf_area
*new;
564 /* Allocate new config_network. */
565 new = XCALLOC (MTYPE_OSPF_AREA
, sizeof (struct ospf_area
));
569 new->area_id
= area_id
;
571 new->external_routing
= OSPF_AREA_DEFAULT
;
572 new->default_cost
= 1;
573 new->auth_type
= OSPF_AUTH_NULL
;
576 new->lsdb
= ospf_lsdb_new ();
578 /* Self-originated LSAs initialize. */
579 new->router_lsa_self
= NULL
;
581 #ifdef HAVE_OPAQUE_LSA
582 ospf_opaque_type10_lsa_init (new);
583 #endif /* HAVE_OPAQUE_LSA */
585 new->oiflist
= list_new ();
586 new->ranges
= route_table_init ();
588 if (area_id
.s_addr
== OSPF_AREA_BACKBONE
)
589 ospf
->backbone
= new;
595 ospf_area_free (struct ospf_area
*area
)
597 struct route_node
*rn
;
598 struct ospf_lsa
*lsa
;
601 LSDB_LOOP (ROUTER_LSDB (area
), rn
, lsa
)
602 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
603 LSDB_LOOP (NETWORK_LSDB (area
), rn
, lsa
)
604 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
605 LSDB_LOOP (SUMMARY_LSDB (area
), rn
, lsa
)
606 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
607 LSDB_LOOP (ASBR_SUMMARY_LSDB (area
), rn
, lsa
)
608 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
610 LSDB_LOOP (NSSA_LSDB (area
), rn
, lsa
)
611 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
612 #ifdef HAVE_OPAQUE_LSA
613 LSDB_LOOP (OPAQUE_AREA_LSDB (area
), rn
, lsa
)
614 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
615 LSDB_LOOP (OPAQUE_LINK_LSDB (area
), rn
, lsa
)
616 ospf_discard_from_db (area
->ospf
, area
->lsdb
, lsa
);
617 #endif /* HAVE_OPAQUE_LSA */
619 ospf_lsdb_delete_all (area
->lsdb
);
620 ospf_lsdb_free (area
->lsdb
);
622 ospf_lsa_unlock (&area
->router_lsa_self
);
624 route_table_finish (area
->ranges
);
625 list_delete (area
->oiflist
);
627 if (EXPORT_NAME (area
))
628 free (EXPORT_NAME (area
));
630 if (IMPORT_NAME (area
))
631 free (IMPORT_NAME (area
));
634 OSPF_TIMER_OFF (area
->t_stub_router
);
635 #ifdef HAVE_OPAQUE_LSA
636 OSPF_TIMER_OFF (area
->t_opaque_lsa_self
);
637 #endif /* HAVE_OPAQUE_LSA */
639 if (OSPF_IS_AREA_BACKBONE (area
))
640 area
->ospf
->backbone
= NULL
;
642 XFREE (MTYPE_OSPF_AREA
, area
);
646 ospf_area_check_free (struct ospf
*ospf
, struct in_addr area_id
)
648 struct ospf_area
*area
;
650 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
652 listcount (area
->oiflist
) == 0 &&
653 area
->ranges
->top
== NULL
&&
654 area
->shortcut_configured
== OSPF_SHORTCUT_DEFAULT
&&
655 area
->external_routing
== OSPF_AREA_DEFAULT
&&
656 area
->no_summary
== 0 &&
657 area
->default_cost
== 1 &&
658 EXPORT_NAME (area
) == NULL
&&
659 IMPORT_NAME (area
) == NULL
&&
660 area
->auth_type
== OSPF_AUTH_NULL
)
662 listnode_delete (ospf
->areas
, area
);
663 ospf_area_free (area
);
668 ospf_area_get (struct ospf
*ospf
, struct in_addr area_id
, int format
)
670 struct ospf_area
*area
;
672 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
675 area
= ospf_area_new (ospf
, area_id
);
676 area
->format
= format
;
677 listnode_add_sort (ospf
->areas
, area
);
678 ospf_check_abr_status (ospf
);
685 ospf_area_lookup_by_area_id (struct ospf
*ospf
, struct in_addr area_id
)
687 struct ospf_area
*area
;
688 struct listnode
*node
;
690 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
691 if (IPV4_ADDR_SAME (&area
->area_id
, &area_id
))
698 ospf_area_add_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
700 listnode_add (area
->oiflist
, oi
);
704 ospf_area_del_if (struct ospf_area
*area
, struct ospf_interface
*oi
)
706 listnode_delete (area
->oiflist
, oi
);
710 /* Config network statement related functions. */
711 static struct ospf_network
*
712 ospf_network_new (struct in_addr area_id
, int format
)
714 struct ospf_network
*new;
715 new = XCALLOC (MTYPE_OSPF_NETWORK
, sizeof (struct ospf_network
));
717 new->area_id
= area_id
;
718 new->format
= format
;
724 ospf_network_free (struct ospf
*ospf
, struct ospf_network
*network
)
726 ospf_area_check_free (ospf
, network
->area_id
);
727 ospf_schedule_abr_task (ospf
);
728 XFREE (MTYPE_OSPF_NETWORK
, network
);
732 ospf_network_set (struct ospf
*ospf
, struct prefix_ipv4
*p
,
733 struct in_addr area_id
)
735 struct ospf_network
*network
;
736 struct ospf_area
*area
;
737 struct route_node
*rn
;
738 struct external_info
*ei
;
739 int ret
= OSPF_AREA_ID_FORMAT_ADDRESS
;
741 rn
= route_node_get (ospf
->networks
, (struct prefix
*)p
);
744 /* There is already same network statement. */
745 route_unlock_node (rn
);
749 rn
->info
= network
= ospf_network_new (area_id
, ret
);
750 area
= ospf_area_get (ospf
, area_id
, ret
);
752 /* Run network config now. */
753 ospf_network_run ((struct prefix
*)p
, area
);
755 /* Update connected redistribute. */
756 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT
))
757 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
))
758 for (rn
= route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
));
759 rn
; rn
= route_next (rn
))
760 if ((ei
= rn
->info
) != NULL
)
761 if (ospf_external_info_find_lsa (ospf
, &ei
->p
))
762 if (!ospf_distribute_check_connected (ospf
, ei
))
763 ospf_external_lsa_flush (ospf
, ei
->type
, &ei
->p
,
764 ei
->ifindex
/*, ei->nexthop */);
766 ospf_area_check_free (ospf
, area_id
);
772 ospf_network_unset (struct ospf
*ospf
, struct prefix_ipv4
*p
,
773 struct in_addr area_id
)
775 struct route_node
*rn
;
776 struct ospf_network
*network
;
777 struct external_info
*ei
;
778 struct listnode
*node
, *nnode
;
779 struct ospf_interface
*oi
;
781 rn
= route_node_lookup (ospf
->networks
, (struct prefix
*)p
);
786 route_unlock_node (rn
);
787 if (!IPV4_ADDR_SAME (&area_id
, &network
->area_id
))
790 ospf_network_free (ospf
, rn
->info
);
792 route_unlock_node (rn
); /* initial reference */
794 /* Find interfaces that not configured already. */
795 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
798 struct connected
*co
= oi
->connected
;
800 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
803 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
805 if (rn
->info
== NULL
)
808 if (ospf_network_match_iface(co
,&rn
->p
))
811 route_unlock_node (rn
);
820 /* Update connected redistribute. */
821 if (ospf_is_type_redistributed (ZEBRA_ROUTE_CONNECT
))
822 if (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
))
823 for (rn
= route_top (EXTERNAL_INFO (ZEBRA_ROUTE_CONNECT
));
824 rn
; rn
= route_next (rn
))
825 if ((ei
= rn
->info
) != NULL
)
826 if (!ospf_external_info_find_lsa (ospf
, &ei
->p
))
827 if (ospf_distribute_check_connected (ospf
, ei
))
828 ospf_external_lsa_originate (ospf
, ei
);
833 /* Check whether interface matches given network
834 * returns: 1, true. 0, false
837 ospf_network_match_iface(const struct connected
*co
, const struct prefix
*net
)
839 /* new approach: more elegant and conceptually clean */
840 return prefix_match(net
, CONNECTED_PREFIX(co
));
844 ospf_network_run_interface (struct prefix
*p
, struct ospf_area
*area
,
845 struct interface
*ifp
)
847 struct listnode
*cnode
;
848 struct connected
*co
;
850 if (memcmp (ifp
->name
, "VLINK", 5) == 0)
853 /* if interface prefix is match specified prefix,
854 then create socket and join multicast group. */
855 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, cnode
, co
))
858 if (CHECK_FLAG(co
->flags
,ZEBRA_IFA_SECONDARY
))
861 if (p
->family
== co
->address
->family
862 && ! ospf_if_table_lookup(ifp
, co
->address
)
863 && ospf_network_match_iface(co
,p
))
865 struct ospf_interface
*oi
;
867 oi
= ospf_if_new (area
->ospf
, ifp
, co
->address
);
872 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
873 oi
->output_cost
= ospf_if_get_output_cost (oi
);
875 /* Add pseudo neighbor. */
876 ospf_nbr_add_self (oi
);
878 /* Relate ospf interface to ospf instance. */
879 oi
->ospf
= area
->ospf
;
881 /* update network type as interface flag */
882 /* If network type is specified previously,
883 skip network type setting. */
884 oi
->type
= IF_DEF_PARAMS (ifp
)->type
;
886 ospf_area_add_if (oi
->area
, oi
);
888 /* if router_id is not configured, dont bring up
890 * ospf_router_id_update() will call ospf_if_update
891 * whenever r-id is configured instead.
893 if ((area
->ospf
->router_id
.s_addr
!= 0)
894 && if_is_operative (ifp
))
901 ospf_network_run (struct prefix
*p
, struct ospf_area
*area
)
903 struct interface
*ifp
;
904 struct listnode
*node
;
906 /* Schedule Router ID Update. */
907 if (area
->ospf
->router_id
.s_addr
== 0)
908 ospf_router_id_update (area
->ospf
);
910 /* Get target interface. */
911 for (ALL_LIST_ELEMENTS_RO (om
->iflist
, node
, ifp
))
912 ospf_network_run_interface (p
, area
, ifp
);
916 ospf_ls_upd_queue_empty (struct ospf_interface
*oi
)
918 struct route_node
*rn
;
919 struct listnode
*node
, *nnode
;
921 struct ospf_lsa
*lsa
;
923 /* empty ls update queue */
924 for (rn
= route_top (oi
->ls_upd_queue
); rn
;
925 rn
= route_next (rn
))
926 if ((lst
= (struct list
*) rn
->info
))
928 for (ALL_LIST_ELEMENTS (lst
, node
, nnode
, lsa
))
929 ospf_lsa_unlock (&lsa
); /* oi->ls_upd_queue */
934 /* remove update event */
935 if (oi
->t_ls_upd_event
)
937 thread_cancel (oi
->t_ls_upd_event
);
938 oi
->t_ls_upd_event
= NULL
;
943 ospf_if_update (struct ospf
*ospf
, struct interface
*ifp
)
945 struct route_node
*rn
;
946 struct ospf_network
*network
;
947 struct ospf_area
*area
;
950 ospf
= ospf_lookup ();
952 /* OSPF must be on and Router-ID must be configured. */
953 if (!ospf
|| ospf
->router_id
.s_addr
== 0)
956 /* Run each netowrk for this interface. */
957 for (rn
= route_top (ospf
->networks
); rn
; rn
= route_next (rn
))
958 if (rn
->info
!= NULL
)
960 network
= (struct ospf_network
*) rn
->info
;
961 area
= ospf_area_get (ospf
, network
->area_id
, network
->format
);
962 ospf_network_run_interface (&rn
->p
, area
, ifp
);
967 ospf_remove_vls_through_area (struct ospf
*ospf
, struct ospf_area
*area
)
969 struct listnode
*node
, *nnode
;
970 struct ospf_vl_data
*vl_data
;
972 for (ALL_LIST_ELEMENTS (ospf
->vlinks
, node
, nnode
, vl_data
))
973 if (IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
974 ospf_vl_delete (ospf
, vl_data
);
978 static const struct message ospf_area_type_msg
[] =
980 { OSPF_AREA_DEFAULT
, "Default" },
981 { OSPF_AREA_STUB
, "Stub" },
982 { OSPF_AREA_NSSA
, "NSSA" },
984 static const int ospf_area_type_msg_max
= OSPF_AREA_TYPE_MAX
;
987 ospf_area_type_set (struct ospf_area
*area
, int type
)
989 struct listnode
*node
;
990 struct ospf_interface
*oi
;
992 if (area
->external_routing
== type
)
994 if (IS_DEBUG_OSPF_EVENT
)
995 zlog_debug ("Area[%s]: Types are the same, ignored.",
996 inet_ntoa (area
->area_id
));
1000 area
->external_routing
= type
;
1002 if (IS_DEBUG_OSPF_EVENT
)
1003 zlog_debug ("Area[%s]: Configured as %s", inet_ntoa (area
->area_id
),
1004 LOOKUP (ospf_area_type_msg
, type
));
1006 switch (area
->external_routing
)
1008 case OSPF_AREA_DEFAULT
:
1009 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1010 if (oi
->nbr_self
!= NULL
)
1012 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1013 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1016 case OSPF_AREA_STUB
:
1017 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1018 if (oi
->nbr_self
!= NULL
)
1020 if (IS_DEBUG_OSPF_EVENT
)
1021 zlog_debug ("setting options on %s accordingly", IF_NAME (oi
));
1022 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1023 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1024 if (IS_DEBUG_OSPF_EVENT
)
1025 zlog_debug ("options set on %s: %x",
1026 IF_NAME (oi
), OPTIONS (oi
));
1029 case OSPF_AREA_NSSA
:
1030 for (ALL_LIST_ELEMENTS_RO (area
->oiflist
, node
, oi
))
1031 if (oi
->nbr_self
!= NULL
)
1033 zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi
));
1034 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
1035 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
1036 zlog_debug ("options set on %s: %x", IF_NAME (oi
), OPTIONS (oi
));
1043 ospf_router_lsa_update_area (area
);
1044 ospf_schedule_abr_task (area
->ospf
);
1048 ospf_area_shortcut_set (struct ospf
*ospf
, struct ospf_area
*area
, int mode
)
1050 if (area
->shortcut_configured
== mode
)
1053 area
->shortcut_configured
= mode
;
1054 ospf_router_lsa_update_area (area
);
1055 ospf_schedule_abr_task (ospf
);
1057 ospf_area_check_free (ospf
, area
->area_id
);
1063 ospf_area_shortcut_unset (struct ospf
*ospf
, struct ospf_area
*area
)
1065 area
->shortcut_configured
= OSPF_SHORTCUT_DEFAULT
;
1066 ospf_router_lsa_update_area (area
);
1067 ospf_area_check_free (ospf
, area
->area_id
);
1068 ospf_schedule_abr_task (ospf
);
1074 ospf_area_vlink_count (struct ospf
*ospf
, struct ospf_area
*area
)
1076 struct ospf_vl_data
*vl
;
1077 struct listnode
*node
;
1080 for (ALL_LIST_ELEMENTS_RO (ospf
->vlinks
, node
, vl
))
1081 if (IPV4_ADDR_SAME (&vl
->vl_area_id
, &area
->area_id
))
1088 ospf_area_stub_set (struct ospf
*ospf
, struct in_addr area_id
)
1090 struct ospf_area
*area
;
1091 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1093 area
= ospf_area_get (ospf
, area_id
, format
);
1094 if (ospf_area_vlink_count (ospf
, area
))
1097 if (area
->external_routing
!= OSPF_AREA_STUB
)
1098 ospf_area_type_set (area
, OSPF_AREA_STUB
);
1104 ospf_area_stub_unset (struct ospf
*ospf
, struct in_addr area_id
)
1106 struct ospf_area
*area
;
1108 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1112 if (area
->external_routing
== OSPF_AREA_STUB
)
1113 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1115 ospf_area_check_free (ospf
, area_id
);
1121 ospf_area_no_summary_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 area
->no_summary
= 1;
1133 ospf_area_no_summary_unset (struct ospf
*ospf
, struct in_addr area_id
)
1135 struct ospf_area
*area
;
1137 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1141 area
->no_summary
= 0;
1142 ospf_area_check_free (ospf
, area_id
);
1148 ospf_area_nssa_set (struct ospf
*ospf
, struct in_addr area_id
)
1150 struct ospf_area
*area
;
1151 int format
= OSPF_AREA_ID_FORMAT_ADDRESS
;
1153 area
= ospf_area_get (ospf
, area_id
, format
);
1154 if (ospf_area_vlink_count (ospf
, area
))
1157 if (area
->external_routing
!= OSPF_AREA_NSSA
)
1159 ospf_area_type_set (area
, OSPF_AREA_NSSA
);
1163 /* set NSSA area defaults */
1164 area
->no_summary
= 0;
1165 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1166 area
->NSSATranslatorState
= OSPF_NSSA_TRANSLATE_DISABLED
;
1167 area
->NSSATranslatorStabilityInterval
= OSPF_NSSA_TRANS_STABLE_DEFAULT
;
1173 ospf_area_nssa_unset (struct ospf
*ospf
, struct in_addr area_id
)
1175 struct ospf_area
*area
;
1177 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1181 if (area
->external_routing
== OSPF_AREA_NSSA
)
1184 ospf_area_type_set (area
, OSPF_AREA_DEFAULT
);
1187 ospf_area_check_free (ospf
, area_id
);
1193 ospf_area_nssa_translator_role_set (struct ospf
*ospf
, struct in_addr area_id
,
1196 struct ospf_area
*area
;
1198 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1202 area
->NSSATranslatorRole
= role
;
1207 /* XXX: unused? Leave for symmetry? */
1209 ospf_area_nssa_translator_role_unset (struct ospf
*ospf
,
1210 struct in_addr area_id
)
1212 struct ospf_area
*area
;
1214 area
= ospf_area_lookup_by_area_id (ospf
, area_id
);
1218 area
->NSSATranslatorRole
= OSPF_NSSA_ROLE_CANDIDATE
;
1220 ospf_area_check_free (ospf
, area_id
);
1226 ospf_area_export_list_set (struct ospf
*ospf
,
1227 struct ospf_area
*area
, const char *list_name
)
1229 struct access_list
*list
;
1230 list
= access_list_lookup (AFI_IP
, list_name
);
1232 EXPORT_LIST (area
) = list
;
1234 if (EXPORT_NAME (area
))
1235 free (EXPORT_NAME (area
));
1237 EXPORT_NAME (area
) = strdup (list_name
);
1238 ospf_schedule_abr_task (ospf
);
1244 ospf_area_export_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1247 EXPORT_LIST (area
) = 0;
1249 if (EXPORT_NAME (area
))
1250 free (EXPORT_NAME (area
));
1252 EXPORT_NAME (area
) = NULL
;
1254 ospf_area_check_free (ospf
, area
->area_id
);
1256 ospf_schedule_abr_task (ospf
);
1262 ospf_area_import_list_set (struct ospf
*ospf
, struct ospf_area
*area
,
1265 struct access_list
*list
;
1266 list
= access_list_lookup (AFI_IP
, name
);
1268 IMPORT_LIST (area
) = list
;
1270 if (IMPORT_NAME (area
))
1271 free (IMPORT_NAME (area
));
1273 IMPORT_NAME (area
) = strdup (name
);
1274 ospf_schedule_abr_task (ospf
);
1280 ospf_area_import_list_unset (struct ospf
*ospf
, struct ospf_area
* area
)
1282 IMPORT_LIST (area
) = 0;
1284 if (IMPORT_NAME (area
))
1285 free (IMPORT_NAME (area
));
1287 IMPORT_NAME (area
) = NULL
;
1288 ospf_area_check_free (ospf
, area
->area_id
);
1290 ospf_schedule_abr_task (ospf
);
1296 ospf_timers_refresh_set (struct ospf
*ospf
, int interval
)
1300 if (ospf
->lsa_refresh_interval
== interval
)
1303 time_left
= ospf
->lsa_refresh_interval
-
1304 (quagga_time (NULL
) - ospf
->lsa_refresher_started
);
1306 if (time_left
> interval
)
1308 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1309 ospf
->t_lsa_refresher
=
1310 thread_add_timer (master
, ospf_lsa_refresh_walker
, ospf
, interval
);
1312 ospf
->lsa_refresh_interval
= interval
;
1318 ospf_timers_refresh_unset (struct ospf
*ospf
)
1322 time_left
= ospf
->lsa_refresh_interval
-
1323 (quagga_time (NULL
) - ospf
->lsa_refresher_started
);
1325 if (time_left
> OSPF_LSA_REFRESH_INTERVAL_DEFAULT
)
1327 OSPF_TIMER_OFF (ospf
->t_lsa_refresher
);
1328 ospf
->t_lsa_refresher
=
1329 thread_add_timer (master
, ospf_lsa_refresh_walker
, ospf
,
1330 OSPF_LSA_REFRESH_INTERVAL_DEFAULT
);
1333 ospf
->lsa_refresh_interval
= OSPF_LSA_REFRESH_INTERVAL_DEFAULT
;
1339 static struct ospf_nbr_nbma
*
1340 ospf_nbr_nbma_new (void)
1342 struct ospf_nbr_nbma
*nbr_nbma
;
1344 nbr_nbma
= XCALLOC (MTYPE_OSPF_NEIGHBOR_STATIC
,
1345 sizeof (struct ospf_nbr_nbma
));
1347 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1348 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1354 ospf_nbr_nbma_free (struct ospf_nbr_nbma
*nbr_nbma
)
1356 XFREE (MTYPE_OSPF_NEIGHBOR_STATIC
, nbr_nbma
);
1360 ospf_nbr_nbma_delete (struct ospf
*ospf
, struct ospf_nbr_nbma
*nbr_nbma
)
1362 struct route_node
*rn
;
1363 struct prefix_ipv4 p
;
1366 p
.prefix
= nbr_nbma
->addr
;
1367 p
.prefixlen
= IPV4_MAX_BITLEN
;
1369 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1372 ospf_nbr_nbma_free (rn
->info
);
1374 route_unlock_node (rn
);
1375 route_unlock_node (rn
);
1380 ospf_nbr_nbma_down (struct ospf_nbr_nbma
*nbr_nbma
)
1382 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1386 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
1387 OSPF_NSM_EVENT_EXECUTE (nbr_nbma
->nbr
, NSM_KillNbr
);
1391 listnode_delete (nbr_nbma
->oi
->nbr_nbma
, nbr_nbma
);
1395 ospf_nbr_nbma_add (struct ospf_nbr_nbma
*nbr_nbma
,
1396 struct ospf_interface
*oi
)
1398 struct ospf_neighbor
*nbr
;
1399 struct route_node
*rn
;
1402 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1405 if (nbr_nbma
->nbr
!= NULL
)
1408 if (IPV4_ADDR_SAME (&oi
->nbr_self
->address
.u
.prefix4
, &nbr_nbma
->addr
))
1412 listnode_add (oi
->nbr_nbma
, nbr_nbma
);
1414 /* Get neighbor information from table. */
1416 p
.prefixlen
= IPV4_MAX_BITLEN
;
1417 p
.u
.prefix4
= nbr_nbma
->addr
;
1419 rn
= route_node_get (oi
->nbrs
, (struct prefix
*)&p
);
1423 nbr
->nbr_nbma
= nbr_nbma
;
1424 nbr_nbma
->nbr
= nbr
;
1426 route_unlock_node (rn
);
1430 nbr
= rn
->info
= ospf_nbr_new (oi
);
1431 nbr
->state
= NSM_Down
;
1432 nbr
->src
= nbr_nbma
->addr
;
1433 nbr
->nbr_nbma
= nbr_nbma
;
1434 nbr
->priority
= nbr_nbma
->priority
;
1437 nbr_nbma
->nbr
= nbr
;
1439 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_Start
);
1444 ospf_nbr_nbma_if_update (struct ospf
*ospf
, struct ospf_interface
*oi
)
1446 struct ospf_nbr_nbma
*nbr_nbma
;
1447 struct route_node
*rn
;
1448 struct prefix_ipv4 p
;
1450 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
1453 for (rn
= route_top (ospf
->nbr_nbma
); rn
; rn
= route_next (rn
))
1454 if ((nbr_nbma
= rn
->info
))
1455 if (nbr_nbma
->oi
== NULL
&& nbr_nbma
->nbr
== NULL
)
1458 p
.prefix
= nbr_nbma
->addr
;
1459 p
.prefixlen
= IPV4_MAX_BITLEN
;
1461 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1462 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1466 struct ospf_nbr_nbma
*
1467 ospf_nbr_nbma_lookup (struct ospf
*ospf
, struct in_addr nbr_addr
)
1469 struct route_node
*rn
;
1470 struct prefix_ipv4 p
;
1473 p
.prefix
= nbr_addr
;
1474 p
.prefixlen
= IPV4_MAX_BITLEN
;
1476 rn
= route_node_lookup (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1479 route_unlock_node (rn
);
1485 struct ospf_nbr_nbma
*
1486 ospf_nbr_nbma_lookup_next (struct ospf
*ospf
, struct in_addr
*addr
, int first
)
1489 struct ospf_nbr_nbma
*nbr_nbma
;
1490 struct listnode
*node
;
1497 for (ALL_LIST_ELEMENTS_RO (ospf
->nbr_nbma
, node
, nbr_nbma
))
1501 *addr
= nbr_nbma
->addr
;
1504 else if (ntohl (nbr_nbma
->addr
.s_addr
) > ntohl (addr
->s_addr
))
1506 *addr
= nbr_nbma
->addr
;
1515 ospf_nbr_nbma_set (struct ospf
*ospf
, struct in_addr nbr_addr
)
1517 struct ospf_nbr_nbma
*nbr_nbma
;
1518 struct ospf_interface
*oi
;
1519 struct prefix_ipv4 p
;
1520 struct route_node
*rn
;
1521 struct listnode
*node
;
1523 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1527 nbr_nbma
= ospf_nbr_nbma_new ();
1528 nbr_nbma
->addr
= nbr_addr
;
1531 p
.prefix
= nbr_addr
;
1532 p
.prefixlen
= IPV4_MAX_BITLEN
;
1534 rn
= route_node_get (ospf
->nbr_nbma
, (struct prefix
*)&p
);
1535 rn
->info
= nbr_nbma
;
1537 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
1539 if (oi
->type
== OSPF_IFTYPE_NBMA
)
1540 if (prefix_match (oi
->address
, (struct prefix
*)&p
))
1542 ospf_nbr_nbma_add (nbr_nbma
, oi
);
1551 ospf_nbr_nbma_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1553 struct ospf_nbr_nbma
*nbr_nbma
;
1555 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1556 if (nbr_nbma
== NULL
)
1559 ospf_nbr_nbma_down (nbr_nbma
);
1560 ospf_nbr_nbma_delete (ospf
, nbr_nbma
);
1566 ospf_nbr_nbma_priority_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1569 struct ospf_nbr_nbma
*nbr_nbma
;
1571 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1572 if (nbr_nbma
== NULL
)
1575 if (nbr_nbma
->priority
!= priority
)
1576 nbr_nbma
->priority
= priority
;
1582 ospf_nbr_nbma_priority_unset (struct ospf
*ospf
, struct in_addr nbr_addr
)
1584 struct ospf_nbr_nbma
*nbr_nbma
;
1586 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1587 if (nbr_nbma
== NULL
)
1590 if (nbr_nbma
!= OSPF_NEIGHBOR_PRIORITY_DEFAULT
)
1591 nbr_nbma
->priority
= OSPF_NEIGHBOR_PRIORITY_DEFAULT
;
1597 ospf_nbr_nbma_poll_interval_set (struct ospf
*ospf
, struct in_addr nbr_addr
,
1598 unsigned int interval
)
1600 struct ospf_nbr_nbma
*nbr_nbma
;
1602 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, nbr_addr
);
1603 if (nbr_nbma
== NULL
)
1606 if (nbr_nbma
->v_poll
!= interval
)
1608 nbr_nbma
->v_poll
= interval
;
1609 if (nbr_nbma
->oi
&& ospf_if_is_up (nbr_nbma
->oi
))
1611 OSPF_TIMER_OFF (nbr_nbma
->t_poll
);
1612 OSPF_POLL_TIMER_ON (nbr_nbma
->t_poll
, ospf_poll_timer
,
1621 ospf_nbr_nbma_poll_interval_unset (struct ospf
*ospf
, struct in_addr addr
)
1623 struct ospf_nbr_nbma
*nbr_nbma
;
1625 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, addr
);
1626 if (nbr_nbma
== NULL
)
1629 if (nbr_nbma
->v_poll
!= OSPF_POLL_INTERVAL_DEFAULT
)
1630 nbr_nbma
->v_poll
= OSPF_POLL_INTERVAL_DEFAULT
;
1638 memset (&ospf_master
, 0, sizeof (struct ospf_master
));
1641 om
->ospf
= list_new ();
1642 om
->master
= thread_master_create ();
1643 om
->start_time
= quagga_time (NULL
);