back to topotato report
topotato coverage report
Current view: top level - ospfd - ospf_flood.c (source / functions) Hit Total Coverage
Test: aggregated run ( view descriptions ) Lines: 239 434 55.1 %
Date: 2023-02-24 14:41:08 Functions: 24 28 85.7 %

          Line data    Source code
       1             : /*
       2             :  * OSPF Flooding -- RFC2328 Section 13.
       3             :  * Copyright (C) 1999, 2000 Toshiaki Takada
       4             :  *
       5             :  * This file is part of GNU Zebra.
       6             :  *
       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.
      11             :  *
      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.
      16             :  *
      17             :  * You should have received a copy of the GNU General Public License along
      18             :  * with this program; see the file COPYING; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : #include <zebra.h>
      23             : 
      24             : #include "monotime.h"
      25             : #include "linklist.h"
      26             : #include "prefix.h"
      27             : #include "if.h"
      28             : #include "command.h"
      29             : #include "table.h"
      30             : #include "thread.h"
      31             : #include "memory.h"
      32             : #include "log.h"
      33             : #include "zclient.h"
      34             : 
      35             : #include "ospfd/ospfd.h"
      36             : #include "ospfd/ospf_interface.h"
      37             : #include "ospfd/ospf_ism.h"
      38             : #include "ospfd/ospf_asbr.h"
      39             : #include "ospfd/ospf_lsa.h"
      40             : #include "ospfd/ospf_lsdb.h"
      41             : #include "ospfd/ospf_neighbor.h"
      42             : #include "ospfd/ospf_nsm.h"
      43             : #include "ospfd/ospf_spf.h"
      44             : #include "ospfd/ospf_flood.h"
      45             : #include "ospfd/ospf_packet.h"
      46             : #include "ospfd/ospf_abr.h"
      47             : #include "ospfd/ospf_route.h"
      48             : #include "ospfd/ospf_zebra.h"
      49             : #include "ospfd/ospf_dump.h"
      50             : 
      51             : extern struct zclient *zclient;
      52             : 
      53             : /* Do the LSA acking specified in table 19, Section 13.5, row 2
      54             :  * This get called from ospf_flood_out_interface. Declared inline
      55             :  * for speed. */
      56          53 : static void ospf_flood_delayed_lsa_ack(struct ospf_neighbor *inbr,
      57             :                                        struct ospf_lsa *lsa)
      58             : {
      59             :         /* LSA is more recent than database copy, but was not
      60             :            flooded back out receiving interface.  Delayed
      61             :            acknowledgment sent. If interface is in Backup state
      62             :            delayed acknowledgment sent only if advertisement
      63             :            received from Designated Router, otherwise do nothing See
      64             :            RFC 2328 Section 13.5 */
      65             : 
      66             :         /* Whether LSA is more recent or not, and whether this is in
      67             :            response to the LSA being sent out recieving interface has been
      68             :            worked out previously */
      69             : 
      70             :         /* Deal with router as BDR */
      71          53 :         if (inbr->oi->state == ISM_Backup && !NBR_IS_DR(inbr))
      72             :                 return;
      73             : 
      74             :         /* Schedule a delayed LSA Ack to be sent */
      75          52 :         listnode_add(inbr->oi->ls_ack,
      76          52 :                      ospf_lsa_lock(lsa)); /* delayed LSA Ack */
      77             : }
      78             : 
      79             : /* Check LSA is related to external info. */
      80           0 : struct external_info *ospf_external_info_check(struct ospf *ospf,
      81             :                                                struct ospf_lsa *lsa)
      82             : {
      83           0 :         struct as_external_lsa *al;
      84           0 :         struct prefix_ipv4 p;
      85           0 :         struct route_node *rn;
      86           0 :         struct list *ext_list;
      87           0 :         struct listnode *node;
      88           0 :         struct ospf_external *ext;
      89           0 :         int type;
      90             : 
      91           0 :         al = (struct as_external_lsa *)lsa->data;
      92             : 
      93           0 :         p.family = AF_INET;
      94           0 :         p.prefix = lsa->data->id;
      95           0 :         p.prefixlen = ip_masklen(al->mask);
      96             : 
      97           0 :         for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
      98           0 :                 int redist_on = 0;
      99             : 
     100           0 :                 redist_on =
     101           0 :                         is_default_prefix4(&p)
     102           0 :                                 ? vrf_bitmap_check(
     103           0 :                                         zclient->default_information[AFI_IP],
     104             :                                         ospf->vrf_id)
     105           0 :                                 : (zclient->mi_redist[AFI_IP][type].enabled
     106           0 :                                    || vrf_bitmap_check(
     107             :                                            zclient->redist[AFI_IP][type],
     108             :                                            ospf->vrf_id));
     109             :                 // Pending: check for MI above.
     110           0 :                 if (redist_on) {
     111           0 :                         ext_list = ospf->external[type];
     112           0 :                         if (!ext_list)
     113           0 :                                 continue;
     114             : 
     115           0 :                         for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) {
     116           0 :                                 rn = NULL;
     117           0 :                                 if (ext->external_info)
     118           0 :                                         rn = route_node_lookup(
     119             :                                                 ext->external_info,
     120             :                                                 (struct prefix *)&p);
     121           0 :                                 if (rn) {
     122           0 :                                         route_unlock_node(rn);
     123           0 :                                         if (rn->info != NULL)
     124           0 :                                                 return (struct external_info *)
     125             :                                                         rn->info;
     126             :                                 }
     127             :                         }
     128             :                 }
     129             :         }
     130             : 
     131           0 :         if (is_default_prefix4(&p) && ospf->external[DEFAULT_ROUTE]) {
     132           0 :                 ext_list = ospf->external[DEFAULT_ROUTE];
     133             : 
     134           0 :                 for (ALL_LIST_ELEMENTS_RO(ext_list, node, ext)) {
     135           0 :                         if (!ext->external_info)
     136           0 :                                 continue;
     137             : 
     138           0 :                         rn = route_node_lookup(ext->external_info,
     139             :                                                (struct prefix *)&p);
     140           0 :                         if (!rn)
     141           0 :                                 continue;
     142           0 :                         route_unlock_node(rn);
     143           0 :                         if (rn->info != NULL)
     144           0 :                                 return (struct external_info *)rn->info;
     145             :                 }
     146             :         }
     147             :         return NULL;
     148             : }
     149             : 
     150           0 : static void ospf_process_self_originated_lsa(struct ospf *ospf,
     151             :                                              struct ospf_lsa *new,
     152             :                                              struct ospf_area *area)
     153             : {
     154           0 :         struct ospf_interface *oi;
     155           0 :         struct external_info *ei;
     156           0 :         struct listnode *node;
     157           0 :         struct as_external_lsa *al;
     158           0 :         struct prefix_ipv4 p;
     159           0 :         struct ospf_external_aggr_rt *aggr;
     160             : 
     161           0 :         if (IS_DEBUG_OSPF_EVENT)
     162           0 :                 zlog_debug(
     163             :                         "%s:LSA[Type%d:%pI4]: Process self-originated LSA seq 0x%x",
     164             :                         ospf_get_name(ospf), new->data->type,
     165             :                         &new->data->id, ntohl(new->data->ls_seqnum));
     166             : 
     167             :         /* If we're here, we installed a self-originated LSA that we received
     168             :            from a neighbor, i.e. it's more recent.  We must see whether we want
     169             :            to originate it.
     170             :            If yes, we should use this LSA's sequence number and reoriginate
     171             :            a new instance.
     172             :            if not --- we must flush this LSA from the domain. */
     173           0 :         switch (new->data->type) {
     174           0 :         case OSPF_ROUTER_LSA:
     175             :                 /* Originate a new instance and schedule flooding */
     176           0 :                 if (area->router_lsa_self)
     177           0 :                         area->router_lsa_self->data->ls_seqnum =
     178           0 :                                 new->data->ls_seqnum;
     179           0 :                 ospf_router_lsa_update_area(area);
     180           0 :                 return;
     181           0 :         case OSPF_NETWORK_LSA:
     182             :         case OSPF_OPAQUE_LINK_LSA:
     183             :                 /* We must find the interface the LSA could belong to.
     184             :                    If the interface is no more a broadcast type or we are no
     185             :                    more
     186             :                    the DR, we flush the LSA otherwise -- create the new instance
     187             :                    and
     188             :                    schedule flooding. */
     189             : 
     190             :                 /* Look through all interfaces, not just area, since interface
     191             :                    could be moved from one area to another. */
     192           0 :                 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi))
     193             :                         /* These are sanity check. */
     194           0 :                         if (IPV4_ADDR_SAME(&oi->address->u.prefix4,
     195             :                                            &new->data->id)) {
     196           0 :                                 if (oi->area != area
     197           0 :                                     || oi->type != OSPF_IFTYPE_BROADCAST
     198           0 :                                     || !IPV4_ADDR_SAME(&oi->address->u.prefix4,
     199             :                                                        &DR(oi))) {
     200           0 :                                         ospf_schedule_lsa_flush_area(area, new);
     201           0 :                                         return;
     202             :                                 }
     203             : 
     204           0 :                                 if (new->data->type == OSPF_OPAQUE_LINK_LSA) {
     205           0 :                                         ospf_opaque_lsa_refresh(new);
     206           0 :                                         return;
     207             :                                 }
     208             : 
     209           0 :                                 if (oi->network_lsa_self)
     210           0 :                                         oi->network_lsa_self->data->ls_seqnum =
     211           0 :                                                 new->data->ls_seqnum;
     212             :                                 /* Schedule network-LSA origination. */
     213           0 :                                 ospf_network_lsa_update(oi);
     214           0 :                                 return;
     215             :                         }
     216             :                 break;
     217           0 :         case OSPF_SUMMARY_LSA:
     218             :         case OSPF_ASBR_SUMMARY_LSA:
     219           0 :                 ospf_schedule_abr_task(ospf);
     220           0 :                 break;
     221           0 :         case OSPF_AS_EXTERNAL_LSA:
     222             :         case OSPF_AS_NSSA_LSA:
     223           0 :                 if ((new->data->type == OSPF_AS_EXTERNAL_LSA)
     224           0 :                     && CHECK_FLAG(new->flags, OSPF_LSA_LOCAL_XLT)) {
     225           0 :                         ospf_translated_nssa_refresh(ospf, NULL, new);
     226           0 :                         return;
     227             :                 }
     228             : 
     229           0 :                 al = (struct as_external_lsa *)new->data;
     230           0 :                 p.family = AF_INET;
     231           0 :                 p.prefixlen = ip_masklen(al->mask);
     232           0 :                 p.prefix = new->data->id;
     233             : 
     234           0 :                 ei = ospf_external_info_check(ospf, new);
     235           0 :                 if (ei) {
     236           0 :                         if (ospf_external_aggr_match(ospf, &ei->p)) {
     237           0 :                                 if (IS_DEBUG_OSPF(lsa, EXTNL_LSA_AGGR))
     238           0 :                                         zlog_debug(
     239             :                                                 "%s, Matching external aggregate route found for %pI4, so don't refresh it.",
     240             :                                                 __func__,
     241             :                                                 &ei->p.prefix);
     242             : 
     243             :                                 /* Aggregated external route shouldn't
     244             :                                  * be in LSDB.
     245             :                                  */
     246           0 :                                 if (!IS_LSA_MAXAGE(new))
     247           0 :                                         ospf_lsa_flush_as(ospf, new);
     248             : 
     249           0 :                                 return;
     250             :                         }
     251             : 
     252           0 :                         ospf_external_lsa_refresh(ospf, new, ei,
     253             :                                                   LSA_REFRESH_FORCE, false);
     254             :                 } else {
     255           0 :                         aggr = (struct ospf_external_aggr_rt *)
     256             :                                 ospf_extrenal_aggregator_lookup(ospf, &p);
     257           0 :                         if (aggr) {
     258           0 :                                 struct external_info ei_aggr;
     259             : 
     260           0 :                                 memset(&ei_aggr, 0,
     261             :                                         sizeof(struct external_info));
     262           0 :                                 ei_aggr.p = aggr->p;
     263           0 :                                 ei_aggr.tag = aggr->tag;
     264           0 :                                 ei_aggr.instance = ospf->instance;
     265           0 :                                 ei_aggr.route_map_set.metric = -1;
     266           0 :                                 ei_aggr.route_map_set.metric_type = -1;
     267             : 
     268           0 :                                 ospf_external_lsa_refresh(ospf, new, &ei_aggr,
     269             :                                                   LSA_REFRESH_FORCE, true);
     270           0 :                                 SET_FLAG(aggr->flags,
     271             :                                          OSPF_EXTERNAL_AGGRT_ORIGINATED);
     272             :                         } else
     273           0 :                                 ospf_lsa_flush_as(ospf, new);
     274             :                 }
     275             :                 break;
     276           0 :         case OSPF_OPAQUE_AREA_LSA:
     277           0 :                 ospf_opaque_lsa_refresh(new);
     278           0 :                 break;
     279           0 :         case OSPF_OPAQUE_AS_LSA:
     280           0 :                 ospf_opaque_lsa_refresh(new);
     281             :                 /* Reconsideration may needed. */ /* XXX */
     282           0 :                 break;
     283             :         default:
     284             :                 break;
     285             :         }
     286             : }
     287             : 
     288             : /* OSPF LSA flooding -- RFC2328 Section 13.(5). */
     289             : 
     290             : /* Now Updated for NSSA operation, as follows:
     291             : 
     292             : 
     293             :         Type-5's have no change.  Blocked to STUB or NSSA.
     294             : 
     295             :         Type-7's can be received, and if a DR
     296             :         they will also flood the local NSSA Area as Type-7's
     297             : 
     298             :         If a Self-Originated LSA (now an ASBR),
     299             :         The LSDB will be updated as Type-5's, (for continual re-fresh)
     300             : 
     301             :             If an NSSA-IR it is installed/flooded as Type-7, P-bit on.
     302             :             if an NSSA-ABR it is installed/flooded as Type-7, P-bit off.
     303             : 
     304             :         Later, during the ABR TASK, if the ABR is the Elected NSSA
     305             :         translator, then All Type-7s (with P-bit ON) are Translated to
     306             :         Type-5's and flooded to all non-NSSA/STUB areas.
     307             : 
     308             :         During ASE Calculations,
     309             :             non-ABRs calculate external routes from Type-7's
     310             :             ABRs calculate external routes from Type-5's and non-self Type-7s
     311             : */
     312          86 : int ospf_flood(struct ospf *ospf, struct ospf_neighbor *nbr,
     313             :                struct ospf_lsa *current, struct ospf_lsa *new)
     314             : {
     315          86 :         struct ospf_interface *oi;
     316          86 :         int lsa_ack_flag;
     317             : 
     318             :         /* Type-7 LSA's will be flooded throughout their native NSSA area,
     319             :            but will also be flooded as Type-5's into ABR capable links.  */
     320             : 
     321          86 :         if (IS_DEBUG_OSPF_EVENT)
     322          86 :                 zlog_debug(
     323             :                         "%s:LSA[Flooding]: start, NBR %pI4 (%s), cur(%p), New-LSA[%s]",
     324             :                         ospf_get_name(ospf), &nbr->router_id,
     325             :                         lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
     326             :                         (void *)current, dump_lsa_key(new));
     327             : 
     328          86 :         oi = nbr->oi;
     329             : 
     330             :         /* If there is already a database copy, and if the
     331             :            database copy was received via flooding and installed less
     332             :            than MinLSArrival seconds ago, discard the new LSA
     333             :            (without acknowledging it). */
     334          86 :         if (current != NULL) /* -- endo. */
     335             :         {
     336          50 :                 if (IS_LSA_SELF(current)
     337           0 :                     && (ntohs(current->data->ls_age) == 0
     338           0 :                         && ntohl(current->data->ls_seqnum)
     339             :                                    == OSPF_INITIAL_SEQUENCE_NUMBER)) {
     340           0 :                         if (IS_DEBUG_OSPF_EVENT)
     341           0 :                                 zlog_debug(
     342             :                                         "%s:LSA[Flooding]: Got a self-originated LSA, while local one is initial instance.",
     343             :                                         ospf_get_name(ospf));
     344             :                         ; /* Accept this LSA for quick LSDB resynchronization.
     345             :                              */
     346          50 :                 } else if (monotime_since(&current->tv_recv, NULL)
     347          50 :                            < ospf->min_ls_arrival * 1000LL) {
     348          28 :                         if (IS_DEBUG_OSPF_EVENT)
     349          28 :                                 zlog_debug(
     350             :                                         "%s:LSA[Flooding]: LSA is received recently.",
     351             :                                         ospf_get_name(ospf));
     352          28 :                         return -1;
     353             :                 }
     354             :         }
     355             : 
     356             :         /* Flood the new LSA out some subset of the router's interfaces.
     357             :            In some cases (e.g., the state of the receiving interface is
     358             :            DR and the LSA was received from a router other than the
     359             :            Backup DR) the LSA will be flooded back out the receiving
     360             :            interface. */
     361          58 :         lsa_ack_flag = ospf_flood_through(ospf, nbr, new);
     362             : 
     363             :         /* Remove the current database copy from all neighbors' Link state
     364             :            retransmission lists.  AS_EXTERNAL and AS_EXTERNAL_OPAQUE does
     365             :                                               ^^^^^^^^^^^^^^^^^^^^^^^
     366             :            not have area ID.
     367             :            All other (even NSSA's) do have area ID.  */
     368          58 :         if (current) {
     369          22 :                 switch (current->data->type) {
     370           2 :                 case OSPF_AS_EXTERNAL_LSA:
     371             :                 case OSPF_OPAQUE_AS_LSA:
     372           2 :                         ospf_ls_retransmit_delete_nbr_as(ospf, current);
     373           2 :                         break;
     374          20 :                 default:
     375          20 :                         ospf_ls_retransmit_delete_nbr_area(oi->area, current);
     376          20 :                         break;
     377             :                 }
     378             :         }
     379             : 
     380             :         /* Do some internal house keeping that is needed here */
     381          58 :         SET_FLAG(new->flags, OSPF_LSA_RECEIVED);
     382          58 :         (void)ospf_lsa_is_self_originated(ospf, new); /* Let it set the flag */
     383             : 
     384             :         /* Received non-self-originated Grace LSA */
     385          58 :         if (IS_GRACE_LSA(new) && !IS_LSA_SELF(new)) {
     386             : 
     387           0 :                 if (IS_LSA_MAXAGE(new)) {
     388             : 
     389             :                         /*  Handling Max age grace LSA.*/
     390           0 :                         if (IS_DEBUG_OSPF_GR)
     391           0 :                                 zlog_debug(
     392             :                                         "%s, Received a maxage GRACE-LSA from router %pI4",
     393             :                                         __func__, &new->data->adv_router);
     394             : 
     395           0 :                         if (current) {
     396           0 :                                 ospf_process_maxage_grace_lsa(ospf, new, nbr);
     397             :                         } else {
     398           0 :                                 if (IS_DEBUG_OSPF_GR)
     399           0 :                                         zlog_debug(
     400             :                                                 "%s, Grace LSA doesn't exist in lsdb, so discarding grace lsa",
     401             :                                                 __func__);
     402           0 :                                 return -1;
     403             :                         }
     404             :                 } else {
     405           0 :                         if (IS_DEBUG_OSPF_GR)
     406           0 :                                 zlog_debug(
     407             :                                         "%s, Received a GRACE-LSA from router %pI4",
     408             :                                         __func__, &new->data->adv_router);
     409             : 
     410           0 :                         if (ospf_process_grace_lsa(ospf, new, nbr)
     411             :                             == OSPF_GR_NOT_HELPER) {
     412           0 :                                 if (IS_DEBUG_OSPF_GR)
     413           0 :                                         zlog_debug(
     414             :                                                 "%s, Not moving to HELPER role, So discarding grace LSA",
     415             :                                                 __func__);
     416           0 :                                 return -1;
     417             :                         }
     418             :                 }
     419             :         }
     420             : 
     421             :         /* Install the new LSA in the link state database
     422             :            (replacing the current database copy).  This may cause the
     423             :            routing table calculation to be scheduled.  In addition,
     424             :            timestamp the new LSA with the current time.  The flooding
     425             :            procedure cannot overwrite the newly installed LSA until
     426             :            MinLSArrival seconds have elapsed. */
     427             : 
     428          58 :         if (!(new = ospf_lsa_install(ospf, oi, new)))
     429             :                 return -1; /* unknown LSA type or any other error condition */
     430             : 
     431             :         /* Acknowledge the receipt of the LSA by sending a Link State
     432             :            Acknowledgment packet back out the receiving interface. */
     433          58 :         if (lsa_ack_flag)
     434          53 :                 ospf_flood_delayed_lsa_ack(nbr, new);
     435             : 
     436             :         /* If this new LSA indicates that it was originated by the
     437             :            receiving router itself, the router must take special action,
     438             :            either updating the LSA or in some cases flushing it from
     439             :            the routing domain. */
     440          58 :         if (ospf_lsa_is_self_originated(ospf, new))
     441           0 :                 ospf_process_self_originated_lsa(ospf, new, oi->area);
     442             :         else
     443             :                 /* Update statistics value for OSPF-MIB. */
     444          58 :                 ospf->rx_lsa_count++;
     445             : 
     446             :         return 0;
     447             : }
     448             : 
     449             : /* OSPF LSA flooding -- RFC2328 Section 13.3. */
     450         316 : int ospf_flood_through_interface(struct ospf_interface *oi,
     451             :                                  struct ospf_neighbor *inbr,
     452             :                                  struct ospf_lsa *lsa)
     453             : {
     454         316 :         struct ospf_neighbor *onbr;
     455         316 :         struct route_node *rn;
     456         316 :         int retx_flag;
     457             : 
     458         316 :         if (IS_DEBUG_OSPF_EVENT)
     459         316 :                 zlog_debug(
     460             :                         "%s: considering int %s (%s), INBR(%pI4), LSA[%s] AGE %u",
     461             :                         __func__, IF_NAME(oi), ospf_get_name(oi->ospf),
     462             :                         inbr ? &inbr->router_id : NULL, dump_lsa_key(lsa),
     463             :                         ntohs(lsa->data->ls_age));
     464             : 
     465         316 :         if (!ospf_if_is_enable(oi))
     466             :                 return 0;
     467             : 
     468             :         /* Remember if new LSA is added to a retransmit list. */
     469         316 :         retx_flag = 0;
     470             : 
     471             :         /* Each of the neighbors attached to this interface are examined,
     472             :            to determine whether they must receive the new LSA.  The following
     473             :            steps are executed for each neighbor: */
     474        1028 :         for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
     475         712 :                 struct ospf_lsa *ls_req;
     476             : 
     477         712 :                 if (rn->info == NULL)
     478         198 :                         continue;
     479             : 
     480         514 :                 onbr = rn->info;
     481         514 :                 if (IS_DEBUG_OSPF_EVENT)
     482         514 :                         zlog_debug(
     483             :                                 "%s: considering nbr %pI4 via %s (%s), state: %s",
     484             :                                 __func__, &onbr->router_id, IF_NAME(oi),
     485             :                                 ospf_get_name(oi->ospf),
     486             :                                 lookup_msg(ospf_nsm_state_msg, onbr->state,
     487             :                                            NULL));
     488             : 
     489             :                 /* If the neighbor is in a lesser state than Exchange, it
     490             :                    does not participate in flooding, and the next neighbor
     491             :                    should be examined. */
     492         514 :                 if (onbr->state < NSM_Exchange)
     493         373 :                         continue;
     494             : 
     495             :                 /* If the adjacency is not yet full (neighbor state is
     496             :                    Exchange or Loading), examine the Link state request
     497             :                    list associated with this adjacency.  If there is an
     498             :                    instance of the new LSA on the list, it indicates that
     499             :                    the neighboring router has an instance of the LSA
     500             :                    already.  Compare the new LSA to the neighbor's copy: */
     501         141 :                 if (onbr->state < NSM_Full) {
     502          34 :                         if (IS_DEBUG_OSPF_EVENT)
     503          34 :                                 zlog_debug(
     504             :                                         "%s: adj to onbr %pI4 is not Full (%s)",
     505             :                                         __func__, &onbr->router_id,
     506             :                                         lookup_msg(ospf_nsm_state_msg,
     507             :                                                    onbr->state, NULL));
     508          68 :                         ls_req = ospf_ls_request_lookup(onbr, lsa);
     509          34 :                         if (ls_req != NULL) {
     510          20 :                                 int ret;
     511             : 
     512          20 :                                 ret = ospf_lsa_more_recent(ls_req, lsa);
     513             :                                 /* The new LSA is less recent. */
     514          20 :                                 if (ret > 0)
     515           0 :                                         continue;
     516             :                                 /* The two copies are the same instance, then
     517             :                                    delete
     518             :                                    the LSA from the Link state request list. */
     519          20 :                                 else if (ret == 0) {
     520          20 :                                         ospf_ls_request_delete(onbr, ls_req);
     521          20 :                                         ospf_check_nbr_loading(onbr);
     522          20 :                                         continue;
     523             :                                 }
     524             :                                 /* The new LSA is more recent.  Delete the LSA
     525             :                                    from the Link state request list. */
     526             :                                 else {
     527           0 :                                         ospf_ls_request_delete(onbr, ls_req);
     528           0 :                                         ospf_check_nbr_loading(onbr);
     529             :                                 }
     530             :                         }
     531             :                 }
     532             : 
     533         121 :                 if (IS_OPAQUE_LSA(lsa->data->type)) {
     534           0 :                         if (!CHECK_FLAG(onbr->options, OSPF_OPTION_O)) {
     535           0 :                                 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     536           0 :                                         zlog_debug(
     537             :                                                 "%s: Skipping neighbor %s via %pI4 -- Not Opaque-capable.",
     538             :                                                 __func__, IF_NAME(oi),
     539             :                                                 &onbr->router_id);
     540           0 :                                 continue;
     541             :                         }
     542             :                 }
     543             : 
     544             :  /* If the new LSA was received from this neighbor,
     545             :     examine the next neighbor. */
     546         121 :                 if (inbr) {
     547             :                         /*
     548             :                          * Triggered by LSUpd message parser "ospf_ls_upd ()".
     549             :                          * E.g., all LSAs handling here is received via network.
     550             :                          */
     551          56 :                         if (IPV4_ADDR_SAME(&inbr->router_id,
     552             :                                            &onbr->router_id)) {
     553          38 :                                 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     554           0 :                                         zlog_debug(
     555             :                                                 "%s: Skipping neighbor %s via %pI4 -- inbr == onbr.",
     556             :                                                 __func__, IF_NAME(oi),
     557             :                                                 &inbr->router_id);
     558          38 :                                 continue;
     559             :                         }
     560             :                 } else {
     561             :                         /*
     562             :                          * Triggered by MaxAge remover, so far.
     563             :                          * NULL "inbr" means flooding starts from this node.
     564             :                          */
     565          65 :                         if (IPV4_ADDR_SAME(&lsa->data->adv_router,
     566             :                                            &onbr->router_id)) {
     567           0 :                                 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     568           0 :                                         zlog_debug(
     569             :                                                 "%s: Skipping neighbor %s via %pI4 -- lsah->adv_router == onbr.",
     570             :                                                 __func__, IF_NAME(oi),
     571             :                                                 &onbr->router_id);
     572           0 :                                 continue;
     573             :                         }
     574             :                 }
     575             : 
     576             :                 /* Add the new LSA to the Link state retransmission list
     577             :                    for the adjacency. The LSA will be retransmitted
     578             :                    at intervals until an acknowledgment is seen from
     579             :                    the neighbor. */
     580          83 :                 ospf_ls_retransmit_add(onbr, lsa);
     581          83 :                 retx_flag = 1;
     582             :         }
     583             : 
     584             :         /* If in the previous step, the LSA was NOT added to any of
     585             :            the Link state retransmission lists, there is no need to
     586             :            flood the LSA out the interface. */
     587         316 :         if (retx_flag == 0) {
     588         242 :                 return (inbr && inbr->oi == oi);
     589             :         }
     590             : 
     591             :         /* if we've received the lsa on this interface we need to perform
     592             :            additional checking */
     593          74 :         if (inbr && (inbr->oi == oi)) {
     594             :                 /* If the new LSA was received on this interface, and it was
     595             :                    received from either the Designated Router or the Backup
     596             :                    Designated Router, chances are that all the neighbors have
     597             :                    received the LSA already. */
     598          16 :                 if (NBR_IS_DR(inbr) || NBR_IS_BDR(inbr)) {
     599          10 :                         if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     600           0 :                                 zlog_debug("%s: DR/BDR NOT SEND to int %s (%s)",
     601             :                                            __func__, IF_NAME(oi),
     602             :                                            ospf_get_name(oi->ospf));
     603          10 :                         return 1;
     604             :                 }
     605             : 
     606             :                 /* If the new LSA was received on this interface, and the
     607             :                    interface state is Backup, examine the next interface.  The
     608             :                    Designated Router will do the flooding on this interface.
     609             :                    However, if the Designated Router fails the router will
     610             :                    end up retransmitting the updates. */
     611             : 
     612           6 :                 if (oi->state == ISM_Backup) {
     613           1 :                         if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     614           0 :                                 zlog_debug(
     615             :                                         "%s: ISM_Backup NOT SEND to int %s (%s)",
     616             :                                         __func__, IF_NAME(oi),
     617             :                                         ospf_get_name(oi->ospf));
     618           1 :                         return 1;
     619             :                 }
     620             :         }
     621             : 
     622             :         /* The LSA must be flooded out the interface. Send a Link State
     623             :            Update packet (including the new LSA as contents) out the
     624             :            interface.  The LSA's LS age must be incremented by InfTransDelay
     625             :            (which       must be > 0) when it is copied into the outgoing Link
     626             :            State Update packet (until the LS age field reaches the maximum
     627             :            value of MaxAge). */
     628          63 :         if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     629           0 :                 zlog_debug("%s: DR/BDR sending upd to int %s (%s)", __func__,
     630             :                            IF_NAME(oi), ospf_get_name(oi->ospf));
     631             : 
     632             :         /*  RFC2328  Section 13.3
     633             :             On non-broadcast networks, separate Link State Update
     634             :             packets must be sent, as unicasts, to each adjacent neighbor
     635             :             (i.e., those in state Exchange or greater).  The destination
     636             :             IP addresses for these packets are the neighbors' IP
     637             :             addresses.   */
     638          63 :         if (oi->type == OSPF_IFTYPE_NBMA) {
     639           0 :                 struct ospf_neighbor *nbr;
     640             : 
     641           0 :                 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
     642           0 :                         nbr = rn->info;
     643             : 
     644           0 :                         if (!nbr)
     645           0 :                                 continue;
     646           0 :                         if (nbr != oi->nbr_self && nbr->state >= NSM_Exchange)
     647           0 :                                 ospf_ls_upd_send_lsa(nbr, lsa,
     648             :                                                      OSPF_SEND_PACKET_DIRECT);
     649             :                 }
     650             :         } else
     651             :                 /* Optimization: for P2MP interfaces,
     652             :                    don't send back out the incoming interface immediately,
     653             :                    allow time to rx multicast ack to the rx'ed (multicast)
     654             :                    update */
     655          63 :                 if (retx_flag != 1 ||
     656           0 :                     oi->type != OSPF_IFTYPE_POINTOMULTIPOINT || inbr == NULL ||
     657           0 :                     oi != inbr->oi)
     658          63 :                 ospf_ls_upd_send_lsa(oi->nbr_self, lsa,
     659             :                                      OSPF_SEND_PACKET_INDIRECT);
     660             : 
     661             :         return 0;
     662             : }
     663             : 
     664         168 : int ospf_flood_through_area(struct ospf_area *area, struct ospf_neighbor *inbr,
     665             :                             struct ospf_lsa *lsa)
     666             : {
     667         168 :         struct listnode *node, *nnode;
     668         168 :         struct ospf_interface *oi;
     669         168 :         int lsa_ack_flag = 0;
     670             : 
     671         168 :         assert(area);
     672             :         /* All other types are specific to a single area (Area A).  The
     673             :            eligible interfaces are all those interfaces attaching to the
     674             :            Area A.  If Area A is the backbone, this includes all the virtual
     675             :            links.  */
     676         604 :         for (ALL_LIST_ELEMENTS(area->oiflist, node, nnode, oi)) {
     677         268 :                 if (area->area_id.s_addr != OSPF_AREA_BACKBONE
     678          95 :                     && oi->type == OSPF_IFTYPE_VIRTUALLINK)
     679           0 :                         continue;
     680             : 
     681         268 :                 if ((lsa->data->type == OSPF_OPAQUE_LINK_LSA)
     682           0 :                     && (lsa->oi != oi)) {
     683             :                         /*
     684             :                          * Link local scoped Opaque-LSA should only be flooded
     685             :                          * for the link on which the LSA has received.
     686             :                          */
     687           0 :                         if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     688           0 :                                 zlog_debug(
     689             :                                         "Type-9 Opaque-LSA: lsa->oi(%p) != oi(%p)",
     690             :                                         (void *)lsa->oi, (void *)oi);
     691           0 :                         continue;
     692             :                 }
     693             : 
     694         268 :                 if (ospf_flood_through_interface(oi, inbr, lsa))
     695         268 :                         lsa_ack_flag = 1;
     696             :         }
     697             : 
     698         168 :         return (lsa_ack_flag);
     699             : }
     700             : 
     701          22 : int ospf_flood_through_as(struct ospf *ospf, struct ospf_neighbor *inbr,
     702             :                           struct ospf_lsa *lsa)
     703             : {
     704          22 :         struct listnode *node;
     705          22 :         struct ospf_area *area;
     706          22 :         int lsa_ack_flag;
     707             : 
     708          22 :         lsa_ack_flag = 0;
     709             : 
     710             :         /* The incoming LSA is type 5 or type 7  (AS-EXTERNAL or AS-NSSA )
     711             : 
     712             :           Divert the Type-5 LSA's to all non-NSSA/STUB areas
     713             : 
     714             :           Divert the Type-7 LSA's to all NSSA areas
     715             : 
     716             :            AS-external-LSAs are flooded throughout the entire AS, with the
     717             :            exception of stub areas (see Section 3.6).  The eligible
     718             :            interfaces are all the router's interfaces, excluding virtual
     719             :            links and those interfaces attaching to stub areas.  */
     720             : 
     721          22 :         if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) /* Translated from 7  */
     722           0 :                 if (IS_DEBUG_OSPF_NSSA)
     723           0 :                         zlog_debug("Flood/AS: NSSA TRANSLATED LSA");
     724             : 
     725          71 :         for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
     726          27 :                 int continue_flag = 0;
     727          27 :                 struct listnode *if_node;
     728          27 :                 struct ospf_interface *oi;
     729             : 
     730          27 :                 switch (area->external_routing) {
     731             :                 /* Don't send AS externals into stub areas.  Various types
     732             :                    of support for partial stub areas can be implemented
     733             :                    here.  NSSA's will receive Type-7's that have areas
     734             :                    matching the originl LSA. */
     735           0 :                 case OSPF_AREA_NSSA: /* Sending Type 5 or 7 into NSSA area */
     736             :                                      /* Type-7, flood NSSA area */
     737           0 :                         if (lsa->data->type == OSPF_AS_NSSA_LSA
     738           0 :                             && area == lsa->area)
     739             :                                 /* We will send it. */
     740             :                                 continue_flag = 0;
     741             :                         else
     742             :                                 continue_flag = 1; /* Skip this NSSA area for
     743             :                                                       Type-5's et al */
     744             :                         break;
     745             : 
     746             :                 case OSPF_AREA_TYPE_MAX:
     747             :                 case OSPF_AREA_STUB:
     748             :                         continue_flag = 1; /* Skip this area. */
     749             :                         break;
     750             : 
     751          27 :                 case OSPF_AREA_DEFAULT:
     752             :                 default:
     753             :                         /* No Type-7 into normal area */
     754          27 :                         if (lsa->data->type == OSPF_AS_NSSA_LSA)
     755             :                                 continue_flag = 1; /* skip Type-7 */
     756             :                         else
     757             :                                 continue_flag = 0; /* Do this area. */
     758             :                         break;
     759             :                 }
     760             : 
     761             :                 /* Do continue for above switch.  Saves a big if then mess */
     762           0 :                 if (continue_flag)
     763           0 :                         continue; /* main for-loop */
     764             : 
     765             :                 /* send to every interface in this area */
     766             : 
     767         102 :                 for (ALL_LIST_ELEMENTS_RO(area->oiflist, if_node, oi)) {
     768             :                         /* Skip virtual links */
     769          48 :                         if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
     770          48 :                                 if (ospf_flood_through_interface(oi, inbr,
     771             :                                                                  lsa)) /* lsa */
     772          48 :                                         lsa_ack_flag = 1;
     773             :                 }
     774             :         } /* main area for-loop */
     775             : 
     776          22 :         return (lsa_ack_flag);
     777             : }
     778             : 
     779          58 : int ospf_flood_through(struct ospf *ospf, struct ospf_neighbor *inbr,
     780             :                        struct ospf_lsa *lsa)
     781             : {
     782          58 :         int lsa_ack_flag = 0;
     783             : 
     784             :         /* Type-7 LSA's for NSSA are flooded throughout the AS here, and
     785             :            upon return are updated in the LSDB for Type-7's.  Later,
     786             :            re-fresh will re-send them (and also, if ABR, packet code will
     787             :            translate to Type-5's)
     788             : 
     789             :            As usual, Type-5 LSA's (if not DISCARDED because we are STUB or
     790             :            NSSA) are flooded throughout the AS, and are updated in the
     791             :            global table.  */
     792             :         /*
     793             :          * At the common sub-sub-function "ospf_flood_through_interface()",
     794             :          * a parameter "inbr" will be used to distinguish the called context
     795             :          * whether the given LSA was received from the neighbor, or the
     796             :          * flooding for the LSA starts from this node (e.g. the LSA was self-
     797             :          * originated, or the LSA is going to be flushed from routing domain).
     798             :          *
     799             :          * So, for consistency reasons, this function "ospf_flood_through()"
     800             :          * should also allow the usage that the given "inbr" parameter to be
     801             :          * NULL. If we do so, corresponding AREA parameter should be referred
     802             :          * by "lsa->area", instead of "inbr->oi->area".
     803             :          */
     804          58 :         switch (lsa->data->type) {
     805          14 :         case OSPF_AS_EXTERNAL_LSA: /* Type-5 */
     806             :         case OSPF_OPAQUE_AS_LSA:
     807          14 :                 lsa_ack_flag = ospf_flood_through_as(ospf, inbr, lsa);
     808          14 :                 break;
     809             :         /* Type-7 Only received within NSSA, then flooded */
     810           0 :         case OSPF_AS_NSSA_LSA:
     811             :                 /* Any P-bit was installed with the Type-7. */
     812             : 
     813           0 :                 if (IS_DEBUG_OSPF_NSSA)
     814           0 :                         zlog_debug("%s: LOCAL NSSA FLOOD of Type-7.", __func__);
     815             :         /* Fallthrough */
     816             :         default:
     817          44 :                 lsa_ack_flag = ospf_flood_through_area(lsa->area, inbr, lsa);
     818          44 :                 break;
     819             :         }
     820             : 
     821             :         /* always need to send ack when incoming intf is PTP or P2MP */
     822          58 :         if (inbr != NULL && (inbr->oi->type == OSPF_IFTYPE_POINTOMULTIPOINT ||
     823             :                              inbr->oi->type == OSPF_IFTYPE_POINTOPOINT))
     824          58 :                 lsa_ack_flag = 1;
     825             : 
     826          58 :         return (lsa_ack_flag);
     827             : }
     828             : 
     829             : 
     830             : /* Management functions for neighbor's Link State Request list. */
     831          20 : void ospf_ls_request_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
     832             : {
     833             :         /*
     834             :          * We cannot make use of the newly introduced callback function
     835             :          * "lsdb->new_lsa_hook" to replace debug output below, just because
     836             :          * it seems no simple and smart way to pass neighbor information to
     837             :          * the common function "ospf_lsdb_add()" -- endo.
     838             :          */
     839          20 :         if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     840           0 :                 zlog_debug("RqstL(%lu)++, NBR(%pI4(%s)), LSA[%s]",
     841             :                            ospf_ls_request_count(nbr),
     842             :                            &nbr->router_id,
     843             :                            ospf_get_name(nbr->oi->ospf), dump_lsa_key(lsa));
     844             : 
     845          20 :         ospf_lsdb_add(&nbr->ls_req, lsa);
     846          20 : }
     847             : 
     848          71 : unsigned long ospf_ls_request_count(struct ospf_neighbor *nbr)
     849             : {
     850          71 :         return ospf_lsdb_count_all(&nbr->ls_req);
     851             : }
     852             : 
     853          34 : int ospf_ls_request_isempty(struct ospf_neighbor *nbr)
     854             : {
     855          34 :         return ospf_lsdb_isempty(&nbr->ls_req);
     856             : }
     857             : 
     858             : /* Remove LSA from neighbor's ls-request list. */
     859          20 : void ospf_ls_request_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
     860             : {
     861          20 :         if (nbr->ls_req_last == lsa) {
     862           8 :                 ospf_lsa_unlock(&nbr->ls_req_last);
     863           8 :                 nbr->ls_req_last = NULL;
     864             :         }
     865             : 
     866          20 :         if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */
     867           0 :                 zlog_debug("RqstL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
     868             :                            ospf_ls_request_count(nbr),
     869             :                            &nbr->router_id,
     870             :                            ospf_get_name(nbr->oi->ospf), dump_lsa_key(lsa));
     871             : 
     872          20 :         ospf_lsdb_delete(&nbr->ls_req, lsa);
     873          20 : }
     874             : 
     875             : /* Remove all LSA from neighbor's ls-requenst list. */
     876           0 : void ospf_ls_request_delete_all(struct ospf_neighbor *nbr)
     877             : {
     878           0 :         ospf_lsa_unlock(&nbr->ls_req_last);
     879           0 :         nbr->ls_req_last = NULL;
     880           0 :         ospf_lsdb_delete_all(&nbr->ls_req);
     881           0 : }
     882             : 
     883             : /* Lookup LSA from neighbor's ls-request list. */
     884          53 : struct ospf_lsa *ospf_ls_request_lookup(struct ospf_neighbor *nbr,
     885             :                                         struct ospf_lsa *lsa)
     886             : {
     887          53 :         return ospf_lsdb_lookup(&nbr->ls_req, lsa);
     888             : }
     889             : 
     890          28 : struct ospf_lsa *ospf_ls_request_new(struct lsa_header *lsah)
     891             : {
     892          28 :         struct ospf_lsa *new;
     893             : 
     894          28 :         new = ospf_lsa_new_and_data(OSPF_LSA_HEADER_SIZE);
     895          28 :         memcpy(new->data, lsah, OSPF_LSA_HEADER_SIZE);
     896             : 
     897          28 :         return new;
     898             : }
     899             : 
     900             : 
     901             : /* Management functions for neighbor's ls-retransmit list. */
     902          71 : unsigned long ospf_ls_retransmit_count(struct ospf_neighbor *nbr)
     903             : {
     904          71 :         return ospf_lsdb_count_all(&nbr->ls_rxmt);
     905             : }
     906             : 
     907           0 : unsigned long ospf_ls_retransmit_count_self(struct ospf_neighbor *nbr,
     908             :                                             int lsa_type)
     909             : {
     910           0 :         return ospf_lsdb_count_self(&nbr->ls_rxmt, lsa_type);
     911             : }
     912             : 
     913           8 : int ospf_ls_retransmit_isempty(struct ospf_neighbor *nbr)
     914             : {
     915           8 :         return ospf_lsdb_isempty(&nbr->ls_rxmt);
     916             : }
     917             : 
     918             : /* Add LSA to be retransmitted to neighbor's ls-retransmit list. */
     919          83 : void ospf_ls_retransmit_add(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
     920             : {
     921          83 :         struct ospf_lsa *old;
     922             : 
     923         166 :         old = ospf_ls_retransmit_lookup(nbr, lsa);
     924             : 
     925          83 :         if (ospf_lsa_more_recent(old, lsa) < 0) {
     926          80 :                 if (old) {
     927           0 :                         old->retransmit_counter--;
     928           0 :                         if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     929           0 :                                 zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
     930             :                                            ospf_ls_retransmit_count(nbr),
     931             :                                            &nbr->router_id,
     932             :                                            ospf_get_name(nbr->oi->ospf),
     933             :                                            dump_lsa_key(old));
     934           0 :                         ospf_lsdb_delete(&nbr->ls_rxmt, old);
     935             :                 }
     936          80 :                 lsa->retransmit_counter++;
     937             :                 /*
     938             :                  * We cannot make use of the newly introduced callback function
     939             :                  * "lsdb->new_lsa_hook" to replace debug output below, just
     940             :                  * because
     941             :                  * it seems no simple and smart way to pass neighbor information
     942             :                  * to
     943             :                  * the common function "ospf_lsdb_add()" -- endo.
     944             :                  */
     945          80 :                 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
     946           0 :                         zlog_debug("RXmtL(%lu)++, NBR(%pI4(%s)), LSA[%s]",
     947             :                                    ospf_ls_retransmit_count(nbr),
     948             :                                    &nbr->router_id,
     949             :                                    ospf_get_name(nbr->oi->ospf),
     950             :                                    dump_lsa_key(lsa));
     951          80 :                 ospf_lsdb_add(&nbr->ls_rxmt, lsa);
     952             :         }
     953          83 : }
     954             : 
     955             : /* Remove LSA from neibghbor's ls-retransmit list. */
     956          80 : void ospf_ls_retransmit_delete(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
     957             : {
     958          80 :         if (ospf_ls_retransmit_lookup(nbr, lsa)) {
     959          80 :                 lsa->retransmit_counter--;
     960          80 :                 if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) /* -- endo. */
     961           0 :                         zlog_debug("RXmtL(%lu)--, NBR(%pI4(%s)), LSA[%s]",
     962             :                                    ospf_ls_retransmit_count(nbr),
     963             :                                    &nbr->router_id,
     964             :                                    ospf_get_name(nbr->oi->ospf),
     965             :                                    dump_lsa_key(lsa));
     966          80 :                 ospf_lsdb_delete(&nbr->ls_rxmt, lsa);
     967             :         }
     968          80 : }
     969             : 
     970             : /* Clear neighbor's ls-retransmit list. */
     971           5 : void ospf_ls_retransmit_clear(struct ospf_neighbor *nbr)
     972             : {
     973           5 :         struct ospf_lsdb *lsdb;
     974           5 :         int i;
     975             : 
     976           5 :         lsdb = &nbr->ls_rxmt;
     977             : 
     978          60 :         for (i = OSPF_MIN_LSA; i < OSPF_MAX_LSA; i++) {
     979          55 :                 struct route_table *table = lsdb->type[i].db;
     980          55 :                 struct route_node *rn;
     981          55 :                 struct ospf_lsa *lsa;
     982             : 
     983          72 :                 for (rn = route_top(table); rn; rn = route_next(rn))
     984          17 :                         if ((lsa = rn->info) != NULL)
     985          13 :                                 ospf_ls_retransmit_delete(nbr, lsa);
     986             :         }
     987             : 
     988           5 :         ospf_lsa_unlock(&nbr->ls_req_last);
     989           5 :         nbr->ls_req_last = NULL;
     990           5 : }
     991             : 
     992             : /* Lookup LSA from neighbor's ls-retransmit list. */
     993         800 : struct ospf_lsa *ospf_ls_retransmit_lookup(struct ospf_neighbor *nbr,
     994             :                                            struct ospf_lsa *lsa)
     995             : {
     996         262 :         return ospf_lsdb_lookup(&nbr->ls_rxmt, lsa);
     997             : }
     998             : 
     999         347 : static void ospf_ls_retransmit_delete_nbr_if(struct ospf_interface *oi,
    1000             :                                              struct ospf_lsa *lsa)
    1001             : {
    1002         347 :         struct route_node *rn;
    1003         347 :         struct ospf_neighbor *nbr;
    1004         347 :         struct ospf_lsa *lsr;
    1005             : 
    1006         347 :         if (ospf_if_is_enable(oi))
    1007        1076 :                 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
    1008             :                         /* If LSA find in LS-retransmit list, then remove it. */
    1009         729 :                         nbr = rn->info;
    1010             : 
    1011         729 :                         if (!nbr)
    1012         191 :                                 continue;
    1013             : 
    1014         538 :                         lsr = ospf_ls_retransmit_lookup(nbr, lsa);
    1015             : 
    1016             :                         /* If LSA find in ls-retransmit list, remove it. */
    1017         538 :                         if (lsr != NULL &&
    1018          48 :                             lsr->data->ls_seqnum == lsa->data->ls_seqnum)
    1019          32 :                                 ospf_ls_retransmit_delete(nbr, lsr);
    1020             :                 }
    1021         347 : }
    1022             : 
    1023         232 : void ospf_ls_retransmit_delete_nbr_area(struct ospf_area *area,
    1024             :                                         struct ospf_lsa *lsa)
    1025             : {
    1026         232 :         struct listnode *node, *nnode;
    1027         232 :         struct ospf_interface *oi;
    1028             : 
    1029         799 :         for (ALL_LIST_ELEMENTS(area->oiflist, node, nnode, oi))
    1030         335 :                 ospf_ls_retransmit_delete_nbr_if(oi, lsa);
    1031         232 : }
    1032             : 
    1033          20 : void ospf_ls_retransmit_delete_nbr_as(struct ospf *ospf, struct ospf_lsa *lsa)
    1034             : {
    1035          20 :         struct listnode *node, *nnode;
    1036          20 :         struct ospf_interface *oi;
    1037             : 
    1038          52 :         for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi))
    1039          12 :                 ospf_ls_retransmit_delete_nbr_if(oi, lsa);
    1040          20 : }
    1041             : 
    1042             : 
    1043             : /* Sets ls_age to MaxAge and floods throu the area.
    1044             :    When we implement ASE routing, there will be another function
    1045             :    flushing an LSA from the whole domain. */
    1046          27 : void ospf_lsa_flush_area(struct ospf_lsa *lsa, struct ospf_area *area)
    1047             : {
    1048          27 :         struct ospf *ospf = area->ospf;
    1049             : 
    1050          27 :         if (ospf_lsa_is_self_originated(ospf, lsa)
    1051          27 :             && ospf->gr_info.restart_in_progress) {
    1052           0 :                 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
    1053           0 :                         zlog_debug(
    1054             :                                 "%s:LSA[Type%d:%pI4]: Graceful Restart in progress -- not flushing self-originated LSA",
    1055             :                                 ospf_get_name(ospf), lsa->data->type,
    1056             :                                 &lsa->data->id);
    1057           0 :                 return;
    1058             :         }
    1059             : 
    1060             :         /* Reset the lsa origination time such that it gives
    1061             :            more time for the ACK to be received and avoid
    1062             :            retransmissions */
    1063          27 :         lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
    1064          27 :         if (IS_DEBUG_OSPF_EVENT)
    1065          27 :                 zlog_debug("%s: MaxAge set to LSA[%s]", __func__,
    1066             :                            dump_lsa_key(lsa));
    1067          27 :         monotime(&lsa->tv_recv);
    1068          27 :         lsa->tv_orig = lsa->tv_recv;
    1069          27 :         ospf_flood_through_area(area, NULL, lsa);
    1070          27 :         ospf_lsa_maxage(ospf, lsa);
    1071             : }
    1072             : 
    1073           4 : void ospf_lsa_flush_as(struct ospf *ospf, struct ospf_lsa *lsa)
    1074             : {
    1075           4 :         if (ospf_lsa_is_self_originated(ospf, lsa)
    1076           4 :             && ospf->gr_info.restart_in_progress) {
    1077           0 :                 if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
    1078           0 :                         zlog_debug(
    1079             :                                 "%s:LSA[Type%d:%pI4]: Graceful Restart in progress -- not flushing self-originated LSA",
    1080             :                                 ospf_get_name(ospf), lsa->data->type,
    1081             :                                 &lsa->data->id);
    1082           0 :                 return;
    1083             :         }
    1084             : 
    1085             :         /* Reset the lsa origination time such that it gives
    1086             :            more time for the ACK to be received and avoid
    1087             :            retransmissions */
    1088           4 :         lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
    1089           4 :         if (IS_DEBUG_OSPF_EVENT)
    1090           4 :                 zlog_debug("%s: MaxAge set to LSA[%s]", __func__,
    1091             :                            dump_lsa_key(lsa));
    1092           4 :         monotime(&lsa->tv_recv);
    1093           4 :         lsa->tv_orig = lsa->tv_recv;
    1094           4 :         ospf_flood_through_as(ospf, NULL, lsa);
    1095           4 :         ospf_lsa_maxage(ospf, lsa);
    1096             : }
    1097             : 
    1098          13 : void ospf_lsa_flush(struct ospf *ospf, struct ospf_lsa *lsa)
    1099             : {
    1100          13 :         lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
    1101             : 
    1102          13 :         switch (lsa->data->type) {
    1103           9 :         case OSPF_ROUTER_LSA:
    1104             :         case OSPF_NETWORK_LSA:
    1105             :         case OSPF_SUMMARY_LSA:
    1106             :         case OSPF_ASBR_SUMMARY_LSA:
    1107             :         case OSPF_AS_NSSA_LSA:
    1108             :         case OSPF_OPAQUE_LINK_LSA:
    1109             :         case OSPF_OPAQUE_AREA_LSA:
    1110           9 :                 ospf_lsa_flush_area(lsa, lsa->area);
    1111           9 :                 break;
    1112           4 :         case OSPF_AS_EXTERNAL_LSA:
    1113             :         case OSPF_OPAQUE_AS_LSA:
    1114           4 :                 ospf_lsa_flush_as(ospf, lsa);
    1115           4 :                 break;
    1116           0 :         default:
    1117           0 :                 zlog_info("%s: Unknown LSA type %u", __func__, lsa->data->type);
    1118           0 :                 break;
    1119             :         }
    1120          13 : }

Generated by: LCOV version v1.16-topotato