mirror of
https://github.com/ipxe/ipxe
synced 2025-12-11 22:11:08 +03:00
[autoboot] Use next-server from filename's settings block
Locate the settings block containing the filename, and search only that settings block for the next-server address. This avoids problems caused by misconfigured DHCP servers which provide a next-server address (often defaulting to the DHCP server's own IP address) even when not providing a filename. Originally-implemented-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -251,31 +251,42 @@ static void close_all_netdevs ( void ) {
|
|||||||
* @ret uri URI, or NULL on failure
|
* @ret uri URI, or NULL on failure
|
||||||
*/
|
*/
|
||||||
struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
|
struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
|
||||||
struct in_addr next_server;
|
struct in_addr next_server = { 0 };
|
||||||
char buf[256];
|
char *raw_filename = NULL;
|
||||||
|
struct uri *uri = NULL;
|
||||||
char *filename;
|
char *filename;
|
||||||
struct uri *uri;
|
|
||||||
|
|
||||||
/* Fetch next-server setting */
|
/* Determine settings block containing the filename, if any */
|
||||||
fetch_ipv4_setting ( settings, &next_server_setting, &next_server );
|
settings = fetch_setting_origin ( settings, &filename_setting );
|
||||||
if ( next_server.s_addr )
|
|
||||||
printf ( "Next server: %s\n", inet_ntoa ( next_server ) );
|
|
||||||
|
|
||||||
/* Fetch filename setting */
|
/* If we have a filename, fetch it along with next-server */
|
||||||
fetch_string_setting ( settings, &filename_setting,
|
if ( settings ) {
|
||||||
buf, sizeof ( buf ) );
|
fetch_ipv4_setting ( settings, &next_server_setting,
|
||||||
if ( buf[0] )
|
&next_server );
|
||||||
printf ( "Filename: %s\n", buf );
|
if ( fetch_string_setting_copy ( settings, &filename_setting,
|
||||||
|
&raw_filename ) < 0 )
|
||||||
|
goto err_fetch;
|
||||||
|
}
|
||||||
|
|
||||||
/* Expand filename setting */
|
/* Expand filename setting */
|
||||||
filename = expand_settings ( buf );
|
filename = expand_settings ( raw_filename ? raw_filename : "" );
|
||||||
if ( ! filename )
|
if ( ! filename )
|
||||||
return NULL;
|
goto err_expand;
|
||||||
|
|
||||||
/* Parse next server and filename */
|
/* Parse next server and filename */
|
||||||
|
if ( next_server.s_addr )
|
||||||
|
printf ( "Next server: %s\n", inet_ntoa ( next_server ) );
|
||||||
|
if ( filename[0] )
|
||||||
|
printf ( "Filename: %s\n", filename );
|
||||||
uri = parse_next_server_and_filename ( next_server, filename );
|
uri = parse_next_server_and_filename ( next_server, filename );
|
||||||
|
if ( ! uri )
|
||||||
|
goto err_parse;
|
||||||
|
|
||||||
|
err_parse:
|
||||||
free ( filename );
|
free ( filename );
|
||||||
|
err_expand:
|
||||||
|
free ( raw_filename );
|
||||||
|
err_fetch:
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user