Skip to content

Commit

Permalink
ospf6d: use macros for LSA pointer calcs
Browse files Browse the repository at this point in the history
Replace open coded iterators with new lsdesc iterator macro

Signed-off-by: Andrew Cooks <[email protected]>
  • Loading branch information
acooks-at-bda committed May 21, 2024
1 parent 0099a99 commit b2210a1
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 196 deletions.
64 changes: 11 additions & 53 deletions ospf6d/ospf6_gr.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,23 +271,12 @@ static int ospf6_router_lsa_contains_adj(struct ospf6_area *area,

type = ntohs(OSPF6_LSTYPE_ROUTER);
for (ALL_LSDB_TYPED_ADVRTR(area->lsdb, type, adv_router, lsa)) {
struct ospf6_router_lsa *router_lsa;
char *start, *end, *current;

struct ospf6_router_lsdesc *lsdesc;
empty = false;
router_lsa = (struct ospf6_router_lsa
*)((char *)lsa->header
+ sizeof(struct ospf6_lsa_header));

/* Iterate over all interfaces in the Router-LSA. */
start = (char *)router_lsa + sizeof(struct ospf6_router_lsa);
end = (char *)lsa->header + ntohs(lsa->header->length);
for (current = start;
current + sizeof(struct ospf6_router_lsdesc) <= end;
current += sizeof(struct ospf6_router_lsdesc)) {
struct ospf6_router_lsdesc *lsdesc;

lsdesc = (struct ospf6_router_lsdesc *)current;
for_each_lsdesc(lsdesc, ospf6_router_lsa, ospf6_router_lsdesc, lsa) {

if (lsdesc->type != OSPF6_ROUTER_LSDESC_POINTTOPOINT)
continue;

Expand All @@ -309,22 +298,11 @@ static bool ospf6_gr_check_router_lsa_consistency(struct ospf6 *ospf6,
struct ospf6_lsa *lsa)
{
if (lsa->header->adv_router == ospf6->router_id) {
struct ospf6_router_lsa *router_lsa;
char *start, *end, *current;

router_lsa = (struct ospf6_router_lsa
*)((char *)lsa->header
+ sizeof(struct ospf6_lsa_header));
struct ospf6_router_lsdesc *lsdesc;

/* Iterate over all interfaces in the Router-LSA. */
start = (char *)router_lsa + sizeof(struct ospf6_router_lsa);
end = (char *)lsa->header + ntohs(lsa->header->length);
for (current = start;
current + sizeof(struct ospf6_router_lsdesc) <= end;
current += sizeof(struct ospf6_router_lsdesc)) {
struct ospf6_router_lsdesc *lsdesc;

lsdesc = (struct ospf6_router_lsdesc *)current;
for_each_lsdesc(lsdesc, ospf6_router_lsa, ospf6_router_lsdesc, lsa) {

if (lsdesc->type != OSPF6_ROUTER_LSDESC_POINTTOPOINT)
continue;

Expand Down Expand Up @@ -400,8 +378,6 @@ static bool ospf6_gr_check_adjs_lsa_transit(struct ospf6_area *area,
/* Check if we are the DR. */
if (neighbor_router_id == ospf6->router_id) {
struct ospf6_lsa *lsa;
char *start, *end, *current;
struct ospf6_network_lsa *network_lsa;
struct ospf6_network_lsdesc *lsdesc;

/* Lookup Network LSA corresponding to this interface. */
Expand All @@ -412,15 +388,7 @@ static bool ospf6_gr_check_adjs_lsa_transit(struct ospf6_area *area,
return false;

/* Iterate over all routers present in the network. */
network_lsa = (struct ospf6_network_lsa
*)((char *)lsa->header
+ sizeof(struct ospf6_lsa_header));
start = (char *)network_lsa + sizeof(struct ospf6_network_lsa);
end = (char *)lsa->header + ntohs(lsa->header->length);
for (current = start;
current + sizeof(struct ospf6_network_lsdesc) <= end;
current += sizeof(struct ospf6_network_lsdesc)) {
lsdesc = (struct ospf6_network_lsdesc *)current;
for_each_lsdesc(lsdesc, ospf6_network_lsa, ospf6_network_lsdesc, lsa) {

/* Skip self in the pseudonode. */
if (lsdesc->router_id == ospf6->router_id)
Expand Down Expand Up @@ -450,25 +418,15 @@ static bool ospf6_gr_check_adjs_lsa_transit(struct ospf6_area *area,
return true;
}



static bool ospf6_gr_check_adjs_lsa(struct ospf6_area *area,
struct ospf6_lsa *lsa)
{
struct ospf6_router_lsa *router_lsa;
char *start, *end, *current;

router_lsa =
(struct ospf6_router_lsa *)((char *)lsa->header
+ sizeof(struct ospf6_lsa_header));
struct ospf6_router_lsdesc *lsdesc;

/* Iterate over all interfaces in the Router-LSA. */
start = (char *)router_lsa + sizeof(struct ospf6_router_lsa);
end = (char *)lsa->header + ntohs(lsa->header->length);
for (current = start;
current + sizeof(struct ospf6_router_lsdesc) <= end;
current += sizeof(struct ospf6_router_lsdesc)) {
struct ospf6_router_lsdesc *lsdesc;

lsdesc = (struct ospf6_router_lsdesc *)current;
for_each_lsdesc(lsdesc, ospf6_router_lsa, ospf6_router_lsdesc, lsa) {
switch (lsdesc->type) {
case OSPF6_ROUTER_LSDESC_POINTTOPOINT:
if (!ospf6_gr_check_adj_id(area,
Expand Down
Loading

0 comments on commit b2210a1

Please sign in to comment.