summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste Daroussin <bapt@FreeBSD.org>2017-05-27 12:06:52 +0000
committerBaptiste Daroussin <bapt@FreeBSD.org>2017-05-27 12:06:52 +0000
commit404f5b6b297cebe602c2f48c9b84289df7db7cf1 (patch)
tree3f03a26678fbe0d4086b243ae8a34338d39c6417
parentb2390b67da76aeccd2379d5c673fd0fa0fbe405e (diff)
Notes
-rw-r--r--sys/boot/common/dev_net.c62
1 files changed, 52 insertions, 10 deletions
diff --git a/sys/boot/common/dev_net.c b/sys/boot/common/dev_net.c
index b209185f0709b..f4136b0f5bb4a 100644
--- a/sys/boot/common/dev_net.c
+++ b/sys/boot/common/dev_net.c
@@ -97,6 +97,14 @@ struct devsw netdev = {
net_cleanup
};
+static struct uri_scheme {
+ const char *scheme;
+ int proto;
+} uri_schemes[] = {
+ { "tftp:/", NET_TFTP },
+ { "nfs:/", NET_NFS },
+};
+
static int
net_init(void)
{
@@ -334,11 +342,8 @@ net_getparams(int sock)
return (EIO);
}
exit:
- netproto = NET_TFTP;
- if ((rootaddr = net_parse_rootpath()) != INADDR_NONE) {
- netproto = NET_NFS;
+ if ((rootaddr = net_parse_rootpath()) != INADDR_NONE)
rootip.s_addr = rootaddr;
- }
#ifdef NETIF_DEBUG
if (debug) {
@@ -387,14 +392,51 @@ net_print(int verbose)
uint32_t
net_parse_rootpath()
{
- n_long addr = INADDR_NONE;
- char *ptr;
+ n_long addr = htonl(INADDR_NONE);
+ size_t i;
+ char ip[FNAME_SIZE];
+ char *ptr, *val;
+
+ netproto = NET_NONE;
+
+ for (i = 0; i < nitems(uri_schemes); i++) {
+ if (strncmp(rootpath, uri_schemes[i].scheme,
+ strlen(uri_schemes[i].scheme)) != 0)
+ continue;
+ netproto = uri_schemes[i].proto;
+ break;
+ }
ptr = rootpath;
- (void)strsep(&ptr, ":");
- if (ptr != NULL) {
- addr = inet_addr(rootpath);
- bcopy(ptr, rootpath, strlen(ptr) + 1);
+ /* Fallback for compatibility mode */
+ if (netproto == NET_NONE) {
+ netproto = NET_NFS;
+ (void)strsep(&ptr, ":");
+ if (ptr != NULL) {
+ addr = inet_addr(rootpath);
+ bcopy(ptr, rootpath, strlen(ptr) + 1);
+ }
+ } else {
+ ptr += strlen(uri_schemes[i].scheme);
+ 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
+ */
+ val = strchr(ptr, '/');
+ if (val != NULL) {
+ snprintf(ip, sizeof(ip), "%.*s",
+ (int)((uintptr_t)val - (uintptr_t)ptr), ptr);
+ printf("%s\n", ip);
+ addr = inet_addr(ip);
+ bcopy(val, rootpath, strlen(val) + 1);
+ }
+ } else {
+ ptr--;
+ bcopy(ptr, rootpath, strlen(ptr) + 1);
+ }
}
return (addr);