* SUCH DAMAGE.
*/
+#define NETDISSECT_REWORKED
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
static const char tstr[] = "[|babel]";
-static void babel_print_v2(const u_char *cp, u_int length);
+static void babel_print_v2(netdissect_options *, const u_char *cp, u_int length);
void
-babel_print(const u_char *cp, u_int length) {
- printf("babel");
+babel_print(netdissect_options *ndo,
+ const u_char *cp, u_int length) {
+ ND_PRINT((ndo, "babel"));
- TCHECK2(*cp, 4);
+ ND_TCHECK2(*cp, 4);
if(cp[0] != 42) {
- printf(" malformed header");
+ ND_PRINT((ndo, " malformed header"));
return;
} else {
- printf(" %d", cp[1]);
+ ND_PRINT((ndo, " %d", cp[1]));
}
switch(cp[1]) {
case 2:
- babel_print_v2(cp,length);
+ babel_print_v2(ndo, cp, length);
break;
default:
- printf(" unknown version");
+ ND_PRINT((ndo, " unknown version"));
break;
}
return;
trunc:
- printf(" %s", tstr);
+ ND_PRINT((ndo, " %s", tstr));
return;
}
* The former would mean a lack of any claims about the interference, and the
* latter would state that interference is definitely absent. */
static void
-subtlvs_print(const u_char *cp, const u_char *ep, const uint8_t tlv_type) {
+subtlvs_print(netdissect_options *ndo,
+ const u_char *cp, const u_char *ep, const uint8_t tlv_type) {
uint8_t subtype, sublen;
const char *sep;
while (cp < ep) {
subtype = *cp++;
if(subtype == MESSAGE_SUB_PAD1) {
- printf(" sub-pad1");
+ ND_PRINT((ndo, " sub-pad1"));
continue;
}
if(cp == ep)
switch(subtype) {
case MESSAGE_SUB_PADN:
- printf(" sub-padn");
+ ND_PRINT((ndo, " sub-padn"));
cp += sublen;
break;
case MESSAGE_SUB_DIVERSITY:
- printf(" sub-diversity");
+ ND_PRINT((ndo, " sub-diversity"));
if (sublen == 0) {
- printf(" empty");
+ ND_PRINT((ndo, " empty"));
break;
}
sep = " ";
while(sublen--) {
- printf("%s%s", sep, tok2str(diversity_str, "%u", *cp++));
+ ND_PRINT((ndo, "%s%s", sep, tok2str(diversity_str, "%u", *cp++)));
sep = "-";
}
if(tlv_type != MESSAGE_UPDATE)
- printf(" (bogus)");
+ ND_PRINT((ndo, " (bogus)"));
break;
default:
- printf(" sub-unknown-0x%02x", subtype);
+ ND_PRINT((ndo, " sub-unknown-0x%02x", subtype));
cp += sublen;
} /* switch */
} /* while */
return;
corrupt:
- printf(" (corrupt)");
+ ND_PRINT((ndo, " (corrupt)"));
}
#define ICHECK(i, l) \
if ((i) + (l) > bodylen || (i) + (l) > length) goto corrupt;
static void
-babel_print_v2(const u_char *cp, u_int length) {
+babel_print_v2(netdissect_options *ndo,
+ const u_char *cp, u_int length) {
u_int i;
u_short bodylen;
u_char v4_prefix[16] =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 };
u_char v6_prefix[16] = {0};
- TCHECK2(*cp, 4);
+ ND_TCHECK2(*cp, 4);
if (length < 4)
goto corrupt;
bodylen = EXTRACT_16BITS(cp + 2);
- printf(" (%u)", bodylen);
+ ND_PRINT((ndo, " (%u)", bodylen));
/* Process the TLVs in the body */
i = 0;
message = cp + 4 + i;
- TCHECK2(*message, 1);
+ ND_TCHECK2(*message, 1);
if((type = message[0]) == MESSAGE_PAD1) {
- printf(vflag ? "\n\tPad 1" : " pad1");
+ ND_PRINT((ndo, ndo->ndo_vflag ? "\n\tPad 1" : " pad1"));
i += 1;
continue;
}
- TCHECK2(*message, 2);
+ ND_TCHECK2(*message, 2);
ICHECK(i, 2);
len = message[1];
- TCHECK2(*message, 2 + len);
+ ND_TCHECK2(*message, 2 + len);
ICHECK(i, 2 + len);
switch(type) {
case MESSAGE_PADN: {
- if(!vflag)
- printf(" padN");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " padN"));
else
- printf("\n\tPad %d", len + 2);
+ ND_PRINT((ndo, "\n\tPad %d", len + 2));
}
break;
case MESSAGE_ACK_REQ: {
u_short nonce, interval;
- if(!vflag)
- printf(" ack-req");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " ack-req"));
else {
- printf("\n\tAcknowledgment Request ");
+ ND_PRINT((ndo, "\n\tAcknowledgment Request "));
if(len < 6) goto corrupt;
nonce = EXTRACT_16BITS(message + 4);
interval = EXTRACT_16BITS(message + 6);
- printf("%04x %s", nonce, format_interval(interval));
+ ND_PRINT((ndo, "%04x %s", nonce, format_interval(interval)));
}
}
break;
case MESSAGE_ACK: {
u_short nonce;
- if(!vflag)
- printf(" ack");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " ack"));
else {
- printf("\n\tAcknowledgment ");
+ ND_PRINT((ndo, "\n\tAcknowledgment "));
if(len < 2) goto corrupt;
nonce = EXTRACT_16BITS(message + 2);
- printf("%04x", nonce);
+ ND_PRINT((ndo, "%04x", nonce));
}
}
break;
case MESSAGE_HELLO: {
u_short seqno, interval;
- if(!vflag)
- printf(" hello");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " hello"));
else {
- printf("\n\tHello ");
+ ND_PRINT((ndo, "\n\tHello "));
if(len < 6) goto corrupt;
seqno = EXTRACT_16BITS(message + 4);
interval = EXTRACT_16BITS(message + 6);
- printf("seqno %u interval %s", seqno, format_interval(interval));
+ ND_PRINT((ndo, "seqno %u interval %s", seqno, format_interval(interval)));
}
}
break;
case MESSAGE_IHU: {
unsigned short txcost, interval;
- if(!vflag)
- printf(" ihu");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " ihu"));
else {
u_char address[16];
int rc;
- printf("\n\tIHU ");
+ ND_PRINT((ndo, "\n\tIHU "));
if(len < 6) goto corrupt;
txcost = EXTRACT_16BITS(message + 4);
interval = EXTRACT_16BITS(message + 6);
rc = network_address(message[2], message + 8, len - 6, address);
- if(rc < 0) { printf("%s", tstr); break; }
- printf("%s txcost %u interval %s",
- format_address(address), txcost, format_interval(interval));
+ if(rc < 0) { ND_PRINT((ndo, "%s", tstr)); break; }
+ ND_PRINT((ndo, "%s txcost %u interval %s",
+ format_address(address), txcost, format_interval(interval)));
}
}
break;
case MESSAGE_ROUTER_ID: {
- if(!vflag)
- printf(" router-id");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " router-id"));
else {
- printf("\n\tRouter Id");
+ ND_PRINT((ndo, "\n\tRouter Id"));
if(len < 10) goto corrupt;
- printf(" %s", format_id(message + 4));
+ ND_PRINT((ndo, " %s", format_id(message + 4)));
}
}
break;
case MESSAGE_NH: {
- if(!vflag)
- printf(" nh");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " nh"));
else {
int rc;
u_char nh[16];
- printf("\n\tNext Hop");
+ ND_PRINT((ndo, "\n\tNext Hop"));
if(len < 2) goto corrupt;
rc = network_address(message[2], message + 4, len - 2, nh);
if(rc < 0) goto corrupt;
- printf(" %s", format_address(nh));
+ ND_PRINT((ndo, " %s", format_address(nh)));
}
}
break;
case MESSAGE_UPDATE: {
- if(!vflag) {
- printf(" update");
+ if (!ndo->ndo_vflag) {
+ ND_PRINT((ndo, " update"));
if(len < 1)
- printf("/truncated");
+ ND_PRINT((ndo, "/truncated"));
else
- printf("%s%s%s",
+ ND_PRINT((ndo, "%s%s%s",
(message[3] & 0x80) ? "/prefix": "",
(message[3] & 0x40) ? "/id" : "",
- (message[3] & 0x3f) ? "/unknown" : "");
+ (message[3] & 0x3f) ? "/unknown" : ""));
} else {
u_short interval, seqno, metric;
u_char plen;
int rc;
u_char prefix[16];
- printf("\n\tUpdate");
+ ND_PRINT((ndo, "\n\tUpdate"));
if(len < 10) goto corrupt;
plen = message[4] + (message[2] == 1 ? 96 : 0);
rc = network_prefix(message[2], message[4], message[5],
interval = EXTRACT_16BITS(message + 6);
seqno = EXTRACT_16BITS(message + 8);
metric = EXTRACT_16BITS(message + 10);
- printf("%s%s%s %s metric %u seqno %u interval %s",
+ ND_PRINT((ndo, "%s%s%s %s metric %u seqno %u interval %s",
(message[3] & 0x80) ? "/prefix": "",
(message[3] & 0x40) ? "/id" : "",
(message[3] & 0x3f) ? "/unknown" : "",
format_prefix(prefix, plen),
- metric, seqno, format_interval_update(interval));
+ metric, seqno, format_interval_update(interval)));
if(message[3] & 0x80) {
if(message[2] == 1)
memcpy(v4_prefix, prefix, 16);
}
/* extra data? */
if((u_int)rc < len - 10)
- subtlvs_print(message + 12 + rc, message + 2 + len, type);
+ subtlvs_print(ndo, message + 12 + rc, message + 2 + len, type);
}
}
break;
case MESSAGE_REQUEST: {
- if(!vflag)
- printf(" request");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " request"));
else {
int rc;
u_char prefix[16], plen;
- printf("\n\tRequest ");
+ ND_PRINT((ndo, "\n\tRequest "));
if(len < 2) goto corrupt;
plen = message[3] + (message[2] == 1 ? 96 : 0);
rc = network_prefix(message[2], message[3], 0,
message + 4, NULL, len - 2, prefix);
if(rc < 0) goto corrupt;
- printf("for %s",
- message[2] == 0 ? "any" : format_prefix(prefix, plen));
+ ND_PRINT((ndo, "for %s",
+ message[2] == 0 ? "any" : format_prefix(prefix, plen)));
}
}
break;
case MESSAGE_MH_REQUEST : {
- if(!vflag)
- printf(" mh-request");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " mh-request"));
else {
int rc;
u_short seqno;
u_char prefix[16], plen;
- printf("\n\tMH-Request ");
+ ND_PRINT((ndo, "\n\tMH-Request "));
if(len < 14) goto corrupt;
seqno = EXTRACT_16BITS(message + 4);
rc = network_prefix(message[2], message[3], 0,
message + 16, NULL, len - 14, prefix);
if(rc < 0) goto corrupt;
plen = message[3] + (message[2] == 1 ? 96 : 0);
- printf("(%u hops) for %s seqno %u id %s",
+ ND_PRINT((ndo, "(%u hops) for %s seqno %u id %s",
message[6], format_prefix(prefix, plen),
- seqno, format_id(message + 8));
+ seqno, format_id(message + 8)));
}
}
break;
case MESSAGE_TSPC :
- if(!vflag)
- printf(" tspc");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " tspc"));
else {
- printf("\n\tTS/PC ");
+ ND_PRINT((ndo, "\n\tTS/PC "));
if(len < 6) goto corrupt;
- printf("timestamp %u packetcounter %u", EXTRACT_32BITS (message + 4),
- EXTRACT_16BITS(message + 2));
+ ND_PRINT((ndo, "timestamp %u packetcounter %u", EXTRACT_32BITS (message + 4),
+ EXTRACT_16BITS(message + 2)));
}
break;
case MESSAGE_HMAC : {
- if(!vflag)
- printf(" hmac");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " hmac"));
else {
unsigned j;
- printf("\n\tHMAC ");
+ ND_PRINT((ndo, "\n\tHMAC "));
if(len < 18) goto corrupt;
- printf("key-id %u digest-%u ", EXTRACT_16BITS(message + 2), len - 2);
+ ND_PRINT((ndo, "key-id %u digest-%u ", EXTRACT_16BITS(message + 2), len - 2));
for (j = 0; j < len - 2; j++)
- printf ("%02X", message[4 + j]);
+ ND_PRINT((ndo, "%02X", message[4 + j]));
}
}
break;
default:
- if(!vflag)
- printf(" unknown");
+ if (!ndo->ndo_vflag)
+ ND_PRINT((ndo, " unknown"));
else
- printf("\n\tUnknown message type %d", type);
+ ND_PRINT((ndo, "\n\tUnknown message type %d", type));
}
i += len + 2;
}
return;
trunc:
- printf(" %s", tstr);
+ ND_PRINT((ndo, " %s", tstr));
return;
corrupt:
- printf(" (corrupt)");
+ ND_PRINT((ndo, " (corrupt)"));
return;
}