blob: 118381808fdad8c8fef075c540341a8d9d65dbcd [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
JP Abgrall53f17a92014-02-12 14:02:41 -08002 * Copyright (c) 1998-2006 The TCPDUMP project
The Android Open Source Project2949f582009-03-03 19:30:46 -08003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * support for the IEEE "slow protocols" LACP, MARKER as per 802.3ad
JP Abgrall53f17a92014-02-12 14:02:41 -080016 * OAM as per 802.3ah
The Android Open Source Project2949f582009-03-03 19:30:46 -080017 *
Elliott Hughescec480a2017-12-19 16:54:57 -080018 * Original code by Hannes Gredler (hannes@gredler.at)
The Android Open Source Project2949f582009-03-03 19:30:46 -080019 */
20
Elliott Hughese2e3bd12017-05-15 10:59:29 -070021/* \summary: IEEE "slow protocols" (802.3ad/802.3ah) printer */
22
The Android Open Source Project2949f582009-03-03 19:30:46 -080023#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070024#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080025#endif
26
Elliott Hughes820eced2021-08-20 18:00:50 -070027#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080028
Elliott Hughes820eced2021-08-20 18:00:50 -070029#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070030#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080031#include "extract.h"
32#include "addrtoname.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080033#include "oui.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080034
Elliott Hughes820eced2021-08-20 18:00:50 -070035
The Android Open Source Project2949f582009-03-03 19:30:46 -080036#define SLOW_PROTO_LACP 1
37#define SLOW_PROTO_MARKER 2
JP Abgrall53f17a92014-02-12 14:02:41 -080038#define SLOW_PROTO_OAM 3
The Android Open Source Project2949f582009-03-03 19:30:46 -080039
40#define LACP_VERSION 1
41#define MARKER_VERSION 1
42
43static const struct tok slow_proto_values[] = {
44 { SLOW_PROTO_LACP, "LACP" },
45 { SLOW_PROTO_MARKER, "MARKER" },
JP Abgrall53f17a92014-02-12 14:02:41 -080046 { SLOW_PROTO_OAM, "OAM" },
47 { 0, NULL}
48};
49
50static const struct tok slow_oam_flag_values[] = {
51 { 0x0001, "Link Fault" },
52 { 0x0002, "Dying Gasp" },
53 { 0x0004, "Critical Event" },
54 { 0x0008, "Local Evaluating" },
55 { 0x0010, "Local Stable" },
56 { 0x0020, "Remote Evaluating" },
57 { 0x0040, "Remote Stable" },
58 { 0, NULL}
Elliott Hughes892a68b2015-10-19 14:43:53 -070059};
JP Abgrall53f17a92014-02-12 14:02:41 -080060
61#define SLOW_OAM_CODE_INFO 0x00
62#define SLOW_OAM_CODE_EVENT_NOTIF 0x01
63#define SLOW_OAM_CODE_VAR_REQUEST 0x02
64#define SLOW_OAM_CODE_VAR_RESPONSE 0x03
65#define SLOW_OAM_CODE_LOOPBACK_CTRL 0x04
66#define SLOW_OAM_CODE_PRIVATE 0xfe
67
68static const struct tok slow_oam_code_values[] = {
69 { SLOW_OAM_CODE_INFO, "Information" },
70 { SLOW_OAM_CODE_EVENT_NOTIF, "Event Notification" },
71 { SLOW_OAM_CODE_VAR_REQUEST, "Variable Request" },
72 { SLOW_OAM_CODE_VAR_RESPONSE, "Variable Response" },
73 { SLOW_OAM_CODE_LOOPBACK_CTRL, "Loopback Control" },
74 { SLOW_OAM_CODE_PRIVATE, "Vendor Private" },
75 { 0, NULL}
76};
77
78struct slow_oam_info_t {
Elliott Hughes820eced2021-08-20 18:00:50 -070079 nd_uint8_t info_type;
80 nd_uint8_t info_length;
81 nd_uint8_t oam_version;
82 nd_uint16_t revision;
83 nd_uint8_t state;
84 nd_uint8_t oam_config;
85 nd_uint16_t oam_pdu_config;
86 nd_uint24_t oui;
87 nd_uint32_t vendor_private;
JP Abgrall53f17a92014-02-12 14:02:41 -080088};
89
90#define SLOW_OAM_INFO_TYPE_END_OF_TLV 0x00
91#define SLOW_OAM_INFO_TYPE_LOCAL 0x01
92#define SLOW_OAM_INFO_TYPE_REMOTE 0x02
93#define SLOW_OAM_INFO_TYPE_ORG_SPECIFIC 0xfe
94
95static const struct tok slow_oam_info_type_values[] = {
96 { SLOW_OAM_INFO_TYPE_END_OF_TLV, "End of TLV marker" },
97 { SLOW_OAM_INFO_TYPE_LOCAL, "Local" },
98 { SLOW_OAM_INFO_TYPE_REMOTE, "Remote" },
99 { SLOW_OAM_INFO_TYPE_ORG_SPECIFIC, "Organization specific" },
100 { 0, NULL}
101};
102
103#define OAM_INFO_TYPE_PARSER_MASK 0x3
104static const struct tok slow_oam_info_type_state_parser_values[] = {
105 { 0x00, "forwarding" },
106 { 0x01, "looping back" },
107 { 0x02, "discarding" },
108 { 0x03, "reserved" },
109 { 0, NULL}
110};
111
112#define OAM_INFO_TYPE_MUX_MASK 0x4
113static const struct tok slow_oam_info_type_state_mux_values[] = {
114 { 0x00, "forwarding" },
115 { 0x04, "discarding" },
116 { 0, NULL}
117};
118
119static const struct tok slow_oam_info_type_oam_config_values[] = {
120 { 0x01, "Active" },
121 { 0x02, "Unidirectional" },
122 { 0x04, "Remote-Loopback" },
123 { 0x08, "Link-Events" },
124 { 0x10, "Variable-Retrieval" },
125 { 0, NULL}
126};
127
128/* 11 Bits */
129#define OAM_INFO_TYPE_PDU_SIZE_MASK 0x7ff
130
131#define SLOW_OAM_LINK_EVENT_END_OF_TLV 0x00
132#define SLOW_OAM_LINK_EVENT_ERR_SYM_PER 0x01
133#define SLOW_OAM_LINK_EVENT_ERR_FRM 0x02
134#define SLOW_OAM_LINK_EVENT_ERR_FRM_PER 0x03
135#define SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM 0x04
136#define SLOW_OAM_LINK_EVENT_ORG_SPECIFIC 0xfe
137
138static const struct tok slow_oam_link_event_values[] = {
139 { SLOW_OAM_LINK_EVENT_END_OF_TLV, "End of TLV marker" },
140 { SLOW_OAM_LINK_EVENT_ERR_SYM_PER, "Errored Symbol Period Event" },
141 { SLOW_OAM_LINK_EVENT_ERR_FRM, "Errored Frame Event" },
142 { SLOW_OAM_LINK_EVENT_ERR_FRM_PER, "Errored Frame Period Event" },
143 { SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM, "Errored Frame Seconds Summary Event" },
144 { SLOW_OAM_LINK_EVENT_ORG_SPECIFIC, "Organization specific" },
145 { 0, NULL}
146};
147
148struct slow_oam_link_event_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700149 nd_uint8_t event_type;
150 nd_uint8_t event_length;
151 nd_uint16_t time_stamp;
152 nd_uint64_t window;
153 nd_uint64_t threshold;
154 nd_uint64_t errors;
155 nd_uint64_t errors_running_total;
156 nd_uint32_t event_running_total;
JP Abgrall53f17a92014-02-12 14:02:41 -0800157};
158
159struct slow_oam_variablerequest_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700160 nd_uint8_t branch;
161 nd_uint16_t leaf;
JP Abgrall53f17a92014-02-12 14:02:41 -0800162};
163
164struct slow_oam_variableresponse_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700165 nd_uint8_t branch;
166 nd_uint16_t leaf;
167 nd_uint8_t length;
JP Abgrall53f17a92014-02-12 14:02:41 -0800168};
169
170struct slow_oam_loopbackctrl_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700171 nd_uint8_t command;
JP Abgrall53f17a92014-02-12 14:02:41 -0800172};
173
174static const struct tok slow_oam_loopbackctrl_cmd_values[] = {
175 { 0x01, "Enable OAM Remote Loopback" },
176 { 0x02, "Disable OAM Remote Loopback" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800177 { 0, NULL}
178};
179
180struct tlv_header_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700181 nd_uint8_t type;
182 nd_uint8_t length;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800183};
184
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700185#define LACP_MARKER_TLV_TERMINATOR 0x00 /* same code for LACP and Marker */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800186
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700187#define LACP_TLV_ACTOR_INFO 0x01
188#define LACP_TLV_PARTNER_INFO 0x02
189#define LACP_TLV_COLLECTOR_INFO 0x03
190
191#define MARKER_TLV_MARKER_INFO 0x01
The Android Open Source Project2949f582009-03-03 19:30:46 -0800192
193static const struct tok slow_tlv_values[] = {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700194 { (SLOW_PROTO_LACP << 8) + LACP_MARKER_TLV_TERMINATOR, "Terminator"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800195 { (SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO, "Actor Information"},
196 { (SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO, "Partner Information"},
197 { (SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO, "Collector Information"},
198
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700199 { (SLOW_PROTO_MARKER << 8) + LACP_MARKER_TLV_TERMINATOR, "Terminator"},
The Android Open Source Project2949f582009-03-03 19:30:46 -0800200 { (SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO, "Marker Information"},
201 { 0, NULL}
202};
203
204struct lacp_tlv_actor_partner_info_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700205 nd_uint16_t sys_pri;
206 nd_mac_addr sys;
207 nd_uint16_t key;
208 nd_uint16_t port_pri;
209 nd_uint16_t port;
210 nd_uint8_t state;
211 nd_byte pad[3];
Elliott Hughes892a68b2015-10-19 14:43:53 -0700212};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800213
214static const struct tok lacp_tlv_actor_partner_info_state_values[] = {
215 { 0x01, "Activity"},
216 { 0x02, "Timeout"},
217 { 0x04, "Aggregation"},
218 { 0x08, "Synchronization"},
219 { 0x10, "Collecting"},
220 { 0x20, "Distributing"},
221 { 0x40, "Default"},
222 { 0x80, "Expired"},
223 { 0, NULL}
224};
225
226struct lacp_tlv_collector_info_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700227 nd_uint16_t max_delay;
228 nd_byte pad[12];
Elliott Hughes892a68b2015-10-19 14:43:53 -0700229};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800230
231struct marker_tlv_marker_info_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700232 nd_uint16_t req_port;
233 nd_mac_addr req_sys;
234 nd_uint32_t req_trans_id;
235 nd_byte pad[2];
Elliott Hughes892a68b2015-10-19 14:43:53 -0700236};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800237
238struct lacp_marker_tlv_terminator_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700239 nd_byte pad[50];
Elliott Hughes892a68b2015-10-19 14:43:53 -0700240};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800241
Elliott Hughes820eced2021-08-20 18:00:50 -0700242static void slow_marker_lacp_print(netdissect_options *, const u_char *, u_int, u_int);
243static void slow_oam_print(netdissect_options *, const u_char *, u_int);
JP Abgrall53f17a92014-02-12 14:02:41 -0800244
The Android Open Source Project2949f582009-03-03 19:30:46 -0800245void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700246slow_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700247 const u_char *pptr, u_int len)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700248{
JP Abgrall53f17a92014-02-12 14:02:41 -0800249 int print_version;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700250 u_int subtype;
JP Abgrall53f17a92014-02-12 14:02:41 -0800251
Elliott Hughes820eced2021-08-20 18:00:50 -0700252 ndo->ndo_protocol = "slow";
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700253 if (len < 1)
254 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700255 subtype = GET_U_1(pptr);
JP Abgrall53f17a92014-02-12 14:02:41 -0800256
257 /*
258 * Sanity checking of the header.
259 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700260 switch (subtype) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800261 case SLOW_PROTO_LACP:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700262 if (len < 2)
263 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700264 if (GET_U_1(pptr + 1) != LACP_VERSION) {
265 ND_PRINT("LACP version %u packet not supported",
266 GET_U_1(pptr + 1));
JP Abgrall53f17a92014-02-12 14:02:41 -0800267 return;
268 }
269 print_version = 1;
270 break;
271
272 case SLOW_PROTO_MARKER:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700273 if (len < 2)
274 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700275 if (GET_U_1(pptr + 1) != MARKER_VERSION) {
276 ND_PRINT("MARKER version %u packet not supported",
277 GET_U_1(pptr + 1));
JP Abgrall53f17a92014-02-12 14:02:41 -0800278 return;
279 }
280 print_version = 1;
281 break;
282
283 case SLOW_PROTO_OAM: /* fall through */
284 print_version = 0;
285 break;
286
287 default:
288 /* print basic information and exit */
289 print_version = -1;
290 break;
291 }
292
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700293 if (print_version == 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700294 ND_PRINT("%sv%u, length %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700295 tok2str(slow_proto_values, "unknown (%u)", subtype),
Elliott Hughes820eced2021-08-20 18:00:50 -0700296 GET_U_1((pptr + 1)),
297 len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800298 } else {
299 /* some slow protos don't have a version number in the header */
Elliott Hughes820eced2021-08-20 18:00:50 -0700300 ND_PRINT("%s, length %u",
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700301 tok2str(slow_proto_values, "unknown (%u)", subtype),
Elliott Hughes820eced2021-08-20 18:00:50 -0700302 len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800303 }
304
305 /* unrecognized subtype */
306 if (print_version == -1) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700307 print_unknown_data(ndo, pptr, "\n\t", len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800308 return;
309 }
310
Elliott Hughes892a68b2015-10-19 14:43:53 -0700311 if (!ndo->ndo_vflag)
JP Abgrall53f17a92014-02-12 14:02:41 -0800312 return;
313
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700314 switch (subtype) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800315 default: /* should not happen */
316 break;
317
318 case SLOW_PROTO_OAM:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700319 /* skip subtype */
320 len -= 1;
321 pptr += 1;
322 slow_oam_print(ndo, pptr, len);
JP Abgrall53f17a92014-02-12 14:02:41 -0800323 break;
324
325 case SLOW_PROTO_LACP: /* LACP and MARKER share the same semantics */
326 case SLOW_PROTO_MARKER:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700327 /* skip subtype and version */
328 len -= 2;
329 pptr += 2;
330 slow_marker_lacp_print(ndo, pptr, len, subtype);
JP Abgrall53f17a92014-02-12 14:02:41 -0800331 break;
332 }
333 return;
334
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700335tooshort:
336 if (!ndo->ndo_vflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700337 ND_PRINT(" (packet is too short)");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700338 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700339 ND_PRINT("\n\t\t packet is too short");
JP Abgrall53f17a92014-02-12 14:02:41 -0800340}
341
Elliott Hughes892a68b2015-10-19 14:43:53 -0700342static void
343slow_marker_lacp_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700344 const u_char *tptr, u_int tlen,
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700345 u_int proto_subtype)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700346{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800347 const struct tlv_header_t *tlv_header;
JP Abgrall53f17a92014-02-12 14:02:41 -0800348 const u_char *tlv_tptr;
Elliott Hughes820eced2021-08-20 18:00:50 -0700349 u_int tlv_type, tlv_len, tlv_tlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800350
351 union {
352 const struct lacp_marker_tlv_terminator_t *lacp_marker_tlv_terminator;
353 const struct lacp_tlv_actor_partner_info_t *lacp_tlv_actor_partner_info;
354 const struct lacp_tlv_collector_info_t *lacp_tlv_collector_info;
355 const struct marker_tlv_marker_info_t *marker_tlv_marker_info;
356 } tlv_ptr;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700357
The Android Open Source Project2949f582009-03-03 19:30:46 -0800358 while(tlen>0) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700359 /* is the packet big enough to include the tlv header ? */
360 if (tlen < sizeof(struct tlv_header_t))
361 goto tooshort;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800362 /* did we capture enough for fully decoding the tlv header ? */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800363 tlv_header = (const struct tlv_header_t *)tptr;
Elliott Hughes820eced2021-08-20 18:00:50 -0700364 tlv_type = GET_U_1(tlv_header->type);
365 tlv_len = GET_U_1(tlv_header->length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800366
Elliott Hughes820eced2021-08-20 18:00:50 -0700367 ND_PRINT("\n\t%s TLV (0x%02x), length %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800368 tok2str(slow_tlv_values,
369 "Unknown",
Elliott Hughes820eced2021-08-20 18:00:50 -0700370 (proto_subtype << 8) + tlv_type),
371 tlv_type,
372 tlv_len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800373
Elliott Hughes820eced2021-08-20 18:00:50 -0700374 if (tlv_type == LACP_MARKER_TLV_TERMINATOR) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700375 /*
376 * This TLV has a length of zero, and means there are no
377 * more TLVs to process.
378 */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800379 return;
380 }
381
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700382 /* length includes the type and length fields */
383 if (tlv_len < sizeof(struct tlv_header_t)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700384 ND_PRINT("\n\t ERROR: illegal length - should be >= %zu",
385 sizeof(struct tlv_header_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700386 return;
387 }
388
389 /* is the packet big enough to include the tlv ? */
390 if (tlen < tlv_len)
391 goto tooshort;
392 /* did we capture enough for fully decoding the tlv ? */
Elliott Hughes820eced2021-08-20 18:00:50 -0700393 ND_TCHECK_LEN(tptr, tlv_len);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700394
The Android Open Source Project2949f582009-03-03 19:30:46 -0800395 tlv_tptr=tptr+sizeof(struct tlv_header_t);
396 tlv_tlen=tlv_len-sizeof(struct tlv_header_t);
397
Elliott Hughes820eced2021-08-20 18:00:50 -0700398 switch((proto_subtype << 8) + tlv_type) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800399
400 /* those two TLVs have the same structure -> fall through */
401 case ((SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO):
402 case ((SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO):
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700403 if (tlv_tlen !=
404 sizeof(struct lacp_tlv_actor_partner_info_t)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700405 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
406 sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_actor_partner_info_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700407 goto badlength;
408 }
409
The Android Open Source Project2949f582009-03-03 19:30:46 -0800410 tlv_ptr.lacp_tlv_actor_partner_info = (const struct lacp_tlv_actor_partner_info_t *)tlv_tptr;
411
Elliott Hughes820eced2021-08-20 18:00:50 -0700412 ND_PRINT("\n\t System %s, System Priority %u, Key %u"
The Android Open Source Project2949f582009-03-03 19:30:46 -0800413 ", Port %u, Port Priority %u\n\t State Flags [%s]",
Elliott Hughes820eced2021-08-20 18:00:50 -0700414 GET_ETHERADDR_STRING(tlv_ptr.lacp_tlv_actor_partner_info->sys),
415 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->sys_pri),
416 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->key),
417 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->port),
418 GET_BE_U_2(tlv_ptr.lacp_tlv_actor_partner_info->port_pri),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800419 bittok2str(lacp_tlv_actor_partner_info_state_values,
420 "none",
Elliott Hughes820eced2021-08-20 18:00:50 -0700421 GET_U_1(tlv_ptr.lacp_tlv_actor_partner_info->state)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800422
423 break;
424
425 case ((SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO):
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700426 if (tlv_tlen !=
427 sizeof(struct lacp_tlv_collector_info_t)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700428 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
429 sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_collector_info_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700430 goto badlength;
431 }
432
The Android Open Source Project2949f582009-03-03 19:30:46 -0800433 tlv_ptr.lacp_tlv_collector_info = (const struct lacp_tlv_collector_info_t *)tlv_tptr;
434
Elliott Hughes820eced2021-08-20 18:00:50 -0700435 ND_PRINT("\n\t Max Delay %u",
436 GET_BE_U_2(tlv_ptr.lacp_tlv_collector_info->max_delay));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800437
438 break;
439
440 case ((SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO):
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700441 if (tlv_tlen !=
442 sizeof(struct marker_tlv_marker_info_t)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700443 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
444 sizeof(struct tlv_header_t) + sizeof(struct marker_tlv_marker_info_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700445 goto badlength;
446 }
447
The Android Open Source Project2949f582009-03-03 19:30:46 -0800448 tlv_ptr.marker_tlv_marker_info = (const struct marker_tlv_marker_info_t *)tlv_tptr;
449
Elliott Hughes820eced2021-08-20 18:00:50 -0700450 ND_PRINT("\n\t Request System %s, Request Port %u, Request Transaction ID 0x%08x",
451 GET_ETHERADDR_STRING(tlv_ptr.marker_tlv_marker_info->req_sys),
452 GET_BE_U_2(tlv_ptr.marker_tlv_marker_info->req_port),
453 GET_BE_U_4(tlv_ptr.marker_tlv_marker_info->req_trans_id));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800454
455 break;
456
The Android Open Source Project2949f582009-03-03 19:30:46 -0800457 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700458 if (ndo->ndo_vflag <= 1)
459 print_unknown_data(ndo, tlv_tptr, "\n\t ", tlv_tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800460 break;
461 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700462
463 badlength:
JP Abgrall53f17a92014-02-12 14:02:41 -0800464 /* do we want to see an additional hexdump ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700465 if (ndo->ndo_vflag > 1) {
466 print_unknown_data(ndo, tptr+sizeof(struct tlv_header_t), "\n\t ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800467 tlv_len-sizeof(struct tlv_header_t));
JP Abgrall53f17a92014-02-12 14:02:41 -0800468 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800469
470 tptr+=tlv_len;
471 tlen-=tlv_len;
472 }
473 return;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700474
475tooshort:
Elliott Hughes820eced2021-08-20 18:00:50 -0700476 ND_PRINT("\n\t\t packet is too short");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800477}
JP Abgrall53f17a92014-02-12 14:02:41 -0800478
Elliott Hughes892a68b2015-10-19 14:43:53 -0700479static void
480slow_oam_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700481 const u_char *tptr, u_int tlen)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700482{
Elliott Hughes820eced2021-08-20 18:00:50 -0700483 uint8_t code;
484 uint8_t type, length;
485 uint8_t state;
486 uint8_t command;
JP Abgrall53f17a92014-02-12 14:02:41 -0800487 u_int hexdump;
488
489 struct slow_oam_common_header_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700490 nd_uint16_t flags;
491 nd_uint8_t code;
JP Abgrall53f17a92014-02-12 14:02:41 -0800492 };
493
494 struct slow_oam_tlv_header_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700495 nd_uint8_t type;
496 nd_uint8_t length;
JP Abgrall53f17a92014-02-12 14:02:41 -0800497 };
498
499 union {
500 const struct slow_oam_common_header_t *slow_oam_common_header;
501 const struct slow_oam_tlv_header_t *slow_oam_tlv_header;
502 } ptr;
503
504 union {
Elliott Hughes820eced2021-08-20 18:00:50 -0700505 const struct slow_oam_info_t *slow_oam_info;
JP Abgrall53f17a92014-02-12 14:02:41 -0800506 const struct slow_oam_link_event_t *slow_oam_link_event;
507 const struct slow_oam_variablerequest_t *slow_oam_variablerequest;
508 const struct slow_oam_variableresponse_t *slow_oam_variableresponse;
509 const struct slow_oam_loopbackctrl_t *slow_oam_loopbackctrl;
510 } tlv;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700511
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700512 ptr.slow_oam_common_header = (const struct slow_oam_common_header_t *)tptr;
513 if (tlen < sizeof(*ptr.slow_oam_common_header))
514 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700515 ND_TCHECK_SIZE(ptr.slow_oam_common_header);
JP Abgrall53f17a92014-02-12 14:02:41 -0800516 tptr += sizeof(struct slow_oam_common_header_t);
517 tlen -= sizeof(struct slow_oam_common_header_t);
518
Elliott Hughes820eced2021-08-20 18:00:50 -0700519 code = GET_U_1(ptr.slow_oam_common_header->code);
520 ND_PRINT("\n\tCode %s OAM PDU, Flags [%s]",
521 tok2str(slow_oam_code_values, "Unknown (%u)", code),
JP Abgrall53f17a92014-02-12 14:02:41 -0800522 bittok2str(slow_oam_flag_values,
523 "none",
Elliott Hughes820eced2021-08-20 18:00:50 -0700524 GET_BE_U_2(ptr.slow_oam_common_header->flags)));
JP Abgrall53f17a92014-02-12 14:02:41 -0800525
Elliott Hughes820eced2021-08-20 18:00:50 -0700526 switch (code) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800527 case SLOW_OAM_CODE_INFO:
528 while (tlen > 0) {
529 ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700530 if (tlen < sizeof(*ptr.slow_oam_tlv_header))
531 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700532 ND_TCHECK_SIZE(ptr.slow_oam_tlv_header);
533 type = GET_U_1(ptr.slow_oam_tlv_header->type);
534 length = GET_U_1(ptr.slow_oam_tlv_header->length);
535 ND_PRINT("\n\t %s Information Type (%u), length %u",
536 tok2str(slow_oam_info_type_values, "Reserved", type),
537 type,
538 length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800539
Elliott Hughes820eced2021-08-20 18:00:50 -0700540 if (type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700541 /*
542 * As IEEE Std 802.3-2015 says for the End of TLV Marker,
543 * "(the length and value of the Type 0x00 TLV can be ignored)".
544 */
545 return;
546 }
547
548 /* length includes the type and length fields */
Elliott Hughes820eced2021-08-20 18:00:50 -0700549 if (length < sizeof(struct slow_oam_tlv_header_t)) {
550 ND_PRINT("\n\t ERROR: illegal length - should be >= %zu",
551 sizeof(struct slow_oam_tlv_header_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700552 return;
553 }
554
Elliott Hughes820eced2021-08-20 18:00:50 -0700555 if (tlen < length)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700556 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700557 ND_TCHECK_LEN(tptr, length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700558
JP Abgrall53f17a92014-02-12 14:02:41 -0800559 hexdump = FALSE;
Elliott Hughes820eced2021-08-20 18:00:50 -0700560 switch (type) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800561 case SLOW_OAM_INFO_TYPE_LOCAL: /* identical format - fall through */
562 case SLOW_OAM_INFO_TYPE_REMOTE:
563 tlv.slow_oam_info = (const struct slow_oam_info_t *)tptr;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700564
Elliott Hughes820eced2021-08-20 18:00:50 -0700565 if (GET_U_1(tlv.slow_oam_info->info_length) !=
JP Abgrall53f17a92014-02-12 14:02:41 -0800566 sizeof(struct slow_oam_info_t)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700567 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
568 sizeof(struct slow_oam_info_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700569 hexdump = TRUE;
570 goto badlength_code_info;
JP Abgrall53f17a92014-02-12 14:02:41 -0800571 }
572
Elliott Hughes820eced2021-08-20 18:00:50 -0700573 ND_PRINT("\n\t OAM-Version %u, Revision %u",
574 GET_U_1(tlv.slow_oam_info->oam_version),
575 GET_BE_U_2(tlv.slow_oam_info->revision));
JP Abgrall53f17a92014-02-12 14:02:41 -0800576
Elliott Hughes820eced2021-08-20 18:00:50 -0700577 state = GET_U_1(tlv.slow_oam_info->state);
578 ND_PRINT("\n\t State-Parser-Action %s, State-MUX-Action %s",
JP Abgrall53f17a92014-02-12 14:02:41 -0800579 tok2str(slow_oam_info_type_state_parser_values, "Reserved",
Elliott Hughes820eced2021-08-20 18:00:50 -0700580 state & OAM_INFO_TYPE_PARSER_MASK),
JP Abgrall53f17a92014-02-12 14:02:41 -0800581 tok2str(slow_oam_info_type_state_mux_values, "Reserved",
Elliott Hughes820eced2021-08-20 18:00:50 -0700582 state & OAM_INFO_TYPE_MUX_MASK));
583 ND_PRINT("\n\t OAM-Config Flags [%s], OAM-PDU-Config max-PDU size %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800584 bittok2str(slow_oam_info_type_oam_config_values, "none",
Elliott Hughes820eced2021-08-20 18:00:50 -0700585 GET_U_1(tlv.slow_oam_info->oam_config)),
586 GET_BE_U_2(tlv.slow_oam_info->oam_pdu_config) &
587 OAM_INFO_TYPE_PDU_SIZE_MASK);
588 ND_PRINT("\n\t OUI %s (0x%06x), Vendor-Private 0x%08x",
JP Abgrall53f17a92014-02-12 14:02:41 -0800589 tok2str(oui_values, "Unknown",
Elliott Hughes820eced2021-08-20 18:00:50 -0700590 GET_BE_U_3(tlv.slow_oam_info->oui)),
591 GET_BE_U_3(tlv.slow_oam_info->oui),
592 GET_BE_U_4(tlv.slow_oam_info->vendor_private));
JP Abgrall53f17a92014-02-12 14:02:41 -0800593 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700594
JP Abgrall53f17a92014-02-12 14:02:41 -0800595 case SLOW_OAM_INFO_TYPE_ORG_SPECIFIC:
596 hexdump = TRUE;
597 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700598
JP Abgrall53f17a92014-02-12 14:02:41 -0800599 default:
600 hexdump = TRUE;
601 break;
602 }
603
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700604 badlength_code_info:
JP Abgrall53f17a92014-02-12 14:02:41 -0800605 /* do we also want to see a hex dump ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700606 if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
607 print_unknown_data(ndo, tptr, "\n\t ",
Elliott Hughes820eced2021-08-20 18:00:50 -0700608 length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800609 }
610
Elliott Hughes820eced2021-08-20 18:00:50 -0700611 tlen -= length;
612 tptr += length;
JP Abgrall53f17a92014-02-12 14:02:41 -0800613 }
614 break;
615
616 case SLOW_OAM_CODE_EVENT_NOTIF:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700617 /* Sequence number */
618 if (tlen < 2)
619 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700620 ND_PRINT("\n\t Sequence Number %u", GET_BE_U_2(tptr));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700621 tlen -= 2;
622 tptr += 2;
623
624 /* TLVs */
JP Abgrall53f17a92014-02-12 14:02:41 -0800625 while (tlen > 0) {
626 ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700627 if (tlen < sizeof(*ptr.slow_oam_tlv_header))
628 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700629 type = GET_U_1(ptr.slow_oam_tlv_header->type);
630 length = GET_U_1(ptr.slow_oam_tlv_header->length);
631 ND_PRINT("\n\t %s Link Event Type (%u), length %u",
JP Abgrall53f17a92014-02-12 14:02:41 -0800632 tok2str(slow_oam_link_event_values, "Reserved",
Elliott Hughes820eced2021-08-20 18:00:50 -0700633 type),
634 type,
635 length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800636
Elliott Hughes820eced2021-08-20 18:00:50 -0700637 if (type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700638 /*
639 * As IEEE Std 802.3-2015 says for the End of TLV Marker,
640 * "(the length and value of the Type 0x00 TLV can be ignored)".
641 */
642 return;
643 }
644
645 /* length includes the type and length fields */
Elliott Hughes820eced2021-08-20 18:00:50 -0700646 if (length < sizeof(struct slow_oam_tlv_header_t)) {
647 ND_PRINT("\n\t ERROR: illegal length - should be >= %zu",
648 sizeof(struct slow_oam_tlv_header_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700649 return;
650 }
651
Elliott Hughes820eced2021-08-20 18:00:50 -0700652 if (tlen < length)
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700653 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700654 ND_TCHECK_LEN(tptr, length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700655
JP Abgrall53f17a92014-02-12 14:02:41 -0800656 hexdump = FALSE;
Elliott Hughes820eced2021-08-20 18:00:50 -0700657 switch (type) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800658 case SLOW_OAM_LINK_EVENT_ERR_SYM_PER: /* identical format - fall through */
659 case SLOW_OAM_LINK_EVENT_ERR_FRM:
660 case SLOW_OAM_LINK_EVENT_ERR_FRM_PER:
661 case SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM:
662 tlv.slow_oam_link_event = (const struct slow_oam_link_event_t *)tptr;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700663
Elliott Hughes820eced2021-08-20 18:00:50 -0700664 if (GET_U_1(tlv.slow_oam_link_event->event_length) !=
JP Abgrall53f17a92014-02-12 14:02:41 -0800665 sizeof(struct slow_oam_link_event_t)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700666 ND_PRINT("\n\t ERROR: illegal length - should be %zu",
667 sizeof(struct slow_oam_link_event_t));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700668 hexdump = TRUE;
669 goto badlength_event_notif;
JP Abgrall53f17a92014-02-12 14:02:41 -0800670 }
671
Elliott Hughes820eced2021-08-20 18:00:50 -0700672 ND_PRINT("\n\t Timestamp %u ms, Errored Window %" PRIu64
JP Abgrall53f17a92014-02-12 14:02:41 -0800673 "\n\t Errored Threshold %" PRIu64
674 "\n\t Errors %" PRIu64
675 "\n\t Error Running Total %" PRIu64
676 "\n\t Event Running Total %u",
Elliott Hughes820eced2021-08-20 18:00:50 -0700677 GET_BE_U_2(tlv.slow_oam_link_event->time_stamp)*100,
678 GET_BE_U_8(tlv.slow_oam_link_event->window),
679 GET_BE_U_8(tlv.slow_oam_link_event->threshold),
680 GET_BE_U_8(tlv.slow_oam_link_event->errors),
681 GET_BE_U_8(tlv.slow_oam_link_event->errors_running_total),
682 GET_BE_U_4(tlv.slow_oam_link_event->event_running_total));
JP Abgrall53f17a92014-02-12 14:02:41 -0800683 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700684
JP Abgrall53f17a92014-02-12 14:02:41 -0800685 case SLOW_OAM_LINK_EVENT_ORG_SPECIFIC:
686 hexdump = TRUE;
687 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700688
JP Abgrall53f17a92014-02-12 14:02:41 -0800689 default:
690 hexdump = TRUE;
691 break;
692 }
693
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700694 badlength_event_notif:
JP Abgrall53f17a92014-02-12 14:02:41 -0800695 /* do we also want to see a hex dump ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700696 if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
697 print_unknown_data(ndo, tptr, "\n\t ",
Elliott Hughes820eced2021-08-20 18:00:50 -0700698 length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800699 }
700
Elliott Hughes820eced2021-08-20 18:00:50 -0700701 tlen -= length;
702 tptr += length;
JP Abgrall53f17a92014-02-12 14:02:41 -0800703 }
704 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700705
JP Abgrall53f17a92014-02-12 14:02:41 -0800706 case SLOW_OAM_CODE_LOOPBACK_CTRL:
707 tlv.slow_oam_loopbackctrl = (const struct slow_oam_loopbackctrl_t *)tptr;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700708 if (tlen < sizeof(*tlv.slow_oam_loopbackctrl))
709 goto tooshort;
Elliott Hughes820eced2021-08-20 18:00:50 -0700710 command = GET_U_1(tlv.slow_oam_loopbackctrl->command);
711 ND_PRINT("\n\t Command %s (%u)",
JP Abgrall53f17a92014-02-12 14:02:41 -0800712 tok2str(slow_oam_loopbackctrl_cmd_values,
713 "Unknown",
Elliott Hughes820eced2021-08-20 18:00:50 -0700714 command),
715 command);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700716 tptr ++;
717 tlen --;
JP Abgrall53f17a92014-02-12 14:02:41 -0800718 break;
719
720 /*
721 * FIXME those are the defined codes that lack a decoder
722 * you are welcome to contribute code ;-)
723 */
724 case SLOW_OAM_CODE_VAR_REQUEST:
725 case SLOW_OAM_CODE_VAR_RESPONSE:
726 case SLOW_OAM_CODE_PRIVATE:
727 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700728 if (ndo->ndo_vflag <= 1) {
729 print_unknown_data(ndo, tptr, "\n\t ", tlen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800730 }
731 break;
732 }
733 return;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700734
735tooshort:
Elliott Hughes820eced2021-08-20 18:00:50 -0700736 ND_PRINT("\n\t\t packet is too short");
JP Abgrall53f17a92014-02-12 14:02:41 -0800737}