lsa_header = (struct ospf6_lsa_header *)buffer;
if (route->type == OSPF6_DEST_TYPE_ROUTER) {
- router_lsa = (struct ospf6_inter_router_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ router_lsa = (struct ospf6_inter_router_lsa *)
+ ospf6_lsa_header_end(lsa_header);
p = (caddr_t)router_lsa + sizeof(struct ospf6_inter_router_lsa);
/* Fill Inter-Area-Router-LSA */
router_lsa->router_id = ADV_ROUTER_IN_PREFIX(&route->prefix);
type = htons(OSPF6_LSTYPE_INTER_ROUTER);
} else {
- prefix_lsa = (struct ospf6_inter_prefix_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ prefix_lsa = (struct ospf6_inter_prefix_lsa *)
+ ospf6_lsa_header_end(lsa_header);
p = (caddr_t)prefix_lsa + sizeof(struct ospf6_inter_prefix_lsa);
/* Fill Inter-Area-Prefix-LSA */
oa->name);
}
- prefix_lsa =
- (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END(
- lsa->header);
+ prefix_lsa = (struct ospf6_inter_prefix_lsa *)
+ ospf6_lsa_header_end(lsa->header);
prefix.family = AF_INET6;
prefix.prefixlen = prefix_lsa->prefix.prefix_length;
ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa,
oa->name);
}
- router_lsa =
- (struct ospf6_inter_router_lsa *)OSPF6_LSA_HEADER_END(
- lsa->header);
- ospf6_linkstate_prefix(router_lsa->router_id, htonl(0),
- &prefix);
+ router_lsa = (struct ospf6_inter_router_lsa *)
+ ospf6_lsa_header_end(lsa->header);
+ ospf6_linkstate_prefix(router_lsa->router_id, htonl(0), &prefix);
if (is_debug)
inet_ntop(AF_INET, &router_lsa->router_id, buf,
sizeof(buf));
char tbuf[16];
if (lsa != NULL) {
- prefix_lsa =
- (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END(
- lsa->header);
+ prefix_lsa = (struct ospf6_inter_prefix_lsa *)
+ ospf6_lsa_header_end(lsa->header);
ospf6_prefix_in6_addr(&in6, prefix_lsa, &prefix_lsa->prefix);
if (buf) {
struct ospf6_inter_prefix_lsa *prefix_lsa;
char buf[INET6_ADDRSTRLEN];
- prefix_lsa = (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END(
+ prefix_lsa = (struct ospf6_inter_prefix_lsa *)ospf6_lsa_header_end(
lsa->header);
if (use_json) {
struct ospf6_inter_router_lsa *router_lsa;
if (lsa != NULL) {
- router_lsa =
- (struct ospf6_inter_router_lsa *)OSPF6_LSA_HEADER_END(
- lsa->header);
+ router_lsa = (struct ospf6_inter_router_lsa *)
+ ospf6_lsa_header_end(lsa->header);
if (buf)
struct ospf6_inter_router_lsa *router_lsa;
char buf[64];
- router_lsa = (struct ospf6_inter_router_lsa *)OSPF6_LSA_HEADER_END(
+ router_lsa = (struct ospf6_inter_router_lsa *)ospf6_lsa_header_end(
lsa->header);
ospf6_options_printbuf(router_lsa->options, buf, sizeof(buf));
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- as_external_lsa = (struct ospf6_as_external_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ as_external_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
+ lsa_header);
p = (caddr_t)((caddr_t)as_external_lsa
+ sizeof(struct ospf6_as_external_lsa));
if (!lsa)
return 0;
- external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (!CHECK_FLAG(external->bits_metric, OSPF6_ASBR_BIT_T))
type = ntohs(lsa->header->type);
oa = lsa->lsdb->data;
- external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL))
int type;
bool debug = false;
- external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (IS_OSPF6_DEBUG_EXAMIN(AS_EXTERNAL) || (IS_OSPF6_DEBUG_NSSA))
char tbuf[16];
if (lsa) {
- external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (pos == 0) {
char buf[64];
assert(lsa->header);
- external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
/* bits */
return;
}
- external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END
- (aggr_lsa->header);
+ external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
+ aggr_lsa->header);
metric = (unsigned long)OSPF6_ASBR_METRIC(external);
tag = ospf6_as_external_lsa_get_tag(aggr_lsa);
mtype = CHECK_FLAG(external->bits_metric,
return OSPF6_FAILURE;
}
- asel = (struct ospf6_as_external_lsa *)
- OSPF6_LSA_HEADER_END(lsa->header);
+ asel = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(lsa->header);
metric = (unsigned long)OSPF6_ASBR_METRIC(asel);
tag = ospf6_as_external_lsa_get_tag(lsa);
mtype = CHECK_FLAG(asel->bits_metric,
lsa = ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_AS_EXTERNAL),
htonl(info->id), ospf6->router_id, ospf6->lsdb);
if (lsa) {
- ext_lsa = (struct ospf6_as_external_lsa
- *)((char *)(lsa->header)
- + sizeof(struct ospf6_lsa_header));
+ ext_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
+ lsa->header);
if (rt->prefix.prefixlen != ext_lsa->prefix.prefix_length)
return;
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- grace_lsa =
- (struct ospf6_grace_lsa *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ grace_lsa = (struct ospf6_grace_lsa *)ospf6_lsa_header_end(lsa_header);
/* Put grace period. */
grace_lsa->tlv_period.header.type = htons(GRACE_PERIOD_TYPE);
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- router_lsa =
- (struct ospf6_router_lsa *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ router_lsa = (struct ospf6_router_lsa *)ospf6_lsa_header_end(lsa_header);
ospf6_router_lsa_options_set(oa, router_lsa);
/* Reset Buffer to fill next Router LSA */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- router_lsa =
- (struct ospf6_router_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ router_lsa = (struct ospf6_router_lsa *)
+ ospf6_lsa_header_end(lsa_header);
ospf6_router_lsa_options_set(oa, router_lsa);
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
network_lsa =
- (struct ospf6_network_lsa *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ (struct ospf6_network_lsa *)ospf6_lsa_header_end(lsa_header);
/* Collect the interface's Link-LSAs to describe
network's optional capabilities */
type = htons(OSPF6_LSTYPE_LINK);
for (ALL_LSDB_TYPED(oi->lsdb, type, lsa)) {
- link_lsa = (struct ospf6_link_lsa
- *)((caddr_t)lsa->header
- + sizeof(struct ospf6_lsa_header));
+ link_lsa = (struct ospf6_link_lsa *)ospf6_lsa_header_end(
+ lsa->header);
network_lsa->options[0] |= link_lsa->options[0];
network_lsa->options[1] |= link_lsa->options[1];
network_lsa->options[2] |= link_lsa->options[2];
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- link_lsa = (struct ospf6_link_lsa *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ link_lsa = (struct ospf6_link_lsa *)ospf6_lsa_header_end(lsa_header);
/* Fill Link-LSA */
link_lsa->priority = oi->priority;
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- intra_prefix_lsa = (struct ospf6_intra_prefix_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end(
+ lsa_header);
/* Fill Intra-Area-Prefix-LSA */
intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_ROUTER);
/* Prepare next buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- intra_prefix_lsa =
- (struct ospf6_intra_prefix_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
+ ospf6_lsa_header_end(lsa_header);
/* Fill Intra-Area-Prefix-LSA */
intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_ROUTER);
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- intra_prefix_lsa = (struct ospf6_intra_prefix_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end(
+ lsa_header);
/* Fill Intra-Area-Prefix-LSA */
intra_prefix_lsa->ref_type = htons(OSPF6_LSTYPE_NETWORK);
}
intra_prefix_lsa =
(struct ospf6_intra_prefix_lsa *)
- OSPF6_LSA_HEADER_END(lsa->header);
+ ospf6_lsa_header_end(
+ lsa->header);
if (intra_prefix_lsa->ref_adv_router
== oa->ospf6->router_id) {
oa = OSPF6_AREA(lsa->lsdb->data);
- intra_prefix_lsa =
- (struct ospf6_intra_prefix_lsa *)OSPF6_LSA_HEADER_END(
- lsa->header);
+ intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end(
+ lsa->header);
if (intra_prefix_lsa->ref_type == htons(OSPF6_LSTYPE_ROUTER) ||
intra_prefix_lsa->ref_type == htons(OSPF6_LSTYPE_NETWORK))
ospf6_linkstate_prefix(intra_prefix_lsa->ref_adv_router,
oa = OSPF6_AREA(lsa->lsdb->data);
- intra_prefix_lsa =
- (struct ospf6_intra_prefix_lsa *)OSPF6_LSA_HEADER_END(
- lsa->header);
+ intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)ospf6_lsa_header_end(
+ lsa->header);
prefix_num = ntohs(intra_prefix_lsa->prefix_num);
start = (caddr_t)intra_prefix_lsa
static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
json_object *json_obj, bool use_json)
{
- uint8_t *start, *end, *current;
+ char *start, *end, *current;
- start = (uint8_t *)lsa->header + sizeof(struct ospf6_lsa_header);
- end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
+ start = ospf6_lsa_header_end(lsa->header);
+ end = (char *)lsa->header + ntohs(lsa->header->length);
if (use_json) {
json_object_string_add(json_obj, "lsaType", "unknown");
if (length <= 0)
return 0;
- return memcmp(OSPF6_LSA_HEADER_END(lsa1->header),
- OSPF6_LSA_HEADER_END(lsa2->header), length);
+ return memcmp(ospf6_lsa_header_end(lsa1->header),
+ ospf6_lsa_header_end(lsa2->header), length);
}
/* ospf6 age functions */
uint16_t length; /* LSA length */
};
-#define OSPF6_LSA_HEADER_END(h) ((caddr_t)(h) + sizeof(struct ospf6_lsa_header))
#define OSPF6_LSA_SIZE(h) (ntohs(((struct ospf6_lsa_header *)(h))->length))
#define OSPF6_LSA_END(h) \
((caddr_t)(h) + ntohs(((struct ospf6_lsa_header *)(h))->length))
+
+static inline char *ospf6_lsa_header_end(struct ospf6_lsa_header *header)
+{
+ return (char *)header + sizeof(struct ospf6_lsa_header);
+}
+
#define OSPF6_LSA_IS_TYPE(t, L) \
((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0)
#define OSPF6_LSA_IS_SAME(L1, L2) \
struct ospf6_inter_prefix_lsa *prefix_lsa;
struct prefix prefix;
- prefix_lsa =
- (struct ospf6_inter_prefix_lsa *)OSPF6_LSA_HEADER_END(
- lsa->header);
+ prefix_lsa = (struct ospf6_inter_prefix_lsa *)
+ ospf6_lsa_header_end(lsa->header);
prefix.family = AF_INET6;
prefix.prefixlen = prefix_lsa->prefix.prefix_length;
ospf6_prefix_in6_addr(&prefix.u.prefix6, prefix_lsa,
/* Verify all the router LSA to compare the router ID */
for (ALL_LSDB_TYPED(oa->lsdb, type, lsa)) {
-
- router_lsa = (struct ospf6_router_lsa
- *)((caddr_t)lsa->header
- + sizeof(struct ospf6_lsa_header));
+ router_lsa = (struct ospf6_router_lsa *)ospf6_lsa_header_end(
+ lsa->header);
/* ignore non-ABR routers */
if (!CHECK_FLAG(router_lsa->bits, OSPF6_ROUTER_BIT_B))
}
/* find the translated Type-5 for this Type-7 */
- nssa = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ nssa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
type7->header);
prefix.family = AF_INET6;
prefix.prefixlen = nssa->prefix.prefix_length;
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- extnew = (struct ospf6_as_external_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
- ext = (struct ospf6_as_external_lsa
- *)((caddr_t)(type7->header)
- + sizeof(struct ospf6_lsa_header));
+ extnew = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
+ lsa_header);
+ ext = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
+ type7->header);
old_ptr =
(caddr_t)((caddr_t)ext + sizeof(struct ospf6_as_external_lsa));
new_ptr = (caddr_t)((caddr_t)extnew
"%s: try to find translated Type-5 LSA for %s",
__func__, type7->name);
- ext_lsa = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ ext_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
type7->header);
prefix.family = AF_INET6;
prefix.prefixlen = ext_lsa->prefix.prefix_length;
struct ospf6 *ospf6;
ospf6 = area->ospf6;
- nssa_lsa = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ nssa_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
if (!CHECK_FLAG(nssa_lsa->prefix.prefix_options,
/* prepare buffer */
memset(buffer, 0, sizeof(buffer));
lsa_header = (struct ospf6_lsa_header *)buffer;
- as_external_lsa = (struct ospf6_as_external_lsa
- *)((caddr_t)lsa_header
- + sizeof(struct ospf6_lsa_header));
+ as_external_lsa = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
+ lsa_header);
p = (caddr_t)((caddr_t)as_external_lsa
+ sizeof(struct ospf6_as_external_lsa));
v->lsa = lsa;
/* capability bits + options */
- v->capability = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header));
- v->options[0] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 1);
- v->options[1] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 2);
- v->options[2] = *(uint8_t *)(OSPF6_LSA_HEADER_END(lsa->header) + 3);
+ v->capability = *(uint8_t *)(ospf6_lsa_header_end(lsa->header));
+ v->options[0] = *(uint8_t *)(ospf6_lsa_header_end(lsa->header) + 1);
+ v->options[1] = *(uint8_t *)(ospf6_lsa_header_end(lsa->header) + 2);
+ v->options[2] = *(uint8_t *)(ospf6_lsa_header_end(lsa->header) + 3);
v->nh_list = list_new();
v->nh_list->cmp = (int (*)(void *, void *))ospf6_nexthop_cmp;
size = (OSPF6_LSA_IS_TYPE(ROUTER, lsa)
? sizeof(struct ospf6_router_lsdesc)
: sizeof(struct ospf6_network_lsdesc));
- for (backlink = OSPF6_LSA_HEADER_END(lsa->header) + 4;
+ for (backlink = ospf6_lsa_header_end(lsa->header) + 4;
backlink + size <= OSPF6_LSA_END(lsa->header); backlink += size) {
assert(!(OSPF6_LSA_IS_TYPE(NETWORK, lsa)
&& VERTEX_IS_TYPE(NETWORK, v)));
!= lsa->header->id)
continue;
- link_lsa = (struct ospf6_link_lsa *)OSPF6_LSA_HEADER_END(
+ link_lsa = (struct ospf6_link_lsa *)ospf6_lsa_header_end(
lsa->header);
if (IS_OSPF6_DEBUG_SPF(PROCESS)) {
inet_ntop(AF_INET6, &link_lsa->linklocal_addr, buf,
size = (VERTEX_IS_TYPE(ROUTER, v)
? sizeof(struct ospf6_router_lsdesc)
: sizeof(struct ospf6_network_lsdesc));
- for (lsdesc = OSPF6_LSA_HEADER_END(v->lsa->header) + 4;
+ for (lsdesc = ospf6_lsa_header_end(v->lsa->header) + 4;
lsdesc + size <= OSPF6_LSA_END(v->lsa->header);
lsdesc += size) {
lsa = ospf6_lsdesc_lsa(lsdesc, v);
}
if (IS_OSPF6_DEBUG_SPF(PROCESS)) {
- lsd = OSPF6_LSA_HEADER_END(rtr_lsa->header) + 4;
+ lsd = ospf6_lsa_header_end(rtr_lsa->header) + 4;
interface_id = ROUTER_LSDESC_GET_IFID(lsd);
inet_ntop(AF_INET, &interface_id, ifbuf, sizeof(ifbuf));
zlog_debug(
/* Append Next Link State ID LSA */
lsa_header = rtr_lsa->header;
- memcpy(new_header, (OSPF6_LSA_HEADER_END(rtr_lsa->header) + 4),
+ memcpy(new_header, (ospf6_lsa_header_end(rtr_lsa->header) + 4),
(ntohs(lsa_header->length) - lsa_length));
new_header += (ntohs(lsa_header->length) - lsa_length);
num_lsa--;
return 0;
}
- external = (struct ospf6_as_external_lsa *)OSPF6_LSA_HEADER_END(
+ external = (struct ospf6_as_external_lsa *)ospf6_lsa_header_end(
lsa->header);
prefix.family = AF_INET6;
prefix.prefixlen = external->prefix.prefix_length;