2 * Copyright (c) 2014 The TCPDUMP project
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
17 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
20 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 /* \summary: ATA over Ethernet (AoE) protocol printer */
31 * https://web.archive.org/web/20161025044402/http://brantleycoilecompany.com/AoEr11.pdf
38 #include "netdissect-stdinc.h"
40 #define ND_LONGJMP_FROM_TCHECK
41 #include "netdissect.h"
43 #include "addrtoname.h"
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_bitmap_str[] = {
97 { AOEV1_AFLAG_E, "Ext48" },
99 { AOEV1_AFLAG_D, "Device" },
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, u_int len)
147 if (len < AOEV1_ISSUE_ARG_LEN)
150 ND_PRINT("\n\tAFlags: [%s]",
151 bittok2str(aoev1_aflag_bitmap_str, "none", GET_U_1(cp)));
155 ND_PRINT(", Err/Feature: %u", GET_U_1(cp));
158 /* Sector Count (not correlated with the length) */
159 ND_PRINT(", Sector Count: %u", GET_U_1(cp));
163 ND_PRINT(", Cmd/Status: %u", GET_U_1(cp));
167 ND_PRINT("\n\tlba0: %u", GET_U_1(cp));
171 ND_PRINT(", lba1: %u", GET_U_1(cp));
175 ND_PRINT(", lba2: %u", GET_U_1(cp));
179 ND_PRINT(", lba3: %u", GET_U_1(cp));
183 ND_PRINT(", lba4: %u", GET_U_1(cp));
187 ND_PRINT(", lba5: %u", GET_U_1(cp));
196 ND_PRINT("\n\tData: %u bytes", len);
200 nd_print_invalid(ndo);
201 ND_TCHECK_LEN(cp, len);
205 aoev1_query_print(netdissect_options *ndo,
206 const u_char *cp, u_int len)
210 if (len < AOEV1_QUERY_ARG_LEN)
213 ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp));
216 /* Firmware Version */
217 ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp));
221 ND_PRINT(", Sector Count: %u", GET_U_1(cp));
225 ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp) & 0xF0) >> 4,
226 tok2str(aoev1_ccmd_str, "Unknown (0x02x)", GET_U_1(cp) & 0x0F));
229 /* Config String Length */
230 cslen = GET_BE_U_2(cp);
233 if (cslen > AOEV1_MAX_CONFSTR_LEN || cslen > len)
237 ND_PRINT("\n\tConfig String (length %u): ", cslen);
238 (void)nd_printn(ndo, cp, cslen, NULL);
243 nd_print_invalid(ndo);
244 ND_TCHECK_LEN(cp, len);
248 aoev1_mac_print(netdissect_options *ndo,
249 const u_char *cp, u_int len)
253 if (len < AOEV1_MAC_ARG_LEN)
259 ND_PRINT("\n\tMCmd: %s",
260 tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
264 ND_PRINT(", MError: %s",
265 tok2str(aoev1_merror_str, "Unknown (0x%02x)", GET_U_1(cp)));
269 dircount = GET_U_1(cp);
272 ND_PRINT(", Dir Count: %u", dircount);
273 if (dircount * 8U > len)
276 for (i = 0; i < dircount; i++) {
281 ND_PRINT("\n\t DCmd: %s",
282 tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
285 /* Ethernet Address */
286 ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp));
293 nd_print_invalid(ndo);
294 ND_TCHECK_LEN(cp, len);
298 aoev1_reserve_print(netdissect_options *ndo,
299 const u_char *cp, u_int len)
303 if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % MAC_ADDR_LEN)
306 ND_PRINT("\n\tRCmd: %s",
307 tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
310 /* NMacs (correlated with the length) */
314 ND_PRINT(", NMacs: %u", nmacs);
315 if (nmacs * MAC_ADDR_LEN != len)
318 for (i = 0; i < nmacs; i++) {
319 ND_PRINT("\n\tEthernet Address %u: %s", i, GET_ETHERADDR_STRING(cp));
326 nd_print_invalid(ndo);
327 ND_TCHECK_LEN(cp, len);
330 /* cp points to the Ver/Flags octet */
332 aoev1_print(netdissect_options *ndo,
333 const u_char *cp, u_int len)
335 uint8_t flags, command;
336 void (*cmd_decoder)(netdissect_options *, const u_char *, u_int);
338 if (len < AOEV1_COMMON_HDR_LEN)
341 flags = GET_U_1(cp) & 0x0F;
342 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags));
345 if (! ndo->ndo_vflag)
348 if (flags & AOEV1_FLAG_E)
349 ND_PRINT("\n\tError: %s",
350 tok2str(aoev1_errcode_str, "Invalid (%u)", GET_U_1(cp)));
354 ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp));
358 ND_PRINT(", Minor: 0x%02x", GET_U_1(cp));
362 command = GET_U_1(cp);
365 ND_PRINT(", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command));
367 ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp));
372 command == AOEV1_CMD_ISSUE_ATA_COMMAND ? aoev1_issue_print :
373 command == AOEV1_CMD_QUERY_CONFIG_INFORMATION ? aoev1_query_print :
374 command == AOEV1_CMD_MAC_MASK_LIST ? aoev1_mac_print :
375 command == AOEV1_CMD_RESERVE_RELEASE ? aoev1_reserve_print :
377 if (cmd_decoder != NULL)
378 cmd_decoder(ndo, cp, len);
382 nd_print_invalid(ndo);
383 ND_TCHECK_LEN(cp, len);
387 aoe_print(netdissect_options *ndo,
388 const u_char *cp, const u_int len)
392 ndo->ndo_protocol = "aoe";
393 ND_PRINT("AoE length %u", len);
398 ver = (GET_U_1(cp) & 0xF0) >> 4;
399 /* Don't advance cp yet: low order 4 bits are version-specific. */
400 ND_PRINT(", Ver %u", ver);
404 aoev1_print(ndo, cp, len);
410 nd_print_invalid(ndo);
411 ND_TCHECK_LEN(cp, len);