]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospf6d/ospf6_lsa.c
Merge pull request #5257 from ton31337/fix/update_rib_on_bgp_distance_changes
[mirror_frr.git] / ospf6d / ospf6_lsa.c
index cca4616c163323b6385d967e5d93d2639c7770e9..9acbd09b1a958b2b1239f0403e80e857c619c520 100644 (file)
@@ -47,11 +47,11 @@ vector ospf6_lsa_handler_vector;
 
 static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
 {
-       u_char *start, *end, *current;
+       uint8_t *start, *end, *current;
        char byte[4];
 
-       start = (u_char *)lsa->header + sizeof(struct ospf6_lsa_header);
-       end = (u_char *)lsa->header + ntohs(lsa->header->length);
+       start = (uint8_t *)lsa->header + sizeof(struct ospf6_lsa_header);
+       end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
 
        vty_out(vty, "        Unknown contents:\n");
        for (current = start; current < end; current++) {
@@ -84,7 +84,7 @@ void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler)
        vector_set_index(ospf6_lsa_handler_vector, index, (void *)handler);
 }
 
-const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type)
+const struct ospf6_lsa_handler *ospf6_get_lsa_handler(uint16_t type)
 {
        const struct ospf6_lsa_handler *handler = NULL;
        unsigned int index = ntohs(type) & OSPF6_LSTYPE_FCODE_MASK;
@@ -100,7 +100,7 @@ const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type)
        return handler;
 }
 
-const char *ospf6_lstype_name(u_int16_t type)
+const char *ospf6_lstype_name(uint16_t type)
 {
        static char buf[8];
        const struct ospf6_lsa_handler *handler;
@@ -113,7 +113,7 @@ const char *ospf6_lstype_name(u_int16_t type)
        return buf;
 }
 
-const char *ospf6_lstype_short_name(u_int16_t type)
+const char *ospf6_lstype_short_name(uint16_t type)
 {
        static char buf[8];
        const struct ospf6_lsa_handler *handler;
@@ -126,11 +126,11 @@ const char *ospf6_lstype_short_name(u_int16_t type)
        return buf;
 }
 
-u_char ospf6_lstype_debug(u_int16_t type)
+uint8_t ospf6_lstype_debug(uint16_t type)
 {
        const struct ospf6_lsa_handler *handler;
        handler = ospf6_get_lsa_handler(type);
-       return handler->debug;
+       return handler->lh_debug;
 }
 
 /* RFC2328: Section 13.2 */
@@ -207,11 +207,11 @@ void ospf6_lsa_age_set(struct ospf6_lsa *lsa)
 
 /* this function calculates current age from its birth,
    then update age field of LSA header. return value is current age */
-u_int16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa)
+uint16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa)
 {
        struct timeval now;
-       u_int32_t ulage;
-       u_int16_t age;
+       uint32_t ulage;
+       uint16_t age;
 
        assert(lsa);
        assert(lsa->header);
@@ -237,7 +237,7 @@ u_int16_t ospf6_lsa_age_current(struct ospf6_lsa *lsa)
 }
 
 /* update age field of LSA header with adding InfTransDelay */
-void ospf6_lsa_age_update_to_send(struct ospf6_lsa *lsa, u_int32_t transdelay)
+void ospf6_lsa_age_update_to_send(struct ospf6_lsa *lsa, uint32_t transdelay)
 {
        unsigned short age;
 
@@ -292,8 +292,8 @@ void ospf6_lsa_premature_aging(struct ospf6_lsa *lsa)
 int ospf6_lsa_compare(struct ospf6_lsa *a, struct ospf6_lsa *b)
 {
        int32_t seqnuma, seqnumb;
-       u_int16_t cksuma, cksumb;
-       u_int16_t agea, ageb;
+       uint16_t cksuma, cksumb;
+       uint16_t agea, ageb;
 
        assert(a && a->header);
        assert(b && b->header);
@@ -355,7 +355,7 @@ void ospf6_lsa_header_print_raw(struct ospf6_lsa_header *header)
        zlog_debug("    [%s Id:%s Adv:%s]", ospf6_lstype_name(header->type), id,
                   adv_router);
        zlog_debug("    Age: %4hu SeqNum: %#08lx Cksum: %04hx Len: %d",
-                  ntohs(header->age), (u_long)ntohl(header->seqnum),
+                  ntohs(header->age), (unsigned long)ntohl(header->seqnum),
                   ntohs(header->checksum), ntohs(header->length));
 }
 
@@ -394,13 +394,13 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa)
                vty_out(vty, "%-4s %-15s%-15s%4hu %8lx %30s\n",
                        ospf6_lstype_short_name(lsa->header->type), id,
                        adv_router, ospf6_lsa_age_current(lsa),
-                       (u_long)ntohl(lsa->header->seqnum),
+                       (unsigned long)ntohl(lsa->header->seqnum),
                        handler->lh_get_prefix_str(lsa, buf, sizeof(buf), 0));
        } else if (type != OSPF6_LSTYPE_UNKNOWN) {
                sprintf(tmpbuf, "%-4s %-15s%-15s%4hu %8lx",
                        ospf6_lstype_short_name(lsa->header->type), id,
                        adv_router, ospf6_lsa_age_current(lsa),
-                       (u_long)ntohl(lsa->header->seqnum));
+                       (unsigned long)ntohl(lsa->header->seqnum));
 
                while (handler->lh_get_prefix_str(lsa, buf, sizeof(buf), cnt)
                       != NULL) {
@@ -411,17 +411,17 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa)
                vty_out(vty, "%-4s %-15s%-15s%4hu %8lx\n",
                        ospf6_lstype_short_name(lsa->header->type), id,
                        adv_router, ospf6_lsa_age_current(lsa),
-                       (u_long)ntohl(lsa->header->seqnum));
+                       (unsigned long)ntohl(lsa->header->seqnum));
        }
 }
 
 void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa)
 {
-       u_char *start, *end, *current;
+       uint8_t *start, *end, *current;
        char byte[4];
 
-       start = (u_char *)lsa->header;
-       end = (u_char *)lsa->header + ntohs(lsa->header->length);
+       start = (uint8_t *)lsa->header;
+       end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
 
        vty_out(vty, "\n");
        vty_out(vty, "%s:\n", lsa->name);
@@ -456,7 +456,7 @@ void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa)
        vty_out(vty, "Link State ID: %s\n", id);
        vty_out(vty, "Advertising Router: %s\n", adv_router);
        vty_out(vty, "LS Sequence Number: %#010lx\n",
-               (u_long)ntohl(lsa->header->seqnum));
+               (unsigned long)ntohl(lsa->header->seqnum));
        vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
                ntohs(lsa->header->checksum), ntohs(lsa->header->length));
        vty_out(vty, "Flag: %x \n", lsa->flag);
@@ -490,7 +490,7 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa)
        vty_out(vty, "Link State ID: %s\n", id);
        vty_out(vty, "Advertising Router: %s\n", adv_router);
        vty_out(vty, "LS Sequence Number: %#010lx\n",
-               (u_long)ntohl(lsa->header->seqnum));
+               (unsigned long)ntohl(lsa->header->seqnum));
        vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
                ntohs(lsa->header->checksum), ntohs(lsa->header->length));
        vty_out(vty, "Duration: %s\n", duration);
@@ -512,23 +512,20 @@ struct ospf6_lsa *ospf6_lsa_create(struct ospf6_lsa_header *header)
 {
        struct ospf6_lsa *lsa = NULL;
        struct ospf6_lsa_header *new_header = NULL;
-       u_int16_t lsa_size = 0;
+       uint16_t lsa_size = 0;
 
        /* size of the entire LSA */
        lsa_size = ntohs(header->length); /* XXX vulnerable */
 
        /* allocate memory for this LSA */
-       new_header =
-               (struct ospf6_lsa_header *)XMALLOC(MTYPE_OSPF6_LSA_HEADER,
-                                                  lsa_size);
+       new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, lsa_size);
 
        /* copy LSA from original header */
        memcpy(new_header, header, lsa_size);
 
        /* LSA information structure */
        /* allocate memory */
