On 2006/10/27 14:03, Pete Vickers wrote:
> A nice start could be to teach our tcpdump about RSTP. At present it  
> just pukes:

something like this? (coding style probably sucks, but I'm no coder :)

Index: print-stp.c
===================================================================
RCS file: /data/cvsroot/OpenBSD/src/usr.sbin/tcpdump/print-stp.c,v
retrieving revision 1.4
diff -u -r1.4 print-stp.c
--- print-stp.c 20 Dec 2004 08:30:40 -0000      1.4
+++ print-stp.c 29 Oct 2006 13:13:02 -0000
@@ -63,11 +63,22 @@
 #include "llc.h"
 
 #define        STP_MSGTYPE_CBPDU       0x00
+#define        STP_MSGTYPE_RBPDU       0x02            /* 802.1W RSTP */
 #define        STP_MSGTYPE_TBPDU       0x80
 
 #define        STP_FLAGS_TC            0x01            /* Topology change */
 #define        STP_FLAGS_TCA           0x80            /* Topology change ack 
*/
 
+#define        RSTP_FLAGS_PROPOSAL     0x02
+#define        RSTP_FLAGS_LEARNING     0x10
+#define        RSTP_FLAGS_FORWARDING   0x20
+#define        RSTP_FLAGS_AGREEMENT    0x40
+
+#define        RSTP_MASK_PORTROLE      0x0C
+#define        RSTP_ROLE_ALTERNATE     0x04            
+#define        RSTP_ROLE_ROOT          0x08
+#define        RSTP_ROLE_DESIGNATED    0x0C
+
 static void stp_print_cbpdu(const u_char *, u_int, int);
 static void stp_print_tbpdu(const u_char *, u_int);
 
@@ -102,9 +113,13 @@
                printf(" unknown protocol id(0x%x)", id);
                return;
        }
-       if (p[2] != 0) {
-               printf(" unknown protocol ver(0x%x)", p[2]);
-               return;
+       if (p[2] == 2 ) {
+               printf(" RSTP");
+       } else {
+               if (p[2] != 0) {
+                       printf(" unknown protocol ver(0x%x)", p[2]);
+                       return;
+               }
        }
        p += 3;
        len -= 3;
@@ -113,6 +128,7 @@
                goto truncated;
        switch (*p) {
        case STP_MSGTYPE_CBPDU:
+       case STP_MSGTYPE_RBPDU:
                stp_print_cbpdu(p, len, cisco_sstp);
                break;
        case STP_MSGTYPE_TBPDU:
@@ -154,6 +170,28 @@
                        printf("%stc", (x++ != 0) ? "," : "");
                if ((*p) & STP_FLAGS_TCA)
                        printf("%stcack", (x++ != 0) ? "," : "");
+               if ((*p) & RSTP_FLAGS_PROPOSAL)
+                       printf("%sproposal", (x++ != 0) ? "," : "");
+               if ((*p) & RSTP_FLAGS_LEARNING)
+                       printf("%slearn", (x++ != 0) ? "," : "");
+               if ((*p) & RSTP_FLAGS_FORWARDING)
+                       printf("%sfwd", (x++ != 0) ? "," : "");
+               if ((*p) & RSTP_FLAGS_AGREEMENT)
+                       printf("%sagree", (x++ != 0) ? "," : "");
+
+               t = ((*p) & RSTP_MASK_PORTROLE);
+
+               switch (t) {
+                       case RSTP_ROLE_ALTERNATE:
+                               printf("%srole=alt", (x++ != 0) ? "," : "");
+                               break;
+                       case RSTP_ROLE_ROOT:
+                               printf("%srole=root", (x++ != 0) ? "," : "");
+                               break;
+                       case RSTP_ROLE_DESIGNATED:
+                               printf("%srole=desig", (x++ != 0) ? "," : "");
+                               break;
+               }
                putchar('>');
        }
        p += 1;

Reply via email to