From f5fd4dec3bab362a2ff7844859914e1f191fb905 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 22 Mar 2011 16:56:35 +0000 Subject: [settings] Formalise notion of setting applicability Expose a function setting_applies() to allow a caller to determine whether or not a particular setting is applicable to a particular settings block. Restrict DHCP-backed settings blocks to accepting only DHCP-based settings. Restrict network device settings blocks to accepting only DHCP-based settings and network device-specific settings such as "mac". Inspired-by: Glenn Brown Signed-off-by: Michael Brown --- src/drivers/net/phantom/phantom.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/drivers') diff --git a/src/drivers/net/phantom/phantom.c b/src/drivers/net/phantom/phantom.c index 1060103c7..a55319ea6 100644 --- a/src/drivers/net/phantom/phantom.c +++ b/src/drivers/net/phantom/phantom.c @@ -1697,6 +1697,24 @@ phantom_clp_setting ( struct phantom_nic *phantom, struct setting *setting ) { return 0; } +/** + * Check applicability of Phantom CLP setting + * + * @v settings Settings block + * @v setting Setting + * @ret applies Setting applies within this settings block + */ +static int phantom_setting_applies ( struct settings *settings, + struct setting *setting ) { + struct phantom_nic *phantom = + container_of ( settings, struct phantom_nic, settings ); + unsigned int clp_setting; + + /* Find Phantom setting equivalent to iPXE setting */ + clp_setting = phantom_clp_setting ( phantom, setting ); + return ( clp_setting != 0 ); +} + /** * Store Phantom CLP setting * @@ -1716,8 +1734,7 @@ static int phantom_store_setting ( struct settings *settings, /* Find Phantom setting equivalent to iPXE setting */ clp_setting = phantom_clp_setting ( phantom, setting ); - if ( ! clp_setting ) - return -ENOTSUP; + assert ( clp_setting != 0 ); /* Store setting */ if ( ( rc = phantom_clp_store ( phantom, phantom->port, @@ -1750,8 +1767,7 @@ static int phantom_fetch_setting ( struct settings *settings, /* Find Phantom setting equivalent to iPXE setting */ clp_setting = phantom_clp_setting ( phantom, setting ); - if ( ! clp_setting ) - return -ENOTSUP; + assert ( clp_setting != 0 ); /* Fetch setting */ if ( ( read_len = phantom_clp_fetch ( phantom, phantom->port, @@ -1767,6 +1783,7 @@ static int phantom_fetch_setting ( struct settings *settings, /** Phantom CLP settings operations */ static struct settings_operations phantom_settings_operations = { + .applies = phantom_setting_applies, .store = phantom_store_setting, .fetch = phantom_fetch_setting, }; -- cgit v1.2.3-55-g7522