]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospf6d/ospf6_neighbor.c
Merge pull request #13019 from rgirada/ospf_type3_fix
[mirror_frr.git] / ospf6d / ospf6_neighbor.c
index 439b94c9af039d76f3b6c3bcdcfa968bdc265fd9..5ab5a49a4b3d7932493915776dbed44cc824b030 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2003 Yasuhiro Ohara
- *
- * 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>
@@ -106,6 +91,23 @@ struct ospf6_neighbor *ospf6_area_neighbor_lookup(struct ospf6_area *area,
        return NULL;
 }
 
+static void ospf6_neighbor_clear_ls_lists(struct ospf6_neighbor *on)
+{
+       struct ospf6_lsa *lsa;
+       struct ospf6_lsa *lsanext;
+
+       ospf6_lsdb_remove_all(on->summary_list);
+       if (on->last_ls_req) {
+               ospf6_lsa_unlock(on->last_ls_req);
+               on->last_ls_req = NULL;
+       }
+       ospf6_lsdb_remove_all(on->request_list);
+       for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
+               ospf6_decrement_retrans_count(lsa);
+               ospf6_lsdb_remove(lsa, on->retrans_list);
+       }
+}
+
 /* create ospf6_neighbor */
 struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
                                             struct ospf6_interface *oi)
@@ -147,14 +149,7 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id,
 
 void ospf6_neighbor_delete(struct ospf6_neighbor *on)
 {
-       struct ospf6_lsa *lsa, *lsanext;
-
-       ospf6_lsdb_remove_all(on->summary_list);
-       ospf6_lsdb_remove_all(on->request_list);
-       for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
-               ospf6_decrement_retrans_count(lsa);
-               ospf6_lsdb_remove(lsa, on->retrans_list);
-       }
+       ospf6_neighbor_clear_ls_lists(on);
 
        ospf6_lsdb_remove_all(on->dbdesc_list);
        ospf6_lsdb_remove_all(on->lsupdate_list);
@@ -201,10 +196,12 @@ static void ospf6_neighbor_state_change(uint8_t next_state,
 
        /* log */
        if (IS_OSPF6_DEBUG_NEIGHBOR(STATE)) {
-               zlog_debug("Neighbor state change %s: [%s]->[%s] (%s)",
-                          on->name, ospf6_neighbor_state_str[prev_state],
-                          ospf6_neighbor_state_str[next_state],
-                          ospf6_neighbor_event_string(event));
+               zlog_debug(
+                       "Neighbor state change %s (Router-ID: %pI4): [%s]->[%s] (%s)",
+                       on->name, &on->router_id,
+                       ospf6_neighbor_state_str[prev_state],
+                       ospf6_neighbor_state_str[next_state],
+                       ospf6_neighbor_event_string(event));
        }
 
        /* Optionally notify about adjacency changes */
@@ -214,10 +211,13 @@ static void ospf6_neighbor_state_change(uint8_t next_state,
                           OSPF6_LOG_ADJACENCY_DETAIL)
                || (next_state == OSPF6_NEIGHBOR_FULL)
                || (next_state < prev_state)))
