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
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.
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]
23 * Copyright (c) 1991, 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
30 #include <sys/types.h>
31 #include <sys/errno.h>
33 #include <sys/tiuser.h>
36 #include <rpc/types.h>
40 #include <rpc/rpc_msg.h>
41 #include <rpc/pmap_prot.h>
45 * Number of bytes to display from a string (address, netid, etc.).
47 #define MAXSTRINGLEN 64
49 extern char *dlc_header
;
50 extern jmp_buf xdr_err
;
52 static void interpret_pmap_2(int, int, int, int, int, char *, int);
53 static void interpret_pmap_4(int, int, int, int, int, char *, int);
54 static void stash_callit(ulong_t
, int, int, int, int);
57 interpret_pmap(flags
, type
, xid
, vers
, proc
, data
, len
)
58 int flags
, type
, xid
, vers
, proc
;
63 case 2: interpret_pmap_2(flags
, type
, xid
, vers
, proc
, data
, len
);
66 /* Version 3 is a subset of version 4 */
68 case 4: interpret_pmap_4(flags
, type
, xid
, vers
, proc
, data
, len
);
77 static char *procnames_short_2
[] = {
86 static char *procnames_long_2
[] = {
87 "Null procedure", /* 0 */
90 "Get port number", /* 3 */
91 "Dump the mappings", /* 4 */
92 "Indirect call", /* 5 */
98 interpret_pmap_2(flags
, type
, xid
, vers
, proc
, data
, len
)
99 int flags
, type
, xid
, vers
, proc
;
104 unsigned port
, proto
;
105 unsigned iprog
, ivers
, iproc
, ilen
;
107 struct cache_struct
*x
, *find_callit();
108 int trailer_done
= 0;
110 if (proc
< 0 || proc
> MAXPROC_2
)
113 if (proc
== PMAPPROC_CALLIT
) {
115 iprog
= getxdr_u_long();
116 ivers
= getxdr_u_long();
117 iproc
= getxdr_u_long();
118 stash_callit(xid
, pi_frame
, iprog
, ivers
, iproc
);
120 x
= find_callit(xid
);
125 if (setjmp(xdr_err
)) {
129 line
= get_sum_line();
132 (void) sprintf(line
, "PORTMAP C %s",
133 procnames_short_2
[proc
]);
134 line
+= strlen(line
);
136 case PMAPPROC_GETPORT
:
137 iprog
= getxdr_u_long();
138 ivers
= getxdr_u_long();
139 proto
= getxdr_u_long();
141 " prog=%d (%s) vers=%d proto=%s",
142 iprog
, nameof_prog(iprog
),
146 case PMAPPROC_CALLIT
:
148 " prog=%s vers=%d proc=%d",
151 if (flags
& F_ALLSUM
) {
152 (void) getxdr_u_long(); /* length */
153 data
+= 16; /* prog+ver+proc+len */
155 protoprint(flags
, type
, xid
,
163 check_retransmit(line
, xid
);
165 (void) sprintf(line
, "PORTMAP R %s ",
166 procnames_short_2
[proc
]);
167 line
+= strlen(line
);
169 case PMAPPROC_GETPORT
:
170 port
= getxdr_u_long();
171 (void) sprintf(line
, "port=%d", port
);
174 (void) sprintf(line
, "%s", sum_pmaplist());
176 case PMAPPROC_CALLIT
:
177 port
= getxdr_u_long();
178 ilen
= getxdr_u_long();
179 (void) sprintf(line
, "port=%d len=%d",
181 if (flags
& F_ALLSUM
&& x
!= NULL
) {
182 data
+= 8; /* port+len */
184 protoprint(flags
, type
, xid
,
197 if (flags
& F_DTAIL
) {
198 show_header("PMAP: ", "Portmapper", len
);
200 if (setjmp(xdr_err
)) {
203 (void) sprintf(get_line(0, 0),
205 proc
, procnames_long_2
[proc
]);
212 case PMAPPROC_GETPORT
:
213 iprog
= getxdr_u_long();
214 (void) sprintf(get_line(0, 0),
216 iprog
, nameof_prog(iprog
));
217 (void) showxdr_u_long("Version = %d");
218 proto
= getxdr_u_long();
219 (void) sprintf(get_line(0, 0),
220 "Protocol = %d (%s)",
221 proto
, getproto(proto
));
225 case PMAPPROC_CALLIT
:
226 (void) sprintf(get_line(0, 0),
228 iprog
, nameof_prog(iprog
));
229 (void) sprintf(get_line(0, 0),
230 "Version = %d", ivers
);
231 (void) sprintf(get_line(0, 0),
233 (void) showxdr_u_long("Callit data = %d bytes");
236 data
+= 16; /* prog+ver+proc+len */
238 protoprint(flags
, type
, xid
,
249 case PMAPPROC_GETPORT
:
250 (void) showxdr_u_long("Port = %d");
255 case PMAPPROC_CALLIT
:
256 (void) showxdr_u_long("Port = %d");
257 (void) showxdr_u_long("Length = %d bytes");
261 protoprint(flags
, type
, xid
,
279 static char buff
[16];
281 if (setjmp(xdr_err
)) {
282 (void) sprintf(buff
, "%d+ map(s) found", maps
);
286 while (getxdr_u_long()) {
287 (void) getxdr_u_long(); /* program */
288 (void) getxdr_u_long(); /* version */
289 (void) getxdr_u_long(); /* protocol */
290 (void) getxdr_u_long(); /* port */
294 (void) sprintf(buff
, "%d map(s) found", maps
);
301 unsigned prog
, vers
, proto
, port
;
304 if (setjmp(xdr_err
)) {
305 (void) sprintf(get_line(0, 0),
306 " %d+ maps. (Frame is incomplete)",
311 (void) sprintf(get_line(0, 0), " Program Version Protocol Port");
313 while (getxdr_u_long()) {
314 prog
= getxdr_u_long();
315 vers
= getxdr_u_long();
316 proto
= getxdr_u_long();
317 port
= getxdr_u_long();
318 (void) sprintf(get_line(0, 0),
320 prog
, vers
, proto
, port
, nameof_prog(prog
));
324 (void) sprintf(get_line(0, 0), " %d maps", maps
);
328 * ******************************************
330 char *sum_rpcblist();
331 void show_rpcblist();
332 char *sum_rpcb_entry_list();
333 void show_rpcb_entry_list();
335 static char *procnames_short_4
[] = {
337 * version 3 and 4 procs
346 "UADDR2TADDR", /* 7 */
347 "TADDR2UADDR", /* 8 */
349 * version 4 procs only
351 "GETVERSADDR", /* 9 */
353 "GETADDRLIST", /* 11 */
357 static char *procnames_long_4
[] = {
359 * version 3 and 4 procs
361 "Null procedure", /* 0 */
362 "Set address", /* 1 */
363 "Unset address", /* 2 */
364 "Get address", /* 3 */
365 "Dump the mappings", /* 4 */
366 "Broadcast call (no error)", /* 5 */
367 "Get the time", /* 6 */
368 "Universal to transport address", /* 7 */
369 "Transport to universal address", /* 8 */
371 * version 4 procs only
373 "Get address of specific version", /* 9 */
374 "Indirect call (return error)", /* 10 */
375 "Return addresses of prog/vers", /* 11 */
376 "Get statistics", /* 12 */
381 #define RPCBPROC_NULL 0
384 interpret_pmap_4(flags
, type
, xid
, vers
, proc
, data
, len
)
385 int flags
, type
, xid
, vers
, proc
;
391 char buff1
[MAXSTRINGLEN
+ 1];
392 int iprog
, ivers
, iproc
, ilen
;
394 struct cache_struct
*x
, *find_callit();
395 int trailer_done
= 0;
397 if (proc
< 0 || proc
> MAXPROC_4
|| (vers
== 3 && proc
> MAXPROC_3
))
400 if (proc
== RPCBPROC_BCAST
|| proc
== RPCBPROC_INDIRECT
) {
402 iprog
= getxdr_u_long();
403 ivers
= getxdr_u_long();
404 iproc
= getxdr_u_long();
405 stash_callit(xid
, pi_frame
,
406 iprog
, ivers
, iproc
);
408 x
= find_callit(xid
);
413 if (setjmp(xdr_err
)) {
417 line
= get_sum_line();
422 procnames_short_4
[proc
]);
423 line
+= strlen(line
);
427 case RPCBPROC_GETADDR
:
428 case RPCBPROC_GETVERSADDR
:
429 case RPCBPROC_GETADDRLIST
:
430 prog
= getxdr_u_long();
431 ver
= getxdr_u_long();
433 " prog=%d (%s) vers=%d",
434 prog
, nameof_prog(prog
),
438 case RPCBPROC_INDIRECT
:
440 " prog=%s vers=%d proc=%d",
443 if (flags
& F_ALLSUM
) {
444 (void) getxdr_u_long(); /* length */
445 data
+= 16; /* prog+ver+proc+len */
447 protoprint(flags
, type
, xid
,
456 check_retransmit(line
, xid
);
460 (void) sprintf(line
, "RPCBIND R %s ",
461 procnames_short_4
[proc
]);
462 line
+= strlen(line
);
464 case RPCBPROC_GETADDR
:
465 case RPCBPROC_TADDR2UADDR
:
466 case RPCBPROC_GETVERSADDR
:
467 (void) getxdr_string(buff1
, MAXSTRINGLEN
);
473 case RPCBPROC_INDIRECT
:
475 (void) getxdr_string(buff1
, MAXSTRINGLEN
);
476 ilen
= getxdr_u_long();
477 (void) sprintf(line
, "Uaddr=%s len=%d",
479 if (flags
& F_ALLSUM
&& x
!= NULL
) {
480 pos
= getxdr_pos() - pos
;
481 data
+= pos
; /* uaddr+len */
483 protoprint(flags
, type
, xid
,
491 (void) sprintf(line
, "%s",
494 case RPCBPROC_GETTIME
:
496 time_t sec
= getxdr_long();
497 struct tm
*tmp
= gmtime(&sec
);
498 (void) strftime(line
, MAXLINE
,
499 "%d-%h-%y %T GMT", tmp
);
502 case RPCBPROC_GETADDRLIST
:
503 (void) sprintf(line
, "%s",
504 sum_rpcb_entry_list());
512 if (flags
& F_DTAIL
) {
513 show_header("RPCB: ", "RPC Bind", len
);
515 if (setjmp(xdr_err
)) {
518 (void) sprintf(get_line(0, 0),
520 proc
, procnames_long_4
[proc
]);
527 case RPCBPROC_GETADDR
:
528 case RPCBPROC_GETVERSADDR
:
529 case RPCBPROC_GETADDRLIST
:
530 (void) showxdr_u_long("Program = %d");
531 (void) showxdr_u_long("Version = %d");
532 (void) showxdr_string(64, "Netid = %s");
537 case RPCBPROC_INDIRECT
:
538 (void) sprintf(get_line(0, 0),
540 iprog
, nameof_prog(iprog
));
541 (void) sprintf(get_line(0, 0),
542 "Version = %d", ivers
);
543 (void) sprintf(get_line(0, 0),
545 (void) showxdr_u_long(
546 "Callit data = %d bytes");
549 data
+= 16; /* prog+ver+proc+len */
551 protoprint(flags
, type
, xid
,
555 case RPCBPROC_GETTIME
:
557 case RPCBPROC_UADDR2TADDR
:
558 case RPCBPROC_TADDR2UADDR
:
567 case RPCBPROC_GETADDR
:
568 case RPCBPROC_TADDR2UADDR
:
569 case RPCBPROC_GETVERSADDR
:
570 (void) showxdr_string(64, "Uaddr = %s");
576 case RPCBPROC_INDIRECT
:
577 (void) showxdr_string(64, "Uaddr = %s");
578 (void) showxdr_u_long("Length = %d bytes");
582 protoprint(flags
, type
, xid
,
589 case RPCBPROC_GETTIME
:
591 int pos
= getxdr_pos();
592 time_t sec
= getxdr_long();
593 struct tm
*tmp
= gmtime(&sec
);
594 (void) strftime(get_line(pos
,
595 getxdr_pos()), MAXLINE
,
596 "Time = %d-%h-%y %T GMT", tmp
);
599 case RPCBPROC_UADDR2TADDR
:
601 case RPCBPROC_GETADDRLIST
:
602 show_rpcb_entry_list();
615 static char buff
[MAXSTRINGLEN
+ 1];
617 if (setjmp(xdr_err
)) {
618 (void) sprintf(buff
, "%d+ map(s) found", maps
);
622 while (getxdr_u_long()) {
623 (void) getxdr_u_long(); /* program */
624 (void) getxdr_u_long(); /* version */
625 (void) getxdr_string(buff
, MAXSTRINGLEN
); /* netid */
626 (void) getxdr_string(buff
, MAXSTRINGLEN
); /* uaddr */
627 (void) getxdr_string(buff
, MAXSTRINGLEN
); /* owner */
631 (void) sprintf(buff
, "%d map(s) found", maps
);
639 char netid
[MAXSTRINGLEN
+ 1], uaddr
[MAXSTRINGLEN
+ 1];
640 char owner
[MAXSTRINGLEN
+ 1];
643 if (setjmp(xdr_err
)) {
644 (void) sprintf(get_line(0, 0),
645 " %d+ maps. (Frame is incomplete)",
651 (void) sprintf(get_line(0, 0),
652 " Program Vers Netid Uaddr Owner");
654 while (getxdr_u_long()) {
655 prog
= getxdr_u_long();
656 vers
= getxdr_u_long();
657 (void) getxdr_string(netid
, MAXSTRINGLEN
);
658 (void) getxdr_string(uaddr
, MAXSTRINGLEN
);
659 (void) getxdr_string(owner
, MAXSTRINGLEN
);
660 (void) sprintf(get_line(0, 0),
661 "%8d%5d %-12s %-18s %-10s (%s)",
668 (void) sprintf(get_line(0, 0), " (%d maps)", maps
);
672 sum_rpcb_entry_list()
675 static char buff
[MAXSTRINGLEN
+ 1];
677 if (setjmp(xdr_err
)) {
678 (void) sprintf(buff
, "%d+ map(s) found", maps
);
682 while (getxdr_u_long()) {
683 (void) getxdr_string(buff
, MAXSTRINGLEN
); /* maddr */
684 (void) getxdr_string(buff
, MAXSTRINGLEN
); /* nc_netid */
685 (void) getxdr_u_long(); /* nc_semantics */
686 (void) getxdr_string(buff
, MAXSTRINGLEN
); /* nc_protofmly */
687 (void) getxdr_string(buff
, MAXSTRINGLEN
); /* nc_proto */
691 (void) sprintf(buff
, "%d map(s) found", maps
);
695 char *semantics_strs
[] = {"", "CLTS", "COTS", "COTS-ORD", "RAW"};
698 show_rpcb_entry_list()
700 char maddr
[MAXSTRINGLEN
+ 1], netid
[MAXSTRINGLEN
+ 1];
701 char protofmly
[MAXSTRINGLEN
+ 1], proto
[MAXSTRINGLEN
+ 1];
705 if (setjmp(xdr_err
)) {
706 (void) sprintf(get_line(0, 0),
707 " %d+ maps. (Frame is incomplete)",
713 (void) sprintf(get_line(0, 0),
714 " Maddr Netid Semantics Protofmly Proto");
716 while (getxdr_u_long()) {
717 (void) getxdr_string(maddr
, MAXSTRINGLEN
);
718 (void) getxdr_string(netid
, MAXSTRINGLEN
);
719 sem
= getxdr_u_long();
720 (void) getxdr_string(protofmly
, MAXSTRINGLEN
);
721 (void) getxdr_string(proto
, MAXSTRINGLEN
);
722 (void) sprintf(get_line(0, 0),
723 "%-12s %-12s %-8s %-8s %-8s",
730 (void) sprintf(get_line(0, 0), " (%d maps)", maps
);
733 #define CXID_CACHE_SIZE 16
734 struct cache_struct cxid_cache
[CXID_CACHE_SIZE
];
735 struct cache_struct
*cxcpfirst
= &cxid_cache
[0];
736 struct cache_struct
*cxcp
= &cxid_cache
[0];
737 struct cache_struct
*cxcplast
= &cxid_cache
[CXID_CACHE_SIZE
- 1];
739 struct cache_struct
*
743 struct cache_struct
*x
;
745 for (x
= cxcp
; x
>= cxcpfirst
; x
--)
746 if (x
->xid_num
== xid
)
748 for (x
= cxcplast
; x
> cxcp
; x
--)
749 if (x
->xid_num
== xid
)
755 stash_callit(xid
, frame
, prog
, vers
, proc
)
757 int frame
, prog
, vers
, proc
;
759 struct cache_struct
*x
;
761 x
= find_callit(xid
);
767 x
->xid_frame
= frame
;