iPXE
Data Structures | Defines | Typedefs | Functions | Variables
settings.h File Reference

Configuration settings. More...

#include <stdint.h>
#include <ipxe/tables.h>
#include <ipxe/list.h>
#include <ipxe/refcnt.h>

Go to the source code of this file.

Data Structures

struct  setting
 A setting. More...
struct  settings_operations
 Settings block operations. More...
struct  settings
 A settings block. More...
struct  settings_scope
 A setting scope. More...
struct  setting_type
 A setting type. More...
struct  settings_applicator
 A settings applicator. More...
struct  builtin_setting
 A built-in setting. More...
struct  generic_settings
 A generic settings block. More...

Defines

#define SETTINGS   __table ( struct setting, "settings" )
 Configuration setting table.
#define __setting(setting_order, name)   __table_entry ( SETTINGS, setting_order.name )
 Declare a configuration setting.
#define SETTING_NETDEV   01
 Network device settings.
#define SETTING_NETDEV_EXTRA   02
 Network device additional settings.
#define SETTING_IP4   03
 IPv4 settings.
#define SETTING_IP4_EXTRA   04
 IPv4 additional settings.
#define SETTING_IP6   05
 IPv6 settings.
#define SETTING_IP6_EXTRA   06
 IPv6 additional settings.
#define SETTING_IP   07
 IPv4 settings.
#define SETTING_IP_EXTRA   08
 IPv4 additional settings.
#define SETTING_BOOT   09
 Generic boot settings.
#define SETTING_BOOT_EXTRA   10
 Generic boot additional settings.
#define SETTING_SANBOOT   11
 SAN boot settings.
#define SETTING_SANBOOT_EXTRA   12
 SAN boot additional settings.
#define SETTING_HOST   13
 Host identity settings.
#define SETTING_HOST_EXTRA   14
 Host identity additional settings.
#define SETTING_AUTH   15
 Authentication settings.
#define SETTING_AUTH_EXTRA   16
 Authentication additional settings.
#define SETTING_CRYPTO   17
 Cryptography settings.
#define SETTING_MISC   18
 Miscellaneous settings.
#define SETTING_TYPES   __table ( struct setting_type, "setting_types" )
 Configuration setting type table.
#define __setting_type   __table_entry ( SETTING_TYPES, 01 )
 Declare a configuration setting type.
#define SETTINGS_APPLICATORS   __table ( struct settings_applicator, "settings_applicators" )
 Settings applicator table.
#define __settings_applicator   __table_entry ( SETTINGS_APPLICATORS, 01 )
 Declare a settings applicator.
#define BUILTIN_SETTINGS   __table ( struct builtin_setting, "builtin_settings" )
 Built-in settings table.
#define __builtin_setting   __table_entry ( BUILTIN_SETTINGS, 01 )
 Declare a built-in setting.

Typedefs

typedef struct settings *(* get_child_settings_t )(struct settings *settings, const char *name)
 A child settings block locator function.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int generic_settings_store (struct settings *settings, const struct setting *setting, const void *data, size_t len)
 Store value of generic setting.
int generic_settings_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of generic setting.
void generic_settings_clear (struct settings *settings)
 Clear generic settings block.
int register_settings (struct settings *settings, struct settings *parent, const char *name)
 Register settings block.
void unregister_settings (struct settings *settings)
 Unregister settings block.
struct settingssettings_target (struct settings *settings)
 Redirect to target settings block.
int setting_applies (struct settings *settings, const struct setting *setting)
 Check applicability of setting.
int store_setting (struct settings *settings, const struct setting *setting, const void *data, size_t len)
 Store value of setting.
