[BACK]Return to net.c CVS log [TXT][DIR] Up to [local] / sys / arch / sparc / stand / common

Annotation of sys/arch/sparc/stand/common/net.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: net.c,v 1.2 2003/08/14 17:13:57 deraadt Exp $ */
        !             2: /*     $NetBSD: net.c,v 1.2 1997/07/22 17:41:07 drochner Exp $ */
        !             3:
        !             4: /*
        !             5:  * Copyright (c) 1995 Gordon W. Ross
        !             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. The name of the author may not be used to endorse or promote products
        !            17:  *    derived from this software without specific prior written permission.
        !            18:  * 4. All advertising materials mentioning features or use of this software
        !            19:  *    must display the following acknowledgement:
        !            20:  *      This product includes software developed by Gordon W. Ross
        !            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:  * This module implements a "raw device" interface suitable for
        !            36:  * use by the stand-alone I/O library NFS code.  This interface
        !            37:  * does not support any "block" access, and exists only for the
        !            38:  * purpose of initializing the network interface, getting boot
        !            39:  * parameters, and performing the NFS mount.
        !            40:  *
        !            41:  * At open time, this does:
        !            42:  *
        !            43:  * find interface      - netif_open()
        !            44:  * RARP for IP address - rarp_getipaddress()
        !            45:  * RPC/bootparams      - callrpc(d, RPC_BOOTPARAMS, ...)
        !            46:  * RPC/mountd          - nfs_mount(sock, ip, path)
        !            47:  *
        !            48:  * the root file handle from mountd is saved in a global
        !            49:  * for use by the NFS open code (NFS/lookup).
        !            50:  */
        !            51:
        !            52: #include <sys/param.h>
        !            53: #include <sys/socket.h>
        !            54: #include <net/if.h>
        !            55: #include <netinet/in.h>
        !            56: #include <netinet/in_systm.h>
        !            57:
        !            58: #include <lib/libsa/stand.h>
        !            59: #include <lib/libsa/net.h>
        !            60: #include <lib/libsa/netif.h>
        !            61: #include <lib/libsa/bootparam.h>
        !            62:
        !            63: #include "promdev.h"
        !            64:
        !            65: char           rootpath[FNAME_SIZE];
        !            66:
        !            67: int    netdev_sock = -1;
        !            68: static int open_count;
        !            69:
        !            70: /*
        !            71:  * Called by devopen after it sets f->f_dev to our devsw entry.
        !            72:  * This opens the low-level device and sets f->f_devdata.
        !            73:  */
        !            74: int
        !            75: net_open(struct promdata *pd)
        !            76: {
        !            77:        int error = 0;
        !            78:
        !            79:        /* On first open, do netif open, mount, etc. */
        !            80:        if (open_count == 0) {
        !            81:                /* Find network interface. */
        !            82:                if ((netdev_sock = netif_open(pd)) < 0) {
        !            83:                        error = errno;
        !            84:                        goto bad;
        !            85:                }
        !            86:                if ((error = net_mountroot()) != 0)
        !            87:                        goto bad;
        !            88:        }
        !            89:        open_count++;
        !            90: bad:
        !            91:        return (error);
        !            92: }
        !            93:
        !            94: int
        !            95: net_close(struct promdata *pd)
        !            96: {
        !            97:        /* On last close, do netif close, etc. */
        !            98:        if (open_count > 0)
        !            99:                if (--open_count == 0)
        !           100:                        netif_close(netdev_sock);
        !           101: }
        !           102:
        !           103: int
        !           104: net_mountroot(void)
        !           105: {
        !           106:
        !           107: #ifdef DEBUG
        !           108:        printf("net_mountroot\n");
        !           109: #endif
        !           110:
        !           111:        /*
        !           112:         * Get info for NFS boot: our IP address, our hostname,
        !           113:         * server IP address, and our root path on the server.
        !           114:         * There are two ways to do this:  The old, Sun way,
        !           115:         * and the more modern, BOOTP way. (RFC951, RFC1048)
        !           116:         */
        !           117:
        !           118: #ifdef SUN_BOOTPARAMS
        !           119:        /* Get boot info using RARP and Sun bootparams. */
        !           120:
        !           121:        /* Get our IP address.  (rarp.c) */
        !           122:        if (rarp_getipaddress(netdev_sock) == -1)
        !           123:                return errno;
        !           124:
        !           125:        printf("boot: client IP address: %s\n", inet_ntoa(myip));
        !           126:
        !           127:        /* Get our hostname, server IP address. */
        !           128:        if (bp_whoami(netdev_sock))
        !           129:                return (errno);
        !           130:
        !           131:        printf("boot: client name: %s\n", hostname);
        !           132:
        !           133:        /* Get the root pathname. */
        !           134:        if (bp_getfile(netdev_sock, "root", &rootip, rootpath))
        !           135:                return (errno);
        !           136:
        !           137: #else
        !           138:
        !           139:        /* Get boot info using BOOTP way. (RFC951, RFC1048) */
        !           140:        bootp(netdev_sock);
        !           141:
        !           142:        printf("Using IP address: %s\n", inet_ntoa(myip));
        !           143:
        !           144:        printf("myip: %s (%s)", hostname, inet_ntoa(myip));
        !           145:        if (gateip)
        !           146:                printf(", gateip: %s", inet_ntoa(gateip));
        !           147:        if (netmask)
        !           148:                printf(", netmask: %s", intoa(netmask));
        !           149:        printf("\n");
        !           150:
        !           151: #endif
        !           152:
        !           153:        printf("root addr=%s path=%s\n", inet_ntoa(rootip), rootpath);
        !           154:
        !           155:        /* Get the NFS file handle (mount). */
        !           156:        if (nfs_mount(netdev_sock, rootip, rootpath) != 0)
        !           157:                return (errno);
        !           158:        return 0;
        !           159: }

CVSweb