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