aboutsummaryrefslogtreecommitdiff
path: root/stand/common
diff options
context:
space:
mode:
Diffstat (limited to 'stand/common')
-rw-r--r--stand/common/dev_net.c41
-rw-r--r--stand/common/misc.c13
2 files changed, 42 insertions, 12 deletions
diff --git a/stand/common/dev_net.c b/stand/common/dev_net.c
index 964fa514cac5..d1c48d40691a 100644
--- a/stand/common/dev_net.c
+++ b/stand/common/dev_net.c
@@ -66,6 +66,10 @@
#include "dev_net.h"
#include "bootstrap.h"
+#ifndef NETPROTO_DEFAULT
+# define NETPROTO_DEFAULT NET_NFS
+#endif
+
static char *netdev_name;
static int netdev_sock = -1;
static int netdev_opens;
@@ -182,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;
@@ -193,7 +198,7 @@ net_close(struct open_file *f)
{
struct devdesc *dev;
- DEBUG_PRINTF(1,("%s: opens=%d\n", __func__, netdev_opens));
+ DEBUG_PRINTF(2,("%s: opens=%d\n", __func__, netdev_opens));
dev = f->f_devdata;
dev->d_opendata = NULL;
@@ -303,7 +308,7 @@ 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;
DEBUG_PRINTF(1,("%s: proto: %d\n", __func__, netproto));
@@ -344,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
@@ -363,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;
@@ -381,7 +392,7 @@ 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);
@@ -394,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 {
@@ -411,6 +427,7 @@ net_parse_rootpath(void)
bcopy(ptr, rootpath, strlen(ptr) + 1);
}
}
-
+ if (addr == 0)
+ addr = htonl(INADDR_NONE);
return (addr);
}
diff --git a/stand/common/misc.c b/stand/common/misc.c
index 402213100951..a7c46ad2e74c 100644
--- a/stand/common/misc.c
+++ b/stand/common/misc.c
@@ -220,3 +220,16 @@ set_currdev(const char *devname)
env_setenv("loaddev", EV_VOLATILE | EV_NOHOOK, devname, env_noset,
env_nounset);
}
+
+#ifndef LOADER_NET_SUPPORT
+/*
+ * This api is normally provided by dev_net.c
+ * This stub keeps libsa happy when LOADER_NET_SUPPORT
+ * is not enabled.
+ */
+bool
+is_tftp(void)
+{
+ return false;
+}
+#endif