aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-pulse.c
blob: 59b5071e05edc32c4f18ca8326f83fa9db9dd296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/* packet-pulse.c
 * Routines for pulse dissection
 * Copyright 2013, Masatake YAMATO <yamato@redhat.com>
 * Copyright 2013, Red Hat, Inc.
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */


/* About pulse, see
    http://sourceware.org/piranha/ */

# include "config.h"

#include <epan/packet.h>
#include <epan/prefs.h>

#define PORT_PULSE 539


static guint  pulse_port = PORT_PULSE;

void proto_register_pulse(void);
void proto_reg_handoff_pulse(void);

static int  proto_pulse    = -1;
static int  hf_pulse_magic = -1;
static gint ett_pulse      = -1;

/* piranha/pulse.c */
#define PULSE_HEARTBEAT_RUNNING_MAGIC     0xbdaddbda
#define PULSE_HEARTBEAT_STOPPED_MAGIC     0xadbddabd

static const value_string pulse_magic_type[] = {
    { PULSE_HEARTBEAT_RUNNING_MAGIC,   "running" },
    { PULSE_HEARTBEAT_STOPPED_MAGIC,   "stopped" },
    { 0, NULL                                    }
};

static int
dissect_pulse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
{
    proto_item *item;
    proto_tree *tree;

    guint32 magic;
    const char* magic_str;
    guint little_endian;

    if (tvb_length(tvb) < 4)
        return 0;

    /* Try to read MAGIC in both endians */
    little_endian = ENC_LITTLE_ENDIAN;
    magic = tvb_get_letohl(tvb, 0);
    magic_str = try_val_to_str(magic, pulse_magic_type);
    if (magic_str == NULL) {
      magic = tvb_get_ntohl(tvb, 0);
      magic_str = try_val_to_str(magic, pulse_magic_type);
      if (magic_str == NULL) {
        return 0;
      }
      little_endian = ENC_BIG_ENDIAN;
    }

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "PULSE");
    col_set_str(pinfo->cinfo, COL_INFO, magic_str);

    if (parent_tree) {
        item = proto_tree_add_item(parent_tree, proto_pulse, tvb, 0,
                                   -1, little_endian);
        tree = proto_item_add_subtree(item, ett_pulse);
        proto_tree_add_item(tree, hf_pulse_magic, tvb, 0, 4, little_endian);
    }
    return 4;
}

void
proto_register_pulse(void)
{
    module_t *pulse_module;

    static hf_register_info hf[] = {
        { &hf_pulse_magic,
          { "Magic", "pulse.magic",
            FT_UINT32, BASE_HEX, VALS(pulse_magic_type), 0x0,
            NULL, HFILL }},
    };

    static gint *ett[] = {
        &ett_pulse,
    };


    proto_pulse = proto_register_protocol("PULSE protocol for Linux Virtual Server redundancy",
                                          "PULSE",
                                          "pulse");
    proto_register_field_array(proto_pulse, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    pulse_module = prefs_register_protocol(proto_pulse, proto_reg_handoff_pulse);
    prefs_register_uint_preference(pulse_module, "udp.port",
                                   "UDP Port",
                                   "Set the UDP port for pulse",
                                   10,
                                   &pulse_port);
}

void
proto_reg_handoff_pulse(void)
{
    static gboolean initialized = FALSE;

    static int port = 0;

    static dissector_handle_t pulse_handle;

    if (initialized)
        {
            dissector_delete_uint("udp.port", port, pulse_handle);
        }
    else
        {
            pulse_handle = new_create_dissector_handle(dissect_pulse,
                                                       proto_pulse);
            initialized = TRUE;
        }

    port  = pulse_port;
    dissector_add_uint("udp.port", port, pulse_handle);
}

/*
 * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */