net: Read bracketed IPv6 addrs and port numbers

Allow specifying port numbers for http and tftp paths and allow IPv6
addresses to be recognized with brackets around them, which is required
to specify a port number.

Co-authored-by: Aaron Miller <aaronmiller@fb.com>
Signed-off-by: Aaron Miller <aaronmiller@fb.com>
Co-authored-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
authored and Daniel Kiper committed 2023-05-16 17:26:28 +02:00
1 parent 52061b2cf4
commit 26cfaa8a90
5 files changed
+111 -10

No files matched your search

+14 -4
View File
@@ -318,12 +318,14 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
int i;
struct grub_net_buff *nb;
grub_err_t err;
char *server = file->device->net->server;
int port = file->device->net->port;
nb = grub_netbuff_alloc (GRUB_NET_TCP_RESERVE_SIZE
+ sizeof ("GET ") - 1
+ grub_strlen (data->filename)
+ sizeof (" HTTP/1.1\r\nHost: ") - 1
+ grub_strlen (file->device->net->server)
+ grub_strlen (server) + sizeof (":XXXXXXXXXX")
+ sizeof ("\r\nUser-Agent: " PACKAGE_STRING
"\r\n") - 1
+ sizeof ("Range: bytes=XXXXXXXXXXXXXXXXXXXX"
@@ -362,7 +364,7 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
sizeof (" HTTP/1.1\r\nHost: ") - 1);
ptr = nb->tail;
err = grub_netbuff_put (nb, grub_strlen (file->device->net->server));
err = grub_netbuff_put (nb, grub_strlen (server));
if (err)
{
grub_netbuff_free (nb);
@@ -371,6 +373,12 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
grub_memcpy (ptr, file->device->net->server,
grub_strlen (file->device->net->server));
if (port)
{
ptr = nb->tail;
grub_snprintf ((char *) ptr, sizeof (":XXXXXXXXXX"), ":%d", port);
}
ptr = nb->tail;
err = grub_netbuff_put (nb,
sizeof ("\r\nUser-Agent: " PACKAGE_STRING "\r\n")
@@ -396,8 +404,10 @@ http_establish (struct grub_file *file, grub_off_t offset, int initial)
grub_netbuff_put (nb, 2);
grub_memcpy (ptr, "\r\n", 2);
data->sock = grub_net_tcp_open (file->device->net->server,
HTTP_PORT, http_receive,
grub_dprintf ("http", "opening path %s on host %s TCP port %d\n",
data->filename, server, port ? port : HTTP_PORT);
data->sock = grub_net_tcp_open (server,
port ? port : HTTP_PORT, http_receive,
http_err, NULL,
file);
if (!data->sock)