summaryrefslogtreecommitdiffstats
path: root/src/net/netdev_settings.c
diff options
context:
space:
mode:
authorMichael Brown2013-07-13 15:06:20 +0200
committerMichael Brown2013-07-13 15:11:45 +0200
commit66ea4581256449fe9dcb26340851c09ffd9d6290 (patch)
tree89144d4ecd20220f55328cd9d267d27dc4495465 /src/net/netdev_settings.c
parent[settings] Expose PCI configuration space via settings mechanism (diff)
downloadipxe-66ea4581256449fe9dcb26340851c09ffd9d6290.tar.gz
ipxe-66ea4581256449fe9dcb26340851c09ffd9d6290.tar.xz
ipxe-66ea4581256449fe9dcb26340851c09ffd9d6290.zip
[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.c49
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,
+};