2007-03-19 23:14:14 +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: Cisco UniDirectional Link Detection (UDLD) protocol printer */
|
|
|
|
|
|
|
|
/* specification: RFC 5171 */
|
|
|
|
|
2007-03-19 23:14:14 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2007-03-19 23:14:14 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2007-03-19 23:14:14 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2014-01-02 10:27:54 +08:00
|
|
|
#include "extract.h"
|
2007-03-19 23:14:14 +08:00
|
|
|
|
2015-11-21 03:23:11 +08:00
|
|
|
|
2007-03-19 23:14:14 +08:00
|
|
|
#define UDLD_HEADER_LEN 4
|
|
|
|
#define UDLD_DEVICE_ID_TLV 0x0001
|
|
|
|
#define UDLD_PORT_ID_TLV 0x0002
|
|
|
|
#define UDLD_ECHO_TLV 0x0003
|
|
|
|
#define UDLD_MESSAGE_INTERVAL_TLV 0x0004
|
|
|
|
#define UDLD_TIMEOUT_INTERVAL_TLV 0x0005
|
|
|
|
#define UDLD_DEVICE_NAME_TLV 0x0006
|
|
|
|
#define UDLD_SEQ_NUMBER_TLV 0x0007
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok udld_tlv_values[] = {
|
2007-03-19 23:14:14 +08:00
|
|
|
{ UDLD_DEVICE_ID_TLV, "Device-ID TLV"},
|
|
|
|
{ UDLD_PORT_ID_TLV, "Port-ID TLV"},
|
|
|
|
{ UDLD_ECHO_TLV, "Echo TLV"},
|
|
|
|
{ UDLD_MESSAGE_INTERVAL_TLV, "Message Interval TLV"},
|
|
|
|
{ UDLD_TIMEOUT_INTERVAL_TLV, "Timeout Interval TLV"},
|
|
|
|
{ UDLD_DEVICE_NAME_TLV, "Device Name TLV"},
|
|
|
|
{ UDLD_SEQ_NUMBER_TLV,"Sequence Number TLV"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok udld_code_values[] = {
|
2007-03-19 23:14:14 +08:00
|
|
|
{ 0x00, "Reserved"},
|
|
|
|
{ 0x01, "Probe message"},
|
|
|
|
{ 0x02, "Echo message"},
|
|
|
|
{ 0x03, "Flush message"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok udld_flags_values[] = {
|
2007-03-19 23:14:14 +08:00
|
|
|
{ 0x00, "RT"},
|
|
|
|
{ 0x01, "RSY"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2015-11-21 03:23:11 +08:00
|
|
|
* UDLD's Protocol Data Unit format:
|
2007-03-19 23:14:14 +08:00
|
|
|
*
|
2015-11-21 03:23:11 +08:00
|
|
|
* 0 1 2 3
|
|
|
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
2014-01-02 10:27:54 +08:00
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Ver | Opcode | Flags | Checksum |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | List of TLVs (variable length list) |
|
|
|
|
* | ... |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2007-03-19 23:14:14 +08:00
|
|
|
*
|
2015-11-21 03:23:11 +08:00
|
|
|
* TLV format:
|
|
|
|
*
|
|
|
|
* 0 1 2 3
|
|
|
|
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | TYPE | LENGTH |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | VALUE |
|
|
|
|
* | ... |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*
|
|
|
|
* LENGTH: Length in bytes of the Type, Length, and Value fields.
|
2007-03-19 23:14:14 +08:00
|
|
|
*/
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
#define UDLD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
|
|
|
|
#define UDLD_EXTRACT_OPCODE(x) ((x)&0x1f)
|
2007-03-19 23:14:14 +08:00
|
|
|
|
|
|
|
void
|
2018-05-10 23:40:20 +08:00
|
|
|
udld_print(netdissect_options *ndo, const u_char *pptr, u_int length)
|
2007-03-19 23:14:14 +08:00
|
|
|
{
|
|
|
|
int code, type, len;
|
|
|
|
const u_char *tptr;
|
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "udld";
|
2007-03-19 23:14:14 +08:00
|
|
|
if (length < UDLD_HEADER_LEN)
|
|
|
|
goto trunc;
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
tptr = pptr;
|
2007-03-19 23:14:14 +08:00
|
|
|
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(tptr, UDLD_HEADER_LEN);
|
2007-03-19 23:14:14 +08:00
|
|
|
|
2017-11-28 01:28:49 +08:00
|
|
|
code = UDLD_EXTRACT_OPCODE(EXTRACT_U_1(tptr));
|
2007-03-19 23:14:14 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u",
|
2017-11-28 01:28:49 +08:00
|
|
|
UDLD_EXTRACT_VERSION(EXTRACT_U_1(tptr)),
|
2007-03-19 23:14:14 +08:00
|
|
|
tok2str(udld_code_values, "Reserved", code),
|
|
|
|
code,
|
2017-11-23 06:54:09 +08:00
|
|
|
bittok2str(udld_flags_values, "none", EXTRACT_U_1((tptr + 1))),
|
|
|
|
EXTRACT_U_1((tptr + 1)),
|
2018-01-07 18:47:30 +08:00
|
|
|
length);
|
2007-03-19 23:14:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In non-verbose mode, just print version and opcode type
|
|
|
|
*/
|
2014-03-04 17:55:24 +08:00
|
|
|
if (ndo->ndo_vflag < 1) {
|
2007-03-19 23:14:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tChecksum 0x%04x (unverified)", EXTRACT_BE_U_2(tptr + 2));
|
2007-03-19 23:14:14 +08:00
|
|
|
|
|
|
|
tptr += UDLD_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);
|
2007-03-19 23:14:14 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\t%s (0x%04x) TLV, length %u",
|
2007-03-19 23:14:14 +08:00
|
|
|
tok2str(udld_tlv_values, "Unknown", type),
|
2018-01-07 18:47:30 +08:00
|
|
|
type, len);
|
2007-03-19 23:14:14 +08:00
|
|
|
|
2015-11-21 03:23:11 +08:00
|
|
|
if (type == 0)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
/* infinite loop check */
|
|
|
|
if (len <= 4)
|
|
|
|
goto invalid;
|
|
|
|
|
|
|
|
len -= 4;
|
|
|
|
tptr += 4;
|
|
|
|
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(tptr, len);
|
2015-11-21 03:23:11 +08:00
|
|
|
|
2007-03-19 23:14:14 +08:00
|
|
|
switch (type) {
|
|
|
|
case UDLD_DEVICE_ID_TLV:
|
|
|
|
case UDLD_PORT_ID_TLV:
|
2014-01-02 10:27:54 +08:00
|
|
|
case UDLD_DEVICE_NAME_TLV:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", ");
|
2018-04-30 18:52:10 +08:00
|
|
|
nd_printzp(ndo, tptr, len, NULL);
|
2015-11-21 03:23:11 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDLD_ECHO_TLV:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", ");
|
2018-04-30 18:52:10 +08:00
|
|
|
(void)nd_printn(ndo, tptr, len, NULL);
|
2007-03-19 23:14:14 +08:00
|
|
|
break;
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
case UDLD_MESSAGE_INTERVAL_TLV:
|
2007-03-19 23:14:14 +08:00
|
|
|
case UDLD_TIMEOUT_INTERVAL_TLV:
|
2015-11-21 03:23:11 +08:00
|
|
|
if (len != 1)
|
|
|
|
goto invalid;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", %us", (EXTRACT_U_1(tptr)));
|
2007-03-19 23:14:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UDLD_SEQ_NUMBER_TLV:
|
2015-11-21 03:23:11 +08:00
|
|
|
if (len != 4)
|
|
|
|
goto invalid;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", %u", EXTRACT_BE_U_4(tptr));
|
2007-03-19 23:14:14 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-01-02 10:27:54 +08:00
|
|
|
}
|
2007-03-19 23:14:14 +08:00
|
|
|
tptr += len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
2015-11-21 03:23:11 +08:00
|
|
|
invalid:
|
2018-09-11 18:27:55 +08:00
|
|
|
nd_print_invalid(ndo);
|
2015-11-21 03:23:11 +08:00
|
|
|
return;
|
|
|
|
trunc:
|
2018-05-02 23:15:04 +08:00
|
|
|
nd_print_trunc(ndo);
|
2007-03-19 23:14:14 +08:00
|
|
|
}
|