diff options
author | Michael Brown <mcb30@ipxe.org> | 2013-07-13 15:06:20 +0200 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2013-07-13 15:11:45 +0200 |
commit | 66ea4581256449fe9dcb26340851c09ffd9d6290 (patch) | |
tree | 89144d4ecd20220f55328cd9d267d27dc4495465 /src/net/netdev_settings.c | |
parent | dbfa13ff2cd7eb313d002f185f0274f2ac883231 (diff) | |
download | ipxe-66ea4581256449fe9dcb26340851c09ffd9d6290.tar.gz |
[settings] Make "netX" settings block function as a symbolic link
Add a facility for settings blocks to act as symbolic links to other
settings blocks, and reimplement the "netX" virtual settings block
using this facility.
The primary advantage of this approach is that unscoped settings such
as ${mac} and ${filename} will now reflect the settings obtained from
the most recently opened network device: in most cases, this will mean
the settings obtained from the most recent DHCP attempt. This should
improve conformance to the principle of least astonishment.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/net/netdev_settings.c')
-rw-r--r-- | src/net/netdev_settings.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/net/netdev_settings.c b/src/net/netdev_settings.c index 3ea7ace5..72152762 100644 --- a/src/net/netdev_settings.c +++ b/src/net/netdev_settings.c @@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include <ipxe/settings.h> #include <ipxe/device.h> #include <ipxe/netdevice.h> +#include <ipxe/init.h> /** @file * @@ -295,3 +296,51 @@ struct settings_operations netdev_settings_operations = { .fetch = netdev_fetch, .clear = netdev_clear, }; + +/** + * Redirect "netX" settings block + * + * @v settings Settings block + * @ret settings Underlying settings block + */ +static struct settings * netdev_redirect ( struct settings *settings ) { + struct net_device *netdev; + + /* Redirect to most recently opened network device */ + netdev = last_opened_netdev(); + if ( netdev ) { + return netdev_settings ( netdev ); + } else { + return settings; + } +} + +/** "netX" settings operations */ +static struct settings_operations netdev_redirect_settings_operations = { + .redirect = netdev_redirect, +}; + +/** "netX" settings */ +static struct settings netdev_redirect_settings = { + .refcnt = NULL, + .siblings = LIST_HEAD_INIT ( netdev_redirect_settings.siblings ), + .children = LIST_HEAD_INIT ( netdev_redirect_settings.children ), + .op = &netdev_redirect_settings_operations, +}; + +/** Initialise "netX" settings */ +static void netdev_redirect_settings_init ( void ) { + int rc; + + if ( ( rc = register_settings ( &netdev_redirect_settings, NULL, + "netX" ) ) != 0 ) { + DBG ( "Could not register netX settings: %s\n", + strerror ( rc ) ); + return; + } +} + +/** "netX" settings initialiser */ +struct init_fn netdev_redirect_settings_init_fn __init_fn ( INIT_LATE ) = { + .initialise = netdev_redirect_settings_init, +}; |