aboutsummaryrefslogtreecommitdiffstats
path: root/packet-ipxwan.c
blob: 9e0ca0667829c66889104e29d3ba78ea9e875ddd (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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
/* packet-ipxwan.c
 * Routines for NetWare IPX WAN Protocol
 *
 * $Id: packet-ipxwan.c,v 1.1 2003/04/06 02:32:38 guy Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * 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.
 */

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

#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <epan/packet.h>
#include "packet-ipx.h"

/*
 * See RFC 1362 for version 1 of this protocol; see the NetWare Link
 * Services Protocol Specification, chapter 3, for version 2.
 */
static int proto_ipxwan = -1;

static int hf_ipxwan_identifier = -1;
static int hf_ipxwan_packet_type = -1;
static int hf_ipxwan_node_id = -1;
static int hf_ipxwan_sequence_number = -1;
static int hf_ipxwan_num_options = -1;
static int hf_ipxwan_option_num = -1;
static int hf_ipxwan_accept_option = -1;
static int hf_ipxwan_option_data_len = -1;
static int hf_ipxwan_routing_type = -1;
static int hf_ipxwan_wan_link_delay = -1;
static int hf_ipxwan_common_network_number = -1;
static int hf_ipxwan_router_name = -1;
static int hf_ipxwan_delay = -1;
static int hf_ipxwan_throughput = -1;
static int hf_ipxwan_request_size = -1;
static int hf_ipxwan_delta_time = -1;
static int hf_ipxwan_extended_node_id = -1;
static int hf_ipxwan_node_number = -1;
static int hf_ipxwan_compression_type = -1;

static gint ett_ipxwan = -1;
static gint ett_ipxwan_option = -1;

static const value_string ipxwan_packet_type_vals[] = {
	{ 0,    "Timer Request" },
	{ 1,    "Timer Response" },
	{ 2,    "Information Request" },
	{ 3,    "Information Response" },
	{ 4,    "Throughput Request" },
	{ 5,    "Throughput Response" },
	{ 6,    "Delay Request" },
	{ 7,    "Delay Response" },
	{ 0xFF, "NAK" },
	{ 0,    NULL }
};

#define OPT_ROUTING_TYPE		0x00
#define OPT_RIP_SAP_INFO_EXCHANGE	0x01
#define OPT_NLSP_INFORMATION		0x02
#define OPT_NLSP_RAW_THROUGHPUT_DATA	0x03
#define OPT_EXTENDED_NODE_ID		0x04
#define OPT_NODE_NUMBER			0x05
#define OPT_COMPRESSION			0x80
#define OPT_PAD				0xFF

static const value_string ipxwan_option_num_vals[] = {
	{ OPT_ROUTING_TYPE,             "Routing Type" },
	{ OPT_RIP_SAP_INFO_EXCHANGE,    "RIP/SAP Info Exchange" },
	{ OPT_NLSP_INFORMATION,         "NLSP Information" },
	{ OPT_NLSP_RAW_THROUGHPUT_DATA, "NLSP Raw Throughput Data" },
	{ OPT_EXTENDED_NODE_ID,         "Extended Node ID" },
	{ OPT_NODE_NUMBER,              "Node Number" },
	{ OPT_COMPRESSION,              "Compression" },
	{ OPT_PAD,                      "Pad" },
	{ 0,                            NULL }
};

static const value_string ipxwan_accept_option_vals[] = {
	{ 0, "No" },
	{ 1, "Yes" },
	{ 3, "Not Appplicable" },
	{ 0, NULL }
};

static const value_string ipxwan_routing_type_vals[] = {
	{ 0, "RIP" },
	{ 1, "NLSP" },
	{ 2, "Unnumbered RIP" },
	{ 3, "On-demand, static routing" },
	{ 4, "Client-router connection" },
	{ 0, NULL }
};

#define COMP_TYPE_TELEBIT	0

static const value_string ipxwan_compression_type_vals[] = {
	{ COMP_TYPE_TELEBIT, "Telebit" },
	{ 0,                 NULL }
};

static void
dissect_ipxwan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
	proto_item *ti;
	proto_tree *ipxwan_tree = NULL;
	int offset = 0;
	guint8 packet_type;
	guint8 num_options;
	guint8 option_number;
	proto_tree *option_tree;
	guint16 option_data_len;
	guint16 wan_link_delay;
	guint32 delay;
	guint32 throughput;
	guint32 delta_time;
	guint8 compression_type;

	if (check_col(pinfo->cinfo, COL_PROTOCOL))
		col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPX WAN");
	if (check_col(pinfo->cinfo, COL_INFO))
		col_clear(pinfo->cinfo, COL_INFO);

	if (tree) {
		ti = proto_tree_add_item(tree, proto_ipxwan, tvb, 0, -1,
		    FALSE);
		ipxwan_tree = proto_item_add_subtree(ti, ett_ipxwan);
	}

	if (tree) {
		proto_tree_add_item(ipxwan_tree, hf_ipxwan_identifier, tvb,
		    offset, 4, FALSE);
	}
	offset += 4;
	packet_type = tvb_get_guint8(tvb, offset);
	if (check_col(pinfo->cinfo, COL_INFO)) {
		col_add_str(pinfo->cinfo, COL_INFO,
		    val_to_str(packet_type, ipxwan_packet_type_vals,
		        "Unknown packet type %u"));
	}
	if (tree) {
		proto_tree_add_uint(ipxwan_tree, hf_ipxwan_packet_type, tvb,
			offset, 1, packet_type);
		offset += 1;
		proto_tree_add_item(ipxwan_tree, hf_ipxwan_node_id, tvb,
			offset, 4, FALSE);
		offset += 4;
		proto_tree_add_item(ipxwan_tree, hf_ipxwan_sequence_number, tvb,
			offset, 1, FALSE);
		offset += 1;
		num_options = tvb_get_guint8(tvb, offset);
		proto_tree_add_uint(ipxwan_tree, hf_ipxwan_num_options, tvb,
			offset, 1, num_options);
		offset += 1;

		while (num_options != 0) {
			option_number = tvb_get_guint8(tvb, offset);
			ti = proto_tree_add_text(ipxwan_tree, tvb, offset, -1,
			    "Option: %s",
			    val_to_str(option_number, ipxwan_option_num_vals,
			        "Unknown (%u)"));
			option_tree = proto_item_add_subtree(ti,
			    ett_ipxwan_option);

			proto_tree_add_uint(option_tree, hf_ipxwan_option_num,
			    tvb, offset, 1, option_number);
			offset += 1;
			proto_tree_add_item(option_tree, hf_ipxwan_accept_option,
			    tvb, offset, 1, FALSE);
			offset += 1;
			option_data_len = tvb_get_ntohs(tvb, offset);
			proto_tree_add_uint(option_tree, hf_ipxwan_option_data_len,
			    tvb, offset, 2, option_data_len);
			offset += 2;
			proto_item_set_len(ti, option_data_len+4);
			switch (option_number) {

			case OPT_ROUTING_TYPE:
				if (option_data_len != 1) {
					proto_tree_add_text(option_tree,
					    tvb, offset, option_data_len,
					    "Bogus length: %u, should be 1",
					    option_data_len);
				} else {
					proto_tree_add_item(option_tree,
					    hf_ipxwan_routing_type, tvb,
					    offset, 1, FALSE);
				}
				break;

			case OPT_RIP_SAP_INFO_EXCHANGE:
				if (option_data_len != 54) {
					proto_tree_add_text(option_tree,
					    tvb, offset, option_data_len,
					    "Bogus length: %u, should be 54",
					    option_data_len);
				} else {
					wan_link_delay = tvb_get_ntohs(tvb,
					    offset);
					proto_tree_add_uint_format(option_tree,
					    hf_ipxwan_wan_link_delay, tvb,
					    offset, 2, wan_link_delay,
					    "WAN Link Delay: %ums",
					    wan_link_delay);
					proto_tree_add_item(option_tree,
					    hf_ipxwan_common_network_number,
					    tvb, offset+2, 4, FALSE);
					proto_tree_add_item(option_tree,
					    hf_ipxwan_router_name, tvb,
					    offset+6, 48, FALSE);
				}
				break;

			case OPT_NLSP_INFORMATION:
				if (option_data_len != 8) {
					proto_tree_add_text(option_tree,
					    tvb, offset, option_data_len,
					    "Bogus length: %u, should be 8",
					    option_data_len);
				} else {
					delay = tvb_get_ntohl(tvb, offset);
					proto_tree_add_uint_format(option_tree,
					    hf_ipxwan_delay, tvb,
					    offset, 4, delay,
					    "Delay: %uus", delay);
					throughput = tvb_get_ntohl(tvb, offset);
					proto_tree_add_uint_format(option_tree,
					    hf_ipxwan_throughput, tvb,
					    offset, 4, throughput,
					    "Throughput: %uus",
					    throughput);
				}
				break;

			case OPT_NLSP_RAW_THROUGHPUT_DATA:
				if (option_data_len != 8) {
					proto_tree_add_text(option_tree,
					    tvb, offset, option_data_len,
					    "Bogus length: %u, should be 8",
					    option_data_len);
				} else {
					proto_tree_add_item(option_tree,
					    hf_ipxwan_request_size, tvb,
					    offset, 4, FALSE);
					delta_time = tvb_get_ntohl(tvb, offset);
					proto_tree_add_uint_format(option_tree,
					    hf_ipxwan_delta_time, tvb,
					    offset, 4, delta_time,
					    "Delta Time: %uus",
					    delta_time);
				}
				break;

			case OPT_EXTENDED_NODE_ID:
				if (option_data_len != 4) {
					proto_tree_add_text(option_tree,
					    tvb, offset, option_data_len,
					    "Bogus length: %u, should be 4",
					    option_data_len);
				} else {
					proto_tree_add_item(option_tree,
					    hf_ipxwan_extended_node_id, tvb,
					    offset, 4, FALSE);
				}
				break;

			case OPT_NODE_NUMBER:
				if (option_data_len != 6) {
					proto_tree_add_text(option_tree,
					    tvb, offset, option_data_len,
					    "Bogus length: %u, should be 6",
					    option_data_len);
				} else {
					proto_tree_add_item(option_tree,
					    hf_ipxwan_node_number, tvb,
					    offset, 6, FALSE);
				}
				break;

			case OPT_COMPRESSION:
				if (option_data_len < 1) {
					proto_tree_add_text(option_tree,
					    tvb, offset, option_data_len,
					    "Bogus length: %u, should be >= 1",
					    option_data_len);
				} else {
					compression_type = tvb_get_guint8(tvb,
					    offset);
					proto_tree_add_uint(option_tree,
					    hf_ipxwan_compression_type, tvb,
					    offset, 1, compression_type);
					switch (compression_type) {

					case COMP_TYPE_TELEBIT:
						if (option_data_len < 3) {
							proto_tree_add_text(option_tree,
							    tvb, offset+1,
							    option_data_len-1,
							    "Bogus length: %u, should be >= 3",
							    option_data_len);
						} else {
							proto_tree_add_text(
							    option_tree,
							    tvb, offset+1, 1,
							    "Compression options: 0x%02x",
							    tvb_get_guint8(tvb,
							        offset+1));
							proto_tree_add_text(
							    option_tree,
							    tvb, offset+2, 1,
							    "Number of compression slots: %u",
							    tvb_get_guint8(tvb,
							        offset+2));
						}
						break;

					default:
						proto_tree_add_text(option_tree,
						    tvb, offset+1,
						    option_data_len-1,
						    "Option parameters");
						break;
					}
				}
				break;

			case OPT_PAD:
				proto_tree_add_text(option_tree,
				    tvb, offset, option_data_len,
				    "Padding");
				break;

			default:
				proto_tree_add_text(option_tree,
				    tvb, offset, option_data_len,
				    "Option value");
				break;
			}

			offset += option_data_len;
			num_options--;
		}
	}
}

