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 */
128 /* lookup oi for specified prefix/ifp */
129 struct ospf_interface
*
130 ospf_if_table_lookup (struct interface
*ifp
, struct prefix
*prefix
)
133 struct route_node
*rn
;
134 struct ospf_interface
*rninfo
;
138 rn
= route_node_get (IF_OIFS (ifp
), &p
);
139 /* route_node_get implicitely locks */
140 rninfo
= (struct ospf_interface
*) rn
->info
;
141 route_unlock_node (rn
);
146 ospf_add_to_if (struct interface
*ifp
, struct ospf_interface
*oi
)
148 struct route_node
*rn
;
152 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
154 rn
= route_node_get (IF_OIFS (ifp
), &p
);
155 /* rn->info should either be NULL or equal to this oi
156 * as route_node_get may return an existing node
158 assert (!rn
->info
|| rn
->info
== oi
);
163 ospf_delete_from_if (struct interface
*ifp
, struct ospf_interface
*oi
)
165 struct route_node
*rn
;
169 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
171 rn
= route_node_lookup (IF_OIFS (oi
->ifp
), &p
);
175 route_unlock_node (rn
);
176 route_unlock_node (rn
);
179 struct ospf_interface
*
180 ospf_if_new (struct ospf
*ospf
, struct interface
*ifp
, struct prefix
*p
)
182 struct ospf_interface
*oi
;
184 if ((oi
= ospf_if_table_lookup (ifp
, p
)) == NULL
)
186 oi
= XCALLOC (MTYPE_OSPF_IF
, sizeof (struct ospf_interface
));
187 memset (oi
, 0, sizeof (struct ospf_interface
));
192 /* Set zebra interface pointer. */
196 ospf_add_to_if (ifp
, oi
);
197 listnode_add (ospf
->oiflist
, oi
);
199 /* Clear self-originated network-LSA. */
200 oi
->network_lsa_self
= NULL
;
202 /* Initialize neighbor list. */
203 oi
->nbrs
= route_table_init ();
205 /* Initialize static neighbor list. */
206 oi
->nbr_nbma
= list_new ();
208 /* Initialize Link State Acknowledgment list. */
209 oi
->ls_ack
= list_new ();
210 oi
->ls_ack_direct
.ls_ack
= list_new ();
212 /* Set default values. */
213 ospf_if_reset_variables (oi
);
215 /* Add pseudo neighbor. */
216 oi
->nbr_self
= ospf_nbr_new (oi
);
217 oi
->nbr_self
->state
= NSM_TwoWay
;
218 oi
->nbr_self
->priority
= OSPF_IF_PARAM (oi
, priority
);
219 oi
->nbr_self
->options
= OSPF_OPTION_E
;
221 oi
->ls_upd_queue
= route_table_init ();
222 oi
->t_ls_upd_event
= NULL
;
223 oi
->t_ls_ack_direct
= NULL
;
225 oi
->crypt_seqnum
= time (NULL
);
227 #ifdef HAVE_OPAQUE_LSA
228 ospf_opaque_type9_lsa_init (oi
);
229 #endif /* HAVE_OPAQUE_LSA */
236 /* Restore an interface to its pre UP state
237 Used from ism_interface_down only */
239 ospf_if_cleanup (struct ospf_interface
*oi
)
241 struct route_node
*rn
;
242 struct listnode
*node
;
243 struct ospf_neighbor
*nbr
;
245 /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */
246 /* delete all static neighbors attached to this interface */
247 for (node
= listhead (oi
->nbr_nbma
); node
; )
249 struct ospf_nbr_nbma
*nbr_nbma
= getdata (node
);
252 OSPF_POLL_TIMER_OFF (nbr_nbma
->t_poll
);
256 nbr_nbma
->nbr
->nbr_nbma
= NULL
;
257 nbr_nbma
->nbr
= NULL
;
262 listnode_delete (oi
->nbr_nbma
, nbr_nbma
);
265 /* send Neighbor event KillNbr to all associated neighbors. */
266 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
267 if ((nbr
= rn
->info
) != NULL
)
268 if (nbr
!= oi
->nbr_self
)
269 OSPF_NSM_EVENT_EXECUTE (nbr
, NSM_KillNbr
);
271 /* Cleanup Link State Acknowlegdment list. */
272 for (node
= listhead (oi
->ls_ack
); node
; nextnode (node
))
273 ospf_lsa_unlock (node
->data
);
274 list_delete_all_node (oi
->ls_ack
);
276 oi
->crypt_seqnum
= 0;
278 /* Empty link state update queue */
279 ospf_ls_upd_queue_empty (oi
);
281 /* Handle pseudo neighbor. */
282 ospf_nbr_delete (oi
->nbr_self
);
283 oi
->nbr_self
= ospf_nbr_new (oi
);
284 oi
->nbr_self
->state
= NSM_TwoWay
;
285 oi
->nbr_self
->priority
= OSPF_IF_PARAM (oi
, priority
);
287 switch (oi
->area
->external_routing
)
289 case OSPF_AREA_DEFAULT
:
290 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
293 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
296 UNSET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_E
);
297 SET_FLAG (oi
->nbr_self
->options
, OSPF_OPTION_NP
);
301 ospf_lsa_unlock (oi
->network_lsa_self
);
302 oi
->network_lsa_self
= NULL
;
303 OSPF_TIMER_OFF (oi
->t_network_lsa_self
);
307 ospf_if_free (struct ospf_interface
*oi
)
311 assert (oi
->state
== ISM_Down
);
313 #ifdef HAVE_OPAQUE_LSA
314 ospf_opaque_type9_lsa_term (oi
);
315 #endif /* HAVE_OPAQUE_LSA */
317 /* Free Pseudo Neighbour */
318 ospf_nbr_delete (oi
->nbr_self
);
320 route_table_finish (oi
->nbrs
);
321 route_table_finish (oi
->ls_upd_queue
);
323 /* Free any lists that should be freed */
324 list_free (oi
->nbr_nbma
);
326 list_free (oi
->ls_ack
);
327 list_free (oi
->ls_ack_direct
.ls_ack
);
329 ospf_delete_from_if (oi
->ifp
, oi
);
331 listnode_delete (oi
->ospf
->oiflist
, oi
);
332 listnode_delete (oi
->area
->oiflist
, oi
);
334 memset (oi
, 0, sizeof (*oi
));
335 XFREE (MTYPE_OSPF_IF
, oi
);
340 * check if interface with given address is configured and
341 * return it if yes. special treatment for PtP networks.
343 struct ospf_interface
*
344 ospf_if_is_configured (struct ospf
*ospf
, struct in_addr
*address
)
346 struct listnode
*node
;
347 struct ospf_interface
*oi
;
348 struct prefix_ipv4 addr
;
350 addr
.family
= AF_INET
;
351 addr
.prefix
= *address
;
352 addr
.prefixlen
= IPV4_MAX_PREFIXLEN
;
354 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
355 if ((oi
= getdata (node
)) != NULL
&& oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
357 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
359 if (CONNECTED_DEST_HOST(oi
->connected
))
361 /* match only destination addr, since local addr is most likely
362 * not unique (borrowed from another interface) */
363 if (IPV4_ADDR_SAME (address
,
364 &oi
->connected
->destination
->u
.prefix4
))
369 /* special leniency: match if addr is anywhere on PtP subnet */
370 if (prefix_match(oi
->address
,(struct prefix
*)&addr
))
376 if (IPV4_ADDR_SAME (address
, &oi
->address
->u
.prefix4
))
384 ospf_if_is_up (struct ospf_interface
*oi
)
386 return if_is_up (oi
->ifp
);
389 struct ospf_interface
*
390 ospf_if_exists (struct ospf_interface
*oic
)
392 struct listnode
*node
;
394 struct ospf_interface
*oi
;
396 ospf
= ospf_lookup ();
398 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
400 if (((oi
= getdata (node
)) != NULL
) && (oi
== oic
))
406 struct ospf_interface
*
407 ospf_if_lookup_by_local_addr (struct ospf
*ospf
,
408 struct interface
*ifp
, struct in_addr address
)
410 struct listnode
*node
;
411 struct ospf_interface
*oi
;
413 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
414 if ((oi
= getdata (node
)) != NULL
&& oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
416 if (ifp
&& oi
->ifp
!= ifp
)
419 if (IPV4_ADDR_SAME (&address
, &oi
->address
->u
.prefix4
))
426 struct ospf_interface
*
427 ospf_if_lookup_by_prefix (struct ospf
*ospf
, struct prefix_ipv4
*p
)
429 struct listnode
*node
;
430 struct ospf_interface
*oi
;
433 /* Check each Interface. */
434 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
436 if ((oi
= getdata (node
)) != NULL
&& oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
438 if ((oi
->type
== OSPF_IFTYPE_POINTOPOINT
) &&
439 CONNECTED_DEST_HOST(oi
->connected
))
441 prefix_copy (&ptmp
, oi
->connected
->destination
);
442 ptmp
.prefixlen
= IPV4_MAX_BITLEN
;
445 prefix_copy (&ptmp
, oi
->address
);
448 if (prefix_same (&ptmp
, (struct prefix
*) p
))
455 /* determine receiving interface by source of packet */
456 struct ospf_interface
*
457 ospf_if_lookup_recv_if (struct ospf
*ospf
, struct in_addr src
)
459 struct listnode
*node
;
460 struct prefix_ipv4 addr
;
461 struct ospf_interface
*oi
, *match
;
463 addr
.family
= AF_INET
;
465 addr
.prefixlen
= IPV4_MAX_BITLEN
;
469 for (node
= listhead (ospf
->oiflist
); node
; nextnode (node
))
473 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
476 if ((oi
->type
== OSPF_IFTYPE_POINTOPOINT
) &&
477 CONNECTED_DEST_HOST(oi
->connected
))
479 if (IPV4_ADDR_SAME (&oi
->connected
->destination
->u
.prefix4
, &src
))
484 if (prefix_match (oi
->address
, (struct prefix
*) &addr
))
486 if ( (match
== NULL
) ||
487 (match
->address
->prefixlen
< oi
->address
->prefixlen
)
498 ospf_if_stream_set (struct ospf_interface
*oi
)
500 /* set output fifo queue. */
501 if (oi
->obuf
== NULL
)
502 oi
->obuf
= ospf_fifo_new ();
506 ospf_if_stream_unset (struct ospf_interface
*oi
)
508 struct ospf
*ospf
= oi
->ospf
;
512 ospf_fifo_free (oi
->obuf
);
517 listnode_delete (ospf
->oi_write_q
, oi
);
518 if (list_isempty(ospf
->oi_write_q
))
519 OSPF_TIMER_OFF (ospf
->t_write
);
526 struct ospf_if_params
*
527 ospf_new_if_params ()
529 struct ospf_if_params
*oip
;
531 oip
= XMALLOC (MTYPE_OSPF_IF_PARAMS
, sizeof (struct ospf_if_params
));
536 memset (oip
, 0, sizeof (struct ospf_if_params
));
538 UNSET_IF_PARAM (oip
, output_cost_cmd
);
539 UNSET_IF_PARAM (oip
, transmit_delay
);
540 UNSET_IF_PARAM (oip
, retransmit_interval
);
541 UNSET_IF_PARAM (oip
, passive_interface
);
542 UNSET_IF_PARAM (oip
, v_hello
);
543 UNSET_IF_PARAM (oip
, v_wait
);
544 UNSET_IF_PARAM (oip
, priority
);
545 UNSET_IF_PARAM (oip
, type
);
546 UNSET_IF_PARAM (oip
, auth_simple
);
547 UNSET_IF_PARAM (oip
, auth_crypt
);
548 UNSET_IF_PARAM (oip
, auth_type
);
550 oip
->auth_crypt
= list_new ();
556 ospf_del_if_params (struct ospf_if_params
*oip
)
558 list_delete (oip
->auth_crypt
);
559 XFREE (MTYPE_OSPF_IF_PARAMS
, oip
);
563 ospf_free_if_params (struct interface
*ifp
, struct in_addr addr
)
565 struct ospf_if_params
*oip
;
566 struct prefix_ipv4 p
;
567 struct route_node
*rn
;
570 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
572 rn
= route_node_lookup (IF_OIFS_PARAMS (ifp
), (struct prefix
*)&p
);
573 if (!rn
|| !rn
->info
)
577 route_unlock_node (rn
);
579 if (!OSPF_IF_PARAM_CONFIGURED (oip
, output_cost_cmd
) &&
580 !OSPF_IF_PARAM_CONFIGURED (oip
, transmit_delay
) &&
581 !OSPF_IF_PARAM_CONFIGURED (oip
, retransmit_interval
) &&
582 !OSPF_IF_PARAM_CONFIGURED (oip
, passive_interface
) &&
583 !OSPF_IF_PARAM_CONFIGURED (oip
, v_hello
) &&
584 !OSPF_IF_PARAM_CONFIGURED (oip
, v_wait
) &&
585 !OSPF_IF_PARAM_CONFIGURED (oip
, priority
) &&
586 !OSPF_IF_PARAM_CONFIGURED (oip
, type
) &&
587 !OSPF_IF_PARAM_CONFIGURED (oip
, auth_simple
) &&
588 !OSPF_IF_PARAM_CONFIGURED (oip
, auth_type
) &&
589 listcount (oip
->auth_crypt
) == 0)
591 ospf_del_if_params (oip
);
593 route_unlock_node (rn
);
597 struct ospf_if_params
*
598 ospf_lookup_if_params (struct interface
*ifp
, struct in_addr addr
)
600 struct prefix_ipv4 p
;
601 struct route_node
*rn
;
604 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
607 rn
= route_node_lookup (IF_OIFS_PARAMS (ifp
), (struct prefix
*)&p
);
611 route_unlock_node (rn
);
618 struct ospf_if_params
*
619 ospf_get_if_params (struct interface
*ifp
, struct in_addr addr
)
621 struct prefix_ipv4 p
;
622 struct route_node
*rn
;
625 p
.prefixlen
= IPV4_MAX_PREFIXLEN
;
628 rn
= route_node_get (IF_OIFS_PARAMS (ifp
), (struct prefix
*)&p
);
630 if (rn
->info
== NULL
)
631 rn
->info
= ospf_new_if_params ();
633 route_unlock_node (rn
);
639 ospf_if_update_params (struct interface
*ifp
, struct in_addr addr
)
641 struct route_node
*rn
;
642 struct ospf_interface
*oi
;
644 for (rn
= route_top (IF_OIFS (ifp
)); rn
; rn
= route_next (rn
))
646 if ((oi
= rn
->info
) == NULL
)
649 if (IPV4_ADDR_SAME (&oi
->address
->u
.prefix4
, &addr
))
650 oi
->params
= ospf_lookup_if_params (ifp
, oi
->address
->u
.prefix4
);
655 ospf_if_new_hook (struct interface
*ifp
)
659 ifp
->info
= XMALLOC (MTYPE_OSPF_IF_INFO
, sizeof (struct ospf_if_info
));
660 memset (ifp
->info
, 0, sizeof (struct ospf_if_info
));
662 IF_OIFS (ifp
) = route_table_init ();
663 IF_OIFS_PARAMS (ifp
) = route_table_init ();
665 IF_DEF_PARAMS (ifp
) = ospf_new_if_params ();
667 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), transmit_delay
);
668 IF_DEF_PARAMS (ifp
)->transmit_delay
= OSPF_TRANSMIT_DELAY_DEFAULT
;
670 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), retransmit_interval
);
671 IF_DEF_PARAMS (ifp
)->retransmit_interval
= OSPF_RETRANSMIT_INTERVAL_DEFAULT
;
673 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), priority
);
674 IF_DEF_PARAMS (ifp
)->priority
= OSPF_ROUTER_PRIORITY_DEFAULT
;
676 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), passive_interface
);
677 IF_DEF_PARAMS (ifp
)->passive_interface
= OSPF_IF_ACTIVE
;
679 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), v_hello
);
680 IF_DEF_PARAMS (ifp
)->v_hello
= OSPF_HELLO_INTERVAL_DEFAULT
;
682 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), v_wait
);
683 IF_DEF_PARAMS (ifp
)->v_wait
= OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
;
685 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), auth_simple
);
686 memset (IF_DEF_PARAMS (ifp
)->auth_simple
, 0, OSPF_AUTH_SIMPLE_SIZE
);
688 SET_IF_PARAM (IF_DEF_PARAMS (ifp
), auth_type
);
689 IF_DEF_PARAMS (ifp
)->auth_type
= OSPF_AUTH_NOTSET
;
691 #ifdef HAVE_OPAQUE_LSA
692 rc
= ospf_opaque_new_if (ifp
);
693 #endif /* HAVE_OPAQUE_LSA */
698 ospf_if_delete_hook (struct interface
*ifp
)
701 struct route_node
*rn
;
702 #ifdef HAVE_OPAQUE_LSA
703 rc
= ospf_opaque_del_if (ifp
);
704 #endif /* HAVE_OPAQUE_LSA */
706 route_table_finish (IF_OIFS (ifp
));
708 for (rn
= route_top (IF_OIFS_PARAMS (ifp
)); rn
; rn
= route_next (rn
))
710 ospf_del_if_params (rn
->info
);
711 route_table_finish (IF_OIFS_PARAMS (ifp
));
713 ospf_del_if_params ((struct ospf_if_params
*) IF_DEF_PARAMS (ifp
));
714 XFREE (MTYPE_OSPF_IF_INFO
, ifp
->info
);
721 ospf_if_is_enable (struct ospf_interface
*oi
)
723 if (!if_is_loopback (oi
->ifp
))
724 if (if_is_up (oi
->ifp
))
731 ospf_if_up (struct ospf_interface
*oi
)
736 if (oi
->type
== OSPF_IFTYPE_LOOPBACK
)
737 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_LoopInd
);
740 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
741 ospf_if_add_allspfrouters (oi
->ospf
, oi
->address
, oi
->ifp
->ifindex
);
742 ospf_if_stream_set (oi
);
743 OSPF_ISM_EVENT_SCHEDULE (oi
, ISM_InterfaceUp
);
750 ospf_if_down (struct ospf_interface
*oi
)
755 OSPF_ISM_EVENT_EXECUTE (oi
, ISM_InterfaceDown
);
756 /* Shutdown packet reception and sending */
757 ospf_if_stream_unset (oi
);
758 if (oi
->type
!= OSPF_IFTYPE_VIRTUALLINK
)
759 ospf_if_drop_allspfrouters (oi
->ospf
, oi
->address
, oi
->ifp
->ifindex
);
766 /* Virtual Link related functions. */
768 struct ospf_vl_data
*
769 ospf_vl_data_new (struct ospf_area
*area
, struct in_addr vl_peer
)
771 struct ospf_vl_data
*vl_data
;
773 vl_data
= XMALLOC (MTYPE_OSPF_VL_DATA
, sizeof (struct ospf_vl_data
));
774 memset (vl_data
, 0, sizeof (struct ospf_vl_data
));
776 vl_data
->vl_peer
.s_addr
= vl_peer
.s_addr
;
777 vl_data
->vl_area_id
= area
->area_id
;
778 vl_data
->format
= area
->format
;
784 ospf_vl_data_free (struct ospf_vl_data
*vl_data
)
786 XFREE (MTYPE_OSPF_VL_DATA
, vl_data
);
789 u_int vlink_count
= 0;
791 struct ospf_interface
*
792 ospf_vl_new (struct ospf
*ospf
, struct ospf_vl_data
*vl_data
)
794 struct ospf_interface
* voi
;
795 struct interface
* vi
;
796 char ifname
[INTERFACE_NAMSIZ
+ 1];
797 struct ospf_area
*area
;
798 struct in_addr area_id
;
799 struct connected
*co
;
800 struct prefix_ipv4
*p
;
802 if (IS_DEBUG_OSPF_EVENT
)
803 zlog_debug ("ospf_vl_new(): Start");
804 if (vlink_count
== OSPF_VL_MAX_COUNT
)
806 if (IS_DEBUG_OSPF_EVENT
)
807 zlog_debug ("ospf_vl_new(): Alarm: "
808 "cannot create more than OSPF_MAX_VL_COUNT virtual links");
812 if (IS_DEBUG_OSPF_EVENT
)
813 zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
815 snprintf (ifname
, INTERFACE_NAMSIZ
+ 1, "VLINK%d", vlink_count
);
816 vi
= if_create (ifname
, INTERFACE_NAMSIZ
);
817 co
= connected_new ();
819 listnode_add (vi
->connected
, co
);
821 p
= prefix_ipv4_new ();
823 p
->prefix
.s_addr
= 0;
826 co
->address
= (struct prefix
*)p
;
828 voi
= ospf_if_new (ospf
, vi
, co
->address
);
831 if (IS_DEBUG_OSPF_EVENT
)
832 zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
836 voi
->vl_data
= vl_data
;
837 voi
->ifp
->mtu
= OSPF_VL_MTU
;
838 voi
->type
= OSPF_IFTYPE_VIRTUALLINK
;
841 if (IS_DEBUG_OSPF_EVENT
)
842 zlog_debug ("ospf_vl_new(): Created name: %s", ifname
);
843 if (IS_DEBUG_OSPF_EVENT
)
844 zlog_debug ("ospf_vl_new(): set if->name to %s", vi
->name
);
847 area
= ospf_area_get (ospf
, area_id
, OSPF_AREA_ID_FORMAT_ADDRESS
);
850 if (IS_DEBUG_OSPF_EVENT
)
851 zlog_debug ("ospf_vl_new(): set associated area to the backbone");
853 ospf_area_add_if (voi
->area
, voi
);
855 ospf_if_stream_set (voi
);
857 if (IS_DEBUG_OSPF_EVENT
)
858 zlog_debug ("ospf_vl_new(): Stop");
863 ospf_vl_if_delete (struct ospf_vl_data
*vl_data
)
865 struct interface
*ifp
= vl_data
->vl_oi
->ifp
;
866 vl_data
->vl_oi
->address
->u
.prefix4
.s_addr
= 0;
867 vl_data
->vl_oi
->address
->prefixlen
= 0;
868 ospf_if_free (vl_data
->vl_oi
);
873 struct ospf_vl_data
*
874 ospf_vl_lookup (struct ospf_area
*area
, struct in_addr vl_peer
)
876 struct ospf_vl_data
*vl_data
;
877 struct listnode
*node
;
879 for (node
= listhead (area
->ospf
->vlinks
); node
; nextnode (node
))
880 if ((vl_data
= getdata (node
)) != NULL
)
881 if (vl_data
->vl_peer
.s_addr
== vl_peer
.s_addr
&&
882 IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
889 ospf_vl_shutdown (struct ospf_vl_data
*vl_data
)
891 struct ospf_interface
*oi
;
893 if ((oi
= vl_data
->vl_oi
) == NULL
)
896 oi
->address
->u
.prefix4
.s_addr
= 0;
897 oi
->address
->prefixlen
= 0;
899 UNSET_FLAG (oi
->ifp
->flags
, IFF_UP
);
900 /* OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceDown); */
901 OSPF_ISM_EVENT_EXECUTE (oi
, ISM_InterfaceDown
);
905 ospf_vl_add (struct ospf
*ospf
, struct ospf_vl_data
*vl_data
)
907 listnode_add (ospf
->vlinks
, vl_data
);
909 ospf_snmp_vl_add (vl_data
);
910 #endif /* HAVE_SNMP */
914 ospf_vl_delete (struct ospf
*ospf
, struct ospf_vl_data
*vl_data
)
916 ospf_vl_shutdown (vl_data
);
917 ospf_vl_if_delete (vl_data
);
920 ospf_snmp_vl_delete (vl_data
);
921 #endif /* HAVE_SNMP */
922 listnode_delete (ospf
->vlinks
, vl_data
);
924 ospf_vl_data_free (vl_data
);
928 ospf_vl_set_params (struct ospf_vl_data
*vl_data
, struct vertex
*v
)
931 struct ospf_interface
*voi
;
932 struct listnode
*node
;
933 struct vertex_nexthop
*nh
;
935 struct router_lsa
*rl
;
937 voi
= vl_data
->vl_oi
;
939 if (voi
->output_cost
!= v
->distance
)
942 voi
->output_cost
= v
->distance
;
946 for (node
= listhead (v
->nexthop
); node
; nextnode (node
))
947 if ((nh
= getdata (node
)) != NULL
)
949 vl_data
->out_oi
= (struct ospf_interface
*) nh
->oi
;
951 if (!IPV4_ADDR_SAME(&voi
->address
->u
.prefix4
,
952 &vl_data
->out_oi
->address
->u
.prefix4
))
955 voi
->address
->u
.prefix4
= vl_data
->out_oi
->address
->u
.prefix4
;
956 voi
->address
->prefixlen
= vl_data
->out_oi
->address
->prefixlen
;
958 break; /* We take the first interface. */
961 rl
= (struct router_lsa
*)v
->lsa
;
963 /* use SPF determined backlink index in struct vertex
964 * for virtual link destination address
966 if (v
->backlink
>= 0)
968 if (!IPV4_ADDR_SAME (&vl_data
->peer_addr
,
969 &rl
->link
[v
->backlink
].link_data
))
971 vl_data
->peer_addr
= rl
->link
[v
->backlink
].link_data
;
975 /* This is highly odd, there is no backlink index
976 * there should be due to the ospf_spf_has_link() check
977 * in SPF. Lets warn and try pick a link anyway.
979 zlog_warn ("ospf_vl_set_params: No backlink for %s!",
980 vl_data
->vl_oi
->ifp
->name
);
981 for (i
= 0; i
< ntohs (rl
->links
); i
++)
983 switch (rl
->link
[i
].type
)
985 case LSA_LINK_TYPE_VIRTUALLINK
:
986 if (IS_DEBUG_OSPF_EVENT
)
987 zlog_debug ("found back link through VL");
988 case LSA_LINK_TYPE_TRANSIT
:
989 case LSA_LINK_TYPE_POINTOPOINT
:
990 if (!IPV4_ADDR_SAME (&vl_data
->peer_addr
,
991 &rl
->link
[i
].link_data
))
993 vl_data
->peer_addr
= rl
->link
[i
].link_data
;
994 if (IS_DEBUG_OSPF_EVENT
)
995 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
996 vl_data
->vl_oi
->ifp
->name
,
997 inet_ntoa(vl_data
->peer_addr
));
1003 if (IS_DEBUG_OSPF_EVENT
)
1004 zlog_debug ("ospf_vl_set_params: %s peer address is %s\n",
1005 vl_data
->vl_oi
->ifp
->name
,
1006 inet_ntoa(vl_data
->peer_addr
));
1013 ospf_vl_up_check (struct ospf_area
*area
, struct in_addr rid
,
1016 struct ospf
*ospf
= area
->ospf
;
1017 struct listnode
*node
;
1018 struct ospf_vl_data
*vl_data
;
1019 struct ospf_interface
*oi
;
1021 if (IS_DEBUG_OSPF_EVENT
)
1023 zlog_debug ("ospf_vl_up_check(): Start");
1024 zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid
));
1025 zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area
->area_id
));
1028 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
1030 if ((vl_data
= getdata (node
)) == NULL
)
1033 if (IS_DEBUG_OSPF_EVENT
)
1035 zlog_debug ("ospf_vl_up_check(): considering VL, name: %s",
1036 vl_data
->vl_oi
->ifp
->name
);
1037 zlog_debug ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
1038 inet_ntoa (vl_data
->vl_area_id
),
1039 inet_ntoa (vl_data
->vl_peer
));
1042 if (IPV4_ADDR_SAME (&vl_data
->vl_peer
, &rid
) &&
1043 IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
1045 oi
= vl_data
->vl_oi
;
1046 SET_FLAG (vl_data
->flags
, OSPF_VL_FLAG_APPROVED
);
1048 if (IS_DEBUG_OSPF_EVENT
)
1049 zlog_debug ("ospf_vl_up_check(): this VL matched");
1051 if (oi
->state
== ISM_Down
)
1053 if (IS_DEBUG_OSPF_EVENT
)
1054 zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
1055 SET_FLAG (oi
->ifp
->flags
, IFF_UP
);
1056 OSPF_ISM_EVENT_EXECUTE(oi
,ISM_InterfaceUp
);
1059 if (ospf_vl_set_params (vl_data
, v
))
1061 if (IS_DEBUG_OSPF (ism
, ISM_EVENTS
))
1062 zlog_debug ("ospf_vl_up_check: VL cost change,"
1063 " scheduling router lsa refresh");
1065 ospf_router_lsa_timer_add (ospf
->backbone
);
1066 else if (IS_DEBUG_OSPF (ism
, ISM_EVENTS
))
1067 zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
1074 ospf_vl_unapprove (struct ospf
*ospf
)
1076 struct listnode
*node
;
1077 struct ospf_vl_data
*vl_data
;
1079 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
1080 if ((vl_data
= getdata (node
)) != NULL
)
1081 UNSET_FLAG (vl_data
->flags
, OSPF_VL_FLAG_APPROVED
);
1085 ospf_vl_shut_unapproved (struct ospf
*ospf
)
1087 struct listnode
*node
;
1088 struct ospf_vl_data
*vl_data
;
1090 for (node
= listhead (ospf
->vlinks
); node
; nextnode (node
))
1091 if ((vl_data
= getdata (node
)) != NULL
)
1092 if (!CHECK_FLAG (vl_data
->flags
, OSPF_VL_FLAG_APPROVED
))
1093 ospf_vl_shutdown (vl_data
);
1097 ospf_full_virtual_nbrs (struct ospf_area
*area
)
1099 if (IS_DEBUG_OSPF_EVENT
)
1101 zlog_debug ("counting fully adjacent virtual neighbors in area %s",
1102 inet_ntoa (area
->area_id
));
1103 zlog_debug ("there are %d of them", area
->full_vls
);
1106 return area
->full_vls
;
1110 ospf_vls_in_area (struct ospf_area
*area
)
1112 struct listnode
*node
;
1113 struct ospf_vl_data
*vl_data
;
1116 for (node
= listhead (area
->ospf
->vlinks
); node
; nextnode (node
))
1117 if ((vl_data
= getdata (node
)) != NULL
)
1118 if (IPV4_ADDR_SAME (&vl_data
->vl_area_id
, &area
->area_id
))
1126 ospf_crypt_key_new ()
1128 struct crypt_key
*ck
;
1130 ck
= XMALLOC (MTYPE_OSPF_CRYPT_KEY
, sizeof (struct crypt_key
));
1131 memset (ck
, 0, sizeof (struct crypt_key
));
1137 ospf_crypt_key_add (struct list
*crypt
, struct crypt_key
*ck
)
1139 listnode_add (crypt
, ck
);
1143 ospf_crypt_key_lookup (struct list
*auth_crypt
, u_char key_id
)
1145 struct listnode
*node
;
1146 struct crypt_key
*ck
;
1148 for (node
= listhead (auth_crypt
); node
; nextnode (node
))
1150 ck
= getdata (node
);
1151 if (ck
->key_id
== key_id
)
1159 ospf_crypt_key_delete (struct list
*auth_crypt
, u_char key_id
)
1161 struct listnode
*node
;
1162 struct crypt_key
*ck
;
1164 for (node
= listhead (auth_crypt
); node
; nextnode (node
))
1166 ck
= getdata (node
);
1167 if (ck
->key_id
== key_id
)
1169 listnode_delete (auth_crypt
, ck
);
1180 /* Initialize Zebra interface data structure. */
1182 om
->iflist
= iflist
;
1183 if_add_hook (IF_NEW_HOOK
, ospf_if_new_hook
);
1184 if_add_hook (IF_DELETE_HOOK
, ospf_if_delete_hook
);