grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
From: Keng-Yu Lin <kengyu@hpe.com>
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	[thread overview]
Message-ID: <1482483252-8710-4-git-send-email-kengyu@hpe.com> (raw)
In-Reply-To: <1482483252-8710-1-git-send-email-kengyu@hpe.com>

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 <kengyu@hpe.com>
---
 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



  parent reply	other threads:[~2016-12-23  8:54 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-23  8:54 [PATCH v2 0/9] Add UEFI HTTP Boot support for IPv4 and IPv6 Keng-Yu Lin
2016-12-23  8:54 ` [PATCH 1/9] strtoull: Fix behaviour on chars between '9' and 'a' Keng-Yu Lin
2016-12-23  8:54 ` [PATCH 2/9] net: read bracketed ipv6 addrs and port numbers Keng-Yu Lin
2016-12-23  8:54 ` Keng-Yu Lin [this message]
2016-12-23  8:54 ` [PATCH 4/9] bootp: New net_bootp6 command Keng-Yu Lin
2016-12-23  8:54 ` [PATCH 5/9] efinet: UEFI IPv6 PXE support Keng-Yu Lin
2016-12-23  8:54 ` [PATCH 6/9] grub.texi: Add net_bootp6 doument Keng-Yu Lin
2016-12-23  8:54 ` [PATCH 7/9] bootp: Add processing DHCPACK packet from HTTP Boot Keng-Yu Lin
2016-12-23  8:54 ` [PATCH 8/9] efinet: Setting network from UEFI device path Keng-Yu Lin
2016-12-23  8:54 ` [PATCH 9/9] efinet: Setting DNS server from UEFI protocol Keng-Yu Lin
2017-01-16  9:07 ` [PATCH v2 0/9] Add UEFI HTTP Boot support for IPv4 and IPv6 Lin, Keng-Yu (HPS OE-Linux TDC)
2017-01-16 10:12   ` Daniel Kiper
2017-07-06  6:52     ` Lin, Keng-Yu
2017-07-10 10:10       ` Michael Chang
2017-07-11  7:39         ` Lin, Keng-Yu
2017-07-11  9:48           ` Michael Chang
2017-07-10 20:41       ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1482483252-8710-4-git-send-email-kengyu@hpe.com \
    --to=kengyu@hpe.com \
    --cc=clayc@hpe.com \
    --cc=grub-devel@gnu.org \
    --cc=ken.lin@hpe.com \
    --cc=ljk@hpe.com \
    --cc=mchang@suse.com \
    --cc=michael.ruan@hpe.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).