From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1XzOoG-0007wj-Us for mharc-grub-devel@gnu.org; Fri, 12 Dec 2014 06:55:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzOo6-0007vo-JK for grub-devel@gnu.org; Fri, 12 Dec 2014 06:54:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XzOnx-00021X-4a for grub-devel@gnu.org; Fri, 12 Dec 2014 06:54:50 -0500 Received: from mail-lb0-x22c.google.com ([2a00:1450:4010:c04::22c]:38872) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XzOnw-00021D-N1 for grub-devel@gnu.org; Fri, 12 Dec 2014 06:54:41 -0500 Received: by mail-lb0-f172.google.com with SMTP id u10so5813093lbd.17 for ; Fri, 12 Dec 2014 03:54:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=Jx7Qafmc78yvsEs6dwJYuHehRjQm7jWRk2H0JuIVGiY=; b=NJr0M4xJx0r4N55Qt/iHvSVx3SVk0Q1na3ShoiDwdhp0+E2SmD4BFFo7nTgGpgBPaD DPjgRrJfj6Wl5d3rGh3OpIaVJgKqKy2TlHIV7wdNB14UD6kebquvdmONIPoidnFlXZfW NQzsYdB5WHZ+gPAbNISuGdLN/7ShypZG0/1Aa8oeOLXtdJw5Qumgao+Sasq7+jpn6Jok wS3P+PJaff3GlWsL+V1HR/ZNmWby9PPln1UQjZVL5t4luJaG3JbwkyBcmzaqQZzB4aXv NqSWs0FA+426UPPVDrk2ouU/IYxo0CkHtNPUkrTRLRPIek5DH5j7NW+AnrcvfbltETfu vWLg== X-Received: by 10.152.22.67 with SMTP id b3mr11473431laf.82.1418385279525; Fri, 12 Dec 2014 03:54:39 -0800 (PST) Received: from opensuse.site (ppp91-76-15-25.pppoe.mtu-net.ru. [91.76.15.25]) by mx.google.com with ESMTPSA id r3sm332532lal.37.2014.12.12.03.54.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Dec 2014 03:54:38 -0800 (PST) Date: Fri, 12 Dec 2014 14:54:36 +0300 From: Andrei Borzenkov To: Victor Lowther Subject: Re: [PATCH] Allow nonstandard ports when specifying network protocols. Message-ID: <20141212145436.198c0324@opensuse.site> In-Reply-To: References: X-Mailer: Claws Mail 3.11.0 (GTK+ 2.24.25; x86_64-suse-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22c Cc: grub-devel@gnu.org X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Dec 2014 11:54:59 -0000 =D0=92 Thu, 11 Dec 2014 13:58:04 -0600 Victor Lowther =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > There are usecases for running TFTP and HTTP on nonstandard ports. This > patch allows you to specify nonstandard ports with the following syntax: >=20 > set root=3D(http,$net_default_server,portno) > or > set root=3D(http,,portno) >=20 > It also allows an initial : where a , should be for pxe: backwards compat= ibility > --- > ChangeLog | 11 ++++ > grub-core/net/http.c | 3 +- > grub-core/net/net.c | 152 +++++++++++++++++++++++++--------------------= ------ > grub-core/net/tftp.c | 3 +- > include/grub/net.h | 2 + > 5 files changed, 90 insertions(+), 81 deletions(-) >=20 > diff --git a/ChangeLog b/ChangeLog > index c38917b..4f08e29 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,3 +1,14 @@ > +2014-12-11 Victor Lowther > + > + * grub-core/net/net.c: Allow grub_net_open_real to handle parsing > + an optional port number for tftp and http network protocols. > + * grub-core/net/http.c: Expose default port for HTTP in the > + grub_http_protocol struct. > + * grub-core/net/tftp.c: Expose default port for TFTP in the > + grub_tftp_protocol struct. > + * includegrub/net.h: Extend grub_net_app_protocol and grub_net_t > + to include the port number. > + > 2014-12-09 Andrei Borzenkov >=20 > * grub-core/term/serial.c (grub_cmd_serial): Fix --rtscts > diff --git a/grub-core/net/http.c b/grub-core/net/http.c > index 4684f8b..2562d5e 100644 > --- a/grub-core/net/http.c > +++ b/grub-core/net/http.c > @@ -392,7 +392,7 @@ http_establish (struct grub_file *file, grub_off_t > offset, int initial) > grub_memcpy (ptr, "\r\n", 2); >=20 > data->sock =3D grub_net_tcp_open (file->device->net->server, > - HTTP_PORT, http_receive, > + file->device->net->port, http_receive, > http_err, http_err, > file); > if (!data->sock) > @@ -545,6 +545,7 @@ http_packets_pulled (struct grub_file *file) > static struct grub_net_app_protocol grub_http_protocol =3D > { > .name =3D "http", > + .port =3D HTTP_PORT, > .open =3D http_open, > .close =3D http_close, > .seek =3D http_seek, > diff --git a/grub-core/net/net.c b/grub-core/net/net.c > index 21a4e94..5dfad02 100644 > --- a/grub-core/net/net.c > +++ b/grub-core/net/net.c > @@ -1271,98 +1271,92 @@ static grub_net_t > grub_net_open_real (const char *name) > { > grub_net_app_level_t proto; > - const char *protname, *server; > + char *server; > + const char *protname, *work, *comma; > grub_size_t protnamelen; > - int try; > - > - if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) =3D=3D 0) > + grub_uint16_t port; > + grub_net_t ret; > + port =3D 0; > + server =3D NULL; > + work =3D name; > + protname =3D NULL; > + > + if (grub_strncmp (work, "pxe", sizeof ("pxe") - 1) =3D=3D 0) > { > protname =3D "tftp"; > - protnamelen =3D sizeof ("tftp") - 1; > - server =3D name + sizeof ("pxe:") - 1; > + work +=3D (sizeof ("pxe") - 1); > } > - else if (grub_strcmp (name, "pxe") =3D=3D 0) > + else if (grub_strncmp (work, "tftp", sizeof("tftp") - 1) =3D=3D 0) No, that's wrong. grub_net_open_real should not have any hardcoded dependencies on supported protocols. "pxe" and "pxe:" are just for compatibility with legacy configuration. Any new code should rely on protocol modules registration. Do not overcomplicate things. You just need to add additional server name parsing after protocol was extracted. And please also update documentation to indicate new syntax.