]> The Tcpdump Group git mirrors - tcpdump/commitdiff
add skeleton support for 802.1ag CFM
authorhannes <hannes>
Thu, 12 Oct 2006 10:26:12 +0000 (10:26 +0000)
committerhannes <hannes>
Thu, 12 Oct 2006 10:26:12 +0000 (10:26 +0000)
FILES
Makefile.in
ethertype.h
interface.h
print-cfm.c [new file with mode: 0644]
print-ether.c
win32/prj/GNUmakefile
win32/prj/WinDump.dsp

diff --git a/FILES b/FILES
index 110c268aaef114a4b650efaba39f5b2b7cfcac77..4faaa4b20ce2fc367183b75a69302b6b4e477f42 100644 (file)
--- a/FILES
+++ b/FILES
@@ -126,6 +126,7 @@ print-bfd.c
 print-bgp.c
 print-bootp.c
 print-cdp.c
+print-cfm.c
 print-chdlc.c
 print-cip.c
 print-cnfp.c
index 9891ad69eca2e58e30056dd24484af969bd4ae6e..86e5a0173fa0218f9ced03cf8936c554eb4ffa7b 100644 (file)
@@ -17,7 +17,7 @@
 #  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 #  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 #
-# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.303 2006-10-04 18:03:15 guy Exp $ (LBL)
+# @(#) $Header: /tcpdump/master/tcpdump/Makefile.in,v 1.304 2006-10-12 10:26:12 hannes Exp $ (LBL)
 
 #
 # Various configurable paths (remember to edit Makefile.in, not Makefile)
@@ -70,7 +70,7 @@ CSRC =        addrtoname.c af.c checksum.c cpack.c gmpls.c oui.c gmt2local.c ipproto.c
        print-802_11.c print-ap1394.c print-ah.c print-arcnet.c \
        print-aodv.c print-arp.c print-ascii.c print-atalk.c print-atm.c \
        print-beep.c print-bfd.c print-bgp.c print-bootp.c print-cdp.c \
-       print-chdlc.c print-cip.c print-cnfp.c print-dccp.c print-decnet.c \
+       print-cfm.c print-chdlc.c print-cip.c print-cnfp.c print-dccp.c print-decnet.c \
        print-domain.c print-dvmrp.c print-enc.c print-egp.c \
        print-eap.c print-eigrp.c\
        print-esp.c print-ether.c print-fddi.c print-fr.c \
index 17d81965fa41a0c37b046d82b4f9f7b37a4143bb..96d6186959dfa14a13f0c1c55f92af853d49771a 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/ethertype.h,v 1.26 2006-02-10 04:52:25 hannes Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/ethertype.h,v 1.27 2006-10-12 10:26:12 hannes Exp $ (LBL)
  */
 
 /*
 #ifndef        ETHERTYPE_VMAN
 #define        ETHERTYPE_VMAN          0x9100 /* Extreme VMAN Protocol */ 
 #endif
+#ifndef        ETHERTYPE_CFM
+#define        ETHERTYPE_CFM           0xabcd /* 802.1ag - Ethertype is not yet assigned */
+#endif
 #ifndef        ETHERTYPE_ISO
 #define        ETHERTYPE_ISO           0xfefe  /* nonstandard - used in Cisco HDLC encapsulation */
 #endif
index 4204063d14574aa02bfb28c2915acf5fec02e79a..7464a3b392fd003ce8f45b1f31cbeac9f2a613f3 100644 (file)
@@ -18,7 +18,7 @@
  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.271 2006-09-25 09:23:32 hannes Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/interface.h,v 1.272 2006-10-12 10:26:12 hannes Exp $ (LBL)
  */
 
 #ifndef tcpdump_interface_h
@@ -300,6 +300,7 @@ extern void l2tp_print(const u_char *, u_int);
 extern void vrrp_print(const u_char *, u_int, int);
 extern void slow_print(const u_char *, u_int);
 extern void mpcp_print(const u_char *, u_int);
+extern void cfm_print(const u_char *, u_int);
 extern void pgm_print(const u_char *, u_int, const u_char *);
 extern void cdp_print(const u_char *, u_int, u_int);
 extern void stp_print(const u_char *, u_int);
