Home | History | Annotate | Line # | Download | only in dist
print-cfm.c revision 1.1.1.10
      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.1.8  christos  * Original code by Hannes Gredler (hannes (at) gredler.at)
     16      1.1  christos  */
     17      1.1  christos 
     18  1.1.1.7       spz /* \summary: IEEE 802.1ag Connectivity Fault Management (CFM) protocols printer */
     19  1.1.1.7       spz 
     20  1.1.1.9  christos #include <config.h>
     21      1.1  christos 
     22  1.1.1.9  christos #include "netdissect-stdinc.h"
     23      1.1  christos 
     24  1.1.1.6  christos #include "netdissect.h"
     25      1.1  christos #include "extract.h"
     26      1.1  christos #include "addrtoname.h"
     27      1.1  christos #include "oui.h"
     28      1.1  christos #include "af.h"
     29      1.1  christos 
     30  1.1.1.9  christos 
     31      1.1  christos struct cfm_common_header_t {
     32  1.1.1.9  christos     nd_uint8_t mdlevel_version;
     33  1.1.1.9  christos     nd_uint8_t opcode;
     34  1.1.1.9  christos     nd_uint8_t flags;
     35  1.1.1.9  christos     nd_uint8_t first_tlv_offset;
     36      1.1  christos };
     37      1.1  christos 
     38      1.1  christos #define	CFM_VERSION 0
     39  1.1.1.9  christos #define CFM_EXTRACT_VERSION(x) ((x)&0x1f)
     40      1.1  christos #define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5)
     41      1.1  christos 
     42      1.1  christos #define	CFM_OPCODE_CCM 1
     43      1.1  christos #define	CFM_OPCODE_LBR 2
     44      1.1  christos #define	CFM_OPCODE_LBM 3
     45      1.1  christos #define	CFM_OPCODE_LTR 4
     46      1.1  christos #define	CFM_OPCODE_LTM 5
     47      1.1  christos 
     48      1.1  christos static const struct tok cfm_opcode_values[] = {
     49  1.1.1.9  christos     { CFM_OPCODE_CCM, "Continuity Check Message"},
     50      1.1  christos     { CFM_OPCODE_LBR, "Loopback Reply"},
     51      1.1  christos     { CFM_OPCODE_LBM, "Loopback Message"},
     52      1.1  christos     { CFM_OPCODE_LTR, "Linktrace Reply"},
     53      1.1  christos     { CFM_OPCODE_LTM, "Linktrace Message"},
     54      1.1  christos     { 0, NULL}
     55      1.1  christos };
     56      1.1  christos 
     57      1.1  christos /*
     58      1.1  christos  * Message Formats.
     59      1.1  christos  */
     60      1.1  christos struct cfm_ccm_t {
     61  1.1.1.9  christos     nd_uint32_t sequence;
     62  1.1.1.9  christos     nd_uint16_t ma_epi;
     63  1.1.1.9  christos     nd_byte     names[48];
     64  1.1.1.9  christos     nd_byte     itu_t_y_1731[16];
     65      1.1  christos };
     66      1.1  christos 
     67      1.1  christos /*
     68      1.1  christos  * Timer Bases for the CCM Interval field.
     69      1.1  christos  * Expressed in units of seconds.
     70      1.1  christos  */
     71  1.1.1.9  christos static const float ccm_interval_base[8] = {0.0f, 0.003333f, 0.01f, 0.1f, 1.0f, 10.0f, 60.0f, 600.0f};
     72      1.1  christos #define CCM_INTERVAL_MIN_MULTIPLIER 3.25
     73      1.1  christos #define CCM_INTERVAL_MAX_MULTIPLIER 3.5
     74      1.1  christos 
     75      1.1  christos #define CFM_CCM_RDI_FLAG 0x80
     76  1.1.1.9  christos #define CFM_EXTRACT_CCM_INTERVAL(x) ((x)&0x07)
     77      1.1  christos 
     78      1.1  christos #define CFM_CCM_MD_FORMAT_8021 0
     79      1.1  christos #define CFM_CCM_MD_FORMAT_NONE 1
     80      1.1  christos #define CFM_CCM_MD_FORMAT_DNS  2
     81      1.1  christos #define CFM_CCM_MD_FORMAT_MAC  3
     82      1.1  christos #define CFM_CCM_MD_FORMAT_CHAR 4
     83      1.1  christos 
     84      1.1  christos static const struct tok cfm_md_nameformat_values[] = {
     85      1.1  christos     { CFM_CCM_MD_FORMAT_8021, "IEEE 802.1"},
     86      1.1  christos     { CFM_CCM_MD_FORMAT_NONE, "No MD Name present"},
     87      1.1  christos     { CFM_CCM_MD_FORMAT_DNS, "DNS string"},
     88      1.1  christos     { CFM_CCM_MD_FORMAT_MAC, "MAC + 16Bit Integer"},
     89      1.1  christos     { CFM_CCM_MD_FORMAT_CHAR, "Character string"},
     90      1.1  christos     { 0, NULL}
     91      1.1  christos };
     92      1.1  christos 
     93      1.1  christos #define CFM_CCM_MA_FORMAT_8021 0
     94      1.1  christos #define CFM_CCM_MA_FORMAT_VID  1
     95      1.1  christos #define CFM_CCM_MA_FORMAT_CHAR 2
     96      1.1  christos #define CFM_CCM_MA_FORMAT_INT  3
     97      1.1  christos #define CFM_CCM_MA_FORMAT_VPN  4
     98      1.1  christos 
     99      1.1  christos static const struct tok cfm_ma_nameformat_values[] = {
    100      1.1  christos     { CFM_CCM_MA_FORMAT_8021, "IEEE 802.1"},
    101      1.1  christos     { CFM_CCM_MA_FORMAT_VID, "Primary VID"},
    102      1.1  christos     { CFM_CCM_MA_FORMAT_CHAR, "Character string"},
    103      1.1  christos     { CFM_CCM_MA_FORMAT_INT, "16Bit Integer"},
    104      1.1  christos     { CFM_CCM_MA_FORMAT_VPN, "RFC2685 VPN-ID"},
    105      1.1  christos     { 0, NULL}
    106      1.1  christos };
    107      1.1  christos 
    108      1.1  christos struct cfm_lbm_t {
    109  1.1.1.9  christos     nd_uint32_t transaction_id;
    110      1.1  christos };
    111      1.1  christos 
    112      1.1  christos struct cfm_ltm_t {
    113  1.1.1.9  christos     nd_uint32_t transaction_id;
    114  1.1.1.9  christos     nd_uint8_t  ttl;
    115  1.1.1.9  christos     nd_mac_addr original_mac;
    116  1.1.1.9  christos     nd_mac_addr target_mac;
    117      1.1  christos };
    118      1.1  christos 
    119      1.1  christos static const struct tok cfm_ltm_flag_values[] = {
    120      1.1  christos     { 0x80, "Use Forwarding-DB only"},
    121      1.1  christos     { 0, NULL}
    122      1.1  christos };
    123      1.1  christos 
    124      1.1  christos struct cfm_ltr_t {
    125  1.1.1.9  christos     nd_uint32_t transaction_id;
    126  1.1.1.9  christos     nd_uint8_t  ttl;
    127  1.1.1.9  christos     nd_uint8_t  replay_action;
    128      1.1  christos };
    129      1.1  christos 
    130      1.1  christos static const struct tok cfm_ltr_flag_values[] = {
    131  1.1.1.4  christos     { 0x80, "UseFDB Only"},
    132  1.1.1.4  christos     { 0x40, "FwdYes"},
    133  1.1.1.4  christos     { 0x20, "Terminal MEP"},
    134      1.1  christos     { 0, NULL}
    135      1.1  christos };
    136      1.1  christos 
    137      1.1  christos static const struct tok cfm_ltr_replay_action_values[] = {
    138      1.1  christos     { 1, "Exact Match"},
    139      1.1  christos     { 2, "Filtering DB"},
    140      1.1  christos     { 3, "MIP CCM DB"},
    141      1.1  christos     { 0, NULL}
    142      1.1  christos };
    143      1.1  christos 
    144      1.1  christos 
    145      1.1  christos #define CFM_TLV_END 0
    146      1.1  christos #define CFM_TLV_SENDER_ID 1
    147      1.1  christos #define CFM_TLV_PORT_STATUS 2
    148      1.1  christos #define CFM_TLV_INTERFACE_STATUS 3
    149      1.1  christos #define CFM_TLV_DATA 4
    150      1.1  christos #define CFM_TLV_REPLY_INGRESS 5
    151      1.1  christos #define CFM_TLV_REPLY_EGRESS 6
    152      1.1  christos #define CFM_TLV_PRIVATE 31
    153      1.1  christos 
    154      1.1  christos static const struct tok cfm_tlv_values[] = {
    155      1.1  christos     { CFM_TLV_END, "End"},
    156      1.1  christos     { CFM_TLV_SENDER_ID, "Sender ID"},
    157      1.1  christos     { CFM_TLV_PORT_STATUS, "Port status"},
    158      1.1  christos     { CFM_TLV_INTERFACE_STATUS, "Interface status"},
    159      1.1  christos     { CFM_TLV_DATA, "Data"},
    160      1.1  christos     { CFM_TLV_REPLY_INGRESS, "Reply Ingress"},
    161      1.1  christos     { CFM_TLV_REPLY_EGRESS, "Reply Egress"},
    162      1.1  christos     { CFM_TLV_PRIVATE, "Organization Specific"},
    163      1.1  christos     { 0, NULL}
    164      1.1  christos };
    165      1.1  christos 
    166      1.1  christos /*
    167      1.1  christos  * TLVs
    168      1.1  christos  */
    169      1.1  christos 
    170      1.1  christos struct cfm_tlv_header_t {
    171  1.1.1.9  christos     nd_uint8_t  type;
    172  1.1.1.9  christos     nd_uint16_t length;
    173      1.1  christos };
    174      1.1  christos 
    175      1.1  christos /* FIXME define TLV formats */
    176      1.1  christos 
    177      1.1  christos static const struct tok cfm_tlv_port_status_values[] = {
    178      1.1  christos     { 1, "Blocked"},
    179      1.1  christos     { 2, "Up"},
    180      1.1  christos     { 0, NULL}
    181      1.1  christos };
    182      1.1  christos 
    183      1.1  christos static const struct tok cfm_tlv_interface_status_values[] = {
    184      1.1  christos     { 1, "Up"},
    185      1.1  christos     { 2, "Down"},
    186      1.1  christos     { 3, "Testing"},
    187      1.1  christos     { 5, "Dormant"},
    188      1.1  christos     { 6, "not present"},
    189      1.1  christos     { 7, "lower Layer down"},
    190      1.1  christos     { 0, NULL}
    191      1.1  christos };
    192      1.1  christos 
    193      1.1  christos #define CFM_CHASSIS_ID_CHASSIS_COMPONENT 1
    194      1.1  christos #define CFM_CHASSIS_ID_INTERFACE_ALIAS 2
    195      1.1  christos #define CFM_CHASSIS_ID_PORT_COMPONENT 3
    196      1.1  christos #define CFM_CHASSIS_ID_MAC_ADDRESS 4
    197      1.1  christos #define CFM_CHASSIS_ID_NETWORK_ADDRESS 5
    198      1.1  christos #define CFM_CHASSIS_ID_INTERFACE_NAME 6
    199      1.1  christos #define CFM_CHASSIS_ID_LOCAL 7
    200      1.1  christos 
    201      1.1  christos static const struct tok cfm_tlv_senderid_chassisid_values[] = {
    202      1.1  christos     { 0, "Reserved"},
    203      1.1  christos     { CFM_CHASSIS_ID_CHASSIS_COMPONENT, "Chassis component"},
    204      1.1  christos     { CFM_CHASSIS_ID_INTERFACE_ALIAS, "Interface alias"},
    205      1.1  christos     { CFM_CHASSIS_ID_PORT_COMPONENT, "Port component"},
    206      1.1  christos     { CFM_CHASSIS_ID_MAC_ADDRESS, "MAC address"},
    207      1.1  christos     { CFM_CHASSIS_ID_NETWORK_ADDRESS, "Network address"},
    208      1.1  christos     { CFM_CHASSIS_ID_INTERFACE_NAME, "Interface name"},
    209      1.1  christos     { CFM_CHASSIS_ID_LOCAL, "Locally assigned"},
    210      1.1  christos     { 0, NULL}
    211      1.1  christos };
    212      1.1  christos 
    213      1.1  christos 
    214  1.1.1.4  christos static int
    215  1.1.1.7       spz cfm_network_addr_print(netdissect_options *ndo,
    216  1.1.1.9  christos                        const u_char *tptr, const u_int length)
    217  1.1.1.5  christos {
    218  1.1.1.7       spz     u_int network_addr_type;
    219      1.1  christos     u_int hexdump =  FALSE;
    220      1.1  christos 
    221      1.1  christos     /*
    222  1.1.1.9  christos      * Although AFIs are typically 2 octets wide,
    223      1.1  christos      * 802.1ab specifies that this field width
    224  1.1.1.9  christos      * is only one octet.
    225      1.1  christos      */
    226  1.1.1.8  christos     if (length < 1) {
    227  1.1.1.9  christos         ND_PRINT("\n\t  Network Address Type (invalid, no data");
    228  1.1.1.8  christos         return hexdump;
    229  1.1.1.8  christos     }
    230  1.1.1.8  christos     /* The calling function must make any due ND_TCHECK calls. */
    231  1.1.1.9  christos     network_addr_type = GET_U_1(tptr);
    232  1.1.1.9  christos     ND_PRINT("\n\t  Network Address Type %s (%u)",
    233  1.1.1.7       spz            tok2str(af_values, "Unknown", network_addr_type),
    234  1.1.1.9  christos            network_addr_type);
    235      1.1  christos 
    236      1.1  christos     /*
    237      1.1  christos      * Resolve the passed in Address.
    238      1.1  christos      */
    239  1.1.1.7       spz     switch(network_addr_type) {
    240      1.1  christos     case AFNUM_INET:
    241  1.1.1.8  christos         if (length != 1 + 4) {
    242  1.1.1.9  christos             ND_PRINT("(invalid IPv4 address length %u)", length - 1);
    243  1.1.1.8  christos             hexdump = TRUE;
    244  1.1.1.8  christos             break;
    245  1.1.1.8  christos         }
    246  1.1.1.9  christos         ND_PRINT(", %s", GET_IPADDR_STRING(tptr + 1));
    247      1.1  christos         break;
    248      1.1  christos 
    249      1.1  christos     case AFNUM_INET6:
    250  1.1.1.8  christos         if (length != 1 + 16) {
    251  1.1.1.9  christos             ND_PRINT("(invalid IPv6 address length %u)", length - 1);
    252  1.1.1.8  christos             hexdump = TRUE;
    253  1.1.1.8  christos             break;
    254  1.1.1.8  christos         }
    255  1.1.1.9  christos         ND_PRINT(", %s", GET_IP6ADDR_STRING(tptr + 1));
    256      1.1  christos         break;
    257      1.1  christos 
    258      1.1  christos     default:
    259      1.1  christos         hexdump = TRUE;
    260      1.1  christos         break;
    261      1.1  christos     }
    262      1.1  christos 
    263      1.1  christos     return hexdump;
    264      1.1  christos }
    265      1.1  christos 
    266      1.1  christos void
    267  1.1.1.4  christos cfm_print(netdissect_options *ndo,
    268  1.1.1.9  christos           const u_char *pptr, u_int length)
    269  1.1.1.5  christos {
    270      1.1  christos     const struct cfm_common_header_t *cfm_common_header;
    271  1.1.1.9  christos     uint8_t mdlevel_version, opcode, flags, first_tlv_offset;
    272      1.1  christos     const struct cfm_tlv_header_t *cfm_tlv_header;
    273  1.1.1.7       spz     const uint8_t *tptr, *tlv_ptr;
    274  1.1.1.7       spz     const uint8_t *namesp;
    275  1.1.1.7       spz     u_int names_data_remaining;
    276  1.1.1.7       spz     uint8_t md_nameformat, md_namelength;
    277  1.1.1.7       spz     const uint8_t *md_name;
    278  1.1.1.7       spz     uint8_t ma_nameformat, ma_namelength;
    279  1.1.1.7       spz     const uint8_t *ma_name;
    280      1.1  christos     u_int hexdump, tlen, cfm_tlv_len, cfm_tlv_type, ccm_interval;
    281      1.1  christos 
    282      1.1  christos 
    283      1.1  christos     union {
    284      1.1  christos         const struct cfm_ccm_t *cfm_ccm;
    285      1.1  christos         const struct cfm_lbm_t *cfm_lbm;
    286      1.1  christos         const struct cfm_ltm_t *cfm_ltm;
    287      1.1  christos         const struct cfm_ltr_t *cfm_ltr;
    288      1.1  christos     } msg_ptr;
    289      1.1  christos 
    290  1.1.1.9  christos     ndo->ndo_protocol = "cfm";
    291      1.1  christos     tptr=pptr;
    292      1.1  christos     cfm_common_header = (const struct cfm_common_header_t *)pptr;
    293  1.1.1.7       spz     if (length < sizeof(*cfm_common_header))
    294  1.1.1.7       spz         goto tooshort;
    295  1.1.1.9  christos     ND_TCHECK_SIZE(cfm_common_header);
    296      1.1  christos 
    297      1.1  christos     /*
    298      1.1  christos      * Sanity checking of the header.
    299      1.1  christos      */
    300  1.1.1.9  christos     mdlevel_version = GET_U_1(cfm_common_header->mdlevel_version);
    301  1.1.1.9  christos     if (CFM_EXTRACT_VERSION(mdlevel_version) != CFM_VERSION) {
    302  1.1.1.9  christos 	ND_PRINT("CFMv%u not supported, length %u",
    303  1.1.1.9  christos                CFM_EXTRACT_VERSION(mdlevel_version), length);
    304      1.1  christos 	return;
    305      1.1  christos     }
    306      1.1  christos 
    307  1.1.1.9  christos     opcode = GET_U_1(cfm_common_header->opcode);
    308  1.1.1.9  christos     ND_PRINT("CFMv%u %s, MD Level %u, length %u",
    309  1.1.1.9  christos            CFM_EXTRACT_VERSION(mdlevel_version),
    310  1.1.1.9  christos            tok2str(cfm_opcode_values, "unknown (%u)", opcode),
    311  1.1.1.9  christos            CFM_EXTRACT_MD_LEVEL(mdlevel_version),
    312  1.1.1.9  christos            length);
    313      1.1  christos 
    314      1.1  christos     /*
    315      1.1  christos      * In non-verbose mode just print the opcode and md-level.
    316      1.1  christos      */
    317  1.1.1.4  christos     if (ndo->ndo_vflag < 1) {
    318      1.1  christos         return;
    319      1.1  christos     }
    320      1.1  christos 
    321  1.1.1.9  christos     flags = GET_U_1(cfm_common_header->flags);
    322  1.1.1.9  christos     first_tlv_offset = GET_U_1(cfm_common_header->first_tlv_offset);
    323  1.1.1.9  christos     ND_PRINT("\n\tFirst TLV offset %u", first_tlv_offset);
    324      1.1  christos 
    325  1.1.1.9  christos     tptr += sizeof(struct cfm_common_header_t);
    326      1.1  christos     tlen = length - sizeof(struct cfm_common_header_t);
    327      1.1  christos 
    328  1.1.1.7       spz     /*
    329  1.1.1.7       spz      * Sanity check the first TLV offset.
    330  1.1.1.7       spz      */
    331  1.1.1.9  christos     if (first_tlv_offset > tlen) {
    332  1.1.1.9  christos         ND_PRINT(" (too large, must be <= %u)", tlen);
    333  1.1.1.7       spz         return;
    334  1.1.1.7       spz     }
    335  1.1.1.7       spz 
    336  1.1.1.9  christos     switch (opcode) {
    337      1.1  christos     case CFM_OPCODE_CCM:
    338      1.1  christos         msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
    339  1.1.1.9  christos         if (first_tlv_offset < sizeof(*msg_ptr.cfm_ccm)) {
    340  1.1.1.9  christos             ND_PRINT(" (too small 1, must be >= %zu)",
    341  1.1.1.9  christos                      sizeof(*msg_ptr.cfm_ccm));
    342  1.1.1.7       spz             return;
    343  1.1.1.7       spz         }
    344  1.1.1.7       spz         if (tlen < sizeof(*msg_ptr.cfm_ccm))
    345  1.1.1.7       spz             goto tooshort;
    346  1.1.1.9  christos         ND_TCHECK_SIZE(msg_ptr.cfm_ccm);
    347      1.1  christos 
    348  1.1.1.9  christos         ccm_interval = CFM_EXTRACT_CCM_INTERVAL(flags);
    349  1.1.1.9  christos         ND_PRINT(", Flags [CCM Interval %u%s]",
    350      1.1  christos                ccm_interval,
    351  1.1.1.9  christos                flags & CFM_CCM_RDI_FLAG ?
    352  1.1.1.9  christos                ", RDI" : "");
    353      1.1  christos 
    354      1.1  christos         /*
    355      1.1  christos          * Resolve the CCM interval field.
    356      1.1  christos          */
    357      1.1  christos         if (ccm_interval) {
    358  1.1.1.9  christos             ND_PRINT("\n\t  CCM Interval %.3fs"
    359      1.1  christos                    ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
    360      1.1  christos                    ccm_interval_base[ccm_interval],
    361      1.1  christos                    ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
    362  1.1.1.9  christos                    ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER);
    363      1.1  christos         }
    364      1.1  christos 
    365  1.1.1.9  christos         ND_PRINT("\n\t  Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
    366  1.1.1.9  christos                GET_BE_U_4(msg_ptr.cfm_ccm->sequence),
    367  1.1.1.9  christos                GET_BE_U_2(msg_ptr.cfm_ccm->ma_epi));
    368      1.1  christos 
    369  1.1.1.7       spz         namesp = msg_ptr.cfm_ccm->names;
    370  1.1.1.7       spz         names_data_remaining = sizeof(msg_ptr.cfm_ccm->names);
    371      1.1  christos 
    372      1.1  christos         /*
    373      1.1  christos          * Resolve the MD fields.
    374      1.1  christos          */
    375  1.1.1.9  christos         md_nameformat = GET_U_1(namesp);
    376  1.1.1.7       spz         namesp++;
    377  1.1.1.7       spz         names_data_remaining--;  /* We know this is != 0 */
    378  1.1.1.7       spz         if (md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
    379  1.1.1.9  christos             md_namelength = GET_U_1(namesp);
    380  1.1.1.7       spz             namesp++;
    381  1.1.1.7       spz             names_data_remaining--; /* We know this is !=0 */
    382  1.1.1.9  christos             ND_PRINT("\n\t  MD Name Format %s (%u), MD Name length %u",
    383  1.1.1.7       spz                    tok2str(cfm_md_nameformat_values, "Unknown",
    384  1.1.1.7       spz                            md_nameformat),
    385  1.1.1.7       spz                    md_nameformat,
    386  1.1.1.9  christos                    md_namelength);
    387  1.1.1.7       spz 
    388  1.1.1.8  christos             /*
    389  1.1.1.8  christos              * -3 for the MA short name format and length and one byte
    390  1.1.1.8  christos              * of MA short name.
    391  1.1.1.8  christos              */
    392  1.1.1.8  christos             if (md_namelength > names_data_remaining - 3) {
    393  1.1.1.9  christos                 ND_PRINT(" (too large, must be <= %u)", names_data_remaining - 2);
    394  1.1.1.7       spz                 return;
    395  1.1.1.7       spz             }
    396      1.1  christos 
    397  1.1.1.7       spz             md_name = namesp;
    398  1.1.1.9  christos             ND_PRINT("\n\t  MD Name: ");
    399  1.1.1.7       spz             switch (md_nameformat) {
    400      1.1  christos             case CFM_CCM_MD_FORMAT_DNS:
    401      1.1  christos             case CFM_CCM_MD_FORMAT_CHAR:
    402  1.1.1.9  christos                 nd_printjnp(ndo, md_name, md_namelength);
    403      1.1  christos                 break;
    404      1.1  christos 
    405      1.1  christos             case CFM_CCM_MD_FORMAT_MAC:
    406  1.1.1.9  christos                 if (md_namelength == MAC_ADDR_LEN) {
    407  1.1.1.9  christos                     ND_PRINT("\n\t  MAC %s", GET_ETHERADDR_STRING(md_name));
    408  1.1.1.7       spz                 } else {
    409  1.1.1.9  christos                     ND_PRINT("\n\t  MAC (length invalid)");
    410  1.1.1.7       spz                 }
    411      1.1  christos                 break;
    412      1.1  christos 
    413      1.1  christos                 /* FIXME add printers for those MD formats - hexdump for now */
    414      1.1  christos             case CFM_CCM_MA_FORMAT_8021:
    415      1.1  christos             default:
    416  1.1.1.7       spz                 print_unknown_data(ndo, md_name, "\n\t    ",
    417  1.1.1.7       spz                                    md_namelength);
    418      1.1  christos             }
    419  1.1.1.7       spz             namesp += md_namelength;
    420  1.1.1.7       spz             names_data_remaining -= md_namelength;
    421  1.1.1.7       spz         } else {
    422  1.1.1.9  christos             ND_PRINT("\n\t  MD Name Format %s (%u)",
    423  1.1.1.7       spz                    tok2str(cfm_md_nameformat_values, "Unknown",
    424  1.1.1.7       spz                            md_nameformat),
    425  1.1.1.9  christos                    md_nameformat);
    426      1.1  christos         }
    427      1.1  christos 
    428      1.1  christos 
    429      1.1  christos         /*
    430      1.1  christos          * Resolve the MA fields.
    431      1.1  christos          */
    432  1.1.1.9  christos         ma_nameformat = GET_U_1(namesp);
    433  1.1.1.7       spz         namesp++;
    434  1.1.1.7       spz         names_data_remaining--; /* We know this is != 0 */
    435  1.1.1.9  christos         ma_namelength = GET_U_1(namesp);
    436  1.1.1.7       spz         namesp++;
    437  1.1.1.7       spz         names_data_remaining--; /* We know this is != 0 */
    438  1.1.1.9  christos         ND_PRINT("\n\t  MA Name-Format %s (%u), MA name length %u",
    439      1.1  christos                tok2str(cfm_ma_nameformat_values, "Unknown",
    440  1.1.1.7       spz                        ma_nameformat),
    441  1.1.1.7       spz                ma_nameformat,
    442  1.1.1.9  christos                ma_namelength);
    443  1.1.1.7       spz 
    444  1.1.1.7       spz         if (ma_namelength > names_data_remaining) {
    445  1.1.1.9  christos             ND_PRINT(" (too large, must be <= %u)", names_data_remaining);
    446  1.1.1.7       spz             return;
    447  1.1.1.7       spz         }
    448      1.1  christos 
    449  1.1.1.7       spz         ma_name = namesp;
    450  1.1.1.9  christos         ND_PRINT("\n\t  MA Name: ");
    451  1.1.1.7       spz         switch (ma_nameformat) {
    452      1.1  christos         case CFM_CCM_MA_FORMAT_CHAR:
    453  1.1.1.9  christos             nd_printjnp(ndo, ma_name, ma_namelength);
    454      1.1  christos             break;
    455      1.1  christos 
    456      1.1  christos             /* FIXME add printers for those MA formats - hexdump for now */
    457      1.1  christos         case CFM_CCM_MA_FORMAT_8021:
    458      1.1  christos         case CFM_CCM_MA_FORMAT_VID:
    459      1.1  christos         case CFM_CCM_MA_FORMAT_INT:
    460      1.1  christos         case CFM_CCM_MA_FORMAT_VPN:
    461      1.1  christos         default:
    462  1.1.1.7       spz             print_unknown_data(ndo, ma_name, "\n\t    ", ma_namelength);
    463      1.1  christos         }
    464      1.1  christos         break;
    465      1.1  christos 
    466      1.1  christos     case CFM_OPCODE_LTM:
    467      1.1  christos         msg_ptr.cfm_ltm = (const struct cfm_ltm_t *)tptr;
    468  1.1.1.9  christos         if (first_tlv_offset < sizeof(*msg_ptr.cfm_ltm)) {
    469  1.1.1.9  christos             ND_PRINT(" (too small 4, must be >= %zu)",
    470  1.1.1.9  christos                      sizeof(*msg_ptr.cfm_ltm));
    471  1.1.1.7       spz             return;
    472  1.1.1.7       spz         }
    473  1.1.1.7       spz         if (tlen < sizeof(*msg_ptr.cfm_ltm))
    474  1.1.1.7       spz             goto tooshort;
    475  1.1.1.9  christos         ND_TCHECK_SIZE(msg_ptr.cfm_ltm);
    476      1.1  christos 
    477  1.1.1.9  christos         ND_PRINT(", Flags [%s]",
    478  1.1.1.9  christos                bittok2str(cfm_ltm_flag_values, "none", flags));
    479      1.1  christos 
    480  1.1.1.9  christos         ND_PRINT("\n\t  Transaction-ID 0x%08x, ttl %u",
    481  1.1.1.9  christos                GET_BE_U_4(msg_ptr.cfm_ltm->transaction_id),
    482  1.1.1.9  christos                GET_U_1(msg_ptr.cfm_ltm->ttl));
    483  1.1.1.9  christos 
    484  1.1.1.9  christos         ND_PRINT("\n\t  Original-MAC %s, Target-MAC %s",
    485  1.1.1.9  christos                GET_ETHERADDR_STRING(msg_ptr.cfm_ltm->original_mac),
    486  1.1.1.9  christos                GET_ETHERADDR_STRING(msg_ptr.cfm_ltm->target_mac));
    487      1.1  christos         break;
    488      1.1  christos 
    489      1.1  christos     case CFM_OPCODE_LTR:
    490      1.1  christos         msg_ptr.cfm_ltr = (const struct cfm_ltr_t *)tptr;
    491  1.1.1.9  christos         if (first_tlv_offset < sizeof(*msg_ptr.cfm_ltr)) {
    492  1.1.1.9  christos             ND_PRINT(" (too small 5, must be >= %zu)",
    493  1.1.1.9  christos                      sizeof(*msg_ptr.cfm_ltr));
    494  1.1.1.7       spz             return;
    495  1.1.1.7       spz         }
    496  1.1.1.7       spz         if (tlen < sizeof(*msg_ptr.cfm_ltr))
    497  1.1.1.7       spz             goto tooshort;
    498  1.1.1.9  christos         ND_TCHECK_SIZE(msg_ptr.cfm_ltr);
    499      1.1  christos 
    500  1.1.1.9  christos         ND_PRINT(", Flags [%s]",
    501  1.1.1.9  christos                bittok2str(cfm_ltr_flag_values, "none", flags));
    502      1.1  christos 
    503  1.1.1.9  christos         ND_PRINT("\n\t  Transaction-ID 0x%08x, ttl %u",
    504  1.1.1.9  christos                GET_BE_U_4(msg_ptr.cfm_ltr->transaction_id),
    505  1.1.1.9  christos                GET_U_1(msg_ptr.cfm_ltr->ttl));
    506      1.1  christos 
    507  1.1.1.9  christos         ND_PRINT("\n\t  Replay-Action %s (%u)",
    508      1.1  christos                tok2str(cfm_ltr_replay_action_values,
    509      1.1  christos                        "Unknown",
    510  1.1.1.9  christos                        GET_U_1(msg_ptr.cfm_ltr->replay_action)),
    511  1.1.1.9  christos                GET_U_1(msg_ptr.cfm_ltr->replay_action));
    512      1.1  christos         break;
    513      1.1  christos 
    514      1.1  christos         /*
    515      1.1  christos          * No message decoder yet.
    516      1.1  christos          * Hexdump everything up until the start of the TLVs
    517      1.1  christos          */
    518      1.1  christos     case CFM_OPCODE_LBR:
    519      1.1  christos     case CFM_OPCODE_LBM:
    520      1.1  christos     default:
    521  1.1.1.7       spz         print_unknown_data(ndo, tptr, "\n\t  ",
    522  1.1.1.9  christos                            tlen -  first_tlv_offset);
    523      1.1  christos         break;
    524      1.1  christos     }
    525      1.1  christos 
    526  1.1.1.9  christos     tptr += first_tlv_offset;
    527  1.1.1.9  christos     tlen -= first_tlv_offset;
    528  1.1.1.4  christos 
    529      1.1  christos     while (tlen > 0) {
    530      1.1  christos         cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
    531      1.1  christos 
    532      1.1  christos         /* Enough to read the tlv type ? */
    533  1.1.1.9  christos         cfm_tlv_type = GET_U_1(cfm_tlv_header->type);
    534      1.1  christos 
    535  1.1.1.9  christos         ND_PRINT("\n\t%s TLV (0x%02x)",
    536      1.1  christos                tok2str(cfm_tlv_values, "Unknown", cfm_tlv_type),
    537  1.1.1.9  christos                cfm_tlv_type);
    538      1.1  christos 
    539  1.1.1.7       spz         if (cfm_tlv_type == CFM_TLV_END) {
    540  1.1.1.7       spz             /* Length is "Not present if the Type field is 0." */
    541      1.1  christos             return;
    542      1.1  christos         }
    543      1.1  christos 
    544  1.1.1.7       spz         /* do we have the full tlv header ? */
    545  1.1.1.7       spz         if (tlen < sizeof(struct cfm_tlv_header_t))
    546  1.1.1.7       spz             goto tooshort;
    547  1.1.1.9  christos         ND_TCHECK_LEN(tptr, sizeof(struct cfm_tlv_header_t));
    548  1.1.1.9  christos         cfm_tlv_len=GET_BE_U_2(cfm_tlv_header->length);
    549  1.1.1.7       spz 
    550  1.1.1.9  christos         ND_PRINT(", length %u", cfm_tlv_len);
    551  1.1.1.7       spz 
    552      1.1  christos         tptr += sizeof(struct cfm_tlv_header_t);
    553      1.1  christos         tlen -= sizeof(struct cfm_tlv_header_t);
    554      1.1  christos         tlv_ptr = tptr;
    555      1.1  christos 
    556  1.1.1.7       spz         /* do we have the full tlv ? */
    557  1.1.1.7       spz         if (tlen < cfm_tlv_len)
    558  1.1.1.7       spz             goto tooshort;
    559  1.1.1.9  christos         ND_TCHECK_LEN(tptr, cfm_tlv_len);
    560      1.1  christos         hexdump = FALSE;
    561      1.1  christos 
    562      1.1  christos         switch(cfm_tlv_type) {
    563      1.1  christos         case CFM_TLV_PORT_STATUS:
    564  1.1.1.7       spz             if (cfm_tlv_len < 1) {
    565  1.1.1.9  christos                 ND_PRINT(" (too short, must be >= 1)");
    566  1.1.1.7       spz                 return;
    567  1.1.1.7       spz             }
    568  1.1.1.9  christos             ND_PRINT(", Status: %s (%u)",
    569  1.1.1.9  christos                    tok2str(cfm_tlv_port_status_values, "Unknown", GET_U_1(tptr)),
    570  1.1.1.9  christos                    GET_U_1(tptr));
    571      1.1  christos             break;
    572      1.1  christos 
    573      1.1  christos         case CFM_TLV_INTERFACE_STATUS:
    574  1.1.1.7       spz             if (cfm_tlv_len < 1) {
    575  1.1.1.9  christos                 ND_PRINT(" (too short, must be >= 1)");
    576  1.1.1.7       spz                 return;
    577  1.1.1.7       spz             }
    578  1.1.1.9  christos             ND_PRINT(", Status: %s (%u)",
    579  1.1.1.9  christos                    tok2str(cfm_tlv_interface_status_values, "Unknown", GET_U_1(tptr)),
    580  1.1.1.9  christos                    GET_U_1(tptr));
    581      1.1  christos             break;
    582      1.1  christos 
    583      1.1  christos         case CFM_TLV_PRIVATE:
    584  1.1.1.7       spz             if (cfm_tlv_len < 4) {
    585  1.1.1.9  christos                 ND_PRINT(" (too short, must be >= 4)");
    586  1.1.1.7       spz                 return;
    587  1.1.1.7       spz             }
    588  1.1.1.9  christos             ND_PRINT(", Vendor: %s (%u), Sub-Type %u",
    589  1.1.1.9  christos                    tok2str(oui_values,"Unknown", GET_BE_U_3(tptr)),
    590  1.1.1.9  christos                    GET_BE_U_3(tptr),
    591  1.1.1.9  christos                    GET_U_1(tptr + 3));
    592      1.1  christos             hexdump = TRUE;
    593      1.1  christos             break;
    594      1.1  christos 
    595      1.1  christos         case CFM_TLV_SENDER_ID:
    596      1.1  christos         {
    597      1.1  christos             u_int chassis_id_type, chassis_id_length;
    598      1.1  christos             u_int mgmt_addr_length;
    599      1.1  christos 
    600  1.1.1.7       spz             if (cfm_tlv_len < 1) {
    601  1.1.1.9  christos                 ND_PRINT(" (too short, must be >= 1)");
    602  1.1.1.8  christos                 goto next_tlv;
    603  1.1.1.7       spz             }
    604  1.1.1.7       spz 
    605      1.1  christos             /*
    606  1.1.1.7       spz              * Get the Chassis ID length and check it.
    607  1.1.1.8  christos              * IEEE 802.1Q-2014 Section 21.5.3.1
    608      1.1  christos              */
    609  1.1.1.9  christos             chassis_id_length = GET_U_1(tptr);
    610      1.1  christos             tptr++;
    611      1.1  christos             tlen--;
    612  1.1.1.7       spz             cfm_tlv_len--;
    613      1.1  christos 
    614      1.1  christos             if (chassis_id_length) {
    615  1.1.1.8  christos                 /*
    616  1.1.1.8  christos                  * IEEE 802.1Q-2014 Section 21.5.3.2: Chassis ID Subtype, references
    617  1.1.1.8  christos                  * IEEE 802.1AB-2005 Section 9.5.2.2, subsequently
    618  1.1.1.8  christos                  * IEEE 802.1AB-2016 Section 8.5.2.2: chassis ID subtype
    619  1.1.1.8  christos                  */
    620  1.1.1.7       spz                 if (cfm_tlv_len < 1) {
    621  1.1.1.9  christos                     ND_PRINT("\n\t  (TLV too short)");
    622  1.1.1.8  christos                     goto next_tlv;
    623  1.1.1.7       spz                 }
    624  1.1.1.9  christos                 chassis_id_type = GET_U_1(tptr);
    625  1.1.1.7       spz                 cfm_tlv_len--;
    626  1.1.1.9  christos                 ND_PRINT("\n\t  Chassis-ID Type %s (%u), Chassis-ID length %u",
    627      1.1  christos                        tok2str(cfm_tlv_senderid_chassisid_values,
    628      1.1  christos                                "Unknown",
    629      1.1  christos                                chassis_id_type),
    630      1.1  christos                        chassis_id_type,
    631  1.1.1.9  christos                        chassis_id_length);
    632      1.1  christos 
    633  1.1.1.7       spz                 if (cfm_tlv_len < chassis_id_length) {
    634  1.1.1.9  christos                     ND_PRINT("\n\t  (TLV too short)");
    635  1.1.1.8  christos                     goto next_tlv;
    636  1.1.1.7       spz                 }
    637  1.1.1.7       spz 
    638  1.1.1.8  christos                 /* IEEE 802.1Q-2014 Section 21.5.3.3: Chassis ID */
    639      1.1  christos                 switch (chassis_id_type) {
    640      1.1  christos                 case CFM_CHASSIS_ID_MAC_ADDRESS:
    641  1.1.1.9  christos                     if (chassis_id_length != MAC_ADDR_LEN) {
    642  1.1.1.9  christos                         ND_PRINT(" (invalid MAC address length)");
    643  1.1.1.8  christos                         hexdump = TRUE;
    644  1.1.1.8  christos                         break;
    645  1.1.1.8  christos                     }
    646  1.1.1.9  christos                     ND_PRINT("\n\t  MAC %s", GET_ETHERADDR_STRING(tptr + 1));
    647      1.1  christos                     break;
    648      1.1  christos 
    649      1.1  christos                 case CFM_CHASSIS_ID_NETWORK_ADDRESS:
    650  1.1.1.8  christos                     hexdump |= cfm_network_addr_print(ndo, tptr + 1, chassis_id_length);
    651      1.1  christos                     break;
    652      1.1  christos 
    653      1.1  christos                 case CFM_CHASSIS_ID_INTERFACE_NAME: /* fall through */
    654      1.1  christos                 case CFM_CHASSIS_ID_INTERFACE_ALIAS:
    655      1.1  christos                 case CFM_CHASSIS_ID_LOCAL:
    656      1.1  christos                 case CFM_CHASSIS_ID_CHASSIS_COMPONENT:
    657      1.1  christos                 case CFM_CHASSIS_ID_PORT_COMPONENT:
    658  1.1.1.9  christos                     nd_printjnp(ndo, tptr + 1, chassis_id_length);
    659      1.1  christos                     break;
    660      1.1  christos 
    661      1.1  christos                 default:
    662      1.1  christos                     hexdump = TRUE;
    663      1.1  christos                     break;
    664      1.1  christos                 }
    665  1.1.1.7       spz                 cfm_tlv_len -= chassis_id_length;
    666      1.1  christos 
    667  1.1.1.7       spz                 tptr += 1 + chassis_id_length;
    668  1.1.1.7       spz                 tlen -= 1 + chassis_id_length;
    669  1.1.1.7       spz             }
    670      1.1  christos 
    671      1.1  christos             /*
    672      1.1  christos              * Check if there is a Management Address.
    673  1.1.1.8  christos              * IEEE 802.1Q-2014 Section 21.5.3.4: Management Address Domain Length
    674  1.1.1.8  christos              * This and all subsequent fields are not present if the TLV length
    675  1.1.1.8  christos              * allows only the above fields.
    676      1.1  christos              */
    677  1.1.1.7       spz             if (cfm_tlv_len == 0) {
    678  1.1.1.7       spz                 /* No, there isn't; we're done. */
    679  1.1.1.8  christos                 break;
    680      1.1  christos             }
    681      1.1  christos 
    682  1.1.1.8  christos             /* Here mgmt_addr_length stands for the management domain length. */
    683  1.1.1.9  christos             mgmt_addr_length = GET_U_1(tptr);
    684      1.1  christos             tptr++;
    685      1.1  christos             tlen--;
    686  1.1.1.7       spz             cfm_tlv_len--;
    687  1.1.1.9  christos             ND_PRINT("\n\t  Management Address Domain Length %u", mgmt_addr_length);
    688      1.1  christos             if (mgmt_addr_length) {
    689  1.1.1.8  christos                 /* IEEE 802.1Q-2014 Section 21.5.3.5: Management Address Domain */
    690  1.1.1.7       spz                 if (cfm_tlv_len < mgmt_addr_length) {
    691  1.1.1.9  christos                     ND_PRINT("\n\t  (TLV too short)");
    692  1.1.1.8  christos                     goto next_tlv;
    693  1.1.1.7       spz                 }
    694  1.1.1.7       spz                 cfm_tlv_len -= mgmt_addr_length;
    695  1.1.1.7       spz                 /*
    696  1.1.1.7       spz                  * XXX - this is an OID; print it as such.
    697  1.1.1.7       spz                  */
    698  1.1.1.8  christos                 hex_print(ndo, "\n\t  Management Address Domain: ", tptr, mgmt_addr_length);
    699  1.1.1.7       spz                 tptr += mgmt_addr_length;
    700  1.1.1.7       spz                 tlen -= mgmt_addr_length;
    701  1.1.1.7       spz 
    702  1.1.1.8  christos                 /*
    703  1.1.1.8  christos                  * IEEE 802.1Q-2014 Section 21.5.3.6: Management Address Length
    704  1.1.1.8  christos                  * This field is present if Management Address Domain Length is not 0.
    705  1.1.1.8  christos                  */
    706  1.1.1.7       spz                 if (cfm_tlv_len < 1) {
    707  1.1.1.9  christos                     ND_PRINT(" (Management Address Length is missing)");
    708  1.1.1.8  christos                     hexdump = TRUE;
    709  1.1.1.8  christos                     break;
    710  1.1.1.7       spz                 }
    711  1.1.1.8  christos 
    712  1.1.1.8  christos                 /* Here mgmt_addr_length stands for the management address length. */
    713  1.1.1.9  christos                 mgmt_addr_length = GET_U_1(tptr);
    714  1.1.1.7       spz                 tptr++;
    715  1.1.1.7       spz                 tlen--;
    716  1.1.1.7       spz                 cfm_tlv_len--;
    717  1.1.1.9  christos                 ND_PRINT("\n\t  Management Address Length %u", mgmt_addr_length);
    718  1.1.1.7       spz                 if (mgmt_addr_length) {
    719  1.1.1.8  christos                     /* IEEE 802.1Q-2014 Section 21.5.3.7: Management Address */
    720  1.1.1.7       spz                     if (cfm_tlv_len < mgmt_addr_length) {
    721  1.1.1.9  christos                         ND_PRINT("\n\t  (TLV too short)");
    722  1.1.1.7       spz                         return;
    723  1.1.1.7       spz                     }
    724  1.1.1.7       spz                     cfm_tlv_len -= mgmt_addr_length;
    725  1.1.1.7       spz                     /*
    726  1.1.1.7       spz                      * XXX - this is a TransportDomain; print it as such.
    727  1.1.1.7       spz                      */
    728  1.1.1.8  christos                     hex_print(ndo, "\n\t  Management Address: ", tptr, mgmt_addr_length);
    729  1.1.1.7       spz                     tptr += mgmt_addr_length;
    730  1.1.1.7       spz                     tlen -= mgmt_addr_length;
    731  1.1.1.7       spz                 }
    732      1.1  christos             }
    733  1.1.1.7       spz             break;
    734      1.1  christos         }
    735      1.1  christos 
    736      1.1  christos             /*
    737      1.1  christos              * FIXME those are the defined TLVs that lack a decoder
    738      1.1  christos              * you are welcome to contribute code ;-)
    739      1.1  christos              */
    740      1.1  christos 
    741      1.1  christos         case CFM_TLV_DATA:
    742      1.1  christos         case CFM_TLV_REPLY_INGRESS:
    743      1.1  christos         case CFM_TLV_REPLY_EGRESS:
    744      1.1  christos         default:
    745      1.1  christos             hexdump = TRUE;
    746      1.1  christos             break;
    747      1.1  christos         }
    748      1.1  christos         /* do we want to see an additional hexdump ? */
    749  1.1.1.4  christos         if (hexdump || ndo->ndo_vflag > 1)
    750  1.1.1.4  christos             print_unknown_data(ndo, tlv_ptr, "\n\t  ", cfm_tlv_len);
    751      1.1  christos 
    752  1.1.1.8  christos next_tlv:
    753      1.1  christos         tptr+=cfm_tlv_len;
    754      1.1  christos         tlen-=cfm_tlv_len;
    755      1.1  christos     }
    756      1.1  christos     return;
    757  1.1.1.7       spz 
    758  1.1.1.7       spz tooshort:
    759  1.1.1.9  christos     ND_PRINT("\n\t\t packet is too short");
    760  1.1.1.7       spz     return;
    761  1.1.1.7       spz 
    762      1.1  christos trunc:
    763  1.1.1.9  christos     nd_print_trunc(ndo);
    764      1.1  christos }
    765