david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[settings] Explicitly separate the concept of a completed fetched setting

The fetch_setting() family of functions may currently modify the
definition of the specified setting (e.g. to add missing type
information).  Clean up this interface by requiring callers to provide
an explicit buffer to contain the completed definition of the fetched
setting, if required.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-12-03 16:48:56 +00:00
parent a2638a8edd
commit 22001cb206
37 changed files with 620 additions and 573 deletions

View File

@ -51,7 +51,7 @@ static int guestinfo_channel;
*/
static int guestinfo_fetch_type ( struct settings *settings,
struct setting *setting,
struct setting_type *type,
const struct setting_type *type,
void *data, size_t len, int *found ) {
const char *parent_name = settings->parent->name;
char command[ 24 /* "info-get guestinfo.ipxe." */ +

View File

@ -117,7 +117,7 @@ enum cpuid_registers {
#define CPUID_NUM_REGISTERS( tag ) ( ( ( (tag) >> 16 ) & 0x3 ) + 1 )
/** CPUID settings scope */
static struct settings_scope cpuid_settings_scope;
static const struct settings_scope cpuid_settings_scope;
/**
* Check applicability of CPUID setting
@ -127,7 +127,7 @@ static struct settings_scope cpuid_settings_scope;
* @ret applies Setting applies within this settings block
*/
static int cpuid_settings_applies ( struct settings *settings __unused,
struct setting *setting ) {
const struct setting *setting ) {
return ( setting->scope == &cpuid_settings_scope );
}
@ -252,7 +252,7 @@ struct init_fn cpuid_settings_init_fn __init_fn ( INIT_NORMAL ) = {
};
/** CPUID predefined settings */
struct setting cpuid_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
const struct setting cpuid_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
{
.name = "cpuvendor",
.description = "CPU vendor",

View File

@ -108,7 +108,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define MEMMAP_SCALE( tag ) ( (tag) & 0x3f )
/** Memory map settings scope */
static struct settings_scope memmap_settings_scope;
static const struct settings_scope memmap_settings_scope;
/**
* Check applicability of memory map setting
@ -118,7 +118,7 @@ static struct settings_scope memmap_settings_scope;
* @ret applies Setting applies within this settings block
*/
static int memmap_settings_applies ( struct settings *settings __unused,
struct setting *setting ) {
const struct setting *setting ) {
return ( setting->scope == &memmap_settings_scope );
}
@ -231,7 +231,7 @@ struct init_fn memmap_settings_init_fn __init_fn ( INIT_NORMAL ) = {
};
/** Memory map predefined settings */
struct setting memmap_predefined_settings[] __setting ( SETTING_MISC ) = {
const struct setting memmap_predefined_settings[] __setting ( SETTING_MISC ) = {
{
.name = "memsize",
.description = "Memory size (in MB)",

View File

@ -193,7 +193,7 @@ static int nvo_save ( struct nvo_block *nvo ) {
* @ret applies Setting applies within this settings block
*/
int nvo_applies ( struct settings *settings __unused,
struct setting *setting ) {
const struct setting *setting ) {
return ( ( setting->scope == NULL ) &&
dhcpopt_applies ( setting->tag ) );
@ -208,7 +208,7 @@ int nvo_applies ( struct settings *settings __unused,
* @v len Length of setting data
* @ret rc Return status code
*/
static int nvo_store ( struct settings *settings, struct setting *setting,
static int nvo_store ( struct settings *settings, const struct setting *setting,
const void *data, size_t len ) {
struct nvo_block *nvo =
container_of ( settings, struct nvo_block, settings );

File diff suppressed because it is too large Load Diff

View File

@ -128,8 +128,8 @@ static int clientcert_apply_settings ( void ) {
/* Fetch new client certificate, if any */
free ( cert );
if ( ( len = fetch_setting_copy ( NULL, &cert_setting,
&cert ) ) >= 0 ) {
if ( ( len = fetch_raw_setting_copy ( NULL, &cert_setting,
&cert ) ) >= 0 ) {
client_certificate.data = cert;
client_certificate.len = len;
}
@ -140,8 +140,8 @@ static int clientcert_apply_settings ( void ) {
/* Fetch new client private key, if any */
free ( key );
if ( ( len = fetch_setting_copy ( NULL, &privkey_setting,
&key ) ) >= 0 ) {
if ( ( len = fetch_raw_setting_copy ( NULL, &privkey_setting,
&key ) ) >= 0 ) {
client_private_key.data = key;
client_private_key.len = len;
}

View File

@ -100,8 +100,8 @@ static void rootcert_init ( void ) {
/* Fetch copy of "trust" setting, if it exists. This
* memory will never be freed.
*/
if ( ( len = fetch_setting_copy ( NULL, &trust_setting,
&external ) ) >= 0 ) {
if ( ( len = fetch_raw_setting_copy ( NULL, &trust_setting,
&external ) ) >= 0 ) {
root_certificates.fingerprints = external;
root_certificates.count = ( len / FINGERPRINT_LEN );
}

View File

@ -107,7 +107,7 @@ static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
* @v count Maximum number of IP addresses
*/
static void ibft_set_ipaddr_setting ( struct ibft_ipaddr *ipaddr,
struct setting *setting,
const struct setting *setting,
unsigned int count ) {
struct in_addr in[count];
unsigned int i;
@ -183,11 +183,13 @@ static int ibft_set_string ( struct ibft_strings *strings,
*/
static int ibft_set_string_setting ( struct ibft_strings *strings,
struct ibft_string *string,
struct setting *setting ) {
const struct setting *setting ) {
struct settings *origin;
struct setting fetched;
int len;
char *dest;
len = fetch_setting_len ( NULL, setting );
len = fetch_setting ( NULL, setting, &origin, &fetched, NULL, 0 );
if ( len < 0 ) {
string->offset = 0;
string->len = 0;
@ -197,7 +199,7 @@ static int ibft_set_string_setting ( struct ibft_strings *strings,
dest = ibft_alloc_string ( strings, string, len );
if ( ! dest )
return -ENOBUFS;
fetch_string_setting ( NULL, setting, dest, ( len + 1 ) );
fetch_string_setting ( origin, &fetched, dest, ( len + 1 ));
return 0;
}

View File

@ -32,7 +32,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/
/** PCI device settings scope */
static struct settings_scope pci_settings_scope;
static const struct settings_scope pci_settings_scope;
/**
* Check applicability of PCI device setting
@ -42,7 +42,7 @@ static struct settings_scope pci_settings_scope;
* @ret applies Setting applies within this settings block
*/
static int pci_settings_applies ( struct settings *settings __unused,
struct setting *setting ) {
const struct setting *setting ) {
return ( setting->scope == &pci_settings_scope );
}

View File

@ -1455,7 +1455,7 @@ static struct net_device_operations phantom_operations = {
*/
/** Phantom CLP settings scope */
static struct settings_scope phantom_settings_scope;
static const struct settings_scope phantom_settings_scope;
/** Phantom CLP data
*
@ -1656,7 +1656,7 @@ static int phantom_clp_fetch ( struct phantom_nic *phantom, unsigned int port,
/** A Phantom CLP setting */
struct phantom_clp_setting {
/** iPXE setting */
struct setting *setting;
const struct setting *setting;
/** Setting number */
unsigned int clp_setting;
};
@ -1673,7 +1673,8 @@ static struct phantom_clp_setting clp_settings[] = {
* @v clp_setting Setting number, or 0 if not found
*/
static unsigned int
phantom_clp_setting ( struct phantom_nic *phantom, struct setting *setting ) {
phantom_clp_setting ( struct phantom_nic *phantom,
const struct setting *setting ) {
struct phantom_clp_setting *clp_setting;
unsigned int i;
@ -1703,7 +1704,7 @@ phantom_clp_setting ( struct phantom_nic *phantom, struct setting *setting ) {
* @ret applies Setting applies within this settings block
*/
static int phantom_setting_applies ( struct settings *settings,
struct setting *setting ) {
const struct setting *setting ) {
struct phantom_nic *phantom =
container_of ( settings, struct phantom_nic, settings );
unsigned int clp_setting;
@ -1723,7 +1724,7 @@ static int phantom_setting_applies ( struct settings *settings,
* @ret rc Return status code
*/
static int phantom_store_setting ( struct settings *settings,
struct setting *setting,
const struct setting *setting,
const void *data, size_t len ) {
struct phantom_nic *phantom =
container_of ( settings, struct phantom_nic, settings );

View File

@ -58,8 +58,10 @@ static int show_exec ( int argc, char **argv ) {
struct show_options opts;
struct named_setting setting;
struct settings *origin;
struct setting fetched;
char name_buf[32];
char *value;
int len;
int rc;
/* Parse options */
@ -71,19 +73,16 @@ static int show_exec ( int argc, char **argv ) {
goto err_parse_setting;
/* Fetch formatted setting value */
if ( ( rc = fetchf_setting_copy ( setting.settings, &setting.setting,
&value ) ) < 0 ) {
if ( ( len = fetchf_setting_copy ( setting.settings, &setting.setting,
&origin, &fetched, &value ) ) < 0 ) {
rc = len;
printf ( "Could not find \"%s\": %s\n",
setting.setting.name, strerror ( rc ) );
goto err_fetchf;
}
/* Fetch origin and format fully-qualified name */
origin = fetch_setting_origin ( setting.settings, &setting.setting );
assert ( origin != NULL );
setting_name ( origin, &setting.setting, name_buf, sizeof ( name_buf ));
/* Print setting value */
setting_name ( origin, &fetched, name_buf, sizeof ( name_buf ) );
printf ( "%s = %s\n", name_buf, value );
/* Success */
@ -234,7 +233,8 @@ static int read_value ( struct named_setting *setting, char **args __unused,
/* Read existing value, treating errors as equivalent to an
* empty initial setting.
*/
fetchf_setting_copy ( setting->settings, &setting->setting, &existing );
fetchf_setting_copy ( setting->settings, &setting->setting,
NULL, &setting->setting, &existing );
/* Read new value */
if ( ( rc = readline_history ( NULL, existing, NULL, value ) ) != 0 )
@ -294,12 +294,11 @@ static int inc_exec ( int argc, char **argv ) {
( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
goto err_parse_increment;
/* Fetch existing setting value, if any, allowing for the fact
* that numeric settings are big-endian and variable-length.
/* Read existing value, treating errors as equivalent to a
* zero-valued :int32 initial setting.
*/
if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
&value ) ) != 0 ) {
/* Treat as a non-existent :int32 setting with a zero value */
NULL, &setting.setting, &value ) ) != 0 ) {
value = 0;
if ( ! setting.setting.type )
setting.setting.type = &setting_type_int32;

View File

@ -68,8 +68,8 @@ static int pciscan_exec ( int argc, char **argv ) {
goto err_parse_setting;
/* Determine starting bus:dev.fn address */
if ( ( len = fetch_uint_setting ( setting.settings, &setting.setting,
&prev ) ) < 0 ) {
if ( ( len = fetchn_setting ( setting.settings, &setting.setting,
NULL, &setting.setting, &prev ) ) < 0 ) {
/* Setting not yet defined: start searching from 00:00.0 */
prev = 0;
} else {

View File

@ -72,11 +72,16 @@ struct setting_row_widget {
* Valid only for rows that lead to new settings blocks.
*/
struct settings *settings;
/** Configuration setting origin
*
* Valid only for rows that represent individual settings.
*/
struct settings *origin;
/** Configuration setting
*
* Valid only for rows that represent individual settings.
*/
struct setting *setting;
struct setting setting;
/** Screen row */
unsigned int row;
/** Screen column */
@ -85,8 +90,6 @@ struct setting_row_widget {
struct edit_box editbox;
/** Editing in progress flag */
int editing;
/** Setting originates from this block flag */
int originates_here;
/** Buffer for setting's value */
char value[256]; /* enough size for a DHCP string */
};
@ -115,7 +118,6 @@ struct setting_widget {
static unsigned int select_setting_row ( struct setting_widget *widget,
unsigned int index ) {
struct settings *settings;
struct settings *origin;
struct setting *setting;
unsigned int count = 0;
@ -147,18 +149,13 @@ static unsigned int select_setting_row ( struct setting_widget *widget,
if ( ! setting_applies ( widget->settings, setting ) )
continue;
if ( count++ == index ) {
widget->row.setting = setting;
/* Read current setting value */
fetchf_setting ( widget->settings, widget->row.setting,
/* Read current setting value and origin */
fetchf_setting ( widget->settings, setting,
&widget->row.origin,
&widget->row.setting,
widget->row.value,
sizeof ( widget->row.value ) );
/* Check setting's origin */
origin = fetch_setting_origin ( widget->settings,
widget->row.setting );
widget->row.originates_here =
( origin == widget->settings );
}
}
@ -209,7 +206,7 @@ static void draw_setting_row ( struct setting_widget *widget ) {
/* Construct dot-padded name */
memset ( text.name, '.', sizeof ( text.name ) );
string_copy ( text.name, widget->row.setting->name,
string_copy ( text.name, widget->row.setting.name,
sizeof ( text.name ) );
/* Construct space-padded value */
@ -222,8 +219,10 @@ static void draw_setting_row ( struct setting_widget *widget ) {
}
/* Print row */
if ( widget->row.originates_here || widget->row.settings )
if ( ( widget->row.origin == widget->settings ) ||
( widget->row.settings != NULL ) ) {
attron ( A_BOLD );
}
mvprintw ( widget->row.row, widget->row.col, "%s", text.start );
attroff ( A_BOLD );
move ( widget->row.row, widget->row.col + curs_offset );
@ -237,7 +236,7 @@ static void draw_setting_row ( struct setting_widget *widget ) {
* @ret key Key returned to application, or zero
*/
static int edit_setting ( struct setting_widget *widget, int key ) {
assert ( widget->row.setting != NULL );
assert ( widget->row.setting.name != NULL );
widget->row.editing = 1;
return edit_editbox ( &widget->row.editbox, key );
}
@ -248,8 +247,8 @@ static int edit_setting ( struct setting_widget *widget, int key ) {
* @v widget Setting widget
*/
static int save_setting ( struct setting_widget *widget ) {
assert ( widget->row.setting != NULL );
return storef_setting ( widget->settings, widget->row.setting,
assert ( widget->row.setting.name != NULL );
return storef_setting ( widget->settings, &widget->row.setting,
widget->row.value );
}
@ -344,28 +343,26 @@ static void draw_title_row ( struct setting_widget *widget ) {
* @v widget Setting widget
*/
static void draw_info_row ( struct setting_widget *widget ) {
struct settings *origin;
char buf[32];
/* Draw nothing unless this row represents a setting */
clearmsg ( INFO_ROW );
clearmsg ( INFO_ROW + 1 );
if ( ! widget->row.setting )
if ( ! widget->row.setting.name )
return;
/* Determine a suitable setting name */
origin = fetch_setting_origin ( widget->settings, widget->row.setting );
if ( ! origin )
origin = widget->settings;
setting_name ( origin, widget->row.setting, buf, sizeof ( buf ) );
setting_name ( ( widget->row.origin ?
widget->row.origin : widget->settings ),
&widget->row.setting, buf, sizeof ( buf ) );
/* Draw row */
attron ( A_BOLD );
msg ( INFO_ROW, "%s - %s", buf, widget->row.setting->description );
msg ( INFO_ROW, "%s - %s", buf, widget->row.setting.description );
attroff ( A_BOLD );
color_set ( CPAIR_URL, NULL );
msg ( ( INFO_ROW + 1 ), "http://ipxe.org/cfg/%s",
widget->row.setting->name );
widget->row.setting.name );
color_set ( CPAIR_NORMAL, NULL );
}
@ -384,7 +381,7 @@ static void draw_instruction_row ( struct setting_widget *widget ) {
} else {
msg ( INSTRUCTION_ROW,
"%sCtrl-X - exit configuration utility",
( widget->row.originates_here ?
( ( widget->row.origin == widget->settings ) ?
"Ctrl-D - delete setting" INSTRUCTION_PAD : "" ) );
}
}
@ -479,7 +476,7 @@ static int main_loop ( struct settings *settings ) {
if ( widget.row.editing ) {
/* Sanity check */
assert ( widget.row.setting != NULL );
assert ( widget.row.setting.name != NULL );
/* Redraw edit box */
color_set ( CPAIR_EDIT, NULL );
@ -530,10 +527,10 @@ static int main_loop ( struct settings *settings ) {
move = +widget.num_rows;
break;
case CTRL_D:
if ( ! widget.row.setting )
if ( ! widget.row.setting.name )
break;
if ( ( rc = delete_setting ( widget.settings,
widget.row.setting ) ) != 0 ) {
&widget.row.setting ) ) != 0 ) {
alert ( " %s ", strerror ( rc ) );
}
select_setting_row ( &widget, widget.current );
@ -550,7 +547,7 @@ static int main_loop ( struct settings *settings ) {
}
/* Fall through */
default:
if ( widget.row.setting ) {
if ( widget.row.setting.name ) {
edit_setting ( &widget, key );
redraw = 1;
}

View File

@ -1093,7 +1093,7 @@ struct net80211_wlan
/** 802.11 encryption key setting */
extern struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA );
extern const struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA );
/**

View File

@ -45,7 +45,8 @@ struct nvo_block {
/** Name of non-volatile options settings block */
#define NVO_SETTINGS_NAME "nvo"
extern int nvo_applies ( struct settings *settings, struct setting *setting );
extern int nvo_applies ( struct settings *settings,
const struct setting *setting );
extern void nvo_init ( struct nvo_block *nvo, struct nvs_device *nvs,
size_t address, size_t len,
int ( * resize ) ( struct nvo_block *nvo, size_t len ),

View File

@ -32,7 +32,7 @@ struct setting {
* This identifies the type of setting (e.g. string, IPv4
* address, etc.).
*/
struct setting_type *type;
const struct setting_type *type;
/** Setting tag, if applicable
*
* The setting tag is a numerical description of the setting
@ -45,7 +45,7 @@ struct setting {
* For historic reasons, a NULL scope with a non-zero tag
* indicates a DHCPv4 option setting.
*/
struct settings_scope *scope;
const struct settings_scope *scope;
};
/** Configuration setting table */
@ -90,7 +90,7 @@ struct settings_operations {
* @ret applies Setting applies within this settings block
*/
int ( * applies ) ( struct settings *settings,
struct setting *setting );
const struct setting *setting );
/** Store value of setting
*
* @v settings Settings block
@ -99,7 +99,8 @@ struct settings_operations {
* @v len Length of setting data
* @ret rc Return status code
*/
int ( * store ) ( struct settings *settings, struct setting *setting,
int ( * store ) ( struct settings *settings,
const struct setting *setting,
const void *data, size_t len );
/** Fetch value of setting
*
@ -136,7 +137,7 @@ struct settings {
/** Settings block operations */
struct settings_operations *op;
/** Default scope for numerical settings constructed for this block */
struct settings_scope *default_scope;
const struct settings_scope *default_scope;
};
/**
@ -193,7 +194,7 @@ struct setting_type {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
int ( * parse ) ( struct setting_type *type, const char *value,
int ( * parse ) ( const struct setting_type *type, const char *value,
void *buf, size_t len );
/** Format setting value as a string
*
@ -204,7 +205,7 @@ struct setting_type {
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
int ( * format ) ( struct setting_type *type, const void *raw,
int ( * format ) ( const struct setting_type *type, const void *raw,
size_t raw_len, char *buf, size_t len );
/** Convert number to setting value
*
@ -214,7 +215,8 @@ struct setting_type {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
int ( * denumerate ) ( struct setting_type *type, unsigned long value,
int ( * denumerate ) ( const struct setting_type *type,
unsigned long value,
void *buf, size_t len );
/** Convert setting value to number
*
@ -224,7 +226,7 @@ struct setting_type {
* @v value Numeric value to fill in
* @ret rc Return status code
*/
int ( * numerate ) ( struct setting_type *type, const void *raw,
int ( * numerate ) ( const struct setting_type *type, const void *raw,
size_t raw_len, unsigned long *value );
};
@ -256,7 +258,7 @@ struct settings_applicator {
/** A built-in setting */
struct builtin_setting {
/** Setting */
struct setting *setting;
const struct setting *setting;
/** Fetch setting value
*
* @v data Buffer to fill with setting data
@ -273,7 +275,7 @@ struct builtin_setting {
#define __builtin_setting __table_entry ( BUILTIN_SETTINGS, 01 )
/** Built-in setting scope */
extern struct settings_scope builtin_scope;
extern const struct settings_scope builtin_scope;
/**
* A generic settings block
@ -291,7 +293,7 @@ typedef struct settings * ( *get_child_settings_t ) ( struct settings *settings,
const char *name );
extern struct settings_operations generic_settings_operations;
extern int generic_settings_store ( struct settings *settings,
struct setting *setting,
const struct setting *setting,
const void *data, size_t len );
extern int generic_settings_fetch ( struct settings *settings,
struct setting *setting,
@ -304,42 +306,50 @@ extern void unregister_settings ( struct settings *settings );
extern struct settings * settings_target ( struct settings *settings );
extern int setting_applies ( struct settings *settings,
struct setting *setting );
extern int store_setting ( struct settings *settings, struct setting *setting,
const struct setting *setting );
extern int store_setting ( struct settings *settings,
const struct setting *setting,
const void *data, size_t len );
extern int fetch_setting ( struct settings *settings, struct setting *setting,
extern int fetch_setting ( struct settings *settings,
const struct setting *setting,
struct settings **origin, struct setting *fetched,
void *data, size_t len );
extern struct settings * fetch_setting_origin ( struct settings *settings,
struct setting *setting );
extern int fetch_setting_len ( struct settings *settings,
struct setting *setting );
extern int fetch_setting_copy ( struct settings *settings,
struct setting *setting, void **data );
const struct setting *setting,
struct settings **origin,
struct setting *fetched, void **data );
extern int fetch_raw_setting ( struct settings *settings,
const struct setting *setting,
void *data, size_t len );
extern int fetch_raw_setting_copy ( struct settings *settings,
const struct setting *setting,
void **data );
extern int fetch_string_setting ( struct settings *settings,
struct setting *setting,
const struct setting *setting,
char *data, size_t len );
extern int fetch_string_setting_copy ( struct settings *settings,
struct setting *setting,
const struct setting *setting,
char **data );
extern int fetch_ipv4_array_setting ( struct settings *settings,
struct setting *setting,
struct in_addr *inp,
unsigned int count );
const struct setting *setting,
struct in_addr *inp, unsigned int count );
extern int fetch_ipv4_setting ( struct settings *settings,
struct setting *setting, struct in_addr *inp );
const struct setting *setting,
struct in_addr *inp );
extern int fetch_int_setting ( struct settings *settings,
struct setting *setting, long *value );
const struct setting *setting, long *value );
extern int fetch_uint_setting ( struct settings *settings,
struct setting *setting,
const struct setting *setting,
unsigned long *value );
extern long fetch_intz_setting ( struct settings *settings,
struct setting *setting );
const struct setting *setting );
extern unsigned long fetch_uintz_setting ( struct settings *settings,
struct setting *setting );
const struct setting *setting );
extern int fetch_uuid_setting ( struct settings *settings,
struct setting *setting, union uuid *uuid );
const struct setting *setting,
union uuid *uuid );
extern void clear_settings ( struct settings *settings );
extern int setting_cmp ( struct setting *a, struct setting *b );
extern int setting_cmp ( const struct setting *a, const struct setting *b );
extern struct settings * find_child_settings ( struct settings *parent,
const char *name );
@ -351,61 +361,68 @@ extern struct setting * find_setting ( const char *name );
extern int parse_setting_name ( char *name, get_child_settings_t get_child,
struct settings **settings,
struct setting *setting );
extern int setting_name ( struct settings *settings, struct setting *setting,
extern int setting_name ( struct settings *settings,
const struct setting *setting,
char *buf, size_t len );
extern int setting_format ( struct setting_type *type, const void *raw,
extern int setting_format ( const struct setting_type *type, const void *raw,
size_t raw_len, char *buf, size_t len );
extern int setting_parse ( struct setting_type *type, const char *value,
extern int setting_parse ( const struct setting_type *type, const char *value,
void *buf, size_t len );
extern int setting_numerate ( struct setting_type *type, const void *raw,
extern int setting_numerate ( const struct setting_type *type, const void *raw,
size_t raw_len, unsigned long *value );
extern int setting_denumerate ( struct setting_type *type, unsigned long value,
void *buf, size_t len );
extern int fetchf_setting ( struct settings *settings, struct setting *setting,
extern int setting_denumerate ( const struct setting_type *type,
unsigned long value, void *buf, size_t len );
extern int fetchf_setting ( struct settings *settings,
const struct setting *setting,
struct settings **origin, struct setting *fetched,
char *buf, size_t len );
extern int fetchf_setting_copy ( struct settings *settings,
struct setting *setting, char **value );
const struct setting *setting,
struct settings **origin,
struct setting *fetched, char **value );
extern int storef_setting ( struct settings *settings,
struct setting *setting,
const char *value );
extern int fetchn_setting ( struct settings *settings, struct setting *setting,
const struct setting *setting, const char *value );
extern int fetchn_setting ( struct settings *settings,
const struct setting *setting,
struct settings **origin, struct setting *fetched,
unsigned long *value );
extern int storen_setting ( struct settings *settings, struct setting *setting,
extern int storen_setting ( struct settings *settings,
const struct setting *setting,
unsigned long value );
extern char * expand_settings ( const char *string );
extern struct setting_type setting_type_string __setting_type;
extern struct setting_type setting_type_uristring __setting_type;
extern struct setting_type setting_type_ipv4 __setting_type;
extern struct setting_type setting_type_ipv6 __setting_type;
extern struct setting_type setting_type_int8 __setting_type;
extern struct setting_type setting_type_int16 __setting_type;
extern struct setting_type setting_type_int32 __setting_type;
extern struct setting_type setting_type_uint8 __setting_type;
extern struct setting_type setting_type_uint16 __setting_type;
extern struct setting_type setting_type_uint32 __setting_type;
extern struct setting_type setting_type_hex __setting_type;
extern struct setting_type setting_type_hexhyp __setting_type;
extern struct setting_type setting_type_hexraw __setting_type;
extern struct setting_type setting_type_uuid __setting_type;
extern struct setting_type setting_type_busdevfn __setting_type;
extern const struct setting_type setting_type_string __setting_type;
extern const struct setting_type setting_type_uristring __setting_type;
extern const struct setting_type setting_type_ipv4 __setting_type;
extern const struct setting_type setting_type_ipv6 __setting_type;
extern const struct setting_type setting_type_int8 __setting_type;
extern const struct setting_type setting_type_int16 __setting_type;
extern const struct setting_type setting_type_int32 __setting_type;
extern const struct setting_type setting_type_uint8 __setting_type;
extern const struct setting_type setting_type_uint16 __setting_type;
extern const struct setting_type setting_type_uint32 __setting_type;
extern const struct setting_type setting_type_hex __setting_type;
extern const struct setting_type setting_type_hexhyp __setting_type;
extern const struct setting_type setting_type_hexraw __setting_type;
extern const struct setting_type setting_type_uuid __setting_type;
extern const struct setting_type setting_type_busdevfn __setting_type;
extern struct setting ip_setting __setting ( SETTING_IPv4 );
extern struct setting netmask_setting __setting ( SETTING_IPv4 );
extern struct setting gateway_setting __setting ( SETTING_IPv4 );
extern struct setting dns_setting __setting ( SETTING_IPv4_EXTRA );
extern struct setting hostname_setting __setting ( SETTING_HOST );
extern struct setting domain_setting __setting ( SETTING_IPv4_EXTRA );
extern struct setting filename_setting __setting ( SETTING_BOOT );
extern struct setting root_path_setting __setting ( SETTING_SANBOOT );
extern struct setting username_setting __setting ( SETTING_AUTH );
extern struct setting password_setting __setting ( SETTING_AUTH );
extern struct setting priority_setting __setting ( SETTING_MISC );
extern struct setting uuid_setting __setting ( SETTING_HOST );
extern struct setting next_server_setting __setting ( SETTING_BOOT );
extern struct setting mac_setting __setting ( SETTING_NETDEV );
extern struct setting busid_setting __setting ( SETTING_NETDEV );
extern struct setting user_class_setting __setting ( SETTING_HOST_EXTRA );
extern const struct setting ip_setting __setting ( SETTING_IPv4 );
extern const struct setting netmask_setting __setting ( SETTING_IPv4 );
extern const struct setting gateway_setting __setting ( SETTING_IPv4 );
extern const struct setting dns_setting __setting ( SETTING_IPv4_EXTRA );
extern const struct setting hostname_setting __setting ( SETTING_HOST );
extern const struct setting domain_setting __setting ( SETTING_IPv4_EXTRA );
extern const struct setting filename_setting __setting ( SETTING_BOOT );
extern const struct setting root_path_setting __setting ( SETTING_SANBOOT );
extern const struct setting username_setting __setting ( SETTING_AUTH );
extern const struct setting password_setting __setting ( SETTING_AUTH );
extern const struct setting priority_setting __setting ( SETTING_MISC );
extern const struct setting uuid_setting __setting ( SETTING_HOST );
extern const struct setting next_server_setting __setting ( SETTING_BOOT );
extern const struct setting mac_setting __setting ( SETTING_NETDEV );
extern const struct setting busid_setting __setting ( SETTING_NETDEV );
extern const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA );
/**
* Initialise a settings block
@ -418,7 +435,7 @@ extern struct setting user_class_setting __setting ( SETTING_HOST_EXTRA );
static inline void settings_init ( struct settings *settings,
struct settings_operations *op,
struct refcnt *refcnt,
struct settings_scope *default_scope ) {
const struct settings_scope *default_scope ){
INIT_LIST_HEAD ( &settings->siblings );
INIT_LIST_HEAD ( &settings->children );
settings->op = op;
@ -447,20 +464,21 @@ static inline void generic_settings_init ( struct generic_settings *generics,
* @ret rc Return status code
*/
static inline int delete_setting ( struct settings *settings,
struct setting *setting ) {
const struct setting *setting ) {
return store_setting ( settings, setting, NULL, 0 );
}
/**
* Check existence of setting
* Check existence of predefined setting
*
* @v settings Settings block, or NULL to search all blocks
* @v setting Setting to fetch
* @ret exists Setting exists
*/
static inline int setting_exists ( struct settings *settings,
struct setting *setting ) {
return ( fetch_setting_len ( settings, setting ) >= 0 );
const struct setting *setting ) {
return ( fetch_setting ( settings, setting, NULL, NULL,
NULL, 0 ) >= 0 );
}
#endif /* _IPXE_SETTINGS_H */

View File

@ -276,7 +276,9 @@ static int efi_snp_hii_fetch ( struct efi_snp_device *snpdev,
const char *key, const char *value,
wchar_t **results, int *have_setting ) {
struct settings *settings = efi_snp_hii_settings ( snpdev );
struct settings *origin;
struct setting *setting;
struct setting fetched;
int len;
char *buf;
char *encoded;
@ -311,7 +313,8 @@ static int efi_snp_hii_fetch ( struct efi_snp_device *snpdev,
if ( setting_exists ( settings, setting ) ) {
/* Calculate formatted length */
len = fetchf_setting ( settings, setting, NULL, 0 );
len = fetchf_setting ( settings, setting, &origin, &fetched,
NULL, 0 );
if ( len < 0 ) {
rc = len;
DBGC ( snpdev, "SNPDEV %p could not fetch %s: %s\n",
@ -328,7 +331,8 @@ static int efi_snp_hii_fetch ( struct efi_snp_device *snpdev,
encoded = ( buf + len + 1 /* NUL */ );
/* Format value */
fetchf_setting ( settings, setting, buf, ( len + 1 /* NUL */ ));
fetchf_setting ( origin, &fetched, NULL, NULL, buf,
( len + 1 /* NUL */ ) );
for ( i = 0 ; i < len ; i++ ) {
sprintf ( ( encoded + ( 4 * i ) ), "%04x",
*( ( uint8_t * ) buf + i ) );

View File

@ -28,7 +28,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/smbios.h>
/** SMBIOS settings scope */
static struct settings_scope smbios_settings_scope;
static const struct settings_scope smbios_settings_scope;
/**
* Construct SMBIOS raw-data tag
@ -63,7 +63,7 @@ static struct settings_scope smbios_settings_scope;
* @ret applies Setting applies within this settings block
*/
static int smbios_applies ( struct settings *settings __unused,
struct setting *setting ) {
const struct setting *setting ) {
return ( setting->scope == &smbios_settings_scope );
}
@ -188,7 +188,7 @@ struct init_fn smbios_init_fn __init_fn ( INIT_NORMAL ) = {
};
/** UUID setting obtained via SMBIOS */
struct setting uuid_setting __setting ( SETTING_HOST ) = {
const struct setting uuid_setting __setting ( SETTING_HOST ) = {
.name = "uuid",
.description = "UUID",
.tag = SMBIOS_RAW_TAG ( SMBIOS_TYPE_SYSTEM_INFORMATION,
@ -198,7 +198,7 @@ struct setting uuid_setting __setting ( SETTING_HOST ) = {
};
/** Other SMBIOS predefined settings */
struct setting smbios_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
const struct setting smbios_predefined_settings[] __setting ( SETTING_HOST_EXTRA ) = {
{
.name = "manufacturer",
.description = "Manufacturer",

View File

@ -204,7 +204,7 @@ struct settings_applicator net80211_applicator __settings_applicator = {
* If this is blank, we scan for all networks and use the one with the
* greatest signal strength.
*/
struct setting net80211_ssid_setting __setting ( SETTING_NETDEV_EXTRA ) = {
const struct setting net80211_ssid_setting __setting ( SETTING_NETDEV_EXTRA ) = {
.name = "ssid",
.description = "Wireless SSID",
.type = &setting_type_string,
@ -216,7 +216,7 @@ struct setting net80211_ssid_setting __setting ( SETTING_NETDEV_EXTRA ) = {
* active scan (send probe packets). If this setting is nonzero, an
* active scan on the 2.4GHz band will be used to associate.
*/
struct setting net80211_active_setting __setting ( SETTING_NETDEV_EXTRA ) = {
const struct setting net80211_active_setting __setting ( SETTING_NETDEV_EXTRA ) = {
.name = "active-scan",
.description = "Actively scan for wireless networks",
.type = &setting_type_int8,
@ -228,7 +228,7 @@ struct setting net80211_active_setting __setting ( SETTING_NETDEV_EXTRA ) = {
* normal iPXE method for entering hex settings; an ASCII string of
* hex characters will not behave as expected.
*/
struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA ) = {
const struct setting net80211_key_setting __setting ( SETTING_NETDEV_EXTRA ) = {
.name = "key",
.description = "Wireless encryption key",
.type = &setting_type_string,

View File

@ -236,8 +236,8 @@ static int trivial_init ( struct net80211_device *dev )
dev->associating->crypto == NET80211_CRYPT_NONE )
return 0; /* no crypto? OK. */
len = fetch_setting ( netdev_settings ( dev->netdev ),
&net80211_key_setting, key, WEP_MAX_KEY );
len = fetch_raw_setting ( netdev_settings ( dev->netdev ),
&net80211_key_setting, key, WEP_MAX_KEY );
if ( len <= 0 ) {
DBGC ( dev, "802.11 %p cannot do WEP without a key\n", dev );
@ -278,8 +278,8 @@ static int trivial_change_key ( struct net80211_device *dev )
if ( ! dev->crypto || ( dev->crypto->init != wep_init ) )
change ^= 1;
len = fetch_setting ( netdev_settings ( dev->netdev ),
&net80211_key_setting, key, WEP_MAX_KEY );
len = fetch_raw_setting ( netdev_settings ( dev->netdev ),
&net80211_key_setting, key, WEP_MAX_KEY );
if ( len <= 0 )
change ^= 1;

View File

@ -226,7 +226,7 @@ int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
* @ret applies Setting applies within this settings block
*/
static int dhcppkt_settings_applies ( struct settings *settings,
struct setting *setting ) {
const struct setting *setting ) {
struct dhcp_packet *dhcppkt =
container_of ( settings, struct dhcp_packet, settings );
@ -244,7 +244,7 @@ static int dhcppkt_settings_applies ( struct settings *settings,
* @ret rc Return status code
*/
static int dhcppkt_settings_store ( struct settings *settings,
struct setting *setting,
const struct setting *setting,
const void *data, size_t len ) {
struct dhcp_packet *dhcppkt =
container_of ( settings, struct dhcp_packet, settings );

View File

@ -49,8 +49,8 @@ static int copy_encap_settings ( struct dhcp_packet *dest,
struct setting setting = { .name = "" };
unsigned int subtag;
unsigned int tag;
void *data;
int len;
int check_len;
int rc;
for ( subtag = DHCP_MIN_OPTION; subtag <= DHCP_MAX_OPTION; subtag++ ) {
@ -66,17 +66,11 @@ static int copy_encap_settings ( struct dhcp_packet *dest,
default:
/* Copy setting, if present */
setting.tag = tag;
len = fetch_setting_len ( source, &setting );
if ( len < 0 )
break;
{
char buf[len];
check_len = fetch_setting ( source, &setting,
buf, sizeof (buf));
assert ( check_len == len );
if ( ( rc = dhcppkt_store ( dest, tag, buf,
sizeof(buf) )) !=0)
len = fetch_raw_setting_copy ( source, &setting, &data);
if ( len >= 0 ) {
rc = dhcppkt_store ( dest, tag, data, len );
free ( data );
if ( rc != 0 )
return rc;
}
break;

View File

@ -591,7 +591,7 @@ struct sockaddr_converter ipv4_sockaddr_converter __sockaddr_converter = {
*/
/** IPv4 address setting */
struct setting ip_setting __setting ( SETTING_IPv4 ) = {
const struct setting ip_setting __setting ( SETTING_IPv4 ) = {
.name = "ip",
.description = "IP address",
.tag = DHCP_EB_YIADDR,
@ -599,7 +599,7 @@ struct setting ip_setting __setting ( SETTING_IPv4 ) = {
};
/** IPv4 subnet mask setting */
struct setting netmask_setting __setting ( SETTING_IPv4 ) = {
const struct setting netmask_setting __setting ( SETTING_IPv4 ) = {
.name = "netmask",
.description = "Subnet mask",
.tag = DHCP_SUBNET_MASK,
@ -607,7 +607,7 @@ struct setting netmask_setting __setting ( SETTING_IPv4 ) = {
};
/** Default gateway setting */
struct setting gateway_setting __setting ( SETTING_IPv4 ) = {
const struct setting gateway_setting __setting ( SETTING_IPv4 ) = {
.name = "gateway",
.description = "Default gateway",
.tag = DHCP_ROUTERS,

View File

@ -954,7 +954,7 @@ struct sockaddr_converter ipv6_sockaddr_converter __sockaddr_converter = {
* @v len Length of buffer
* @ret len Length of raw value, or negative error
*/
static int parse_ipv6_setting ( struct setting_type *type __unused,
static int parse_ipv6_setting ( const struct setting_type *type __unused,
const char *value, void *buf, size_t len ) {
struct in6_addr ipv6;
int rc;
@ -981,7 +981,7 @@ static int parse_ipv6_setting ( struct setting_type *type __unused,
* @v len Length of buffer
* @ret len Length of formatted value, or negative error
*/
static int format_ipv6_setting ( struct setting_type *type __unused,
static int format_ipv6_setting ( const struct setting_type *type __unused,
const void *raw, size_t raw_len, char *buf,
size_t len ) {
const struct in6_addr *ipv6 = raw;
@ -992,7 +992,7 @@ static int format_ipv6_setting ( struct setting_type *type __unused,
}
/** An IPv6 address setting type */
struct setting_type setting_type_ipv6 __setting_type = {
const struct setting_type setting_type_ipv6 __setting_type = {
.name = "ipv6",
.parse = parse_ipv6_setting,
.format = format_ipv6_setting,

View File

@ -36,27 +36,27 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/
/** Network device predefined settings */
struct setting mac_setting __setting ( SETTING_NETDEV ) = {
const struct setting mac_setting __setting ( SETTING_NETDEV ) = {
.name = "mac",
.description = "MAC address",
.type = &setting_type_hex,
};
struct setting bustype_setting __setting ( SETTING_NETDEV ) = {
const struct setting bustype_setting __setting ( SETTING_NETDEV ) = {
.name = "bustype",
.description = "Bus type",
.type = &setting_type_string,
};
struct setting busloc_setting __setting ( SETTING_NETDEV ) = {
const struct setting busloc_setting __setting ( SETTING_NETDEV ) = {
.name = "busloc",
.description = "Bus location",
.type = &setting_type_uint32,
};
struct setting busid_setting __setting ( SETTING_NETDEV ) = {
const struct setting busid_setting __setting ( SETTING_NETDEV ) = {
.name = "busid",
.description = "Bus ID",
.type = &setting_type_hex,
};
struct setting chip_setting __setting ( SETTING_NETDEV ) = {
const struct setting chip_setting __setting ( SETTING_NETDEV ) = {
.name = "chip",
.description = "Chip",
.type = &setting_type_string,
@ -194,7 +194,7 @@ static int netdev_fetch_chip ( struct net_device *netdev, void *data,
/** A network device setting operation */
struct netdev_setting_operation {
/** Setting */
struct setting *setting;
const struct setting *setting;
/** Store setting (or NULL if not supported)
*
* @v netdev Network device
@ -232,7 +232,8 @@ static struct netdev_setting_operation netdev_setting_operations[] = {
* @v len Length of setting data
* @ret rc Return status code
*/
static int netdev_store ( struct settings *settings, struct setting *setting,
static int netdev_store ( struct settings *settings,
const struct setting *setting,
const void *data, size_t len ) {
struct net_device *netdev = container_of ( settings, struct net_device,
settings.settings );

View File

@ -1860,7 +1860,7 @@ enum iscsi_root_path_component {
};
/** iSCSI initiator IQN setting */
struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
const struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
.name = "initiator-iqn",
.description = "iSCSI initiator name",
.tag = DHCP_ISCSI_INITIATOR_IQN,
@ -1868,7 +1868,7 @@ struct setting initiator_iqn_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
};
/** iSCSI reverse username setting */
struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = {
const struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = {
.name = "reverse-username",
.description = "Reverse user name",
.tag = DHCP_EB_REVERSE_USERNAME,
@ -1876,7 +1876,7 @@ struct setting reverse_username_setting __setting ( SETTING_AUTH_EXTRA ) = {
};
/** iSCSI reverse password setting */
struct setting reverse_password_setting __setting ( SETTING_AUTH_EXTRA ) = {
const struct setting reverse_password_setting __setting ( SETTING_AUTH_EXTRA ) = {
.name = "reverse-password",
.description = "Reverse password",
.tag = DHCP_EB_REVERSE_PASSWORD,
@ -1947,46 +1947,23 @@ static int iscsi_fetch_settings ( struct iscsi_session *iscsi ) {
/* Fetch relevant settings. Don't worry about freeing on
* error, since iscsi_free() will take care of that anyway.
*/
if ( ( len = fetch_string_setting_copy ( NULL, &username_setting,
&iscsi->initiator_username ) ) < 0 ) {
DBGC ( iscsi, "iSCSI %p could not fetch username: %s\n",
iscsi, strerror ( len ) );
return len;
}
if ( ( len = fetch_string_setting_copy ( NULL, &password_setting,
&iscsi->initiator_password ) ) < 0 ) {
DBGC ( iscsi, "iSCSI %p could not fetch password: %s\n",
iscsi, strerror ( len ) );
return len;
}
if ( ( len = fetch_string_setting_copy( NULL, &reverse_username_setting,
&iscsi->target_username ) ) < 0 ) {
DBGC ( iscsi, "iSCSI %p could not fetch reverse username: %s\n",
iscsi, strerror ( len ) );
return len;
}
if ( ( len = fetch_string_setting_copy( NULL, &reverse_password_setting,
&iscsi->target_password ) ) < 0 ) {
DBGC ( iscsi, "iSCSI %p could not fetch reverse password: %s\n",
iscsi, strerror ( len ) );
return len;
}
fetch_string_setting_copy ( NULL, &username_setting,
&iscsi->initiator_username );
fetch_string_setting_copy ( NULL, &password_setting,
&iscsi->initiator_password );
fetch_string_setting_copy ( NULL, &reverse_username_setting,
&iscsi->target_username );
fetch_string_setting_copy ( NULL, &reverse_password_setting,
&iscsi->target_password );
/* Find a suitable initiator name */
if ( ( len = fetch_string_setting_copy ( NULL, &initiator_iqn_setting,
&iscsi->initiator_iqn ) ) < 0 ) {
DBGC ( iscsi, "iSCSI %p could not fetch initiator IQN: %s\n",
iscsi, strerror ( len ) );
return len;
}
/* Use explicit initiator IQN if provided */
fetch_string_setting_copy ( NULL, &initiator_iqn_setting,
&iscsi->initiator_iqn );
if ( iscsi->initiator_iqn )
return 0;
if ( ( len = fetch_string_setting_copy ( NULL, &hostname_setting,
&hostname ) ) < 0 ) {
DBGC ( iscsi, "iSCSI %p could not fetch hostname: %s\n",
iscsi, strerror ( len ) );
return len;
}
/* Otherwise, try to construct an initiator IQN from the hostname */
fetch_string_setting_copy ( NULL, &hostname_setting, &hostname );
if ( hostname ) {
len = asprintf ( &iscsi->initiator_iqn,
ISCSI_DEFAULT_IQN_PREFIX ":%s", hostname );
@ -1999,6 +1976,8 @@ static int iscsi_fetch_settings ( struct iscsi_session *iscsi ) {
assert ( iscsi->initiator_iqn );
return 0;
}
/* Otherwise, try to construct an initiator IQN from the UUID */
if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting, &uuid ) ) < 0 ) {
DBGC ( iscsi, "iSCSI %p has no suitable initiator IQN\n",
iscsi );

View File

@ -58,14 +58,14 @@ struct oncrpc_cred oncrpc_auth_none = {
.length = 0
};
struct setting uid_setting __setting ( SETTING_AUTH ) = {
const struct setting uid_setting __setting ( SETTING_AUTH ) = {
.name = "uid",
.description = "User ID",
.tag = DHCP_EB_UID,
.type = &setting_type_uint32
};
struct setting gid_setting __setting ( SETTING_AUTH ) = {
const struct setting gid_setting __setting ( SETTING_AUTH ) = {
.name = "gid",
.description = "Group ID",
.tag = DHCP_EB_GID,

View File

@ -190,7 +190,7 @@ struct console_driver syslogs_console __console_driver = {
*/
/** Encrypted syslog server setting */
struct setting syslogs_setting __setting ( SETTING_MISC ) = {
const struct setting syslogs_setting __setting ( SETTING_MISC ) = {
.name = "syslogs",
.description = "Encrypted syslog server",
.tag = DHCP_EB_SYSLOGS_SERVER,
@ -206,15 +206,10 @@ static int apply_syslogs_settings ( void ) {
static char *old_server;
char *server;
struct interface *socket;
int len;
int rc;
/* Fetch log server */
len = fetch_string_setting_copy ( NULL, &syslogs_setting, &server );
if ( len < 0 ) {
rc = len;
goto err_fetch_server;
}
fetch_string_setting_copy ( NULL, &syslogs_setting, &server );
/* Do nothing unless log server has changed */
if ( ( ( server == NULL ) && ( old_server == NULL ) ) ||
@ -266,7 +261,6 @@ static int apply_syslogs_settings ( void ) {
out_no_server:
out_no_change:
free ( server );
err_fetch_server:
return rc;
}

View File

@ -92,7 +92,7 @@ static uint8_t dhcp_request_options_data[] = {
};
/** DHCP server address setting */
struct setting dhcp_server_setting __setting ( SETTING_MISC ) = {
const struct setting dhcp_server_setting __setting ( SETTING_MISC ) = {
.name = "dhcp-server",
.description = "DHCP server",
.tag = DHCP_SERVER_IDENTIFIER,
@ -975,6 +975,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
uint8_t *dhcp_features;
size_t dhcp_features_len;
size_t ll_addr_len;
void *user_class;
ssize_t len;
int rc;
@ -985,7 +986,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
data, max_len ) ) != 0 ) {
DBG ( "DHCP could not create DHCP packet: %s\n",
strerror ( rc ) );
return rc;
goto err_create_packet;
}
/* Set client IP address */
@ -998,17 +999,17 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
dhcp_features_len ) ) != 0 ) {
DBG ( "DHCP could not set features list option: %s\n",
strerror ( rc ) );
return rc;
goto err_store_features;
}
/* Add options to identify the network device */
fetch_setting ( &netdev->settings.settings, &busid_setting, &dhcp_desc,
sizeof ( dhcp_desc ) );
fetch_raw_setting ( netdev_settings ( netdev ), &busid_setting,
&dhcp_desc, sizeof ( dhcp_desc ) );
if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_EB_BUS_ID, &dhcp_desc,
sizeof ( dhcp_desc ) ) ) != 0 ) {
DBG ( "DHCP could not set bus ID option: %s\n",
strerror ( rc ) );
return rc;
goto err_store_busid;
}
/* Add DHCP client identifier. Required for Infiniband, and
@ -1022,7 +1023,7 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
( ll_addr_len + 1 ) ) ) != 0 ) {
DBG ( "DHCP could not set client ID: %s\n",
strerror ( rc ) );
return rc;
goto err_store_client_id;
}
/* Add client UUID, if we have one. Required for PXE. The
@ -1039,25 +1040,29 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
sizeof ( client_uuid ) ) ) != 0 ) {
DBG ( "DHCP could not set client UUID: %s\n",
strerror ( rc ) );
return rc;
goto err_store_client_uuid;
}
}
/* Add user class, if we have one. */
if ( ( len = fetch_setting_len ( NULL, &user_class_setting ) ) >= 0 ) {
char user_class[len];
fetch_setting ( NULL, &user_class_setting, user_class,
sizeof ( user_class ) );
if ( ( len = fetch_raw_setting_copy ( NULL, &user_class_setting,
&user_class ) ) >= 0 ) {
if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_USER_CLASS_ID,
&user_class,
sizeof ( user_class ) ) ) != 0 ) {
user_class, len ) ) != 0 ) {
DBG ( "DHCP could not set user class: %s\n",
strerror ( rc ) );
return rc;
goto err_store_user_class;
}
}
return 0;
err_store_user_class:
free ( user_class );
err_store_client_uuid:
err_store_client_id:
err_store_busid:
err_store_features:
err_create_packet:
return rc;
}
/****************************************************************************
@ -1384,7 +1389,8 @@ int start_pxebs ( struct interface *job, struct net_device *netdev,
int rc;
/* Get upper bound for PXE boot server IP address list */
pxebs_list_len = fetch_setting_len ( NULL, &pxe_boot_servers_setting );
pxebs_list_len = fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
NULL, 0 );
if ( pxebs_list_len < 0 )
pxebs_list_len = 0;
@ -1422,8 +1428,8 @@ int start_pxebs ( struct interface *job, struct net_device *netdev,
if ( pxebs_list_len ) {
uint8_t buf[pxebs_list_len];
fetch_setting ( NULL, &pxe_boot_servers_setting,
buf, sizeof ( buf ) );
fetch_raw_setting ( NULL, &pxe_boot_servers_setting,
buf, sizeof ( buf ) );
pxebs_list ( dhcp, buf, sizeof ( buf ), ip );
}
if ( ! dhcp->pxe_attempt->s_addr ) {

View File

@ -256,7 +256,7 @@ static int dhcpv6_iaaddr ( struct dhcpv6_option_list *options, uint32_t iaid,
*/
/** DHCPv6 settings scope */
static struct settings_scope dhcpv6_settings_scope;
static const struct settings_scope dhcpv6_settings_scope;
/** A DHCPv6 settings block */
struct dhcpv6_settings {
@ -276,7 +276,7 @@ struct dhcpv6_settings {
* @ret applies Setting applies within this settings block
*/
static int dhcpv6_applies ( struct settings *settings __unused,
struct setting *setting ) {
const struct setting *setting ) {
return ( setting->scope == &dhcpv6_settings_scope );
}
@ -543,7 +543,7 @@ static size_t dhcpv6_user_class ( void *data, size_t len ) {
int actual_len;
/* Fetch user-class setting, if defined */
actual_len = fetch_setting ( NULL, &user_class_setting, data, len );
actual_len = fetch_raw_setting ( NULL, &user_class_setting, data, len );
if ( actual_len >= 0 )
return actual_len;

View File

@ -594,7 +594,7 @@ struct resolver dns_resolver __resolver ( RESOLV_NORMAL ) = {
*/
/** DNS server setting */
struct setting dns_setting __setting ( SETTING_IPv4_EXTRA ) = {
const struct setting dns_setting __setting ( SETTING_IPv4_EXTRA ) = {
.name = "dns",
.description = "DNS server",
.tag = DHCP_DNS_SERVERS,
@ -622,11 +622,7 @@ static int apply_dns_settings ( void ) {
/* Get local domain DHCP option */
free ( localdomain );
if ( ( len = fetch_string_setting_copy ( NULL, &domain_setting,
&localdomain ) ) < 0 ) {
DBG ( "DNS could not fetch local domain: %s\n",
strerror ( len ) );
}
fetch_string_setting_copy ( NULL, &domain_setting, &localdomain );
if ( localdomain )
DBG ( "DNS local domain %s\n", localdomain );

View File

@ -188,7 +188,7 @@ struct console_driver syslog_console __console_driver = {
*/
/** Syslog server setting */
struct setting syslog_setting __setting ( SETTING_MISC ) = {
const struct setting syslog_setting __setting ( SETTING_MISC ) = {
.name = "syslog",
.description = "Syslog server",
.tag = DHCP_LOG_SERVERS,
@ -209,17 +209,9 @@ static int apply_syslog_settings ( void ) {
/* Fetch hostname and domain name */
free ( syslog_hostname );
if ( ( len = fetch_string_setting_copy ( NULL, &hostname_setting,
&syslog_hostname ) ) < 0 ) {
rc = len;
DBG ( "SYSLOG could not fetch hostname: %s\n", strerror ( rc ));
}
fetch_string_setting_copy ( NULL, &hostname_setting, &syslog_hostname );
free ( syslog_domain );
if ( ( len = fetch_string_setting_copy ( NULL, &domain_setting,
&syslog_domain ) ) < 0 ) {
rc = len;
DBG ( "SYSLOG could not fetch domain: %s\n", strerror ( rc ) );
}
fetch_string_setting_copy ( NULL, &domain_setting, &syslog_domain );
/* Fetch log server */
syslog_console.disabled = CONSOLE_DISABLED;

View File

@ -121,7 +121,7 @@ static struct interface_descriptor validator_job_desc =
*/
/** Cross-signed certificate source setting */
struct setting crosscert_setting __setting ( SETTING_CRYPTO ) = {
const struct setting crosscert_setting __setting ( SETTING_CRYPTO ) = {
.name = "crosscert",
.description = "Cross-signed certificate source",
.tag = DHCP_EB_CROSS_CERT,
@ -232,14 +232,7 @@ static int validator_start_download ( struct validator *validator,
int rc;
/* Determine cross-signed certificate source */
len = fetch_string_setting_copy ( NULL, &crosscert_setting,
&crosscert_copy );
if ( len < 0 ) {
rc = len;
DBGC ( validator, "VALIDATOR %p could not fetch crosscert "
"setting: %s\n", validator, strerror ( rc ) );
goto err_fetch_crosscert;
}
fetch_string_setting_copy ( NULL, &crosscert_setting, &crosscert_copy );
crosscert = ( crosscert_copy ? crosscert_copy : crosscert_default );
/* Allocate URI string */
@ -279,7 +272,6 @@ static int validator_start_download ( struct validator *validator,
free ( uri_string );
err_alloc_uri_string:
free ( crosscert_copy );
err_fetch_crosscert:
return rc;
}

View File

@ -38,26 +38,26 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Report a formatted-store test result
*
* @v settings Settings block
* @v setting Setting
* @v formatted Formatted value
* @v raw_array Expected raw value
* @v _settings Settings block
* @v _setting Setting
* @v _formatted Formatted value
* @v _raw_array Expected raw value
*/
#define storef_ok( settings, setting, formatted, raw_array ) do { \
const uint8_t expected[] = raw_array; \
#define storef_ok( _settings, _setting, _formatted, _raw_array ) do { \
const uint8_t expected[] = _raw_array; \
uint8_t actual[ sizeof ( expected ) ]; \
int len; \
\
ok ( storef_setting ( settings, setting, formatted ) == 0 ); \
len = fetch_setting ( settings, setting, actual, \
ok ( storef_setting ( _settings, _setting, _formatted ) == 0 ); \
len = fetch_setting ( _settings, _setting, NULL, NULL, actual, \
sizeof ( actual ) ); \
if ( len >= 0 ) { \
DBGC ( settings, "Stored %s \"%s\", got:\n", \
(setting)->type->name, formatted ); \
DBGC_HDA ( settings, 0, actual, len ); \
DBGC ( _settings, "Stored %s \"%s\", got:\n", \
(_setting)->type->name, _formatted ); \
DBGC_HDA ( _settings, 0, actual, len ); \
} else { \
DBGC ( settings, "Stored %s \"%s\", got error %s\n", \
(setting)->type->name, formatted, \
DBGC ( _settings, "Stored %s \"%s\", got error %s\n", \
(_setting)->type->name, _formatted, \
strerror ( len ) ); \
} \
ok ( len == ( int ) sizeof ( actual ) ); \
@ -67,52 +67,52 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Report a formatted-fetch test result
*
* @v settings Settings block
* @v setting Setting
* @v raw_array Raw value
* @v formatted Expected formatted value
* @v _settings Settings block
* @v _setting Setting
* @v _raw_array Raw value
* @v _formatted Expected formatted value
*/
#define fetchf_ok( settings, setting, raw_array, formatted ) do { \
const uint8_t raw[] = raw_array; \
char actual[ strlen ( formatted ) + 1 ]; \
#define fetchf_ok( _settings, _setting, _raw_array, _formatted ) do { \
const uint8_t raw[] = _raw_array; \
char actual[ strlen ( _formatted ) + 1 ]; \
int len; \
\
ok ( store_setting ( settings, setting, raw, \
ok ( store_setting ( _settings, _setting, raw, \
sizeof ( raw ) ) == 0 ); \
len = fetchf_setting ( settings, setting, actual, \
len = fetchf_setting ( _settings, _setting, NULL, NULL, actual, \
sizeof ( actual ) ); \
DBGC ( settings, "Fetched %s \"%s\" from:\n", \
(setting)->type->name, actual ); \
DBGC_HDA ( settings, 0, raw, sizeof ( raw ) ); \
DBGC ( _settings, "Fetched %s \"%s\" from:\n", \
(_setting)->type->name, actual ); \
DBGC_HDA ( _settings, 0, raw, sizeof ( raw ) ); \
ok ( len == ( int ) ( sizeof ( actual ) - 1 ) ); \
ok ( strcmp ( actual, formatted ) == 0 ); \
ok ( strcmp ( actual, _formatted ) == 0 ); \
} while ( 0 )
/**
* Report a numeric-store test result
*
* @v settings Settings block
* @v setting Setting
* @v numeric Numeric value
* @v raw_array Expected raw value
* @v _settings Settings block
* @v _setting Setting
* @v _numeric Numeric value
* @v _raw_array Expected raw value
*/
#define storen_ok( settings, setting, numeric, raw_array ) do { \
const uint8_t expected[] = raw_array; \
#define storen_ok( _settings, _setting, _numeric, _raw_array ) do { \
const uint8_t expected[] = _raw_array; \
uint8_t actual[ sizeof ( expected ) ]; \
int len; \
\
ok ( storen_setting ( settings, setting, numeric ) == 0 ); \
len = fetch_setting ( settings, setting, actual, \
ok ( storen_setting ( _settings, _setting, _numeric ) == 0 ); \
len = fetch_setting ( _settings, _setting, NULL, NULL, actual, \
sizeof ( actual ) ); \
if ( len >= 0 ) { \
DBGC ( settings, "Stored %s %#lx, got:\n", \
(setting)->type->name, \
( unsigned long ) numeric ); \
DBGC_HDA ( settings, 0, actual, len ); \
DBGC ( _settings, "Stored %s %#lx, got:\n", \
(_setting)->type->name, \
( unsigned long ) _numeric ); \
DBGC_HDA ( _settings, 0, actual, len ); \
} else { \
DBGC ( settings, "Stored %s %#lx, got error %s\n", \
(setting)->type->name, \
( unsigned long ) numeric, strerror ( len ) ); \
DBGC ( _settings, "Stored %s %#lx, got error %s\n", \
(_setting)->type->name, \
( unsigned long ) _numeric, strerror ( len ) ); \
} \
ok ( len == ( int ) sizeof ( actual ) ); \
ok ( memcmp ( actual, expected, sizeof ( actual ) ) == 0 ); \
@ -121,22 +121,23 @@ FILE_LICENCE ( GPL2_OR_LATER );
/**
* Report a numeric-fetch test result
*
* @v settings Settings block
* @v setting Setting
* @v raw_array Raw array
* @v numeric Expected numeric value
* @v _settings Settings block
* @v _setting Setting
* @v _raw_array Raw array
* @v _numeric Expected numeric value
*/
#define fetchn_ok( settings, setting, raw_array, numeric ) do { \
const uint8_t raw[] = raw_array; \
#define fetchn_ok( _settings, _setting, _raw_array, _numeric ) do { \
const uint8_t raw[] = _raw_array; \
unsigned long actual; \
\
ok ( store_setting ( settings, setting, raw, \
ok ( store_setting ( _settings, _setting, raw, \
sizeof ( raw ) ) == 0 ); \
ok ( fetchn_setting ( settings, setting, &actual ) == 0 ); \
DBGC ( settings, "Fetched %s %#lx from:\n", \
(setting)->type->name, actual ); \
DBGC_HDA ( settings, 0, raw, sizeof ( raw ) ); \
ok ( actual == ( unsigned long ) numeric ); \
ok ( fetchn_setting ( _settings, _setting, NULL, NULL, \
&actual ) == 0 ); \
DBGC ( _settings, "Fetched %s %#lx from:\n", \
(_setting)->type->name, actual ); \
DBGC_HDA ( _settings, 0, raw, sizeof ( raw ) ); \
ok ( actual == ( unsigned long ) _numeric ); \
} while ( 0 )
/** Test generic settings block */

View File

@ -59,7 +59,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
#define CYAN "\033[36m"
/** The "scriptlet" setting */
struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
const struct setting scriptlet_setting __setting ( SETTING_MISC ) = {
.name = "scriptlet",
.description = "Boot scriptlet",
.tag = DHCP_EB_SCRIPTLET,
@ -119,7 +119,7 @@ static struct uri * parse_next_server_and_filename ( struct in_addr next_server,
}
/** The "keep-san" setting */
struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
const struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
.name = "keep-san",
.description = "Preserve SAN connection",
.tag = DHCP_EB_KEEP_SAN,
@ -127,7 +127,7 @@ struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
};
/** The "skip-san-boot" setting */
struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA ) = {
const struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA )={
.name = "skip-san-boot",
.description = "Do not boot from SAN device",
.tag = DHCP_EB_SKIP_SAN_BOOT,
@ -256,16 +256,15 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
struct uri *uri = NULL;
char *filename;
/* Determine settings block containing the filename, if any */
settings = fetch_setting_origin ( settings, &filename_setting );
/* If we have a filename, fetch it along with next-server */
if ( settings ) {
/* If we have a filename, fetch it along with the next-server
* setting from the same settings block.
*/
if ( fetch_setting ( settings, &filename_setting, &settings,
NULL, NULL, 0 ) >= 0 ) {
fetch_string_setting_copy ( settings, &filename_setting,
&raw_filename );
fetch_ipv4_setting ( settings, &next_server_setting,
&next_server );
if ( fetch_string_setting_copy ( settings, &filename_setting,
&raw_filename ) < 0 )
goto err_fetch;
}
/* Expand filename setting */
@ -286,7 +285,6 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
free ( filename );
err_expand:
free ( raw_filename );
err_fetch:
return uri;
}
@ -297,25 +295,30 @@ struct uri * fetch_next_server_and_filename ( struct settings *settings ) {
* @ret uri URI, or NULL on failure
*/
static struct uri * fetch_root_path ( struct settings *settings ) {
char buf[256];
struct uri *uri = NULL;
char *raw_root_path;
char *root_path;
struct uri *uri;
/* Fetch root-path setting */
fetch_string_setting ( settings, &root_path_setting,
buf, sizeof ( buf ) );
if ( buf[0] )
printf ( "Root path: %s\n", buf );
fetch_string_setting_copy ( settings, &root_path_setting,
&raw_root_path );
/* Expand filename setting */
root_path = expand_settings ( buf );
root_path = expand_settings ( raw_root_path ? raw_root_path : "" );
if ( ! root_path )
return NULL;
goto err_expand;
/* Parse root path */
if ( root_path[0] )
printf ( "Root path: %s\n", root_path );
uri = parse_uri ( root_path );
if ( ! uri )
goto err_parse;
err_parse:
free ( root_path );
err_expand:
free ( raw_root_path );
return uri;
}
@ -331,7 +334,7 @@ static int have_pxe_menu ( void ) {
= { .tag = DHCP_PXE_DISCOVERY_CONTROL };
struct setting pxe_boot_menu_setting
= { .tag = DHCP_PXE_BOOT_MENU };
char buf[256];
char buf[ 10 /* "PXEClient" + NUL */ ];
unsigned int pxe_discovery_control;
fetch_string_setting ( NULL, &vendor_class_id_setting,

View File

@ -71,7 +71,7 @@ static void nslookup_close ( struct nslookup *nslookup, int rc ) {
static void nslookup_resolv_done ( struct nslookup *nslookup,
struct sockaddr *sa ) {
struct sockaddr_in *sin;
struct setting_type *default_type;
const struct setting_type *default_type;
struct settings *settings;
struct setting setting;
void *data;

View File

@ -101,9 +101,9 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
/* Fetch raw menu */
memset ( raw_menu, 0, sizeof ( raw_menu ) );
if ( ( raw_menu_len = fetch_setting ( NULL, &pxe_boot_menu_setting,
raw_menu,
sizeof ( raw_menu ) ) ) < 0 ) {
if ( ( raw_menu_len = fetch_raw_setting ( NULL, &pxe_boot_menu_setting,
raw_menu,
sizeof ( raw_menu ) ) ) < 0 ){
rc = raw_menu_len;
DBG ( "Could not retrieve raw PXE boot menu: %s\n",
strerror ( rc ) );
@ -116,8 +116,9 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
raw_menu_end = ( raw_menu + raw_menu_len );
/* Fetch raw prompt length */
raw_prompt_len = fetch_setting_len ( NULL,
&pxe_boot_menu_prompt_setting );
raw_prompt_len =
fetch_raw_setting ( NULL, &pxe_boot_menu_prompt_setting,
NULL, 0 );
if ( raw_prompt_len < 0 )
raw_prompt_len = 0;
@ -168,8 +169,8 @@ static int pxe_menu_parse ( struct pxe_menu **menu ) {
if ( raw_prompt_len ) {
raw_menu_prompt = ( ( ( void * ) raw_menu_item ) +
1 /* NUL */ );
fetch_setting ( NULL, &pxe_boot_menu_prompt_setting,
raw_menu_prompt, raw_prompt_len );
fetch_raw_setting ( NULL, &pxe_boot_menu_prompt_setting,
raw_menu_prompt, raw_prompt_len );
(*menu)->timeout =
( ( raw_menu_prompt->timeout == 0xff ) ?
-1 : raw_menu_prompt->timeout );