]> The Tcpdump Group git mirrors - tcpdump/blob - print-aoe.c
OpenFlow: Add an overshoot guard back.
[tcpdump] / print-aoe.c
1 /*
2 * 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
28 /* \summary: ATA over Ethernet (AoE) protocol printer */
29
30 /* specification:
31 * https://web.archive.org/web/20161025044402/http://brantleycoilecompany.com/AoEr11.pdf
32 */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37
38 #include "netdissect-stdinc.h"
39
40 #include "netdissect.h"
41 #include "extract.h"
42 #include "addrtoname.h"
43
44
45 #define AOE_V1 1
46 #define ATA_SECTOR_SIZE 512
47
48 #define AOEV1_CMD_ISSUE_ATA_COMMAND 0
49 #define AOEV1_CMD_QUERY_CONFIG_INFORMATION 1
50 #define AOEV1_CMD_MAC_MASK_LIST 2
51 #define AOEV1_CMD_RESERVE_RELEASE 3
52
53 static const struct tok cmdcode_str[] = {
54 { AOEV1_CMD_ISSUE_ATA_COMMAND, "Issue ATA Command" },
55 { AOEV1_CMD_QUERY_CONFIG_INFORMATION, "Query Config Information" },
56 { AOEV1_CMD_MAC_MASK_LIST, "MAC Mask List" },
57 { AOEV1_CMD_RESERVE_RELEASE, "Reserve/Release" },
58 { 0, NULL }
59 };
60
61 #define AOEV1_COMMON_HDR_LEN 10U /* up to but w/o Arg */
62 #define AOEV1_ISSUE_ARG_LEN 12U /* up to but w/o Data */
63 #define AOEV1_QUERY_ARG_LEN 8U /* up to but w/o Config String */
64 #define AOEV1_MAC_ARG_LEN 4U /* up to but w/o Directive 0 */
65 #define AOEV1_RESERVE_ARG_LEN 2U /* up to but w/o Ethernet address 0 */
66 #define AOEV1_MAX_CONFSTR_LEN 1024U
67
68 #define AOEV1_FLAG_R 0x08
69 #define AOEV1_FLAG_E 0x04
70
71 static const struct tok aoev1_flag_str[] = {
72 { AOEV1_FLAG_R, "Response" },
73 { AOEV1_FLAG_E, "Error" },
74 { 0x02, "MBZ-0x02" },
75 { 0x01, "MBZ-0x01" },
76 { 0, NULL }
77 };
78
79 static const struct tok aoev1_errcode_str[] = {
80 { 1, "Unrecognized command code" },
81 { 2, "Bad argument parameter" },
82 { 3, "Device unavailable" },
83 { 4, "Config string present" },
84 { 5, "Unsupported version" },
85 { 6, "Target is reserved" },
86 { 0, NULL }
87 };
88
89 #define AOEV1_AFLAG_E 0x40
90 #define AOEV1_AFLAG_D 0x10
91 #define AOEV1_AFLAG_A 0x02
92 #define AOEV1_AFLAG_W 0x01
93
94 static const struct tok aoev1_aflag_str[] = {
95 { 0x08, "MBZ-0x08" },
96 { AOEV1_AFLAG_E, "Ext48" },
97 { 0x06, "MBZ-0x06" },
98 { AOEV1_AFLAG_D, "Device" },
99 { 0x04, "MBZ-0x04" },
100 { 0x03, "MBZ-0x03" },
101 { AOEV1_AFLAG_A, "Async" },
102 { AOEV1_AFLAG_W, "Write" },
103 { 0, NULL }
104 };
105
106 static const struct tok aoev1_ccmd_str[] = {
107 { 0, "read config string" },
108 { 1, "test config string" },
109 { 2, "test config string prefix" },
110 { 3, "set config string" },
111 { 4, "force set config string" },
112 { 0, NULL }
113 };
114
115 static const struct tok aoev1_mcmd_str[] = {
116 { 0, "Read Mac Mask List" },
117 { 1, "Edit Mac Mask List" },
118 { 0, NULL }
119 };
120
121 static const struct tok aoev1_merror_str[] = {
122 { 1, "Unspecified Error" },
123 { 2, "Bad DCmd directive" },
124 { 3, "Mask list full" },
125 { 0, NULL }
126 };
127
128 static const struct tok aoev1_dcmd_str[] = {
129 { 0, "No Directive" },
130 { 1, "Add mac address to mask list" },
131 { 2, "Delete mac address from mask list" },
132 { 0, NULL }
133 };
134
135 static const struct tok aoev1_rcmd_str[] = {
136 { 0, "Read reserve list" },
137 { 1, "Set reserve list" },
138 { 2, "Force set reserve list" },
139 { 0, NULL }
140 };
141
142 static void
143 aoev1_issue_print(netdissect_options *ndo,
144 const u_char *cp, u_int len)
145 {
146 if (len < AOEV1_ISSUE_ARG_LEN)
147 goto invalid;
148 /* AFlags */
149 ND_PRINT("\n\tAFlags: [%s]",
150 bittok2str(aoev1_aflag_str, "none", GET_U_1(cp)));
151 cp += 1;
152 len -= 1;
153 /* Err/Feature */
154 ND_PRINT(", Err/Feature: %u", GET_U_1(cp));
155 cp += 1;
156 len -= 1;
157 /* Sector Count (not correlated with the length) */
158 ND_PRINT(", Sector Count: %u", GET_U_1(cp));
159 cp += 1;
160 len -= 1;
161 /* Cmd/Status */
162 ND_PRINT(", Cmd/Status: %u", GET_U_1(cp));
163 cp += 1;
164 len -= 1;
165 /* lba0 */
166 ND_PRINT("\n\tlba0: %u", GET_U_1(cp));
167 cp += 1;
168 len -= 1;
169 /* lba1 */
170 ND_PRINT(", lba1: %u", GET_U_1(cp));
171 cp += 1;
172 len -= 1;
173 /* lba2 */
174 ND_PRINT(", lba2: %u", GET_U_1(cp));
175 cp += 1;
176 len -= 1;
177 /* lba3 */
178 ND_PRINT(", lba3: %u", GET_U_1(cp));
179 cp += 1;
180 len -= 1;
181 /* lba4 */
182 ND_PRINT(", lba4: %u", GET_U_1(cp));
183 cp += 1;
184 len -= 1;
185 /* lba5 */
186 ND_PRINT(", lba5: %u", GET_U_1(cp));
187 cp += 1;
188 len -= 1;
189 /* Reserved */
190 ND_TCHECK_2(cp);
191 cp += 2;
192 len -= 2;
193 /* Data */
194 if (len)
195 ND_PRINT("\n\tData: %u bytes", len);
196 return;
197
198 invalid:
199 nd_print_invalid(ndo);
200 ND_TCHECK_LEN(cp, len);
201 return;
202 trunc:
203 nd_trunc(ndo);
204 }
205
206 static void
207 aoev1_query_print(netdissect_options *ndo,
208 const u_char *cp, u_int len)
209 {
210 uint16_t cslen;
211
212 if (len < AOEV1_QUERY_ARG_LEN)
213 goto invalid;
214 /* Buffer Count */
215 ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp));
216 cp += 2;
217 len -= 2;
218 /* Firmware Version */
219 ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp));
220 cp += 2;
221 len -= 2;
222 /* Sector Count */
223 ND_PRINT(", Sector Count: %u", GET_U_1(cp));
224 cp += 1;
225 len -= 1;
226 /* AoE/CCmd */
227 ND_PRINT(", AoE: %u, CCmd: %s", (GET_U_1(cp) & 0xF0) >> 4,
228 tok2str(aoev1_ccmd_str, "Unknown (0x02x)", GET_U_1(cp) & 0x0F));
229 cp += 1;
230 len -= 1;
231 /* Config String Length */
232 cslen = GET_BE_U_2(cp);
233 cp += 2;
234 len -= 2;
235 if (cslen > AOEV1_MAX_CONFSTR_LEN || cslen > len)
236 goto invalid;
237 /* Config String */
238 if (cslen) {
239 ND_PRINT("\n\tConfig String (length %u): ", cslen);
240 (void)nd_printn(ndo, cp, cslen, NULL);
241 }
242 return;
243
244 invalid:
245 nd_print_invalid(ndo);
246 ND_TCHECK_LEN(cp, len);
247 return;
248 trunc:
249 nd_trunc(ndo);
250 }
251
252 static void
253 aoev1_mac_print(netdissect_options *ndo,
254 const u_char *cp, u_int len)
255 {
256 uint8_t dircount, i;
257
258 if (len < AOEV1_MAC_ARG_LEN)
259 goto invalid;
260 /* Reserved */
261 cp += 1;
262 len -= 1;
263 /* MCmd */
264 ND_PRINT("\n\tMCmd: %s",
265 tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
266 cp += 1;
267 len -= 1;
268 /* MError */
269 ND_PRINT(", MError: %s",
270 tok2str(aoev1_merror_str, "Unknown (0x%02x)", GET_U_1(cp)));
271 cp += 1;
272 len -= 1;
273 /* Dir Count */
274 dircount = GET_U_1(cp);
275 cp += 1;
276 len -= 1;
277 ND_PRINT(", Dir Count: %u", dircount);
278 if (dircount * 8 > len)
279 goto invalid;
280 /* directives */
281 for (i = 0; i < dircount; i++) {
282 /* Reserved */
283 cp += 1;
284 len -= 1;
285 /* DCmd */
286 ND_PRINT("\n\t DCmd: %s",
287 tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
288 cp += 1;
289 len -= 1;
290 /* Ethernet Address */
291 ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp));
292 cp += MAC_ADDR_LEN;
293 len -= MAC_ADDR_LEN;
294 }
295 return;
296
297 invalid:
298 nd_print_invalid(ndo);
299 ND_TCHECK_LEN(cp, len);
300 return;
301 trunc:
302 nd_trunc(ndo);
303 }
304
305 static void
306 aoev1_reserve_print(netdissect_options *ndo,
307 const u_char *cp, u_int len)
308 {
309 uint8_t nmacs, i;
310
311 if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % MAC_ADDR_LEN)
312 goto invalid;
313 /* RCmd */
314 ND_PRINT("\n\tRCmd: %s",
315 tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", GET_U_1(cp)));
316 cp += 1;
317 len -= 1;
318 /* NMacs (correlated with the length) */
319 nmacs = GET_U_1(cp);
320 cp += 1;
321 len -= 1;
322 ND_PRINT(", NMacs: %u", nmacs);
323 if (nmacs * MAC_ADDR_LEN != len)
324 goto invalid;
325 /* addresses */
326 for (i = 0; i < nmacs; i++) {
327 ND_PRINT("\n\tEthernet Address %u: %s", i, GET_ETHERADDR_STRING(cp));
328 cp += MAC_ADDR_LEN;
329 len -= MAC_ADDR_LEN;
330 }
331 return;
332
333 invalid:
334 nd_print_invalid(ndo);
335 ND_TCHECK_LEN(cp, len);
336 return;
337 trunc:
338 nd_trunc(ndo);
339 }
340
341 /* cp points to the Ver/Flags octet */
342 static void
343 aoev1_print(netdissect_options *ndo,
344 const u_char *cp, u_int len)
345 {
346 uint8_t flags, command;
347 void (*cmd_decoder)(netdissect_options *, const u_char *, u_int);
348
349 if (len < AOEV1_COMMON_HDR_LEN)
350 goto invalid;
351 /* Flags */
352 flags = GET_U_1(cp) & 0x0F;
353 ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags));
354 cp += 1;
355 len -= 1;
356 if (! ndo->ndo_vflag)
357 return;
358 /* Error */
359 if (flags & AOEV1_FLAG_E)
360 ND_PRINT("\n\tError: %s",
361 tok2str(aoev1_errcode_str, "Invalid (%u)", GET_U_1(cp)));
362 cp += 1;
363 len -= 1;
364 /* Major */
365 ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp));
366 cp += 2;
367 len -= 2;
368 /* Minor */
369 ND_PRINT(", Minor: 0x%02x", GET_U_1(cp));
370 cp += 1;
371 len -= 1;
372 /* Command */
373 command = GET_U_1(cp);
374 cp += 1;
375 len -= 1;
376 ND_PRINT(", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command));
377 /* Tag */
378 ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp));
379 cp += 4;
380 len -= 4;
381 /* Arg */
382 cmd_decoder =
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 :
387 NULL;
388 if (cmd_decoder != NULL)
389 cmd_decoder(ndo, cp, len);
390 return;
391
392 invalid:
393 nd_print_invalid(ndo);
394 ND_TCHECK_LEN(cp, len);
395 return;
396 trunc:
397 nd_trunc(ndo);
398 }
399
400 void
401 aoe_print(netdissect_options *ndo,
402 const u_char *cp, const u_int len)
403 {
404 uint8_t ver;
405
406 ndo->ndo_protocol = "aoe";
407 ND_PRINT("AoE length %u", len);
408
409 if (len < 1)
410 goto invalid;
411 /* Ver/Flags */
412 ver = (GET_U_1(cp) & 0xF0) >> 4;
413 /* Don't advance cp yet: low order 4 bits are version-specific. */
414 ND_PRINT(", Ver %u", ver);
415
416 switch (ver) {
417 case AOE_V1:
418 aoev1_print(ndo, cp, len);
419 break;
420 }
421 return;
422
423 invalid:
424 nd_print_invalid(ndo);
425 ND_TCHECK_LEN(cp, len);
426 return;
427 trunc:
428 nd_trunc(ndo);
429 }
430