summaryrefslogtreecommitdiffstats
path: root/contrib/tcpdump/print-rip.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2013-05-30 20:51:22 +0000
committerdelphij <delphij@FreeBSD.org>2013-05-30 20:51:22 +0000
commitcc86f133652d396d6f3dac311d20761a9ee00ad9 (patch)
treef1ffd0911b49d93d246ae1677dd73d297cd2d92d /contrib/tcpdump/print-rip.c
parent0c381861b05890dec1e89030d37c6dbea3c12ca5 (diff)
parenta765887ce77351bac1c77be2cf18a3a66a602fc5 (diff)
downloadFreeBSD-src-cc86f133652d396d6f3dac311d20761a9ee00ad9.zip
FreeBSD-src-cc86f133652d396d6f3dac311d20761a9ee00ad9.tar.gz
MFV: tcpdump 4.4.0.
MFC after: 4 weeks
Diffstat (limited to 'contrib/tcpdump/print-rip.c')
-rw-r--r--contrib/tcpdump/print-rip.c69
1 files changed, 43 insertions, 26 deletions
diff --git a/contrib/tcpdump/print-rip.c b/contrib/tcpdump/print-rip.c
index 27446a6..0aaa2a6 100644
--- a/contrib/tcpdump/print-rip.c
+++ b/contrib/tcpdump/print-rip.c
@@ -17,6 +17,8 @@
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $FreeBSD$
*/
#ifndef lint
@@ -102,7 +104,7 @@ rip_entry_print_v1(register const struct rip_netinfo *ni)
/* RFC 1058 */
family = EXTRACT_16BITS(&ni->rip_family);
- if (family != BSD_AFNUM_INET) {
+ if (family != BSD_AFNUM_INET && family != 0) {
printf("\n\t AFI %s, ", tok2str(bsd_af_values, "Unknown (%u)", family));
print_unknown_data((u_int8_t *)&ni->rip_family,"\n\t ",RIP_ROUTELEN);
return;
@@ -113,41 +115,55 @@ rip_entry_print_v1(register const struct rip_netinfo *ni)
/* MBZ fields not zero */
print_unknown_data((u_int8_t *)&ni->rip_family,"\n\t ",RIP_ROUTELEN);
return;
+ }
+ if (family == 0) {
+ printf("\n\t AFI 0, %s, metric: %u",
+ ipaddr_string(&ni->rip_dest),
+ EXTRACT_32BITS(&ni->rip_metric));
+ return;
} /* BSD_AFNUM_INET */
printf("\n\t %s, metric: %u",
ipaddr_string(&ni->rip_dest),
EXTRACT_32BITS(&ni->rip_metric));
}
-static void
-rip_entry_print_v2(register const struct rip_netinfo *ni)
+static unsigned
+rip_entry_print_v2(register const struct rip_netinfo *ni, const unsigned remaining)
{
- register u_char *p;
register u_short family;
- u_char buf[RIP_AUTHLEN];
family = EXTRACT_16BITS(&ni->rip_family);
- if (family == 0xFFFF) { /* 16 bytes authentication ? */
- if (EXTRACT_16BITS(&ni->rip_tag) == 2) { /* simple text authentication ? */
- memcpy(buf, &ni->rip_dest, sizeof(buf));
- buf[sizeof(buf)-1] = '\0';
- for (p = buf; *p; p++) {
- if (!isprint(*p))
- break;
- }
- printf("\n\t Simple Text Authentication data: %s", buf);
+ if (family == 0xFFFF) { /* variable-sized authentication structures */
+ u_int16_t auth_type = EXTRACT_16BITS(&ni->rip_tag);
+ if (auth_type == 2) {
+ register u_char *p = (u_char *)&ni->rip_dest;
+ u_int i = 0;
+ printf("\n\t Simple Text Authentication data: ");
+ for (; i < RIP_AUTHLEN; p++, i++)
+ putchar (isprint(*p) ? *p : '.');
+ } else if (auth_type == 3) {
+ printf("\n\t Auth header:");
+ printf(" Packet Len %u,", EXTRACT_16BITS((u_int16_t *)ni + 2));
+ printf(" Key-ID %u,", *((u_int8_t *)ni + 6));
+ printf(" Auth Data Len %u,", *((u_int8_t *)ni + 7));
+ printf(" SeqNo %u,", EXTRACT_32BITS(&ni->rip_dest_mask));
+ printf(" MBZ %u,", EXTRACT_32BITS(&ni->rip_router));
+ printf(" MBZ %u", EXTRACT_32BITS(&ni->rip_metric));
+ } else if (auth_type == 1) {
+ printf("\n\t Auth trailer:");
+ print_unknown_data((u_int8_t *)&ni->rip_dest,"\n\t ",remaining);
+ return remaining; /* AT spans till the packet end */
} else {
printf("\n\t Unknown (%u) Authentication data:",
EXTRACT_16BITS(&ni->rip_tag));
- print_unknown_data((u_int8_t *)&ni->rip_dest,"\n\t ",RIP_AUTHLEN);
+ print_unknown_data((u_int8_t *)&ni->rip_dest,"\n\t ",remaining);
}
- } else if (family != BSD_AFNUM_INET) {
+ } else if (family != BSD_AFNUM_INET && family != 0) {
printf("\n\t AFI %s", tok2str(bsd_af_values, "Unknown (%u)", family));
print_unknown_data((u_int8_t *)&ni->rip_tag,"\n\t ",RIP_ROUTELEN-2);
- return;
- } else { /* BSD_AFNUM_INET */
+ } else { /* BSD_AFNUM_INET or AFI 0 */
printf("\n\t AFI %s, %15s/%-2d, tag 0x%04x, metric: %u, next-hop: ",
- tok2str(bsd_af_values, "Unknown (%u)", family),
+ tok2str(bsd_af_values, "%u", family),
ipaddr_string(&ni->rip_dest),
mask2plen(EXTRACT_32BITS(&ni->rip_dest_mask)),
EXTRACT_16BITS(&ni->rip_tag),
@@ -157,6 +173,7 @@ rip_entry_print_v2(register const struct rip_netinfo *ni)
else
printf("self");
}
+ return sizeof (*ni);
}
void
@@ -165,7 +182,6 @@ rip_print(const u_char *dat, u_int length)
register const struct rip *rp;
register const struct rip_netinfo *ni;
register u_int i, j;
- register int trunc;
if (snapend < dat) {
printf(" [|rip]");
@@ -213,25 +229,26 @@ rip_print(const u_char *dat, u_int length)
return;
switch (rp->rip_cmd) {
+ case RIPCMD_REQUEST:
case RIPCMD_RESPONSE:
j = length / sizeof(*ni);
- printf(", routes: %u",j);
- trunc = (i / sizeof(*ni)) != j;
+ printf(", routes: %u%s", j, rp->rip_vers == 2 ? " or less" : "");
ni = (struct rip_netinfo *)(rp + 1);
for (; i >= sizeof(*ni); ++ni) {
if (rp->rip_vers == 1)
+ {
rip_entry_print_v1(ni);
+ i -= sizeof(*ni);
+ }
else if (rp->rip_vers == 2)
- rip_entry_print_v2(ni);
+ i -= rip_entry_print_v2(ni, i);
else
break;
- i -= sizeof(*ni);
}
- if (trunc)
+ if (i)
printf("[|rip]");
break;
- case RIPCMD_REQUEST:
case RIPCMD_TRACEOFF:
case RIPCMD_POLL:
case RIPCMD_POLLENTRY:
OpenPOWER on IntegriCloud