2 * This module implements decoding of the ATA over Ethernet (AoE) protocol
3 * according to the following specification:
4 * http://support.coraid.com/documents/AoEr11.txt
6 * Copyright (c) 2014 The TCPDUMP project
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 #include <tcpdump-stdinc.h>
38 #include "netdissect.h"
40 #include "addrtoname.h"
43 static const char tstr
[] = " [|aoe]";
44 static const char cstr
[] = " (corrupt)";
47 #define ATA_SECTOR_SIZE 512
49 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0
50 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1
51 #define AOEV1_CMD_MAC_MASK_LIST 2
52 #define AOEV1_CMD_RESERVE_RELEASE 3
54 static const struct tok cmdcode_str
[] = {
55 { AOEV1_CMD_ISSUE_ATA_COMMAND
, "Issue ATA Command" },
56 { AOEV1_CMD_QUERY_CONFIG_INFORMATION
, "Query Config Information" },
57 { AOEV1_CMD_MAC_MASK_LIST
, "MAC Mask List" },
58 { AOEV1_CMD_RESERVE_RELEASE
, "Reserve/Release" },
62 #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */
63 #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */
64 #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */
65 #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */
66 #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */
67 #define AOEV1_MAX_CONFSTR_LEN 1024U
69 #define AOEV1_FLAG_R 0x08
70 #define AOEV1_FLAG_E 0x04
72 static const struct tok aoev1_flag_str
[] = {
73 { AOEV1_FLAG_R
, "Response" },
74 { AOEV1_FLAG_E
, "Error" },
80 static const struct tok aoev1_errcode_str
[] = {
81 { 1, "Unrecognized command code" },
82 { 2, "Bad argument parameter" },
83 { 3, "Device unavailable" },
84 { 4, "Config string present" },
85 { 5, "Unsupported version" },
86 { 6, "Target is reserved" },
90 #define AOEV1_AFLAG_E 0x40
91 #define AOEV1_AFLAG_D 0x10
92 #define AOEV1_AFLAG_A 0x02
93 #define AOEV1_AFLAG_W 0x01
95 static const struct tok aoev1_aflag_str
[] = {
97 { AOEV1_AFLAG_E
, "Ext48" },
99 { AOEV1_AFLAG_D
, "Device" },
100 { 0x04, "MBZ-0x04" },
101 { 0x03, "MBZ-0x03" },
102 { AOEV1_AFLAG_A
, "Async" },
103 { AOEV1_AFLAG_W
, "Write" },
107 static const struct tok aoev1_ccmd_str
[] = {
108 { 0, "read config string" },
109 { 1, "test config string" },
110 { 2, "test config string prefix" },
111 { 3, "set config string" },
112 { 4, "force set config string" },
116 static const struct tok aoev1_mcmd_str
[] = {
117 { 0, "Read Mac Mask List" },
118 { 1, "Edit Mac Mask List" },
122 static const struct tok aoev1_merror_str
[] = {
123 { 1, "Unspecified Error" },
124 { 2, "Bad DCmd directive" },
125 { 3, "Mask list full" },
129 static const struct tok aoev1_dcmd_str
[] = {
130 { 0, "No Directive" },
131 { 1, "Add mac address to mask list" },
132 { 2, "Delete mac address from mask list" },
136 static const struct tok aoev1_rcmd_str
[] = {
137 { 0, "Read reserve list" },
138 { 1, "Set reserve list" },
139 { 2, "Force set reserve list" },
144 aoev1_issue_print(netdissect_options
*ndo
,
145 const u_char
*cp
, const u_int len
)
147 const u_char
*ep
= cp
+ len
;
149 if (len
< AOEV1_ISSUE_ARG_LEN
)
153 ND_PRINT((ndo
, "\n\tAFlags: [%s]", bittok2str(aoev1_aflag_str
, "none", *cp
)));
157 ND_PRINT((ndo
, ", Err/Feature: %u", *cp
));
159 /* Sector Count (not correlated with the length) */
161 ND_PRINT((ndo
, ", Sector Count: %u", *cp
));
165 ND_PRINT((ndo
, ", Cmd/Status: %u", *cp
));
169 ND_PRINT((ndo
, "\n\tlba0: %u", *cp
));
173 ND_PRINT((ndo
, ", lba1: %u", *cp
));
177 ND_PRINT((ndo
, ", lba2: %u", *cp
));
181 ND_PRINT((ndo
, ", lba3: %u", *cp
));
185 ND_PRINT((ndo
, ", lba4: %u", *cp
));
189 ND_PRINT((ndo
, ", lba5: %u", *cp
));
195 if (len
> AOEV1_ISSUE_ARG_LEN
)
196 ND_PRINT((ndo
, "\n\tData: %u bytes", len
- AOEV1_ISSUE_ARG_LEN
));
200 ND_PRINT((ndo
, "%s", cstr
));
201 ND_TCHECK2(*cp
, ep
- cp
);
204 ND_PRINT((ndo
, "%s", tstr
));
208 aoev1_query_print(netdissect_options
*ndo
,
209 const u_char
*cp
, const u_int len
)
211 const u_char
*ep
= cp
+ len
;
214 if (len
< AOEV1_QUERY_ARG_LEN
)
218 ND_PRINT((ndo
, "\n\tBuffer Count: %u", EXTRACT_16BITS(cp
)));
220 /* Firmware Version */
222 ND_PRINT((ndo
, ", Firmware Version: %u", EXTRACT_16BITS(cp
)));
226 ND_PRINT((ndo
, ", Sector Count: %u", *cp
));
230 ND_PRINT((ndo
, ", AoE: %u, CCmd: %s", (*cp
& 0xF0) >> 4,
231 tok2str(aoev1_ccmd_str
, "Unknown (0x02x)", *cp
& 0x0F)));
233 /* Config String Length */
235 cslen
= EXTRACT_16BITS(cp
);
237 if (cslen
> AOEV1_MAX_CONFSTR_LEN
|| AOEV1_QUERY_ARG_LEN
+ cslen
> len
)
240 ND_TCHECK2(*cp
, cslen
);
242 ND_PRINT((ndo
, "\n\tConfig String (length %u): ", cslen
));
243 if (fn_printn(ndo
, cp
, cslen
, ndo
->ndo_snapend
))
249 ND_PRINT((ndo
, "%s", cstr
));
250 ND_TCHECK2(*cp
, ep
- cp
);
253 ND_PRINT((ndo
, "%s", tstr
));
257 aoev1_mac_print(netdissect_options
*ndo
,
258 const u_char
*cp
, const u_int len
)
260 const u_char
*ep
= cp
+ len
;
263 if (len
< AOEV1_MAC_ARG_LEN
)
270 ND_PRINT((ndo
, "\n\tMCmd: %s", tok2str(aoev1_mcmd_str
, "Unknown (0x%02x)", *cp
)));
274 ND_PRINT((ndo
, ", MError: %s", tok2str(aoev1_merror_str
, "Unknown (0x%02x)", *cp
)));
280 ND_PRINT((ndo
, ", Dir Count: %u", dircount
));
281 if (AOEV1_MAC_ARG_LEN
+ dircount
* 8 > len
)
284 for (i
= 0; i
< dircount
; i
++) {
290 ND_PRINT((ndo
, "\n\t DCmd: %s", tok2str(aoev1_dcmd_str
, "Unknown (0x%02x)", *cp
)));
292 /* Ethernet Address */
293 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
294 ND_PRINT((ndo
, ", Ethernet Address: %s", etheraddr_string(ndo
, cp
)));
295 cp
+= ETHER_ADDR_LEN
;
300 ND_PRINT((ndo
, "%s", cstr
));
301 ND_TCHECK2(*cp
, ep
- cp
);
304 ND_PRINT((ndo
, "%s", tstr
));
308 aoev1_reserve_print(netdissect_options
*ndo
,
309 const u_char
*cp
, const u_int len
)
311 const u_char
*ep
= cp
+ len
;
314 if (len
< AOEV1_RESERVE_ARG_LEN
|| (len
- AOEV1_RESERVE_ARG_LEN
) % ETHER_ADDR_LEN
)
318 ND_PRINT((ndo
, "\n\tRCmd: %s", tok2str(aoev1_rcmd_str
, "Unknown (0x%02x)", *cp
)));
320 /* NMacs (correlated with the length) */
324 ND_PRINT((ndo
, ", NMacs: %u", nmacs
));
325 if (AOEV1_RESERVE_ARG_LEN
+ nmacs
* ETHER_ADDR_LEN
!= len
)
328 for (i
= 0; i
< nmacs
; i
++) {
329 ND_PRINT((ndo
, "\n\tEthernet Address %u: %s", i
, etheraddr_string(ndo
, cp
)));
330 cp
+= ETHER_ADDR_LEN
;
335 ND_PRINT((ndo
, "%s", cstr
));
336 ND_TCHECK2(*cp
, ep
- cp
);
339 ND_PRINT((ndo
, "%s", tstr
));
342 /* cp points to the Ver/Flags octet */
344 aoev1_print(netdissect_options
*ndo
,
345 const u_char
*cp
, const u_int len
)
347 const u_char
*ep
= cp
+ len
;
348 uint8_t flags
, command
;
349 void (*cmd_decoder
)(netdissect_options
*, const u_char
*, const u_int
);
351 if (len
< AOEV1_COMMON_HDR_LEN
)
355 ND_PRINT((ndo
, ", Flags: [%s]", bittok2str(aoev1_flag_str
, "none", flags
)));
357 if (! ndo
->ndo_vflag
)
361 if (flags
& AOEV1_FLAG_E
)
362 ND_PRINT((ndo
, "\n\tError: %s", tok2str(aoev1_errcode_str
, "Invalid (%u)", *cp
)));
366 ND_PRINT((ndo
, "\n\tMajor: 0x%04x", EXTRACT_16BITS(cp
)));
370 ND_PRINT((ndo
, ", Minor: 0x%02x", *cp
));
376 ND_PRINT((ndo
, ", Command: %s", tok2str(cmdcode_str
, "Unknown (0x%02x)", command
)));
379 ND_PRINT((ndo
, ", Tag: 0x%08x", EXTRACT_32BITS(cp
)));
383 command
== AOEV1_CMD_ISSUE_ATA_COMMAND
? aoev1_issue_print
:
384 command
== AOEV1_CMD_QUERY_CONFIG_INFORMATION
? aoev1_query_print
:
385 command
== AOEV1_CMD_MAC_MASK_LIST
? aoev1_mac_print
:
386 command
== AOEV1_CMD_RESERVE_RELEASE
? aoev1_reserve_print
:
388 if (cmd_decoder
!= NULL
)
389 cmd_decoder(ndo
, cp
, len
- AOEV1_COMMON_HDR_LEN
);
393 ND_PRINT((ndo
, "%s", cstr
));
394 ND_TCHECK2(*cp
, ep
- cp
);
397 ND_PRINT((ndo
, "%s", tstr
));
401 aoe_print(netdissect_options
*ndo
,
402 const u_char
*cp
, const u_int len
)
404 const u_char
*ep
= cp
+ len
;
407 ND_PRINT((ndo
, "AoE length %u", len
));
413 ver
= (*cp
& 0xF0) >> 4;
414 /* Don't advance cp yet: low order 4 bits are version-specific. */
415 ND_PRINT((ndo
, ", Ver %u", ver
));
419 aoev1_print(ndo
, cp
, len
);
425 ND_PRINT((ndo
, "%s", cstr
));
426 ND_TCHECK2(*cp
, ep
- cp
);
429 ND_PRINT((ndo
, "%s", tstr
));