Source-Changes-HG archive

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

[src/trunk]: src/sys/nfs Some tweaks to enable NFS over IPv6. The special-cas...



details:   https://anonhg.NetBSD.org/src/rev/ca6fea8e1305
branches:  trunk
changeset: 487524:ca6fea8e1305
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Fri Jun 09 00:00:17 2000 +0000

description:
Some tweaks to enable NFS over IPv6. The special-casing of AF_INET
should really be removed.

diffstat:

 sys/nfs/nfs.h          |   8 +++++++-
 sys/nfs/nfs_nqlease.c  |  27 +++++++++++++++++++++++----
 sys/nfs/nfs_socket.c   |  23 ++++++++++++++++++++++-
 sys/nfs/nfs_subs.c     |  24 ++++++++++++++++++++++--
 sys/nfs/nfs_syscalls.c |  25 +++++++++++++++++++++++--
 sys/nfs/nqnfs.h        |   3 ++-
 6 files changed, 99 insertions(+), 11 deletions(-)

diffs (297 lines):

diff -r 2f08c6ff18e6 -r ca6fea8e1305 sys/nfs/nfs.h
--- a/sys/nfs/nfs.h     Thu Jun 08 23:39:43 2000 +0000
+++ b/sys/nfs/nfs.h     Fri Jun 09 00:00:17 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs.h,v 1.21 2000/04/15 21:14:52 tsarna Exp $  */
+/*     $NetBSD: nfs.h,v 1.22 2000/06/09 00:00:17 fvdl Exp $    */
 /*
  * Copyright (c) 1989, 1993, 1995
  *     The Regents of the University of California.  All rights reserved.
@@ -380,7 +380,13 @@
 /* Bits for nu_flag */
 #define        NU_INETADDR     0x1
 #define NU_NAM         0x2
+#ifdef INET6
+#define NU_NETFAM(u) \
+       (((u)->nu_flag & NU_INETADDR) ? \
+       (((u)->nu_flag & NU_NAM) ? AF_INET6 : AF_INET) : AF_ISO)
+#else
 #define NU_NETFAM(u)   (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
+#endif
 
 struct nfssvc_sock {
        TAILQ_ENTRY(nfssvc_sock) ns_chain;      /* List of all nfssvc_sock's */
diff -r 2f08c6ff18e6 -r ca6fea8e1305 sys/nfs/nfs_nqlease.c
--- a/sys/nfs/nfs_nqlease.c     Thu Jun 08 23:39:43 2000 +0000
+++ b/sys/nfs/nfs_nqlease.c     Fri Jun 09 00:00:17 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_nqlease.c,v 1.31 2000/03/30 12:51:14 augustss Exp $        */
+/*     $NetBSD: nfs_nqlease.c,v 1.32 2000/06/09 00:00:17 fvdl Exp $    */
 
 /*
  * Copyright (c) 1992, 1993
@@ -54,6 +54,7 @@
 
 #include "fs_nfs.h"
 #include "opt_nfsserver.h"
+#include "opt_inet.h"
 
 #include <sys/param.h>
 #include <sys/vnode.h>
@@ -123,6 +124,9 @@
 extern nfstype nfsv2_type[9];
 extern nfstype nfsv3_type[9];
 extern struct nfssvc_sock *nfs_udpsock, *nfs_cltpsock;
+#ifdef INET6
+extern struct nfssvc_sock *nfs_udp6sock;
+#endif
 extern int nfsd_waiting;
 extern struct nfsstats nfsstats;
 
@@ -331,6 +335,11 @@
                lph->lph_flag |= (LC_VALID | LC_UDP);
                lph->lph_inetaddr = saddr->sin_addr.s_addr;
                lph->lph_port = saddr->sin_port;
+#ifdef INET6
+       } else if (slp == nfs_udp6sock) {
+               lph->lph_nam = m_copym(nam, 0, M_COPYALL, M_WAIT);
+               lph->lph_flag |= (LC_VALID | LC_UDP6);
+#endif
        } else if (slp == nfs_cltpsock) {
                lph->lph_nam = m_copym(nam, 0, M_COPYALL, M_WAIT);
                lph->lph_flag |= (LC_VALID | LC_CLTP);
@@ -399,7 +408,11 @@
                else
                        return (0);
        }
-       if (slp == nfs_udpsock || slp == nfs_cltpsock)
+       if (slp == nfs_udpsock || slp == nfs_cltpsock
+#ifdef INET6
+           || slp == nfs_udp6sock
+#endif
+       )
                addr = nam;
        else
                addr = slp->ns_nam;
@@ -461,6 +474,11 @@
                        } else if (lph->lph_flag & LC_CLTP) {
                                nam2 = lph->lph_nam;
                                so = nfs_cltpsock->ns_so;
+#ifdef INET6
+                       } else if (lph->lph_flag & LC_UDP6) {
+                               nam2 = lph->lph_nam;
+                               so = nfs_udp6sock->ns_so;
+#endif
                        } else if (lph->lph_slp->ns_flag & SLP_VALID) {
                                nam2 = (struct mbuf *)0;
                                so = lph->lph_slp->ns_so;
@@ -503,7 +521,8 @@
                                *mtod(m, u_int32_t *) = htonl(0x80000000 |
                                        (m->m_pkthdr.len - NFSX_UNSIGNED));
                        }
-                       if (((lph->lph_flag & (LC_UDP | LC_CLTP)) == 0 &&
+                       if (((lph->lph_flag & (LC_UDP | LC_CLTP | LC_UDP6))
+                           == 0 &&
                            (lph->lph_slp->ns_flag & SLP_VALID) == 0) ||
                            (solockp && (*solockp & NFSMNT_SNDLOCK)))
                                m_freem(m);
@@ -632,7 +651,7 @@
                        i = 0;
                        ok = 1;
                        while (ok && (lph->lph_flag & LC_VALID)) {
-                               if (lph->lph_flag & LC_CLTP)
+                               if (lph->lph_flag & (LC_CLTP | LC_UDP6))
                                        MFREE(lph->lph_nam, n);
                                if (lph->lph_flag & LC_SREF)
                                        nfsrv_slpderef(lph->lph_slp);
diff -r 2f08c6ff18e6 -r ca6fea8e1305 sys/nfs/nfs_socket.c
--- a/sys/nfs/nfs_socket.c      Thu Jun 08 23:39:43 2000 +0000
+++ b/sys/nfs/nfs_socket.c      Fri Jun 09 00:00:17 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_socket.c,v 1.56 2000/05/27 04:52:41 thorpej Exp $  */
+/*     $NetBSD: nfs_socket.c,v 1.57 2000/06/09 00:00:17 fvdl Exp $     */
 
 /*
  * Copyright (c) 1989, 1991, 1993, 1995
@@ -44,6 +44,7 @@
 
 #include "fs_nfs.h"
 #include "opt_nfsserver.h"
+#include "opt_inet.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -158,6 +159,9 @@
        int s, error, rcvreserve, sndreserve;
        struct sockaddr *saddr;
        struct sockaddr_in *sin;
+#ifdef INET6
+       struct sockaddr_in6 *sin6;
+#endif
        struct mbuf *m;
        u_int16_t tport;
 
@@ -188,6 +192,23 @@
                if (error)
                        goto bad;
        }
+#ifdef INET6
+       if (saddr->sa_family == AF_INET6 && (nmp->nm_flag & NFSMNT_RESVPORT)) {
+               MGET(m, M_WAIT, MT_SONAME);
+               sin6 = mtod(m, struct sockaddr_in6 *);
+               sin6->sin6_len = m->m_len = sizeof (struct sockaddr_in6);
+               sin6->sin6_family = AF_INET6;
+               sin6->sin6_addr = in6addr_any;
+               tport = IPV6PORT_RESERVED - 1;
+               sin6->sin6_port = htons(tport);
+               while ((error = sobind(so, m)) == EADDRINUSE &&
+                      --tport > IPV6PORT_RESERVED / 2)
+                       sin6->sin6_port = htons(tport);
+               m_freem(m);
+               if (error)
+                       goto bad;
+       }
+#endif
 
        /*
         * Protocols that do not require connections may be optionally left
diff -r 2f08c6ff18e6 -r ca6fea8e1305 sys/nfs/nfs_subs.c
--- a/sys/nfs/nfs_subs.c        Thu Jun 08 23:39:43 2000 +0000
+++ b/sys/nfs/nfs_subs.c        Fri Jun 09 00:00:17 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_subs.c,v 1.75 2000/03/30 12:51:16 augustss Exp $   */
+/*     $NetBSD: nfs_subs.c,v 1.76 2000/06/09 00:00:18 fvdl Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,6 +41,7 @@
 #include "fs_nfs.h"
 #include "opt_nfsserver.h"
 #include "opt_iso.h"
+#include "opt_inet.h"
 
 /*
  * These functions support the macros and help fiddle mbuf chains for
@@ -2228,11 +2229,18 @@
 
        if (!(exflags & (MNT_EXNORESPORT|MNT_EXPUBLIC))) {
                saddr = mtod(nam, struct sockaddr_in *);
-               if (saddr->sin_family == AF_INET &&
+               if ((saddr->sin_family == AF_INET) &&
                    ntohs(saddr->sin_port) >= IPPORT_RESERVED) {
                        vput(*vpp);
                        return (NFSERR_AUTHERR | AUTH_TOOWEAK);
                }
+#ifdef INET6
+               if ((saddr->sin_family == AF_INET6) &&
+                   ntohs(saddr->sin_port) >= IPV6PORT_RESERVED) {
+                       vput(*vpp);
+                       return (NFSERR_AUTHERR | AUTH_TOOWEAK);
+               }
+#endif
        }
        /*
         * Check/setup credentials.
@@ -2301,6 +2309,18 @@
                    inetaddr->sin_addr.s_addr == haddr->had_inetaddr)
                        return (1);
                break;
+#ifdef INET6
+       case AF_INET6:
+           {
+               struct sockaddr_in6 *sin6_1, *sin6_2;
+
+               sin6_1 = mtod(nam, struct sockaddr_in6 *);
+               sin6_2 = mtod(haddr->had_nam, struct sockaddr_in6 *);
+               if (sin6_1->sin6_family == AF_INET6 &&
+                   IN6_ARE_ADDR_EQUAL(&sin6_1->sin6_addr, &sin6_2->sin6_addr))
+                       return 1;
+           }
+#endif
 #ifdef ISO
        case AF_ISO:
            {
diff -r 2f08c6ff18e6 -r ca6fea8e1305 sys/nfs/nfs_syscalls.c
--- a/sys/nfs/nfs_syscalls.c    Thu Jun 08 23:39:43 2000 +0000
+++ b/sys/nfs/nfs_syscalls.c    Fri Jun 09 00:00:17 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nfs_syscalls.c,v 1.40 2000/05/07 01:38:36 tsarna Exp $ */
+/*     $NetBSD: nfs_syscalls.c,v 1.41 2000/06/09 00:00:18 fvdl Exp $   */
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,6 +41,7 @@
 #include "fs_nfs.h"
 #include "opt_nfsserver.h"
 #include "opt_iso.h"
+#include "opt_inet.h"
 #include "opt_compat_netbsd.h"
 
 #include <sys/param.h>
@@ -95,6 +96,9 @@
 extern struct nfsstats nfsstats;
 extern int nfsrvw_procrastinate;
 struct nfssvc_sock *nfs_udpsock, *nfs_cltpsock;
+#ifdef INET6
+struct nfssvc_sock *nfs_udp6sock;
+#endif
 int nuidhash_max = NFS_MAXUIDHASH;
 int nfsd_waiting = 0;
 #ifdef NFSSERVER
@@ -348,6 +352,11 @@
         * Add it to the list, as required.
         */
        if (so->so_proto->pr_protocol == IPPROTO_UDP) {
+#ifdef INET6
+               if (so->so_proto->pr_domain->dom_family == AF_INET6)
+                       tslp = nfs_udp6sock;
+               else
+#endif
                tslp = nfs_udpsock;
                if (tslp->ns_flag & SLP_VALID) {
                        m_freem(mynam);
@@ -383,7 +392,11 @@
                m->m_len = sizeof(int32_t);
                sosetopt(so, SOL_SOCKET, SO_KEEPALIVE, m);
        }
-       if (so->so_proto->pr_domain->dom_family == AF_INET &&
+       if ((so->so_proto->pr_domain->dom_family == AF_INET
+#ifdef INET6
+           || so->so_proto->pr_domain->dom_family == AF_INET6
+#endif
+           ) &&
            so->so_proto->pr_protocol == IPPROTO_TCP) {
                MGET(m, M_WAIT, MT_SOOPTS);
                *mtod(m, int32_t *) = 1;
@@ -839,6 +852,14 @@
        TAILQ_INIT(&nfs_udpsock->ns_uidlruhead);
        TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain);
 
+#ifdef INET6
+       nfs_udp6sock = (struct nfssvc_sock *)
+           malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
+       memset((caddr_t)nfs_udp6sock, 0, sizeof (struct nfssvc_sock));
+       TAILQ_INIT(&nfs_udp6sock->ns_uidlruhead);
+       TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_udp6sock, ns_chain);
+#endif
+
        nfs_cltpsock = (struct nfssvc_sock *)
            malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
        memset((caddr_t)nfs_cltpsock, 0, sizeof (struct nfssvc_sock));
diff -r 2f08c6ff18e6 -r ca6fea8e1305 sys/nfs/nqnfs.h
--- a/sys/nfs/nqnfs.h   Thu Jun 08 23:39:43 2000 +0000
+++ b/sys/nfs/nqnfs.h   Fri Jun 09 00:00:17 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nqnfs.h,v 1.6 1996/02/18 11:54:10 fvdl Exp $   */
+/*     $NetBSD: nqnfs.h,v 1.7 2000/06/09 00:00:18 fvdl Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -138,6 +138,7 @@
 #define        LC_VACATED      0x0200  /* Host has vacated lease */
 #define        LC_WRITTEN      0x0400  /* Recently wrote to the leased file */
 #define        LC_SREF         0x0800  /* Holds a nfssvc_sock reference */
+#define LC_UDP6                0x1000  /* Host address for udp6 socket */
 
 struct nqm {
        struct nqm      *lpm_next;



Home | Main Index | Thread Index | Old Index