From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1cKLcn-0000k7-LX for mharc-grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cKLcY-0000e7-D1 for grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cKLcX-0005SV-9A for grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:34 -0500 Received: from g2t2352.austin.hpe.com ([15.233.44.25]:44559) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cKLcX-0005Rs-1Z for grub-devel@gnu.org; Fri, 23 Dec 2016 03:54:33 -0500 Received: from g2t2360.austin.hpecorp.net (g2t2360.austin.hpecorp.net [16.196.225.135]) by g2t2352.austin.hpe.com (Postfix) with ESMTP id 311BC43; Fri, 23 Dec 2016 08:54:32 +0000 (UTC) Received: from hpe.com (hpe.asiapacific.hpqcorp.net [16.159.110.186]) by g2t2360.austin.hpecorp.net (Postfix) with ESMTP id AE07049; Fri, 23 Dec 2016 08:54:31 +0000 (UTC) From: Keng-Yu Lin To: grub-devel@gnu.org Cc: mchang@suse.com, ken.lin@hpe.com, ljk@hpe.com, michael.ruan@hpe.com, clayc@hpe.com, kengyu@hpe.com Subject: [PATCH v2 3/9] Add default port in grub_net_app_protocol Date: Fri, 23 Dec 2016 16:54:06 +0800 Message-Id: <1482483252-8710-4-git-send-email-kengyu@hpe.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482483252-8710-1-git-send-email-kengyu@hpe.com> References: <1482483252-8710-1-git-send-email-kengyu@hpe.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 15.233.44.25 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Dec 2016 08:54:38 -0000 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 --- 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