]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospf6d: add nth_lsdesc()
authorAndrew Cooks <acooks.at.bda@gmail.com>
Mon, 5 Aug 2024 06:09:30 +0000 (16:09 +1000)
committerAndrew Cooks <acooks.at.bda@gmail.com>
Mon, 16 Sep 2024 08:38:16 +0000 (18:38 +1000)
Add utility function to find the Nth router lsdesc or network lsdesc in
an LSA.

Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
ospf6d/ospf6_lsa.c
ospf6d/ospf6_lsa.h

index de04391b6b18e3b8b9a7485b60037b06e6e56241..088ebf56a416ddd0472601029c57fc7ff003520c 100644 (file)
@@ -70,6 +70,28 @@ void *lsdesc_start(struct ospf6_lsa_header *header)
 
 static struct ospf6_lsa_handler *lsa_handlers[OSPF6_LSTYPE_SIZE];
 
+void *nth_lsdesc(struct ospf6_lsa_header *header, int pos)
+{
+       char *lsdesc = lsdesc_start(header);
+       char *lsa_end = ospf6_lsa_end(header);
+       char *nth;
+       int lsdesc_size;
+
+       if (ntohs(header->type) == OSPF6_LSTYPE_ROUTER)
+               lsdesc_size = OSPF6_ROUTER_LSDESC_FIX_SIZE;
+       else if (ntohs(header->type) == OSPF6_LSTYPE_NETWORK)
+               lsdesc_size = OSPF6_NETWORK_LSDESC_FIX_SIZE;
+       else
+               return NULL;
+
+       nth = lsdesc + (pos * lsdesc_size);
+
+       if (nth + lsdesc_size <= lsa_end)
+               return nth;
+
+       return NULL;
+}
+
 struct ospf6 *ospf6_get_by_lsdb(struct ospf6_lsa *lsa)
 {
        struct ospf6 *ospf6 = NULL;
index 2f443603c2884cddc46e98bd33992fbb7feafd6b..d6e0cf77103089e8b3a34db74fc432ab216a5980 100644 (file)
@@ -374,4 +374,6 @@ struct ospf6_lsa *ospf6_find_external_lsa(struct ospf6 *ospf6,
 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);
+
 #endif /* OSPF6_LSA_H */