]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_interface.c
lib: enforce vrf_name_to_id by returning default_vrf when name is null
[mirror_frr.git] / ospfd / ospf_interface.c
index 0305305b81917631d578603508a0fd6838e55165..f1477ba14dc531ad32d3f9fba56515302c85aebe 100644 (file)
@@ -76,8 +76,8 @@ int ospf_interface_neighbor_count(struct ospf_interface *oi)
 int ospf_if_get_output_cost(struct ospf_interface *oi)
 {
        /* If all else fails, use default OSPF cost */
-       u_int32_t cost;
-       u_int32_t bw, refbw;
+       uint32_t cost;
+       uint32_t bw, refbw;
 
        /* ifp speed and bw can be 0 in some platforms, use ospf default bw
           if bw is configured under interface it would be used.
@@ -96,7 +96,7 @@ int ospf_if_get_output_cost(struct ospf_interface *oi)
        /* See if a cost can be calculated from the zebra processes
           interface bandwidth field. */
        else {
-               cost = (u_int32_t)((double)refbw / (double)bw + (double)0.5);
+               cost = (uint32_t)((double)refbw / (double)bw + (double)0.5);
                if (cost < 1)
                        cost = 1;
                else if (cost > 65535)
@@ -108,7 +108,7 @@ int ospf_if_get_output_cost(struct ospf_interface *oi)
 
 void ospf_if_recalculate_output_cost(struct interface *ifp)
 {
-       u_int32_t newcost;
+       uint32_t newcost;
        struct route_node *rn;
 
        for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
@@ -263,6 +263,9 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp,
        ospf_opaque_type9_lsa_init(oi);
 
        oi->ospf = ospf;
+
+       ospf_if_stream_set(oi);
+
        QOBJ_REG(oi, ospf_interface);
 
        if (IS_DEBUG_OSPF_EVENT)
@@ -322,6 +325,9 @@ void ospf_if_free(struct ospf_interface *oi)
 {
        ospf_if_down(oi);
 
+       if (oi->obuf)
+               ospf_fifo_free(oi->obuf);
+
        assert(oi->state == ISM_Down);
 
        ospf_opaque_type9_lsa_term(oi);
@@ -335,10 +341,10 @@ void ospf_if_free(struct ospf_interface *oi)
        route_table_finish(oi->ls_upd_queue);
 
        /* Free any lists that should be freed */
-       list_delete_and_null(&oi->nbr_nbma);
+       list_delete(&oi->nbr_nbma);
 
-       list_delete_and_null(&oi->ls_ack);
-       list_delete_and_null(&oi->ls_ack_direct.ls_ack);
+       list_delete(&oi->ls_ack);
+       list_delete(&oi->ls_ack_direct.ls_ack);
 
        if (IS_DEBUG_OSPF_EVENT)
                zlog_debug("%s: ospf interface %s vrf %s id %u deleted",
@@ -496,9 +502,8 @@ void ospf_if_stream_unset(struct ospf_interface *oi)
        struct ospf *ospf = oi->ospf;
 
        if (oi->obuf) {
-               ospf_fifo_free(oi->obuf);
-               oi->obuf = NULL;
-
+               /* flush the interface packet queue */
+               ospf_fifo_flush(oi->obuf);
                /*reset protocol stats */
                ospf_if_reset_stats(oi);
 
@@ -518,9 +523,6 @@ static struct ospf_if_params *ospf_new_if_params(void)
 
        oip = XCALLOC(MTYPE_OSPF_IF_PARAMS, sizeof(struct ospf_if_params));
 
-       if (!oip)
-               return NULL;
-
        UNSET_IF_PARAM(oip, output_cost_cmd);
        UNSET_IF_PARAM(oip, transmit_delay);
        UNSET_IF_PARAM(oip, retransmit_interval);
@@ -543,7 +545,7 @@ static struct ospf_if_params *ospf_new_if_params(void)
 
 void ospf_del_if_params(struct ospf_if_params *oip)
 {
-       list_delete_and_null(&oip->auth_crypt);
+       list_delete(&oip->auth_crypt);
        bfd_info_free(&(oip->bfd_info));
        XFREE(MTYPE_OSPF_IF_PARAMS, oip);
 }
@@ -781,7 +783,6 @@ int ospf_if_up(struct ospf_interface *oi)
        if (oi->type == OSPF_IFTYPE_LOOPBACK)
                OSPF_ISM_EVENT_SCHEDULE(oi, ISM_LoopInd);
        else {
-               ospf_if_stream_set(oi);
                OSPF_ISM_EVENT_SCHEDULE(oi, ISM_InterfaceUp);
        }
 
@@ -825,7 +826,7 @@ void ospf_vl_data_free(struct ospf_vl_data *vl_data)
        XFREE(MTYPE_OSPF_VL_DATA, vl_data);
 }
 
-u_int vlink_count = 0;
+unsigned int vlink_count = 0;
 
 struct ospf_interface *ospf_vl_new(struct ospf *ospf,
                                   struct ospf_vl_data *vl_data)
@@ -853,7 +854,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
                        "ospf_vl_new(): creating pseudo zebra interface vrf id %u",
                        ospf->vrf_id);
 
-       snprintf(ifname, sizeof(ifname), "VLINK%d", vlink_count);
+       snprintf(ifname, sizeof(ifname), "VLINK%u", vlink_count);
        vi = if_create(ifname, ospf->vrf_id);
        /*
         * if_create sets ZEBRA_INTERFACE_LINKDETECTION
@@ -919,6 +920,23 @@ static void ospf_vl_if_delete(struct ospf_vl_data *vl_data)
        vlink_count--;
 }
 
+/* for a defined area, count the number of configured vl
+ */
+int ospf_vl_count(struct ospf *ospf, struct ospf_area *area)
+{
+       int count = 0;
+       struct ospf_vl_data *vl_data;
+       struct listnode *node;
+
+       for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
+               if (area
+                   && !IPV4_ADDR_SAME(&vl_data->vl_area_id, &area->area_id))
+                       continue;
+               count++;
+       }
+       return count;
+}
+
 /* Look up vl_data for given peer, optionally qualified to be in the
  * specified area. NULL area returns first found..
  */
@@ -1032,7 +1050,7 @@ static int ospf_vl_set_params(struct ospf_vl_data *vl_data, struct vertex *v)
                 * 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!",
+               zlog_info("ospf_vl_set_params: No backlink for %s!",
                          vl_data->vl_oi->ifp->name);
                for (i = 0; i < ntohs(rl->links); i++) {
                        switch (rl->link[i].type) {
@@ -1174,7 +1192,7 @@ void ospf_crypt_key_add(struct list *crypt, struct crypt_key *ck)
        listnode_add(crypt, ck);
 }
 
-struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, u_char key_id)
+struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, uint8_t key_id)
 {
        struct listnode *node;
        struct crypt_key *ck;
@@ -1186,7 +1204,7 @@ struct crypt_key *ospf_crypt_key_lookup(struct list *auth_crypt, u_char key_id)
        return NULL;
 }
 
-int ospf_crypt_key_delete(struct list *auth_crypt, u_char key_id)
+int ospf_crypt_key_delete(struct list *auth_crypt, uint8_t key_id)
 {
        struct listnode *node, *nnode;
        struct crypt_key *ck;
@@ -1202,7 +1220,7 @@ int ospf_crypt_key_delete(struct list *auth_crypt, u_char key_id)
        return 0;
 }
 
-u_char ospf_default_iftype(struct interface *ifp)
+uint8_t ospf_default_iftype(struct interface *ifp)
 {
        if (if_is_pointopoint(ifp))
                return OSPF_IFTYPE_POINTOPOINT;