Home | History | Annotate | Line # | Download | only in dist
print-stp.c revision 1.2.6.1
      1      1.1  christos /*
      2      1.1  christos  * Copyright (c) 2000 Lennert Buytenhek
      3      1.1  christos  *
      4      1.1  christos  * This software may be distributed either under the terms of the
      5      1.1  christos  * BSD-style license that accompanies tcpdump or the GNU General
      6      1.1  christos  * Public License
      7      1.1  christos  *
      8      1.1  christos  * Format and print IEEE 802.1d spanning tree protocol packets.
      9      1.1  christos  * Contributed by Lennert Buytenhek <buytenh (at) gnu.org>
     10      1.1  christos  */
     11      1.1  christos 
     12      1.2  christos #include <sys/cdefs.h>
     13      1.1  christos #ifndef lint
     14      1.2  christos #if 0
     15      1.1  christos static const char rcsid[] _U_ =
     16  1.2.6.1      yamt "@(#) Header: /tcpdump/master/tcpdump/print-stp.c,v 1.20 2007-03-18 17:11:46 hannes Exp ";
     17      1.2  christos #else
     18  1.2.6.1      yamt __RCSID("$NetBSD: print-stp.c,v 1.2.6.1 2014/05/22 15:51:20 yamt Exp $");
     19      1.2  christos #endif
     20      1.1  christos #endif
     21      1.1  christos 
     22      1.1  christos #ifdef HAVE_CONFIG_H
     23      1.1  christos #include "config.h"
     24      1.1  christos #endif
     25      1.1  christos 
     26      1.1  christos #include <tcpdump-stdinc.h>
     27      1.1  christos 
     28      1.1  christos #include <stdlib.h>
     29      1.1  christos #include <stdio.h>
     30      1.1  christos #include <string.h>
     31      1.1  christos 
     32      1.1  christos #include "interface.h"
     33      1.1  christos #include "addrtoname.h"
     34      1.1  christos #include "extract.h"
     35      1.1  christos 
     36      1.1  christos #define	RSTP_EXTRACT_PORT_ROLE(x) (((x)&0x0C)>>2)
     37      1.1  christos /* STP timers are expressed in multiples of 1/256th second */
     38      1.1  christos #define STP_TIME_BASE 256
     39      1.1  christos #define STP_BPDU_MSTP_MIN_LEN 102
     40      1.1  christos 
     41      1.1  christos struct stp_bpdu_ {
     42      1.1  christos     u_int8_t protocol_id[2];
     43      1.1  christos     u_int8_t protocol_version;
     44      1.1  christos     u_int8_t bpdu_type;
     45      1.1  christos     u_int8_t flags;
     46      1.1  christos     u_int8_t root_id[8];
     47      1.1  christos     u_int8_t root_path_cost[4];
     48      1.1  christos     u_int8_t bridge_id[8];
     49      1.1  christos     u_int8_t port_id[2];
     50      1.1  christos     u_int8_t message_age[2];
     51      1.1  christos     u_int8_t max_age[2];
     52      1.1  christos     u_int8_t hello_time[2];
     53      1.1  christos     u_int8_t forward_delay[2];
     54      1.1  christos     u_int8_t v1_length;
     55      1.1  christos };
     56      1.1  christos 
     57      1.1  christos #define STP_PROTO_REGULAR 0x00
     58      1.1  christos #define STP_PROTO_RAPID   0x02
     59      1.1  christos #define STP_PROTO_MSTP    0x03
     60  1.2.6.1      yamt #define STP_PROTO_SPB     0x04
     61      1.1  christos 
     62  1.2.6.1      yamt static const struct tok stp_proto_values[] = {
     63      1.1  christos     { STP_PROTO_REGULAR, "802.1d" },
     64      1.1  christos     { STP_PROTO_RAPID, "802.1w" },
     65      1.1  christos     { STP_PROTO_MSTP, "802.1s" },
     66  1.2.6.1      yamt     { STP_PROTO_SPB, "802.1aq" },
     67      1.1  christos     { 0, NULL}
     68      1.1  christos };
     69      1.1  christos 
     70      1.1  christos #define STP_BPDU_TYPE_CONFIG      0x00
     71      1.1  christos #define STP_BPDU_TYPE_RSTP        0x02
     72      1.1  christos #define STP_BPDU_TYPE_TOPO_CHANGE 0x80
     73      1.1  christos 
     74  1.2.6.1      yamt static const struct tok stp_bpdu_flag_values[] = {
     75      1.1  christos     { 0x01, "Topology change" },
     76      1.1  christos     { 0x02, "Proposal" },
     77      1.1  christos     { 0x10, "Learn" },
     78      1.1  christos     { 0x20, "Forward" },
     79      1.1  christos     { 0x40, "Agreement" },
     80      1.1  christos     { 0x80, "Topology change ACK" },
     81      1.1  christos     { 0, NULL}
     82      1.1  christos };
     83      1.1  christos 
     84  1.2.6.1      yamt static const struct tok stp_bpdu_type_values[] = {
     85      1.1  christos     { STP_BPDU_TYPE_CONFIG, "Config" },
     86      1.1  christos     { STP_BPDU_TYPE_RSTP, "Rapid STP" },
     87      1.1  christos     { STP_BPDU_TYPE_TOPO_CHANGE, "Topology Change" },
     88      1.1  christos     { 0, NULL}
     89      1.1  christos };
     90      1.1  christos 
     91  1.2.6.1      yamt static const struct tok rstp_obj_port_role_values[] = {
     92      1.1  christos     { 0x00, "Unknown" },
     93      1.1  christos     { 0x01, "Alternate" },
     94      1.1  christos     { 0x02, "Root" },
     95      1.1  christos     { 0x03, "Designated" },
     96      1.1  christos     { 0, NULL}
     97      1.1  christos };
     98      1.1  christos 
     99      1.1  christos static char *
    100      1.1  christos stp_print_bridge_id(const u_char *p)
    101      1.1  christos {
    102      1.1  christos     static char bridge_id_str[sizeof("pppp.aa:bb:cc:dd:ee:ff")];
    103      1.1  christos 
    104      1.1  christos     snprintf(bridge_id_str, sizeof(bridge_id_str),
    105      1.1  christos              "%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
    106      1.1  christos              p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
    107      1.1  christos 
    108      1.1  christos     return bridge_id_str;
    109      1.1  christos }
    110      1.1  christos 
    111      1.1  christos static void
    112      1.1  christos stp_print_config_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
    113      1.1  christos {
    114      1.1  christos     printf(", Flags [%s]",
    115      1.1  christos            bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags));
    116      1.1  christos 
    117      1.1  christos     printf(", bridge-id %s.%04x, length %u",
    118      1.1  christos            stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id),
    119      1.1  christos            EXTRACT_16BITS(&stp_bpdu->port_id), length);
    120      1.1  christos 
    121      1.1  christos     /* in non-verbose mode just print the bridge-id */
    122      1.1  christos     if (!vflag) {
    123      1.1  christos         return;
    124      1.1  christos     }
    125      1.1  christos 
    126      1.1  christos     printf("\n\tmessage-age %.2fs, max-age %.2fs"
    127      1.1  christos            ", hello-time %.2fs, forwarding-delay %.2fs",
    128      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
    129      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
    130      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
    131      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE);
    132      1.1  christos 
    133      1.1  christos     printf("\n\troot-id %s, root-pathcost %u",
    134      1.1  christos            stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
    135      1.1  christos            EXTRACT_32BITS(&stp_bpdu->root_path_cost));
    136      1.1  christos 
    137      1.1  christos     /* Port role is only valid for 802.1w */
    138      1.1  christos     if (stp_bpdu->protocol_version == STP_PROTO_RAPID) {
    139      1.1  christos         printf(", port-role %s",
    140      1.1  christos                tok2str(rstp_obj_port_role_values, "Unknown",
    141      1.1  christos                        RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)));
    142      1.1  christos     }
    143      1.1  christos }
    144      1.1  christos 
    145      1.1  christos /*
    146      1.1  christos  * MSTP packet format
    147      1.1  christos  * Ref. IEEE 802.1Q 2003 Ed. Section 14
    148      1.1  christos  *
    149      1.1  christos  * MSTP BPDU
    150      1.1  christos  *
    151      1.1  christos  * 2 -  bytes Protocol Id
    152      1.1  christos  * 1 -  byte  Protocol Ver.
    153      1.1  christos  * 1 -  byte  BPDU tye
    154      1.1  christos  * 1 -  byte  Flags
    155      1.1  christos  * 8 -  bytes CIST Root Identifier
    156      1.1  christos  * 4 -  bytes CIST External Path Cost
    157      1.1  christos  * 8 -  bytes CIST Regional Root Identifier
    158      1.1  christos  * 2 -  bytes CIST Port Identifier
    159      1.1  christos  * 2 -  bytes Message Age
    160      1.1  christos  * 2 -  bytes Max age
    161      1.1  christos  * 2 -  bytes Hello Time
    162      1.1  christos  * 2 -  bytes Forward delay
    163      1.1  christos  * 1 -  byte  Version 1 length. Must be 0
    164      1.1  christos  * 2 -  bytes Version 3 length
    165      1.1  christos  * 1 -  byte  Config Identifier
    166      1.1  christos  * 32 - bytes Config Name
    167      1.1  christos  * 2 -  bytes Revision level
    168      1.1  christos  * 16 - bytes Config Digest [MD5]
    169      1.1  christos  * 4 -  bytes CIST Internal Root Path Cost
    170      1.1  christos  * 8 -  bytes CIST Bridge Identifier
    171      1.1  christos  * 1 -  byte  CIST Remaining Hops
    172      1.1  christos  * 16 - bytes MSTI information [Max 64 MSTI, each 16 bytes]
    173      1.1  christos  *
    174  1.2.6.1      yamt  *
    175  1.2.6.1      yamt  * SPB BPDU
    176  1.2.6.1      yamt  * Ref. IEEE 802.1aq. Section 14
    177  1.2.6.1      yamt  *
    178  1.2.6.1      yamt  * 2 -  bytes Version 4 length
    179  1.2.6.1      yamt  * 1 -  byte  Aux Config Identifier
    180  1.2.6.1      yamt  * 32 - bytes Aux Config Name
    181  1.2.6.1      yamt  * 2 -  bytes Aux Revision level
    182  1.2.6.1      yamt  * 16 - bytes Aux Config Digest [MD5]
    183  1.2.6.1      yamt  * 1 -  byte  (1 - 2) Agreement Number
    184  1.2.6.1      yamt  *            (3 - 4) Discarded Agreement Number
    185  1.2.6.1      yamt  *            (5) Agreement Valid Flag
    186  1.2.6.1      yamt  *            (6) Restricted Role Flag
    187  1.2.6.1      yamt  *            (7 - 8) Unused sent zero
    188  1.2.6.1      yamt  * 1 -  byte Unused
    189  1.2.6.1      yamt  * 1 -  byte (1 - 4) Agreement Digest Format Identifier
    190  1.2.6.1      yamt  *           (5 - 8) Agreement Digest Format Capabilities
    191  1.2.6.1      yamt  * 1 -  byte (1 - 4) Agreement Digest Convention Identifier
    192  1.2.6.1      yamt  *           (5 - 8) Agreement Digest Convention Capabilities
    193  1.2.6.1      yamt  * 2 -  bytes Agreement Digest Edge Count
    194  1.2.6.1      yamt  * 8 -  byte Reserved Set
    195  1.2.6.1      yamt  * 20 - bytes Computed Topology Digest
    196  1.2.6.1      yamt  *
    197  1.2.6.1      yamt  *
    198      1.1  christos  * MSTI Payload
    199      1.1  christos  *
    200      1.1  christos  * 1 - byte  MSTI flag
    201      1.1  christos  * 8 - bytes MSTI Regional Root Identifier
    202      1.1  christos  * 4 - bytes MSTI Regional Path Cost
    203      1.1  christos  * 1 - byte  MSTI Bridge Priority
    204      1.1  christos  * 1 - byte  MSTI Port Priority
    205      1.1  christos  * 1 - byte  MSTI Remaining Hops
    206  1.2.6.1      yamt  *
    207      1.1  christos  */
    208      1.1  christos 
    209      1.1  christos #define MST_BPDU_MSTI_LENGTH		    16
    210      1.1  christos #define MST_BPDU_CONFIG_INFO_LENGTH	    64
    211      1.1  christos 
    212      1.1  christos /* Offsets of fields from the begginning for the packet */
    213      1.1  christos #define MST_BPDU_VER3_LEN_OFFSET	    36
    214      1.1  christos #define MST_BPDU_CONFIG_NAME_OFFSET	    39
    215      1.1  christos #define MST_BPDU_CONFIG_DIGEST_OFFSET	    73
    216      1.1  christos #define MST_BPDU_CIST_INT_PATH_COST_OFFSET  89
    217      1.1  christos #define MST_BPDU_CIST_BRIDGE_ID_OFFSET	    93
    218      1.1  christos #define MST_BPDU_CIST_REMAIN_HOPS_OFFSET    101
    219      1.1  christos #define MST_BPDU_MSTI_OFFSET		    102
    220      1.1  christos /* Offsets within  an MSTI */
    221      1.1  christos #define MST_BPDU_MSTI_ROOT_PRIO_OFFSET	    1
    222      1.1  christos #define MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET 9
    223      1.1  christos #define MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET    13
    224      1.1  christos #define MST_BPDU_MSTI_PORT_PRIO_OFFSET	    14
    225      1.1  christos #define MST_BPDU_MSTI_REMAIN_HOPS_OFFSET    15
    226      1.1  christos 
    227  1.2.6.1      yamt #define SPB_BPDU_MIN_LEN                  87
    228  1.2.6.1      yamt #define SPB_BPDU_CONFIG_NAME_OFFSET       3
    229  1.2.6.1      yamt #define SPB_BPDU_CONFIG_REV_OFFSET        SPB_BPDU_CONFIG_NAME_OFFSET + 32
    230  1.2.6.1      yamt #define SPB_BPDU_CONFIG_DIGEST_OFFSET     SPB_BPDU_CONFIG_REV_OFFSET + 2
    231  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_OFFSET         SPB_BPDU_CONFIG_DIGEST_OFFSET + 16
    232  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_UNUSED_OFFSET  SPB_BPDU_AGREEMENT_OFFSET + 1
    233  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_FORMAT_OFFSET  SPB_BPDU_AGREEMENT_UNUSED_OFFSET + 1
    234  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_CON_OFFSET     SPB_BPDU_AGREEMENT_FORMAT_OFFSET + 1
    235  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_EDGE_OFFSET    SPB_BPDU_AGREEMENT_CON_OFFSET + 1
    236  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_RES1_OFFSET    SPB_BPDU_AGREEMENT_EDGE_OFFSET + 2
    237  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_RES2_OFFSET    SPB_BPDU_AGREEMENT_RES1_OFFSET + 4
    238  1.2.6.1      yamt #define SPB_BPDU_AGREEMENT_DIGEST_OFFSET  SPB_BPDU_AGREEMENT_RES2_OFFSET + 4
    239  1.2.6.1      yamt 
    240  1.2.6.1      yamt 
    241      1.1  christos static void
    242      1.1  christos stp_print_mstp_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
    243      1.1  christos {
    244  1.2.6.1      yamt     const u_char *ptr;
    245      1.1  christos     u_int16_t	    v3len;
    246      1.1  christos     u_int16_t	    len;
    247      1.1  christos     u_int16_t	    msti;
    248  1.2.6.1      yamt     u_int	    offset;
    249      1.1  christos 
    250      1.1  christos     ptr = (const u_char *)stp_bpdu;
    251  1.2.6.1      yamt     printf(", CIST Flags [%s], length %u",
    252  1.2.6.1      yamt            bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags), length);
    253      1.1  christos 
    254      1.1  christos     /*
    255  1.2.6.1      yamt      * in non-verbose mode just print the flags.
    256      1.1  christos      */
    257      1.1  christos     if (!vflag) {
    258      1.1  christos         return;
    259      1.1  christos     }
    260      1.1  christos 
    261  1.2.6.1      yamt     printf("\n\tport-role %s, ",
    262  1.2.6.1      yamt            tok2str(rstp_obj_port_role_values, "Unknown",
    263  1.2.6.1      yamt                    RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)));
    264      1.1  christos 
    265  1.2.6.1      yamt     printf("CIST root-id %s, CIST ext-pathcost %u ",
    266  1.2.6.1      yamt            stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
    267  1.2.6.1      yamt            EXTRACT_32BITS(&stp_bpdu->root_path_cost));
    268  1.2.6.1      yamt 
    269  1.2.6.1      yamt     printf("\n\tCIST regional-root-id %s, ",
    270  1.2.6.1      yamt            stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id));
    271  1.2.6.1      yamt 
    272  1.2.6.1      yamt     printf("CIST port-id %04x, ", EXTRACT_16BITS(&stp_bpdu->port_id));
    273      1.1  christos 
    274      1.1  christos     printf("\n\tmessage-age %.2fs, max-age %.2fs"
    275      1.1  christos            ", hello-time %.2fs, forwarding-delay %.2fs",
    276      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
    277      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
    278      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
    279      1.1  christos            (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE);
    280      1.1  christos 
    281  1.2.6.1      yamt     printf ("\n\tv3len %d, ", EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET));
    282  1.2.6.1      yamt     printf("MCID Name %s, rev %u, "
    283  1.2.6.1      yamt             "\n\t\tdigest %08x%08x%08x%08x, ",
    284  1.2.6.1      yamt             ptr + MST_BPDU_CONFIG_NAME_OFFSET,
    285  1.2.6.1      yamt 	          EXTRACT_16BITS(ptr + MST_BPDU_CONFIG_NAME_OFFSET + 32),
    286  1.2.6.1      yamt       	    EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET),
    287  1.2.6.1      yamt         	  EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 4),
    288  1.2.6.1      yamt 	          EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 8),
    289  1.2.6.1      yamt 	          EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12));
    290      1.1  christos 
    291  1.2.6.1      yamt     printf ("CIST int-root-pathcost %u, ",
    292  1.2.6.1      yamt             EXTRACT_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET));
    293      1.1  christos 
    294  1.2.6.1      yamt     printf("\n\tCIST bridge-id %s, ",
    295  1.2.6.1      yamt            stp_print_bridge_id(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET));
    296      1.1  christos 
    297  1.2.6.1      yamt     printf("CIST remaining-hops %d", ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET]);
    298      1.1  christos 
    299      1.1  christos     /* Dump all MSTI's */
    300      1.1  christos     v3len = EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET);
    301      1.1  christos     if (v3len > MST_BPDU_CONFIG_INFO_LENGTH) {
    302      1.1  christos         len = v3len - MST_BPDU_CONFIG_INFO_LENGTH;
    303      1.1  christos         offset = MST_BPDU_MSTI_OFFSET;
    304      1.1  christos         while (len >= MST_BPDU_MSTI_LENGTH) {
    305      1.1  christos             msti = EXTRACT_16BITS(ptr + offset +
    306      1.1  christos                                   MST_BPDU_MSTI_ROOT_PRIO_OFFSET);
    307      1.1  christos             msti = msti & 0x0FFF;
    308      1.1  christos 
    309      1.1  christos             printf("\n\tMSTI %d, Flags [%s], port-role %s",
    310      1.1  christos                    msti, bittok2str(stp_bpdu_flag_values, "none", ptr[offset]),
    311      1.1  christos                    tok2str(rstp_obj_port_role_values, "Unknown",
    312      1.1  christos                            RSTP_EXTRACT_PORT_ROLE(ptr[offset])));
    313      1.1  christos             printf("\n\t\tMSTI regional-root-id %s, pathcost %u",
    314      1.1  christos                    stp_print_bridge_id(ptr + offset +
    315      1.1  christos                                        MST_BPDU_MSTI_ROOT_PRIO_OFFSET),
    316      1.1  christos                    EXTRACT_32BITS(ptr + offset +
    317      1.1  christos                                   MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET));
    318      1.1  christos             printf("\n\t\tMSTI bridge-prio %d, port-prio %d, hops %d",
    319      1.1  christos                    ptr[offset + MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET] >> 4,
    320      1.1  christos                    ptr[offset + MST_BPDU_MSTI_PORT_PRIO_OFFSET] >> 4,
    321      1.1  christos                    ptr[offset + MST_BPDU_MSTI_REMAIN_HOPS_OFFSET]);
    322      1.1  christos 
    323      1.1  christos             len -= MST_BPDU_MSTI_LENGTH;
    324      1.1  christos             offset += MST_BPDU_MSTI_LENGTH;
    325      1.1  christos         }
    326      1.1  christos     }
    327      1.1  christos }
    328      1.1  christos 
    329  1.2.6.1      yamt static void
    330  1.2.6.1      yamt stp_print_spb_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int offset)
    331  1.2.6.1      yamt {
    332  1.2.6.1      yamt     const u_char *ptr;
    333  1.2.6.1      yamt 
    334  1.2.6.1      yamt     /*
    335  1.2.6.1      yamt      * in non-verbose mode don't print anything.
    336  1.2.6.1      yamt      */
    337  1.2.6.1      yamt     if (!vflag) {
    338  1.2.6.1      yamt         return;
    339  1.2.6.1      yamt     }
    340  1.2.6.1      yamt 
    341  1.2.6.1      yamt     ptr = (const u_char *)stp_bpdu;
    342  1.2.6.1      yamt     printf("\n\tv4len %d AUXMCID Name %s, Rev %u, \n\t\tdigest %08x%08x%08x%08x",
    343  1.2.6.1      yamt             EXTRACT_16BITS (ptr + offset),
    344  1.2.6.1      yamt             ptr + offset + SPB_BPDU_CONFIG_NAME_OFFSET,
    345  1.2.6.1      yamt             EXTRACT_16BITS(ptr + offset + SPB_BPDU_CONFIG_REV_OFFSET),
    346  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET),
    347  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 4),
    348  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 8),
    349  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 12));
    350  1.2.6.1      yamt 
    351  1.2.6.1      yamt     printf("\n\tAgreement num %d, Discarded Agreement num %d, Agreement valid-"
    352  1.2.6.1      yamt             "flag %d, \n\tRestricted role-flag: %d, Format id %d cap %d, "
    353  1.2.6.1      yamt             "Convention id %d cap %d, \n\tEdge count %d, "
    354  1.2.6.1      yamt             "Agreement digest %08x%08x%08x%08x%08x\n",
    355  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>6,
    356  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>4 & 0x3,
    357  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>3 & 0x1,
    358  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>2 & 0x1,
    359  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET]>>4,
    360  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET]&0x00ff,
    361  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_CON_OFFSET]>>4,
    362  1.2.6.1      yamt             ptr[offset + SPB_BPDU_AGREEMENT_CON_OFFSET]&0x00ff,
    363  1.2.6.1      yamt             EXTRACT_16BITS(ptr + offset + SPB_BPDU_AGREEMENT_EDGE_OFFSET),
    364  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET),
    365  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+4,
    366  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+8,
    367  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+12,
    368  1.2.6.1      yamt             EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET)+16);
    369  1.2.6.1      yamt }
    370  1.2.6.1      yamt 
    371      1.1  christos /*
    372  1.2.6.1      yamt  * Print 802.1d / 802.1w / 802.1q (mstp) / 802.1aq (spb) packets.
    373      1.1  christos  */
    374      1.1  christos void
    375      1.1  christos stp_print(const u_char *p, u_int length)
    376      1.1  christos {
    377      1.1  christos     const struct stp_bpdu_ *stp_bpdu;
    378  1.2.6.1      yamt     u_int                  mstp_len;
    379  1.2.6.1      yamt     u_int                  spb_len;
    380      1.1  christos 
    381      1.1  christos     stp_bpdu = (struct stp_bpdu_*)p;
    382      1.1  christos 
    383      1.1  christos     /* Minimum STP Frame size. */
    384      1.1  christos     if (length < 4)
    385      1.1  christos         goto trunc;
    386      1.1  christos 
    387      1.1  christos     if (EXTRACT_16BITS(&stp_bpdu->protocol_id)) {
    388      1.1  christos         printf("unknown STP version, length %u", length);
    389      1.1  christos         return;
    390      1.1  christos     }
    391      1.1  christos 
    392      1.1  christos     printf("STP %s", tok2str(stp_proto_values, "Unknown STP protocol (0x%02x)",
    393      1.1  christos                          stp_bpdu->protocol_version));
    394      1.1  christos 
    395      1.1  christos     switch (stp_bpdu->protocol_version) {
    396      1.1  christos     case STP_PROTO_REGULAR:
    397      1.1  christos     case STP_PROTO_RAPID:
    398      1.1  christos     case STP_PROTO_MSTP:
    399  1.2.6.1      yamt     case STP_PROTO_SPB:
    400      1.1  christos         break;
    401      1.1  christos     default:
    402      1.1  christos         return;
    403      1.1  christos     }
    404      1.1  christos 
    405      1.1  christos     printf(", %s", tok2str(stp_bpdu_type_values, "Unknown BPDU Type (0x%02x)",
    406      1.1  christos                            stp_bpdu->bpdu_type));
    407      1.1  christos 
    408      1.1  christos     switch (stp_bpdu->bpdu_type) {
    409      1.1  christos     case STP_BPDU_TYPE_CONFIG:
    410      1.1  christos         if (length < sizeof(struct stp_bpdu_) - 1) {
    411      1.1  christos             goto trunc;
    412      1.1  christos         }
    413      1.1  christos         stp_print_config_bpdu(stp_bpdu, length);
    414      1.1  christos         break;
    415      1.1  christos 
    416      1.1  christos     case STP_BPDU_TYPE_RSTP:
    417      1.1  christos         if (stp_bpdu->protocol_version == STP_PROTO_RAPID) {
    418      1.1  christos             if (length < sizeof(struct stp_bpdu_)) {
    419      1.1  christos                 goto trunc;
    420      1.1  christos             }
    421      1.1  christos             stp_print_config_bpdu(stp_bpdu, length);
    422  1.2.6.1      yamt         } else if (stp_bpdu->protocol_version == STP_PROTO_MSTP ||
    423  1.2.6.1      yamt                    stp_bpdu->protocol_version == STP_PROTO_SPB) {
    424      1.1  christos             if (length < STP_BPDU_MSTP_MIN_LEN) {
    425      1.1  christos                 goto trunc;
    426      1.1  christos             }
    427  1.2.6.1      yamt 
    428      1.1  christos             if (stp_bpdu->v1_length != 0) {
    429      1.1  christos                 /* FIX ME: Emit a message here ? */
    430      1.1  christos                 goto trunc;
    431      1.1  christos             }
    432  1.2.6.1      yamt 
    433      1.1  christos             /* Validate v3 length */
    434      1.1  christos             mstp_len = EXTRACT_16BITS(p + MST_BPDU_VER3_LEN_OFFSET);
    435      1.1  christos             mstp_len += 2;  /* length encoding itself is 2 bytes */
    436      1.1  christos             if (length < (sizeof(struct stp_bpdu_) + mstp_len)) {
    437      1.1  christos                 goto trunc;
    438      1.1  christos             }
    439      1.1  christos             stp_print_mstp_bpdu(stp_bpdu, length);
    440  1.2.6.1      yamt 
    441  1.2.6.1      yamt             if (stp_bpdu->protocol_version == STP_PROTO_SPB)
    442  1.2.6.1      yamt             {
    443  1.2.6.1      yamt               /* Validate v4 length */
    444  1.2.6.1      yamt               spb_len = EXTRACT_16BITS (p + MST_BPDU_VER3_LEN_OFFSET + mstp_len);
    445  1.2.6.1      yamt               spb_len += 2;
    446  1.2.6.1      yamt               if (length < (sizeof(struct stp_bpdu_) + mstp_len + spb_len) ||
    447  1.2.6.1      yamt                   spb_len < SPB_BPDU_MIN_LEN) {
    448  1.2.6.1      yamt                 goto trunc;
    449  1.2.6.1      yamt               }
    450  1.2.6.1      yamt               stp_print_spb_bpdu(stp_bpdu, (sizeof(struct stp_bpdu_) + mstp_len));
    451  1.2.6.1      yamt             }
    452      1.1  christos         }
    453      1.1  christos         break;
    454      1.1  christos 
    455      1.1  christos     case STP_BPDU_TYPE_TOPO_CHANGE:
    456      1.1  christos         /* always empty message - just break out */
    457      1.1  christos         break;
    458      1.1  christos 
    459      1.1  christos     default:
    460      1.1  christos         break;
    461      1.1  christos     }
    462      1.1  christos 
    463      1.1  christos     return;
    464      1.1  christos  trunc:
    465      1.1  christos     printf("[|stp %d]", length);
    466      1.1  christos }
    467      1.1  christos 
    468      1.1  christos /*
    469      1.1  christos  * Local Variables:
    470      1.1  christos  * c-style: whitesmith
    471      1.1  christos  * c-basic-offset: 4
    472      1.1  christos  * End:
    473      1.1  christos  */
    474