Skip to content

Commit

Permalink
ospf6d: add an iterator for LSA descriptors
Browse files Browse the repository at this point in the history
Adds iterator macros for the descriptors in an LSA, to replace the
number of repeated open coded pointer casts and pointer arithmetic.

Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
  • Loading branch information
acooks-at-bda committed May 22, 2024
1 parent a49fb62 commit 772f1b7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ospf6d/ospf6_lsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ inline uint16_t ospf6_lsa_size(struct ospf6_lsa_header *header)
#define OSPF6_LSA_IS_CHANGED(L1, L2) ospf6_lsa_is_changed (L1, L2)
#define OSPF6_LSA_IS_SEQWRAP(L) ((L)->header->seqnum == htonl(OSPF_MAX_SEQUENCE_NUMBER + 1))

#define lsa_from_container(type, container) \
((struct type *)((char *)container->header + \
sizeof(struct ospf6_lsa_header)))

#define lsdesc_start(lsdesc_type, lsa) \
((struct lsdesc_type *)((char *)lsa + sizeof(*lsa)))

#define for_each_lsdesc(current, lsa_type, lsdesc_type, lsa_container) \
for (current = \
lsdesc_start(lsdesc_type, \
lsa_from_container(lsa_type, lsa_container)); \
(char *)(current + 1) <= ospf6_lsa_end(lsa_container->header); \
current++)

struct ospf6_lsa {
char name[64]; /* dump string */
Expand Down

0 comments on commit 772f1b7

Please sign in to comment.