]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_interface.c
*: auto-convert to SPDX License IDs
[mirror_frr.git] / ospfd / ospf_interface.c
index 2626cccc3782962fdcf07f31bbdd0c0343d606af..4ea367ecad36bf5eac3fc4618ea043c322728dac 100644 (file)
@@ -1,22 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * OSPF Interface functions.
  * Copyright (C) 1999, 2000 Toshiaki Takada
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -30,6 +15,7 @@
 #include "command.h"
 #include "stream.h"
 #include "log.h"
+#include "network.h"
 #include "zclient.h"
 #include "bfd.h"
 #include "ldp_sync.h"
@@ -66,15 +52,16 @@ int ospf_interface_neighbor_count(struct ospf_interface *oi)
 
        for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
                nbr = rn->info;
-               if (nbr) {
-                       /* Do not show myself. */
-                       if (nbr == oi->nbr_self)
-                               continue;
-                       /* Down state is not shown. */
-                       if (nbr->state == NSM_Down)
-                               continue;
-                       count++;
-               }
+               if (!nbr)
+                       continue;
+
+               /* Do not show myself. */
+               if (nbr == oi->nbr_self)
+                       continue;
+               /* Down state is not shown. */
+               if (nbr->state == NSM_Down)
+                       continue;
+               count++;
        }
 
        return count;
@@ -102,7 +89,7 @@ int ospf_if_get_output_cost(struct ospf_interface *oi)
                                        : OSPF_DEFAULT_BANDWIDTH;
        refbw = oi->ospf->ref_bandwidth;
 
-       /* A specifed ip ospf cost overrides a calculated one. */
+       /* A specified ip ospf cost overrides a calculated one. */
        if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), output_cost_cmd)
            || OSPF_IF_PARAM_CONFIGURED(oi->params, output_cost_cmd))
                cost = OSPF_IF_PARAM(oi, output_cost_cmd);
@@ -273,7 +260,7 @@ struct ospf_interface *ospf_if_new(struct ospf *ospf, struct interface *ifp,
        oi->t_ls_upd_event = NULL;
        oi->t_ls_ack_direct = NULL;
 
-       oi->crypt_seqnum = time(NULL);
+       oi->crypt_seqnum = frr_sequence32_next();
 
        ospf_opaque_type9_lsa_init(oi);
 
@@ -302,7 +289,7 @@ void ospf_if_cleanup(struct ospf_interface *oi)
        /* oi->nbrs and oi->nbr_nbma should be deleted on InterfaceDown event */
        /* delete all static neighbors attached to this interface */
        for (ALL_LIST_ELEMENTS(oi->nbr_nbma, node, nnode, nbr_nbma)) {
-               OSPF_POLL_TIMER_OFF(nbr_nbma->t_poll);
+               THREAD_OFF(nbr_nbma->t_poll);
 
                if (nbr_nbma->nbr) {
                        nbr_nbma->nbr->nbr_nbma = NULL;
@@ -315,10 +302,11 @@ void ospf_if_cleanup(struct ospf_interface *oi)
        }
 
        /* send Neighbor event KillNbr to all associated neighbors. */
-       for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
+       for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
                if ((nbr = rn->info) != NULL)
                        if (nbr != oi->nbr_self)
                                OSPF_NSM_EVENT_EXECUTE(nbr, NSM_KillNbr);
+       }
 
        /* Cleanup Link State Acknowlegdment list. */
        for (ALL_LIST_ELEMENTS(oi->ls_ack, node, nnode, lsa))
@@ -459,13 +447,13 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
 {
        struct route_node *rn;
        struct prefix_ipv4 addr;
-       struct ospf_interface *oi, *match;
+       struct ospf_interface *oi, *match, *unnumbered_match;
 
        addr.family = AF_INET;
        addr.prefix = src;
        addr.prefixlen = IPV4_MAX_BITLEN;
 
-       match = NULL;
+       match = unnumbered_match = NULL;
 
        for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
                oi = rn->info;
@@ -480,7 +468,7 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
                        continue;
 
                if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
-                       match = oi;
+                       unnumbered_match = oi;
                else if (prefix_match(CONNECTED_PREFIX(oi->connected),
                                      (struct prefix *)&addr)) {
                        if ((match == NULL) || (match->address->prefixlen
@@ -489,7 +477,24 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
                }
        }
 
-       return match;
+       if (match)
+               return match;
+
+       return unnumbered_match;
+}
+
+void ospf_interface_fifo_flush(struct ospf_interface *oi)
+{
+       struct ospf *ospf = oi->ospf;
+
+       ospf_fifo_flush(oi->obuf);
+
+       if (oi->on_write_q) {
+               listnode_delete(ospf->oi_write_q, oi);
+               if (list_isempty(ospf->oi_write_q))
+                       THREAD_OFF(ospf->t_write);
+               oi->on_write_q = 0;
+       }
 }
 
 static void ospf_if_reset_stats(struct ospf_interface *oi)
@@ -503,19 +508,10 @@ static void ospf_if_reset_stats(struct ospf_interface *oi)
 
 void ospf_if_stream_unset(struct ospf_interface *oi)
 {
-       struct ospf *ospf = oi->ospf;
-
        /* flush the interface packet queue */
-       ospf_fifo_flush(oi->obuf);
+       ospf_interface_fifo_flush(oi);
        /*reset protocol stats */
        ospf_if_reset_stats(oi);
-
-       if (oi->on_write_q) {
-               listnode_delete(ospf->oi_write_q, oi);
-               if (list_isempty(ospf->oi_write_q))
-                       OSPF_TIMER_OFF(ospf->t_write);
-               oi->on_write_q = 0;
-       }
 }
 
 
@@ -902,18 +898,19 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
        struct prefix_ipv4 *p;
 
        if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug("ospf_vl_new()(%s): Start", ospf_get_name(ospf));
+               zlog_debug("%s: (%s): Start", __func__, ospf_get_name(ospf));
        if (vlink_count == OSPF_VL_MAX_COUNT) {
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug(
-                               "ospf_vl_new(): Alarm: cannot create more than OSPF_MAX_VL_COUNT virtual links");
+                               "%s: Alarm: cannot create more than OSPF_MAX_VL_COUNT virtual links",
+                               __func__);
+
                return NULL;
        }
 
        if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug(
-                       "ospf_vl_new(): creating pseudo zebra interface vrf id %u",
-                       ospf->vrf_id);
+               zlog_debug("%s: creating pseudo zebra interface vrf id %u",
+                          __func__, ospf->vrf_id);
 
        snprintf(ifname, sizeof(ifname), "VLINK%u", vlink_count);
        vi = if_get_by_name(ifname, ospf->vrf_id, ospf->name);
@@ -937,7 +934,9 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
        if (voi == NULL) {
                if (IS_DEBUG_OSPF_EVENT)
                        zlog_debug(
-                               "ospf_vl_new(): Alarm: OSPF int structure is not created");
+                               "%s: Alarm: OSPF int structure is not created",
+                               __func__);
+
                return NULL;
        }
        voi->connected = co;
