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.
24 #define NETDISSECT_REWORKED
29 #include <tcpdump-stdinc.h>
31 #include "interface.h"
33 #include "addrtoname.h"
34 #include "ethertype.h"
37 const struct tok ethertype_values[] = {
38 { ETHERTYPE_IP, "IPv4" },
39 { ETHERTYPE_MPLS, "MPLS unicast" },
40 { ETHERTYPE_MPLS_MULTI, "MPLS multicast" },
41 { ETHERTYPE_IPV6, "IPv6" },
42 { ETHERTYPE_8021Q, "802.1Q" },
43 { ETHERTYPE_8021Q9100, "802.1Q-9100" },
44 { ETHERTYPE_8021QinQ, "802.1Q-QinQ" },
45 { ETHERTYPE_8021Q9200, "802.1Q-9200" },
46 { ETHERTYPE_VMAN, "VMAN" },
47 { ETHERTYPE_PUP, "PUP" },
48 { ETHERTYPE_ARP, "ARP"},
49 { ETHERTYPE_REVARP, "Reverse ARP"},
50 { ETHERTYPE_NS, "NS" },
51 { ETHERTYPE_SPRITE, "Sprite" },
52 { ETHERTYPE_TRAIL, "Trail" },
53 { ETHERTYPE_MOPDL, "MOP DL" },
54 { ETHERTYPE_MOPRC, "MOP RC" },
55 { ETHERTYPE_DN, "DN" },
56 { ETHERTYPE_LAT, "LAT" },
57 { ETHERTYPE_SCA, "SCA" },
58 { ETHERTYPE_TEB, "TEB" },
59 { ETHERTYPE_LANBRIDGE, "Lanbridge" },
60 { ETHERTYPE_DECDNS, "DEC DNS" },
61 { ETHERTYPE_DECDTS, "DEC DTS" },
62 { ETHERTYPE_VEXP, "VEXP" },
63 { ETHERTYPE_VPROD, "VPROD" },
64 { ETHERTYPE_ATALK, "Appletalk" },
65 { ETHERTYPE_AARP, "Appletalk ARP" },
66 { ETHERTYPE_IPX, "IPX" },
67 { ETHERTYPE_PPP, "PPP" },
68 { ETHERTYPE_MPCP, "MPCP" },
69 { ETHERTYPE_SLOW, "Slow Protocols" },
70 { ETHERTYPE_PPPOED, "PPPoE D" },
71 { ETHERTYPE_PPPOES, "PPPoE S" },
72 { ETHERTYPE_EAPOL, "EAPOL" },
73 { ETHERTYPE_RRCP, "RRCP" },
74 { ETHERTYPE_MS_NLB_HB, "MS NLB heartbeat" },
75 { ETHERTYPE_JUMBO, "Jumbo" },
76 { ETHERTYPE_LOOPBACK, "Loopback" },
77 { ETHERTYPE_ISO, "OSI" },
78 { ETHERTYPE_GRE_ISO, "GRE-OSI" },
79 { ETHERTYPE_CFM_OLD, "CFM (old)" },
80 { ETHERTYPE_CFM, "CFM" },
81 { ETHERTYPE_IEEE1905_1, "IEEE1905.1" },
82 { ETHERTYPE_LLDP, "LLDP" },
83 { ETHERTYPE_TIPC, "TIPC"},
84 { ETHERTYPE_GEONET_OLD, "GeoNet (old)"},
85 { ETHERTYPE_GEONET, "GeoNet"},
86 { ETHERTYPE_CALM_FAST, "CALM FAST"},
87 { ETHERTYPE_AOE, "AoE" },
92 ether_hdr_print(netdissect_options *ndo,
93 const u_char *bp, u_int length)
95 register const struct ether_header *ep;
98 ep = (const struct ether_header *)bp;
100 ND_PRINT((ndo, "%s > %s",
101 etheraddr_string(ndo, ESRC(ep)),
102 etheraddr_string(ndo, EDST(ep))));
104 ether_type = EXTRACT_16BITS(&ep->ether_type);
105 if (!ndo->ndo_qflag) {
106 if (ether_type <= ETHERMTU)
107 ND_PRINT((ndo, ", 802.3"));
109 ND_PRINT((ndo, ", ethertype %s (0x%04x)",
110 tok2str(ethertype_values,"Unknown", ether_type),
113 if (ether_type <= ETHERMTU)
114 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 struct ether_header *ep;
136 u_short extracted_ether_type;
138 if (caplen < ETHER_HDRLEN || length < ETHER_HDRLEN) {
139 ND_PRINT((ndo, "[|ether]"));
143 if (ndo->ndo_eflag) {
144 if (print_encap_header != NULL)
145 (*print_encap_header)(ndo, encap_header_arg);
146 ether_hdr_print(ndo, p, length);
148 orig_length = length;
150 length -= ETHER_HDRLEN;
151 caplen -= ETHER_HDRLEN;
152 ep = (struct ether_header *)p;
155 ether_type = EXTRACT_16BITS(&ep->ether_type);
159 * Is it (gag) an 802.3 encapsulation?
161 if (ether_type <= ETHERMTU) {
162 /* Try to print the LLC-layer header & higher layers */
163 if (llc_print(ndo, p, length, caplen, ESRC(ep), EDST(ep),
164 &extracted_ether_type) == 0) {
165 /* ether_type not known, print raw packet */
166 if (!ndo->ndo_eflag) {
167 if (print_encap_header != NULL)
168 (*print_encap_header)(ndo, encap_header_arg);
169 ether_hdr_print(ndo, (u_char *)ep, orig_length);
172 if (!ndo->ndo_suppress_default_print)
173 ND_DEFAULTPRINT(p, caplen);
175 } else if (ether_type == ETHERTYPE_8021Q ||
176 ether_type == ETHERTYPE_8021Q9100 ||
177 ether_type == ETHERTYPE_8021Q9200 ||
178 ether_type == ETHERTYPE_8021QinQ) {
180 * Print VLAN information, and then go back and process
181 * the enclosed type field.
183 if (caplen < 4 || length < 4) {
184 ND_PRINT((ndo, "[|vlan]"));
187 if (ndo->ndo_eflag) {
188 uint16_t tag = EXTRACT_16BITS(p);
190 ND_PRINT((ndo, "%s, ", ieee8021q_tci_string(tag)));
193 ether_type = EXTRACT_16BITS(p + 2);
194 if (ndo->ndo_eflag && ether_type > ETHERMTU)
195 ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type)));
200 } else if (ether_type == ETHERTYPE_JUMBO) {
202 * Alteon jumbo frames.
205 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
207 * which indicates that, following the type field,
208 * there's an LLC header and payload.
210 /* Try to print the LLC-layer header & higher layers */
211 if (llc_print(ndo, p, length, caplen, ESRC(ep), EDST(ep),
212 &extracted_ether_type) == 0) {
213 /* ether_type not known, print raw packet */
214 if (!ndo->ndo_eflag) {
215 if (print_encap_header != NULL)
216 (*print_encap_header)(ndo, encap_header_arg);
217 ether_hdr_print(ndo, (u_char *)ep, orig_length);
220 if (!ndo->ndo_suppress_default_print)
221 ND_DEFAULTPRINT(p, caplen);
224 if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) {
225 /* ether_type not known, print raw packet */
226 if (!ndo->ndo_eflag) {
227 if (print_encap_header != NULL)
228 (*print_encap_header)(ndo, encap_header_arg);
229 ether_hdr_print(ndo, (u_char *)ep, orig_length);
232 if (!ndo->ndo_suppress_default_print)
233 ND_DEFAULTPRINT(p, caplen);
239 * This is the top level routine of the printer. 'p' points
240 * to the ether header of the packet, 'h->ts' is the timestamp,
241 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
242 * is the number of bytes actually captured.
245 ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
248 ether_print(ndo, p, h->len, h->caplen, NULL, NULL);
250 return (ETHER_HDRLEN);
254 * This is the top level routine of the printer. 'p' points
255 * to the ether header of the packet, 'h->ts' is the timestamp,
256 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
257 * is the number of bytes actually captured.
259 * This is for DLT_NETANALYZER, which has a 4-byte pseudo-header
260 * before the Ethernet header.
263 netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
267 * Fail if we don't have enough data for the Hilscher pseudo-header.
269 if (h->len < 4 || h->caplen < 4) {
270 ND_PRINT((ndo, "[|netanalyzer]"));
274 /* Skip the pseudo-header. */
275 ether_print(ndo, p + 4, h->len - 4, h->caplen - 4, NULL, NULL);
277 return (4 + ETHER_HDRLEN);
281 * This is the top level routine of the printer. 'p' points
282 * to the ether header of the packet, 'h->ts' is the timestamp,
283 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
284 * is the number 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 ether_print(ndo, p + 12, h->len - 12, h->caplen - 12, NULL, NULL);
307 return (12 + ETHER_HDRLEN);
311 * Prints the packet payload, given an Ethernet type code for the payload's
314 * Returns non-zero if it can do so, zero if the ethertype is unknown.
318 ethertype_print(netdissect_options *ndo,
319 u_short ether_type, const u_char *p,
320 u_int length, u_int caplen)
322 switch (ether_type) {
325 ip_print(ndo, p, length);
329 ip6_print(ndo, p, length);
333 case ETHERTYPE_REVARP:
334 arp_print(ndo, p, length, caplen);
338 decnet_print(ndo, p, length, caplen);
341 case ETHERTYPE_ATALK:
343 ND_PRINT((ndo, "et1 "));
344 atalk_print(ndo, p, length);
348 aarp_print(ndo, p, length);
352 ND_PRINT((ndo, "(NOV-ETHII) "));
353 ipx_print(ndo, p, length);
357 isoclns_print(ndo, p + 1, length - 1, length - 1);
360 case ETHERTYPE_PPPOED:
361 case ETHERTYPE_PPPOES:
362 case ETHERTYPE_PPPOED2:
363 case ETHERTYPE_PPPOES2:
364 pppoe_print(ndo, p, length);
367 case ETHERTYPE_EAPOL:
368 eap_print(ndo, p, length);
372 rrcp_print(ndo, p - 14 , length + 14);
377 ND_PRINT((ndo, ": "));
378 ppp_print(ndo, p, length);
383 mpcp_print(ndo, p, length);
387 slow_print(ndo, p, length);
391 case ETHERTYPE_CFM_OLD:
392 cfm_print(ndo, p, length);
396 lldp_print(ndo, p, length);
399 case ETHERTYPE_LOOPBACK:
400 loopback_print(ndo, p, length);
404 case ETHERTYPE_MPLS_MULTI:
405 mpls_print(ndo, p, length);
409 tipc_print(ndo, p, length, caplen);
412 case ETHERTYPE_MS_NLB_HB:
416 case ETHERTYPE_GEONET_OLD:
417 case ETHERTYPE_GEONET:
418 geonet_print(ndo, p-14, p, length);
421 case ETHERTYPE_CALM_FAST:
422 calm_fast_print(ndo, p-14, p, length);
426 aoe_print(ndo, p, length);
431 case ETHERTYPE_MOPRC:
432 case ETHERTYPE_MOPDL:
433 case ETHERTYPE_IEEE1905_1:
434 /* default_print for now */
443 * c-style: whitesmith