diff options
author | Andrew Cooks <acooks.at.bda@gmail.com> | 2024-08-05 08:09:30 +0200 |
---|---|---|
committer | Andrew Cooks <acooks.at.bda@gmail.com> | 2024-09-16 10:38:16 +0200 |
commit | cd6d36fd82603d803666d04fd8e539362ae9fcfa (patch) | |
tree | afd37cf48fd8219e1906d3878698fe13c23061e6 /ospf6d | |
parent | ospf6d: replace TLV_HDR_TOP macro with lsdesc_start function (diff) | |
download | frr-cd6d36fd82603d803666d04fd8e539362ae9fcfa.tar.xz frr-cd6d36fd82603d803666d04fd8e539362ae9fcfa.zip |
ospf6d: add nth_lsdesc()
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>
Diffstat (limited to 'ospf6d')
-rw-r--r-- | ospf6d/ospf6_lsa.c | 22 | ||||
-rw-r--r-- | ospf6d/ospf6_lsa.h | 2 |
2 files changed, 24 insertions, 0 deletions
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index de04391b6..088ebf56a 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -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; diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index 2f443603c..d6e0cf771 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -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 */ |