Skip to contentSkip to conversation

Patch for export IP addresses from PXE into grub2 enviroment variables

PATCH Aleš Kapica 5 participants 8 messages Oct 15, 2009

lore
Share & tools
lore
#0 lore raw

Could I ask you for apply patch from attachment on pxecmd.c in grub2, please? It's adding an option -s to the command pxe, which do make possible set IP addresses of the server and the client machine, got from PXE, among grub2 enviroment variables. DHCP gives IP according to MAC address, and we use it to identify the client station by IP address.

Thanks a lot, with regards Aleš Kapica

Signature · 1 line
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
grub2/commands/i386/pc/pxecmd.c +19 -1
index df53870..066d9a0 100644
@@ -22,12 +22,14 @@
 #include <grub/misc.h>
 #include <grub/machine/pxe.h>
 #include <grub/extcmd.h>
+#include <grub/env.h>
 
 static const struct grub_arg_option options[] =
 {
     {"info", 'i', 0, "show PXE information.", 0, 0},
     {"bsize", 'b', 0, "set PXE block size", 0, ARG_TYPE_INT},
     {"unload", 'u', 0, "unload PXE stack.", 0, 0},
+    {"set", 's', 0, "set network variables PXE_IP etc.", 0, 0},
     {0, 0, 0, 0, 0, 0}
   };
 
@@ -43,6 +45,15 @@ print_ip (grub_uint32_t ip)
     }
   grub_printf ("%d", ip);
 }
