summaryrefslogtreecommitdiff
path: root/ospf6d/ospf6_intra.c
diff options
context:
space:
mode:
authorAndrew Cooks <acooks.at.bda@gmail.com>2024-07-18 12:56:14 +1000
committerAndrew Cooks <acooks.at.bda@gmail.com>2024-09-16 18:38:16 +1000
commitd0366de57c11a7698945acc1dfaf8a6bead1f6f5 (patch)
treeba30a659bcfc254368c3dd56fe12226e7f188de3 /ospf6d/ospf6_intra.c
parent1bb4955371b234e3833fbe8421bf31838d9aae7b (diff)
ospf6d: replace TLV_HDR_TOP macro with lsdesc_start function
The original TLV_HDR_TOP implementation only worked for Graceful Restart LSAs, because they had no "LSA body". This change introduces a body size lookup table and changes the macro to a function that accounts for the LSA body for all LSA types, and provides type checking on the provided pointer before arithmetic. It also removes the open type casting and pointer arithmetic. The introduced lsdesc_start() is used to find the start of a descriptor, and will be used for TLVs in E-LSAs as well as old LSA. Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
Diffstat (limited to 'ospf6d/ospf6_intra.c')
-rw-r--r--ospf6d/ospf6_intra.c35
1 files changed, 12 insertions, 23 deletions
diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c
index f12f125b7b..470fc66084 100644
--- a/ospf6d/ospf6_intra.c
+++ b/ospf6d/ospf6_intra.c
@@ -246,9 +246,7 @@ void ospf6_router_lsa_originate(struct event *thread)
ospf6_router_lsa_options_set(oa, router_lsa);
/* describe links for each interfaces */
- lsdesc = (struct ospf6_router_lsdesc
- *)((caddr_t)router_lsa
- + sizeof(struct ospf6_router_lsa));
+ lsdesc = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_ROUTER);
for (ALL_LIST_ELEMENTS(oa->if_list, node, nnode, oi)) {
/* Interfaces in state Down or Loopback are not described */
@@ -271,9 +269,9 @@ void ospf6_router_lsa_originate(struct event *thread)
&& ((size_t)((char *)lsdesc - buffer)
+ sizeof(struct ospf6_router_lsdesc)
> oa->router_lsa_size_limit)) {
- if ((caddr_t)lsdesc
- == (caddr_t)router_lsa
- + sizeof(struct ospf6_router_lsa)) {
+ if (lsdesc ==
+ lsdesc_start_lsa_type(lsa_header,
+ OSPF6_LSTYPE_ROUTER)) {
zlog_warn(
"Size limit setting for Router-LSA too short");
return;
@@ -307,9 +305,8 @@ void ospf6_router_lsa_originate(struct event *thread)
ospf6_router_lsa_options_set(oa, router_lsa);
/* describe links for each interfaces */
- lsdesc = (struct ospf6_router_lsdesc
- *)((caddr_t)router_lsa
- + sizeof(struct ospf6_router_lsa));
+ lsdesc = lsdesc_start_lsa_type(lsa_header,
+ OSPF6_LSTYPE_ROUTER);
link_state_id++;
}
@@ -571,9 +568,7 @@ void ospf6_network_lsa_originate(struct event *thread)
network_lsa->options[2] |= link_lsa->options[2];
}
- lsdesc = (struct ospf6_network_lsdesc
- *)((caddr_t)network_lsa
- + sizeof(struct ospf6_network_lsa));
+ lsdesc = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_NETWORK);
/* set Link Description to the router itself */
lsdesc->router_id = oi->area->ospf6->router_id;
@@ -797,8 +792,7 @@ void ospf6_link_lsa_originate(struct event *thread)
sizeof(struct in6_addr));
link_lsa->prefix_num = htonl(oi->route_connected->count);
- op = (struct ospf6_prefix *)((caddr_t)link_lsa
- + sizeof(struct ospf6_link_lsa));
+ op = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_LINK);
/* connected prefix to advertise */
for (route = ospf6_route_head(oi->route_connected); route;
@@ -1109,12 +1103,10 @@ void ospf6_intra_prefix_lsa_originate_stub(struct event *thread)
/* put prefixes to advertise */
prefix_num = 0;
- op = (struct ospf6_prefix *)((caddr_t)intra_prefix_lsa
- + sizeof(struct ospf6_intra_prefix_lsa));
+ op = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_INTRA_PREFIX);
for (route = ospf6_route_head(route_advertise); route;
route = ospf6_route_best_next(route)) {
if (((caddr_t)op - (caddr_t)lsa_header) > MAX_LSA_PAYLOAD) {
-
intra_prefix_lsa->prefix_num = htons(prefix_num);
/* Fill LSA Header */
@@ -1149,10 +1141,8 @@ void ospf6_intra_prefix_lsa_originate_stub(struct event *thread)
/* Put next set of prefixes to advertise */
prefix_num = 0;
- op = (struct ospf6_prefix
- *)((caddr_t)intra_prefix_lsa
- + sizeof(struct
- ospf6_intra_prefix_lsa));
+ op = lsdesc_start_lsa_type(lsa_header,
+ OSPF6_LSTYPE_INTRA_PREFIX);
}
op->prefix_length = route->prefix.prefixlen;
@@ -1339,8 +1329,7 @@ void ospf6_intra_prefix_lsa_originate_transit(struct event *thread)
zlog_debug("Trailing garbage in %s", lsa->name);
}
- op = (struct ospf6_prefix *)((caddr_t)intra_prefix_lsa
- + sizeof(struct ospf6_intra_prefix_lsa));
+ op = lsdesc_start_lsa_type(lsa_header, OSPF6_LSTYPE_INTRA_PREFIX);
prefix_num = 0;
for (route = ospf6_route_head(route_advertise); route;