[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 3/9] Add default port in grub_net_app_protocol
From: |
Keng-Yu Lin |
Subject: |
[PATCH v2 3/9] Add default port in grub_net_app_protocol |
Date: |
Fri, 23 Dec 2016 16:54:06 +0800 |
In this patch, it introduces port 80 as HTTP's default port,
and port 69 as TFTP's default port.
Signed-off-by: Keng-Yu Lin <address@hidden>
---
grub-core/net/http.c | 22 ++++++----------------
grub-core/net/net.c | 7 ++++++-
grub-core/net/tftp.c | 5 ++++-
include/grub/net.h | 1 +
4 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/grub-core/net/http.c b/grub-core/net/http.c
index f182d7b..08f7580 100644
--- a/grub-core/net/http.c
+++ b/grub-core/net/http.c
@@ -29,11 +29,6 @@
GRUB_MOD_LICENSE ("GPLv3+");
-enum
- {
- HTTP_PORT = 80
- };
-
typedef struct http_data
{
@@ -319,7 +314,7 @@ http_establish (struct grub_file *file, grub_off_t offset,
int initial)
+ sizeof ("GET ") - 1
+ grub_strlen (data->filename)
+ sizeof (" HTTP/1.1\r\nHost: ") - 1
- + grub_strlen (server) + sizeof (":XXXXXXXXXX")
+ + grub_strlen (server) + sizeof (":XXXXX") /*
0~65535 */
+ sizeof ("\r\nUser-Agent: " PACKAGE_STRING
"\r\n") - 1
+ sizeof ("Range: bytes=XXXXXXXXXXXXXXXXXXXX"
@@ -367,14 +362,8 @@ 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;
+ grub_snprintf ((char *) ptr, sizeof (":XXXXX"), ":%d", port);
ptr = nb->tail;
err = grub_netbuff_put (nb,
@@ -402,9 +391,9 @@ http_establish (struct grub_file *file, grub_off_t offset,
int initial)
grub_memcpy (ptr, "\r\n", 2);
grub_dprintf ("http", "opening path %s on host %s TCP port %d\n",
- data->filename, server, port ? port : HTTP_PORT);
+ data->filename, server, port );
data->sock = grub_net_tcp_open (server,
- port ? port : HTTP_PORT, http_receive,
+ port, http_receive,
http_err, http_err,
file);
if (!data->sock)
@@ -558,6 +547,7 @@ http_packets_pulled (struct grub_file *file)
static struct grub_net_app_protocol grub_http_protocol =
{
.name = "http",
+ .default_port = 80,
.open = http_open,
.close = http_close,
.seek = http_seek,
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
index 5cc0d2f..2b329ee 100644
--- a/grub-core/net/net.c
+++ b/grub-core/net/net.c
@@ -1272,7 +1272,7 @@ grub_net_open_real (const char *name)
char *host;
grub_size_t protnamelen;
int try;
- int port = 0;
+ int port = -1;
if (grub_strncmp (name, "pxe:", sizeof ("pxe:") - 1) == 0)
{
@@ -1341,6 +1341,10 @@ grub_net_open_real (const char *name)
{
if (grub_strchr (port_start + 1, ':'))
{
+ /* If the second ':' is found and there is no '[' nor ']',
+ this indicates this is an ipv6 address without brackets.
+ Bracket the address here.
+ */
int iplen = grub_strlen (server);
/* bracket bare ipv6 addrs */
host = grub_malloc (iplen + 3);
@@ -1390,6 +1394,7 @@ grub_net_open_real (const char *name)
return NULL;
}
ret->protocol = proto;
+ if (port == -1) port = proto->default_port;
ret->port = port;
ret->server = host;
ret->fs = &grub_net_fs;
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
index a0817a0..658921b 100644
--- a/grub-core/net/tftp.c
+++ b/grub-core/net/tftp.c
@@ -391,8 +391,10 @@ tftp_open (struct grub_file *file, const char *filename)
return err;
}
+ grub_dprintf ("tftp","opening host %s UDP port %d\n",
+ file->device->net->server, port);
data->sock = grub_net_udp_open (addr,
- port ? port : TFTP_SERVER_PORT, tftp_receive,
+ port, tftp_receive,
file);
if (!data->sock)
{
@@ -492,6 +494,7 @@ tftp_packets_pulled (struct grub_file *file)
static struct grub_net_app_protocol grub_tftp_protocol =
{
.name = "tftp",
+ .default_port = 69,
.open = tftp_open,
.close = tftp_close,
.packets_pulled = tftp_packets_pulled
diff --git a/include/grub/net.h b/include/grub/net.h
index ccc169c..d13ee61 100644
--- a/include/grub/net.h
+++ b/include/grub/net.h
@@ -257,6 +257,7 @@ struct grub_net_app_protocol
struct grub_net_app_protocol *next;
struct grub_net_app_protocol **prev;
const char *name;
+ int default_port;
grub_err_t (*dir) (grub_device_t device, const char *path,
int (*hook) (const char *filename,
const struct grub_dirhook_info *info));
--
2.7.4
- [PATCH v2 0/9] Add UEFI HTTP Boot support for IPv4 and IPv6, Keng-Yu Lin, 2016/12/23
- [PATCH 1/9] strtoull: Fix behaviour on chars between '9' and 'a'., Keng-Yu Lin, 2016/12/23
- [PATCH 2/9] net: read bracketed ipv6 addrs and port numbers, Keng-Yu Lin, 2016/12/23
- [PATCH 6/9] grub.texi: Add net_bootp6 doument, Keng-Yu Lin, 2016/12/23
- [PATCH v2 3/9] Add default port in grub_net_app_protocol,
Keng-Yu Lin <=
- [PATCH 5/9] efinet: UEFI IPv6 PXE support, Keng-Yu Lin, 2016/12/23
- [PATCH 4/9] bootp: New net_bootp6 command, Keng-Yu Lin, 2016/12/23
- [PATCH 8/9] efinet: Setting network from UEFI device path, Keng-Yu Lin, 2016/12/23
- [PATCH 7/9] bootp: Add processing DHCPACK packet from HTTP Boot, Keng-Yu Lin, 2016/12/23
- [PATCH 9/9] efinet: Setting DNS server from UEFI protocol, Keng-Yu Lin, 2016/12/23