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 <netdissect-stdinc.h>
28 #include "netdissect.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" },
85 { ETHERTYPE_MEDSA
, "MEDSA" },
90 ether_hdr_print(netdissect_options
*ndo
,
91 const u_char
*bp
, u_int length
)
93 register const struct ether_header
*ep
;
96 ep
= (const struct ether_header
*)bp
;
98 ND_PRINT((ndo
, "%s > %s",
99 etheraddr_string(ndo
, ESRC(ep
)),
100 etheraddr_string(ndo
, EDST(ep
))));
102 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
103 if (!ndo
->ndo_qflag
) {
104 if (ether_type
<= ETHERMTU
) {
105 ND_PRINT((ndo
, ", 802.3"));
108 ND_PRINT((ndo
, ", ethertype %s (0x%04x)",
109 tok2str(ethertype_values
,"Unknown", ether_type
),
112 if (ether_type
<= ETHERMTU
) {
113 ND_PRINT((ndo
, ", 802.3"));
116 ND_PRINT((ndo
, ", %s", tok2str(ethertype_values
,"Unknown Ethertype (0x%04x)", ether_type
)));
119 ND_PRINT((ndo
, ", length %u: ", length
));
123 * Print an Ethernet frame.
124 * This might be encapsulated within another frame; we might be passed
125 * a pointer to a function that can print header information for that
126 * frame's protocol, and an argument to pass to that function.
129 ether_print(netdissect_options
*ndo
,
130 const u_char
*p
, u_int length
, u_int caplen
,
131 void (*print_encap_header
)(netdissect_options
*ndo
, const u_char
*), const u_char
*encap_header_arg
)
133 const struct ether_header
*ep
;
139 if (caplen
< ETHER_HDRLEN
) {
140 ND_PRINT((ndo
, "[|ether]"));
143 if (length
< ETHER_HDRLEN
) {
144 ND_PRINT((ndo
, "[|ether]"));
148 if (ndo
->ndo_eflag
) {
149 if (print_encap_header
!= NULL
)
150 (*print_encap_header
)(ndo
, encap_header_arg
);
151 ether_hdr_print(ndo
, p
, length
);
153 orig_length
= length
;
155 length
-= ETHER_HDRLEN
;
156 caplen
-= ETHER_HDRLEN
;
157 ep
= (const struct ether_header
*)p
;
159 hdrlen
= ETHER_HDRLEN
;
161 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
165 * Is it (gag) an 802.3 encapsulation?
167 if (ether_type
<= ETHERMTU
) {
168 /* Try to print the LLC-layer header & higher layers */
169 llc_hdrlen
= llc_print(ndo
, p
, length
, caplen
, ESRC(ep
), EDST(ep
));
170 if (llc_hdrlen
< 0) {
171 /* packet type not known, print raw packet */
172 if (!ndo
->ndo_suppress_default_print
)
173 ND_DEFAULTPRINT(p
, caplen
);
174 llc_hdrlen
= -llc_hdrlen
;
176 hdrlen
+= llc_hdrlen
;
177 } else if (ether_type
== ETHERTYPE_8021Q
||
178 ether_type
== ETHERTYPE_8021Q9100
||
179 ether_type
== ETHERTYPE_8021Q9200
||
180 ether_type
== ETHERTYPE_8021QinQ
) {
182 * Print VLAN information, and then go back and process
183 * the enclosed type field.
186 ND_PRINT((ndo
, "[|vlan]"));
187 return (hdrlen
+ caplen
);
190 ND_PRINT((ndo
, "[|vlan]"));
191 return (hdrlen
+ length
);
193 if (ndo
->ndo_eflag
) {
194 uint16_t tag
= EXTRACT_16BITS(p
);
196 ND_PRINT((ndo
, "%s, ", ieee8021q_tci_string(tag
)));
199 ether_type
= EXTRACT_16BITS(p
+ 2);
200 if (ndo
->ndo_eflag
&& ether_type
> ETHERMTU
)
201 ND_PRINT((ndo
, "ethertype %s, ", tok2str(ethertype_values
,"0x%04x", ether_type
)));
207 } else if (ether_type
== ETHERTYPE_JUMBO
) {
209 * Alteon jumbo frames.
212 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
214 * which indicates that, following the type field,
215 * there's an LLC header and payload.
217 /* Try to print the LLC-layer header & higher layers */
218 llc_hdrlen
= llc_print(ndo
, p
, length
, caplen
, ESRC(ep
), EDST(ep
));
219 if (llc_hdrlen
< 0) {
220 /* packet type not known, print raw packet */
221 if (!ndo
->ndo_suppress_default_print
)
222 ND_DEFAULTPRINT(p
, caplen
);
223 llc_hdrlen
= -llc_hdrlen
;
225 hdrlen
+= llc_hdrlen
;
227 if (ethertype_print(ndo
, ether_type
, p
, length
, caplen
) == 0) {
228 /* ether_type not known, print raw packet */
229 if (!ndo
->ndo_eflag
) {
230 if (print_encap_header
!= NULL
)
231 (*print_encap_header
)(ndo
, encap_header_arg
);
232 ether_hdr_print(ndo
, (const u_char
*)ep
, orig_length
);
235 if (!ndo
->ndo_suppress_default_print
)
236 ND_DEFAULTPRINT(p
, caplen
);
243 * This is the top level routine of the printer. 'p' points
244 * to the ether header of the packet, 'h->len' is the length
245 * of the packet off the wire, and 'h->caplen' is the number
246 * of bytes actually captured.
249 ether_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
,
252 return (ether_print(ndo
, p
, h
->len
, h
->caplen
, NULL
, NULL
));
256 * This is the top level routine of the printer. 'p' points
257 * to the ether header of the packet, 'h->len' is the length
258 * of the packet off the wire, and 'h->caplen' is the number
259 * of bytes actually captured.
261 * This is for DLT_NETANALYZER, which has a 4-byte pseudo-header
262 * before the Ethernet header.
265 netanalyzer_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
,
269 * Fail if we don't have enough data for the Hilscher pseudo-header.
271 if (h
->len
< 4 || h
->caplen
< 4) {
272 ND_PRINT((ndo
, "[|netanalyzer]"));
276 /* Skip the pseudo-header. */
277 return (4 + ether_print(ndo
, p
+ 4, h
->len
- 4, h
->caplen
- 4, NULL
, NULL
));
281 * This is the top level routine of the printer. 'p' points
282 * to the ether header of the packet, 'h->len' is the length
283 * of the packet off the wire, and 'h->caplen' is the number
284 * of bytes actually captured.
286 * This is for DLT_NETANALYZER_TRANSPARENT, which has a 4-byte
287 * pseudo-header, a 7-byte Ethernet preamble, and a 1-byte Ethernet SOF
288 * before the Ethernet header.
291 netanalyzer_transparent_if_print(netdissect_options
*ndo
,
292 const struct pcap_pkthdr
*h
,
296 * Fail if we don't have enough data for the Hilscher pseudo-header,
299 if (h
->len
< 12 || h
->caplen
< 12) {
300 ND_PRINT((ndo
, "[|netanalyzer-transparent]"));
304 /* Skip the pseudo-header, preamble, and SOF. */
305 return (12 + ether_print(ndo
, p
+ 12, h
->len
- 12, h
->caplen
- 12, NULL
, NULL
));
309 * Prints the packet payload, given an Ethernet type code for the payload's
312 * Returns non-zero if it can do so, zero if the ethertype is unknown.
316 ethertype_print(netdissect_options
*ndo
,
317 u_short ether_type
, const u_char
*p
,
318 u_int length
, u_int caplen
)
320 switch (ether_type
) {
323 ip_print(ndo
, p
, length
);
327 ip6_print(ndo
, p
, length
);
331 case ETHERTYPE_REVARP
:
332 arp_print(ndo
, p
, length
, caplen
);
336 decnet_print(ndo
, p
, length
, caplen
);
339 case ETHERTYPE_ATALK
:
341 ND_PRINT((ndo
, "et1 "));
342 atalk_print(ndo
, p
, length
);
346 aarp_print(ndo
, p
, length
);
350 ND_PRINT((ndo
, "(NOV-ETHII) "));
351 ipx_print(ndo
, p
, length
);
355 isoclns_print(ndo
, p
+ 1, length
- 1, length
- 1);
358 case ETHERTYPE_PPPOED
:
359 case ETHERTYPE_PPPOES
:
360 case ETHERTYPE_PPPOED2
:
361 case ETHERTYPE_PPPOES2
:
362 pppoe_print(ndo
, p
, length
);
365 case ETHERTYPE_EAPOL
:
366 eap_print(ndo
, p
, length
);
370 rrcp_print(ndo
, p
- 14 , length
+ 14);
375 ND_PRINT((ndo
, ": "));
376 ppp_print(ndo
, p
, length
);
381 mpcp_print(ndo
, p
, length
);
385 slow_print(ndo
, p
, length
);
389 case ETHERTYPE_CFM_OLD
:
390 cfm_print(ndo
, p
, length
);
394 lldp_print(ndo
, p
, length
);
397 case ETHERTYPE_LOOPBACK
:
398 loopback_print(ndo
, p
, length
);
402 case ETHERTYPE_MPLS_MULTI
:
403 mpls_print(ndo
, p
, length
);
407 tipc_print(ndo
, p
, length
, caplen
);
410 case ETHERTYPE_MS_NLB_HB
:
414 case ETHERTYPE_GEONET_OLD
:
415 case ETHERTYPE_GEONET
:
416 geonet_print(ndo
, p
-14, p
, length
);
419 case ETHERTYPE_CALM_FAST
:
420 calm_fast_print(ndo
, p
-14, p
, length
);
424 aoe_print(ndo
, p
, length
);
427 case ETHERTYPE_MEDSA
:
428 medsa_print(ndo
, p
, length
, caplen
);
433 case ETHERTYPE_MOPRC
:
434 case ETHERTYPE_MOPDL
:
435 case ETHERTYPE_IEEE1905_1
:
436 /* default_print for now */
445 * c-style: whitesmith