mirror of
https://github.com/xcat2/xNBA.git
synced 2025-01-20 14:33:15 +00:00
[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"
This commit is contained in:
parent
193426d960
commit
481a21798d
@ -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
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user