Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/tcpdump support NFS over IPv6. from tcpdump.org



details:   https://anonhg.NetBSD.org/src/rev/2ec78525daa2
branches:  trunk
changeset: 487629:2ec78525daa2
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat Jun 10 05:27:27 2000 +0000

description:
support NFS over IPv6.  from tcpdump.org

diffstat:

 usr.sbin/tcpdump/print-nfs.c |  516 +++++++++++++++++++++++++-----------------
 1 files changed, 306 insertions(+), 210 deletions(-)

diffs (truncated from 1028 to 300 lines):

diff -r 95ac3802c9a5 -r 2ec78525daa2 usr.sbin/tcpdump/print-nfs.c
--- a/usr.sbin/tcpdump/print-nfs.c      Sat Jun 10 05:24:46 2000 +0000
+++ b/usr.sbin/tcpdump/print-nfs.c      Sat Jun 10 05:27:27 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: print-nfs.c,v 1.10 1999/09/04 03:36:41 itojun Exp $    */
+/*     $NetBSD: print-nfs.c,v 1.11 2000/06/10 05:27:27 itojun Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -27,7 +27,7 @@
 static const char rcsid[] =
     "@(#) Header: print-nfs.c,v 1.65 97/08/17 13:24:22 leres Exp  (LBL)";
 #else
-__RCSID("$NetBSD: print-nfs.c,v 1.10 1999/09/04 03:36:41 itojun Exp $");
+__RCSID("$NetBSD: print-nfs.c,v 1.11 2000/06/10 05:27:27 itojun Exp $");
 #endif
 #endif
 
@@ -49,7 +49,9 @@
 #include <netinet/in.h>
 #include <netinet/in_systm.h>
 #include <netinet/ip.h>
-#include <netinet/ip_var.h>
+#ifdef INET6
+#include <netinet/ip6.h>
+#endif
 
 #include <rpc/rpc.h>
 
@@ -65,13 +67,14 @@
 #include "nfsfh.h"
 
 static void nfs_printfh(const u_int32_t *, const u_int);
-static void xid_map_enter(const struct rpc_msg *, const struct ip *);
-static int32_t xid_map_find(const struct rpc_msg *, const struct ip *,
-                         u_int32_t *, u_int32_t *);
+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 *,
+                           u_int32_t *, u_int32_t *);
 static void interp_reply(const struct rpc_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 *);
 
 /*
  * Mapping of old NFS Version 2 RPC numbers to generic numbers.
@@ -105,10 +108,11 @@
        NFSPROC_NOOP
 };
 
-const char *nfsv3_writemodes[NFSV3WRITE_NMODES] = {
-       "unstable",
-       "datasync",
-       "filesync"
+static struct tok nfsv3_writemodes[] = {
+       { 0,            "unstable" },
+       { 1,            "datasync" },
+       { 2,            "filesync" },
+       { 0,            NULL }
 };
 
 static struct tok type2str[] = {
@@ -155,78 +159,102 @@
                return (0);
        }
 #else
-#if 0
-       int sign;
-#endif
-       /*
-        * XXX - throw upper 32 bits away.
-        * Could also go for hex: printf("0x%x%x", dp[0], dp[1]);
-        */
-       if (sign)
-               printf("%d", (int)dp[1]);
-       else
-               printf("%u", (unsigned int)dp[1]);
+       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)
+{
+       struct ip *ip;
+#ifdef INET6
+       struct ip6_hdr *ip6;
+       char srcaddr[INET6_ADDRSTRLEN], dstaddr[INET6_ADDRSTRLEN];
+#else
+       char srcaddr[INET_ADDRSTRLEN], dstaddr[INET_ADDRSTRLEN];
+#endif
+
+       srcaddr[0] = dstaddr[0] = '\0';
+       switch (((struct ip *)bp)->ip_v) {
+       case 4:
+               ip = (struct ip *)bp;
+               strlcpy(srcaddr, ipaddr_string(&ip->ip_src), sizeof(srcaddr));
+               strlcpy(dstaddr, ipaddr_string(&ip->ip_dst), sizeof(dstaddr));
+               break;
+#ifdef INET6
+       case 6:
+               ip6 = (struct ip6_hdr *)bp;
+               strlcpy(srcaddr, ip6addr_string(&ip6->ip6_src),
+                   sizeof(srcaddr));
+               strlcpy(dstaddr, ip6addr_string(&ip6->ip6_dst),
+                   sizeof(dstaddr));
+               break;
+#endif
+       default:
+               strlcpy(srcaddr, "?", sizeof(srcaddr));
+               strlcpy(dstaddr, "?", sizeof(dstaddr));
+               break;
+       }
+
+       (void)printf("%s.%s > %s.%s: ", srcaddr, s, dstaddr, d);
+}
+
 static const u_int32_t *
 parse_sattr3(const u_int32_t *dp, struct nfsv3_sattr *sa3)
 {
-       register const u_int32_t *ep = (u_int32_t *)snapend;
-
-       if (dp + 1 > ep)
-               return (0);
+       TCHECK(dp[0]);
        if ((sa3->sa_modeset = ntohl(*dp++))) {
-               if (dp + 1 > ep)
-                       return (0);
+               TCHECK(dp[0]);
                sa3->sa_mode = ntohl(*dp++);
        }
 
-       if (dp + 1 > ep)
-               return (0);
+       TCHECK(dp[0]);
        if ((sa3->sa_uidset = ntohl(*dp++))) {
-               if (dp + 1 > ep)
-                       return (0);
+               TCHECK(dp[0]);
                sa3->sa_uid = ntohl(*dp++);
        }
 
-       if (dp + 1 > ep)
-               return (0);
+       TCHECK(dp[0]);
        if ((sa3->sa_gidset = ntohl(*dp++))) {
-               if (dp + 1 > ep)
-                       return (0);
+               TCHECK(dp[0]);
                sa3->sa_gid = ntohl(*dp++);
        }
 
-       if (dp + 1 > ep)
-               return (0);
+       TCHECK(dp[0]);
        if ((sa3->sa_sizeset = ntohl(*dp++))) {
-               if (dp + 1 > ep)
-                       return (0);
+               TCHECK(dp[0]);
                sa3->sa_size = ntohl(*dp++);
        }
 
-       if (dp + 1 > ep)
-               return (0);
+       TCHECK(dp[0]);
        if ((sa3->sa_atimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
-               if (dp + 2 > ep)
-                       return (0);
+               TCHECK(dp[1]);
                sa3->sa_atime.nfsv3_sec = ntohl(*dp++);
                sa3->sa_atime.nfsv3_nsec = ntohl(*dp++);
        }
 
-       if (dp + 1 > ep)
-               return (0);
+       TCHECK(dp[0]);
        if ((sa3->sa_mtimetype = ntohl(*dp++)) == NFSV3SATTRTIME_TOCLIENT) {
-               if (dp + 2 > ep)
-                       return (0);
+               TCHECK(dp[1]);
                sa3->sa_mtime.nfsv3_sec = ntohl(*dp++);
                sa3->sa_mtime.nfsv3_nsec = ntohl(*dp++);
        }
 
        return dp;
+trunc:
+       return NULL;
 }
+
 static int nfserr;             /* true if we error rather than trunc */
 
 static void
@@ -253,32 +281,28 @@
               register const u_char *bp2)
 {
        register const struct rpc_msg *rp;
-       register const struct ip *ip;
        u_int32_t proc, vers;
+       char srcid[20], dstid[20];      /*fits 32bit*/
 
        nfserr = 0;             /* assume no error */
        rp = (const struct rpc_msg *)bp;
-       ip = (const struct ip *)bp2;
 
-       if (!nflag)
-               (void)printf("%s.nfs > %s.%u: reply %s %d",
-                            ipaddr_string(&ip->ip_src),
-                            ipaddr_string(&ip->ip_dst),
-                            (u_int32_t)ntohl(rp->rm_xid),
-                            ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED?
-                                    "ok":"ERR",
-                            length);
-       else
-               (void)printf("%s.%u > %s.%u: reply %s %d",
-                            ipaddr_string(&ip->ip_src),
-                            NFS_PORT,
-                            ipaddr_string(&ip->ip_dst),
-                            (u_int32_t)ntohl(rp->rm_xid),
-                            ntohl(rp->rm_reply.rp_stat) == MSG_ACCEPTED?
-                               "ok":"ERR",
+       if (!nflag) {
+               strlcpy(srcid, "nfs", sizeof(srcid));
+               snprintf(dstid, sizeof(dstid), "%u",
+                   (u_int32_t)ntohl(rp->rm_xid));
+       } else {
+               snprintf(srcid, sizeof(srcid), "%u", NFS_PORT);
+               snprintf(dstid, sizeof(dstid), "%u",
+                   (u_int32_t)ntohl(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, ip, &proc, &vers) >= 0)
+       if (xid_map_find(rp, bp2, &proc, &vers) >= 0)
                interp_reply(rp, proc, vers, length);
 }
 
@@ -322,17 +346,17 @@
        int len;
 
        if (v3) {
-               if (dp + 1 > (u_int32_t *)snapend)
-                       return (0);
+               TCHECK(dp[0]);
                len = (int)ntohl(*dp) / 4;
                dp++;
        } else
                len = NFSX_V2FH / 4;
 
-       if (dp + len <= (u_int32_t *)snapend) {
+       if (TTEST2(*dp, len * sizeof(*dp))) {
                nfs_printfh(dp, len);
                return (dp + len);
        }
+trunc:
        return (NULL);
 }
 
@@ -347,24 +371,25 @@
        register const u_char *cp;
 
        /* Bail if we don't have the string length */
-       if ((u_char *)dp > snapend - sizeof(*dp))
-               return (NULL);
+       TCHECK(*dp);
 
        /* Fetch string length; convert to host order */
        len = *dp++;
        NTOHL(len);
 
+       TCHECK2(*dp, ((len + 3) & ~3));
+
        cp = (u_char *)dp;
        /* Update 32-bit pointer (NFS filenames padded to 32-bit boundaries) */
        dp += ((len + 3) & ~3) / sizeof(*dp);
-       if ((u_char *)dp > snapend)
-               return (NULL);
        /* XXX seems like we should be checking the length */
        putchar('"');
        (void) fn_printn(cp, len, NULL);
        putchar('"');
 
        return (dp);
+trunc:
+       return NULL;
 }



Home | Main Index | Thread Index | Old Index