2 * Routines for ypserv dissection
4 * $Id: packet-ypserv.c,v 1.26 2002/10/24 20:59:21 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * Copied from packet-smb.c
12 * 2001 Ronnie Sahlberg <See AUTHORS for email>
13 * Added all remaining dissectors for this protocol
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include "packet-rpc.h"
37 #include "packet-ypserv.h"
39 static int proto_ypserv = -1;
40 static int hf_ypserv_procedure_v1 = -1;
41 static int hf_ypserv_procedure_v2 = -1;
42 static int hf_ypserv_domain = -1;
43 static int hf_ypserv_servesdomain = -1;
44 static int hf_ypserv_map = -1;
45 static int hf_ypserv_key = -1;
46 static int hf_ypserv_peer = -1;
47 static int hf_ypserv_more = -1;
48 static int hf_ypserv_ordernum = -1;
49 static int hf_ypserv_transid = -1;
50 static int hf_ypserv_prog = -1;
51 static int hf_ypserv_port = -1;
52 static int hf_ypserv_value = -1;
53 static int hf_ypserv_status = -1;
54 static int hf_ypserv_map_parms = -1;
55 static int hf_ypserv_xfrstat = -1;
57 static gint ett_ypserv = -1;
58 static gint ett_ypserv_map_parms = -1;
60 static const value_string ypstat[] =
76 static const value_string xfrstat[] =
80 { -1, "YPXFR_NOMAP" },
81 { -2, "YPXFR_NODOM" },
84 { -5, "YPXFR_MADDR" },
85 { -6, "YPXFR_YPERR" },
86 { -7, "YPXFR_BADARGS" },
89 { -10, "YPXFR_SKEW" },
90 { -11, "YPXFR_CLEAR" },
91 { -12, "YPXFR_FORCE" },
92 { -13, "YPXFR_XFRERR" },
93 { -14, "YPXFR_REFUSED" },
98 dissect_domain_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
102 offset = dissect_rpc_string(tvb,tree,hf_ypserv_domain,offset,NULL);
109 dissect_domain_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
113 proto_tree_add_boolean(tree, hf_ypserv_servesdomain, tvb,
114 offset, 4, tvb_get_ntohl(tvb,offset));
122 dissect_match_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
126 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
127 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
128 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
135 dissect_match_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
139 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
141 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value,offset, NULL);
149 dissect_first_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
152 * XXX - does Sun's "yp.x" lie, and claim that the argument to a
153 * FIRST call is a "ypreq_key" rather than a "ypreq_nokey"?
154 * You presumably need the key for NEXT, as "next" is "next
155 * after some entry", and the key tells you which entry, but
156 * you don't need a key for FIRST, as there's only one entry that
157 * is the first entry.
159 * The NIS server originally used DBM, which has a "firstkey()"
160 * call, with no argument, and a "nextkey()" argument, with
161 * a key argument. (Heck, it might *still* use DBM.)
163 * Given that, and given that at least one FIRST call from a Sun
164 * running Solaris 8 (the Sun on which I'm typing this, in fact)
165 * had a "ypreq_nokey" as the argument, I'm assuming that "yp.x"
171 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
172 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
180 dissect_firstnext_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
184 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
186 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
187 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
195 dissect_next_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
199 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
200 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
201 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
208 dissect_xfr_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
210 proto_item *sub_item=NULL;
211 proto_tree *sub_tree=NULL;
212 int start_offset = offset;
215 sub_item = proto_tree_add_item(tree, hf_ypserv_map_parms, tvb,
218 sub_tree = proto_item_add_subtree(sub_item, ett_ypserv_map_parms);
221 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_domain, offset, NULL);
223 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_map, offset, NULL);
225 offset = dissect_rpc_uint32(tvb, sub_tree, hf_ypserv_ordernum, offset);
227 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_peer, offset, NULL);
229 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
232 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_prog, offset);
233 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_port, offset);
236 proto_item_set_len(sub_item, offset - start_offset);
242 dissect_xfr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
244 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
247 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_xfrstat, offset);
253 dissect_ypreq_nokey(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
256 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
258 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
264 dissect_ypresp_all(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
269 more = tvb_get_ntohl(tvb, offset);
271 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
274 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
275 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
276 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
283 dissect_ypresp_master(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
286 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
288 offset = dissect_rpc_string(tvb, tree, hf_ypserv_peer, offset, NULL);
295 dissect_ypresp_order(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
298 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
300 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_ordernum, offset);
307 dissect_ypresp_maplist(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
309 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
310 while(tvb_get_ntohl(tvb,offset)){
311 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
312 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
315 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
320 /* proc number, "proc name", dissect_request, dissect_reply */
321 /* NULL as function pointer means: type of arguments is "void". */
323 /* someone please get me a version 1 trace */
325 static const vsff ypserv1_proc[] = {
326 { 0, "NULL", NULL, NULL },
327 { YPPROC_DOMAIN, "DOMAIN",
329 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
331 { YPPROC_MATCH, "MATCH",
333 { YPPROC_FIRST, "FIRST",
335 { YPPROC_NEXT, "NEXT",
339 { YPPROC_CLEAR, "CLEAR",
343 { YPPROC_MASTER, "MASTER",
345 { YPPROC_ORDER, "ORDER",
347 { YPPROC_MAPLIST, "MAPLIST",
349 { 0, NULL, NULL, NULL }
352 static const value_string ypserv1_proc_vals[] = {
353 { YPPROC_DOMAIN, "DOMAIN" },
354 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK" },
355 { YPPROC_MATCH, "MATCH" },
356 { YPPROC_FIRST, "FIRST" },
357 { YPPROC_NEXT, "NEXT" },
358 { YPPROC_XFR, "XFR" },
359 { YPPROC_CLEAR, "CLEAR" },
360 { YPPROC_ALL, "ALL" },
361 { YPPROC_MASTER, "MASTER" },
362 { YPPROC_ORDER, "ORDER" },
363 { YPPROC_MAPLIST, "MAPLIST" },
367 /* end of YPServ version 1 */
369 /* proc number, "proc name", dissect_request, dissect_reply */
370 /* NULL as function pointer means: type of arguments is "void". */
372 static const vsff ypserv2_proc[] = {
373 { 0, "NULL", NULL, NULL },
374 { YPPROC_DOMAIN, "DOMAIN",
375 dissect_domain_call, dissect_domain_reply },
376 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
377 dissect_domain_call, dissect_domain_reply },
378 { YPPROC_MATCH, "MATCH",
379 dissect_match_call, dissect_match_reply },
380 { YPPROC_FIRST, "FIRST",
381 dissect_first_call, dissect_firstnext_reply },
382 { YPPROC_NEXT, "NEXT",
383 dissect_next_call, dissect_firstnext_reply },
385 dissect_xfr_call, dissect_xfr_reply },
386 { YPPROC_CLEAR, "CLEAR",
389 dissect_ypreq_nokey, dissect_ypresp_all },
390 { YPPROC_MASTER, "MASTER",
391 dissect_ypreq_nokey, dissect_ypresp_master },
392 { YPPROC_ORDER, "ORDER",
393 dissect_ypreq_nokey, dissect_ypresp_order },
394 { YPPROC_MAPLIST, "MAPLIST",
395 dissect_domain_call, dissect_ypresp_maplist },
396 { 0, NULL, NULL, NULL }
399 static const value_string ypserv2_proc_vals[] = {
400 { YPPROC_DOMAIN, "DOMAIN" },
401 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK" },
402 { YPPROC_MATCH, "MATCH" },
403 { YPPROC_FIRST, "FIRST" },
404 { YPPROC_NEXT, "NEXT" },
405 { YPPROC_XFR, "XFR" },
406 { YPPROC_CLEAR, "CLEAR" },
407 { YPPROC_ALL, "ALL" },
408 { YPPROC_MASTER, "MASTER" },
409 { YPPROC_ORDER, "ORDER" },
410 { YPPROC_MAPLIST, "MAPLIST" },
414 /* end of YPServ version 2 */
418 proto_register_ypserv(void)
420 /*static struct true_false_string okfailed = { "Ok", "Failed" };*/
421 static struct true_false_string yesno = { "Yes", "No" };
423 static hf_register_info hf[] = {
424 { &hf_ypserv_procedure_v1, {
425 "V1 Procedure", "ypserv.procedure_v1", FT_UINT32, BASE_DEC,
426 VALS(ypserv1_proc_vals), 0, "V1 Procedure", HFILL }},
427 { &hf_ypserv_procedure_v2, {
428 "V2 Procedure", "ypserv.procedure_v2", FT_UINT32, BASE_DEC,
429 VALS(ypserv2_proc_vals), 0, "V2 Procedure", HFILL }},
430 { &hf_ypserv_domain, {
431 "Domain", "ypserv.domain", FT_STRING, BASE_DEC,
432 NULL, 0, "Domain", HFILL }},
433 { &hf_ypserv_servesdomain, {
434 "Serves Domain", "ypserv.servesdomain", FT_BOOLEAN, BASE_DEC,
435 &yesno, 0, "Serves Domain", HFILL }},
437 "Map Name", "ypserv.map", FT_STRING, BASE_DEC,
438 NULL, 0, "Map Name", HFILL }},
440 "Peer Name", "ypserv.peer", FT_STRING, BASE_DEC,
441 NULL, 0, "Peer Name", HFILL }},
443 "More", "ypserv.more", FT_BOOLEAN, BASE_NONE,
444 &yesno, 0, "More", HFILL }},
445 { &hf_ypserv_ordernum, {
446 "Order Number", "ypserv.ordernum", FT_UINT32, BASE_DEC,
447 NULL, 0, "Order Number for XFR", HFILL }},
448 { &hf_ypserv_transid, {
449 "Host Transport ID", "ypserv.transid", FT_IPv4, BASE_DEC,
450 NULL, 0, "Host Transport ID to use for XFR Callback", HFILL }},
452 "Program Number", "ypserv.prog", FT_UINT32, BASE_DEC,
453 NULL, 0, "Program Number to use for XFR Callback", HFILL }},
455 "Port", "ypserv.port", FT_UINT32, BASE_DEC,
456 NULL, 0, "Port to use for XFR Callback", HFILL }},
458 "Key", "ypserv.key", FT_STRING, BASE_DEC,
459 NULL, 0, "Key", HFILL }},
460 { &hf_ypserv_value, {
461 "Value", "ypserv.value", FT_STRING, BASE_DEC,
462 NULL, 0, "Value", HFILL }},
463 { &hf_ypserv_status, {
464 "Status", "ypserv.status", FT_INT32, BASE_DEC,
465 VALS(ypstat) , 0, "Status", HFILL }},
466 { &hf_ypserv_map_parms, {
467 "YP Map Parameters", "ypserv.map_parms", FT_NONE, BASE_DEC,
468 NULL, 0, "YP Map Parameters", HFILL }},
469 { &hf_ypserv_xfrstat, {
470 "Xfrstat", "ypserv.xfrstat", FT_INT32, BASE_DEC,
471 VALS(xfrstat), 0, "Xfrstat", HFILL }},
473 static gint *ett[] = {
475 &ett_ypserv_map_parms,
478 proto_ypserv = proto_register_protocol("Yellow Pages Service",
480 proto_register_field_array(proto_ypserv, hf, array_length(hf));
481 proto_register_subtree_array(ett, array_length(ett));
485 proto_reg_handoff_ypserv(void)
487 /* Register the protocol as RPC */
488 rpc_init_prog(proto_ypserv, YPSERV_PROGRAM, ett_ypserv);
489 /* Register the procedure tables */
490 rpc_init_proc_table(YPSERV_PROGRAM, 1, ypserv1_proc,
491 hf_ypserv_procedure_v1);
492 rpc_init_proc_table(YPSERV_PROGRAM, 2, ypserv2_proc,
493 hf_ypserv_procedure_v2);