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