-       lsa = (struct ospf6_lsa *)XCALLOC(MTYPE_OSPF6_LSA,
-                                         sizeof(struct ospf6_lsa));
+       lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
 
        lsa->header = (struct ospf6_lsa_header *)new_header;
 
@@ -547,16 +544,15 @@ struct ospf6_lsa *ospf6_lsa_create_headeronly(struct ospf6_lsa_header *header)
        struct ospf6_lsa_header *new_header = NULL;
 
        /* allocate memory for this LSA */
-       new_header = (struct ospf6_lsa_header *)XMALLOC(
-               MTYPE_OSPF6_LSA_HEADER, sizeof(struct ospf6_lsa_header));
+       new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER,
+                            sizeof(struct ospf6_lsa_header));
 
        /* copy LSA from original header */
        memcpy(new_header, header, sizeof(struct ospf6_lsa_header));
 
        /* LSA information structure */
        /* allocate memory */
-       lsa = (struct ospf6_lsa *)XCALLOC(MTYPE_OSPF6_LSA,
-                                         sizeof(struct ospf6_lsa));
+       lsa = XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa));
 
        lsa->header = (struct ospf6_lsa_header *)new_header;
        SET_FLAG(lsa->flag, OSPF6_LSA_HEADERONLY);
@@ -706,6 +702,37 @@ int ospf6_lsa_refresh(struct thread *thread)
        return 0;
 }
 
+void ospf6_flush_self_originated_lsas_now(void)
+{
+       struct listnode *node;
+       struct ospf6_area *oa;
+       struct ospf6_lsa *lsa;
+       const struct route_node *end = NULL;
+       uint32_t type, adv_router;
+
+       ospf6->inst_shutdown = 1;
+
+       for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
+               end = ospf6_lsdb_head(oa->lsdb_self, 0, 0, ospf6->router_id,
+                                     &lsa);
+               while (lsa) {
+                       /* RFC 2328 (14.1):  Set MAXAGE */
+                       lsa->header->age = htons(OSPF_LSA_MAXAGE);
+                       /* Flood MAXAGE LSA*/
+                       ospf6_flood(NULL, lsa);
+
+                       lsa = ospf6_lsdb_next(end, lsa);
+               }
+       }
+
+       type = htons(OSPF6_LSTYPE_AS_EXTERNAL);
+       adv_router = ospf6->router_id;
+       for (ALL_LSDB_TYPED_ADVRTR(ospf6->lsdb, type, adv_router, lsa)) {
+               /* RFC 2328 (14.1):  Set MAXAGE */
+               lsa->header->age = htons(OSPF_LSA_MAXAGE);
+               ospf6_flood(NULL, lsa);
+       }
+}
 
 /* Fletcher Checksum -- Refer to RFC1008. */
 
@@ -713,26 +740,28 @@ int ospf6_lsa_refresh(struct thread *thread)
    one-based. */
 unsigned short ospf6_lsa_checksum(struct ospf6_lsa_header *lsa_header)
 {
-       u_char *buffer = (u_char *)&lsa_header->type;
-       int type_offset = buffer - (u_char *)&lsa_header->age; /* should be 2 */
+       uint8_t *buffer = (uint8_t *)&lsa_header->type;
+       int type_offset =
+               buffer - (uint8_t *)&lsa_header->age; /* should be 2 */
 
        /* Skip the AGE field */
-       u_int16_t len = ntohs(lsa_header->length) - type_offset;
+       uint16_t len = ntohs(lsa_header->length) - type_offset;
 
        /* Checksum offset starts from "type" field, not the beginning of the
           lsa_header struct. The offset is 14, rather than 16. */
-       int checksum_offset = (u_char *)&lsa_header->checksum - buffer;
+       int checksum_offset = (uint8_t *)&lsa_header->checksum - buffer;
 
        return (unsigned short)fletcher_checksum(buffer, len, checksum_offset);
 }
 
 int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *lsa_header)
 {
-       u_char *buffer = (u_char *)&lsa_header->type;
-       int type_offset = buffer - (u_char *)&lsa_header->age; /* should be 2 */
+       uint8_t *buffer = (uint8_t *)&lsa_header->type;
+       int type_offset =
+               buffer - (uint8_t *)&lsa_header->age; /* should be 2 */
 
        /* Skip the AGE field */
-       u_int16_t len = ntohs(lsa_header->length) - type_offset;
+       uint16_t len = ntohs(lsa_header->length) - type_offset;
 
        return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE)
                == 0);