diff --git a/print-cfm.c b/print-cfm.c
new file mode 100644 (file)
index 0000000..7f4360f
--- /dev/null
@@ -0,0 +1,389 @@
+/*
+ * Copyright (c) 1998-2006 The TCPDUMP project
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that: (1) source code
+ * distributions retain the above copyright notice and this paragraph
+ * in its entirety, and (2) distributions including binary code include
+ * the above copyright notice and this paragraph in its entirety in
+ * the documentation or other materials provided with the distribution.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
+ * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
+ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE.
+ *
+ * Support for the IEEE Connectivity Fault Management Protocols as per 802.1ag.
+ *
+ * Original code by Hannes Gredler ([email protected])
+ */
+
+#ifndef lint
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/tcpdump/print-cfm.c,v 1.1 2006-10-12 10:26:12 hannes Exp $";
+#endif
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tcpdump-stdinc.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "interface.h"
+#include "extract.h"
+#include "ether.h"
+#include "addrtoname.h"
+
+struct cfm_common_header_t {
+    u_int8_t mdlevel_version;
+    u_int8_t opcode;
+    u_int8_t flags;
+    u_int8_t first_tlv_offset;
+};
+
+#define        CFM_VERSION 0
+#define CFM_EXTRACT_VERSION(x) (((x)&0x1f))
+#define CFM_EXTRACT_MD_LEVEL(x) (((x)&0xe0)>>5)
+
+#define        CFM_OPCODE_CCM 1
+#define        CFM_OPCODE_LBR 2
+#define        CFM_OPCODE_LBM 3
+#define        CFM_OPCODE_LTR 4
+#define        CFM_OPCODE_LTM 5
+
+static const struct tok cfm_opcode_values[] = {
+    { CFM_OPCODE_CCM, "Continouity Check Message"},
+    { CFM_OPCODE_LBR, "Loopback Reply"},
+    { CFM_OPCODE_LBM, "Loopback Message"},
+    { CFM_OPCODE_LTR, "Linktrace Reply"},
+    { CFM_OPCODE_LTM, "Linktrace Message"},
+    { 0, NULL}
+};
+
+/*
+ * Message Formats.
+ */
+struct cfm_ccm_t {
+    u_int8_t sequence[4];
+    u_int8_t ma_epi[2];
+    u_int8_t md_nameformat;
+    u_int8_t md_namelength;
+    u_int8_t md_name[46]; /* md name and short ma name */
+    u_int8_t reserved_itu[16];
+    u_int8_t reserved[6];
+};
+
+/*
+ * Timer Bases for the CCM Interval field.
+ * Expressed in units of seconds.
+ */
+const float ccm_interval_base[8] = {0, 0.003333, 0.01, 0.1, 1, 10, 60, 600};
+#define CCM_INTERVAL_MIN_MULTIPLIER 3.25
+#define CCM_INTERVAL_MAX_MULTIPLIER 3.5
+
+#define CFM_CCM_RDI_FLAG 0x80
+#define CFM_EXTRACT_CCM_INTERVAL(x) (((x)&0x07))
+
+#define CFM_CCM_MD_FORMAT_8021 0
+#define CFM_CCM_MD_FORMAT_NONE 1
+#define CFM_CCM_MD_FORMAT_DNS  2
+#define CFM_CCM_MD_FORMAT_MAC  3
+#define CFM_CCM_MD_FORMAT_CHAR 4
+
+static const struct tok cfm_md_nameformat_values[] = {
+    { CFM_CCM_MD_FORMAT_8021, "IEEE 802.1"},
+    { CFM_CCM_MD_FORMAT_NONE, "No MD Name present"},
+    { CFM_CCM_MD_FORMAT_DNS, "DNS string"},
+    { CFM_CCM_MD_FORMAT_MAC, "MAC + 16Bit Integer"},
+    { CFM_CCM_MD_FORMAT_CHAR, "Character string"},
+    { 0, NULL}
+};
+
+#define CFM_CCM_MA_FORMAT_8021 0
+#define CFM_CCM_MA_FORMAT_VID  1
+#define CFM_CCM_MA_FORMAT_CHAR 2
+#define CFM_CCM_MA_FORMAT_INT  3
+#define CFM_CCM_MA_FORMAT_VPN  4
+
+static const struct tok cfm_ma_nameformat_values[] = {
+    { CFM_CCM_MA_FORMAT_8021, "IEEE 802.1"},
+    { CFM_CCM_MA_FORMAT_VID, "Primary VID"},
+    { CFM_CCM_MA_FORMAT_CHAR, "Character string"},
+    { CFM_CCM_MA_FORMAT_INT, "16Bit Integer"},
+    { CFM_CCM_MA_FORMAT_VPN, "RFC2685 VPN-ID"},
+    { 0, NULL}
+};
+
+struct cfm_lbm_t {
+    u_int8_t transaction_id[4];
+    u_int8_t reserved[4];
+};
+
+struct cfm_ltm_t {
+    u_int8_t transaction_id[4];
+    u_int8_t egress_id[8];
+    u_int8_t ttl;
+    u_int8_t original_mac[ETHER_ADDR_LEN];
+    u_int8_t target_mac[ETHER_ADDR_LEN];
+    u_int8_t reserved[3];
+};
+
+struct cfm_ltr_t {
+    u_int8_t transaction_id[4];
+    u_int8_t last_egress_id[8];
+    u_int8_t next_egress_id[8];
+    u_int8_t ttl;
+    u_int8_t replay_action;
+    u_int8_t reserved[6];
+};
+
+/*
+ * TLVs
+ */
+
+struct cfm_tlv_header_t {
+    u_int8_t type;
+    u_int8_t length[2];
+};
+
+#define CFM_TLV_END 0
+#define CFM_TLV_SENDER_ID 1
+#define CFM_TLV_PORT_STATUS 2
+#define CFM_TLV_INTERFACE_STATUS 3
+#define CFM_TLV_DATA 4
+#define CFM_TLV_REPLY_INGRESS 5
+#define CFM_TLV_REPLY_EGRESS 6
+#define CFM_TLV_PRIVATE 31
+
+static const struct tok cfm_tlv_values[] = {
+    { CFM_TLV_END, "End"},
+    { CFM_TLV_SENDER_ID, "Sender ID"},
+    { CFM_TLV_PORT_STATUS, "Port status"},
+    { CFM_TLV_INTERFACE_STATUS, "Interface status"},
+    { CFM_TLV_DATA, "Data"},
+    { CFM_TLV_REPLY_INGRESS, "Reply Ingress"},
+    { CFM_TLV_REPLY_EGRESS, "Reply Egress"},
+    { CFM_TLV_PRIVATE, "Organization Specific"},
+    { 0, NULL}
+};
+
+/* FIXME define TLV formats */
+
+void
+cfm_print(register const u_char *pptr, register u_int length) {
+
+    const struct cfm_common_header_t *cfm_common_header;
+    const struct cfm_tlv_header_t *cfm_tlv_header;
+    const u_int8_t *tptr, *tlv_tptr, *ma_name, *ma_nameformat, *ma_namelength;
+    u_int tlen, cfm_tlv_len, cfm_tlv_type, tlv_tlen, ccm_interval;
+
+
+    union {
+        const struct cfm_ccm_t *cfm_ccm;
+        const struct cfm_lbm_t *cfm_lbm;
+        const struct cfm_ltm_t *cfm_ltm;
+        const struct cfm_ltr_t *cfm_ltr;
+    } msg_ptr;
+
+    tptr=pptr;
+    cfm_common_header = (const struct cfm_common_header_t *)pptr;
+    TCHECK(*cfm_common_header);
+
+    /*
+     * Sanity checking of the header.
+     */
+    if (CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version) != CFM_VERSION) {
+       printf("CFMv%u not supported, length %u",
+               CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version), length);
+       return;
+    }
+
+    printf("CFMv%u %s, length %u",
+           CFM_EXTRACT_VERSION(cfm_common_header->mdlevel_version),
+           tok2str(cfm_opcode_values, "unknown (%u)", cfm_common_header->opcode),
+           length);
+
+    /*
+     * In non-verbose mode just lets print the opcode and bail.
+     */
+    if (vflag < 1) {
+        return;
+    }
+
+    printf("\n\tMD Level %u, First TLV offset %u",
+           CFM_EXTRACT_MD_LEVEL(cfm_common_header->mdlevel_version),
+           cfm_common_header->first_tlv_offset);
+
+    tptr += sizeof(const struct cfm_common_header_t);
+    tlen = length - sizeof(struct cfm_common_header_t);
+
+    switch (cfm_common_header->opcode) {
+    case CFM_OPCODE_CCM:
+        msg_ptr.cfm_ccm = (const struct cfm_ccm_t *)tptr;
+
+        ccm_interval = CFM_EXTRACT_CCM_INTERVAL(cfm_common_header->flags);
+        printf(", Flags [CCM Interval %u%s]",
+               ccm_interval,
+               cfm_common_header->flags & CFM_CCM_RDI_FLAG ?
+               ", RDI" : "");
+
+        /*
+         * Resolve the CCM interval field.
+         */
+        if (ccm_interval) {
+            printf("\n\t  CCM Interval %.3fs"
+                   ", min CCM Lifetime %.3fs, max CCM Lifetime %.3fs",
+                   ccm_interval_base[ccm_interval],
+                   ccm_interval_base[ccm_interval] * CCM_INTERVAL_MIN_MULTIPLIER,
+                   ccm_interval_base[ccm_interval] * CCM_INTERVAL_MAX_MULTIPLIER);
+        }
+
+        printf("\n\t  Sequence Number 0x%08x, MA-End-Point-ID 0x%04x",
+               EXTRACT_32BITS(msg_ptr.cfm_ccm->sequence),
+               EXTRACT_16BITS(msg_ptr.cfm_ccm->ma_epi));
+
+
+        /*
+         * Resolve the MD fields.
+         */
+        printf("\n\t  MD Name Format %s (%u), MD Name length %u",
+               tok2str(cfm_md_nameformat_values, "Unknown",
+                       msg_ptr.cfm_ccm->md_nameformat),
+               msg_ptr.cfm_ccm->md_nameformat,
+               msg_ptr.cfm_ccm->md_namelength);
+
+        if (msg_ptr.cfm_ccm->md_nameformat != CFM_CCM_MD_FORMAT_NONE) {
+            printf("\n\t  MD Name: ");
+            switch (msg_ptr.cfm_ccm->md_nameformat) {
+            case CFM_CCM_MD_FORMAT_DNS:
+            case CFM_CCM_MD_FORMAT_CHAR:
+                safeputs(msg_ptr.cfm_ccm->md_name, msg_ptr.cfm_ccm->md_namelength);
+                break;
+
+                /* FIXME add printers for those MD formats - hexdump for now */
+            case CFM_CCM_MA_FORMAT_8021:
+            case CFM_CCM_MD_FORMAT_MAC:
+            default:
+                print_unknown_data(msg_ptr.cfm_ccm->md_name, "\n\t    ",
+                                   msg_ptr.cfm_ccm->md_namelength);
+            }
+        }
+
+
+        /*
+         * Resolve the MA fields.
+         */
+        ma_nameformat = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength;
+        ma_namelength = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 1;
+        ma_name = msg_ptr.cfm_ccm->md_name + msg_ptr.cfm_ccm->md_namelength + 2;
+
+        printf("\n\t  MA Name-Format %s (%u), MA name length %u",
+               tok2str(cfm_ma_nameformat_values, "Unknown",
+                       *ma_nameformat),
+               *ma_nameformat,
+               *ma_namelength);        
+
+        printf("\n\t  MA Name: ");
+        switch (*ma_nameformat) {
+        case CFM_CCM_MA_FORMAT_CHAR:
+            safeputs(ma_name, *ma_namelength);
+            break;
+
+            /* FIXME add printers for those MA formats - hexdump for now */
+        case CFM_CCM_MA_FORMAT_8021:
+        case CFM_CCM_MA_FORMAT_VID:
+        case CFM_CCM_MA_FORMAT_INT:
+        case CFM_CCM_MA_FORMAT_VPN:
+        default:
+            print_unknown_data(ma_name, "\n\t    ", *ma_namelength);
+        }
+        break;
+
+        /*
+         * No message decoder yet.
+         * Hexdump everything up until the start of the TLVs
+         */
+    case CFM_OPCODE_LBR:
+    case CFM_OPCODE_LBM:
+    case CFM_OPCODE_LTR:
+    case CFM_OPCODE_LTM:
+    default:
+        if (tlen > cfm_common_header->first_tlv_offset) {
+            print_unknown_data(tptr, "\n\t  ",
+                               tlen -  cfm_common_header->first_tlv_offset);
+        }
+        break;
+    }
+
+    /*
+     * Sanity check for not walking off.
+     */
+    if (tlen <= cfm_common_header->first_tlv_offset) {
+        return;
+    }
+
+    tptr += cfm_common_header->first_tlv_offset;
+    tlen -= cfm_common_header->first_tlv_offset;
+    
+    while (tlen > 0) {
+        /* did we capture enough for fully decoding the object header ? */
+        TCHECK2(*tptr, sizeof(struct cfm_tlv_header_t));
+
+        cfm_tlv_header = (const struct cfm_tlv_header_t *)tptr;
+        cfm_tlv_len=EXTRACT_16BITS(&cfm_tlv_header->length);
+        cfm_tlv_type=cfm_tlv_header->type;
+
+        if (cfm_tlv_len < sizeof(struct cfm_tlv_header_t) ||
+            cfm_tlv_len > tlen) {
+            print_unknown_data(tptr+sizeof(sizeof(struct cfm_tlv_header_t)),"\n\t    ",tlen);
+            return;
+        }
+
+        printf("\n\t  %s TLV (0x%04x), length: %u",
+               tok2str(cfm_tlv_values,
+                       "Unknown",
+                       cfm_tlv_type),
+               cfm_tlv_type,
+               cfm_tlv_len);
+
+        tlv_tptr=tptr+sizeof(struct cfm_tlv_header_t);
+        tlv_tlen=cfm_tlv_len-sizeof(struct cfm_tlv_header_t);
+
+        /* did we capture enough for fully decoding the object ? */
+        TCHECK2(*tptr, cfm_tlv_len);
+
+        switch(cfm_tlv_type) {
+
+            /*
+             * FIXME those are the defined TLVs that lack a decoder
+             * you are welcome to contribute code ;-)
+             */
+
+        case CFM_TLV_END:
+        case CFM_TLV_SENDER_ID:
+        case CFM_TLV_PORT_STATUS:
+        case CFM_TLV_INTERFACE_STATUS:
+        case CFM_TLV_DATA:
+        case CFM_TLV_REPLY_INGRESS:
+        case CFM_TLV_REPLY_EGRESS:
+        case CFM_TLV_PRIVATE:
+        default:
+            if (vflag <= 1)
+                print_unknown_data(tlv_tptr,"\n\t    ",tlv_tlen);
+            break;
+        }
+        /* do we want to see an additional hexdump ? */
+        if (vflag > 1)
+            print_unknown_data(tptr+sizeof(sizeof(struct cfm_tlv_header_t)),"\n\t    ",
+                               cfm_tlv_len-sizeof(struct cfm_tlv_header_t));
+
+        tptr+=cfm_tlv_len;
+        tlen-=cfm_tlv_len;
+    }
+    return;
+trunc:
+    printf("\n\t\t packet exceeded snapshot");
+}
index 2f656430a319762687dddf54a2eed9ec27f8d9ca..441cee0f1afd5cfb69a1aad7ecbc9e18f7c8a35e 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.102 2006-02-20 18:13:55 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.103 2006-10-12 10:26:12 hannes Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -74,6 +74,7 @@ const struct tok ethertype_values[] = {
     { ETHERTYPE_LOOPBACK,       "Loopback" },
     { ETHERTYPE_ISO,            "OSI" },
     { ETHERTYPE_GRE_ISO,        "GRE-OSI" },
+    { ETHERTYPE_CFM,            "CFM" },
     { 0, NULL}
 };
 
@@ -307,6 +308,10 @@ ether_encap_print(u_short ether_type, const u_char *p,
                slow_print(p, length);
                return (1);
 
+       case ETHERTYPE_CFM:
+               cfm_print(p, length);
+               return (1);
+
         case ETHERTYPE_LOOPBACK:
                 return (1);
 
index 6013f1f4ad9c300f1c3fd19023b511e4183a0207..7cd03efc5cb2a411b63463b6f54952d50cfaa5a2 100644 (file)
@@ -57,6 +57,7 @@ OBJS = \
        ../../print-bgp.o \
        ../../print-bootp.o \
        ../../print-cdp.o \
+       ../../print-cfm.o \
        ../../print-chdlc.o \
        ../../print-cip.o \
        ../../print-cnfp.o \
index 03611b53f9803b5aadfc0d71bd222acbb273a727..a8e0fa13514e0a1aec8e92716a9ea5f5e732cc63 100644 (file)
@@ -217,6 +217,10 @@ SOURCE="..\..\print-cdp.c"
 # End Source File
 # Begin Source File
 
+SOURCE="..\..\print-cfm.c"
+# End Source File
+# Begin Source File
+
 SOURCE="..\..\print-chdlc.c"
 # End Source File
 # Begin Source File