blob: da95862b3c0b5150a4b324f0439caf4eb828f395 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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.
4 *
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
16 * written permission.
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.
20 */
The Android Open Source Project2949f582009-03-03 19:30:46 -080021
Elliott Hughese2e3bd12017-05-15 10:59:29 -070022/* \summary: Ethernet printer */
23
The Android Open Source Project2949f582009-03-03 19:30:46 -080024#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070025#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080026#endif
27
Elliott Hughes820eced2021-08-20 18:00:50 -070028#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080029
Elliott Hughes820eced2021-08-20 18:00:50 -070030#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070031#include "netdissect.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080032#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080033#include "addrtoname.h"
34#include "ethertype.h"
Elliott Hughes820eced2021-08-20 18:00:50 -070035
36/*
37 * Structure of an Ethernet header.
38 */
39struct ether_header {
40 nd_mac_addr ether_dhost;
41 nd_mac_addr ether_shost;
42 nd_uint16_t ether_length_type;
43};
44
45/*
46 * Length of an Ethernet header; note that some compilers may pad
47 * "struct ether_header" to a multiple of 4 bytes, for example, so
48 * "sizeof (struct ether_header)" may not give the right answer.
49 */
50#define ETHER_HDRLEN 14
The Android Open Source Project2949f582009-03-03 19:30:46 -080051
Elliott Hughes892a68b2015-10-19 14:43:53 -070052const struct tok ethertype_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080053 { ETHERTYPE_IP, "IPv4" },
54 { ETHERTYPE_MPLS, "MPLS unicast" },
55 { ETHERTYPE_MPLS_MULTI, "MPLS multicast" },
56 { ETHERTYPE_IPV6, "IPv6" },
57 { ETHERTYPE_8021Q, "802.1Q" },
JP Abgrall53f17a92014-02-12 14:02:41 -080058 { ETHERTYPE_8021Q9100, "802.1Q-9100" },
59 { ETHERTYPE_8021QinQ, "802.1Q-QinQ" },
60 { ETHERTYPE_8021Q9200, "802.1Q-9200" },
Elliott Hughes820eced2021-08-20 18:00:50 -070061 { ETHERTYPE_MACSEC, "802.1AE MACsec" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080062 { ETHERTYPE_VMAN, "VMAN" },
63 { ETHERTYPE_PUP, "PUP" },
64 { ETHERTYPE_ARP, "ARP"},
65 { ETHERTYPE_REVARP, "Reverse ARP"},
66 { ETHERTYPE_NS, "NS" },
67 { ETHERTYPE_SPRITE, "Sprite" },
68 { ETHERTYPE_TRAIL, "Trail" },
69 { ETHERTYPE_MOPDL, "MOP DL" },
70 { ETHERTYPE_MOPRC, "MOP RC" },
71 { ETHERTYPE_DN, "DN" },
72 { ETHERTYPE_LAT, "LAT" },
73 { ETHERTYPE_SCA, "SCA" },
JP Abgrall53f17a92014-02-12 14:02:41 -080074 { ETHERTYPE_TEB, "TEB" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080075 { ETHERTYPE_LANBRIDGE, "Lanbridge" },
76 { ETHERTYPE_DECDNS, "DEC DNS" },
77 { ETHERTYPE_DECDTS, "DEC DTS" },
78 { ETHERTYPE_VEXP, "VEXP" },
79 { ETHERTYPE_VPROD, "VPROD" },
80 { ETHERTYPE_ATALK, "Appletalk" },
81 { ETHERTYPE_AARP, "Appletalk ARP" },
82 { ETHERTYPE_IPX, "IPX" },
83 { ETHERTYPE_PPP, "PPP" },
JP Abgrall53f17a92014-02-12 14:02:41 -080084 { ETHERTYPE_MPCP, "MPCP" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080085 { ETHERTYPE_SLOW, "Slow Protocols" },
86 { ETHERTYPE_PPPOED, "PPPoE D" },
87 { ETHERTYPE_PPPOES, "PPPoE S" },
88 { ETHERTYPE_EAPOL, "EAPOL" },
JP Abgrall53f17a92014-02-12 14:02:41 -080089 { ETHERTYPE_RRCP, "RRCP" },
90 { ETHERTYPE_MS_NLB_HB, "MS NLB heartbeat" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080091 { ETHERTYPE_JUMBO, "Jumbo" },
Elliott Hughes820eced2021-08-20 18:00:50 -070092 { ETHERTYPE_NSH, "NSH" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080093 { ETHERTYPE_LOOPBACK, "Loopback" },
94 { ETHERTYPE_ISO, "OSI" },
95 { ETHERTYPE_GRE_ISO, "GRE-OSI" },
JP Abgrall53f17a92014-02-12 14:02:41 -080096 { ETHERTYPE_CFM_OLD, "CFM (old)" },
97 { ETHERTYPE_CFM, "CFM" },
Elliott Hughes892a68b2015-10-19 14:43:53 -070098 { ETHERTYPE_IEEE1905_1, "IEEE1905.1" },
JP Abgrall53f17a92014-02-12 14:02:41 -080099 { ETHERTYPE_LLDP, "LLDP" },
Elliott Hughes892a68b2015-10-19 14:43:53 -0700100 { ETHERTYPE_TIPC, "TIPC"},
JP Abgrall53f17a92014-02-12 14:02:41 -0800101 { ETHERTYPE_GEONET_OLD, "GeoNet (old)"},
102 { ETHERTYPE_GEONET, "GeoNet"},
103 { ETHERTYPE_CALM_FAST, "CALM FAST"},
Elliott Hughes892a68b2015-10-19 14:43:53 -0700104 { ETHERTYPE_AOE, "AoE" },
Elliott Hughes820eced2021-08-20 18:00:50 -0700105 { ETHERTYPE_PTP, "PTP" },
106 { ETHERTYPE_ARISTA, "Arista Vendor Specific Protocol" },
The Android Open Source Project2949f582009-03-03 19:30:46 -0800107 { 0, NULL}
108};
109
Elliott Hughes820eced2021-08-20 18:00:50 -0700110static void
111ether_addresses_print(netdissect_options *ndo, const u_char *src,
112 const u_char *dst)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800113{
Elliott Hughes820eced2021-08-20 18:00:50 -0700114 ND_PRINT("%s > %s, ",
115 GET_ETHERADDR_STRING(src), GET_ETHERADDR_STRING(dst));
116}
JP Abgrall53f17a92014-02-12 14:02:41 -0800117
Elliott Hughes820eced2021-08-20 18:00:50 -0700118static void
119ether_type_print(netdissect_options *ndo, uint16_t type)
120{
121 if (!ndo->ndo_qflag)
122 ND_PRINT("ethertype %s (0x%04x)",
123 tok2str(ethertype_values, "Unknown", type), type);
124 else
125 ND_PRINT("%s",
126 tok2str(ethertype_values, "Unknown Ethertype (0x%04x)", type));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800127}
128
JP Abgrall53f17a92014-02-12 14:02:41 -0800129/*
Elliott Hughes820eced2021-08-20 18:00:50 -0700130 * Common code for printing Ethernet frames.
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700131 *
Elliott Hughes820eced2021-08-20 18:00:50 -0700132 * It can handle Ethernet headers with extra tag information inserted
133 * after the destination and source addresses, as is inserted by some
134 * switch chips, and extra encapsulation header information before
135 * printing Ethernet header information (such as a LANE ID for ATM LANE).
JP Abgrall53f17a92014-02-12 14:02:41 -0800136 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700137static u_int
138ether_common_print(netdissect_options *ndo, const u_char *p, u_int length,
139 u_int caplen,
140 void (*print_switch_tag)(netdissect_options *ndo, const u_char *),
141 u_int switch_tag_len,
142 void (*print_encap_header)(netdissect_options *ndo, const u_char *),
143 const u_char *encap_header_arg)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800144{
Elliott Hughes820eced2021-08-20 18:00:50 -0700145 const struct ether_header *ehp;
JP Abgrall53f17a92014-02-12 14:02:41 -0800146 u_int orig_length;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700147 u_int hdrlen;
Elliott Hughes820eced2021-08-20 18:00:50 -0700148 u_short length_type;
149 int printed_length;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700150 int llc_hdrlen;
151 struct lladdr_info src, dst;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800152
Elliott Hughes820eced2021-08-20 18:00:50 -0700153 if (caplen < ETHER_HDRLEN + switch_tag_len) {
154 nd_print_trunc(ndo);
155 return caplen;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700156 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700157 if (length < ETHER_HDRLEN + switch_tag_len) {
158 nd_print_trunc(ndo);
159 return length;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800160 }
161
Elliott Hughes820eced2021-08-20 18:00:50 -0700162 if (print_encap_header != NULL)
163 (*print_encap_header)(ndo, encap_header_arg);
164
JP Abgrall53f17a92014-02-12 14:02:41 -0800165 orig_length = length;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800166
The Android Open Source Project2949f582009-03-03 19:30:46 -0800167 /*
Elliott Hughes820eced2021-08-20 18:00:50 -0700168 * Get the source and destination addresses, skip past them,
169 * and print them if we're printing the link-layer header.
The Android Open Source Project2949f582009-03-03 19:30:46 -0800170 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700171 ehp = (const struct ether_header *)p;
172 src.addr = ehp->ether_shost;
173 src.addr_string = etheraddr_string;
174 dst.addr = ehp->ether_dhost;
175 dst.addr_string = etheraddr_string;
176
177 length -= 2*MAC_ADDR_LEN;
178 caplen -= 2*MAC_ADDR_LEN;
179 p += 2*MAC_ADDR_LEN;
180 hdrlen = 2*MAC_ADDR_LEN;
181
182 if (ndo->ndo_eflag)
183 ether_addresses_print(ndo, src.addr, dst.addr);
184
185 /*
186 * Print the switch tag, if we have one, and skip past it.
187 */
188 if (print_switch_tag != NULL)
189 (*print_switch_tag)(ndo, p);
190
191 length -= switch_tag_len;
192 caplen -= switch_tag_len;
193 p += switch_tag_len;
194 hdrlen += switch_tag_len;
195
196 /*
197 * Get the length/type field, skip past it, and print it
198 * if we're printing the link-layer header.
199 */
200recurse:
201 length_type = GET_BE_U_2(p);
202
203 length -= 2;
204 caplen -= 2;
205 p += 2;
206 hdrlen += 2;
207
208 /*
209 * Process 802.1AE MACsec headers.
210 */
211 printed_length = 0;
212 if (length_type == ETHERTYPE_MACSEC) {
213 /*
214 * MACsec, aka IEEE 802.1AE-2006
215 * Print the header, and try to print the payload if it's not encrypted
216 */
217 if (ndo->ndo_eflag) {
218 ether_type_print(ndo, length_type);
219 ND_PRINT(", length %u: ", orig_length);
220 printed_length = 1;
221 }
222
223 int ret = macsec_print(ndo, &p, &length, &caplen, &hdrlen,
224 &src, &dst);
225
226 if (ret == 0) {
227 /* Payload is encrypted; print it as raw data. */
228 if (!ndo->ndo_suppress_default_print)
229 ND_DEFAULTPRINT(p, caplen);
230 return hdrlen;
231 } else if (ret > 0) {
232 /* Problem printing the header; just quit. */
233 return ret;
234 } else {
235 /*
236 * Keep processing type/length fields.
237 */
238 length_type = GET_BE_U_2(p);
239
240 length -= 2;
241 caplen -= 2;
242 p += 2;
243 hdrlen += 2;
244 }
245 }
246
247 /*
248 * Process VLAN tag types.
249 */
250 while (length_type == ETHERTYPE_8021Q ||
251 length_type == ETHERTYPE_8021Q9100 ||
252 length_type == ETHERTYPE_8021Q9200 ||
253 length_type == ETHERTYPE_8021QinQ) {
254 /*
255 * It has a VLAN tag.
256 * Print VLAN information, and then go back and process
257 * the enclosed type field.
258 */
259 if (caplen < 4) {
260 ndo->ndo_protocol = "vlan";
261 nd_print_trunc(ndo);
262 return hdrlen + caplen;
263 }
264 if (length < 4) {
265 ndo->ndo_protocol = "vlan";
266 nd_print_trunc(ndo);
267 return hdrlen + length;
268 }
269 if (ndo->ndo_eflag) {
270 uint16_t tag = GET_BE_U_2(p);
271
272 ether_type_print(ndo, length_type);
273 if (!printed_length) {
274 ND_PRINT(", length %u: ", orig_length);
275 printed_length = 1;
276 } else
277 ND_PRINT(", ");
278 ND_PRINT("%s, ", ieee8021q_tci_string(tag));
279 }
280
281 length_type = GET_BE_U_2(p + 2);
282 p += 4;
283 length -= 4;
284 caplen -= 4;
285 hdrlen += 4;
286 }
287
288 /*
289 * We now have the final length/type field.
290 */
291 if (length_type <= MAX_ETHERNET_LENGTH_VAL) {
292 /*
293 * It's a length field, containing the length of the
294 * remaining payload; use it as such, as long as
295 * it's not too large (bigger than the actual payload).
296 */
297 if (length_type < length) {
298 length = length_type;
299 if (caplen > length)
300 caplen = length;
301 }
302
303 /*
304 * Cut off the snapshot length to the end of the
305 * payload.
306 */
307 nd_push_snapend(ndo, p + length);
308
309 if (ndo->ndo_eflag) {
310 ND_PRINT("802.3");
311 if (!printed_length)
312 ND_PRINT(", length %u: ", length);
313 }
314
315 /*
316 * An LLC header follows the length. Print that and
317 * higher layers.
318 */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700319 llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst);
320 if (llc_hdrlen < 0) {
321 /* packet type not known, print raw packet */
JP Abgrall53f17a92014-02-12 14:02:41 -0800322 if (!ndo->ndo_suppress_default_print)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700323 ND_DEFAULTPRINT(p, caplen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700324 llc_hdrlen = -llc_hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800325 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700326 hdrlen += llc_hdrlen;
Elliott Hughes820eced2021-08-20 18:00:50 -0700327 nd_pop_packet_info(ndo);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700328 } else if (length_type == ETHERTYPE_JUMBO) {
JP Abgrall53f17a92014-02-12 14:02:41 -0800329 /*
Elliott Hughes820eced2021-08-20 18:00:50 -0700330 * It's a type field, with the type for Alteon jumbo frames.
JP Abgrall53f17a92014-02-12 14:02:41 -0800331 * See
332 *
Elliott Hughes820eced2021-08-20 18:00:50 -0700333 * https://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
JP Abgrall53f17a92014-02-12 14:02:41 -0800334 *
335 * which indicates that, following the type field,
336 * there's an LLC header and payload.
337 */
338 /* Try to print the LLC-layer header & higher layers */
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700339 llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst);
340 if (llc_hdrlen < 0) {
341 /* packet type not known, print raw packet */
JP Abgrall53f17a92014-02-12 14:02:41 -0800342 if (!ndo->ndo_suppress_default_print)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700343 ND_DEFAULTPRINT(p, caplen);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700344 llc_hdrlen = -llc_hdrlen;
JP Abgrall53f17a92014-02-12 14:02:41 -0800345 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700346 hdrlen += llc_hdrlen;
Elliott Hughes820eced2021-08-20 18:00:50 -0700347 } else if (length_type == ETHERTYPE_ARISTA) {
348 if (caplen < 2) {
349 ND_PRINT("[|arista]");
350 return hdrlen + caplen;
351 }
352 if (length < 2) {
353 ND_PRINT("[|arista]");
354 return hdrlen + length;
355 }
356 ether_type_print(ndo, length_type);
357 ND_PRINT(", length %u: ", orig_length);
358 int bytesConsumed = arista_ethertype_print(ndo, p, length);
359 if (bytesConsumed > 0) {
360 p += bytesConsumed;
361 length -= bytesConsumed;
362 caplen -= bytesConsumed;
363 hdrlen += bytesConsumed;
364 goto recurse;
365 } else {
366 /* subtype/version not known, print raw packet */
367 if (!ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) {
368 ether_addresses_print(ndo, src.addr, dst.addr);
369 ether_type_print(ndo, length_type);
370 ND_PRINT(", length %u: ", orig_length);
371 }
372 if (!ndo->ndo_suppress_default_print)
373 ND_DEFAULTPRINT(p, caplen);
374 }
JP Abgrall53f17a92014-02-12 14:02:41 -0800375 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700376 /*
377 * It's a type field with some other value.
378 */
379 if (ndo->ndo_eflag) {
380 ether_type_print(ndo, length_type);
381 if (!printed_length)
382 ND_PRINT(", length %u: ", orig_length);
383 else
384 ND_PRINT(", ");
385 }
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700386 if (ethertype_print(ndo, length_type, p, length, caplen, &src, &dst) == 0) {
387 /* type not known, print raw packet */
JP Abgrall53f17a92014-02-12 14:02:41 -0800388 if (!ndo->ndo_eflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700389 /*
390 * We didn't print the full link-layer
391 * header, as -e wasn't specified, so
392 * print only the source and destination
393 * MAC addresses and the final Ethernet
394 * type.
395 */
396 ether_addresses_print(ndo, src.addr, dst.addr);
397 ether_type_print(ndo, length_type);
398 ND_PRINT(", length %u: ", orig_length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800399 }
400
401 if (!ndo->ndo_suppress_default_print)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700402 ND_DEFAULTPRINT(p, caplen);
JP Abgrall53f17a92014-02-12 14:02:41 -0800403 }
404 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700405 return hdrlen;
406}
407
408/*
409 * Print an Ethernet frame while specyfing a non-standard Ethernet header
410 * length.
411 * This might be encapsulated within another frame; we might be passed
412 * a pointer to a function that can print header information for that
413 * frame's protocol, and an argument to pass to that function.
414 *
415 * FIXME: caplen can and should be derived from ndo->ndo_snapend and p.
416 */
417u_int
418ether_switch_tag_print(netdissect_options *ndo, const u_char *p, u_int length,
419 u_int caplen,
420 void (*print_switch_tag)(netdissect_options *, const u_char *),
421 u_int switch_tag_len)
422{
423 return ether_common_print(ndo, p, length, caplen, print_switch_tag,
424 switch_tag_len, NULL, NULL);
425}
426
427/*
428 * Print an Ethernet frame.
429 * This might be encapsulated within another frame; we might be passed
430 * a pointer to a function that can print header information for that
431 * frame's protocol, and an argument to pass to that function.
432 *
433 * FIXME: caplen can and should be derived from ndo->ndo_snapend and p.
434 */
435u_int
436ether_print(netdissect_options *ndo,
437 const u_char *p, u_int length, u_int caplen,
438 void (*print_encap_header)(netdissect_options *ndo, const u_char *),
439 const u_char *encap_header_arg)
440{
441 ndo->ndo_protocol = "ether";
442 return ether_common_print(ndo, p, length, caplen, NULL, 0,
443 print_encap_header, encap_header_arg);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800444}
445
446/*
447 * This is the top level routine of the printer. 'p' points
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700448 * to the ether header of the packet, 'h->len' is the length
449 * of the packet off the wire, and 'h->caplen' is the number
450 * of bytes actually captured.
The Android Open Source Project2949f582009-03-03 19:30:46 -0800451 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700452void
JP Abgrall53f17a92014-02-12 14:02:41 -0800453ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
Elliott Hughes820eced2021-08-20 18:00:50 -0700454 const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800455{
Elliott Hughes820eced2021-08-20 18:00:50 -0700456 ndo->ndo_protocol = "ether";
457 ndo->ndo_ll_hdr_len +=
458 ether_print(ndo, p, h->len, h->caplen, NULL, NULL);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800459}
460
461/*
JP Abgrall53f17a92014-02-12 14:02:41 -0800462 * This is the top level routine of the printer. 'p' points
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700463 * to the ether header of the packet, 'h->len' is the length
464 * of the packet off the wire, and 'h->caplen' is the number
465 * of bytes actually captured.
JP Abgrall53f17a92014-02-12 14:02:41 -0800466 *
467 * This is for DLT_NETANALYZER, which has a 4-byte pseudo-header
468 * before the Ethernet header.
469 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700470void
JP Abgrall53f17a92014-02-12 14:02:41 -0800471netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
Elliott Hughes820eced2021-08-20 18:00:50 -0700472 const u_char *p)
JP Abgrall53f17a92014-02-12 14:02:41 -0800473{
474 /*
475 * Fail if we don't have enough data for the Hilscher pseudo-header.
476 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700477 ndo->ndo_protocol = "netanalyzer";
478 ND_TCHECK_LEN(p, 4);
JP Abgrall53f17a92014-02-12 14:02:41 -0800479
480 /* Skip the pseudo-header. */
Elliott Hughes820eced2021-08-20 18:00:50 -0700481 ndo->ndo_ll_hdr_len += 4;
482 ndo->ndo_ll_hdr_len +=
483 ether_print(ndo, p + 4, h->len - 4, h->caplen - 4, NULL, NULL);
JP Abgrall53f17a92014-02-12 14:02:41 -0800484}
485
486/*
487 * This is the top level routine of the printer. 'p' points
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700488 * to the ether header of the packet, 'h->len' is the length
489 * of the packet off the wire, and 'h->caplen' is the number
490 * of bytes actually captured.
JP Abgrall53f17a92014-02-12 14:02:41 -0800491 *
492 * This is for DLT_NETANALYZER_TRANSPARENT, which has a 4-byte
493 * pseudo-header, a 7-byte Ethernet preamble, and a 1-byte Ethernet SOF
494 * before the Ethernet header.
495 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700496void
JP Abgrall53f17a92014-02-12 14:02:41 -0800497netanalyzer_transparent_if_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700498 const struct pcap_pkthdr *h,
499 const u_char *p)
JP Abgrall53f17a92014-02-12 14:02:41 -0800500{
501 /*
502 * Fail if we don't have enough data for the Hilscher pseudo-header,
503 * preamble, and SOF.
504 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700505 ndo->ndo_protocol = "netanalyzer_transparent";
506 ND_TCHECK_LEN(p, 12);
JP Abgrall53f17a92014-02-12 14:02:41 -0800507
508 /* Skip the pseudo-header, preamble, and SOF. */
Elliott Hughes820eced2021-08-20 18:00:50 -0700509 ndo->ndo_ll_hdr_len += 12;
510 ndo->ndo_ll_hdr_len +=
511 ether_print(ndo, p + 12, h->len - 12, h->caplen - 12, NULL, NULL);
JP Abgrall53f17a92014-02-12 14:02:41 -0800512}
513
514/*
515 * Prints the packet payload, given an Ethernet type code for the payload's
516 * protocol.
The Android Open Source Project2949f582009-03-03 19:30:46 -0800517 *
518 * Returns non-zero if it can do so, zero if the ethertype is unknown.
The Android Open Source Project2949f582009-03-03 19:30:46 -0800519 */
520
521int
JP Abgrall53f17a92014-02-12 14:02:41 -0800522ethertype_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700523 u_short ether_type, const u_char *p,
524 u_int length, u_int caplen,
525 const struct lladdr_info *src, const struct lladdr_info *dst)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800526{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800527 switch (ether_type) {
528
529 case ETHERTYPE_IP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700530 ip_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800531 return (1);
532
The Android Open Source Project2949f582009-03-03 19:30:46 -0800533 case ETHERTYPE_IPV6:
JP Abgrall53f17a92014-02-12 14:02:41 -0800534 ip6_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800535 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800536
537 case ETHERTYPE_ARP:
538 case ETHERTYPE_REVARP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700539 arp_print(ndo, p, length, caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800540 return (1);
541
542 case ETHERTYPE_DN:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700543 decnet_print(ndo, p, length, caplen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800544 return (1);
545
546 case ETHERTYPE_ATALK:
JP Abgrall53f17a92014-02-12 14:02:41 -0800547 if (ndo->ndo_vflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700548 ND_PRINT("et1 ");
Elliott Hughes892a68b2015-10-19 14:43:53 -0700549 atalk_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800550 return (1);
551
552 case ETHERTYPE_AARP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700553 aarp_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800554 return (1);
555
556 case ETHERTYPE_IPX:
Elliott Hughes820eced2021-08-20 18:00:50 -0700557 ND_PRINT("(NOV-ETHII) ");
Elliott Hughes892a68b2015-10-19 14:43:53 -0700558 ipx_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800559 return (1);
560
Elliott Hughes892a68b2015-10-19 14:43:53 -0700561 case ETHERTYPE_ISO:
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700562 if (length == 0 || caplen == 0) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700563 ndo->ndo_protocol = "isoclns";
564 nd_print_trunc(ndo);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700565 return (1);
566 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700567 /* At least one byte is required */
568 /* FIXME: Reference for this byte? */
569 ND_TCHECK_LEN(p, 1);
Elliott Hughescec480a2017-12-19 16:54:57 -0800570 isoclns_print(ndo, p + 1, length - 1);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700571 return(1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800572
573 case ETHERTYPE_PPPOED:
574 case ETHERTYPE_PPPOES:
JP Abgrall53f17a92014-02-12 14:02:41 -0800575 case ETHERTYPE_PPPOED2:
576 case ETHERTYPE_PPPOES2:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700577 pppoe_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800578 return (1);
579
580 case ETHERTYPE_EAPOL:
Elliott Hughes820eced2021-08-20 18:00:50 -0700581 eapol_print(ndo, p);
JP Abgrall53f17a92014-02-12 14:02:41 -0800582 return (1);
583
584 case ETHERTYPE_RRCP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700585 rrcp_print(ndo, p, length, src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800586 return (1);
587
588 case ETHERTYPE_PPP:
589 if (length) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700590 ND_PRINT(": ");
Elliott Hughes892a68b2015-10-19 14:43:53 -0700591 ppp_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800592 }
593 return (1);
594
JP Abgrall53f17a92014-02-12 14:02:41 -0800595 case ETHERTYPE_MPCP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700596 mpcp_print(ndo, p, length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800597 return (1);
598
The Android Open Source Project2949f582009-03-03 19:30:46 -0800599 case ETHERTYPE_SLOW:
Elliott Hughes820eced2021-08-20 18:00:50 -0700600 slow_print(ndo, p, length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800601 return (1);
602
603 case ETHERTYPE_CFM:
604 case ETHERTYPE_CFM_OLD:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700605 cfm_print(ndo, p, length);
JP Abgrall53f17a92014-02-12 14:02:41 -0800606 return (1);
607
608 case ETHERTYPE_LLDP:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700609 lldp_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800610 return (1);
611
Elliott Hughes820eced2021-08-20 18:00:50 -0700612 case ETHERTYPE_NSH:
613 nsh_print(ndo, p, length);
614 return (1);
615
616 case ETHERTYPE_LOOPBACK:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700617 loopback_print(ndo, p, length);
Elliott Hughes820eced2021-08-20 18:00:50 -0700618 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800619
620 case ETHERTYPE_MPLS:
621 case ETHERTYPE_MPLS_MULTI:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700622 mpls_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800623 return (1);
624
JP Abgrall53f17a92014-02-12 14:02:41 -0800625 case ETHERTYPE_TIPC:
626 tipc_print(ndo, p, length, caplen);
627 return (1);
628
629 case ETHERTYPE_MS_NLB_HB:
630 msnlb_print(ndo, p);
631 return (1);
632
Elliott Hughes820eced2021-08-20 18:00:50 -0700633 case ETHERTYPE_GEONET_OLD:
634 case ETHERTYPE_GEONET:
635 geonet_print(ndo, p, length, src);
636 return (1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800637
Elliott Hughes820eced2021-08-20 18:00:50 -0700638 case ETHERTYPE_CALM_FAST:
639 calm_fast_print(ndo, p, length, src);
640 return (1);
JP Abgrall53f17a92014-02-12 14:02:41 -0800641
Elliott Hughes892a68b2015-10-19 14:43:53 -0700642 case ETHERTYPE_AOE:
643 aoe_print(ndo, p, length);
644 return (1);
645
Elliott Hughes820eced2021-08-20 18:00:50 -0700646 case ETHERTYPE_PTP:
647 ptp_print(ndo, p, length);
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700648 return (1);
649
The Android Open Source Project2949f582009-03-03 19:30:46 -0800650 case ETHERTYPE_LAT:
651 case ETHERTYPE_SCA:
652 case ETHERTYPE_MOPRC:
653 case ETHERTYPE_MOPDL:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700654 case ETHERTYPE_IEEE1905_1:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800655 /* default_print for now */
656 default:
657 return (0);
658 }
659}