Home | History | Annotate | Line # | Download | only in dist
print-cfm.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 Connectivity Fault Management Protocols as per 802.1ag.
     16  1.1  christos  *
     17  1.1  christos  * Original code by Hannes Gredler (hannes (at) juniper.net)
     18  1.1  christos  */
     19  1.1  christos 
     20  1.2  christos #include <sys/cdefs.h>
     21  1.1  christos #ifndef lint
     22  1.5  christos __RCSID("$NetBSD: print-cfm.c,v 1.5 2014/11/20 03:05:03 christos Exp $");
     23  1.1  christos #endif
     24  1.1  christos 
     25  1.5  christos #define NETDISSECT_REWORKED
     26  1.1  christos #ifdef HAVE_CONFIG_H
     27  1.1  christos #include "config.h"
     28  1.1  christos #endif
     29  1.1  christos 
     30  1.1  christos #include <tcpdump-stdinc.h>
     31  1.1  christos 
     32  1.1  christos #include <stdio.h>
     33  1.1  christos 
     34  1.1  christos #include "interface.h"
     35  1.1  christos #include "extract.h"
     36  1.1  christos #include "ether.h"
     37  1.1  christos #include "addrtoname.h"
     38  1.1  christos #include "oui.h"
     39  1.1  christos #include "af.h"
     40  1.1  christos 
     41  1.1  christos struct cfm_common_header_t {
     42  1.5  christos     uint8_t mdlevel_version;
     43  1.5  christos     uint8_t opcode;
     44  1.5  christos     uint8_t flags;
     45  1.5  christos     uint8_t first_tlv_offset;
     46  1.1  christos };
     47  1.1  christos 
     48  1.1  christos #define	CFM_VERSION 0
     49  1.1  christos #define CFM_EXTRACT_VERSION(x) (((x)&0x1f))
     50  1.1  christos #define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5)
     51  1.1  christos 
     52  1.1  christos #define	CFM_OPCODE_CCM 1
     53  1.1  christos #define	CFM_OPCODE_LBR 2
     54  1.1  christos #define	CFM_OPCODE_LBM 3
     55  1.1  christos #define	CFM_OPCODE_LTR 4
     56  1.1  christos #define	CFM_OPCODE_LTM 5
     57  1.1  christos 
     58  1.1  christos static const struct tok cfm_opcode_values[] = {
     59  1.1  christos     { CFM_OPCODE_CCM, "Continouity Check Message"},
     60  1.1  christos     { CFM_OPCODE_LBR, "Loopback Reply"},
     61  1.1  christos     { CFM_OPCODE_LBM, "Loopback Message"},
     62  1.1  christos     { CFM_OPCODE_LTR, "Linktrace Reply"},
     63  1.1  christos     { CFM_OPCODE_LTM, "Linktrace Message"},
     64  1.1  christos     { 0, NULL}
     65  1.1  christos };
     66  1.1  christos 
     67  1.1  christos /*
     68  1.1  christos  * Message Formats.
     69  1.1  christos  */
     70  1.1  christos struct cfm_ccm_t {
     71  1.5  christos     uint8_t sequence[4];
     72  1.5  christos     uint8_t ma_epi[2];
     73  1.5  christos     uint8_t md_nameformat;
     74  1.5  christos     uint8_t md_namelength;
     75  1.5  christos     uint8_t md_name[46]; /* md name and short ma name */
     76  1.5  christos     uint8_t reserved_itu[16];
     77  1.5  christos     uint8_t reserved[6];
     78  1.1  christos };
     79  1.1  christos 
     80  1.1  christos /*
     81  1.1  christos  * Timer Bases for the CCM Interval field.
     82  1.1  christos  * Expressed in units of seconds.
     83  1.1  christos  */
     84  1.1  christos const float ccm_interval_base[8] = {0, 0.003333, 0.01, 0.1, 1, 10, 60, 600};
     85  1.1  christos #define CCM_INTERVAL_MIN_MULTIPLIER 3.25
     86  1.1  christos #define CCM_INTERVAL_MAX_MULTIPLIER 3.5
     87  1.1  christos 
     88  1.1  christos #define CFM_CCM_RDI_FLAG 0x80
     89  1.1  christos #define CFM_EXTRACT_CCM_INTERVAL(x) (((x)&0x07))
     90  1.1  christos 
     91  1.1  christos #define CFM_CCM_MD_FORMAT_8021 0
     92  1.1  christos #define CFM_CCM_MD_FORMAT_NONE 1
     93  1.1  christos #define CFM_CCM_MD_FORMAT_DNS  2
     94  1.1  christos #define CFM_CCM_MD_FORMAT_MAC  3
     95  1.1  christos #define CFM_CCM_MD_FORMAT_CHAR 4
     96  1.1  christos 
     97  1.1  christos static const struct tok cfm_md_nameformat_values[] = {
     98  1.1  christos     { CFM_CCM_MD_FORMAT_8021, "IEEE 802.1"},
     99  1.1  christos     { CFM_CCM_MD_FORMAT_NONE, "No MD Name present"},
    100  1.1  christos     { CFM_CCM_MD_FORMAT_DNS, "DNS string"},
    101  1.1  christos     { CFM_CCM_MD_FORMAT_MAC, "MAC + 16Bit Integer"},
    102  1.1  christos     { CFM_CCM_MD_FORMAT_CHAR, "Character string"},
    103  1.1  christos     { 0, NULL}
    104  1.1  christos };
    105  1.1  christos 
    106  1.1  christos #define CFM_CCM_MA_FORMAT_8021 0
    107  1.1  christos #define CFM_CCM_MA_FORMAT_VID  1
    108  1.1  christos #define CFM_CCM_MA_FORMAT_CHAR 2
    109  1.1  christos #define CFM_CCM_MA_FORMAT_INT  3
    110  1.1  christos #define CFM_CCM_MA_FORMAT_VPN  4
    111  1.1  christos 
    112  1.1  christos static const struct tok cfm_ma_nameformat_values[] = {
    113  1.1  christos     { CFM_CCM_MA_FORMAT_8021, "IEEE 802.1"},
    114  1.1  christos     { CFM_CCM_MA_FORMAT_VID, "Primary VID"},
    115  1.1  christos     { CFM_CCM_MA_FORMAT_CHAR, "Character string"},
    116  1.1  christos     { CFM_CCM_MA_FORMAT_INT, "16Bit Integer"},
    117  1.1  christos     { CFM_CCM_MA_FORMAT_VPN, "RFC2685 VPN-ID"},
    118  1.1  christos     { 0, NULL}
    119  1.1  christos };
    120  1.1  christos 
    121  1.1  christos struct cfm_lbm_t {
    122  1.5  christos     uint8_t transaction_id[4];
    123  1.5  christos     uint8_t reserved[4];
    124  1.1  christos };
    125  1.1  christos 
    126  1.1  christos struct cfm_ltm_t {
    127  1.5  christos     uint8_t transaction_id[4];
    128  1.5  christos     uint8_t egress_id[8];
    129  1.5  christos     uint8_t ttl;
    130  1.5  christos     uint8_t original_mac[ETHER_ADDR_LEN];
    131  1.5  christos     uint8_t target_mac[ETHER_ADDR_LEN];
    132  1.5  christos     uint8_t reserved[3];
    133  1.1  christos };
    134  1.1  christos 
    135  1.1  christos static const struct tok cfm_ltm_flag_values[] = {
    136  1.1  christos     { 0x80, "Use Forwarding-DB only"},
    137  1.1  christos     { 0, NULL}
    138  1.1  christos };
    139  1.1  christos 
    140  1.1  christos struct cfm_ltr_t {
    141  1.5  christos     uint8_t transaction_id[4];
    142  1.5  christos     uint8_t last_egress_id[8];
    143  1.5  christos     uint8_t next_egress_id[8];
    144  1.5  christos     uint8_t ttl;
    145  1.5  christos     uint8_t replay_action;
    146  1.5  christos     uint8_t reserved[6];
    147  1.1  christos };
    148  1.1  christos 
    149  1.1  christos static const struct tok cfm_ltr_flag_values[] = {
    150  1.5  christos     { 0x80, "UseFDB Only"},
    151  1.5  christos     { 0x40, "FwdYes"},
    152  1.5  christos     { 0x20, "Terminal MEP"},
    153  1.1  christos     { 0, NULL}
    154  1.1  christos };
    155  1.1  christos 
    156  1.1  christos static const struct tok cfm_ltr_replay_action_values[] = {
    157  1.1  christos     { 1, "Exact Match"},
    158  1.1  christos     { 2, "Filtering DB"},
    159  1.1  christos     { 3, "MIP CCM DB"},
    160  1.1  christos     { 0, NULL}
    161  1.1  christos };
    162  1.1  christos 
    163  1.1  christos 
    164  1.1  christos #define CFM_TLV_END 0
    165  1.1  christos #define CFM_TLV_SENDER_ID 1
    166  1.1  christos #define CFM_TLV_PORT_STATUS 2
    167  1.1  christos #define CFM_TLV_INTERFACE_STATUS 3
    168  1.1  christos #define CFM_TLV_DATA 4
    169  1.1  christos #define CFM_TLV_REPLY_INGRESS 5
    170  1.1  christos #define CFM_TLV_REPLY_EGRESS 6
    171  1.1  christos #define CFM_TLV_PRIVATE 31
    172  1.1  christos 
    173  1.1  christos static const struct tok cfm_tlv_values[] = {
    174  1.1  christos     { CFM_TLV_END, "End"},
    175  1.1  christos     { CFM_TLV_SENDER_ID, "Sender ID"},
    176  1.1  christos     { CFM_TLV_PORT_STATUS, "Port status"},
    177  1.1  christos     { CFM_TLV_INTERFACE_STATUS, "Interface status"},
    178  1.1  christos     { CFM_TLV_DATA, "Data"},
    179  1.1  christos     { CFM_TLV_REPLY_INGRESS, "Reply Ingress"},
    180  1.1  christos     { CFM_TLV_REPLY_EGRESS, "Reply Egress"},
    181  1.1  christos     { CFM_TLV_PRIVATE, "Organization Specific"},
    182  1.1  christos     { 0, NULL}
    183  1.1  christos };
    184  1.1  christos 
    185  1.1  christos /*
    186  1.1  christos  * TLVs
    187  1.1  christos  */
    188  1.1  christos 
    189  1.1  christos struct cfm_tlv_header_t {
    190  1.5  christos     uint8_t type;
    191  1.5  christos     uint8_t length[2];
    192  1.1  christos };
    193  1.1  christos 
    194  1.1  christos /* FIXME define TLV formats */
    195  1.1  christos 
    196  1.1  christos static const struct tok cfm_tlv_port_status_values[] = {
    197  1.1  christos     { 1, "Blocked"},
    198  1.1  christos     { 2, "Up"},
    199  1.1  christos     { 0, NULL}
    200  1.1  christos };
    201  1.1  christos 
    202  1.1  christos static const struct tok cfm_tlv_interface_status_values[] = {
    203  1.1  christos     { 1, "Up"},
    204  1.1  christos     { 2, "Down"},
    205  1.1  christos     { 3, "Testing"},
    206  1.1  christos     { 5, "Dormant"},
    207  1.1  christos     { 6, "not present"},
    208  1.1  christos     { 7, "lower Layer down"},
    209  1.1  christos     { 0, NULL}
    210  1.1  christos };
    211  1.1  christos 
    212  1.1  christos #define CFM_CHASSIS_ID_CHASSIS_COMPONENT 1
    213  1.1  christos #define CFM_CHASSIS_ID_INTERFACE_ALIAS 2
    214  1.1  christos #define CFM_CHASSIS_ID_PORT_COMPONENT 3
    215  1.1  christos #define CFM_CHASSIS_ID_MAC_ADDRESS 4
    216  1.1  christos #define CFM_CHASSIS_ID_NETWORK_ADDRESS 5
    217  1.1  christos #define CFM_CHASSIS_ID_INTERFACE_NAME 6
    218  1.1  christos #define CFM_CHASSIS_ID_LOCAL 7
    219  1.1  christos 
    220  1.1  christos static const struct tok cfm_tlv_senderid_chassisid_values[] = {
    221  1.1  christos     { 0, "Reserved"},
    222  1.1  christos     { CFM_CHASSIS_ID_CHASSIS_COMPONENT, "Chassis component"},
    223  1.1  christos     { CFM_CHASSIS_ID_INTERFACE_ALIAS, "Interface alias"},
    224  1.1  christos     { CFM_CHASSIS_ID_PORT_COMPONENT, "Port component"},
    225  1.1  christos     { CFM_CHASSIS_ID_MAC_ADDRESS, "MAC address"},
    226  1.1  christos     { CFM_CHASSIS_ID_NETWORK_ADDRESS, "Network address"},
    227  1.1  christos     { CFM_CHASSIS_ID_INTERFACE_NAME, "Interface name"},
    228  1.1  christos     { CFM_CHASSIS_ID_LOCAL, "Locally assigned"},
    229  1.1  christos     { 0, NULL}
    230  1.1  christos };
    231  1.1  christos 
    232  1.1  christos 
    233  1.5  christos static int
    234  1.5  christos cfm_mgmt_addr_print(netdissect_options *ndo,
    235  1.5  christos                     register const u_char *tptr) {
    236  1.1  christos 
    237  1.1  christos     u_int mgmt_addr_type;
    238  1.1  christos     u_int hexdump =  FALSE;
    239  1.1  christos 
    240  1.1  christos     /*
    241  1.1  christos      * Altough AFIs are tpically 2 octects wide,
    242  1.1  christos      * 802.1ab specifies that this field width
    243  1.1  christos      * is only once octet
    244  1.1  christos      */
    245  1.1  christos     mgmt_addr_type = *tptr;
    246  1.5  christos     ND_PRINT((ndo, "\n\t  Management Address Type %s (%u)",
    247  1.1  christos            tok2str(af_values, "Unknown", mgmt_addr_type),
    248  1.5  christos            mgmt_addr_type));
    249  1.1  christos 
    250  1.1  christos     /*
    251  1.1  christos      * Resolve the passed in Address.
    252  1.1  christos      */
    253  1.1  christos     switch(mgmt_addr_type) {
    254  1.1  christos     case AFNUM_INET:
    255  1.5  christos         ND_PRINT((ndo, ", %s", ipaddr_string(ndo, tptr + 1)));
    256  1.1  christos         break;
    257  1.1  christos 
    258  1.1  christos #ifdef INET6
    259  1.1  christos     case AFNUM_INET6:
    260  1.5  christos         ND_PRINT((ndo, ", %s", ip6addr_string(ndo, tptr + 1)));
    261  1.1  christos         break;
    262  1.1  christos #endif
    263  1.1  christos 
    264  1.1  christos     default:
    265  1.1  christos         hexdump = TRUE;
    266  1.1  christos         break;
    267  1.1  christos     }
    268  1.1  christos 
    269  1.1  christos     return hexdump;
    270  1.1  christos }
    271  1.1  christos 
    272  1.1  christos /*
    273  1.1  christos  * The egress-ID string is a 16-Bit string plus a MAC address.
    274  1.1  christos  */
    275  1.5  christos static const char *
    276  1.5  christos cfm_egress_id_string(netdissect_options *ndo, register const u_char *tptr) {
    277  1.1  christos     static char egress_id_buffer[80];
    278  1.5  christos 
    279  1.1  christos     snprintf(egress_id_buffer, sizeof(egress_id_buffer),
    280  1.4  christos              "MAC 0x%4x-%s",
    281  1.1  christos              EXTRACT_16BITS(tptr),
    282  1.5  christos              etheraddr_string(ndo, tptr+2));
    283  1.1  christos 
    284  1.1  christos     return egress_id_buffer;
    285  1.1  christos }
    286  1.1  christos 
    287  1.1  christos void
    288  1.5  christos cfm_print(netdissect_options *ndo,
    289  1.5  christos           register const u_char *pptr, register u_int length) {
    290  1.1  christos 
    291  1.1  christos     const struct cfm_common_header_t *cfm_common_header;
    292  1.1  christos     const struct cfm_tlv_header_t *cfm_tlv_header;
    293  1.5  christos     const uint8_t *tptr, *tlv_ptr, *ma_name, *ma_nameformat, *ma_namelength;
    294  1.1  christos     u_int hexdump, tlen, cfm_tlv_len, cfm_tlv_type, ccm_interval;
    295  1.1  christos 
    296  1.1  christos 
    297  1.1  christos     union {
    298  1.1  christos         const struct cfm_ccm_t *cfm_ccm;
    299  1.1  christos         const struct cfm_lbm_t *cfm_lbm;
    300  1.1  christos         const struct cfm_ltm_t *cfm_ltm;
    301  1.1  christos         const struct cfm_ltr_t *cfm_ltr;
    302  1.1  christos     } msg_ptr;
    303  1.1  christos 
    304  1.1  christos     tptr=pptr;
    305  1.1  christos     cfm_common_header = (const struct cfm_common_header_t *)pptr;
    306  1.5  christos     ND_TCHECK(*cfm_common_header);
    307  1.1  christos 
    308  1.1  christos     /*
    309  1.1  christos      * Sanity checking of the header.
    310  1.1  christos      */
    311  1.1  christos     if (CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version) != CFM_VERSION) {
    312  1.5  christos 	ND_PRINT((ndo, "CFMv%u not supported, length %u",
    313  1.5  christos                CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length));
    314  1.1  christos 	return;
    315  1.1  christos     }
    316  1.1  christos 
    317  1.5  christos     ND_PRINT((ndo, "CFMv%u %s, MD Level %u, length %u",
    318  1.1  christos            CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version),
    319  1.1  christos            tok2str(cfm_opcode_values, "unknown (%u)", cfm_common_header->opcode),
    320  1.1  christos            CFM_EXTRACT_MD_LEVEL(cfm_common_header->mdlevel_version),
    321  1.5  christos            length));
    322  1.1  christos 
    323  1.1  christos     /*
    324  1.1  christos      * In non-verbose mode just print the opcode and md-level.
    325  1.1  christos      */
    326  1.5  christos     if (ndo->ndo_vflag < 1) {
    327  1.1  christos         return;
    328  1.1  christos     }
    329  1.1  christos 
    330  1.5  christos     ND_PRINT((ndo, "\n\tFirst TLV offset %u", cfm_common_header->first_tlv_offset));
    331  1.1  christos 
    332  1.1  christos     tptr += sizeof(const struct cfm_common_header_t);
    333  1.1  christos     tlen = length - sizeof(struct cfm_common_header_t);
    334  1.1  christos 
    335  1.1  christos     switch (cfm_common_header->opcode) {
    336  1.1  christos     case CFM_OPCODE_CCM:
    337  1.1  christos         msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
    338  1.1  christos 
    339  1.1  christos         ccm_interval = CFM_EXTRACT_CCM_INTERVAL(cfm_common_header->flags);
    340  1.5  christos         ND_PRINT((ndo, ", Flags [CCM Interval %u%s]",
    341  1.1  christos                ccm_interval,
    342  1.1  christos                cfm_common_header->flags & CFM_CCM_RDI_FLAG ?
    343  1.5  christos                ", RDI" : ""));
    344  1.1  christos 
    345  1.1  christos         /*
    346  1.1  christos          * Resolve the CCM interval field.
    347  1.1  christos          */
    348  1.1  christos         if (ccm_interval) {
    349  1.5  christos             ND_PRINT((ndo, "\n\t  CCM Interval %.3fs"
    350  1.1  christos                    ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
    351  1.1  christos                    ccm_interval_base[ccm_interval],
    352  1.1  christos                    ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
    353  1.5  christos                    ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER));
    354  1.1  christos         }
    355  1.1  christos 
    356  1.5  christos         ND_PRINT((ndo, "\n\t  Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
    357  1.1  christos                EXTRACT_32BITS(msg_ptr.cfm_ccm->sequence),
    358  1.5  christos                EXTRACT_16BITS(msg_ptr.cfm_ccm->ma_epi)));
    359  1.1  christos 
    360  1.1  christos 
    361  1.1  christos         /*
    362  1.1  christos          * Resolve the MD fields.
    363  1.1  christos          */
    364  1.5  christos         ND_PRINT((ndo, "\n\t  MD Name Format %s (%u), MD Name length %u",
    365  1.1  christos                tok2str(cfm_md_nameformat_values, "Unknown",
    366  1.1  christos                        msg_ptr.cfm_ccm->md_nameformat),
    367  1.1  christos                msg_ptr.cfm_ccm->md_nameformat,
    368  1.5  christos                msg_ptr.cfm_ccm->md_namelength));
    369  1.1  christos 
    370  1.1  christos         if (msg_ptr.cfm_ccm->md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
    371  1.5  christos             ND_PRINT((ndo, "\n\t  MD Name: "));
    372  1.1  christos             switch (msg_ptr.cfm_ccm->md_nameformat) {
    373  1.1  christos             case CFM_CCM_MD_FORMAT_DNS:
    374  1.1  christos             case CFM_CCM_MD_FORMAT_CHAR:
    375  1.5  christos                 safeputs(ndo, msg_ptr.cfm_ccm->md_name, msg_ptr.cfm_ccm->md_namelength);
    376  1.1  christos                 break;
    377  1.1  christos 
    378  1.1  christos             case CFM_CCM_MD_FORMAT_MAC:
    379  1.5  christos                 ND_PRINT((ndo, "\n\t  MAC %s", etheraddr_string(ndo,
    380  1.5  christos                            msg_ptr.cfm_ccm->md_name)));
    381  1.1  christos                 break;
    382  1.1  christos 
    383  1.1  christos                 /* FIXME add printers for those MD formats - hexdump for now */
    384  1.1  christos             case CFM_CCM_MA_FORMAT_8021:
    385  1.1  christos             default:
    386  1.5  christos                 print_unknown_data(ndo, msg_ptr.cfm_ccm->md_name, "\n\t    ",
    387  1.1  christos                                    msg_ptr.cfm_ccm->md_namelength);
    388  1.1  christos             }
    389  1.1  christos         }
    390  1.1  christos 
    391  1.1  christos 
    392  1.1  christos         /*
    393  1.1  christos          * Resolve the MA fields.
    394  1.1  christos          */
    395  1.1  christos         ma_nameformat = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength;
    396  1.1  christos         ma_namelength = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 1;
    397  1.1  christos         ma_name = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 2;
    398  1.1  christos 
    399  1.5  christos         ND_PRINT((ndo, "\n\t  MA Name-Format %s (%u), MA name length %u",
    400  1.1  christos                tok2str(cfm_ma_nameformat_values, "Unknown",
    401  1.1  christos                        *ma_nameformat),
    402  1.1  christos                *ma_nameformat,
    403  1.5  christos                *ma_namelength));
    404  1.1  christos 
    405  1.5  christos         ND_PRINT((ndo, "\n\t  MA Name: "));
    406  1.1  christos         switch (*ma_nameformat) {
    407  1.1  christos         case CFM_CCM_MA_FORMAT_CHAR:
    408  1.5  christos             safeputs(ndo, ma_name, *ma_namelength);
    409  1.1  christos             break;
    410  1.1  christos 
    411  1.1  christos             /* FIXME add printers for those MA formats - hexdump for now */
    412  1.1  christos         case CFM_CCM_MA_FORMAT_8021:
    413  1.1  christos         case CFM_CCM_MA_FORMAT_VID:
    414  1.1  christos         case CFM_CCM_MA_FORMAT_INT:
    415  1.1  christos         case CFM_CCM_MA_FORMAT_VPN:
    416  1.1  christos         default:
    417  1.5  christos             print_unknown_data(ndo, ma_name, "\n\t    ", *ma_namelength);
    418  1.1  christos         }
    419  1.1  christos         break;
    420  1.1  christos 
    421  1.1  christos     case CFM_OPCODE_LTM:
    422  1.1  christos         msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr;
    423  1.1  christos 
    424  1.5  christos         ND_PRINT((ndo, ", Flags [%s]",
    425  1.5  christos                bittok2str(cfm_ltm_flag_values, "none", cfm_common_header->flags)));
    426  1.1  christos 
    427  1.5  christos         ND_PRINT((ndo, "\n\t  Transaction-ID 0x%08x, Egress-ID %s, ttl %u",
    428  1.1  christos                EXTRACT_32BITS(msg_ptr.cfm_ltm->transaction_id),
    429  1.5  christos                cfm_egress_id_string(ndo, msg_ptr.cfm_ltm->egress_id),
    430  1.5  christos                msg_ptr.cfm_ltm->ttl));
    431  1.1  christos 
    432  1.5  christos         ND_PRINT((ndo, "\n\t  Original-MAC %s, Target-MAC %s",
    433  1.5  christos                etheraddr_string(ndo, msg_ptr.cfm_ltm->original_mac),
    434  1.5  christos                etheraddr_string(ndo, msg_ptr.cfm_ltm->target_mac)));
    435  1.1  christos         break;
    436  1.1  christos 
    437  1.1  christos     case CFM_OPCODE_LTR:
    438  1.1  christos         msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr;
    439  1.1  christos 
    440  1.5  christos         ND_PRINT((ndo, ", Flags [%s]",
    441  1.5  christos                bittok2str(cfm_ltr_flag_values, "none", cfm_common_header->flags)));
    442  1.1  christos 
    443  1.5  christos         ND_PRINT((ndo, "\n\t  Transaction-ID 0x%08x, Last-Egress-ID %s",
    444  1.1  christos                EXTRACT_32BITS(msg_ptr.cfm_ltr->transaction_id),
    445  1.5  christos                cfm_egress_id_string(ndo, msg_ptr.cfm_ltr->last_egress_id)));
    446  1.1  christos 
    447  1.5  christos         ND_PRINT((ndo, "\n\t  Next-Egress-ID %s, ttl %u",
    448  1.5  christos                cfm_egress_id_string(ndo, msg_ptr.cfm_ltr->next_egress_id),
    449  1.5  christos                msg_ptr.cfm_ltr->ttl));
    450  1.1  christos 
    451  1.5  christos         ND_PRINT((ndo, "\n\t  Replay-Action %s (%u)",
    452  1.1  christos                tok2str(cfm_ltr_replay_action_values,
    453  1.1  christos                        "Unknown",
    454  1.1  christos                        msg_ptr.cfm_ltr->replay_action),
    455  1.5  christos                msg_ptr.cfm_ltr->replay_action));
    456  1.1  christos         break;
    457  1.1  christos 
    458  1.1  christos         /*
    459  1.1  christos          * No message decoder yet.
    460  1.1  christos          * Hexdump everything up until the start of the TLVs
    461  1.1  christos          */
    462  1.1  christos     case CFM_OPCODE_LBR:
    463  1.1  christos     case CFM_OPCODE_LBM:
    464  1.1  christos     default:
    465  1.1  christos         if (tlen > cfm_common_header->first_tlv_offset) {
    466  1.5  christos             print_unknown_data(ndo, tptr, "\n\t  ",
    467  1.1  christos                                tlen -  cfm_common_header->first_tlv_offset);
    468  1.1  christos         }
    469  1.1  christos         break;
    470  1.1  christos     }
    471  1.1  christos 
    472  1.1  christos     /*
    473  1.1  christos      * Sanity check for not walking off.
    474  1.1  christos      */
    475  1.1  christos     if (tlen <= cfm_common_header->first_tlv_offset) {
    476  1.1  christos         return;
    477  1.1  christos     }
    478  1.1  christos 
    479  1.1  christos     tptr += cfm_common_header->first_tlv_offset;
    480  1.1  christos     tlen -= cfm_common_header->first_tlv_offset;
    481  1.5  christos 
    482  1.1  christos     while (tlen > 0) {
    483  1.1  christos         cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
    484  1.1  christos 
    485  1.1  christos         /* Enough to read the tlv type ? */
    486  1.5  christos         ND_TCHECK2(*tptr, 1);
    487  1.1  christos         cfm_tlv_type=cfm_tlv_header->type;
    488  1.1  christos 
    489  1.1  christos         if (cfm_tlv_type != CFM_TLV_END) {
    490  1.1  christos             /* did we capture enough for fully decoding the object header ? */
    491  1.5  christos             ND_TCHECK2(*tptr, sizeof(struct cfm_tlv_header_t));
    492  1.1  christos             cfm_tlv_len=EXTRACT_16BITS(&cfm_tlv_header->length);
    493  1.1  christos         } else {
    494  1.1  christos             cfm_tlv_len = 0;
    495  1.1  christos         }
    496  1.1  christos 
    497  1.5  christos         ND_PRINT((ndo, "\n\t%s TLV (0x%02x), length %u",
    498  1.1  christos                tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type),
    499  1.1  christos                cfm_tlv_type,
    500  1.5  christos                cfm_tlv_len));
    501  1.1  christos 
    502  1.1  christos         /* sanity check for not walking off and infinite loop check. */
    503  1.1  christos         if ((cfm_tlv_type != CFM_TLV_END) &&
    504  1.1  christos             ((cfm_tlv_len + sizeof(struct cfm_tlv_header_t) > tlen) ||
    505  1.1  christos              (!cfm_tlv_len))) {
    506  1.5  christos             print_unknown_data(ndo, tptr, "\n\t  ", tlen);
    507  1.1  christos             return;
    508  1.1  christos         }
    509  1.1  christos 
    510  1.1  christos         tptr += sizeof(struct cfm_tlv_header_t);
    511  1.1  christos         tlen -= sizeof(struct cfm_tlv_header_t);
    512  1.1  christos         tlv_ptr = tptr;
    513  1.1  christos 
    514  1.1  christos         /* did we capture enough for fully decoding the object ? */
    515  1.1  christos         if (cfm_tlv_type != CFM_TLV_END) {
    516  1.5  christos             ND_TCHECK2(*tptr, cfm_tlv_len);
    517  1.1  christos         }
    518  1.1  christos         hexdump = FALSE;
    519  1.1  christos 
    520  1.1  christos         switch(cfm_tlv_type) {
    521  1.1  christos         case CFM_TLV_END:
    522  1.1  christos             /* we are done - bail out */
    523  1.1  christos             return;
    524  1.1  christos 
    525  1.1  christos         case CFM_TLV_PORT_STATUS:
    526  1.5  christos             ND_PRINT((ndo, ", Status: %s (%u)",
    527  1.1  christos                    tok2str(cfm_tlv_port_status_values, "Unknown", *tptr),
    528  1.5  christos                    *tptr));
    529  1.1  christos             break;
    530  1.1  christos 
    531  1.1  christos         case CFM_TLV_INTERFACE_STATUS:
    532  1.5  christos             ND_PRINT((ndo, ", Status: %s (%u)",
    533  1.1  christos                    tok2str(cfm_tlv_interface_status_values, "Unknown", *tptr),
    534  1.5  christos                    *tptr));
    535  1.1  christos             break;
    536  1.1  christos 
    537  1.1  christos         case CFM_TLV_PRIVATE:
    538  1.5  christos             ND_PRINT((ndo, ", Vendor: %s (%u), Sub-Type %u",
    539  1.1  christos                    tok2str(oui_values,"Unknown", EXTRACT_24BITS(tptr)),
    540  1.1  christos                    EXTRACT_24BITS(tptr),
    541  1.5  christos                    *(tptr + 3)));
    542  1.1  christos             hexdump = TRUE;
    543  1.1  christos             break;
    544  1.1  christos 
    545  1.1  christos         case CFM_TLV_SENDER_ID:
    546  1.1  christos         {
    547  1.1  christos             u_int chassis_id_type, chassis_id_length;
    548  1.1  christos             u_int mgmt_addr_length;
    549  1.1  christos 
    550  1.1  christos             /*
    551  1.1  christos              * Check if there is a Chassis-ID.
    552  1.1  christos              */
    553  1.1  christos             chassis_id_length = *tptr;
    554  1.1  christos             if (chassis_id_length > tlen) {
    555  1.1  christos                 hexdump = TRUE;
    556  1.1  christos                 break;
    557  1.1  christos             }
    558  1.1  christos 
    559  1.1  christos             tptr++;
    560  1.1  christos             tlen--;
    561  1.1  christos 
    562  1.1  christos             if (chassis_id_length) {
    563  1.1  christos                 chassis_id_type = *tptr;
    564  1.5  christos                 ND_PRINT((ndo, "\n\t  Chassis-ID Type %s (%u), Chassis-ID length %u",
    565  1.1  christos                        tok2str(cfm_tlv_senderid_chassisid_values,
    566  1.1  christos                                "Unknown",
    567  1.1  christos                                chassis_id_type),
    568  1.1  christos                        chassis_id_type,
    569  1.5  christos                        chassis_id_length));
    570  1.1  christos 
    571  1.1  christos                 switch (chassis_id_type) {
    572  1.1  christos                 case CFM_CHASSIS_ID_MAC_ADDRESS:
    573  1.5  christos                     ND_PRINT((ndo, "\n\t  MAC %s", etheraddr_string(ndo, tptr + 1)));
    574  1.1  christos                     break;
    575  1.1  christos 
    576  1.1  christos                 case CFM_CHASSIS_ID_NETWORK_ADDRESS:
    577  1.5  christos                     hexdump |= cfm_mgmt_addr_print(ndo, tptr);
    578  1.1  christos                     break;
    579  1.1  christos 
    580  1.1  christos                 case CFM_CHASSIS_ID_INTERFACE_NAME: /* fall through */
    581  1.1  christos                 case CFM_CHASSIS_ID_INTERFACE_ALIAS:
    582  1.1  christos                 case CFM_CHASSIS_ID_LOCAL:
    583  1.1  christos                 case CFM_CHASSIS_ID_CHASSIS_COMPONENT:
    584  1.1  christos                 case CFM_CHASSIS_ID_PORT_COMPONENT:
    585  1.5  christos                     safeputs(ndo, tptr + 1, chassis_id_length);
    586  1.1  christos                     break;
    587  1.1  christos 
    588  1.1  christos                 default:
    589  1.1  christos                     hexdump = TRUE;
    590  1.1  christos                     break;
    591  1.1  christos                 }
    592  1.1  christos             }
    593  1.1  christos 
    594  1.1  christos             tptr += chassis_id_length;
    595  1.1  christos             tlen -= chassis_id_length;
    596  1.1  christos 
    597  1.1  christos             /*
    598  1.1  christos              * Check if there is a Management Address.
    599  1.1  christos              */
    600  1.1  christos             mgmt_addr_length = *tptr;
    601  1.1  christos             if (mgmt_addr_length > tlen) {
    602  1.1  christos                 hexdump = TRUE;
    603  1.1  christos                 break;
    604  1.1  christos             }
    605  1.1  christos 
    606  1.1  christos             tptr++;
    607  1.1  christos             tlen--;
    608  1.1  christos 
    609  1.1  christos             if (mgmt_addr_length) {
    610  1.5  christos                 hexdump |= cfm_mgmt_addr_print(ndo, tptr);
    611  1.1  christos             }
    612  1.1  christos 
    613  1.1  christos             tptr += mgmt_addr_length;
    614  1.1  christos             tlen -= mgmt_addr_length;
    615  1.1  christos 
    616  1.1  christos         }
    617  1.1  christos         break;
    618  1.1  christos 
    619  1.1  christos             /*
    620  1.1  christos              * FIXME those are the defined TLVs that lack a decoder
    621  1.1  christos              * you are welcome to contribute code ;-)
    622  1.1  christos              */
    623  1.1  christos 
    624  1.1  christos         case CFM_TLV_DATA:
    625  1.1  christos         case CFM_TLV_REPLY_INGRESS:
    626  1.1  christos         case CFM_TLV_REPLY_EGRESS:
    627  1.1  christos         default:
    628  1.1  christos             hexdump = TRUE;
    629  1.1  christos             break;
    630  1.1  christos         }
    631  1.1  christos         /* do we want to see an additional hexdump ? */
    632  1.5  christos         if (hexdump || ndo->ndo_vflag > 1)
    633  1.5  christos             print_unknown_data(ndo, tlv_ptr, "\n\t  ", cfm_tlv_len);
    634  1.1  christos 
    635  1.1  christos         tptr+=cfm_tlv_len;
    636  1.1  christos         tlen-=cfm_tlv_len;
    637  1.1  christos     }
    638  1.1  christos     return;
    639  1.1  christos trunc:
    640  1.5  christos     ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
    641  1.1  christos }
    642