/* * Called by devopen after it sets f->f_dev to our devsw entry. * This opens the low-level device and sets f->f_devdata. */ int net_open(struct of_dev *op) { int error = 0; /* * On first open, do netif open, mount, etc. */ if (open_count == 0) { /* Find network interface. */ if ((netdev_sock = netif_open(op)) < 0) { error = errno; goto bad; } if ((error = net_mountroot()) != 0) goto bad; } open_count++; bad: if (netdev_sock >= 0 && open_count == 0) { netif_close(netdev_sock); netdev_sock = -1; } return error; }
int net_close(struct open_file *f) { #ifdef NETIF_DEBUG if (debug) printf("net_close: opens=%d\n", netdev_opens); #endif /* On last close, do netif close, etc. */ f->f_devdata = NULL; /* Extra close call? */ if (netdev_opens <= 0) return (0); netdev_opens--; /* Not last close? */ if (netdev_opens > 0) return(0); rootip.s_addr = 0; if (netdev_sock >= 0) { if (debug) printf("net_close: calling netif_close()\n"); netif_close(netdev_sock); netdev_sock = -1; } return (0); }
/* * Called by devopen after it sets f->f_dev to our devsw entry. * This opens the low-level device and sets f->f_devdata. * This is declared with variable arguments... */ int net_open(struct open_file *f, void *vdev) { char *devname; /* Device part of file name (or NULL). */ int error = 0; devname = vdev; /* On first open, do netif open, mount, etc. */ if (netdev_opens == 0) { /* Find network interface. */ if (netdev_sock < 0) { netdev_sock = netif_open(devname); if (netdev_sock < 0) { printf("net_open: netif_open() failed\n"); return (ENXIO); } if (debug) printf("net_open: netif_open() succeeded\n"); } if (rootip.s_addr == 0) { /* Get root IP address, and path, etc. */ error = net_getparams(netdev_sock); if (error) { /* getparams makes its own noise */ netif_close(netdev_sock); netdev_sock = -1; return (error); } } } netdev_opens++; f->f_devdata = &netdev_sock; return (error); }
int net_close(struct promdata *pd) { /* On last close, do netif close, etc. */ if (open_count > 0) if (--open_count == 0) netif_close(netdev_sock); }
int net_close(struct open_file *f) { /* On last close, do netif close, etc. */ if (open_count > 0) if (--open_count == 0) netif_close(netdev_sock); f->f_devdata = NULL; }
int net_close(struct open_file *f) { int sock; sock = *((int *) f->f_devdata); netif_close(sock); f->f_devdata = NULL; return 0; }
/* * Called by devopen after it sets f->f_dev to our devsw entry. * This opens the low-level device and sets f->f_devdata. * This is declared with variable arguments... */ int net_open(struct open_file *f, ...) { va_list ap; char *devname; /* Device part of file name (or NULL). */ int error = 0; va_start(ap, f); devname = va_arg(ap, char*); va_end(ap); #ifdef NETIF_DEBUG if (debug) printf("net_open: %s\n", devname); #endif /* On first open, do netif open, mount, etc. */ if (netdev_opens == 0) { /* Find network interface. */ if (netdev_sock < 0) { netdev_sock = netif_open(devname); if (netdev_sock < 0) { printf("net_open: netif_open() failed\n"); return (ENXIO); } if (debug) printf("net_open: netif_open() succeeded\n"); } if (rootip.s_addr == 0) { /* Get root IP address, and path, etc. */ error = net_getparams(netdev_sock); if (error) { /* getparams makes its own noise */ goto fail; } /* Get the NFS file handle (mountd). */ error = nfs_mount(netdev_sock, rootip, rootpath); if (error) { error = errno; printf("net_open: NFS mount error=%d\n", error); rootip.s_addr = 0; fail: netif_close(netdev_sock); netdev_sock = -1; return (error); } if (debug) printf("net_open: NFS mount succeeded\n"); } } netdev_opens++; f->f_devdata = nfs_root_node; return (error); }
int net_close(struct of_dev *op) { /* * On last close, do netif close, etc. */ if (open_count > 0) if (--open_count == 0) { netif_close(netdev_sock); netdev_sock = -1; } }
static void net_cleanup(void) { if (netdev_sock >= 0) { #ifdef NETIF_DEBUG if (debug) printf("net_cleanup: calling netif_close()\n"); #endif rootip.s_addr = 0; free(netdev_name); netif_close(netdev_sock); netdev_sock = -1; } }
int net_open(struct open_file *f, ...) { char *fname; char **file; struct iodesc *s; va_list ap; va_start(ap, f); fname = va_arg(ap, char *); file = va_arg(ap, char **); va_end(ap); f->f_devdata = &netdev_sock; netdev_sock = netif_open(NULL); bootfile[0] = '\0'; if (bootopts.b_flags & B_F_USE_BOOTP) { s = socktodesc(netdev_sock); bootp(netdev_sock); if (fname[0] != '\0') strlcpy(bootfile, fname, sizeof bootfile); } else { s = socktodesc(netdev_sock); servip = s->destip = bootopts.b_remote_ip; myip = s->myip = bootopts.b_local_ip; netmask = bootopts.b_netmask; gateip = bootopts.b_gate_ip; if (fname[0] == '\0') { printf("no boot filename\n"); netif_close(netdev_sock); return EIO; } strlcpy(bootfile, fname, sizeof bootfile); } *file = bootfile; return 0; }
/* * Called by devopen after it sets f->f_dev to our devsw entry. * This opens the low-level device and sets f->f_devdata. * This is declared with variable arguments... */ static int net_open(struct open_file *f, ...) { char temp[FNAME_SIZE]; struct iodesc *d; va_list args; char *devname; /* Device part of file name (or NULL). */ int error = 0; va_start(args, f); devname = va_arg(args, char*); va_end(args); #ifdef NETIF_OPEN_CLOSE_ONCE /* Before opening another interface, close the previous one first. */ if (netdev_sock >= 0 && strcmp(devname, netdev_name) != 0) net_cleanup(); #endif /* On first open, do netif open, mount, etc. */ if (netdev_opens == 0) { /* Find network interface. */ if (netdev_sock < 0) { netdev_sock = netif_open(devname); if (netdev_sock < 0) { printf("net_open: netif_open() failed\n"); return (ENXIO); } netdev_name = strdup(devname); #ifdef NETIF_DEBUG if (debug) printf("net_open: netif_open() succeeded\n"); #endif } /* * If network params were not set by netif_open(), try to get * them via bootp, rarp, etc. */ if (rootip.s_addr == 0) { /* Get root IP address, and path, etc. */ error = net_getparams(netdev_sock); if (error) { /* getparams makes its own noise */ free(netdev_name); netif_close(netdev_sock); netdev_sock = -1; return (error); } } /* * Set the variables required by the kernel's nfs_diskless * mechanism. This is the minimum set of variables required to * mount a root filesystem without needing to obtain additional * info from bootp or other sources. */ d = socktodesc(netdev_sock); sprintf(temp, "%6D", d->myea, ":"); setenv("boot.netif.hwaddr", temp, 1); setenv("boot.netif.ip", inet_ntoa(myip), 1); setenv("boot.netif.netmask", intoa(netmask), 1); setenv("boot.netif.gateway", inet_ntoa(gateip), 1); setenv("boot.nfsroot.server", inet_ntoa(rootip), 1); setenv("boot.nfsroot.path", rootpath, 1); } netdev_opens++; f->f_devdata = &netdev_sock; return (error); }
/* * Called by devopen after it sets f->f_dev to our devsw entry. * This opens the low-level device and sets f->f_devdata. */ int net_open(struct open_file *f, ...) { int error = 0; #ifdef NET_DEBUG if (netdev_sock != -1) panic("net_open"); #endif /* Find network interface. */ if ((netdev_sock = netif_open()) < 0) return (ENXIO); #ifdef SUPPORT_BOOTP printf("configure network...trying bootp\n"); /* Get boot info using BOOTP way. (RFC951, RFC1048) */ bootp(netdev_sock); #endif if (myip.s_addr != INADDR_ANY) { /* got bootp reply or * manually set */ #ifdef TFTP_HACK int num, i; /* XXX (some) tftp servers don't like leading "/" */ for (num = 0; bootfile[num] == '/'; num++); for (i = 0; (bootfile[i] = bootfile[i + num]) != 0; i++); #endif printf("boot: client IP address: %s\n", inet_ntoa(myip)); printf("boot: client name: %s\n", hostname); } else { #ifdef SUPPORT_RARP /* * no answer, Get boot info using RARP and Sun * bootparams. */ printf("configure network...trying rarp\n"); /* Get our IP address. (rarp.c) */ if (rarp_getipaddress(netdev_sock)) { error = EIO; goto bad; } printf("boot: client IP address: %s\n", inet_ntoa(myip)); #ifdef SUPPORT_BOOTPARAM /* Get our hostname, server IP address. */ if (!bp_whoami(netdev_sock)) { printf("boot: client name: %s\n", hostname); /* Get the root pathname. */ bp_getfile(netdev_sock, "root", &rootip, rootpath); } #else /* * else fallback: use rarp server address */ #endif #else /* no SUPPORT_RARP */ error = EIO; goto bad; #endif } printf("boot: server: %s, rootpath: %s, bootfile: %s\n", inet_ntoa(rootip), rootpath, bootfile); f->f_devdata = &netdev_sock; return (error); bad: printf("net_open failed\n"); netif_close(netdev_sock); return (error); }