]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospfd: ospf GR helper initialization
authorrgirada <rgirada@vmware.com>
Fri, 21 Aug 2020 17:03:05 +0000 (10:03 -0700)
committerrgirada <rgirada@vmware.com>
Tue, 22 Sep 2020 07:02:33 +0000 (00:02 -0700)
Description:
1. Graceful restart helper init/de-init.
2. Defining dedicated memory for helper.

Signed-off-by: Rajesh Girada <rgirada@vmware.com>
ospfd/ospf_dump.c
ospfd/ospf_gr_helper.c [new file with mode: 0644]
ospfd/ospf_gr_helper.h
ospfd/ospf_memory.c
ospfd/ospf_memory.h
ospfd/ospf_neighbor.c
ospfd/ospfd.c
ospfd/subdir.am

index e8798e023e2c50324db25f5b8236db717c10a0d2..66caf844368f8b3328b94270492f0a81daf17177 100644 (file)
@@ -55,6 +55,7 @@ unsigned long conf_debug_ospf_ext = 0;
 unsigned long conf_debug_ospf_sr = 0;
 unsigned long conf_debug_ospf_defaultinfo = 0;
 unsigned long conf_debug_ospf_ldp_sync = 0;
+unsigned long conf_debug_ospf_gr = 0;
 
 /* Enable debug option variables -- valid only session. */
 unsigned long term_debug_ospf_packet[5] = {0, 0, 0, 0, 0};
@@ -69,6 +70,7 @@ unsigned long term_debug_ospf_ext = 0;
 unsigned long term_debug_ospf_sr = 0;
 unsigned long term_debug_ospf_defaultinfo;
 unsigned long term_debug_ospf_ldp_sync;
+unsigned long term_debug_ospf_gr = 0;
 
 const char *ospf_redist_string(unsigned int route_type)
 {
diff --git a/ospfd/ospf_gr_helper.c b/ospfd/ospf_gr_helper.c
new file mode 100644 (file)
index 0000000..8bb740a
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * OSPF Graceful Restart helper functions.
+ *
+ * Copyright (C) 2020-21 Vmware, Inc.
+ * Rajesh Kumar Girada
+ *
+ * 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>
+
+#include "thread.h"
+#include "memory.h"
+#include "linklist.h"
+#include "prefix.h"
+#include "if.h"
+#include "table.h"
+#include "vty.h"
+#include "filter.h"
+#include "log.h"
+#include "jhash.h"
+
+#include "ospfd/ospfd.h"
+#include "ospfd/ospf_interface.h"
+#include "ospfd/ospf_asbr.h"
+#include "ospfd/ospf_lsa.h"
+#include "ospfd/ospf_lsdb.h"
+#include "ospfd/ospf_neighbor.h"
+#include "ospfd/ospf_spf.h"
+#include "ospfd/ospf_flood.h"
+#include "ospfd/ospf_route.h"
+#include "ospfd/ospf_zebra.h"
+#include "ospfd/ospf_dump.h"
+#include "ospfd/ospf_errors.h"
+#include "ospfd/ospf_nsm.h"
+#include "ospfd/ospf_ism.h"
+#include "ospfd/ospf_gr_helper.h"
+
+
+static unsigned int ospf_enable_rtr_hash_key(const void *data)
+{
+       const struct advRtr *rtr = data;
+
+       return jhash_1word(rtr->advRtrAddr.s_addr, 0);
+}
+
+static bool ospf_enable_rtr_hash_cmp(const void *d1, const void *d2)
+{
+       const struct advRtr *rtr1 = (struct advRtr *)d1;
+       const struct advRtr *rtr2 = (struct advRtr *)d2;
+
+       return (rtr1->advRtrAddr.s_addr == rtr2->advRtrAddr.s_addr);
+}
+
+static void *ospf_enable_rtr_hash_alloc(void *p)
+{
+       struct advRtr *rid;
+
+       rid = XCALLOC(MTYPE_OSPF_GR_HELPER, sizeof(struct advRtr));
+       rid->advRtrAddr.s_addr = ((struct in_addr *)p)->s_addr;
+
+       return rid;
+}
+
+static void ospf_disable_rtr_hash_free(void *rtr)
+{
+       XFREE(MTYPE_OSPF_GR_HELPER, rtr);
+}
+
+static void ospf_enable_rtr_hash_destroy(struct ospf *ospf)
+{
+       if (ospf->enable_rtr_list == NULL)
+               return;
+
+       hash_clean(ospf->enable_rtr_list, ospf_disable_rtr_hash_free);
+       hash_free(ospf->enable_rtr_list);
+       ospf->enable_rtr_list = NULL;
+}
+
+/*
+ * Initialize GR helper config data structures.
+ *
+ * OSPF
+ *    OSPF pointer
+ *
+ * Returns:
+ *    Nothing
+ */
+void ospf_gr_helper_init(struct ospf *ospf)
+{
+       if (IS_DEBUG_OSPF_GR_HELPER)
+               zlog_debug("%s, GR Helper init.", __PRETTY_FUNCTION__);
+
+       ospf->is_helper_supported = OSPF_FALSE;
+       ospf->strict_lsa_check = OSPF_TRUE;
+       ospf->only_planned_restart = OSPF_FALSE;
+       ospf->supported_grace_time = OSPF_MAX_GRACE_INTERVAL;
+       ospf->last_exit_reason = OSPF_GR_HELPER_EXIT_NONE;
+       ospf->active_restarter_cnt = 0;
+
+       ospf->enable_rtr_list =
+               hash_create(ospf_enable_rtr_hash_key, ospf_enable_rtr_hash_cmp,
+                           "OSPF enable router hash");
+}
+
+/*
+ * De-Initialize GR helper config data structures.
+ *
+ * OSPF
+ *    OSPF pointer
+ *
+ * Returns:
+ *    Nothing
+ */
+void ospf_gr_helper_stop(struct ospf *ospf)
+{
+
+       if (IS_DEBUG_OSPF_GR_HELPER)
+               zlog_debug("%s, GR helper deinit.", __PRETTY_FUNCTION__);
+
+       ospf_enable_rtr_hash_destroy(ospf);
+}
index 8cf9f3ab76f2c74b5f8495e55088b5e816c211e5..ac41243253a528ce95185914d2fee663e4fd578d 100644 (file)
@@ -21,8 +21,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#ifndef _ZEBRA_OSPF_HELPER_H
-#define _ZEBRA_OSPF_HELPER_H
+#ifndef _ZEBRA_OSPF_GR_HELPER_H
+#define _ZEBRA_OSPF_GR_HELPER_H
 
 #define OSPF_GR_NOT_HELPER 0
 #define OSPF_GR_ACTIVE_HELPER 1
@@ -151,4 +151,7 @@ struct advRtr {
 #define OSPF_GR_SUCCESS 1
 #define OSPF_GR_FAILURE 0
 #define OSPF_GR_INVALID -1
-#endif /* _ZEBRA_OSPF_HELPER_H */
+
+extern void ospf_gr_helper_init(struct ospf *);
+extern void ospf_gr_helper_stop(struct ospf *ospf);
+#endif /* _ZEBRA_OSPF_GR_HELPER_H */
index c4dc0136edaeae7b512ba9cd8e9fe5360c83cf14..d102fddf86e4a5c2c37a4cc4ab7bbb1bf31556dd 100644 (file)
@@ -56,3 +56,4 @@ DEFINE_MTYPE(OSPFD, OSPF_ROUTER_INFO, "OSPF Router Info parameters")
 DEFINE_MTYPE(OSPFD, OSPF_PCE_PARAMS, "OSPF PCE parameters")
 DEFINE_MTYPE(OSPFD, OSPF_EXT_PARAMS, "OSPF Extended parameters")
 DEFINE_MTYPE(OSPFD, OSPF_SR_PARAMS, "OSPF Segment Routing parameters")
+DEFINE_MTYPE(OSPFD, OSPF_GR_HELPER, "OSPF Graceful Restart Helper")
index 861de64c25d3f0de9869af16832026c6308b5208..58f23aa9c739d7c0a0e624aa5542a13a3bce76e4 100644 (file)
@@ -55,5 +55,6 @@ DECLARE_MTYPE(OSPF_ROUTER_INFO)
 DECLARE_MTYPE(OSPF_PCE_PARAMS)
 DECLARE_MTYPE(OSPF_SR_PARAMS)
 DECLARE_MTYPE(OSPF_EXT_PARAMS)
+DECLARE_MTYPE(OSPF_GR_HELPER)
 
 #endif /* _QUAGGA_OSPF_MEMORY_H */
index 46dfc505ef0f0475968d7419571246632c56c04d..b0ff40afe5d94e296cc496431bebb3fb3e72258f 100644 (file)
@@ -43,6 +43,7 @@
 #include "ospfd/ospf_flood.h"
 #include "ospfd/ospf_dump.h"
 #include "ospfd/ospf_bfd.h"
+#include "ospfd/ospf_gr_helper.h"
 
 /* Fill in the the 'key' as appropriate to retrieve the entry for nbr
  * from the ospf_interface's nbrs table. Indexed by interface address
@@ -99,6 +100,14 @@ struct ospf_neighbor *ospf_nbr_new(struct ospf_interface *oi)
        nbr->crypt_seqnum = 0;
 
        ospf_bfd_info_nbr_create(oi, nbr);
+
+       /* Initialize GR Helper info*/
+       nbr->gr_helper_info.recvd_grace_period = 0;
+       nbr->gr_helper_info.actual_grace_period = 0;
+       nbr->gr_helper_info.gr_helper_status = OSPF_GR_NOT_HELPER;
+       nbr->gr_helper_info.helper_exit_reason = OSPF_GR_HELPER_EXIT_NONE;
+       nbr->gr_helper_info.gr_restart_reason = OSPF_GR_UNKNOWN_RESTART;
+
        return nbr;
 }
 
@@ -142,6 +151,8 @@ void ospf_nbr_free(struct ospf_neighbor *nbr)
 
        ospf_bfd_info_free(&nbr->bfd_info);
 
+       OSPF_NSM_TIMER_OFF(nbr->gr_helper_info.t_grace_timer);
+
        nbr->oi = NULL;
        XFREE(MTYPE_OSPF_NEIGHBOR, nbr);
 }
index cc5839a810c442b347403035ddc17e3366b3d646..aa063a0759af436ef6c3116c2dfd5e4d8e20cb4f 100644 (file)
@@ -59,6 +59,7 @@
 #include "ospfd/ospf_flood.h"
 #include "ospfd/ospf_ase.h"
 #include "ospfd/ospf_ldp_sync.h"
+#include "ospfd/ospf_gr_helper.h"
 
 
 DEFINE_QOBJ_TYPE(ospf)
@@ -309,6 +310,8 @@ static struct ospf *ospf_new(unsigned short instance, const char *name)
 
        new->proactive_arp = OSPF_PROACTIVE_ARP_DEFAULT;
 
+       ospf_gr_helper_init(new);
+
        QOBJ_REG(new, ospf);
 
        new->fd = -1;
@@ -766,6 +769,9 @@ static void ospf_finish_final(struct ospf *ospf)
        list_delete(&ospf->areas);
        list_delete(&ospf->oi_write_q);
 
+       /* Reset GR helper data structers */
+       ospf_gr_helper_stop(ospf);
+
        close(ospf->fd);
        stream_free(ospf->ibuf);
        ospf->fd = -1;
index 236b76a1f7ba1aa57a70b863b34ee9602853152a..2a59a625219925a1b016cc984e7d9c65327ebea9 100644 (file)
@@ -56,6 +56,7 @@ ospfd_libfrrospf_a_SOURCES = \
        ospfd/ospf_vty.c \
        ospfd/ospf_zebra.c \
        ospfd/ospfd.c \
+       ospfd/ospf_gr_helper.c \
        # end
 
 if OSPFD
@@ -77,6 +78,7 @@ endif
 clippy_scan += \
        ospfd/ospf_vty.c \
        ospfd/ospf_ldp_sync.c \
+       ospfd/ospf_dump.c \
        # end
 
 noinst_HEADERS += \
@@ -101,6 +103,7 @@ noinst_HEADERS += \
        ospfd/ospf_te.h \
        ospfd/ospf_vty.h \
        ospfd/ospf_zebra.h \
+       ospfd/ospf_gr_helper.h \
        # end
 
 ospfd_ospfd_LDADD = ospfd/libfrrospf.a lib/libfrr.la $(LIBCAP) $(LIBM)