#include "command.h"
#include "stream.h"
#include "log.h"
+#include "zclient.h"
+#include "bfd.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_spf.h"
#include "ospfd/ospf_snmp.h"
#endif /* HAVE_SNMP */
-\f
+
int
ospf_if_get_output_cost (struct ospf_interface *oi)
{
if (oi->output_cost != newcost)
{
oi->output_cost = newcost;
- ospf_router_lsa_timer_add (oi->area);
+ ospf_router_lsa_update_area (oi->area);
}
}
}
+/* Simulate down/up on the interface. This is needed, for example, when
+ the MTU changes. */
+void
+ospf_if_reset(struct interface *ifp)
+{
+ struct route_node *rn;
+
+ for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
+ {
+ struct ospf_interface *oi;
+
+ if ( (oi = rn->info) == NULL)
+ continue;
+
+ ospf_if_down(oi);
+ ospf_if_up(oi);
+ }
+}
+
void
ospf_if_reset_variables (struct ospf_interface *oi)
{
ospf_if_table_lookup (struct interface *ifp, struct prefix *prefix)
{
struct prefix p;
- struct route_node rn;
+ struct route_node *rn;
+ struct ospf_interface *rninfo = NULL;
p = *prefix;
-
- rn = route_node_get (IF_OIFS (ifp), &p));
+ p.prefixlen = IPV4_MAX_PREFIXLEN;
+
/* route_node_get implicitely locks */
- route_node_unlock (rn);
- return (struct ospf_interface *) rn->info;
+ if ((rn = route_node_lookup (IF_OIFS (ifp), &p)))
+ {
+ rninfo = (struct ospf_interface *) rn->info;
+ route_unlock_node (rn);
+ }
+
+ return rninfo;
}
-void
+static void
ospf_add_to_if (struct interface *ifp, struct ospf_interface *oi)
{
struct route_node *rn;
rn->info = oi;
}
-void
+static void
ospf_delete_from_if (struct interface *ifp, struct ospf_interface *oi)
{
struct route_node *rn;
ospf_add_to_if (ifp, oi);
listnode_add (ospf->oiflist, oi);
- /* Clear self-originated network-LSA. */
- oi->network_lsa_self = NULL;
-
/* Initialize neighbor list. */
oi->nbrs = route_table_init ();
/* Add pseudo neighbor. */
oi->nbr_self = ospf_nbr_new (oi);
- oi->nbr_self->state = NSM_TwoWay;
- oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
- oi->nbr_self->options = OSPF_OPTION_E;
oi->ls_upd_queue = route_table_init ();
oi->t_ls_upd_event = NULL;
ospf_if_cleanup (struct ospf_interface *oi)
{
struct route_node *rn;
- listnode node;
+ struct listnode *node, *nnode;
struct ospf_neighbor *nbr;
+ struct ospf_nbr_nbma *nbr_nbma;
+ struct ospf_lsa *lsa;
- /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */
+ /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */
/* delete all static neighbors attached to this interface */
- for (node = listhead (oi->nbr_nbma); node; )
+ for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma))
{
- struct ospf_nbr_nbma *nbr_nbma = getdata (node);
- nextnode (node);
-
OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
if (nbr_nbma->nbr)
OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
/* Cleanup Link State Acknowlegdment list. */
- for (node = listhead (oi->ls_ack); node; nextnode (node))
- ospf_lsa_unlock (node->data);
+ for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
+ ospf_lsa_unlock (&lsa); /* oi->ls_ack */
list_delete_all_node (oi->ls_ack);
oi->crypt_seqnum = 0;
/* Empty link state update queue */
ospf_ls_upd_queue_empty (oi);
- /* Handle pseudo neighbor. */
+ /* Reset pseudo neighbor. */
ospf_nbr_delete (oi->nbr_self);
oi->nbr_self = ospf_nbr_new (oi);
- oi->nbr_self->state = NSM_TwoWay;
- oi->nbr_self->priority = OSPF_IF_PARAM (oi, priority);
-
- switch (oi->area->external_routing)
- {
- case OSPF_AREA_DEFAULT:
- SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
- break;
- case OSPF_AREA_STUB:
- UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
- break;
-#ifdef HAVE_NSSA
- case OSPF_AREA_NSSA:
- UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E);
- SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
- break;
-#endif /* HAVE_NSSA */
- }
-
- ospf_lsa_unlock (oi->network_lsa_self);
- oi->network_lsa_self = NULL;
- OSPF_TIMER_OFF (oi->t_network_lsa_self);
+ ospf_nbr_add_self (oi);
}
void
listnode_delete (oi->ospf->oiflist, oi);
listnode_delete (oi->area->oiflist, oi);
+ thread_cancel_event (master, oi);
+
memset (oi, 0, sizeof (*oi));
XFREE (MTYPE_OSPF_IF, oi);
}
-\f
+
/*
* check if interface with given address is configured and
-* return it if yes.
+* return it if yes. special treatment for PtP networks.
*/
struct ospf_interface *
ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
{
- listnode node;
+ struct listnode *node, *nnode;
struct ospf_interface *oi;
- struct prefix *addr;
-
- for (node = listhead (ospf->oiflist); node; nextnode (node))
- if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
+ struct prefix_ipv4 addr;
+
+ addr.family = AF_INET;
+ addr.prefix = *address;
+ addr.prefixlen = IPV4_MAX_PREFIXLEN;
+
+ for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
+ if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
{
- if (oi->type == OSPF_IFTYPE_POINTOPOINT)
- addr = oi->connected->destination;
- else
- addr = oi->address;
-
- if (IPV4_ADDR_SAME (address, &addr->u.prefix4))
- return oi;
+ if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
+ {
+ if (htonl(oi->ifp->ifindex) == address->s_addr)
+ return oi;
+ }
+ else if (oi->type == OSPF_IFTYPE_POINTOPOINT)
+ {
+ /* special leniency: match if addr is anywhere on peer subnet */
+ if (prefix_match(CONNECTED_PREFIX(oi->connected),
+ (struct prefix *)&addr))
+ return oi;
+ }
+ else
+ {
+ if (IPV4_ADDR_SAME (address, &oi->address->u.prefix4))
+ return oi;
+ }
}
-
return NULL;
}
return if_is_up (oi->ifp);
}
+struct ospf_interface *
+ospf_if_exists (struct ospf_interface *oic)
+{
+ struct listnode *node;
+ struct ospf *ospf;
+ struct ospf_interface *oi;
+
+ if ((ospf = ospf_lookup ()) == NULL)
+ return NULL;
+
+ for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
+ if (oi == oic)
+ return oi;
+
+ return NULL;
+}
+
+/* Lookup OSPF interface by router LSA posistion */
+struct ospf_interface *
+ospf_if_lookup_by_lsa_pos (struct ospf_area *area, int lsa_pos)
+{
+ struct listnode *node;
+ struct ospf_interface *oi;
+
+ for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
+ {
+ if (lsa_pos >= oi->lsa_pos_beg && lsa_pos < oi->lsa_pos_end)
+ return oi;
+ }
+ return NULL;
+}
+
struct ospf_interface *
ospf_if_lookup_by_local_addr (struct ospf *ospf,
struct interface *ifp, struct in_addr address)
{
- listnode node;
+ struct listnode *node;
struct ospf_interface *oi;
- for (node = listhead (ospf->oiflist); node; nextnode (node))
- if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
+ for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
+ if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
{
if (ifp && oi->ifp != ifp)
continue;
struct ospf_interface *
ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p)
{
- listnode node;
+ struct listnode *node;
struct ospf_interface *oi;
- struct prefix ptmp;
/* Check each Interface. */
- for (node = listhead (ospf->oiflist); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
{
- if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
+ if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
{
- if (oi->type == OSPF_IFTYPE_POINTOPOINT)
- {
- prefix_copy (&ptmp, oi->connected->destination);
- ptmp.prefixlen = IPV4_MAX_BITLEN;
- }
- else
- prefix_copy (&ptmp, oi->address);
-
+ struct prefix ptmp;
+
+ prefix_copy (&ptmp, CONNECTED_PREFIX(oi->connected));
apply_mask (&ptmp);
if (prefix_same (&ptmp, (struct prefix *) p))
return oi;
return NULL;
}
-/* determine receiving interface by source of packet */
+/* determine receiving interface by ifp and source address */
struct ospf_interface *
-ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src)
+ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src,
+ struct interface *ifp)
{
- listnode node;
+ struct route_node *rn;
struct prefix_ipv4 addr;
struct ospf_interface *oi, *match;
match = NULL;
- for (node = listhead (ospf->oiflist); node; nextnode (node))
+ for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
{
- oi = getdata (node);
-
+ oi = rn->info;
+
+ if (!oi) /* oi can be NULL for PtP aliases */
+ continue;
+
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
continue;
-
- if (oi->type == OSPF_IFTYPE_POINTOPOINT)
- {
- if (IPV4_ADDR_SAME (&oi->connected->destination->u.prefix4, &src))
- return oi;
- }
- else
+
+ if (if_is_loopback (oi->ifp))
+ continue;
+
+ if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
+ match = oi;
+ else if (prefix_match (CONNECTED_PREFIX(oi->connected),
+ (struct prefix *) &addr))
{
- if (prefix_match (oi->address, (struct prefix *) &addr))
- {
- if ( (match == NULL) ||
- (match->address->prefixlen < oi->address->prefixlen)
- )
- match = oi;
- }
+ if ( (match == NULL) ||
+ (match->address->prefixlen < oi->address->prefixlen)
+ )
+ match = oi;
}
}
return match;
}
-\f
+
void
ospf_if_stream_set (struct ospf_interface *oi)
{
}
}
-\f
-struct ospf_if_params *
-ospf_new_if_params ()
+
+static struct ospf_if_params *
+ospf_new_if_params (void)
{
struct ospf_if_params *oip;
- oip = XMALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
+ oip = XCALLOC (MTYPE_OSPF_IF_PARAMS, sizeof (struct ospf_if_params));
if (!oip)
return NULL;
- memset (oip, 0, sizeof (struct ospf_if_params));
-
UNSET_IF_PARAM (oip, output_cost_cmd);
UNSET_IF_PARAM (oip, transmit_delay);
UNSET_IF_PARAM (oip, retransmit_interval);
UNSET_IF_PARAM (oip, passive_interface);
UNSET_IF_PARAM (oip, v_hello);
+ UNSET_IF_PARAM (oip, fast_hello);
UNSET_IF_PARAM (oip, v_wait);
UNSET_IF_PARAM (oip, priority);
UNSET_IF_PARAM (oip, type);
oip->auth_crypt = list_new ();
+ oip->network_lsa_seqnum = htonl(OSPF_INITIAL_SEQUENCE_NUMBER);
+
return oip;
}
ospf_del_if_params (struct ospf_if_params *oip)
{
list_delete (oip->auth_crypt);
+ bfd_info_free(&(oip->bfd_info));
XFREE (MTYPE_OSPF_IF_PARAMS, oip);
}
struct ospf_if_params *oip;
struct prefix_ipv4 p;
struct route_node *rn;
+
+ p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefix = addr;
rn = route_node_lookup (IF_OIFS_PARAMS (ifp), (struct prefix*)&p);
!OSPF_IF_PARAM_CONFIGURED (oip, retransmit_interval) &&
!OSPF_IF_PARAM_CONFIGURED (oip, passive_interface) &&
!OSPF_IF_PARAM_CONFIGURED (oip, v_hello) &&
+ !OSPF_IF_PARAM_CONFIGURED (oip, fast_hello) &&
!OSPF_IF_PARAM_CONFIGURED (oip, v_wait) &&
!OSPF_IF_PARAM_CONFIGURED (oip, priority) &&
!OSPF_IF_PARAM_CONFIGURED (oip, type) &&
!OSPF_IF_PARAM_CONFIGURED (oip, auth_simple) &&
!OSPF_IF_PARAM_CONFIGURED (oip, auth_type) &&
- listcount (oip->auth_crypt) == 0)
+ listcount (oip->auth_crypt) == 0 &&
+ ntohl (oip->network_lsa_seqnum) != OSPF_INITIAL_SEQUENCE_NUMBER)
{
ospf_del_if_params (oip);
rn->info = NULL;
struct prefix_ipv4 p;
struct route_node *rn;
+ p.family = AF_INET;
p.prefixlen = IPV4_MAX_PREFIXLEN;
p.prefix = addr;
{
int rc = 0;
- ifp->info = XMALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
- memset (ifp->info, 0, sizeof (struct ospf_if_info));
+ ifp->info = XCALLOC (MTYPE_OSPF_IF_INFO, sizeof (struct ospf_if_info));
IF_OIFS (ifp) = route_table_init ();
IF_OIFS_PARAMS (ifp) = route_table_init ();
SET_IF_PARAM (IF_DEF_PARAMS (ifp), priority);
IF_DEF_PARAMS (ifp)->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
- SET_IF_PARAM (IF_DEF_PARAMS (ifp), passive_interface);
- IF_DEF_PARAMS (ifp)->passive_interface = OSPF_IF_ACTIVE;
+ IF_DEF_PARAMS (ifp)->mtu_ignore = OSPF_MTU_IGNORE_DEFAULT;
SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_hello);
IF_DEF_PARAMS (ifp)->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
+ SET_IF_PARAM (IF_DEF_PARAMS (ifp), fast_hello);
+ IF_DEF_PARAMS (ifp)->fast_hello = OSPF_FAST_HELLO_DEFAULT;
+
SET_IF_PARAM (IF_DEF_PARAMS (ifp), v_wait);
IF_DEF_PARAMS (ifp)->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
return rc;
}
-int
+static int
ospf_if_delete_hook (struct interface *ifp)
{
int rc = 0;
+ struct route_node *rn;
#ifdef HAVE_OPAQUE_LSA
rc = ospf_opaque_del_if (ifp);
#endif /* HAVE_OPAQUE_LSA */
+
route_table_finish (IF_OIFS (ifp));
+
+ for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
+ if (rn->info)
+ ospf_del_if_params (rn->info);
route_table_finish (IF_OIFS_PARAMS (ifp));
+
ospf_del_if_params ((struct ospf_if_params *) IF_DEF_PARAMS (ifp));
XFREE (MTYPE_OSPF_IF_INFO, ifp->info);
ifp->info = NULL;
return 0;
}
+void
+ospf_if_set_multicast(struct ospf_interface *oi)
+{
+ if ((oi->state > ISM_Loopback) &&
+ (oi->type != OSPF_IFTYPE_LOOPBACK) &&
+ (oi->type != OSPF_IFTYPE_VIRTUALLINK) &&
+ (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
+ {
+ /* The interface should belong to the OSPF-all-routers group. */
+ if (!OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) &&
+ (ospf_if_add_allspfrouters(oi->ospf, oi->address,
+ oi->ifp->ifindex) >= 0))
+ /* Set the flag only if the system call to join succeeded. */
+ OI_MEMBER_JOINED(oi, MEMBER_ALLROUTERS);
+ }
+ else
+ {
+ /* The interface should NOT belong to the OSPF-all-routers group. */
+ if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
+ {
+ /* Only actually drop if this is the last reference */
+ if (OI_MEMBER_COUNT(oi, MEMBER_ALLROUTERS) == 1)
+ ospf_if_drop_allspfrouters (oi->ospf, oi->address,
+ oi->ifp->ifindex);
+ /* Unset the flag regardless of whether the system call to leave
+ the group succeeded, since it's much safer to assume that
+ we are not a member. */
+ OI_MEMBER_LEFT(oi,MEMBER_ALLROUTERS);
+ }
+ }
+
+ if (((oi->type == OSPF_IFTYPE_BROADCAST) ||
+ (oi->type == OSPF_IFTYPE_POINTOPOINT)) &&
+ ((oi->state == ISM_DR) || (oi->state == ISM_Backup)) &&
+ (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE))
+ {
+ /* The interface should belong to the OSPF-designated-routers group. */
+ if (!OI_MEMBER_CHECK(oi, MEMBER_DROUTERS) &&
+ (ospf_if_add_alldrouters(oi->ospf, oi->address,
+ oi->ifp->ifindex) >= 0))
+ /* Set the flag only if the system call to join succeeded. */
+ OI_MEMBER_JOINED(oi, MEMBER_DROUTERS);
+ }
+ else
+ {
+ /* The interface should NOT belong to the OSPF-designated-routers group */
+ if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
+ {
+ /* drop only if last reference */
+ if (OI_MEMBER_COUNT(oi, MEMBER_DROUTERS) == 1)
+ ospf_if_drop_alldrouters(oi->ospf, oi->address, oi->ifp->ifindex);
+
+ /* Unset the flag regardless of whether the system call to leave
+ the group succeeded, since it's much safer to assume that
+ we are not a member. */
+ OI_MEMBER_LEFT(oi, MEMBER_DROUTERS);
+ }
+ }
+}
+
int
ospf_if_up (struct ospf_interface *oi)
{
OSPF_ISM_EVENT_SCHEDULE (oi, ISM_LoopInd);
else
{
- if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
- ospf_if_add_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
+ struct ospf *ospf = ospf_lookup ();
+ if (ospf != NULL)
+ ospf_adjust_sndbuflen (ospf, oi->ifp->mtu);
+ else
+ zlog_warn ("%s: ospf_lookup() returned NULL", __func__);
ospf_if_stream_set (oi);
OSPF_ISM_EVENT_SCHEDULE (oi, ISM_InterfaceUp);
}
return 0;
OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
+ /* delete position in router LSA */
+ oi->lsa_pos_beg = 0;
+ oi->lsa_pos_end = 0;
/* Shutdown packet reception and sending */
ospf_if_stream_unset (oi);
- if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
- ospf_if_drop_allspfrouters (oi->ospf, oi->address, oi->ifp->ifindex);
-
return 1;
}
-\f
+
/* Virtual Link related functions. */
struct ospf_vl_data *
{
struct ospf_vl_data *vl_data;
- vl_data = XMALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
- memset (vl_data, 0, sizeof (struct ospf_vl_data));
+ vl_data = XCALLOC (MTYPE_OSPF_VL_DATA, sizeof (struct ospf_vl_data));
vl_data->vl_peer.s_addr = vl_peer.s_addr;
vl_data->vl_area_id = area->area_id;
struct prefix_ipv4 *p;
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): Start");
+ zlog_debug ("ospf_vl_new(): Start");
if (vlink_count == OSPF_VL_MAX_COUNT)
{
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): Alarm: "
+ zlog_debug ("ospf_vl_new(): Alarm: "
"cannot create more than OSPF_MAX_VL_COUNT virtual links");
return NULL;
}
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): creating pseudo zebra interface");
+ zlog_debug ("ospf_vl_new(): creating pseudo zebra interface");
- snprintf (ifname, INTERFACE_NAMSIZ + 1, "VLINK%d", vlink_count);
- vi = if_create (ifname, INTERFACE_NAMSIZ);
+ snprintf (ifname, sizeof(ifname), "VLINK%d", vlink_count);
+ vi = if_create (ifname, strnlen(ifname, sizeof(ifname)));
+ /*
+ * if_create sets ZEBRA_INTERFACE_LINKDETECTION
+ * virtual links don't need this.
+ */
+ UNSET_FLAG (vi->status, ZEBRA_INTERFACE_LINKDETECTION);
co = connected_new ();
co->ifp = vi;
listnode_add (vi->connected, co);
if (voi == NULL)
{
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): Alarm: OSPF int structure is not created");
+ zlog_debug ("ospf_vl_new(): Alarm: OSPF int structure is not created");
return NULL;
}
voi->connected = co;
vlink_count++;
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): Created name: %s", ifname);
+ zlog_debug ("ospf_vl_new(): Created name: %s", ifname);
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): set if->name to %s", vi->name);
+ zlog_debug ("ospf_vl_new(): set if->name to %s", vi->name);
area_id.s_addr = 0;
area = ospf_area_get (ospf, area_id, OSPF_AREA_ID_FORMAT_ADDRESS);
voi->area = area;
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): set associated area to the backbone");
+ zlog_debug ("ospf_vl_new(): set associated area to the backbone");
+ ospf_nbr_add_self (voi);
ospf_area_add_if (voi->area, voi);
ospf_if_stream_set (voi);
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_new(): Stop");
+ zlog_debug ("ospf_vl_new(): Stop");
return voi;
}
-void
+static void
ospf_vl_if_delete (struct ospf_vl_data *vl_data)
{
struct interface *ifp = vl_data->vl_oi->ifp;
vlink_count--;
}
+/* Look up vl_data for given peer, optionally qualified to be in the
+ * specified area. NULL area returns first found..
+ */
struct ospf_vl_data *
-ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer)
+ospf_vl_lookup (struct ospf *ospf, struct ospf_area *area,
+ struct in_addr vl_peer)
{
struct ospf_vl_data *vl_data;
- listnode node;
-
- for (node = listhead (area->ospf->vlinks); node; nextnode (node))
- if ((vl_data = getdata (node)) != NULL)
- if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
- IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
+ struct listnode *node;
+
+ if (IS_DEBUG_OSPF_EVENT)
+ {
+ zlog_debug ("%s: Looking for %s", __func__, inet_ntoa (vl_peer));
+ if (area)
+ zlog_debug ("%s: in area %s", __func__, inet_ntoa (area->area_id));
+ }
+
+ for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
+ {
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug ("%s: VL %s, peer %s", __func__,
+ vl_data->vl_oi->ifp->name,
+ inet_ntoa (vl_data->vl_peer));
+
+ if (area && !IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
+ continue;
+
+ if (IPV4_ADDR_SAME (&vl_data->vl_peer, &vl_peer))
return vl_data;
+ }
return NULL;
}
-void
+static void
ospf_vl_shutdown (struct ospf_vl_data *vl_data)
{
struct ospf_interface *oi;
ospf_vl_data_free (vl_data);
}
-int
+static int
ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v)
{
int changed = 0;
struct ospf_interface *voi;
- listnode node;
- struct vertex_nexthop *nh;
- int i;
+ struct listnode *node;
+ struct vertex_parent *vp = NULL;
+ unsigned int i;
struct router_lsa *rl;
voi = vl_data->vl_oi;
if (voi->output_cost != v->distance)
{
+
voi->output_cost = v->distance;
changed = 1;
}
- for (node = listhead (v->nexthop); node; nextnode (node))
- if ((nh = getdata (node)) != NULL)
- {
- vl_data->out_oi = (struct ospf_interface *) nh->oi;
-
- voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
- voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
-
- break; /* We take the first interface. */
- }
+ for (ALL_LIST_ELEMENTS_RO (v->parents, node, vp))
+ {
+ vl_data->nexthop.oi = vp->nexthop->oi;
+ vl_data->nexthop.router = vp->nexthop->router;
+
+ if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
+ &vl_data->nexthop.oi->address->u.prefix4))
+ changed = 1;
+
+ voi->address->u.prefix4 = vl_data->nexthop.oi->address->u.prefix4;
+ voi->address->prefixlen = vl_data->nexthop.oi->address->prefixlen;
+
+ break; /* We take the first interface. */
+ }
rl = (struct router_lsa *)v->lsa;
-
- for (i = 0; i < ntohs (rl->links); i++)
+
+ /* use SPF determined backlink index in struct vertex
+ * for virtual link destination address
+ */
+ if (vp && vp->backlink >= 0)
{
- switch (rl->link[i].type)
+ if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
+ &rl->link[vp->backlink].link_data))
+ changed = 1;
+ vl_data->peer_addr = rl->link[vp->backlink].link_data;
+ }
+ else
+ {
+ /* This is highly odd, there is no backlink index
+ * there should be due to the ospf_spf_has_link() check
+ * in SPF. Lets warn and try pick a link anyway.
+ */
+ zlog_warn ("ospf_vl_set_params: No backlink for %s!",
+ vl_data->vl_oi->ifp->name);
+ for (i = 0; i < ntohs (rl->links); i++)
{
- case LSA_LINK_TYPE_VIRTUALLINK:
- if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("found back link through VL");
- case LSA_LINK_TYPE_TRANSIT:
- case LSA_LINK_TYPE_POINTOPOINT:
- vl_data->peer_addr = rl->link[i].link_data;
- if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("%s peer address is %s\n",
- vl_data->vl_oi->ifp->name,
- inet_ntoa(vl_data->peer_addr));
- return changed;
+ switch (rl->link[i].type)
+ {
+ case LSA_LINK_TYPE_VIRTUALLINK:
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug ("found back link through VL");
+ case LSA_LINK_TYPE_TRANSIT:
+ case LSA_LINK_TYPE_POINTOPOINT:
+ if (!IPV4_ADDR_SAME (&vl_data->peer_addr,
+ &rl->link[i].link_data))
+ changed = 1;
+ vl_data->peer_addr = rl->link[i].link_data;
+ }
}
}
+
+ if (IS_DEBUG_OSPF_EVENT)
+ zlog_debug ("%s: %s peer address: %s, cost: %d,%schanged", __func__,
+ vl_data->vl_oi->ifp->name,
+ inet_ntoa(vl_data->peer_addr),
+ voi->output_cost,
+ (changed ? " " : " un"));
+
return changed;
}
struct vertex *v)
{
struct ospf *ospf = area->ospf;
- listnode node;
+ struct listnode *node;
struct ospf_vl_data *vl_data;
struct ospf_interface *oi;
if (IS_DEBUG_OSPF_EVENT)
{
- zlog_info ("ospf_vl_up_check(): Start");
- zlog_info ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
- zlog_info ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
+ zlog_debug ("ospf_vl_up_check(): Start");
+ zlog_debug ("ospf_vl_up_check(): Router ID is %s", inet_ntoa (rid));
+ zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
}
- for (node = listhead (ospf->vlinks); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
{
- if ((vl_data = getdata (node)) == NULL)
- continue;
-
if (IS_DEBUG_OSPF_EVENT)
{
- zlog_info ("ospf_vl_up_check(): considering VL, name: %s",
- vl_data->vl_oi->ifp->name);
- zlog_info ("ospf_vl_up_check(): VL area: %s, peer ID: %s",
- inet_ntoa (vl_data->vl_area_id),
+ zlog_debug ("%s: considering VL, %s in area %s", __func__,
+ vl_data->vl_oi->ifp->name,
+ inet_ntoa (vl_data->vl_area_id));
+ zlog_debug ("%s: peer ID: %s", __func__,
inet_ntoa (vl_data->vl_peer));
}
SET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_up_check(): this VL matched");
+ zlog_debug ("ospf_vl_up_check(): this VL matched");
if (oi->state == ISM_Down)
{
if (IS_DEBUG_OSPF_EVENT)
- zlog_info ("ospf_vl_up_check(): VL is down, waking it up");
+ zlog_debug ("ospf_vl_up_check(): VL is down, waking it up");
SET_FLAG (oi->ifp->flags, IFF_UP);
OSPF_ISM_EVENT_EXECUTE(oi,ISM_InterfaceUp);
}
if (ospf_vl_set_params (vl_data, v))
{
if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
- zlog_info ("ospf_vl_up_check: VL cost change, scheduling router lsa refresh");
- if(ospf->backbone)
- ospf_router_lsa_timer_add(ospf->backbone);
+ zlog_debug ("ospf_vl_up_check: VL cost change,"
+ " scheduling router lsa refresh");
+ if (ospf->backbone)
+ ospf_router_lsa_update_area (ospf->backbone);
else if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
- zlog_info ("ospf_vl_up_check: VL cost change, no backbone!");
+ zlog_debug ("ospf_vl_up_check: VL cost change, no backbone!");
}
}
}
void
ospf_vl_unapprove (struct ospf *ospf)
{
- listnode node;
+ struct listnode *node;
struct ospf_vl_data *vl_data;
- for (node = listhead (ospf->vlinks); node; nextnode (node))
- if ((vl_data = getdata (node)) != NULL)
- UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
+ for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
+ UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
}
void
ospf_vl_shut_unapproved (struct ospf *ospf)
{
- listnode node;
+ struct listnode *node, *nnode;
struct ospf_vl_data *vl_data;
- for (node = listhead (ospf->vlinks); node; nextnode (node))
- if ((vl_data = getdata (node)) != NULL)
- if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
- ospf_vl_shutdown (vl_data);
+ for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
+ if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
+ ospf_vl_shutdown (vl_data);
}
int
{
if (IS_DEBUG_OSPF_EVENT)
{
- zlog_info ("counting fully adjacent virtual neighbors in area %s",
+ zlog_debug ("counting fully adjacent virtual neighbors in area %s",
inet_ntoa (area->area_id));
- zlog_info ("there are %d of them", area->full_vls);
+ zlog_debug ("there are %d of them", area->full_vls);
}
return area->full_vls;
int
ospf_vls_in_area (struct ospf_area *area)
{
- listnode node;
+ struct listnode *node;
struct ospf_vl_data *vl_data;
int c = 0;
- for (node = listhead (area->ospf->vlinks); node; nextnode (node))
- if ((vl_data = getdata (node)) != NULL)
- if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
- c++;
+ for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
+ if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
+ c++;
return c;
}
-\f
+
struct crypt_key *
ospf_crypt_key_new ()
{
- struct crypt_key *ck;
-
- ck = XMALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
- memset (ck, 0, sizeof (struct crypt_key));
-
- return ck;
+ return XCALLOC (MTYPE_OSPF_CRYPT_KEY, sizeof (struct crypt_key));
}
void
-ospf_crypt_key_add (list crypt, struct crypt_key *ck)
+ospf_crypt_key_add (struct list *crypt, struct crypt_key *ck)
{
listnode_add (crypt, ck);
}
struct crypt_key *
-ospf_crypt_key_lookup (list auth_crypt, u_char key_id)
+ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id)
{
- listnode node;
+ struct listnode *node;
struct crypt_key *ck;
- for (node = listhead (auth_crypt); node; nextnode (node))
- {
- ck = getdata (node);
- if (ck->key_id == key_id)
- return ck;
- }
+ for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
+ if (ck->key_id == key_id)
+ return ck;
return NULL;
}
int
-ospf_crypt_key_delete (list auth_crypt, u_char key_id)
+ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
{
- listnode node;
+ struct listnode *node, *nnode;
struct crypt_key *ck;
- for (node = listhead (auth_crypt); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
{
- ck = getdata (node);
if (ck->key_id == key_id)
{
listnode_delete (auth_crypt, ck);
+ XFREE (MTYPE_OSPF_CRYPT_KEY, ck);
return 1;
}
}
return 0;
}
+u_char
+ospf_default_iftype(struct interface *ifp)
+{
+ if (if_is_pointopoint (ifp))
+ return OSPF_IFTYPE_POINTOPOINT;
+ else if (if_is_loopback (ifp))
+ return OSPF_IFTYPE_LOOPBACK;
+ else
+ return OSPF_IFTYPE_BROADCAST;
+}
+
void
ospf_if_init ()
{
/* Initialize Zebra interface data structure. */
- if_init ();
- om->iflist = iflist;
+ om->iflist = vrf_iflist (VRF_DEFAULT);
if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);
}