The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/nfs/nfs_bootstatic.c

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: nfs_bootstatic.c,v 1.8 2009/10/23 02:32:34 snj Exp $   */
    2 
    3 /*
    4  *
    5  * Copyright (c) 2004 Christian Limpach.
    6  * All rights reserved.
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 
   30 #include <sys/cdefs.h>
   31 __KERNEL_RCSID(0, "$NetBSD: nfs_bootstatic.c,v 1.8 2009/10/23 02:32:34 snj Exp $");
   32 
   33 #ifdef _KERNEL_OPT
   34 #include "opt_nfs_boot.h"
   35 #endif
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/kernel.h>
   40 #include <sys/ioctl.h>
   41 #include <sys/proc.h>
   42 #include <sys/mount.h>
   43 #include <sys/mbuf.h>
   44 #include <sys/socket.h>
   45 #include <sys/socketvar.h>
   46 
   47 #include <net/if.h>
   48 #include <net/if_types.h>
   49 #include <net/if_media.h>
   50 #include <net/route.h>
   51 #include <net/if_ether.h>
   52 
   53 #include <netinet/in.h>
   54 #include <netinet/if_inarp.h>
   55 
   56 #include <nfs/rpcv2.h>
   57 
   58 #include <nfs/nfsproto.h>
   59 #include <nfs/nfs.h>
   60 #include <nfs/nfsmount.h>
   61 #include <nfs/nfsdiskless.h>
   62 
   63 int (*nfs_bootstatic_callback)(struct nfs_diskless *) = NULL;
   64 
   65 int
   66 nfs_bootstatic(struct nfs_diskless *nd, struct lwp *lwp, int *_flags)
   67 {
   68         struct ifnet *ifp = nd->nd_ifp;
   69         struct sockaddr_in *sin;
   70         int error, flags;
   71 
   72         if (nfs_bootstatic_callback)
   73                 flags = (*nfs_bootstatic_callback)(nd);
   74         else
   75                 flags = 0;
   76 
   77         if (flags & NFS_BOOT_NOSTATIC)
   78                 return EOPNOTSUPP;
   79 
   80         if (flags == 0) {
   81 #ifdef NFS_BOOTSTATIC_MYIP
   82                 if (!(*_flags & NFS_BOOT_HAS_MYIP)) {
   83                         nd->nd_myip.s_addr = inet_addr(NFS_BOOTSTATIC_MYIP);
   84                         flags |= NFS_BOOT_HAS_MYIP;
   85                 }
   86 #endif
   87 #ifdef NFS_BOOTSTATIC_GWIP
   88                 if (!(*_flags & NFS_BOOT_HAS_GWIP)) {
   89                         nd->nd_gwip.s_addr = inet_addr(NFS_BOOTSTATIC_GWIP);
   90                         flags |= NFS_BOOT_HAS_GWIP;
   91                 }
   92 #endif
   93 #ifdef NFS_BOOTSTATIC_MASK
   94                 if (!(*_flags & NFS_BOOT_HAS_MASK)) {
   95                         nd->nd_mask.s_addr = inet_addr(NFS_BOOTSTATIC_MASK);
   96                         flags |= NFS_BOOT_HAS_MASK;
   97                 }
   98 #endif
   99 #ifdef NFS_BOOTSTATIC_SERVADDR
  100                 if (!(*_flags & NFS_BOOT_HAS_SERVADDR)) {
  101                         sin = (struct sockaddr_in *) &nd->nd_root.ndm_saddr;
  102                         memset((void *)sin, 0, sizeof(*sin));
  103                         sin->sin_len = sizeof(*sin);
  104                         sin->sin_family = AF_INET;
  105                         sin->sin_addr.s_addr = inet_addr(NFS_BOOTSTATIC_SERVADDR);
  106                         flags |= NFS_BOOT_HAS_SERVADDR;
  107                 }
  108 #endif
  109 #ifdef NFS_BOOTSTATIC_SERVER
  110                 if (!(*_flags & NFS_BOOT_HAS_SERVER)) {
  111                         strncpy(nd->nd_root.ndm_host, NFS_BOOTSTATIC_SERVER,
  112                                 MNAMELEN);
  113                         flags |= NFS_BOOT_HAS_SERVER;
  114                         if (strchr(nd->nd_root.ndm_host, ':') != NULL)
  115                                 flags |= NFS_BOOT_HAS_ROOTPATH;
  116                 }
  117 #endif
  118         }
  119 
  120         *_flags |= flags;
  121 
  122         if (!(*_flags & NFS_BOOT_HAS_SERVADDR) && (*_flags & NFS_BOOT_HAS_SERVER)) {
  123                 char rootserver[MNAMELEN];
  124                 char *sep;
  125 
  126                 sep = strchr(nd->nd_root.ndm_host, ':');
  127                 strlcpy(rootserver, nd->nd_root.ndm_host,
  128                         sep - nd->nd_root.ndm_host+1);
  129 
  130                 sin = (struct sockaddr_in *) &nd->nd_root.ndm_saddr;
  131                 memset((void *)sin, 0, sizeof(*sin));
  132                 sin->sin_len = sizeof(*sin);
  133                 sin->sin_family = AF_INET;
  134                 sin->sin_addr.s_addr = inet_addr(rootserver);
  135                 flags |= NFS_BOOT_HAS_SERVADDR;
  136                 *_flags |= NFS_BOOT_HAS_SERVADDR;
  137         }
  138 
  139         if (flags & NFS_BOOT_HAS_MYIP)
  140                 aprint_normal("nfs_boot: client_addr=%s\n",
  141                     inet_ntoa(nd->nd_myip));
  142 
  143         if (flags & NFS_BOOT_HAS_GWIP)
  144                 aprint_normal("nfs_boot: gateway=%s\n",
  145                     inet_ntoa(nd->nd_gwip));
  146 
  147         if (flags & NFS_BOOT_HAS_MASK)
  148                 aprint_normal("nfs_boot: netmask=%s\n",
  149                     inet_ntoa(nd->nd_mask));
  150 
  151         if (flags & NFS_BOOT_HAS_SERVADDR) {
  152                 sin = (struct sockaddr_in *) &nd->nd_root.ndm_saddr;
  153                 aprint_normal("nfs_boot: server=%s\n",
  154                     inet_ntoa(sin->sin_addr));
  155         }
  156 
  157         if (flags & NFS_BOOT_HAS_SERVER)
  158                 aprint_normal("nfs_boot: root=%.*s\n", MNAMELEN,
  159                     nd->nd_root.ndm_host);
  160 
  161         /*
  162          * Do enough of ifconfig(8) so that the chosen interface
  163          * can talk to the servers.
  164          */
  165         error = nfs_boot_setaddress(ifp, lwp,
  166             *_flags & NFS_BOOT_HAS_MYIP ? nd->nd_myip.s_addr : INADDR_ANY,
  167             *_flags & NFS_BOOT_HAS_MASK ? nd->nd_mask.s_addr : INADDR_ANY,
  168             INADDR_ANY);
  169         if (error) {
  170                 aprint_error("nfs_boot: set ifaddr, error=%d\n", error);
  171                 goto out;
  172         }
  173 
  174         if ((*_flags & NFS_BOOT_ALLINFO) != NFS_BOOT_ALLINFO)
  175                 return EADDRNOTAVAIL;
  176 
  177         error = 0;
  178 
  179  out:
  180 
  181         return error;
  182 }

Cache object: cf2e3d3eb0a90c946080bfe5d6028f4b


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.