All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: RFC Patch [0/2] PXE Add support for proxy DHCP
Date: Sun, 20 Apr 2014 16:05:42 +0200	[thread overview]
Message-ID: <5353D436.60007@gmail.com> (raw)
In-Reply-To: <6D165E863E048E4D86C25F15CEA5329797665DF1@ORSMSX109.amr.corp.intel.com>


[-- Attachment #1.1: Type: text/plain, Size: 1038 bytes --]

On 19.04.2014 02:26, Mroczek, Joseph T wrote:
> Hello:
> 
> Currently, grub does not support getting boot server information from a proxy DHCP server. This patch set adds this support for EFI. If the approach is good, I will go back and create a i386-pc patch as well.
> 
> It works by combining the contents from the two DHCP packets into a single source. This seems simpler and cleaner than updating all the DHCP code to work with multiple packets and juggling precedence across all the options.
> 
> Any help in getting this support into grub would be greatly appreciated.
> 
We have patch for similar problem for i386-pc port (attached).
The main problem with it is that it wasn't tested. If you can confirm
that it works for EFI as well (after adaptations from your patch), we
could commit pxe2.diff and necessarry adaptations on top of it.
> ~joe
> 
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: pxe2.diff --]
[-- Type: text/x-diff; name="pxe2.diff", Size: 7444 bytes --]

diff --git a/grub-core/kern/main.c b/grub-core/kern/main.c
index 19dc988..a1dcde6 100644
--- a/grub-core/kern/main.c
+++ b/grub-core/kern/main.c
@@ -142,8 +142,9 @@ grub_set_prefix_and_root (void)
       if (pptr[0])
 	path = grub_strdup (pptr);
     }
-  if ((!device || device[0] == ',' || !device[0]) || !path)
-    grub_machine_get_bootlocation (&fwdevice, &fwpath);
+
+  /* Call unconditionally as it also configures the network.  */
+  grub_machine_get_bootlocation (&fwdevice, &fwpath);
 
   if (!device && fwdevice)
     device = fwdevice;
diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c
index ed15941..38b0836 100644
--- a/grub-core/net/bootp.c
+++ b/grub-core/net/bootp.c
@@ -161,33 +161,14 @@ parse_dhcp_vendor (const char *name, const void *vend, int limit, int *mask)
 
 #define OFFSET_OF(x, y) ((grub_size_t)((grub_uint8_t *)((y)->x) - (grub_uint8_t *)(y)))
 
