]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospf6d: Helper functionality changes
authorrgirada <rgirada@vmware.com>
Mon, 28 Jun 2021 11:55:27 +0000 (04:55 -0700)
committerrgirada <rgirada@vmware.com>
Tue, 10 Aug 2021 09:57:23 +0000 (02:57 -0700)
Description:
1. changes to process GRACE LSA packet.
2. Validation changes to enter Helper role.
3. Helper functionality during graceful restart.

Signed-off-by: Rajesh Girada <rgirada@vmware.com>
ospf6d/ospf6_flood.c
ospf6d/ospf6_gr.h [new file with mode: 0644]
ospf6d/ospf6_gr_helper.c
ospf6d/ospf6_gr_helper.h [deleted file]
ospf6d/ospf6_message.c
ospf6d/ospf6_neighbor.c
ospf6d/ospf6_top.c
ospf6d/subdir.am

index 3d52597161766aae744af26ecc132ba199231b0e..77c2ad16281256f644feae967d1723fa9f9c80c9 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "ospf6_flood.h"
 #include "ospf6_nssa.h"
+#include "ospf6_gr.h"
 
 unsigned char conf_debug_ospf6_flooding;
 
@@ -999,6 +1000,30 @@ void ospf6_receive_lsa(struct ospf6_neighbor *from,
                    != from->ospf6_if->area->ospf6->router_id)
                        ospf6_flood(from, new);
 
+               /* Received Grace-LSA */
+               if (IS_GRACE_LSA(new)) {
+                       struct ospf6 *ospf6;
+
+                       ospf6 = ospf6_get_by_lsdb(new);
+
+                       assert(ospf6);
+
+                       if (IS_DEBUG_OSPF6_GR_HELPER)
+                               zlog_debug(
+                                       "%s, Received a GraceLSA from router %d",
+                                       __PRETTY_FUNCTION__,
+                                       new->header->adv_router);
+
+                       if (ospf6_process_grace_lsa(ospf6, new, from)
+                           == OSPF6_GR_NOT_HELPER) {
+                               if (IS_DEBUG_OSPF6_GR_HELPER)
+                                       zlog_debug(
+                                               "%s, Not moving to HELPER role, So dicarding GraceLSA",
+                                               __PRETTY_FUNCTION__);
+                               return;
+                       }
+               }
+
                /* (d), installing lsdb, which may cause routing
                        table calculation (replacing database copy) */
                ospf6_install_lsa(new);
