aboutsummaryrefslogtreecommitdiffstats
path: root/packet-mip.c
blob: dd4b3c981726ed977bf5854dc1172c50e67893a7 (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
/* packet-mip.c
 * Routines for Mobile IP dissection
 * Copyright 2000, Stefan Raab <Stefan.Raab@nextel.com>
 *
 * $Id: packet-mip.c,v 1.2 2000/05/27 15:46:02 gram Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@unicom.net>
 * Copyright 1998 Gerald Combs
 *
 * Copied from WHATEVER_FILE_YOU_USED
 * 
 * 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 <stdlib.h>

#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#ifdef HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif

#ifdef NEED_SNPRINTF_H
# ifdef HAVE_STDARG_H
#  include <stdarg.h>
# else
#  include <varargs.h>
# endif
# include "snprintf.h"
#endif

#include <string.h>
#include <glib.h>
#include "packet.h"

/* Initialize the protocol and registered fields */
static int proto_mip = -1;
static int hf_mip_type = -1;
static int hf_mip_s = -1;
static int hf_mip_b = -1;
static int hf_mip_d = -1;
static int hf_mip_m = -1;
static int hf_mip_g = -1;
static int hf_mip_v = -1;
static int hf_mip_code = -1;
static int hf_mip_life = -1;
static int hf_mip_homeaddr = -1;
static int hf_mip_haaddr = -1;
static int hf_mip_coa = -1;
static int hf_mip_ident = -1;

/* Initialize the subtree pointers */
static gint ett_mip = -1;

/* Port used for Mobile IP */
#define UDP_PORT_MIP    434


/*
struct mip_packet{
  unsigned char type;
};


struct mip_request_packet{
  unsigned char type;
  unsigned char code;
  unsigned char life[2];
  unsigned char homeaddr[4];
  unsigned char haaddr[4];
  unsigned char coa[4];
  unsigned char ident[8];

};


struct mip_reply_packet{
  unsigned char type;
  unsigned char code;
  unsigned char life[2];
  unsigned char homeaddr[4];
  unsigned char haaddr[4];
  unsigned char ident[8];

};
*/

static const value_string mip_types[] = {
  {1, "Registration Request"},
  {3, "Registration Reply"}
};

static const value_string mip_reply_codes[]= {
  {0, "Registration Accepted"},
  {1, "Registration Accepted, no simul bindings"},
  {64, "Registration Denied by FA, unspecified reason"},
  {65, "Registration Denied by FA, Admin Prohibit"},
  {66, "Registration Denied by FA, Insufficient Resources"},
  {67, "Registration Denied by FA, MN failed Auth"},
  {68, "Registration Denied by FA, HA failed Auth"},
  {69, "Registration Denied by FA, Lifetime to long"},
  {70, "Registration Denied by FA, Poorly Formed Request"},
  {71, "Registration Denied by FA, Poorly Formed Reply"},
  {72, "Registration Denied by FA, encap unavailable"},
  {73, "Registration Denied by FA, VJ unavailable"},
  {80, "Registration Denied by FA, Home net unreachable"},
  {81, "Registration Denied by FA, Home Agent host unreachable"},
  {82, "Registration Denied by FA, Home Agent port unreachable"},
  {88, "Registration Denied by FA, Home Agent unreachable"},
  {128, "Registration Denied by HA, unspecified"},
  {129, "Registration Denied by HA, Admin Prohibit"},
  {130, "Registration Denied by HA, insufficient resources"},
  {131, "Registration Denied by HA, MN failed Auth"},
  {132, "Registration Denied by HA, FA failed Auth"},
  {133, "Registration Denied by HA, registration ID Mismatch"},
  {134, "Registration Denied by HA, poorly formed request"},
  {135, "Registration Denied by HA, too many simul bindings"},
  {136, "Registration Denied by HA, unknown HA address"},
};

/* Code to actually dissect the packets */
static void
dissect_mip(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
{

/* Set up structures we will need to add the protocol subtree and manage it */
	proto_item	*ti;
	proto_tree	*mip_tree;
	guint8		type, code;

	/* Make our own tvb until the function call includes one */
	tvbuff_t	*tvb;
	packet_info	*pinfo = &pi;
	tvb = tvb_new_subset(pi.compat_top_tvb, offset, -1, -1);

/* Make entries in Protocol column and Info column on summary display */

	pinfo->current_proto = "Mobile IP";
	if (check_col(fd, COL_PROTOCOL)) 
		col_add_str(fd, COL_PROTOCOL, "mip");
    
	type = tvb_get_guint8(tvb, 0);

/* This field shows up as the "Info" column in the display; you should make
   it, if possible, summarize what's in the packet, so that a user looking
   at the list of packets can tell what type of packet it is.

   "col_add_fstr()" can be used instead of "col_add_str()"; it takes
   "printf()"-like arguments. */

	if (type==1) {

	  if (check_col(fd, COL_INFO)) 
		 col_add_str(fd, COL_INFO, "Mobile IP Registration Request");
	
	  if (tree) {
		 ti = proto_tree_add_item(tree, proto_mip, tvb, 0, tvb_length(tvb), NULL);
	   	 mip_tree = proto_item_add_subtree(ti, ett_mip);
		 proto_tree_add_item(mip_tree, hf_mip_type, 0, 1, type);

		 code = tvb_get_guint8(tvb, 1);
		 proto_tree_add_item(mip_tree, hf_mip_s, tvb, 1, 1, code);
		 proto_tree_add_item(mip_tree, hf_mip_b, tvb, 1, 1, code);
		 proto_tree_add_item(mip_tree, hf_mip_d, tvb, 1, 1, code);
		 proto_tree_add_item(mip_tree, hf_mip_m, tvb, 1, 1, code);
		 proto_tree_add_item(mip_tree, hf_mip_g, tvb, 1, 1, code);
		 proto_tree_add_item(mip_tree, hf_mip_v, tvb, 1, 1, code);

		 proto_tree_add_item(mip_tree, hf_mip_life, tvb, 2, 2, tvb_get_ntohs(tvb, 2));
		 proto_tree_add_item(mip_tree, hf_mip_homeaddr, tvb, 4, 4, tvb_get_letohl(tvb, 4));
		 proto_tree_add_item(mip_tree, hf_mip_haaddr, tvb, 8, 4, tvb_get_letohl(tvb, 8));
		 proto_tree_add_item(mip_tree, hf_mip_coa, tvb, 12, 4, tvb_get_letohl(tvb, 12));
		 proto_tree_add_item(mip_tree, hf_mip_ident, tvb, 16, 8, tvb_get_ptr(tvb, 16, 8));
	  }
	}


	if (type==3){
	  if (check_col(fd, COL_INFO)) 
		 col_add_str(fd, COL_INFO, "Mobile IP Registration Reply");

/* In the interest of speed, if "tree" is NULL, don't do any work not
   necessary to generate protocol tree items. */
	  if (tree) {
		 ti = proto_tree_add_item(tree, proto_mip, tvb, 0, tvb_length(tvb), NULL);
	   	 mip_tree = proto_item_add_subtree(ti, ett_mip);
		 proto_tree_add_item(mip_tree, hf_mip_type, tvb, 0, 1, type);

		 code = tvb_get_guint8(tvb, 1);
		 proto_tree_add_item(mip_tree, hf_mip_code, tvb, 1, 1, code);
		 proto_tree_add_item(mip_tree, hf_mip_life, tvb, 2, 2, tvb_get_ntohs(tvb, 2));
		 proto_tree_add_item(mip_tree, hf_mip_homeaddr, tvb, 4, 4, tvb_get_letohl(tvb, 4));
		 proto_tree_add_item(mip_tree, hf_mip_haaddr, tvb, 8, 4, tvb_get_letohl(tvb, 8));
		 proto_tree_add_item(mip_tree, hf_mip_ident, tvb, 12, 8, tvb_get_ptr(tvb, 12, 8));
	  }
	}
}

/* Register the protocol with Ethereal */
void proto_register_mip(void)
{                 

/* Setup list of header fields */
	static hf_register_info hf[] = {
	  { &hf_mip_type,
		 { "Message Type",           "mip.type",
			FT_INT8, BASE_DEC, VALS(mip_types), 0,          
			"Mobile IP Message type." }
	  },
	  { &hf_mip_s,
		 {"Simultaneous Bindings",           "mip.s",
		   FT_BOOLEAN, 8, NULL, 128,          
		   "Simultaneous Bindings Allowed" }
	  },
     { &hf_mip_b,
		 {"Broadcast Datagrams",           "mip.b",
		   FT_BOOLEAN, 8, NULL, 64,          
		   "Broadcast Datagrams requested" }
	  },
	  { &hf_mip_d,
		 { "Co-lcated Care-of Address",           "mip.d",
		   FT_BOOLEAN, 8, NULL, 32,          
		   "MN using Co-located Care-of address" }
	  },
	  { &hf_mip_m,
		 {"Minimal Encapsulation",           "mip.m",
		   FT_BOOLEAN, 8, NULL, 16,          
		   "MN wants Minimal encapsulation" }
	  },
	  { &hf_mip_g,
		 {"GRE",           "mip.g",
		   FT_BOOLEAN, 8, NULL, 8,          
		   "MN wants GRE encapsulation" }
	  },
	  { &hf_mip_v,
		 { "Van Jacobson",           "mip.v",
		   FT_BOOLEAN, 8, NULL, 4,          
		   "Van Jacbson" }
	  },
	  { &hf_mip_code,
		 { "Reply Code",           "mip.code",
			FT_UINT8, BASE_DEC, VALS(mip_reply_codes), 0,          
			"Mobile IP Reply code." }
	  },
	  { &hf_mip_life,
		 { "Lifetime",           "mip.life",
			FT_INT16, BASE_DEC, NULL, 0,          
			"Mobile IP Lifetime." }
	  },
	  { &hf_mip_homeaddr,
		 { "Home Address",           "mip.homeaddr",
			FT_IPv4, BASE_NONE, NULL, 0,          
			"Mobile Nodes home address." }
	  },
	  
	  { &hf_mip_haaddr,
		 { "Home Agent",           "mip.haaddr",
			FT_IPv4, BASE_NONE, NULL, 0,          
			"Home agent Ip Address." }
	  },
	  { &hf_mip_coa,
		 { "Care of Address",           "mip.coa",
			FT_IPv4, BASE_NONE, NULL, 0,          
			"Care of Address." }
	  },
	  { &hf_mip_ident,
		 { "Identification",           "mip.ident",
			FT_BYTES, BASE_NONE, NULL, 0,          
			"MN Identification." }
	  },




	};

/* Setup protocol subtree array */
	static gint *ett[] = {
		&ett_mip,
	};

/* Register the protocol name and description */
	proto_mip = proto_register_protocol("Mobile IP", "mip");

/* Required function calls to register the header fields and subtrees used */
	proto_register_field_array(proto_mip, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
};



void
proto_reg_handoff_mip(void)
{
  dissector_add("udp.port", UDP_PORT_MIP, dissect_mip);
}