summaryrefslogtreecommitdiffstats
path: root/ospf6d
diff options
context:
space:
mode:
authorAndrew Cooks <acooks.at.bda@gmail.com>2024-06-19 08:40:55 +0200
committerAndrew Cooks <acooks.at.bda@gmail.com>2024-09-16 10:38:17 +0200
commit9eef5e64833c9f2727914cec1a3355c31c2952b9 (patch)
tree6d53cd6a9338afa111440198d3186015768df426 /ospf6d
parentospf6d: use nth_prefix() in ospf6_link_lsa_get_prefix_str() (diff)
downloadfrr-9eef5e64833c9f2727914cec1a3355c31c2952b9.tar.xz
frr-9eef5e64833c9f2727914cec1a3355c31c2952b9.zip
ospf6d: use nth_prefix() in ospf6_intra_prefix_lsa_get_prefix_str()
Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
Diffstat (limited to 'ospf6d')
-rw-r--r--ospf6d/ospf6_intra.c49
1 files changed, 11 insertions, 38 deletions
diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c
index 2988f1239..e3c76b971 100644
--- a/ospf6d/ospf6_intra.c
+++ b/ospf6d/ospf6_intra.c
@@ -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,