-               zlog_notice("AdjChg: Nbr %s: %s -> %s (%s)", on->name,
-                           ospf6_neighbor_state_str[prev_state],
-                           ospf6_neighbor_state_str[next_state],
-                           ospf6_neighbor_event_string(event));
+               zlog_notice(
+                       "AdjChg: Nbr %pI4(%s) on %s: %s -> %s (%s)",
+                       &on->router_id,
+                       vrf_id_to_name(on->ospf6_if->interface->vrf->vrf_id),
+                       on->name, ospf6_neighbor_state_str[prev_state],
+                       ospf6_neighbor_state_str[next_state],
+                       ospf6_neighbor_event_string(event));
 
        if (prev_state == OSPF6_NEIGHBOR_FULL
            || next_state == OSPF6_NEIGHBOR_FULL) {
@@ -339,12 +339,7 @@ void negotiation_done(struct thread *thread)
                zlog_debug("Neighbor Event %s: *NegotiationDone*", on->name);
 
        /* clear ls-list */
-       ospf6_lsdb_remove_all(on->summary_list);
-       ospf6_lsdb_remove_all(on->request_list);
-       for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
-               ospf6_decrement_retrans_count(lsa);
-               ospf6_lsdb_remove(lsa, on->retrans_list);
-       }
+       ospf6_neighbor_clear_ls_lists(on);
 
        /* Interface scoped LSAs */
        for (ALL_LSDB(on->ospf6_if->lsdb, lsa, lsanext)) {
@@ -464,7 +459,6 @@ void loading_done(struct thread *thread)
 void adj_ok(struct thread *thread)
 {
        struct ospf6_neighbor *on;
-       struct ospf6_lsa *lsa, *lsanext;
 
        on = (struct ospf6_neighbor *)THREAD_ARG(thread);
        assert(on);
@@ -486,19 +480,13 @@ void adj_ok(struct thread *thread)
        } else if (on->state >= OSPF6_NEIGHBOR_EXSTART && !need_adjacency(on)) {
                ospf6_neighbor_state_change(OSPF6_NEIGHBOR_TWOWAY, on,
                                            OSPF6_NEIGHBOR_EVENT_ADJ_OK);
-               ospf6_lsdb_remove_all(on->summary_list);
-               ospf6_lsdb_remove_all(on->request_list);
-               for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
-                       ospf6_decrement_retrans_count(lsa);
-                       ospf6_lsdb_remove(lsa, on->retrans_list);
-               }
+               ospf6_neighbor_clear_ls_lists(on);
        }
 }
 
 void seqnumber_mismatch(struct thread *thread)
 {
        struct ospf6_neighbor *on;
-       struct ospf6_lsa *lsa, *lsanext;
 
        on = (struct ospf6_neighbor *)THREAD_ARG(thread);
        assert(on);
@@ -515,12 +503,7 @@ void seqnumber_mismatch(struct thread *thread)
        SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
        SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
 
-       ospf6_lsdb_remove_all(on->summary_list);
-       ospf6_lsdb_remove_all(on->request_list);
-       for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
-               ospf6_decrement_retrans_count(lsa);
-               ospf6_lsdb_remove(lsa, on->retrans_list);
-       }
+       ospf6_neighbor_clear_ls_lists(on);
 
        THREAD_OFF(on->thread_send_dbdesc);
        on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
@@ -532,7 +515,6 @@ void seqnumber_mismatch(struct thread *thread)
 void bad_lsreq(struct thread *thread)
 {
        struct ospf6_neighbor *on;
-       struct ospf6_lsa *lsa, *lsanext;
 
        on = (struct ospf6_neighbor *)THREAD_ARG(thread);
        assert(on);
@@ -549,12 +531,7 @@ void bad_lsreq(struct thread *thread)
        SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_MBIT);
        SET_FLAG(on->dbdesc_bits, OSPF6_DBDESC_IBIT);
 
-       ospf6_lsdb_remove_all(on->summary_list);
-       ospf6_lsdb_remove_all(on->request_list);
-       for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
-               ospf6_decrement_retrans_count(lsa);
-               ospf6_lsdb_remove(lsa, on->retrans_list);
-       }
+       ospf6_neighbor_clear_ls_lists(on);
 
        THREAD_OFF(on->thread_send_dbdesc);
        on->dbdesc_seqnum++; /* Incr seqnum as per RFC2328, sec 10.3 */
@@ -567,7 +544,6 @@ void bad_lsreq(struct thread *thread)
 void oneway_received(struct thread *thread)
 {
        struct ospf6_neighbor *on;
-       struct ospf6_lsa *lsa, *lsanext;
 
        on = (struct ospf6_neighbor *)THREAD_ARG(thread);
        assert(on);
@@ -582,12 +558,7 @@ void oneway_received(struct thread *thread)
                                    OSPF6_NEIGHBOR_EVENT_ONEWAY_RCVD);
        thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
 
-       ospf6_lsdb_remove_all(on->summary_list);
-       ospf6_lsdb_remove_all(on->request_list);
-       for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
-               ospf6_decrement_retrans_count(lsa);
-               ospf6_lsdb_remove(lsa, on->retrans_list);
-       }
+       ospf6_neighbor_clear_ls_lists(on);
 
        THREAD_OFF(on->thread_send_dbdesc);
        THREAD_OFF(on->thread_send_lsreq);