blob: 0cd4299a7a6bf7b6ae205f0692b3727899c12ac7 [file] [log] [blame]
Elliott Hughes892a68b2015-10-19 14:43:53 -07001/*
Elliott Hughes892a68b2015-10-19 14:43:53 -07002 * Copyright (c) 2014 The TCPDUMP project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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.
26 */
27
Elliott Hughese2e3bd12017-05-15 10:59:29 -070028/* \summary: ATA over Ethernet (AoE) protocol printer */
29
Elliott Hughes820eced2021-08-20 18:00:50 -070030/* specification:
31 * https://web.archive.org/web/20161025044402/http://brantleycoilecompany.com/AoEr11.pdf
32 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -070033
Elliott Hughes892a68b2015-10-19 14:43:53 -070034#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070035#include <config.h>
Elliott Hughes892a68b2015-10-19 14:43:53 -070036#endif
37
Elliott Hughes820eced2021-08-20 18:00:50 -070038#include "netdissect-stdinc.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070039
Elliott Hughes820eced2021-08-20 18:00:50 -070040#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070041#include "netdissect.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070042#include "extract.h"
43#include "addrtoname.h"
Elliott Hughes892a68b2015-10-19 14:43:53 -070044
Elliott Hughes892a68b2015-10-19 14:43:53 -070045
46#define AOE_V1 1
47#define ATA_SECTOR_SIZE 512
48
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
53
54static 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" },
59 { 0, NULL }
60};
61
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
68
69#define AOEV1_FLAG_R 0x08
70#define AOEV1_FLAG_E 0x04
71
72static const struct tok aoev1_flag_str[] = {
73 { AOEV1_FLAG_R, "Response" },
74 { AOEV1_FLAG_E, "Error" },
Elliott Hughes820eced2021-08-20 18:00:50 -070075 { 0x02, "MBZ-1" },
76 { 0x01, "MBZ-0" },
Elliott Hughes892a68b2015-10-19 14:43:53 -070077 { 0, NULL }
78};
79
80static 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" },
87 { 0, NULL }
88};
89
90#define AOEV1_AFLAG_E 0x40
91#define AOEV1_AFLAG_D 0x10
92#define AOEV1_AFLAG_A 0x02
93#define AOEV1_AFLAG_W 0x01
94
Elliott Hughes820eced2021-08-20 18:00:50 -070095static const struct tok aoev1_aflag_bitmap_str[] = {
96 { 0x80, "MBZ-7" },
Elliott Hughes892a68b2015-10-19 14:43:53 -070097 { AOEV1_AFLAG_E, "Ext48" },
Elliott Hughes820eced2021-08-20 18:00:50 -070098 { 0x20, "MBZ-5" },
Elliott Hughes892a68b2015-10-19 14:43:53 -070099 { AOEV1_AFLAG_D, "Device" },
Elliott Hughes820eced2021-08-20 18:00:50 -0700100 { 0x08, "MBZ-3" },
101 { 0x04, "MBZ-2" },
Elliott Hughes892a68b2015-10-19 14:43:53 -0700102 { AOEV1_AFLAG_A, "Async" },
103 { AOEV1_AFLAG_W, "Write" },
104 { 0, NULL }
105};
106
107static 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" },
113 { 0, NULL }
114};
115
116static const struct tok aoev1_mcmd_str[] = {
117 { 0, "Read Mac Mask List" },
118 { 1, "Edit Mac Mask List" },
119 { 0, NULL }
120};
121
122static const struct tok aoev1_merror_str[] = {
123 { 1, "Unspecified Error" },
124 { 2, "Bad DCmd directive" },
125 { 3, "Mask list full" },
126 { 0, NULL }
127};
128
129static 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" },
133 { 0, NULL }
134};
135
136static const struct tok aoev1_rcmd_str[] = {
137 { 0, "Read reserve list" },
138 { 1, "Set reserve list" },
139 { 2, "Force set reserve list" },
140 { 0, NULL }
141};
142
143static void
144aoev1_issue_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700145 const u_char *cp, u_int len)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700146{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700147 if (len < AOEV1_ISSUE_ARG_LEN)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700148 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700149 /* AFlags */
Elliott Hughes820eced2021-08-20 18:00:50 -0700150 ND_PRINT("\n\tAFlags: [%s]",
151 bittok2str(aoev1_aflag_bitmap_str, "none", GET_U_1(cp)));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700152 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700153 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700154 /* Err/Feature */
Elliott Hughes820eced2021-08-20 18:00:50 -0700155 ND_PRINT(", Err/Feature: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700156 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700157 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700158 /* Sector Count (not correlated with the length) */
Elliott Hughes820eced2021-08-20 18:00:50 -0700159 ND_PRINT(", Sector Count: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700160 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700161 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700162 /* Cmd/Status */
Elliott Hughes820eced2021-08-20 18:00:50 -0700163 ND_PRINT(", Cmd/Status: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700164 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700165 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700166 /* lba0 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700167 ND_PRINT("\n\tlba0: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700168 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700169 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700170 /* lba1 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700171 ND_PRINT(", lba1: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700172 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700173 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700174 /* lba2 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700175 ND_PRINT(", lba2: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700176 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700177 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700178 /* lba3 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700179 ND_PRINT(", lba3: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700180 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700181 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700182 /* lba4 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700183 ND_PRINT(", lba4: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700184 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700185 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700186 /* lba5 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700187 ND_PRINT(", lba5: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700188 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700189 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700190 /* Reserved */
Elliott Hughes820eced2021-08-20 18:00:50 -0700191 ND_TCHECK_2(cp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700192 cp += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700193 len -= 2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700194 /* Data */
Elliott Hughes820eced2021-08-20 18:00:50 -0700195 if (len)
196 ND_PRINT("\n\tData: %u bytes", len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700197 return;
198
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700199invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700200 nd_print_invalid(ndo);
201 ND_TCHECK_LEN(cp, len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700202}
203
204static void
205aoev1_query_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700206 const u_char *cp, u_int len)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700207{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700208 uint16_t cslen;
209
210 if (len < AOEV1_QUERY_ARG_LEN)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700211 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700212 /* Buffer Count */
Elliott Hughes820eced2021-08-20 18:00:50 -0700213 ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700214 cp += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700215 len -= 2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700216 /* Firmware Version */
Elliott Hughes820eced2021-08-20 18:00:50 -0700217 ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700218 cp += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700219 len -= 2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700220 /* Sector Count */
Elliott Hughes820eced2021-08-20 18:00:50 -0700221 ND_PRINT(", Sector Count: %u", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700222 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700223 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700224 /* AoE/CCmd */
Elliott Hughes820eced2021-08-20 18:00:50 -0700225 ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp) & 0xF0) >> 4,
226 tok2str(aoev1_ccmd_str, "Unknown (0x02x)", GET_U_1(cp) & 0x0F));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700227 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700228 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700229 /* Config String Length */
Elliott Hughes820eced2021-08-20 18:00:50 -0700230 cslen = GET_BE_U_2(cp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700231 cp += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700232 len -= 2;
233 if (cslen > AOEV1_MAX_CONFSTR_LEN || cslen > len)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700234 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700235 /* Config String */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700236 if (cslen) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700237 ND_PRINT("\n\tConfig String (length %u): ", cslen);
238 (void)nd_printn(ndo, cp, cslen, NULL);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700239 }
240 return;
241
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700242invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700243 nd_print_invalid(ndo);
244 ND_TCHECK_LEN(cp, len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700245}
246
247static void
248aoev1_mac_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700249 const u_char *cp, u_int len)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700250{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700251 uint8_t dircount, i;
252
253 if (len < AOEV1_MAC_ARG_LEN)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700254 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700255 /* Reserved */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700256 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700257 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700258 /* MCmd */
Elliott Hughes820eced2021-08-20 18:00:50 -0700259 ND_PRINT("\n\tMCmd: %s",
260 tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700261 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700262 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700263 /* MError */
Elliott Hughes820eced2021-08-20 18:00:50 -0700264 ND_PRINT(", MError: %s",
265 tok2str(aoev1_merror_str, "Unknown (0x%02x)", GET_U_1(cp)));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700266 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700267 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700268 /* Dir Count */
Elliott Hughes820eced2021-08-20 18:00:50 -0700269 dircount = GET_U_1(cp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700270 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700271 len -= 1;
272 ND_PRINT(", Dir Count: %u", dircount);
273 if (dircount * 8U > len)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700274 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700275 /* directives */
276 for (i = 0; i < dircount; i++) {
277 /* Reserved */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700278 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700279 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700280 /* DCmd */
Elliott Hughes820eced2021-08-20 18:00:50 -0700281 ND_PRINT("\n\t DCmd: %s",
282 tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700283 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700284 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700285 /* Ethernet Address */
Elliott Hughes820eced2021-08-20 18:00:50 -0700286 ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp));
287 cp += MAC_ADDR_LEN;
288 len -= MAC_ADDR_LEN;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700289 }
290 return;
291
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700292invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700293 nd_print_invalid(ndo);
294 ND_TCHECK_LEN(cp, len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700295}
296
297static void
298aoev1_reserve_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700299 const u_char *cp, u_int len)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700300{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700301 uint8_t nmacs, i;
302
Elliott Hughes820eced2021-08-20 18:00:50 -0700303 if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % MAC_ADDR_LEN)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700304 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700305 /* RCmd */
Elliott Hughes820eced2021-08-20 18:00:50 -0700306 ND_PRINT("\n\tRCmd: %s",
307 tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700308 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700309 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700310 /* NMacs (correlated with the length) */
Elliott Hughes820eced2021-08-20 18:00:50 -0700311 nmacs = GET_U_1(cp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700312 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700313 len -= 1;
314 ND_PRINT(", NMacs: %u", nmacs);
315 if (nmacs * MAC_ADDR_LEN != len)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700316 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700317 /* addresses */
318 for (i = 0; i < nmacs; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700319 ND_PRINT("\n\tEthernet Address %u: %s", i, GET_ETHERADDR_STRING(cp));
320 cp += MAC_ADDR_LEN;
321 len -= MAC_ADDR_LEN;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700322 }
323 return;
324
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700325invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700326 nd_print_invalid(ndo);
327 ND_TCHECK_LEN(cp, len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700328}
329
330/* cp points to the Ver/Flags octet */
331static void
332aoev1_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700333 const u_char *cp, u_int len)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700334{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700335 uint8_t flags, command;
Elliott Hughes820eced2021-08-20 18:00:50 -0700336 void (*cmd_decoder)(netdissect_options *, const u_char *, u_int);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700337
338 if (len < AOEV1_COMMON_HDR_LEN)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700339 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700340 /* Flags */
Elliott Hughes820eced2021-08-20 18:00:50 -0700341 flags = GET_U_1(cp) & 0x0F;
342 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700343 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700344 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700345 if (! ndo->ndo_vflag)
346 return;
347 /* Error */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700348 if (flags & AOEV1_FLAG_E)
Elliott Hughes820eced2021-08-20 18:00:50 -0700349 ND_PRINT("\n\tError: %s",
350 tok2str(aoev1_errcode_str, "Invalid (%u)", GET_U_1(cp)));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700351 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700352 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700353 /* Major */
Elliott Hughes820eced2021-08-20 18:00:50 -0700354 ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700355 cp += 2;
Elliott Hughes820eced2021-08-20 18:00:50 -0700356 len -= 2;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700357 /* Minor */
Elliott Hughes820eced2021-08-20 18:00:50 -0700358 ND_PRINT(", Minor: 0x%02x", GET_U_1(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700359 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700360 len -= 1;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700361 /* Command */
Elliott Hughes820eced2021-08-20 18:00:50 -0700362 command = GET_U_1(cp);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700363 cp += 1;
Elliott Hughes820eced2021-08-20 18:00:50 -0700364 len -= 1;
365 ND_PRINT(", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700366 /* Tag */
Elliott Hughes820eced2021-08-20 18:00:50 -0700367 ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700368 cp += 4;
Elliott Hughes820eced2021-08-20 18:00:50 -0700369 len -= 4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700370 /* Arg */
371 cmd_decoder =
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 :
376 NULL;
377 if (cmd_decoder != NULL)
Elliott Hughes820eced2021-08-20 18:00:50 -0700378 cmd_decoder(ndo, cp, len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700379 return;
380
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700381invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700382 nd_print_invalid(ndo);
383 ND_TCHECK_LEN(cp, len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700384}
385
386void
387aoe_print(netdissect_options *ndo,
388 const u_char *cp, const u_int len)
389{
Elliott Hughes892a68b2015-10-19 14:43:53 -0700390 uint8_t ver;
391
Elliott Hughes820eced2021-08-20 18:00:50 -0700392 ndo->ndo_protocol = "aoe";
393 ND_PRINT("AoE length %u", len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700394
395 if (len < 1)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700396 goto invalid;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700397 /* Ver/Flags */
Elliott Hughes820eced2021-08-20 18:00:50 -0700398 ver = (GET_U_1(cp) & 0xF0) >> 4;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700399 /* Don't advance cp yet: low order 4 bits are version-specific. */
Elliott Hughes820eced2021-08-20 18:00:50 -0700400 ND_PRINT(", Ver %u", ver);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700401
402 switch (ver) {
403 case AOE_V1:
404 aoev1_print(ndo, cp, len);
405 break;
406 }
407 return;
408
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700409invalid:
Elliott Hughes820eced2021-08-20 18:00:50 -0700410 nd_print_invalid(ndo);
411 ND_TCHECK_LEN(cp, len);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700412}
413