@@ -947,17 +946,15 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
 
        vlink_count++;
        if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug("ospf_vl_new(): Created name: %s", ifname);
-       if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug("ospf_vl_new(): set if->name to %s", vi->name);
+               zlog_debug("%s: Created name: %s set if->name to %s", __func__,
+                          ifname, vi->name);
 
        area_id.s_addr = INADDR_ANY;
        area = ospf_area_get(ospf, area_id);
        voi->area = area;
 
        if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug(
-                       "ospf_vl_new(): set associated area to the backbone");
+               zlog_debug("%s: set associated area to the backbone", __func__);
 
        /* Add pseudo neighbor. */
        ospf_nbr_self_reset(voi, voi->ospf->router_id);
@@ -965,7 +962,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
        ospf_area_add_if(voi->area, voi);
 
        if (IS_DEBUG_OSPF_EVENT)
-               zlog_debug("ospf_vl_new(): Stop");
+               zlog_debug("%s: Stop", __func__);
        return voi;
 }
 
@@ -1160,10 +1157,8 @@ void ospf_vl_up_check(struct ospf_area *area, struct in_addr rid,
        struct ospf_interface *oi;
 
        if (IS_DEBUG_OSPF_EVENT) {
-               zlog_debug("ospf_vl_up_check(): Start");
-               zlog_debug("ospf_vl_up_check(): Router ID is %pI4",
-                          &rid);
-               zlog_debug("ospf_vl_up_check(): Area is %pI4",
+               zlog_debug("%s: Start", __func__);
+               zlog_debug("%s: Router ID is %pI4 Area is %pI4", __func__, &rid,
                           &area->area_id);
        }
 
@@ -1182,13 +1177,13 @@ void ospf_vl_up_check(struct ospf_area *area, struct in_addr rid,
                        SET_FLAG(vl_data->flags, OSPF_VL_FLAG_APPROVED);
 
                        if (IS_DEBUG_OSPF_EVENT)
-                               zlog_debug(
-                                       "ospf_vl_up_check(): this VL matched");
+                               zlog_debug("%s: this VL matched", __func__);
 
                        if (oi->state == ISM_Down) {
                                if (IS_DEBUG_OSPF_EVENT)
                                        zlog_debug(
-                                               "ospf_vl_up_check(): VL is down, waking it up");
+                                               "%s: VL is down, waking it up",
+                                               __func__);
                                SET_FLAG(oi->ifp->flags, IFF_UP);
                                OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
                        }
@@ -1196,13 +1191,15 @@ void ospf_vl_up_check(struct ospf_area *area, struct in_addr rid,
                        if (ospf_vl_set_params(area, vl_data, v)) {
                                if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
                                        zlog_debug(
-                                               "ospf_vl_up_check: VL cost change, scheduling router lsa refresh");
+                                               "%s: VL cost change, scheduling router lsa refresh",
+                                               __func__);
                                if (ospf->backbone)
                                        ospf_router_lsa_update_area(
                                                ospf->backbone);
                                else if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
                                        zlog_debug(
-                                               "ospf_vl_up_check: VL cost change, no backbone!");
+                                               "%s: VL cost change, no backbone!",
+                                               __func__);
                        }
                }
        }
@@ -1474,7 +1471,7 @@ void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr,
                        ospf_hello_send(oi);
 
                        /* Restart hello timer for this interface */
-                       OSPF_ISM_TIMER_OFF(oi->t_hello);
+                       THREAD_OFF(oi->t_hello);
                        OSPF_HELLO_TIMER_ON(oi);
                }
 
@@ -1498,7 +1495,7 @@ void ospf_reset_hello_timer(struct interface *ifp, struct in_addr addr,
                ospf_hello_send(oi);
 
                /* Restart the hello timer. */
-               OSPF_ISM_TIMER_OFF(oi->t_hello);
+               THREAD_OFF(oi->t_hello);
                OSPF_HELLO_TIMER_ON(oi);
        }
 }