summaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
authorSimon Rettberg2023-10-06 18:37:21 +0200
committerSimon Rettberg2023-10-06 18:37:21 +0200
commit95a57769874a70456670984debc05084feb75f6b (patch)
tree9943c86b682e1b1d21a0439637b3849840a50137 /src/core
parent[efi] Remove old RDRAND hack; now officially supported (diff)
parent[libc] Use wall clock time as seed for the (non-cryptographic) RNG (diff)
downloadipxe-95a57769874a70456670984debc05084feb75f6b.tar.gz
ipxe-95a57769874a70456670984debc05084feb75f6b.tar.xz
ipxe-95a57769874a70456670984debc05084feb75f6b.zip
Merge branch 'master' into openslx
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cachedhcp.c3
-rw-r--r--src/core/image.c69
-rw-r--r--src/core/interface.c1
-rw-r--r--src/core/parseopt.c15
-rw-r--r--src/core/random.c8
-rw-r--r--src/core/xfer.c3
6 files changed, 60 insertions, 39 deletions
diff --git a/src/core/cachedhcp.c b/src/core/cachedhcp.c
index 60213f02d..57226e165 100644
--- a/src/core/cachedhcp.c
+++ b/src/core/cachedhcp.c
@@ -295,9 +295,10 @@ struct startup_fn cachedhcp_startup_fn __startup_fn ( STARTUP_LATE ) = {
* Apply cached DHCPACK to network device, if applicable
*
* @v netdev Network device
+ * @v priv Private data
* @ret rc Return status code
*/
-static int cachedhcp_probe ( struct net_device *netdev ) {
+static int cachedhcp_probe ( struct net_device *netdev, void *priv __unused ) {
/* Apply cached DHCPACK to network device, if applicable */
return cachedhcp_apply ( &cached_dhcpack, netdev );
diff --git a/src/core/image.c b/src/core/image.c
index b280eb4d3..3e65b5edf 100644
--- a/src/core/image.c
+++ b/src/core/image.c
@@ -56,8 +56,15 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** List of registered images */
struct list_head images = LIST_HEAD_INIT ( images );
+/** Image selected for execution */
+struct image_tag selected_image __image_tag = {
+ .name = "SELECTED",
+};
+
/** Currently-executing image */
-struct image *current_image;
+struct image_tag current_image __image_tag = {
+ .name = "CURRENT",
+};
/** Current image trust requirement */
static int require_trusted_images = 0;
@@ -72,8 +79,13 @@ static int require_trusted_images_permanent = 0;
*/
static void free_image ( struct refcnt *refcnt ) {
struct image *image = container_of ( refcnt, struct image, refcnt );
+ struct image_tag *tag;
DBGC ( image, "IMAGE %s freed\n", image->name );
+ for_each_table_entry ( tag, IMAGE_TAGS ) {
+ if ( tag->image == image )
+ tag->image = NULL;
+ }
free ( image->name );
free ( image->cmdline );
uri_put ( image->uri );
@@ -261,12 +273,6 @@ int register_image ( struct image *image ) {
return rc;
}
- /* Avoid ending up with multiple "selected" images on
- * re-registration
- */
- if ( image_find_selected() )
- image->flags &= ~IMAGE_SELECTED;
-
/* Add to image list */
image_get ( image );
image->flags |= IMAGE_REGISTERED;
@@ -321,6 +327,23 @@ struct image * find_image ( const char *name ) {
}
/**
+ * Find image by tag
+ *
+ * @v tag Image tag
+ * @ret image Executable image, or NULL
+ */
+struct image * find_image_tag ( struct image_tag *tag ) {
+ struct image *image;
+
+ for_each_image ( image ) {
+ if ( tag->image == image )
+ return image;
+ }
+
+ return NULL;
+}
+
+/**
* Execute image
*
* @v image Executable image
@@ -346,13 +369,13 @@ int image_exec ( struct image *image ) {
if ( image->uri )
churi ( image->uri );
- /* Preserve record of any currently-running image */
- saved_current_image = current_image;
+ /* Set as currently running image */
+ saved_current_image = image_tag ( image, &current_image );
/* Take out a temporary reference to the image, so that it
* does not get freed when temporarily unregistered.
*/
- current_image = image_get ( image );
+ image_get ( image );
/* Check that this image can be executed */
if ( ! ( image->type && image->type->exec ) ) {
@@ -419,7 +442,7 @@ int image_exec ( struct image *image ) {
image_put ( image );
/* Restore previous currently-running image */
- current_image = saved_current_image;
+ image_tag ( saved_current_image, &current_image );
/* Reset current working directory */
churi ( old_cwuri );
@@ -442,7 +465,7 @@ int image_exec ( struct image *image ) {
* registered until the currently-executing image returns.
*/
int image_replace ( struct image *replacement ) {
- struct image *image = current_image;
+ struct image *image = current_image.image;
int rc;
/* Sanity check */
@@ -478,38 +501,18 @@ int image_replace ( struct image *replacement ) {
* @ret rc Return status code
*/
int image_select ( struct image *image ) {
- struct image *tmp;
-
- /* Unselect all other images */
- for_each_image ( tmp )
- tmp->flags &= ~IMAGE_SELECTED;
/* Check that this image can be executed */
if ( ! ( image->type && image->type->exec ) )
return -ENOEXEC;
/* Mark image as selected */
- image->flags |= IMAGE_SELECTED;
+ image_tag ( image, &selected_image );
return 0;
}
/**
- * Find selected image
- *
- * @ret image Executable image, or NULL
- */
-struct image * image_find_selected ( void ) {
- struct image *image;
-
- for_each_image ( image ) {
- if ( image->flags & IMAGE_SELECTED )
- return image;
- }
- return NULL;
-}
-
-/**
* Change image trust requirement
*
* @v require_trusted Require trusted images
diff --git a/src/core/interface.c b/src/core/interface.c
index 34a4180a5..ea0606893 100644
--- a/src/core/interface.c
+++ b/src/core/interface.c
@@ -285,6 +285,7 @@ void intf_shutdown ( struct interface *intf, int rc ) {
intf_nullify ( intf );
/* Transfer destination to temporary interface */
+ intf_temp_init ( &tmp, intf );
tmp.dest = intf->dest;
intf->dest = &null_intf;
diff --git a/src/core/parseopt.c b/src/core/parseopt.c
index 1dbfc7aef..cd3b3101c 100644
--- a/src/core/parseopt.c
+++ b/src/core/parseopt.c
@@ -28,6 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/netdevice.h>
@@ -35,6 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/settings.h>
#include <ipxe/params.h>
#include <ipxe/timer.h>
+#include <ipxe/keys.h>
#include <ipxe/parseopt.h>
#include <config/branding.h>
@@ -213,6 +215,7 @@ int parse_flag ( char *text __unused, int *flag ) {
* @ret rc Return status code
*/
int parse_key ( char *text, unsigned int *key ) {
+ int rc;
/* Interpret single characters as being a literal key character */
if ( text[0] && ! text[1] ) {
@@ -221,7 +224,17 @@ int parse_key ( char *text, unsigned int *key ) {
}
/* Otherwise, interpret as an integer */
- return parse_integer ( text, key );
+ if ( ( rc = parse_integer ( text, key ) ) < 0 )
+ return rc;
+
+ /* For backwards compatibility with existing scripts, treat
+ * integers between the ASCII range and special key range as
+ * being relative special key values.
+ */
+ if ( ( ! isascii ( *key ) ) && ( *key < KEY_MIN ) )
+ *key += KEY_MIN;
+
+ return 0;
}
/**
diff --git a/src/core/random.c b/src/core/random.c
index 975a03cf5..e3251964b 100644
--- a/src/core/random.c
+++ b/src/core/random.c
@@ -6,8 +6,9 @@
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+#include <stddef.h>
#include <stdlib.h>
-#include <ipxe/timer.h>
+#include <time.h>
static int32_t rnd_seed = 0;
@@ -30,8 +31,9 @@ void srandom ( unsigned int seed ) {
long int random ( void ) {
int32_t q;
- if ( ! rnd_seed ) /* Initialize linear congruential generator */
- srandom ( currticks() );
+ /* Initialize linear congruential generator */
+ if ( ! rnd_seed )
+ srandom ( time ( NULL ) );
/* simplified version of the LCG given in Bruce Schneier's
"Applied Cryptography" */
diff --git a/src/core/xfer.c b/src/core/xfer.c
index 0faf3292a..269359e15 100644
--- a/src/core/xfer.c
+++ b/src/core/xfer.c
@@ -60,7 +60,7 @@ static struct xfer_metadata dummy_metadata;
* @ret rc Return status code
*/
int xfer_vredirect ( struct interface *intf, int type, va_list args ) {
- struct interface tmp = INTF_INIT ( null_intf_desc );
+ struct interface tmp;
struct interface *dest;
xfer_vredirect_TYPE ( void * ) *op =
intf_get_dest_op_no_passthru ( intf, xfer_vredirect, &dest );
@@ -85,6 +85,7 @@ int xfer_vredirect ( struct interface *intf, int type, va_list args ) {
* If redirection fails, then send intf_close() to the
* parent interface.
*/
+ intf_temp_init ( &tmp, intf );
intf_plug ( &tmp, dest );
rc = xfer_vreopen ( dest, type, args );
if ( rc == 0 ) {