iPXE
Data Structures | Defines | Enumerations | Functions | Variables
settings.c File Reference

Configuration settings. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <byteswap.h>
#include <errno.h>
#include <assert.h>
#include <time.h>
#include <ipxe/in.h>
#include <ipxe/ip.h>
#include <ipxe/ipv6.h>
#include <ipxe/vsprintf.h>
#include <ipxe/dhcp.h>
#include <ipxe/uuid.h>
#include <ipxe/uri.h>
#include <ipxe/base16.h>
#include <ipxe/base64.h>
#include <ipxe/pci.h>
#include <ipxe/init.h>
#include <ipxe/version.h>
#include <ipxe/settings.h>

Go to the source code of this file.

Data Structures

struct  generic_setting
 A generic setting. More...
struct  autovivified_settings
 Autovivified settings block. More...

Defines

#define settings_root   generic_settings_root.settings
 Root settings block.
#define SETTING_TYPE_UINT_NAME(index)   setting_type_int_name[index]
 Get unsigned integer setting type name.
#define SETTING_TYPE_INT_NAME(index)   ( setting_type_int_name[index] + 1 )
 Get signed integer setting type name.
#define SETTING_TYPE_INT(index)
 Define a signed integer setting type.
#define SETTING_TYPE_UINT(index)
 Define an unsigned integer setting type.

Enumerations

enum  setting_type_int_index { SETTING_TYPE_INT8 = 0, SETTING_TYPE_INT16 = 1, SETTING_TYPE_INT32 = 2 }
 Integer setting type indices. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void * generic_setting_name (struct generic_setting *generic)
 Get generic setting name.
static void * generic_setting_data (struct generic_setting *generic)
 Get generic setting data.
static struct generic_settingfind_generic_setting (struct generic_settings *generics, const struct setting *setting)
 Find generic setting.
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.
static void autovivified_settings_free (struct refcnt *refcnt)
 Free autovivified settings block.
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.
static struct settingsparse_settings_name (const char *name, get_child_settings_t get_child)
 Parse settings block name.
struct settingsfind_settings (const char *name)
 Find settings block.
static int apply_settings (void)
 Apply all settings.
static void reprioritise_settings (struct settings *settings)
 Reprioritise settings.
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.
static struct settingapplicable_setting (struct settings *settings, const struct setting *setting)
 Find setting applicable to settings block, if any.
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.
static int fetch_setting_alloc (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data, void *(*alloc)(size_t len))
 Fetch allocated copy of 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.
static void * fetch_string_setting_copy_alloc (size_t len)
 Allocate memory for copy 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.
static int numeric_setting_value (int is_signed, const void *raw, size_t len, unsigned long *value)
 Extract numeric value of setting.
