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