Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-ns-ha.c
blobeb4e23dc33230687e387fb4ea46bd197bfa878a2
1 /* packet-ns-ha.c
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
12 #include "config.h"
14 #include <epan/packet.h>
15 #include <epan/tfs.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;
24 static int ett_nsha;
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[] = {
47 { 0x00, "BASE" },
48 { 0x01, "REMOTE IOCTL" },
50 { 0, NULL }
53 static const value_string ns_ha_type_vals[] = {
54 { 0x00, "MSG" },
55 { 0x01, "REQ_INIT" },
57 { 0, NULL }
60 static const value_string ns_ha_state_vals[] = {
61 { 0x00, "UNKNOWN" },
62 { 0x01, "INIT" },
63 { 0x02, "DOWN" },
64 { 0x03, "UP" },
65 { 0x04, "PARTIAL_FAIL" },
66 { 0x05, "MONITOR_FAIL" },
67 { 0x06, "MONITOR_OK" },
68 { 0x07, "COMPLETE_FAIL" },
69 { 0x08, "DUMB" },
70 { 0x09, "DISABLED" },
71 { 0x0A, "PARTIAL_FAIL_SSL" },
72 { 0x0B, "ROUTEMONITOR_FAIL" },
74 { 0, NULL }
77 static const value_string ns_ha_masterstate_vals[] = {
78 { 0x00, "INACTIVE" },
79 { 0x01, "CLAIMING" },
80 { 0x02, "ACTIVE" },
81 { 0x03, "ALWAYS_SECONDARY" },
82 { 0x04, "FORCE_CHANGE" },
84 { 0, NULL }
87 static const value_string ns_ha_syncstate_vals[] = {
88 { 0x00, "ENABLED" },
89 { 0x04, "FAILED" },
90 { 0x10, "SUCCESS" },
91 { 0x40, "DISABLED" },
92 { 0x20, "IN PROGRESS" },
94 { 0, NULL }
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[] = {
105 &hf_nsha_flags_vm,
106 &hf_nsha_flags_sp,
107 &hf_nsha_flags_inc,
108 &hf_nsha_flags_propdis,
109 &hf_nsha_flags_sslfail,
110 &hf_nsha_flags_nossl,
111 NULL
114 static int
115 dissect_ns_ha(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
117 uint32_t offset = 0, master_state=0;
118 proto_item *ti;
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);
130 offset += 4;
132 proto_tree_add_item_ret_uint(ns_ha_tree, hf_nsha_version, tvb, offset, 1, ENC_LITTLE_ENDIAN, &version);
133 offset += 1;
134 proto_tree_add_item(ns_ha_tree, hf_nsha_app, tvb, offset, 1, ENC_LITTLE_ENDIAN);
135 offset += 1;
136 proto_tree_add_item(ns_ha_tree, hf_nsha_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
137 offset += 1;
138 proto_tree_add_item_ret_uint(ns_ha_tree, hf_nsha_state, tvb, offset, 1, ENC_LITTLE_ENDIAN, &state);
139 offset += 1;
141 switch(version) {
142 /* all releases from 7.0 */
143 case 10:
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);
147 offset += 4;
148 proto_tree_add_item(ns_ha_tree, hf_nsha_release, tvb, offset, 4, ENC_LITTLE_ENDIAN);
149 offset += 4;
150 proto_tree_add_bitmask(ns_ha_tree, tvb, offset, hf_nsha_flags, ett_nsha_flags, ha_flags, ENC_LITTLE_ENDIAN);
151 offset += 4;
152 proto_tree_add_item(ns_ha_tree, hf_nsha_inc, tvb, offset, 4, ENC_LITTLE_ENDIAN);
153 offset += 4;
154 proto_tree_add_item(ns_ha_tree, hf_nsha_syncstate, tvb, offset, 4, ENC_LITTLE_ENDIAN);
155 offset += 4;
156 offset += 96; /* interface information */
157 proto_tree_add_item(ns_ha_tree, hf_nsha_drinc, tvb, offset, 4, ENC_LITTLE_ENDIAN);
158 break;
160 case 8: /* 6.0 */
161 case 9: /* 6.1 */
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);
165 offset += 4;
166 proto_tree_add_item(ns_ha_tree, hf_nsha_inc, tvb, offset, 4, ENC_LITTLE_ENDIAN);
167 offset += 4;
168 proto_tree_add_item(ns_ha_tree, hf_nsha_syncstate, tvb, offset, 4, ENC_LITTLE_ENDIAN);
169 offset += 4;
170 proto_tree_add_bitmask(ns_ha_tree, tvb, offset, hf_nsha_flags, ett_nsha_flags, ha_flags, ENC_LITTLE_ENDIAN);
171 if (version == 9) {
172 offset += 4;
173 offset += 96; /* interface information */
174 proto_tree_add_item(ns_ha_tree, hf_nsha_drinc, tvb, offset, 4, ENC_LITTLE_ENDIAN);
176 break;
178 /* 5.2 */
179 case 3:
180 case 4:
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);
183 offset += 4;
184 proto_tree_add_item(ns_ha_tree, hf_nsha_inc, tvb, offset, 4, ENC_LITTLE_ENDIAN);
185 break;
187 default:
188 break;
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);
199 void
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,
205 NULL, HFILL }},
207 { &hf_nsha_version,
208 { "Version", "nstrace.ha.version", FT_UINT8, BASE_DEC, NULL, 0x0,
209 NULL, HFILL }},
211 { &hf_nsha_app,
212 { "App", "nstrace.ha.app", FT_UINT8, BASE_DEC, VALS(ns_ha_app_vals), 0x0,
213 NULL, HFILL }},
215 { &hf_nsha_type,
216 { "Type", "nstrace.ha.type", FT_UINT8, BASE_DEC, VALS(ns_ha_type_vals), 0x0,
217 NULL, HFILL }},
219 { &hf_nsha_state,
220 { "State", "nstrace.ha.state", FT_UINT8, BASE_DEC, VALS(ns_ha_state_vals), 0x0,
221 NULL, HFILL }},
223 { &hf_nsha_startime,
224 { "Start Time", "nstrace.ha.startime", FT_UINT32, BASE_DEC, NULL, 0x0,
225 NULL, HFILL }},
227 { &hf_nsha_masterstate,
228 { "Master State", "nstrace.ha.masterstate", FT_UINT32, BASE_DEC, VALS(ns_ha_masterstate_vals), 0x0,
229 NULL, HFILL }},
231 { &hf_nsha_release,
232 { "Release", "nstrace.ha.release", FT_UINT32, BASE_DEC, NULL, 0x0,
233 NULL, HFILL }},
235 { &hf_nsha_inc,
236 { "Incarnation Number", "nstrace.ha.inc", FT_UINT32, BASE_DEC, NULL, 0x0,
237 NULL, HFILL }},
239 { &hf_nsha_syncstate,
240 { "Sync State", "nstrace.ha.syncstate", FT_UINT32, BASE_DEC, VALS(ns_ha_syncstate_vals), 0x0,
241 NULL, HFILL }},
243 { &hf_nsha_drinc,
244 { "DR Incarnation Number", "nstrace.ha.drinc", FT_UINT32, BASE_DEC, NULL, 0x0,
245 NULL, HFILL }},
247 { &hf_nsha_flags,
248 { "Flags", "nstrace.ha.flags", FT_UINT32, BASE_HEX, NULL, 0x0,
249 NULL, HFILL }},
251 { &hf_nsha_flags_vm,
252 { "Version Mismatch", "nstrace.ha.flags.versionmismatch", FT_BOOLEAN, 32, TFS(&tfs_yes_no), NSAHA_VERSION_MISMATCH,
253 NULL, HFILL }},
255 { &hf_nsha_flags_sp,
256 { "Stay Primary", "nstrace.ha.flags.stayprimary", FT_BOOLEAN, 32, TFS(&tfs_yes_no), NSAHA_STAY_PRIMARY,
257 NULL, HFILL }},
259 { &hf_nsha_flags_propdis,
260 { "Propagation Disabled", "nstrace.ha.flags.propdis", FT_BOOLEAN, 32, TFS(&tfs_yes_no), NSAHA_PROP_DISABLED,
261 NULL, HFILL }},
263 { &hf_nsha_flags_inc,
264 { "INC Enabled", "nstrace.ha.flags.inc", FT_BOOLEAN, 32, TFS(&tfs_yes_no), NSAHA_INC_STATE,
265 NULL, HFILL }},
267 { &hf_nsha_flags_sslfail,
268 { "SSL Card Failure", "nstrace.ha.flags.sslfail", FT_BOOLEAN, 32, TFS(&tfs_yes_no), NSAHA_SSLCARD_DOWN,
269 NULL, HFILL }},
271 { &hf_nsha_flags_nossl,
272 { "SSL Card Absent", "nstrace.ha.flags.nossl", FT_BOOLEAN, 32, TFS(&tfs_yes_no), NSAHA_NO_DEVICES,
273 NULL, HFILL }},
277 static int *ett[] = {
278 &ett_nsha,
279 &ett_nsha_flags,
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
297 * Local variables:
298 * c-basic-offset: 8
299 * tab-width: 8
300 * indent-tabs-mode: t
301 * End:
303 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
304 * :indentSize=8:tabSize=8:noTabs=false: