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.
32 #define NETDISSECT_REWORKED
37 #include <tcpdump-stdinc.h>
39 #include "interface.h"
41 #include "addrtoname.h"
44 static const char tstr[] = " [|aoe]";
45 static const char cstr[] = " (corrupt)";
48 #define ATA_SECTOR_SIZE 512
50 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0
51 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1
52 #define AOEV1_CMD_MAC_MASK_LIST 2
53 #define AOEV1_CMD_RESERVE_RELEASE 3
55 static const struct tok cmdcode_str[] = {
56 { AOEV1_CMD_ISSUE_ATA_COMMAND, "Issue ATA Command" },
57 { AOEV1_CMD_QUERY_CONFIG_INFORMATION, "Query Config Information" },
58 { AOEV1_CMD_MAC_MASK_LIST, "MAC Mask List" },
59 { AOEV1_CMD_RESERVE_RELEASE, "Reserve/Release" },
63 #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */
64 #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */
65 #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */
66 #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */
67 #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */
68 #define AOEV1_MAX_CONFSTR_LEN 1024U
70 #define AOEV1_FLAG_R 0x08
71 #define AOEV1_FLAG_E 0x04
73 static const struct tok aoev1_flag_str[] = {
74 { AOEV1_FLAG_R, "Response" },
75 { AOEV1_FLAG_E, "Error" },
81 static const struct tok aoev1_errcode_str[] = {
82 { 1, "Unrecognized command code" },
83 { 2, "Bad argument parameter" },
84 { 3, "Device unavailable" },
85 { 4, "Config string present" },
86 { 5, "Unsupported version" },
87 { 6, "Target is reserved" },
91 #define AOEV1_AFLAG_E 0x40
92 #define AOEV1_AFLAG_D 0x10
93 #define AOEV1_AFLAG_A 0x02
94 #define AOEV1_AFLAG_W 0x01
96 static const struct tok aoev1_aflag_str[] = {
98 { AOEV1_AFLAG_E, "Ext48" },
100 { AOEV1_AFLAG_D, "Device" },
101 { 0x04, "MBZ-0x04" },
102 { 0x03, "MBZ-0x03" },
103 { AOEV1_AFLAG_A, "Async" },
104 { AOEV1_AFLAG_W, "Write" },
108 static const struct tok aoev1_ccmd_str[] = {
109 { 0, "read config string" },
110 { 1, "test config string" },
111 { 2, "test config string prefix" },
112 { 3, "set config string" },
113 { 4, "force set config string" },
117 static const struct tok aoev1_mcmd_str[] = {
118 { 0, "Read Mac Mask List" },
119 { 1, "Edit Mac Mask List" },
123 static const struct tok aoev1_merror_str[] = {
124 { 1, "Unspecified Error" },
125 { 2, "Bad DCmd directive" },
126 { 3, "Mask list full" },
130 static const struct tok aoev1_dcmd_str[] = {
131 { 0, "No Directive" },
132 { 1, "Add mac address to mask list" },
133 { 2, "Delete mac address from mask list" },
137 static const struct tok aoev1_rcmd_str[] = {
138 { 0, "Read reserve list" },
139 { 1, "Set reserve list" },
140 { 2, "Force set reserve list" },
145 aoev1_issue_print(netdissect_options *ndo,
146 const u_char *cp, const u_int len)
148 const u_char *ep = cp + len;
150 if (len < AOEV1_ISSUE_ARG_LEN)
154 ND_PRINT((ndo, "\n\tAFlags: [%s]", bittok2str(aoev1_aflag_str, "none", *cp)));
158 ND_PRINT((ndo, ", Err/Feature: %u", *cp));
160 /* Sector Count (not correlated with the length) */
162 ND_PRINT((ndo, ", Sector Count: %u", *cp));
166 ND_PRINT((ndo, ", Cmd/Status: %u", *cp));
170 ND_PRINT((ndo, "\n\tlba0: %u", *cp));
174 ND_PRINT((ndo, ", lba1: %u", *cp));
178 ND_PRINT((ndo, ", lba2: %u", *cp));
182 ND_PRINT((ndo, ", lba3: %u", *cp));
186 ND_PRINT((ndo, ", lba4: %u", *cp));
190 ND_PRINT((ndo, ", lba5: %u", *cp));
196 if (len > AOEV1_ISSUE_ARG_LEN)
197 ND_PRINT((ndo, "\n\tData: %u bytes", len - AOEV1_ISSUE_ARG_LEN));
201 ND_PRINT((ndo, "%s", cstr));
202 ND_TCHECK2(*cp, ep - cp);
205 ND_PRINT((ndo, "%s", tstr));
209 aoev1_query_print(netdissect_options *ndo,
210 const u_char *cp, const u_int len)
212 const u_char *ep = cp + len;
215 if (len < AOEV1_QUERY_ARG_LEN)
219 ND_PRINT((ndo, "\n\tBuffer Count: %u", EXTRACT_16BITS(cp)));
221 /* Firmware Version */
223 ND_PRINT((ndo, ", Firmware Version: %u", EXTRACT_16BITS(cp)));
227 ND_PRINT((ndo, ", Sector Count: %u", *cp));
231 ND_PRINT((ndo, ", AoE: %u, CCmd: %s", (*cp & 0xF0) >> 4,
232 tok2str(aoev1_ccmd_str, "Unknown (0x02x)", *cp & 0x0F)));
234 /* Config String Length */
236 cslen = EXTRACT_16BITS(cp);
238 if (cslen > AOEV1_MAX_CONFSTR_LEN || AOEV1_QUERY_ARG_LEN + cslen > len)
241 ND_TCHECK2(*cp, cslen);
243 ND_PRINT((ndo, "\n\tConfig String (length %u): ", cslen));
244 if (fn_printn(ndo, cp, cslen, ndo->ndo_snapend))
250 ND_PRINT((ndo, "%s", cstr));
251 ND_TCHECK2(*cp, ep - cp);
254 ND_PRINT((ndo, "%s", tstr));
258 aoev1_mac_print(netdissect_options *ndo,
259 const u_char *cp, const u_int len)
261 const u_char *ep = cp + len;
264 if (len < AOEV1_MAC_ARG_LEN)
271 ND_PRINT((ndo, "\n\tMCmd: %s", tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", *cp)));
275 ND_PRINT((ndo, ", MError: %s", tok2str(aoev1_merror_str, "Unknown (0x%02x)", *cp)));
281 ND_PRINT((ndo, ", Dir Count: %u", dircount));
282 if (AOEV1_MAC_ARG_LEN + dircount * 8 > len)
285 for (i = 0; i < dircount; i++) {
291 ND_PRINT((ndo, "\n\t DCmd: %s", tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", *cp)));
293 /* Ethernet Address */
294 ND_TCHECK2(*cp, ETHER_ADDR_LEN);
295 ND_PRINT((ndo, ", Ethernet Address: %s", etheraddr_string(ndo, cp)));
296 cp += ETHER_ADDR_LEN;
301 ND_PRINT((ndo, "%s", cstr));
302 ND_TCHECK2(*cp, ep - cp);
305 ND_PRINT((ndo, "%s", tstr));
309 aoev1_reserve_print(netdissect_options *ndo,
310 const u_char *cp, const u_int len)
312 const u_char *ep = cp + len;
315 if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % ETHER_ADDR_LEN)
319 ND_PRINT((ndo, "\n\tRCmd: %s", tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", *cp)));
321 /* NMacs (correlated with the length) */
325 ND_PRINT((ndo, ", NMacs: %u", nmacs));
326 if (AOEV1_RESERVE_ARG_LEN + nmacs * ETHER_ADDR_LEN != len)
329 for (i = 0; i < nmacs; i++) {
330 ND_PRINT((ndo, "\n\tEthernet Address %u: %s", i, etheraddr_string(ndo, cp)));
331 cp += ETHER_ADDR_LEN;
336 ND_PRINT((ndo, "%s", cstr));
337 ND_TCHECK2(*cp, ep - cp);
340 ND_PRINT((ndo, "%s", tstr));
343 /* cp points to the Ver/Flags octet */
345 aoev1_print(netdissect_options *ndo,
346 const u_char *cp, const u_int len)
348 const u_char *ep = cp + len;
349 uint8_t flags, command;
350 void (*cmd_decoder)(netdissect_options *, const u_char *, const u_int);
352 if (len < AOEV1_COMMON_HDR_LEN)
356 ND_PRINT((ndo, ", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags)));
358 if (! ndo->ndo_vflag)
362 if (flags & AOEV1_FLAG_E)
363 ND_PRINT((ndo, "\n\tError: %s", tok2str(aoev1_errcode_str, "Invalid (%u)", *cp)));
367 ND_PRINT((ndo, "\n\tMajor: 0x%04x", EXTRACT_16BITS(cp)));
371 ND_PRINT((ndo, ", Minor: 0x%02x", *cp));
377 ND_PRINT((ndo, ", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command)));
380 ND_PRINT((ndo, ", Tag: 0x%08x", EXTRACT_32BITS(cp)));
384 command == AOEV1_CMD_ISSUE_ATA_COMMAND ? aoev1_issue_print :
385 command == AOEV1_CMD_QUERY_CONFIG_INFORMATION ? aoev1_query_print :
386 command == AOEV1_CMD_MAC_MASK_LIST ? aoev1_mac_print :
387 command == AOEV1_CMD_RESERVE_RELEASE ? aoev1_reserve_print :
389 if (cmd_decoder != NULL)
390 cmd_decoder(ndo, cp, len - AOEV1_COMMON_HDR_LEN);
394 ND_PRINT((ndo, "%s", cstr));
395 ND_TCHECK2(*cp, ep - cp);
398 ND_PRINT((ndo, "%s", tstr));
402 aoe_print(netdissect_options *ndo,
403 const u_char *cp, const u_int len)
405 const u_char *ep = cp + len;
408 ND_PRINT((ndo, "AoE length %u", len));
414 ver = (*cp & 0xF0) >> 4;
415 /* Don't advance cp yet: low order 4 bits are version-specific. */
416 ND_PRINT((ndo, ", Ver %u", ver));
420 aoev1_print(ndo, cp, len);
426 ND_PRINT((ndo, "%s", cstr));
427 ND_TCHECK2(*cp, ep - cp);
430 ND_PRINT((ndo, "%s", tstr));