2 * Routines for portmap dissection
4 * $Id: packet-portmap.c,v 1.41 2002/11/01 00:48:38 sahlberg 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 * 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"
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_,
82 /* make sure we remember protocol type until the reply packet */
83 if(!pinfo->fd->flags.visited){
84 rpc_call_info_value *rpc_call=pinfo->private_data;
86 proto = tvb_get_ntohl(tvb, offset+8);
87 if(proto==IP_PROTO_UDP){ /* only do this for UDP */
88 rpc_call->private_data=(void *)PT_UDP;
95 prog = tvb_get_ntohl(tvb, offset+0);
96 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
97 offset, 4, prog, "Program: %s (%u)",
98 rpc_prog_name(prog), prog);
99 proto_tree_add_item(tree, hf_portmap_version, tvb,
102 proto = tvb_get_ntohl(tvb, offset+8);
103 proto_tree_add_uint_format(tree, hf_portmap_proto, tvb,
104 offset+8, 4, proto, "Proto: %s (%u)", ipprotostr(proto), proto);
106 proto_tree_add_item(tree, hf_portmap_port, tvb,
107 offset+12, 4, FALSE);
114 dissect_getport_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
117 /* we might have learnt a <ipaddr><protocol><port> mapping for ONC-RPC*/
118 if(!pinfo->fd->flags.visited){
119 rpc_call_info_value *rpc_call=pinfo->private_data;
120 /* only do this for UDP, TCP does not need anything like this */
121 if(rpc_call && ((int)rpc_call->private_data==PT_UDP) ){
123 port=tvb_get_ntohl(tvb, offset);
125 conversation_t *conv;
126 conv=find_conversation(&pinfo->src, &pinfo->dst, (port_type)rpc_call->private_data, port, 0, NO_ADDR_B|NO_PORT_B);
128 conv=conversation_new(&pinfo->src, &pinfo->dst, (port_type)rpc_call->private_data, port, 0, NO_ADDR_B|NO_PORT_B);
130 conversation_set_dissector(conv, rpc_handle);
135 offset = dissect_rpc_uint32(tvb, tree, hf_portmap_port,
140 /* Dissect a 'set' call */
142 dissect_set_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
150 prog = tvb_get_ntohl(tvb, offset+0);
151 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
152 offset, 4, prog, "Program: %s (%d)",
153 rpc_prog_name(prog), prog);
154 proto_tree_add_item(tree, hf_portmap_version, tvb,
157 proto = tvb_get_ntohl(tvb, offset+8);
158 proto_tree_add_uint_format(tree, hf_portmap_proto,tvb,
159 offset+8, 4, proto, "Proto: %s (%d)", ipprotostr(proto), proto);
161 proto_tree_add_item(tree, hf_portmap_port, tvb,
162 offset+12, 4, FALSE);
168 /* Dissect a 'unset' call */
170 dissect_unset_call(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
178 prog = tvb_get_ntohl(tvb, offset+0);
179 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
180 offset, 4, prog, "Program: %s (%d)",
181 rpc_prog_name(prog), prog);
182 proto_tree_add_item(tree, hf_portmap_version, tvb,
185 proto = tvb_get_ntohl(tvb, offset+8);
186 proto_tree_add_uint(tree, hf_portmap_proto, tvb,
189 proto_tree_add_item(tree, hf_portmap_port, tvb,
190 offset+12, 4, FALSE);
197 dissect_set_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
200 offset = dissect_rpc_bool(tvb, tree, hf_portmap_answer,
206 dissect_dump_entry(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
209 int prog, version, proto, port;
210 proto_item *ti, *subtree;
212 prog = tvb_get_ntohl(tvb, offset+0);
213 version = tvb_get_ntohl(tvb, offset+4);
214 proto = tvb_get_ntohl(tvb, offset+8);
215 port = tvb_get_ntohl(tvb, offset+12);
218 ti = proto_tree_add_text(tree, tvb, offset, 16,
219 "Map Entry: %s (%u) V%d",
220 rpc_prog_name(prog), prog, version);
221 subtree = proto_item_add_subtree(ti, ett_portmap_entry);
223 proto_tree_add_uint_format(subtree, hf_portmap_prog, tvb,
225 "Program: %s (%u)", rpc_prog_name(prog), prog);
226 proto_tree_add_uint(subtree, hf_portmap_version, tvb,
227 offset+4, 4, version);
228 proto_tree_add_uint_format(subtree, hf_portmap_proto, tvb,
230 "Protocol: %s (0x%02x)", ipprotostr(proto), proto);
231 proto_tree_add_uint(subtree, hf_portmap_port, tvb,
239 dissect_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
242 offset = dissect_rpc_list(tvb, pinfo, tree, offset,
247 /* Dissect a callit call */
249 dissect_callit_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
252 guint32 prog, vers, proc;
254 prog = tvb_get_ntohl(tvb, offset+0);
257 proto_tree_add_uint_format(tree, hf_portmap_prog, tvb,
258 offset, 4, prog, "Program: %s (%u)",
259 rpc_prog_name(prog), prog);
262 vers = tvb_get_ntohl(tvb, offset+4);
265 proto_tree_add_uint(tree, hf_portmap_version, tvb,
269 proc = tvb_get_ntohl(tvb, offset+8);
272 proto_tree_add_uint_format(tree, hf_portmap_proc, tvb,
273 offset+8, 4, proc, "Procedure: %s (%u)",
274 rpc_proc_name(prog, vers, proc), proc);
279 /* Dissect the arguments for this procedure.
280 Make the columns non-writable, so the dissector won't change
281 them out from under us. */
282 col_set_writable(pinfo->cinfo, FALSE);
283 offset = dissect_rpc_indir_call(tvb, pinfo, tree, offset,
284 hf_portmap_args, prog, vers, proc);
289 /* Dissect a callit reply */
291 dissect_callit_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
296 proto_tree_add_item(tree, hf_portmap_port, tvb,
301 /* Dissect the result of this procedure.
302 Make the columns non-writable, so the dissector won't change
303 them out from under us. */
304 col_set_writable(pinfo->cinfo, FALSE);
305 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
306 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
312 /* proc number, "proc name", dissect_request, dissect_reply */
313 /* NULL as function pointer means: type of arguments is "void". */
314 static const vsff portmap1_proc[] = {
315 { PORTMAPPROC_NULL, "NULL", NULL, NULL },
316 { PORTMAPPROC_SET, "SET", NULL, NULL },
317 { PORTMAPPROC_UNSET, "UNSET", NULL, NULL },
318 { PORTMAPPROC_GETPORT, "GETPORT", NULL, NULL },
319 { PORTMAPPROC_DUMP, "DUMP", NULL, NULL },
320 { PORTMAPPROC_CALLIT, "CALLIT", NULL, NULL },
321 { 0, NULL, NULL, NULL }
323 static const value_string portmap1_proc_vals[] = {
324 { PORTMAPPROC_NULL, "NULL" },
325 { PORTMAPPROC_SET, "SET" },
326 { PORTMAPPROC_UNSET, "UNSET" },
327 { PORTMAPPROC_GETPORT, "GETPORT" },
328 { PORTMAPPROC_DUMP, "DUMP" },
329 { PORTMAPPROC_CALLIT, "CALLIT" },
332 /* end of Portmap version 1 */
334 static const vsff portmap2_proc[] = {
335 { PORTMAPPROC_NULL, "NULL",
337 { PORTMAPPROC_SET, "SET",
338 dissect_set_call, dissect_set_reply },
339 { PORTMAPPROC_UNSET, "UNSET",
340 dissect_unset_call, dissect_set_reply },
341 { PORTMAPPROC_GETPORT, "GETPORT",
342 dissect_getport_call, dissect_getport_reply },
343 { PORTMAPPROC_DUMP, "DUMP",
344 NULL, dissect_dump_reply },
345 { PORTMAPPROC_CALLIT, "CALLIT",
346 dissect_callit_call, dissect_callit_reply },
347 { 0, NULL, NULL, NULL }
349 static const value_string portmap2_proc_vals[] = {
350 { PORTMAPPROC_NULL, "NULL" },
351 { PORTMAPPROC_SET, "SET" },
352 { PORTMAPPROC_UNSET, "UNSET" },
353 { PORTMAPPROC_GETPORT, "GETPORT" },
354 { PORTMAPPROC_DUMP, "DUMP" },
355 { PORTMAPPROC_CALLIT, "CALLIT" },
358 /* end of Portmap version 2 */
361 /* RFC 1833, Page 3 */
363 dissect_rpcb(tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree)
365 proto_item* rpcb_item = NULL;
366 proto_tree* rpcb_tree = NULL;
367 int old_offset = offset;
371 rpcb_item = proto_tree_add_item(tree, hf_portmap_rpcb, tvb,
374 rpcb_tree = proto_item_add_subtree(rpcb_item, ett_portmap_rpcb);
377 prog = tvb_get_ntohl(tvb, offset);
379 proto_tree_add_uint_format(rpcb_tree, hf_portmap_rpcb_prog, tvb,
381 "Program: %s (%u)", rpc_prog_name(prog), prog);
384 offset = dissect_rpc_uint32(tvb, rpcb_tree,
385 hf_portmap_rpcb_version, offset);
386 offset = dissect_rpc_string(tvb, rpcb_tree,
387 hf_portmap_rpcb_netid, offset, NULL);
388 offset = dissect_rpc_string(tvb, rpcb_tree,
389 hf_portmap_rpcb_addr, offset, NULL);
390 offset = dissect_rpc_string(tvb, rpcb_tree,
391 hf_portmap_rpcb_owner, offset, NULL);
393 /* now we know, that rpcb is shorter */
395 proto_item_set_len(rpcb_item, offset - old_offset);
403 /* RFC 1833, Page 7 */
405 dissect_rpcb3_getaddr_call(tvbuff_t *tvb, int offset, packet_info *pinfo,
408 offset = dissect_rpcb(tvb, offset, pinfo, tree);
414 /* RFC 1833, Page 7 */
416 dissect_rpcb3_getaddr_reply(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
419 offset = dissect_rpc_string(tvb, tree,
420 hf_portmap_uaddr, offset, NULL);
426 /* RFC 1833, Page 7 */
428 dissect_rpcb3_dump_reply(tvbuff_t *tvb, int offset, packet_info *pinfo,
431 offset = dissect_rpc_list(tvb, pinfo, tree, offset, dissect_rpcb);
435 /* RFC 1833, page 4 */
437 dissect_rpcb_rmtcallres(tvbuff_t *tvb, int offset, packet_info *pinfo _U_,
440 /* Dissect the remote universal address. */
441 offset = dissect_rpc_string(tvb, tree,
442 hf_portmap_rpcb_addr, offset, NULL);
444 /* Dissect the result of this procedure.
445 Make the columns non-writable, so the dissector won't change
446 them out from under us. */
447 col_set_writable(pinfo->cinfo, FALSE);
448 offset = dissect_rpc_indir_reply(tvb, pinfo, tree, offset,
449 hf_portmap_result, hf_portmap_prog, hf_portmap_version,
456 /* Portmapper version 3, RFC 1833, Page 7 */
457 static const vsff portmap3_proc[] = {
458 { RPCBPROC_NULL, "NULL",
460 { RPCBPROC_SET, "SET",
462 { RPCBPROC_UNSET, "UNSET",
464 { RPCBPROC_GETADDR, "GETADDR",
465 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
466 { RPCBPROC_DUMP, "DUMP",
467 NULL, dissect_rpcb3_dump_reply },
468 { RPCBPROC_CALLIT, "CALLIT",
469 dissect_callit_call, dissect_rpcb_rmtcallres },
470 { RPCBPROC_GETTIME, "GETTIME",
472 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
474 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
476 { 0, NULL, NULL, NULL }
478 static const value_string portmap3_proc_vals[] = {
479 { RPCBPROC_NULL, "NULL" },
480 { RPCBPROC_SET, "SET" },
481 { RPCBPROC_UNSET, "UNSET" },
482 { RPCBPROC_GETADDR, "GETADDR" },
483 { RPCBPROC_DUMP, "DUMP" },
484 { RPCBPROC_CALLIT, "CALLIT" },
485 { RPCBPROC_GETTIME, "GETTIME" },
486 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR" },
487 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR" },
490 /* end of Portmap version 3 */
493 /* Portmapper version 4, RFC 1833, Page 8 */
494 static const vsff portmap4_proc[] = {
495 { RPCBPROC_NULL, "NULL",
497 { RPCBPROC_SET, "SET",
499 { RPCBPROC_UNSET, "UNSET",
501 { RPCBPROC_GETADDR, "GETADDR",
502 dissect_rpcb3_getaddr_call, dissect_rpcb3_getaddr_reply},
503 { RPCBPROC_DUMP, "DUMP",
504 NULL, dissect_rpcb3_dump_reply },
505 { RPCBPROC_BCAST, "BCAST",
506 dissect_callit_call, dissect_rpcb_rmtcallres },
507 { RPCBPROC_GETTIME, "GETTIME",
509 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR",
511 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR",
513 { RPCBPROC_GETVERSADDR, "GETVERSADDR",
515 { RPCBPROC_INDIRECT, "INDIRECT",
516 dissect_callit_call, dissect_rpcb_rmtcallres },
517 { RPCBPROC_GETADDRLIST, "GETADDRLIST",
519 { RPCBPROC_GETSTAT, "GETSTAT",
521 { 0, NULL, NULL, NULL }
523 static const value_string portmap4_proc_vals[] = {
524 { RPCBPROC_NULL, "NULL" },
525 { RPCBPROC_SET, "SET" },
526 { RPCBPROC_UNSET, "UNSET" },
527 { RPCBPROC_GETADDR, "GETADDR" },
528 { RPCBPROC_DUMP, "DUMP" },
529 { RPCBPROC_BCAST, "BCAST" },
530 { RPCBPROC_GETTIME, "GETTIME" },
531 { RPCBPROC_UADDR2TADDR, "UADDR2TADDR" },
532 { RPCBPROC_TADDR2UADDR, "TADDR2UADDR" },
533 { RPCBPROC_GETVERSADDR, "GETVERSADDR" },
534 { RPCBPROC_INDIRECT, "INDIRECT" },
535 { RPCBPROC_GETADDRLIST, "GETADDRLIST" },
536 { RPCBPROC_GETSTAT, "GETSTAT" },
539 /* end of Portmap version 4 */
542 proto_register_portmap(void)
544 static hf_register_info hf[] = {
545 { &hf_portmap_procedure_v1, {
546 "V1 Procedure", "portmap.procedure_v1", FT_UINT32, BASE_DEC,
547 VALS(portmap1_proc_vals), 0, "V1 Procedure", HFILL }},
548 { &hf_portmap_procedure_v2, {
549 "V2 Procedure", "portmap.procedure_v2", FT_UINT32, BASE_DEC,
550 VALS(portmap2_proc_vals), 0, "V2 Procedure", HFILL }},
551 { &hf_portmap_procedure_v3, {
552 "V3 Procedure", "portmap.procedure_v3", FT_UINT32, BASE_DEC,
553 VALS(portmap3_proc_vals), 0, "V3 Procedure", HFILL }},
554 { &hf_portmap_procedure_v4, {
555 "V4 Procedure", "portmap.procedure_v4", FT_UINT32, BASE_DEC,
556 VALS(portmap4_proc_vals), 0, "V4 Procedure", HFILL }},
557 { &hf_portmap_prog, {
558 "Program", "portmap.prog", FT_UINT32, BASE_DEC,
559 NULL, 0, "Program", HFILL }},
560 { &hf_portmap_port, {
561 "Port", "portmap.port", FT_UINT32, BASE_DEC,
562 NULL, 0, "Port", HFILL }},
563 { &hf_portmap_proc, {
564 "Procedure", "portmap.proc", FT_UINT32, BASE_DEC,
565 NULL, 0, "Procedure", HFILL }},
566 { &hf_portmap_proto, {
567 "Protocol", "portmap.proto", FT_UINT32, BASE_DEC,
568 NULL, 0, "Protocol", HFILL }},
569 { &hf_portmap_version, {
570 "Version", "portmap.version", FT_UINT32, BASE_DEC,
571 NULL, 0, "Version", HFILL }},
572 { &hf_portmap_answer, {
573 "Answer", "portmap.answer", FT_BOOLEAN, BASE_DEC,
574 NULL, 0, "Answer", HFILL }},
575 { &hf_portmap_args, {
576 "Arguments", "portmap.args", FT_BYTES, BASE_HEX,
577 NULL, 0, "Arguments", HFILL }},
578 { &hf_portmap_result, {
579 "Result", "portmap.result", FT_BYTES, BASE_HEX,
580 NULL, 0, "Result", HFILL }},
581 { &hf_portmap_rpcb, {
582 "RPCB", "portmap.rpcb", FT_NONE, 0,
583 NULL, 0, "RPCB", HFILL }},
584 { &hf_portmap_rpcb_prog, {
585 "Program", "portmap.rpcb.prog", FT_UINT32, BASE_DEC,
586 NULL, 0, "Program", HFILL }},
587 { &hf_portmap_rpcb_version, {
588 "Version", "portmap.rpcb.version", FT_UINT32, BASE_DEC,
589 NULL, 0, "Version", HFILL }},
590 { &hf_portmap_rpcb_netid, {
591 "Network Id", "portmap.rpcb.netid", FT_STRING, BASE_DEC,
592 NULL, 0, "Network Id", HFILL }},
593 { &hf_portmap_rpcb_addr, { /* address in rpcb structure in request */
594 "Universal Address", "portmap.rpcb.addr", FT_STRING, BASE_DEC,
595 NULL, 0, "Universal Address", HFILL }},
596 { &hf_portmap_rpcb_owner, {
597 "Owner of this Service", "portmap.rpcb.owner", FT_STRING, BASE_DEC,
598 NULL, 0, "Owner of this Service", HFILL }},
599 { &hf_portmap_uaddr, { /* address in RPCBPROC_GETADDR reply */
600 "Universal Address", "portmap.uaddr", FT_STRING, BASE_DEC,
601 NULL, 0, "Universal Address", HFILL }},
603 static gint *ett[] = {
609 proto_portmap = proto_register_protocol("Portmap", "Portmap", "portmap");
610 proto_register_field_array(proto_portmap, hf, array_length(hf));
611 proto_register_subtree_array(ett, array_length(ett));
615 proto_reg_handoff_portmap(void)
617 /* Register the protocol as RPC */
618 rpc_init_prog(proto_portmap, PORTMAP_PROGRAM, ett_portmap);
619 /* Register the procedure tables */
620 rpc_init_proc_table(PORTMAP_PROGRAM, 1, portmap1_proc, hf_portmap_procedure_v1);
621 rpc_init_proc_table(PORTMAP_PROGRAM, 2, portmap2_proc, hf_portmap_procedure_v2);
622 rpc_init_proc_table(PORTMAP_PROGRAM, 3, portmap3_proc, hf_portmap_procedure_v3);
623 rpc_init_proc_table(PORTMAP_PROGRAM, 4, portmap4_proc, hf_portmap_procedure_v4);
624 rpc_handle = find_dissector("rpc");
625 rpc_tcp_handle = find_dissector("rpc-tcp");