summaryrefslogtreecommitdiffstats
path: root/ospf6d
diff options
context:
space:
mode:
authorAndrew Cooks <acooks.at.bda@gmail.com>2024-08-05 08:14:20 +0200
committerAndrew Cooks <acooks.at.bda@gmail.com>2024-09-16 10:38:17 +0200
commit554350abe0e0c11ca15b0d8c71b17adf231b1595 (patch)
treebf66d7dd0768d3bb8320858c06b99ae89e1fc6f1 /ospf6d
parentospf6d: use nth_lsdesc() in ospf6_router_lsa_get_nbr_id() (diff)
downloadfrr-554350abe0e0c11ca15b0d8c71b17adf231b1595.tar.xz
frr-554350abe0e0c11ca15b0d8c71b17adf231b1595.zip
ospf6d: add nth_prefix()
Add utility function to find the Nth prefix in a link LSA or Intra Prefix LSA. Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
Diffstat (limited to 'ospf6d')
-rw-r--r--ospf6d/ospf6_lsa.c24
-rw-r--r--ospf6d/ospf6_lsa.h1
2 files changed, 25 insertions, 0 deletions
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c
index 088ebf56a..622e5f9e0 100644
--- a/ospf6d/ospf6_lsa.c
+++ b/ospf6d/ospf6_lsa.c
@@ -92,6 +92,30 @@ void *nth_lsdesc(struct ospf6_lsa_header *header, int pos)
return NULL;
}
+void *nth_prefix(struct ospf6_lsa_header *header, int pos)
+{
+ struct ospf6_prefix *prefix = lsdesc_start(header);
+ char *end = ospf6_lsa_end(header);
+ int i = 0;
+
+ if (ntohs(header->type) != OSPF6_LSTYPE_LINK &&
+ ntohs(header->type) != OSPF6_LSTYPE_INTRA_PREFIX)
+ return NULL;
+
+ if (pos == 0)
+ return prefix;
+
+ while ((char *)prefix < end &&
+ (char *)prefix + OSPF6_PREFIX_SIZE(prefix) <= end) {
+ if (i == pos)
+ return prefix;
+ i++;
+ prefix = OSPF6_PREFIX_NEXT(prefix);
+ }
+
+ return NULL;
+}
+
struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa)
{
struct ospf6 *ospf6 = NULL;
diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h
index d6e0cf771..e2c8edd24 100644
--- a/ospf6d/ospf6_lsa.h
+++ b/ospf6d/ospf6_lsa.h
@@ -375,5 +375,6 @@ void *lsdesc_start_lsa_type(struct ospf6_lsa_header *header, int lsa_type);
void *lsdesc_start(struct ospf6_lsa_header *header);
void *nth_lsdesc(struct ospf6_lsa_header *header, int pos);
+void *nth_prefix(struct ospf6_lsa_header *header, int pos);
#endif /* OSPF6_LSA_H */