Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 1 | /* |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 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 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 28 | /* \summary: ATA over Ethernet (AoE) protocol printer */ |
| 29 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 30 | /* specification: |
| 31 | * https://web.archive.org/web/20161025044402/http://brantleycoilecompany.com/AoEr11.pdf |
| 32 | */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 33 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 34 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 35 | #include <config.h> |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 36 | #endif |
| 37 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 38 | #include "netdissect-stdinc.h" |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 39 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 40 | #define ND_LONGJMP_FROM_TCHECK |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 41 | #include "netdissect.h" |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 42 | #include "extract.h" |
| 43 | #include "addrtoname.h" |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 44 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 45 | |
| 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 | |
| 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" }, |
| 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 | |
| 72 | static const struct tok aoev1_flag_str[] = { |
| 73 | { AOEV1_FLAG_R, "Response" }, |
| 74 | { AOEV1_FLAG_E, "Error" }, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 75 | { 0x02, "MBZ-1" }, |
| 76 | { 0x01, "MBZ-0" }, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 77 | { 0, NULL } |
| 78 | }; |
| 79 | |
| 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" }, |
| 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 Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 95 | static const struct tok aoev1_aflag_bitmap_str[] = { |
| 96 | { 0x80, "MBZ-7" }, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 97 | { AOEV1_AFLAG_E, "Ext48" }, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 98 | { 0x20, "MBZ-5" }, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 99 | { AOEV1_AFLAG_D, "Device" }, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 100 | { 0x08, "MBZ-3" }, |
| 101 | { 0x04, "MBZ-2" }, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 102 | { AOEV1_AFLAG_A, "Async" }, |
| 103 | { AOEV1_AFLAG_W, "Write" }, |
| 104 | { 0, NULL } |
| 105 | }; |
| 106 | |
| 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" }, |
| 113 | { 0, NULL } |
| 114 | }; |
| 115 | |
| 116 | static const struct tok aoev1_mcmd_str[] = { |
| 117 | { 0, "Read Mac Mask List" }, |
| 118 | { 1, "Edit Mac Mask List" }, |
| 119 | { 0, NULL } |
| 120 | }; |
| 121 | |
| 122 | static 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 | |
| 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" }, |
| 133 | { 0, NULL } |
| 134 | }; |
| 135 | |
| 136 | static 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 | |
| 143 | static void |
| 144 | aoev1_issue_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 145 | const u_char *cp, u_int len) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 146 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 147 | if (len < AOEV1_ISSUE_ARG_LEN) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 148 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 149 | /* AFlags */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 150 | ND_PRINT("\n\tAFlags: [%s]", |
| 151 | bittok2str(aoev1_aflag_bitmap_str, "none", GET_U_1(cp))); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 152 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 153 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 154 | /* Err/Feature */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 155 | ND_PRINT(", Err/Feature: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 156 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 157 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 158 | /* Sector Count (not correlated with the length) */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 159 | ND_PRINT(", Sector Count: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 160 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 161 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 162 | /* Cmd/Status */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 163 | ND_PRINT(", Cmd/Status: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 164 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 165 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 166 | /* lba0 */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 167 | ND_PRINT("\n\tlba0: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 168 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 169 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 170 | /* lba1 */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 171 | ND_PRINT(", lba1: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 172 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 173 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 174 | /* lba2 */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 175 | ND_PRINT(", lba2: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 176 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 177 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 178 | /* lba3 */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 179 | ND_PRINT(", lba3: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 180 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 181 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 182 | /* lba4 */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 183 | ND_PRINT(", lba4: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 184 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 185 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 186 | /* lba5 */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 187 | ND_PRINT(", lba5: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 188 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 189 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 190 | /* Reserved */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 191 | ND_TCHECK_2(cp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 192 | cp += 2; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 193 | len -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 194 | /* Data */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 195 | if (len) |
| 196 | ND_PRINT("\n\tData: %u bytes", len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 197 | return; |
| 198 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 199 | invalid: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 200 | nd_print_invalid(ndo); |
| 201 | ND_TCHECK_LEN(cp, len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | static void |
| 205 | aoev1_query_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 206 | const u_char *cp, u_int len) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 207 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 208 | uint16_t cslen; |
| 209 | |
| 210 | if (len < AOEV1_QUERY_ARG_LEN) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 211 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 212 | /* Buffer Count */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 213 | ND_PRINT("\n\tBuffer Count: %u", GET_BE_U_2(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 214 | cp += 2; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 215 | len -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 216 | /* Firmware Version */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 217 | ND_PRINT(", Firmware Version: %u", GET_BE_U_2(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 218 | cp += 2; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 219 | len -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 220 | /* Sector Count */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 221 | ND_PRINT(", Sector Count: %u", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 222 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 223 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 224 | /* AoE/CCmd */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 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)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 227 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 228 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 229 | /* Config String Length */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 230 | cslen = GET_BE_U_2(cp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 231 | cp += 2; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 232 | len -= 2; |
| 233 | if (cslen > AOEV1_MAX_CONFSTR_LEN || cslen > len) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 234 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 235 | /* Config String */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 236 | if (cslen) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 237 | ND_PRINT("\n\tConfig String (length %u): ", cslen); |
| 238 | (void)nd_printn(ndo, cp, cslen, NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 239 | } |
| 240 | return; |
| 241 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 242 | invalid: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 243 | nd_print_invalid(ndo); |
| 244 | ND_TCHECK_LEN(cp, len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | static void |
| 248 | aoev1_mac_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 249 | const u_char *cp, u_int len) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 250 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 251 | uint8_t dircount, i; |
| 252 | |
| 253 | if (len < AOEV1_MAC_ARG_LEN) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 254 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 255 | /* Reserved */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 256 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 257 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 258 | /* MCmd */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 259 | ND_PRINT("\n\tMCmd: %s", |
| 260 | tok2str(aoev1_mcmd_str, "Unknown (0x%02x)", GET_U_1(cp))); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 261 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 262 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 263 | /* MError */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 264 | ND_PRINT(", MError: %s", |
| 265 | tok2str(aoev1_merror_str, "Unknown (0x%02x)", GET_U_1(cp))); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 266 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 267 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 268 | /* Dir Count */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 269 | dircount = GET_U_1(cp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 270 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 271 | len -= 1; |
| 272 | ND_PRINT(", Dir Count: %u", dircount); |
| 273 | if (dircount * 8U > len) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 274 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 275 | /* directives */ |
| 276 | for (i = 0; i < dircount; i++) { |
| 277 | /* Reserved */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 278 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 279 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 280 | /* DCmd */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 281 | ND_PRINT("\n\t DCmd: %s", |
| 282 | tok2str(aoev1_dcmd_str, "Unknown (0x%02x)", GET_U_1(cp))); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 283 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 284 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 285 | /* Ethernet Address */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 286 | ND_PRINT(", Ethernet Address: %s", GET_ETHERADDR_STRING(cp)); |
| 287 | cp += MAC_ADDR_LEN; |
| 288 | len -= MAC_ADDR_LEN; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 289 | } |
| 290 | return; |
| 291 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 292 | invalid: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 293 | nd_print_invalid(ndo); |
| 294 | ND_TCHECK_LEN(cp, len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void |
| 298 | aoev1_reserve_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 299 | const u_char *cp, u_int len) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 300 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 301 | uint8_t nmacs, i; |
| 302 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 303 | if (len < AOEV1_RESERVE_ARG_LEN || (len - AOEV1_RESERVE_ARG_LEN) % MAC_ADDR_LEN) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 304 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 305 | /* RCmd */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 306 | ND_PRINT("\n\tRCmd: %s", |
| 307 | tok2str(aoev1_rcmd_str, "Unknown (0x%02x)", GET_U_1(cp))); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 308 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 309 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 310 | /* NMacs (correlated with the length) */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 311 | nmacs = GET_U_1(cp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 312 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 313 | len -= 1; |
| 314 | ND_PRINT(", NMacs: %u", nmacs); |
| 315 | if (nmacs * MAC_ADDR_LEN != len) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 316 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 317 | /* addresses */ |
| 318 | for (i = 0; i < nmacs; i++) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 319 | ND_PRINT("\n\tEthernet Address %u: %s", i, GET_ETHERADDR_STRING(cp)); |
| 320 | cp += MAC_ADDR_LEN; |
| 321 | len -= MAC_ADDR_LEN; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 322 | } |
| 323 | return; |
| 324 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 325 | invalid: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 326 | nd_print_invalid(ndo); |
| 327 | ND_TCHECK_LEN(cp, len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /* cp points to the Ver/Flags octet */ |
| 331 | static void |
| 332 | aoev1_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 333 | const u_char *cp, u_int len) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 334 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 335 | uint8_t flags, command; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 336 | void (*cmd_decoder)(netdissect_options *, const u_char *, u_int); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 337 | |
| 338 | if (len < AOEV1_COMMON_HDR_LEN) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 339 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 340 | /* Flags */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 341 | flags = GET_U_1(cp) & 0x0F; |
| 342 | ND_PRINT(", Flags: [%s]", bittok2str(aoev1_flag_str, "none", flags)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 343 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 344 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 345 | if (! ndo->ndo_vflag) |
| 346 | return; |
| 347 | /* Error */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 348 | if (flags & AOEV1_FLAG_E) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 349 | ND_PRINT("\n\tError: %s", |
| 350 | tok2str(aoev1_errcode_str, "Invalid (%u)", GET_U_1(cp))); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 351 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 352 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 353 | /* Major */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 354 | ND_PRINT("\n\tMajor: 0x%04x", GET_BE_U_2(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 355 | cp += 2; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 356 | len -= 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 357 | /* Minor */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 358 | ND_PRINT(", Minor: 0x%02x", GET_U_1(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 359 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 360 | len -= 1; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 361 | /* Command */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 362 | command = GET_U_1(cp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 363 | cp += 1; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 364 | len -= 1; |
| 365 | ND_PRINT(", Command: %s", tok2str(cmdcode_str, "Unknown (0x%02x)", command)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 366 | /* Tag */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 367 | ND_PRINT(", Tag: 0x%08x", GET_BE_U_4(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 368 | cp += 4; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 369 | len -= 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 370 | /* 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 Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 378 | cmd_decoder(ndo, cp, len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 379 | return; |
| 380 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 381 | invalid: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 382 | nd_print_invalid(ndo); |
| 383 | ND_TCHECK_LEN(cp, len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void |
| 387 | aoe_print(netdissect_options *ndo, |
| 388 | const u_char *cp, const u_int len) |
| 389 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 390 | uint8_t ver; |
| 391 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 392 | ndo->ndo_protocol = "aoe"; |
| 393 | ND_PRINT("AoE length %u", len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 394 | |
| 395 | if (len < 1) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 396 | goto invalid; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 397 | /* Ver/Flags */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 398 | ver = (GET_U_1(cp) & 0xF0) >> 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 399 | /* Don't advance cp yet: low order 4 bits are version-specific. */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 400 | ND_PRINT(", Ver %u", ver); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 401 | |
| 402 | switch (ver) { |
| 403 | case AOE_V1: |
| 404 | aoev1_print(ndo, cp, len); |
| 405 | break; |
| 406 | } |
| 407 | return; |
| 408 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 409 | invalid: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 410 | nd_print_invalid(ndo); |
| 411 | ND_TCHECK_LEN(cp, len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 412 | } |
| 413 | |