Skip to content

Commit 15ada8d

Browse files
committed
fixup! slow: Move version handling to subtype functions
Consolidate the subtype-functions into the common function.
1 parent 5f4b040 commit 15ada8d

File tree

1 file changed

+25
-83
lines changed

1 file changed

+25
-83
lines changed

print-slow.c

Lines changed: 25 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ struct lacp_marker_tlv_terminator_t {
231231
nd_byte pad[50];
232232
};
233233

234-
static void slow_lacp_print(netdissect_options *, const u_char *, u_int);
235-
static void slow_marker_print(netdissect_options *, const u_char *, u_int);
234+
static void slow_marker_lacp_print(netdissect_options *, const u_char *, u_int, u_int);
236235
static void slow_oam_print(netdissect_options *, const u_char *, u_int);
237236
static void slow_ossp_print(netdissect_options *, const u_char *, u_int);
238237

@@ -254,12 +253,9 @@ slow_print(netdissect_options *ndo,
254253
pptr += 1;
255254

256255
switch (subtype) {
257-
case SLOW_PROTO_LACP:
258-
slow_lacp_print(ndo, pptr, len);
259-
break;
260-
256+
case SLOW_PROTO_LACP: /* fall through */
261257
case SLOW_PROTO_MARKER:
262-
slow_marker_print(ndo, pptr, len);
258+
slow_marker_lacp_print(ndo, pptr, len, subtype);
263259
break;
264260

265261
case SLOW_PROTO_OAM:
@@ -286,7 +282,7 @@ slow_print(netdissect_options *ndo,
286282
}
287283

288284
/*
289-
* Common tlv logic for LACPv1 and Marker.
285+
* Print Link Aggregation Control Protocol and Marker protocol. (802.3ad / 802.1ax)
290286
*/
291287
static void
292288
slow_marker_lacp_print(netdissect_options *ndo,
@@ -295,7 +291,7 @@ slow_marker_lacp_print(netdissect_options *ndo,
295291
{
296292
const struct tlv_header_t *tlv_header;
297293
const u_char *tlv_tptr;
298-
u_int tlv_type, tlv_len, tlv_tlen;
294+
u_int tlv_type, tlv_len, tlv_tlen, version;
299295

300296
union {
301297
const struct lacp_marker_tlv_terminator_t *lacp_marker_tlv_terminator;
@@ -304,6 +300,26 @@ slow_marker_lacp_print(netdissect_options *ndo,
304300
const struct marker_tlv_marker_info_t *marker_tlv_marker_info;
305301
} tlv_ptr;
306302

303+
if (tlen < 1)
304+
goto tooshort;
305+
306+
version = GET_U_1(tptr);
307+
tlen -= 1;
308+
tptr += 1;
309+
310+
ND_PRINT("%sv%u, length %u",
311+
proto_subtype == SLOW_PROTO_LACP ? "LACP" : "MARKER",
312+
version, tlen + 2);
313+
314+
if (!ndo->ndo_vflag)
315+
return;
316+
317+
if ((proto_subtype == SLOW_PROTO_LACP && version != LACP_VERSION)
318+
|| (proto_subtype == SLOW_PROTO_MARKER && version != MARKER_VERSION)) {
319+
print_unknown_data(ndo, tptr, "\n\t", tlen);
320+
return;
321+
}
322+
307323
while(tlen != 0) {
308324
/* is the packet big enough to include the tlv header ? */
309325
if (tlen < sizeof(struct tlv_header_t))
@@ -425,80 +441,6 @@ slow_marker_lacp_print(netdissect_options *ndo,
425441
ND_PRINT("\n\t\t packet is too short");
426442
}
427443

428-
/*
429-
* Print Link Aggregation Control Protocol. (802.3ad / 802.1AX)
430-
*/
431-
static void
432-
slow_lacp_print(netdissect_options *ndo,
433-
const u_char *tptr, u_int tlen)
434-
{
435-
u_int version;
436-
437-
if (tlen < 1)
438-
goto tooshort;
439-
440-
version = GET_U_1(tptr);
441-
tlen -= 1;
442-
tptr += 1;
443-
444-
ND_PRINT("LACPv%u, length %u", version, tlen + 2);
445-
446-
if (!ndo->ndo_vflag)
447-
return;
448-
449-
switch (version) {
450-
case LACP_VERSION:
451-
slow_marker_lacp_print(ndo, tptr, tlen, SLOW_PROTO_LACP);
452-
break;
453-
454-
/* TODO LACPv2 */
455-
456-
default:
457-
print_unknown_data(ndo, tptr, "\n\t", tlen);
458-
break;
459-
}
460-
return;
461-
462-
tooshort:
463-
ND_PRINT("\n\t\t packet is too short");
464-
}
465-
466-
/*
467-
* Print Marker protocol. (802.3ad / 802.1ax)
468-
*/
469-
static void
470-
slow_marker_print(netdissect_options *ndo,
471-
const u_char *tptr, u_int tlen)
472-
{
473-
u_int version;
474-
475-
if (tlen < 1)
476-
goto tooshort;
477-
478-
version = GET_U_1(tptr);
479-
tlen -= 1;
480-
tptr += 1;
481-
482-
ND_PRINT("MARKERv%u, length %u", version, tlen + 2);
483-
484-
if (!ndo->ndo_vflag)
485-
return;
486-
487-
switch (version) {
488-
case MARKER_VERSION:
489-
slow_marker_lacp_print(ndo, tptr, tlen, SLOW_PROTO_MARKER);
490-
break;
491-
492-
default:
493-
print_unknown_data(ndo, tptr, "\n\t", tlen);
494-
break;
495-
}
496-
return;
497-
498-
tooshort:
499-
ND_PRINT("\n\t\t packet is too short");
500-
}
501-
502444
/*
503445
* Print Operations, Administration, and Maintenance. (802.3)
504446
*/

0 commit comments

Comments
 (0)