Dropping the macro enables better compiler type checking.
The macro was not used consistently when reading the lsa size from the
header, so this change also aims to use the replacement inline function
consistently.
Keeping the inline function has (marginal) utility in that it ensures that
the endian conversion is consistently performed.
Signed-off-by: Andrew Cooks <acooks.at.bda@gmail.com>
return 1;
/* compare body */
- if (ntohs(lsa1->header->length) != ntohs(lsa2->header->length))
+ if (ospf6_lsa_size(lsa1->header) != ospf6_lsa_size(lsa2->header))
return 1;
- len = ntohs(lsa1->header->length) - sizeof(struct ospf6_lsa_header);
+ len = ospf6_lsa_size(lsa1->header) - sizeof(struct ospf6_lsa_header);
return memcmp(lsa1->header + 1, lsa2->header + 1, len);
}
if (OSPF6_LSA_IS_MAXAGE(lsa1) ^ OSPF6_LSA_IS_MAXAGE(lsa2))
return 1;
- if (ntohs(lsa1->header->length) != ntohs(lsa2->header->length))
+ if (ospf6_lsa_size(lsa1->header) != ospf6_lsa_size(lsa2->header))
return 1;
/* Going beyond LSA headers to compare the payload only makes sense,
* when both LSAs aren't header-only. */
if (CHECK_FLAG(lsa1->flag, OSPF6_LSA_HEADERONLY))
return 0;
- length = OSPF6_LSA_SIZE(lsa1->header) - sizeof(struct ospf6_lsa_header);
+ length = ospf6_lsa_size(lsa1->header) - sizeof(struct ospf6_lsa_header);
/* Once upper layer verifies LSAs received, length underrun should
* become a warning. */
if (length <= 0)
json_object_int_add(json_obj, "checksum",
ntohs(lsa->header->checksum));
json_object_int_add(json_obj, "length",
- ntohs(lsa->header->length));
+ ospf6_lsa_size(lsa->header));
json_object_int_add(json_obj, "flag", lsa->flag);
json_object_int_add(json_obj, "lock", lsa->lock);
json_object_int_add(json_obj, "reTxCount", lsa->retrans_count);
(unsigned long)ntohl(lsa->header->seqnum));
vty_out(vty, "CheckSum: %#06hx Length: %hu\n",
ntohs(lsa->header->checksum),
- ntohs(lsa->header->length));
+ ospf6_lsa_size(lsa->header));
vty_out(vty, "Flag: %x \n", lsa->flag);
vty_out(vty, "Lock: %d \n", lsa->lock);
vty_out(vty, "ReTx Count: %d\n", lsa->retrans_count);
uint16_t lsa_size = 0;
/* size of the entire LSA */
- lsa_size = ntohs(header->length); /* XXX vulnerable */
+ lsa_size = ospf6_lsa_size(header); /* XXX vulnerable */
lsa = ospf6_lsa_alloc(lsa_size);
buffer - (uint8_t *)&lsa_header->age; /* should be 2 */
/* Skip the AGE field */
- uint16_t len = ntohs(lsa_header->length) - type_offset;
+ uint16_t len = ospf6_lsa_size(lsa_header) - type_offset;
/* Checksum offset starts from "type" field, not the beginning of the
lsa_header struct. The offset is 14, rather than 16. */
buffer - (uint8_t *)&lsa_header->age; /* should be 2 */
/* Skip the AGE field */
- uint16_t len = ntohs(lsa_header->length) - type_offset;
+ uint16_t len = ospf6_lsa_size(lsa_header) - type_offset;
return (fletcher_checksum(buffer, len, FLETCHER_CHECKSUM_VALIDATE)
== 0);
uint16_t length; /* LSA length */
};
-#define OSPF6_LSA_SIZE(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);
return (char *)header + ntohs(header->length);
}
+static inline uint16_t ospf6_lsa_size(struct ospf6_lsa_header *header)
+{
+ return ntohs(header->length);
+}
+
#define OSPF6_LSA_IS_TYPE(t, L) \
((L)->header->type == htons(OSPF6_LSTYPE_##t) ? 1 : 0)
#define OSPF6_LSA_IS_SAME(L1, L2) \
&& action == OSPF6_ACTION_RECV)
|| (IS_OSPF6_DEBUG_MESSAGE(oh->type, SEND)
&& action == OSPF6_ACTION_SEND)) {
-
- for (p = (char *)((caddr_t)lsupdate
- + sizeof(struct ospf6_lsupdate));
- p < OSPF6_MESSAGE_END(oh)
- && p + OSPF6_LSA_SIZE(p) <= OSPF6_MESSAGE_END(oh);
- p += OSPF6_LSA_SIZE(p)) {
+ for (p = (char *)((caddr_t)lsupdate +
+ sizeof(struct ospf6_lsupdate));
+ p < OSPF6_MESSAGE_END(oh) &&
+ p + ospf6_lsa_size((struct ospf6_lsa_header *)p) <=
+ OSPF6_MESSAGE_END(oh);
+ p += ospf6_lsa_size((struct ospf6_lsa_header *)p)) {
ospf6_lsa_header_print_raw(
(struct ospf6_lsa_header *)p);
}
return MSG_NG;
}
/* save on ntohs() calls here and in the LSA validator */
- lsalen = OSPF6_LSA_SIZE(lsah);
+ lsalen = ospf6_lsa_size(lsah);
if (lsalen < OSPF6_LSA_HEADER_SIZE) {
zlog_warn(
"%s: malformed LSA header #%u, declared length is %u B",
/* Process LSAs */
for (p = (char *)((caddr_t)lsupdate + sizeof(struct ospf6_lsupdate));
- p < OSPF6_MESSAGE_END(oh)
- && p + OSPF6_LSA_SIZE(p) <= OSPF6_MESSAGE_END(oh);
- p += OSPF6_LSA_SIZE(p)) {
+ p < OSPF6_MESSAGE_END(oh) &&
+ p + ospf6_lsa_size((struct ospf6_lsa_header *)p) <=
+ OSPF6_MESSAGE_END(oh);
+ p += ospf6_lsa_size((struct ospf6_lsa_header *)p)) {
ospf6_receive_lsa(on, (struct ospf6_lsa_header *)p);
}
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
for (ALL_LSDB(on->lsupdate_list, lsa, lsanext)) {
- if ((length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE) >
+ if ((length + ospf6_lsa_size(lsa->header) + OSPF6_HEADER_SIZE) >
ospf6_packet_max(on->ospf6_if)) {
ospf6_fill_header(on->ospf6_if, (*op)->s,
length + OSPF6_HEADER_SIZE);
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
}
ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay);
- stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
+ stream_put((*op)->s, lsa->header, ospf6_lsa_size(lsa->header));
(*lsa_cnt)++;
- length += OSPF6_LSA_SIZE(lsa->header);
+ length += ospf6_lsa_size(lsa->header);
assert(lsa->lock == 2);
ospf6_lsdb_remove(lsa, on->lsupdate_list);
}
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
for (ALL_LSDB(on->retrans_list, lsa, lsanext)) {
- if ((length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE) >
+ if ((length + ospf6_lsa_size(lsa->header) + OSPF6_HEADER_SIZE) >
ospf6_packet_max(on->ospf6_if)) {
ospf6_fill_header(on->ospf6_if, (*op)->s,
length + OSPF6_HEADER_SIZE);
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
}
ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay);
- stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
+ stream_put((*op)->s, lsa->header, ospf6_lsa_size(lsa->header));
(*lsa_cnt)++;
- length += OSPF6_LSA_SIZE(lsa->header);
+ length += ospf6_lsa_size(lsa->header);
}
return length;
}
/* skip over fixed header */
stream_forward_endp(op->s, OSPF6_LS_UPD_MIN_SIZE);
ospf6_lsa_age_update_to_send(lsa, on->ospf6_if->transdelay);
- stream_put(op->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
- length = OSPF6_HEADER_SIZE + OSPF6_LS_UPD_MIN_SIZE
- + OSPF6_LSA_SIZE(lsa->header);
+ stream_put(op->s, lsa->header, ospf6_lsa_size(lsa->header));
+ length = OSPF6_HEADER_SIZE + OSPF6_LS_UPD_MIN_SIZE +
+ ospf6_lsa_size(lsa->header);
ospf6_fill_header(on->ospf6_if, op->s, length);
ospf6_fill_lsupdate_header(op->s, 1);
op->length = length;
stream_forward_endp((*op)->s, OSPF6_LS_UPD_MIN_SIZE);
for (ALL_LSDB(oi->lsupdate_list, lsa, lsanext)) {
- if (length + OSPF6_LSA_SIZE(lsa->header) + OSPF6_HEADER_SIZE >
+ if (length + ospf6_lsa_size(lsa->header) + OSPF6_HEADER_SIZE >
ospf6_packet_max(oi)) {
ospf6_fill_header(oi, (*op)->s,
length + OSPF6_HEADER_SIZE);
}
ospf6_lsa_age_update_to_send(lsa, oi->transdelay);
- stream_put((*op)->s, lsa->header, OSPF6_LSA_SIZE(lsa->header));
+ stream_put((*op)->s, lsa->header, ospf6_lsa_size(lsa->header));
(*lsa_cnt)++;
- length += OSPF6_LSA_SIZE(lsa->header);
+ length += ospf6_lsa_size(lsa->header);
assert(lsa->lock == 2);
ospf6_lsdb_remove(lsa, oi->lsupdate_list);
case OSPFv3WWLSDBCHECKSUM:
return SNMP_INTEGER(ntohs(lsa->header->checksum));
case OSPFv3WWLSDBADVERTISEMENT:
- *var_len = ntohs(lsa->header->length);
+ *var_len = ospf6_lsa_size(lsa->header);
return (uint8_t *)lsa->header;
case OSPFv3WWLSDBTYPEKNOWN:
return SNMP_INTEGER(OSPF6_LSA_IS_KNOWN(lsa->header->type)
inet_ntop(AF_INET, &adv_router, abuf, sizeof(abuf));
if (lsa)
zlog_debug(" Link to: %s len %u, V %s", lsa->name,
- ntohs(lsa->header->length), v->name);
+ ospf6_lsa_size(lsa->header), v->name);
else
zlog_debug(" Link to: [%s Id:%s Adv:%s] No LSA , V %s",
ospf6_lstype_name(type), ibuf, abuf,
continue;
}
lsa_header = rtr_lsa->header;
- total_lsa_length += (ntohs(lsa_header->length) - lsa_length);
+ total_lsa_length += (ospf6_lsa_size(lsa_header) - lsa_length);
num_lsa++;
rtr_lsa = ospf6_lsdb_next(end, rtr_lsa);
}
if (!OSPF6_LSA_IS_MAXAGE(rtr_lsa)) {
/* Append first Link State ID LSA */
lsa_header = rtr_lsa->header;
- memcpy(new_header, lsa_header, ntohs(lsa_header->length));
+ memcpy(new_header, lsa_header, ospf6_lsa_size(lsa_header));
/* Assign new lsa length as aggregated length. */
((struct ospf6_lsa_header *)new_header)->length =
htons(total_lsa_length);
- new_header += ntohs(lsa_header->length);
+ new_header += ospf6_lsa_size(lsa_header);
num_lsa--;
}
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(
- "%s: Next Router LSA %s to aggreat with len %u interface_id %s",
- __func__, rtr_lsa->name,
- ntohs(lsa_header->length), ifbuf);
+ zlog_debug("%s: Next Router LSA %s to aggreat with len %u interface_id %s",
+ __func__, rtr_lsa->name,
+ ospf6_lsa_size(lsa_header), ifbuf);
}
/* Append Next Link State ID LSA */
lsa_header = rtr_lsa->header;
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);
+ (ospf6_lsa_size(lsa_header) - lsa_length));
+ new_header += (ospf6_lsa_size(lsa_header) - lsa_length);
num_lsa--;
rtr_lsa = ospf6_lsdb_next(end, rtr_lsa);
if (IS_OSPF6_DEBUG_SPF(PROCESS))
zlog_debug("%s: LSA %s id %u type 0%x len %u num_lsa %u",
__func__, lsa->name, ntohl(lsa->header->id),
- ntohs(lsa->header->type), ntohs(lsa->header->length),
- num_lsa);
+ ntohs(lsa->header->type),
+ ospf6_lsa_size(lsa->header), num_lsa);
return lsa;
}