-struct grub_net_network_level_interface *
-grub_net_configure_by_dhcp_ack (const char *name,
-				struct grub_net_card *card,
-				grub_net_interface_flags_t flags,
-				const struct grub_net_bootp_packet *bp,
-				grub_size_t size,
-				int is_def, char **device, char **path)
+void
+grub_net_process_dhcp_ack (struct grub_net_network_level_interface *inter,
+			   const struct grub_net_bootp_packet *bp,
+			   grub_size_t size,
+			   int is_def, char **device, char **path)
 {
-  grub_net_network_level_address_t addr;
-  grub_net_link_level_address_t hwaddr;
-  struct grub_net_network_level_interface *inter;
   int mask = -1;
 
-  addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
-  addr.ipv4 = bp->your_ip;
-
-  if (device)
-    *device = 0;
-  if (path)
-    *path = 0;
-
-  grub_memcpy (hwaddr.mac, bp->mac_addr,
-	       bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len
-	       : sizeof (hwaddr.mac));
-  hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
-
-  inter = grub_net_add_addr (name, card, &addr, &hwaddr, flags);
   if (bp->gateway_ip)
     {
       grub_net_network_level_netaddress_t target;
@@ -199,7 +180,7 @@ grub_net_configure_by_dhcp_ack (const char *name,
       target.ipv4.masksize = 32;
       gw.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
       gw.ipv4 = bp->gateway_ip;
-      rname = grub_xasprintf ("%s:gw", name);
+      rname = grub_xasprintf ("%s:gw", inter->name);
       if (rname)
 	grub_net_add_route_gw (rname, target, gw);
       grub_free (rname);
@@ -207,14 +188,12 @@ grub_net_configure_by_dhcp_ack (const char *name,
       target.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
       target.ipv4.base = bp->gateway_ip;
       target.ipv4.masksize = 32;
-      grub_net_add_route (name, target, inter);
+      grub_net_add_route (inter->name, target, inter);
     }
 
   if (size > OFFSET_OF (boot_file, bp))
-    set_env_limn_ro (name, "boot_file", (char *) bp->boot_file,
+    set_env_limn_ro (inter->name, "boot_file", (char *) bp->boot_file,
 		     sizeof (bp->boot_file));
-  if (is_def)
-    grub_net_default_server = 0;
   if (is_def && !grub_net_default_server && bp->server_ip)
     {
       grub_net_default_server = grub_xasprintf ("%d.%d.%d.%d",
@@ -225,12 +204,6 @@ grub_net_configure_by_dhcp_ack (const char *name,
       grub_print_error ();
     }
 
-  if (is_def)
-    {
-      grub_env_set ("net_default_interface", name);
-      grub_env_export ("net_default_interface");
-    }
-
   if (device && !*device && bp->server_ip)
     {
       *device = grub_xasprintf ("tftp,%d.%d.%d.%d",
@@ -243,7 +216,7 @@ grub_net_configure_by_dhcp_ack (const char *name,
   if (size > OFFSET_OF (server_name, bp)
       && bp->server_name[0])
     {
-      set_env_limn_ro (name, "dhcp_server_name", (char *) bp->server_name,
+      set_env_limn_ro (inter->name, "dhcp_server_name", (char *) bp->server_name,
 		       sizeof (bp->server_name));
       if (is_def && !grub_net_default_server)
 	{
@@ -257,7 +230,8 @@ grub_net_configure_by_dhcp_ack (const char *name,
 	}
     }
 
-  if (size > OFFSET_OF (boot_file, bp) && path)
+  if (size > OFFSET_OF (boot_file, bp) && path && !*path
+      && bp->boot_file[0])
     {
       *path = grub_strndup (bp->boot_file, sizeof (bp->boot_file));
       grub_print_error ();
@@ -272,9 +246,47 @@ grub_net_configure_by_dhcp_ack (const char *name,
 	}
     }
   if (size > OFFSET_OF (vendor, bp))
-    parse_dhcp_vendor (name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask);
+    parse_dhcp_vendor (inter->name, &bp->vendor, size - OFFSET_OF (vendor, bp), &mask);
   grub_net_add_ipv4_local (inter, mask);
-  
+}
+
+
+struct grub_net_network_level_interface *
+grub_net_configure_by_dhcp_ack (const char *name,
+				struct grub_net_card *card,
+				grub_net_interface_flags_t flags,
+				const struct grub_net_bootp_packet *bp,
+				grub_size_t size,
+				int is_def, char **device, char **path)
+{
+  grub_net_network_level_address_t addr;
+  grub_net_link_level_address_t hwaddr;
+  struct grub_net_network_level_interface *inter;
+
+  addr.type = GRUB_NET_NETWORK_LEVEL_PROTOCOL_IPV4;
+  addr.ipv4 = bp->your_ip;
+
+  if (device)
+    *device = 0;
+  if (path)
+    *path = 0;
+
+  grub_memcpy (hwaddr.mac, bp->mac_addr,
+	       bp->hw_len < sizeof (hwaddr.mac) ? bp->hw_len
+	       : sizeof (hwaddr.mac));
+  hwaddr.type = GRUB_NET_LINK_LEVEL_PROTOCOL_ETHERNET;
+
+  inter = grub_net_add_addr (name, card, &addr, &hwaddr, flags);
+
+  if (is_def)
+    {
+      grub_env_set ("net_default_interface", name);
+      grub_env_export ("net_default_interface");
+      grub_net_default_server = 0;
+    }
+
+  grub_net_process_dhcp_ack (inter, bp, size, is_def, device, path);
+
   inter->dhcp_ack = grub_malloc (size);
   if (inter->dhcp_ack)
     {
diff --git a/grub-core/net/drivers/i386/pc/pxe.c b/grub-core/net/drivers/i386/pc/pxe.c
index 3e75b2e..0a2ed82 100644
--- a/grub-core/net/drivers/i386/pc/pxe.c
+++ b/grub-core/net/drivers/i386/pc/pxe.c
@@ -360,15 +360,24 @@ static void
 grub_pc_net_config_real (char **device, char **path)
 {
   struct grub_net_bootp_packet *bp;
+  struct grub_net_network_level_interface *inter;
 
   bp = grub_pxe_get_cached (GRUB_PXENV_PACKET_TYPE_DHCP_ACK);
 
   if (!bp)
     return;
-  grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, 0,
-				  bp, GRUB_PXE_BOOTP_SIZE,
-				  1, device, path);
+  inter = grub_net_configure_by_dhcp_ack ("pxe", &grub_pxe_card, 0,
+					  bp, GRUB_PXE_BOOTP_SIZE,
+					  1, device, path);
 
+
+  /* Boot server PXE options add and override boot file/server */
+  bp = grub_pxe_get_cached (GRUB_PXENV_PACKET_TYPE_CACHED_REPLY);
+
+
+  if (bp)
+    grub_net_process_dhcp_ack (inter, bp, GRUB_PXE_BOOTP_SIZE,
+			       1, device, path);
 }
 
 static struct grub_preboot *fini_hnd;
diff --git a/include/grub/net.h b/include/grub/net.h
index 788516a..507f985 100644
--- a/include/grub/net.h
+++ b/include/grub/net.h
@@ -444,6 +444,12 @@ grub_net_configure_by_dhcp_ack (const char *name,
 				grub_size_t size,
 				int is_def, char **device, char **path);
 
+void
+grub_net_process_dhcp_ack (struct grub_net_network_level_interface *inter,
+			   const struct grub_net_bootp_packet *bp,
+			   grub_size_t size,
+			   int is_def, char **device, char **path);
+
 grub_err_t
 grub_net_add_ipv4_local (struct grub_net_network_level_interface *inf,
 			 int mask);

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 274 bytes --]

  reply	other threads:[~2014-04-20 14:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-19  0:26 RFC Patch [0/2] PXE Add support for proxy DHCP Mroczek, Joseph T
2014-04-20 14:05 ` Vladimir 'φ-coder/phcoder' Serbinenko [this message]
2014-04-29  0:16   ` Mroczek, Joseph T
2014-05-02  0:11   ` Mroczek, Joseph T
2014-05-22 16:53     ` Mroczek, Joseph T
  -- strict thread matches above, loose matches on Subject: below --
2019-02-03 15:04 Alkis Georgopoulos

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=5353D436.60007@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.