Home | History | Annotate | Line # | Download | only in dist
print-slow.c revision 1.9
      1  1.1  christos /*
      2  1.1  christos  * Copyright (c) 1998-2006 The TCPDUMP project
      3  1.1  christos  *
      4  1.1  christos  * Redistribution and use in source and binary forms, with or without
      5  1.1  christos  * modification, are permitted provided that: (1) source code
      6  1.1  christos  * distributions retain the above copyright notice and this paragraph
      7  1.1  christos  * in its entirety, and (2) distributions including binary code include
      8  1.1  christos  * the above copyright notice and this paragraph in its entirety in
      9  1.1  christos  * the documentation or other materials provided with the distribution.
     10  1.1  christos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
     11  1.1  christos  * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
     12  1.1  christos  * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     13  1.1  christos  * FOR A PARTICULAR PURPOSE.
     14  1.1  christos  *
     15  1.1  christos  * support for the IEEE "slow protocols" LACP, MARKER as per 802.3ad
     16  1.1  christos  *                                       OAM as per 802.3ah
     17  1.1  christos  *
     18  1.9  christos  * Original code by Hannes Gredler (hannes (at) gredler.at)
     19  1.1  christos  */
     20  1.1  christos 
     21  1.2  christos #include <sys/cdefs.h>
     22  1.1  christos #ifndef lint
     23  1.9  christos __RCSID("$NetBSD: print-slow.c,v 1.9 2017/09/08 14:01:13 christos Exp $");
     24  1.1  christos #endif
     25  1.1  christos 
     26  1.8       spz /* \summary: IEEE "slow protocols" (802.3ad/802.3ah) printer */
     27  1.8       spz 
     28  1.1  christos #ifdef HAVE_CONFIG_H
     29  1.1  christos #include "config.h"
     30  1.1  christos #endif
     31  1.1  christos 
     32  1.7  christos #include <netdissect-stdinc.h>
     33  1.1  christos 
     34  1.7  christos #include "netdissect.h"
     35  1.1  christos #include "extract.h"
     36  1.1  christos #include "addrtoname.h"
     37  1.1  christos #include "ether.h"
     38  1.1  christos #include "oui.h"
     39  1.1  christos 
     40  1.1  christos #define	SLOW_PROTO_LACP                     1
     41  1.1  christos #define	SLOW_PROTO_MARKER                   2
     42  1.1  christos #define SLOW_PROTO_OAM                      3
     43  1.1  christos 
     44  1.1  christos #define	LACP_VERSION                        1
     45  1.1  christos #define	MARKER_VERSION                      1
     46  1.1  christos 
     47  1.1  christos static const struct tok slow_proto_values[] = {
     48  1.1  christos     { SLOW_PROTO_LACP, "LACP" },
     49  1.1  christos     { SLOW_PROTO_MARKER, "MARKER" },
     50  1.1  christos     { SLOW_PROTO_OAM, "OAM" },
     51  1.1  christos     { 0, NULL}
     52  1.1  christos };
     53  1.1  christos 
     54  1.1  christos static const struct tok slow_oam_flag_values[] = {
     55  1.1  christos     { 0x0001, "Link Fault" },
     56  1.1  christos     { 0x0002, "Dying Gasp" },
     57  1.1  christos     { 0x0004, "Critical Event" },
     58  1.1  christos     { 0x0008, "Local Evaluating" },
     59  1.1  christos     { 0x0010, "Local Stable" },
     60  1.1  christos     { 0x0020, "Remote Evaluating" },
     61  1.1  christos     { 0x0040, "Remote Stable" },
     62  1.1  christos     { 0, NULL}
     63  1.5  christos };
     64  1.1  christos 
     65  1.1  christos #define SLOW_OAM_CODE_INFO          0x00
     66  1.1  christos #define SLOW_OAM_CODE_EVENT_NOTIF   0x01
     67  1.1  christos #define SLOW_OAM_CODE_VAR_REQUEST   0x02
     68  1.1  christos #define SLOW_OAM_CODE_VAR_RESPONSE  0x03
     69  1.1  christos #define SLOW_OAM_CODE_LOOPBACK_CTRL 0x04
     70  1.1  christos #define SLOW_OAM_CODE_PRIVATE       0xfe
     71  1.1  christos 
     72  1.1  christos static const struct tok slow_oam_code_values[] = {
     73  1.1  christos     { SLOW_OAM_CODE_INFO, "Information" },
     74  1.1  christos     { SLOW_OAM_CODE_EVENT_NOTIF, "Event Notification" },
     75  1.1  christos     { SLOW_OAM_CODE_VAR_REQUEST, "Variable Request" },
     76  1.1  christos     { SLOW_OAM_CODE_VAR_RESPONSE, "Variable Response" },
     77  1.1  christos     { SLOW_OAM_CODE_LOOPBACK_CTRL, "Loopback Control" },
     78  1.1  christos     { SLOW_OAM_CODE_PRIVATE, "Vendor Private" },
     79  1.1  christos     { 0, NULL}
     80  1.1  christos };
     81  1.1  christos 
     82  1.1  christos struct slow_oam_info_t {
     83  1.5  christos     uint8_t info_type;
     84  1.5  christos     uint8_t info_length;
     85  1.5  christos     uint8_t oam_version;
     86  1.5  christos     uint8_t revision[2];
     87  1.5  christos     uint8_t state;
     88  1.5  christos     uint8_t oam_config;
     89  1.5  christos     uint8_t oam_pdu_config[2];
     90  1.5  christos     uint8_t oui[3];
     91  1.5  christos     uint8_t vendor_private[4];
     92  1.1  christos };
     93  1.1  christos 
     94  1.1  christos #define SLOW_OAM_INFO_TYPE_END_OF_TLV 0x00
     95  1.1  christos #define SLOW_OAM_INFO_TYPE_LOCAL 0x01
     96  1.1  christos #define SLOW_OAM_INFO_TYPE_REMOTE 0x02
     97  1.1  christos #define SLOW_OAM_INFO_TYPE_ORG_SPECIFIC 0xfe
     98  1.1  christos 
     99  1.1  christos static const struct tok slow_oam_info_type_values[] = {
    100  1.1  christos     { SLOW_OAM_INFO_TYPE_END_OF_TLV, "End of TLV marker" },
    101  1.1  christos     { SLOW_OAM_INFO_TYPE_LOCAL, "Local" },
    102  1.1  christos     { SLOW_OAM_INFO_TYPE_REMOTE, "Remote" },
    103  1.1  christos     { SLOW_OAM_INFO_TYPE_ORG_SPECIFIC, "Organization specific" },
    104  1.1  christos     { 0, NULL}
    105  1.1  christos };
    106  1.1  christos 
    107  1.1  christos #define OAM_INFO_TYPE_PARSER_MASK 0x3
    108  1.1  christos static const struct tok slow_oam_info_type_state_parser_values[] = {
    109  1.1  christos     { 0x00, "forwarding" },
    110  1.1  christos     { 0x01, "looping back" },
    111  1.1  christos     { 0x02, "discarding" },
    112  1.1  christos     { 0x03, "reserved" },
    113  1.1  christos     { 0, NULL}
    114  1.1  christos };
    115  1.1  christos 
    116  1.1  christos #define OAM_INFO_TYPE_MUX_MASK 0x4
    117  1.1  christos static const struct tok slow_oam_info_type_state_mux_values[] = {
    118  1.1  christos     { 0x00, "forwarding" },
    119  1.1  christos     { 0x04, "discarding" },
    120  1.1  christos     { 0, NULL}
    121  1.1  christos };
    122  1.1  christos 
    123  1.1  christos static const struct tok slow_oam_info_type_oam_config_values[] = {
    124  1.1  christos     { 0x01, "Active" },
    125  1.1  christos     { 0x02, "Unidirectional" },
    126  1.1  christos     { 0x04, "Remote-Loopback" },
    127  1.1  christos     { 0x08, "Link-Events" },
    128  1.1  christos     { 0x10, "Variable-Retrieval" },
    129  1.1  christos     { 0, NULL}
    130  1.1  christos };
    131  1.1  christos 
    132  1.1  christos /* 11 Bits */
    133  1.1  christos #define OAM_INFO_TYPE_PDU_SIZE_MASK 0x7ff
    134  1.1  christos 
    135  1.1  christos #define SLOW_OAM_LINK_EVENT_END_OF_TLV 0x00
    136  1.1  christos #define SLOW_OAM_LINK_EVENT_ERR_SYM_PER 0x01
    137  1.1  christos #define SLOW_OAM_LINK_EVENT_ERR_FRM 0x02
    138  1.1  christos #define SLOW_OAM_LINK_EVENT_ERR_FRM_PER 0x03
    139  1.1  christos #define SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM 0x04
    140  1.1  christos #define SLOW_OAM_LINK_EVENT_ORG_SPECIFIC 0xfe
    141  1.1  christos 
    142  1.1  christos static const struct tok slow_oam_link_event_values[] = {
    143  1.1  christos     { SLOW_OAM_LINK_EVENT_END_OF_TLV, "End of TLV marker" },
    144  1.1  christos     { SLOW_OAM_LINK_EVENT_ERR_SYM_PER, "Errored Symbol Period Event" },
    145  1.1  christos     { SLOW_OAM_LINK_EVENT_ERR_FRM, "Errored Frame Event" },
    146  1.1  christos     { SLOW_OAM_LINK_EVENT_ERR_FRM_PER, "Errored Frame Period Event" },
    147  1.1  christos     { SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM, "Errored Frame Seconds Summary Event" },
    148  1.1  christos     { SLOW_OAM_LINK_EVENT_ORG_SPECIFIC, "Organization specific" },
    149  1.1  christos     { 0, NULL}
    150  1.1  christos };
    151  1.1  christos 
    152  1.1  christos struct slow_oam_link_event_t {
    153  1.5  christos     uint8_t event_type;
    154  1.5  christos     uint8_t event_length;
    155  1.5  christos     uint8_t time_stamp[2];
    156  1.5  christos     uint8_t window[8];
    157  1.5  christos     uint8_t threshold[8];
    158  1.5  christos     uint8_t errors[8];
    159  1.5  christos     uint8_t errors_running_total[8];
    160  1.5  christos     uint8_t event_running_total[4];
    161  1.1  christos };
    162  1.1  christos 
    163  1.1  christos struct slow_oam_variablerequest_t {
    164  1.5  christos     uint8_t branch;
    165  1.5  christos     uint8_t leaf[2];
    166  1.1  christos };
    167  1.1  christos 
    168  1.1  christos struct slow_oam_variableresponse_t {
    169  1.5  christos     uint8_t branch;
    170  1.5  christos     uint8_t leaf[2];
    171  1.5  christos     uint8_t length;
    172  1.1  christos };
    173  1.1  christos 
    174  1.1  christos struct slow_oam_loopbackctrl_t {
    175  1.5  christos     uint8_t command;
    176  1.1  christos };
    177  1.1  christos 
    178  1.1  christos static const struct tok slow_oam_loopbackctrl_cmd_values[] = {
    179  1.1  christos     { 0x01, "Enable OAM Remote Loopback" },
    180  1.1  christos     { 0x02, "Disable OAM Remote Loopback" },
    181  1.1  christos     { 0, NULL}
    182  1.1  christos };
    183  1.1  christos 
    184  1.1  christos struct tlv_header_t {
    185  1.5  christos     uint8_t type;
    186  1.5  christos     uint8_t length;
    187  1.1  christos };
    188  1.1  christos 
    189  1.8       spz #define LACP_MARKER_TLV_TERMINATOR     0x00  /* same code for LACP and Marker */
    190  1.8       spz 
    191  1.8       spz #define LACP_TLV_ACTOR_INFO            0x01
    192  1.8       spz #define LACP_TLV_PARTNER_INFO          0x02
    193  1.8       spz #define LACP_TLV_COLLECTOR_INFO        0x03
    194  1.1  christos 
    195  1.8       spz #define MARKER_TLV_MARKER_INFO         0x01
    196  1.1  christos 
    197  1.1  christos static const struct tok slow_tlv_values[] = {
    198  1.8       spz     { (SLOW_PROTO_LACP << 8) + LACP_MARKER_TLV_TERMINATOR, "Terminator"},
    199  1.1  christos     { (SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO, "Actor Information"},
    200  1.1  christos     { (SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO, "Partner Information"},
    201  1.1  christos     { (SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO, "Collector Information"},
    202  1.1  christos 
    203  1.8       spz     { (SLOW_PROTO_MARKER << 8) + LACP_MARKER_TLV_TERMINATOR, "Terminator"},
    204  1.1  christos     { (SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO, "Marker Information"},
    205  1.1  christos     { 0, NULL}
    206  1.1  christos };
    207  1.1  christos 
    208  1.1  christos struct lacp_tlv_actor_partner_info_t {
    209  1.5  christos     uint8_t sys_pri[2];
    210  1.5  christos     uint8_t sys[ETHER_ADDR_LEN];
    211  1.5  christos     uint8_t key[2];
    212  1.5  christos     uint8_t port_pri[2];
    213  1.5  christos     uint8_t port[2];
    214  1.5  christos     uint8_t state;
    215  1.5  christos     uint8_t pad[3];
    216  1.5  christos };
    217  1.1  christos 
    218  1.1  christos static const struct tok lacp_tlv_actor_partner_info_state_values[] = {
    219  1.1  christos     { 0x01, "Activity"},
    220  1.1  christos     { 0x02, "Timeout"},
    221  1.1  christos     { 0x04, "Aggregation"},
    222  1.1  christos     { 0x08, "Synchronization"},
    223  1.1  christos     { 0x10, "Collecting"},
    224  1.1  christos     { 0x20, "Distributing"},
    225  1.1  christos     { 0x40, "Default"},
    226  1.1  christos     { 0x80, "Expired"},
    227  1.1  christos     { 0, NULL}
    228  1.1  christos };
    229  1.1  christos 
    230  1.1  christos struct lacp_tlv_collector_info_t {
    231  1.5  christos     uint8_t max_delay[2];
    232  1.5  christos     uint8_t pad[12];
    233  1.5  christos };
    234  1.1  christos 
    235  1.1  christos struct marker_tlv_marker_info_t {
    236  1.5  christos     uint8_t req_port[2];
    237  1.5  christos     uint8_t req_sys[ETHER_ADDR_LEN];
    238  1.5  christos     uint8_t req_trans_id[4];
    239  1.5  christos     uint8_t pad[2];
    240  1.5  christos };
    241  1.1  christos 
    242  1.1  christos struct lacp_marker_tlv_terminator_t {
    243  1.5  christos     uint8_t pad[50];
    244  1.5  christos };
    245  1.1  christos 
    246  1.8       spz static void slow_marker_lacp_print(netdissect_options *, register const u_char *, register u_int, u_int);
    247  1.5  christos static void slow_oam_print(netdissect_options *, register const u_char *, register u_int);
    248  1.1  christos 
    249  1.1  christos void
    250  1.5  christos slow_print(netdissect_options *ndo,
    251  1.6  christos            register const u_char *pptr, register u_int len)
    252  1.6  christos {
    253  1.1  christos     int print_version;
    254  1.8       spz     u_int subtype;
    255  1.1  christos 
    256  1.8       spz     if (len < 1)
    257  1.8       spz         goto tooshort;
    258  1.8       spz     ND_TCHECK(*pptr);
    259  1.8       spz     subtype = *pptr;
    260  1.1  christos 
    261  1.1  christos     /*
    262  1.1  christos      * Sanity checking of the header.
    263  1.1  christos      */
    264  1.8       spz     switch (subtype) {
    265  1.1  christos     case SLOW_PROTO_LACP:
    266  1.8       spz         if (len < 2)
    267  1.8       spz             goto tooshort;
    268  1.8       spz         ND_TCHECK(*(pptr+1));
    269  1.8       spz         if (*(pptr+1) != LACP_VERSION) {
    270  1.8       spz             ND_PRINT((ndo, "LACP version %u packet not supported", *(pptr+1)));
    271  1.1  christos             return;
    272  1.1  christos         }
    273  1.1  christos         print_version = 1;
    274  1.1  christos         break;
    275  1.1  christos 
    276  1.1  christos     case SLOW_PROTO_MARKER:
    277  1.8       spz         if (len < 2)
    278  1.8       spz             goto tooshort;
    279  1.8       spz         ND_TCHECK(*(pptr+1));
    280  1.8       spz         if (*(pptr+1) != MARKER_VERSION) {
    281  1.8       spz             ND_PRINT((ndo, "MARKER version %u packet not supported", *(pptr+1)));
    282  1.1  christos             return;
    283  1.1  christos         }
    284  1.1  christos         print_version = 1;
    285  1.1  christos         break;
    286  1.1  christos 
    287  1.1  christos     case SLOW_PROTO_OAM: /* fall through */
    288  1.1  christos         print_version = 0;
    289  1.1  christos         break;
    290  1.1  christos 
    291  1.1  christos     default:
    292  1.1  christos         /* print basic information and exit */
    293  1.1  christos         print_version = -1;
    294  1.1  christos         break;
    295  1.1  christos     }
    296  1.1  christos 
    297  1.8       spz     if (print_version == 1) {
    298  1.5  christos         ND_PRINT((ndo, "%sv%u, length %u",
    299  1.8       spz                tok2str(slow_proto_values, "unknown (%u)", subtype),
    300  1.8       spz                *(pptr+1),
    301  1.5  christos                len));
    302  1.1  christos     } else {
    303  1.1  christos         /* some slow protos don't have a version number in the header */
    304  1.5  christos         ND_PRINT((ndo, "%s, length %u",
    305  1.8       spz                tok2str(slow_proto_values, "unknown (%u)", subtype),
    306  1.5  christos                len));
    307  1.1  christos     }
    308  1.1  christos 
    309  1.1  christos     /* unrecognized subtype */
    310  1.1  christos     if (print_version == -1) {
    311  1.5  christos         print_unknown_data(ndo, pptr, "\n\t", len);
    312  1.1  christos         return;
    313  1.1  christos     }
    314  1.1  christos 
    315  1.5  christos     if (!ndo->ndo_vflag)
    316  1.1  christos         return;
    317  1.1  christos 
    318  1.8       spz     switch (subtype) {
    319  1.1  christos     default: /* should not happen */
    320  1.1  christos         break;
    321  1.1  christos 
    322  1.1  christos     case SLOW_PROTO_OAM:
    323  1.8       spz         /* skip subtype */
    324  1.8       spz         len -= 1;
    325  1.8       spz         pptr += 1;
    326  1.8       spz         slow_oam_print(ndo, pptr, len);
    327  1.1  christos         break;
    328  1.1  christos 
    329  1.1  christos     case SLOW_PROTO_LACP:   /* LACP and MARKER share the same semantics */
    330  1.1  christos     case SLOW_PROTO_MARKER:
    331  1.8       spz         /* skip subtype and version */
    332  1.8       spz         len -= 2;
    333  1.8       spz         pptr += 2;
    334  1.8       spz         slow_marker_lacp_print(ndo, pptr, len, subtype);
    335  1.1  christos         break;
    336  1.1  christos     }
    337  1.1  christos     return;
    338  1.1  christos 
    339  1.8       spz tooshort:
    340  1.8       spz     if (!ndo->ndo_vflag)
    341  1.8       spz         ND_PRINT((ndo, " (packet is too short)"));
    342  1.8       spz     else
    343  1.8       spz         ND_PRINT((ndo, "\n\t\t packet is too short"));
    344  1.8       spz     return;
    345  1.8       spz 
    346  1.1  christos trunc:
    347  1.8       spz     if (!ndo->ndo_vflag)
    348  1.8       spz         ND_PRINT((ndo, " (packet exceeded snapshot)"));
    349  1.8       spz     else
    350  1.8       spz         ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
    351  1.1  christos }
    352  1.1  christos 
    353  1.5  christos static void
    354  1.5  christos slow_marker_lacp_print(netdissect_options *ndo,
    355  1.8       spz                        register const u_char *tptr, register u_int tlen,
    356  1.8       spz                        u_int proto_subtype)
    357  1.6  christos {
    358  1.1  christos     const struct tlv_header_t *tlv_header;
    359  1.1  christos     const u_char *tlv_tptr;
    360  1.1  christos     u_int tlv_len, tlv_tlen;
    361  1.1  christos 
    362  1.1  christos     union {
    363  1.1  christos         const struct lacp_marker_tlv_terminator_t *lacp_marker_tlv_terminator;
    364  1.1  christos         const struct lacp_tlv_actor_partner_info_t *lacp_tlv_actor_partner_info;
    365  1.1  christos         const struct lacp_tlv_collector_info_t *lacp_tlv_collector_info;
    366  1.1  christos         const struct marker_tlv_marker_info_t *marker_tlv_marker_info;
    367  1.1  christos     } tlv_ptr;
    368  1.5  christos 
    369  1.1  christos     while(tlen>0) {
    370  1.8       spz         /* is the packet big enough to include the tlv header ? */
    371  1.8       spz         if (tlen < sizeof(struct tlv_header_t))
    372  1.8       spz             goto tooshort;
    373  1.1  christos         /* did we capture enough for fully decoding the tlv header ? */
    374  1.5  christos         ND_TCHECK2(*tptr, sizeof(struct tlv_header_t));
    375  1.1  christos         tlv_header = (const struct tlv_header_t *)tptr;
    376  1.1  christos         tlv_len = tlv_header->length;
    377  1.1  christos 
    378  1.5  christos         ND_PRINT((ndo, "\n\t%s TLV (0x%02x), length %u",
    379  1.1  christos                tok2str(slow_tlv_values,
    380  1.1  christos                        "Unknown",
    381  1.8       spz                        (proto_subtype << 8) + tlv_header->type),
    382  1.1  christos                tlv_header->type,
    383  1.5  christos                tlv_len));
    384  1.1  christos 
    385  1.8       spz         if (tlv_header->type == LACP_MARKER_TLV_TERMINATOR) {
    386  1.8       spz             /*
    387  1.8       spz              * This TLV has a length of zero, and means there are no
    388  1.8       spz              * more TLVs to process.
    389  1.8       spz              */
    390  1.1  christos             return;
    391  1.1  christos         }
    392  1.1  christos 
    393  1.8       spz         /* length includes the type and length fields */
    394  1.8       spz         if (tlv_len < sizeof(struct tlv_header_t)) {
    395  1.8       spz             ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be >= %lu",
    396  1.8       spz                    (unsigned long) sizeof(struct tlv_header_t)));
    397  1.8       spz             return;
    398  1.8       spz         }
    399  1.1  christos 
    400  1.8       spz         /* is the packet big enough to include the tlv ? */
    401  1.8       spz         if (tlen < tlv_len)
    402  1.8       spz             goto tooshort;
    403  1.1  christos         /* did we capture enough for fully decoding the tlv ? */
    404  1.5  christos         ND_TCHECK2(*tptr, tlv_len);
    405  1.1  christos 
    406  1.8       spz         tlv_tptr=tptr+sizeof(struct tlv_header_t);
    407  1.8       spz         tlv_tlen=tlv_len-sizeof(struct tlv_header_t);
    408  1.8       spz 
    409  1.8       spz         switch((proto_subtype << 8) + tlv_header->type) {
    410  1.1  christos 
    411  1.1  christos             /* those two TLVs have the same structure -> fall through */
    412  1.1  christos         case ((SLOW_PROTO_LACP << 8) + LACP_TLV_ACTOR_INFO):
    413  1.1  christos         case ((SLOW_PROTO_LACP << 8) + LACP_TLV_PARTNER_INFO):
    414  1.8       spz             if (tlv_tlen !=
    415  1.8       spz                 sizeof(struct lacp_tlv_actor_partner_info_t)) {
    416  1.8       spz                 ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be %lu",
    417  1.8       spz                        (unsigned long) (sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_actor_partner_info_t))));
    418  1.8       spz                 goto badlength;
    419  1.8       spz             }
    420  1.8       spz 
    421  1.1  christos             tlv_ptr.lacp_tlv_actor_partner_info = (const struct lacp_tlv_actor_partner_info_t *)tlv_tptr;
    422  1.1  christos 
    423  1.5  christos             ND_PRINT((ndo, "\n\t  System %s, System Priority %u, Key %u" \
    424  1.1  christos                    ", Port %u, Port Priority %u\n\t  State Flags [%s]",
    425  1.5  christos                    etheraddr_string(ndo, tlv_ptr.lacp_tlv_actor_partner_info->sys),
    426  1.1  christos                    EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->sys_pri),
    427  1.1  christos                    EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->key),
    428  1.1  christos                    EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->port),
    429  1.1  christos                    EXTRACT_16BITS(tlv_ptr.lacp_tlv_actor_partner_info->port_pri),
    430  1.1  christos                    bittok2str(lacp_tlv_actor_partner_info_state_values,
    431  1.1  christos                               "none",
    432  1.5  christos                               tlv_ptr.lacp_tlv_actor_partner_info->state)));
    433  1.1  christos 
    434  1.1  christos             break;
    435  1.1  christos 
    436  1.1  christos         case ((SLOW_PROTO_LACP << 8) + LACP_TLV_COLLECTOR_INFO):
    437  1.8       spz             if (tlv_tlen !=
    438  1.8       spz                 sizeof(struct lacp_tlv_collector_info_t)) {
    439  1.8       spz                 ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be %lu",
    440  1.8       spz                        (unsigned long) (sizeof(struct tlv_header_t) + sizeof(struct lacp_tlv_collector_info_t))));
    441  1.8       spz                 goto badlength;
    442  1.8       spz             }
    443  1.8       spz 
    444  1.1  christos             tlv_ptr.lacp_tlv_collector_info = (const struct lacp_tlv_collector_info_t *)tlv_tptr;
    445  1.1  christos 
    446  1.5  christos             ND_PRINT((ndo, "\n\t  Max Delay %u",
    447  1.5  christos                    EXTRACT_16BITS(tlv_ptr.lacp_tlv_collector_info->max_delay)));
    448  1.1  christos 
    449  1.1  christos             break;
    450  1.1  christos 
    451  1.1  christos         case ((SLOW_PROTO_MARKER << 8) + MARKER_TLV_MARKER_INFO):
    452  1.8       spz             if (tlv_tlen !=
    453  1.8       spz                 sizeof(struct marker_tlv_marker_info_t)) {
    454  1.8       spz                 ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be %lu",
    455  1.8       spz                        (unsigned long) (sizeof(struct tlv_header_t) + sizeof(struct marker_tlv_marker_info_t))));
    456  1.8       spz                 goto badlength;
    457  1.8       spz             }
    458  1.8       spz 
    459  1.1  christos             tlv_ptr.marker_tlv_marker_info = (const struct marker_tlv_marker_info_t *)tlv_tptr;
    460  1.1  christos 
    461  1.5  christos             ND_PRINT((ndo, "\n\t  Request System %s, Request Port %u, Request Transaction ID 0x%08x",
    462  1.5  christos                    etheraddr_string(ndo, tlv_ptr.marker_tlv_marker_info->req_sys),
    463  1.1  christos                    EXTRACT_16BITS(tlv_ptr.marker_tlv_marker_info->req_port),
    464  1.5  christos                    EXTRACT_32BITS(tlv_ptr.marker_tlv_marker_info->req_trans_id)));
    465  1.1  christos 
    466  1.1  christos             break;
    467  1.1  christos 
    468  1.1  christos         default:
    469  1.5  christos             if (ndo->ndo_vflag <= 1)
    470  1.5  christos                 print_unknown_data(ndo, tlv_tptr, "\n\t  ", tlv_tlen);
    471  1.1  christos             break;
    472  1.1  christos         }
    473  1.8       spz 
    474  1.8       spz     badlength:
    475  1.1  christos         /* do we want to see an additional hexdump ? */
    476  1.5  christos         if (ndo->ndo_vflag > 1) {
    477  1.5  christos             print_unknown_data(ndo, tptr+sizeof(struct tlv_header_t), "\n\t  ",
    478  1.1  christos                                tlv_len-sizeof(struct tlv_header_t));
    479  1.1  christos         }
    480  1.1  christos 
    481  1.1  christos         tptr+=tlv_len;
    482  1.1  christos         tlen-=tlv_len;
    483  1.1  christos     }
    484  1.1  christos     return;
    485  1.8       spz 
    486  1.8       spz tooshort:
    487  1.8       spz     ND_PRINT((ndo, "\n\t\t packet is too short"));
    488  1.8       spz     return;
    489  1.8       spz 
    490  1.1  christos trunc:
    491  1.5  christos     ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
    492  1.1  christos }
    493  1.1  christos 
    494  1.5  christos static void
    495  1.5  christos slow_oam_print(netdissect_options *ndo,
    496  1.6  christos                register const u_char *tptr, register u_int tlen)
    497  1.6  christos {
    498  1.1  christos     u_int hexdump;
    499  1.1  christos 
    500  1.1  christos     struct slow_oam_common_header_t {
    501  1.5  christos         uint8_t flags[2];
    502  1.5  christos         uint8_t code;
    503  1.1  christos     };
    504  1.1  christos 
    505  1.1  christos     struct slow_oam_tlv_header_t {
    506  1.5  christos         uint8_t type;
    507  1.5  christos         uint8_t length;
    508  1.1  christos     };
    509  1.1  christos 
    510  1.1  christos     union {
    511  1.1  christos         const struct slow_oam_common_header_t *slow_oam_common_header;
    512  1.1  christos         const struct slow_oam_tlv_header_t *slow_oam_tlv_header;
    513  1.1  christos     } ptr;
    514  1.1  christos 
    515  1.1  christos     union {
    516  1.1  christos 	const struct slow_oam_info_t *slow_oam_info;
    517  1.1  christos         const struct slow_oam_link_event_t *slow_oam_link_event;
    518  1.1  christos         const struct slow_oam_variablerequest_t *slow_oam_variablerequest;
    519  1.1  christos         const struct slow_oam_variableresponse_t *slow_oam_variableresponse;
    520  1.1  christos         const struct slow_oam_loopbackctrl_t *slow_oam_loopbackctrl;
    521  1.1  christos     } tlv;
    522  1.5  christos 
    523  1.7  christos     ptr.slow_oam_common_header = (const struct slow_oam_common_header_t *)tptr;
    524  1.8       spz     if (tlen < sizeof(*ptr.slow_oam_common_header))
    525  1.8       spz         goto tooshort;
    526  1.8       spz     ND_TCHECK(*ptr.slow_oam_common_header);
    527  1.1  christos     tptr += sizeof(struct slow_oam_common_header_t);
    528  1.1  christos     tlen -= sizeof(struct slow_oam_common_header_t);
    529  1.1  christos 
    530  1.5  christos     ND_PRINT((ndo, "\n\tCode %s OAM PDU, Flags [%s]",
    531  1.1  christos            tok2str(slow_oam_code_values, "Unknown (%u)", ptr.slow_oam_common_header->code),
    532  1.1  christos            bittok2str(slow_oam_flag_values,
    533  1.1  christos                       "none",
    534  1.5  christos                       EXTRACT_16BITS(&ptr.slow_oam_common_header->flags))));
    535  1.1  christos 
    536  1.1  christos     switch (ptr.slow_oam_common_header->code) {
    537  1.1  christos     case SLOW_OAM_CODE_INFO:
    538  1.1  christos         while (tlen > 0) {
    539  1.1  christos             ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
    540  1.8       spz             if (tlen < sizeof(*ptr.slow_oam_tlv_header))
    541  1.8       spz                 goto tooshort;
    542  1.8       spz             ND_TCHECK(*ptr.slow_oam_tlv_header);
    543  1.5  christos             ND_PRINT((ndo, "\n\t  %s Information Type (%u), length %u",
    544  1.1  christos                    tok2str(slow_oam_info_type_values, "Reserved",
    545  1.1  christos                            ptr.slow_oam_tlv_header->type),
    546  1.1  christos                    ptr.slow_oam_tlv_header->type,
    547  1.5  christos                    ptr.slow_oam_tlv_header->length));
    548  1.1  christos 
    549  1.8       spz             if (ptr.slow_oam_tlv_header->type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
    550  1.8       spz                 /*
    551  1.8       spz                  * As IEEE Std 802.3-2015 says for the End of TLV Marker,
    552  1.8       spz                  * "(the length and value of the Type 0x00 TLV can be ignored)".
    553  1.8       spz                  */
    554  1.8       spz                 return;
    555  1.8       spz             }
    556  1.8       spz 
    557  1.8       spz             /* length includes the type and length fields */
    558  1.8       spz             if (ptr.slow_oam_tlv_header->length < sizeof(struct slow_oam_tlv_header_t)) {
    559  1.8       spz                 ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be >= %u",
    560  1.8       spz                        (u_int)sizeof(struct slow_oam_tlv_header_t)));
    561  1.8       spz                 return;
    562  1.8       spz             }
    563  1.8       spz 
    564  1.8       spz             if (tlen < ptr.slow_oam_tlv_header->length)
    565  1.8       spz                 goto tooshort;
    566  1.8       spz             ND_TCHECK2(*tptr, ptr.slow_oam_tlv_header->length);
    567  1.8       spz 
    568  1.1  christos             hexdump = FALSE;
    569  1.1  christos             switch (ptr.slow_oam_tlv_header->type) {
    570  1.1  christos             case SLOW_OAM_INFO_TYPE_LOCAL: /* identical format - fall through */
    571  1.1  christos             case SLOW_OAM_INFO_TYPE_REMOTE:
    572  1.1  christos                 tlv.slow_oam_info = (const struct slow_oam_info_t *)tptr;
    573  1.5  christos 
    574  1.1  christos                 if (tlv.slow_oam_info->info_length !=
    575  1.1  christos                     sizeof(struct slow_oam_info_t)) {
    576  1.5  christos                     ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be %lu",
    577  1.5  christos                            (unsigned long) sizeof(struct slow_oam_info_t)));
    578  1.8       spz                     hexdump = TRUE;
    579  1.8       spz                     goto badlength_code_info;
    580  1.1  christos                 }
    581  1.1  christos 
    582  1.5  christos                 ND_PRINT((ndo, "\n\t    OAM-Version %u, Revision %u",
    583  1.1  christos                        tlv.slow_oam_info->oam_version,
    584  1.5  christos                        EXTRACT_16BITS(&tlv.slow_oam_info->revision)));
    585  1.1  christos 
    586  1.5  christos                 ND_PRINT((ndo, "\n\t    State-Parser-Action %s, State-MUX-Action %s",
    587  1.1  christos                        tok2str(slow_oam_info_type_state_parser_values, "Reserved",
    588  1.1  christos                                tlv.slow_oam_info->state & OAM_INFO_TYPE_PARSER_MASK),
    589  1.1  christos                        tok2str(slow_oam_info_type_state_mux_values, "Reserved",
    590  1.5  christos                                tlv.slow_oam_info->state & OAM_INFO_TYPE_MUX_MASK)));
    591  1.5  christos                 ND_PRINT((ndo, "\n\t    OAM-Config Flags [%s], OAM-PDU-Config max-PDU size %u",
    592  1.1  christos                        bittok2str(slow_oam_info_type_oam_config_values, "none",
    593  1.1  christos                                   tlv.slow_oam_info->oam_config),
    594  1.1  christos                        EXTRACT_16BITS(&tlv.slow_oam_info->oam_pdu_config) &
    595  1.5  christos                        OAM_INFO_TYPE_PDU_SIZE_MASK));
    596  1.5  christos                 ND_PRINT((ndo, "\n\t    OUI %s (0x%06x), Vendor-Private 0x%08x",
    597  1.1  christos                        tok2str(oui_values, "Unknown",
    598  1.1  christos                                EXTRACT_24BITS(&tlv.slow_oam_info->oui)),
    599  1.1  christos                        EXTRACT_24BITS(&tlv.slow_oam_info->oui),
    600  1.5  christos                        EXTRACT_32BITS(&tlv.slow_oam_info->vendor_private)));
    601  1.1  christos                 break;
    602  1.5  christos 
    603  1.1  christos             case SLOW_OAM_INFO_TYPE_ORG_SPECIFIC:
    604  1.1  christos                 hexdump = TRUE;
    605  1.1  christos                 break;
    606  1.5  christos 
    607  1.1  christos             default:
    608  1.1  christos                 hexdump = TRUE;
    609  1.1  christos                 break;
    610  1.1  christos             }
    611  1.1  christos 
    612  1.8       spz         badlength_code_info:
    613  1.1  christos             /* do we also want to see a hex dump ? */
    614  1.5  christos             if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
    615  1.5  christos                 print_unknown_data(ndo, tptr, "\n\t  ",
    616  1.1  christos                                    ptr.slow_oam_tlv_header->length);
    617  1.1  christos             }
    618  1.1  christos 
    619  1.1  christos             tlen -= ptr.slow_oam_tlv_header->length;
    620  1.1  christos             tptr += ptr.slow_oam_tlv_header->length;
    621  1.1  christos         }
    622  1.1  christos         break;
    623  1.1  christos 
    624  1.1  christos     case SLOW_OAM_CODE_EVENT_NOTIF:
    625  1.8       spz         /* Sequence number */
    626  1.8       spz         if (tlen < 2)
    627  1.8       spz             goto tooshort;
    628  1.8       spz         ND_TCHECK2(*tptr, 2);
    629  1.8       spz         ND_PRINT((ndo, "\n\t  Sequence Number %u", EXTRACT_16BITS(tptr)));
    630  1.8       spz         tlen -= 2;
    631  1.8       spz         tptr += 2;
    632  1.8       spz 
    633  1.8       spz         /* TLVs */
    634  1.1  christos         while (tlen > 0) {
    635  1.1  christos             ptr.slow_oam_tlv_header = (const struct slow_oam_tlv_header_t *)tptr;
    636  1.8       spz             if (tlen < sizeof(*ptr.slow_oam_tlv_header))
    637  1.8       spz                 goto tooshort;
    638  1.8       spz             ND_TCHECK(*ptr.slow_oam_tlv_header);
    639  1.5  christos             ND_PRINT((ndo, "\n\t  %s Link Event Type (%u), length %u",
    640  1.1  christos                    tok2str(slow_oam_link_event_values, "Reserved",
    641  1.1  christos                            ptr.slow_oam_tlv_header->type),
    642  1.1  christos                    ptr.slow_oam_tlv_header->type,
    643  1.5  christos                    ptr.slow_oam_tlv_header->length));
    644  1.1  christos 
    645  1.8       spz             if (ptr.slow_oam_tlv_header->type == SLOW_OAM_INFO_TYPE_END_OF_TLV) {
    646  1.8       spz                 /*
    647  1.8       spz                  * As IEEE Std 802.3-2015 says for the End of TLV Marker,
    648  1.8       spz                  * "(the length and value of the Type 0x00 TLV can be ignored)".
    649  1.8       spz                  */
    650  1.8       spz                 return;
    651  1.8       spz             }
    652  1.8       spz 
    653  1.8       spz             /* length includes the type and length fields */
    654  1.8       spz             if (ptr.slow_oam_tlv_header->length < sizeof(struct slow_oam_tlv_header_t)) {
    655  1.8       spz                 ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be >= %u",
    656  1.8       spz                        (u_int)sizeof(struct slow_oam_tlv_header_t)));
    657  1.8       spz                 return;
    658  1.8       spz             }
    659  1.8       spz 
    660  1.8       spz             if (tlen < ptr.slow_oam_tlv_header->length)
    661  1.8       spz                 goto tooshort;
    662  1.8       spz             ND_TCHECK2(*tptr, ptr.slow_oam_tlv_header->length);
    663  1.8       spz 
    664  1.1  christos             hexdump = FALSE;
    665  1.1  christos             switch (ptr.slow_oam_tlv_header->type) {
    666  1.1  christos             case SLOW_OAM_LINK_EVENT_ERR_SYM_PER: /* identical format - fall through */
    667  1.1  christos             case SLOW_OAM_LINK_EVENT_ERR_FRM:
    668  1.1  christos             case SLOW_OAM_LINK_EVENT_ERR_FRM_PER:
    669  1.1  christos             case SLOW_OAM_LINK_EVENT_ERR_FRM_SUMM:
    670  1.1  christos                 tlv.slow_oam_link_event = (const struct slow_oam_link_event_t *)tptr;
    671  1.5  christos 
    672  1.1  christos                 if (tlv.slow_oam_link_event->event_length !=
    673  1.1  christos                     sizeof(struct slow_oam_link_event_t)) {
    674  1.5  christos                     ND_PRINT((ndo, "\n\t    ERROR: illegal length - should be %lu",
    675  1.5  christos                            (unsigned long) sizeof(struct slow_oam_link_event_t)));
    676  1.8       spz                     hexdump = TRUE;
    677  1.8       spz                     goto badlength_event_notif;
    678  1.1  christos                 }
    679  1.1  christos 
    680  1.5  christos                 ND_PRINT((ndo, "\n\t    Timestamp %u ms, Errored Window %" PRIu64
    681  1.1  christos                        "\n\t    Errored Threshold %" PRIu64
    682  1.1  christos                        "\n\t    Errors %" PRIu64
    683  1.1  christos                        "\n\t    Error Running Total %" PRIu64
    684  1.1  christos                        "\n\t    Event Running Total %u",
    685  1.1  christos                        EXTRACT_16BITS(&tlv.slow_oam_link_event->time_stamp)*100,
    686  1.1  christos                        EXTRACT_64BITS(&tlv.slow_oam_link_event->window),
    687  1.1  christos                        EXTRACT_64BITS(&tlv.slow_oam_link_event->threshold),
    688  1.1  christos                        EXTRACT_64BITS(&tlv.slow_oam_link_event->errors),
    689  1.1  christos                        EXTRACT_64BITS(&tlv.slow_oam_link_event->errors_running_total),
    690  1.5  christos                        EXTRACT_32BITS(&tlv.slow_oam_link_event->event_running_total)));
    691  1.1  christos                 break;
    692  1.5  christos 
    693  1.1  christos             case SLOW_OAM_LINK_EVENT_ORG_SPECIFIC:
    694  1.1  christos                 hexdump = TRUE;
    695  1.1  christos                 break;
    696  1.5  christos 
    697  1.1  christos             default:
    698  1.1  christos                 hexdump = TRUE;
    699  1.1  christos                 break;
    700  1.1  christos             }
    701  1.1  christos 
    702  1.8       spz         badlength_event_notif:
    703  1.1  christos             /* do we also want to see a hex dump ? */
    704  1.5  christos             if (ndo->ndo_vflag > 1 || hexdump==TRUE) {
    705  1.5  christos                 print_unknown_data(ndo, tptr, "\n\t  ",
    706  1.1  christos                                    ptr.slow_oam_tlv_header->length);
    707  1.1  christos             }
    708  1.1  christos 
    709  1.1  christos             tlen -= ptr.slow_oam_tlv_header->length;
    710  1.1  christos             tptr += ptr.slow_oam_tlv_header->length;
    711  1.1  christos         }
    712  1.1  christos         break;
    713  1.5  christos 
    714  1.1  christos     case SLOW_OAM_CODE_LOOPBACK_CTRL:
    715  1.1  christos         tlv.slow_oam_loopbackctrl = (const struct slow_oam_loopbackctrl_t *)tptr;
    716  1.8       spz         if (tlen < sizeof(*tlv.slow_oam_loopbackctrl))
    717  1.8       spz             goto tooshort;
    718  1.8       spz         ND_TCHECK(*tlv.slow_oam_loopbackctrl);
    719  1.5  christos         ND_PRINT((ndo, "\n\t  Command %s (%u)",
    720  1.1  christos                tok2str(slow_oam_loopbackctrl_cmd_values,
    721  1.1  christos                        "Unknown",
    722  1.1  christos                        tlv.slow_oam_loopbackctrl->command),
    723  1.5  christos                tlv.slow_oam_loopbackctrl->command));
    724  1.8       spz         tptr ++;
    725  1.8       spz         tlen --;
    726  1.1  christos         break;
    727  1.1  christos 
    728  1.1  christos         /*
    729  1.1  christos          * FIXME those are the defined codes that lack a decoder
    730  1.1  christos          * you are welcome to contribute code ;-)
    731  1.1  christos          */
    732  1.1  christos     case SLOW_OAM_CODE_VAR_REQUEST:
    733  1.1  christos     case SLOW_OAM_CODE_VAR_RESPONSE:
    734  1.1  christos     case SLOW_OAM_CODE_PRIVATE:
    735  1.1  christos     default:
    736  1.5  christos         if (ndo->ndo_vflag <= 1) {
    737  1.5  christos             print_unknown_data(ndo, tptr, "\n\t  ", tlen);
    738  1.1  christos         }
    739  1.1  christos         break;
    740  1.1  christos     }
    741  1.1  christos     return;
    742  1.8       spz 
    743  1.8       spz tooshort:
    744  1.8       spz     ND_PRINT((ndo, "\n\t\t packet is too short"));
    745  1.8       spz     return;
    746  1.8       spz 
    747  1.8       spz trunc:
    748  1.8       spz     ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
    749  1.1  christos }
    750