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 */
|
|
|
|
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2020-12-01 08:05:32 +08:00
|
|
|
#define ND_LONGJMP_FROM_TCHECK
|
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
|
|
|
|
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[] = {
|
2020-12-01 08:05:32 +08:00
|
|
|
{ DTP_DOMAIN_TLV, "Domain" },
|
|
|
|
{ DTP_STATUS_TLV, "Status" },
|
|
|
|
{ DTP_DTP_TYPE_TLV, "DTP type" },
|
|
|
|
{ DTP_NEIGHBOR_TLV, "Neighbor" },
|
2007-03-23 16:12:00 +08:00
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2020-12-01 08:05:32 +08:00
|
|
|
dtp_print(netdissect_options *ndo, const u_char *tptr, u_int length)
|
2007-03-23 16:12:00 +08:00
|
|
|
{
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "dtp";
|
2020-12-01 08:05:32 +08:00
|
|
|
if (length < DTP_HEADER_LEN) {
|
|
|
|
ND_PRINT("[zero packet length]");
|
|
|
|
goto invalid;
|
|
|
|
}
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("DTPv%u, length %u",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_U_1(tptr),
|
2018-01-07 18:47:30 +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;
|
2020-12-01 08:05:32 +08:00
|
|
|
length -= DTP_HEADER_LEN;
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2020-12-01 08:05:32 +08:00
|
|
|
while (length) {
|
|
|
|
uint16_t type, len;
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2020-12-01 08:05:32 +08:00
|
|
|
if (length < 4) {
|
|
|
|
ND_PRINT("[%u bytes remaining]", length);
|
|
|
|
goto invalid;
|
|
|
|
}
|
2018-06-16 23:23:21 +08:00
|
|
|
type = GET_BE_U_2(tptr);
|
|
|
|
len = GET_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;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t%s (0x%04x) TLV, length %u",
|
2007-03-23 16:12:00 +08:00
|
|
|
tok2str(dtp_tlv_values, "Unknown", type),
|
2018-01-07 18:47:30 +08:00
|
|
|
type, len);
|
2007-03-23 16:12:00 +08:00
|
|
|
|
2015-09-06 04:17:30 +08:00
|
|
|
/* infinite loop check */
|
2020-12-01 08:05:32 +08:00
|
|
|
if (len < 4 || len > length) {
|
2023-05-13 21:43:38 +08:00
|
|
|
ND_PRINT("[TLV length %u]", len);
|
2015-09-06 04:17:30 +08:00
|
|
|
goto invalid;
|
2020-12-01 08:05:32 +08:00
|
|
|
}
|
2015-09-06 04:17:30 +08:00
|
|
|
|
2007-03-23 16:12:00 +08:00
|
|
|
switch (type) {
|
|
|
|
case DTP_DOMAIN_TLV:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", ");
|
2020-12-11 03:40:15 +08:00
|
|
|
nd_printjnp(ndo, tptr+4, len-4);
|
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:
|
2020-12-01 08:05:32 +08:00
|
|
|
if (len != 5)
|
2015-09-06 04:17:30 +08:00
|
|
|
goto invalid;
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(", 0x%x", GET_U_1(tptr + 4));
|
2007-03-23 16:12:00 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DTP_NEIGHBOR_TLV:
|
2020-12-01 08:05:32 +08:00
|
|
|
if (len != 10)
|
2015-09-06 04:17:30 +08:00
|
|
|
goto invalid;
|
2023-07-14 15:27:39 +08:00
|
|
|
ND_PRINT(", %s", GET_MAC48_STRING(tptr+4));
|
2007-03-23 16:12:00 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2020-12-01 08:05:32 +08:00
|
|
|
ND_TCHECK_LEN(tptr, len);
|
2007-03-23 16:12:00 +08:00
|
|
|
break;
|
2014-01-02 10:27:54 +08:00
|
|
|
}
|
2007-03-23 16:12:00 +08:00
|
|
|
tptr += len;
|
2020-12-01 08:05:32 +08:00
|
|
|
length -= len;
|
2007-03-23 16:12:00 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2015-09-06 04:17:30 +08:00
|
|
|
invalid:
|
2018-09-11 18:27:55 +08:00
|
|
|
nd_print_invalid(ndo);
|
2020-12-01 08:05:32 +08:00
|
|
|
ND_TCHECK_LEN(tptr, length);
|
2007-03-23 16:12:00 +08:00
|
|
|
}
|