diff --git a/ospf6d/ospf6_gr.h b/ospf6d/ospf6_gr.h
new file mode 100644 (file)
index 0000000..6336363
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * OSPF6 Graceful Retsart helper functions.
+ *
+ * Copyright (C) 2021-22 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
+ */
+
+#ifndef OSPF6_GR_H
+#define OSPF6_GR_H
+
+#define OSPF6_GR_NOT_HELPER 0
+#define OSPF6_GR_ACTIVE_HELPER 1
+
+#define OSPF6_GR_HELPER_NO_LSACHECK 0
+#define OSPF6_GR_HELPER_LSACHECK 1
+
+#define OSPF6_MAX_GRACE_INTERVAL 1800
+#define OSPF6_MIN_GRACE_INTERVAL 1
+
+/* Debug option */
+extern unsigned char conf_debug_ospf6_gr;
+
+#define OSPF6_DEBUG_GR_HELPER 0x01
+
+#define OSPF6_DEBUG_GR_HELPER_ON()                                             \
+       (conf_debug_ospf6_gr |= OSPF6_DEBUG_GR_HELPER)
+
+#define OSPF6_DEBUG_GR_HELPER_OFF()                                            \
+       (conf_debug_ospf6_gr &= ~OSPF6_DEBUG_GR_HELPER)
+
+#define IS_DEBUG_OSPF6_GR_HELPER conf_debug_ospf6_gr
+
+
+enum ospf6_helper_exit_reason {
+       OSPF6_GR_HELPER_EXIT_NONE = 0,
+       OSPF6_GR_HELPER_INPROGRESS,
+       OSPF6_GR_HELPER_TOPO_CHG,
+       OSPF6_GR_HELPER_GRACE_TIMEOUT,
+       OSPF6_GR_HELPER_COMPLETED
+};
+
+enum ospf6_gr_restart_reason {
+       OSPF6_GR_UNKNOWN_RESTART = 0,
+       OSPF6_GR_SW_RESTART = 1,
+       OSPF6_GR_SW_UPGRADE = 2,
+       OSPF6_GR_SWITCH_REDUNDANT_CARD = 3,
+       OSPF6_GR_INVALID_REASON_CODE = 4
+};
+
+enum ospf6_gr_helper_rejected_reason {
+       OSPF6_HELPER_REJECTED_NONE,
+       OSPF6_HELPER_SUPPORT_DISABLED,
+       OSPF6_HELPER_NOT_A_VALID_NEIGHBOUR,
+       OSPF6_HELPER_PLANNED_ONLY_RESTART,
+       OSPF6_HELPER_TOPO_CHANGE_RTXMT_LIST,
+       OSPF6_HELPER_LSA_AGE_MORE
+};
+
+#ifdef roundup
+#define ROUNDUP(val, gran) roundup(val, gran)
+#else /* roundup */
+#define ROUNDUP(val, gran) (((val)-1 | (gran)-1) + 1)
+#endif /* roundup */
+
+/*
+ * Generic TLV (type, length, value) macros
+ */
+struct tlv_header {
+       uint16_t type;   /* Type of Value */
+       uint16_t length; /* Length of Value portion only, in bytes */
+};
+
+#define TLV_HDR_SIZE (sizeof(struct tlv_header))
+
+#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t)))
+
+#define TLV_SIZE(tlvh) (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
+
+#define TLV_HDR_TOP(lsah)                                                      \
+       (struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE)
+
+#define TLV_HDR_NEXT(tlvh)                                                     \
+       (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
+
+/* Ref RFC5187 appendex-A */
+/* Grace period TLV */
+#define GRACE_PERIOD_TYPE 1
+#define GRACE_PERIOD_LENGTH 4
+struct grace_tlv_graceperiod {
+       struct tlv_header header;
+       uint32_t interval;
+};
+#define GRACE_PERIOD_TLV_SIZE sizeof(struct grace_tlv_graceperiod)
+
+/* Restart reason TLV */
+#define RESTART_REASON_TYPE 2
+#define RESTART_REASON_LENGTH 1
+struct grace_tlv_restart_reason {
+       struct tlv_header header;
+       uint8_t reason;
+       uint8_t reserved[3];
+};
+#define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct grace_tlv_restart_reason)
+
+#define OSPF6_GRACE_LSA_MIN_SIZE                                               \
+       GRACE_PERIOD_TLV_SIZE + GRACE_RESTART_REASON_TLV_SIZE
+
+struct advRtr {
+       in_addr_t advRtrAddr;
+};
+
+#define OSPF6_HELPER_ENABLE_RTR_COUNT(ospf)                                    \
+       (ospf6->ospf6_helper_cfg.enableRtrList->count)
+
+/* Check , it is a planned restart */
+#define OSPF6_GR_IS_PLANNED_RESTART(reason)                                    \
+       ((reason == OSPF6_GR_SW_RESTART) || (reason == OSPF6_GR_SW_UPGRADE))
+
+/* Check the router is HELPER for current neighbour */
+#define OSPF6_GR_IS_ACTIVE_HELPER(N)                                           \
+       ((N)->gr_helper_info.gr_helper_status == OSPF6_GR_ACTIVE_HELPER)
+
+/* Check the LSA is GRACE LSA */
+#define IS_GRACE_LSA(lsa) (ntohs(lsa->header->type) == OSPF6_LSTYPE_GRACE_LSA)
+
+/* Check neighbour is in FULL state */
+#define IS_NBR_STATE_FULL(nbr) (nbr->state == OSPF6_NEIGHBOR_FULL)
+
+extern const char *ospf6_exit_reason_desc[];
+extern const char *ospf6_restart_reason_desc[];
+extern const char *ospf6_rejected_reason_desc[];
+
+extern void ospf6_gr_helper_init(struct ospf6 *ospf6);
+extern void ospf6_gr_helper_deinit(struct ospf6 *ospf6);
+extern int ospf6_process_grace_lsa(struct ospf6 *ospf6, struct ospf6_lsa *lsa,
+                                  struct ospf6_neighbor *nbr);
+#endif /* OSPF6_GR_H */
index a7a1b7cbabe5c78a705fc5fee502df36fc451c99..d0351711542f0c0891c3de3a6c17ce4b85c12214 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * OSPF6 Graceful Retsart helper functions.
+ * OSPF6 Graceful Restart helper functions.
  *
  * Copyright (C) 2021-22 Vmware, Inc.
  * Rajesh Kumar Girada
@@ -47,7 +47,7 @@
 #include "ospf6_neighbor.h"
 #include "ospf6_intra.h"
 #include "ospf6d.h"
-#include "ospf6_gr_helper.h"
+#include "ospf6_gr.h"
 #include "lib/json.h"
 #ifndef VTYSH_EXTRACT_PL
 #include "ospf6d/ospf6_gr_helper_clippy.c"
@@ -55,7 +55,7 @@
 
 DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_GR_HELPER, "OSPF6 Graceful restart helper");
 
