--- /dev/null
+/*
+ * 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);
+}
* 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
#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 */
#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
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;
}
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);
}