freebsd-dev/contrib/tcpdump/print-dtp.c

129 lines
3.0 KiB
C
Raw Normal View History

2009-03-21 16:23:46 +00:00
/*
* Copyright (c) 1998-2007 The TCPDUMP project
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code
* distributions retain the above copyright notice and this paragraph
* in its entirety, and (2) distributions including binary code include
* the above copyright notice and this paragraph in its entirety in
* the documentation or other materials provided with the distribution.
* 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.
*
* Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
*/
2017-01-31 19:17:06 +00:00
/* \summary: Dynamic Trunking Protocol (DTP) printer */
2009-03-21 16:23:46 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2017-01-31 19:17:06 +00:00
#include <netdissect-stdinc.h>
2009-03-21 16:23:46 +00:00
2017-01-31 19:17:06 +00:00
#include "netdissect.h"
2009-03-21 16:23:46 +00:00
#include "addrtoname.h"
2015-01-06 19:03:11 +00:00
#include "extract.h"
2009-03-21 16:23:46 +00:00
2017-01-31 19:17:06 +00:00
static const char tstr[] = " [|dtp]";
2009-03-21 16:23:46 +00:00
#define DTP_HEADER_LEN 1
#define DTP_DOMAIN_TLV 0x0001
#define DTP_STATUS_TLV 0x0002
#define DTP_DTP_TYPE_TLV 0x0003
#define DTP_NEIGHBOR_TLV 0x0004
2015-01-06 19:03:11 +00:00
static const struct tok dtp_tlv_values[] = {
2009-03-21 16:23:46 +00:00
{ DTP_DOMAIN_TLV, "Domain TLV"},
{ DTP_STATUS_TLV, "Status TLV"},
{ DTP_DTP_TYPE_TLV, "DTP type TLV"},
{ DTP_NEIGHBOR_TLV, "Neighbor TLV"},
{ 0, NULL}
};
void
2015-01-06 19:03:11 +00:00
dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
2009-03-21 16:23:46 +00:00
{
int type, len;
const u_char *tptr;
if (length < DTP_HEADER_LEN)
goto trunc;
2015-01-06 19:03:11 +00:00
tptr = pptr;
2009-03-21 16:23:46 +00:00
2015-01-06 19:03:11 +00:00
ND_TCHECK2(*tptr, DTP_HEADER_LEN);
2009-03-21 16:23:46 +00:00
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, "DTPv%u, length %u",
2009-03-21 16:23:46 +00:00
(*tptr),
2015-01-06 19:03:11 +00:00
length));
2009-03-21 16:23:46 +00:00
/*
* In non-verbose mode, just print version.
*/
2015-01-06 19:03:11 +00:00
if (ndo->ndo_vflag < 1) {
2009-03-21 16:23:46 +00:00
return;
}
tptr += DTP_HEADER_LEN;
while (tptr < (pptr+length)) {
2015-01-06 19:03:11 +00:00
ND_TCHECK2(*tptr, 4);
2009-03-21 16:23:46 +00:00
type = EXTRACT_16BITS(tptr);
2015-01-06 19:03:11 +00:00
len = EXTRACT_16BITS(tptr+2);
2017-01-31 19:17:06 +00:00
/* XXX: should not be but sometimes it is, see the test captures */
if (type == 0)
2009-03-21 16:23:46 +00:00
return;
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
2009-03-21 16:23:46 +00:00
tok2str(dtp_tlv_values, "Unknown", type),
2015-01-06 19:03:11 +00:00
type, len));
2009-03-21 16:23:46 +00:00
2017-01-31 19:17:06 +00:00
/* infinite loop check */
if (len < 4)
goto invalid;
ND_TCHECK2(*tptr, len);
2009-03-21 16:23:46 +00:00
switch (type) {
case DTP_DOMAIN_TLV:
2017-01-31 19:17:06 +00:00
ND_PRINT((ndo, ", "));
fn_printzp(ndo, tptr+4, len-4, pptr+length);
2009-03-21 16:23:46 +00:00
break;
2015-01-06 19:03:11 +00:00
case DTP_STATUS_TLV:
2009-03-21 16:23:46 +00:00
case DTP_DTP_TYPE_TLV:
2017-01-31 19:17:06 +00:00
if (len < 5)
goto invalid;
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, ", 0x%x", *(tptr+4)));
2009-03-21 16:23:46 +00:00
break;
case DTP_NEIGHBOR_TLV:
2017-01-31 19:17:06 +00:00
if (len < 10)
goto invalid;
2015-01-06 19:03:11 +00:00
ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4)));
2009-03-21 16:23:46 +00:00
break;
default:
break;
2015-01-06 19:03:11 +00:00
}
2009-03-21 16:23:46 +00:00
tptr += len;
}
return;
2017-01-31 19:17:06 +00:00
invalid:
ND_PRINT((ndo, "%s", istr));
return;
2009-03-21 16:23:46 +00:00
trunc:
2017-01-31 19:17:06 +00:00
ND_PRINT((ndo, "%s", tstr));
2009-03-21 16:23:46 +00:00
}
/*
* Local Variables:
* c-style: whitesmith
* c-basic-offset: 4
* End:
*/