svn commit: r318987 - head/sys/boot/common
Baptiste Daroussin
bapt at FreeBSD.org
Sat May 27 12:06:54 UTC 2017
Author: bapt
Date: Sat May 27 12:06:52 2017
New Revision: 318987
URL: https://svnweb.freebsd.org/changeset/base/318987
Log:
Support URI scheme for root-path in netbooting
Rather that previous attempts to add tftpfs support at the same time as NFS
support. This time decide on a proper URI parser rather than hacks.
root-path can now be define the following way:
For tftpfs:
tftp://ip/path
tftp:/path (this one will consider the tftp server is the same as the one where
the pxeboot file was fetched from)
For nfs:
nfs:/path
nfs://ip/path
The historical
ip:/path
/path
are kept on NFS
Reviewed by: tsoom, rgrimes
Differential Revision: https://reviews.freebsd.org/D10947
Modified:
head/sys/boot/common/dev_net.c
Modified: head/sys/boot/common/dev_net.c
==============================================================================
--- head/sys/boot/common/dev_net.c Sat May 27 11:41:54 2017 (r318986)
+++ head/sys/boot/common/dev_net.c Sat May 27 12:06:52 2017 (r318987)
@@ -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);
More information about the svn-src-head
mailing list