-unsigned char conf_debug_ospf6_gr = 0;
+unsigned char conf_debug_ospf6_gr;
 
 const char *ospf6_exit_reason_desc[] = {
        "Unknown reason",     "Helper inprogress",         "Topology Change",
@@ -119,6 +119,290 @@ static void ospf6_enable_rtr_hash_destroy(struct ospf6 *ospf6)
        ospf6->ospf6_helper_cfg.enable_rtr_list = NULL;
 }
 
+/*
+ * Extracting tlv info from GRACE LSA.
+ *
+ * lsa
+ *   ospf6 grace lsa
+ *
+ * Returns:
+ * interval : grace interval.
+ * reason   : Restarting reason.
+ */
+static int ospf6_extract_grace_lsa_fields(struct ospf6_lsa *lsa,
+                                         uint32_t *interval, uint8_t *reason)
+{
+       struct ospf6_lsa_header *lsah = NULL;
+       struct tlv_header *tlvh = NULL;
+       struct grace_tlv_graceperiod *gracePeriod;
+       struct grace_tlv_restart_reason *grReason;
+       uint16_t length = 0;
+       int sum = 0;
+
+       lsah = (struct ospf6_lsa_header *)lsa->header;
+
+       length = ntohs(lsah->length) - OSPF6_LSA_HEADER_SIZE;
+
+       for (tlvh = TLV_HDR_TOP(lsah); sum < length;
+            tlvh = TLV_HDR_NEXT(tlvh)) {
+               switch (ntohs(tlvh->type)) {
+               case GRACE_PERIOD_TYPE:
+                       gracePeriod = (struct grace_tlv_graceperiod *)tlvh;
+                       *interval = ntohl(gracePeriod->interval);
+                       sum += TLV_SIZE(tlvh);
+
+                       /* Check if grace interval is valid */
+                       if (*interval > OSPF6_MAX_GRACE_INTERVAL
+                           || *interval < OSPF6_MIN_GRACE_INTERVAL)
+                               return OSPF6_FAILURE;
+                       break;
+               case RESTART_REASON_TYPE:
+                       grReason = (struct grace_tlv_restart_reason *)tlvh;
+                       *reason = grReason->reason;
+                       sum += TLV_SIZE(tlvh);
+
+                       if (*reason >= OSPF6_GR_INVALID_REASON_CODE)
+                               return OSPF6_FAILURE;
+                       break;
+               default:
+                       if (IS_DEBUG_OSPF6_GR_HELPER)
+                               zlog_debug(
+                                       "%s, Ignoring unknown TLV type:%d",
+                                       __func__, ntohs(tlvh->type));
+               }
+       }
+
+       return OSPF6_SUCCESS;
+}
+
+/*
+ * Grace timer expiry handler.
+ * HELPER aborts its role at grace timer expiry.
+ *
+ * thread
+ *    thread pointer
+ *
+ * Returns:
+ *    Nothing
+ */
+static int ospf6_handle_grace_timer_expiry(struct thread *thread)
+{
+       struct ospf6_neighbor *nbr = THREAD_ARG(thread);
+
+       nbr->gr_helper_info.t_grace_timer = NULL;
+
+       // ospf6_gr_helper_exit(nbr, OSPF6_GR_HELPER_GRACE_TIMEOUT);
+       return OSPF6_SUCCESS;
+}
+
+/*
+ * API to check any change in the neighbor's
+ * retransmission list.
+ *
+ * nbr
+ *    ospf6 neighbor
+ *
+ * Returns:
+ *    TRUE  - if any change in the lsa.
+ *    FALSE - no change in the lsas.
+ */
+static bool ospf6_check_chg_in_rxmt_list(struct ospf6_neighbor *nbr)
+{
+       struct ospf6_lsa *lsa, *lsanext;
+
+       for (ALL_LSDB(nbr->retrans_list, lsa, lsanext)) {
+               struct ospf6_lsa *lsa_in_db = NULL;
+
+               /* Fetching the same copy of LSA form LSDB to validate the
+                * topochange.
+                */
+               lsa_in_db =
+                       ospf6_lsdb_lookup(lsa->header->type, lsa->header->id,
+                                         lsa->header->adv_router, lsa->lsdb);
+
+               if (lsa_in_db && lsa_in_db->tobe_acknowledged)
+                       return OSPF6_TRUE;
+       }
+
+       return OSPF6_FALSE;
+}
+
+/*
+ * Process Grace LSA.If it is eligible move to HELPER role.
+ * Ref rfc3623 section 3.1 and rfc5187
+ *
+ * ospf
+ *    Ospf6 pointer.
+ *
+ * lsa
+ *    Grace LSA received from RESTARTER.
+ *
+ * restarter
+ *    ospf6 neighbour which requests the router to act as
+ *    HELPER.
+ *
+ * Returns:
+ *    status.
+ *    If supported as HELPER : OSPF_GR_HELPER_INPROGRESS
+ *    If Not supported as HELPER : OSPF_GR_HELPER_NONE
+ */
+int ospf6_process_grace_lsa(struct ospf6 *ospf6, struct ospf6_lsa *lsa,
+                           struct ospf6_neighbor *restarter)
+{
+       uint8_t restart_reason = 0;
+       uint32_t grace_interval = 0;
+       uint32_t actual_grace_interval = 0;
+       struct advRtr lookup;
+       int ret;
+
+       /* Extract the grace lsa packet fields */
+       ret = ospf6_extract_grace_lsa_fields(lsa, &grace_interval,
+                                            &restart_reason);
+       if (ret != OSPF6_SUCCESS) {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug("%s, Wrong Grace LSA packet.",
+                                  __func__);
+               return OSPF6_GR_NOT_HELPER;
+       }
+
+       if (IS_DEBUG_OSPF6_GR_HELPER)
+               zlog_debug(
+                       "%s, Grace LSA received from  %pI4, grace interval:%u, restart reason :%s",
+                       __func__, &restarter->router_id,
+                       grace_interval,
+                       ospf6_restart_reason_desc[restart_reason]);
+
+       /* Verify Helper enabled globally */
+       if (!ospf6->ospf6_helper_cfg.is_helper_supported) {
+               /* Verify Helper support is enabled for the
+                * current neighbour router-id.
+                */
+               lookup.advRtrAddr = restarter->router_id;
+
+               if (!hash_lookup(ospf6->ospf6_helper_cfg.enable_rtr_list,
+                                &lookup)) {
+                       if (IS_DEBUG_OSPF6_GR_HELPER)
+                               zlog_debug(
+                                       "%s, HELPER support is disabled, So not a HELPER",
+                                       __func__);
+                       restarter->gr_helper_info.rejected_reason =
+                               OSPF6_HELPER_SUPPORT_DISABLED;
+                       return OSPF6_GR_NOT_HELPER;
+               }
+       }
+
+       /* Check neighbour is in FULL state and
+        * became a adjacency.
+        */
+       if (!IS_NBR_STATE_FULL(restarter)) {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, This Neighbour %pI6 is not in FULL state.",
+                               __func__, &restarter->linklocal_addr);
+               restarter->gr_helper_info.rejected_reason =
+                       OSPF6_HELPER_NOT_A_VALID_NEIGHBOUR;
+               return OSPF6_GR_NOT_HELPER;
+       }
+
+       /* Based on the restart reason from grace lsa
+        * check the current router is supporting or not
+        */
+       if (ospf6->ospf6_helper_cfg.only_planned_restart
+           && !OSPF6_GR_IS_PLANNED_RESTART(restart_reason)) {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Router supports only planned restarts but received the GRACE LSA due a unplanned restart",
+                               __func__);
+               restarter->gr_helper_info.rejected_reason =
+                       OSPF6_HELPER_PLANNED_ONLY_RESTART;
+               return OSPF6_GR_NOT_HELPER;
+       }
+
+       /* Check the retransmission list of this
+        * neighbour, check any change in lsas.
+        */
+       if (ospf6->ospf6_helper_cfg.strict_lsa_check
+           && restarter->retrans_list->count
+           && ospf6_check_chg_in_rxmt_list(restarter)) {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Changed LSA in Rxmt list.So not Helper.",
+                               __func__);
+               restarter->gr_helper_info.rejected_reason =
+                       OSPF6_HELPER_TOPO_CHANGE_RTXMT_LIST;
+               return OSPF6_GR_NOT_HELPER;
+       }
+
+       /*LSA age must be less than the grace period */
+       if (ntohs(lsa->header->age) >= grace_interval) {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Grace LSA age(%d) is more than the grace interval(%d)",
+                               __func__, lsa->header->age,
+                               grace_interval);
+               restarter->gr_helper_info.rejected_reason =
+                       OSPF6_HELPER_LSA_AGE_MORE;
+               return OSPF6_GR_NOT_HELPER;
+       }
+
+       /* check supported grace period configured
+        * if configured, use this to start the grace
+        * timer otherwise use the interval received
+        * in grace LSA packet.
+        */
+       actual_grace_interval = grace_interval;
+       if (grace_interval > ospf6->ospf6_helper_cfg.supported_grace_time) {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Received grace period %d is larger than supported grace %d",
+                               __func__, grace_interval,
+                               ospf6->ospf6_helper_cfg.supported_grace_time);
+               actual_grace_interval =
+                       ospf6->ospf6_helper_cfg.supported_grace_time;
+       }
+
+       if (OSPF6_GR_IS_ACTIVE_HELPER(restarter)) {
+               if (restarter->gr_helper_info.t_grace_timer)
+                       THREAD_OFF(restarter->gr_helper_info.t_grace_timer);
+
+               if (ospf6->ospf6_helper_cfg.active_restarter_cnt > 0)
+                       ospf6->ospf6_helper_cfg.active_restarter_cnt--;
+
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Router is already acting as a HELPER for this nbr,so restart the grace timer",
+                               __func__);
+       } else {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, This Router becomes a HELPER for the neighbour %pI6",
+                               __func__, &restarter->linklocal_addr);
+       }
+
+       /* Became a Helper to the RESTART neighbour.
+        * change the helper status.
+        */
+       restarter->gr_helper_info.gr_helper_status = OSPF6_GR_ACTIVE_HELPER;
+       restarter->gr_helper_info.recvd_grace_period = grace_interval;
+       restarter->gr_helper_info.actual_grace_period = actual_grace_interval;
+       restarter->gr_helper_info.gr_restart_reason = restart_reason;
+       restarter->gr_helper_info.rejected_reason = OSPF6_HELPER_REJECTED_NONE;
+
+       /* Increment the active restart nbr count */
+       ospf6->ospf6_helper_cfg.active_restarter_cnt++;
+
+       if (IS_DEBUG_OSPF6_GR_HELPER)
+               zlog_debug("%s, Grace timer started.interval:%u",
+                          __func__, actual_grace_interval);
+
+       /* Start the grace timer */
+       thread_add_timer(master, ospf6_handle_grace_timer_expiry, restarter,
+                        actual_grace_interval,
+                        &restarter->gr_helper_info.t_grace_timer);
+
+       return OSPF6_GR_ACTIVE_HELPER;
+}
+
 /* Debug commands */
 DEFPY(debug_ospf6_gr,
       debug_ospf6_gr_cmd,
@@ -136,7 +420,7 @@ DEFPY(debug_ospf6_gr,
 }
 
 /*
- * Initilise GR helper config datastructer.
+ * Initialize GR helper config data structure.
  *
  * ospf6
  *    ospf6 pointer
@@ -147,7 +431,7 @@ DEFPY(debug_ospf6_gr,
 void ospf6_gr_helper_init(struct ospf6 *ospf6)
 {
        if (IS_DEBUG_OSPF6_GR_HELPER)
-               zlog_debug("%s, GR Helper init.", __PRETTY_FUNCTION__);
+               zlog_debug("%s, GR Helper init.", __func__);
 
        ospf6->ospf6_helper_cfg.is_helper_supported = OSPF6_FALSE;
        ospf6->ospf6_helper_cfg.strict_lsa_check = OSPF6_TRUE;
@@ -174,7 +458,7 @@ void ospf6_gr_helper_deinit(struct ospf6 *ospf6)
 {
 
        if (IS_DEBUG_OSPF6_GR_HELPER)
-               zlog_debug("%s, GR helper deinit.", __PRETTY_FUNCTION__);
+               zlog_debug("%s, GR helper deinit.", __func__);
 
        ospf6_enable_rtr_hash_destroy(ospf6);
 }
diff --git a/ospf6d/ospf6_gr_helper.h b/ospf6d/ospf6_gr_helper.h
deleted file mode 100644 (file)
index f09ffa1..0000000
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * OSPF6 Graceful Retsart helper functions.
- *
- * Copyright (C) 2021-22 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
- */
-
-#ifndef OSPF6_GR_HELPER_H
-#define OSPF6_GR_HELPER_H
-
-#define OSPF6_GR_NOT_HELPER 0
-#define OSPF6_GR_ACTIVE_HELPER 1
-
-#define OSPF6_GR_HELPER_NO_LSACHECK 0
-#define OSPF6_GR_HELPER_LSACHECK 1
-
-#define OSPF6_MAX_GRACE_INTERVAL 1800
-#define OSPF6_MIN_GRACE_INTERVAL 1
-
-/* Debug option */
-extern unsigned char conf_debug_ospf6_gr;
-
-#define OSPF6_DEBUG_GR_HELPER 0x01
-
-#define OSPF6_DEBUG_GR_HELPER_ON()                                             \
-       (conf_debug_ospf6_gr |= OSPF6_DEBUG_GR_HELPER)
-
-#define OSPF6_DEBUG_GR_HELPER_OFF()                                            \
-       (conf_debug_ospf6_gr &= ~OSPF6_DEBUG_GR_HELPER)
-
-#define IS_DEBUG_OSPF6_GR_HELPER conf_debug_ospf6_gr
-
-
-enum ospf6_helper_exit_reason {
-       OSPF6_GR_HELPER_EXIT_NONE = 0,
-       OSPF6_GR_HELPER_INPROGRESS,
-       OSPF6_GR_HELPER_TOPO_CHG,
-       OSPF6_GR_HELPER_GRACE_TIMEOUT,
-       OSPF6_GR_HELPER_COMPLETED
-};
-
-enum ospf6_gr_restart_reason {
-       OSPF6_GR_UNKNOWN_RESTART = 0,
-       OSPF6_GR_SW_RESTART = 1,
-       OSPF6_GR_SW_UPGRADE = 2,
-       OSPF6_GR_SWITCH_REDUNDANT_CARD = 3,
-       OSPF6_GR_INVALID_REASON_CODE = 4
-};
-
-enum ospf6_gr_helper_rejected_reason {
-       OSPF6_HELPER_REJECTED_NONE,
-       OSPF6_HELPER_SUPPORT_DISABLED,
-       OSPF6_HELPER_NOT_A_VALID_NEIGHBOUR,
-       OSPF6_HELPER_PLANNED_ONLY_RESTART,
-       OSPF6_HELPER_TOPO_CHANGE_RTXMT_LIST,
-       OSPF6_HELPER_LSA_AGE_MORE
-};
-
-#ifdef roundup
-#define ROUNDUP(val, gran) roundup(val, gran)
-#else /* roundup */
-#define ROUNDUP(val, gran) (((val)-1 | (gran)-1) + 1)
-#endif /* roundup */
-
-/*
- * Generic TLV (type, length, value) macros
- */
-struct tlv_header {
-       uint16_t type;   /* Type of Value */
-       uint16_t length; /* Length of Value portion only, in bytes */
-};
-
-#define TLV_HDR_SIZE (sizeof(struct tlv_header))
-
-#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(uint32_t)))
-
-#define TLV_SIZE(tlvh) (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh))
-
-#define TLV_HDR_TOP(lsah)                                                      \
-       (struct tlv_header *)((char *)(lsah) + OSPF6_LSA_HEADER_SIZE)
-
-#define TLV_HDR_NEXT(tlvh)                                                     \
-       (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh))
-
-/* Ref RFC5187 appendex-A */
-/* Grace period TLV */
-#define GRACE_PERIOD_TYPE 1
-#define GRACE_PERIOD_LENGTH 4
-struct grace_tlv_graceperiod {
-       struct tlv_header header;
-       uint32_t interval;
-};
-#define GRACE_PERIOD_TLV_SIZE sizeof(struct grace_tlv_graceperiod)
-
-/* Restart reason TLV */
-#define RESTART_REASON_TYPE 2
-#define RESTART_REASON_LENGTH 1
-struct grace_tlv_restart_reason {
-       struct tlv_header header;
-       uint8_t reason;
-       uint8_t reserved[3];
-};
-#define GRACE_RESTART_REASON_TLV_SIZE sizeof(struct grace_tlv_restart_reason)
-
-#define OSPF6_GRACE_LSA_MIN_SIZE                                               \
-       GRACE_PERIOD_TLV_SIZE + GRACE_RESTART_REASON_TLV_SIZE
-
-struct advRtr {
-       in_addr_t advRtrAddr;
-};
-
-#define OSPF6_HELPER_ENABLE_RTR_COUNT(ospf)                                    \
-       (ospf6->ospf6_helper_cfg.enableRtrList->count)
-
-/* Check , it is a planned restart */
-#define OSPF6_GR_IS_PLANNED_RESTART(reason)                                    \
-       ((reason == OSPF6_GR_SW_RESTART) || (reason == OSPF6_GR_SW_UPGRADE))
-
-/* Check the router is HELPER for current neighbour */
-#define OSPF6_GR_IS_ACTIVE_HELPER(N)                                           \
-       ((N)->grHelperInfo.grHelper_status == OSPF6_GR_ACTIVE_HELPER)
-
-/* Check the LSA is GRACE LSA */
-#define IS_GRACE_LSA(lsa) (ntohs(lsa->header->type) == OSPF6_LSTYPE_GRACE_LSA)
-
-/* Check neighbour is in FULL state */
-#define IS_NBR_STATE_FULL(nbr) (nbr->state == OSPF6_NEIGHBOR_FULL)
-
-extern const char *ospf6_exit_reason_desc[];
-extern const char *ospf6_restart_reason_desc[];
-extern const char *ospf6_rejected_reason_desc[];
-
-extern void ospf6_gr_helper_init(struct ospf6 *ospf6);
-extern void ospf6_gr_helper_deinit(struct ospf6 *ospf6);
-#endif /* OSPF6_GR_HELPER_H */
index 549f5668b9121c3d46a81521d6417a8a08e51481..a80ec4430fa9f5550dafe2452ee8392e3dd650c5 100644 (file)
@@ -46,7 +46,7 @@
 
 #include "ospf6_flood.h"
 #include "ospf6d.h"
