summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2008-07-31 17:55:46 +0200
committerMichael Brown2008-07-31 17:55:46 +0200
commit481a21798daf0a805f048cabb65f3a80fc60fd06 (patch)
tree02697d7b99464078fe95a0c83a2fb8929c6d0387
parent[cleanup] Remove obsolete README.cvs file (diff)
downloadipxe-481a21798daf0a805f048cabb65f3a80fc60fd06.tar.gz
ipxe-481a21798daf0a805f048cabb65f3a80fc60fd06.tar.xz
ipxe-481a21798daf0a805f048cabb65f3a80fc60fd06.zip
[autoboot] Retain initial-slash (if present) when constructing TFTP URIs
When we boot from a DHCP-supplied filename, we previously relied on the fact that the current working URI is set to tftp://[next-server]/ in order to resolve the filename into a full tftp:// URI. However, this process will eliminate the distinction between filenames with and without initial slashes: cwuri="tftp://10.0.0.1/" filename="vmlinuz" => URI="tftp://10.0.0.1/vmlinuz" cwuri="tftp://10.0.0.1/" filename="/vmlinuz" => URI="tftp://10.0.0.1/vmlinuz" This distinction is important for some TFTP servers. We now explicitly construct a string of the form "tftp://[next-server]/filename" so that a filename with an initial slash will result in a URI containing a double-slash, e.g. "tftp://10.0.0.1//vmlinuz" The TFTP code always strips a single initial slash, and so ends up presenting the correct path to the server. URIs entered explicitly by users at the command line must include a double slash if they want an initial slash presented to the TFTP server: "kernel tftp://10.0.0.1/vmlinuz" => filename="vmlinuz" "kernel tftp://10.0.0.1//vmlinuz" => filename="/vmlinuz"
-rw-r--r--src/include/gpxe/settings.h1
-rw-r--r--src/usr/autoboot.c33
2 files changed, 31 insertions, 3 deletions
diff --git a/src/include/gpxe/settings.h b/src/include/gpxe/settings.h
index ae5a259d..78f3e698 100644
--- a/src/include/gpxe/settings.h
+++ b/src/include/gpxe/settings.h
@@ -215,6 +215,7 @@ extern struct setting password_setting __setting;
extern struct setting priority_setting __setting;
extern struct setting bios_drive_setting __setting;
extern struct setting uuid_setting __setting;
+extern struct setting next_server_setting __setting;
/**
* Initialise a settings block
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index fdd502da..326292b4 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -24,6 +24,7 @@
#include <gpxe/settings.h>
#include <gpxe/image.h>
#include <gpxe/embedded.h>
+#include <gpxe/uri.h>
#include <usr/ifmgmt.h>
#include <usr/route.h>
#include <usr/dhcpmgmt.h>
@@ -78,15 +79,39 @@ static int boot_embedded_image ( void ) {
}
/**
- * Boot using filename
+ * Boot using next-server and filename
*
* @v filename Boot filename
* @ret rc Return status code
*/
-static int boot_filename ( const char *filename ) {
+static int boot_next_server_and_filename ( struct in_addr next_server,
+ const char *filename ) {
+ struct uri *uri;
struct image *image;
+ char buf[ 23 /* tftp://xxx.xxx.xxx.xxx/ */ + strlen(filename) + 1 ];
+ int filename_is_absolute;
int rc;
+ /* Construct URI */
+ uri = parse_uri ( filename );
+ if ( ! uri ) {
+ printf ( "Out of memory\n" );
+ return -ENOMEM;
+ }
+ filename_is_absolute = uri_is_absolute ( uri );
+ uri_put ( uri );
+ if ( ! filename_is_absolute ) {
+ /* Construct a tftp:// URI for the filename. We can't
+ * just rely on the current working URI, because the
+ * relative URI resolution will remove the distinction
+ * between filenames with and without initial slashes,
+ * which is significant for TFTP.
+ */
+ snprintf ( buf, sizeof ( buf ), "tftp://%s/%s",
+ inet_ntoa ( next_server ), filename );
+ filename = buf;
+ }
+
image = alloc_image();
if ( ! image ) {
printf ( "Out of memory\n" );
@@ -135,6 +160,7 @@ int boot_root_path ( const char *root_path ) {
*/
static int netboot ( struct net_device *netdev ) {
char buf[256];
+ struct in_addr next_server;
int rc;
/* Open device and display device status */
@@ -161,10 +187,11 @@ static int netboot ( struct net_device *netdev ) {
return rc;
/* Try to download and boot whatever we are given as a filename */
+ fetch_ipv4_setting ( NULL, &next_server_setting, &next_server );
fetch_string_setting ( NULL, &filename_setting, buf, sizeof ( buf ) );
if ( buf[0] ) {
printf ( "Booting from filename \"%s\"\n", buf );
- return boot_filename ( buf );
+ return boot_next_server_and_filename ( next_server, buf );
}
/* No filename; try the root path */