1 1.1 christos /* 2 1.1 christos * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 1.1 christos * The Regents of the University of California. All rights reserved. 4 1.1 christos * 5 1.1 christos * Redistribution and use in source and binary forms, with or without 6 1.1 christos * modification, are permitted provided that: (1) source code distributions 7 1.1 christos * retain the above copyright notice and this paragraph in its entirety, (2) 8 1.1 christos * distributions including binary code include the above copyright notice and 9 1.1 christos * this paragraph in its entirety in the documentation or other materials 10 1.1 christos * provided with the distribution, and (3) all advertising materials mentioning 11 1.1 christos * features or use of this software display the following acknowledgement: 12 1.1 christos * ``This product includes software developed by the University of California, 13 1.1 christos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 1.1 christos * the University nor the names of its contributors may be used to endorse 15 1.1 christos * or promote products derived from this software without specific prior 16 1.1 christos * written permission. 17 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 1.1 christos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 1.1 christos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 1.1 christos */ 21 1.1 christos 22 1.1 christos /* \summary: Marvell (Ethertype) Distributed Switch Architecture printer */ 23 1.1 christos 24 1.1 christos #include <config.h> 25 1.1 christos 26 1.1 christos #include "netdissect-stdinc.h" 27 1.1 christos 28 1.1 christos #include "netdissect.h" 29 1.1 christos #include "ethertype.h" 30 1.1 christos #include "addrtoname.h" 31 1.1 christos #include "extract.h" 32 1.1 christos 33 1.1 christos /* 34 1.1 christos * Format of (Ethertyped or not) DSA tagged frames: 35 1.1 christos * 36 1.1 christos * 7 6 5 4 3 2 1 0 37 1.1 christos * . . . . . . . . . 38 1.1 christos * 0 +---+---+---+---+---+---+---+---+ 39 1.1 christos * | Ether Destination Address | 40 1.1 christos * +6 +---+---+---+---+---+---+---+---+ 41 1.1 christos * | Ether Source Address | 42 1.1 christos * +6 +---+---+---+---+---+---+---+---+ +- 43 1.1 christos * | Prog. DSA Ether Type [15:8] | | (8-byte) EDSA Tag 44 1.1 christos * +1 +---+---+---+---+---+---+---+---+ | Contains a programmable Ether type, 45 1.1 christos * | Prog. DSA Ether Type [7:0] | | two reserved bytes (always 0), 46 1.1 christos * +1 +---+---+---+---+---+---+---+---+ | and a standard DSA tag. 47 1.1 christos * | Reserved (0x00 0x00) | | 48 1.1 christos * +2 +---+---+---+---+---+---+---+---+ | +- 49 1.1 christos * | Mode |b29| Src/Trg Dev | | | (4-byte) DSA Tag 50 1.1 christos * +1 +---+---+---+---+---+---+---+---+ | | Contains a DSA tag mode, 51 1.1 christos * |Src/Trg Port/Trunk |b18|b17|b16| | | source or target switch device, 52 1.1 christos * +1 +---+---+---+---+---+---+---+---+ | | source or target port or trunk, 53 1.1 christos * | PRI [2:0] |b12| VID [11:8] | | | and misc (IEEE and FPri) bits. 54 1.1 christos * +1 +---+---+---+---+---+---+---+---+ | | 55 1.1 christos * | VID [7:0] | | | 56 1.1 christos * +1 +---+---+---+---+---+---+---+---+ +- +- 57 1.1 christos * | Ether Length/Type | 58 1.1 christos * +2 +---+---+---+---+---+---+---+---+ 59 1.1 christos * . . . . . . . . . 60 1.1 christos * 61 1.1 christos * Mode: Forward, To_CPU, From_CPU, To_Sniffer 62 1.1 christos * b29: (Source or Target) IEEE Tag Mode 63 1.1 christos * b18: Forward's Src_Is_Trunk, To_CPU's Code[2], To_Sniffer's Rx_Sniff 64 1.1 christos * b17: To_CPU's Code[1] 65 1.1 christos * b16: Original frame's CFI 66 1.1 christos * b12: To_CPU's Code[0] 67 1.1 christos */ 68 1.1 christos 69 1.1 christos #define TOK(tag, byte, mask, shift) ((GET_U_1(&(((const u_char *) tag)[byte])) & (mask)) >> (shift)) 70 1.1 christos 71 1.1 christos #define DSA_LEN 4 72 1.1 christos #define DSA_MODE(tag) TOK(tag, 0, 0xc0, 6) 73 1.1 christos #define DSA_MODE_TO_CPU 0x0 74 1.1 christos #define DSA_MODE_FROM_CPU 0x1 75 1.1 christos #define DSA_MODE_TO_SNIFFER 0x2 76 1.1 christos #define DSA_MODE_FORWARD 0x3 77 1.1 christos #define DSA_TAGGED(tag) TOK(tag, 0, 0x20, 5) 78 1.1 christos #define DSA_DEV(tag) TOK(tag, 0, 0x1f, 0) 79 1.1 christos #define DSA_PORT(tag) TOK(tag, 1, 0xf8, 3) 80 1.1 christos #define DSA_TRUNK(tag) TOK(tag, 1, 0x04, 2) 81 1.1 christos #define DSA_RX_SNIFF(tag) TOK(tag, 1, 0x04, 2) 82 1.1 christos #define DSA_CFI(tag) TOK(tag, 1, 0x01, 0) 83 1.1 christos #define DSA_PRI(tag) TOK(tag, 2, 0xe0, 5) 84 1.1 christos #define DSA_VID(tag) ((u_short)((TOK(tag, 2, 0x0f, 0) << 8) | (TOK(tag, 3, 0xff, 0)))) 85 1.1 christos #define DSA_CODE(tag) ((TOK(tag, 1, 0x06, 1) << 1) | TOK(tag, 2, 0x10, 4)) 86 1.1 christos 87 1.1 christos #define EDSA_LEN 8 88 1.1 christos 89 1.1 christos static const struct tok dsa_mode_values[] = { 90 1.1 christos { DSA_MODE_TO_CPU, "To CPU" }, 91 1.1 christos { DSA_MODE_FROM_CPU, "From CPU" }, 92 1.1 christos { DSA_MODE_TO_SNIFFER, "To Sniffer"}, 93 1.1 christos { DSA_MODE_FORWARD, "Forward" }, 94 1.1 christos { 0, NULL } 95 1.1 christos }; 96 1.1 christos 97 1.1 christos static const struct tok dsa_code_values[] = { 98 1.1 christos { 0x0, "BPDU (MGMT) Trap" }, 99 1.1 christos { 0x1, "Frame2Reg" }, 100 1.1 christos { 0x2, "IGMP/MLD Trap" }, 101 1.1 christos { 0x3, "Policy Trap" }, 102 1.1 christos { 0x4, "ARP Mirror" }, 103 1.1 christos { 0x5, "Policy Mirror" }, 104 1.1 christos { 0, NULL } 105 1.1 christos }; 106 1.1 christos 107 1.1 christos static void 108 1.1 christos tag_common_print(netdissect_options *ndo, const u_char *p) 109 1.1 christos { 110 1.1 christos if (ndo->ndo_eflag) { 111 1.1 christos ND_PRINT("mode %s, ", tok2str(dsa_mode_values, "unknown", DSA_MODE(p))); 112 1.1 christos 113 1.1 christos switch (DSA_MODE(p)) { 114 1.1 christos case DSA_MODE_FORWARD: 115 1.1 christos ND_PRINT("dev %u, %s %u, ", DSA_DEV(p), 116 1.1 christos DSA_TRUNK(p) ? "trunk" : "port", DSA_PORT(p)); 117 1.1 christos break; 118 1.1 christos case DSA_MODE_FROM_CPU: 119 1.1 christos ND_PRINT("target dev %u, port %u, ", 120 1.1 christos DSA_DEV(p), DSA_PORT(p)); 121 1.1 christos break; 122 1.1 christos case DSA_MODE_TO_CPU: 123 1.1 christos ND_PRINT("source dev %u, port %u, ", 124 1.1 christos DSA_DEV(p), DSA_PORT(p)); 125 1.1 christos ND_PRINT("code %s, ", 126 1.1 christos tok2str(dsa_code_values, "reserved", DSA_CODE(p))); 127 1.1 christos break; 128 1.1 christos case DSA_MODE_TO_SNIFFER: 129 1.1 christos ND_PRINT("source dev %u, port %u, ", 130 1.1 christos DSA_DEV(p), DSA_PORT(p)); 131 1.1 christos ND_PRINT("%s sniff, ", 132 1.1 christos DSA_RX_SNIFF(p) ? "ingress" : "egress"); 133 1.1 christos break; 134 1.1 christos default: 135 1.1 christos break; 136 1.1 christos } 137 1.1 christos 138 1.1 christos ND_PRINT("%s, ", DSA_TAGGED(p) ? "tagged" : "untagged"); 139 1.1 christos ND_PRINT("%s", DSA_CFI(p) ? "CFI, " : ""); 140 1.1 christos ND_PRINT("VID %u, ", DSA_VID(p)); 141 1.1 christos ND_PRINT("FPri %u, ", DSA_PRI(p)); 142 1.1 christos } else { 143 1.1 christos switch (DSA_MODE(p)) { 144 1.1 christos case DSA_MODE_FORWARD: 145 1.1 christos ND_PRINT("Forward %s %u.%u, ", 146 1.1 christos DSA_TRUNK(p) ? "trunk" : "port", 147 1.1 christos DSA_DEV(p), DSA_PORT(p)); 148 1.1 christos break; 149 1.1 christos case DSA_MODE_FROM_CPU: 150 1.1 christos ND_PRINT("CPU > port %u.%u, ", 151 1.1 christos DSA_DEV(p), DSA_PORT(p)); 152 1.1 christos break; 153 1.1 christos case DSA_MODE_TO_CPU: 154 1.1 christos ND_PRINT("port %u.%u > CPU, ", 155 1.1 christos DSA_DEV(p), DSA_PORT(p)); 156 1.1 christos break; 157 1.1 christos case DSA_MODE_TO_SNIFFER: 158 1.1 christos ND_PRINT("port %u.%u > %s Sniffer, ", 159 1.1 christos DSA_DEV(p), DSA_PORT(p), 160 1.1 christos DSA_RX_SNIFF(p) ? "Rx" : "Tx"); 161 1.1 christos break; 162 1.1 christos default: 163 1.1 christos break; 164 1.1 christos } 165 1.1 christos 166 1.1 christos ND_PRINT("VLAN %u%c, ", DSA_VID(p), DSA_TAGGED(p) ? 't' : 'u'); 167 1.1 christos } 168 1.1 christos } 169 1.1 christos 170 1.1 christos static void 171 1.1 christos dsa_tag_print(netdissect_options *ndo, const u_char *bp) 172 1.1 christos { 173 1.1 christos if (ndo->ndo_eflag) 174 1.1 christos ND_PRINT("Marvell DSA "); 175 1.1 christos else 176 1.1 christos ND_PRINT("DSA "); 177 1.1 christos tag_common_print(ndo, bp); 178 1.1 christos } 179 1.1 christos 180 1.1 christos static void 181 1.1 christos edsa_tag_print(netdissect_options *ndo, const u_char *bp) 182 1.1 christos { 183 1.1 christos const u_char *p = bp; 184 1.1 christos uint16_t edsa_etype; 185 1.1 christos 186 1.1 christos edsa_etype = GET_BE_U_2(p); 187 1.1 christos if (ndo->ndo_eflag) { 188 1.1 christos ND_PRINT("Marvell EDSA ethertype 0x%04x (%s), ", edsa_etype, 189 1.1 christos tok2str(ethertype_values, "Unknown", edsa_etype)); 190 1.1 christos ND_PRINT("rsvd %u %u, ", GET_U_1(p + 2), GET_U_1(p + 3)); 191 1.1 christos } else 192 1.1 christos ND_PRINT("EDSA 0x%04x, ", edsa_etype); 193 1.1 christos p += 4; 194 1.1 christos tag_common_print(ndo, p); 195 1.1 christos } 196 1.1 christos 197 1.1 christos void 198 1.1 christos dsa_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) 199 1.1 christos { 200 1.1 christos u_int caplen = h->caplen; 201 1.1 christos u_int length = h->len; 202 1.1 christos 203 1.1 christos ndo->ndo_protocol = "dsa"; 204 1.1 christos ndo->ndo_ll_hdr_len += 205 1.1 christos ether_switch_tag_print(ndo, p, length, caplen, dsa_tag_print, DSA_LEN); 206 1.1 christos } 207 1.1 christos 208 1.1 christos void 209 1.1 christos edsa_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) 210 1.1 christos { 211 1.1 christos u_int caplen = h->caplen; 212 1.1 christos u_int length = h->len; 213 1.1 christos 214 1.1 christos ndo->ndo_protocol = "edsa"; 215 1.1 christos ndo->ndo_ll_hdr_len += 216 1.1 christos ether_switch_tag_print(ndo, p, length, caplen, edsa_tag_print, EDSA_LEN); 217 1.1 christos } 218