print-sunrpc.c revision 1.5
1/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22#include <sys/cdefs.h>
23#ifndef lint
24__RCSID("$NetBSD: print-sunrpc.c,v 1.5 2014/11/20 03:05:03 christos Exp $");
25#endif
26
27#define NETDISSECT_REWORKED
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32/*
33 * At least on HP-UX:
34 *
35 *	1) getrpcbynumber() is declared in <netdb.h>, not any of the RPC
36 *	   header files
37 *
38 * and
39 *
40 *	2) if _XOPEN_SOURCE_EXTENDED is defined, <netdb.h> doesn't declare
41 *	   it
42 *
43 * so we undefine it.
44 */
45#undef _XOPEN_SOURCE_EXTENDED
46
47#include <tcpdump-stdinc.h>
48
49#if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
50#include <rpc/rpc.h>
51#ifdef HAVE_RPC_RPCENT_H
52#include <rpc/rpcent.h>
53#endif /* HAVE_RPC_RPCENT_H */
54#endif /* defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) */
55
56#include <stdio.h>
57#include <string.h>
58
59#include "interface.h"
60#include "addrtoname.h"
61#include "extract.h"
62
63#include "ip.h"
64#ifdef INET6
65#include "ip6.h"
66#endif
67
68#include "rpc_auth.h"
69#include "rpc_msg.h"
70
71/*
72 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
73 * unrestricted use provided that this legend is included on all tape
74 * media and as a part of the software program in whole or part.  Users
75 * may copy or modify Sun RPC without charge, but are not authorized
76 * to license or distribute it to anyone else except as part of a product or
77 * program developed by the user.
78 *
79 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
80 * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
81 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
82 *
83 * Sun RPC is provided with no support and without any obligation on the
84 * part of Sun Microsystems, Inc. to assist in its use, correction,
85 * modification or enhancement.
86 *
87 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
88 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
89 * OR ANY PART THEREOF.
90 *
91 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
92 * or profits or other special, indirect and consequential damages, even if
93 * Sun has been advised of the possibility of such damages.
94 *
95 * Sun Microsystems, Inc.
96 * 2550 Garcia Avenue
97 * Mountain View, California  94043
98 *
99 *	from: @(#)pmap_prot.h 1.14 88/02/08 SMI
100 *	from: @(#)pmap_prot.h	2.1 88/07/29 4.0 RPCSRC
101 * $FreeBSD: src/include/rpc/pmap_prot.h,v 1.9.2.1 1999/08/29 14:39:05 peter Exp $
102 */
103
104/*
105 * pmap_prot.h
106 * Protocol for the local binder service, or pmap.
107 *
108 * Copyright (C) 1984, Sun Microsystems, Inc.
109 *
110 * The following procedures are supported by the protocol:
111 *
112 * PMAPPROC_NULL() returns ()
113 * 	takes nothing, returns nothing
114 *
115 * PMAPPROC_SET(struct pmap) returns (bool_t)
116 * 	TRUE is success, FALSE is failure.  Registers the tuple
117 *	[prog, vers, prot, port].
118 *
119 * PMAPPROC_UNSET(struct pmap) returns (bool_t)
120 *	TRUE is success, FALSE is failure.  Un-registers pair
121 *	[prog, vers].  prot and port are ignored.
122 *
123 * PMAPPROC_GETPORT(struct pmap) returns (long unsigned).
124 *	0 is failure.  Otherwise returns the port number where the pair
125 *	[prog, vers] is registered.  It may lie!
126 *
127 * PMAPPROC_DUMP() RETURNS (struct pmaplist *)
128 *
129 * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>)
130 * 	RETURNS (port, string<>);
131 * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs);
132 * 	Calls the procedure on the local machine.  If it is not registered,
133 *	this procedure is quite; ie it does not return error information!!!
134 *	This procedure only is supported on rpc/udp and calls via
135 *	rpc/udp.  This routine only passes null authentication parameters.
136 *	This file has no interface to xdr routines for PMAPPROC_CALLIT.
137 *
138 * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
139 */
140
141#define SUNRPC_PMAPPORT		((uint16_t)111)
142#define SUNRPC_PMAPPROG		((uint32_t)100000)
143#define SUNRPC_PMAPVERS		((uint32_t)2)
144#define SUNRPC_PMAPVERS_PROTO	((uint32_t)2)
145#define SUNRPC_PMAPVERS_ORIG	((uint32_t)1)
146#define SUNRPC_PMAPPROC_NULL	((uint32_t)0)
147#define SUNRPC_PMAPPROC_SET	((uint32_t)1)
148#define SUNRPC_PMAPPROC_UNSET	((uint32_t)2)
149#define SUNRPC_PMAPPROC_GETPORT	((uint32_t)3)
150#define SUNRPC_PMAPPROC_DUMP	((uint32_t)4)
151#define SUNRPC_PMAPPROC_CALLIT	((uint32_t)5)
152
153struct sunrpc_pmap {
154	uint32_t pm_prog;
155	uint32_t pm_vers;
156	uint32_t pm_prot;
157	uint32_t pm_port;
158};
159
160static const struct tok proc2str[] = {
161	{ SUNRPC_PMAPPROC_NULL,		"null" },
162	{ SUNRPC_PMAPPROC_SET,		"set" },
163	{ SUNRPC_PMAPPROC_UNSET,	"unset" },
164	{ SUNRPC_PMAPPROC_GETPORT,	"getport" },
165	{ SUNRPC_PMAPPROC_DUMP,		"dump" },
166	{ SUNRPC_PMAPPROC_CALLIT,	"call" },
167	{ 0,				NULL }
168};
169
170/* Forwards */
171static char *progstr(uint32_t);
172
173void
174sunrpcrequest_print(netdissect_options *ndo, register const u_char *bp,
175                    register u_int length, register const u_char *bp2)
176{
177	register const struct sunrpc_msg *rp;
178	register const struct ip *ip;
179#ifdef INET6
180	register const struct ip6_hdr *ip6;
181#endif
182	uint32_t x;
183	char srcid[20], dstid[20];	/*fits 32bit*/
184
185	rp = (struct sunrpc_msg *)bp;
186
187	if (!ndo->ndo_nflag) {
188		snprintf(srcid, sizeof(srcid), "0x%x",
189		    EXTRACT_32BITS(&rp->rm_xid));
190		strlcpy(dstid, "sunrpc", sizeof(dstid));
191	} else {
192		snprintf(srcid, sizeof(srcid), "0x%x",
193		    EXTRACT_32BITS(&rp->rm_xid));
194		snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT);
195	}
196
197	switch (IP_V((struct ip *)bp2)) {
198	case 4:
199		ip = (struct ip *)bp2;
200		ND_PRINT((ndo, "%s.%s > %s.%s: %d",
201		    ipaddr_string(ndo, &ip->ip_src), srcid,
202		    ipaddr_string(ndo, &ip->ip_dst), dstid, length));
203		break;
204#ifdef INET6
205	case 6:
206		ip6 = (struct ip6_hdr *)bp2;
207		ND_PRINT((ndo, "%s.%s > %s.%s: %d",
208		    ip6addr_string(ndo, &ip6->ip6_src), srcid,
209		    ip6addr_string(ndo, &ip6->ip6_dst), dstid, length));
210		break;
211#endif
212	default:
213		ND_PRINT((ndo, "%s.%s > %s.%s: %d", "?", srcid, "?", dstid, length));
214		break;
215	}
216
217	ND_PRINT((ndo, " %s", tok2str(proc2str, " proc #%u",
218	    EXTRACT_32BITS(&rp->rm_call.cb_proc))));
219	x = EXTRACT_32BITS(&rp->rm_call.cb_rpcvers);
220	if (x != 2)
221		ND_PRINT((ndo, " [rpcver %u]", x));
222
223	switch (EXTRACT_32BITS(&rp->rm_call.cb_proc)) {
224
225	case SUNRPC_PMAPPROC_SET:
226	case SUNRPC_PMAPPROC_UNSET:
227	case SUNRPC_PMAPPROC_GETPORT:
228	case SUNRPC_PMAPPROC_CALLIT:
229		x = EXTRACT_32BITS(&rp->rm_call.cb_prog);
230		if (!ndo->ndo_nflag)
231			ND_PRINT((ndo, " %s", progstr(x)));
232		else
233			ND_PRINT((ndo, " %u", x));
234		ND_PRINT((ndo, ".%u", EXTRACT_32BITS(&rp->rm_call.cb_vers)));
235		break;
236	}
237}
238
239static char *
240progstr(uint32_t prog)
241{
242#if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
243	register struct rpcent *rp;
244#endif
245	static char buf[32];
246	static uint32_t lastprog = 0;
247
248	if (lastprog != 0 && prog == lastprog)
249		return (buf);
250#if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
251	rp = getrpcbynumber(prog);
252	if (rp == NULL)
253#endif
254		(void) snprintf(buf, sizeof(buf), "#%u", prog);
255#if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H)
256	else
257		strlcpy(buf, rp->r_name, sizeof(buf));
258#endif
259	return (buf);
260}
261