xref: /titanic_51/usr/src/uts/common/rpc/clnt_perr.c (revision 06e46062ef4f5f4b687cbafb4518fb123fe23920)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * Portions of this source code were derived from Berkeley 4.3 BSD
32  * under license from the Regents of the University of California.
33  */
34 
35 #pragma ident	"%Z%%M%	%I%	%E% SMI"
36 
37 /*
38  * clnt_perror.c
39  */
40 #include <sys/types.h>
41 #include <sys/t_lock.h>
42 #include <rpc/types.h>
43 #include <rpc/auth.h>
44 #include <rpc/clnt.h>
45 #include <sys/systm.h>
46 #include <sys/cmn_err.h>
47 #include <sys/inttypes.h>
48 
49 /*
50  * Return an ascii string which matches the RPC clnt stat passed in.
51  */
52 const char *
53 clnt_sperrno(const enum clnt_stat stat)
54 {
55 	switch (stat) {
56 	case RPC_SUCCESS:
57 		return ("RPC: Success");
58 	case RPC_CANTENCODEARGS:
59 		return ("RPC: Can't encode arguments");
60 	case RPC_CANTDECODERES:
61 		return ("RPC: Can't decode result");
62 	case RPC_CANTSEND:
63 		return ("RPC: Unable to send");
64 	case RPC_CANTRECV:
65 		return ("RPC: Unable to receive");
66 	case RPC_TIMEDOUT:
67 		return ("RPC: Timed out");
68 	case RPC_INTR:
69 		return ("RPC: Interrupted");
70 	case RPC_UDERROR:
71 		return ("RPC: Unitdata error");
72 	case RPC_VERSMISMATCH:
73 		return ("RPC: Incompatible versions of RPC");
74 	case RPC_AUTHERROR:
75 		return ("RPC: Authentication error");
76 	case RPC_PROGUNAVAIL:
77 		return ("RPC: Program unavailable");
78 	case RPC_PROGVERSMISMATCH:
79 		return ("RPC: Program/version mismatch");
80 	case RPC_PROCUNAVAIL:
81 		return ("RPC: Procedure unavailable");
82 	case RPC_CANTDECODEARGS:
83 		return ("RPC: Server can't decode arguments");
84 	case RPC_SYSTEMERROR:
85 		return ("RPC: Remote system error");
86 	case RPC_UNKNOWNHOST:
87 		return ("RPC: Unknown host");
88 	case RPC_UNKNOWNPROTO:
89 		return ("RPC: Unknown protocol");
90 	case RPC_UNKNOWNADDR:
91 		return ("RPC: Remote address unknown");
92 	case RPC_NOBROADCAST:
93 		return ("RPC: Broadcasting not supported");
94 	case RPC_PMAPFAILURE:
95 		return ("RPC: Port mapper failure");
96 	case RPC_PROGNOTREGISTERED:
97 		return ("RPC: Program not registered");
98 	case RPC_N2AXLATEFAILURE:
99 		return ("RPC: Name to address translation failed");
100 	case RPC_TLIERROR:
101 		return ("RPC: TLI error");
102 	case RPC_FAILED:
103 		return ("RPC: Failed (unspecified error)");
104 	case RPC_INPROGRESS:
105 		return ("RPC: Operation in progress");
106 	case RPC_STALERACHANDLE:
107 		return ("RPC: Stale RAC handle");
108 	case RPC_CANTCONNECT:
109 		return ("RPC: Couldn't make connection");
110 	case RPC_XPRTFAILED:
111 		return ("RPC: Received disconnect from remote");
112 	case RPC_CANTCREATESTREAM:
113 		return ("RPC: Can't push RPC module");
114 	case RPC_CANTSTORE:
115 		return ("RPC: Can't store pending message");
116 	}
117 	return ("RPC: (unknown error code)");
118 }
119 
120 /*
121  * Return string reply error info. For use after clnt_call().
122  * It allocates the  buffer of size MAXPATHLEN and assumes
123  * caller's responsibility to free the memory after use.
124  */
125 char *
126 clnt_sperror(const CLIENT *cl, const char *s)
127 {
128 	struct rpc_err e;
129 #ifdef notyet
130 	char *err;
131 #endif
132 	char *str;
133 	char *strstart;
134 
135 	str = kmem_alloc(MAXPATHLEN, KM_SLEEP);
136 	strstart = str;
137 
138 	CLNT_GETERR((CLIENT *) cl, &e);
139 
140 	(void) sprintf(str, "%s: ", s);
141 	str += strlen(str);
142 
143 	(void) strcpy(str, clnt_sperrno(e.re_status));
144 	str += strlen(str);
145 
146 	switch (e.re_status) {
147 	case RPC_SUCCESS:
148 	case RPC_CANTENCODEARGS:
149 	case RPC_CANTDECODERES:
150 	case RPC_TIMEDOUT:
151 	case RPC_PROGUNAVAIL:
152 	case RPC_PROCUNAVAIL:
153 	case RPC_CANTDECODEARGS:
154 	case RPC_SYSTEMERROR:
155 	case RPC_UNKNOWNHOST:
156 	case RPC_UNKNOWNPROTO:
157 	case RPC_UNKNOWNADDR:
158 	case RPC_NOBROADCAST:
159 	case RPC_RPCBFAILURE:
160 	case RPC_PROGNOTREGISTERED:
161 	case RPC_FAILED:
162 	case RPC_INPROGRESS:
163 		break;
164 
165 #ifdef notyet
166 	case RPC_N2AXLATEFAILURE:
167 		(void) sprintf(str, "; %s", netdir_sperror());
168 		break;
169 #endif
170 
171 	case RPC_TLIERROR:
172 #ifdef notyet
173 		(void) sprintf(str, "; %s", t_errlist[e.re_terrno]);
174 #else
175 		(void) sprintf(str, "; %d", e.re_terrno);
176 #endif
177 		str += strlen(str);
178 		if (e.re_errno) {
179 #ifdef notyet
180 			(void) sprintf(str, "; %s", strerror(e.re_errno));
181 #else
182 			(void) sprintf(str, "; %d", e.re_errno);
183 #endif
184 		}
185 		break;
186 
187 	case RPC_CANTSEND:
188 	case RPC_CANTRECV:
189 		if (e.re_errno) {
190 #ifdef notyet
191 			(void) sprintf(str, "; errno = %s",
192 			    strerror(e.re_errno));
193 #else
194 			(void) sprintf(str, "; errno = %d", e.re_errno);
195 #endif
196 			str += strlen(str);
197 		}
198 		if (e.re_terrno) {
199 #ifdef notyet
200 			(void) sprintf(str, "; %s", t_errlist[e.re_terrno]);
201 #else
202 			(void) sprintf(str, "; %d", e.re_terrno);
203 #endif
204 		}
205 		break;
206 
207 	case RPC_VERSMISMATCH:
208 		(void) sprintf(str,
209 		    "; low version = %" PRIu32 ", high version = %" PRIu32,
210 		    e.re_vers.low, e.re_vers.high);
211 		break;
212 
213 #ifdef notyet
214 	case RPC_AUTHERROR:
215 		err = auth_errmsg(e.re_why);
216 		(void) sprintf(str, "; why = ");
217 		str += strlen(str);
218 		if (err != NULL) {
219 			(void) sprintf(str, "%s", err);
220 		} else {
221 			(void) sprintf(str,
222 			    "(unknown authentication error - %d)",
223 			    (int)e.re_why);
224 		}
225 		break;
226 #endif
227 
228 	case RPC_PROGVERSMISMATCH:
229 		(void) sprintf(str,
230 		    "; low version = %" PRIu32 ", high version = %" PRIu32,
231 		    e.re_vers.low, e.re_vers.high);
232 		break;
233 
234 	default:	/* unknown */
235 		(void) sprintf(str, "; s1 = %" PRIu32 ", s2 = %" PRIu32,
236 		    e.re_lb.s1, e.re_lb.s2);
237 		break;
238 	}
239 	return (strstart);
240 }
241