2007-01-12 07:05:27 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-07-20 20:55:45 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301, USA.
|
2015-03-02 12:54:40 +01:00
|
|
|
*
|
|
|
|
* You can also choose to distribute this program under the terms of
|
|
|
|
* the Unmodified Binary Distribution Licence (as given in the file
|
|
|
|
* COPYING.UBDL), provided that you have satisfied its requirements.
|
2007-01-12 07:05:27 +01:00
|
|
|
*/
|
|
|
|
|
2015-03-02 12:54:40 +01:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
2009-05-01 16:41:06 +02:00
|
|
|
|
2007-01-12 07:05:27 +01:00
|
|
|
#include <stdint.h>
|
2007-01-12 08:22:20 +01:00
|
|
|
#include <stdlib.h>
|
2007-01-19 02:13:12 +01:00
|
|
|
#include <stdio.h>
|
2007-01-12 08:22:20 +01:00
|
|
|
#include <errno.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/image.h>
|
|
|
|
#include <ipxe/downloader.h>
|
|
|
|
#include <ipxe/monojob.h>
|
|
|
|
#include <ipxe/open.h>
|
|
|
|
#include <ipxe/uri.h>
|
2007-01-12 07:05:27 +01:00
|
|
|
#include <usr/imgmgmt.h>
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Image management
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2011-03-09 17:55:51 +01:00
|
|
|
/**
|
2012-03-24 02:16:37 +01:00
|
|
|
* Download a new image
|
2011-03-09 17:55:51 +01:00
|
|
|
*
|
2011-01-27 19:48:47 +01:00
|
|
|
* @v uri URI
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
* @v timeout Download timeout
|
2012-03-24 02:16:37 +01:00
|
|
|
* @v image Image to fill in
|
2007-01-12 08:22:20 +01:00
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
int imgdownload ( struct uri *uri, unsigned long timeout,
|
|
|
|
struct image **image ) {
|
2009-02-17 13:10:35 +01:00
|
|
|
const char *password;
|
2014-02-27 14:32:53 +01:00
|
|
|
char *uri_string_redacted;
|
2007-01-12 08:22:20 +01:00
|
|
|
int rc;
|
|
|
|
|
2014-02-27 14:32:53 +01:00
|
|
|
/* Construct redacted URI */
|
2009-02-17 13:10:35 +01:00
|
|
|
password = uri->password;
|
|
|
|
if ( password )
|
|
|
|
uri->password = "***";
|
2014-02-27 14:32:53 +01:00
|
|
|
uri_string_redacted = format_uri_alloc ( uri );
|
2009-02-17 13:10:35 +01:00
|
|
|
uri->password = password;
|
2014-02-27 14:32:53 +01:00
|
|
|
if ( ! uri_string_redacted ) {
|
|
|
|
rc = -ENOMEM;
|
2014-02-25 16:29:00 +01:00
|
|
|
goto err_uri_string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resolve URI */
|
|
|
|
uri = resolve_uri ( cwuri, uri );
|
|
|
|
if ( ! uri ) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_resolve_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate image */
|
|
|
|
*image = alloc_image ( uri );
|
|
|
|
if ( ! *image ) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto err_alloc_image;
|
2014-02-27 14:32:53 +01:00
|
|
|
}
|
2009-02-17 13:10:35 +01:00
|
|
|
|
2011-01-27 19:48:47 +01:00
|
|
|
/* Create downloader */
|
2014-02-25 16:29:00 +01:00
|
|
|
if ( ( rc = create_downloader ( &monojob, *image ) ) != 0 ) {
|
2012-03-24 02:16:37 +01:00
|
|
|
printf ( "Could not start download: %s\n", strerror ( rc ) );
|
2011-10-25 02:41:41 +02:00
|
|
|
goto err_create_downloader;
|
2011-03-09 17:55:51 +01:00
|
|
|
}
|
2011-01-27 19:48:47 +01:00
|
|
|
|
|
|
|
/* Wait for download to complete */
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
if ( ( rc = monojob_wait ( uri_string_redacted, timeout ) ) != 0 )
|
2011-10-25 02:41:41 +02:00
|
|
|
goto err_monojob_wait;
|
2011-01-27 19:48:47 +01:00
|
|
|
|
2011-10-25 02:41:41 +02:00
|
|
|
/* Register image */
|
2012-03-24 02:16:37 +01:00
|
|
|
if ( ( rc = register_image ( *image ) ) != 0 ) {
|
|
|
|
printf ( "Could not register image: %s\n", strerror ( rc ) );
|
2011-10-25 02:41:41 +02:00
|
|
|
goto err_register_image;
|
2012-03-24 02:16:37 +01:00
|
|
|
}
|
2011-10-25 02:41:41 +02:00
|
|
|
|
|
|
|
err_register_image:
|
|
|
|
err_monojob_wait:
|
|
|
|
err_create_downloader:
|
2012-03-24 02:16:37 +01:00
|
|
|
image_put ( *image );
|
2011-10-25 02:41:41 +02:00
|
|
|
err_alloc_image:
|
2014-02-25 16:29:00 +01:00
|
|
|
uri_put ( uri );
|
|
|
|
err_resolve_uri:
|
|
|
|
free ( uri_string_redacted );
|
|
|
|
err_uri_string:
|
2011-10-25 02:41:41 +02:00
|
|
|
return rc;
|
2011-01-27 19:48:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-03-24 02:16:37 +01:00
|
|
|
* Download a new image
|
2011-01-27 19:48:47 +01:00
|
|
|
*
|
2012-03-24 02:16:37 +01:00
|
|
|
* @v uri_string URI string
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
* @v timeout Download timeout
|
2012-03-24 02:16:37 +01:00
|
|
|
* @v image Image to fill in
|
2011-01-27 19:48:47 +01:00
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
int imgdownload_string ( const char *uri_string, unsigned long timeout,
|
|
|
|
struct image **image ) {
|
2011-01-27 19:48:47 +01:00
|
|
|
struct uri *uri;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ( ! ( uri = parse_uri ( uri_string ) ) )
|
|
|
|
return -ENOMEM;
|
|
|
|
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
rc = imgdownload ( uri, timeout, image );
|
2007-01-12 08:22:20 +01:00
|
|
|
|
2007-08-02 21:18:32 +02:00
|
|
|
uri_put ( uri );
|
2007-01-12 08:22:20 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2012-03-24 02:16:37 +01:00
|
|
|
/**
|
|
|
|
* Acquire an image
|
|
|
|
*
|
|
|
|
* @v name_uri Name or URI string
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
* @v timeout Download timeout
|
2012-03-24 02:16:37 +01:00
|
|
|
* @v image Image to fill in
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
int imgacquire ( const char *name_uri, unsigned long timeout,
|
|
|
|
struct image **image ) {
|
2012-03-24 02:16:37 +01:00
|
|
|
|
|
|
|
/* If we already have an image with the specified name, use it */
|
|
|
|
*image = find_image ( name_uri );
|
|
|
|
if ( *image )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Otherwise, download a new image */
|
[image] Add "--timeout" parameter to image downloading commands
iPXE will detect timeout failures in several situations: network
link-up, DHCP, TCP connection attempts, unacknowledged TCP data, etc.
This does not cover all possible circumstances. For example, if a
connection to a web server is successfully established and the web
server acknowledges the HTTP request but never sends any data in
response, then no timeout will be triggered. There is no timeout
defined within the HTTP specifications, and the underlying TCP
connection will not generate a timeout since it has no way to know
that the HTTP layer is expecting to receive data from the server.
Add a "--timeout" parameter to "imgfetch", "chain", etc. If no
progress is made (i.e. no data is downloaded) within the timeout
period, then the download will be aborted.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
2014-03-10 14:32:39 +01:00
|
|
|
return imgdownload_string ( name_uri, timeout, image );
|
2012-03-24 02:16:37 +01:00
|
|
|
}
|
|
|
|
|
2007-01-12 07:05:27 +01:00
|
|
|
/**
|
|
|
|
* Display status of an image
|
|
|
|
*
|
|
|
|
* @v image Executable/loadable image
|
|
|
|
*/
|
|
|
|
void imgstat ( struct image *image ) {
|
2011-03-07 01:37:50 +01:00
|
|
|
printf ( "%s : %zd bytes", image->name, image->len );
|
2007-01-12 07:05:27 +01:00
|
|
|
if ( image->type )
|
|
|
|
printf ( " [%s]", image->type->name );
|
2012-03-22 14:39:45 +01:00
|
|
|
if ( image->flags & IMAGE_TRUSTED )
|
|
|
|
printf ( " [TRUSTED]" );
|
2011-03-07 01:37:50 +01:00
|
|
|
if ( image->flags & IMAGE_SELECTED )
|
|
|
|
printf ( " [SELECTED]" );
|
2012-07-20 11:37:24 +02:00
|
|
|
if ( image->flags & IMAGE_AUTO_UNREGISTER )
|
|
|
|
printf ( " [AUTOFREE]" );
|
2007-08-02 21:18:32 +02:00
|
|
|
if ( image->cmdline )
|
2007-01-12 08:22:20 +01:00
|
|
|
printf ( " \"%s\"", image->cmdline );
|
2007-01-12 07:05:27 +01:00
|
|
|
printf ( "\n" );
|
|
|
|
}
|