Преглед на файлове

[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>
tags/v1.20.1
Michael Brown преди 11 години
родител
ревизия
936134ed46
променени са 1 файла, в които са добавени 25 реда и са изтрити 14 реда
  1. 25
    14
      src/usr/autoboot.c

+ 25
- 14
src/usr/autoboot.c Целия файл

@@ -251,31 +251,42 @@ static void close_all_netdevs ( void ) {
251 251
  * @ret uri		URI, or NULL on failure
252 252
  */
253 253
 struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
254
-	struct in_addr next_server;
255
-	char buf[256];
254
+	struct in_addr next_server = { 0 };
255
+	char *raw_filename = NULL;
256
+	struct uri *uri = NULL;
256 257
 	char *filename;
257
-	struct uri *uri;
258 258
 
259
-	/* Fetch next-server setting */
260
-	fetch_ipv4_setting ( settings, &next_server_setting, &next_server );
261
-	if ( next_server.s_addr )
262
-		printf ( "Next server: %s\n", inet_ntoa ( next_server ) );
259
+	/* Determine settings block containing the filename, if any */
260
+	settings = fetch_setting_origin ( settings, &filename_setting );
263 261
 
264
-	/* Fetch filename setting */
265
-	fetch_string_setting ( settings, &filename_setting,
266
-			       buf, sizeof ( buf ) );
267
-	if ( buf[0] )
268
-		printf ( "Filename: %s\n", buf );
262
+	/* If we have a filename, fetch it along with next-server */
263
+	if ( settings ) {
264
+		fetch_ipv4_setting ( settings, &next_server_setting,
265
+				     &next_server );
266
+		if ( fetch_string_setting_copy ( settings, &filename_setting,
267
+						 &raw_filename ) < 0 )
268
+			goto err_fetch;
269
+	}
269 270
 
270 271
 	/* Expand filename setting */
271
-	filename = expand_settings ( buf );
272
+	filename = expand_settings ( raw_filename ? raw_filename : "" );
272 273
 	if ( ! filename )
273
-		return NULL;
274
+		goto err_expand;
274 275
 
275 276
 	/* Parse next server and filename */
277
+	if ( next_server.s_addr )
278
+		printf ( "Next server: %s\n", inet_ntoa ( next_server ) );
279
+	if ( filename[0] )
280
+		printf ( "Filename: %s\n", filename );
276 281
 	uri = parse_next_server_and_filename ( next_server, filename );
282
+	if ( ! uri )
283
+		goto err_parse;
277 284
 
285
+ err_parse:
278 286
 	free ( filename );
287
+ err_expand:
288
+	free ( raw_filename );
289
+ err_fetch:
279 290
 	return uri;
280 291
 }
281 292
 

Loading…
Отказ
Запис