[BACK]Return to netio.c CVS log [TXT][DIR] Up to [local] / sys / arch / vax / boot / boot

Annotation of sys/arch/vax/boot/boot/netio.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: netio.c,v 1.4 2002/06/11 09:36:23 hugh Exp $  */
        !             2: /*     $NetBSD: netio.c,v 1.6 2000/05/26 20:16:46 ragge Exp $  */
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * This code is derived from software contributed to The NetBSD Foundation
        !             9:  * by Jason R. Thorpe.
        !            10:  *
        !            11:  * Redistribution and use in source and binary forms, with or without
        !            12:  * modification, are permitted provided that the following conditions
        !            13:  * are met:
        !            14:  * 1. Redistributions of source code must retain the above copyright
        !            15:  *    notice, this list of conditions and the following disclaimer.
        !            16:  * 2. Redistributions in binary form must reproduce the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer in the
        !            18:  *    documentation and/or other materials provided with the distribution.
        !            19:  * 3. All advertising materials mentioning features or use of this software
        !            20:  *    must display the following acknowledgement:
        !            21:  *     This product includes software developed by the NetBSD
        !            22:  *     Foundation, Inc. and its contributors.
        !            23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
        !            24:  *    contributors may be used to endorse or promote products derived
        !            25:  *    from this software without specific prior written permission.
        !            26:  *
        !            27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            37:  * POSSIBILITY OF SUCH DAMAGE.
        !            38:  */
        !            39:
        !            40: /*
        !            41:  * Copyright (c) 1995 Gordon W. Ross
        !            42:  * All rights reserved.
        !            43:  *
        !            44:  * Redistribution and use in source and binary forms, with or without
        !            45:  * modification, are permitted provided that the following conditions
        !            46:  * are met:
        !            47:  * 1. Redistributions of source code must retain the above copyright
        !            48:  *    notice, this list of conditions and the following disclaimer.
        !            49:  * 2. Redistributions in binary form must reproduce the above copyright
        !            50:  *    notice, this list of conditions and the following disclaimer in the
        !            51:  *    documentation and/or other materials provided with the distribution.
        !            52:  * 3. The name of the author may not be used to endorse or promote products
        !            53:  *    derived from this software without specific prior written permission.
        !            54:  * 4. All advertising materials mentioning features or use of this software
        !            55:  *    must display the following acknowledgement:
        !            56:  *     This product includes software developed by Gordon W. Ross
        !            57:  *
        !            58:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
        !            59:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
        !            60:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
        !            61:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
        !            62:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
        !            63:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
        !            64:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
        !            65:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
        !            66:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
        !            67:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        !            68:  */
        !            69:
        !            70: /*
        !            71:  * This module implements a "raw device" interface suitable for
        !            72:  * use by the stand-alone I/O library NFS code.         This interface
        !            73:  * does not support any "block" access, and exists only for the
        !            74:  * purpose of initializing the network interface, getting boot
        !            75:  * parameters, and performing the NFS mount.
        !            76:  *
        !            77:  * At open time, this does:
        !            78:  *
        !            79:  * find interface      - netif_open()
        !            80:  * RARP for IP address - rarp_getipaddress()
        !            81:  * RPC/bootparams      - callrpc(d, RPC_BOOTPARAMS, ...)
        !            82:  * RPC/mountd         - nfs_mount(sock, ip, path)
        !            83:  *
        !            84:  * the root file handle from mountd is saved in a global
        !            85:  * for use by the NFS open code (NFS/lookup).
        !            86:  */
        !            87:
        !            88: #include <sys/param.h>
        !            89: #include <sys/socket.h>
        !            90: #include <net/if.h>
        !            91: #include <netinet/in.h>
        !            92: #include <netinet/if_ether.h>
        !            93: #include <netinet/in_systm.h>
        !            94:
        !            95: #include "lib/libsa/stand.h"
        !            96: #include "lib/libsa/net.h"
        !            97: #include "lib/libsa/netif.h"
        !            98: #include "lib/libsa/bootparam.h"
        !            99: #include "lib/libsa/nfs.h"
        !           100: #include "lib/libsa/bootp.h"
        !           101:
        !           102: #include "vaxstand.h"
        !           103:
        !           104: static struct iodesc desc;
        !           105: static int inited = 0;
        !           106:
        !           107: struct iodesc *
        !           108: socktodesc(sock)
        !           109: {
        !           110:        return &desc;
        !           111: }
        !           112:
        !           113: int
        !           114: net_devinit(struct open_file *f, struct netif_driver *drv, u_char *eaddr) {
        !           115:        static struct netif best_if;
        !           116:        struct iodesc *s;
        !           117:        int r;
        !           118:
        !           119:        if (inited)
        !           120:                return 0;
        !           121:        /* find a free socket */
        !           122:        s = &desc;
        !           123:
        !           124:        bzero(s, sizeof(*s));
        !           125:        best_if.nif_driver = drv;
        !           126:        s->io_netif = &best_if;
        !           127:        bcopy(eaddr, s->myea, 6);
        !           128:
        !           129:        /*
        !           130:         * Get info for NFS boot: our IP address, our hostname,
        !           131:         * server IP address, and our root path on the server.
        !           132:         * There are two ways to do this:  The old, Sun way,
        !           133:         * and the more modern, BOOTP way. (RFC951, RFC1048)
        !           134:         */
        !           135:
        !           136: #ifdef SUPPORT_BOOTP
        !           137:
        !           138:        /* Get boot info using BOOTP way. (RFC951, RFC1048) */
        !           139:        printf("Trying BOOTP\n");
        !           140:        bootp(0);
        !           141:
        !           142:        if (myip.s_addr) {
        !           143:                printf("Using IP address: %s\n", inet_ntoa(myip));
        !           144:
        !           145:                printf("myip: %s (%s)\n", hostname, inet_ntoa(myip));
        !           146:        } else
        !           147:
        !           148: #endif /* SUPPORT_BOOTP */
        !           149:        {
        !           150: #ifdef SUPPORT_BOOTPARAMS
        !           151:                /* Get boot info using RARP and Sun bootparams. */
        !           152:
        !           153:                printf("Trying BOOTPARAMS\n");
        !           154:                /* Get our IP address.  (rarp.c) */
        !           155:                if (rarp_getipaddress(0) == -1)
        !           156:                        return (errno);
        !           157:
        !           158:                printf("boot: client IP address: %s\n", inet_ntoa(myip));
        !           159:
        !           160:                /* Get our hostname, server IP address. */
        !           161:                if (bp_whoami(0))
        !           162:                        return (errno);
        !           163:
        !           164:                printf("boot: client name: %s\n", hostname);
        !           165:
        !           166:                /* Get the root pathname. */
        !           167:                if (bp_getfile(0, "root", &rootip, rootpath))
        !           168:                        return (errno);
        !           169: #endif
        !           170:        }
        !           171:        printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
        !           172:        f->f_devdata = s;
        !           173:
        !           174:        /* Get the NFS file handle (mount). */
        !           175:        r = nfs_mount(0, rootip, rootpath);
        !           176:        if (r)
        !           177:                return r;
        !           178:
        !           179:        inited = 1;
        !           180:        return 0;
        !           181: }
        !           182:
        !           183: ssize_t
        !           184: netif_put(struct iodesc *desc, void *pkt, size_t len)
        !           185: {
        !           186:        return (*desc->io_netif->nif_driver->netif_put)(desc, pkt, len);
        !           187: }
        !           188:
        !           189: ssize_t
        !           190: netif_get(struct iodesc *desc, void *pkt, size_t len, time_t timo)
        !           191: {
        !           192:        return (*desc->io_netif->nif_driver->netif_get)(desc, pkt, len, timo);
        !           193: }

CVSweb