]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-atm.c
Improve printout of DHCPv6 options.
[tcpdump] / print-atm.c
index b7a1c341c242d7bfa1a05268829ef2bceb7d3ad5..135898bad91a89e2d5ba777eceeed83594f2ad6e 100644 (file)
@@ -20,7 +20,7 @@
  */
 #ifndef lint
 static const char rcsid[] _U_ =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.45 2006-02-08 01:43:00 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-atm.c,v 1.49 2007-10-22 19:37:51 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -49,8 +49,19 @@ static const char rcsid[] _U_ =
 #define OAM_CELLTYPE_FUNCTYPE_LEN 1
 
 struct tok oam_f_values[] = {
-    { OAMF4SC, "OAM F4 (segment)" },
-    { OAMF4EC, "OAM F4 (end)" },
+    { VCI_OAMF4SC, "OAM F4 (segment)" },
+    { VCI_OAMF4EC, "OAM F4 (end)" },
+    { 0, NULL }
+};
+
+struct tok atm_pty_values[] = {
+    { 0x0, "user data, uncongested, SDU 0" },
+    { 0x1, "user data, uncongested, SDU 1" },
+    { 0x2, "user data, congested, SDU 0" },
+    { 0x3, "user data, congested, SDU 1" },
+    { 0x4, "VCC OAM F5 flow segment" },
+    { 0x5, "VCC OAM F5 flow end-to-end" },
+    { 0x6, "Traffic Control and resource Mgmt" },
     { 0, NULL }
 };
 
@@ -284,24 +295,24 @@ atm_print(u_int vpi, u_int vci, u_int traftype, const u_char *p, u_int length,
        if (vpi == 0) {
                switch (vci) {
 
-               case PPC:
+               case VCI_PPC:
                        sig_print(p, caplen);
                        return;
 
-               case BCC:
+               case VCI_BCC:
                        printf("broadcast sig: ");
                        return;
 
-               case OAMF4SC: /* fall through */
-               case OAMF4EC:
+               case VCI_OAMF4SC: /* fall through */
+               case VCI_OAMF4EC:
                         oam_print(p, length, ATM_OAM_HEC);
                        return;
 
-               case METAC:
+               case VCI_METAC:
                        printf("meta: ");
                        return;
 
-               case ILMIC:
+               case VCI_ILMIC:
                        printf("ilmi: ");
                        snmp_print(p, length);
                        return;
@@ -338,47 +349,11 @@ struct oam_fm_ais_rdi_t {
     u_int8_t unused[28];
 };
 
-
-#define CRC10_POLYNOMIAL 0x633
-static u_int16_t crc10_table[256];
-
-static void
-gen_crc10_table(void)
-{   
-    register int i, j;
-    register u_int16_t accum;
-    
-    for ( i = 0;  i < 256;  i++ )
-    {
-        accum = ((unsigned short) i << 2);
-        for ( j = 0;  j < 8;  j++ )
-        {
-            if ((accum <<= 1) & 0x400) accum ^= CRC10_POLYNOMIAL;
-        }
-        crc10_table[i] = accum;
-    }
-    return;
-}
-
-static u_int16_t
-verify_crc10_cksum(u_int16_t accum, const u_char *p, int length)
-{
-    register int i;
-
-    for ( i = 0;  i < length;  i++ )
-    {
-        accum = ((accum << 8) & 0x3ff)
-            ^ crc10_table[( accum >> 2) & 0xff]
-            ^ *p++;
-    }
-    return accum;
-}
-
 int 
 oam_print (const u_char *p, u_int length, u_int hec) {
 
     u_int32_t cell_header;
-    u_int16_t vpi, vci, cksum, cksum_shouldbe;
+    u_int16_t vpi, vci, cksum, cksum_shouldbe, idx;
     u_int8_t  cell_type, func_type, payload, clp;
 
     union {
@@ -396,9 +371,11 @@ oam_print (const u_char *p, u_int length, u_int hec) {
     payload = (cell_header>>1)&0x7;
     clp = cell_header&0x1;
 
-    printf("%s, vpi %u, vci %u, payload %u, clp %u, length %u",
+    printf("%s, vpi %u, vci %u, payload [ %s ], clp %u, length %u",
            tok2str(oam_f_values, "OAM F5", vci),
-           vpi, vci, payload, clp, length);
+           vpi, vci,
+           tok2str(atm_pty_values, "Unknown", payload),
+           clp, length);
 
     if (!vflag) {
         return 1;
@@ -424,30 +401,49 @@ oam_print (const u_char *p, u_int length, u_int hec) {
                tok2str(oam_fm_loopback_indicator_values,
                        "Unknown",
                        oam_ptr.oam_fm_loopback->loopback_indicator & OAM_FM_LOOPBACK_INDICATOR_MASK),
-               EXTRACT_LE_32BITS(&oam_ptr.oam_fm_loopback->correlation_tag));
+               EXTRACT_32BITS(&oam_ptr.oam_fm_loopback->correlation_tag));
         printf("\n\tLocation-ID ");
-        safeputs((const char *)&oam_ptr.oam_fm_loopback->loopback_id,
-                 sizeof(oam_ptr.oam_fm_loopback->loopback_id));
+        for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->loopback_id); idx++) {
+            if (idx % 2) {
+                printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_loopback->loopback_id[idx]));
+            }
+        }
         printf("\n\tSource-ID   ");
-        safeputs((const char *)&oam_ptr.oam_fm_loopback->source_id,
-                 sizeof(oam_ptr.oam_fm_loopback->source_id));
+        for (idx = 0; idx < sizeof(oam_ptr.oam_fm_loopback->source_id); idx++) {
+            if (idx % 2) {
+                printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_loopback->source_id[idx]));
+            }
+        }
         break;
+
+    case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_AIS):
+    case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_RDI):
+        oam_ptr.oam_fm_ais_rdi = (const struct oam_fm_ais_rdi_t *)(p + OAM_CELLTYPE_FUNCTYPE_LEN);
+        printf("\n\tFailure-type 0x%02x", oam_ptr.oam_fm_ais_rdi->failure_type);
+        printf("\n\tLocation-ID ");
+        for (idx = 0; idx < sizeof(oam_ptr.oam_fm_ais_rdi->failure_location); idx++) {
+            if (idx % 2) {
+                printf("%04x ", EXTRACT_16BITS(&oam_ptr.oam_fm_ais_rdi->failure_location[idx]));
+            }
+        }
+        break;
+
+    case (OAM_CELLTYPE_FM << 4 | OAM_FM_FUNCTYPE_CONTCHECK):
+        /* FIXME */
+        break;
+
     default:
         break;
     }
 
     /* crc10 checksum verification */
-    gen_crc10_table();
-    cksum = EXTRACT_16BITS(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN) & OAM_CRC10_MASK;
+    cksum = EXTRACT_16BITS(p + OAM_CELLTYPE_FUNCTYPE_LEN + OAM_FUNCTION_SPECIFIC_LEN)
+        & OAM_CRC10_MASK;
     cksum_shouldbe = verify_crc10_cksum(0, p, OAM_PAYLOAD_LEN);
     
-    printf("\n\tcksum 0x%03x", cksum);
-
-    if (cksum_shouldbe == 0) {
-        printf(" (correct)");
-    } else {
-        printf(" (incorrect (-> 0x%03x))", cksum_shouldbe);
-    }
+    printf("\n\tcksum 0x%03x (%scorrect)",
+           cksum,
+           cksum_shouldbe == 0 ? "" : "in");
 
     return 1;
 }