summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cooks <acooks.at.bda@gmail.com>2024-06-19 15:38:51 +1000
committerAndrew Cooks <acooks.at.bda@gmail.com>2024-09-16 18:38:17 +1000
commit6a7751b38aa5b8140f6f7f2c17b519ed4992247e (patch)
treed7c56136827a0bd771da58dc5b50026a28fba8bc
parent554350abe0e0c11ca15b0d8c71b17adf231b1595 (diff)
ospf6d: use nth_prefix() in ospf6_link_lsa_get_prefix_str()
Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
-rw-r--r--ospf6d/ospf6_intra.c56
1 files changed, 15 insertions, 41 deletions
diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c
index fb3bf15dcd..2988f12394 100644
--- a/ospf6d/ospf6_intra.c
+++ b/ospf6d/ospf6_intra.c
@@ -574,52 +574,26 @@ void ospf6_network_lsa_originate(struct event *thread)
static char *ospf6_link_lsa_get_prefix_str(struct ospf6_lsa *lsa, char *buf,
int buflen, int pos)
{
- char *start, *end, *current;
- struct ospf6_link_lsa *link_lsa;
- struct in6_addr in6;
- struct ospf6_prefix *prefix;
- int cnt = 0, prefixnum;
+ struct ospf6_link_lsa *link_lsa = lsa_after_header(lsa->header);
+ struct ospf6_prefix *prefix = nth_prefix(lsa->header, pos);
+ struct in6_addr in6 = { 0 };
- if (lsa) {
- link_lsa = (struct ospf6_link_lsa
- *)((caddr_t)lsa->header
- + sizeof(struct ospf6_lsa_header));
-
- if (pos == 0) {
- inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf,
- buflen);
- return (buf);
- }
+ if (!lsa || !prefix || !buf || buflen < (1 + INET6_ADDRSTRLEN))
+ return NULL;
- prefixnum = ntohl(link_lsa->prefix_num);
- if (pos > prefixnum)
- return NULL;
+ /* position zero is used for the lladdr in the body of the LSA */
+ if (pos == 0) {
+ inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf, buflen);
+ return buf;
+ }
- start = (char *)link_lsa + sizeof(struct ospf6_link_lsa);
- end = (char *)lsa->header + ntohs(lsa->header->length);
- current = start;
+ memcpy(&in6, OSPF6_PREFIX_BODY(prefix),
+ OSPF6_PREFIX_SPACE(prefix->prefix_length));
+ inet_ntop(AF_INET6, &in6, buf, buflen);
+
+ return buf;
- 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;
- }
- if (cnt < (pos - 1)) {
- 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);
- return (buf);
- }
- }
- }
- return NULL;
}
static int ospf6_link_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,