]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_gr_helper.c
ospfd: fix GR helper initialization and termination
[mirror_frr.git] / ospfd / ospf_gr_helper.c
index d818878cf5f3ac67eee87479d7474e37c7791390..8ee4207b048b84ed3a7639ed84015bd212afb1d2 100644 (file)
@@ -159,10 +159,8 @@ const char *ospf_rejected_reason2str(unsigned int reason)
  * Returns:
  *    Nothing
  */
-void ospf_gr_helper_init(struct ospf *ospf)
+void ospf_gr_helper_instance_init(struct ospf *ospf)
 {
-       int rc;
-
        if (IS_DEBUG_OSPF_GR_HELPER)
                zlog_debug("%s, GR Helper init.", __func__);
 
@@ -176,6 +174,37 @@ void ospf_gr_helper_init(struct ospf *ospf)
        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_instance_stop(struct ospf *ospf)
+{
+       if (IS_DEBUG_OSPF_GR_HELPER)
+               zlog_debug("%s, GR helper deinit.", __func__);
+
+       ospf_enable_rtr_hash_destroy(ospf);
+}
+
+/*
+ * Initialize GR helper config data structures.
+ *
+ * Returns:
+ *    Nothing
+ */
+void ospf_gr_helper_init(void)
+{
+       int rc;
+
+       if (IS_DEBUG_OSPF_GR_HELPER)
+               zlog_debug("%s, GR Helper init.", __func__);
 
        rc = ospf_register_opaque_functab(
                OSPF_OPAQUE_LINK_LSA, OPAQUE_TYPE_GRACE_LSA, NULL, NULL, NULL,
@@ -191,20 +220,15 @@ void ospf_gr_helper_init(struct ospf *ospf)
 /*
  * De-Initialize GR helper config data structures.
  *
- * OSPF
- *    OSPF pointer
- *
  * Returns:
  *    Nothing
  */
-void ospf_gr_helper_stop(struct ospf *ospf)
+void ospf_gr_helper_stop(void)
 {
 
        if (IS_DEBUG_OSPF_GR_HELPER)
                zlog_debug("%s, GR helper deinit.", __func__);
 
-       ospf_enable_rtr_hash_destroy(ospf);
-
        ospf_delete_opaque_functab(OSPF_OPAQUE_LINK_LSA, OPAQUE_TYPE_GRACE_LSA);
 }
 
@@ -233,19 +257,17 @@ static int ospf_extract_grace_lsa_fields(struct ospf_lsa *lsa,
 
        lsah = (struct lsa_header *)lsa->data;
 
-       length = ntohs(lsah->length);
-
        /* Check LSA len */
-       if (length <= OSPF_LSA_HEADER_SIZE) {
+       if (lsa->size <= OSPF_LSA_HEADER_SIZE) {
                if (IS_DEBUG_OSPF_GR_HELPER)
                        zlog_debug("%s: Malformed packet: Invalid LSA len:%d",
                                   __func__, length);
                return OSPF_GR_FAILURE;
        }
 
-       length -= OSPF_LSA_HEADER_SIZE;
+       length = lsa->size - OSPF_LSA_HEADER_SIZE;
 
-       for (tlvh = TLV_HDR_TOP(lsah); sum < length;
+       for (tlvh = TLV_HDR_TOP(lsah); sum < length && tlvh;
             tlvh = TLV_HDR_NEXT(tlvh)) {
 
                /* Check TLV len against overall LSA */
@@ -996,18 +1018,16 @@ static void show_ospf_grace_lsa_info(struct vty *vty, struct ospf_lsa *lsa)
 
        lsah = (struct lsa_header *)lsa->data;
 
-       length = ntohs(lsah->length);
-
-       if (length <= OSPF_LSA_HEADER_SIZE) {
+       if (lsa->size <= OSPF_LSA_HEADER_SIZE) {
                vty_out(vty, "%% Invalid LSA length: %d\n", length);
                return;
        }
 
-       length -= OSPF_LSA_HEADER_SIZE;
+       length = lsa->size - OSPF_LSA_HEADER_SIZE;
 
        vty_out(vty, "  TLV info:\n");
 
-       for (tlvh = TLV_HDR_TOP(lsah); sum < length;
+       for (tlvh = TLV_HDR_TOP(lsah); sum < length && tlvh;
             tlvh = TLV_HDR_NEXT(tlvh)) {
                /* Check TLV len */
                if (sum + TLV_SIZE(tlvh) > length) {