int fetch_numeric_setting (struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
 Fetch value of numeric 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.
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.
struct settingfind_setting (const char *name)
 Find predefined setting.
static uint64_t parse_setting_tag (const char *name)
 Parse setting name as tag number.
static struct setting_typefind_setting_type (const char *name)
 Find setting type.
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.
static int parse_string_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse string setting value.
static int format_string_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format string setting value.
static int parse_uristring_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse URI-encoded string setting value.
static int format_uristring_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format URI-encoded string setting value.
__weak int parse_ipv4_setting (const struct setting_type *type __unused, const char *value __unused, void *buf __unused, size_t len __unused)
 Parse IPv4 address setting value (when IPv4 support is not present)
__weak int format_ipv4_setting (const struct setting_type *type __unused, const void *raw __unused, size_t raw_len __unused, char *buf __unused, size_t len __unused)
 Format IPv4 address setting value (when IPv4 support is not present)
__weak int parse_ipv6_setting (const struct setting_type *type __unused, const char *value __unused, void *buf __unused, size_t len __unused)
 Parse IPv6 address setting value (when IPv6 support is not present)
__weak int format_ipv6_setting (const struct setting_type *type __unused, const void *raw __unused, size_t raw_len __unused, char *buf __unused, size_t len __unused)
 Format IPv6 address setting value (when IPv6 support is not present)
static unsigned int setting_type_int_index (const struct setting_type *type)
 Get integer setting type index.
static unsigned int setting_type_int_width (const struct setting_type *type)
 Get integer setting type width.
static int setting_type_int_is_signed (const struct setting_type *type)
 Get integer setting type signedness.
static int denumerate_int_setting (const struct setting_type *type, unsigned long value, void *buf, size_t len)
 Convert number to setting value.
static int numerate_int_setting (const struct setting_type *type, const void *raw, size_t raw_len, unsigned long *value)
 Convert setting value to number.
static int parse_int_setting (const struct setting_type *type, const char *value, void *buf, size_t len)
 Parse integer setting value.
static int format_int_setting (const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
 Format signed integer setting value.
static int format_uint_setting (const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
 Format unsigned integer setting value.
static int parse_hex_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse hex string setting value (using colon delimiter)
static int format_hex_colon_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format hex string setting value (using colon delimiter)
static int parse_hex_hyphen_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse hex string setting value (using hyphen delimiter)
static int format_hex_hyphen_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format hex string setting value (using hyphen delimiter)
static int parse_hex_raw_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse hex string setting value (using no delimiter)
static int format_hex_raw_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format hex string setting value (using no delimiter)
static int parse_base64_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse Base64-encoded setting value.
static int format_base64_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format Base64-encoded setting value.
static int format_uuid_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format UUID setting value.
static int format_busdevfn_setting (const struct setting_type *type __unused, const void *raw, size_t raw_len, char *buf, size_t len)
 Format PCI bus:dev.fn setting value.
char * expand_settings (const char *string)
 Expand variables within string.
struct setting hostname_setting __setting (SETTING_HOST, hostname)
 Hostname setting.
struct setting domain_setting __setting (SETTING_IP_EXTRA, domain)
 Domain name setting.
struct setting next_server_setting __setting (SETTING_BOOT, next-server)
 TFTP server setting.
struct setting filename_setting __setting (SETTING_BOOT, filename)
 Filename setting.
struct setting root_path_setting __setting (SETTING_SANBOOT, root-path)
 Root path setting.
struct setting san_filename_setting __setting (SETTING_SANBOOT, san-filename)
 SAN filename setting.
struct setting username_setting __setting (SETTING_AUTH, username)
 Username setting.
struct setting password_setting __setting (SETTING_AUTH, password)
 Password setting.
struct setting priority_setting __setting (SETTING_MISC, priority)
 Priority setting.
struct setting user_class_setting __setting (SETTING_HOST_EXTRA, user-class)
 DHCP user class setting.
struct setting vendor_class_setting __setting (SETTING_HOST_EXTRA, vendor-class)
 DHCP vendor class setting.
static int errno_fetch (void *data, size_t len)
 Fetch error number setting.
struct setting errno_setting __setting (SETTING_MISC, errno)
 Error number setting.
static int buildarch_fetch (void *data, size_t len)
 Fetch build architecture setting.
struct setting buildarch_setting __setting (SETTING_MISC, buildarch)
 Build architecture setting.
static int platform_fetch (void *data, size_t len)
 Fetch platform setting.
struct setting platform_setting __setting (SETTING_MISC, platform)
 Platform setting.
static int version_fetch (void *data, size_t len)
 Fetch version setting.
struct setting version_setting __setting (SETTING_MISC, version)
 Version setting.
static int unixtime_fetch (void *data, size_t len)
 Fetch current time setting.
struct setting unixtime_setting __setting (SETTING_MISC, unixtime)
 Current time setting.
static int builtin_fetch (struct settings *settings __unused, struct setting *setting, void *data, size_t len)
 Fetch built-in setting.
static int builtin_applies (struct settings *settings __unused, const struct setting *setting)
 Check applicability of built-in setting.
static void builtin_init (void)
 Initialise built-in settings.
struct init_fn builtin_init_fn __init_fn (INIT_NORMAL)
 Built-in settings initialiser.

Variables

struct settings_operations generic_settings_operations
 Generic settings operations.
struct generic_settings generic_settings_root
 Root generic settings block.
struct setting_type
setting_type_string 
__setting_type
 A string setting type.
struct settings_scope dhcpv6_scope
 IPv6 settings scope.
static const char setting_type_int_name [][8]
 Integer setting type names.
struct settings_scope builtin_scope
 Built-in setting scope.
struct builtin_setting
errno_builtin_setting 
__builtin_setting
 Error number built-in setting.
static struct settings_operations builtin_settings_operations
 Built-in settings operations.
static struct settings builtin_settings
 Built-in settings.

Detailed Description

Configuration settings.

Definition in file settings.c.


Define Documentation

#define settings_root   generic_settings_root.settings

Root settings block.

Definition at line 249 of file settings.c.

Referenced by parse_setting_name(), parse_settings_name(), settings_target(), and store_setting().

Get unsigned integer setting type name.

Parameters:
indexInteger setting type index
Return values:
nameSetting type name

Definition at line 1826 of file settings.c.

Get signed integer setting type name.

Parameters:
indexInteger setting type index
Return values:
nameSetting type name

Definition at line 1834 of file settings.c.

#define SETTING_TYPE_INT (   index)
Value:
{                               \
        .name = SETTING_TYPE_INT_NAME ( index ),                \
        .parse = parse_int_setting,                             \
        .format = format_int_setting,                           \
        .denumerate = denumerate_int_setting,                   \
        .numerate = numerate_int_setting,                       \
}

Define a signed integer setting type.

Parameters:
indexInteger setting type index
Return values:
typeSetting type

Definition at line 1995 of file settings.c.

#define SETTING_TYPE_UINT (   index)
Value:
{                               \
        .name = SETTING_TYPE_UINT_NAME ( index ),               \
        .parse = parse_int_setting,                             \
        .format = format_uint_setting,                          \
        .denumerate = denumerate_int_setting,                   \
        .numerate = numerate_int_setting,                       \
}

Define an unsigned integer setting type.

Parameters:
indexInteger setting type index
Return values:
typeSetting type

Definition at line 2009 of file settings.c.


Enumeration Type Documentation

Integer setting type indices.

These indexes are defined such that (1<<index) gives the width of the integer, in bytes.

Enumerator:
SETTING_TYPE_INT8 
SETTING_TYPE_INT16 
SETTING_TYPE_INT32 

Definition at line 1799 of file settings.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void* generic_setting_name ( struct generic_setting generic) [inline, static]

Get generic setting name.

Parameters:
genericGeneric setting
Return values:
nameGeneric setting name

Definition at line 83 of file settings.c.

Referenced by generic_settings_store().

                                                                              {
        return ( ( ( void * ) generic ) + sizeof ( *generic ) );
}
static void* generic_setting_data ( struct generic_setting generic) [inline, static]

Get generic setting data.

Parameters:
genericGeneric setting
Return values:
dataGeneric setting data

Definition at line 93 of file settings.c.

References generic.

Referenced by generic_settings_fetch(), and generic_settings_store().

                                                                              {
        return ( ( ( void * ) generic ) + sizeof ( *generic ) +
                 generic->name_len );
}
static struct generic_setting* find_generic_setting ( struct generic_settings generics,
const struct setting setting 
) [static, read]

Find generic setting.

Parameters:
genericsGeneric settings block
settingSetting to find
Return values:
genericGeneric setting, or NULL

Definition at line 106 of file settings.c.

References generic, generic_setting::list, generic_settings::list, list_for_each_entry, NULL, and setting_cmp().

Referenced by generic_settings_fetch(), and generic_settings_store().

                                                       {
        struct generic_setting *generic;

        list_for_each_entry ( generic, &generics->list, list ) {
                if ( setting_cmp ( &generic->setting, setting ) == 0 )
                        return generic;
        }
        return NULL;
}
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 ) );
}
static void autovivified_settings_free ( struct refcnt refcnt) [static]

