* 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
- *
*/
+/* \summary: Cisco UniDirectional Link Detection (UDLD) protocol printer */
+
+/* specification: RFC 5171 */
+
#ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
#endif
-#include <tcpdump-stdinc.h>
-
-#include <stdio.h>
-#include <string.h>
+#include "netdissect-stdinc.h"
-#include "interface.h"
-#include "addrtoname.h"
+#include "netdissect.h"
#include "extract.h"
-#include "nlpid.h"
+
#define UDLD_HEADER_LEN 4
#define UDLD_DEVICE_ID_TLV 0x0001
};
/*
+ * 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)
#define UDLD_EXTRACT_OPCODE(x) ((x)&0x1f)
void
-udld_print (const u_char *pptr, u_int length)
+udld_print(netdissect_options *ndo, const u_char *pptr, u_int length)
{
int code, type, len;
const u_char *tptr;
+ ndo->ndo_protocol = "udld";
if (length < UDLD_HEADER_LEN)
goto trunc;
tptr = pptr;
- if (!TTEST2(*tptr, UDLD_HEADER_LEN))
- goto trunc;
+ ND_TCHECK_LEN(tptr, UDLD_HEADER_LEN);
- code = UDLD_EXTRACT_OPCODE(*tptr);
+ code = UDLD_EXTRACT_OPCODE(EXTRACT_U_1(tptr));
- printf("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u",
- UDLD_EXTRACT_VERSION(*tptr),
+ ND_PRINT("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u",
+ 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);
/*
* In non-verbose mode, just print version and opcode type
*/
- if (vflag < 1) {
+ if (ndo->ndo_vflag < 1) {
return;
}
- printf("\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr+2));
+ ND_PRINT("\n\tChecksum 0x%04x (unverified)", EXTRACT_BE_U_2(tptr + 2));
tptr += UDLD_HEADER_LEN;
while (tptr < (pptr+length)) {
- if (!TTEST2(*tptr, 4))
- goto trunc;
+ ND_TCHECK_4(tptr);
+ type = EXTRACT_BE_U_2(tptr);
+ len = EXTRACT_BE_U_2(tptr + 2);
- type = EXTRACT_16BITS(tptr);
- len = EXTRACT_16BITS(tptr+2);
- len -= 4;
- tptr += 4;
+ ND_PRINT("\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 (type == 0 || len == 0) {
- return;
- }
+ if (len <= 4)
+ goto invalid;
- printf("\n\t%s (0x%04x) TLV, length %u",
- tok2str(udld_tlv_values, "Unknown", type),
- type, len);
+ len -= 4;
+ tptr += 4;
+
+ ND_TCHECK_LEN(tptr, len);
switch (type) {
case UDLD_DEVICE_ID_TLV:
case UDLD_PORT_ID_TLV:
- case UDLD_ECHO_TLV:
case UDLD_DEVICE_NAME_TLV:
- printf(", %s", tptr);
+ ND_PRINT(", ");
+ nd_printzp(ndo, tptr, len, NULL);
+ break;
+
+ case UDLD_ECHO_TLV:
+ ND_PRINT(", ");
+ (void)nd_printn(ndo, tptr, len, NULL);
break;
case UDLD_MESSAGE_INTERVAL_TLV:
case UDLD_TIMEOUT_INTERVAL_TLV:
- printf(", %us", (*tptr));
+ if (len != 1)
+ goto invalid;
+ ND_PRINT(", %us", (EXTRACT_U_1(tptr)));
break;
case UDLD_SEQ_NUMBER_TLV:
- printf(", %u", EXTRACT_32BITS(tptr));
+ if (len != 4)
+ goto invalid;
+ ND_PRINT(", %u", EXTRACT_BE_U_4(tptr));
break;
default:
return;
- trunc:
- printf("[|udld]");
+invalid:
+ ND_PRINT("%s", istr);
+ return;
+trunc:
+ nd_print_trunc(ndo);
}
-
-/*
- * Local Variables:
- * c-style: whitesmith
- * c-basic-offset: 4
- * End:
- */