[settings] Eliminate settings "tag magic"

Create an explicit concept of "settings scope" and eliminate the magic
values used for numerical setting tags.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2013-05-01 17:20:39 +01:00
parent b4ec6a6a68
commit 15d2f947f5
11 changed files with 82 additions and 170 deletions

View File

@@ -208,7 +208,6 @@ struct setting net80211_ssid_setting __setting ( SETTING_NETDEV_EXTRA ) = {
.name = "ssid",
.description = "Wireless SSID",
.type = &setting_type_string,
.tag = NET80211_SETTING_TAG_SSID,
};
/** Whether to use active scanning
@@ -221,7 +220,6 @@ struct setting net80211_active_setting __setting ( SETTING_NETDEV_EXTRA ) = {
.name = "active-scan",
.description = "Actively scan for wireless networks",
.type = &setting_type_int8,
.tag = NET80211_SETTING_TAG_ACTIVE_SCAN,
};
/** The cryptographic key to use
@@ -234,7 +232,6 @@ struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA ) = {
.name = "key",
.description = "Wireless encryption key",
.type = &setting_type_string,
.tag = NET80211_SETTING_TAG_KEY,
};
/** @} */

View File

@@ -230,7 +230,8 @@ static int dhcppkt_settings_applies ( struct settings *settings,
struct dhcp_packet *dhcppkt =
container_of ( settings, struct dhcp_packet, settings );
return dhcppkt_applies ( dhcppkt, setting->tag );
return ( ( setting->scope == NULL ) &&
dhcppkt_applies ( dhcppkt, setting->tag ) );
}
/**
@@ -299,6 +300,6 @@ void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data,
dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
( len - offsetof ( struct dhcphdr, options ) ),
dhcpopt_no_realloc );
settings_init ( &dhcppkt->settings,
&dhcppkt_settings_operations, &dhcppkt->refcnt, 0 );
settings_init ( &dhcppkt->settings, &dhcppkt_settings_operations,
&dhcppkt->refcnt, NULL );
}

View File

@@ -39,29 +39,13 @@ struct setting mac_setting __setting ( SETTING_NETDEV ) = {
.name = "mac",
.description = "MAC address",
.type = &setting_type_hex,
.tag = NETDEV_SETTING_TAG_MAC,
};
struct setting busid_setting __setting ( SETTING_NETDEV ) = {
.name = "busid",
.description = "Bus ID",
.type = &setting_type_hex,
.tag = NETDEV_SETTING_TAG_BUS_ID,
};
/**
* Check applicability of network device setting
*
* @v settings Settings block
* @v setting Setting
* @ret applies Setting applies within this settings block
*/
static int netdev_applies ( struct settings *settings __unused,
struct setting *setting ) {
return ( IS_NETDEV_SETTING_TAG ( setting->tag ) ||
dhcpopt_applies ( setting->tag ) );
}
/**
* Store value of network device setting
*
@@ -134,7 +118,6 @@ static void netdev_clear ( struct settings *settings ) {
/** Network device configuration settings operations */
struct settings_operations netdev_settings_operations = {
.applies = netdev_applies,
.store = netdev_store,
.fetch = netdev_fetch,
.clear = netdev_clear,