Free autovivified settings block.

Parameters:
refcntReference count

Definition at line 264 of file settings.c.

References container_of, free, autovivified_settings::generic, generic_settings_clear(), and generic_settings::settings.

Referenced by autovivify_child_settings().

                                                                 {
        struct autovivified_settings *autovivified =
                container_of ( refcnt, struct autovivified_settings, refcnt );

        generic_settings_clear ( &autovivified->generic.settings );
        free ( autovivified );
}
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;
}
static struct settings* parse_settings_name ( const char *  name,
get_child_settings_t  get_child 
) [static, read]

Parse settings block name.

Parameters:
nameName
get_childFunction to find or create child settings block
Return values:
settingsSettings block, or NULL

Definition at line 371 of file settings.c.

References memcpy(), settings_root, strchr(), and strlen().

Referenced by find_settings(), and parse_setting_name().

                                                                         {
        struct settings *settings = &settings_root;
        char name_copy[ strlen ( name ) + 1 ];
        char *subname;
        char *remainder;

        /* Create modifiable copy of name */
        memcpy ( name_copy, name, sizeof ( name_copy ) );
        remainder = name_copy;

        /* Parse each name component in turn */
        while ( remainder ) {
                subname = remainder;
                remainder = strchr ( subname, '.' );
                if ( remainder )
                        *(remainder++) = '\0';
                settings = get_child ( settings, subname );
                if ( ! settings )
                        break;
        }

        return settings;
}
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().

static int apply_settings ( void  ) [static]

Apply all settings.

Return values:
rcReturn status code

Definition at line 411 of file settings.c.

References settings_applicator::apply, DBG, for_each_table_entry, rc, SETTINGS_APPLICATORS, and strerror().

