2007-03-23 16:12:00 +08: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>
|
|
|
|
*/
|
|
|
|
|
2016-08-15 21:27:28 +08:00
|
|
|
/* \summary: Dynamic Trunking Protocol (DTP) printer */
|
|
|
|
|
2007-03-23 16:12:00 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-09-10 04:42:38 +08:00
|
|
|
#include <netdissect-stdinc.h>
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2007-03-23 16:12:00 +08:00
|
|
|
#include "addrtoname.h"
|
2014-01-02 10:27:54 +08:00
|
|
|
#include "extract.h"
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2015-09-06 04:17:30 +08:00
|
|
|
static const char tstr[] = " [|dtp]";
|
|
|
|
|
2007-03-23 16:12:00 +08: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
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok dtp_tlv_values[] = {
|
2007-03-23 16:12:00 +08: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
|
2014-02-27 19:13:43 +08:00
|
|
|
dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
|
2007-03-23 16:12:00 +08:00
|
|
|
{
|
|
|
|
int type, len;
|
|
|
|
const u_char *tptr;
|
|
|
|
|
|
|
|
if (length < DTP_HEADER_LEN)
|
|
|
|
goto trunc;
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
tptr = pptr;
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(tptr, DTP_HEADER_LEN);
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2014-02-27 19:13:43 +08:00
|
|
|
ND_PRINT((ndo, "DTPv%u, length %u",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_U_1(tptr),
|
2014-02-27 19:13:43 +08:00
|
|
|
length));
|
2007-03-23 16:12:00 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In non-verbose mode, just print version.
|
|
|
|
*/
|
2014-02-27 19:13:43 +08:00
|
|
|
if (ndo->ndo_vflag < 1) {
|
2007-03-23 16:12:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tptr += DTP_HEADER_LEN;
|
|
|
|
|
|
|
|
while (tptr < (pptr+length)) {
|
|
|
|
|
2017-11-25 05:48:55 +08:00
|
|
|
ND_TCHECK_4(tptr);
|
2017-11-23 06:54:09 +08:00
|
|
|
type = EXTRACT_BE_U_2(tptr);
|
|
|
|
len = EXTRACT_BE_U_2(tptr + 2);
|
2015-09-06 04:17:30 +08:00
|
|
|
/* XXX: should not be but sometimes it is, see the test captures */
|
|
|
|
if (type == 0)
|
2007-03-23 16:12:00 +08:00
|
|
|
return;
|
2014-02-27 19:13:43 +08:00
|
|
|
ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
|
2007-03-23 16:12:00 +08:00
|
|
|
tok2str(dtp_tlv_values, "Unknown", type),
|
2014-02-27 19:13:43 +08:00
|
|
|
type, len));
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2015-09-06 04:17:30 +08:00
|
|
|
/* infinite loop check */
|
|
|
|
if (len < 4)
|
|
|
|
goto invalid;
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(tptr, len);
|
2015-09-06 04:17:30 +08:00
|
|
|
|
2007-03-23 16:12:00 +08:00
|
|
|
switch (type) {
|
|
|
|
case DTP_DOMAIN_TLV:
|
2015-09-06 04:17:30 +08:00
|
|
|
ND_PRINT((ndo, ", "));
|
|
|
|
fn_printzp(ndo, tptr+4, len-4, pptr+length);
|
2007-03-23 16:12:00 +08:00
|
|
|
break;
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
case DTP_STATUS_TLV:
|
2007-03-23 16:12:00 +08:00
|
|
|
case DTP_DTP_TYPE_TLV:
|
2015-09-06 04:17:30 +08:00
|
|
|
if (len < 5)
|
|
|
|
goto invalid;
|
2017-11-27 04:33:24 +08:00
|
|
|
ND_PRINT((ndo, ", 0x%x", EXTRACT_U_1(tptr + 4)));
|
2007-03-23 16:12:00 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTP_NEIGHBOR_TLV:
|
2015-09-06 04:17:30 +08:00
|
|
|
if (len < 10)
|
|
|
|
goto invalid;
|
2014-04-04 15:43:46 +08:00
|
|
|
ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4)));
|
2007-03-23 16:12:00 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-01-02 10:27:54 +08:00
|
|
|
}
|
2007-03-23 16:12:00 +08:00
|
|
|
tptr += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
2015-09-06 04:17:30 +08:00
|
|
|
invalid:
|
|
|
|
ND_PRINT((ndo, "%s", istr));
|
|
|
|
return;
|
2007-03-23 16:12:00 +08:00
|
|
|
trunc:
|
2015-09-06 04:17:30 +08:00
|
|
|
ND_PRINT((ndo, "%s", tstr));
|
2007-03-23 16:12:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-style: whitesmith
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|