Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-asap.c
blobeb79f982ebba92805ce6708405ea6e3d4397940b
1 /* packet-asap.c
2 * Routines for Aggregate Server Access Protocol (ASAP)
3 * It is hopefully (needs testing) compliant to
4 * RFC 5352
5 * RFC 5354
6 * RFC 5356
7 * https://tools.ietf.org/html/draft-dreibholz-rserpool-asap-hropt-27
8 * https://tools.ietf.org/html/draft-dreibholz-rserpool-delay-26
10 * Copyright 2008-2021 Thomas Dreibholz <dreibh [AT] iem.uni-due.de>
11 * Copyright 2004-2007 Michael Tüxen <tuexen [AT] fh-muenster.de>
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * Copied from README.developer
19 * SPDX-License-Identifier: GPL-2.0-or-later
22 #include "config.h"
24 #include <epan/packet.h>
25 #include <epan/to_str.h>
26 #include <epan/sctpppids.h>
27 #include <epan/stat_tap_ui.h>
28 #include <epan/tfs.h>
29 #include <epan/unit_strings.h>
31 #include <wsutil/str_util.h>
32 #include <wsutil/ws_roundup.h>
33 #include <wsutil/array.h>
35 #include "packet-asap+enrp-common.h"
37 void proto_register_asap(void);
38 void proto_reg_handoff_asap(void);
40 static dissector_handle_t asap_handle;
42 /* Initialize the protocol and registered fields */
43 static int asap_tap;
44 static int proto_asap;
45 static int hf_cause_code;
46 static int hf_cause_length;
47 static int hf_cause_info;
48 static int hf_cause_padding;
49 static int hf_message_type;
50 static int hf_message_flags;
51 static int hf_message_length;
52 static int hf_parameter_type;
53 static int hf_parameter_length;
54 static int hf_parameter_value;
55 static int hf_parameter_padding;
56 static int hf_parameter_ipv4_address;
57 static int hf_parameter_ipv6_address;
58 static int hf_dccp_port;
59 static int hf_dccp_reserved;
60 static int hf_dccp_service_code;
61 static int hf_sctp_port;
62 static int hf_transport_use;
63 static int hf_tcp_port;
64 static int hf_udp_port;
65 static int hf_udp_reserved;
66 static int hf_udp_lite_port;
67 static int hf_udp_lite_reserved;
68 static int hf_policy_type;
69 static int hf_policy_value;
70 static int hf_policy_weight;
71 static int hf_policy_priority;
72 static int hf_policy_load;
73 static int hf_policy_degradation;
74 static int hf_policy_loaddpf;
75 static int hf_policy_weightdpf;
76 static int hf_policy_distance;
77 static int hf_pool_handle;
78 static int hf_pe_pe_identifier;
79 static int hf_home_enrp_id;
80 static int hf_reg_life;
81 static int hf_server_identifier;
82 static int hf_cookie;
83 static int hf_pe_identifier;
84 static int hf_pe_checksum;
85 static int hf_hropt_items;
86 static int hf_home_enrp_server_bit;
87 static int hf_reject_bit;
89 /* Initialize the subtree pointers */
90 static int ett_asap;
91 static int ett_asap_parameter;
92 static int ett_asap_cause;
93 static int ett_asap_flags;
95 static uint64_t asap_total_msgs;
96 static uint64_t asap_total_bytes;
98 static void
99 dissect_parameters(tvbuff_t *, packet_info *, proto_tree *);
100 static void
101 dissect_parameter(tvbuff_t *, packet_info *, proto_tree *);
102 static int
103 dissect_asap(tvbuff_t *, packet_info *, proto_tree *, void *);
105 #define ASAP_UDP_PORT 3863
106 #define ASAP_TCP_PORT 3863
107 #define ASAP_SCTP_PORT 3863
109 typedef struct _asap_tap_rec_t {
110 uint8_t type;
111 uint16_t size;
112 const char* type_string;
113 } asap_tap_rec_t;
115 /* Dissectors for error causes. This is common for ASAP and ENRP. */
117 static void
118 dissect_unknown_cause(tvbuff_t *cause_tvb, proto_tree *cause_tree, proto_item *cause_item)
120 uint16_t code, length, cause_info_length;
122 code = tvb_get_ntohs(cause_tvb, CAUSE_CODE_OFFSET);
123 length = tvb_get_ntohs(cause_tvb, CAUSE_LENGTH_OFFSET);
124 cause_info_length = length - CAUSE_HEADER_LENGTH;
125 if (cause_info_length > 0)
126 proto_tree_add_item(cause_tree, hf_cause_info, cause_tvb, CAUSE_INFO_OFFSET, cause_info_length, ENC_NA);
127 proto_item_append_text(cause_item, " (code %u and %u byte%s information)", code, cause_info_length, plurality(cause_info_length, "", "s"));
130 static void
131 // NOLINTNEXTLINE(misc-no-recursion)
132 dissect_error_cause(tvbuff_t *cause_tvb, packet_info *pinfo, proto_tree *parameter_tree)
134 uint16_t code, length, padding_length;
135 proto_item *cause_item;
136 proto_tree *cause_tree;
137 tvbuff_t *parameter_tvb, *message_tvb;
139 pinfo->flags.in_error_pkt = true;
141 code = tvb_get_ntohs(cause_tvb, CAUSE_CODE_OFFSET);
142 length = tvb_get_ntohs(cause_tvb, CAUSE_LENGTH_OFFSET);
143 padding_length = tvb_reported_length(cause_tvb) - length;
145 cause_tree = proto_tree_add_subtree(parameter_tree, cause_tvb, CAUSE_HEADER_OFFSET, -1, ett_asap_cause, &cause_item,
146 val_to_str_const(code, cause_code_values, "Unknown error cause"));
148 proto_tree_add_item(cause_tree, hf_cause_code, cause_tvb, CAUSE_CODE_OFFSET, CAUSE_CODE_LENGTH, ENC_BIG_ENDIAN);
149 proto_tree_add_item(cause_tree, hf_cause_length, cause_tvb, CAUSE_LENGTH_OFFSET, CAUSE_LENGTH_LENGTH, ENC_BIG_ENDIAN);
151 switch(code) {
152 case UNRECOGNIZED_PARAMETER_CAUSE_CODE:
153 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
154 dissect_parameter(parameter_tvb, pinfo, cause_tree);
155 break;
156 case UNRECONGNIZED_MESSAGE_CAUSE_CODE:
157 message_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
158 dissect_asap(message_tvb, pinfo, cause_tree, NULL);
159 break;
160 case INVALID_VALUES:
161 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
162 dissect_parameter(parameter_tvb, pinfo, cause_tree);
163 break;
164 case NON_UNIQUE_PE_IDENTIFIER:
165 break;
166 case POOLING_POLICY_INCONSISTENT_CAUSE_CODE:
167 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
168 dissect_parameter(parameter_tvb, pinfo, cause_tree);
169 break;
170 case LACK_OF_RESOURCES_CAUSE_CODE:
171 break;
172 case INCONSISTENT_TRANSPORT_TYPE_CAUSE_CODE:
173 parameter_tvb = tvb_new_subset_remaining(cause_tvb, CAUSE_INFO_OFFSET);
174 dissect_parameter(parameter_tvb, pinfo, cause_tree);
175 break;
176 case INCONSISTENT_DATA_CONTROL_CONFIGURATION_CAUSE_CODE:
177 break;
178 case UNKNOWN_POOL_HANDLE:
179 break;
180 case REJECTION_DUE_TO_SECURITY_CAUSE_CODE:
181 break;
182 default:
183 dissect_unknown_cause(cause_tvb, cause_tree, cause_item);
184 break;
186 if (padding_length > 0)
187 proto_tree_add_item(cause_tree, hf_cause_padding, cause_tvb, CAUSE_HEADER_OFFSET + length, padding_length, ENC_NA);
190 static void
191 // NOLINTNEXTLINE(misc-no-recursion)
192 dissect_error_causes(tvbuff_t *error_causes_tvb, packet_info *pinfo, proto_tree *parameter_tree)
194 uint16_t length, total_length;
195 int offset;
196 tvbuff_t *error_cause_tvb;
198 offset = 0;
199 while(tvb_reported_length_remaining(error_causes_tvb, offset) > 0) {
200 length = tvb_get_ntohs(error_causes_tvb, offset + CAUSE_LENGTH_OFFSET);
201 total_length = WS_ROUNDUP_4(length);
202 error_cause_tvb = tvb_new_subset_length(error_causes_tvb, offset , total_length);
203 dissect_error_cause(error_cause_tvb, pinfo, parameter_tree);
204 offset += total_length;
208 /* Dissectors for parameters. This is common for ASAP and ENRP. */
210 static void
211 dissect_ipv4_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
213 proto_tree_add_item(parameter_tree, hf_parameter_ipv4_address, parameter_tvb, IPV4_ADDRESS_OFFSET, IPV4_ADDRESS_LENGTH, ENC_BIG_ENDIAN);
214 proto_item_append_text(parameter_item, " (%s)", tvb_ip_to_str(wmem_packet_scope(), parameter_tvb, IPV4_ADDRESS_OFFSET));
217 static void
218 dissect_ipv6_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
220 proto_tree_add_item(parameter_tree, hf_parameter_ipv6_address, parameter_tvb, IPV6_ADDRESS_OFFSET, IPV6_ADDRESS_LENGTH, ENC_NA);
221 proto_item_append_text(parameter_item, " (%s)", tvb_ip6_to_str(wmem_packet_scope(), parameter_tvb, IPV6_ADDRESS_OFFSET));
224 static void
225 // NOLINTNEXTLINE(misc-no-recursion)
226 dissect_dccp_transport_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
228 tvbuff_t *parameters_tvb;
230 proto_tree_add_item(parameter_tree, hf_dccp_port, parameter_tvb, DCCP_PORT_OFFSET, DCCP_PORT_LENGTH, ENC_BIG_ENDIAN);
231 proto_tree_add_item(parameter_tree, hf_dccp_reserved, parameter_tvb, DCCP_RESERVED_OFFSET, DCCP_RESERVED_LENGTH, ENC_BIG_ENDIAN);
232 proto_tree_add_item(parameter_tree, hf_dccp_service_code, parameter_tvb, DCCP_SERVICE_CODE_OFFSET, DCCP_SERVICE_CODE_LENGTH, ENC_BIG_ENDIAN);
234 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, DCCP_ADDRESS_OFFSET);
235 dissect_parameters(parameters_tvb, pinfo, parameter_tree);
238 static void
239 // NOLINTNEXTLINE(misc-no-recursion)
240 dissect_sctp_transport_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
242 tvbuff_t *parameters_tvb;
244 proto_tree_add_item(parameter_tree, hf_sctp_port, parameter_tvb, SCTP_PORT_OFFSET, SCTP_PORT_LENGTH, ENC_BIG_ENDIAN);
245 proto_tree_add_item(parameter_tree, hf_transport_use, parameter_tvb, SCTP_TRANSPORT_USE_OFFSET, SCTP_TRANSPORT_USE_LENGTH, ENC_BIG_ENDIAN);
247 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, SCTP_ADDRESS_OFFSET);
248 dissect_parameters(parameters_tvb, pinfo, parameter_tree);
251 static void
252 // NOLINTNEXTLINE(misc-no-recursion)
253 dissect_tcp_transport_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
255 tvbuff_t *parameters_tvb;
257 proto_tree_add_item(parameter_tree, hf_tcp_port, parameter_tvb, TCP_PORT_OFFSET, TCP_PORT_LENGTH, ENC_BIG_ENDIAN);
258 proto_tree_add_item(parameter_tree, hf_transport_use, parameter_tvb, TCP_TRANSPORT_USE_OFFSET, TCP_TRANSPORT_USE_LENGTH, ENC_BIG_ENDIAN);
260 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, TCP_ADDRESS_OFFSET);
261 dissect_parameters(parameters_tvb, pinfo, parameter_tree);
264 static void
265 // NOLINTNEXTLINE(misc-no-recursion)
266 dissect_udp_transport_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
268 tvbuff_t *parameters_tvb;
270 proto_tree_add_item(parameter_tree, hf_udp_port, parameter_tvb, UDP_PORT_OFFSET, UDP_PORT_LENGTH, ENC_BIG_ENDIAN);
271 proto_tree_add_item(parameter_tree, hf_udp_reserved, parameter_tvb, UDP_RESERVED_OFFSET, UDP_RESERVED_LENGTH, ENC_BIG_ENDIAN);
273 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, UDP_ADDRESS_OFFSET);
274 dissect_parameters(parameters_tvb, pinfo, parameter_tree);
277 static void
278 // NOLINTNEXTLINE(misc-no-recursion)
279 dissect_udp_lite_transport_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
281 tvbuff_t *parameters_tvb;
283 proto_tree_add_item(parameter_tree, hf_udp_lite_port, parameter_tvb, UDP_LITE_PORT_OFFSET, UDP_LITE_PORT_LENGTH, ENC_BIG_ENDIAN);
284 proto_tree_add_item(parameter_tree, hf_udp_lite_reserved, parameter_tvb, UDP_LITE_RESERVED_OFFSET, UDP_LITE_RESERVED_LENGTH, ENC_BIG_ENDIAN);
286 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, UDP_LITE_ADDRESS_OFFSET);
287 dissect_parameters(parameters_tvb, pinfo, parameter_tree);
290 static void
291 dissect_pool_member_selection_policy_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
293 uint32_t type;
294 unsigned length;
296 proto_tree_add_item(parameter_tree, hf_policy_type, parameter_tvb, POLICY_TYPE_OFFSET, POLICY_TYPE_LENGTH, ENC_BIG_ENDIAN);
297 type = tvb_get_ntohl(parameter_tvb, POLICY_TYPE_OFFSET);
298 switch (type) {
299 case RANDOM_POLICY:
300 case ROUND_ROBIN_POLICY:
301 break;
302 case WEIGHTED_RANDOM_POLICY:
303 case WEIGHTED_ROUND_ROBIN_POLICY:
304 proto_tree_add_item(parameter_tree, hf_policy_weight, parameter_tvb, POLICY_WEIGHT_OFFSET, POLICY_WEIGHT_LENGTH, ENC_BIG_ENDIAN);
305 break;
306 case PRIORITY_POLICY:
307 proto_tree_add_item(parameter_tree, hf_policy_priority, parameter_tvb, POLICY_PRIORITY_OFFSET, POLICY_PRIORITY_LENGTH, ENC_BIG_ENDIAN);
308 break;
309 case LEAST_USED_POLICY:
310 case RANDOMIZED_LEAST_USED_POLICY:
311 proto_tree_add_double_format_value(parameter_tree, hf_policy_load, parameter_tvb, POLICY_LOAD_OFFSET, POLICY_LOAD_LENGTH,
312 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff, "%1.2f%%",
313 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff);
314 break;
315 case LEAST_USED_WITH_DEG_POLICY:
316 case PRIORITY_LEAST_USED_POLICY:
317 proto_tree_add_double_format_value(parameter_tree, hf_policy_load, parameter_tvb, POLICY_LOAD_OFFSET, POLICY_LOAD_LENGTH,
318 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff, "%1.2f%%",
319 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff);
320 proto_tree_add_double_format_value(parameter_tree, hf_policy_degradation, parameter_tvb, POLICY_DEGRADATION_OFFSET, POLICY_DEGRADATION_LENGTH,
321 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_DEGRADATION_OFFSET) / (double)0xffffffff, "%1.2f%%",
322 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_DEGRADATION_OFFSET) / (double)0xffffffff);
323 break;
324 case LEAST_USED_DPF_POLICY:
325 proto_tree_add_double_format_value(parameter_tree, hf_policy_load, parameter_tvb, POLICY_LOAD_OFFSET, POLICY_LOAD_LENGTH,
326 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff, "%1.2f%%",
327 100.0 * tvb_get_ntohl(parameter_tvb, POLICY_LOAD_OFFSET) / (double)0xffffffff);
328 proto_tree_add_double_format_value(parameter_tree, hf_policy_loaddpf, parameter_tvb, POLICY_LUDPF_LOADDPF_OFFSET, POLICY_LUDPF_LOADDPF_LENGTH,
329 tvb_get_ntohl(parameter_tvb, POLICY_LUDPF_LOADDPF_OFFSET) / (double)0xffffffff, "%1.5f",
330 tvb_get_ntohl(parameter_tvb, POLICY_LUDPF_LOADDPF_OFFSET) / (double)0xffffffff);
331 proto_tree_add_item(parameter_tree, hf_policy_distance, parameter_tvb, POLICY_LUDPF_DISTANCE_OFFSET, POLICY_LUDPF_DISTANCE_LENGTH, ENC_BIG_ENDIAN);
332 break;
333 case WEIGHTED_RANDOM_DPF_POLICY:
334 proto_tree_add_item(parameter_tree, hf_policy_weight, parameter_tvb, POLICY_WEIGHT_OFFSET, POLICY_WEIGHT_LENGTH, ENC_BIG_ENDIAN);
335 proto_tree_add_double_format_value(parameter_tree, hf_policy_weightdpf, parameter_tvb, POLICY_WRANDDPF_WEIGHTDPF_OFFSET, POLICY_WRANDDPF_WEIGHTDPF_LENGTH,
336 tvb_get_ntohl(parameter_tvb, POLICY_WRANDDPF_WEIGHTDPF_OFFSET) / (double)0xffffffff, "%1.5f",
337 tvb_get_ntohl(parameter_tvb, POLICY_WRANDDPF_WEIGHTDPF_OFFSET) / (double)0xffffffff);
338 proto_tree_add_item(parameter_tree, hf_policy_distance, parameter_tvb, POLICY_WRANDDPF_DISTANCE_OFFSET, POLICY_WRANDDPF_DISTANCE_LENGTH, ENC_BIG_ENDIAN);
339 break;
340 default:
341 length = tvb_reported_length(parameter_tvb) - POLICY_VALUE_OFFSET;
342 if (length > 0) {
343 proto_tree_add_item(parameter_tree, hf_policy_value, parameter_tvb, POLICY_VALUE_OFFSET, length, ENC_NA);
345 break;
349 static void
350 dissect_pool_handle_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
352 uint16_t handle_length;
353 proto_item* pi;
355 handle_length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET) - PARAMETER_HEADER_LENGTH;
356 pi = proto_tree_add_item(parameter_tree, hf_pool_handle, parameter_tvb, POOL_HANDLE_OFFSET, handle_length, ENC_NA);
358 proto_item_append_text(pi, " (%s)",
359 tvb_format_text(wmem_packet_scope(), parameter_tvb, POOL_HANDLE_OFFSET, handle_length));
362 static void
363 // NOLINTNEXTLINE(misc-no-recursion)
364 dissect_pool_element_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
366 tvbuff_t* parameters_tvb;
368 proto_tree_add_item(parameter_tree, hf_pe_pe_identifier, parameter_tvb, PE_PE_IDENTIFIER_OFFSET, PE_PE_IDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
369 proto_tree_add_item(parameter_tree, hf_home_enrp_id, parameter_tvb, HOME_ENRP_INDENTIFIER_OFFSET, HOME_ENRP_INDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
370 proto_tree_add_item(parameter_tree, hf_reg_life, parameter_tvb, REGISTRATION_LIFE_OFFSET, REGISTRATION_LIFE_LENGTH, ENC_BIG_ENDIAN);
372 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, USER_TRANSPORT_PARAMETER_OFFSET);
373 dissect_parameters(parameters_tvb, pinfo, parameter_tree);
376 static void
377 // NOLINTNEXTLINE(misc-no-recursion)
378 dissect_server_information_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
380 tvbuff_t *parameters_tvb;
382 proto_tree_add_item(parameter_tree, hf_server_identifier, parameter_tvb, SERVER_ID_OFFSET, SERVER_ID_LENGTH, ENC_BIG_ENDIAN);
384 parameters_tvb = tvb_new_subset_remaining(parameter_tvb, SERVER_TRANSPORT_OFFSET);
385 dissect_parameters(parameters_tvb, pinfo, parameter_tree);
388 static void
389 // NOLINTNEXTLINE(misc-no-recursion)
390 dissect_operation_error_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *parameter_tree)
392 tvbuff_t *error_causes_tvb;
394 error_causes_tvb = tvb_new_subset_remaining(parameter_tvb, ERROR_CAUSES_OFFSET);
395 dissect_error_causes(error_causes_tvb, pinfo, parameter_tree);
398 static void
399 dissect_cookie_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
401 uint16_t cookie_length;
403 cookie_length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET) - PARAMETER_HEADER_LENGTH;
404 if (cookie_length > 0)
405 proto_tree_add_item(parameter_tree, hf_cookie, parameter_tvb, COOKIE_OFFSET, cookie_length, ENC_NA);
406 proto_item_append_text(parameter_item, " (%u byte%s)", cookie_length, plurality(cookie_length, "", "s"));
409 static void
410 dissect_pe_identifier_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
412 proto_tree_add_item(parameter_tree, hf_pe_identifier, parameter_tvb, PE_IDENTIFIER_OFFSET, PE_IDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
413 proto_item_append_text(parameter_item, " (0x%x)", tvb_get_ntohl(parameter_tvb, PE_IDENTIFIER_OFFSET));
416 static void
417 dissect_pe_checksum_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
419 proto_tree_add_checksum(parameter_tree, parameter_tvb, PE_CHECKSUM_OFFSET, hf_pe_checksum, -1, NULL, NULL, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
420 proto_item_append_text(parameter_item, " (0x%x)", tvb_get_ntohs(parameter_tvb, PE_CHECKSUM_OFFSET));
423 static void
424 dissect_handle_resolution_option_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree)
426 proto_tree_add_item(parameter_tree, hf_hropt_items, parameter_tvb, HROPT_ITEMS_OFFSET, HROPT_ITEMS_LENGTH, ENC_BIG_ENDIAN);
429 static void
430 dissect_unknown_parameter(tvbuff_t *parameter_tvb, proto_tree *parameter_tree, proto_item *parameter_item)
432 uint16_t type, parameter_value_length;
434 type = tvb_get_ntohs(parameter_tvb, PARAMETER_TYPE_OFFSET);
435 parameter_value_length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET) - PARAMETER_HEADER_LENGTH;
437 if (parameter_value_length > 0)
438 proto_tree_add_item(parameter_tree, hf_parameter_value, parameter_tvb, PARAMETER_VALUE_OFFSET, parameter_value_length, ENC_NA);
440 proto_item_append_text(parameter_item, " (type %u and %u byte%s value)", type, parameter_value_length, plurality(parameter_value_length, "", "s"));
443 static void
444 // NOLINTNEXTLINE(misc-no-recursion)
445 dissect_parameter(tvbuff_t *parameter_tvb, packet_info *pinfo, proto_tree *asap_tree)
447 uint16_t type, length, padding_length;
448 proto_item *parameter_item;
449 proto_tree *parameter_tree;
451 /* extract tag and length from the parameter */
452 type = tvb_get_ntohs(parameter_tvb, PARAMETER_TYPE_OFFSET);
453 length = tvb_get_ntohs(parameter_tvb, PARAMETER_LENGTH_OFFSET);
454 padding_length = tvb_reported_length(parameter_tvb) - length;
456 /* create proto_tree stuff */
457 parameter_tree = proto_tree_add_subtree(asap_tree, parameter_tvb, PARAMETER_HEADER_OFFSET, -1,
458 ett_asap_parameter, &parameter_item, val_to_str_const(type, parameter_type_values, "Unknown Parameter"));
460 /* add tag and length to the asap tree */
461 proto_tree_add_item(parameter_tree, hf_parameter_type, parameter_tvb, PARAMETER_TYPE_OFFSET, PARAMETER_TYPE_LENGTH, ENC_BIG_ENDIAN);
462 proto_tree_add_item(parameter_tree, hf_parameter_length, parameter_tvb, PARAMETER_LENGTH_OFFSET, PARAMETER_LENGTH_LENGTH, ENC_BIG_ENDIAN);
464 increment_dissection_depth(pinfo);
465 switch(type) {
466 case IPV4_ADDRESS_PARAMETER_TYPE:
467 dissect_ipv4_parameter(parameter_tvb, parameter_tree, parameter_item);
468 break;
469 case IPV6_ADDRESS_PARAMETER_TYPE:
470 dissect_ipv6_parameter(parameter_tvb, parameter_tree, parameter_item);
471 break;
472 case DCCP_TRANSPORT_PARAMETER_TYPE:
473 dissect_dccp_transport_parameter(parameter_tvb, pinfo, parameter_tree);
474 break;
475 case SCTP_TRANSPORT_PARAMETER_TYPE:
476 dissect_sctp_transport_parameter(parameter_tvb, pinfo, parameter_tree);
477 break;
478 case TCP_TRANSPORT_PARAMETER_TYPE:
479 dissect_tcp_transport_parameter(parameter_tvb, pinfo, parameter_tree);
480 break;
481 case UDP_TRANSPORT_PARAMETER_TYPE:
482 dissect_udp_transport_parameter(parameter_tvb, pinfo, parameter_tree);
483 break;
484 case UDP_LITE_TRANSPORT_PARAMETER_TYPE:
485 dissect_udp_lite_transport_parameter(parameter_tvb, pinfo, parameter_tree);
486 break;
487 case POOL_MEMBER_SELECTION_POLICY_PARAMETER_TYPE:
488 dissect_pool_member_selection_policy_parameter(parameter_tvb, parameter_tree);
489 break;
490 case POOL_HANDLE_PARAMETER_TYPE:
491 dissect_pool_handle_parameter(parameter_tvb, parameter_tree);
492 break;
493 case POOL_ELEMENT_PARAMETER_TYPE:
494 dissect_pool_element_parameter(parameter_tvb, pinfo, parameter_tree);
495 break;
496 case SERVER_INFORMATION_PARAMETER_TYPE:
497 dissect_server_information_parameter(parameter_tvb, pinfo, parameter_tree);
498 break;
499 case OPERATION_ERROR_PARAMETER_TYPE:
500 dissect_operation_error_parameter(parameter_tvb, pinfo, parameter_tree);
501 break;
502 case COOKIE_PARAMETER_TYPE:
503 dissect_cookie_parameter(parameter_tvb, parameter_tree, parameter_item);
504 break;
505 case PE_IDENTIFIER_PARAMETER_TYPE:
506 dissect_pe_identifier_parameter(parameter_tvb, parameter_tree, parameter_item);
507 break;
508 case PE_CHECKSUM_PARAMETER_TYPE:
509 dissect_pe_checksum_parameter(parameter_tvb, parameter_tree, parameter_item);
510 break;
511 case HANDLE_RESOLUTION_OPTION_PARAMETER_TYPE:
512 dissect_handle_resolution_option_parameter(parameter_tvb, parameter_tree);
513 break;
514 default:
515 dissect_unknown_parameter(parameter_tvb, parameter_tree, parameter_item);
516 break;
518 decrement_dissection_depth(pinfo);
520 if (padding_length > 0)
521 proto_tree_add_item(parameter_tree, hf_parameter_padding, parameter_tvb, PARAMETER_HEADER_OFFSET + length, padding_length, ENC_NA);
524 static void
525 // NOLINTNEXTLINE(misc-no-recursion)
526 dissect_parameters(tvbuff_t *parameters_tvb, packet_info *pinfo, proto_tree *tree)
528 int offset, length, total_length, remaining_length;
529 tvbuff_t *parameter_tvb;
531 offset = 0;
532 while((remaining_length = tvb_reported_length_remaining(parameters_tvb, offset)) > 0) {
533 length = tvb_get_ntohs(parameters_tvb, offset + PARAMETER_LENGTH_OFFSET);
534 total_length = WS_ROUNDUP_4(length);
535 if (remaining_length >= length)
536 total_length = MIN(total_length, remaining_length);
537 /* create a tvb for the parameter including the padding bytes */
538 parameter_tvb = tvb_new_subset_length(parameters_tvb, offset, total_length);
539 dissect_parameter(parameter_tvb, pinfo, tree);
540 /* get rid of the handled parameter */
541 offset += total_length;
545 /* Dissectors for messages. This is specific to ASAP */
547 #define REGISTRATION_MESSAGE_TYPE 0x01
548 #define DEREGISTRATION_MESSAGE_TYPE 0x02
549 #define REGISTRATION_RESPONSE_MESSAGE_TYPE 0x03
550 #define DEREGISTRATION_RESPONSE_MESSAGE_TYPE 0x04
551 #define HANDLE_RESOLUTION_MESSAGE_TYPE 0x05
552 #define HANDLE_RESOLUTION_RESPONSE_MESSAGE_TYPE 0x06
553 #define ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE 0x07
554 #define ENDPOINT_KEEP_ALIVE_ACK_MESSAGE_TYPE 0x08
555 #define ENDPOINT_UNREACHABLE_MESSAGE_TYPE 0x09
556 #define SERVER_ANNOUNCE_MESSAGE_TYPE 0x0a
557 #define COOKIE_MESSAGE_TYPE 0x0b
558 #define COOKIE_ECHO_MESSAGE_TYPE 0x0c
559 #define BUSINESS_CARD_MESSAGE_TYPE 0x0d
560 #define ERROR_MESSAGE_TYPE 0x0e
562 static const value_string message_type_values[] = {
563 { REGISTRATION_MESSAGE_TYPE, "ASAP Registration" },
564 { DEREGISTRATION_MESSAGE_TYPE, "ASAP Deregistration" },
565 { REGISTRATION_RESPONSE_MESSAGE_TYPE, "ASAP Registration Response" },
566 { DEREGISTRATION_RESPONSE_MESSAGE_TYPE, "ASAP Deregistration Response" },
567 { HANDLE_RESOLUTION_MESSAGE_TYPE, "ASAP Handle Resolution" },
568 { HANDLE_RESOLUTION_RESPONSE_MESSAGE_TYPE, "ASAP Handle Resolution Response" },
569 { ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE, "ASAP Endpoint Keep-Alive" },
570 { ENDPOINT_KEEP_ALIVE_ACK_MESSAGE_TYPE, "ASAP Endpoint Keep-Alive Acknowledgement" },
571 { ENDPOINT_UNREACHABLE_MESSAGE_TYPE, "ASAP Endpoint Unreachable" },
572 { SERVER_ANNOUNCE_MESSAGE_TYPE, "ASAP Server Announce" },
573 { COOKIE_MESSAGE_TYPE, "ASAP Cookie" },
574 { COOKIE_ECHO_MESSAGE_TYPE, "ASAP Cookie Echo" },
575 { BUSINESS_CARD_MESSAGE_TYPE, "ASAP Business Card" },
576 { ERROR_MESSAGE_TYPE, "ASAP Error" },
577 { 0, NULL } };
579 #define SERVER_IDENTIFIER_OFFSET MESSAGE_VALUE_OFFSET
580 #define SERVER_IDENTIFIER_LENGTH 4
582 #define HOME_ENRP_SERVER_BIT_MASK 0x01
583 #define REJECT_BIT_MASK 0x01
585 static const true_false_string home_enrp_server_bit_value = {
586 "Want to be new ENRP server",
587 "Do not want to be new ENRP server"
590 static const true_false_string reject_bit_value = {
591 "Rejected",
592 "Accepted"
595 static void
596 // NOLINTNEXTLINE(misc-no-recursion)
597 dissect_asap_message(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *asap_tree)
599 asap_tap_rec_t *tap_rec;
600 tvbuff_t *parameters_tvb;
601 proto_item *flags_item;
602 proto_tree *flags_tree;
603 uint8_t type;
605 type = tvb_get_uint8(message_tvb, MESSAGE_TYPE_OFFSET);
606 /* pinfo is NULL only if dissect_asap_message is called via dissect_error_cause */
607 if (!pinfo->flags.in_error_pkt) {
608 tap_rec = wmem_new0(pinfo->pool, asap_tap_rec_t);
609 tap_rec->type = type;
610 tap_rec->size = tvb_get_ntohs(message_tvb, MESSAGE_LENGTH_OFFSET);
611 tap_rec->type_string = val_to_str_const(tap_rec->type, message_type_values, "Unknown ASAP type");
612 tap_queue_packet(asap_tap, pinfo, tap_rec);
614 col_add_fstr(pinfo->cinfo, COL_INFO, "%s ", val_to_str_const(type, message_type_values, "Unknown ASAP type"));
617 if (asap_tree) {
618 proto_tree_add_item(asap_tree, hf_message_type, message_tvb, MESSAGE_TYPE_OFFSET, MESSAGE_TYPE_LENGTH, ENC_BIG_ENDIAN);
619 flags_item = proto_tree_add_item(asap_tree, hf_message_flags, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
620 flags_tree = proto_item_add_subtree(flags_item, ett_asap_flags);
621 if (type == REGISTRATION_RESPONSE_MESSAGE_TYPE) {
622 proto_tree_add_item(flags_tree, hf_reject_bit, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
624 if (type == ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE) {
625 proto_tree_add_item(flags_tree, hf_home_enrp_server_bit, message_tvb, MESSAGE_FLAGS_OFFSET, MESSAGE_FLAGS_LENGTH, ENC_BIG_ENDIAN);
627 proto_tree_add_item(asap_tree, hf_message_length, message_tvb, MESSAGE_LENGTH_OFFSET, MESSAGE_LENGTH_LENGTH, ENC_BIG_ENDIAN);
628 if ((type == SERVER_ANNOUNCE_MESSAGE_TYPE) || (type == ENDPOINT_KEEP_ALIVE_MESSAGE_TYPE)) {
629 proto_tree_add_item(asap_tree, hf_server_identifier, message_tvb, SERVER_IDENTIFIER_OFFSET, SERVER_IDENTIFIER_LENGTH, ENC_BIG_ENDIAN);
630 parameters_tvb = tvb_new_subset_remaining(message_tvb, MESSAGE_VALUE_OFFSET + SERVER_IDENTIFIER_LENGTH);
631 } else {
632 parameters_tvb = tvb_new_subset_remaining(message_tvb, MESSAGE_VALUE_OFFSET);
634 dissect_parameters(parameters_tvb, pinfo, asap_tree);
638 static int
639 // NOLINTNEXTLINE(misc-no-recursion)
640 dissect_asap(tvbuff_t *message_tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
642 proto_item *asap_item;
643 proto_tree *asap_tree;
645 /* pinfo is NULL only if dissect_asap is called from dissect_error_cause */
646 if (!pinfo->flags.in_error_pkt) {
647 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ASAP");
650 /* create the asap protocol tree */
651 asap_item = proto_tree_add_item(tree, proto_asap, message_tvb, 0, -1, ENC_NA);
652 asap_tree = proto_item_add_subtree(asap_item, ett_asap);
654 /* dissect the message */
655 dissect_asap_message(message_tvb, pinfo, asap_tree);
656 return tvb_captured_length(message_tvb);
659 /* TAP STAT INFO */
660 typedef enum
662 MESSAGE_TYPE_COLUMN = 0,
663 MESSAGES_COLUMN,
664 MESSAGES_SHARE_COLUMN,
665 BYTES_COLUMN,
666 BYTES_SHARE_COLUMN,
667 FIRST_SEEN_COLUMN,
668 LAST_SEEN_COLUMN,
669 INTERVAL_COLUMN,
670 MESSAGE_RATE_COLUMN,
671 BYTE_RATE_COLUMN
672 } asap_stat_columns;
674 static stat_tap_table_item asap_stat_fields[] = {
675 { TABLE_ITEM_STRING, TAP_ALIGN_LEFT, "ASAP Message Type", "%-25s" },
676 { TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Messages ", "%u" },
677 { TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Messages Share (%)" , "%1.3f %%" },
678 { TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Bytes (B)", "%u" },
679 { TABLE_ITEM_UINT, TAP_ALIGN_RIGHT, "Bytes Share (%) ", "%1.3f %%" },
680 { TABLE_ITEM_FLOAT, TAP_ALIGN_LEFT, "First Seen (s)", "%1.6f" },
681 { TABLE_ITEM_FLOAT, TAP_ALIGN_LEFT, "Last Seen (s)", "%1.6f" },
682 { TABLE_ITEM_FLOAT, TAP_ALIGN_LEFT, "Interval (s)", "%1.6f" },
683 { TABLE_ITEM_FLOAT, TAP_ALIGN_LEFT, "Message Rate (Msg/s)", "%1.2f" },
684 { TABLE_ITEM_FLOAT, TAP_ALIGN_LEFT, "Byte Rate (B/s)", "%1.2f" }
687 static void asap_stat_init(stat_tap_table_ui* new_stat)
689 const char *table_name = "ASAP Statistics";
690 int num_fields = array_length(asap_stat_fields);
691 stat_tap_table *table;
692 int i = 0;
693 stat_tap_table_item_type items[array_length(asap_stat_fields)];
695 table = stat_tap_find_table(new_stat, table_name);
696 if (table) {
697 if (new_stat->stat_tap_reset_table_cb) {
698 new_stat->stat_tap_reset_table_cb(table);
700 return;
703 table = stat_tap_init_table(table_name, num_fields, 0, NULL);
704 stat_tap_add_table(new_stat, table);
706 memset(items, 0x0, sizeof(items));
707 /* Add a row for each value type */
708 while (message_type_values[i].strptr) {
709 items[MESSAGE_TYPE_COLUMN].type = TABLE_ITEM_STRING;
710 items[MESSAGE_TYPE_COLUMN].value.string_value = message_type_values[i].strptr;
711 items[MESSAGES_COLUMN].type = TABLE_ITEM_UINT;
712 items[MESSAGES_COLUMN].value.uint_value = 0;
713 items[MESSAGES_SHARE_COLUMN].type = TABLE_ITEM_NONE;
714 items[MESSAGES_SHARE_COLUMN].value.float_value = -1.0;
715 items[BYTES_COLUMN].type = TABLE_ITEM_UINT;
716 items[BYTES_COLUMN].value.uint_value = 0;
717 items[BYTES_SHARE_COLUMN].type = TABLE_ITEM_NONE;
718 items[BYTES_SHARE_COLUMN].value.float_value = -1.0;
719 items[FIRST_SEEN_COLUMN].type = TABLE_ITEM_NONE;
720 items[FIRST_SEEN_COLUMN].value.float_value = DBL_MAX;
721 items[LAST_SEEN_COLUMN].type = TABLE_ITEM_NONE;
722 items[LAST_SEEN_COLUMN].value.float_value = DBL_MIN;
723 items[INTERVAL_COLUMN].type = TABLE_ITEM_NONE;
724 items[INTERVAL_COLUMN].value.float_value = -1.0;
725 items[MESSAGE_RATE_COLUMN].type = TABLE_ITEM_NONE;
726 items[MESSAGE_RATE_COLUMN].value.float_value = -1.0;
727 items[BYTE_RATE_COLUMN].type = TABLE_ITEM_NONE;
728 items[BYTE_RATE_COLUMN].value.float_value = -1.0;
729 stat_tap_init_table_row(table, i, num_fields, items);
730 i++;
734 static tap_packet_status
735 asap_stat_packet(void* tapdata, packet_info* pinfo _U_, epan_dissect_t* edt _U_, const void* data, tap_flags_t flags _U_)
737 stat_data_t* stat_data = (stat_data_t*)tapdata;
738 const asap_tap_rec_t* tap_rec = (const asap_tap_rec_t*)data;
739 stat_tap_table* table;
740 stat_tap_table_item_type* msg_data;
741 int idx;
742 uint64_t messages;
743 uint64_t bytes;
744 int i = 0;
745 double firstSeen = -1.0;
746 double lastSeen = -1.0;
748 idx = str_to_val_idx(tap_rec->type_string, message_type_values);
749 if (idx < 0)
750 return TAP_PACKET_DONT_REDRAW;
752 table = g_array_index(stat_data->stat_tap_data->tables, stat_tap_table*, 0);
754 /* Update packets counter */
755 asap_total_msgs++;
756 msg_data = stat_tap_get_field_data(table, idx, MESSAGES_COLUMN);
757 msg_data->value.uint_value++;
758 messages = msg_data->value.uint_value;
759 stat_tap_set_field_data(table, idx, MESSAGES_COLUMN, msg_data);
761 /* Update bytes counter */
762 asap_total_bytes += tap_rec->size;
763 msg_data = stat_tap_get_field_data(table, idx, BYTES_COLUMN);
764 msg_data->value.uint_value += tap_rec->size;
765 bytes = msg_data->value.uint_value;
766 stat_tap_set_field_data(table, idx, BYTES_COLUMN, msg_data);
768 /* Update messages and bytes share */
769 while (message_type_values[i].strptr) {
770 msg_data = stat_tap_get_field_data(table, i, MESSAGES_COLUMN);
771 const unsigned m = msg_data->value.uint_value;
772 msg_data = stat_tap_get_field_data(table, i, BYTES_COLUMN);
773 const unsigned b = msg_data->value.uint_value;
775 msg_data = stat_tap_get_field_data(table, i, MESSAGES_SHARE_COLUMN);
776 msg_data->type = TABLE_ITEM_FLOAT;
777 msg_data->value.float_value = 100.0 * m / (double)asap_total_msgs;
778 stat_tap_set_field_data(table, i, MESSAGES_SHARE_COLUMN, msg_data);
780 msg_data = stat_tap_get_field_data(table, i, BYTES_SHARE_COLUMN);
781 msg_data->type = TABLE_ITEM_FLOAT;
782 msg_data->value.float_value = 100.0 * b / (double)asap_total_bytes;
783 stat_tap_set_field_data(table, i, BYTES_SHARE_COLUMN, msg_data);
784 i++;
787 /* Update first seen time */
788 if (pinfo->presence_flags & PINFO_HAS_TS) {
789 msg_data = stat_tap_get_field_data(table, idx, FIRST_SEEN_COLUMN);
790 msg_data->type = TABLE_ITEM_FLOAT;
791 msg_data->value.float_value = MIN(msg_data->value.float_value, nstime_to_sec(&pinfo->rel_ts));
792 firstSeen = msg_data->value.float_value;
793 stat_tap_set_field_data(table, idx, FIRST_SEEN_COLUMN, msg_data);
796 /* Update last seen time */
797 if (pinfo->presence_flags & PINFO_HAS_TS) {
798 msg_data = stat_tap_get_field_data(table, idx, LAST_SEEN_COLUMN);
799 msg_data->type = TABLE_ITEM_FLOAT;
800 msg_data->value.float_value = MAX(msg_data->value.float_value, nstime_to_sec(&pinfo->rel_ts));
801 lastSeen = msg_data->value.float_value;
802 stat_tap_set_field_data(table, idx, LAST_SEEN_COLUMN, msg_data);
805 if ((lastSeen - firstSeen) > 0.0) {
806 /* Update interval */
807 msg_data = stat_tap_get_field_data(table, idx, INTERVAL_COLUMN);
808 msg_data->type = TABLE_ITEM_FLOAT;
809 msg_data->value.float_value = lastSeen - firstSeen;
810 stat_tap_set_field_data(table, idx, INTERVAL_COLUMN, msg_data);
812 /* Update message rate */
813 msg_data = stat_tap_get_field_data(table, idx, MESSAGE_RATE_COLUMN);
814 msg_data->type = TABLE_ITEM_FLOAT;
815 msg_data->value.float_value = messages / (lastSeen - firstSeen);
816 stat_tap_set_field_data(table, idx, MESSAGE_RATE_COLUMN, msg_data);
818 /* Update byte rate */
819 msg_data = stat_tap_get_field_data(table, idx, BYTE_RATE_COLUMN);
820 msg_data->type = TABLE_ITEM_FLOAT;
821 msg_data->value.float_value = bytes / (lastSeen - firstSeen);
822 stat_tap_set_field_data(table, idx, BYTE_RATE_COLUMN, msg_data);
825 return TAP_PACKET_REDRAW;
828 static void
829 asap_stat_reset(stat_tap_table* table)
831 unsigned element;
832 stat_tap_table_item_type* item_data;
834 for (element = 0; element < table->num_elements; element++) {
835 item_data = stat_tap_get_field_data(table, element, MESSAGES_COLUMN);
836 item_data->value.uint_value = 0;
837 stat_tap_set_field_data(table, element, MESSAGES_COLUMN, item_data);
839 item_data = stat_tap_get_field_data(table, element, MESSAGES_SHARE_COLUMN);
840 item_data->type = TABLE_ITEM_NONE;
841 item_data->value.float_value = -1.0;
842 stat_tap_set_field_data(table, element, MESSAGES_SHARE_COLUMN, item_data);
844 item_data = stat_tap_get_field_data(table, element, BYTES_COLUMN);
845 item_data->value.uint_value = 0;
846 stat_tap_set_field_data(table, element, BYTES_COLUMN, item_data);
848 item_data = stat_tap_get_field_data(table, element, BYTES_SHARE_COLUMN);
849 item_data->type = TABLE_ITEM_NONE;
850 item_data->value.float_value = -1.0;
851 stat_tap_set_field_data(table, element, BYTES_SHARE_COLUMN, item_data);
853 item_data = stat_tap_get_field_data(table, element, FIRST_SEEN_COLUMN);
854 item_data->type = TABLE_ITEM_NONE;
855 item_data->value.float_value = DBL_MAX;
856 stat_tap_set_field_data(table, element, FIRST_SEEN_COLUMN, item_data);
858 item_data = stat_tap_get_field_data(table, element, LAST_SEEN_COLUMN);
859 item_data->type = TABLE_ITEM_NONE;
860 item_data->value.float_value = DBL_MIN;
861 stat_tap_set_field_data(table, element, LAST_SEEN_COLUMN, item_data);
863 item_data = stat_tap_get_field_data(table, element, INTERVAL_COLUMN);
864 item_data->type = TABLE_ITEM_NONE;
865 item_data->value.float_value = -1.0;
866 stat_tap_set_field_data(table, element, INTERVAL_COLUMN, item_data);
868 item_data = stat_tap_get_field_data(table, element, MESSAGE_RATE_COLUMN);
869 item_data->type = TABLE_ITEM_NONE;
870 item_data->value.float_value = -1.0;
871 stat_tap_set_field_data(table, element, MESSAGE_RATE_COLUMN, item_data);
873 item_data = stat_tap_get_field_data(table, element, BYTE_RATE_COLUMN);
874 item_data->type = TABLE_ITEM_NONE;
875 item_data->value.float_value = -1.0;
876 stat_tap_set_field_data(table, element, BYTE_RATE_COLUMN, item_data);
878 asap_total_msgs = 0;
879 asap_total_bytes = 0;
882 /* Register the protocol with Wireshark */
883 void
884 proto_register_asap(void)
887 /* Setup list of header fields */
888 static hf_register_info hf[] = {
889 { &hf_message_type, { "Type", "asap.message_type", FT_UINT8, BASE_DEC, VALS(message_type_values), 0x0, NULL, HFILL } },
890 { &hf_message_flags, { "Flags", "asap.message_flags", FT_UINT8, BASE_HEX, NULL, 0x0, NULL, HFILL } },
891 { &hf_message_length, { "Length", "asap.message_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
892 { &hf_cause_code, { "Cause Code", "asap.cause_code", FT_UINT16, BASE_HEX, VALS(cause_code_values), 0x0, NULL, HFILL } },
893 { &hf_cause_length, { "Cause Length", "asap.cause_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
894 { &hf_cause_info, { "Cause Info", "asap.cause_info", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
895 { &hf_cause_padding, { "Padding", "asap.cause_padding", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
896 { &hf_parameter_type, { "Parameter Type", "asap.parameter_type", FT_UINT16, BASE_HEX, VALS(parameter_type_values), 0x0, NULL, HFILL } },
897 { &hf_parameter_length, { "Parameter Length", "asap.parameter_length", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
898 { &hf_parameter_value, { "Parameter Value", "asap.parameter_value", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
899 { &hf_parameter_padding, { "Padding", "asap.parameter_padding", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
900 { &hf_parameter_ipv4_address, { "IP Version 4 Address", "asap.ipv4_address", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL } },
901 { &hf_parameter_ipv6_address, { "IP Version 6 Address", "asap.ipv6_address", FT_IPv6, BASE_NONE, NULL, 0x0, NULL, HFILL } },
902 { &hf_dccp_port, { "Port", "asap.dccp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
903 { &hf_dccp_reserved, { "Reserved", "asap.dccp_transport_reserved", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
904 { &hf_dccp_service_code, { "Service Code", "asap.dccp_transport_service_code", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
905 { &hf_sctp_port, { "Port", "asap.sctp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
906 { &hf_transport_use, { "Transport Use", "asap.transport_use", FT_UINT16, BASE_DEC, VALS(transport_use_values), 0x0, NULL, HFILL } },
907 { &hf_tcp_port, { "Port", "asap.tcp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
908 { &hf_udp_port, { "Port", "asap.udp_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
909 { &hf_udp_reserved, { "Reserved", "asap.udp_transport_reserved", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
910 { &hf_udp_lite_port, { "Port", "asap.udp_lite_transport_port", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
911 { &hf_udp_lite_reserved, { "Reserved", "asap.udp_lite_transport_reserved", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
912 { &hf_policy_type, { "Policy Type", "asap.pool_member_selection_policy_type", FT_UINT32, BASE_HEX, VALS(policy_type_values), 0x0, NULL, HFILL } },
913 { &hf_policy_weight, { "Policy Weight", "asap.pool_member_selection_policy_weight", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
914 { &hf_policy_priority, { "Policy Priority", "asap.pool_member_selection_policy_priority", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
915 { &hf_policy_load, { "Policy Load", "asap.pool_member_selection_policy_load", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
916 { &hf_policy_degradation, { "Policy Degradation", "asap.pool_member_selection_policy_degradation", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
917 { &hf_policy_loaddpf, { "Policy Load DPF", "asap.pool_member_selection_policy_load_dpf", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
918 { &hf_policy_weightdpf, { "Policy Weight DPF", "asap.pool_member_selection_policy_weight_dpf", FT_DOUBLE, BASE_NONE, NULL, 0x0, NULL, HFILL } },
919 { &hf_policy_distance, { "Policy Distance", "asap.pool_member_selection_policy_distance", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
920 { &hf_policy_value, { "Policy Value", "asap.pool_member_selection_policy_value", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
921 { &hf_pool_handle, { "Pool Handle", "asap.pool_handle_pool_handle", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
922 { &hf_pe_pe_identifier, { "PE Identifier", "asap.pool_element_pe_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
923 { &hf_home_enrp_id, { "Home ENRP Server Identifier", "asap.pool_element_home_enrp_server_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
924 { &hf_reg_life, { "Registration Life", "asap.pool_element_registration_life", FT_INT32, BASE_DEC|BASE_UNIT_STRING, UNS(&units_milliseconds), 0x0, NULL, HFILL } },
925 { &hf_cookie, { "Cookie", "asap.cookie", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL } },
926 { &hf_pe_identifier, { "PE Identifier", "asap.pe_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
927 { &hf_pe_checksum, { "PE Checksum", "asap.pe_checksum", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL } },
928 { &hf_hropt_items, { "Items", "asap.hropt_items", FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL } },
929 { &hf_server_identifier, { "Server Identifier", "asap.server_identifier", FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL } },
930 { &hf_home_enrp_server_bit, { "H Bit", "asap.h_bit", FT_BOOLEAN, 8, TFS(&home_enrp_server_bit_value), HOME_ENRP_SERVER_BIT_MASK, NULL, HFILL } },
931 { &hf_reject_bit, { "R Bit", "asap.r_bit", FT_BOOLEAN, 8, TFS(&reject_bit_value), REJECT_BIT_MASK, NULL, HFILL } },
934 /* Setup protocol subtree array */
935 static int *ett[] = {
936 &ett_asap,
937 &ett_asap_flags,
938 &ett_asap_parameter,
939 &ett_asap_cause,
942 static tap_param asap_stat_params[] = {
943 { PARAM_FILTER, "filter", "Filter", NULL, true }
946 static stat_tap_table_ui asap_stat_table = {
947 REGISTER_STAT_GROUP_RSERPOOL,
948 "ASAP Statistics",
949 "asap",
950 "asap,stat",
951 asap_stat_init,
952 asap_stat_packet,
953 asap_stat_reset,
954 NULL,
955 NULL,
956 array_length(asap_stat_fields), asap_stat_fields,
957 array_length(asap_stat_params), asap_stat_params,
958 NULL,
962 /* Register the protocol name and description */
963 proto_asap = proto_register_protocol("Aggregate Server Access Protocol", "ASAP", "asap");
965 /* Required function calls to register the header fields and subtrees used */
966 proto_register_field_array(proto_asap, hf, array_length(hf));
967 proto_register_subtree_array(ett, array_length(ett));
968 asap_tap = register_tap("asap");
970 asap_handle = register_dissector("asap", dissect_asap, proto_asap);
972 register_stat_tap_table_ui(&asap_stat_table);
975 void
976 proto_reg_handoff_asap(void)
978 dissector_add_uint("sctp.ppi", ASAP_PAYLOAD_PROTOCOL_ID, asap_handle);
979 dissector_add_uint_with_preference("udp.port", ASAP_UDP_PORT, asap_handle);
980 dissector_add_uint_with_preference("tcp.port", ASAP_TCP_PORT, asap_handle);
981 dissector_add_uint("sctp.port", ASAP_SCTP_PORT, asap_handle);
985 * Editor modelines - https://www.wireshark.org/tools/modelines.html
987 * Local Variables:
988 * c-basic-offset: 2
989 * tab-width: 8
990 * indent-tabs-mode: nil
991 * End:
993 * ex: set shiftwidth=2 tabstop=8 expandtab:
994 * :indentSize=2:tabSize=8:noTabs=true: