aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-glbp.c
blob: 596d1bf781c20dd2b49169ab64bed432b156be73 (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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/* packet-glbp.c
 *
 * Cisco's GLBP:  Gateway Load Balancing Protocol
 *
 * $Id$
 *
 * Copyright 2007 Joerg Mayer (see AUTHORS file)
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/*
 * Documentation:
 * http://www.cisco.com/en/US/docs/ios/12_2t/12_2t15/feature/guide/ft_glbp.pdf
 *
 * TODO: This dissector has been written without specs, so much of it is
 *    guesswork. Candidate values that might be somewhere in the packet:
 *    - weight (current/lower/upper)
 *    - group#
 *    - forwarder#
 *    - preempt (capable/delay)
 *    - vg state
 *    - vf state
 *    - authentication
 *    - ipv6 support
 *    - sso capable
 *    - secondary IP addresses
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <string.h>
#include <glib.h>
#include <epan/packet.h>

static int proto_glbp = -1;
/* glbp header? */
static gint hf_glbp_version = -1;
static gint hf_glbp_type1 = -1;
static gint hf_glbp_unknown1 = -1;
static gint hf_glbp_unknown2 = -1;
static gint hf_glbp_somemac = -1;
static gint hf_glbp_type2 = -1;
static gint hf_glbp_length2 = -1;
/* glbp type2 = 1 - hello */
static gint hf_glbp_unknown11 = -1;
static gint hf_glbp_priority = -1;
static gint hf_glbp_unknown12 = -1;
static gint hf_glbp_helloint = -1;
static gint hf_glbp_holdint = -1;
static gint hf_glbp_redirect = -1;
static gint hf_glbp_timeout = -1;
static gint hf_glbp_unknown13 = -1;
static gint hf_glbp_numips = -1;
static gint hf_glbp_lenip = -1;
static gint hf_glbp_virtualip = -1;
/* glbp type2 = 2 - Request/Response??? */
static gint hf_glbp_subtype = -1;
static gint hf_glbp_unknown21 = -1;
static gint hf_glbp_virtualmac = -1;
/* unknown type */
static gint hf_glbp_unknown6 = -1;

static gint ett_glbp = -1;

static const value_string glbp_type2_vals[] = {
	{ 1,	"Hello" },
	{ 2,	"Request/Response?" },

	{ 0, NULL }
};

static const value_string glbp_subtype_vals[] = {
	{ 0,	"Request?" },
	{ 2,	"Response?" },

	{ 0, NULL }
};

#if 0
static const value_string glbp_loadbalancing_vals[] = {
	{ x,	"None (AVG only)" },
	{ x,	"Weighted" },
	{ x,	"Host dependent" },
	{ x,	"Round robin" },

	{ 0, NULL }
};


static const value_string glbp_authentication_vals[] = {
	{ x,	"None" },
	{ x,	"Plain text" },
	{ x,	"MD5" },

	{ 0, NULL }
};

static const value_string glbp_vgstate_vals[] = {
	{ x,	"Active" },
	{ x,	"Standby" },
	{ x,	"Listen" },
	{ x,	"Initial" },
	{ x,	"Speak" },
	{ x,	"Disabled" },

	{ 0, NULL }
};

static const value_string glbp_vfstate_vals[] = {
	{ x,	"Active" },
	{ x,	"Listen" },
	{ x,	"Initial" },
	{ x,	"Disabled" },

	{ 0, NULL }
};
#endif

static int
dissect_glbp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
  proto_tree *glbp_tree = NULL;
  proto_item *ti = NULL;
  guint32 type2;
  guint32 length2;

  type2 = tvb_get_guint8(tvb, 12);

  if (check_col(pinfo->cinfo, COL_PROTOCOL))
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "GLBP");
  if (check_col(pinfo->cinfo, COL_INFO))
    col_add_str(pinfo->cinfo, COL_INFO, val_to_str(type2,
      glbp_type2_vals, "Type 0x%02x"));

  length2 = tvb_get_guint8(tvb, 13);

  if (tree) {
    ti = proto_tree_add_item(tree, proto_glbp, tvb, 0, -1, FALSE);
    glbp_tree = proto_item_add_subtree(ti, ett_glbp);

    /* glbp header? */
    proto_tree_add_item(glbp_tree, hf_glbp_version, tvb, 0, 1,  FALSE);
    proto_tree_add_item(glbp_tree, hf_glbp_type1, tvb, 1, 1,  FALSE);
    proto_tree_add_item(glbp_tree, hf_glbp_unknown1, tvb, 2, 2,  FALSE);
    proto_tree_add_item(glbp_tree, hf_glbp_unknown2, tvb, 4, 2,  FALSE);
    proto_tree_add_item(glbp_tree, hf_glbp_somemac, tvb, 6, 6, FALSE);
    proto_tree_add_item(glbp_tree, hf_glbp_type2, tvb, 12, 1,  FALSE);
    proto_tree_add_item(glbp_tree, hf_glbp_length2, tvb, 13, 1,  FALSE);

    switch(type2) {
      case 1: /* Hello */
        proto_tree_add_item(glbp_tree, hf_glbp_unknown11, tvb, 14, 3,  FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_priority, tvb, 17, 1,  FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_unknown12, tvb, 18, 2, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_helloint, tvb, 20, 4, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_holdint, tvb, 24, 4, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_redirect, tvb, 28, 2, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_timeout, tvb, 30, 2, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_unknown13, tvb, 32, 2, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_numips, tvb, 34, 1, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_lenip, tvb, 35, 1, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_virtualip, tvb, 36, 4, FALSE);
	break;
      case 2:
        proto_tree_add_item(glbp_tree, hf_glbp_subtype, tvb, 14, 1, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_unknown21, tvb, 15, 11, FALSE);
        proto_tree_add_item(glbp_tree, hf_glbp_virtualmac, tvb, 26, 6, FALSE);
	break;
      default:
        proto_tree_add_item(glbp_tree, hf_glbp_unknown6, tvb, 14, length2-2, FALSE);
	break;
    }

  }
  return 12 + length2;
}

static gboolean
test_glbp(tvbuff_t *tvb, packet_info *pinfo)
{
	guint32 type1;
	if ( tvb_length(tvb) < 2)
		return FALSE;
	type1 = tvb_get_guint8(tvb, 1);
	if (tvb_get_guint8(tvb, 0) != 1 /* version? */
		|| type1 > 2
		|| pinfo->srcport != pinfo->destport
#if 0 /* XXX */
		|| type1 == 0 && pinfo->net_dst != ipv4:224.0.0.102
		|| type1 == 0 && pinfo->dl_src != ether:c2-00-7c-b8-00-00
#endif
	) {
		return FALSE;
	}
	return TRUE;
}

static int
dissect_glbp_static(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	if ( !test_glbp(tvb, pinfo) ) {
		return 0;
	}
	return dissect_glbp(tvb, pinfo, tree);
}


void
proto_register_glbp(void)
{
  static hf_register_info hf[] = {
	/* Header */
	{ &hf_glbp_version,
	   { "Version?",      "glbp.version", FT_UINT8, BASE_DEC, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_type1,
	   { "Type1???",      "glbp.type1", FT_UINT8, BASE_DEC, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_unknown1,
	   { "Unknown1",      "glbp.unknown1", FT_BYTES, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_unknown2,
	   { "Unknown2",      "glbp.unknown2", FT_BYTES, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_somemac,
	   { "Somemac?",       "glbp.somemac", FT_ETHER, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_type2,
	   { "Type2???",      "glbp.type2", FT_UINT8, BASE_DEC, VALS(glbp_type2_vals),
	     0x0, NULL, HFILL }},

	{ &hf_glbp_length2,
	   { "Length2?",      "glbp.length2", FT_UINT8, BASE_DEC, NULL,
	     0x0, NULL, HFILL }},

	/* type = 1 - hello */
	{ &hf_glbp_unknown11,
	   { "Unknown1-1",      "glbp.unknown11", FT_BYTES, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_priority,
	   { "Priority",      "glbp.priority", FT_UINT8, BASE_DEC, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_unknown12,
	   { "Unknown1-2",      "glbp.unknown12", FT_BYTES, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_helloint,
	   { "Helloint",      "glbp.helloint", FT_UINT32, BASE_DEC, NULL,
	     0x0, "Hello interval [msec]", HFILL }},

	{ &hf_glbp_holdint,
	   { "Holdint",      "glbp.holdint", FT_UINT32, BASE_DEC, NULL,
	     0x0, "Hold interval [msec]", HFILL }},

	{ &hf_glbp_redirect,
	   { "Redirect",      "glbp.redirect", FT_UINT16, BASE_DEC, NULL,
	     0x0, "Redirect interval [sec]", HFILL }},

	{ &hf_glbp_timeout,
	   { "Timeout",      "glbp.timeout", FT_UINT16, BASE_DEC, NULL,
	     0x0, "Forwarder timeout interval [sec]", HFILL }},

	{ &hf_glbp_unknown13,
	   { "Unknown1-3",      "glbp.unknown13", FT_BYTES, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_numips,
	   { "Number IPs???",      "glbp.numips", FT_UINT8, BASE_DEC, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_lenip,
	   { "Length IP???",      "glbp.lenip", FT_UINT8, BASE_DEC, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_virtualip,
	   { "Virtual IP",      "glbp.virtualip", FT_IPv4, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	/* type = 2 - request/response??? */
	{ &hf_glbp_subtype,
	   { "Subtype???",      "glbp.subtype", FT_UINT8, BASE_DEC, VALS(glbp_subtype_vals),
	     0x0, NULL, HFILL }},

	{ &hf_glbp_unknown21,
	   { "Unknown2-1",      "glbp.unknown21", FT_BYTES, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	{ &hf_glbp_virtualmac,
	   { "Virtualmac",       "glbp.virtualmac", FT_ETHER, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

	/* type = unknown */
	{ &hf_glbp_unknown6,
	   { "Unknown6",      "glbp.unknown6", FT_BYTES, BASE_NONE, NULL,
	     0x0, NULL, HFILL }},

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

  proto_glbp = proto_register_protocol(
	"Gateway Load Balancing Protocol", "GLBP", "glbp");
  proto_register_field_array(proto_glbp, hf, array_length(hf));
  proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_glbp(void)
{
  dissector_handle_t glbp_handle;

  glbp_handle = new_create_dissector_handle(dissect_glbp_static, proto_glbp);
  dissector_add("udp.port", 3222, glbp_handle);
}