/* * 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; }
/* * 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); }
/* * 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); }
/* * 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 netopen(struct open_file *f, char *devname) { int error = 0; /* On first open, do netif open, mount, etc. */ if (open_count == 0) { /* Find network interface. */ if ((netdev_sock = netif_open(devname)) < 0) return (error=ENXIO); if ((error = netmountroot(f, devname)) != 0) return (error); } open_count++; f->f_devdata = nfs_root_node; 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 promdata *pd) { int error = 0; /* On first open, do netif open, mount, etc. */ if (open_count == 0) { /* Find network interface. */ if ((netdev_sock = netif_open(pd)) < 0) { error = errno; goto bad; } if ((error = net_mountroot()) != 0) goto bad; } open_count++; bad: return (error); }
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); }
int mrpw_init_protocols(void) { uint16_t ether_types[4]; WSADATA wsa_data; int rc; mrpd_port = MRPD_PORT_DEFAULT; mmrp_enable = 1; mvrp_enable = 1; msrp_enable = 1; periodic_enable = 1; logging_enable = 1; WSAStartup(MAKEWORD(1, 1), &wsa_data); /* open our network interface and set the capture ethertype to MRP types */ net_if = netif_open(TIME_PERIOD_25_MILLISECONDS); // time out is 25ms if (!net_if) { fprintf(stderr, "ERROR - opening network interface\n"); return -1; } ether_types[0] = MVRP_ETYPE; ether_types[1] = MMRP_ETYPE; ether_types[2] = MSRP_ETYPE; if (netif_set_capture_ethertype(net_if, ether_types, 3)) { fprintf(stderr, "ERROR - setting netif capture ethertype\n"); return -1; } rc = mrp_init(); if (rc) goto out; rc = init_local_ctl(); if (rc) goto out; if (mmrp_enable) { rc = mmrp_init(mmrp_enable); if (rc) goto out; } if (mvrp_enable) { rc = mvrp_init(mvrp_enable); if (rc) goto out; } if (msrp_enable) { rc = msrp_init(msrp_enable); if (rc) goto out; } rc = init_timers(); if (rc) goto out; return 0; out: return -1; }
int main(int argc, char *argv[]) { uint16_t ether_types[4]; WSADATA wsa_data; int rc; mrpd_port = MRPD_PORT_DEFAULT; mmrp_enable = 1; mvrp_enable = 1; msrp_enable = 1; periodic_enable = 1; logging_enable = 1; WSAStartup(MAKEWORD(1, 1), &wsa_data); /* open our network interface and set the capture ethertype to MRP types */ net_if = netif_open(TIME_PERIOD_25_MILLISECONDS); // time out is 25ms if (!net_if) { fprintf(stderr, "ERROR - opening network interface\n"); exit(-1); } ether_types[0] = MVRP_ETYPE; ether_types[1] = MMRP_ETYPE; ether_types[2] = MSRP_ETYPE; if (netif_set_capture_ethertype(net_if, ether_types, 3)) { fprintf(stderr, "ERROR - setting netif capture ethertype\n"); exit(-1); } rc = mrp_init(); if (rc) goto out; rc = init_local_ctl(); if (rc) goto out; if (mmrp_enable) { rc = mmrp_init(mmrp_enable); if (rc) goto out; } if (mvrp_enable) { rc = mvrp_init(mvrp_enable); if (rc) goto out; } if (msrp_enable) { rc = msrp_init(msrp_enable); if (rc) goto out; } rc = init_timers(); if (rc) goto out; process_events(); out: if (rc) printf("Error starting. Run as sudo?\n"); WSACleanup(); return rc; }
/* * 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); }