[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

@@ -1183,25 +1183,4 @@ static inline u16 net80211_cts_duration ( struct net80211_device *dev,
net80211_duration ( dev, size, dev->rates[dev->rate] ) );
}
/** 802.11 device setting tag magic */
#define NET80211_SETTING_TAG_MAGIC 0x8211
/**
* Construct 802.11 setting tag
*
* @v id Unique identifier
* @ret tag Setting tag
*/
#define NET80211_SETTING_TAG( id ) \
NETDEV_SETTING_TAG ( ( NET80211_SETTING_TAG_MAGIC << 8 ) | (id) )
/** SSID setting tag */
#define NET80211_SETTING_TAG_SSID NET80211_SETTING_TAG ( 0x01 )
/** Active scanning setting tag */
#define NET80211_SETTING_TAG_ACTIVE_SCAN NET80211_SETTING_TAG ( 0x02 )
/** Wireless key setting tag */
#define NET80211_SETTING_TAG_KEY NET80211_SETTING_TAG ( 0x03 )
#endif

View File

@@ -411,38 +411,6 @@ struct net_driver {
/** Declare a network driver */
#define __net_driver __table_entry ( NET_DRIVERS, 01 )
/** Network device setting tag magic
*
* All DHCP option settings are deemed to be valid as network device
* settings. There are also some extra non-DHCP settings (such as
* "mac"), which are marked as being valid network device settings by
* using a magic tag value.
*/
#define NETDEV_SETTING_TAG_MAGIC 0xeb
/**
* Construct network device setting tag
*
* @v id Unique identifier
* @ret tag Setting tag
*/
#define NETDEV_SETTING_TAG( id ) ( ( NETDEV_SETTING_TAG_MAGIC << 24 ) | (id) )
/**
* Check if tag is a network device setting tag
*
* @v tag Setting tag
* @ret is_ours Tag is a network device setting tag
*/
#define IS_NETDEV_SETTING_TAG( tag ) \
( ( (tag) >> 24 ) == NETDEV_SETTING_TAG_MAGIC )
/** MAC address setting tag */
#define NETDEV_SETTING_TAG_MAC NETDEV_SETTING_TAG ( 0x01 )
/** Bus ID setting tag */
#define NETDEV_SETTING_TAG_BUS_ID NETDEV_SETTING_TAG ( 0x02 )
extern struct list_head net_devices;
extern struct net_device_operations null_netdev_operations;
extern struct settings_operations netdev_settings_operations;

View File

@@ -38,27 +38,14 @@ struct setting {
* The setting tag is a numerical description of the setting
* (such as a DHCP option number, or an SMBIOS structure and
* field number).
*
* Users can construct tags for settings that are not
* explicitly known to iPXE using the generic syntax for
* numerical settings. For example, the setting name "60"
* will be interpreted as referring to DHCP option 60 (the
* vendor class identifier).
*
* This creates a potential for namespace collisions, since
* the interpretation of the numerical description will vary
* according to the settings block. When a user attempts to
* fetch a generic numerical setting, we need to ensure that
* only the intended settings block interprets the numerical
* description. (For example, we do not want to attempt to
* retrieve the subnet mask from SMBIOS, or the system UUID
* from DHCP.)
*
* This potential problem is resolved by allowing the setting
* tag to include a "magic" value indicating the
* interpretation to be placed upon the numerical description.
*/
unsigned int tag;
/** Setting scope (or NULL)
*
* For historic reasons, a NULL scope with a non-zero tag
* indicates a DHCPv4 option setting.
*/
struct settings_scope *scope;
};
/** Configuration setting table */
@@ -134,12 +121,6 @@ struct settings {
struct refcnt *refcnt;
/** Name */
const char *name;
/** Tag magic
*
* This value will be ORed in to any numerical tags
* constructed by parse_setting_name().
*/
unsigned int tag_magic;
/** Parent settings block */
struct settings *parent;
/** Sibling settings blocks */
@@ -148,8 +129,44 @@ struct settings {
struct list_head children;
/** Settings block operations */
struct settings_operations *op;
/** Default scope for numerical settings constructed for this block */
struct settings_scope *default_scope;
};
/**
* A setting scope
*
* Users can construct tags for settings that are not explicitly known
* to iPXE using the generic syntax for numerical settings. For
* example, the setting name "60" will be interpreted as referring to
* DHCP option 60 (the vendor class identifier).
*
* This creates a potential for namespace collisions, since the
* interpretation of the numerical description will vary according to
* the settings block. When a user attempts to fetch a generic
* numerical setting, we need to ensure that only the intended
* settings blocks interpret this numerical description. (For
* example, we do not want to attempt to retrieve the subnet mask from
* SMBIOS, or the system UUID from DHCP.)
*
* This potential problem is resolved by including a user-invisible
* "scope" within the definition of each setting. Settings blocks may
* use this to determine whether or not the setting is applicable.
* Any settings constructed from a numerical description
* (e.g. "smbios/1.4.0") will be assigned the default scope of the
* settings block specified in the description (e.g. "smbios"); this
* provides behaviour matching the user's expectations in most
* circumstances.
*/
struct settings_scope {
/** Dummy field
*
* This is included only to ensure that pointers to different
* scopes always compare differently.
*/
uint8_t dummy;
} __attribute__ (( packed ));
/**
* A setting type
*
@@ -329,17 +346,17 @@ extern struct setting busid_setting __setting ( SETTING_NETDEV );
* @v settings Settings block
* @v op Settings block operations
* @v refcnt Containing object reference counter, or NULL
* @v tag_magic Tag magic
* @v default_scope Default scope
*/
static inline void settings_init ( struct settings *settings,
struct settings_operations *op,
struct refcnt *refcnt,
unsigned int tag_magic ) {
struct settings_scope *default_scope ) {
INIT_LIST_HEAD ( &settings->siblings );
INIT_LIST_HEAD ( &settings->children );
settings->op = op;
settings->refcnt = refcnt;
settings->tag_magic = tag_magic;
settings->default_scope = default_scope;
}
/**
@@ -351,7 +368,7 @@ static inline void settings_init ( struct settings *settings,
static inline void generic_settings_init ( struct generic_settings *generics,
struct refcnt *refcnt ) {
settings_init ( &generics->settings, &generic_settings_operations,
refcnt, 0 );
refcnt, NULL );
INIT_LIST_HEAD ( &generics->list );
}