2 * Routines for portmap 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 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include "packet-rpc.h"
34 #include "packet-portmap.h"
35 #include <epan/ipproto.h>
36 #include "epan/conversation.h"
37 #include "epan/packet_info.h"
42 * RFC 1833, "Binding Protocols for ONC RPC Version 2".
45 static int proto_portmap = -1;
46 static int hf_portmap_procedure_v1 = -1;
47 static int hf_portmap_procedure_v2 = -1;
48 static int hf_portmap_procedure_v3 = -1;
49 static int hf_portmap_procedure_v4 = -1;
50 static int hf_portmap_proto = -1;
51 static int hf_portmap_prog = -1;
52 static int hf_portmap_proc = -1;
53 static int hf_portmap_version = -1;
54 static int hf_portmap_port = -1;
55 static int hf_portmap_answer = -1;
56 static int hf_portmap_args = -1;
57 static int hf_portmap_result = -1;
58 static int hf_portmap_rpcb = -1;
59 static int hf_portmap_rpcb_prog = -1;
60 static int hf_portmap_rpcb_version = -1;
61 static int hf_portmap_rpcb_netid = -1;
62 static int hf_portmap_rpcb_addr = -1;
63 static int hf_portmap_rpcb_owner = -1;
64 static int hf_portmap_uaddr = -1;
67 static gint ett_portmap = -1;
68 static gint ett_portmap_rpcb = -1;
69 static gint ett_portmap_entry = -1;
71 static dissector_handle_t rpc_handle;
72 static dissector_handle_t rpc_tcp_handle;
74 /* Dissect a getport call */
76 dissect_getport_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
79 guint32 proto, version;
81 char *prog_name, *proto_name;
83 /* make sure we remember protocol type until the reply packet */
84 if(!pinfo->fd->flags.visited){
85 rpc_call_info_value *rpc_call=pinfo->private_data;
87 proto = tvb_get_ntohl(tvb, offset+8);
88 if(proto==IP_PROTO_UDP){ /* only do this for UDP */
89 rpc_call->private_data=(void *)PT_UDP;
95 prog = tvb_get_ntohl(tvb, offset+0);
96 prog_name = rpc_prog_name(prog);
97 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
98 offset, 4, prog, "Program: %s (%u)",
100 if (check_col(pinfo->cinfo, COL_INFO)) {
101 col_append_fstr(pinfo->cinfo, COL_INFO, " %s(%u)", prog_name, prog);
104 proto_item_append_text(tree, " GETPORT Call %s(%u)", prog_name, prog);
107 version = tvb_get_ntohl(tvb, offset+4);
108 proto_tree_add_item(tree, hf_portmap_version, tvb,
110 if (check_col(pinfo->cinfo, COL_INFO)) {
111 col_append_fstr(pinfo->cinfo, COL_INFO, " V:%d", version);
114 proto_item_append_text(tree, " Version:%d", version);
118 proto = tvb_get_ntohl(tvb, offset+8);
119 proto_name = (char *)ipprotostr(proto);
120 proto_tree_add_uint_format(tree, hf_portmap_proto, tvb,
121 offset+8, 4, proto, "Proto: %s (%u)", proto_name, proto);
122 if (check_col(pinfo->cinfo, COL_INFO)) {
123 col_append_fstr(pinfo->cinfo, COL_INFO, " %s", proto_name);
126 proto_item_append_text(tree, " %s", proto_name);
129 proto_tree_add_item(tree, hf_portmap_port, tvb,
130 offset+12, 4, FALSE);
136 dissect_getport_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
141 /* we might have learnt a <ipaddr><protocol><port> mapping for ONC-RPC*/
142 if(!pinfo->fd->flags.visited){
143 rpc_call_info_value *rpc_call=pinfo->private_data;
144 /* only do this for UDP, TCP does not need anything like this */
145 if(rpc_call && (GPOINTER_TO_UINT(rpc_call->private_data)==PT_UDP) ){
147 port=tvb_get_ntohl(tvb, offset);
149 conversation_t *conv;
150 conv=find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, (port_type)rpc_call->private_data, port, 0, NO_ADDR_B|NO_PORT_B);
152 conv=conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, (port_type)rpc_call->private_data, port, 0, NO_ADDR2|NO_PORT2);
154 conversation_set_dissector(conv, rpc_handle);
159 port = tvb_get_ntohl(tvb, offset);
160 offset = dissect_rpc_uint32(tvb, tree, hf_portmap_port,
162 proto_item_append_text(tree, " GETPORT Reply Port:%d", port);
164 if (check_col(pinfo->cinfo, COL_INFO)) {
165 col_append_fstr(pinfo->cinfo, COL_INFO, " Port:%d", port);
167 proto_item_append_text(tree, " Port:%d", port);
169 if (check_col(pinfo->cinfo, COL_INFO)) {
170 col_append_fstr(pinfo->cinfo, COL_INFO, " PROGRAM_NOT_AVAILABLE");
172 proto_item_append_text(tree, " PROGRAM_NOT_AVAILABLE");
178 /* Dissect a 'set' call */
180 dissect_set_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
188 prog = tvb_get_ntohl(tvb, offset+0);
189 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
190 offset, 4, prog, "Program: %s (%d)",
191 rpc_prog_name(prog), prog);
192 proto_tree_add_item(tree, hf_portmap_version, tvb,
195 proto = tvb_get_ntohl(tvb, offset+8);
196 proto_tree_add_uint_format(tree, hf_portmap_proto,tvb,
197 offset+8, 4, proto, "Proto: %s (%d)", ipprotostr(proto), proto);
199 proto_tree_add_item(tree, hf_portmap_port, tvb,
200 offset+12, 4, FALSE);
206 /* Dissect a 'unset' call */
208 dissect_unset_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
216 prog = tvb_get_ntohl(tvb, offset+0);
217 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
218 offset, 4, prog, "Program: %s (%d)",
219 rpc_prog_name(prog), prog);
220 proto_tree_add_item(tree, hf_portmap_version, tvb,
223 proto = tvb_get_ntohl(tvb, offset+8);
224 proto_tree_add_uint(tree, hf_portmap_proto, tvb,
227 proto_tree_add_item(tree, hf_portmap_port, tvb,
228 offset+12, 4, FALSE);
235 dissect_set_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
238 offset = dissect_rpc_bool(tvb, tree, hf_portmap_answer,
244 dissect_dump_entry(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
247 int prog, version, proto, port;
248 proto_item *ti, *subtree;
250 prog = tvb_get_ntohl(tvb, offset+0);
251 version = tvb_get_ntohl(tvb, offset+4);
252 proto = tvb_get_ntohl(tvb, offset+8);
253 port = tvb_get_ntohl(tvb, offset+12);
256 ti = proto_tree_add_text(tree, tvb, offset, 16,
257 "Map Entry: %s (%u) V%d",
258 rpc_prog_name(prog), prog, version);
259 subtree = proto_item_add_subtree(ti, ett_portmap_entry);
261 proto_tree_add_uint_format(subtree, hf_portmap_prog, tvb,
263 "Program: %s (%u)", rpc_prog_name(prog), prog);
264 proto_tree_add_uint(subtree, hf_portmap_version, tvb,
265 offset+4, 4, version);
266 proto_tree_add_uint_format(subtree, hf_portmap_proto, tvb,
268 "Protocol: %s (0x%02x)", ipprotostr(proto), proto);
269 proto_tree_add_uint(subtree, hf_portmap_port, tvb,
277 dissect_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
280 offset = dissect_rpc_list(tvb, pinfo, tree, offset,
285 /* Dissect a callit call */
287 dissect_callit_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
290 guint32 prog, vers, proc;
292 prog = tvb_get_ntohl(tvb, offset+0);
295 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
296 offset, 4, prog, "Program: %s (%u)",
297 rpc_prog_name(prog), prog);
300 vers = tvb_get_ntohl(tvb, offset+4);
303 proto_tree_add_uint(tree, hf_portmap_version, tvb,
307 proc = tvb_get_ntohl(tvb, offset+8);
310 proto_tree_add_uint_format(tree, hf_portmap_proc, tvb,
311 offset+8, 4, proc, "Procedure: %s (%u)",
312 rpc_proc_name(prog, vers, proc), proc);
317 /* Dissect the arguments for this procedure.
318 Make the columns non-writable, so the dissector won't change
319 them out from under us. */
320 col_set_writable(pinfo->cinfo, FALSE);
321 offset = dissect_rpc_indir_call(tvb, pinfo, tree, offset,
322 hf_portmap_args, prog, vers, proc);
327 /* Dissect a callit reply */
329 dissect_callit_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
334 proto_tree_add_item(tree, hf_portmap_port, tvb,
339 /* Dissect the result of this procedure.
340 Make the columns non-writable, so the dissector won't change
341 them out from under us. */
342 col_set_writable(pinfo->cinfo, FALSE);
343 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
344 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
350 /* proc number, "proc name", dissect_request, dissect_reply */
351 /* NULL as function pointer means: type of arguments is "void". */
352 static const vsff portmap1_proc[] = {
353 { PORTMAPPROC_NULL, "NULL", NULL, NULL },
354 { PORTMAPPROC_SET, "SET", NULL, NULL },
355 { PORTMAPPROC_UNSET, "UNSET", NULL, NULL },
356 { PORTMAPPROC_GETPORT, "GETPORT", NULL, NULL },
357 { PORTMAPPROC_DUMP, "DUMP", NULL, NULL },
358 { PORTMAPPROC_CALLIT, "CALLIT", NULL, NULL },
359 { 0, NULL, NULL, NULL }
361 static const value_string portmap1_proc_vals[] = {
362 { PORTMAPPROC_NULL, "NULL" },
363 { PORTMAPPROC_SET, "SET" },
364 { PORTMAPPROC_UNSET, "UNSET" },
365 { PORTMAPPROC_GETPORT, "GETPORT" },
366 { PORTMAPPROC_DUMP, "DUMP" },
367 { PORTMAPPROC_CALLIT, "CALLIT" },
370 /* end of Portmap version 1 */
372 static const vsff portmap2_proc[] = {
373 { PORTMAPPROC_NULL, "NULL",
375 { PORTMAPPROC_SET, "SET",
376 dissect_set_call, dissect_set_reply },
377 { PORTMAPPROC_UNSET, "UNSET",
378 dissect_unset_call, dissect_set_reply },
379 { PORTMAPPROC_GETPORT, "GETPORT",
380 dissect_getport_call, dissect_getport_reply },
381 { PORTMAPPROC_DUMP, "DUMP",
382 NULL, dissect_dump_reply },
383 { PORTMAPPROC_CALLIT, "CALLIT",
384 dissect_callit_call, dissect_callit_reply },
385 { 0, NULL, NULL, NULL }
387 static const value_string portmap2_proc_vals[] = {
388 { PORTMAPPROC_NULL, "NULL" },
389 { PORTMAPPROC_SET, "SET" },
390 { PORTMAPPROC_UNSET, "UNSET" },
391 { PORTMAPPROC_GETPORT, "GETPORT" },
392 { PORTMAPPROC_DUMP, "DUMP" },
393 { PORTMAPPROC_CALLIT, "CALLIT" },
396 /* end of Portmap version 2 */
399 /* RFC 1833, Page 3 */
401 dissect_rpcb(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
403 proto_item* rpcb_item = NULL;
404 proto_tree* rpcb_tree = NULL;
405 int old_offset = offset;
409 rpcb_item = proto_tree_add_item(tree, hf_portmap_rpcb, tvb,
412 rpcb_tree = proto_item_add_subtree(rpcb_item, ett_portmap_rpcb);
415 prog = tvb_get_ntohl(tvb, offset);
417 proto_tree_add_uint_format(rpcb_tree, hf_portmap_rpcb_prog, tvb,
419 "Program: %s (%u)", rpc_prog_name(prog), prog);
422 offset = dissect_rpc_uint32(tvb, rpcb_tree,
423 hf_portmap_rpcb_version, offset);
424 offset = dissect_rpc_string(tvb, rpcb_tree,
425 hf_portmap_rpcb_netid, offset, NULL);
426 offset = dissect_rpc_string(tvb, rpcb_tree,
427 hf_portmap_rpcb_addr, offset, NULL);
428 offset = dissect_rpc_string(tvb, rpcb_tree,
429 hf_portmap_rpcb_owner, offset, NULL);
431 /* now we know, that rpcb is shorter */
433 proto_item_set_len(rpcb_item, offset - old_offset);
441 /* RFC 1833, Page 7 */
443 dissect_rpcb3_getaddr_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
446 offset = dissect_rpcb(tvb, offset, pinfo, tree);
452 /* RFC 1833, Page 7 */
454 dissect_rpcb3_getaddr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
457 offset = dissect_rpc_string(tvb, tree,
458 hf_portmap_uaddr, offset, NULL);
464 /* RFC 1833, Page 7 */
466 dissect_rpcb3_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
469 offset = dissect_rpc_list(tvb, pinfo, tree, offset, dissect_rpcb);
473 /* RFC 1833, page 4 */
475 dissect_rpcb_rmtcallres(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
478 /* Dissect the remote universal address. */
479 offset = dissect_rpc_string(tvb, tree,
480 hf_portmap_rpcb_addr, offset, NULL);
482 /* Dissect the result of this procedure.
483 Make the columns non-writable, so the dissector won't change
484 them out from under us. */
485 col_set_writable(pinfo->cinfo, FALSE);
486 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
487 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
494 /* Portmapper version 3, RFC 1833, Page 7 */
495 static const vsff portmap3_proc[] = {
496 { RPCBPROC_NULL, "NULL",
498 { RPCBPROC_SET, "SET",
500 { RPCBPROC_UNSET, "UNSET",
502 { RPCBPROC_GETADDR, "GETADDR",
503 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
504 { RPCBPROC_DUMP, "DUMP",
505 NULL, dissect_rpcb3_dump_reply },
506 { RPCBPROC_CALLIT, "CALLIT",
507 dissect_callit_call, dissect_rpcb_rmtcallres },
508 { RPCBPROC_GETTIME, "GETTIME",
510 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
512 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
514 { 0, NULL, NULL, NULL }
516 static const value_string portmap3_proc_vals[] = {
517 { RPCBPROC_NULL, "NULL" },
518 { RPCBPROC_SET, "SET" },
519 { RPCBPROC_UNSET, "UNSET" },
520 { RPCBPROC_GETADDR, "GETADDR" },
521 { RPCBPROC_DUMP, "DUMP" },
522 { RPCBPROC_CALLIT, "CALLIT" },
523 { RPCBPROC_GETTIME, "GETTIME" },
524 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR" },
525 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR" },
528 /* end of Portmap version 3 */
531 /* Portmapper version 4, RFC 1833, Page 8 */
532 static const vsff portmap4_proc[] = {
533 { RPCBPROC_NULL, "NULL",
535 { RPCBPROC_SET, "SET",
537 { RPCBPROC_UNSET, "UNSET",
539 { RPCBPROC_GETADDR, "GETADDR",
540 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
541 { RPCBPROC_DUMP, "DUMP",
542 NULL, dissect_rpcb3_dump_reply },
543 { RPCBPROC_BCAST, "BCAST",
544 dissect_callit_call, dissect_rpcb_rmtcallres },
545 { RPCBPROC_GETTIME, "GETTIME",
547 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
549 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
551 { RPCBPROC_GETVERSADDR, "GETVERSADDR",
553 { RPCBPROC_INDIRECT, "INDIRECT",
554 dissect_callit_call, dissect_rpcb_rmtcallres },
555 { RPCBPROC_GETADDRLIST, "GETADDRLIST",
557 { RPCBPROC_GETSTAT, "GETSTAT",
559 { 0, NULL, NULL, NULL }
561 static const value_string portmap4_proc_vals[] = {
562 { RPCBPROC_NULL, "NULL" },
563 { RPCBPROC_SET, "SET" },
564 { RPCBPROC_UNSET, "UNSET" },
565 { RPCBPROC_GETADDR, "GETADDR" },
566 { RPCBPROC_DUMP, "DUMP" },
567 { RPCBPROC_BCAST, "BCAST" },
568 { RPCBPROC_GETTIME, "GETTIME" },
569 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR" },
570 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR" },
571 { RPCBPROC_GETVERSADDR, "GETVERSADDR" },
572 { RPCBPROC_INDIRECT, "INDIRECT" },
573 { RPCBPROC_GETADDRLIST, "GETADDRLIST" },
574 { RPCBPROC_GETSTAT, "GETSTAT" },
577 /* end of Portmap version 4 */
580 proto_register_portmap(void)
582 static hf_register_info hf[] = {
583 { &hf_portmap_procedure_v1, {
584 "V1 Procedure", "portmap.procedure_v1", FT_UINT32, BASE_DEC,
585 VALS(portmap1_proc_vals), 0, "V1 Procedure", HFILL }},
586 { &hf_portmap_procedure_v2, {
587 "V2 Procedure", "portmap.procedure_v2", FT_UINT32, BASE_DEC,
588 VALS(portmap2_proc_vals), 0, "V2 Procedure", HFILL }},
589 { &hf_portmap_procedure_v3, {
590 "V3 Procedure", "portmap.procedure_v3", FT_UINT32, BASE_DEC,
591 VALS(portmap3_proc_vals), 0, "V3 Procedure", HFILL }},
592 { &hf_portmap_procedure_v4, {
593 "V4 Procedure", "portmap.procedure_v4", FT_UINT32, BASE_DEC,
594 VALS(portmap4_proc_vals), 0, "V4 Procedure", HFILL }},
595 { &hf_portmap_prog, {
596 "Program", "portmap.prog", FT_UINT32, BASE_DEC,
597 NULL, 0, "Program", HFILL }},
598 { &hf_portmap_port, {
599 "Port", "portmap.port", FT_UINT32, BASE_DEC,
600 NULL, 0, "Port", HFILL }},
601 { &hf_portmap_proc, {
602 "Procedure", "portmap.proc", FT_UINT32, BASE_DEC,
603 NULL, 0, "Procedure", HFILL }},
604 { &hf_portmap_proto, {
605 "Protocol", "portmap.proto", FT_UINT32, BASE_DEC,
606 NULL, 0, "Protocol", HFILL }},
607 { &hf_portmap_version, {
608 "Version", "portmap.version", FT_UINT32, BASE_DEC,
609 NULL, 0, "Version", HFILL }},
610 { &hf_portmap_answer, {
611 "Answer", "portmap.answer", FT_BOOLEAN, BASE_DEC,
612 NULL, 0, "Answer", HFILL }},
613 { &hf_portmap_args, {
614 "Arguments", "portmap.args", FT_BYTES, BASE_HEX,
615 NULL, 0, "Arguments", HFILL }},
616 { &hf_portmap_result, {
617 "Result", "portmap.result", FT_BYTES, BASE_HEX,
618 NULL, 0, "Result", HFILL }},
619 { &hf_portmap_rpcb, {
620 "RPCB", "portmap.rpcb", FT_NONE, 0,
621 NULL, 0, "RPCB", HFILL }},
622 { &hf_portmap_rpcb_prog, {
623 "Program", "portmap.rpcb.prog", FT_UINT32, BASE_DEC,
624 NULL, 0, "Program", HFILL }},
625 { &hf_portmap_rpcb_version, {
626 "Version", "portmap.rpcb.version", FT_UINT32, BASE_DEC,
627 NULL, 0, "Version", HFILL }},
628 { &hf_portmap_rpcb_netid, {
629 "Network Id", "portmap.rpcb.netid", FT_STRING, BASE_DEC,
630 NULL, 0, "Network Id", HFILL }},
631 { &hf_portmap_rpcb_addr, { /* address in rpcb structure in request */
632 "Universal Address", "portmap.rpcb.addr", FT_STRING, BASE_DEC,
633 NULL, 0, "Universal Address", HFILL }},
634 { &hf_portmap_rpcb_owner, {
635 "Owner of this Service", "portmap.rpcb.owner", FT_STRING, BASE_DEC,
636 NULL, 0, "Owner of this Service", HFILL }},
637 { &hf_portmap_uaddr, { /* address in RPCBPROC_GETADDR reply */
638 "Universal Address", "portmap.uaddr", FT_STRING, BASE_DEC,
639 NULL, 0, "Universal Address", HFILL }},
641 static gint *ett[] = {
647 proto_portmap = proto_register_protocol("Portmap", "Portmap", "portmap");
648 proto_register_field_array(proto_portmap, hf, array_length(hf));
649 proto_register_subtree_array(ett, array_length(ett));
653 proto_reg_handoff_portmap(void)
655 /* Register the protocol as RPC */
656 rpc_init_prog(proto_portmap, PORTMAP_PROGRAM, ett_portmap);
657 /* Register the procedure tables */
658 rpc_init_proc_table(PORTMAP_PROGRAM, 1, portmap1_proc, hf_portmap_procedure_v1);
659 rpc_init_proc_table(PORTMAP_PROGRAM, 2, portmap2_proc, hf_portmap_procedure_v2);
660 rpc_init_proc_table(PORTMAP_PROGRAM, 3, portmap3_proc, hf_portmap_procedure_v3);
661 rpc_init_proc_table(PORTMAP_PROGRAM, 4, portmap4_proc, hf_portmap_procedure_v4);
662 rpc_handle = find_dissector("rpc");
663 rpc_tcp_handle = find_dissector("rpc-tcp");