/src/wireshark/epan/dissectors/packet-etherip.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2003 Markus Friedl. All rights reserved. |
3 | | * |
4 | | * SPDX-License-Identifier: BSD-2-Clause |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #include <epan/packet.h> |
10 | | #include <epan/ipproto.h> |
11 | | #include <epan/expert.h> |
12 | | |
13 | | void proto_register_etherip(void); |
14 | | void proto_reg_handoff_etherip(void); |
15 | | |
16 | | static int proto_etherip; |
17 | | static int hf_etherip_ver; |
18 | | static int hf_etherip_reserved; |
19 | | |
20 | | static int ett_etherip; |
21 | | |
22 | | static expert_field ei_etherip_ver_3; |
23 | | static expert_field ei_etherip_reserved_0; |
24 | | |
25 | | static dissector_handle_t eth_withoutfcs_handle; |
26 | | static dissector_handle_t etherip_handle; |
27 | | |
28 | | /* |
29 | | * RFC 3378: EtherIP: Tunneling Ethernet Frames in IP Datagrams |
30 | | * |
31 | | * Bits 0-3: Protocol version |
32 | | * Bits 4-15: Reserved for future use |
33 | | */ |
34 | | |
35 | 6.41k | #define ETHERIP_VERS_MASK 0xF000 |
36 | 6.41k | #define ETHERIP_RESERVE_MASK 0x0FFF |
37 | | |
38 | | |
39 | | static int |
40 | | dissect_etherip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
41 | 6.39k | { |
42 | 6.39k | tvbuff_t *next_tvb; |
43 | 6.39k | proto_tree *etherip_tree; |
44 | 6.39k | proto_item *ti; |
45 | 6.39k | uint16_t field, version; |
46 | | |
47 | 6.39k | col_set_str(pinfo->cinfo, COL_PROTOCOL, "ETHERIP"); |
48 | | |
49 | 6.39k | field = tvb_get_ntohs(tvb, 0); |
50 | 6.39k | version = (field & ETHERIP_VERS_MASK) >> 12; |
51 | | |
52 | 6.39k | if (tree) { |
53 | 6.39k | ti = proto_tree_add_protocol_format(tree, proto_etherip, tvb, 0, |
54 | 6.39k | 2, |
55 | 6.39k | "EtherIP, Version %d", |
56 | 6.39k | version |
57 | 6.39k | ); |
58 | 6.39k | etherip_tree = proto_item_add_subtree(ti, ett_etherip); |
59 | | |
60 | 6.39k | ti = proto_tree_add_item(etherip_tree, hf_etherip_ver, tvb, |
61 | 6.39k | 0, 2, ENC_BIG_ENDIAN); |
62 | 6.39k | if (version != 3) { |
63 | 6.29k | expert_add_info(pinfo, ti, &ei_etherip_ver_3); |
64 | 6.29k | } |
65 | | |
66 | 6.39k | ti = proto_tree_add_item(etherip_tree, hf_etherip_reserved, tvb, |
67 | 6.39k | 0, 2, ENC_BIG_ENDIAN); |
68 | 6.39k | if ((field & ETHERIP_RESERVE_MASK) != 0) { |
69 | 4.42k | expert_add_info(pinfo, ti, &ei_etherip_reserved_0); |
70 | 4.42k | } |
71 | 6.39k | } |
72 | | |
73 | | /* Set the tvbuff for the payload after the header */ |
74 | 6.39k | next_tvb = tvb_new_subset_remaining(tvb, 2); |
75 | | |
76 | 6.39k | call_dissector(eth_withoutfcs_handle, next_tvb, pinfo, tree); |
77 | 6.39k | return tvb_captured_length(tvb); |
78 | 6.39k | } |
79 | | |
80 | | void |
81 | | proto_register_etherip(void) |
82 | 14 | { |
83 | 14 | static hf_register_info hf_etherip[] = { |
84 | 14 | { &hf_etherip_ver, |
85 | 14 | { "Version", "etherip.ver", FT_UINT16, BASE_DEC, NULL, ETHERIP_VERS_MASK, |
86 | 14 | NULL, HFILL }}, |
87 | 14 | { &hf_etherip_reserved, |
88 | 14 | { "Reserved", "etherip.reserved", FT_UINT16, BASE_HEX, NULL, ETHERIP_RESERVE_MASK, |
89 | 14 | "Reserved (must be 0)", HFILL }}, |
90 | 14 | }; |
91 | | |
92 | 14 | static int *ett[] = { |
93 | 14 | &ett_etherip, |
94 | 14 | }; |
95 | | |
96 | 14 | static ei_register_info ei[] = { |
97 | 14 | { &ei_etherip_ver_3, { "etherip.ver.not3", PI_PROTOCOL, PI_WARN, "Version must be 3", EXPFILL }}, |
98 | 14 | { &ei_etherip_reserved_0, { "etherip.reserved.not0", PI_PROTOCOL, PI_WARN, "Reserved field must be 0", EXPFILL }}, |
99 | 14 | }; |
100 | | |
101 | 14 | expert_module_t* expert_etherip; |
102 | | |
103 | 14 | proto_etherip = proto_register_protocol("Ethernet over IP", |
104 | 14 | "ETHERIP", "etherip"); |
105 | 14 | proto_register_field_array(proto_etherip, hf_etherip, array_length(hf_etherip)); |
106 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
107 | 14 | expert_etherip = expert_register_protocol(proto_etherip); |
108 | 14 | expert_register_field_array(expert_etherip, ei, array_length(ei)); |
109 | | |
110 | 14 | etherip_handle = register_dissector("etherip", dissect_etherip, proto_etherip); |
111 | 14 | } |
112 | | |
113 | | void |
114 | | proto_reg_handoff_etherip(void) |
115 | 14 | { |
116 | 14 | eth_withoutfcs_handle = find_dissector_add_dependency("eth_withoutfcs", proto_etherip); |
117 | 14 | dissector_add_uint("ip.proto", IP_PROTO_ETHERIP, etherip_handle); |
118 | 14 | } |
119 | | |
120 | | /* |
121 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
122 | | * |
123 | | * Local Variables: |
124 | | * c-basic-offset: 2 |
125 | | * tab-width: 8 |
126 | | * indent-tabs-mode: nil |
127 | | * End: |
128 | | * |
129 | | * ex: set shiftwidth=2 tabstop=8 expandtab: |
130 | | * :indentSize=2:tabSize=8:noTabs=true: |
131 | | */ |