2 * Routines for Netscaler HA heartbeat protocol dissection
3 * Copyright 2008, Sandhya Gopinath <Sandhya.Gopinath@citrix.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
16 #include <wsutil/array.h>
18 void proto_register_ns_ha(void);
19 void proto_reg_handoff_ns_ha(void);
21 static dissector_handle_t nsha_handle
;
23 static int proto_ns_ha
;
25 static int ett_nsha_flags
;
27 static int hf_nsha_signature
;
28 static int hf_nsha_version
;
29 static int hf_nsha_app
;
30 static int hf_nsha_type
;
31 static int hf_nsha_state
;
32 static int hf_nsha_startime
;
33 static int hf_nsha_masterstate
;
34 static int hf_nsha_release
;
35 static int hf_nsha_inc
;
36 static int hf_nsha_syncstate
;
37 static int hf_nsha_drinc
;
38 static int hf_nsha_flags
;
39 static int hf_nsha_flags_vm
;
40 static int hf_nsha_flags_sp
;
41 static int hf_nsha_flags_propdis
;
42 static int hf_nsha_flags_inc
;
43 static int hf_nsha_flags_sslfail
;
44 static int hf_nsha_flags_nossl
;
46 static const value_string ns_ha_app_vals
[] = {
48 { 0x01, "REMOTE IOCTL" },
53 static const value_string ns_ha_type_vals
[] = {
60 static const value_string ns_ha_state_vals
[] = {
65 { 0x04, "PARTIAL_FAIL" },
66 { 0x05, "MONITOR_FAIL" },
67 { 0x06, "MONITOR_OK" },
68 { 0x07, "COMPLETE_FAIL" },
71 { 0x0A, "PARTIAL_FAIL_SSL" },
72 { 0x0B, "ROUTEMONITOR_FAIL" },
77 static const value_string ns_ha_masterstate_vals
[] = {
81 { 0x03, "ALWAYS_SECONDARY" },
82 { 0x04, "FORCE_CHANGE" },
87 static const value_string ns_ha_syncstate_vals
[] = {
92 { 0x20, "IN PROGRESS" },
97 #define NSAHA_SSLCARD_DOWN 0x00000100
98 #define NSAHA_NO_DEVICES 0x00000200
99 #define NSAHA_INC_STATE 0x00001000
100 #define NSAHA_PROP_DISABLED 0x00002000
101 #define NSAHA_STAY_PRIMARY 0x00004000
102 #define NSAHA_VERSION_MISMATCH 0x00008000
104 static int * const ha_flags
[] = {
108 &hf_nsha_flags_propdis
,
109 &hf_nsha_flags_sslfail
,
110 &hf_nsha_flags_nossl
,
115 dissect_ns_ha(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
117 uint32_t offset
= 0, master_state
=0;
119 proto_tree
*ns_ha_tree
;
120 uint32_t version
, state
;
122 /* It is Netscaler HA heartbeat packet. */
123 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "NS-HA");
124 col_clear(pinfo
->cinfo
, COL_INFO
);
126 ti
= proto_tree_add_protocol_format(tree
, proto_ns_ha
, tvb
, 0, -1, "NS HA Protocol");
127 ns_ha_tree
= proto_item_add_subtree(ti
, ett_nsha
);
129 proto_tree_add_item(ns_ha_tree
, hf_nsha_signature
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
132 proto_tree_add_item_ret_uint(ns_ha_tree
, hf_nsha_version
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
, &version
);
134 proto_tree_add_item(ns_ha_tree
, hf_nsha_app
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
136 proto_tree_add_item(ns_ha_tree
, hf_nsha_type
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
);
138 proto_tree_add_item_ret_uint(ns_ha_tree
, hf_nsha_state
, tvb
, offset
, 1, ENC_LITTLE_ENDIAN
, &state
);
142 /* all releases from 7.0 */
144 proto_tree_add_item(ns_ha_tree
, hf_nsha_startime
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
145 offset
+= 8; /* startime and rx_sn */
146 proto_tree_add_item_ret_uint(ns_ha_tree
, hf_nsha_masterstate
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
, &master_state
);
148 proto_tree_add_item(ns_ha_tree
, hf_nsha_release
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
150 proto_tree_add_bitmask(ns_ha_tree
, tvb
, offset
, hf_nsha_flags
, ett_nsha_flags
, ha_flags
, ENC_LITTLE_ENDIAN
);
152 proto_tree_add_item(ns_ha_tree
, hf_nsha_inc
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
154 proto_tree_add_item(ns_ha_tree
, hf_nsha_syncstate
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
156 offset
+= 96; /* interface information */
157 proto_tree_add_item(ns_ha_tree
, hf_nsha_drinc
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
162 proto_tree_add_item(ns_ha_tree
, hf_nsha_startime
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
163 offset
+= 8; /* startime and rx_sn */
164 proto_tree_add_item_ret_uint(ns_ha_tree
, hf_nsha_masterstate
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
, &master_state
);
166 proto_tree_add_item(ns_ha_tree
, hf_nsha_inc
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
168 proto_tree_add_item(ns_ha_tree
, hf_nsha_syncstate
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
170 proto_tree_add_bitmask(ns_ha_tree
, tvb
, offset
, hf_nsha_flags
, ett_nsha_flags
, ha_flags
, ENC_LITTLE_ENDIAN
);
173 offset
+= 96; /* interface information */
174 proto_tree_add_item(ns_ha_tree
, hf_nsha_drinc
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
181 offset
+= 8; /* sn and rx_sn */
182 proto_tree_add_item_ret_uint(ns_ha_tree
, hf_nsha_masterstate
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
, &master_state
);
184 proto_tree_add_item(ns_ha_tree
, hf_nsha_inc
, tvb
, offset
, 4, ENC_LITTLE_ENDIAN
);
192 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Node state: %s Master State: %s",
193 val_to_str(state
, ns_ha_state_vals
, "Unknown (%u)"),
194 val_to_str(master_state
, ns_ha_masterstate_vals
, "Unknown(%u)"));
196 return tvb_captured_length(tvb
);
200 proto_register_ns_ha(void)
202 static hf_register_info hf_nsha
[] = {
203 { &hf_nsha_signature
,
204 { "Signature", "nstrace.ha.signature", FT_UINT32
, BASE_HEX
, NULL
, 0x0,
208 { "Version", "nstrace.ha.version", FT_UINT8
, BASE_DEC
, NULL
, 0x0,
212 { "App", "nstrace.ha.app", FT_UINT8
, BASE_DEC
, VALS(ns_ha_app_vals
), 0x0,
216 { "Type", "nstrace.ha.type", FT_UINT8
, BASE_DEC
, VALS(ns_ha_type_vals
), 0x0,
220 { "State", "nstrace.ha.state", FT_UINT8
, BASE_DEC
, VALS(ns_ha_state_vals
), 0x0,
224 { "Start Time", "nstrace.ha.startime", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
227 { &hf_nsha_masterstate
,
228 { "Master State", "nstrace.ha.masterstate", FT_UINT32
, BASE_DEC
, VALS(ns_ha_masterstate_vals
), 0x0,
232 { "Release", "nstrace.ha.release", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
236 { "Incarnation Number", "nstrace.ha.inc", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
239 { &hf_nsha_syncstate
,
240 { "Sync State", "nstrace.ha.syncstate", FT_UINT32
, BASE_DEC
, VALS(ns_ha_syncstate_vals
), 0x0,
244 { "DR Incarnation Number", "nstrace.ha.drinc", FT_UINT32
, BASE_DEC
, NULL
, 0x0,
248 { "Flags", "nstrace.ha.flags", FT_UINT32
, BASE_HEX
, NULL
, 0x0,
252 { "Version Mismatch", "nstrace.ha.flags.versionmismatch", FT_BOOLEAN
, 32, TFS(&tfs_yes_no
), NSAHA_VERSION_MISMATCH
,
256 { "Stay Primary", "nstrace.ha.flags.stayprimary", FT_BOOLEAN
, 32, TFS(&tfs_yes_no
), NSAHA_STAY_PRIMARY
,
259 { &hf_nsha_flags_propdis
,
260 { "Propagation Disabled", "nstrace.ha.flags.propdis", FT_BOOLEAN
, 32, TFS(&tfs_yes_no
), NSAHA_PROP_DISABLED
,
263 { &hf_nsha_flags_inc
,
264 { "INC Enabled", "nstrace.ha.flags.inc", FT_BOOLEAN
, 32, TFS(&tfs_yes_no
), NSAHA_INC_STATE
,
267 { &hf_nsha_flags_sslfail
,
268 { "SSL Card Failure", "nstrace.ha.flags.sslfail", FT_BOOLEAN
, 32, TFS(&tfs_yes_no
), NSAHA_SSLCARD_DOWN
,
271 { &hf_nsha_flags_nossl
,
272 { "SSL Card Absent", "nstrace.ha.flags.nossl", FT_BOOLEAN
, 32, TFS(&tfs_yes_no
), NSAHA_NO_DEVICES
,
277 static int *ett
[] = {
282 proto_ns_ha
= proto_register_protocol("NetScaler HA Protocol", "NetScaler HA", "nstrace.ha");
283 proto_register_field_array(proto_ns_ha
, hf_nsha
, array_length(hf_nsha
));
284 proto_register_subtree_array(ett
, array_length(ett
));
286 nsha_handle
= register_dissector("nstrace.ha", dissect_ns_ha
, proto_ns_ha
);
289 void proto_reg_handoff_ns_ha(void)
291 dissector_add_for_decode_as("udp.port", nsha_handle
);
295 * Editor modelines - https://www.wireshark.org/tools/modelines.html
300 * indent-tabs-mode: t
303 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
304 * :indentSize=8:tabSize=8:noTabs=false: