epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-eth.c
blob043ddd466bea6dc96e60dbd77d9f722adaead9a8
1 /* packet-eth.c
2 * Routines for ethernet packet disassembly
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <epan/packet.h>
14 #include <epan/exceptions.h>
15 #include <epan/prefs.h>
16 #include <epan/etypes.h>
17 #include <epan/ipproto.h>
18 #include <epan/addr_resolv.h>
19 #include <epan/expert.h>
20 #include <epan/conversation_table.h>
21 #include <epan/conversation_filter.h>
22 #include <epan/capture_dissectors.h>
23 #include <epan/exported_pdu.h>
24 #include <epan/tfs.h>
25 #include <wsutil/pint.h>
26 #include "packet-eth.h"
27 #include "packet-gre.h"
28 #include "packet-ieee8023.h"
29 #include "packet-ipx.h"
30 #include "packet-isl.h"
31 #include "packet-llc.h"
32 #include "packet-sll.h"
33 #include "packet-juniper.h"
34 #include "packet-sflow.h"
35 #include "packet-l2tp.h"
36 #include "packet-vxlan.h"
37 #include "packet-nsh.h"
38 #include "packet-acdr.h"
39 #include "packet-mctp.h"
40 #include <epan/crc32-tvb.h>
41 #include <wiretap/erf_record.h>
43 void proto_register_eth(void);
44 void proto_reg_handoff_eth(void);
46 #define PADDING_NONE 0
47 #define PADDING_ZEROS 1
48 #define PADDING_ANY 2
50 static int eth_padding = PADDING_ZEROS;
51 static unsigned eth_trailer_length;
52 /* By default, try to autodetect FCS */
53 static int eth_fcs = -1;
54 static bool eth_check_fcs;
55 /* Interpret packets as FW1 monitor file packets if they look as if they are */
56 static bool eth_interpret_as_fw1_monitor;
57 /* When capturing on a Cisco FEX some frames start with an extra destination mac */
58 static bool eth_deduplicate_dmac;
59 /* Preference settings defining conditions for which the CCSDS dissector is called */
60 static bool ccsds_heuristic_length;
61 static bool ccsds_heuristic_version;
62 static bool ccsds_heuristic_header;
63 static bool ccsds_heuristic_bit;
65 /* protocols and header fields */
66 static int proto_eth;
67 static int hf_eth_dst;
68 static int hf_eth_dst_resolved;
69 static int hf_eth_dst_oui;
70 static int hf_eth_dst_oui_resolved;
71 static int hf_eth_src;
72 static int hf_eth_src_resolved;
73 static int hf_eth_src_oui;
74 static int hf_eth_src_oui_resolved;
75 static int hf_eth_len;
76 static int hf_eth_type;
77 static int hf_eth_invalid_lentype;
78 static int hf_eth_addr;
79 static int hf_eth_addr_resolved;
80 static int hf_eth_addr_oui;
81 static int hf_eth_addr_oui_resolved;
82 static int hf_eth_dst_lg;
83 static int hf_eth_dst_ig;
84 static int hf_eth_src_lg;
85 static int hf_eth_src_ig;
86 static int hf_eth_lg;
87 static int hf_eth_ig;
88 static int hf_eth_padding;
89 static int hf_eth_trailer;
90 static int hf_eth_fcs;
91 static int hf_eth_fcs_status;
92 static int hf_eth_stream;
94 static int ett_ieee8023;
95 static int ett_ether2;
96 static int ett_ether;
97 static int ett_addr;
99 static expert_field ei_eth_invalid_lentype;
100 static expert_field ei_eth_src_not_group;
101 static expert_field ei_eth_fcs_bad;
102 static expert_field ei_eth_len;
103 static expert_field ei_eth_padding_bad;
105 static dissector_handle_t fw1_handle;
106 static dissector_handle_t ethertype_handle;
107 static capture_dissector_handle_t isl_cap_handle;
108 static capture_dissector_handle_t ipx_cap_handle;
109 static capture_dissector_handle_t llc_cap_handle;
110 static heur_dissector_list_t heur_subdissector_list;
111 static heur_dissector_list_t eth_trailer_subdissector_list;
112 static dissector_handle_t eth_withoutfcs_handle;
113 static dissector_handle_t eth_maybefcs_handle;
116 static int eth_tap;
117 static uint32_t eth_stream_count;
119 static int exported_pdu_tap = -1;
121 #define ETH_HEADER_SIZE 14
123 static const true_false_string ig_tfs = {
124 "Group address (multicast/broadcast)",
125 "Individual address (unicast)"
127 static const true_false_string lg_tfs = {
128 "Locally administered address (this is NOT the factory default)",
129 "Globally unique address (factory default)"
132 static const enum_val_t eth_padding_vals[] = {
133 {"never", "Never", PADDING_NONE},
134 {"zeros", "Zeros", PADDING_ZEROS},
135 {"any", "Any", PADDING_ANY},
136 {NULL, NULL, 0}
139 static const enum_val_t eth_fcs_vals[] = {
140 {"heuristic", "According to heuristic", -1},
141 {"never", "Never", 0},
142 {"always", "Always", 4},
143 {NULL, NULL, 0}
146 static const char* eth_conv_get_filter_type(conv_item_t* conv, conv_filter_type_e filter)
148 if ((filter == CONV_FT_SRC_ADDRESS) && (conv->src_address.type == AT_ETHER))
149 return "eth.src";
151 if ((filter == CONV_FT_DST_ADDRESS) && (conv->dst_address.type == AT_ETHER))
152 return "eth.dst";
154 if ((filter == CONV_FT_ANY_ADDRESS) && (conv->src_address.type == AT_ETHER))
155 return "eth.addr";
157 return CONV_FILTER_INVALID;
160 static ct_dissector_info_t eth_ct_dissector_info = {&eth_conv_get_filter_type};
162 static tap_packet_status
163 eth_conversation_packet(void *pct, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip, tap_flags_t flags)
165 conv_hash_t *hash = (conv_hash_t*) pct;
166 hash->flags = flags;
167 const eth_hdr *ehdr=(const eth_hdr *)vip;
169 add_conversation_table_data_with_conv_id(hash, &ehdr->src, &ehdr->dst, 0, 0, (conv_id_t)ehdr->stream, 1, pinfo->fd->pkt_len,
170 &pinfo->rel_ts, &pinfo->abs_ts, &eth_ct_dissector_info, CONVERSATION_ETH);
172 return TAP_PACKET_REDRAW;
175 static const char* eth_endpoint_get_filter_type(endpoint_item_t* endpoint, conv_filter_type_e filter)
177 if ((filter == CONV_FT_ANY_ADDRESS) && (endpoint->myaddress.type == AT_ETHER))
178 return "eth.addr";
180 return CONV_FILTER_INVALID;
183 static et_dissector_info_t eth_endpoint_dissector_info = {&eth_endpoint_get_filter_type};
185 static tap_packet_status
186 eth_endpoint_packet(void *pit, packet_info *pinfo, epan_dissect_t *edt _U_, const void *vip, tap_flags_t flags)
188 conv_hash_t *hash = (conv_hash_t*) pit;
189 hash->flags = flags;
190 const eth_hdr *ehdr=(const eth_hdr *)vip;
192 /* Take two "add" passes per packet, adding for each direction, ensures that all
193 packets are counted properly (even if address is sending to itself)
194 XXX - this could probably be done more efficiently inside endpoint_table */
195 add_endpoint_table_data(hash, &ehdr->src, 0, true, 1, pinfo->fd->pkt_len, &eth_endpoint_dissector_info, ENDPOINT_NONE);
196 add_endpoint_table_data(hash, &ehdr->dst, 0, false, 1, pinfo->fd->pkt_len, &eth_endpoint_dissector_info, ENDPOINT_NONE);
198 return TAP_PACKET_REDRAW;
201 static bool
202 eth_filter_valid(packet_info *pinfo, void *user_data _U_)
204 return (pinfo->dl_src.type == AT_ETHER);
207 static char*
208 eth_build_filter(packet_info *pinfo, void *user_data _U_)
210 return ws_strdup_printf("eth.addr eq %s and eth.addr eq %s",
211 address_to_str(pinfo->pool, &pinfo->dl_src),
212 address_to_str(pinfo->pool, &pinfo->dl_dst));
216 /* These are the Netware-ish names for the different Ethernet frame types.
217 EthernetII: The ethernet with a Type field instead of a length field
218 Ethernet802.2: An 802.3 header followed by an 802.2 header
219 Ethernet802.3: A raw 802.3 packet. IPX/SPX can be the only payload.
220 There's no 802.2 hdr in this.
221 EthernetSNAP: Basically 802.2, just with 802.2SNAP. For our purposes,
222 there's no difference between 802.2 and 802.2SNAP, since we just
223 pass it down to the LLC dissector. -- Gilbert
225 #define ETHERNET_II 0
226 #define ETHERNET_802_2 1
227 #define ETHERNET_802_3 2
228 #define ETHERNET_SNAP 3
230 static bool
231 capture_eth(const unsigned char *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
233 uint16_t etype, length;
234 int ethhdr_type; /* the type of ethernet frame */
236 if (!BYTES_ARE_IN_FRAME(offset, len, ETH_HEADER_SIZE))
237 return false;
239 etype = pntoh16(&pd[offset+12]);
241 if (etype <= IEEE_802_3_MAX_LEN) {
242 /* Oh, yuck. Cisco ISL frames require special interpretation of the
243 destination address field; fortunately, they can be recognized by
244 checking the first 5 octets of the destination address, which are
245 01-00-0C-00-00 or 0C-00-0C-00-00 for ISL frames. */
246 if ((pd[offset] == 0x01 || pd[offset] == 0x0C) && pd[offset+1] == 0x00
247 && pd[offset+2] == 0x0C && pd[offset+3] == 0x00
248 && pd[offset+4] == 0x00) {
249 return call_capture_dissector(isl_cap_handle, pd, offset, len, cpinfo, pseudo_header);
254 * If the type/length field is <= the maximum 802.3 length,
255 * and is not zero, this is an 802.3 frame, and it's a length
256 * field; it might be an Novell "raw 802.3" frame, with no
257 * 802.2 LLC header, or it might be a frame with an 802.2 LLC
258 * header.
260 * If the type/length field is >= the minimum Ethernet II length,
261 * this is an Ethernet II frame, and it's a type field.
263 * If the type/length field is > maximum 802.3 length and < minimum
264 * Ethernet II length, then this is an invalid packet.
266 * If the type/length field is zero (ETHERTYPE_UNK), this is
267 * a frame used internally by the Cisco MDS switch to contain
268 * Fibre Channel ("Vegas"). We treat that as an Ethernet II
269 * frame; the dissector for those frames registers itself with
270 * an ethernet type of ETHERTYPE_UNK.
272 if (etype > IEEE_802_3_MAX_LEN && etype < ETHERNET_II_MIN_LEN)
273 return false;
275 if (etype <= IEEE_802_3_MAX_LEN && etype != ETHERTYPE_UNK) {
276 length = etype;
278 /* Is there an 802.2 layer? I can tell by looking at the first 2
279 bytes after the 802.3 header. If they are 0xffff, then what
280 follows the 802.3 header is an IPX payload, meaning no 802.2.
281 (IPX/SPX is they only thing that can be contained inside a
282 straight 802.3 packet). A non-0xffff value means that there's an
283 802.2 layer inside the 802.3 layer */
284 if (pd[offset+14] == 0xff && pd[offset+15] == 0xff) {
285 ethhdr_type = ETHERNET_802_3;
287 else {
288 ethhdr_type = ETHERNET_802_2;
291 /* Convert the LLC length from the 802.3 header to a total
292 frame length, by adding in the size of any data that preceded
293 the Ethernet header, and adding in the Ethernet header size,
294 and set the payload and captured-payload lengths to the minima
295 of the total length and the frame lengths. */
296 length += offset + ETH_HEADER_SIZE;
297 if (len > length)
298 len = length;
299 } else {
300 ethhdr_type = ETHERNET_II;
302 offset += ETH_HEADER_SIZE;
304 switch (ethhdr_type) {
305 case ETHERNET_802_3:
306 return call_capture_dissector(ipx_cap_handle, pd, offset, len, cpinfo, pseudo_header);
307 case ETHERNET_802_2:
308 return call_capture_dissector(llc_cap_handle, pd, offset, len, cpinfo, pseudo_header);
309 case ETHERNET_II:
310 return try_capture_dissector("ethertype", etype, pd, offset, len, cpinfo, pseudo_header);
313 return false;
316 static bool check_is_802_2(tvbuff_t *tvb, int fcs_len);
318 static void
319 dissect_address_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, bool check_group)
321 static const mac_hf_list_t eth_dst = {
322 &hf_eth_dst,
323 &hf_eth_dst_resolved,
324 &hf_eth_dst_oui,
325 &hf_eth_dst_oui_resolved,
326 &hf_eth_dst_lg,
327 &hf_eth_dst_ig,
329 static const mac_hf_list_t eth_src = {
330 &hf_eth_src,
331 &hf_eth_src_resolved,
332 &hf_eth_src_oui,
333 &hf_eth_src_oui_resolved,
334 &hf_eth_src_lg,
335 &hf_eth_src_ig,
337 static const mac_hf_list_t eth_addr = {
338 &hf_eth_addr,
339 &hf_eth_addr_resolved,
340 &hf_eth_addr_oui,
341 &hf_eth_addr_oui_resolved,
342 &hf_eth_lg,
343 &hf_eth_ig,
345 proto_item *addr_item;
347 proto_tree_add_mac48_detail(&eth_dst, &eth_addr, ett_addr, tvb, tree, 0);
349 addr_item = proto_tree_add_mac48_detail(&eth_src, &eth_addr, ett_addr, tvb, tree, 6);
350 if (check_group) {
351 if (tvb_get_uint8(tvb, 6) & 0x01) {
352 expert_add_info(pinfo, addr_item, &ei_eth_src_not_group);
357 static void
358 export_pdu(tvbuff_t *tvb, packet_info *pinfo)
360 if (have_tap_listener(exported_pdu_tap)) {
361 exp_pdu_data_t *exp_pdu_data = wmem_new0(pinfo->pool, exp_pdu_data_t);
363 exp_pdu_data->tvb_captured_length = tvb_captured_length(tvb);
364 exp_pdu_data->tvb_reported_length = tvb_reported_length(tvb);
365 exp_pdu_data->pdu_tvb = tvb;
366 tap_queue_packet(exported_pdu_tap, pinfo, exp_pdu_data);
370 static struct eth_analysis *
371 init_eth_conversation_data(packet_info *pinfo)
373 struct eth_analysis *ethd;
375 /* Initialize the eth protocol data structure to add to the ip conversation */
376 ethd=wmem_new0(wmem_file_scope(), struct eth_analysis);
378 ethd->initial_frame = pinfo->num;
379 ethd->stream = 0;
380 ethd->stream = eth_stream_count++;
382 return ethd;
385 struct eth_analysis *
386 get_eth_conversation_data(conversation_t *conv, packet_info *pinfo)
388 struct eth_analysis *ethd;
390 /* Did the caller supply the conversation pointer? */
391 if( conv==NULL ) {
392 return NULL;
395 /* Get the data for this conversation */
396 ethd=(struct eth_analysis *)conversation_get_proto_data(conv, proto_eth);
398 if (!ethd) {
399 ethd = init_eth_conversation_data(pinfo);
400 conversation_add_proto_data(conv, proto_eth, ethd);
403 if (!ethd) {
404 return NULL;
407 return ethd;
410 static proto_tree *
411 dissect_eth_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree,
412 int fcs_len)
414 proto_item *ti = NULL;
415 eth_hdr *ehdr;
416 bool is_802_2;
417 proto_tree *fh_tree = NULL;
418 static eth_hdr ehdrs[4];
419 static int ehdr_num=0;
420 proto_tree *tree;
421 ethertype_data_t ethertype_data;
422 heur_dtbl_entry_t *hdtbl_entry = NULL;
423 struct eth_analysis *ethd=NULL;
424 /* a facility for not duplicating long code */
425 bool needs_dissector_with_data = false;
427 /* Rotating buffer */
428 ehdr_num++;
429 if(ehdr_num>=4){
430 ehdr_num=0;
432 ehdr=&ehdrs[ehdr_num];
434 tree=parent_tree;
436 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Ethernet");
438 set_address_tvb(&pinfo->dl_dst, AT_ETHER, 6, tvb, 0);
439 copy_address_shallow(&pinfo->dst, &pinfo->dl_dst);
440 copy_address_shallow(&ehdr->dst, &pinfo->dl_dst);
442 set_address_tvb(&pinfo->dl_src, AT_ETHER, 6, tvb, 6);
443 copy_address_shallow(&pinfo->src, &pinfo->dl_src);
444 copy_address_shallow(&ehdr->src, &pinfo->dl_src);
446 ehdr->type = tvb_get_ntohs(tvb, 12);
448 tap_queue_packet(eth_tap, pinfo, ehdr);
449 export_pdu(tvb, pinfo);
452 * In case the packet is a non-Ethernet packet inside
453 * Ethernet framing, allow heuristic dissectors to take
454 * a first look before we assume that it's actually an
455 * Ethernet packet.
457 * Tell the heuristic dissectors what FCS length was reported for
458 * this packet - the non-Ethernet packet might or might not include
459 * the FCS, or might have a different calculation. (Heuristic
460 * dissectors also can't report a number of bytes consumed, so we
461 * can't really handle the "maybefcs" case otherwise.)
463 struct eth_phdr phdr;
464 phdr.fcs_len = fcs_len;
465 if (dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, parent_tree, &hdtbl_entry, &phdr))
466 return fh_tree;
468 if (ehdr->type <= IEEE_802_3_MAX_LEN) {
469 /* Oh, yuck. Cisco ISL frames require special interpretation of the
470 destination address field; fortunately, they can be recognized by
471 checking the first 5 octets of the destination address, which are
472 01-00-0C-00-00 for ISL frames. */
473 if ((tvb_get_uint8(tvb, 0) == 0x01 ||
474 tvb_get_uint8(tvb, 0) == 0x0C) &&
475 tvb_get_uint8(tvb, 1) == 0x00 &&
476 tvb_get_uint8(tvb, 2) == 0x0C &&
477 tvb_get_uint8(tvb, 3) == 0x00 &&
478 tvb_get_uint8(tvb, 4) == 0x00) {
479 dissect_isl(tvb, pinfo, parent_tree, fcs_len);
480 return fh_tree;
485 * If the type/length field is <= the maximum 802.3 length,
486 * and is not zero, this is an 802.3 frame, and it's a length
487 * field; it might be an Novell "raw 802.3" frame, with no
488 * 802.2 LLC header, or it might be a frame with an 802.2 LLC
489 * header.
491 * If the type/length field is >= the minimum Ethernet II length,
492 * this is an Ethernet II frame, and it's a type field.
494 * If the type/length field is > maximum 802.3 length and < minimum
495 * Ethernet II length, then this is an invalid packet.
497 * If the type/length field is zero (ETHERTYPE_UNK), this is
498 * a frame used internally by the Cisco MDS switch to contain
499 * Fibre Channel ("Vegas"). We treat that as an Ethernet II
500 * frame; the dissector for those frames registers itself with
501 * an ethernet type of ETHERTYPE_UNK.
503 if (ehdr->type > IEEE_802_3_MAX_LEN && ehdr->type < ETHERNET_II_MIN_LEN) {
504 tvbuff_t *next_tvb;
506 col_add_fstr(pinfo->cinfo, COL_INFO,
507 "Ethernet Unknown: Invalid length/type: 0x%04x (%d)",
508 ehdr->type, ehdr->type);
509 ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
510 "Ethernet Unknown, Src: %s, Dst: %s",
511 address_with_resolution_to_str(pinfo->pool, &pinfo->src),
512 address_with_resolution_to_str(pinfo->pool, &pinfo->dst));
513 fh_tree = proto_item_add_subtree(ti, ett_ether);
515 dissect_address_data(tvb, pinfo, fh_tree, false);
517 ti = proto_tree_add_item(fh_tree, hf_eth_invalid_lentype, tvb, 12, 2, ENC_BIG_ENDIAN);
518 expert_add_info_format(pinfo, ti, &ei_eth_invalid_lentype,
519 "Invalid length/type: 0x%04x (%d)", ehdr->type, ehdr->type);
520 next_tvb = tvb_new_subset_remaining(tvb, 14);
521 call_data_dissector(next_tvb, pinfo, parent_tree);
522 return fh_tree;
525 if (ehdr->type <= IEEE_802_3_MAX_LEN && ehdr->type != ETHERTYPE_UNK) {
527 is_802_2 = check_is_802_2(tvb, fcs_len);
529 col_add_fstr(pinfo->cinfo, COL_INFO, "IEEE 802.3 Ethernet %s",
530 (is_802_2 ? "" : "Raw "));
531 if (tree) {
532 ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
533 "IEEE 802.3 Ethernet %s", (is_802_2 ? "" : "Raw "));
535 fh_tree = proto_item_add_subtree(ti, ett_ieee8023);
538 /* if IP is not referenced from any filters we don't need to worry about
539 generating any tree items. We must do this after we created the actual
540 protocol above so that proto hier stat still works though.
542 if(!proto_field_is_referenced(parent_tree, proto_eth)){
543 tree=NULL;
544 fh_tree=NULL;
547 dissect_address_data(tvb, pinfo, fh_tree, false);
549 dissect_802_3(ehdr->type, is_802_2, tvb, ETH_HEADER_SIZE, pinfo,
550 parent_tree, fh_tree, hf_eth_len, hf_eth_trailer, &ei_eth_len, fcs_len);
551 } else {
552 if (eth_interpret_as_fw1_monitor) {
553 const uint8_t *dst_addr = (const uint8_t*)pinfo->dst.data;
555 if ((dst_addr[0] == 'i') || (dst_addr[0] == 'I') ||
556 (dst_addr[0] == 'o') || (dst_addr[0] == 'O') ||
557 (dst_addr[0] == 'e') || (dst_addr[0] == 'E')) {
558 call_dissector(fw1_handle, tvb, pinfo, parent_tree);
559 return fh_tree;
563 col_set_str(pinfo->cinfo, COL_INFO, "Ethernet II");
564 if (parent_tree) {
565 if (PTREE_DATA(parent_tree)->visible) {
566 ti = proto_tree_add_protocol_format(parent_tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
567 "Ethernet II, Src: %s, Dst: %s",
568 address_with_resolution_to_str(pinfo->pool, &pinfo->src),
569 address_with_resolution_to_str(pinfo->pool, &pinfo->dst));
571 else {
572 ti = proto_tree_add_item(parent_tree, proto_eth, tvb, 0, ETH_HEADER_SIZE, ENC_NA);
574 fh_tree = proto_item_add_subtree(ti, ett_ether2);
577 dissect_address_data(tvb, pinfo, fh_tree, true);
579 proto_tree_add_uint(fh_tree, hf_eth_type, tvb, 12, 2, ehdr->type);
581 ethertype_data.etype = ehdr->type;
582 ethertype_data.payload_offset = ETH_HEADER_SIZE;
583 ethertype_data.fh_tree = fh_tree;
584 ethertype_data.trailer_id = hf_eth_trailer;
585 ethertype_data.fcs_len = fcs_len;
587 needs_dissector_with_data = true;
590 /* if we still did not leave the dissection, try identifying any ETH conversation
591 * When deinterlacing was asked and an interface is known, create an _IN conv,
592 * otherwise create an ordinary _NN one.
596 unsigned conv_type = CONVERSATION_ETH_NN;
597 /* deinterlacing is requested */
598 if(prefs.conversation_deinterlacing_key>0) {
599 uint32_t dtlc_iface = 0;
601 if(prefs.conversation_deinterlacing_key&CONV_DEINT_KEY_INTERFACE &&
602 pinfo->rec->presence_flags & WTAP_HAS_INTERFACE_ID) {
604 conv_type = CONVERSATION_ETH_IN;
605 dtlc_iface = pinfo->rec->rec_header.packet_header.interface_id;
607 else {
608 conv_type = CONVERSATION_ETH_NN;
611 // identify an existing conversation or create a new one
612 conversation_t *conv_deint = find_conversation_deinterlacer(pinfo->num, &pinfo->src, &pinfo->dst, conv_type,
613 dtlc_iface, 0, 0);
614 if(!conv_deint) {
615 conversation_new_deinterlacer(pinfo->num, &pinfo->src, &pinfo->dst,
616 conv_type, dtlc_iface, 0, 0);
620 conversation_t *conv = find_conversation(pinfo->num, &pinfo->src, &pinfo->dst, conv_type, 0, 0, NO_PORT_X);
622 if(!conv) {
623 conv = conversation_new(pinfo->num, &pinfo->src, &pinfo->dst, conv_type, 0, 0, NO_PORTS);
625 else {
627 * while not strictly necessary because there is only 1
628 * conversation between 2 IPs, we still move the last frame
629 * indicator as being a usual practice.
631 if (!(pinfo->fd->visited)) {
632 if (pinfo->num > conv->last_frame) {
633 conv->last_frame = pinfo->num;
638 ethd = get_eth_conversation_data(conv, pinfo);
639 if(ethd) {
640 ehdr->stream = ethd->stream;
641 if(tree) {
642 ti = proto_tree_add_uint(fh_tree, hf_eth_stream, tvb, 0, 0, ethd->stream);
643 proto_item_set_generated(ti);
647 if(needs_dissector_with_data) {
648 call_dissector_with_data(ethertype_handle, tvb, pinfo, parent_tree, &ethertype_data);
651 return fh_tree;
654 static void
655 eth_init(void)
657 eth_stream_count = 0;
660 /* -------------- */
661 static bool check_is_802_2(tvbuff_t *tvb, int fcs_len)
663 volatile bool is_802_2;
664 volatile int length;
665 int captured_length, reported_length;
667 is_802_2 = true;
669 /* Is there an 802.2 layer? I can tell by looking at the first 2
670 bytes after the 802.3 header. If they are 0xffff, then what
671 follows the 802.3 header is an IPX payload, meaning no 802.2.
672 A non-0xffff value means that there's an 802.2 layer or CCSDS
673 layer inside the 802.3 layer */
675 TRY {
676 if (tvb_get_ntohs(tvb, 14) == 0xffff) {
677 is_802_2 = false;
679 /* Is this a CCSDS payload instead of an 802.2 (LLC)?
680 Check the conditions enabled by the user for CCSDS presence */
681 else if (ccsds_heuristic_length || ccsds_heuristic_version ||
682 ccsds_heuristic_header || ccsds_heuristic_bit) {
683 bool CCSDS_len = true;
684 bool CCSDS_ver = true;
685 bool CCSDS_head = true;
686 bool CCSDS_bit = true;
687 /* See if the reported payload size matches the
688 size contained in the CCSDS header. */
689 if (ccsds_heuristic_length) {
690 /* The following technique to account for FCS
691 is copied from packet-ieee8023.c dissect_802_3() */
692 length = tvb_get_ntohs(tvb, 12);
693 reported_length = tvb_reported_length_remaining(tvb, ETH_HEADER_SIZE);
694 if (fcs_len > 0) {
695 if (reported_length >= fcs_len)
696 reported_length -= fcs_len;
698 /* Make sure the length in the 802.3 header doesn't go past the end of
699 the payload. */
700 if (length > reported_length) {
701 length = reported_length;
703 /* Only allow inspection of 'length' number of bytes. */
704 captured_length = tvb_captured_length_remaining(tvb, ETH_HEADER_SIZE);
705 if (captured_length > length)
706 captured_length = length;
708 /* Check if payload is large enough to contain a CCSDS header */
709 if (captured_length >= 6) {
710 /* Compare length to packet length contained in CCSDS header. */
711 if (length != 7 + tvb_get_ntohs(tvb, ETH_HEADER_SIZE + 4))
712 CCSDS_len = false;
715 /* Check if CCSDS Version number (first 3 bits of payload) is zero */
716 if ((ccsds_heuristic_version) && (tvb_get_bits8(tvb, 8*ETH_HEADER_SIZE, 3)!=0))
717 CCSDS_ver = false;
718 /* Check if Secondary Header Flag (4th bit of payload) is set to one. */
719 if ((ccsds_heuristic_header) && (tvb_get_bits8(tvb, 8*ETH_HEADER_SIZE + 4, 1)!=1))
720 CCSDS_head = false;
721 /* Check if spare bit (1st bit of 7th word of payload) is zero. */
722 if ((ccsds_heuristic_bit) && (tvb_get_bits8(tvb, 8*ETH_HEADER_SIZE + 16*6, 1)!=0))
723 CCSDS_bit = false;
724 /* If all the conditions are true, don't interpret payload as an 802.2 (LLC).
725 * Additional check in packet-802.3.c will distinguish between
726 * IPX and CCSDS packets*/
727 if (CCSDS_len && CCSDS_ver && CCSDS_head && CCSDS_bit)
728 is_802_2 = false;
731 CATCH_BOUNDS_ERRORS {
732 ; /* do nothing */
735 ENDTRY;
736 return is_802_2;
740 * Add an Ethernet trailer - which, for some captures, might be the FCS
741 * rather than a pad-to-60-bytes trailer.
743 * If fcs_len is 0, we assume the frame has no FCS; if it's 4, we assume
744 * it has an FCS; if it's anything else (such as -1, which means "maybe
745 * it does, maybe it doesn't"), we try to infer whether it has an FCS.
747 void
748 add_ethernet_trailer(packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
749 int trailer_id, tvbuff_t *tvb, tvbuff_t *trailer_tvb, int fcs_len,
750 int payload_offset)
752 /* If there're some bytes left over, it could be a combination of:
753 - padding to meet the minimum 64 byte frame length
754 - an FCS, if present (if fcs_len is 0, we know it's not present;
755 if fcs_len is 4, we know it's present; if fcs_len is -1, we
756 need some heuristics to determine whether it's present)
757 - information inserted by TAPs or other network monitoring equipment.
759 If we don't know whether the FCS is present, then, if we don't have a
760 network monitoring trailer, and if the Ethernet frame was claimed to
761 have had 64 or more bytes - i.e., it was at least an FCS worth of data
762 longer than the minimum payload size - we could assume the last 4 bytes
763 of the trailer are an FCS. */
764 heur_dtbl_entry_t *hdtbl_entry;
766 if (trailer_tvb) {
767 unsigned trailer_length, trailer_reported_length;
768 unsigned padding_length = 0;
769 bool has_fcs = false;
770 bool maybe_padded = false;
771 tvbuff_t *real_trailer_tvb;
773 trailer_length = tvb_captured_length(trailer_tvb);
774 trailer_reported_length = tvb_reported_length(trailer_tvb);
776 /* Theoretically padding is added if the frame length without the FCS is
777 * less than 60 bytes, starting from the addresses. In practice, frames
778 * are often padded so that the length is 60 bytes not counting any tags
779 * before the final Ethertype. (I.e., padding so that the payload portion
780 * is 46.)
782 * Padding might be added to a frame at one point in a network, and then a
783 * tag or trailer added later without removing the padding. Conversely, a
784 * frame might have padding and a tag and trailer, and then the tag removed,
785 * dropping the frame below 60 octets, leading to more padding at the end,
786 * after the trailer. https://gitlab.com/wireshark/wireshark/-/wikis/PRP
787 * has useful illustrations of both situations. The heuristic trailer
788 * dissectors can try to deal with both situations (though looping through
789 * the trailer bytes increases false positives.)
791 * By increasing the minimum frame size (padding payload to 46) the former
792 * situation always occurs, and trailers appear at the end. IEEE Std
793 * 802.1Q-2014 G.2.1 "Treatment of PAD fields in IEEE 802.3 frames"
794 * and G.2.3 "Minimum PDU size" specifically state it is permissible for a
795 * Bridge to to adopt a minimum tagged frame length of 68 bytes (64 without
796 * FCS) when 802.1Q is used. Other specs don't directly address this, but
797 * we often see padding on frames that are more than 60 octets without FCS.
799 int frame_len;
800 if (eth_padding == PADDING_ANY) {
801 /* This is a size at which there definitely should be padding,
802 * which we use with PADDING_ANY to be conservative so we don't
803 * mark any possible trailer as padding. Fo certain cases (tags,
804 * trailers, especially encapsulation like ISL, GSE Bridged Frames)
805 * some padding will be classified as trailer.
807 frame_len = pinfo->fd->pkt_len;
808 } else {
809 /* This is the size up to which there might be padding, if padding
810 * was added before adding tags after the first ethertype.
811 * Use this if we're testing PADDING_ZERO, which is strict.
812 * Consecutive zeroes up to this point will be padding,
813 * anything starting with the first non-zero will be trailer.
815 frame_len = tvb_reported_length(tvb) + (14 - payload_offset);
817 maybe_padded = (frame_len >= 60 && (frame_len - trailer_reported_length) < 60);
819 if (eth_padding != PADDING_NONE && maybe_padded) {
820 /* XXX: There could be another 4 bytes of padding if a Bridge extends
821 * the minimum frame size of 68 on untagged fraomes, see discussion
822 * above of IEEE 802.1Q Annex G. If we require padding to be zeros,
823 * we could possibly use 64 instead of 60. (Too many false positives
824 * with PADDING_ANY.)
826 padding_length = 60 - (frame_len - trailer_reported_length);
827 /* Require padding to be zeros */
828 if (eth_padding == PADDING_ZEROS) {
829 for (unsigned i = 0; i < padding_length; i++) {
830 if (tvb_get_int8(trailer_tvb, i) != 0) {
831 padding_length = i;
832 break;
836 /* If it was determined that we have padding, add it to the tree. */
837 if (padding_length > 0) {
838 tvb_ensure_bytes_exist(tvb, 0, padding_length);
839 proto_tree_add_item(fh_tree, hf_eth_padding, trailer_tvb, 0,
840 padding_length, ENC_NA);
841 trailer_length -= padding_length;
842 trailer_reported_length -= padding_length;
846 int payload_length = tvb_reported_length(tvb) - payload_offset;
847 bool dissected = false;
849 if (fcs_len != 4) {
850 /* Try trailer dissection without an FCS */
851 real_trailer_tvb = tvb_new_subset_remaining(trailer_tvb, padding_length);
852 /* Call all ethernet trailer dissectors to dissect the trailer if
853 we actually have a trailer. The PRP trailer dissector wants
854 to know about the payload (LSDU) length. */
855 if (tvb_reported_length(real_trailer_tvb) != 0) {
856 dissected = dissector_try_heuristic(eth_trailer_subdissector_list,
857 real_trailer_tvb, pinfo, tree,
858 &hdtbl_entry, &payload_length);
862 if (fcs_len != 0) {
863 /* If fcs_len is 4, we assume we definitely have an FCS.
864 If fcs_len is -1, if the frame is big enough that, if we
865 have a trailer, it probably includes an FCS, and we have
866 enough space in the trailer for the FCS, and we didn't
867 have a heuristic trailer dissector successfully dissect
868 without an FCS, we assume we have an FCS.
870 "Big enough" means 64 bytes or more; any frame that big
871 needs no trailer, as there's no need to pad an Ethernet
872 packet past 60 bytes.
874 XXX: This is not quite true. See IEEE Std 802.1Q-2014
875 G.2.1 "Treatment of PAD fields in IEEE 802.3 frames" and
876 G.2.3 "Minimum PDU size" and the discussion above.
878 The trailer must be at least 4 bytes long to have enough
879 space for an FCS. */
881 if (fcs_len == 4 || (fcs_len == -1 && !dissected &&
882 frame_len >= 64 && trailer_reported_length >= 4)) {
883 /* Either we know we have an FCS, or we believe we have an FCS. */
884 if (trailer_length < trailer_reported_length) {
885 /* The packet is claimed to have enough data for a 4-byte FCS,
886 but we didn't capture all of the packet.
887 Slice off the 4-byte FCS from the reported length, and
888 trim the captured length so it's no more than the reported
889 length; that will slice off what of the FCS, if any, is
890 in the captured packet. */
891 trailer_reported_length -= 4;
892 if (trailer_length > trailer_reported_length) {
893 payload_length -= (trailer_length - trailer_reported_length);
894 trailer_length = trailer_reported_length;
896 has_fcs = true;
897 } else {
898 /* We captured all of the packet, including what appears to
899 be a 4-byte FCS. Slice it off. */
900 trailer_length -= 4;
901 trailer_reported_length -= 4;
902 payload_length -= 4;
903 has_fcs = true;
906 real_trailer_tvb = tvb_new_subset_length_caplen(trailer_tvb, padding_length,
907 trailer_length, trailer_reported_length);
909 /* Call all ethernet trailer dissectors to dissect the trailer if
910 we actually have a trailer. */
911 if (tvb_reported_length(real_trailer_tvb) != 0) {
912 dissected = dissector_try_heuristic(eth_trailer_subdissector_list,
913 real_trailer_tvb, pinfo, tree,
914 &hdtbl_entry, &payload_length);
919 if (!dissected) {
920 /* No luck with the trailer dissectors, so just display the
921 extra bytes as general trailer */
922 if (trailer_length != 0) {
923 tvb_ensure_bytes_exist(real_trailer_tvb, 0, trailer_length);
924 proto_item *pi = proto_tree_add_item(fh_tree, trailer_id, real_trailer_tvb, 0,
925 trailer_length, ENC_NA);
926 if (maybe_padded) {
927 if (eth_padding == PADDING_ANY && padding_length > 0) {
928 expert_add_info_format(pinfo, pi, &ei_eth_padding_bad,
929 "Padding was assumed, and an undecoded trailer exists. Some of the trailer may have been consumed by padding.");
931 else if (eth_padding == PADDING_ZEROS && padding_length == 0) {
932 expert_add_info_format(pinfo, pi, &ei_eth_padding_bad,
933 "Didn't find padding of zeros, and an undecoded trailer exists. There may be padding of non-zeros.");
939 if (has_fcs) {
940 uint32_t sent_fcs = tvb_get_ntohl(trailer_tvb, padding_length+trailer_length);
941 /* If we don't have the entire header, we can't actually check the FCS.
942 * Dissectors that don't have the entire header (say, a tag) probably
943 * should have set fcs_len to zero in the ethertype_data struct.
944 * XXX: Maybe add an expert info saying why we aren't checking the FCS? */
945 if (eth_check_fcs && payload_offset == ETH_HEADER_SIZE) {
946 uint32_t fcs = crc32_802_tvb(tvb, tvb_captured_length(tvb) - 4);
947 proto_tree_add_checksum(fh_tree, trailer_tvb, padding_length+trailer_length, hf_eth_fcs, hf_eth_fcs_status, &ei_eth_fcs_bad, pinfo, fcs, ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY);
949 if (fcs != sent_fcs) {
950 col_append_str(pinfo->cinfo, COL_INFO, " [ETHERNET FRAME CHECK SEQUENCE INCORRECT]");
952 }else{
953 proto_tree_add_checksum(fh_tree, trailer_tvb, padding_length+trailer_length, hf_eth_fcs, hf_eth_fcs_status, &ei_eth_fcs_bad, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
955 trailer_length += 4;
957 proto_tree_set_appendix(fh_tree, tvb, tvb_captured_length(tvb) - padding_length - trailer_length, padding_length + trailer_length);
961 /* Called for the Ethernet Wiretap encapsulation type; pass the FCS length
962 reported to us, if known, otherwise falling back to the "fcs" preference. */
963 static int
964 dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
966 struct eth_phdr *eth = (struct eth_phdr *)data;
967 proto_tree *fh_tree;
968 tvbuff_t *real_tvb;
969 int fcs_len;
971 if (eth && eth->fcs_len != -1) {
972 /* Use the value reported from Wiretap, if known. */
973 fcs_len = eth->fcs_len;
974 } else {
975 fcs_len = eth_fcs;
978 /* When capturing on a Cisco FEX, some frames (most likely all frames
979 captured without a vntag) have an extra destination mac prepended. */
980 if (eth_deduplicate_dmac && tvb_captured_length(tvb) > 20 &&
981 memcmp(tvb_get_ptr(tvb,0,6),tvb_get_ptr(tvb,6,6), 6) == 0) {
982 real_tvb = tvb_new_subset_length_caplen(tvb, 6,
983 tvb_captured_length(tvb) - 6, tvb_reported_length(tvb) - 6);
984 } else {
985 real_tvb = tvb;
988 /* Some devices slice the packet and add their own trailer before
989 putting the frame on the network. Make sure these packets get
990 a proper trailer (even though the sliced frame might not
991 properly dissect. */
992 if ( (eth_trailer_length > 0) && (eth_trailer_length < tvb_captured_length(real_tvb)) ) {
993 tvbuff_t *next_tvb;
994 unsigned total_trailer_length = eth_trailer_length;
996 /* If we have to guess if the trailer includes the FCS, assume not; the
997 * user probably set the "eth_trailer_length" preference to the total
998 * trailer length. The user has already set the preference, so should
999 * have little difficulty changing it or the "fcs" preference if need be.
1001 total_trailer_length += (fcs_len < 0 ? 0 : (unsigned)fcs_len);
1003 /* Dissect the tvb up to, but not including the trailer */
1004 next_tvb = tvb_new_subset_length_caplen(real_tvb, 0,
1005 tvb_captured_length(real_tvb) - total_trailer_length,
1006 tvb_reported_length(real_tvb) - total_trailer_length);
1007 fh_tree = dissect_eth_common(next_tvb, pinfo, tree, 0);
1009 /* Now handle the ethernet trailer and optional FCS */
1010 next_tvb = tvb_new_subset_remaining(real_tvb, tvb_captured_length(real_tvb) - total_trailer_length);
1011 add_ethernet_trailer(pinfo, tree, fh_tree, hf_eth_trailer, real_tvb, next_tvb,
1012 fcs_len, ETH_HEADER_SIZE);
1013 } else {
1014 dissect_eth_common(real_tvb, pinfo, tree, fcs_len);
1016 return tvb_captured_length(tvb);
1019 /* Called by other dissectors This one's for encapsulated Ethernet
1020 packets that don't include an FCS. */
1021 static int
1022 dissect_eth_withoutfcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1024 dissect_eth_common(tvb, pinfo, tree, 0);
1025 return tvb_captured_length(tvb);
1028 /* ...and this one's for encapsulated packets that do. */
1029 static int
1030 dissect_eth_withfcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1032 dissect_eth_common(tvb, pinfo, tree, 4);
1033 return tvb_captured_length(tvb);
1036 /* ...and this one's for encapsulated packets that might or might not. */
1037 static int
1038 dissect_eth_maybefcs(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
1040 dissect_eth_common(tvb, pinfo, tree, eth_fcs);
1041 return tvb_captured_length(tvb);
1044 void
1045 proto_register_eth(void)
1047 register_init_routine(eth_init);
1049 static hf_register_info hf[] = {
1051 { &hf_eth_dst,
1052 { "Destination", "eth.dst", FT_ETHER, BASE_NONE, NULL, 0x0,
1053 "Destination Hardware Address", HFILL }},
1055 { &hf_eth_dst_resolved,
1056 { "Destination (resolved)", "eth.dst_resolved", FT_STRING, BASE_NONE,
1057 NULL, 0x0, "Destination Hardware Address (resolved)", HFILL }},
1059 { &hf_eth_dst_oui,
1060 { "Destination OUI", "eth.dst.oui", FT_UINT24, BASE_OUI,
1061 NULL, 0x0, "Destination Organizationally Unique Identifier", HFILL } },
1063 { &hf_eth_dst_oui_resolved,
1064 { "Destination OUI (resolved)", "eth.dst.oui_resolved", FT_STRING, BASE_NONE,
1065 NULL, 0x0, "Destination Organizationally Unique Identifier (resolved)", HFILL } },
1067 { &hf_eth_src,
1068 { "Source", "eth.src", FT_ETHER, BASE_NONE, NULL, 0x0,
1069 "Source Hardware Address", HFILL }},
1071 { &hf_eth_src_resolved,
1072 { "Source (resolved)", "eth.src_resolved", FT_STRING, BASE_NONE,
1073 NULL, 0x0, "Source Hardware Address (resolved)", HFILL }},
1076 { &hf_eth_src_oui,
1077 { "Source OUI", "eth.src.oui", FT_UINT24, BASE_OUI,
1078 NULL, 0x0, "Source Organizationally Unique Identifier", HFILL } },
1080 { &hf_eth_src_oui_resolved,
1081 { "Source OUI (resolved)", "eth.src.oui_resolved", FT_STRING, BASE_NONE,
1082 NULL, 0x0, "Source Organizationally Unique Identifier (resolved)", HFILL } },
1084 { &hf_eth_len,
1085 { "Length", "eth.len", FT_UINT16, BASE_DEC, NULL, 0x0,
1086 NULL, HFILL }},
1088 /* registered here but handled in packet-ethertype.c */
1089 { &hf_eth_type,
1090 { "Type", "eth.type", FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0,
1091 NULL, HFILL }},
1093 { &hf_eth_invalid_lentype,
1094 { "Invalid length/type", "eth.invalid_lentype", FT_UINT16, BASE_HEX_DEC,
1095 NULL, 0x0, NULL, HFILL }},
1097 { &hf_eth_addr,
1098 { "Address", "eth.addr", FT_ETHER, BASE_NONE, NULL, 0x0,
1099 "Source or Destination Hardware Address", HFILL }},
1101 { &hf_eth_addr_resolved,
1102 { "Address (resolved)", "eth.addr_resolved", FT_STRING, BASE_NONE,
1103 NULL, 0x0, "Source or Destination Hardware Address (resolved)",
1104 HFILL }},
1106 { &hf_eth_addr_oui,
1107 { "Address OUI", "eth.addr.oui", FT_UINT24, BASE_OUI,
1108 NULL, 0x0, "Address Organizationally Unique Identifier", HFILL } },
1110 { &hf_eth_addr_oui_resolved,
1111 { "Address OUI (resolved)", "eth.addr.oui_resolved", FT_STRING, BASE_NONE,
1112 NULL, 0x0, "Address Organizationally Unique Identifier (resolved)", HFILL } },
1114 { &hf_eth_padding,
1115 { "Padding", "eth.padding", FT_BYTES, BASE_NONE, NULL, 0x0,
1116 "Ethernet Padding", HFILL }},
1118 { &hf_eth_trailer,
1119 { "Trailer", "eth.trailer", FT_BYTES, BASE_NONE, NULL, 0x0,
1120 "Ethernet Trailer or Checksum", HFILL }},
1122 { &hf_eth_fcs,
1123 { "Frame check sequence", "eth.fcs", FT_UINT32, BASE_HEX, NULL, 0x0,
1124 "Ethernet checksum", HFILL }},
1126 { &hf_eth_fcs_status,
1127 { "FCS Status", "eth.fcs.status", FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
1128 NULL, HFILL }},
1130 { &hf_eth_dst_lg,
1131 { "LG bit", "eth.dst.lg", FT_BOOLEAN, 24,
1132 TFS(&lg_tfs), 0x020000,
1133 "Specifies if this is a locally administered or globally unique (IEEE assigned) address", HFILL }},
1135 { &hf_eth_dst_ig,
1136 { "IG bit", "eth.dst.ig", FT_BOOLEAN, 24,
1137 TFS(&ig_tfs), 0x010000,
1138 "Specifies if this is an individual (unicast) or group (broadcast/multicast) address", HFILL }},
1140 { &hf_eth_src_lg,
1141 { "LG bit", "eth.src.lg", FT_BOOLEAN, 24,
1142 TFS(&lg_tfs), 0x020000,
1143 "Specifies if this is a locally administered or globally unique (IEEE assigned) address", HFILL }},
1145 { &hf_eth_src_ig,
1146 { "IG bit", "eth.src.ig", FT_BOOLEAN, 24,
1147 TFS(&ig_tfs), 0x010000,
1148 "Specifies if this is an individual (unicast) or group (broadcast/multicast) address", HFILL }},
1150 { &hf_eth_lg,
1151 { "LG bit", "eth.lg", FT_BOOLEAN, 24,
1152 TFS(&lg_tfs), 0x020000,
1153 "Specifies if this is a locally administered or globally unique (IEEE assigned) address", HFILL }},
1155 { &hf_eth_ig,
1156 { "IG bit", "eth.ig", FT_BOOLEAN, 24,
1157 TFS(&ig_tfs), 0x010000,
1158 "Specifies if this is an individual (unicast) or group (broadcast/multicast) address", HFILL }},
1160 { &hf_eth_stream,
1161 { "Stream index", "eth.stream", FT_UINT32, BASE_DEC, NULL, 0x0,
1162 NULL, HFILL }}
1164 static int *ett[] = {
1165 &ett_ieee8023,
1166 &ett_ether2,
1167 &ett_ether,
1168 &ett_addr,
1171 static ei_register_info ei[] = {
1172 { &ei_eth_invalid_lentype, { "eth.invalid_lentype.expert", PI_PROTOCOL, PI_WARN, "Invalid length/type", EXPFILL }},
1173 { &ei_eth_src_not_group, { "eth.src_not_group", PI_PROTOCOL, PI_WARN, "Source MAC must not be a group address: IEEE 802.3-2002, Section 3.2.3(b)", EXPFILL }},
1174 { &ei_eth_fcs_bad, { "eth.fcs_bad", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
1175 { &ei_eth_len, { "eth.len.past_end", PI_MALFORMED, PI_ERROR, "Length field value goes past the end of the payload", EXPFILL }},
1176 { &ei_eth_padding_bad, {"eth.padding_bad", PI_PROTOCOL, PI_NOTE, "Padding identification may be inaccurate and impact trailer dissector", EXPFILL }},
1179 module_t *eth_module;
1180 expert_module_t* expert_eth;
1182 proto_eth = proto_register_protocol("Ethernet", "Ethernet", "eth");
1183 proto_register_field_array(proto_eth, hf, array_length(hf));
1184 proto_register_subtree_array(ett, array_length(ett));
1185 expert_eth = expert_register_protocol(proto_eth);
1186 expert_register_field_array(expert_eth, ei, array_length(ei));
1188 /* subdissector code */
1189 heur_subdissector_list = register_heur_dissector_list_with_description("eth", "Ethernet framed non-Ethernet data", proto_eth);
1190 eth_trailer_subdissector_list = register_heur_dissector_list_with_description("eth.trailer", "Ethernet trailer", proto_eth);
1192 /* Register configuration preferences */
1193 eth_module = prefs_register_protocol(proto_eth, NULL);
1195 prefs_register_obsolete_preference(eth_module, "assume_padding");
1196 prefs_register_enum_preference(eth_module, "padding",
1197 "Assume padding for short frames with trailer",
1198 "Some devices add trailing data to frames. Depending on where this "
1199 "device exists in the network, padding could be added to short "
1200 "frames before the additional trailer. This option determines how "
1201 "that padding will be detected.\n\n"
1202 "Never - Don't detect any padding. Any bytes after the ethernet "
1203 "payload will be considered trailer.\n"
1204 "Zeros (default) - Consecutive bytes of zeros up to the minimum "
1205 "ethernet frame size will be treated as padding. Additional bytes will "
1206 "be considered trailer.\n"
1207 "Any - Any bytes after the payload up to the minimum ethernet frame "
1208 "size will be treated as padding. Additional bytes will be considered "
1209 "trailer.",
1210 &eth_padding, eth_padding_vals, false);
1212 prefs_register_uint_preference(eth_module, "trailer_length",
1213 "Fixed ethernet trailer length",
1214 "Some TAPs add a fixed length ethernet trailer at the end "
1215 "of the frame, but before the (optional) FCS. Make sure it "
1216 "gets interpreted correctly.",
1217 10, &eth_trailer_length);
1219 prefs_register_obsolete_preference(eth_module, "assume_fcs");
1220 prefs_register_enum_preference(eth_module, "fcs",
1221 "Assume packets have FCS",
1222 "Some Ethernet adapters and drivers include the FCS at the end of a packet, others do not. "
1223 "Some capture file formats and protocols do not indicate whether or not the FCS is included. "
1224 "The Ethernet dissector then attempts to guess whether a captured packet has an FCS, "
1225 "but it cannot always guess correctly. This option can override that heuristic "
1226 "and assume that the FCS is either never or always present in such cases.",
1227 &eth_fcs, eth_fcs_vals, false);
1229 prefs_register_bool_preference(eth_module, "check_fcs",
1230 "Validate the Ethernet checksum if possible",
1231 "Whether to validate the Frame Check Sequence",
1232 &eth_check_fcs);
1234 prefs_register_bool_preference(eth_module, "interpret_as_fw1_monitor",
1235 "Attempt to interpret as FireWall-1 monitor file",
1236 "Whether packets should be interpreted as coming from CheckPoint FireWall-1 monitor file if they look as if they do",
1237 &eth_interpret_as_fw1_monitor);
1239 prefs_register_bool_preference(eth_module, "deduplicate_dmac",
1240 "Skip bytes 1-6 if identical to 7-12",
1241 "When capturing on a Cisco FEX some frames start with an extra destination mac",
1242 &eth_deduplicate_dmac);
1244 prefs_register_static_text_preference(eth_module, "ccsds_heuristic",
1245 "Dissect as CCSDS if",
1246 "These are the conditions to match a payload against in order to determine if this\n"
1247 "is a CCSDS (Consultative Committee for Space Data Systems) packet within\n"
1248 "an 802.3 packet. A packet is considered as a possible CCSDS packet only if\n"
1249 "one or more of the conditions are checked.");
1251 prefs_register_bool_preference(eth_module, "ccsds_heuristic_length",
1252 "CCSDS Length in header matches payload size",
1253 "Set the condition that must be true for the CCSDS dissector to be called",
1254 &ccsds_heuristic_length);
1256 prefs_register_bool_preference(eth_module, "ccsds_heuristic_version",
1257 "CCSDS Version # is zero",
1258 "Set the condition that must be true for the CCSDS dissector to be called",
1259 &ccsds_heuristic_version);
1261 prefs_register_bool_preference(eth_module, "ccsds_heuristic_header",
1262 "CCSDS Secondary Header Flag is set",
1263 "Set the condition that must be true for the CCSDS dissector to be called",
1264 &ccsds_heuristic_header);
1266 prefs_register_bool_preference(eth_module, "ccsds_heuristic_bit",
1267 "CCSDS Spare bit is cleared",
1268 "Set the condition that must be true for the CCSDS dissector to be called",
1269 &ccsds_heuristic_bit);
1271 eth_withoutfcs_handle = register_dissector("eth_withoutfcs", dissect_eth_withoutfcs, proto_eth);
1272 register_dissector("eth_withfcs", dissect_eth_withfcs, proto_eth);
1273 eth_maybefcs_handle = register_dissector("eth_maybefcs", dissect_eth_maybefcs, proto_eth);
1274 eth_tap = register_tap("eth");
1276 register_conversation_table(proto_eth, true, eth_conversation_packet, eth_endpoint_packet);
1277 register_conversation_filter("eth", "Ethernet", eth_filter_valid, eth_build_filter, NULL);
1279 register_capture_dissector("eth", capture_eth, proto_eth);
1282 void
1283 proto_reg_handoff_eth(void)
1285 dissector_handle_t eth_handle;
1286 capture_dissector_handle_t eth_cap_handle;
1288 /* Get a handle for the Firewall-1 dissector. */
1289 fw1_handle = find_dissector_add_dependency("fw1", proto_eth);
1291 /* Get a handle for the ethertype dissector. */
1292 ethertype_handle = find_dissector_add_dependency("ethertype", proto_eth);
1294 eth_handle = create_dissector_handle(dissect_eth, proto_eth);
1295 dissector_add_uint("wtap_encap", WTAP_ENCAP_ETHERNET, eth_handle);
1296 /* This needs a different (& more user-friendly) name than the other tap */
1297 exported_pdu_tap = register_export_pdu_tap_with_encap("Ethernet", WTAP_ENCAP_ETHERNET);
1299 dissector_add_uint("ethertype", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);
1301 dissector_add_uint("erf.types.type", ERF_TYPE_ETH, eth_maybefcs_handle);
1302 dissector_add_uint("erf.types.type", ERF_TYPE_COLOR_ETH, eth_maybefcs_handle);
1303 dissector_add_uint("erf.types.type", ERF_TYPE_DSM_COLOR_ETH, eth_maybefcs_handle);
1304 dissector_add_uint("erf.types.type", ERF_TYPE_COLOR_HASH_ETH, eth_maybefcs_handle);
1305 dissector_add_uint("ip.proto", IP_PROTO_ETHERNET, eth_maybefcs_handle);
1307 dissector_add_uint("chdlc.protocol", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);
1308 dissector_add_for_decode_as("gre.subproto", eth_withoutfcs_handle);
1309 dissector_add_uint("gre.proto", ETHERTYPE_ETHBRIDGE, eth_withoutfcs_handle);
1310 dissector_add_uint("gre.proto", GRE_MIKROTIK_EOIP, eth_withoutfcs_handle);
1311 dissector_add_uint("juniper.proto", JUNIPER_PROTO_ETHER, eth_withoutfcs_handle);
1312 dissector_add_uint("sflow_245.header_protocol", SFLOW_245_HEADER_ETHERNET, eth_withoutfcs_handle);
1313 dissector_add_uint("l2tp.pw_type", L2TPv3_PW_ETH, eth_withoutfcs_handle);
1314 dissector_add_uint("vxlan.next_proto", VXLAN_ETHERNET, eth_withoutfcs_handle);
1315 dissector_add_uint("sll.ltype", LINUX_SLL_P_ETHERNET, eth_withoutfcs_handle);
1316 dissector_add_uint("nsh.next_proto", NSH_ETHERNET, eth_withoutfcs_handle);
1318 dissector_add_uint("acdr.media_type", ACDR_Control, eth_withoutfcs_handle);
1319 dissector_add_uint("acdr.media_type", ACDR_DSP_SNIFFER, eth_withoutfcs_handle);
1320 dissector_add_uint("mctp.encap-type", MCTP_TYPE_ETHERNET, eth_withoutfcs_handle);
1323 * This is to handle the output for the Cisco CMTS "cable intercept"
1324 * command - it encapsulates Ethernet frames in UDP packets, but
1325 * the UDP port is user-defined.
1327 dissector_add_for_decode_as_with_preference("udp.port", eth_withoutfcs_handle);
1329 dissector_add_for_decode_as("pcli.payload", eth_withoutfcs_handle);
1331 eth_cap_handle = find_capture_dissector("eth");
1332 capture_dissector_add_uint("wtap_encap", WTAP_ENCAP_ETHERNET, eth_cap_handle);
1333 capture_dissector_add_uint("atm_lane", TRAF_ST_LANE_802_3, eth_cap_handle);
1334 capture_dissector_add_uint("atm_lane", TRAF_ST_LANE_802_3_MC, eth_cap_handle);
1335 capture_dissector_add_uint("ppi", 1 /* DLT_EN10MB */, eth_cap_handle);
1336 capture_dissector_add_uint("sll.ltype", LINUX_SLL_P_ETHERNET, eth_cap_handle);
1338 isl_cap_handle = find_capture_dissector("isl");
1339 ipx_cap_handle = find_capture_dissector("ipx");
1340 llc_cap_handle = find_capture_dissector("llc");
1344 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1346 * Local Variables:
1347 * c-basic-offset: 2
1348 * tab-width: 8
1349 * indent-tabs-mode: nil
1350 * End:
1352 * ex: set shiftwidth=2 tabstop=8 expandtab:
1353 * :indentSize=2:tabSize=8:noTabs=true: