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  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: nfs_bootstatic.c,v 1.3 2005/12/11 12:25:16 christos 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  * 3. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by Christian Limpach.
   19  * 4. The name of the author may not be used to endorse or promote products
   20  *    derived from this software without specific prior written permission.
   21  *
   22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   32  */
   33 
   34 
   35 #include <sys/cdefs.h>
   36 __KERNEL_RCSID(0, "$NetBSD: nfs_bootstatic.c,v 1.3 2005/12/11 12:25:16 christos Exp $");
   37 
   38 #include "opt_nfs_boot.h"
   39 #include "opt_inet.h"
   40 
   41 #include <sys/param.h>
   42 #include <sys/systm.h>
   43 #include <sys/kernel.h>
   44 #include <sys/ioctl.h>
   45 #include <sys/proc.h>
   46 #include <sys/mount.h>
   47 #include <sys/mbuf.h>
   48 #include <sys/socket.h>
   49 #include <sys/socketvar.h>
   50 
   51 #include <net/if.h>
   52 #include <net/if_types.h>
   53 #include <net/if_media.h>
   54 #include <net/route.h>
   55 #include <net/if_ether.h>
   56 
   57 #include <netinet/in.h>
   58 #include <netinet/if_inarp.h>
   59 
   60 #include <nfs/rpcv2.h>
   61 
   62 #include <nfs/nfsproto.h>
   63 #include <nfs/nfs.h>
   64 #include <nfs/nfsmount.h>
   65 #include <nfs/nfsdiskless.h>
   66 
   67 int (*nfs_bootstatic_callback)(struct nfs_diskless *) = NULL;
   68 
   69 int
   70 nfs_bootstatic(struct nfs_diskless *nd, struct lwp *lwp)
   71 {
   72         struct ifnet *ifp = nd->nd_ifp;
   73         struct sockaddr_in *sin;
   74         int error, flags;
   75 
   76         if (nfs_bootstatic_callback)
   77                 flags = (*nfs_bootstatic_callback)(nd);
   78         else
   79                 flags = 0;
   80 
   81         if (flags == 0) {
   82 #ifdef NFS_BOOTSTATIC_MYIP
   83                 nd->nd_myip.s_addr = inet_addr(NFS_BOOTSTATIC_MYIP);
   84                 flags |= NFS_BOOTSTATIC_HAS_MYIP;
   85 #endif
   86 #ifdef NFS_BOOTSTATIC_GWIP
   87                 nd->nd_gwip.s_addr = inet_addr(NFS_BOOTSTATIC_GWIP);
   88                 flags |= NFS_BOOTSTATIC_HAS_GWIP;
   89 #endif
   90 #ifdef NFS_BOOTSTATIC_MASK
   91                 nd->nd_mask.s_addr = inet_addr(NFS_BOOTSTATIC_MASK);
   92                 flags |= NFS_BOOTSTATIC_HAS_MASK;
   93 #endif
   94 #ifdef NFS_BOOTSTATIC_SERVADDR
   95                 sin = (struct sockaddr_in *) &nd->nd_root.ndm_saddr;
   96                 memset((caddr_t)sin, 0, sizeof(*sin));
   97                 sin->sin_len = sizeof(*sin);
   98                 sin->sin_family = AF_INET;
   99                 sin->sin_addr.s_addr = inet_addr(NFS_BOOTSTATIC_SERVADDR);
  100                 flags |= NFS_BOOTSTATIC_HAS_SERVADDR;
  101 #endif
  102 #ifdef NFS_BOOTSTATIC_SERVER
  103                 strncpy(nd->nd_root.ndm_host, NFS_BOOTSTATIC_SERVER, MNAMELEN);
  104                 flags |= NFS_BOOTSTATIC_HAS_SERVER;
  105 #endif
  106         }
  107 
  108         if (flags & NFS_BOOTSTATIC_HAS_MYIP)
  109                 aprint_normal("nfs_boot: client_addr=%s\n",
  110                     inet_ntoa(nd->nd_myip));
  111 
  112         if (flags & NFS_BOOTSTATIC_HAS_GWIP)
  113                 aprint_normal("nfs_boot: gateway=%s\n",
  114                     inet_ntoa(nd->nd_gwip));
  115 
  116         if (flags & NFS_BOOTSTATIC_HAS_MASK)
  117                 aprint_normal("nfs_boot: netmask=%s\n",
  118                     inet_ntoa(nd->nd_mask));
  119 
  120         if (flags & NFS_BOOTSTATIC_HAS_SERVADDR) {
  121                 sin = (struct sockaddr_in *) &nd->nd_root.ndm_saddr;
  122                 aprint_normal("nfs_boot: server=%s\n",
  123                     inet_ntoa(sin->sin_addr));
  124         }
  125 
  126         if (flags & NFS_BOOTSTATIC_HAS_SERVER)
  127                 aprint_normal("nfs_boot: root=%.*s\n", MNAMELEN,
  128                     nd->nd_root.ndm_host);
  129 
  130         /*
  131          * Do enough of ifconfig(8) so that the chosen interface
  132          * can talk to the servers.
  133          */
  134         error = nfs_boot_setaddress(ifp, lwp,
  135             flags & NFS_BOOTSTATIC_HAS_MYIP ? nd->nd_myip.s_addr : INADDR_ANY,
  136             flags & NFS_BOOTSTATIC_HAS_MASK ? nd->nd_mask.s_addr : INADDR_ANY,
  137             INADDR_ANY);
  138         if (error) {
  139                 aprint_error("nfs_boot: set ifaddr, error=%d\n", error);
  140                 goto out;
  141         }
  142 
  143         error = 0;
  144 
  145  out:
  146 
  147         return error;
  148 }

Cache object: 672ccee4753dbc2364defd5b758cf5a7


[ 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.