+static void
+set_ip2env_var(char *var_name, grub_uint32_t ip)
+{
+	char s[20];
+	grub_sprintf (s,"%d.%d.%d.%d", (ip>>0)&0xFF,
+		(ip>>8)&0xFF, (ip>>16)&0xFF, (ip>>24)&0xFF);
+	grub_env_set (var_name, s);
+}
+
 
 static grub_err_t
 grub_cmd_pxe (grub_extcmd_t cmd, int argc __attribute__ ((unused)),
@@ -78,6 +89,13 @@ grub_cmd_pxe (grub_extcmd_t cmd, int argc __attribute__ ((unused)),
       grub_printf ("\n");
     }
 
+  if (state[3].set)
+    {
+		set_ip2env_var ("pxe_your_ip", grub_pxe_your_ip);
+		set_ip2env_var ("pxe_server_ip", grub_pxe_server_ip);
+		set_ip2env_var ("pxe_gateway_ip", grub_pxe_gateway_ip);
+	}
+
   if (state[2].set)
     grub_pxe_unload ();
 
@@ -89,7 +107,7 @@ static grub_extcmd_t cmd;
 GRUB_MOD_INIT(pxecmd)
 {
   cmd = grub_register_extcmd ("pxe", grub_cmd_pxe, GRUB_COMMAND_FLAG_BOTH,
-			      "pxe [-i|-b|-u]",
+			      "pxe [-i|-b|-u|-s']",
 			      "Command to control the PXE device.", options);
 }
 
#1 lore raw

Hi,

That's actually not sufficient -- we need the entire DHCPACK to be passed
(somehow) to the loading kernel. I've discussed this a bit with phcoder, and he suggested adding another member to the multiboot structure off of which we can hang the DHCPACK packet. The environment variables may also have value, for other OSes that don't use multiboot.

--S

Quoting Aleš Kapica, who wrote the following on Thu, 15 Oct 2009:

Quoted 7 lines

Could I ask you for apply patch from attachment on pxecmd.c in grub2, please? It's adding an option -s to the command pxe, which do make possible set IP addresses of the server and the client machine, got from PXE, among grub2 enviroment variables. DHCP gives IP according to MAC address, and we use it to identify the client station by IP address.

Thanks a lot, with regards Aleš Kapica

Signature · 1 line
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
#2 lore raw

Am Mittwoch, den 14.10.2009, 23:53 -0700 schrieb Seth Goldberg:

Quoted 8 lines

Hi,

That's actually not sufficient -- we need the entire DHCPACK to be passed
(somehow) to the loading kernel. I've discussed this a bit with phcoder, and he suggested adding another member to the multiboot structure off of which we can hang the DHCPACK packet. The environment variables may also have value, for other OSes that don't use multiboot.

Quoted 13 lines

--S

Quoting Aleš Kapica, who wrote the following on Thu, 15 Oct 2009:

Quoted 9 lines

Could I ask you for apply patch from attachment on pxecmd.c in grub2, please? It's adding an option -s to the command pxe, which do make possible set IP addresses of the server and the client machine, got from PXE, among grub2 enviroment variables.
DHCP gives IP according to MAC address, and we use it to identify the client station by IP address.

Thanks a lot, with regards Aleš Kapica

Having the Client IP avaible inside grub.cfg might be useful for some. Then you could have one grub.cfg for all your machines and if one or a small number of it needs some special stuff, you could just check for the IP inside the grub.cfg. Then you don't need to use a seperate one for them.

But maybe this isn't that useful if option-150 gets implemented which Yoann requested.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer and GNU GRUB developer
#3 lore raw

Quoting Felix Zielcke, who wrote the following on Thu, 15 Oct 2009:

Quoted 20 lines

Am Mittwoch, den 14.10.2009, 23:53 -0700 schrieb Seth Goldberg:

Quoted 19 lines

Hi,

That's actually not sufficient -- we need the entire DHCPACK to be passed
(somehow) to the loading kernel. I've discussed this a bit with phcoder, and he suggested adding another member to the multiboot structure off of which we can hang the DHCPACK packet. The environment variables may also have value, for other OSes that don't use multiboot.

--S

Quoting Aleš Kapica, who wrote the following on Thu, 15 Oct 2009:

Quoted 7 lines

Could I ask you for apply patch from attachment on pxecmd.c in grub2, please? It's adding an option -s to the command pxe, which do make possible set IP addresses of the server and the client machine, got from PXE, among grub2 enviroment variables.
DHCP gives IP according to MAC address, and we use it to identify the client station by IP address.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks a lot, with regards Aleš Kapica

Having the Client IP avaible inside grub.cfg might be useful for some. Then you could have one grub.cfg for all your machines and if one or a small number of it needs some special stuff, you could just check for the IP inside the grub.cfg. Then you don't need to use a seperate one for them.

Please, no. That's terribly non-scalable for a large number of clients
(enterprise deployments). We definitely need a solution that includes the configuration file to use as a DHCP option.

--S

#4 lore raw
Quoted 41 lines · Seth Goldberg

Quoting Felix Zielcke, who wrote the following on Thu, 15 Oct 2009:

Quoted 28 lines

Am Mittwoch, den 14.10.2009, 23:53 -0700 schrieb Seth Goldberg:

Quoted 27 lines

Hi,

That's actually not sufficient -- we need the entire DHCPACK to
be passed
(somehow) to the loading kernel. I've discussed this a bit with phcoder, and
he suggested adding another member to the multiboot structure off of which we
can hang the DHCPACK packet. The environment variables may also have value,
for other OSes that don't use multiboot.

--S

Quoting Aleš Kapica, who wrote the following on Thu, 15 Oct 2009:

Quoted 11 lines

Could I ask you for apply patch from attachment on pxecmd.c in grub2, please?
It's adding an option -s to the command pxe, which do make possible set IP
addresses of the server and the client machine, got from PXE, among grub2
enviroment variables.
DHCP gives IP according to MAC address, and we use it to identify the client
station by IP address.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks a lot, with regards Aleš Kapica

Having the Client IP avaible inside grub.cfg might be useful for some. Then you could have one grub.cfg for all your machines and if one or a small number of it needs some special stuff, you could just check for the IP inside the grub.cfg. Then you don't need to use a seperate one for them.

Quoted 4 lines

Please, no. That's terribly non-scalable for a large number of
clients (enterprise deployments). We definitely need a solution that includes the configuration file to use as a DHCP option.

One doesn't prevent another. And then it will be up to administrator to choose the way they want their system to work

Quoted 8 lines

--S
------------------------------------------------------------------------

_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 3 lines
Regards
Vladimir 'phcoder' Serbinenko
Personal git repository: http://repo.or.cz/w/grub2/phcoder.git 
#5 lore raw
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Having the Client IP avaible inside grub.cfg might be useful for some. Then you could have one grub.cfg for all your machines and if one or a small number of it needs some special stuff, you could just check for the IP inside the grub.cfg. Then you don't need to use a seperate one for them.

Quoted 7 lines
Quoted 4 lines

Please, no. That's terribly non-scalable for a large number of
clients (enterprise deployments). We definitely need a solution that includes the configuration file to use as a DHCP option.

One doesn't prevent another. And then it will be up to administrator to choose the way they want their system to work

Quoted 1 line

--S

might be good to get option-150 first for compatibility with old grub than developed new feature ? I mean, this feature can be useful for some people but option-150 must be need by more people ?

Yoann

#6 lore raw
In reply to Vladimir 'phcoder' Serbinenko
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

Having the Client IP avaible inside grub.cfg might be useful for some. Then you could have one grub.cfg for all your machines and if one or a small number of it needs some special stuff, you could just check for the IP inside the grub.cfg. Then you don't need to use a seperate one for them.

Quoted 6 lines
Quoted 4 lines

Please, no. That's terribly non-scalable for a large number of
clients (enterprise deployments). We definitely need a solution that includes the configuration file to use as a DHCP option.

One doesn't prevent another. And then it will be up to administrator to choose the way they want their system to work

As long as we have the choice, that's fine with me.

--S

#7 lore raw
In reply to Seth Goldberg

Am Donnerstag, den 15.10.2009, 00:51 -0700 schrieb Seth Goldberg:

Quoted 32 lines

Quoting Felix Zielcke, who wrote the following on Thu, 15 Oct 2009:

Quoted 20 lines

Am Mittwoch, den 14.10.2009, 23:53 -0700 schrieb Seth Goldberg:

Quoted 19 lines

Hi,

That's actually not sufficient -- we need the entire DHCPACK to be passed
(somehow) to the loading kernel. I've discussed this a bit with phcoder, and he suggested adding another member to the multiboot structure off of which we can hang the DHCPACK packet. The environment variables may also have value, for other OSes that don't use multiboot.

--S

Quoting Aleš Kapica, who wrote the following on Thu, 15 Oct 2009:

Quoted 7 lines

Could I ask you for apply patch from attachment on pxecmd.c in grub2, please? It's adding an option -s to the command pxe, which do make possible set IP addresses of the server and the client machine, got from PXE, among grub2 enviroment variables.
DHCP gives IP according to MAC address, and we use it to identify the client station by IP address.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

Thanks a lot, with regards Aleš Kapica

Having the Client IP avaible inside grub.cfg might be useful for some. Then you could have one grub.cfg for all your machines and if one or a small number of it needs some special stuff, you could just check for the IP inside the grub.cfg. Then you don't need to use a seperate one for them.

Quoted 3 lines

Please, no. That's terribly non-scalable for a large number of clients
(enterprise deployments). We definitely need a solution that includes the configuration file to use as a DHCP option.

Both methods should coexist fine.
I didn't meant to implement only this and not the option-150. I just thought that this method might have an advantage for some people over the other.

As I said as last sentence

Quoted 2 lines

But maybe this isn't that useful if option-150 gets implemented which Yoann requested.

Signature · 2 lines
Felix Zielcke
Proud Debian Maintainer and GNU GRUB developer