diff options
Diffstat (limited to 'stand/common/dev_net.c')
| -rw-r--r-- | stand/common/dev_net.c | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/stand/common/dev_net.c b/stand/common/dev_net.c index 3cd78c5346ac..d1c48d40691a 100644 --- a/stand/common/dev_net.c +++ b/stand/common/dev_net.c @@ -47,9 +47,10 @@ * for use by the NFS open code (NFS/lookup). */ -#include <machine/stdarg.h> #include <sys/param.h> #include <sys/socket.h> +#include <sys/stdarg.h> + #include <net/if.h> #include <netinet/in.h> #include <netinet/in_systm.h> @@ -65,8 +66,8 @@ #include "dev_net.h" #include "bootstrap.h" -#ifdef NETIF_DEBUG -int debug = 0; +#ifndef NETPROTO_DEFAULT +# define NETPROTO_DEFAULT NET_NFS #endif static char *netdev_name; @@ -142,11 +143,8 @@ net_open(struct open_file *f, ...) return (ENXIO); } netdev_name = strdup(devname); -#ifdef NETIF_DEBUG - if (debug) - printf("%s: netif_open() succeeded\n", - __func__); -#endif + DEBUG_PRINTF(1,("%s: netif_open() succeeded %#x\n", + __func__, rootip.s_addr)); } /* * If network params were not set by netif_open(), try to get @@ -188,6 +186,7 @@ net_open(struct open_file *f, ...) setenv("boot.netif.mtu", mtu, 1); } + DEBUG_PRINTF(1,("%s: netproto=%d\n", __func__, netproto)); } netdev_opens++; dev->d_opendata = &netdev_sock; @@ -199,10 +198,7 @@ net_close(struct open_file *f) { struct devdesc *dev; -#ifdef NETIF_DEBUG - if (debug) - printf("%s: opens=%d\n", __func__, netdev_opens); -#endif + DEBUG_PRINTF(2,("%s: opens=%d\n", __func__, netdev_opens)); dev = f->f_devdata; dev->d_opendata = NULL; @@ -215,10 +211,7 @@ net_cleanup(void) { if (netdev_sock >= 0) { -#ifdef NETIF_DEBUG - if (debug) - printf("%s: calling netif_close()\n", __func__); -#endif + DEBUG_PRINTF(1,("%s: calling netif_close()\n", __func__)); rootip.s_addr = 0; free(netdev_name); netif_close(netdev_sock); @@ -270,10 +263,7 @@ net_getparams(int sock) bootp(sock); if (myip.s_addr != 0) goto exit; -#ifdef NETIF_DEBUG - if (debug) - printf("%s: BOOTP failed, trying RARP/RPC...\n", __func__); -#endif + DEBUG_PRINTF(1,("%s: BOOTP failed, trying RARP/RPC...\n", __func__)); #endif /* @@ -291,10 +281,7 @@ net_getparams(int sock) printf("%s: bootparam/whoami RPC failed\n", __func__); return (EIO); } -#ifdef NETIF_DEBUG - if (debug) - printf("%s: client name: %s\n", __func__, hostname); -#endif + DEBUG_PRINTF(1,("%s: client name: %s\n", __func__, hostname)); /* * Ignore the gateway from whoami (unreliable). @@ -308,16 +295,12 @@ net_getparams(int sock) } if (smask) { netmask = smask; -#ifdef NETIF_DEBUG - if (debug) - printf("%s: subnet mask: %s\n", __func__, - intoa(netmask)); -#endif + DEBUG_PRINTF(1,("%s: subnet mask: %s\n", __func__, + intoa(netmask))); } -#ifdef NETIF_DEBUG - if (gateip.s_addr && debug) - printf("%s: net gateway: %s\n", __func__, inet_ntoa(gateip)); -#endif + if (gateip.s_addr) + DEBUG_PRINTF(1,("%s: net gateway: %s\n", __func__, + inet_ntoa(gateip))); /* Get the root server and pathname. */ if (bp_getfile(sock, "root", &rootip, rootpath)) { @@ -325,15 +308,13 @@ net_getparams(int sock) return (EIO); } exit: - if ((rootaddr = net_parse_rootpath()) != INADDR_NONE) + if ((rootaddr = net_parse_rootpath()) != htonl(INADDR_NONE)) rootip.s_addr = rootaddr; -#ifdef NETIF_DEBUG - if (debug) { - printf("%s: server addr: %s\n", __func__, inet_ntoa(rootip)); - printf("%s: server path: %s\n", __func__, rootpath); - } -#endif + DEBUG_PRINTF(1,("%s: proto: %d\n", __func__, netproto)); + DEBUG_PRINTF(1,("%s: server addr: %s\n", __func__, inet_ntoa(rootip))); + DEBUG_PRINTF(1,("%s: server port: %d\n", __func__, rootport)); + DEBUG_PRINTF(1,("%s: server path: %s\n", __func__, rootpath)); return (0); } @@ -368,11 +349,17 @@ net_print(int verbose) return (ret); } +bool +is_tftp(void) +{ + return (netproto == NET_TFTP); +} + /* * Parses the rootpath if present * * The rootpath format can be in the form - * <scheme>://ip/path + * <scheme>://ip[:port]/path * <scheme>:/path * * For compatibility with previous behaviour it also accepts as an NFS scheme @@ -387,10 +374,10 @@ net_print(int verbose) uint32_t net_parse_rootpath(void) { - n_long addr = htonl(INADDR_NONE); + n_long addr = 0; size_t i; char ip[FNAME_SIZE]; - char *ptr, *val; + char *ptr, *portp, *val; netproto = NET_NONE; @@ -405,10 +392,12 @@ net_parse_rootpath(void) ptr = rootpath; /* Fallback for compatibility mode */ if (netproto == NET_NONE) { - netproto = NET_NFS; + netproto = NETPROTO_DEFAULT; (void)strsep(&ptr, ":"); if (ptr != NULL) { addr = inet_addr(rootpath); + DEBUG_PRINTF(1,("rootpath=%s addr=%#x\n", + rootpath, addr)); bcopy(ptr, rootpath, strlen(ptr) + 1); } } else { @@ -416,16 +405,21 @@ net_parse_rootpath(void) if (*ptr == '/') { /* we are in the form <scheme>://, we do expect an ip */ ptr++; - /* - * XXX when http will be there we will need to check for - * a port, but right now we do not need it yet - */ + portp = val = strchr(ptr, ':'); + if (val != NULL) { + val++; + rootport = strtol(val, NULL, 10); + } val = strchr(ptr, '/'); if (val != NULL) { + if (portp == NULL) + portp = val; snprintf(ip, sizeof(ip), "%.*s", - (int)((uintptr_t)val - (uintptr_t)ptr), + (int)(portp - ptr), ptr); addr = inet_addr(ip); + DEBUG_PRINTF(1,("ip=%s addr=%#x\n", + ip, addr)); bcopy(val, rootpath, strlen(val) + 1); } } else { @@ -433,6 +427,7 @@ net_parse_rootpath(void) bcopy(ptr, rootpath, strlen(ptr) + 1); } } - + if (addr == 0) + addr = htonl(INADDR_NONE); return (addr); } |