Referenced by register_settings(), store_setting(), and unregister_settings().

                                   {
        struct settings_applicator *applicator;
        int rc;

        /* Call all settings applicators */
        for_each_table_entry ( applicator, SETTINGS_APPLICATORS ) {
                if ( ( rc = applicator->apply() ) != 0 ) {
                        DBG ( "Could not apply settings using applicator "
                              "%p: %s\n", applicator, strerror ( rc ) );
                        return rc;
                }
        }

        return 0;
}
static void reprioritise_settings ( struct settings settings) [static]

Reprioritise settings.

Parameters:
settingsSettings block

Reorders the settings block amongst its siblings according to its priority.

Definition at line 435 of file settings.c.

References settings::children, fetch_intz_setting(), list_add_tail, list_del, list_for_each_entry, settings::order, settings::parent, priority, and settings::siblings.

Referenced by register_settings(), and store_setting().

                                                                {
        struct settings *parent = settings->parent;
        long priority;
        struct settings *tmp;
        long tmp_priority;

        /* Stop when we reach the top of the tree */
        if ( ! parent )
                return;

        /* Read priority, if present */
        priority = fetch_intz_setting ( settings, &priority_setting );

        /* Remove from siblings list */
        list_del ( &settings->siblings );

        /* Reinsert after any existing blocks which have a higher priority */
        list_for_each_entry ( tmp, &parent->children, siblings ) {
                tmp_priority = fetch_intz_setting ( tmp, &priority_setting );
                if ( priority > tmp_priority )
                        break;
                if ( settings->order > tmp->order )
                        break;
        }
        list_add_tail ( &settings->siblings, &tmp->siblings );

        /* Recurse up the tree */
        reprioritise_settings ( parent );
}
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 );
}
static struct setting* applicable_setting ( struct settings settings,
const struct setting setting 
) [static, read]

Find setting applicable to settings block, if any.

Parameters:
settingsSettings block
settingSetting
Return values:
settingApplicable setting, if any

Definition at line 587 of file settings.c.

References for_each_table_entry, NULL, generic_setting::setting, setting_applies(), setting_cmp(), and SETTINGS.

Referenced by fetch_setting().

                                                                               {
        const struct setting *applicable;

        /* If setting is already applicable, use it */
        if ( setting_applies ( settings, setting ) )
                return setting;

        /* Otherwise, look for a matching predefined setting which does apply */
        for_each_table_entry ( applicable, SETTINGS ) {
                if ( ( setting_cmp ( setting, applicable ) == 0 ) &&
                     ( setting_applies ( settings, applicable ) ) )
                        return applicable;
        }

        return NULL;
}
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, 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;
}
static int fetch_setting_alloc ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
void **  data,
void *(*)(size_t len alloc 
) [static]

Fetch allocated 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
allocAllocation function
Return values:
lenLength of setting, or negative error

The caller is responsible for eventually freeing the allocated buffer.

Definition at line 735 of file settings.c.

References assert, ENOMEM, fetch_setting(), len, and NULL.

Referenced by fetch_setting_copy(), and fetch_string_setting_copy().

                                                                     {
        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 */
        *data = NULL;

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

        /* Allocate buffer */
        *data = alloc ( len );
        if ( ! *data )
                return -ENOMEM;

        /* Fetch setting value */
        check_len = fetch_setting ( *origin, fetched, NULL, NULL, *data, len );
        assert ( check_len == len );
        return len;
}
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 ) );
}
static void* fetch_string_setting_copy_alloc ( size_t  len) [static]

Allocate memory for copy of string setting.

Parameters:
lenLength of setting
Return values:
ptrAllocated memory

Definition at line 855 of file settings.c.

References zalloc().

Referenced by fetch_string_setting_copy().

                                                             {
        return zalloc ( len + 1 /* NUL */ );
}
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 );
}
static int numeric_setting_value ( int  is_signed,
const void *  raw,
size_t  len,
unsigned long *  value 
) [static]

Extract numeric value of setting.

Parameters:
is_signedTreat value as a signed integer
rawRaw setting data
lenLength of raw setting data
Return values:
valueNumeric value
lenLength of setting, or negative error

Definition at line 965 of file settings.c.

References byte, ERANGE, len, pad, raw, and value.

Referenced by fetch_numeric_setting(), format_busdevfn_setting(), and numerate_int_setting().

                                                          {
        const uint8_t *unsigned_bytes = raw;
        const int8_t *signed_bytes = raw;
        int is_negative;
        unsigned int i;
        uint8_t pad;
        uint8_t byte;

        /* Convert to host-ordered longs */
        is_negative = ( len && ( signed_bytes[0] < 0 ) );
        *value = ( ( is_signed && is_negative ) ? -1L : 0 );
        pad = *value;
        for ( i = 0 ; i < len ; i++ ) {
                byte = unsigned_bytes[i];
                *value = ( ( *value << 8 ) | byte );
                if ( ( ( i + sizeof ( *value ) ) < len ) && ( byte != pad ) )
                        return -ERANGE;
        }

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

Fetch value of numeric 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 996 of file settings.c.

References fetch_raw_setting(), len, and numeric_setting_value().

Referenced by fetch_int_setting(), fetch_intz_setting(), fetch_uint_setting(), and fetch_uintz_setting().

                                                                  {
        unsigned long tmp;
        int len;

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

        /* Fetch raw (network-ordered, variable-length) setting */
        len = fetch_raw_setting ( settings, setting, &tmp, sizeof ( tmp ) );
        if ( len < 0 )
                return len;

        /* Extract numeric value */
        return numeric_setting_value ( is_signed, &tmp, len, value );
}
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 );
}
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, 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;
}
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;
}
static uint64_t parse_setting_tag ( const char *  name) [static]

Parse setting name as tag number.

Parameters:
nameName
Return values:
tagTag number, or 0 if not a valid number

Definition at line 1481 of file settings.c.

References strtoul(), and tag.

Referenced by parse_setting_name().

                                                       {
        char *tmp = ( ( char * ) name );
        uint64_t tag = 0;

        while ( 1 ) {
                tag = ( ( tag << 8 ) | strtoul ( tmp, &tmp, 0 ) );
                if ( *tmp == 0 )
                        return tag;
                if ( *tmp != '.' )
                        return 0;
                tmp++;
        }
}
static struct setting_type* find_setting_type ( const char *  name) [static, read]

Find setting type.

Parameters:
nameName
Return values:
typeSetting type, or NULL

Definition at line 1501 of file settings.c.

References for_each_table_entry, setting_type::name, NULL, SETTING_TYPES, strcmp(), and type.

Referenced by parse_setting_name().

                                                                          {
        const struct setting_type *type;

        for_each_table_entry ( type, SETTING_TYPES ) {
                if ( strcmp ( name, type->name ) == 0 )
                        return type;
        }
        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 );
}
static int parse_string_setting ( const struct setting_type *type  __unused,
const char *  value,
void *  buf,
size_t  len 
) [static]

Parse string 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 1631 of file settings.c.

References memcpy(), raw_len, and strlen().

                                                                             {
        size_t raw_len = strlen ( value ); /* Exclude terminating NUL */

        /* Copy string to buffer */
        if ( len > raw_len )
                len = raw_len;
        memcpy ( buf, value, len );

        return raw_len;
}
static int format_string_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format string setting value.

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 1653 of file settings.c.

References memcpy(), memset(), and raw_len.

                                                {

        /* Copy string to buffer, and terminate */
        memset ( buf, 0, len );
        if ( len > raw_len )
                len = raw_len;
        memcpy ( buf, raw, len );

        return raw_len;
}
static int parse_uristring_setting ( const struct setting_type *type  __unused,
const char *  value,
void *  buf,
size_t  len 
) [static]

Parse URI-encoded string 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 1682 of file settings.c.

References uri_decode().

                                                                               {

        return uri_decode ( value, buf, len );
}
static int format_uristring_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format URI-encoded string setting value.

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 1698 of file settings.c.

References uri_encode().

                                                              {

        return uri_encode ( 0, raw, raw_len, buf, len );
}
__weak int parse_ipv4_setting ( const struct setting_type *type  __unused,
const char *value  __unused,
void *buf  __unused,
size_t len  __unused 
)

Parse IPv4 address setting value (when IPv4 support is not present)

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 1721 of file settings.c.

References ENOTSUP.

                                                      {
        return -ENOTSUP;
}
__weak int format_ipv4_setting ( const struct setting_type *type  __unused,
const void *raw  __unused,
size_t raw_len  __unused,
char *buf  __unused,
size_t len  __unused 
)

Format IPv4 address setting value (when IPv4 support is not present)

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 1737 of file settings.c.

References ENOTSUP.

                                                       {
        return -ENOTSUP;
}
__weak int parse_ipv6_setting ( const struct setting_type *type  __unused,
const char *value  __unused,
void *buf  __unused,
size_t len  __unused 
)

Parse IPv6 address setting value (when IPv6 support is not present)

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 1760 of file settings.c.

References ENOTSUP.

                                                      {
        return -ENOTSUP;
}
__weak int format_ipv6_setting ( const struct setting_type *type  __unused,
const void *raw  __unused,
size_t raw_len  __unused,
char *buf  __unused,
size_t len  __unused 
)

Format IPv6 address setting value (when IPv6 support is not present)

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 1776 of file settings.c.

References ENOTSUP.

                                                       {
        return -ENOTSUP;
}
static unsigned int setting_type_int_index ( const struct setting_type type) [static]

Get integer setting type index.

Parameters:
typeSetting type
Return values:
indexInteger setting type index

Definition at line 1842 of file settings.c.

References setting_type::name.

                                                                               {

        return ( ( type->name - setting_type_int_name[0] ) /
                 sizeof ( setting_type_int_name[0] ) );
}
static unsigned int setting_type_int_width ( const struct setting_type type) [static]

Get integer setting type width.

Parameters:
typeSetting type
Return values:
indexInteger setting type width

Definition at line 1854 of file settings.c.

Referenced by denumerate_int_setting().

                                                                               {

        return ( 1 << setting_type_int_index ( type ) );
}
static int setting_type_int_is_signed ( const struct setting_type type) [static]

Get integer setting type signedness.

Parameters:
typeSetting type
Return values:
is_signedInteger setting type is signed

Definition at line 1865 of file settings.c.

References setting_type::name.

Referenced by numerate_int_setting().

                                                                          {
        return ( ( type->name - setting_type_int_name[0] ) & 1 );
}
static int denumerate_int_setting ( const struct setting_type type,
unsigned long  value,
void *  buf,
size_t  len 
) [static]

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 1878 of file settings.c.

References bytes, htonl, memcpy(), num, setting_type_int_width(), size, and u.

                                                 {
        unsigned int size = setting_type_int_width ( type );
        union {
                uint32_t num;
                uint8_t bytes[4];
        } u;

        u.num = htonl ( value );
        if ( len > size )
                len = size;
        memcpy ( buf, &u.bytes[ sizeof ( u ) - size ], len );

        return size;
}
static int numerate_int_setting ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
unsigned long *  value 
) [static]

Convert setting value to number.

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

Definition at line 1904 of file settings.c.

References assert, numeric_setting_value(), and setting_type_int_is_signed().

                                                         {
        int is_signed = setting_type_int_is_signed ( type );
        int check_len;

        /* Extract numeric value */
        check_len = numeric_setting_value ( is_signed, raw, raw_len, value );
        if ( check_len < 0 )
                return check_len;
        assert ( check_len == ( int ) raw_len );

        return 0;
}
static int parse_int_setting ( const struct setting_type type,
const char *  value,
void *  buf,
size_t  len 
) [static]

Parse integer 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 1928 of file settings.c.

References setting_type::denumerate, EINVAL, and strtoul().

                                                                          {
        char *endp;
        unsigned long num_value;

        /* Parse value */
        num_value = strtoul ( value, &endp, 0 );
        if ( *endp )
                return -EINVAL;

        return type->denumerate ( type, num_value, buf, len );
}
static int format_int_setting ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format signed integer setting value.

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 1951 of file settings.c.

References setting_type::numerate, snprintf(), and value.

                                                        {
        unsigned long value;
        int ret;

        /* Extract numeric value */
        if ( ( ret = type->numerate ( type, raw, raw_len, &value ) ) < 0 )
                return ret;

        /* Format value */
        return snprintf ( buf, len, "%ld", value );
}
static int format_uint_setting ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format unsigned integer setting value.

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 1975 of file settings.c.

References setting_type::numerate, snprintf(), and value.

                                                         {
        unsigned long value;
        int ret;

        /* Extract numeric value */
        if ( ( ret = type->numerate ( type, raw, raw_len, &value ) ) < 0 )
                return ret;

        /* Format value */
        return snprintf ( buf, len, "%#lx", value );
}
static int parse_hex_setting ( const struct setting_type *type  __unused,
const char *  value,
void *  buf,
size_t  len 
) [static]

Parse hex string setting value (using colon delimiter)

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

Definition at line 2051 of file settings.c.

References hex_decode().

                                                                          {
        return hex_decode ( ':', value, buf, len );
}
static int format_hex_colon_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format hex string setting value (using colon delimiter)

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 2066 of file settings.c.

References hex_encode().

                                                              {
        return hex_encode ( ':', raw, raw_len, buf, len );
}
static int parse_hex_hyphen_setting ( const struct setting_type *type  __unused,
const char *  value,
void *  buf,
size_t  len 
) [static]

Parse hex string setting value (using hyphen delimiter)

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

Definition at line 2082 of file settings.c.

References hex_decode().

                                                   {
        return hex_decode ( '-', value, buf, len );
}
static int format_hex_hyphen_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format hex string setting value (using hyphen delimiter)

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 2098 of file settings.c.

References hex_encode().

                                                               {
        return hex_encode ( '-', raw, raw_len, buf, len );
}
static int parse_hex_raw_setting ( const struct setting_type *type  __unused,
const char *  value,
void *  buf,
size_t  len 
) [static]

Parse hex string setting value (using no delimiter)

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

Definition at line 2114 of file settings.c.

References hex_decode().

                                                                              {
        return hex_decode ( 0, value, buf, len );
}
static int format_hex_raw_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format hex string setting value (using no delimiter)

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 2129 of file settings.c.

References hex_encode().

                                                            {
        return hex_encode ( 0, raw, raw_len, buf, len );
}
static int parse_base64_setting ( const struct setting_type *type  __unused,
const char *  value,
void *  buf,
size_t  len 
) [static]

Parse Base64-encoded setting value.

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

Definition at line 2166 of file settings.c.

References base64_decode().

                                                                             {

        return base64_decode ( value, buf, len );
}
static int format_base64_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format Base64-encoded setting value.

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 2182 of file settings.c.

References base64_encode().

                                                           {

        return base64_encode ( raw, raw_len, buf, len );
}
static int format_uuid_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format UUID setting value.

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 2206 of file settings.c.

References ERANGE, raw, snprintf(), and uuid_ntoa().

                                              {
        const union uuid *uuid = raw;

        /* Range check */
        if ( raw_len != sizeof ( *uuid ) )
                return -ERANGE;

        /* Format value */
        return snprintf ( buf, len, "%s", uuid_ntoa ( uuid ) );
}
static int format_busdevfn_setting ( const struct setting_type *type  __unused,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
) [static]

Format PCI bus:dev.fn setting value.

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 2235 of file settings.c.

References assert, bus, numeric_setting_value(), PCI_BUS, PCI_FUNC, PCI_SEG, PCI_SLOT, seg, slot, and snprintf().

                                                  {
        unsigned long busdevfn;
        unsigned int seg;
        unsigned int bus;
        unsigned int slot;
        unsigned int func;
        int check_len;

        /* Extract numeric value */
        check_len = numeric_setting_value ( 0, raw, raw_len, &busdevfn );
        if ( check_len < 0 )
                return check_len;
        assert ( check_len == ( int ) raw_len );

        /* Extract PCI address components */
        seg = PCI_SEG ( busdevfn );
        bus = PCI_BUS ( busdevfn );
        slot = PCI_SLOT ( busdevfn );
        func = PCI_FUNC ( busdevfn );

        /* Format value */
        return snprintf ( buf, len, "%04x:%02x:%02x.%x", seg, bus, slot, func );
}
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 hostname_setting __setting ( SETTING_HOST  ,
hostname   
) [read]

Hostname setting.

struct setting domain_setting __setting ( SETTING_IP_EXTRA  ,
domain   
) [read]

Domain name setting.

struct setting next_server_setting __setting ( SETTING_BOOT  ,
next server 
) [read]

TFTP server setting.

struct setting filename_setting __setting ( SETTING_BOOT  ,
filename   
) [read]

Filename setting.

struct setting root_path_setting __setting ( SETTING_SANBOOT  ,
root path 
) [read]

Root path setting.

struct setting san_filename_setting __setting ( SETTING_SANBOOT  ,
san-  filename 
) [read]

SAN filename setting.

struct setting username_setting __setting ( SETTING_AUTH  ,
username   
) [read]

Username setting.

struct setting password_setting __setting ( SETTING_AUTH  ,
password   
) [read]

Password setting.

struct setting priority_setting __setting ( SETTING_MISC  ,
priority   
) [read]

Priority setting.

struct setting user_class_setting __setting ( SETTING_HOST_EXTRA  ,
user class 
) [read]

DHCP user class setting.

struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA  ,
vendor class 
) [read]

DHCP vendor class setting.

static int errno_fetch ( void *  data,
size_t  len 
) [static]

Fetch error number setting.

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

Definition at line 2467 of file settings.c.

References errno, htonl, and memcpy().

                                                  {
        uint32_t content;

        /* Return current error */
        content = htonl ( errno );
        if ( len > sizeof ( content ) )
                len = sizeof ( content );
        memcpy ( data, &content, len );
        return sizeof ( content );
}
struct setting errno_setting __setting ( SETTING_MISC  ,
errno   
) [read]

Error number setting.

static int buildarch_fetch ( void *  data,
size_t  len 
) [static]

Fetch build architecture setting.

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

Definition at line 2499 of file settings.c.

References _S2, and strncpy().

                                                      {
        static const char buildarch[] = _S2 ( ARCH );

        strncpy ( data, buildarch, len );
        return ( sizeof ( buildarch ) - 1 /* NUL */ );
}
struct setting buildarch_setting __setting ( SETTING_MISC  ,
buildarch   
) [read]

Build architecture setting.

static int platform_fetch ( void *  data,
size_t  len 
) [static]

Fetch platform setting.

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

Definition at line 2527 of file settings.c.

References _S2, and strncpy().

                                                     {
        static const char platform[] = _S2 ( PLATFORM );

        strncpy ( data, platform, len );
        return ( sizeof ( platform ) - 1 /* NUL */ );
}
struct setting platform_setting __setting ( SETTING_MISC  ,
platform   
) [read]

Platform setting.

static int version_fetch ( void *  data,
size_t  len 
) [static]

Fetch version setting.

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

Definition at line 2555 of file settings.c.

References product_version, strlen(), and strncpy().

                                                    {
        strncpy ( data, product_version, len );
        return ( strlen ( product_version ) );
}
struct setting version_setting __setting ( SETTING_MISC  ,
version   
) [read]

Version setting.

static int unixtime_fetch ( void *  data,
size_t  len 
) [static]

Fetch current time setting.

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

Definition at line 2581 of file settings.c.

References htonl, memcpy(), NULL, and time.

                                                     {
        uint32_t content;

        /* Return current time */
        content = htonl ( time(NULL) );
        if ( len > sizeof ( content ) )
                len = sizeof ( content );
        memcpy ( data, &content, len );
        return sizeof ( content );
}
struct setting unixtime_setting __setting ( SETTING_MISC  ,
unixtime   
) [read]

Current time setting.

static int builtin_fetch ( struct settings *settings  __unused,
struct setting setting,
void *  data,
size_t  len 
) [static]

Fetch built-in 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 2615 of file settings.c.

References BUILTIN_SETTINGS, ENOENT, builtin_setting::fetch, for_each_table_entry, builtin_setting::setting, and setting_cmp().

                                                    {
        struct builtin_setting *builtin;

        for_each_table_entry ( builtin, BUILTIN_SETTINGS ) {
                if ( setting_cmp ( setting, builtin->setting ) == 0 )
                        return builtin->fetch ( data, len );
        }
        return -ENOENT;
}
static int builtin_applies ( struct settings *settings  __unused,
const struct setting setting 
) [static]

Check applicability of built-in setting.

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

Definition at line 2634 of file settings.c.

References setting::scope.

                                                             {

        return ( setting->scope == &builtin_scope );
}
static void builtin_init ( void  ) [static]

Initialise built-in settings.

Definition at line 2655 of file settings.c.

References DBG, NULL, rc, register_settings(), and strerror().

                                  {
        int rc;

        if ( ( rc = register_settings ( &builtin_settings, NULL,
                                        "builtin" ) ) != 0 ) {
                DBG ( "Could not register built-in settings: %s\n",
                      strerror ( rc ) );
                return;
        }
}
struct init_fn builtin_init_fn __init_fn ( INIT_NORMAL  ) [read]

Built-in settings initialiser.


Variable Documentation

Initial value:

Generic settings operations.

Definition at line 221 of file settings.c.

Referenced by generic_settings_init().

Initial value:

Root generic settings block.

Definition at line 235 of file settings.c.

struct setting_type setting_type_busdevfn __setting_type
Initial value:
 {
        .name = "string",
        .parse = parse_string_setting,
        .format = format_string_setting,
}

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 1667 of file settings.c.

IPv6 settings scope.

DHCPv6 setting scope.

Definition at line 1791 of file settings.c.

Referenced by dhcpv6_applies(), and dhcpv6_register().

const char setting_type_int_name[][8] [static]
Initial value:
 {
        [SETTING_TYPE_INT8] = "uint8",
        [SETTING_TYPE_INT16] = "uint16",
        [SETTING_TYPE_INT32] = "uint32",
}

Integer setting type names.

These names exist as a static array in order to allow the type's integer size and signedness to be determined from the type's name. Note that there are no separate entries for the signed integer types: the name pointers simply point to the second character of the relevant string.

Definition at line 1814 of file settings.c.

Built-in setting scope.

Definition at line 2458 of file settings.c.

struct builtin_setting unixtime_builtin_setting __builtin_setting
Initial value:
 {
        .setting = &errno_setting,
        .fetch = errno_fetch,
}

Error number built-in setting.

Current time built-in setting.

Version built-in setting.

Platform built-in setting.

Build architecture built-in setting.

Definition at line 2487 of file settings.c.

Initial value:
 {
        .applies = builtin_applies,
        .fetch = builtin_fetch,
}

Built-in settings operations.

Definition at line 2641 of file settings.c.

struct settings builtin_settings [static]
Initial value:

Built-in settings.

Definition at line 2647 of file settings.c.