Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/tcpdump/print-olsr.c
Show First 20 Lines • Show All 172 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
#define VTIME_SCALE_FACTOR 0.0625 | #define VTIME_SCALE_FACTOR 0.0625 | ||||
#define ME_TO_DOUBLE(me) \ | #define ME_TO_DOUBLE(me) \ | ||||
(double)(VTIME_SCALE_FACTOR*(1+(double)(me>>4)/16)*(double)(1<<(me&0x0F))) | (double)(VTIME_SCALE_FACTOR*(1+(double)(me>>4)/16)*(double)(1<<(me&0x0F))) | ||||
/* | /* | ||||
* print a neighbor list with LQ extensions. | * print a neighbor list with LQ extensions. | ||||
*/ | */ | ||||
static void | static int | ||||
olsr_print_lq_neighbor4(netdissect_options *ndo, | olsr_print_lq_neighbor4(netdissect_options *ndo, | ||||
const u_char *msg_data, u_int hello_len) | const u_char *msg_data, u_int hello_len) | ||||
{ | { | ||||
struct olsr_lq_neighbor4 *lq_neighbor; | struct olsr_lq_neighbor4 *lq_neighbor; | ||||
while (hello_len >= sizeof(struct olsr_lq_neighbor4)) { | while (hello_len >= sizeof(struct olsr_lq_neighbor4)) { | ||||
lq_neighbor = (struct olsr_lq_neighbor4 *)msg_data; | lq_neighbor = (struct olsr_lq_neighbor4 *)msg_data; | ||||
if (!ND_TTEST(*lq_neighbor)) | |||||
return (-1); | |||||
ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2lf%%" | ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2lf%%" | ||||
", neighbor-link-quality %.2lf%%", | ", neighbor-link-quality %.2lf%%", | ||||
ipaddr_string(ndo, lq_neighbor->neighbor), | ipaddr_string(ndo, lq_neighbor->neighbor), | ||||
((double)lq_neighbor->link_quality/2.55), | ((double)lq_neighbor->link_quality/2.55), | ||||
((double)lq_neighbor->neighbor_link_quality/2.55))); | ((double)lq_neighbor->neighbor_link_quality/2.55))); | ||||
msg_data += sizeof(struct olsr_lq_neighbor4); | msg_data += sizeof(struct olsr_lq_neighbor4); | ||||
hello_len -= sizeof(struct olsr_lq_neighbor4); | hello_len -= sizeof(struct olsr_lq_neighbor4); | ||||
} | } | ||||
return (0); | |||||
} | } | ||||
#if INET6 | #if INET6 | ||||
static void | static int | ||||
olsr_print_lq_neighbor6(netdissect_options *ndo, | olsr_print_lq_neighbor6(netdissect_options *ndo, | ||||
const u_char *msg_data, u_int hello_len) | const u_char *msg_data, u_int hello_len) | ||||
{ | { | ||||
struct olsr_lq_neighbor6 *lq_neighbor; | struct olsr_lq_neighbor6 *lq_neighbor; | ||||
while (hello_len >= sizeof(struct olsr_lq_neighbor6)) { | while (hello_len >= sizeof(struct olsr_lq_neighbor6)) { | ||||
lq_neighbor = (struct olsr_lq_neighbor6 *)msg_data; | lq_neighbor = (struct olsr_lq_neighbor6 *)msg_data; | ||||
if (!ND_TTEST(*lq_neighbor)) | |||||
return (-1); | |||||
ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2lf%%" | ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2lf%%" | ||||
", neighbor-link-quality %.2lf%%", | ", neighbor-link-quality %.2lf%%", | ||||
ip6addr_string(ndo, lq_neighbor->neighbor), | ip6addr_string(ndo, lq_neighbor->neighbor), | ||||
((double)lq_neighbor->link_quality/2.55), | ((double)lq_neighbor->link_quality/2.55), | ||||
((double)lq_neighbor->neighbor_link_quality/2.55))); | ((double)lq_neighbor->neighbor_link_quality/2.55))); | ||||
msg_data += sizeof(struct olsr_lq_neighbor6); | msg_data += sizeof(struct olsr_lq_neighbor6); | ||||
hello_len -= sizeof(struct olsr_lq_neighbor6); | hello_len -= sizeof(struct olsr_lq_neighbor6); | ||||
} | } | ||||
return (0); | |||||
} | } | ||||
#endif /* INET6 */ | #endif /* INET6 */ | ||||
/* | /* | ||||
* print a neighbor list. | * print a neighbor list. | ||||
*/ | */ | ||||
static void | static int | ||||
olsr_print_neighbor(netdissect_options *ndo, | olsr_print_neighbor(netdissect_options *ndo, | ||||
const u_char *msg_data, u_int hello_len) | const u_char *msg_data, u_int hello_len) | ||||
{ | { | ||||
int neighbor; | int neighbor; | ||||
ND_PRINT((ndo, "\n\t neighbor\n\t\t")); | ND_PRINT((ndo, "\n\t neighbor\n\t\t")); | ||||
neighbor = 1; | neighbor = 1; | ||||
while (hello_len >= sizeof(struct in_addr)) { | while (hello_len >= sizeof(struct in_addr)) { | ||||
if (!ND_TTEST2(*msg_data, sizeof(struct in_addr))) | |||||
return (-1); | |||||
/* print 4 neighbors per line */ | /* print 4 neighbors per line */ | ||||
ND_PRINT((ndo, "%s%s", ipaddr_string(ndo, msg_data), | ND_PRINT((ndo, "%s%s", ipaddr_string(ndo, msg_data), | ||||
neighbor % 4 == 0 ? "\n\t\t" : " ")); | neighbor % 4 == 0 ? "\n\t\t" : " ")); | ||||
msg_data += sizeof(struct in_addr); | msg_data += sizeof(struct in_addr); | ||||
hello_len -= sizeof(struct in_addr); | hello_len -= sizeof(struct in_addr); | ||||
} | } | ||||
return (0); | |||||
} | } | ||||
void | void | ||||
olsr_print(netdissect_options *ndo, | olsr_print(netdissect_options *ndo, | ||||
const u_char *pptr, u_int length, int is_ipv6) | const u_char *pptr, u_int length, int is_ipv6) | ||||
{ | { | ||||
union { | union { | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | #if INET6 | ||||
"\n\t vtime %.3lfs, msg-seq 0x%04x, length %u%s", | "\n\t vtime %.3lfs, msg-seq 0x%04x, length %u%s", | ||||
tok2str(olsr_msg_values, "Unknown", msg_type), | tok2str(olsr_msg_values, "Unknown", msg_type), | ||||
msg_type, ip6addr_string(ndo, msgptr.v6->originator), | msg_type, ip6addr_string(ndo, msgptr.v6->originator), | ||||
msgptr.v6->ttl, | msgptr.v6->ttl, | ||||
msgptr.v6->hopcount, | msgptr.v6->hopcount, | ||||
ME_TO_DOUBLE(msgptr.v6->vtime), | ME_TO_DOUBLE(msgptr.v6->vtime), | ||||
EXTRACT_16BITS(msgptr.v6->msg_seq), | EXTRACT_16BITS(msgptr.v6->msg_seq), | ||||
msg_len, (msg_len_valid == 0) ? " (invalid)" : "")); | msg_len, (msg_len_valid == 0) ? " (invalid)" : "")); | ||||
if (!msg_len_valid) { | |||||
return; | |||||
} | |||||
msg_tlen = msg_len - sizeof(struct olsr_msg6); | msg_tlen = msg_len - sizeof(struct olsr_msg6); | ||||
msg_data = tptr + sizeof(struct olsr_msg6); | msg_data = tptr + sizeof(struct olsr_msg6); | ||||
} | } | ||||
else /* (!is_ipv6) */ | else /* (!is_ipv6) */ | ||||
#endif /* INET6 */ | #endif /* INET6 */ | ||||
{ | { | ||||
msgptr.v4 = (struct olsr_msg4 *) tptr; | msgptr.v4 = (struct olsr_msg4 *) tptr; | ||||
Show All 12 Lines | #endif /* INET6 */ | ||||
"\n\t vtime %.3lfs, msg-seq 0x%04x, length %u%s", | "\n\t vtime %.3lfs, msg-seq 0x%04x, length %u%s", | ||||
tok2str(olsr_msg_values, "Unknown", msg_type), | tok2str(olsr_msg_values, "Unknown", msg_type), | ||||
msg_type, ipaddr_string(ndo, msgptr.v4->originator), | msg_type, ipaddr_string(ndo, msgptr.v4->originator), | ||||
msgptr.v4->ttl, | msgptr.v4->ttl, | ||||
msgptr.v4->hopcount, | msgptr.v4->hopcount, | ||||
ME_TO_DOUBLE(msgptr.v4->vtime), | ME_TO_DOUBLE(msgptr.v4->vtime), | ||||
EXTRACT_16BITS(msgptr.v4->msg_seq), | EXTRACT_16BITS(msgptr.v4->msg_seq), | ||||
msg_len, (msg_len_valid == 0) ? " (invalid)" : "")); | msg_len, (msg_len_valid == 0) ? " (invalid)" : "")); | ||||
if (!msg_len_valid) { | |||||
return; | |||||
} | |||||
msg_tlen = msg_len - sizeof(struct olsr_msg4); | msg_tlen = msg_len - sizeof(struct olsr_msg4); | ||||
msg_data = tptr + sizeof(struct olsr_msg4); | msg_data = tptr + sizeof(struct olsr_msg4); | ||||
} | } | ||||
switch (msg_type) { | switch (msg_type) { | ||||
case OLSR_HELLO_MSG: | case OLSR_HELLO_MSG: | ||||
case OLSR_HELLO_LQ_MSG: | case OLSR_HELLO_LQ_MSG: | ||||
if (msg_tlen < sizeof(struct olsr_hello)) | |||||
goto trunc; | |||||
ND_TCHECK2(*msg_data, sizeof(struct olsr_hello)); | ND_TCHECK2(*msg_data, sizeof(struct olsr_hello)); | ||||
ptr.hello = (struct olsr_hello *)msg_data; | ptr.hello = (struct olsr_hello *)msg_data; | ||||
ND_PRINT((ndo, "\n\t hello-time %.3lfs, MPR willingness %u", | ND_PRINT((ndo, "\n\t hello-time %.3lfs, MPR willingness %u", | ||||
ME_TO_DOUBLE(ptr.hello->htime), ptr.hello->will)); | ME_TO_DOUBLE(ptr.hello->htime), ptr.hello->will)); | ||||
msg_data += sizeof(struct olsr_hello); | msg_data += sizeof(struct olsr_hello); | ||||
msg_tlen -= sizeof(struct olsr_hello); | msg_tlen -= sizeof(struct olsr_hello); | ||||
Show All 23 Lines | #endif /* INET6 */ | ||||
if (hello_len_valid == 0) | if (hello_len_valid == 0) | ||||
break; | break; | ||||
msg_data += sizeof(struct olsr_hello_link); | msg_data += sizeof(struct olsr_hello_link); | ||||
msg_tlen -= sizeof(struct olsr_hello_link); | msg_tlen -= sizeof(struct olsr_hello_link); | ||||
hello_len -= sizeof(struct olsr_hello_link); | hello_len -= sizeof(struct olsr_hello_link); | ||||
ND_TCHECK2(*msg_data, hello_len); | |||||
if (msg_type == OLSR_HELLO_MSG) { | if (msg_type == OLSR_HELLO_MSG) { | ||||
olsr_print_neighbor(ndo, msg_data, hello_len); | if (olsr_print_neighbor(ndo, msg_data, hello_len) == -1) | ||||
goto trunc; | |||||
} else { | } else { | ||||
#if INET6 | #if INET6 | ||||
if (is_ipv6) | if (is_ipv6) { | ||||
olsr_print_lq_neighbor6(ndo, msg_data, hello_len); | if (olsr_print_lq_neighbor6(ndo, msg_data, hello_len) == -1) | ||||
else | goto trunc; | ||||
} else | |||||
#endif | #endif | ||||
olsr_print_lq_neighbor4(ndo, msg_data, hello_len); | { | ||||
if (olsr_print_lq_neighbor4(ndo, msg_data, hello_len) == -1) | |||||
goto trunc; | |||||
} | } | ||||
} | |||||
msg_data += hello_len; | msg_data += hello_len; | ||||
msg_tlen -= hello_len; | msg_tlen -= hello_len; | ||||
} | } | ||||
break; | break; | ||||
case OLSR_TC_MSG: | case OLSR_TC_MSG: | ||||
case OLSR_TC_LQ_MSG: | case OLSR_TC_LQ_MSG: | ||||
if (msg_tlen < sizeof(struct olsr_tc)) | |||||
goto trunc; | |||||
ND_TCHECK2(*msg_data, sizeof(struct olsr_tc)); | ND_TCHECK2(*msg_data, sizeof(struct olsr_tc)); | ||||
ptr.tc = (struct olsr_tc *)msg_data; | ptr.tc = (struct olsr_tc *)msg_data; | ||||
ND_PRINT((ndo, "\n\t advertised neighbor seq 0x%04x", | ND_PRINT((ndo, "\n\t advertised neighbor seq 0x%04x", | ||||
EXTRACT_16BITS(ptr.tc->ans_seq))); | EXTRACT_16BITS(ptr.tc->ans_seq))); | ||||
msg_data += sizeof(struct olsr_tc); | msg_data += sizeof(struct olsr_tc); | ||||
msg_tlen -= sizeof(struct olsr_tc); | msg_tlen -= sizeof(struct olsr_tc); | ||||
if (msg_type == OLSR_TC_MSG) { | if (msg_type == OLSR_TC_MSG) { | ||||
olsr_print_neighbor(ndo, msg_data, msg_tlen); | if (olsr_print_neighbor(ndo, msg_data, msg_tlen) == -1) | ||||
goto trunc; | |||||
} else { | } else { | ||||
#if INET6 | #if INET6 | ||||
if (is_ipv6) | if (is_ipv6) { | ||||
olsr_print_lq_neighbor6(ndo, msg_data, msg_tlen); | if (olsr_print_lq_neighbor6(ndo, msg_data, msg_tlen) == -1) | ||||
else | goto trunc; | ||||
} else | |||||
#endif | #endif | ||||
olsr_print_lq_neighbor4(ndo, msg_data, msg_tlen); | { | ||||
if (olsr_print_lq_neighbor4(ndo, msg_data, msg_tlen) == -1) | |||||
goto trunc; | |||||
} | } | ||||
} | |||||
break; | break; | ||||
case OLSR_MID_MSG: | case OLSR_MID_MSG: | ||||
{ | { | ||||
size_t addr_size = sizeof(struct in_addr); | size_t addr_size = sizeof(struct in_addr); | ||||
#if INET6 | #if INET6 | ||||
if (is_ipv6) | if (is_ipv6) | ||||
▲ Show 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | |||||
#if INET6 | #if INET6 | ||||
if (is_ipv6) | if (is_ipv6) | ||||
ND_PRINT((ndo, ", address %s, name \"", | ND_PRINT((ndo, ", address %s, name \"", | ||||
ip6addr_string(ndo, msg_data))); | ip6addr_string(ndo, msg_data))); | ||||
else | else | ||||
#endif | #endif | ||||
ND_PRINT((ndo, ", address %s, name \"", | ND_PRINT((ndo, ", address %s, name \"", | ||||
ipaddr_string(ndo, msg_data))); | ipaddr_string(ndo, msg_data))); | ||||
fn_printn(ndo, msg_data + addr_size, name_entry_len, NULL); | (void)fn_printn(ndo, msg_data + addr_size, name_entry_len, NULL); | ||||
ND_PRINT((ndo, "\"")); | ND_PRINT((ndo, "\"")); | ||||
msg_data += addr_size + name_entry_len + name_entry_padding; | msg_data += addr_size + name_entry_len + name_entry_padding; | ||||
msg_tlen -= addr_size + name_entry_len + name_entry_padding; | msg_tlen -= addr_size + name_entry_len + name_entry_padding; | ||||
} /* for (i = 0; i < name_entries; i++) */ | } /* for (i = 0; i < name_entries; i++) */ | ||||
break; | break; | ||||
} /* case OLSR_NAMESERVICE_MSG */ | } /* case OLSR_NAMESERVICE_MSG */ | ||||
Show All 24 Lines |