]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospf6d: add nth_prefix()
authorAndrew Cooks <acooks.at.bda@gmail.com>
Mon, 5 Aug 2024 06:14:20 +0000 (16:14 +1000)
committerAndrew Cooks <acooks.at.bda@gmail.com>
Mon, 16 Sep 2024 08:38:17 +0000 (18:38 +1000)
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>
ospf6d/ospf6_lsa.c
ospf6d/ospf6_lsa.h

index 088ebf56a416ddd0472601029c57fc7ff003520c..622e5f9e0f73f6f84294ba7abc74f39f18ab42aa 100644 (file)
@@ -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;
index d6e0cf77103089e8b3a34db74fc432ab216a5980..e2c8edd2481e5de977a26d465ce3bd0aa7b062ec 100644 (file)
@@ -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 */