* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
-#ifndef lint
-static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-nfs.c,v 1.88 2001-07-04 19:24:10 fenner Exp $ (LBL)";
-#endif
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
-#include <sys/param.h>
-#include <sys/time.h>
-#include <sys/socket.h>
-
-struct mbuf;
-struct rtentry;
+#include <tcpdump-stdinc.h>
-#include <netinet/in.h>
-
-#include <rpc/rpc.h>
-
-#include <ctype.h>
#include <pcap.h>
#include <stdio.h>
#include <string.h>
#include "interface.h"
#include "addrtoname.h"
+#include "extract.h"
#include "nfs.h"
#include "nfsfh.h"
#ifdef INET6
#include "ip6.h"
#endif
+#include "rpc_auth.h"
+#include "rpc_msg.h"
+
+static const char tstr[] = " [|nfs]";
static void nfs_printfh(const u_int32_t *, const u_int);
-static void xid_map_enter(const struct rpc_msg *, const u_char *);
-static int32_t xid_map_find(const struct rpc_msg *, const u_char *,
+static int xid_map_enter(const struct sunrpc_msg *, const u_char *);
+static int xid_map_find(const struct sunrpc_msg *, const u_char *,
u_int32_t *, u_int32_t *);
-static void interp_reply(const struct rpc_msg *, u_int32_t, u_int32_t, int);
+static void interp_reply(const struct sunrpc_msg *, u_int32_t, u_int32_t, int);
static const u_int32_t *parse_post_op_attr(const u_int32_t *, int);
static void print_sattr3(const struct nfsv3_sattr *sa3, int verbose);
-static int print_int64(const u_int32_t *dp, int how);
static void print_nfsaddr(const u_char *, const char *, const char *);
/*
* the first NFS server was the SunOS 2.0 one, and until 5.0 SunOS
* was primarily BSD-derived.
*/
-static struct tok status2str[] = {
+static const struct tok status2str[] = {
{ 1, "Operation not permitted" }, /* EPERM */
{ 2, "No such file or directory" }, /* ENOENT */
{ 5, "Input/output error" }, /* EIO */
{ 0, NULL }
};
-static struct tok nfsv3_writemodes[] = {
+static const struct tok nfsv3_writemodes[] = {
{ 0, "unstable" },
{ 1, "datasync" },
{ 2, "filesync" },
{ 0, NULL }
};
-static struct tok type2str[] = {
+static const struct tok type2str[] = {
{ NFNON, "NON" },
{ NFREG, "REG" },
{ NFDIR, "DIR" },
{ 0, NULL }
};
-/*
- * Print out a 64-bit integer. This appears to be different on each system,
- * try to make the best of it. The integer stored as 2 consecutive XDR
- * encoded 32-bit integers, to which a pointer is passed.
- *
- * Assume that a system that has INT64_FORMAT defined, has a 64-bit
- * integer datatype and can print it.
- */
-
-#define UNSIGNED 0
-#define SIGNED 1
-#define HEX 2
-
-static int print_int64(const u_int32_t *dp, int how)
-{
-#ifdef INT64_FORMAT
- u_int64_t res;
-
- res = ((u_int64_t)ntohl(dp[0]) << 32) | (u_int64_t)ntohl(dp[1]);
- switch (how) {
- case SIGNED:
- printf(INT64_FORMAT, res);
- break;
- case UNSIGNED:
- printf(U_INT64_FORMAT, res);
- break;
- case HEX:
- printf(HEX_INT64_FORMAT, res);
- break;
- default:
- return (0);
- }
-#else
- switch (how) {
- case SIGNED:
- case UNSIGNED:
- case HEX:
- printf("0x%x%08x", (u_int32_t)ntohl(dp[0]),
- (u_int32_t)ntohl(dp[1]));
- break;
- default:
- return (0);
- }
-#endif
- return 1;
-}
-
static void
print_nfsaddr(const u_char *bp, const char *s, const char *d)
{
parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
{
TCHECK(dp[0]);
- if ((sa3->sa_modeset = ntohl(*dp++))) {
+ sa3->sa_modeset = EXTRACT_32BITS(dp);
+ dp++;
+ if (sa3->sa_modeset) {
TCHECK(dp[0]);
- sa3->sa_mode = ntohl(*dp++);
+ sa3->sa_mode = EXTRACT_32BITS(dp);
+ dp++;
}
TCHECK(dp[0]);
- if ((sa3->sa_uidset = ntohl(*dp++))) {
+ sa3->sa_uidset = EXTRACT_32BITS(dp);
+ dp++;
+ if (sa3->sa_uidset) {
TCHECK(dp[0]);
- sa3->sa_uid = ntohl(*dp++);
+ sa3->sa_uid = EXTRACT_32BITS(dp);
+ dp++;
}
TCHECK(dp[0]);
- if ((sa3->sa_gidset = ntohl(*dp++))) {
+ sa3->sa_gidset = EXTRACT_32BITS(dp);
+ dp++;
+ if (sa3->sa_gidset) {
TCHECK(dp[0]);
- sa3->sa_gid = ntohl(*dp++);
+ sa3->sa_gid = EXTRACT_32BITS(dp);
+ dp++;
}
TCHECK(dp[0]);
- if ((sa3->sa_sizeset = ntohl(*dp++))) {
+ sa3->sa_sizeset = EXTRACT_32BITS(dp);
+ dp++;
+ if (sa3->sa_sizeset) {
TCHECK(dp[0]);
- sa3->sa_size = ntohl(*dp++);
+ sa3->sa_size = EXTRACT_32BITS(dp);
+ dp++;
}
TCHECK(dp[0]);
- if ((sa3->sa_atimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
+ sa3->sa_atimetype = EXTRACT_32BITS(dp);
+ dp++;
+ if (sa3->sa_atimetype == NFSV3SATTRTIME_TOCLIENT) {
TCHECK(dp[1]);
- sa3->sa_atime.nfsv3_sec = ntohl(*dp++);
- sa3->sa_atime.nfsv3_nsec = ntohl(*dp++);
+ sa3->sa_atime.nfsv3_sec = EXTRACT_32BITS(dp);
+ dp++;
+ sa3->sa_atime.nfsv3_nsec = EXTRACT_32BITS(dp);
+ dp++;
}
TCHECK(dp[0]);
- if ((sa3->sa_mtimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
+ sa3->sa_mtimetype = EXTRACT_32BITS(dp);
+ dp++;
+ if (sa3->sa_mtimetype == NFSV3SATTRTIME_TOCLIENT) {
TCHECK(dp[1]);
- sa3->sa_mtime.nfsv3_sec = ntohl(*dp++);
- sa3->sa_mtime.nfsv3_nsec = ntohl(*dp++);
+ sa3->sa_mtime.nfsv3_sec = EXTRACT_32BITS(dp);
+ dp++;
+ sa3->sa_mtime.nfsv3_nsec = EXTRACT_32BITS(dp);
+ dp++;
}
return dp;
nfsreply_print(register const u_char *bp, u_int length,
register const u_char *bp2)
{
- register const struct rpc_msg *rp;
- u_int32_t proc, vers;
+ register const struct sunrpc_msg *rp;
char srcid[20], dstid[20]; /*fits 32bit*/
nfserr = 0; /* assume no error */
- rp = (const struct rpc_msg *)bp;
+ rp = (const struct sunrpc_msg *)bp;
+ TCHECK(rp->rm_xid);
if (!nflag) {
strlcpy(srcid, "nfs", sizeof(srcid));
snprintf(dstid, sizeof(dstid), "%u",
- (u_int32_t)ntohl(rp->rm_xid));
+ EXTRACT_32BITS(&rp->rm_xid));
} else {
snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
snprintf(dstid, sizeof(dstid), "%u",
- (u_int32_t)ntohl(rp->rm_xid));
+ EXTRACT_32BITS(&rp->rm_xid));
}
print_nfsaddr(bp2, srcid, dstid);
- (void)printf("reply %s %d",
- ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED?
- "ok":"ERR",
- length);
- if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
- interp_reply(rp, proc, vers, length);
+ nfsreply_print_noaddr(bp, length, bp2);
+ return;
+
+trunc:
+ if (!nfserr)
+ printf("%s", tstr);
+}
+
+void
+nfsreply_print_noaddr(register const u_char *bp, u_int length,
+ register const u_char *bp2)
+{
+ register const struct sunrpc_msg *rp;
+ u_int32_t proc, vers, reply_stat;
+ enum sunrpc_reject_stat rstat;
+ u_int32_t rlow;
+ u_int32_t rhigh;
+ enum sunrpc_auth_stat rwhy;
+
+ nfserr = 0; /* assume no error */
+ rp = (const struct sunrpc_msg *)bp;
+
+ TCHECK(rp->rm_reply.rp_stat);
+ reply_stat = EXTRACT_32BITS(&rp->rm_reply.rp_stat);
+ switch (reply_stat) {
+
+ case SUNRPC_MSG_ACCEPTED:
+ (void)printf("reply ok %u", length);
+ if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
+ interp_reply(rp, proc, vers, length);
+ break;
+
+ case SUNRPC_MSG_DENIED:
+ (void)printf("reply ERR %u: ", length);
+ TCHECK(rp->rm_reply.rp_reject.rj_stat);
+ rstat = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_stat);
+ switch (rstat) {
+
+ case SUNRPC_RPC_MISMATCH:
+ TCHECK(rp->rm_reply.rp_reject.rj_vers.high);
+ rlow = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.low);
+ rhigh = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_vers.high);
+ (void)printf("RPC Version mismatch (%u-%u)",
+ rlow, rhigh);
+ break;
+
+ case SUNRPC_AUTH_ERROR:
+ TCHECK(rp->rm_reply.rp_reject.rj_why);
+ rwhy = EXTRACT_32BITS(&rp->rm_reply.rp_reject.rj_why);
+ (void)printf("Auth ");
+ switch (rwhy) {
+
+ case SUNRPC_AUTH_OK:
+ (void)printf("OK");
+ break;
+
+ case SUNRPC_AUTH_BADCRED:
+ (void)printf("Bogus Credentials (seal broken)");
+ break;
+
+ case SUNRPC_AUTH_REJECTEDCRED:
+ (void)printf("Rejected Credentials (client should begin new session)");
+ break;
+
+ case SUNRPC_AUTH_BADVERF:
+ (void)printf("Bogus Verifier (seal broken)");
+ break;
+
+ case SUNRPC_AUTH_REJECTEDVERF:
+ (void)printf("Verifier expired or was replayed");
+ break;
+
+ case SUNRPC_AUTH_TOOWEAK:
+ (void)printf("Credentials are too weak");
+ break;
+
+ case SUNRPC_AUTH_INVALIDRESP:
+ (void)printf("Bogus response verifier");
+ break;
+
+ case SUNRPC_AUTH_FAILED:
+ (void)printf("Unknown failure");
+ break;
+
+ default:
+ (void)printf("Invalid failure code %u",
+ (unsigned int)rwhy);
+ break;
+ }
+ break;
+
+ default:
+ (void)printf("Unknown reason for rejecting rpc message %u",
+ (unsigned int)rstat);
+ break;
+ }
+ break;
+
+ default:
+ (void)printf("reply Unknown rpc response code=%u %u",
+ reply_stat, length);
+ break;
+ }
+ return;
+
+trunc:
+ if (!nfserr)
+ printf("%s", tstr);
}
/*
* If the packet was truncated, return 0.
*/
static const u_int32_t *
-parsereq(register const struct rpc_msg *rp, register u_int length)
+parsereq(register const struct sunrpc_msg *rp, register u_int length)
{
register const u_int32_t *dp;
register u_int len;
*/
dp = (u_int32_t *)&rp->rm_call.cb_cred;
TCHECK(dp[1]);
- len = ntohl(dp[1]);
+ len = EXTRACT_32BITS(&dp[1]);
if (len < length) {
dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
TCHECK(dp[1]);
- len = ntohl(dp[1]);
+ len = EXTRACT_32BITS(&dp[1]);
if (len < length) {
dp += (len + (2 * sizeof(*dp) + 3)) / sizeof(*dp);
TCHECK2(dp[0], 0);
static const u_int32_t *
parsefh(register const u_int32_t *dp, int v3)
{
- int len;
+ u_int len;
if (v3) {
TCHECK(dp[0]);
- len = (int)ntohl(*dp) / 4;
+ len = EXTRACT_32BITS(dp) / 4;
dp++;
} else
len = NFSX_V2FH / 4;
cp = (u_char *)dp;
/* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
dp += ((len + 3) & ~3) / sizeof(*dp);
- /* XXX seems like we should be checking the length */
putchar('"');
- (void) fn_printn(cp, len, NULL);
+ if (fn_printn(cp, len, snapend)) {
+ putchar('"');
+ goto trunc;
+ }
putchar('"');
return (dp);
nfsreq_print(register const u_char *bp, u_int length,
register const u_char *bp2)
{
- register const struct rpc_msg *rp;
- register const u_int32_t *dp;
- nfs_type type;
- int v3;
- u_int32_t proc;
- struct nfsv3_sattr sa3;
+ register const struct sunrpc_msg *rp;
char srcid[20], dstid[20]; /*fits 32bit*/
nfserr = 0; /* assume no error */
- rp = (const struct rpc_msg *)bp;
+ rp = (const struct sunrpc_msg *)bp;
+
+ TCHECK(rp->rm_xid);
if (!nflag) {
snprintf(srcid, sizeof(srcid), "%u",
- (u_int32_t)ntohl(rp->rm_xid));
+ EXTRACT_32BITS(&rp->rm_xid));
strlcpy(dstid, "nfs", sizeof(dstid));
} else {
snprintf(srcid, sizeof(srcid), "%u",
- (u_int32_t)ntohl(rp->rm_xid));
+ EXTRACT_32BITS(&rp->rm_xid));
snprintf(dstid, sizeof(dstid), "%u", NFS_PORT);
}
print_nfsaddr(bp2, srcid, dstid);
(void)printf("%d", length);
- xid_map_enter(rp, bp2); /* record proc number for later on */
+ nfsreq_print_noaddr(bp, length, bp2);
+ return;
- v3 = (ntohl(rp->rm_call.cb_vers) == NFS_VER3);
- proc = ntohl(rp->rm_call.cb_proc);
+trunc:
+ if (!nfserr)
+ printf("%s", tstr);
+}
+
+void
+nfsreq_print_noaddr(register const u_char *bp, u_int length,
+ register const u_char *bp2)
+{
+ register const struct sunrpc_msg *rp;
+ register const u_int32_t *dp;
+ nfs_type type;
+ int v3;
+ u_int32_t proc;
+ u_int32_t access_flags;
+ struct nfsv3_sattr sa3;
+
+ nfserr = 0; /* assume no error */
+ rp = (const struct sunrpc_msg *)bp;
+
+ if (!xid_map_enter(rp, bp2)) /* record proc number for later on */
+ goto trunc;
+
+ v3 = (EXTRACT_32BITS(&rp->rm_call.cb_vers) == NFS_VER3);
+ proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
if (!v3 && proc < NFS_NPROCS)
proc = nfsv3_procid[proc];
if ((dp = parsereq(rp, length)) != NULL &&
(dp = parsefh(dp, v3)) != NULL) {
TCHECK(dp[0]);
- printf(" %04x", (u_int32_t)ntohl(dp[0]));
+ access_flags = EXTRACT_32BITS(&dp[0]);
+ if (access_flags & ~NFSV3ACCESS_FULL) {
+ /* NFSV3ACCESS definitions aren't up to date */
+ printf(" %04x", access_flags);
+ } else if ((access_flags & NFSV3ACCESS_FULL) == NFSV3ACCESS_FULL) {
+ printf(" NFS_ACCESS_FULL");
+ } else {
+ char separator = ' ';
+ if (access_flags & NFSV3ACCESS_READ) {
+ printf(" NFS_ACCESS_READ");
+ separator = '|';
+ }
+ if (access_flags & NFSV3ACCESS_LOOKUP) {
+ printf("%cNFS_ACCESS_LOOKUP", separator);
+ separator = '|';
+ }
+ if (access_flags & NFSV3ACCESS_MODIFY) {
+ printf("%cNFS_ACCESS_MODIFY", separator);
+ separator = '|';
+ }
+ if (access_flags & NFSV3ACCESS_EXTEND) {
+ printf("%cNFS_ACCESS_EXTEND", separator);
+ separator = '|';
+ }
+ if (access_flags & NFSV3ACCESS_DELETE) {
+ printf("%cNFS_ACCESS_DELETE", separator);
+ separator = '|';
+ }
+ if (access_flags & NFSV3ACCESS_EXECUTE)
+ printf("%cNFS_ACCESS_EXECUTE", separator);
+ }
return;
}
break;
(dp = parsefh(dp, v3)) != NULL) {
if (v3) {
TCHECK(dp[2]);
- printf(" %u bytes @ ",
- (u_int32_t) ntohl(dp[2]));
- print_int64(dp, UNSIGNED);
+ printf(" %u bytes @ %" PRIu64,
+ EXTRACT_32BITS(&dp[2]),
+ EXTRACT_64BITS(&dp[0]));
} else {
TCHECK(dp[1]);
printf(" %u bytes @ %u",
- (u_int32_t)ntohl(dp[1]),
- (u_int32_t)ntohl(dp[0]));
+ EXTRACT_32BITS(&dp[1]),
+ EXTRACT_32BITS(&dp[0]));
}
return;
}
if ((dp = parsereq(rp, length)) != NULL &&
(dp = parsefh(dp, v3)) != NULL) {
if (v3) {
- TCHECK(dp[4]);
- printf(" %u bytes @ ",
- (u_int32_t) ntohl(dp[4]));
- print_int64(dp, UNSIGNED);
+ TCHECK(dp[2]);
+ printf(" %u (%u) bytes @ %" PRIu64,
+ EXTRACT_32BITS(&dp[4]),
+ EXTRACT_32BITS(&dp[2]),
+ EXTRACT_64BITS(&dp[0]));
if (vflag) {
dp += 3;
TCHECK(dp[0]);
printf(" <%s>",
tok2str(nfsv3_writemodes,
- NULL, ntohl(*dp)));
+ NULL, EXTRACT_32BITS(dp)));
}
} else {
TCHECK(dp[3]);
printf(" %u (%u) bytes @ %u (%u)",
- (u_int32_t)ntohl(dp[3]),
- (u_int32_t)ntohl(dp[2]),
- (u_int32_t)ntohl(dp[1]),
- (u_int32_t)ntohl(dp[0]));
+ EXTRACT_32BITS(&dp[3]),
+ EXTRACT_32BITS(&dp[2]),
+ EXTRACT_32BITS(&dp[1]),
+ EXTRACT_32BITS(&dp[0]));
}
return;
}
if ((dp = parsereq(rp, length)) != 0 &&
(dp = parsefhn(dp, v3)) != 0) {
TCHECK(*dp);
- type = (nfs_type)ntohl(*dp++);
+ type = (nfs_type)EXTRACT_32BITS(dp);
+ dp++;
if ((dp = parse_sattr3(dp, &sa3)) == 0)
break;
printf(" %s", tok2str(type2str, "unk-ft %d", type));
if (vflag && (type == NFCHR || type == NFBLK)) {
TCHECK(dp[1]);
printf(" %u/%u",
- (u_int32_t)ntohl(dp[0]),
- (u_int32_t)ntohl(dp[1]));
+ EXTRACT_32BITS(&dp[0]),
+ EXTRACT_32BITS(&dp[1]));
dp += 2;
}
if (vflag)
* We shouldn't really try to interpret the
* offset cookie here.
*/
- printf(" %u bytes @ ",
- (u_int32_t) ntohl(dp[4]));
- print_int64(dp, SIGNED);
+ printf(" %u bytes @ %" PRId64,
+ EXTRACT_32BITS(&dp[4]),
+ EXTRACT_64BITS(&dp[0]));
if (vflag)
printf(" verf %08x%08x", dp[2],
dp[3]);
* common, but offsets > 2^31 aren't.
*/
printf(" %u bytes @ %d",
- (u_int32_t)ntohl(dp[1]),
- (u_int32_t)ntohl(dp[0]));
+ EXTRACT_32BITS(&dp[1]),
+ EXTRACT_32BITS(&dp[0]));
}
return;
}
* We don't try to interpret the offset
* cookie here.
*/
- printf(" %u bytes @ ", (u_int32_t) ntohl(dp[4]));
- print_int64(dp, SIGNED);
- if (vflag)
+ printf(" %u bytes @ %" PRId64,
+ EXTRACT_32BITS(&dp[4]),
+ EXTRACT_64BITS(&dp[0]));
+ if (vflag) {
+ TCHECK(dp[5]);
printf(" max %u verf %08x%08x",
- (u_int32_t) ntohl(dp[5]), dp[2], dp[3]);
+ EXTRACT_32BITS(&dp[5]), dp[2], dp[3]);
+ }
return;
}
break;
case NFSPROC_FSINFO:
printf(" fsinfo");
+ if ((dp = parsereq(rp, length)) != NULL &&
+ parsefh(dp, v3) != NULL)
+ return;
break;
case NFSPROC_PATHCONF:
printf(" pathconf");
+ if ((dp = parsereq(rp, length)) != NULL &&
+ parsefh(dp, v3) != NULL)
+ return;
break;
case NFSPROC_COMMIT:
printf(" commit");
if ((dp = parsereq(rp, length)) != NULL &&
(dp = parsefh(dp, v3)) != NULL) {
- printf(" %u bytes @ ", (u_int32_t) ntohl(dp[2]));
- print_int64(dp, UNSIGNED);
+ TCHECK(dp[2]);
+ printf(" %u bytes @ %" PRIu64,
+ EXTRACT_32BITS(&dp[2]),
+ EXTRACT_64BITS(&dp[0]));
return;
}
break;
default:
- printf(" proc-%u", (u_int32_t)ntohl(rp->rm_call.cb_proc));
+ printf(" proc-%u", EXTRACT_32BITS(&rp->rm_call.cb_proc));
return;
}
trunc:
if (!nfserr)
- fputs(" [|nfs]", stdout);
+ printf("%s", tstr);
}
/*
nfs_printfh(register const u_int32_t *dp, const u_int len)
{
my_fsid fsid;
- ino_t ino;
- char *sfsname = NULL;
+ u_int32_t ino;
+ const char *sfsname = NULL;
+ char *spacep;
+
+ if (uflag) {
+ u_int i;
+ char const *sep = "";
+
+ printf(" fh[");
+ for (i=0; i<len; i++) {
+ (void)printf("%s%x", sep, dp[i]);
+ sep = ":";
+ }
+ printf("]");
+ return;
+ }
- Parse_fh((caddr_t*)dp, len, &fsid, &ino, NULL, &sfsname, 0);
+ Parse_fh((const u_char *)dp, len, &fsid, &ino, NULL, &sfsname, 0);
if (sfsname) {
/* file system ID is ASCII, not numeric, for this server OS */
strncpy(temp, sfsname, NFSX_V3FHMAX);
temp[sizeof(temp) - 1] = '\0';
/* Remove trailing spaces */
- sfsname = strchr(temp, ' ');
- if (sfsname)
- *sfsname = 0;
+ spacep = strchr(temp, ' ');
+ if (spacep)
+ *spacep = '\0';
(void)printf(" fh %s/", temp);
} else {
fsid.Fsid_dev.Major, fsid.Fsid_dev.Minor);
}
- if(fsid.Fsid_dev.Minor == 257 && uflag)
- /* Print the undecoded handle */
+ if(fsid.Fsid_dev.Minor == 257)
+ /* Print the undecoded handle */
(void)printf("%s", fsid.Opaque_Handle);
else
(void)printf("%ld", (long) ino);
int xid_map_next = 0;
int xid_map_hint = 0;
-static void
-xid_map_enter(const struct rpc_msg *rp, const u_char *bp)
+static int
+xid_map_enter(const struct sunrpc_msg *rp, const u_char *bp)
{
struct ip *ip = NULL;
#ifdef INET6
#endif
struct xid_map_entry *xmep;
+ if (!TTEST(rp->rm_call.cb_vers))
+ return (0);
switch (IP_V((struct ip *)bp)) {
case 4:
ip = (struct ip *)bp;
break;
#endif
default:
- return;
+ return (1);
}
xmep = &xid_map[xid_map_next];
xmep->xid = rp->rm_xid;
if (ip) {
xmep->ipver = 4;
- memcpy(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
- memcpy(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
+ UNALIGNED_MEMCPY(&xmep->client, &ip->ip_src, sizeof(ip->ip_src));
+ UNALIGNED_MEMCPY(&xmep->server, &ip->ip_dst, sizeof(ip->ip_dst));
}
#ifdef INET6
else if (ip6) {
xmep->ipver = 6;
- memcpy(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
- memcpy(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
+ UNALIGNED_MEMCPY(&xmep->client, &ip6->ip6_src, sizeof(ip6->ip6_src));
+ UNALIGNED_MEMCPY(&xmep->server, &ip6->ip6_dst, sizeof(ip6->ip6_dst));
}
#endif
- xmep->proc = ntohl(rp->rm_call.cb_proc);
- xmep->vers = ntohl(rp->rm_call.cb_vers);
+ xmep->proc = EXTRACT_32BITS(&rp->rm_call.cb_proc);
+ xmep->vers = EXTRACT_32BITS(&rp->rm_call.cb_vers);
+ return (1);
}
/*
* version in vers return, or returns -1 on failure
*/
static int
-xid_map_find(const struct rpc_msg *rp, const u_char *bp, u_int32_t *proc,
+xid_map_find(const struct sunrpc_msg *rp, const u_char *bp, u_int32_t *proc,
u_int32_t *vers)
{
int i;
int cmp;
/* Start searching from where we last left off */
- i = xid_map_hint;
+ i = xid_map_hint;
do {
xmep = &xid_map[i];
cmp = 1;
* If the packet was truncated, return 0.
*/
static const u_int32_t *
-parserep(register const struct rpc_msg *rp, register u_int length)
+parserep(register const struct sunrpc_msg *rp, register u_int length)
{
register const u_int32_t *dp;
u_int len;
- enum accept_stat astat;
+ enum sunrpc_accept_stat astat;
/*
* Portability note:
*/
dp = ((const u_int32_t *)&rp->rm_reply) + 1;
TCHECK(dp[1]);
- len = ntohl(dp[1]);
+ len = EXTRACT_32BITS(&dp[1]);
if (len >= length)
return (NULL);
/*
/*
* now we can check the ar_stat field
*/
- astat = ntohl(*(enum accept_stat *)dp);
+ astat = (enum sunrpc_accept_stat) EXTRACT_32BITS(dp);
switch (astat) {
- case SUCCESS:
+ case SUNRPC_SUCCESS:
break;
- case PROG_UNAVAIL:
+ case SUNRPC_PROG_UNAVAIL:
printf(" PROG_UNAVAIL");
nfserr = 1; /* suppress trunc string */
return (NULL);
- case PROG_MISMATCH:
+ case SUNRPC_PROG_MISMATCH:
printf(" PROG_MISMATCH");
nfserr = 1; /* suppress trunc string */
return (NULL);
- case PROC_UNAVAIL:
+ case SUNRPC_PROC_UNAVAIL:
printf(" PROC_UNAVAIL");
nfserr = 1; /* suppress trunc string */
return (NULL);
- case GARBAGE_ARGS:
+ case SUNRPC_GARBAGE_ARGS:
printf(" GARBAGE_ARGS");
nfserr = 1; /* suppress trunc string */
return (NULL);
- case SYSTEM_ERR:
+ case SUNRPC_SYSTEM_ERR:
printf(" SYSTEM_ERR");
nfserr = 1; /* suppress trunc string */
return (NULL);
TCHECK(dp[0]);
- errnum = ntohl(dp[0]);
+ errnum = EXTRACT_32BITS(&dp[0]);
if (er)
*er = errnum;
if (errnum != 0) {
printf(" ERROR: %s",
tok2str(status2str, "unk %d", errnum));
nfserr = 1;
- return (NULL);
}
return (dp + 1);
trunc:
if (verbose) {
printf(" %s %o ids %d/%d",
tok2str(type2str, "unk-ft %d ",
- (u_int32_t)ntohl(fap->fa_type)),
- (u_int32_t)ntohl(fap->fa_mode),
- (u_int32_t)ntohl(fap->fa_uid),
- (u_int32_t) ntohl(fap->fa_gid));
+ EXTRACT_32BITS(&fap->fa_type)),
+ EXTRACT_32BITS(&fap->fa_mode),
+ EXTRACT_32BITS(&fap->fa_uid),
+ EXTRACT_32BITS(&fap->fa_gid));
if (v3) {
TCHECK(fap->fa3_size);
- printf(" sz ");
- print_int64((u_int32_t *)&fap->fa3_size, UNSIGNED);
- putchar(' ');
+ printf(" sz %" PRIu64,
+ EXTRACT_64BITS((u_int32_t *)&fap->fa3_size));
} else {
TCHECK(fap->fa2_size);
- printf(" sz %d ", (u_int32_t) ntohl(fap->fa2_size));
+ printf(" sz %d", EXTRACT_32BITS(&fap->fa2_size));
}
}
/* print lots more stuff */
if (verbose > 1) {
if (v3) {
TCHECK(fap->fa3_ctime);
- printf("nlink %d rdev %d/%d ",
- (u_int32_t)ntohl(fap->fa_nlink),
- (u_int32_t) ntohl(fap->fa3_rdev.specdata1),
- (u_int32_t) ntohl(fap->fa3_rdev.specdata2));
- printf("fsid ");
- print_int64((u_int32_t *)&fap->fa2_fsid, HEX);
- printf(" nodeid ");
- print_int64((u_int32_t *)&fap->fa2_fileid, HEX);
- printf(" a/m/ctime %u.%06u ",
- (u_int32_t) ntohl(fap->fa3_atime.nfsv3_sec),
- (u_int32_t) ntohl(fap->fa3_atime.nfsv3_nsec));
- printf("%u.%06u ",
- (u_int32_t) ntohl(fap->fa3_mtime.nfsv3_sec),
- (u_int32_t) ntohl(fap->fa3_mtime.nfsv3_nsec));
- printf("%u.%06u ",
- (u_int32_t) ntohl(fap->fa3_ctime.nfsv3_sec),
- (u_int32_t) ntohl(fap->fa3_ctime.nfsv3_nsec));
+ printf(" nlink %d rdev %d/%d",
+ EXTRACT_32BITS(&fap->fa_nlink),
+ EXTRACT_32BITS(&fap->fa3_rdev.specdata1),
+ EXTRACT_32BITS(&fap->fa3_rdev.specdata2));
+ printf(" fsid %" PRIx64,
+ EXTRACT_64BITS((u_int32_t *)&fap->fa3_fsid));
+ printf(" fileid %" PRIx64,
+ EXTRACT_64BITS((u_int32_t *)&fap->fa3_fileid));
+ printf(" a/m/ctime %u.%06u",
+ EXTRACT_32BITS(&fap->fa3_atime.nfsv3_sec),
+ EXTRACT_32BITS(&fap->fa3_atime.nfsv3_nsec));
+ printf(" %u.%06u",
+ EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_sec),
+ EXTRACT_32BITS(&fap->fa3_mtime.nfsv3_nsec));
+ printf(" %u.%06u",
+ EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_sec),
+ EXTRACT_32BITS(&fap->fa3_ctime.nfsv3_nsec));
} else {
TCHECK(fap->fa2_ctime);
- printf("nlink %d rdev %x fsid %x nodeid %x a/m/ctime ",
- (u_int32_t) ntohl(fap->fa_nlink),
- (u_int32_t) ntohl(fap->fa2_rdev),
- (u_int32_t) ntohl(fap->fa2_fsid),
- (u_int32_t) ntohl(fap->fa2_fileid));
- printf("%u.%06u ",
- (u_int32_t) ntohl(fap->fa2_atime.nfsv2_sec),
- (u_int32_t) ntohl(fap->fa2_atime.nfsv2_usec));
- printf("%u.%06u ",
- (u_int32_t) ntohl(fap->fa2_mtime.nfsv2_sec),
- (u_int32_t) ntohl(fap->fa2_mtime.nfsv2_usec));
- printf("%u.%06u ",
- (u_int32_t) ntohl(fap->fa2_ctime.nfsv2_sec),
- (u_int32_t) ntohl(fap->fa2_ctime.nfsv2_usec));
+ printf(" nlink %d rdev %x fsid %x nodeid %x a/m/ctime",
+ EXTRACT_32BITS(&fap->fa_nlink),
+ EXTRACT_32BITS(&fap->fa2_rdev),
+ EXTRACT_32BITS(&fap->fa2_fsid),
+ EXTRACT_32BITS(&fap->fa2_fileid));
+ printf(" %u.%06u",
+ EXTRACT_32BITS(&fap->fa2_atime.nfsv2_sec),
+ EXTRACT_32BITS(&fap->fa2_atime.nfsv2_usec));
+ printf(" %u.%06u",
+ EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_sec),
+ EXTRACT_32BITS(&fap->fa2_mtime.nfsv2_usec));
+ printf(" %u.%06u",
+ EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_sec),
+ EXTRACT_32BITS(&fap->fa2_ctime.nfsv2_usec));
}
}
return ((const u_int32_t *)((unsigned char *)dp +
int er;
dp = parsestatus(dp, &er);
- if (dp == NULL || er)
+ if (dp == NULL)
return (0);
+ if (er)
+ return (1);
return (parsefattr(dp, verbose, v3) != NULL);
}
{
int er;
- if (!(dp = parsestatus(dp, &er)) || er)
+ if (!(dp = parsestatus(dp, &er)))
return (0);
+ if (er)
+ return (1);
dp = parsefh(dp, 0);
if (dp == NULL)
int er;
dp = parsestatus(dp, &er);
- if (dp == NULL || er)
+ if (dp == NULL)
return(0);
+ if (er)
+ return(1);
if (v3 && !(dp = parse_post_op_attr(dp, vflag)))
return (0);
putchar(' ');
int er;
dp = parsestatus(dp, &er);
- if (dp == NULL || (!v3 && er))
+ if (dp == NULL)
return (0);
+ if (!v3 && er)
+ return (1);
if (qflag)
return(1);
return (0);
}
- TCHECK2(dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
+ TCHECK2(*dp, (v3 ? NFSX_V3STATFS : NFSX_V2STATFS));
sfsp = (const struct nfs_statfs *)dp;
if (v3) {
- printf(" tbytes ");
- print_int64((u_int32_t *)&sfsp->sf_tbytes, UNSIGNED);
- printf(" fbytes ");
- print_int64((u_int32_t *)&sfsp->sf_fbytes, UNSIGNED);
- printf(" abytes ");
- print_int64((u_int32_t *)&sfsp->sf_abytes, UNSIGNED);
+ printf(" tbytes %" PRIu64 " fbytes %" PRIu64 " abytes %" PRIu64,
+ EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tbytes),
+ EXTRACT_64BITS((u_int32_t *)&sfsp->sf_fbytes),
+ EXTRACT_64BITS((u_int32_t *)&sfsp->sf_abytes));
if (vflag) {
- printf(" tfiles ");
- print_int64((u_int32_t *)&sfsp->sf_tfiles, UNSIGNED);
- printf(" ffiles ");
- print_int64((u_int32_t *)&sfsp->sf_ffiles, UNSIGNED);
- printf(" afiles ");
- print_int64((u_int32_t *)&sfsp->sf_afiles, UNSIGNED);
- printf(" invar %u",
- (u_int32_t) ntohl(sfsp->sf_invarsec));
+ printf(" tfiles %" PRIu64 " ffiles %" PRIu64 " afiles %" PRIu64 " invar %u",
+ EXTRACT_64BITS((u_int32_t *)&sfsp->sf_tfiles),
+ EXTRACT_64BITS((u_int32_t *)&sfsp->sf_ffiles),
+ EXTRACT_64BITS((u_int32_t *)&sfsp->sf_afiles),
+ EXTRACT_32BITS(&sfsp->sf_invarsec));
}
} else {
printf(" tsize %d bsize %d blocks %d bfree %d bavail %d",
- (u_int32_t)ntohl(sfsp->sf_tsize),
- (u_int32_t)ntohl(sfsp->sf_bsize),
- (u_int32_t)ntohl(sfsp->sf_blocks),
- (u_int32_t)ntohl(sfsp->sf_bfree),
- (u_int32_t)ntohl(sfsp->sf_bavail));
+ EXTRACT_32BITS(&sfsp->sf_tsize),
+ EXTRACT_32BITS(&sfsp->sf_bsize),
+ EXTRACT_32BITS(&sfsp->sf_blocks),
+ EXTRACT_32BITS(&sfsp->sf_bfree),
+ EXTRACT_32BITS(&sfsp->sf_bavail));
}
return (1);
int er;
dp = parsestatus(dp, &er);
- if (dp == 0 || er)
+ if (dp == NULL)
return (0);
+ if (er)
+ return (1);
if (qflag)
return (1);
TCHECK(dp[2]);
printf(" offset %x size %d ",
- (u_int32_t)ntohl(dp[0]), (u_int32_t)ntohl(dp[1]));
+ EXTRACT_32BITS(&dp[0]), EXTRACT_32BITS(&dp[1]));
if (dp[2] != 0)
printf(" eof");
static const u_int32_t *
parse_wcc_attr(const u_int32_t *dp)
{
- printf(" sz ");
- print_int64(dp, UNSIGNED);
+ printf(" sz %" PRIu64, EXTRACT_64BITS(&dp[0]));
printf(" mtime %u.%06u ctime %u.%06u",
- (u_int32_t)ntohl(dp[2]), (u_int32_t)ntohl(dp[3]),
- (u_int32_t)ntohl(dp[4]), (u_int32_t)ntohl(dp[5]));
+ EXTRACT_32BITS(&dp[2]), EXTRACT_32BITS(&dp[3]),
+ EXTRACT_32BITS(&dp[4]), EXTRACT_32BITS(&dp[5]));
return (dp + 6);
}
parse_pre_op_attr(const u_int32_t *dp, int verbose)
{
TCHECK(dp[0]);
- if (!ntohl(dp[0]))
+ if (!EXTRACT_32BITS(&dp[0]))
return (dp + 1);
dp++;
- TCHECK2(dp, 24);
+ TCHECK2(*dp, 24);
if (verbose > 1) {
return parse_wcc_attr(dp);
} else {
parse_post_op_attr(const u_int32_t *dp, int verbose)
{
TCHECK(dp[0]);
- if (!ntohl(dp[0]))
+ if (!EXTRACT_32BITS(&dp[0]))
return (dp + 1);
dp++;
if (verbose) {
dp = parse_wcc_data(dp, verbose);
else {
TCHECK(dp[0]);
- if (!ntohl(dp[0]))
+ if (!EXTRACT_32BITS(&dp[0]))
return (dp + 1);
dp++;
if (!(dp = parsefh(dp, 1)))
if (!(dp = parse_post_op_attr(dp, verbose)))
return (0);
if (vflag > 1) {
- printf("dir attr:");
+ printf(" dir attr:");
dp = parse_wcc_data(dp, verbose);
}
}
sfp = (struct nfsv3_fsinfo *)dp;
TCHECK(*sfp);
printf(" rtmax %u rtpref %u wtmax %u wtpref %u dtpref %u",
- (u_int32_t) ntohl(sfp->fs_rtmax),
- (u_int32_t) ntohl(sfp->fs_rtpref),
- (u_int32_t) ntohl(sfp->fs_wtmax),
- (u_int32_t) ntohl(sfp->fs_wtpref),
- (u_int32_t) ntohl(sfp->fs_dtpref));
+ EXTRACT_32BITS(&sfp->fs_rtmax),
+ EXTRACT_32BITS(&sfp->fs_rtpref),
+ EXTRACT_32BITS(&sfp->fs_wtmax),
+ EXTRACT_32BITS(&sfp->fs_wtpref),
+ EXTRACT_32BITS(&sfp->fs_dtpref));
if (vflag) {
- printf(" rtmult %u wtmult %u maxfsz ",
- (u_int32_t) ntohl(sfp->fs_rtmult),
- (u_int32_t) ntohl(sfp->fs_wtmult));
- print_int64((u_int32_t *)&sfp->fs_maxfilesize, UNSIGNED);
+ printf(" rtmult %u wtmult %u maxfsz %" PRIu64,
+ EXTRACT_32BITS(&sfp->fs_rtmult),
+ EXTRACT_32BITS(&sfp->fs_wtmult),
+ EXTRACT_64BITS((u_int32_t *)&sfp->fs_maxfilesize));
printf(" delta %u.%06u ",
- (u_int32_t) ntohl(sfp->fs_timedelta.nfsv3_sec),
- (u_int32_t) ntohl(sfp->fs_timedelta.nfsv3_nsec));
+ EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_sec),
+ EXTRACT_32BITS(&sfp->fs_timedelta.nfsv3_nsec));
}
- return (0);
-trunc:
return (1);
+trunc:
+ return (0);
}
static int
TCHECK(*spp);
printf(" linkmax %u namemax %u %s %s %s %s",
- (u_int32_t) ntohl(spp->pc_linkmax),
- (u_int32_t) ntohl(spp->pc_namemax),
- ntohl(spp->pc_notrunc) ? "notrunc" : "",
- ntohl(spp->pc_chownrestricted) ? "chownres" : "",
- ntohl(spp->pc_caseinsensitive) ? "igncase" : "",
- ntohl(spp->pc_casepreserving) ? "keepcase" : "");
- return (0);
-trunc:
+ EXTRACT_32BITS(&spp->pc_linkmax),
+ EXTRACT_32BITS(&spp->pc_namemax),
+ EXTRACT_32BITS(&spp->pc_notrunc) ? "notrunc" : "",
+ EXTRACT_32BITS(&spp->pc_chownrestricted) ? "chownres" : "",
+ EXTRACT_32BITS(&spp->pc_caseinsensitive) ? "igncase" : "",
+ EXTRACT_32BITS(&spp->pc_casepreserving) ? "keepcase" : "");
return (1);
+trunc:
+ return (0);
}
static void
-interp_reply(const struct rpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
+interp_reply(const struct sunrpc_msg *rp, u_int32_t proc, u_int32_t vers, int length)
{
register const u_int32_t *dp;
register int v3;
if (!(dp = parse_post_op_attr(dp, vflag)))
break;
if (!er)
- printf(" c %04x", (u_int32_t)ntohl(dp[0]));
+ printf(" c %04x", EXTRACT_32BITS(&dp[0]));
return;
case NFSPROC_READLINK:
return;
if (vflag) {
TCHECK(dp[1]);
- printf("%u bytes", (u_int32_t) ntohl(dp[0]));
- if (ntohl(dp[1]))
+ printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
+ if (EXTRACT_32BITS(&dp[1]))
printf(" EOF");
}
return;
return;
if (vflag) {
TCHECK(dp[0]);
- printf("%u bytes", (u_int32_t) ntohl(dp[0]));
+ printf(" %u bytes", EXTRACT_32BITS(&dp[0]));
if (vflag > 1) {
TCHECK(dp[1]);
printf(" <%s>",
tok2str(nfsv3_writemodes,
- NULL, ntohl(dp[1])));
+ NULL, EXTRACT_32BITS(&dp[1])));
}
return;
}
}
trunc:
if (!nfserr)
- fputs(" [|nfs]", stdout);
+ printf("%s", tstr);
}