Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-icp.c
blobb584864db1d07eb0eb3a513106ce4ba292d90fbd
1 /* packet-icp.c
2 * Routines for ICP (internet cache protocol) packet disassembly
3 * RFC 2186 && RFC 2187
4 * By Peter Torvals
5 * Copyright 1999 Peter Torvals
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/expert.h>
19 void proto_register_icp(void);
20 void proto_reg_handoff_icp(void);
22 static dissector_handle_t icp_handle;
24 static int proto_icp;
25 static int hf_icp_length;
26 static int hf_icp_opcode;
27 static int hf_icp_version;
28 static int hf_icp_request_nr;
30 /* Generated from convert_proto_tree_add_text.pl */
31 static int hf_icp_url;
32 static int hf_icp_rtt;
33 static int hf_icp_object_data;
34 static int hf_icp_requester_host_address;
35 static int hf_icp_sender_host_ip_address;
36 static int hf_icp_option_src_rtt;
37 static int hf_icp_object_length;
38 static int hf_icp_option_hit_obj;
40 static int ett_icp;
41 static int ett_icp_payload;
43 /* Generated from convert_proto_tree_add_text.pl */
44 static expert_field ei_icp_fragmented_packet;
46 #define UDP_PORT_ICP 3130
48 #define CODE_ICP_OP_QUERY 1
49 #define CODE_ICP_OP_INVALID 0
50 #define CODE_ICP_OP_HIT 2
51 #define CODE_ICP_OP_MISS 3
52 #define CODE_ICP_OP_ERR 4
53 #define CODE_ICP_OP_SEND 5
54 #define CODE_ICP_OP_SENDA 6
55 #define CODE_ICP_OP_DATABEG 7
56 #define CODE_ICP_OP_DATA 8
57 #define CODE_ICP_OP_DATAEND 9
58 #define CODE_ICP_OP_SECHO 10
59 #define CODE_ICP_OP_DECHO 11
60 #define CODE_ICP_OP_MISS_NOFETCH 21
61 #define CODE_ICP_OP_DENIED 22
62 #define CODE_ICP_OP_HIT_OBJ 23
64 static const value_string opcode_vals[] = {
65 { CODE_ICP_OP_INVALID , "ICP_INVALID" },
66 { CODE_ICP_OP_QUERY , "ICP_QUERY" },
67 { CODE_ICP_OP_HIT , "ICP_HIT" },
68 { CODE_ICP_OP_MISS , "ICP_MISS" },
69 { CODE_ICP_OP_ERR , "ICP_ERR" },
70 { CODE_ICP_OP_SEND, "ICP_SEND" },
71 { CODE_ICP_OP_SENDA, "ICP_SENDA"},
72 { CODE_ICP_OP_DATABEG, "ICP_DATABEG"},
73 { CODE_ICP_OP_DATA, "ICP_DATA"},
74 { CODE_ICP_OP_DATAEND, "ICP_DATA_END"},
75 { CODE_ICP_OP_SECHO , "ICP_SECHO"},
76 { CODE_ICP_OP_DECHO , "ICP_DECHO"},
77 { CODE_ICP_OP_MISS_NOFETCH , "ICP_MISS_NOFETCH"},
78 { CODE_ICP_OP_DENIED , "ICP_DENIED"},
79 { CODE_ICP_OP_HIT_OBJ , "ICP_HIT_OBJ"},
80 { 0, NULL}
83 static void dissect_icp_payload(tvbuff_t *tvb, packet_info *pinfo, int offset,
84 proto_tree *pload_tree, uint8_t opcode)
86 int stringlength;
87 uint16_t objectlength;
88 proto_item* object_item;
90 switch(opcode)
92 case CODE_ICP_OP_QUERY:
93 /* 4 byte requester host address */
94 proto_tree_add_item(pload_tree, hf_icp_requester_host_address, tvb, offset, 4, ENC_BIG_ENDIAN);
95 offset += 4;
97 /* null terminated URL */
98 stringlength = tvb_strsize(tvb, offset);
99 proto_tree_add_item(pload_tree, hf_icp_url, tvb, offset, stringlength, ENC_ASCII);
100 break;
102 case CODE_ICP_OP_SECHO:
103 case CODE_ICP_OP_DECHO:
104 case CODE_ICP_OP_HIT:
105 case CODE_ICP_OP_MISS:
106 case CODE_ICP_OP_ERR:
107 case CODE_ICP_OP_MISS_NOFETCH:
108 case CODE_ICP_OP_DENIED:
109 stringlength = tvb_strsize(tvb, offset);
110 proto_tree_add_item(pload_tree, hf_icp_url, tvb, offset, stringlength, ENC_ASCII);
111 break;
113 case CODE_ICP_OP_HIT_OBJ:
114 /* null terminated URL */
115 stringlength = tvb_strsize(tvb, offset);
116 proto_tree_add_item(pload_tree, hf_icp_url, tvb, offset, stringlength, ENC_ASCII);
117 offset += stringlength;
119 /* 2 byte object size */
120 /* object data not recommended by standard*/
121 objectlength=tvb_get_ntohs(tvb, offset);
122 proto_tree_add_item(pload_tree, hf_icp_object_length, tvb, offset, 2, ENC_BIG_ENDIAN);
123 offset += 2;
125 /* object data not recommended by standard*/
126 object_item = proto_tree_add_item(pload_tree, hf_icp_object_data, tvb, offset, objectlength, ENC_NA);
127 if (objectlength > tvb_reported_length_remaining(tvb, offset))
129 expert_add_info(pinfo, object_item, &ei_icp_fragmented_packet);
131 break;
132 default:
133 break;
137 static int dissect_icp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
139 proto_tree *icp_tree , *payload_tree;
140 proto_item *ti;
141 uint8_t opcode;
142 uint16_t message_length;
143 uint32_t request_number;
144 uint32_t options;
146 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ICP");
147 col_clear(pinfo->cinfo, COL_INFO);
149 opcode=tvb_get_uint8(tvb, 0);
150 message_length=tvb_get_ntohs(tvb, 2);
151 request_number=tvb_get_ntohl(tvb, 4);
153 col_add_fstr(pinfo->cinfo,COL_INFO,"Opcode: %s (%u), Req Nr: %u",
154 val_to_str_const(opcode, opcode_vals, "Unknown"), opcode,
155 request_number);
157 ti = proto_tree_add_item(tree,proto_icp, tvb, 0, message_length, ENC_NA);
158 icp_tree = proto_item_add_subtree(ti, ett_icp);
160 if (tree)
162 proto_tree_add_uint(icp_tree,hf_icp_opcode, tvb, 0, 1, opcode);
164 proto_tree_add_item(icp_tree,hf_icp_version, tvb, 1, 1, ENC_BIG_ENDIAN);
166 proto_tree_add_uint(icp_tree,hf_icp_length, tvb, 2, 2, message_length);
168 proto_tree_add_uint(icp_tree,hf_icp_request_nr, tvb, 4, 4,
169 request_number);
171 options=tvb_get_ntohl(tvb, 8);
172 if ( (opcode == CODE_ICP_OP_QUERY) && ((options & 0x80000000 ) != 0) )
174 proto_tree_add_item(icp_tree, hf_icp_option_hit_obj, tvb, 8, 4, ENC_NA);
176 if ( (opcode == CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0) )
178 proto_tree_add_item(icp_tree, hf_icp_option_src_rtt, tvb, 8, 4, ENC_NA);
180 if ((opcode != CODE_ICP_OP_QUERY)&& ((options & 0x40000000 ) != 0))
182 proto_tree_add_item(icp_tree, hf_icp_option_src_rtt, tvb, 8, 4, ENC_NA);
183 proto_tree_add_item(icp_tree, hf_icp_rtt, tvb, 12, 4, ENC_BIG_ENDIAN);
186 proto_tree_add_item(icp_tree, hf_icp_sender_host_ip_address, tvb, 16, 4, ENC_BIG_ENDIAN);
189 payload_tree = proto_tree_add_subtree(icp_tree, tvb,
190 20, message_length - 20,
191 ett_icp_payload, NULL, "Payload");
192 dissect_icp_payload(tvb, pinfo, 20, payload_tree, opcode);
194 return tvb_captured_length(tvb);
197 void
198 proto_register_icp(void)
200 static hf_register_info hf[] = {
201 { &hf_icp_opcode,
202 { "Opcode", "icp.opcode", FT_UINT8, BASE_HEX, VALS(opcode_vals),
203 0x0, NULL, HFILL }},
205 { &hf_icp_version,
206 { "Version", "icp.version", FT_UINT8, BASE_DEC, NULL,
207 0x0, NULL, HFILL }},
209 { &hf_icp_length,
210 { "Length", "icp.length", FT_UINT16, BASE_DEC, NULL,
211 0x0, NULL, HFILL }},
213 { &hf_icp_request_nr,
214 { "Request Number", "icp.nr", FT_UINT32, BASE_DEC, NULL,
215 0x0, NULL, HFILL }},
217 { &hf_icp_requester_host_address, { "Requester Host Address", "icp.requester_host_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
218 { &hf_icp_url, { "URL", "icp.url", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
219 { &hf_icp_object_length, { "Object length", "icp.object_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
220 { &hf_icp_object_data, { "Object data", "icp.object_data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
221 { &hf_icp_option_hit_obj, { "Option: ICP_FLAG_HIT_OBJ", "icp.option.hit_obj", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
222 { &hf_icp_option_src_rtt, { "Option: ICP_FLAG_SRC_RTT", "icp.option.src_rtt", FT_NONE, BASE_NONE, NULL, 0x0, NULL, HFILL }},
223 { &hf_icp_rtt, { "RTT", "icp.rtt", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
224 { &hf_icp_sender_host_ip_address, { "Sender Host IP address", "icp.sender_host_ip_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
226 static int *ett[] = {
227 &ett_icp,
228 &ett_icp_payload,
231 static ei_register_info ei[] = {
232 { &ei_icp_fragmented_packet, { "icp.fragmented_packet", PI_PROTOCOL, PI_WARN, "Packet is fragmented", EXPFILL }},
235 expert_module_t* expert_icp;
237 proto_icp = proto_register_protocol("Internet Cache Protocol", "ICP", "icp");
239 proto_register_field_array(proto_icp, hf, array_length(hf));
240 proto_register_subtree_array(ett, array_length(ett));
241 expert_icp = expert_register_protocol(proto_icp);
242 expert_register_field_array(expert_icp, ei, array_length(ei));
244 icp_handle = register_dissector("icp", dissect_icp, proto_icp);
247 void
248 proto_reg_handoff_icp(void)
250 dissector_add_uint_with_preference("udp.port", UDP_PORT_ICP, icp_handle);
254 * Editor modelines - https://www.wireshark.org/tools/modelines.html
256 * Local variables:
257 * c-basic-offset: 8
258 * tab-width: 8
259 * indent-tabs-mode: t
260 * End:
262 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
263 * :indentSize=8:tabSize=8:noTabs=false: