From 66ea4581256449fe9dcb26340851c09ffd9d6290 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sat, 13 Jul 2013 15:06:20 +0200 Subject: [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 --- src/net/netdev_settings.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/net/netdev_settings.c') diff --git a/src/net/netdev_settings.c b/src/net/netdev_settings.c index 3ea7ace..7215276 100644 --- a/src/net/netdev_settings.c +++ b/src/net/netdev_settings.c @@ -27,6 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include +#include /** @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, +}; -- cgit v1.1