]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospf6d: use nth_prefix() in ospf6_intra_prefix_lsa_get_prefix_str()
authorAndrew Cooks <acooks.at.bda@gmail.com>
Wed, 19 Jun 2024 06:40:55 +0000 (16:40 +1000)
committerAndrew Cooks <acooks.at.bda@gmail.com>
Mon, 16 Sep 2024 08:38:17 +0000 (18:38 +1000)
Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
ospf6d/ospf6_intra.c

index 2988f12394ed4cb8b5a0c7b85002f4757486b55c..e3c76b971c5c6e45d407a564510f02cb5a0c2a9c 100644 (file)
@@ -769,49 +769,22 @@ static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa *lsa,
                                                   char *buf, int buflen,
                                                   int pos)
 {
-       char *start, *end, *current;
-       struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
-       struct in6_addr in6;
-       int prefixnum, cnt = 0;
-       struct ospf6_prefix *prefix;
+       struct ospf6_prefix *prefix = nth_prefix(lsa->header, pos);
+       struct in6_addr in6 = { 0 };
        char tbuf[16];
 
-       if (lsa) {
-               intra_prefix_lsa = lsa_after_header(lsa->header);
-
-               prefixnum = ntohs(intra_prefix_lsa->prefix_num);
-               if ((pos + 1) > prefixnum)
-                       return NULL;
+       /* ensure buflen >= INET6_ADDRSTRLEN + '/128\0' */
+       if (!lsa || !prefix || !buf || buflen < (5 + INET6_ADDRSTRLEN))
+               return NULL;
 
-               start = (char *)intra_prefix_lsa
-                       + sizeof(struct ospf6_intra_prefix_lsa);
-               end = ospf6_lsa_end(lsa->header);
-               current = start;
+       memcpy(&in6, OSPF6_PREFIX_BODY(prefix),
+              OSPF6_PREFIX_SPACE(prefix->prefix_length));
+       inet_ntop(AF_INET6, &in6, buf, buflen);
 
-               while (current + sizeof(struct ospf6_prefix) <= end) {
-                       prefix = (struct ospf6_prefix *)current;
-                       if (prefix->prefix_length == 0
-                           || current + OSPF6_PREFIX_SIZE(prefix) > end) {
-                               return NULL;
-                       }
+       snprintf(tbuf, sizeof(tbuf), "/%d", prefix->prefix_length);
+       strlcat(buf, tbuf, buflen);
 
-                       if (cnt < pos) {
-                               current += OSPF6_PREFIX_SIZE(prefix);
-                               cnt++;
-                       } else {
-                               memset(&in6, 0, sizeof(in6));
-                               memcpy(&in6, OSPF6_PREFIX_BODY(prefix),
-                                      OSPF6_PREFIX_SPACE(
-                                              prefix->prefix_length));
-                               inet_ntop(AF_INET6, &in6, buf, buflen);
-                               snprintf(tbuf, sizeof(tbuf), "/%d",
-                                        prefix->prefix_length);
-                               strlcat(buf, tbuf, buflen);
-                               return (buf);
-                       }
-               }
-       }
-       return NULL;
+       return buf;
 }
 
 static int ospf6_intra_prefix_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,