/src/wireshark/epan/dissectors/packet-ddtp.c
Line | Count | Source |
1 | | /* packet-ddtp.c |
2 | | * Routines for DDTP (Dynamic DNS Tools Protocol) packet disassembly |
3 | | * see http://ddt.sourceforge.net/ |
4 | | * Olivier Abad <oabad@noos.fr> |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 2000 |
9 | | * |
10 | | * SPDX-License-Identifier: GPL-2.0-or-later |
11 | | */ |
12 | | |
13 | | #include "config.h" |
14 | | |
15 | | #include <epan/packet.h> |
16 | | #include <epan/expert.h> |
17 | | |
18 | | #define DDTP_VERSION_ERROR 0 |
19 | | #define DDTP_VERSION_4 1 |
20 | | #define DDTP_VERSION_5 2 |
21 | | |
22 | | #define DDTP_ENCRYPT_ERROR 0 |
23 | 0 | #define DDTP_ENCRYPT_PLAINTEXT 1 |
24 | | #define DDTP_ENCRYPT_BLOWFISH 2 |
25 | | |
26 | 0 | #define DDTP_MESSAGE_ERROR 0 |
27 | 0 | #define DDTP_UPDATE_QUERY 1 |
28 | 0 | #define DDTP_UPDATE_REPLY 2 |
29 | 0 | #define DDTP_ALIVE_QUERY 3 |
30 | 0 | #define DDTP_ALIVE_REPLY 4 |
31 | | |
32 | | #define DDTP_MARK_ONLINE 0 |
33 | | #define DDTP_MARK_OFFLINE 1 |
34 | | |
35 | | #define DDTP_UPDATE_SUCCEEDED 0 |
36 | | #define DDTP_UPDATE_FAILED 1 |
37 | | #define DDTP_INVALID_PASSWORD 2 |
38 | | #define DDTP_INVALID_ACCOUNT 3 |
39 | | #define DDTP_INVALID_OPCODE 4 |
40 | | |
41 | | void proto_register_ddtp (void); |
42 | | void proto_reg_handoff_ddtp (void); |
43 | | |
44 | | static dissector_handle_t ddtp_handle; |
45 | | |
46 | | static int proto_ddtp; |
47 | | static int hf_ddtp_version; |
48 | | static int hf_ddtp_encrypt; |
49 | | static int hf_ddtp_hostid; |
50 | | static int hf_ddtp_msgtype; |
51 | | static int hf_ddtp_opcode; |
52 | | static int hf_ddtp_ipaddr; |
53 | | static int hf_ddtp_status; |
54 | | static int hf_ddtp_alive; |
55 | | |
56 | | static int ett_ddtp; |
57 | | |
58 | | static expert_field ei_ddtp_msgtype; |
59 | | |
60 | 16 | #define UDP_PORT_DDTP 1052 |
61 | | |
62 | | /* |
63 | | * XXX - is 0 an invalid value? If so, should we remove it from this |
64 | | * list, so that putative DDNS packets with a version number of 0 are |
65 | | * rejected? |
66 | | */ |
67 | | static const value_string vals_ddtp_version[] = { |
68 | | { DDTP_VERSION_ERROR, "Protocol Error" }, |
69 | | { DDTP_VERSION_4, "4" }, |
70 | | { DDTP_VERSION_5, "5" }, |
71 | | { 0, NULL} |
72 | | }; |
73 | | |
74 | | static const value_string vals_ddtp_encrypt[] = { |
75 | | { DDTP_ENCRYPT_ERROR, "Encryption Error" }, |
76 | | { DDTP_ENCRYPT_PLAINTEXT, "Plain text" }, |
77 | | { DDTP_ENCRYPT_BLOWFISH, "Blowfish" }, |
78 | | { 0, NULL} |
79 | | }; |
80 | | |
81 | | static const value_string vals_ddtp_msgtype[] = { |
82 | | { DDTP_MESSAGE_ERROR, "Message Error" }, |
83 | | { DDTP_UPDATE_QUERY, "Update Query" }, |
84 | | { DDTP_UPDATE_REPLY, "Update Reply" }, |
85 | | { DDTP_ALIVE_QUERY, "Alive Query" }, |
86 | | { DDTP_ALIVE_REPLY, "Alive Reply" }, |
87 | | { 0, NULL} |
88 | | }; |
89 | | |
90 | | static const value_string vals_ddtp_opcode[] = { |
91 | | { DDTP_MARK_ONLINE, "Mark online" }, |
92 | | { DDTP_MARK_OFFLINE, "Mark offline" }, |
93 | | { 0, NULL} |
94 | | }; |
95 | | |
96 | | static const value_string vals_ddtp_status[] = { |
97 | | { DDTP_UPDATE_SUCCEEDED, "Update succeeded" }, |
98 | | { DDTP_UPDATE_FAILED, "Update failed" }, |
99 | | { DDTP_INVALID_PASSWORD, "Invalid password" }, |
100 | | { DDTP_INVALID_ACCOUNT, "Invalid account" }, |
101 | | { DDTP_INVALID_OPCODE, "Invalid opcode" }, |
102 | | { 0, NULL} |
103 | | }; |
104 | | |
105 | | static int |
106 | | dissect_ddtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) |
107 | 1 | { |
108 | 1 | proto_tree *ddtp_tree; |
109 | 1 | proto_item *ti; |
110 | | |
111 | | /* |
112 | | * If we don't recognize the version number, don't dissect this. |
113 | | */ |
114 | 1 | if (tvb_reported_length(tvb) < 4) |
115 | 0 | return 0; |
116 | | |
117 | 1 | if (try_val_to_str(tvb_get_ntohl(tvb, 0), vals_ddtp_version) == NULL) |
118 | 1 | return 0; |
119 | | |
120 | | /* Indicate what kind of message this is. */ |
121 | 0 | col_set_str (pinfo->cinfo, COL_PROTOCOL, "DDTP"); |
122 | | /* In case we throw an exception below. */ |
123 | 0 | col_clear (pinfo->cinfo, COL_INFO); |
124 | |
|
125 | 0 | ti = proto_tree_add_item(tree, proto_ddtp, tvb, 0, -1, ENC_NA); |
126 | 0 | ddtp_tree = proto_item_add_subtree(ti, ett_ddtp); |
127 | |
|
128 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_version, tvb, 0, 4, ENC_BIG_ENDIAN); |
129 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_encrypt, tvb, 4, 4, ENC_BIG_ENDIAN); |
130 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_hostid, tvb, 8, 4, ENC_BIG_ENDIAN); |
131 | |
|
132 | 0 | if (tvb_get_ntohl(tvb, 4) == DDTP_ENCRYPT_PLAINTEXT) { |
133 | 0 | ti = proto_tree_add_item(ddtp_tree, hf_ddtp_msgtype, tvb, 12, 4, ENC_BIG_ENDIAN); |
134 | 0 | switch (tvb_get_ntohl(tvb, 12)) { |
135 | 0 | case DDTP_MESSAGE_ERROR : |
136 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Message Error"); |
137 | 0 | break; |
138 | 0 | case DDTP_UPDATE_QUERY : |
139 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Update Query"); |
140 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_opcode, tvb, 16, 4, ENC_BIG_ENDIAN); |
141 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_ipaddr, tvb, 20, 4, ENC_BIG_ENDIAN); |
142 | 0 | break; |
143 | 0 | case DDTP_UPDATE_REPLY : |
144 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Update Reply"); |
145 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_status, tvb, 16, 4, ENC_BIG_ENDIAN); |
146 | 0 | break; |
147 | 0 | case DDTP_ALIVE_QUERY : |
148 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Alive Query"); |
149 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_alive, tvb, 16, 4, ENC_BIG_ENDIAN); |
150 | 0 | break; |
151 | 0 | case DDTP_ALIVE_REPLY : |
152 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Alive Reply"); |
153 | 0 | proto_tree_add_item(ddtp_tree, hf_ddtp_alive, tvb, 16, 4, ENC_BIG_ENDIAN); |
154 | 0 | break; |
155 | 0 | default : |
156 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Unknown type"); |
157 | 0 | expert_add_info(pinfo, ti, &ei_ddtp_msgtype); |
158 | 0 | } |
159 | 0 | } else { |
160 | 0 | col_set_str(pinfo->cinfo, COL_INFO, "Encrypted payload"); |
161 | 0 | } |
162 | 0 | return tvb_reported_length(tvb); |
163 | 0 | } |
164 | | |
165 | | void |
166 | | proto_register_ddtp(void) |
167 | 16 | { |
168 | 16 | static hf_register_info hf_ddtp[] = { |
169 | 16 | { &hf_ddtp_version, |
170 | 16 | { "Version", "ddtp.version", FT_UINT32, BASE_DEC, VALS(vals_ddtp_version), 0x0, |
171 | 16 | NULL, HFILL }}, |
172 | 16 | { &hf_ddtp_encrypt, |
173 | 16 | { "Encryption", "ddtp.encrypt", FT_UINT32, BASE_DEC, VALS(vals_ddtp_encrypt), 0x0, |
174 | 16 | "Encryption type", HFILL }}, |
175 | 16 | { &hf_ddtp_hostid, |
176 | 16 | { "Hostid", "ddtp.hostid", FT_UINT32, BASE_DEC, NULL, 0x0, |
177 | 16 | "Host ID", HFILL }}, |
178 | 16 | { &hf_ddtp_msgtype, |
179 | 16 | { "Message type", "ddtp.msgtype", FT_UINT32, BASE_DEC, VALS(vals_ddtp_msgtype), 0x0, |
180 | 16 | NULL, HFILL }}, |
181 | 16 | { &hf_ddtp_opcode, |
182 | 16 | { "Opcode", "ddtp.opcode", FT_UINT32, BASE_DEC, VALS(vals_ddtp_opcode), 0x0, |
183 | 16 | "Update query opcode", HFILL }}, |
184 | 16 | { &hf_ddtp_ipaddr, |
185 | 16 | { "IP address", "ddtp.ipaddr", FT_IPv4, BASE_NONE, NULL, 0x0, |
186 | 16 | NULL, HFILL }}, |
187 | 16 | { &hf_ddtp_status, |
188 | 16 | { "Status", "ddtp.status", FT_UINT32, BASE_DEC, VALS(vals_ddtp_status), 0x0, |
189 | 16 | "Update reply status", HFILL }}, |
190 | 16 | { &hf_ddtp_alive, |
191 | 16 | { "Dummy", "ddtp.alive", FT_UINT32, BASE_DEC, NULL, 0x0, |
192 | 16 | NULL, HFILL }}, |
193 | 16 | }; |
194 | | |
195 | 16 | static int *ett[] = { &ett_ddtp }; |
196 | | |
197 | 16 | static ei_register_info ei[] = { |
198 | 16 | { &ei_ddtp_msgtype, { "ddtp.msgtype.unknown", PI_PROTOCOL, PI_WARN, "Unknown type", EXPFILL }}, |
199 | 16 | }; |
200 | | |
201 | 16 | expert_module_t* expert_ddtp; |
202 | | |
203 | 16 | proto_ddtp = proto_register_protocol("Dynamic DNS Tools Protocol", "DDTP", "ddtp"); |
204 | 16 | proto_register_field_array(proto_ddtp, hf_ddtp, array_length(hf_ddtp)); |
205 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
206 | 16 | expert_ddtp = expert_register_protocol(proto_ddtp); |
207 | 16 | expert_register_field_array(expert_ddtp, ei, array_length(ei)); |
208 | | |
209 | 16 | ddtp_handle = register_dissector("ddtp", dissect_ddtp, proto_ddtp); |
210 | 16 | } |
211 | | |
212 | | void |
213 | | proto_reg_handoff_ddtp(void) |
214 | 16 | { |
215 | 16 | dissector_add_uint_with_preference("udp.port", UDP_PORT_DDTP, ddtp_handle); |
216 | 16 | } |
217 | | |
218 | | /* |
219 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
220 | | * |
221 | | * Local variables: |
222 | | * c-basic-offset: 4 |
223 | | * tab-width: 8 |
224 | | * indent-tabs-mode: nil |
225 | | * End: |
226 | | * |
227 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
228 | | * :indentSize=4:tabSize=8:noTabs=true: |
229 | | */ |