]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospf6d: replace OSPF6_LSA_END with ospf6_lsa_end
authorAndrew Cooks <acooks.at.bda@gmail.com>
Tue, 21 May 2024 00:39:47 +0000 (10:39 +1000)
committerAndrew Cooks <acooks.at.bda@gmail.com>
Tue, 28 May 2024 04:06:25 +0000 (14:06 +1000)
Replacing the macro with an inline function enables better type
checking.

No functional change.

Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
ospf6d/ospf6_intra.c
ospf6d/ospf6_lsa.c
ospf6d/ospf6_lsa.h
ospf6d/ospf6_spf.c

index 48a7012adac796654cc8d239f931918263e3da2d..b06796ada02c3fb2b4e0a947029a723cea0522c5 100644 (file)
@@ -705,7 +705,8 @@ static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
        }
 
        start = (char *)link_lsa + sizeof(struct ospf6_link_lsa);
-       end = (char *)lsa->header + ntohs(lsa->header->length);
+       end = ospf6_lsa_end(lsa->header);
+
        for (current = start; current < end;
             current += OSPF6_PREFIX_SIZE(prefix)) {
                prefix = (struct ospf6_prefix *)current;
@@ -864,7 +865,7 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa,
 
                start = (char *)intra_prefix_lsa
                        + sizeof(struct ospf6_intra_prefix_lsa);
-               end = (char *)lsa->header + ntohs(lsa->header->length);
+               end = ospf6_lsa_end(lsa->header);
                current = start;
 
                while (current + sizeof(struct ospf6_prefix) <= end) {
@@ -935,7 +936,8 @@ static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
 
        start = (char *)intra_prefix_lsa
                + sizeof(struct ospf6_intra_prefix_lsa);
-       end = (char *)lsa->header + ntohs(lsa->header->length);
+       end = ospf6_lsa_end(lsa->header);
+
        for (current = start; current < end;
             current += OSPF6_PREFIX_SIZE(prefix)) {
                prefix = (struct ospf6_prefix *)current;
@@ -1315,7 +1317,8 @@ void ospf6_intra_prefix_lsa_originate_transit(struct event *thread)
 
                prefix_num = (unsigned short)ntohl(link_lsa->prefix_num);
                start = (char *)link_lsa + sizeof(struct ospf6_link_lsa);
-               end = (char *)lsa->header + ntohs(lsa->header->length);
+               end = ospf6_lsa_end(lsa->header);
+
                for (current = start; current < end && prefix_num;
                     current += OSPF6_PREFIX_SIZE(op)) {
                        op = (struct ospf6_prefix *)current;
@@ -1770,7 +1773,7 @@ void ospf6_intra_prefix_lsa_add(struct ospf6_lsa *lsa)
        prefix_num = ntohs(intra_prefix_lsa->prefix_num);
        start = (caddr_t)intra_prefix_lsa
                + sizeof(struct ospf6_intra_prefix_lsa);
-       end = OSPF6_LSA_END(lsa->header);
+       end = ospf6_lsa_end(lsa->header);
        for (current = start; current < end; current += OSPF6_PREFIX_SIZE(op)) {
                op = (struct ospf6_prefix *)current;
                if (prefix_num == 0)
@@ -1974,7 +1977,7 @@ void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa *lsa)
        prefix_num = ntohs(intra_prefix_lsa->prefix_num);
        start = (caddr_t)intra_prefix_lsa
                + sizeof(struct ospf6_intra_prefix_lsa);
-       end = OSPF6_LSA_END(lsa->header);
+       end = ospf6_lsa_end(lsa->header);
        for (current = start; current < end; current += OSPF6_PREFIX_SIZE(op)) {
                op = (struct ospf6_prefix *)current;
                if (prefix_num == 0)
index 24643164c5fd6004e8a2d71dc883368679621c39..b907ccbc208e4b453bbe5f3d0923d304bfbb5eb8 100644 (file)
@@ -66,7 +66,7 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
        char *start, *end, *current;
 
        start = ospf6_lsa_header_end(lsa->header);
-       end = (char *)lsa->header + ntohs(lsa->header->length);
+       end = ospf6_lsa_end(lsa->header);
 
        if (use_json) {
                json_object_string_add(json_obj, "lsaType", "unknown");
@@ -548,7 +548,7 @@ void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa,
        json_object *json = NULL;
 
        start = (uint8_t *)lsa->header;
-       end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
+       end = (uint8_t *)ospf6_lsa_end(lsa->header);
 
        if (use_json) {
                json = json_object_new_object();
index 0fa632449f59dec6f18b890cb422a20919548c22..714cd5883d5e8bee941d9ae5ad0102c411e6ac71 100644 (file)
@@ -88,14 +88,17 @@ struct ospf6_lsa_header {
 };
 
 #define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length))
-#define OSPF6_LSA_END(h)                                                       \
-       ((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length))
 
 static inline char *ospf6_lsa_header_end(struct ospf6_lsa_header *header)
 {
        return (char *)header + sizeof(struct ospf6_lsa_header);
 }
 
+static inline char *ospf6_lsa_end(struct ospf6_lsa_header *header)
+{
+       return (char *)header + ntohs(header->length);
+}
+
 #define OSPF6_LSA_IS_TYPE(t, L)                                                \
        ((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0)
 #define OSPF6_LSA_IS_SAME(L1, L2)                                              \
index 93120df99915b2ea6674f66e0832bfa0ee9a24aa..7d6dcf8e36bb6022f8f9d0fcc5610791f1525b41 100644 (file)
@@ -207,7 +207,7 @@ static char *ospf6_lsdesc_backlink(struct ospf6_lsa *lsa, caddr_t lsdesc,
                        ? sizeof(struct ospf6_router_lsdesc)
                        : sizeof(struct ospf6_network_lsdesc));
        for (backlink = ospf6_lsa_header_end(lsa->header) + 4;
-            backlink + size <= OSPF6_LSA_END(lsa->header); backlink += size) {
+            backlink + size <= ospf6_lsa_end(lsa->header); backlink += size) {
                assert(!(OSPF6_LSA_IS_TYPE(NETWORK, lsa)
                         && VERTEX_IS_TYPE(NETWORK, v)));
 
@@ -511,7 +511,7 @@ void ospf6_spf_calculation(uint32_t router_id,
                                ? sizeof(struct ospf6_router_lsdesc)
                                : sizeof(struct ospf6_network_lsdesc));
                for (lsdesc = ospf6_lsa_header_end(v->lsa->header) + 4;
-                    lsdesc + size <= OSPF6_LSA_END(v->lsa->header);
+                    lsdesc + size <= ospf6_lsa_end(v->lsa->header);
                     lsdesc += size) {
                        lsa = ospf6_lsdesc_lsa(lsdesc, v);
                        if (lsa == NULL)