@@ -755,7 +784,8 @@ static char *ospf6_lsa_handler_name(const struct ospf6_lsa_handler *h)
        unsigned int i;
        unsigned int size = strlen(h->lh_name);
 
-       if (!strcmp(h->lh_name, "unknown") && h->lh_type != OSPF6_LSTYPE_UNKNOWN) {
+       if (!strcmp(h->lh_name, "unknown")
+           && h->lh_type != OSPF6_LSTYPE_UNKNOWN) {
                snprintf(buf, sizeof(buf), "%#04hx", h->lh_type);
                return buf;
        }
@@ -811,13 +841,13 @@ DEFUN (debug_ospf6_lsa_type,
 
        if (argc == 5) {
                if (strmatch(argv[idx_type]->text, "originate"))
-                       SET_FLAG(handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
+                       SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ORIGINATE);
                else if (strmatch(argv[idx_type]->text, "examine"))
-                       SET_FLAG(handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
+                       SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_EXAMIN);
                else if (strmatch(argv[idx_type]->text, "flooding"))
-                       SET_FLAG(handler->debug, OSPF6_LSA_DEBUG_FLOOD);
+                       SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_FLOOD);
        } else
-               SET_FLAG(handler->debug, OSPF6_LSA_DEBUG);
+               SET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG);
 
        return CMD_SUCCESS;
 }
@@ -843,7 +873,7 @@ DEFUN (no_debug_ospf6_lsa_type,
 {
        int idx_lsa = 4;
        int idx_type = 5;
-       u_int i;
+       unsigned int i;
        struct ospf6_lsa_handler *handler = NULL;
 
        for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) {
@@ -863,13 +893,14 @@ DEFUN (no_debug_ospf6_lsa_type,
 
        if (argc == 6) {
                if (strmatch(argv[idx_type]->text, "originate"))
-                       UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG_ORIGINATE);
+                       UNSET_FLAG(handler->lh_debug,
+                                  OSPF6_LSA_DEBUG_ORIGINATE);
                if (strmatch(argv[idx_type]->text, "examine"))
-                       UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG_EXAMIN);
+                       UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_EXAMIN);
                if (strmatch(argv[idx_type]->text, "flooding"))
-                       UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG_FLOOD);
+                       UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_FLOOD);
        } else
-               UNSET_FLAG(handler->debug, OSPF6_LSA_DEBUG);
+               UNSET_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG);
 
        return CMD_SUCCESS;
 }
@@ -884,23 +915,23 @@ void install_element_ospf6_debug_lsa(void)
 
 int config_write_ospf6_debug_lsa(struct vty *vty)
 {
-       u_int i;
+       unsigned int i;
        const struct ospf6_lsa_handler *handler;
 
        for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) {
                handler = vector_slot(ospf6_lsa_handler_vector, i);
                if (handler == NULL)
                        continue;
-               if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG))
+               if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG))
                        vty_out(vty, "debug ospf6 lsa %s\n",
                                ospf6_lsa_handler_name(handler));
-               if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG_ORIGINATE))
+               if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_ORIGINATE))
                        vty_out(vty, "debug ospf6 lsa %s originate\n",
                                ospf6_lsa_handler_name(handler));
-               if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG_EXAMIN))
+               if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_EXAMIN))
                        vty_out(vty, "debug ospf6 lsa %s examine\n",
                                ospf6_lsa_handler_name(handler));
-               if (CHECK_FLAG(handler->debug, OSPF6_LSA_DEBUG_FLOOD))
+               if (CHECK_FLAG(handler->lh_debug, OSPF6_LSA_DEBUG_FLOOD))
                        vty_out(vty, "debug ospf6 lsa %s flooding\n",
                                ospf6_lsa_handler_name(handler));
        }