2 * Copyright (c) 1998-2007 The TCPDUMP project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
18 /* \summary: Cisco UniDirectional Link Detection (UDLD) protocol printer */
20 /* specification: RFC 5171 */
26 #include "netdissect-stdinc.h"
28 #define ND_LONGJMP_FROM_TCHECK
29 #include "netdissect.h"
33 #define UDLD_HEADER_LEN 4
34 #define UDLD_TLV_HEADER_LEN 4
35 #define UDLD_DEVICE_ID_TLV 0x0001
36 #define UDLD_PORT_ID_TLV 0x0002
37 #define UDLD_ECHO_TLV 0x0003
38 #define UDLD_MESSAGE_INTERVAL_TLV 0x0004
39 #define UDLD_TIMEOUT_INTERVAL_TLV 0x0005
40 #define UDLD_DEVICE_NAME_TLV 0x0006
41 #define UDLD_SEQ_NUMBER_TLV 0x0007
43 static const struct tok udld_tlv_values
[] = {
44 { UDLD_DEVICE_ID_TLV
, "Device-ID TLV"},
45 { UDLD_PORT_ID_TLV
, "Port-ID TLV"},
46 { UDLD_ECHO_TLV
, "Echo TLV"},
47 { UDLD_MESSAGE_INTERVAL_TLV
, "Message Interval TLV"},
48 { UDLD_TIMEOUT_INTERVAL_TLV
, "Timeout Interval TLV"},
49 { UDLD_DEVICE_NAME_TLV
, "Device Name TLV"},
50 { UDLD_SEQ_NUMBER_TLV
,"Sequence Number TLV"},
54 static const struct tok udld_code_values
[] = {
56 { 0x01, "Probe message"},
57 { 0x02, "Echo message"},
58 { 0x03, "Flush message"},
62 static const struct tok udld_flags_bitmap_str
[] = {
75 * UDLD's Protocol Data Unit format:
78 * 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
79 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
80 * | Ver | Opcode | Flags | Checksum |
81 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
82 * | List of TLVs (variable length list) |
84 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 * 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
90 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
92 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
95 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
97 * LENGTH: Length in bytes of the Type, Length, and Value fields.
100 #define UDLD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
101 #define UDLD_EXTRACT_OPCODE(x) ((x)&0x1f)
104 udld_print(netdissect_options
*ndo
,
105 const u_char
*tptr
, u_int length
)
107 uint8_t ver
, code
, flags
;
109 ndo
->ndo_protocol
= "udld";
110 if (length
< UDLD_HEADER_LEN
)
113 ver
= UDLD_EXTRACT_VERSION(GET_U_1(tptr
));
114 code
= UDLD_EXTRACT_OPCODE(GET_U_1(tptr
));
118 flags
= GET_U_1(tptr
);
122 ND_PRINT("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u",
124 tok2str(udld_code_values
, "Reserved", code
),
126 bittok2str(udld_flags_bitmap_str
, "none", flags
),
131 * In non-verbose mode, just print version and opcode type
133 if (ndo
->ndo_vflag
< 1) {
134 goto tcheck_remainder
;
137 ND_PRINT("\n\tChecksum 0x%04x (unverified)", GET_BE_U_2(tptr
));
144 if (length
< UDLD_TLV_HEADER_LEN
)
147 type
= GET_BE_U_2(tptr
);
151 len
= GET_BE_U_2(tptr
);
155 ND_PRINT("\n\t%s (0x%04x) TLV, length %u",
156 tok2str(udld_tlv_values
, "Unknown", type
),
159 /* infinite loop check */
160 if (len
<= UDLD_TLV_HEADER_LEN
)
163 len
-= UDLD_TLV_HEADER_LEN
;
168 case UDLD_DEVICE_ID_TLV
:
169 case UDLD_PORT_ID_TLV
:
170 case UDLD_DEVICE_NAME_TLV
:
172 nd_printzp(ndo
, tptr
, len
, NULL
);
177 (void)nd_printn(ndo
, tptr
, len
, NULL
);
180 case UDLD_MESSAGE_INTERVAL_TLV
:
181 case UDLD_TIMEOUT_INTERVAL_TLV
:
184 ND_PRINT(", %us", (GET_U_1(tptr
)));
187 case UDLD_SEQ_NUMBER_TLV
:
190 ND_PRINT(", %u", GET_BE_U_4(tptr
));
194 ND_TCHECK_LEN(tptr
, len
);
204 nd_print_invalid(ndo
);
206 ND_TCHECK_LEN(tptr
, length
);