2 * OSPF Interface functions.
3 * Copyright (C) 1999, 2000 Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
35 #include "ospfd/ospfd.h"
36 #include "ospfd/ospf_spf.h"
37 #include "ospfd/ospf_interface.h"
38 #include "ospfd/ospf_ism.h"
39 #include "ospfd/ospf_asbr.h"
40 #include "ospfd/ospf_lsa.h"
41 #include "ospfd/ospf_lsdb.h"
42 #include "ospfd/ospf_neighbor.h"
43 #include "ospfd/ospf_nsm.h"
44 #include "ospfd/ospf_packet.h"
45 #include "ospfd/ospf_abr.h"
46 #include "ospfd/ospf_network.h"
47 #include "ospfd/ospf_dump.h"
49 #include "ospfd/ospf_snmp.h"
50 #endif /* HAVE_SNMP */
54 ospf_if_get_output_cost (struct ospf_interface
*oi
)
56 /* If all else fails, use default OSPF cost */
60 bw
= oi
->ifp
->bandwidth
? oi
->ifp
->bandwidth
: OSPF_DEFAULT_BANDWIDTH
;
61 refbw
= oi
->ospf
->ref_bandwidth
;
63 /* A specifed ip ospf cost overrides a calculated one. */
64 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi
->ifp
), output_cost_cmd
) ||
65 OSPF_IF_PARAM_CONFIGURED (oi
->params
, output_cost_cmd
))
66 cost
= OSPF_IF_PARAM (oi
, output_cost_cmd
);
67 /* See if a cost can be calculated from the zebra processes
68 interface bandwidth field. */
71 cost
= (u_int32_t
) ((double)refbw
/ (double)bw
+ (double)0.5);
74 else if (cost
> 65535)
82 ospf_if_recalculate_output_cost (struct interface
*ifp
)
85 struct route_node
*rn
;
87 for (rn
= route_top (IF_OIFS (ifp
)); rn
; rn
= route_next (rn
))
89 struct ospf_interface
*oi
;
91 if ( (oi
= rn
->info
) == NULL
)
94 newcost
= ospf_if_get_output_cost (oi
);
96 /* Is actual output cost changed? */
97 if (oi
->output_cost
!= newcost
)
99 oi
->output_cost
= newcost
;
100 ospf_router_lsa_timer_add (oi
->area
);
106 ospf_if_reset_variables (struct ospf_interface
*oi
)
108 /* Set default values. */
109 /* don't clear this flag. oi->flag = OSPF_IF_DISABLE; */
112 oi
->type
= OSPF_IFTYPE_VIRTUALLINK
;
114 /* preserve network-type */
115 if (oi
->type
!= OSPF_IFTYPE_NBMA
)
116 oi
->type
= OSPF_IFTYPE_BROADCAST
;
118 oi
->state
= ISM_Down
;
120 oi
->crypt_seqnum
= 0;
122 /* This must be short, (less than RxmtInterval)
123 - RFC 2328 Section 13.5 para 3. Set to 1 second to avoid Acks being
124 held back for too long - MAG */
129 ospf_add_to_if (struct interface
*ifp
, struct ospf_interface
*oi
)
131 struct route_node
*rn
;
135 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
137 rn
= route_node_get (IF_OIFS (ifp
), &p
);
138 /* rn->info should either be NULL or equal to this oi
139 * as route_node_get may return an existing node
141 assert (! rn
->info
|| rn
->info
== oi
);
146 ospf_delete_from_if (struct interface
*ifp
, struct ospf_interface
*oi
)
148 struct route_node
*rn
;
152 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
154 rn
= route_node_lookup (IF_OIFS (oi
->ifp
), &p
);
158 route_unlock_node (rn
);
159 route_unlock_node (rn
);
162 struct ospf_interface
*
163 ospf_if_new (struct ospf
*ospf
, struct interface
*ifp
, struct prefix
*p
)
165 struct ospf_interface
*oi
;
167 oi
= XCALLOC (MTYPE_OSPF_IF
, sizeof (struct ospf_interface
));
168 memset (oi
, 0, sizeof (struct ospf_interface
));
170 /* Set zebra interface pointer. */
174 ospf_add_to_if (ifp
, oi
);
175 listnode_add (ospf
->oiflist
, oi
);
177 /* Clear self-originated network-LSA. */
178 oi
->network_lsa_self
= NULL
;
180 /* Initialize neighbor list. */
181 oi
->nbrs
= route_table_init ();
183 /* Initialize static neighbor list. */
184 oi
->nbr_nbma
= list_new ();
186 /* Initialize Link State Acknowledgment list. */
187 oi
->ls_ack
= list_new ();
188 oi
->ls_ack_direct
.ls_ack
= list_new ();
190 /* Set default values. */
191 ospf_if_reset_variables (oi
);
193 /* Add pseudo neighbor. */
194 oi
->nbr_self
= ospf_nbr_new (oi
);
195 oi
->nbr_self
->state
= NSM_TwoWay
;
196 oi
->nbr_self
->priority
= OSPF_IF_PARAM (oi
, priority
);
197 oi
->nbr_self
->options
= OSPF_OPTION_E
;
199 oi
->ls_upd_queue
= route_table_init ();
200 oi
->t_ls_upd_event
= NULL
;
201 oi
->t_ls_ack_direct
= NULL
;
203 oi
->crypt_seqnum
= time (NULL
);
205 #ifdef HAVE_OPAQUE_LSA
206 ospf_opaque_type9_lsa_init (oi
);
207 #endif /* HAVE_OPAQUE_LSA */
214 /* Restore an interface to its pre UP state
215 Used from ism_interface_down only */
217 ospf_if_cleanup (struct ospf_interface
*oi
)
219 struct route_node
*rn
;
221 struct ospf_neighbor
*nbr
;
223 /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */
224 /* delete all static neighbors attached to this interface */
225 for (node
= listhead (oi
->nbr_nbma
); node
; )
227 struct ospf_nbr_nbma
*nbr_nbma
= getdata (node
);
230 OSPF_POLL_TIMER_OFF (nbr_nbma
->t_poll
);
234 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
235 nbr_nbma
->nbr
= NULL
;
240 listnode_delete (oi
->nbr_nbma
, nbr_nbma
);
243 /* send Neighbor event KillNbr to all associated neighbors. */
244 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
245 if ((nbr
= rn
->info
) != NULL
)
246 if (nbr
!= oi
->nbr_self
)
247 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_KillNbr
);
249 /* Cleanup Link State Acknowlegdment list. */
250 for (node
= listhead (oi
->ls_ack
); node
; nextnode (node
))
251 ospf_lsa_unlock (node
->data
);
252 list_delete_all_node (oi
->ls_ack
);
254 oi
->crypt_seqnum
= 0;
256 /* Empty link state update queue */
257 ospf_ls_upd_queue_empty (oi
);
259 /* Handle pseudo neighbor. */
260 ospf_nbr_delete (oi
->nbr_self
);
261 oi
->nbr_self
= ospf_nbr_new (oi
);
262 oi
->nbr_self
->state
= NSM_TwoWay
;
263 oi
->nbr_self
->priority
= OSPF_IF_PARAM (oi
, priority
);
265 switch (oi
->area
->external_routing
)
267 case OSPF_AREA_DEFAULT
:
268 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
271 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
275 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
276 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
278 #endif /* HAVE_NSSA */
281 ospf_lsa_unlock (oi
->network_lsa_self
);
282 oi
->network_lsa_self
= NULL
;
283 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
287 ospf_if_free (struct ospf_interface
*oi
)
291 assert (oi
->state
== ISM_Down
);
293 #ifdef HAVE_OPAQUE_LSA
294 ospf_opaque_type9_lsa_term (oi
);
295 #endif /* HAVE_OPAQUE_LSA */
297 /* Free Pseudo Neighbour */
298 ospf_nbr_delete (oi
->nbr_self
);
300 route_table_finish (oi
->nbrs
);
301 route_table_finish (oi
->ls_upd_queue
);
303 /* Free any lists that should be freed */
304 list_free (oi
->nbr_nbma
);
306 list_free (oi
->ls_ack
);
307 list_free (oi
->ls_ack_direct
.ls_ack
);
309 ospf_delete_from_if (oi
->ifp
, oi
);
311 listnode_delete (oi
->ospf
->oiflist
, oi
);
312 listnode_delete (oi
->area
->oiflist
, oi
);
314 memset (oi
, 0, sizeof (*oi
));
315 XFREE (MTYPE_OSPF_IF
, oi
);
320 * check if interface with given address is configured and
323 struct ospf_interface
*
324 ospf_if_is_configured (struct ospf
*ospf
, struct in_addr
*address
)
327 struct ospf_interface
*oi
;
330 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
331 if ((oi
= getdata (node
)) != NULL
&& oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
333 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
334 addr
= oi
->connected
->destination
;
338 if (IPV4_ADDR_SAME (address
, &addr
->u
.prefix4
))
346 ospf_if_is_up (struct ospf_interface
*oi
)
348 return if_is_up (oi
->ifp
);
351 struct ospf_interface
*
352 ospf_if_lookup_by_local_addr (struct ospf
*ospf
,
353 struct interface
*ifp
, struct in_addr address
)
356 struct ospf_interface
*oi
;
358 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
359 if ((oi
= getdata (node
)) != NULL
&& oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
361 if (ifp
&& oi
->ifp
!= ifp
)
364 if (IPV4_ADDR_SAME (&address
, &oi
->address
->u
.prefix4
))
371 struct ospf_interface
*
372 ospf_if_lookup_by_prefix (struct ospf
*ospf
, struct prefix_ipv4
*p
)
375 struct ospf_interface
*oi
;
378 /* Check each Interface. */
379 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
381 if ((oi
= getdata (node
)) != NULL
&& oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
383 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
385 prefix_copy (&ptmp
, oi
->connected
->destination
);
386 ptmp
.prefixlen
= IPV4_MAX_BITLEN
;
389 prefix_copy (&ptmp
, oi
->address
);
392 if (prefix_same (&ptmp
, (struct prefix
*) p
))
399 /* determine receiving interface by source of packet */
400 struct ospf_interface
*
401 ospf_if_lookup_recv_if (struct ospf
*ospf
, struct in_addr src
)
404 struct prefix_ipv4 addr
;
405 struct ospf_interface
*oi
, *match
;
407 addr
.family
= AF_INET
;
409 addr
.prefixlen
= IPV4_MAX_BITLEN
;
413 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
417 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
420 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
422 if (IPV4_ADDR_SAME (&oi
->connected
->destination
->u
.prefix4
, &src
))
427 if (prefix_match (oi
->address
, (struct prefix
*) &addr
))
436 ospf_if_stream_set (struct ospf_interface
*oi
)
438 /* set output fifo queue. */
439 if (oi
->obuf
== NULL
)
440 oi
->obuf
= ospf_fifo_new ();
444 ospf_if_stream_unset (struct ospf_interface
*oi
)
446 struct ospf
*ospf
= oi
->ospf
;
450 ospf_fifo_free (oi
->obuf
);
455 listnode_delete (ospf
->oi_write_q
, oi
);
456 if (list_isempty(ospf
->oi_write_q
))
457 OSPF_TIMER_OFF (ospf
->t_write
);
464 struct ospf_if_params
*
465 ospf_new_if_params ()
467 struct ospf_if_params
*oip
;
469 oip
= XMALLOC (MTYPE_OSPF_IF_PARAMS
, sizeof (struct ospf_if_params
));
470 memset (oip
, 0, sizeof (struct ospf_if_params
));
475 memset (oip
, 0, sizeof (struct ospf_if_params
));
477 UNSET_IF_PARAM (oip
, output_cost_cmd
);
478 UNSET_IF_PARAM (oip
, transmit_delay
);
479 UNSET_IF_PARAM (oip
, retransmit_interval
);
480 UNSET_IF_PARAM (oip
, passive_interface
);
481 UNSET_IF_PARAM (oip
, v_hello
);
482 UNSET_IF_PARAM (oip
, v_wait
);
483 UNSET_IF_PARAM (oip
, priority
);
484 UNSET_IF_PARAM (oip
, type
);
485 UNSET_IF_PARAM (oip
, auth_simple
);
486 UNSET_IF_PARAM (oip
, auth_crypt
);
487 UNSET_IF_PARAM (oip
, auth_type
);
489 oip
->auth_crypt
= list_new ();
495 ospf_del_if_params (struct ospf_if_params
*oip
)
497 list_delete (oip
->auth_crypt
);
498 XFREE (MTYPE_OSPF_IF_PARAMS
, oip
);
502 ospf_free_if_params (struct interface
*ifp
, struct in_addr addr
)
504 struct ospf_if_params
*oip
;
505 struct prefix_ipv4 p
;
506 struct route_node
*rn
;
507 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
509 rn
= route_node_lookup (IF_OIFS_PARAMS (ifp
), (struct prefix
*)&p
);
510 if (!rn
|| !rn
->info
)
514 route_unlock_node (rn
);
516 if (!OSPF_IF_PARAM_CONFIGURED (oip
, output_cost_cmd
) &&
517 !OSPF_IF_PARAM_CONFIGURED (oip
, transmit_delay
) &&
518 !OSPF_IF_PARAM_CONFIGURED (oip
, retransmit_interval
) &&
519 !OSPF_IF_PARAM_CONFIGURED (oip
, passive_interface
) &&
520 !OSPF_IF_PARAM_CONFIGURED (oip
, v_hello
) &&
521 !OSPF_IF_PARAM_CONFIGURED (oip
, v_wait
) &&
522 !OSPF_IF_PARAM_CONFIGURED (oip
, priority
) &&
523 !OSPF_IF_PARAM_CONFIGURED (oip
, type
) &&
524 !OSPF_IF_PARAM_CONFIGURED (oip
, auth_simple
) &&
525 !OSPF_IF_PARAM_CONFIGURED (oip
, auth_type
) &&
526 listcount (oip
->auth_crypt
) == 0)
528 ospf_del_if_params (oip
);
530 route_unlock_node (rn
);
534 struct ospf_if_params
*
535 ospf_lookup_if_params (struct interface
*ifp
, struct in_addr addr
)
537 struct prefix_ipv4 p
;
538 struct route_node
*rn
;
540 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
543 rn
= route_node_lookup (IF_OIFS_PARAMS (ifp
), (struct prefix
*)&p
);
547 route_unlock_node (rn
);
554 struct ospf_if_params
*
555 ospf_get_if_params (struct interface
*ifp
, struct in_addr addr
)
557 struct prefix_ipv4 p
;
558 struct route_node
*rn
;
561 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
564 rn
= route_node_get (IF_OIFS_PARAMS (ifp
), (struct prefix
*)&p
);
566 if (rn
->info
== NULL
)
567 rn
->info
= ospf_new_if_params ();
569 route_unlock_node (rn
);
575 ospf_if_update_params (struct interface
*ifp
, struct in_addr addr
)
577 struct route_node
*rn
;
578 struct ospf_interface
*oi
;
580 for (rn
= route_top (IF_OIFS (ifp
)); rn
; rn
= route_next (rn
))
582 if ((oi
= rn
->info
) == NULL
)
585 if (IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &addr
))
586 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
591 ospf_if_new_hook (struct interface
*ifp
)
595 ifp
->info
= XMALLOC (MTYPE_OSPF_IF_INFO
, sizeof (struct ospf_if_info
));
596 memset (ifp
->info
, 0, sizeof (struct ospf_if_info
));
598 IF_OIFS (ifp
) = route_table_init ();
599 IF_OIFS_PARAMS (ifp
) = route_table_init ();
601 IF_DEF_PARAMS (ifp
) = ospf_new_if_params ();
603 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), transmit_delay
);
604 IF_DEF_PARAMS (ifp
)->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
606 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), retransmit_interval
);
607 IF_DEF_PARAMS (ifp
)->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
609 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), priority
);
610 IF_DEF_PARAMS (ifp
)->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
612 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), passive_interface
);
613 IF_DEF_PARAMS (ifp
)->passive_interface
= OSPF_IF_ACTIVE
;
615 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), v_hello
);
616 IF_DEF_PARAMS (ifp
)->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
618 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), v_wait
);
619 IF_DEF_PARAMS (ifp
)->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
621 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), auth_simple
);
622 memset (IF_DEF_PARAMS (ifp
)->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
624 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), auth_crypt
);
625 IF_DEF_PARAMS (ifp
)->auth_crypt
= list_new ();
627 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), auth_type
);
628 IF_DEF_PARAMS (ifp
)->auth_type
= OSPF_AUTH_NOTSET
;
630 #ifdef HAVE_OPAQUE_LSA
631 rc
= ospf_opaque_new_if (ifp
);
632 #endif /* HAVE_OPAQUE_LSA */
637 ospf_if_delete_hook (struct interface
*ifp
)
640 #ifdef HAVE_OPAQUE_LSA
641 rc
= ospf_opaque_del_if (ifp
);
642 #endif /* HAVE_OPAQUE_LSA */
643 route_table_finish (IF_OIFS (ifp
));
644 route_table_finish (IF_OIFS_PARAMS (ifp
));
645 XFREE (MTYPE_OSPF_IF_INFO
, ifp
->info
);
652 ospf_if_is_enable (struct ospf_interface
*oi
)
654 if (!if_is_loopback (oi
->ifp
))
655 if (if_is_up (oi
->ifp
))
662 ospf_if_up (struct ospf_interface
*oi
)
667 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
)
668 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_LoopInd
);
671 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
672 ospf_if_add_allspfrouters (oi
->ospf
, oi
->address
, oi
->ifp
->ifindex
);
673 ospf_if_stream_set (oi
);
674 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_InterfaceUp
);
681 ospf_if_down (struct ospf_interface
*oi
)
686 OSPF_ISM_EVENT_EXECUTE (oi
, ISM_InterfaceDown
);
687 /* Shutdown packet reception and sending */
688 ospf_if_stream_unset (oi
);
689 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
690 ospf_if_drop_allspfrouters (oi
->ospf
, oi
->address
, oi
->ifp
->ifindex
);
697 /* Virtual Link related functions. */
699 struct ospf_vl_data
*
700 ospf_vl_data_new (struct ospf_area
*area
, struct in_addr vl_peer
)
702 struct ospf_vl_data
*vl_data
;
704 vl_data
= XMALLOC (MTYPE_OSPF_VL_DATA
, sizeof (struct ospf_vl_data
));
705 memset (vl_data
, 0, sizeof (struct ospf_vl_data
));
707 vl_data
->vl_peer
.s_addr
= vl_peer
.s_addr
;
708 vl_data
->vl_area_id
= area
->area_id
;
709 vl_data
->format
= area
->format
;
715 ospf_vl_data_free (struct ospf_vl_data
*vl_data
)
717 XFREE (MTYPE_OSPF_VL_DATA
, vl_data
);
720 u_int vlink_count
= 0;
722 struct ospf_interface
*
723 ospf_vl_new (struct ospf
*ospf
, struct ospf_vl_data
*vl_data
)
725 struct ospf_interface
* voi
;
726 struct interface
* vi
;
727 char ifname
[INTERFACE_NAMSIZ
+ 1];
728 struct ospf_area
*area
;
729 struct in_addr area_id
;
730 struct connected
*co
;
731 struct prefix_ipv4
*p
;
733 if (IS_DEBUG_OSPF_EVENT
)
734 zlog_info ("ospf_vl_new(): Start");
735 if (vlink_count
== OSPF_VL_MAX_COUNT
)
737 if (IS_DEBUG_OSPF_EVENT
)
738 zlog_info ("ospf_vl_new(): Alarm: "
739 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
743 if (IS_DEBUG_OSPF_EVENT
)
744 zlog_info ("ospf_vl_new(): creating pseudo zebra interface");
747 co
= connected_new ();
749 listnode_add (vi
->connected
, co
);
751 p
= prefix_ipv4_new ();
753 p
->prefix
.s_addr
= 0;
756 co
->address
= (struct prefix
*)p
;
758 voi
= ospf_if_new (ospf
, vi
, co
->address
);
761 if (IS_DEBUG_OSPF_EVENT
)
762 zlog_info ("ospf_vl_new(): Alarm: OSPF int structure is not created");
766 voi
->vl_data
= vl_data
;
767 voi
->ifp
->mtu
= OSPF_VL_MTU
;
768 voi
->type
= OSPF_IFTYPE_VIRTUALLINK
;
770 sprintf (ifname
, "VLINK%d", vlink_count
++);
771 if (IS_DEBUG_OSPF_EVENT
)
772 zlog_info ("ospf_vl_new(): Created name: %s", ifname
);
773 strncpy (vi
->name
, ifname
, IFNAMSIZ
);
774 if (IS_DEBUG_OSPF_EVENT
)
775 zlog_info ("ospf_vl_new(): set if->name to %s", vi
->name
);
778 area
= ospf_area_get (ospf
, area_id
, OSPF_AREA_ID_FORMAT_ADDRESS
);
781 if (IS_DEBUG_OSPF_EVENT
)
782 zlog_info ("ospf_vl_new(): set associated area to the backbone");
784 ospf_area_add_if (voi
->area
, voi
);
786 ospf_if_stream_set (voi
);
788 if (IS_DEBUG_OSPF_EVENT
)
789 zlog_info ("ospf_vl_new(): Stop");
794 ospf_vl_if_delete (struct ospf_vl_data
*vl_data
)
796 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
797 vl_data
->vl_oi
->address
->u
.prefix4
.s_addr
= 0;
798 vl_data
->vl_oi
->address
->prefixlen
= 0;
799 ospf_if_free (vl_data
->vl_oi
);
804 struct ospf_vl_data
*
805 ospf_vl_lookup (struct ospf_area
*area
, struct in_addr vl_peer
)
807 struct ospf_vl_data
*vl_data
;
810 for (node
= listhead (area
->ospf
->vlinks
); node
; nextnode (node
))
811 if ((vl_data
= getdata (node
)) != NULL
)
812 if (vl_data
->vl_peer
.s_addr
== vl_peer
.s_addr
&&
813 IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
820 ospf_vl_shutdown (struct ospf_vl_data
*vl_data
)
822 struct ospf_interface
*oi
;
824 if ((oi
= vl_data
->vl_oi
) == NULL
)
827 oi
->address
->u
.prefix4
.s_addr
= 0;
828 oi
->address
->prefixlen
= 0;
830 UNSET_FLAG (oi
->ifp
->flags
, IFF_UP
);
831 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
832 OSPF_ISM_EVENT_EXECUTE (oi
, ISM_InterfaceDown
);
836 ospf_vl_add (struct ospf
*ospf
, struct ospf_vl_data
*vl_data
)
838 listnode_add (ospf
->vlinks
, vl_data
);
840 ospf_snmp_vl_add (vl_data
);
841 #endif /* HAVE_SNMP */
845 ospf_vl_delete (struct ospf
*ospf
, struct ospf_vl_data
*vl_data
)
847 ospf_vl_shutdown (vl_data
);
848 ospf_vl_if_delete (vl_data
);
851 ospf_snmp_vl_delete (vl_data
);
852 #endif /* HAVE_SNMP */
853 listnode_delete (ospf
->vlinks
, vl_data
);
855 ospf_vl_data_free (vl_data
);
859 ospf_vl_set_params (struct ospf_vl_data
*vl_data
, struct vertex
*v
)
862 struct ospf_interface
*voi
;
864 struct vertex_nexthop
*nh
;
866 struct router_lsa
*rl
;
868 voi
= vl_data
->vl_oi
;
870 if (voi
->output_cost
!= v
->distance
)
872 voi
->output_cost
= v
->distance
;
876 for (node
= listhead (v
->nexthop
); node
; nextnode (node
))
877 if ((nh
= getdata (node
)) != NULL
)
879 vl_data
->out_oi
= (struct ospf_interface
*) nh
->oi
;
881 voi
->address
->u
.prefix4
= vl_data
->out_oi
->address
->u
.prefix4
;
882 voi
->address
->prefixlen
= vl_data
->out_oi
->address
->prefixlen
;
884 break; /* We take the first interface. */
887 rl
= (struct router_lsa
*)v
->lsa
;
889 for (i
= 0; i
< ntohs (rl
->links
); i
++)
891 switch (rl
->link
[i
].type
)
893 case LSA_LINK_TYPE_VIRTUALLINK
:
894 if (IS_DEBUG_OSPF_EVENT
)
895 zlog_info ("found back link through VL");
896 case LSA_LINK_TYPE_TRANSIT
:
897 case LSA_LINK_TYPE_POINTOPOINT
:
898 vl_data
->peer_addr
= rl
->link
[i
].link_data
;
899 if (IS_DEBUG_OSPF_EVENT
)
900 zlog_info ("%s peer address is %s\n",
901 vl_data
->vl_oi
->ifp
->name
, inet_ntoa(vl_data
->peer_addr
));
909 ospf_vl_up_check (struct ospf_area
*area
, struct in_addr rid
,
912 struct ospf
*ospf
= area
->ospf
;
914 struct ospf_vl_data
*vl_data
;
915 struct ospf_interface
*oi
;
917 if (IS_DEBUG_OSPF_EVENT
)
919 zlog_info ("ospf_vl_up_check(): Start");
920 zlog_info ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid
));
921 zlog_info ("ospf_vl_up_check(): Area is %s", inet_ntoa (area
->area_id
));
924 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
926 if ((vl_data
= getdata (node
)) == NULL
)
929 if (IS_DEBUG_OSPF_EVENT
)
931 zlog_info ("ospf_vl_up_check(): considering VL, name: %s",
932 vl_data
->vl_oi
->ifp
->name
);
933 zlog_info ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
934 inet_ntoa (vl_data
->vl_area_id
),
935 inet_ntoa (vl_data
->vl_peer
));
938 if (IPV4_ADDR_SAME (&vl_data
->vl_peer
, &rid
) &&
939 IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
942 SET_FLAG (vl_data
->flags
, OSPF_VL_FLAG_APPROVED
);
944 if (IS_DEBUG_OSPF_EVENT
)
945 zlog_info ("ospf_vl_up_check(): this VL matched");
947 if (oi
->state
== ISM_Down
)
949 if (IS_DEBUG_OSPF_EVENT
)
950 zlog_info ("ospf_vl_up_check(): VL is down, waking it up");
951 SET_FLAG (oi
->ifp
->flags
, IFF_UP
);
952 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_InterfaceUp
);
955 ospf_vl_set_params (vl_data
, v
);
961 ospf_vl_unapprove (struct ospf
*ospf
)
964 struct ospf_vl_data
*vl_data
;
966 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
967 if ((vl_data
= getdata (node
)) != NULL
)
968 UNSET_FLAG (vl_data
->flags
, OSPF_VL_FLAG_APPROVED
);
972 ospf_vl_shut_unapproved (struct ospf
*ospf
)
975 struct ospf_vl_data
*vl_data
;
977 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
978 if ((vl_data
= getdata (node
)) != NULL
)
979 if (!CHECK_FLAG (vl_data
->flags
, OSPF_VL_FLAG_APPROVED
))
980 ospf_vl_shutdown (vl_data
);
984 ospf_full_virtual_nbrs (struct ospf_area
*area
)
986 if (IS_DEBUG_OSPF_EVENT
)
988 zlog_info ("counting fully adjacent virtual neighbors in area %s",
989 inet_ntoa (area
->area_id
));
990 zlog_info ("there are %d of them", area
->full_vls
);
993 return area
->full_vls
;
997 ospf_vls_in_area (struct ospf_area
*area
)
1000 struct ospf_vl_data
*vl_data
;
1003 for (node
= listhead (area
->ospf
->vlinks
); node
; nextnode (node
))
1004 if ((vl_data
= getdata (node
)) != NULL
)
1005 if (IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
1013 ospf_crypt_key_new ()
1015 struct crypt_key
*ck
;
1017 ck
= XMALLOC (MTYPE_OSPF_CRYPT_KEY
, sizeof (struct crypt_key
));
1018 memset (ck
, 0, sizeof (struct crypt_key
));
1024 ospf_crypt_key_add (list crypt
, struct crypt_key
*ck
)
1026 listnode_add (crypt
, ck
);
1030 ospf_crypt_key_lookup (list auth_crypt
, u_char key_id
)
1033 struct crypt_key
*ck
;
1035 for (node
= listhead (auth_crypt
); node
; nextnode (node
))
1037 ck
= getdata (node
);
1038 if (ck
->key_id
== key_id
)
1046 ospf_crypt_key_delete (list auth_crypt
, u_char key_id
)
1049 struct crypt_key
*ck
;
1051 for (node
= listhead (auth_crypt
); node
; nextnode (node
))
1053 ck
= getdata (node
);
1054 if (ck
->key_id
== key_id
)
1056 listnode_delete (auth_crypt
, ck
);
1067 /* Initialize Zebra interface data structure. */
1069 if_add_hook (IF_NEW_HOOK
, ospf_if_new_hook
);
1070 if_add_hook (IF_DELETE_HOOK
, ospf_if_delete_hook
);