* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE.
*
- * UNIDIRECTIONAL LINK DETECTION (UDLD) as per
- * http://www.ietf.org/internet-drafts/draft-foschiano-udld-02.txt
- *
*/
-#define NETDISSECT_REWORKED
+/* \summary: Cisco UniDirectional Link Detection (UDLD) protocol printer */
+
+/* specification: RFC 5171 */
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
-#include "interface.h"
+#include "netdissect.h"
#include "extract.h"
+static const char tstr[] = " [|udld]";
+
#define UDLD_HEADER_LEN 4
#define UDLD_DEVICE_ID_TLV 0x0001
#define UDLD_PORT_ID_TLV 0x0002
};
/*
+ * UDLD's Protocol Data Unit 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
+ * 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
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Ver | Opcode | Flags | Checksum |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | ... |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
+ * 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.
*/
#define UDLD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
ND_TCHECK2(*tptr, UDLD_HEADER_LEN);
- code = UDLD_EXTRACT_OPCODE(*tptr);
+ code = UDLD_EXTRACT_OPCODE(EXTRACT_U_1(tptr));
ND_PRINT((ndo, "UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u",
- UDLD_EXTRACT_VERSION(*tptr),
+ UDLD_EXTRACT_VERSION(EXTRACT_U_1(tptr)),
tok2str(udld_code_values, "Reserved", code),
code,
- bittok2str(udld_flags_values, "none", *(tptr+1)),
- *(tptr+1),
+ bittok2str(udld_flags_values, "none", EXTRACT_U_1((tptr + 1))),
+ EXTRACT_U_1((tptr + 1)),
length));
/*
return;
}
- ND_PRINT((ndo, "\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr+2)));
+ ND_PRINT((ndo, "\n\tChecksum 0x%04x (unverified)", EXTRACT_BE_U_2(tptr + 2)));
tptr += UDLD_HEADER_LEN;
while (tptr < (pptr+length)) {
- ND_TCHECK2(*tptr, 4);
-
- type = EXTRACT_16BITS(tptr);
- len = EXTRACT_16BITS(tptr+2);
- len -= 4;
- tptr += 4;
-
- /* infinite loop check */
- if (type == 0 || len == 0) {
- return;
- }
+ ND_TCHECK_4(tptr);
+ type = EXTRACT_BE_U_2(tptr);
+ len = EXTRACT_BE_U_2(tptr + 2);
ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
tok2str(udld_tlv_values, "Unknown", type),
type, len));
+ if (type == 0)
+ goto invalid;
+
+ /* infinite loop check */
+ if (len <= 4)
+ goto invalid;
+
+ len -= 4;
+ tptr += 4;
+
+ ND_TCHECK2(*tptr, len);
+
switch (type) {
case UDLD_DEVICE_ID_TLV:
case UDLD_PORT_ID_TLV:
- case UDLD_ECHO_TLV:
case UDLD_DEVICE_NAME_TLV:
- ND_PRINT((ndo, ", %s", tptr));
+ ND_PRINT((ndo, ", "));
+ fn_printzp(ndo, tptr, len, NULL);
+ break;
+
+ case UDLD_ECHO_TLV:
+ ND_PRINT((ndo, ", "));
+ (void)fn_printn(ndo, tptr, len, NULL);
break;
case UDLD_MESSAGE_INTERVAL_TLV:
case UDLD_TIMEOUT_INTERVAL_TLV:
- ND_PRINT((ndo, ", %us", (*tptr)));
+ if (len != 1)
+ goto invalid;
+ ND_PRINT((ndo, ", %us", (EXTRACT_U_1(tptr))));
break;
case UDLD_SEQ_NUMBER_TLV:
- ND_PRINT((ndo, ", %u", EXTRACT_32BITS(tptr)));
+ if (len != 4)
+ goto invalid;
+ ND_PRINT((ndo, ", %u", EXTRACT_BE_U_4(tptr)));
break;
default:
return;
- trunc:
- ND_PRINT((ndo, "[|udld]"));
+invalid:
+ ND_PRINT((ndo, "%s", istr));
+ return;
+trunc:
+ ND_PRINT((ndo, "%s", tstr));
}
/*