]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_packet.c
ospfd: use ospf_get_name() wherever possible
[mirror_frr.git] / ospfd / ospf_packet.c
index 580eee13cf0815117d1934f5f9030c7caddf25fd..23817d2eab2dd023a0d73bd2cb37a4345738bd2c 100644 (file)
@@ -54,7 +54,7 @@
 #include "ospfd/ospf_dump.h"
 #include "ospfd/ospf_errors.h"
 #include "ospfd/ospf_zebra.h"
-#include "ospfd/ospf_gr_helper.h"
+#include "ospfd/ospf_gr.h"
 
 /*
  * OSPF Fragmentation / fragmented writes
@@ -1031,7 +1031,7 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
        old_state = nbr->state;
 
        /* Add event to thread. */
-       OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_PacketReceived);
+       OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_HelloReceived);
 
        /*  RFC2328  Section 9.5.1
            If the router is not eligible to become Designated Router,
@@ -1081,6 +1081,25 @@ static void ospf_hello(struct ip *iph, struct ospf_header *ospfh,
                return;
        }
 
+       if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
+               /* As per the GR Conformance Test Case 7.2. Section 3
+                * "Also, if X was the Designated Router on network segment S
+                * when the helping relationship began, Y maintains X as the
+                * Designated Router until the helping relationship is
+                * terminated."
+                * When I am helper for this neighbor, I should not trigger the
+                * ISM Events. Also Intentionally not setting the priority and
+                * other fields so that when the neighbor exits the Grace
+                * period, it can handle if there is any change before GR and
+                * after GR. */
+               if (IS_DEBUG_OSPF_GR)
+                       zlog_debug(
+                               "%s, Neighbor is under GR Restart, hence ignoring the ISM Events",
+                               __PRETTY_FUNCTION__);
+
+               return;
+       }
+
        /* If neighbor itself declares DR and no BDR exists,
           cause event BackupSeen */
        if (IPV4_ADDR_SAME(&nbr->address.u.prefix4, &hello->d_router))
@@ -1356,14 +1375,10 @@ static void ospf_db_desc(struct ip *iph, struct ospf_header *ospfh,
                UNSET_FLAG(dd->options, OSPF_OPTION_O);
        }
 
-       /* Add event to thread. */
-       OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_PacketReceived);
-
        if (CHECK_FLAG(oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
                zlog_info(
                        "%s:Packet[DD]: Neighbor %pI4 state is %s, seq_num:0x%x, local:0x%x",
-                       (oi->ospf->name) ? oi->ospf->name : VRF_DEFAULT_NAME,
-                       &nbr->router_id,
+                       ospf_get_name(oi->ospf), &nbr->router_id,
                        lookup_msg(ospf_nsm_state_msg, nbr->state, NULL),
                        ntohl(dd->dd_seqnum), nbr->dd_seqnum);
 
@@ -1601,9 +1616,6 @@ static void ospf_ls_req(struct ip *iph, struct ospf_header *ospfh,
                return;
        }
 
-       /* Add event to thread. */
-       OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_PacketReceived);
-
        /* Neighbor State should be Exchange or later. */
        if (nbr->state != NSM_Exchange && nbr->state != NSM_Loading
            && nbr->state != NSM_Full) {
@@ -1848,9 +1860,6 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
                return;
        }
 
-       /* Add event to thread. */
-       OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_PacketReceived);
-
        /* Check neighbor state. */
        if (nbr->state < NSM_Exchange) {
                if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
@@ -2025,9 +2034,11 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
 
                                ospf_ls_ack_send(nbr, lsa);
 
-                               ospf_opaque_self_originated_lsa_received(nbr,
-                                                                        lsa);
-                               continue;
+                               if (!ospf->gr_info.restart_in_progress) {
+                                       ospf_opaque_self_originated_lsa_received(
+                                               nbr, lsa);
+                                       continue;
+                               }
                        }
                }
 
