/src/wireshark/epan/dissectors/packet-pulse.c
Line | Count | Source |
1 | | /* packet-pulse.c |
2 | | * Routines for pulse dissection |
3 | | * Copyright 2013, Masatake YAMATO <yamato@redhat.com> |
4 | | * Copyright 2013, Red Hat, Inc. |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 1998 Gerald Combs |
9 | | * |
10 | | * SPDX-License-Identifier: GPL-2.0-or-later |
11 | | */ |
12 | | |
13 | | |
14 | | /* About pulse, see |
15 | | http://sourceware.org/piranha/ */ |
16 | | |
17 | | # include "config.h" |
18 | | |
19 | | #include <epan/packet.h> |
20 | | |
21 | 14 | #define PORT_PULSE 539 /* Not IANA registered */ |
22 | | |
23 | | void proto_register_pulse(void); |
24 | | void proto_reg_handoff_pulse(void); |
25 | | |
26 | | static dissector_handle_t pulse_handle; |
27 | | |
28 | | static int proto_pulse; |
29 | | static int hf_pulse_magic; |
30 | | static int ett_pulse; |
31 | | |
32 | | /* piranha/pulse.c */ |
33 | | #define PULSE_HEARTBEAT_RUNNING_MAGIC 0xbdaddbda |
34 | | #define PULSE_HEARTBEAT_STOPPED_MAGIC 0xadbddabd |
35 | | |
36 | | static const value_string pulse_magic_type[] = { |
37 | | { PULSE_HEARTBEAT_RUNNING_MAGIC, "running" }, |
38 | | { PULSE_HEARTBEAT_STOPPED_MAGIC, "stopped" }, |
39 | | { 0, NULL } |
40 | | }; |
41 | | |
42 | | static int |
43 | | dissect_pulse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_) |
44 | 6 | { |
45 | 6 | proto_item *item; |
46 | 6 | proto_tree *tree; |
47 | | |
48 | 6 | uint32_t magic; |
49 | 6 | const char* magic_str; |
50 | 6 | unsigned endian; |
51 | | |
52 | 6 | if (tvb_captured_length(tvb) < 4) |
53 | 3 | return 0; |
54 | | |
55 | | /* Try to read MAGIC in both endians */ |
56 | 3 | endian = ENC_LITTLE_ENDIAN; |
57 | 3 | magic = tvb_get_letohl(tvb, 0); |
58 | 3 | magic_str = try_val_to_str(magic, pulse_magic_type); |
59 | 3 | if (magic_str == NULL) { |
60 | 3 | magic = tvb_get_ntohl(tvb, 0); |
61 | 3 | magic_str = try_val_to_str(magic, pulse_magic_type); |
62 | 3 | if (magic_str == NULL) { |
63 | 3 | return 0; |
64 | 3 | } |
65 | 0 | endian = ENC_BIG_ENDIAN; |
66 | 0 | } |
67 | | |
68 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "PULSE"); |
69 | 0 | col_set_str(pinfo->cinfo, COL_INFO, magic_str); |
70 | |
|
71 | 0 | if (parent_tree) { |
72 | 0 | item = proto_tree_add_item(parent_tree, proto_pulse, tvb, 0, |
73 | 0 | -1, endian); |
74 | 0 | tree = proto_item_add_subtree(item, ett_pulse); |
75 | 0 | proto_tree_add_item(tree, hf_pulse_magic, tvb, 0, 4, endian); |
76 | 0 | } |
77 | 0 | return 4; |
78 | 3 | } |
79 | | |
80 | | void |
81 | | proto_register_pulse(void) |
82 | 14 | { |
83 | 14 | static hf_register_info hf[] = { |
84 | 14 | { &hf_pulse_magic, |
85 | 14 | { "Magic", "pulse.magic", |
86 | 14 | FT_UINT32, BASE_HEX, VALS(pulse_magic_type), 0x0, |
87 | 14 | NULL, HFILL }}, |
88 | 14 | }; |
89 | | |
90 | 14 | static int *ett[] = { |
91 | 14 | &ett_pulse, |
92 | 14 | }; |
93 | | |
94 | | |
95 | 14 | proto_pulse = proto_register_protocol("PULSE protocol for Linux Virtual Server redundancy", "PULSE", "pulse"); |
96 | 14 | proto_register_field_array(proto_pulse, hf, array_length(hf)); |
97 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
98 | | |
99 | 14 | pulse_handle = register_dissector("pulse", dissect_pulse, proto_pulse); |
100 | 14 | } |
101 | | |
102 | | void |
103 | | proto_reg_handoff_pulse(void) |
104 | 14 | { |
105 | 14 | dissector_add_uint_with_preference("udp.port", PORT_PULSE, pulse_handle); |
106 | 14 | } |
107 | | |
108 | | /* |
109 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
110 | | * |
111 | | * Local variables: |
112 | | * c-basic-offset: 4 |
113 | | * tab-width: 8 |
114 | | * indent-tabs-mode: nil |
115 | | * End: |
116 | | * |
117 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
118 | | * :indentSize=4:tabSize=8:noTabs=true: |
119 | | */ |