10f74e101Schristos /* 20f74e101Schristos * Copyright (c) 1992, 1993, 1994, 1995, 1996 30f74e101Schristos * The Regents of the University of California. All rights reserved. 40f74e101Schristos * 50f74e101Schristos * Redistribution and use in source and binary forms, with or without 60f74e101Schristos * modification, are permitted provided that: (1) source code distributions 70f74e101Schristos * retain the above copyright notice and this paragraph in its entirety, (2) 80f74e101Schristos * distributions including binary code include the above copyright notice and 90f74e101Schristos * this paragraph in its entirety in the documentation or other materials 100f74e101Schristos * provided with the distribution, and (3) all advertising materials mentioning 110f74e101Schristos * features or use of this software display the following acknowledgement: 120f74e101Schristos * ``This product includes software developed by the University of California, 130f74e101Schristos * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 140f74e101Schristos * the University nor the names of its contributors may be used to endorse 150f74e101Schristos * or promote products derived from this software without specific prior 160f74e101Schristos * written permission. 170f74e101Schristos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 180f74e101Schristos * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 190f74e101Schristos * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 200f74e101Schristos */ 210f74e101Schristos 2211b3aaa1Schristos #include <sys/cdefs.h> 230f74e101Schristos #ifndef lint 24*26ba0b50Schristos __RCSID("$NetBSD: print-sunrpc.c,v 1.9 2024/09/02 16:15:33 christos Exp $"); 250f74e101Schristos #endif 260f74e101Schristos 27dc860a36Sspz /* \summary: Sun Remote Procedure Call printer */ 28dc860a36Sspz 29c74ad251Schristos #include <config.h> 300f74e101Schristos 310f74e101Schristos /* 320f74e101Schristos * At least on HP-UX: 330f74e101Schristos * 340f74e101Schristos * 1) getrpcbynumber() is declared in <netdb.h>, not any of the RPC 350f74e101Schristos * header files 360f74e101Schristos * 370f74e101Schristos * and 380f74e101Schristos * 390f74e101Schristos * 2) if _XOPEN_SOURCE_EXTENDED is defined, <netdb.h> doesn't declare 400f74e101Schristos * it 410f74e101Schristos * 420f74e101Schristos * so we undefine it. 430f74e101Schristos */ 440f74e101Schristos #undef _XOPEN_SOURCE_EXTENDED 450f74e101Schristos 46c74ad251Schristos #include "netdissect-stdinc.h" 470f74e101Schristos 480e9868baSchristos #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) 490f74e101Schristos #include <rpc/rpc.h> 500f74e101Schristos #ifdef HAVE_RPC_RPCENT_H 510f74e101Schristos #include <rpc/rpcent.h> 520f74e101Schristos #endif /* HAVE_RPC_RPCENT_H */ 530e9868baSchristos #endif /* defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) */ 540f74e101Schristos 550f74e101Schristos #include <stdio.h> 560f74e101Schristos #include <string.h> 570f74e101Schristos 58c74ad251Schristos #define ND_LONGJMP_FROM_TCHECK 59fdccd7e4Schristos #include "netdissect.h" 600f74e101Schristos #include "addrtoname.h" 610f74e101Schristos #include "extract.h" 620f74e101Schristos 630f74e101Schristos #include "ip.h" 640f74e101Schristos #include "ip6.h" 650f74e101Schristos 660f74e101Schristos #include "rpc_auth.h" 670f74e101Schristos #include "rpc_msg.h" 68b3a00663Schristos 69b3a00663Schristos /* 70b3a00663Schristos * Sun RPC is a product of Sun Microsystems, Inc. and is provided for 71b3a00663Schristos * unrestricted use provided that this legend is included on all tape 72b3a00663Schristos * media and as a part of the software program in whole or part. Users 73b3a00663Schristos * may copy or modify Sun RPC without charge, but are not authorized 74b3a00663Schristos * to license or distribute it to anyone else except as part of a product or 75b3a00663Schristos * program developed by the user. 76b3a00663Schristos * 77b3a00663Schristos * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE 78b3a00663Schristos * WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 79b3a00663Schristos * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. 80b3a00663Schristos * 81b3a00663Schristos * Sun RPC is provided with no support and without any obligation on the 82b3a00663Schristos * part of Sun Microsystems, Inc. to assist in its use, correction, 83b3a00663Schristos * modification or enhancement. 84b3a00663Schristos * 85b3a00663Schristos * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE 86b3a00663Schristos * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC 87b3a00663Schristos * OR ANY PART THEREOF. 88b3a00663Schristos * 89b3a00663Schristos * In no event will Sun Microsystems, Inc. be liable for any lost revenue 90b3a00663Schristos * or profits or other special, indirect and consequential damages, even if 91b3a00663Schristos * Sun has been advised of the possibility of such damages. 92b3a00663Schristos * 93b3a00663Schristos * Sun Microsystems, Inc. 94b3a00663Schristos * 2550 Garcia Avenue 95b3a00663Schristos * Mountain View, California 94043 96b3a00663Schristos * 97b3a00663Schristos * from: @(#)pmap_prot.h 1.14 88/02/08 SMI 98b3a00663Schristos * from: @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC 99b3a00663Schristos * $FreeBSD: src/include/rpc/pmap_prot.h,v 1.9.2.1 1999/08/29 14:39:05 peter Exp $ 100b3a00663Schristos */ 101b3a00663Schristos 102b3a00663Schristos /* 103b3a00663Schristos * pmap_prot.h 104b3a00663Schristos * Protocol for the local binder service, or pmap. 105b3a00663Schristos * 106b3a00663Schristos * Copyright (C) 1984, Sun Microsystems, Inc. 107b3a00663Schristos * 108b3a00663Schristos * The following procedures are supported by the protocol: 109b3a00663Schristos * 110b3a00663Schristos * PMAPPROC_NULL() returns () 111b3a00663Schristos * takes nothing, returns nothing 112b3a00663Schristos * 113b3a00663Schristos * PMAPPROC_SET(struct pmap) returns (bool_t) 114b3a00663Schristos * TRUE is success, FALSE is failure. Registers the tuple 115b3a00663Schristos * [prog, vers, prot, port]. 116b3a00663Schristos * 117b3a00663Schristos * PMAPPROC_UNSET(struct pmap) returns (bool_t) 118b3a00663Schristos * TRUE is success, FALSE is failure. Un-registers pair 119b3a00663Schristos * [prog, vers]. prot and port are ignored. 120b3a00663Schristos * 121b3a00663Schristos * PMAPPROC_GETPORT(struct pmap) returns (long unsigned). 122b3a00663Schristos * 0 is failure. Otherwise returns the port number where the pair 123b3a00663Schristos * [prog, vers] is registered. It may lie! 124b3a00663Schristos * 125b3a00663Schristos * PMAPPROC_DUMP() RETURNS (struct pmaplist *) 126b3a00663Schristos * 127b3a00663Schristos * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>) 128b3a00663Schristos * RETURNS (port, string<>); 129b3a00663Schristos * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs); 130b3a00663Schristos * Calls the procedure on the local machine. If it is not registered, 131b3a00663Schristos * this procedure is quite; ie it does not return error information!!! 132b3a00663Schristos * This procedure only is supported on rpc/udp and calls via 133b3a00663Schristos * rpc/udp. This routine only passes null authentication parameters. 134b3a00663Schristos * This file has no interface to xdr routines for PMAPPROC_CALLIT. 135b3a00663Schristos * 136b3a00663Schristos * The service supports remote procedure calls on udp/ip or tcp/ip socket 111. 137b3a00663Schristos */ 138b3a00663Schristos 139b3a00663Schristos #define SUNRPC_PMAPPORT ((uint16_t)111) 140b3a00663Schristos #define SUNRPC_PMAPPROC_NULL ((uint32_t)0) 141b3a00663Schristos #define SUNRPC_PMAPPROC_SET ((uint32_t)1) 142b3a00663Schristos #define SUNRPC_PMAPPROC_UNSET ((uint32_t)2) 143b3a00663Schristos #define SUNRPC_PMAPPROC_GETPORT ((uint32_t)3) 144b3a00663Schristos #define SUNRPC_PMAPPROC_DUMP ((uint32_t)4) 145b3a00663Schristos #define SUNRPC_PMAPPROC_CALLIT ((uint32_t)5) 146b3a00663Schristos 147870189d2Schristos static const struct tok proc2str[] = { 1480f74e101Schristos { SUNRPC_PMAPPROC_NULL, "null" }, 1490f74e101Schristos { SUNRPC_PMAPPROC_SET, "set" }, 1500f74e101Schristos { SUNRPC_PMAPPROC_UNSET, "unset" }, 1510f74e101Schristos { SUNRPC_PMAPPROC_GETPORT, "getport" }, 1520f74e101Schristos { SUNRPC_PMAPPROC_DUMP, "dump" }, 1530f74e101Schristos { SUNRPC_PMAPPROC_CALLIT, "call" }, 1540f74e101Schristos { 0, NULL } 1550f74e101Schristos }; 1560f74e101Schristos 1570f74e101Schristos /* Forwards */ 158b3a00663Schristos static char *progstr(uint32_t); 1590f74e101Schristos 1600f74e101Schristos void 161c74ad251Schristos sunrpc_print(netdissect_options *ndo, const u_char *bp, 162c74ad251Schristos u_int length, const u_char *bp2) 1630f74e101Schristos { 164c74ad251Schristos const struct sunrpc_msg *rp; 165c74ad251Schristos const struct ip *ip; 166c74ad251Schristos const struct ip6_hdr *ip6; 167b3a00663Schristos uint32_t x; 1680f74e101Schristos char srcid[20], dstid[20]; /*fits 32bit*/ 1690f74e101Schristos 170c74ad251Schristos ndo->ndo_protocol = "sunrpc"; 171fdccd7e4Schristos rp = (const struct sunrpc_msg *)bp; 172c74ad251Schristos ND_TCHECK_SIZE(rp); 1730f74e101Schristos 174b3a00663Schristos if (!ndo->ndo_nflag) { 1750f74e101Schristos snprintf(srcid, sizeof(srcid), "0x%x", 176c74ad251Schristos GET_BE_U_4(rp->rm_xid)); 1770f74e101Schristos strlcpy(dstid, "sunrpc", sizeof(dstid)); 1780f74e101Schristos } else { 1790f74e101Schristos snprintf(srcid, sizeof(srcid), "0x%x", 180c74ad251Schristos GET_BE_U_4(rp->rm_xid)); 1810f74e101Schristos snprintf(dstid, sizeof(dstid), "0x%x", SUNRPC_PMAPPORT); 1820f74e101Schristos } 1830f74e101Schristos 184fdccd7e4Schristos switch (IP_V((const struct ip *)bp2)) { 1850f74e101Schristos case 4: 186fdccd7e4Schristos ip = (const struct ip *)bp2; 187c74ad251Schristos ND_PRINT("%s.%s > %s.%s: %u", 188c74ad251Schristos GET_IPADDR_STRING(ip->ip_src), srcid, 189c74ad251Schristos GET_IPADDR_STRING(ip->ip_dst), dstid, length); 1900f74e101Schristos break; 1910f74e101Schristos case 6: 192fdccd7e4Schristos ip6 = (const struct ip6_hdr *)bp2; 193c74ad251Schristos ND_PRINT("%s.%s > %s.%s: %u", 194c74ad251Schristos GET_IP6ADDR_STRING(ip6->ip6_src), srcid, 195c74ad251Schristos GET_IP6ADDR_STRING(ip6->ip6_dst), dstid, length); 1960f74e101Schristos break; 1970f74e101Schristos default: 198c74ad251Schristos ND_PRINT("%s.%s > %s.%s: %u", "?", srcid, "?", dstid, length); 1990f74e101Schristos break; 2000f74e101Schristos } 2010f74e101Schristos 202c74ad251Schristos ND_PRINT(" %s", tok2str(proc2str, " proc #%u", 203c74ad251Schristos GET_BE_U_4(rp->rm_call.cb_proc))); 204c74ad251Schristos x = GET_BE_U_4(rp->rm_call.cb_rpcvers); 205c74ad251Schristos if (x != SUNRPC_MSG_VERSION) 206c74ad251Schristos ND_PRINT(" [rpcver %u]", x); 2070f74e101Schristos 208c74ad251Schristos switch (GET_BE_U_4(rp->rm_call.cb_proc)) { 2090f74e101Schristos 2100f74e101Schristos case SUNRPC_PMAPPROC_SET: 2110f74e101Schristos case SUNRPC_PMAPPROC_UNSET: 2120f74e101Schristos case SUNRPC_PMAPPROC_GETPORT: 2130f74e101Schristos case SUNRPC_PMAPPROC_CALLIT: 214c74ad251Schristos x = GET_BE_U_4(rp->rm_call.cb_prog); 215b3a00663Schristos if (!ndo->ndo_nflag) 216c74ad251Schristos ND_PRINT(" %s", progstr(x)); 2170f74e101Schristos else 218c74ad251Schristos ND_PRINT(" %u", x); 219c74ad251Schristos ND_PRINT(".%u", GET_BE_U_4(rp->rm_call.cb_vers)); 2200f74e101Schristos break; 2210f74e101Schristos } 2220f74e101Schristos } 2230f74e101Schristos 2240f74e101Schristos static char * 225b3a00663Schristos progstr(uint32_t prog) 2260f74e101Schristos { 2270e9868baSchristos #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) 228c74ad251Schristos struct rpcent *rp; 2290f74e101Schristos #endif 2300f74e101Schristos static char buf[32]; 231b3a00663Schristos static uint32_t lastprog = 0; 2320f74e101Schristos 2330f74e101Schristos if (lastprog != 0 && prog == lastprog) 2340f74e101Schristos return (buf); 2350e9868baSchristos #if defined(HAVE_GETRPCBYNUMBER) && defined(HAVE_RPC_RPC_H) 2360f74e101Schristos rp = getrpcbynumber(prog); 237c74ad251Schristos if (rp != NULL) 238c74ad251Schristos strlcpy(buf, rp->r_name, sizeof(buf)); 239c74ad251Schristos else 2400f74e101Schristos #endif 2410f74e101Schristos (void) snprintf(buf, sizeof(buf), "#%u", prog); 242c74ad251Schristos lastprog = prog; 2430f74e101Schristos return (buf); 2440f74e101Schristos } 245