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>
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;
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 */