int fetch_setting (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
 Fetch setting.
int fetch_setting_copy (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data)
 Fetch copy of setting.
int fetch_raw_setting (struct settings *settings, const struct setting *setting, void *data, size_t len)
 Fetch value of setting.
int fetch_raw_setting_copy (struct settings *settings, const struct setting *setting, void **data)
 Fetch value of setting.
int fetch_string_setting (struct settings *settings, const struct setting *setting, char *data, size_t len)
 Fetch value of string setting.
int fetch_string_setting_copy (struct settings *settings, const struct setting *setting, char **data)
 Fetch value of string setting.
int fetch_ipv4_array_setting (struct settings *settings, const struct setting *setting, struct in_addr *inp, unsigned int count)
 Fetch value of IPv4 address setting.
int fetch_ipv4_setting (struct settings *settings, const struct setting *setting, struct in_addr *inp)
 Fetch value of IPv4 address setting.
int fetch_ipv6_array_setting (struct settings *settings, const struct setting *setting, struct in6_addr *inp, unsigned int count)
 Fetch value of IPv6 address setting.
int fetch_ipv6_setting (struct settings *settings, const struct setting *setting, struct in6_addr *inp)
 Fetch value of IPv6 address setting.
int fetch_int_setting (struct settings *settings, const struct setting *setting, long *value)
 Fetch value of signed integer setting.
int fetch_uint_setting (struct settings *settings, const struct setting *setting, unsigned long *value)
 Fetch value of unsigned integer setting.
long fetch_intz_setting (struct settings *settings, const struct setting *setting)
 Fetch value of signed integer setting, or zero.
unsigned long fetch_uintz_setting (struct settings *settings, const struct setting *setting)
 Fetch value of unsigned integer setting, or zero.
int fetch_uuid_setting (struct settings *settings, const struct setting *setting, union uuid *uuid)
 Fetch value of UUID setting.
void clear_settings (struct settings *settings)
 Clear settings block.
int setting_cmp (const struct setting *a, const struct setting *b)
 Compare two settings.
struct settingsfind_child_settings (struct settings *parent, const char *name)
 Find child settings block.
struct settingsautovivify_child_settings (struct settings *parent, const char *name)
 Find or create child settings block.
const char * settings_name (struct settings *settings)
 Return settings block name.
struct settingsfind_settings (const char *name)
 Find settings block.
struct settingfind_setting (const char *name)
 Find predefined setting.
int parse_setting_name (char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
 Parse setting name.
int setting_name (struct settings *settings, const struct setting *setting, char *buf, size_t len)
 Return full setting name.
int setting_format (const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
 Format setting value as a string.
int setting_parse (const struct setting_type *type, const char *value, void *buf, size_t len)
 Parse formatted string to setting value.
int setting_numerate (const struct setting_type *type, const void *raw, size_t raw_len, unsigned long *value)
 Convert setting value to number.
int setting_denumerate (const struct setting_type *type, unsigned long value, void *buf, size_t len)
 Convert number to setting value.
int fetchf_setting (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char *buf, size_t len)
 Fetch formatted value of setting.
int fetchf_setting_copy (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char **value)
 Fetch copy of formatted value of setting.
int storef_setting (struct settings *settings, const struct setting *setting, const char *value)
 Store formatted value of setting.
int fetchn_setting (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, unsigned long *value)
 Fetch numeric value of setting.
int storen_setting (struct settings *settings, const struct setting *setting, unsigned long value)
 Store numeric value of setting.
char * expand_settings (const char *string)
 Expand variables within string.
struct setting ip_setting __setting (SETTING_IP4, ip)
struct setting netmask_setting __setting (SETTING_IP4, netmask)
struct setting gateway_setting __setting (SETTING_IP4, gateway)
struct setting dns_setting __setting (SETTING_IP4_EXTRA, dns)
struct setting ip6_setting __setting (SETTING_IP6, ip6)
struct setting len6_setting __setting (SETTING_IP6, len6)
struct setting gateway6_setting __setting (SETTING_IP6, gateway6)
struct setting hostname_setting __setting (SETTING_HOST, hostname)
struct setting domain_setting __setting (SETTING_IP_EXTRA, domain)
struct setting filename_setting __setting (SETTING_BOOT, filename)
struct setting root_path_setting __setting (SETTING_SANBOOT, root-path)
struct setting san_filename_setting __setting (SETTING_SANBOOT, san-filename)
struct setting username_setting __setting (SETTING_AUTH, username)
struct setting password_setting __setting (SETTING_AUTH, password)
struct setting priority_setting __setting (SETTING_MISC, priority)
struct setting uuid_setting __setting (SETTING_HOST, uuid)
struct setting next_server_setting __setting (SETTING_BOOT, next-server)
struct setting mac_setting __setting (SETTING_NETDEV, mac)
struct setting busid_setting __setting (SETTING_NETDEV, busid)
struct setting user_class_setting __setting (SETTING_HOST_EXTRA, user-class)
struct setting vendor_class_setting __setting (SETTING_HOST_EXTRA, vendor-class)
struct setting manufacturer_setting __setting (SETTING_HOST_EXTRA, manufacturer)
struct setting product_setting __setting (SETTING_HOST_EXTRA, product)
struct setting serial_setting __setting (SETTING_HOST_EXTRA, serial)
struct setting asset_setting __setting (SETTING_HOST_EXTRA, asset)
struct setting board_serial_setting __setting (SETTING_HOST_EXTRA, board-serial)
struct setting dhcp_server_setting __setting (SETTING_MISC, dhcp-server)
static void settings_init (struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
 Initialise a settings block.
static void generic_settings_init (struct generic_settings *generics, struct refcnt *refcnt)
 Initialise a settings block.
static int delete_setting (struct settings *settings, const struct setting *setting)
 Delete setting.
static int setting_exists (struct settings *settings, const struct setting *setting)
 Check existence of predefined setting.

Variables

struct settings_scope builtin_scope
 Built-in setting scope.
struct settings_scope ipv6_settings_scope
 IPv6 setting scope.
struct settings_scope dhcpv6_scope
 DHCPv6 setting scope.
struct settings_operations generic_settings_operations
 Generic settings operations.
struct setting_type
setting_type_string 
__setting_type
 A string setting type.

Detailed Description

Configuration settings.

Definition in file settings.h.


Define Documentation

#define SETTINGS   __table ( struct setting, "settings" )
#define __setting (   setting_order,
  name 
)    __table_entry ( SETTINGS, setting_order.name )

Declare a configuration setting.

Definition at line 56 of file settings.h.

#define SETTING_TYPES   __table ( struct setting_type, "setting_types" )

Configuration setting type table.

Definition at line 242 of file settings.h.

Referenced by find_setting_type(), and guestinfo_fetch().

struct setting_type setting_type_dnssl __setting_type   __table_entry ( SETTING_TYPES, 01 )

Declare a configuration setting type.

PCI bus:dev.fn setting type.

UUID setting type.

A Base64-encoded setting.

A hex-string setting (non-delimited)

A hex-string setting (hyphen-delimited)

A hex-string setting (colon-delimited)

An unsigned 32-bit integer setting type.

An unsigned 16-bit integer setting type.

An unsigned 8-bit integer setting type.

A signed 32-bit integer setting type.

A signed 16-bit integer setting type.

A signed 8-bit integer setting type.

An IPv6 address setting type.

An IPv4 address setting type.

A URI-encoded string setting type.

Definition at line 245 of file settings.h.

#define SETTINGS_APPLICATORS   __table ( struct settings_applicator, "settings_applicators" )

Settings applicator table.

Definition at line 260 of file settings.h.

Referenced by apply_settings().

Declare a settings applicator.

Definition at line 264 of file settings.h.

#define BUILTIN_SETTINGS   __table ( struct builtin_setting, "builtin_settings" )

Built-in settings table.

Definition at line 280 of file settings.h.

Referenced by builtin_fetch().

struct builtin_setting unixtime_builtin_setting __builtin_setting   __table_entry ( BUILTIN_SETTINGS, 01 )

Declare a built-in setting.

Current time built-in setting.

Version built-in setting.

Platform built-in setting.

Build architecture built-in setting.

Definition at line 283 of file settings.h.


Typedef Documentation

typedef struct settings*( * get_child_settings_t)(struct settings *settings, const char *name)

A child settings block locator function.

Definition at line 306 of file settings.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int generic_settings_store ( struct settings settings,
const struct setting setting,
const void *  data,
size_t  len 
)

Store value of generic setting.

Parameters:
settingsSettings block
settingSetting to store
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values:
rcReturn status code

Definition at line 126 of file settings.c.

References container_of, ENOMEM, find_generic_setting(), free, generic_setting_data(), generic_setting_name(), len, generic_setting::list, generic_settings::list, list_add, list_del, memcpy(), setting::name, generic_setting::name_len, NULL, strlen(), and zalloc().

Referenced by netdev_store().

                                                            {
        struct generic_settings *generics =
                container_of ( settings, struct generic_settings, settings );
        struct generic_setting *old;
        struct generic_setting *new = NULL;
        size_t name_len;

        /* Identify existing generic setting, if any */
        old = find_generic_setting ( generics, setting );

        /* Create new generic setting, if required */
        if ( len ) {
                /* Allocate new generic setting */
                name_len = ( strlen ( setting->name ) + 1 );
                new = zalloc ( sizeof ( *new ) + name_len + len );
                if ( ! new )
                        return -ENOMEM;

                /* Populate new generic setting */
                new->name_len = name_len;
                new->data_len = len;
                memcpy ( &new->setting, setting, sizeof ( new->setting ) );
                new->setting.name = generic_setting_name ( new );
                memcpy ( generic_setting_name ( new ),
                         setting->name, name_len );
                memcpy ( generic_setting_data ( new ), data, len );
        }

        /* Delete existing generic setting, if any */
        if ( old ) {
                list_del ( &old->list );
                free ( old );
        }

        /* Add new setting to list, if any */
        if ( new )
                list_add ( &new->list, &generics->list );

        return 0;
}
int generic_settings_fetch ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)

Fetch value of generic setting.

Parameters:
settingsSettings block
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values:
lenLength of setting data, or negative error

Definition at line 178 of file settings.c.

References container_of, ENOENT, find_generic_setting(), generic, generic_setting_data(), memcpy(), and setting::type.

Referenced by netdev_fetch().

                                                      {
        struct generic_settings *generics =
                container_of ( settings, struct generic_settings, settings );
        struct generic_setting *generic;

        /* Find generic setting */
        generic = find_generic_setting ( generics, setting );
        if ( ! generic )
                return -ENOENT;

        /* Copy out generic setting data */
        if ( len > generic->data_len )
                len = generic->data_len;
        memcpy ( data, generic_setting_data ( generic ), len );

        /* Set setting type, if not yet specified */
        if ( ! setting->type )
                setting->type = generic->setting.type;

        return generic->data_len;
}
void generic_settings_clear ( struct settings settings)

Clear generic settings block.

Parameters:
settingsSettings block

Definition at line 207 of file settings.c.

References assert, container_of, free, generic, generic_setting::list, generic_settings::list, list_del, list_empty, and list_for_each_entry_safe.

Referenced by autovivified_settings_free(), and netdev_clear().

                                                          {
        struct generic_settings *generics =
                container_of ( settings, struct generic_settings, settings );
        struct generic_setting *generic;
        struct generic_setting *tmp;

        list_for_each_entry_safe ( generic, tmp, &generics->list, list ) {
                list_del ( &generic->list );
                free ( generic );
        }
        assert ( list_empty ( &generics->list ) );
}
int register_settings ( struct settings settings,
struct settings parent,
const char *  name 
)

Register settings block.

Parameters:
settingsSettings block
parentParent settings block, or NULL
nameSettings block name
Return values:
rcReturn status code

Definition at line 473 of file settings.c.

References apply_settings(), assert, settings::children, DBGC, find_child_settings(), list_add_tail, settings::name, name, NULL, settings::parent, ref_get, settings::refcnt, reprioritise_settings(), settings_name(), settings_target(), settings::siblings, and unregister_settings().

Referenced by acpi_settings_init(), autovivify_child_settings(), builtin_init(), cachedhcp_probe(), cpuid_settings_init(), dhcp_proxy_rx(), dhcp_pxebs_rx(), dhcp_request_rx(), dhcpv6_register(), guestinfo_init(), guestinfo_net_probe(), ipv6_register_settings(), memmap_settings_init(), ndp_register_settings(), netdev_redirect_settings_init(), pci_settings_init(), phantom_probe(), register_netdev(), register_nvo(), settings_test_exec(), and smbios_init().

                                           {
        struct settings *old_settings;

        /* Sanity check */
        assert ( settings != NULL );

        /* Find target parent settings block */
        parent = settings_target ( parent );

        /* Apply settings block name */
        settings->name = name;

        /* Remove any existing settings with the same name */
        if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
                unregister_settings ( old_settings );

        /* Add to list of settings */
        ref_get ( settings->refcnt );
        ref_get ( parent->refcnt );
        settings->parent = parent;
        list_add_tail ( &settings->siblings, &parent->children );
        DBGC ( settings, "Settings %p (\"%s\") registered\n",
               settings, settings_name ( settings ) );

        /* Fix up settings priority */
        reprioritise_settings ( settings );

        /* Apply potentially-updated settings */
        apply_settings();

        return 0;
}
void unregister_settings ( struct settings settings)

Unregister settings block.

Parameters:
settingsSettings block

Definition at line 512 of file settings.c.

References apply_settings(), settings::children, DBGC, list_del, list_first_entry, NULL, settings::parent, ref_put, settings::refcnt, settings_name(), settings::siblings, and unregister_settings().

Referenced by guestinfo_net_remove(), ndp_register_settings(), phantom_probe(), phantom_remove(), register_netdev(), register_settings(), settings_test_exec(), unregister_netdev(), unregister_nvo(), and unregister_settings().

                                                       {
        struct settings *child;

        /* Unregister child settings */
        while ( ( child = list_first_entry ( &settings->children,
                                             struct settings, siblings ) ) ) {
                unregister_settings ( child );
        }

        DBGC ( settings, "Settings %p (\"%s\") unregistered\n",
               settings, settings_name ( settings ) );

        /* Remove from list of settings */
        ref_put ( settings->parent->refcnt );
        settings->parent = NULL;
        list_del ( &settings->siblings );
        ref_put ( settings->refcnt );

        /* Apply potentially-updated settings */
        apply_settings();
}
struct settings* settings_target ( struct settings settings) [read]

Redirect to target settings block.

Parameters:
settingsSettings block, or NULL
Return values:
settingsUnderlying settings block

Definition at line 547 of file settings.c.

References settings::op, settings_operations::redirect, and settings_root.

Referenced by autovivify_child_settings(), clear_settings(), fetch_setting(), find_child_settings(), register_settings(), select_settings(), setting_applies(), setting_name(), settings_name(), and store_setting().

                                                                {

        /* NULL settings implies the global settings root */
        if ( ! settings )
                settings = &settings_root;

        /* Redirect to underlying settings block, if applicable */
        if ( settings->op->redirect )
                return settings->op->redirect ( settings );

        /* Otherwise, return this settings block */
        return settings;
}
int setting_applies ( struct settings settings,
const struct setting setting 
)

Check applicability of setting.

Parameters:
settingsSettings block
settingSetting
Return values:
appliesSetting applies within this settings block

Definition at line 568 of file settings.c.

References settings_operations::applies, settings::op, and settings_target().

Referenced by applicable_setting(), select_setting_row(), and store_setting().

                                                      {

        /* Find target settings block */
        settings = settings_target ( settings );

        /* Check applicability of setting */
        return ( settings->op->applies ?
                 settings->op->applies ( settings, setting ) : 1 );
}
int store_setting ( struct settings settings,
const struct setting setting,
const void *  data,
size_t  len 
)

Store value of setting.

Parameters:
settingsSettings block, or NULL
settingSetting to store
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values:
rcReturn status code

Definition at line 613 of file settings.c.

References apply_settings(), ENOTSUP, ENOTTY, settings::op, settings::parent, rc, reprioritise_settings(), setting_applies(), setting_cmp(), settings_root, settings_target(), and settings_operations::store.

Referenced by delete_setting(), login_ui(), nslookup_resolv_done(), storef_setting(), and storen_setting().

                                                   {
        int rc;

        /* Find target settings block */
        settings = settings_target ( settings );

        /* Fail if setting does not apply to this settings block */
        if ( ! setting_applies ( settings, setting ) )
                return -ENOTTY;

        /* Sanity check */
        if ( ! settings->op->store )
                return -ENOTSUP;

        /* Store setting */
        if ( ( rc = settings->op->store ( settings, setting,
                                          data, len ) ) != 0 )
                return rc;

        /* Reprioritise settings if necessary */
        if ( setting_cmp ( setting, &priority_setting ) == 0 )
                reprioritise_settings ( settings );

        /* If these settings are registered, apply potentially-updated
         * settings
         */
        for ( ; settings ; settings = settings->parent ) {
                if ( settings == &settings_root ) {
                        if ( ( rc = apply_settings() ) != 0 )
                                return rc;
                        break;
                }
        }

        return 0;
}
int fetch_setting ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
void *  data,
size_t  len 
)

Fetch setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
originOrigin of setting to fill in, or NULL
fetchedFetched setting to fill in, or NULL
dataBuffer to fill with setting data
lenLength of buffer
Return values:
lenLength of setting data, or negative error

The actual length of the setting will be returned even if the buffer was too small.

Definition at line 665 of file settings.c.

References applicable_setting(), settings::children, ENOENT, ENOTSUP, settings_operations::fetch, fetch_setting(), list_for_each_entry, memcpy(), memset(), NULL, settings::op, ret, settings_target(), and setting::type.

Referenced by fetch_next_server_and_filename(), fetch_raw_setting(), fetch_setting(), fetch_setting_alloc(), ibft_fill_nic(), ibft_set_string_setting(), ipv6_create_routes(), and setting_exists().

                                             {
        const struct setting *applicable;
        struct settings *child;
        struct setting tmp;
        int ret;

        /* Avoid returning uninitialised data on error */
        memset ( data, 0, len );
        if ( origin )
                *origin = NULL;
        if ( fetched )
                memcpy ( fetched, setting, sizeof ( *fetched ) );

        /* Find target settings block */
        settings = settings_target ( settings );

        /* Sanity check */
        if ( ! settings->op->fetch )
                return -ENOTSUP;

        /* Try this block first, if an applicable setting exists */
        if ( ( applicable = applicable_setting ( settings, setting ) ) ) {

                /* Create modifiable copy of setting */
                memcpy ( &tmp, applicable, sizeof ( tmp ) );
                if ( ( ret = settings->op->fetch ( settings, &tmp,
                                                   data, len ) ) >= 0 ) {

                        /* Default to string type, if not yet specified */
                        if ( ! tmp.type )
                                tmp.type = &setting_type_string;

                        /* Record origin, if applicable */
                        if ( origin )
                                *origin = settings;

                        /* Record fetched setting, if applicable */
                        if ( fetched )
                                memcpy ( fetched, &tmp, sizeof ( *fetched ) );

                        return ret;
                }
        }

        /* Recurse into each child block in turn */
        list_for_each_entry ( child, &settings->children, siblings ) {
                if ( ( ret = fetch_setting ( child, setting, origin, fetched,
                                             data, len ) ) >= 0 )
                        return ret;
        }

        return -ENOENT;
}
int fetch_setting_copy ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
void **  data 
)

Fetch copy of setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
originOrigin of setting to fill in, or NULL
fetchedFetched setting to fill in, or NULL
dataBuffer to allocate and fill with setting data
Return values:
lenLength of setting, or negative error

The caller is responsible for eventually freeing the allocated buffer.

Definition at line 784 of file settings.c.

References fetch_setting_alloc(), and malloc().

Referenced by apply_dns_search(), fetch_raw_setting_copy(), fetchf_setting(), and fetchn_setting().

                                       {

        return fetch_setting_alloc ( settings, setting, origin, fetched,
                                     data, malloc );
}
int fetch_raw_setting ( struct settings settings,
const struct setting setting,
void *  data,
size_t  len 
)

Fetch value of setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
dataBuffer to fill with setting string data
lenLength of buffer
Return values:
lenLength of setting, or negative error

Definition at line 802 of file settings.c.

References fetch_setting(), and NULL.

Referenced by dhcp_create_request(), dhcpv6_user_class(), fetch_ipv4_array_setting(), fetch_ipv6_array_setting(), fetch_numeric_setting(), fetch_string_setting(), fetch_uuid_setting(), pxe_menu_parse(), start_pxebs(), trivial_change_key(), and trivial_init().

                                                 {

        return fetch_setting ( settings, setting, NULL, NULL, data, len );
}
int fetch_raw_setting_copy ( struct settings settings,
const struct setting setting,
void **  data 
)

Fetch value of setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
dataBuffer to allocate and fill with setting data
Return values:
lenLength of setting, or negative error

The caller is responsible for eventually freeing the allocated buffer.

Definition at line 820 of file settings.c.

References fetch_setting_copy(), and NULL.

Referenced by certstore_apply_settings(), copy_encap_settings(), dhcp_create_request(), privkey_apply_settings(), and rootcert_init().

                                           {

        return fetch_setting_copy ( settings, setting, NULL, NULL, data );
}
int fetch_string_setting ( struct settings settings,
const struct setting setting,
char *  data,
size_t  len 
)

Fetch value of string setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
dataBuffer to fill with setting string data
lenLength of buffer
Return values:
lenLength of string setting, or negative error

The resulting string is guaranteed to be correctly NUL-terminated. The returned length will be the length of the underlying setting data.

Definition at line 840 of file settings.c.

References fetch_raw_setting(), and memset().

Referenced by have_pxe_menu(), ib_sma_node_desc(), ibft_set_string_setting(), login_ui(), net80211_autoassociate(), net80211_check_settings_update(), wpa_psk_start(), and xsigo_xds_complete().

                                                    {

        memset ( data, 0, len );
        return fetch_raw_setting ( settings, setting, data,
                                   ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
}
int fetch_string_setting_copy ( struct settings settings,
const struct setting setting,
char **  data 
)

Fetch value of string setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
dataBuffer to allocate and fill with setting string data
Return values:
lenLength of string setting, or negative error

The resulting string is guaranteed to be correctly NUL-terminated. The returned length will be the length of the underlying setting data. The caller is responsible for eventually freeing the allocated buffer.

Definition at line 872 of file settings.c.

References fetch_setting_alloc(), fetch_string_setting_copy_alloc(), and NULL.

Referenced by apply_dns_search(), apply_syslog_settings(), apply_syslogs_settings(), fetch_next_server_and_filename(), fetch_root_path(), fetch_san_filename(), ipxe(), iscsi_fetch_settings(), oncrpc_init_cred_sys(), and validator_start_download().

                                                                             {

        return fetch_setting_alloc ( settings, setting, NULL, NULL,
                                     ( ( void ** ) data ),
                                     fetch_string_setting_copy_alloc );
}
int fetch_ipv4_array_setting ( struct settings settings,
const struct setting setting,
struct in_addr inp,
unsigned int  count 
)

Fetch value of IPv4 address setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
inpIPv4 addresses to fill in
countMaximum number of IPv4 addresses
Return values:
lenLength of setting, or negative error

Definition at line 889 of file settings.c.

References ERANGE, fetch_raw_setting(), and len.

Referenced by fetch_ipv4_setting(), and ibft_set_ipaddr_setting().

                                                                         {
        int len;

        len = fetch_raw_setting ( settings, setting, inp,
                                  ( sizeof ( *inp ) * count ) );
        if ( len < 0 )
                return len;
        if ( ( len % sizeof ( *inp ) ) != 0 )
                return -ERANGE;
        return len;
}
int fetch_ipv4_setting ( struct settings settings,
const struct setting setting,
struct in_addr inp 
)

Fetch value of IPv4 address setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
inpIPv4 address to fill in
Return values:
lenLength of setting, or negative error

Definition at line 911 of file settings.c.

References fetch_ipv4_array_setting().

Referenced by apply_dns_settings(), apply_syslog_settings(), create_fakepxebsack(), efi_pxe_install(), efi_pxe_ip(), fetch_next_server_and_filename(), gdbudp_configure(), ibft_fill_nic(), ipv4_settings(), start_pxebs(), and tftp_apply_settings().

                                               {

        return fetch_ipv4_array_setting ( settings, setting, inp, 1 );
}
int fetch_ipv6_array_setting ( struct settings settings,
const struct setting setting,
struct in6_addr inp,
unsigned int  count 
)

Fetch value of IPv6 address setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
inpIPv6 addresses to fill in
countMaximum number of IPv6 addresses
Return values:
lenLength of setting, or negative error

Definition at line 927 of file settings.c.

References ERANGE, fetch_raw_setting(), and len.

Referenced by fetch_ipv6_setting().

                                                                          {
        int len;

        len = fetch_raw_setting ( settings, setting, inp,
                                  ( sizeof ( *inp ) * count ) );
        if ( len < 0 )
                return len;
        if ( ( len % sizeof ( *inp ) ) != 0 )
                return -ERANGE;
        return len;
}
int fetch_ipv6_setting ( struct settings settings,
const struct setting setting,
struct in6_addr inp 
)

Fetch value of IPv6 address setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
inpIPv6 address to fill in
Return values:
lenLength of setting, or negative error

Definition at line 949 of file settings.c.

References fetch_ipv6_array_setting().

Referenced by apply_dns_settings(), and apply_syslog_settings().

                                                {

        return fetch_ipv6_array_setting ( settings, setting, inp, 1 );
}
int fetch_int_setting ( struct settings settings,
const struct setting setting,
long *  value 
)

Fetch value of signed integer setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
valueInteger value to fill in
Return values:
lenLength of setting, or negative error

Definition at line 1022 of file settings.c.

References fetch_numeric_setting().

                                      {

        return fetch_numeric_setting ( settings, setting,
                                       ( ( unsigned long * ) value ), 1 );
}
int fetch_uint_setting ( struct settings settings,
const struct setting setting,
unsigned long *  value 
)

Fetch value of unsigned integer setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
valueInteger value to fill in
Return values:
lenLength of setting, or negative error

Definition at line 1038 of file settings.c.

References fetch_numeric_setting().

Referenced by san_default_drive(), and sandev_apply().

                                                {

        return fetch_numeric_setting ( settings, setting, value, 0 );
}
long fetch_intz_setting ( struct settings settings,
const struct setting setting 
)

Fetch value of signed integer setting, or zero.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
Return values:
valueSetting value, or zero

Definition at line 1052 of file settings.c.

References fetch_numeric_setting(), and value.

Referenced by net80211_step_associate(), reprioritise_settings(), and uriboot().

                                                          {
        unsigned long value;

        fetch_numeric_setting ( settings, setting, &value, 1 );
        return value;
}
unsigned long fetch_uintz_setting ( struct settings settings,
const struct setting setting 
)

Fetch value of unsigned integer setting, or zero.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
Return values:
valueSetting value, or zero

Definition at line 1067 of file settings.c.

References fetch_numeric_setting(), and value.

Referenced by apply_netdev_settings(), have_pxe_menu(), oncrpc_init_cred_sys(), and start_pxebs().

                                                                    {
        unsigned long value;

        fetch_numeric_setting ( settings, setting, &value, 0 );
        return value;
}
int fetch_uuid_setting ( struct settings settings,
const struct setting setting,
union uuid uuid 
)

Fetch value of UUID setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
uuidUUID to fill in
Return values:
lenLength of setting, or negative error

Definition at line 1083 of file settings.c.

References ERANGE, fetch_raw_setting(), and len.

Referenced by dhcp_create_request(), iscsi_fetch_settings(), rbg_startup(), and start_dhcpv6().

                                            {
        int len;

        len = fetch_raw_setting ( settings, setting, uuid, sizeof ( *uuid ) );
        if ( len < 0 )
                return len;
        if ( len != sizeof ( *uuid ) )
                return -ERANGE;
        return len;
}
void clear_settings ( struct settings settings)

Clear settings block.

Parameters:
settingsSettings block

Definition at line 1101 of file settings.c.

References settings_operations::clear, settings::op, and settings_target().

Referenced by free_netdev(), register_netdev(), settings_test_exec(), and unregister_netdev().

                                                  {

        /* Find target settings block */
        settings = settings_target ( settings );

        /* Clear settings, if applicable */
        if ( settings->op->clear )
                settings->op->clear ( settings );
}
int setting_cmp ( const struct setting a,
const struct setting b 
)

Compare two settings.

Parameters:
aSetting to compare
bSetting to compare
Return values:
0Settings are the same
non-zeroSettings are not the same

Definition at line 1119 of file settings.c.

References setting::name, setting::scope, strcmp(), and setting::tag.

Referenced by applicable_setting(), builtin_fetch(), dhcpv6_applies(), dhcpv6_fetch(), efi_snp_hii_questions(), find_generic_setting(), ipv6_fetch(), ndp_prefix_fetch(), netdev_fetch(), netdev_store(), parse_setting_name(), phantom_clp_setting(), select_setting_row(), and store_setting().

                                                                     {

        /* If the settings have tags, compare them */
        if ( a->tag && ( a->tag == b->tag ) && ( a->scope == b->scope ) )
                return 0;

        /* Otherwise, if the settings have names, compare them */
        if ( a->name && b->name && a->name[0] )
                return strcmp ( a->name, b->name );

        /* Otherwise, return a non-match */
        return ( ! 0 );
}
struct settings* find_child_settings ( struct settings parent,
const char *  name 
) [read]

Find child settings block.

Parameters:
parentParent settings block
nameName within this parent
Return values:
settingsSettings block, or NULL

Definition at line 279 of file settings.c.

References settings::children, list_for_each_entry, settings::name, NULL, settings_target(), and strcmp().

Referenced by autovivify_child_settings(), efi_snp_hii_settings(), expand_settings(), find_settings(), parse_existing_setting(), and register_settings().

                                                           {
        struct settings *settings;

        /* Find target parent settings block */
        parent = settings_target ( parent );

        /* Treat empty name as meaning "this block" */
        if ( ! *name )
                return parent;

        /* Look for child with matching name */
        list_for_each_entry ( settings, &parent->children, siblings ) {
                if ( strcmp ( settings->name, name ) == 0 )
                        return settings_target ( settings );
        }

        return NULL;
}
struct settings* autovivify_child_settings ( struct settings parent,
const char *  name 
) [read]

Find or create child settings block.

Parameters:
parentParent settings block
nameName within this parent
Return values:
settingsSettings block, or NULL

Definition at line 306 of file settings.c.

References autovivified_settings_free(), DBGC, find_child_settings(), generic_settings_init(), memcpy(), settings::name, NULL, ref_init, ref_put, settings::refcnt, register_settings(), settings_target(), strlen(), and zalloc().

Referenced by nslookup_resolv_done(), and parse_autovivified_setting().

                                                                 {
        struct {
                struct autovivified_settings autovivified;
                char name[ strlen ( name ) + 1 /* NUL */ ];
        } *new_child;
        struct settings *settings;

        /* Find target parent settings block */
        parent = settings_target ( parent );

        /* Return existing settings, if existent */
        if ( ( settings = find_child_settings ( parent, name ) ) != NULL )
                return settings;

        /* Create new generic settings block */
        new_child = zalloc ( sizeof ( *new_child ) );
        if ( ! new_child ) {
                DBGC ( parent, "Settings %p could not create child %s\n",
                       parent, name );
                return NULL;
        }
        memcpy ( new_child->name, name, sizeof ( new_child->name ) );
        ref_init ( &new_child->autovivified.refcnt,
                   autovivified_settings_free );
        generic_settings_init ( &new_child->autovivified.generic,
                                &new_child->autovivified.refcnt );
        settings = &new_child->autovivified.generic.settings;
        register_settings ( settings, parent, new_child->name );
        ref_put ( settings->refcnt );
        return settings;
}
const char* settings_name ( struct settings settings)

Return settings block name.

Parameters:
settingsSettings block
Return values:
nameSettings block name

Definition at line 345 of file settings.c.

References memcpy(), settings_target(), and snprintf().

Referenced by draw_title_row(), parse_setting_name(), register_settings(), setting_name(), and unregister_settings().

                                                         {
        static char buf[16];
        char tmp[ 1 /* '.' */ + sizeof ( buf ) ];

        /* Find target settings block */
        settings = settings_target ( settings );

        /* Construct name */
        buf[0] = '\0';
        tmp[0] = '\0';
        for ( ; settings->parent ; settings = settings->parent ) {
                memcpy ( ( tmp + 1 ), buf, ( sizeof ( tmp ) - 1 ) );
                snprintf ( buf, sizeof ( buf ), "%s%s", settings->name, tmp );
                tmp[0] = '.';
        }
        return buf;
}
struct settings* find_settings ( const char *  name) [read]

Find settings block.

Parameters:
nameName
Return values:
settingsSettings block, or NULL

Definition at line 401 of file settings.c.

References find_child_settings(), and parse_settings_name().

Referenced by create_fakepxebsack(), parse_settings(), and pxe_menu_boot().

struct setting* find_setting ( const char *  name) [read]

Find predefined setting.

Parameters:
nameName
Return values:
settingSetting, or NULL

Definition at line 1465 of file settings.c.

References for_each_table_entry, setting::name, NULL, generic_setting::setting, SETTINGS, and strcmp().

Referenced by efi_snp_hii_fetch(), efi_snp_hii_store(), and guestinfo_fetch_type().

                                                   {
        struct setting *setting;

        for_each_table_entry ( setting, SETTINGS ) {
                if ( strcmp ( name, setting->name ) == 0 )
                        return setting;
        }
        return NULL;
}
int parse_setting_name ( char *  name,
get_child_settings_t  get_child,
struct settings **  settings,
struct setting setting 
)

Parse setting name.

Parameters:
nameName of setting
get_childFunction to find or create child settings block
settingsSettings block to fill in
settingSetting to fill in
Return values:
rcReturn status code

Interprets a name of the form "[settings_name/]tag_name[:type_name]" and fills in the appropriate fields.

Note that on success, this function will have modified the original setting name.

Definition at line 1527 of file settings.c.

References DBG, ENODEV, ENOTSUP, find_setting_type(), for_each_table_entry, memcpy(), memset(), setting::name, name, NULL, parse_setting_tag(), parse_settings_name(), rc, setting::scope, setting_cmp(), setting_name(), SETTINGS, settings_name(), settings_root, strchr(), setting::tag, and setting::type.

Referenced by expand_settings(), nslookup_resolv_done(), and parse_setting().

                                                                               {
        char *settings_name;
        char *setting_name;
        char *type_name;
        struct setting *predefined;
        int rc;

        /* Set defaults */
        *settings = &settings_root;
        memset ( setting, 0, sizeof ( *setting ) );
        setting->name = "";

        /* Split name into "[settings_name/]setting_name[:type_name]" */
        if ( ( setting_name = strchr ( name, '/' ) ) != NULL ) {
                *(setting_name++) = 0;
                settings_name = name;
        } else {
                setting_name = name;
                settings_name = NULL;
        }
        if ( ( type_name = strchr ( setting_name, ':' ) ) != NULL )
                *(type_name++) = 0;

        /* Identify settings block, if specified */
        if ( settings_name ) {
                *settings = parse_settings_name ( settings_name, get_child );
                if ( *settings == NULL ) {
                        DBG ( "Unrecognised settings block \"%s\" in \"%s\"\n",
                              settings_name, name );
                        rc = -ENODEV;
                        goto err;
                }
        }

        /* Identify setting */
        setting->tag = parse_setting_tag ( setting_name );
        setting->scope = (*settings)->default_scope;
        setting->name = setting_name;
        for_each_table_entry ( predefined, SETTINGS ) {
                /* Matches a predefined setting; use that setting */
                if ( setting_cmp ( predefined, setting ) == 0 ) {
                        memcpy ( setting, predefined, sizeof ( *setting ) );
                        break;
                }
        }

        /* Identify setting type, if specified */
        if ( type_name ) {
                setting->type = find_setting_type ( type_name );
                if ( setting->type == NULL ) {
                        DBG ( "Invalid setting type \"%s\" in \"%s\"\n",
                              type_name, name );
                        rc = -ENOTSUP;
                        goto err;
                }
        }

        return 0;

 err:
        /* Restore original name */
        if ( settings_name )
                *( setting_name - 1 ) = '/';
        if ( type_name )
                *( type_name - 1 ) = ':';
        return rc;
}
int setting_name ( struct settings settings,
const struct setting setting,
char *  buf,
size_t  len 
)

Return full setting name.

Parameters:
settingsSettings block, or NULL
settingSetting
bufBuffer
lenLength of buffer
Return values:
lenLength of setting name, or negative error

Definition at line 1605 of file settings.c.

References setting::name, setting_type::name, name, settings_name(), settings_target(), snprintf(), and setting::type.

Referenced by draw_info_row(), nslookup_exec(), parse_setting_name(), and show_exec().

                                           {
        const char *name;

        settings = settings_target ( settings );
        name = settings_name ( settings );
        return snprintf ( buf, len, "%s%s%s:%s", name, ( name[0] ? "/" : "" ),
                          setting->name, setting->type->name );
}
int setting_format ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
)

Format setting value as a string.

Parameters:
typeSetting type
rawRaw setting value
raw_lenLength of raw setting value
bufBuffer to contain formatted value
lenLength of buffer
Return values:
lenLength of formatted value, or negative error

Definition at line 1150 of file settings.c.

References ENOTSUP, and setting_type::format.

Referenced by fetchf_setting().

                                                             {

        /* Sanity check */
        if ( ! type->format )
                return -ENOTSUP;

        return type->format ( type, raw, raw_len, buf, len );
}
int setting_parse ( const struct setting_type type,
const char *  value,
void *  buf,
size_t  len 
)

Parse formatted string to setting value.

Parameters:
typeSetting type
valueFormatted setting value
bufBuffer to contain raw value
lenLength of buffer
Return values:
lenLength of raw value, or negative error

Definition at line 1169 of file settings.c.

References ENOTSUP, and setting_type::parse.

Referenced by guestinfo_fetch_type(), and storef_setting().

                                            {

        /* Sanity check */
        if ( ! type->parse )
                return -ENOTSUP;

        return type->parse ( type, value, buf, len );
}
int setting_numerate ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
unsigned long *  value 
)

Convert setting value to number.

Parameters:
typeSetting type
rawRaw setting value
raw_lenLength of raw setting value
Return values:
valueNumeric value
rcReturn status code

Definition at line 1188 of file settings.c.

References ENOTSUP, and setting_type::numerate.

Referenced by fetchn_setting().

                                                              {

        /* Sanity check */
        if ( ! type->numerate )
                return -ENOTSUP;

        return type->numerate ( type, raw, raw_len, value );
}
int setting_denumerate ( const struct setting_type type,
unsigned long  value,
void *  buf,
size_t  len 
)

Convert number to setting value.

Parameters:
typeSetting type
valueNumeric value
bufBuffer to contain raw value
lenLength of buffer
Return values:
lenLength of raw value, or negative error

Definition at line 1207 of file settings.c.

References setting_type::denumerate, and ENOTSUP.

Referenced by storen_setting().

                                                 {

        /* Sanity check */
        if ( ! type->denumerate )
                return -ENOTSUP;

        return type->denumerate ( type, value, buf, len );
}
int fetchf_setting ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
char *  buf,
size_t  len 
)

Fetch formatted value of setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
originOrigin of setting to fill in, or NULL
fetchedFetched setting to fill in, or NULL
bufBuffer to contain formatted value
lenLength of buffer
Return values:
lenLength of formatted value, or negative error

Definition at line 1228 of file settings.c.

References assert, fetch_setting_copy(), free, NULL, raw, raw_len, ret, setting_format(), and setting::type.

Referenced by efi_snp_hii_fetch(), fetchf_setting_copy(), and select_setting_row().

                                             {
        struct setting tmp_fetched;
        void *raw;
        int raw_len;
        int ret;

        /* Use local buffers if necessary */
        if ( ! fetched )
                fetched = &tmp_fetched;

        /* Fetch raw value */
        raw_len = fetch_setting_copy ( settings, setting, origin, fetched,
                                       &raw );
        if ( raw_len < 0 ) {
                ret = raw_len;
                goto err_fetch_copy;
        }

        /* Sanity check */
        assert ( fetched->type != NULL );

        /* Format setting */
        if ( ( ret = setting_format ( fetched->type, raw, raw_len, buf,
                                      len ) ) < 0 )
                goto err_format;

 err_format:
        free ( raw );
 err_fetch_copy:
        return ret;
}
int fetchf_setting_copy ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
char **  value 
)

Fetch copy of formatted value of setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
originOrigin of setting to fill in, or NULL
fetchedFetched setting to fill in, or NULL
valueBuffer to allocate and fill with formatted value
Return values:
lenLength of formatted value, or negative error

The caller is responsible for eventually freeing the allocated buffer.

Definition at line 1275 of file settings.c.

References assert, ENOMEM, fetchf_setting(), len, NULL, and zalloc().

Referenced by expand_settings(), read_value(), and show_exec().

                                         {
        struct settings *tmp_origin;
        struct setting tmp_fetched;
        int len;
        int check_len;

        /* Use local buffers if necessary */
        if ( ! origin )
                origin = &tmp_origin;
        if ( ! fetched )
                fetched = &tmp_fetched;

        /* Avoid returning uninitialised data on error */
        *value = NULL;

        /* Check existence, and fetch formatted value length */
        len = fetchf_setting ( settings, setting, origin, fetched, NULL, 0 );
        if ( len < 0 )
                return len;

        /* Allocate buffer */
        *value = zalloc ( len + 1 /* NUL */ );
        if ( ! *value )
                return -ENOMEM;

        /* Fetch formatted value */
        check_len = fetchf_setting ( *origin, fetched, NULL, NULL, *value,
                                     ( len + 1 /* NUL */ ) );
        assert ( check_len == len );
        return len;
}
int storef_setting ( struct settings settings,
const struct setting setting,
const char *  value 
)

Store formatted value of setting.

Parameters:
settingsSettings block
settingSetting to store
valueFormatted setting data, or NULL
Return values:
rcReturn status code

Definition at line 1318 of file settings.c.

References assert, delete_setting(), ENOMEM, free, malloc(), NULL, raw, raw_len, rc, setting_parse(), store_setting(), and setting::type.

Referenced by choose_exec(), efi_snp_hii_store(), save_setting(), and set_core_exec().

                                         {
        void *raw;
        int raw_len;
        int check_len;
        int rc;

        /* NULL value or empty string implies deletion */
        if ( ( ! value ) || ( ! value[0] ) )
                return delete_setting ( settings, setting );

        /* Sanity check */
        assert ( setting->type != NULL );

        /* Get raw value length */
        raw_len = setting_parse ( setting->type, value, NULL, 0 );
        if ( raw_len < 0 ) {
                rc = raw_len;
                goto err_raw_len;
        }

        /* Allocate buffer for raw value */
        raw = malloc ( raw_len );
        if ( ! raw ) {
                rc = -ENOMEM;
                goto err_alloc_raw;
        }

        /* Parse formatted value */
        check_len = setting_parse ( setting->type, value, raw, raw_len );
        assert ( check_len == raw_len );

        /* Store raw value */
        if ( ( rc = store_setting ( settings, setting, raw, raw_len ) ) != 0 )
                goto err_store;

 err_store:
        free ( raw );
 err_alloc_raw:
 err_raw_len:
        return rc;
}
int fetchn_setting ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
unsigned long *  value 
)

Fetch numeric value of setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
originOrigin of setting to fill in, or NULL
fetchedFetched setting to fill in, or NULL
valueNumeric value to fill in
Return values:
rcReturn status code

Definition at line 1371 of file settings.c.

References assert, fetch_setting_copy(), free, NULL, raw, raw_len, rc, setting_numerate(), and setting::type.

Referenced by inc_exec(), and pciscan_exec().

                                            {
        struct setting tmp_fetched;
        void *raw;
        int raw_len;
        int rc;

        /* Use local buffers if necessary */
        if ( ! fetched )
                fetched = &tmp_fetched;

        /* Fetch raw value */
        raw_len = fetch_setting_copy ( settings, setting, origin, fetched,
                                       &raw );
        if ( raw_len < 0 ) {
                rc = raw_len;
                goto err_fetch_copy;
        }

        /* Sanity check */
        assert ( fetched->type != NULL );

        /* Numerate setting */
        if ( ( rc = setting_numerate ( fetched->type, raw, raw_len,
                                       value ) ) < 0 )
                goto err_numerate;

 err_numerate:
        free ( raw );
 err_fetch_copy:
        return rc;
}
int storen_setting ( struct settings settings,
const struct setting setting,
unsigned long  value 
)

Store numeric value of setting.

Parameters:
settingsSettings block
settingSetting
valueNumeric value
Return values:
rcReturn status code

Definition at line 1413 of file settings.c.

References assert, ENOMEM, free, malloc(), NULL, raw, raw_len, rc, setting_denumerate(), store_setting(), and setting::type.

Referenced by inc_exec(), and pciscan_exec().

                                           {
        void *raw;
        int raw_len;
        int check_len;
        int rc;

        /* Sanity check */
        assert ( setting->type != NULL );

        /* Get raw value length */
        raw_len = setting_denumerate ( setting->type, value, NULL, 0 );
        if ( raw_len < 0 ) {
                rc = raw_len;
                goto err_raw_len;
        }

        /* Allocate buffer for raw value */
        raw = malloc ( raw_len );
        if ( ! raw ) {
                rc = -ENOMEM;
                goto err_alloc_raw;
        }

        /* Denumerate value */
        check_len = setting_denumerate ( setting->type, value, raw, raw_len );
        assert ( check_len == raw_len );

        /* Store raw value */
        if ( ( rc = store_setting ( settings, setting, raw, raw_len ) ) != 0 )
                goto err_store;

 err_store:
        free ( raw );
 err_alloc_raw:
 err_raw_len:
        return rc;
}
char* expand_settings ( const char *  string)

Expand variables within string.

Parameters:
stringString
Return values:
expstrExpanded string

The expanded string is allocated with malloc() and the caller must eventually free() it.

Definition at line 2283 of file settings.c.

References asprintf(), end, fetchf_setting_copy(), find_child_settings(), free, head, name, NULL, parse_setting_name(), rc, generic_setting::setting, start, strdup(), and value.

Referenced by expand_tokens(), fetch_next_server_and_filename(), fetch_root_path(), and fetch_san_filename().

                                              {
        struct settings *settings;
        struct setting setting;
        char *expstr;
        char *start;
        char *end;
        char *head;
        char *name;
        char *tail;
        char *value;
        char *tmp;
        int new_len;
        int rc;

        /* Obtain temporary modifiable copy of string */
        expstr = strdup ( string );
        if ( ! expstr )
                return NULL;

        /* Expand while expansions remain */
        while ( 1 ) {

                head = expstr;

                /* Locate setting to be expanded */
                start = NULL;
                end = NULL;
                for ( tmp = expstr ; *tmp ; tmp++ ) {
                        if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
                                start = tmp;
                        if ( start && ( tmp[0] == '}' ) ) {
                                end = tmp;
                                break;
                        }
                }
                if ( ! end )
                        break;
                *start = '\0';
                name = ( start + 2 );
                *end = '\0';
                tail = ( end + 1 );

                /* Expand setting */
                if ( ( rc = parse_setting_name ( name, find_child_settings,
                                                 &settings,
                                                 &setting ) ) != 0 ) {
                        /* Treat invalid setting names as empty */
                        value = NULL;
                } else {
                        /* Fetch and format setting value.  Ignore
                         * errors; treat non-existent settings as empty.
                         */
                        fetchf_setting_copy ( settings, &setting, NULL, NULL,
                                              &value );
                }

                /* Construct expanded string and discard old string */
                tmp = expstr;
                new_len = asprintf ( &expstr, "%s%s%s",
                                     head, ( value ? value : "" ), tail );
                free ( value );
                free ( tmp );
                if ( new_len < 0 )
                        return NULL;
        }

        return expstr;
}
struct setting ip_setting __setting ( SETTING_IP4  ,
ip   
) [read]
struct setting netmask_setting __setting ( SETTING_IP4  ,
netmask   
) [read]
struct setting gateway_setting __setting ( SETTING_IP4  ,
gateway   
) [read]
struct setting dns_setting __setting ( SETTING_IP4_EXTRA  ,
dns   
) [read]
struct setting ip6_setting __setting ( SETTING_IP6  ,
ip6   
) [read]
struct setting len6_setting __setting ( SETTING_IP6  ,
len6   
) [read]
struct setting gateway6_setting __setting ( SETTING_IP6  ,
gateway6   
) [read]
struct setting hostname_setting __setting ( SETTING_HOST  ,
hostname   
) [read]
struct setting domain_setting __setting ( SETTING_IP_EXTRA  ,
domain   
) [read]
struct setting filename_setting __setting ( SETTING_BOOT  ,
filename   
) [read]
struct setting root_path_setting __setting ( SETTING_SANBOOT  ,
root path 
) [read]
struct setting san_filename_setting __setting ( SETTING_SANBOOT  ,
san-  filename 
) [read]
struct setting username_setting __setting ( SETTING_AUTH  ,
username   
) [read]
struct setting password_setting __setting ( SETTING_AUTH  ,
password   
) [read]
struct setting priority_setting __setting ( SETTING_MISC  ,
priority   
) [read]
struct setting uuid_setting __setting ( SETTING_HOST  ,
uuid   
) [read]
struct setting next_server_setting __setting ( SETTING_BOOT  ,
next server 
) [read]
struct setting mac_setting __setting ( SETTING_NETDEV  ,
mac   
) [read]
struct setting busid_setting __setting ( SETTING_NETDEV  ,
busid   
) [read]
struct setting user_class_setting __setting ( SETTING_HOST_EXTRA  ,
user class 
) [read]
struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA  ,
vendor class 
) [read]
struct setting manufacturer_setting __setting ( SETTING_HOST_EXTRA  ,
manufacturer   
) [read]
struct setting product_setting __setting ( SETTING_HOST_EXTRA  ,
product   
) [read]
struct setting serial_setting __setting ( SETTING_HOST_EXTRA  ,
serial   
) [read]
struct setting asset_setting __setting ( SETTING_HOST_EXTRA  ,
asset   
) [read]
struct setting board_serial_setting __setting ( SETTING_HOST_EXTRA  ,
board-  serial 
) [read]
struct setting dhcp_server_setting __setting ( SETTING_MISC  ,
dhcp-  server 
) [read]
static void settings_init ( struct settings settings,
struct settings_operations op,
struct refcnt refcnt,
const struct settings_scope default_scope 
) [inline, static]

Initialise a settings block.

Parameters:
settingsSettings block
opSettings block operations
refcntContaining object reference counter, or NULL
default_scopeDefault scope

Definition at line 495 of file settings.h.

References settings::children, settings::default_scope, INIT_LIST_HEAD, settings::op, op, settings::refcnt, and settings::siblings.

Referenced by dhcppkt_init(), dhcpv6_register(), generic_settings_init(), guestinfo_net_probe(), ipv6_register_settings(), ndp_register_settings(), nvo_init(), and phantom_probe().

                                                                               {
        INIT_LIST_HEAD ( &settings->siblings );
        INIT_LIST_HEAD ( &settings->children );
        settings->op = op;
        settings->refcnt = refcnt;
        settings->default_scope = default_scope;
}
static void generic_settings_init ( struct generic_settings generics,
struct refcnt refcnt 
) [inline, static]

Initialise a settings block.

Parameters:
genericsGeneric settings block
refcntContaining object reference counter, or NULL

Definition at line 512 of file settings.h.

References generic_settings_operations, INIT_LIST_HEAD, generic_settings::list, NULL, generic_settings::settings, and settings_init().

Referenced by autovivify_child_settings(), and netdev_settings_init().

                                                                   {
        settings_init ( &generics->settings, &generic_settings_operations,
                        refcnt, NULL );
        INIT_LIST_HEAD ( &generics->list );
}
static int delete_setting ( struct settings settings,
const struct setting setting 
) [inline, static]

Delete setting.

Parameters:
settingsSettings block
settingSetting to delete
Return values:
rcReturn status code

Definition at line 526 of file settings.h.

References NULL, and store_setting().

Referenced by main_loop(), and storef_setting().

                                                                   {
        return store_setting ( settings, setting, NULL, 0 );
}
static int setting_exists ( struct settings settings,
const struct setting setting 
) [inline, static]

Check existence of predefined setting.

Parameters:
settingsSettings block, or NULL to search all blocks
settingSetting to fetch
Return values:
existsSetting exists

Definition at line 538 of file settings.h.

References fetch_setting(), and NULL.

Referenced by efi_snp_hii_fetch(), and have_pxe_menu().

                                                                   {
        return ( fetch_setting ( settings, setting, NULL, NULL,
                                 NULL, 0 ) >= 0 );
}

Variable Documentation

Built-in setting scope.

Definition at line 2458 of file settings.c.

IPv6 setting scope.

Definition at line 1120 of file ipv6.c.

Referenced by ipv6_applies(), ipv6_register_settings(), and ndp_prefix_applies().

DHCPv6 setting scope.

Definition at line 1791 of file settings.c.

Referenced by dhcpv6_applies(), and dhcpv6_register().

Generic settings operations.

Definition at line 221 of file settings.c.

Referenced by generic_settings_init().

struct setting_type setting_type_dnssl __setting_type

A string setting type.

PCI bus:dev.fn setting type.

UUID setting type.

A Base64-encoded setting.

A hex-string setting (non-delimited)

A hex-string setting (hyphen-delimited)

A hex-string setting (colon-delimited)

An unsigned 32-bit integer setting type.

An unsigned 16-bit integer setting type.

An unsigned 8-bit integer setting type.

A signed 32-bit integer setting type.

A signed 16-bit integer setting type.

A signed 8-bit integer setting type.

An IPv6 address setting type.

An IPv4 address setting type.

A URI-encoded string setting type.

Definition at line 415 of file settings.h.