void
proto_register_ipxwan(void)
{
	static hf_register_info hf[] = {
	    { &hf_ipxwan_identifier,
	      { "Identifier",	"ipxwan.identifier",
		FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_packet_type,
	      { "Packet Type", "ipxwan.packet_type",
	        FT_UINT8, BASE_DEC, VALS(ipxwan_packet_type_vals), 0x0, "",
	        HFILL }},

	    { &hf_ipxwan_node_id,
	      { "Node ID", "ipxwan.node_id", FT_UINT32,
	         BASE_HEX, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_sequence_number,
	      { "Sequence Number", "ipxwan.sequence_number", FT_UINT8,
	         BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_num_options,
	      { "Number of Options", "ipxwan.num_options", FT_UINT8,
	         BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_option_num,
	      { "Option Number", "ipxwan.option_num", FT_UINT8,
	         BASE_HEX, VALS(ipxwan_option_num_vals), 0x0, "", HFILL }},

	    { &hf_ipxwan_accept_option,
	      { "Accept Option", "ipxwan.accept_option", FT_UINT8,
	         BASE_DEC, VALS(ipxwan_accept_option_vals), 0x0, "", HFILL }},

	    { &hf_ipxwan_option_data_len,
	      { "Option Data Length", "ipxwan.option_data_len", FT_UINT16,
	         BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_routing_type,
	      { "Routing Type", "ipxwan.routing_type", FT_UINT8,
	         BASE_DEC, VALS(ipxwan_routing_type_vals), 0x0, "", HFILL }},

	    { &hf_ipxwan_wan_link_delay,
	      { "WAN Link Delay", "ipxwan.rip_sap_info_exchange.wan_link_delay",
	         FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_common_network_number,
	      { "Common Network Number", "ipxwan.rip_sap_info_exchange.common_network_number",
	         FT_IPXNET, BASE_NONE, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_router_name,
	      { "Router Name", "ipxwan.rip_sap_info_exchange.router_name",
	         FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_delay,
	      { "Delay", "ipxwan.nlsp_information.delay",
	         FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_throughput,
	      { "Throughput", "ipxwan.nlsp_information.throughput",
	         FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_request_size,
	      { "Request Size", "ipxwan.nlsp_raw_throughput_data.request_size",
	         FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_delta_time,
	      { "Delta Time", "ipxwan.nlsp_raw_throughput_data.delta_time",
	         FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_extended_node_id,
	      { "Extended Node ID", "ipxwan.extended_node_id",
	         FT_IPXNET, BASE_NONE, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_node_number,
	      { "Node Number", "ipxwan.node_number",
	         FT_ETHER, BASE_NONE, NULL, 0x0, "", HFILL }},

	    { &hf_ipxwan_compression_type,
	      { "Compression Type", "ipxwan.compression.type",
	         FT_UINT8, BASE_DEC, VALS(ipxwan_compression_type_vals), 0x0,
	         "", HFILL }},
	};
	static gint *ett[] = {
		&ett_ipxwan,
		&ett_ipxwan_option,
	};

	proto_ipxwan = proto_register_protocol("IPX WAN", "IPX WAN", "ipxwan");
	proto_register_field_array(proto_ipxwan, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_ipxwan(void)
{
	dissector_handle_t ipxwan_handle;

	ipxwan_handle = create_dissector_handle(dissect_ipxwan,
	    proto_ipxwan);
	dissector_add("ipx.socket", IPX_SOCKET_IPXWAN, ipxwan_handle);
}