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 #include <sys/cdefs.h>
34 __RCSID("$NetBSD: print-aoe.c,v 1.2 2014/11/20 03:05:03 christos Exp $");
37 #define NETDISSECT_REWORKED
42 #include <tcpdump-stdinc.h>
44 #include "interface.h"
46 #include "addrtoname.h"
49 static const char tstr
[] = " [|aoe]";
50 static const char cstr
[] = " (corrupt)";
53 #define ATA_SECTOR_SIZE 512
55 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0
56 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1
57 #define AOEV1_CMD_MAC_MASK_LIST 2
58 #define AOEV1_CMD_RESERVE_RELEASE 3
60 static const struct tok cmdcode_str
[] = {
61 { AOEV1_CMD_ISSUE_ATA_COMMAND
, "Issue ATA Command" },
62 { AOEV1_CMD_QUERY_CONFIG_INFORMATION
, "Query Config Information" },
63 { AOEV1_CMD_MAC_MASK_LIST
, "MAC Mask List" },
64 { AOEV1_CMD_RESERVE_RELEASE
, "Reserve/Release" },
68 #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */
69 #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */
70 #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */
71 #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */
72 #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */
73 #define AOEV1_MAX_CONFSTR_LEN 1024U
75 #define AOEV1_FLAG_R 0x08
76 #define AOEV1_FLAG_E 0x04
78 static const struct tok aoev1_flag_str
[] = {
79 { AOEV1_FLAG_R
, "Response" },
80 { AOEV1_FLAG_E
, "Error" },
86 static const struct tok aoev1_errcode_str
[] = {
87 { 1, "Unrecognized command code" },
88 { 2, "Bad argument parameter" },
89 { 3, "Device unavailable" },
90 { 4, "Config string present" },
91 { 5, "Unsupported version" },
92 { 6, "Target is reserved" },
96 #define AOEV1_AFLAG_E 0x40
97 #define AOEV1_AFLAG_D 0x10
98 #define AOEV1_AFLAG_A 0x02
99 #define AOEV1_AFLAG_W 0x01
101 static const struct tok aoev1_aflag_str
[] = {
102 { 0x08, "MBZ-0x08" },
103 { AOEV1_AFLAG_E
, "Ext48" },
104 { 0x06, "MBZ-0x06" },
105 { AOEV1_AFLAG_D
, "Device" },
106 { 0x04, "MBZ-0x04" },
107 { 0x03, "MBZ-0x03" },
108 { AOEV1_AFLAG_A
, "Async" },
109 { AOEV1_AFLAG_W
, "Write" },
113 static const struct tok aoev1_ccmd_str
[] = {
114 { 0, "read config string" },
115 { 1, "test config string" },
116 { 2, "test config string prefix" },
117 { 3, "set config string" },
118 { 4, "force set config string" },
122 static const struct tok aoev1_mcmd_str
[] = {
123 { 0, "Read Mac Mask List" },
124 { 1, "Edit Mac Mask List" },
128 static const struct tok aoev1_merror_str
[] = {
129 { 1, "Unspecified Error" },
130 { 2, "Bad DCmd directive" },
131 { 3, "Mask list full" },
135 static const struct tok aoev1_dcmd_str
[] = {
136 { 0, "No Directive" },
137 { 1, "Add mac address to mask list" },
138 { 2, "Delete mac address from mask list" },
142 static const struct tok aoev1_rcmd_str
[] = {
143 { 0, "Read reserve list" },
144 { 1, "Set reserve list" },
145 { 2, "Force set reserve list" },
150 aoev1_issue_print(netdissect_options
*ndo
,
151 const u_char
*cp
, const u_int len
)
153 const u_char
*ep
= cp
+ len
;
155 if (len
< AOEV1_ISSUE_ARG_LEN
)
159 ND_PRINT((ndo
, "\n\tAFlags: [%s]", bittok2str(aoev1_aflag_str
, "none", *cp
)));
163 ND_PRINT((ndo
, ", Err/Feature: %u", *cp
));
165 /* Sector Count (not correlated with the length) */
167 ND_PRINT((ndo
, ", Sector Count: %u", *cp
));
171 ND_PRINT((ndo
, ", Cmd/Status: %u", *cp
));
175 ND_PRINT((ndo
, "\n\tlba0: %u", *cp
));
179 ND_PRINT((ndo
, ", lba1: %u", *cp
));
183 ND_PRINT((ndo
, ", lba2: %u", *cp
));
187 ND_PRINT((ndo
, ", lba3: %u", *cp
));
191 ND_PRINT((ndo
, ", lba4: %u", *cp
));
195 ND_PRINT((ndo
, ", lba5: %u", *cp
));
201 if (len
> AOEV1_ISSUE_ARG_LEN
)
202 ND_PRINT((ndo
, "\n\tData: %u bytes", len
- AOEV1_ISSUE_ARG_LEN
));
206 ND_PRINT((ndo
, "%s", cstr
));
207 ND_TCHECK2(*cp
, ep
- cp
);
210 ND_PRINT((ndo
, "%s", tstr
));
214 aoev1_query_print(netdissect_options
*ndo
,
215 const u_char
*cp
, const u_int len
)
217 const u_char
*ep
= cp
+ len
;
220 if (len
< AOEV1_QUERY_ARG_LEN
)
224 ND_PRINT((ndo
, "\n\tBuffer Count: %u", EXTRACT_16BITS(cp
)));
226 /* Firmware Version */
228 ND_PRINT((ndo
, ", Firmware Version: %u", EXTRACT_16BITS(cp
)));
232 ND_PRINT((ndo
, ", Sector Count: %u", *cp
));
236 ND_PRINT((ndo
, ", AoE: %u, CCmd: %s", (*cp
& 0xF0) >> 4,
237 tok2str(aoev1_ccmd_str
, "Unknown (0x02x)", *cp
& 0x0F)));
239 /* Config String Length */
241 cslen
= EXTRACT_16BITS(cp
);
243 if (cslen
> AOEV1_MAX_CONFSTR_LEN
|| AOEV1_QUERY_ARG_LEN
+ cslen
> len
)
246 ND_TCHECK2(*cp
, cslen
);
248 ND_PRINT((ndo
, "\n\tConfig String (length %u): ", cslen
));
249 if (fn_printn(ndo
, cp
, cslen
, ndo
->ndo_snapend
))
255 ND_PRINT((ndo
, "%s", cstr
));
256 ND_TCHECK2(*cp
, ep
- cp
);
259 ND_PRINT((ndo
, "%s", tstr
));
263 aoev1_mac_print(netdissect_options
*ndo
,
264 const u_char
*cp
, const u_int len
)
266 const u_char
*ep
= cp
+ len
;
269 if (len
< AOEV1_MAC_ARG_LEN
)
276 ND_PRINT((ndo
, "\n\tMCmd: %s", tok2str(aoev1_mcmd_str
, "Unknown (0x%02x)", *cp
)));
280 ND_PRINT((ndo
, ", MError: %s", tok2str(aoev1_merror_str
, "Unknown (0x%02x)", *cp
)));
286 ND_PRINT((ndo
, ", Dir Count: %u", dircount
));
287 if (AOEV1_MAC_ARG_LEN
+ dircount
* 8 > len
)
290 for (i
= 0; i
< dircount
; i
++) {
296 ND_PRINT((ndo
, "\n\t DCmd: %s", tok2str(aoev1_dcmd_str
, "Unknown (0x%02x)", *cp
)));
298 /* Ethernet Address */
299 ND_TCHECK2(*cp
, ETHER_ADDR_LEN
);
300 ND_PRINT((ndo
, ", Ethernet Address: %s", etheraddr_string(ndo
, cp
)));
301 cp
+= ETHER_ADDR_LEN
;
306 ND_PRINT((ndo
, "%s", cstr
));
307 ND_TCHECK2(*cp
, ep
- cp
);
310 ND_PRINT((ndo
, "%s", tstr
));
314 aoev1_reserve_print(netdissect_options
*ndo
,
315 const u_char
*cp
, const u_int len
)
317 const u_char
*ep
= cp
+ len
;
320 if (len
< AOEV1_RESERVE_ARG_LEN
|| (len
- AOEV1_RESERVE_ARG_LEN
) % ETHER_ADDR_LEN
)
324 ND_PRINT((ndo
, "\n\tRCmd: %s", tok2str(aoev1_rcmd_str
, "Unknown (0x%02x)", *cp
)));
326 /* NMacs (correlated with the length) */
330 ND_PRINT((ndo
, ", NMacs: %u", nmacs
));
331 if (AOEV1_RESERVE_ARG_LEN
+ nmacs
* ETHER_ADDR_LEN
!= len
)
334 for (i
= 0; i
< nmacs
; i
++) {
335 ND_PRINT((ndo
, "\n\tEthernet Address %u: %s", i
, etheraddr_string(ndo
, cp
)));
336 cp
+= ETHER_ADDR_LEN
;
341 ND_PRINT((ndo
, "%s", cstr
));
342 ND_TCHECK2(*cp
, ep
- cp
);
345 ND_PRINT((ndo
, "%s", tstr
));
348 /* cp points to the Ver/Flags octet */
350 aoev1_print(netdissect_options
*ndo
,
351 const u_char
*cp
, const u_int len
)
353 const u_char
*ep
= cp
+ len
;
354 uint8_t flags
, command
;
355 void (*cmd_decoder
)(netdissect_options
*, const u_char
*, const u_int
);
357 if (len
< AOEV1_COMMON_HDR_LEN
)
361 ND_PRINT((ndo
, ", Flags: [%s]", bittok2str(aoev1_flag_str
, "none", flags
)));
363 if (! ndo
->ndo_vflag
)
367 if (flags
& AOEV1_FLAG_E
)
368 ND_PRINT((ndo
, "\n\tError: %s", tok2str(aoev1_errcode_str
, "Invalid (%u)", *cp
)));
372 ND_PRINT((ndo
, "\n\tMajor: 0x%04x", EXTRACT_16BITS(cp
)));
376 ND_PRINT((ndo
, ", Minor: 0x%02x", *cp
));
382 ND_PRINT((ndo
, ", Command: %s", tok2str(cmdcode_str
, "Unknown (0x%02x)", command
)));
385 ND_PRINT((ndo
, ", Tag: 0x%08x", EXTRACT_32BITS(cp
)));
389 command
== AOEV1_CMD_ISSUE_ATA_COMMAND
? aoev1_issue_print
:
390 command
== AOEV1_CMD_QUERY_CONFIG_INFORMATION
? aoev1_query_print
:
391 command
== AOEV1_CMD_MAC_MASK_LIST
? aoev1_mac_print
:
392 command
== AOEV1_CMD_RESERVE_RELEASE
? aoev1_reserve_print
:
394 if (cmd_decoder
!= NULL
)
395 cmd_decoder(ndo
, cp
, len
- AOEV1_COMMON_HDR_LEN
);
399 ND_PRINT((ndo
, "%s", cstr
));
400 ND_TCHECK2(*cp
, ep
- cp
);
403 ND_PRINT((ndo
, "%s", tstr
));
407 aoe_print(netdissect_options
*ndo
,
408 const u_char
*cp
, const u_int len
)
410 const u_char
*ep
= cp
+ len
;
413 ND_PRINT((ndo
, "AoE length %u", len
));
419 ver
= (*cp
& 0xF0) >> 4;
420 /* Don't advance cp yet: low order 4 bits are version-specific. */
421 ND_PRINT((ndo
, ", Ver %u", ver
));
425 aoev1_print(ndo
, cp
, len
);
431 ND_PRINT((ndo
, "%s", cstr
));
432 ND_TCHECK2(*cp
, ep
- cp
);
435 ND_PRINT((ndo
, "%s", tstr
));