2 * Routines for ypserv dissection
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_ypserv_status(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, gint32 *rstatus)
103 status=tvb_get_ntohl(tvb, offset);
107 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_status, offset);
110 err=val_to_str(status, ypstat, "Unknown error:%u");
111 if (check_col(pinfo->cinfo, COL_INFO)) {
112 col_append_fstr(pinfo->cinfo, COL_INFO," %s", err);
114 proto_item_append_text(tree, " Error:%s", err);
121 dissect_domain_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
123 proto_item_append_text(tree, " DOMAIN call");
127 offset = dissect_rpc_string(tvb,tree,hf_ypserv_domain,offset,NULL);
134 dissect_domain_nonack_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
136 proto_item_append_text(tree, " DOMAIN_NONACK call");
140 offset = dissect_rpc_string(tvb,tree,hf_ypserv_domain,offset,NULL);
147 dissect_maplist_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
149 proto_item_append_text(tree, " MAPLIST call");
153 offset = dissect_rpc_string(tvb,tree,hf_ypserv_domain,offset,NULL);
160 dissect_domain_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
162 proto_item_append_text(tree, " DOMAIN reply");
166 proto_tree_add_boolean(tree, hf_ypserv_servesdomain, tvb,
167 offset, 4, tvb_get_ntohl(tvb,offset));
175 dissect_domain_nonack_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
177 proto_item_append_text(tree, " DOMAIN_NONACK reply");
181 proto_tree_add_boolean(tree, hf_ypserv_servesdomain, tvb,
182 offset, 4, tvb_get_ntohl(tvb,offset));
190 dissect_match_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
194 proto_item_append_text(tree, " MATCH call");
197 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, &str);
198 if (check_col(pinfo->cinfo, COL_INFO)) {
199 col_append_fstr(pinfo->cinfo, COL_INFO," %s/", str);
201 proto_item_append_text(tree, " %s/", str);
205 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, &str);
206 if (check_col(pinfo->cinfo, COL_INFO)) {
207 col_append_fstr(pinfo->cinfo, COL_INFO,"%s/", str);
209 proto_item_append_text(tree, "%s/", str);
213 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, &str);
214 if (check_col(pinfo->cinfo, COL_INFO)) {
215 col_append_fstr(pinfo->cinfo, COL_INFO,"%s", str);
217 proto_item_append_text(tree, "%s", str);
224 dissect_match_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
229 proto_item_append_text(tree, " MATCH reply");
233 offset = dissect_ypserv_status(tvb, offset, pinfo, tree, &status);
236 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value,offset, &str);
237 if (check_col(pinfo->cinfo, COL_INFO)) {
238 col_append_fstr(pinfo->cinfo, COL_INFO," %s", str);
240 proto_item_append_text(tree, " %s", str);
244 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value,offset, NULL);
253 dissect_first_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
255 proto_item_append_text(tree, " FIRST call");
258 * XXX - does Sun's "yp.x" lie, and claim that the argument to a
259 * FIRST call is a "ypreq_key" rather than a "ypreq_nokey"?
260 * You presumably need the key for NEXT, as "next" is "next
261 * after some entry", and the key tells you which entry, but
262 * you don't need a key for FIRST, as there's only one entry that
263 * is the first entry.
265 * The NIS server originally used DBM, which has a "firstkey()"
266 * call, with no argument, and a "nextkey()" argument, with
267 * a key argument. (Heck, it might *still* use DBM.)
269 * Given that, and given that at least one FIRST call from a Sun
270 * running Solaris 8 (the Sun on which I'm typing this, in fact)
271 * had a "ypreq_nokey" as the argument, I'm assuming that "yp.x"
277 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
278 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
286 dissect_first_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
288 proto_item_append_text(tree, " FIRST reply");
292 offset = dissect_ypserv_status(tvb, offset, pinfo, tree, NULL);
294 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
295 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
302 dissect_next_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
304 proto_item_append_text(tree, " NEXT reply");
308 offset = dissect_ypserv_status(tvb, offset, pinfo, tree, NULL);
310 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
311 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
319 dissect_next_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
321 proto_item_append_text(tree, " NEXT call");
325 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
326 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
327 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
334 dissect_xfr_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
336 proto_item *sub_item=NULL;
337 proto_tree *sub_tree=NULL;
338 int start_offset = offset;
340 proto_item_append_text(tree, " XFR call");
343 sub_item = proto_tree_add_item(tree, hf_ypserv_map_parms, tvb,
346 sub_tree = proto_item_add_subtree(sub_item, ett_ypserv_map_parms);
349 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_domain, offset, NULL);
351 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_map, offset, NULL);
353 offset = dissect_rpc_uint32(tvb, sub_tree, hf_ypserv_ordernum, offset);
355 offset = dissect_rpc_string(tvb, sub_tree, hf_ypserv_peer, offset, NULL);
357 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
360 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_prog, offset);
361 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_port, offset);
364 proto_item_set_len(sub_item, offset - start_offset);
370 dissect_clear_call(tvbuff_t *tvb _U_, int offset, packet_info *pinfo _U_, proto_tree *tree)
372 proto_item_append_text(tree, " CLEAR call");
378 dissect_clear_reply(tvbuff_t *tvb _U_, int offset, packet_info *pinfo _U_, proto_tree *tree)
380 proto_item_append_text(tree, " CLEAR reply");
386 dissect_xfr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
388 proto_item_append_text(tree, " XFR reply");
390 proto_tree_add_item(tree, hf_ypserv_transid, tvb, offset, 4, FALSE);
393 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_xfrstat, offset);
399 dissect_order_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
403 proto_item_append_text(tree, " ORDER call");
406 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, &str);
407 if (check_col(pinfo->cinfo, COL_INFO)) {
408 col_append_fstr(pinfo->cinfo, COL_INFO," %s/", str);
410 proto_item_append_text(tree, " %s/", str);
414 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, &str);
415 if (check_col(pinfo->cinfo, COL_INFO)) {
416 col_append_fstr(pinfo->cinfo, COL_INFO,"%s", str);
418 proto_item_append_text(tree, "%s", str);
425 dissect_all_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
427 proto_item_append_text(tree, " ALL call");
429 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
431 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
437 dissect_master_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
439 proto_item_append_text(tree, " MASTER call");
441 offset = dissect_rpc_string(tvb, tree, hf_ypserv_domain, offset, NULL);
443 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
449 dissect_all_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
453 proto_item_append_text(tree, " ALL reply");
456 more = tvb_get_ntohl(tvb, offset);
458 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
461 offset = dissect_ypserv_status(tvb, offset, pinfo, tree, NULL);
463 offset = dissect_rpc_string(tvb, tree, hf_ypserv_value, offset, NULL);
464 offset = dissect_rpc_string(tvb, tree, hf_ypserv_key, offset, NULL);
471 dissect_master_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
473 proto_item_append_text(tree, " MASTER reply");
475 offset = dissect_ypserv_status(tvb, offset, pinfo, tree, NULL);
477 offset = dissect_rpc_string(tvb, tree, hf_ypserv_peer, offset, NULL);
484 dissect_order_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
488 proto_item_append_text(tree, " ORDER reply");
490 offset = dissect_ypserv_status(tvb, offset, pinfo, tree, NULL);
493 num=tvb_get_ntohl(tvb, offset);
494 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_ordernum, offset);
495 if (check_col(pinfo->cinfo, COL_INFO)) {
496 col_append_fstr(pinfo->cinfo, COL_INFO," 0x%08x", num);
498 proto_item_append_text(tree, " 0x%08x", num);
505 dissect_maplist_reply(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
507 proto_item_append_text(tree, " MAPLIST reply");
509 offset = dissect_ypserv_status(tvb, offset, pinfo, tree, NULL);
510 while(tvb_get_ntohl(tvb,offset)){
511 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
512 offset = dissect_rpc_string(tvb, tree, hf_ypserv_map, offset, NULL);
515 offset = dissect_rpc_uint32(tvb, tree, hf_ypserv_more, offset);
520 /* proc number, "proc name", dissect_request, dissect_reply */
521 /* NULL as function pointer means: type of arguments is "void". */
523 /* someone please get me a version 1 trace */
525 static const vsff ypserv1_proc[] = {
526 { 0, "NULL", NULL, NULL },
527 { YPPROC_DOMAIN, "DOMAIN",
529 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
531 { YPPROC_MATCH, "MATCH",
533 { YPPROC_FIRST, "FIRST",
535 { YPPROC_NEXT, "NEXT",
539 { YPPROC_CLEAR, "CLEAR",
543 { YPPROC_MASTER, "MASTER",
545 { YPPROC_ORDER, "ORDER",
547 { YPPROC_MAPLIST, "MAPLIST",
549 { 0, NULL, NULL, NULL }
552 static const value_string ypserv1_proc_vals[] = {
553 { YPPROC_DOMAIN, "DOMAIN" },
554 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK" },
555 { YPPROC_MATCH, "MATCH" },
556 { YPPROC_FIRST, "FIRST" },
557 { YPPROC_NEXT, "NEXT" },
558 { YPPROC_XFR, "XFR" },
559 { YPPROC_CLEAR, "CLEAR" },
560 { YPPROC_ALL, "ALL" },
561 { YPPROC_MASTER, "MASTER" },
562 { YPPROC_ORDER, "ORDER" },
563 { YPPROC_MAPLIST, "MAPLIST" },
567 /* end of YPServ version 1 */
569 /* proc number, "proc name", dissect_request, dissect_reply */
570 /* NULL as function pointer means: type of arguments is "void". */
572 static const vsff ypserv2_proc[] = {
573 { 0, "NULL", NULL, NULL },
574 { YPPROC_DOMAIN, "DOMAIN",
575 dissect_domain_call, dissect_domain_reply },
576 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK",
577 dissect_domain_nonack_call, dissect_domain_nonack_reply },
578 { YPPROC_MATCH, "MATCH",
579 dissect_match_call, dissect_match_reply },
580 { YPPROC_FIRST, "FIRST",
581 dissect_first_call, dissect_first_reply },
582 { YPPROC_NEXT, "NEXT",
583 dissect_next_call, dissect_next_reply },
585 dissect_xfr_call, dissect_xfr_reply },
586 { YPPROC_CLEAR, "CLEAR",
587 dissect_clear_call, dissect_clear_reply },
589 dissect_all_call, dissect_all_reply },
590 { YPPROC_MASTER, "MASTER",
591 dissect_master_call, dissect_master_reply },
592 { YPPROC_ORDER, "ORDER",
593 dissect_order_call, dissect_order_reply },
594 { YPPROC_MAPLIST, "MAPLIST",
595 dissect_maplist_call, dissect_maplist_reply },
596 { 0, NULL, NULL, NULL }
599 static const value_string ypserv2_proc_vals[] = {
600 { YPPROC_DOMAIN, "DOMAIN" },
601 { YPPROC_DOMAIN_NONACK, "DOMAIN_NONACK" },
602 { YPPROC_MATCH, "MATCH" },
603 { YPPROC_FIRST, "FIRST" },
604 { YPPROC_NEXT, "NEXT" },
605 { YPPROC_XFR, "XFR" },
606 { YPPROC_CLEAR, "CLEAR" },
607 { YPPROC_ALL, "ALL" },
608 { YPPROC_MASTER, "MASTER" },
609 { YPPROC_ORDER, "ORDER" },
610 { YPPROC_MAPLIST, "MAPLIST" },
614 /* end of YPServ version 2 */
618 proto_register_ypserv(void)
620 /*static struct true_false_string okfailed = { "Ok", "Failed" };*/
621 static struct true_false_string yesno = { "Yes", "No" };
623 static hf_register_info hf[] = {
624 { &hf_ypserv_procedure_v1, {
625 "V1 Procedure", "ypserv.procedure_v1", FT_UINT32, BASE_DEC,
626 VALS(ypserv1_proc_vals), 0, "V1 Procedure", HFILL }},
627 { &hf_ypserv_procedure_v2, {
628 "V2 Procedure", "ypserv.procedure_v2", FT_UINT32, BASE_DEC,
629 VALS(ypserv2_proc_vals), 0, "V2 Procedure", HFILL }},
630 { &hf_ypserv_domain, {
631 "Domain", "ypserv.domain", FT_STRING, BASE_DEC,
632 NULL, 0, "Domain", HFILL }},
633 { &hf_ypserv_servesdomain, {
634 "Serves Domain", "ypserv.servesdomain", FT_BOOLEAN, BASE_DEC,
635 &yesno, 0, "Serves Domain", HFILL }},
637 "Map Name", "ypserv.map", FT_STRING, BASE_DEC,
638 NULL, 0, "Map Name", HFILL }},
640 "Peer Name", "ypserv.peer", FT_STRING, BASE_DEC,
641 NULL, 0, "Peer Name", HFILL }},
643 "More", "ypserv.more", FT_BOOLEAN, BASE_NONE,
644 &yesno, 0, "More", HFILL }},
645 { &hf_ypserv_ordernum, {
646 "Order Number", "ypserv.ordernum", FT_UINT32, BASE_DEC,
647 NULL, 0, "Order Number for XFR", HFILL }},
648 { &hf_ypserv_transid, {
649 "Host Transport ID", "ypserv.transid", FT_IPv4, BASE_DEC,
650 NULL, 0, "Host Transport ID to use for XFR Callback", HFILL }},
652 "Program Number", "ypserv.prog", FT_UINT32, BASE_DEC,
653 NULL, 0, "Program Number to use for XFR Callback", HFILL }},
655 "Port", "ypserv.port", FT_UINT32, BASE_DEC,
656 NULL, 0, "Port to use for XFR Callback", HFILL }},
658 "Key", "ypserv.key", FT_STRING, BASE_DEC,
659 NULL, 0, "Key", HFILL }},
660 { &hf_ypserv_value, {
661 "Value", "ypserv.value", FT_STRING, BASE_DEC,
662 NULL, 0, "Value", HFILL }},
663 { &hf_ypserv_status, {
664 "Status", "ypserv.status", FT_INT32, BASE_DEC,
665 VALS(ypstat) , 0, "Status", HFILL }},
666 { &hf_ypserv_map_parms, {
667 "YP Map Parameters", "ypserv.map_parms", FT_NONE, BASE_DEC,
668 NULL, 0, "YP Map Parameters", HFILL }},
669 { &hf_ypserv_xfrstat, {
670 "Xfrstat", "ypserv.xfrstat", FT_INT32, BASE_DEC,
671 VALS(xfrstat), 0, "Xfrstat", HFILL }},
673 static gint *ett[] = {
675 &ett_ypserv_map_parms,
678 proto_ypserv = proto_register_protocol("Yellow Pages Service",
680 proto_register_field_array(proto_ypserv, hf, array_length(hf));
681 proto_register_subtree_array(ett, array_length(ett));
685 proto_reg_handoff_ypserv(void)
687 /* Register the protocol as RPC */
688 rpc_init_prog(proto_ypserv, YPSERV_PROGRAM, ett_ypserv);
689 /* Register the procedure tables */
690 rpc_init_proc_table(YPSERV_PROGRAM, 1, ypserv1_proc,
691 hf_ypserv_procedure_v1);
692 rpc_init_proc_table(YPSERV_PROGRAM, 2, ypserv2_proc,
693 hf_ypserv_procedure_v2);