switch (ext_type) {
case AODV_EXT_HELLO:
ah = (const struct aodv_hello *)(const void *)ep;
- if (length < sizeof(struct aodv_hello)) {
- ND_PRINT(" (ext data length %u < %zu)", length, sizeof(struct aodv_hello));
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(struct aodv_hello), "ext data length");
if (ext_length < 4) {
ND_PRINT("\n\text HELLO - bad length %u", ext_length);
goto invalid;
u_int i;
const struct aodv_rreq *ap = (const struct aodv_rreq *)dat;
- if (length < sizeof(*ap)) {
- ND_PRINT(" (message length %u)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*ap), "message length");
ND_PRINT(" %u %s%s%s%s%shops %u id 0x%08x\n"
"\tdst %s seq %u src %s seq %u", length,
GET_U_1(ap->rreq_type) & RREQ_JOIN ? "[J]" : "",
u_int i;
const struct aodv_rrep *ap = (const struct aodv_rrep *)dat;
- if (length < sizeof(*ap)) {
- ND_PRINT(" (message length %u)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*ap), "message length");
ND_PRINT(" %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %u src %s %u ms", length,
GET_U_1(ap->rrep_type) & RREP_REPAIR ? "[R]" : "",
const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
const struct rerr_unreach *dp;
- if (length < sizeof(*ap)) {
- ND_PRINT(" (message length %u)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*ap), "message length");
ND_PRINT(" %s [items %u] [%u]:",
GET_U_1(ap->rerr_flags) & RERR_NODELETE ? "[D]" : "",
GET_U_1(ap->rerr_dc), length);
dp = (const struct rerr_unreach *)(dat + sizeof(*ap));
i = length - sizeof(*ap);
for (dc = GET_U_1(ap->rerr_dc); dc != 0; dc--) {
- if (i < sizeof(*dp)) {
- ND_PRINT(" (remaining length %u)", i);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(i, sizeof(*dp), "remaining length");
ND_PRINT(" {%s}(%u)", GET_IPADDR_STRING(dp->u_da),
GET_BE_U_4(dp->u_ds));
dp++;
u_int i;
const struct aodv_rreq6 *ap = (const struct aodv_rreq6 *)dat;
- if (length < sizeof(*ap)) {
- ND_PRINT(" (message length %u)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*ap), "message length");
ND_PRINT(" %u %s%s%s%s%shops %u id 0x%08x\n"
"\tdst %s seq %u src %s seq %u", length,
GET_U_1(ap->rreq_type) & RREQ_JOIN ? "[J]" : "",
u_int i;
const struct aodv_rrep6 *ap = (const struct aodv_rrep6 *)dat;
- if (length < sizeof(*ap)) {
- ND_PRINT(" (message length %u)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*ap), "message length");
ND_PRINT(" %u %s%sprefix %u hops %u\n"
"\tdst %s dseq %u src %s %u ms", length,
GET_U_1(ap->rrep_type) & RREP_REPAIR ? "[R]" : "",
const struct aodv_rerr *ap = (const struct aodv_rerr *)dat;
const struct rerr_unreach6 *dp6;
- if (length < sizeof(*ap)) {
- ND_PRINT(" (message length %u)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*ap), "message length");
ND_PRINT(" %s [items %u] [%u]:",
GET_U_1(ap->rerr_flags) & RERR_NODELETE ? "[D]" : "",
GET_U_1(ap->rerr_dc), length);
dp6 = (const struct rerr_unreach6 *)(const void *)(ap + 1);
i = length - sizeof(*ap);
for (dc = GET_U_1(ap->rerr_dc); dc != 0; dc--) {
- if (i < sizeof(*dp6)) {
- ND_PRINT(" (remaining length %u)", i);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(i, sizeof(*dp6), "remaining length");
ND_PRINT(" {%s}(%u)", GET_IP6ADDR_STRING(dp6->u_da),
GET_BE_U_4(dp6->u_ds));
dp6++;
u_int hdrlen;
ndo->ndo_protocol = "llap";
- if (length < sizeof(*lp)) {
- ND_PRINT(" (LLAP length %u is too small)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*lp), "LLAP length");
lp = (const struct LAP *)bp;
bp += sizeof(*lp);
length -= sizeof(*lp);
case lapShortDDP:
ndo->ndo_protocol = "sddp";
- if (length < ddpSSize) {
- ND_PRINT(" (SDDP length %u is too small)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_U(length, ddpSSize, "SDDP length");
sdp = (const struct atShortDDP *)bp;
ND_PRINT("%s.%s",
ataddr_string(ndo, 0, GET_U_1(lp->src)),
case lapDDP:
ndo->ndo_protocol = "ddp";
- if (length < ddpSize) {
- ND_PRINT(" (DDP length %u is too small)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_U(length, ddpSize, "DDP length");
dp = (const struct atDDP *)bp;
snet = GET_BE_U_2(dp->srcNet);
ND_PRINT("%s.%s",
if(!ndo->ndo_eflag)
ND_PRINT("AT ");
- if (length < ddpSize) {
- ND_PRINT(" (length %u is too small)", length);
- goto invalid;
- }
+ ND_LCHECK_U(length, ddpSize);
dp = (const struct atDDP *)bp;
snet = GET_BE_U_2(dp->srcNet);
ND_PRINT("%s.%s", ataddr_string(ndo, snet, GET_U_1(dp->srcNode)),
ndo->ndo_protocol = "aarp";
ND_PRINT("aarp ");
ap = (const struct aarp *)bp;
- if (length < sizeof(*ap)) {
- ND_PRINT(" (length %u is too small)", length);
- goto invalid;
- }
+ ND_LCHECK_ZU(length, sizeof(*ap));
ND_TCHECK_SIZE(ap);
if (GET_BE_U_2(ap->htype) == 1 &&
GET_BE_U_2(ap->ptype) == ETHERTYPE_ATALK &&
uint32_t data;
ndo->ndo_protocol = "atp";
- if (length < sizeof(*ap)) {
- ND_PRINT(" (ATP length %u is too small)", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*ap), "ATP length");
length -= sizeof(*ap);
control = GET_U_1(ap->control);
switch (control & 0xc0) {
uint8_t control;
u_int i;
- if (length < nbpHeaderSize + 8) {
- /* must be room for at least one tuple */
- ND_PRINT(" undersized-nbp %u", length);
- goto invalid;
- }
+ /* must be room for at least one tuple */
+ ND_LCHECKMSG_U(length, nbpHeaderSize + 8, "undersized-nbp");
length -= nbpHeaderSize;
control = GET_U_1(np->control);
ND_PRINT(" nbp-%s", tok2str(nbp_str, "0x%x", control & 0xf0));
ndo->ndo_protocol = "egp";
egp = (const struct egp_packet *)bp;
- if (length < sizeof(*egp)) {
- ND_PRINT(" packet length %u < %zu", length, sizeof(*egp));
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(*egp), "packet length");
ND_TCHECK_SIZE(egp);
version = GET_U_1(egp->egp_version);
uint8_t opt_type;
uint8_t opt_len;
- if (len < 4) {
- ND_PRINT(" (remaining options length %u < 4)", len);
- goto invalid;
- }
+ ND_LCHECKMSG_U(len, 4, "remaining options length");
ND_PRINT("%s", sep);
sep = ", ";
ndo->ndo_protocol = "geneve";
ND_PRINT("Geneve");
- if (len < 8) {
- ND_PRINT(" [length %u < 8]", len);
- goto invalid;
- }
+ ND_LCHECK_U(len, 8);
ver_opt = GET_U_1(bp);
bp += 1;
len = GET_BE_U_2(dat) & L2TP_AVP_HDR_LEN_MASK;
/* If it is not long enough to contain the header, we'll give up. */
- if (len < 6) {
- ND_PRINT(" (AVP length %u < 6)", len);
- goto invalid;
- }
+ ND_LCHECKMSG_U(len, 6, "AVP length");
/* If it goes past the end of the remaining length of the packet,
we'll give up. */
nd_print_protocol_caps(ndo);
ND_PRINT("v%u", (is_ipv6) ? 6 : 4);
- if (length < sizeof(struct olsr_common)) {
- ND_PRINT(" (packet length < %zu)", sizeof(struct olsr_common));
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(struct olsr_common), "packet length");
ptr.common = (const struct olsr_common *)tptr;
length = ND_MIN(length, GET_BE_U_2(ptr.common->packet_len));
switch (msg_type) {
case OLSR_HELLO_MSG:
case OLSR_HELLO_LQ_MSG:
- if (msg_tlen < sizeof(struct olsr_hello)) {
- ND_PRINT(" (message length < %zu)", sizeof(struct olsr_hello));
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(msg_tlen, sizeof(struct olsr_hello), "message length");
ptr.hello = (const struct olsr_hello *)msg_data;
ND_PRINT("\n\t hello-time %.3fs, MPR willingness %u",
case OLSR_TC_MSG:
case OLSR_TC_LQ_MSG:
- if (msg_tlen < sizeof(struct olsr_tc)) {
- ND_PRINT(" (message length < %zu)", sizeof(struct olsr_tc));
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(msg_tlen, sizeof(struct olsr_tc), "message length");
ND_TCHECK_LEN(msg_data, sizeof(struct olsr_tc));
ptr.tc = (const struct olsr_tc *)msg_data;
int name_entries_valid;
u_int i;
- if (msg_tlen < 4) {
- ND_PRINT(" (message length < 4)");
- goto invalid;
- }
+ ND_LCHECKMSG_U(msg_tlen, 4, "message length");
name_entries = GET_BE_U_2(msg_data + 2);
addr_size = 4;
if (name_entry_len%4 != 0)
name_entry_padding = 4-(name_entry_len%4);
- if (msg_tlen < addr_size + name_entry_len + name_entry_padding) {
- ND_PRINT(" (oversized name entry)");
- goto invalid;
- }
+ ND_LCHECKMSG_U(msg_tlen, addr_size + name_entry_len + name_entry_padding,
+ "name entry length");
ND_TCHECK_LEN(msg_data,
addr_size + name_entry_len + name_entry_padding);
const struct rip_netinfo_v1 *ni = (const struct rip_netinfo_v1 *)p;
/* RFC 1058 */
- if (remaining < RIP_ROUTELEN)
- goto invalid;
+ ND_LCHECKMSG_U(remaining, RIP_ROUTELEN, "remaining data length");
ND_TCHECK_SIZE(ni);
family = GET_BE_U_2(ni->rip_family);
if (family != BSD_AFNUM_INET && family != 0) {
u_short family;
const struct rip_netinfo_v2 *ni;
- if (remaining < sizeof(*eh))
- goto invalid;
+ ND_LCHECKMSG_ZU(remaining, sizeof(*eh), "remaining data length");
ND_TCHECK_SIZE(eh);
family = GET_BE_U_2(eh->rip_family);
if (family == 0xFFFF) { /* variable-sized authentication structures */
const struct rip_auth_crypto_v2 *ch;
ch = (const struct rip_auth_crypto_v2 *)p;
- if (remaining < sizeof(*ch))
- goto invalid;
+ ND_LCHECKMSG_ZU(remaining, sizeof(*ch), "remaining data length");
ND_PRINT("\n\t Auth header:");
ND_PRINT(" Packet Len %u,",
GET_BE_U_2(ch->rip_packet_len));
print_unknown_data(ndo, p + sizeof(*eh), "\n\t ", RIP_ROUTELEN - sizeof(*eh));
} else { /* BSD_AFNUM_INET or AFI 0 */
ni = (const struct rip_netinfo_v2 *)p;
- if (remaining < sizeof(*ni))
- goto invalid;
+ ND_LCHECKMSG_ZU(remaining, sizeof(*ni), "remaining data length");
ND_PRINT("\n\t AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
tok2str(bsd_af_values, "%u", family),
GET_IPADDR_STRING(ni->rip_dest),
unsigned entry_size;
ndo->ndo_protocol = "rip";
- if (len < sizeof(*rp)) {
- ND_PRINT(" (packet length %u)", len);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(len, sizeof(*rp), "packet length");
rp = (const struct rip *)p;
/* Error */
goto invalid;
}
- if (len < entry_size) {
- ND_PRINT(" [remaining entries length %u < %u]",
- len, entry_size);
- goto invalid;
- }
+ ND_LCHECKMSG_U(len, entry_size, "remaining entries length");
p += entry_size;
len -= entry_size;
}
/* Error */
goto invalid;
}
- if (len < entry_size) {
- ND_PRINT(" [remaining entries length %u < %u]",
- len, entry_size);
- goto invalid;
- }
+ ND_LCHECKMSG_U(len, entry_size, "remaining entries length");
p += entry_size;
len -= entry_size;
}
uint32_t i;
} bw;
- if (obj_tlen < 4) {
- ND_PRINT(" (obj_tlen %u < 4)", obj_tlen);
- goto invalid;
- }
+ ND_LCHECK_U(obj_tlen, 4);
parameter_id = GET_U_1(tptr);
parameter_length = GET_BE_U_2(tptr + 2)<<2; /* convert wordcount to bytecount */
parameter_length,
GET_U_1(tptr + 1));
- if (obj_tlen < parameter_length + 4) {
- ND_PRINT(" (obj_tlen %u < %u)", obj_tlen, parameter_length + 4);
- goto invalid;
- }
+ ND_LCHECK_U(obj_tlen, parameter_length + 4);
switch(parameter_id) { /* parameter_id */
case 4:
* each iteration subobj_len may happen to be a multiple of 1
* and test it and total_subobj_len respectively.
*/
- if (total_subobj_len < 4)
- goto invalid;
+ ND_LCHECK_U(total_subobj_len, 4);
subobj_len = GET_BE_U_2(obj_tptr);
subobj_type = (GET_BE_U_2(obj_tptr + 2))>>8;
af = (GET_BE_U_2(obj_tptr + 2))&0x00FF;
if (ndo->ndo_packettype != PT_RPC)
udpipaddr_print(ndo, ip, sport, dport);
- if (length < sizeof(struct udphdr)) {
- ND_PRINT("undersized-udp %u", length);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(length, sizeof(struct udphdr), "undersized-udp");
ulen = GET_BE_U_2(up->uh_ulen);
udp_sum = GET_BE_U_2(up->uh_sum);
/*
*/
if (ulen == 0 && length > 65535)
ulen = length;
- if (ulen < sizeof(struct udphdr)) {
- ND_PRINT("undersized-udplength %u", ulen);
- goto invalid;
- }
+ ND_LCHECKMSG_ZU(ulen, sizeof(struct udphdr), "undersized-udplength");
ulen -= sizeof(struct udphdr);
length -= sizeof(struct udphdr);
if (ulen < length)