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 * UNIDIRECTIONAL LINK DETECTION (UDLD) as per
16 * http://www.ietf.org/internet-drafts/draft-foschiano-udld-02.txt
18 * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
25 #include <tcpdump-stdinc.h>
30 #include "interface.h"
34 #define UDLD_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_values
[] = {
71 * 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
72 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73 * | Ver | Opcode | Flags | Checksum |
74 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75 * | List of TLVs (variable length list) |
77 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81 #define UDLD_EXTRACT_VERSION(x) (((x)&0xe0)>>5)
82 #define UDLD_EXTRACT_OPCODE(x) ((x)&0x1f)
85 udld_print (const u_char
*pptr
, u_int length
)
90 if (length
< UDLD_HEADER_LEN
)
95 if (!TTEST2(*tptr
, UDLD_HEADER_LEN
))
98 code
= UDLD_EXTRACT_OPCODE(*tptr
);
100 printf("UDLDv%u, Code %s (%x), Flags [%s] (0x%02x), length %u",
101 UDLD_EXTRACT_VERSION(*tptr
),
102 tok2str(udld_code_values
, "Reserved", code
),
104 bittok2str(udld_flags_values
, "none", *(tptr
+1)),
109 * In non-verbose mode, just print version and opcode type
115 printf("\n\tChecksum 0x%04x (unverified)", EXTRACT_16BITS(tptr
+2));
117 tptr
+= UDLD_HEADER_LEN
;
119 while (tptr
< (pptr
+length
)) {
121 if (!TTEST2(*tptr
, 4))
124 type
= EXTRACT_16BITS(tptr
);
125 len
= EXTRACT_16BITS(tptr
+2);
129 /* infinite loop check */
130 if (type
== 0 || len
== 0) {
134 printf("\n\t%s (0x%04x) TLV, length %u",
135 tok2str(udld_tlv_values
, "Unknown", type
),
139 case UDLD_DEVICE_ID_TLV
:
140 case UDLD_PORT_ID_TLV
:
142 case UDLD_DEVICE_NAME_TLV
:
143 printf(", %s", tptr
);
146 case UDLD_MESSAGE_INTERVAL_TLV
:
147 case UDLD_TIMEOUT_INTERVAL_TLV
:
148 printf(", %us", (*tptr
));
151 case UDLD_SEQ_NUMBER_TLV
:
152 printf(", %u", EXTRACT_32BITS(tptr
));
169 * c-style: whitesmith