@@ -2087,11 +2098,10 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
                if (current == NULL
                    || (ret = ospf_lsa_more_recent(current, lsa)) < 0) {
                        /* CVE-2017-3224 */
-                       if (current && (lsa->data->ls_seqnum ==
-                                       htonl(OSPF_MAX_SEQUENCE_NUMBER)
-                                       && !IS_LSA_MAXAGE(lsa))) {
+                       if (current && (IS_LSA_MAX_SEQ(current))
+                           && (IS_LSA_MAX_SEQ(lsa)) && !IS_LSA_MAXAGE(lsa)) {
                                zlog_debug(
-                                       "Link State Update[%s]: has Max Seq but not MaxAge. Dropping it",
+                                       "Link State Update[%s]: has Max Seq and higher checksum but not MaxAge. Dropping it",
                                        dump_lsa_key(lsa));
 
                                DISCARD_LSA(lsa, 4);
@@ -2213,6 +2223,9 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
 
        assert(listcount(lsas) == 0);
        list_delete(&lsas);
+
+       if (ospf->gr_info.restart_in_progress)
+               ospf_gr_check_lsdb_consistency(oi->ospf, oi->area);
 }
 
 /* OSPF Link State Acknowledgment message read -- RFC2328 Section 13.7. */
@@ -2233,9 +2246,6 @@ static void ospf_ls_ack(struct ip *iph, struct ospf_header *ospfh,
                return;
        }
 
-       /* Add event to thread. */
-       OSPF_NSM_EVENT_SCHEDULE(nbr, NSM_PacketReceived);
-
        if (nbr->state < NSM_Exchange) {
                if (IS_DEBUG_OSPF(nsm, NSM_EVENTS))
                        zlog_debug(
@@ -2266,8 +2276,10 @@ static void ospf_ls_ack(struct ip *iph, struct ospf_header *ospfh,
 
                lsr = ospf_ls_retransmit_lookup(nbr, lsa);
 
-               if (lsr != NULL && ospf_lsa_more_recent(lsr, lsa) == 0)
+               if (lsr != NULL && ospf_lsa_more_recent(lsr, lsa) == 0) {
                        ospf_ls_retransmit_delete(nbr, lsr);
+                       ospf_check_and_gen_init_seq_lsa(oi, lsa);
+               }
 
                lsa->data = NULL;
                ospf_lsa_discard(lsa);
@@ -3575,14 +3587,13 @@ static int ospf_make_ls_upd(struct ospf_interface *oi, struct list *update,
                struct lsa_header *lsah;
                uint16_t ls_age;
 
-               if (IS_DEBUG_OSPF_EVENT)
-                       zlog_debug("ospf_make_ls_upd: List Iteration %d",
-                                  count);
-
                lsa = listgetdata(node);
-
                assert(lsa->data);
 
+               if (IS_DEBUG_OSPF_EVENT)
+                       zlog_debug("%s: List Iteration %d LSA[%s]", __func__,
+                                  count, dump_lsa_key(lsa));
+
                /* Will it fit? Minimum it has to fit atleast one */
                if ((length + delta + ntohs(lsa->data->length) > size_noauth) &&
                                (count > 0))
@@ -3867,9 +3878,8 @@ void ospf_db_desc_send(struct ospf_neighbor *nbr)
        if (CHECK_FLAG(oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
                zlog_info(
                        "%s:Packet[DD]: %pI4 DB Desc send with seqnum:%x , flags:%x",
-                       (oi->ospf->name) ? oi->ospf->name : VRF_DEFAULT_NAME,
-                       &nbr->router_id, nbr->dd_seqnum,
-                       nbr->dd_flags);
+                       ospf_get_name(oi->ospf), &nbr->router_id,
+                       nbr->dd_seqnum, nbr->dd_flags);
 }
 
 /* Re-send Database Description. */
@@ -3887,9 +3897,8 @@ void ospf_db_desc_resend(struct ospf_neighbor *nbr)
        if (CHECK_FLAG(oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
                zlog_info(
                        "%s:Packet[DD]: %pI4 DB Desc resend with seqnum:%x , flags:%x",
-                       (oi->ospf->name) ? oi->ospf->name : VRF_DEFAULT_NAME,
-                       &nbr->router_id, nbr->dd_seqnum,
-                       nbr->dd_flags);
+                       ospf_get_name(oi->ospf), &nbr->router_id,
+                       nbr->dd_seqnum, nbr->dd_flags);
 }
 
 /* Send Link State Request. */
@@ -4264,7 +4273,7 @@ void ospf_ls_ack_send(struct ospf_neighbor *nbr, struct ospf_lsa *lsa)
        struct ospf_interface *oi = nbr->oi;
 
        if (IS_GRACE_LSA(lsa)) {
-               if (IS_DEBUG_OSPF_GR_HELPER)
+               if (IS_DEBUG_OSPF_GR)
                        zlog_debug("%s, Sending GRACE ACK to Restarter.",
                                   __func__);
        }