-
+#include "ospf6_gr.h"
 #include <netinet/ip6.h>
 
 DEFINE_MTYPE_STATIC(OSPF6D, OSPF6_MESSAGE, "OSPF6 message");
@@ -84,7 +84,9 @@ const uint16_t ospf6_lsa_minlen[OSPF6_LSTYPE_SIZE] = {
        /* 0x2006 */ 0,
        /* 0x2007 */ OSPF6_AS_EXTERNAL_LSA_MIN_SIZE,
        /* 0x0008 */ OSPF6_LINK_LSA_MIN_SIZE,
-       /* 0x2009 */ OSPF6_INTRA_PREFIX_LSA_MIN_SIZE};
+       /* 0x2009 */ OSPF6_INTRA_PREFIX_LSA_MIN_SIZE,
+       /* 0x200a */ 0,
+       /* 0x000b */ OSPF6_GRACE_LSA_MIN_SIZE};
 
 /* print functions */
 
@@ -512,8 +514,44 @@ static void ospf6_hello_recv(struct in6_addr *src, struct in6_addr *dst,
        thread_execute(master, hello_received, on, 0);
        if (twoway)
                thread_execute(master, twoway_received, on, 0);
-       else
-               thread_execute(master, oneway_received, on, 0);
+       else {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Received oneway hello from RESTARTER so ignore here.",
+                               __PRETTY_FUNCTION__);
+
+               if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) {
+                       /* If the router is DR_OTHER, RESTARTER will not wait
+                        * until it receives the hello from it if it receives
+                        * from DR and BDR.
+                        * So, helper might receives ONE_WAY hello from
+                        * RESTARTER. So not allowing to change the state if it
+                        * receives one_way hellow when it acts as HELPER for
+                        * that specific neighbor.
+                        */
+                       thread_execute(master, oneway_received, on, 0);
+               }
+       }
+
+       if (OSPF6_GR_IS_ACTIVE_HELPER(on)) {
+               /* 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 it is a helper for this neighbor, It 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_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Neighbor is under GR Restart, hence ignoring the ISM Events",
+                               __PRETTY_FUNCTION__);
+
+               return;
+       }
 
        /* Schedule interface events */
        if (backupseen)
@@ -1260,7 +1298,15 @@ static unsigned ospf6_lsa_examin(struct ospf6_lsa_header *lsah,
                        lsalen - OSPF6_LSA_HEADER_SIZE
                                - OSPF6_INTRA_PREFIX_LSA_MIN_SIZE,
                        ntohs(intra_prefix_lsa->prefix_num) /* 16 bits */
-                       );
+               );
+       case OSPF6_LSTYPE_GRACE_LSA:
+               if (lsalen < OSPF6_LSA_HEADER_SIZE + GRACE_PERIOD_TLV_SIZE
+                                    + GRACE_RESTART_REASON_TLV_SIZE) {
+                       if (IS_DEBUG_OSPF6_GR_HELPER)
+                               zlog_debug("%s: Undersized GraceLSA.",
+                                          __func__);
+                       return MSG_NG;
+               }
        }
        /* No additional validation is possible for unknown LSA types, which are
           themselves valid in OPSFv3, hence the default decision is to accept.
index 8cf05183e15370cd78ce72723d9e3fb505f5589f..331b75f80389ed2cd1eb49d74e1d59c18cfaf4e0 100644 (file)
@@ -45,6 +45,7 @@
 #include "ospf6_lsa.h"
 #include "ospf6_spf.h"
 #include "ospf6_zebra.h"
+#include "ospf6_gr.h"
 #include "lib/json.h"
 
 DEFINE_MTYPE(OSPF6D, OSPF6_NEIGHBOR, "OSPF6 neighbor");
@@ -151,6 +152,7 @@ void ospf6_neighbor_delete(struct ospf6_neighbor *on)
        THREAD_OFF(on->thread_send_lsreq);
        THREAD_OFF(on->thread_send_lsupdate);
        THREAD_OFF(on->thread_send_lsack);
+       THREAD_OFF(on->gr_helper_info.t_grace_timer);
 
        bfd_sess_free(&on->bfd_session);
        XFREE(MTYPE_OSPF6_NEIGHBOR, on);
@@ -192,19 +194,24 @@ static void ospf6_neighbor_state_change(uint8_t next_state,
 
        if (prev_state == OSPF6_NEIGHBOR_FULL
            || next_state == OSPF6_NEIGHBOR_FULL) {
-               OSPF6_ROUTER_LSA_SCHEDULE(on->ospf6_if->area);
-               if (on->ospf6_if->state == OSPF6_INTERFACE_DR) {
-                       OSPF6_NETWORK_LSA_SCHEDULE(on->ospf6_if);
-                       OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(on->ospf6_if);
+               if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) {
+                       OSPF6_ROUTER_LSA_SCHEDULE(on->ospf6_if->area);
+                       if (on->ospf6_if->state == OSPF6_INTERFACE_DR) {
+                               OSPF6_NETWORK_LSA_SCHEDULE(on->ospf6_if);
+                               OSPF6_INTRA_PREFIX_LSA_SCHEDULE_TRANSIT(
+                                       on->ospf6_if);
+                       }
                }
                if (next_state == OSPF6_NEIGHBOR_FULL)
                        on->ospf6_if->area->intra_prefix_originate = 1;
 
-               OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(on->ospf6_if->area);
+               if (!OSPF6_GR_IS_ACTIVE_HELPER(on))
+                       OSPF6_INTRA_PREFIX_LSA_SCHEDULE_STUB(
+                               on->ospf6_if->area);
 
-               if ((prev_state == OSPF6_NEIGHBOR_LOADING ||
-                    prev_state == OSPF6_NEIGHBOR_EXCHANGE) &&
-                   next_state == OSPF6_NEIGHBOR_FULL) {
+               if ((prev_state == OSPF6_NEIGHBOR_LOADING
+                    || prev_state == OSPF6_NEIGHBOR_EXCHANGE)
+                   && next_state == OSPF6_NEIGHBOR_FULL) {
                        OSPF6_AS_EXTERN_LSA_SCHEDULE(on->ospf6_if);
                        on->ospf6_if->area->full_nbrs++;
                }
@@ -601,12 +608,29 @@ int inactivity_timer(struct thread *thread)
        on->drouter = on->prev_drouter = 0;
        on->bdrouter = on->prev_bdrouter = 0;
 
-       ospf6_neighbor_state_change(OSPF6_NEIGHBOR_DOWN, on,
-                                   OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
-       thread_add_event(master, neighbor_change, on->ospf6_if, 0, NULL);
+       if (!OSPF6_GR_IS_ACTIVE_HELPER(on)) {
+               on->drouter = on->prev_drouter = 0;
+               on->bdrouter = on->prev_bdrouter = 0;
+
+               ospf6_neighbor_state_change(
+                       OSPF6_NEIGHBOR_DOWN, on,
+                       OSPF6_NEIGHBOR_EVENT_INACTIVITY_TIMER);
+               thread_add_event(master, neighbor_change, on->ospf6_if, 0,
+                                NULL);
+
+               listnode_delete(on->ospf6_if->neighbor_list, on);
+               ospf6_neighbor_delete(on);
 
-       listnode_delete(on->ospf6_if->neighbor_list, on);
-       ospf6_neighbor_delete(on);
+       } else {
+               if (IS_DEBUG_OSPF6_GR_HELPER)
+                       zlog_debug(
+                               "%s, Acting as HELPER for this neighbour, So restart the dead timer.",
+                               __PRETTY_FUNCTION__);
+
+               thread_add_timer(master, inactivity_timer, on,
+                                on->ospf6_if->dead_interval,
+                                &on->inactivity_timer);
+       }
 
        return 0;
 }
index e445e8703c0834950b151a5be24f4b879b850594..37361de6890a6fb8fc9d59efb0cdb700a5e0b692 100644 (file)
@@ -51,7 +51,7 @@
 #include "ospf6_intra.h"
 #include "ospf6_spf.h"
 #include "ospf6d.h"
-#include "ospf6_gr_helper.h"
+#include "ospf6_gr.h"
 #include "lib/json.h"
 #include "ospf6_nssa.h"
 
index 608d3d1a298343ff465fd4d192ee23ac6bb65679..ac99e90b263adc904c9eb6a04718d6e53a00c10b 100644 (file)
@@ -63,7 +63,7 @@ noinst_HEADERS += \
        ospf6d/ospf6_asbr.h \
        ospf6d/ospf6_bfd.h \
        ospf6d/ospf6_flood.h \
-       ospf6d/ospf6_gr_helper.h \
+       ospf6d/ospf6_gr.h \
        ospf6d/ospf6_interface.h \
        ospf6d/ospf6_intra.h \
        ospf6d/ospf6_lsa.h \