2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
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.
26 #include <tcpdump-stdinc.h>
28 #include "interface.h"
30 #include "addrtoname.h"
31 #include "ethertype.h"
34 const struct tok ethertype_values
[] = {
35 { ETHERTYPE_IP
, "IPv4" },
36 { ETHERTYPE_MPLS
, "MPLS unicast" },
37 { ETHERTYPE_MPLS_MULTI
, "MPLS multicast" },
38 { ETHERTYPE_IPV6
, "IPv6" },
39 { ETHERTYPE_8021Q
, "802.1Q" },
40 { ETHERTYPE_8021Q9100
, "802.1Q-9100" },
41 { ETHERTYPE_8021QinQ
, "802.1Q-QinQ" },
42 { ETHERTYPE_8021Q9200
, "802.1Q-9200" },
43 { ETHERTYPE_VMAN
, "VMAN" },
44 { ETHERTYPE_PUP
, "PUP" },
45 { ETHERTYPE_ARP
, "ARP"},
46 { ETHERTYPE_REVARP
, "Reverse ARP"},
47 { ETHERTYPE_NS
, "NS" },
48 { ETHERTYPE_SPRITE
, "Sprite" },
49 { ETHERTYPE_TRAIL
, "Trail" },
50 { ETHERTYPE_MOPDL
, "MOP DL" },
51 { ETHERTYPE_MOPRC
, "MOP RC" },
52 { ETHERTYPE_DN
, "DN" },
53 { ETHERTYPE_LAT
, "LAT" },
54 { ETHERTYPE_SCA
, "SCA" },
55 { ETHERTYPE_TEB
, "TEB" },
56 { ETHERTYPE_LANBRIDGE
, "Lanbridge" },
57 { ETHERTYPE_DECDNS
, "DEC DNS" },
58 { ETHERTYPE_DECDTS
, "DEC DTS" },
59 { ETHERTYPE_VEXP
, "VEXP" },
60 { ETHERTYPE_VPROD
, "VPROD" },
61 { ETHERTYPE_ATALK
, "Appletalk" },
62 { ETHERTYPE_AARP
, "Appletalk ARP" },
63 { ETHERTYPE_IPX
, "IPX" },
64 { ETHERTYPE_PPP
, "PPP" },
65 { ETHERTYPE_MPCP
, "MPCP" },
66 { ETHERTYPE_SLOW
, "Slow Protocols" },
67 { ETHERTYPE_PPPOED
, "PPPoE D" },
68 { ETHERTYPE_PPPOES
, "PPPoE S" },
69 { ETHERTYPE_EAPOL
, "EAPOL" },
70 { ETHERTYPE_RRCP
, "RRCP" },
71 { ETHERTYPE_MS_NLB_HB
, "MS NLB heartbeat" },
72 { ETHERTYPE_JUMBO
, "Jumbo" },
73 { ETHERTYPE_LOOPBACK
, "Loopback" },
74 { ETHERTYPE_ISO
, "OSI" },
75 { ETHERTYPE_GRE_ISO
, "GRE-OSI" },
76 { ETHERTYPE_CFM_OLD
, "CFM (old)" },
77 { ETHERTYPE_CFM
, "CFM" },
78 { ETHERTYPE_IEEE1905_1
, "IEEE1905.1" },
79 { ETHERTYPE_LLDP
, "LLDP" },
80 { ETHERTYPE_TIPC
, "TIPC"},
81 { ETHERTYPE_GEONET_OLD
, "GeoNet (old)"},
82 { ETHERTYPE_GEONET
, "GeoNet"},
83 { ETHERTYPE_CALM_FAST
, "CALM FAST"},
84 { ETHERTYPE_AOE
, "AoE" },
89 ether_hdr_print(netdissect_options
*ndo
,
90 const u_char
*bp
, u_int length
)
92 register const struct ether_header
*ep
;
95 ep
= (const struct ether_header
*)bp
;
97 ND_PRINT((ndo
, "%s > %s",
98 etheraddr_string(ndo
, ESRC(ep
)),
99 etheraddr_string(ndo
, EDST(ep
))));
101 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
102 if (!ndo
->ndo_qflag
) {
103 if (ether_type
<= ETHERMTU
)
104 ND_PRINT((ndo
, ", 802.3"));
106 ND_PRINT((ndo
, ", ethertype %s (0x%04x)",
107 tok2str(ethertype_values
,"Unknown", ether_type
),
110 if (ether_type
<= ETHERMTU
)
111 ND_PRINT((ndo
, ", 802.3"));
113 ND_PRINT((ndo
, ", %s", tok2str(ethertype_values
,"Unknown Ethertype (0x%04x)", ether_type
)));
116 ND_PRINT((ndo
, ", length %u: ", length
));
120 * Print an Ethernet frame.
121 * This might be encapsulated within another frame; we might be passed
122 * a pointer to a function that can print header information for that
123 * frame's protocol, and an argument to pass to that function.
126 ether_print(netdissect_options
*ndo
,
127 const u_char
*p
, u_int length
, u_int caplen
,
128 void (*print_encap_header
)(netdissect_options
*ndo
, const u_char
*), const u_char
*encap_header_arg
)
130 struct ether_header
*ep
;
133 u_short extracted_ether_type
;
135 if (caplen
< ETHER_HDRLEN
|| length
< ETHER_HDRLEN
) {
136 ND_PRINT((ndo
, "[|ether]"));
140 if (ndo
->ndo_eflag
) {
141 if (print_encap_header
!= NULL
)
142 (*print_encap_header
)(ndo
, encap_header_arg
);
143 ether_hdr_print(ndo
, p
, length
);
145 orig_length
= length
;
147 length
-= ETHER_HDRLEN
;
148 caplen
-= ETHER_HDRLEN
;
149 ep
= (struct ether_header
*)p
;
152 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
156 * Is it (gag) an 802.3 encapsulation?
158 if (ether_type
<= ETHERMTU
) {
159 /* Try to print the LLC-layer header & higher layers */
160 if (llc_print(ndo
, p
, length
, caplen
, ESRC(ep
), EDST(ep
),
161 &extracted_ether_type
) == 0) {
162 /* ether_type not known, print raw packet */
163 if (!ndo
->ndo_eflag
) {
164 if (print_encap_header
!= NULL
)
165 (*print_encap_header
)(ndo
, encap_header_arg
);
166 ether_hdr_print(ndo
, (u_char
*)ep
, orig_length
);
169 if (!ndo
->ndo_suppress_default_print
)
170 ND_DEFAULTPRINT(p
, caplen
);
172 } else if (ether_type
== ETHERTYPE_8021Q
||
173 ether_type
== ETHERTYPE_8021Q9100
||
174 ether_type
== ETHERTYPE_8021Q9200
||
175 ether_type
== ETHERTYPE_8021QinQ
) {
177 * Print VLAN information, and then go back and process
178 * the enclosed type field.
180 if (caplen
< 4 || length
< 4) {
181 ND_PRINT((ndo
, "[|vlan]"));
184 if (ndo
->ndo_eflag
) {
185 uint16_t tag
= EXTRACT_16BITS(p
);
187 ND_PRINT((ndo
, "%s, ", ieee8021q_tci_string(tag
)));
190 ether_type
= EXTRACT_16BITS(p
+ 2);
191 if (ndo
->ndo_eflag
&& ether_type
> ETHERMTU
)
192 ND_PRINT((ndo
, "ethertype %s, ", tok2str(ethertype_values
,"0x%04x", ether_type
)));
197 } else if (ether_type
== ETHERTYPE_JUMBO
) {
199 * Alteon jumbo frames.
202 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
204 * which indicates that, following the type field,
205 * there's an LLC header and payload.
207 /* Try to print the LLC-layer header & higher layers */
208 if (llc_print(ndo
, p
, length
, caplen
, ESRC(ep
), EDST(ep
),
209 &extracted_ether_type
) == 0) {
210 /* ether_type not known, print raw packet */
211 if (!ndo
->ndo_eflag
) {
212 if (print_encap_header
!= NULL
)
213 (*print_encap_header
)(ndo
, encap_header_arg
);
214 ether_hdr_print(ndo
, (u_char
*)ep
, orig_length
);
217 if (!ndo
->ndo_suppress_default_print
)
218 ND_DEFAULTPRINT(p
, caplen
);
221 if (ethertype_print(ndo
, ether_type
, p
, length
, caplen
) == 0) {
222 /* ether_type not known, print raw packet */
223 if (!ndo
->ndo_eflag
) {
224 if (print_encap_header
!= NULL
)
225 (*print_encap_header
)(ndo
, encap_header_arg
);
226 ether_hdr_print(ndo
, (u_char
*)ep
, orig_length
);
229 if (!ndo
->ndo_suppress_default_print
)
230 ND_DEFAULTPRINT(p
, caplen
);
236 * This is the top level routine of the printer. 'p' points
237 * to the ether header of the packet, 'h->ts' is the timestamp,
238 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
239 * is the number of bytes actually captured.
242 ether_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
,
245 ether_print(ndo
, p
, h
->len
, h
->caplen
, NULL
, NULL
);
247 return (ETHER_HDRLEN
);
251 * This is the top level routine of the printer. 'p' points
252 * to the ether header of the packet, 'h->ts' is the timestamp,
253 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
254 * is the number of bytes actually captured.
256 * This is for DLT_NETANALYZER, which has a 4-byte pseudo-header
257 * before the Ethernet header.
260 netanalyzer_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
,
264 * Fail if we don't have enough data for the Hilscher pseudo-header.
266 if (h
->len
< 4 || h
->caplen
< 4) {
267 ND_PRINT((ndo
, "[|netanalyzer]"));
271 /* Skip the pseudo-header. */
272 ether_print(ndo
, p
+ 4, h
->len
- 4, h
->caplen
- 4, NULL
, NULL
);
274 return (4 + ETHER_HDRLEN
);
278 * This is the top level routine of the printer. 'p' points
279 * to the ether header of the packet, 'h->ts' is the timestamp,
280 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
281 * is the number of bytes actually captured.
283 * This is for DLT_NETANALYZER_TRANSPARENT, which has a 4-byte
284 * pseudo-header, a 7-byte Ethernet preamble, and a 1-byte Ethernet SOF
285 * before the Ethernet header.
288 netanalyzer_transparent_if_print(netdissect_options
*ndo
,
289 const struct pcap_pkthdr
*h
,
293 * Fail if we don't have enough data for the Hilscher pseudo-header,
296 if (h
->len
< 12 || h
->caplen
< 12) {
297 ND_PRINT((ndo
, "[|netanalyzer-transparent]"));
301 /* Skip the pseudo-header, preamble, and SOF. */
302 ether_print(ndo
, p
+ 12, h
->len
- 12, h
->caplen
- 12, NULL
, NULL
);
304 return (12 + ETHER_HDRLEN
);
308 * Prints the packet payload, given an Ethernet type code for the payload's
311 * Returns non-zero if it can do so, zero if the ethertype is unknown.
315 ethertype_print(netdissect_options
*ndo
,
316 u_short ether_type
, const u_char
*p
,
317 u_int length
, u_int caplen
)
319 switch (ether_type
) {
322 ip_print(ndo
, p
, length
);
326 ip6_print(ndo
, p
, length
);
330 case ETHERTYPE_REVARP
:
331 arp_print(ndo
, p
, length
, caplen
);
335 decnet_print(ndo
, p
, length
, caplen
);
338 case ETHERTYPE_ATALK
:
340 ND_PRINT((ndo
, "et1 "));
341 atalk_print(ndo
, p
, length
);
345 aarp_print(ndo
, p
, length
);
349 ND_PRINT((ndo
, "(NOV-ETHII) "));
350 ipx_print(ndo
, p
, length
);
354 isoclns_print(ndo
, p
+ 1, length
- 1, length
- 1);
357 case ETHERTYPE_PPPOED
:
358 case ETHERTYPE_PPPOES
:
359 case ETHERTYPE_PPPOED2
:
360 case ETHERTYPE_PPPOES2
:
361 pppoe_print(ndo
, p
, length
);
364 case ETHERTYPE_EAPOL
:
365 eap_print(ndo
, p
, length
);
369 rrcp_print(ndo
, p
- 14 , length
+ 14);
374 ND_PRINT((ndo
, ": "));
375 ppp_print(ndo
, p
, length
);
380 mpcp_print(ndo
, p
, length
);
384 slow_print(ndo
, p
, length
);
388 case ETHERTYPE_CFM_OLD
:
389 cfm_print(ndo
, p
, length
);
393 lldp_print(ndo
, p
, length
);
396 case ETHERTYPE_LOOPBACK
:
397 loopback_print(ndo
, p
, length
);
401 case ETHERTYPE_MPLS_MULTI
:
402 mpls_print(ndo
, p
, length
);
406 tipc_print(ndo
, p
, length
, caplen
);
409 case ETHERTYPE_MS_NLB_HB
:
413 case ETHERTYPE_GEONET_OLD
:
414 case ETHERTYPE_GEONET
:
415 geonet_print(ndo
, p
-14, p
, length
);
418 case ETHERTYPE_CALM_FAST
:
419 calm_fast_print(ndo
, p
-14, p
, length
);
423 aoe_print(ndo
, p
, length
);
428 case ETHERTYPE_MOPRC
:
429 case ETHERTYPE_MOPDL
:
430 case ETHERTYPE_IEEE1905_1
:
431 /* default_print for now */
440 * c-style: whitesmith