From owner-svn-src-head@freebsd.org Sat May 27 12:06:54 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 2100FD84C2B; Sat, 27 May 2017 12:06:54 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D82281925; Sat, 27 May 2017 12:06:53 +0000 (UTC) (envelope-from bapt@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v4RC6qZR084339; Sat, 27 May 2017 12:06:52 GMT (envelope-from bapt@FreeBSD.org) Received: (from bapt@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v4RC6qCs084338; Sat, 27 May 2017 12:06:52 GMT (envelope-from bapt@FreeBSD.org) Message-Id: <201705271206.v4RC6qCs084338@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bapt set sender to bapt@FreeBSD.org using -f From: Baptiste Daroussin Date: Sat, 27 May 2017 12:06:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r318987 - head/sys/boot/common X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 May 2017 12:06:54 -0000 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 ://, 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);