]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospf6d/ospf6_lsdb.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / ospf6d / ospf6_lsdb.c
index 18f121e3a2bc4f6405081bd09ac87b17f6df4ddd..0221102b59f5ce20e78355e6189435e526c676e0 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>
@@ -30,6 +15,7 @@
 #include "ospf6_proto.h"
 #include "ospf6_lsa.h"
 #include "ospf6_lsdb.h"
+#include "ospf6_asbr.h"
 #include "ospf6_route.h"
 #include "ospf6d.h"
 #include "bitfield.h"
@@ -91,6 +77,16 @@ static void _lsdb_count_assert(struct ospf6_lsdb *lsdb)
 #define ospf6_lsdb_count_assert(t) ((void) 0)
 #endif /*DEBUG*/
 
+static inline void ospf6_lsdb_stats_update(struct ospf6_lsa *lsa,
+                                          struct ospf6_lsdb *lsdb, int count)
+{
+       uint16_t stat = ntohs(lsa->header->type) & OSPF6_LSTYPE_FCODE_MASK;
+
+       if (stat >= OSPF6_LSTYPE_SIZE)
+               stat = OSPF6_LSTYPE_UNKNOWN;
+       lsdb->stats[stat] += count;
+}
+
 void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
 {
        struct prefix_ipv6 key;
@@ -111,6 +107,7 @@ void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
 
        if (!old) {
                lsdb->count++;
+               ospf6_lsdb_stats_update(lsa, lsdb, 1);
 
                if (OSPF6_LSA_IS_MAXAGE(lsa)) {
                        if (lsdb->hook_remove)
@@ -120,6 +117,8 @@ void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
                                (*lsdb->hook_add)(lsa);
                }
        } else {
+               lsa->retrans_count = old->retrans_count;
+
                if (OSPF6_LSA_IS_CHANGED(old, lsa)) {
                        if (OSPF6_LSA_IS_MAXAGE(lsa)) {
                                if (lsdb->hook_remove) {
@@ -160,6 +159,7 @@ void ospf6_lsdb_remove(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb)
 
        node->info = NULL;
        lsdb->count--;
+       ospf6_lsdb_stats_update(lsa, lsdb, -1);
 
        if (lsdb->hook_remove)
                (*lsdb->hook_remove)(lsa);
@@ -194,6 +194,28 @@ struct ospf6_lsa *ospf6_lsdb_lookup(uint16_t type, uint32_t id,
        return (struct ospf6_lsa *)node->info;
 }
 
+struct ospf6_lsa *ospf6_find_external_lsa(struct ospf6 *ospf6, struct prefix *p)
+{
+       struct ospf6_route *match;
+       struct ospf6_lsa *lsa;
+       struct ospf6_external_info *info;
+
+       match = ospf6_route_lookup(p, ospf6->external_table);
+       if (match == NULL) {
+               if (IS_OSPF6_DEBUG_ASBR)
+                       zlog_debug("No such route %pFX to withdraw", p);
+
+               return NULL;
+       }
+
+       info = match->route_option;
+       assert(info);
+
+       lsa = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL),
+                               htonl(info->id), ospf6->router_id, ospf6->lsdb);
+       return lsa;
+}
+
 struct ospf6_lsa *ospf6_lsdb_lookup_next(uint16_t type, uint32_t id,
                                         uint32_t adv_router,
                                         struct ospf6_lsdb *lsdb)
@@ -320,9 +342,17 @@ int ospf6_lsdb_maxage_remover(struct ospf6_lsdb *lsdb)
        struct ospf6_lsa *lsa, *lsanext;
 
        for (ALL_LSDB(lsdb, lsa, lsanext)) {
-               if (!OSPF6_LSA_IS_MAXAGE(lsa))
+               if (!OSPF6_LSA_IS_MAXAGE(lsa)) {
+                       if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type))
+                               zlog_debug("Not MaxAge %s", lsa->name);
                        continue;
+               }
+
                if (lsa->retrans_count != 0) {
+                       if (IS_OSPF6_DEBUG_LSA_TYPE(lsa->header->type))
+                               zlog_debug("Remove MaxAge %s retrans_count %d",
+                                          lsa->name, lsa->retrans_count);
+
                        reschedule = 1;
                        continue;
                }
@@ -341,6 +371,7 @@ int ospf6_lsdb_maxage_remover(struct ospf6_lsdb *lsdb)
                        THREAD_OFF(lsa->refresh);
                        thread_execute(master, ospf6_lsa_refresh, lsa, 0);
                } else {
+                       zlog_debug("calling ospf6_lsdb_remove %s", lsa->name);
                        ospf6_lsdb_remove(lsa, lsdb);
                }
        }