iPXE
Data Structures | Macros | 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...
 

Macros

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

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. More...
 
static void * generic_setting_data (struct generic_setting *generic)
 Get generic setting data. More...
 
static struct generic_settingfind_generic_setting (struct generic_settings *generics, const struct setting *setting)
 Find generic setting. More...
 
int generic_settings_store (struct settings *settings, const struct setting *setting, const void *data, size_t len)
 Store value of generic setting. More...
 
int generic_settings_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of generic setting. More...
 
void generic_settings_clear (struct settings *settings)
 Clear generic settings block. More...
 
static void autovivified_settings_free (struct refcnt *refcnt)
 Free autovivified settings block. More...
 
struct settingsfind_child_settings (struct settings *parent, const char *name)
 Find child settings block. More...
 
struct settingsautovivify_child_settings (struct settings *parent, const char *name)
 Find or create child settings block. More...
 
const char * settings_name (struct settings *settings)
 Return settings block name. More...
 
static struct settingsparse_settings_name (const char *name, get_child_settings_t get_child)
 Parse settings block name. More...
 
struct settingsfind_settings (const char *name)
 Find settings block. More...
 
static void apply_settings (void)
 Apply all settings. More...
 
static void reprioritise_settings (struct settings *settings)
 Reprioritise settings. More...
 
int register_settings (struct settings *settings, struct settings *parent, const char *name)
 Register settings block. More...
 
void unregister_settings (struct settings *settings)
 Unregister settings block. More...
 
struct settingssettings_target (struct settings *settings)
 Redirect to target settings block. More...
 
int setting_applies (struct settings *settings, const struct setting *setting)
 Check applicability of setting. More...
 
static const struct settingapplicable_setting (struct settings *settings, const struct setting *setting)
 Find setting applicable to settings block, if any. More...
 
int store_setting (struct settings *settings, const struct setting *setting, const void *data, size_t len)
 Store value of setting. More...
 
int fetch_setting (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
 Fetch setting. More...
 
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. More...
 
int fetch_setting_copy (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data)
 Fetch copy of setting. More...
 
int fetch_raw_setting (struct settings *settings, const struct setting *setting, void *data, size_t len)
 Fetch value of setting. More...
 
int fetch_raw_setting_copy (struct settings *settings, const struct setting *setting, void **data)
 Fetch value of setting. More...
 
int fetch_string_setting (struct settings *settings, const struct setting *setting, char *data, size_t len)
 Fetch value of string setting. More...
 
static void * fetch_string_setting_copy_alloc (size_t len)
 Allocate memory for copy of string setting. More...
 
int fetch_string_setting_copy (struct settings *settings, const struct setting *setting, char **data)
 Fetch value of string setting. More...
 
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. More...
 
int fetch_ipv4_setting (struct settings *settings, const struct setting *setting, struct in_addr *inp)
 Fetch value of IPv4 address setting. More...
 
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. More...
 
int fetch_ipv6_setting (struct settings *settings, const struct setting *setting, struct in6_addr *inp)
 Fetch value of IPv6 address setting. More...
 
static int numeric_setting_value (int is_signed, const void *raw, size_t len, unsigned long *value)
 Extract numeric value of setting. More...
 
int fetch_numeric_setting (struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
 Fetch value of numeric setting. More...
 
int fetch_int_setting (struct settings *settings, const struct setting *setting, long *value)
 Fetch value of signed integer setting. More...
 
int fetch_uint_setting (struct settings *settings, const struct setting *setting, unsigned long *value)
 Fetch value of unsigned integer setting. More...
 
long fetch_intz_setting (struct settings *settings, const struct setting *setting)
 Fetch value of signed integer setting, or zero. More...
 
unsigned long fetch_uintz_setting (struct settings *settings, const struct setting *setting)
 Fetch value of unsigned integer setting, or zero. More...
 
int fetch_uuid_setting (struct settings *settings, const struct setting *setting, union uuid *uuid)
 Fetch value of UUID setting. More...
 
void clear_settings (struct settings *settings)
 Clear settings block. More...
 
int setting_cmp (const struct setting *a, const struct setting *b)
 Compare two settings. More...
 
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. More...
 
int setting_parse (const struct setting_type *type, const char *value, void *buf, size_t len)
 Parse formatted string to setting value. More...
 
int setting_numerate (const struct setting_type *type, const void *raw, size_t raw_len, unsigned long *value)
 Convert setting value to number. More...
 
int setting_denumerate (const struct setting_type *type, unsigned long value, void *buf, size_t len)
 Convert number to setting value. More...
 
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. More...
 
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. More...
 
int storef_setting (struct settings *settings, const struct setting *setting, const char *value)
 Store formatted value of setting. More...
 
int fetchn_setting (struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, unsigned long *value)
 Fetch numeric value of setting. More...
 
int storen_setting (struct settings *settings, const struct setting *setting, unsigned long value)
 Store numeric value of setting. More...
 
struct settingfind_setting (const char *name)
 Find predefined setting. More...
 
static uint64_t parse_setting_tag (const char *name)
 Parse setting name as tag number. More...
 
static const struct setting_typefind_setting_type (const char *name)
 Find setting type. More...
 
int parse_setting_name (char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
 Parse setting name. More...
 
int setting_name (struct settings *settings, const struct setting *setting, char *buf, size_t len)
 Return full setting name. More...
 
static int parse_string_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse string setting value. More...
 
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. More...
 
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. More...
 
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. More...
 
__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) More...
 
__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) More...
 
__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) More...
 
__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) More...
 
static unsigned int setting_type_int_index (const struct setting_type *type)
 Get integer setting type index. More...
 
static unsigned int setting_type_int_width (const struct setting_type *type)
 Get integer setting type width. More...
 
static int setting_type_int_is_signed (const struct setting_type *type)
 Get integer setting type signedness. More...
 
static int denumerate_int_setting (const struct setting_type *type, unsigned long value, void *buf, size_t len)
 Convert number to setting value. More...
 
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. More...
 
static int parse_int_setting (const struct setting_type *type, const char *value, void *buf, size_t len)
 Parse integer setting value. More...
 
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. More...
 
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. More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
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) More...
 
static int parse_base64_setting (const struct setting_type *type __unused, const char *value, void *buf, size_t len)
 Parse Base64-encoded setting value. More...
 
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. More...
 
static int parse_uuid_setting (const struct setting_type *type, const char *value, void *buf, size_t len)
 Parse UUID/GUID setting value. More...
 
static int format_uuid_setting (const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
 Format UUID/GUID setting value. More...
 
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. More...
 
char * expand_settings (const char *string)
 Expand variables within string. More...
 
const struct setting hostname_setting __setting (SETTING_HOST, hostname)
 Hostname setting. More...
 
const struct setting domain_setting __setting (SETTING_IP_EXTRA, domain)
 Domain name setting. More...
 
const struct setting next_server_setting __setting (SETTING_BOOT, next-server)
 TFTP server setting. More...
 
const struct setting filename_setting __setting (SETTING_BOOT, filename)
 Filename setting. More...
 
const struct setting root_path_setting __setting (SETTING_SANBOOT, root-path)
 Root path setting. More...
 
const struct setting san_filename_setting __setting (SETTING_SANBOOT, san-filename)
 SAN filename setting. More...
 
const struct setting username_setting __setting (SETTING_AUTH, username)
 Username setting. More...
 
const struct setting password_setting __setting (SETTING_AUTH, password)
 Password setting. More...
 
const struct setting priority_setting __setting (SETTING_MISC, priority)
 Priority setting. More...
 
const struct setting user_class_setting __setting (SETTING_HOST_EXTRA, user-class)
 DHCP user class setting. More...
 
const struct setting vendor_class_setting __setting (SETTING_HOST_EXTRA, vendor-class)
 DHCP vendor class setting. More...
 
static int errno_fetch (void *data, size_t len)
 Fetch error number setting. More...
 
const struct setting errno_setting __setting (SETTING_MISC, errno)
 Error number setting. More...
 
static int buildarch_fetch (void *data, size_t len)
 Fetch build architecture setting. More...
 
const struct setting buildarch_setting __setting (SETTING_MISC, buildarch)
 Build architecture setting. More...
 
static int platform_fetch (void *data, size_t len)
 Fetch platform setting. More...
 
const struct setting platform_setting __setting (SETTING_MISC, platform)
 Platform setting. More...
 
static int version_fetch (void *data, size_t len)
 Fetch version setting. More...
 
const struct setting version_setting __setting (SETTING_MISC, version)
 Version setting. More...
 
static int unixtime_fetch (void *data, size_t len)
 Fetch current time setting. More...
 
const struct setting unixtime_setting __setting (SETTING_MISC, unixtime)
 Current time setting. More...
 
static int cwuri_fetch_uri (void *data, size_t len, const char *rel)
 Fetch current working URI-related setting. More...
 
static int cwuri_fetch (void *data, size_t len)
 Fetch current working URI setting. More...
 
static int cwduri_fetch (void *data, size_t len)
 Fetch current working directory URI setting. More...
 
const struct setting cwuri_setting __setting (SETTING_MISC, cwuri)
 Current working URI setting. More...
 
const struct setting cwduri_setting __setting (SETTING_MISC, cwduri)
 Current working directory URI setting. More...
 
static int builtin_fetch (struct settings *settings __unused, struct setting *setting, void *data, size_t len)
 Fetch built-in setting. More...
 
static int builtin_applies (struct settings *settings __unused, const struct setting *setting)
 Check applicability of built-in setting. More...
 
static void builtin_init (void)
 Initialise built-in settings. More...
 
struct init_fn builtin_init_fn __init_fn (INIT_NORMAL)
 Built-in settings initialiser. More...
 

Variables

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

Detailed Description

Configuration settings.

Definition in file settings.c.

Macro Definition Documentation

◆ settings_root

#define settings_root   generic_settings_root.settings

Root settings block.

Definition at line 249 of file settings.c.

◆ SETTING_TYPE_UINT_NAME

#define SETTING_TYPE_UINT_NAME (   index)    setting_type_int_name[index]

Get unsigned integer setting type name.

Parameters
indexInteger setting type index
Return values
nameSetting type name

Definition at line 1827 of file settings.c.

◆ SETTING_TYPE_INT_NAME

#define SETTING_TYPE_INT_NAME (   index)    ( setting_type_int_name[index] + 1 )

Get signed integer setting type name.

Parameters
indexInteger setting type index
Return values
nameSetting type name

Definition at line 1835 of file settings.c.

◆ SETTING_TYPE_INT

#define SETTING_TYPE_INT (   index)
Value:
{ \
.parse = parse_int_setting, \
.format = format_int_setting, \
.denumerate = denumerate_int_setting, \
.numerate = numerate_int_setting, \
}
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.
Definition: settings.c:1905
long index
Definition: bigint.h:61
static int parse_int_setting(const struct setting_type *type, const char *value, void *buf, size_t len)
Parse integer setting value.
Definition: settings.c:1929
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.
Definition: settings.c:1952
static int denumerate_int_setting(const struct setting_type *type, unsigned long value, void *buf, size_t len)
Convert number to setting value.
Definition: settings.c:1879
#define SETTING_TYPE_INT_NAME(index)
Get signed integer setting type name.
Definition: settings.c:1835

Define a signed integer setting type.

Parameters
indexInteger setting type index
Return values
typeSetting type

Definition at line 1996 of file settings.c.

◆ SETTING_TYPE_UINT

#define SETTING_TYPE_UINT (   index)
Value:
{ \
.parse = parse_int_setting, \
.format = format_uint_setting, \
.denumerate = denumerate_int_setting, \
.numerate = numerate_int_setting, \
}
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.
Definition: settings.c:1905
long index
Definition: bigint.h:61
static int parse_int_setting(const struct setting_type *type, const char *value, void *buf, size_t len)
Parse integer setting value.
Definition: settings.c:1929
#define SETTING_TYPE_UINT_NAME(index)
Get unsigned integer setting type name.
Definition: settings.c:1827
static int denumerate_int_setting(const struct setting_type *type, unsigned long value, void *buf, size_t len)
Convert number to setting value.
Definition: settings.c:1879
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.
Definition: settings.c:1976

Define an unsigned integer setting type.

Parameters
indexInteger setting type index
Return values
typeSetting type

Definition at line 2010 of file settings.c.

Enumeration Type Documentation

◆ setting_type_int_index

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ generic_setting_name()

static void* generic_setting_name ( struct generic_setting generic)
inlinestatic

Get generic setting name.

Parameters
genericGeneric setting
Return values
nameGeneric setting name

Definition at line 83 of file settings.c.

83  {
84  return ( ( ( void * ) generic ) + sizeof ( *generic ) );
85 }

Referenced by generic_settings_store().

◆ generic_setting_data()

static void* generic_setting_data ( struct generic_setting generic)
inlinestatic

Get generic setting data.

Parameters
genericGeneric setting
Return values
dataGeneric setting data

Definition at line 93 of file settings.c.

93  {
94  return ( ( ( void * ) generic ) + sizeof ( *generic ) +
95  generic->name_len );
96 }
struct arbelprm_event_queue_entry generic
Definition: arbel.h:11

References generic.

Referenced by generic_settings_fetch(), and generic_settings_store().

◆ find_generic_setting()

static struct generic_setting* find_generic_setting ( struct generic_settings generics,
const struct setting setting 
)
static

Find generic setting.

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

Definition at line 106 of file settings.c.

107  {
108  struct generic_setting *generic;
109 
110  list_for_each_entry ( generic, &generics->list, list ) {
111  if ( setting_cmp ( &generic->setting, setting ) == 0 )
112  return generic;
113  }
114  return NULL;
115 }
struct arbelprm_event_queue_entry generic
Definition: arbel.h:11
struct list_head list
List of generic settings.
Definition: settings.c:68
struct list_head list
List of generic settings.
Definition: settings.h:302
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
A generic setting.
Definition: settings.c:66
A setting.
Definition: settings.h:23
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by generic_settings_fetch(), and generic_settings_store().

◆ generic_settings_store()

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.

128  {
129  struct generic_settings *generics =
131  struct generic_setting *old;
132  struct generic_setting *new = NULL;
133  size_t name_len;
134 
135  /* Identify existing generic setting, if any */
136  old = find_generic_setting ( generics, setting );
137 
138  /* Create new generic setting, if required */
139  if ( len ) {
140  /* Allocate new generic setting */
141  name_len = ( strlen ( setting->name ) + 1 );
142  new = zalloc ( sizeof ( *new ) + name_len + len );
143  if ( ! new )
144  return -ENOMEM;
145 
146  /* Populate new generic setting */
147  new->name_len = name_len;
148  new->data_len = len;
149  memcpy ( &new->setting, setting, sizeof ( new->setting ) );
150  new->setting.name = generic_setting_name ( new );
151  memcpy ( generic_setting_name ( new ),
152  setting->name, name_len );
153  memcpy ( generic_setting_data ( new ), data, len );
154  }
155 
156  /* Delete existing generic setting, if any */
157  if ( old ) {
158  list_del ( &old->list );
159  free ( old );
160  }
161 
162  /* Add new setting to list, if any */
163  if ( new )
164  list_add ( &new->list, &generics->list );
165 
166  return 0;
167 }
size_t name_len
Size of setting name.
Definition: settings.c:72
static struct generic_setting * find_generic_setting(struct generic_settings *generics, const struct setting *setting)
Find generic setting.
Definition: settings.c:106
static void * generic_setting_name(struct generic_setting *generic)
Get generic setting name.
Definition: settings.c:83
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
int old
Definition: bitops.h:64
const char * name
Name.
Definition: settings.h:28
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct list_head list
List of generic settings.
Definition: settings.h:302
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
A generic setting.
Definition: settings.c:66
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static void * generic_setting_data(struct generic_setting *generic)
Get generic setting data.
Definition: settings.c:93
A generic settings block.
Definition: settings.h:298
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by netdev_store().

◆ generic_settings_fetch()

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.

180  {
181  struct generic_settings *generics =
183  struct generic_setting *generic;
184 
185  /* Find generic setting */
186  generic = find_generic_setting ( generics, setting );
187  if ( ! generic )
188  return -ENOENT;
189 
190  /* Copy out generic setting data */
191  if ( len > generic->data_len )
192  len = generic->data_len;
193  memcpy ( data, generic_setting_data ( generic ), len );
194 
195  /* Set setting type, if not yet specified */
196  if ( ! setting->type )
197  setting->type = generic->setting.type;
198 
199  return generic->data_len;
200 }
static struct generic_setting * find_generic_setting(struct generic_settings *generics, const struct setting *setting)
Find generic setting.
Definition: settings.c:106
#define ENOENT
No such file or directory.
Definition: errno.h:514
struct arbelprm_event_queue_entry generic
Definition: arbel.h:11
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
const struct setting_type * type
Setting type.
Definition: settings.h:36
A generic setting.
Definition: settings.c:66
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static void * generic_setting_data(struct generic_setting *generic)
Get generic setting data.
Definition: settings.c:93
A generic settings block.
Definition: settings.h:298
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

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

Referenced by netdev_fetch().

◆ generic_settings_clear()

void generic_settings_clear ( struct settings settings)

Clear generic settings block.

Parameters
settingsSettings block

Definition at line 207 of file settings.c.

207  {
208  struct generic_settings *generics =
210  struct generic_setting *generic;
211  struct generic_setting *tmp;
212 
213  list_for_each_entry_safe ( generic, tmp, &generics->list, list ) {
214  list_del ( &generic->list );
215  free ( generic );
216  }
217  assert ( list_empty ( &generics->list ) );
218 }
struct arbelprm_event_queue_entry generic
Definition: arbel.h:11
struct list_head list
List of generic settings.
Definition: settings.c:68
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
unsigned long tmp
Definition: linux_pci.h:63
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct list_head list
List of generic settings.
Definition: settings.h:302
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:458
A generic setting.
Definition: settings.c:66
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
A generic settings block.
Definition: settings.h:298

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

Referenced by autovivified_settings_free(), and netdev_clear().

◆ autovivified_settings_free()

static void autovivified_settings_free ( struct refcnt refcnt)
static

Free autovivified settings block.

Parameters
refcntReference count

Definition at line 264 of file settings.c.

264  {
265  struct autovivified_settings *autovivified =
267 
268  generic_settings_clear ( &autovivified->generic.settings );
269  free ( autovivified );
270 }
Autovivified settings block.
Definition: settings.c:252
void generic_settings_clear(struct settings *settings)
Clear generic settings block.
Definition: settings.c:207
A reference counter.
Definition: refcnt.h:26
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct settings settings
Settings block.
Definition: settings.h:300
struct generic_settings generic
Generic settings block.
Definition: settings.c:256

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

Referenced by autovivify_child_settings().

◆ find_child_settings()

struct settings* find_child_settings ( struct settings parent,
const char *  name 
)

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.

280  {
281  struct settings *settings;
282 
283  /* Find target parent settings block */
285 
286  /* Treat empty name as meaning "this block" */
287  if ( ! *name )
288  return parent;
289 
290  /* Look for child with matching name */
292  if ( strcmp ( settings->name, name ) == 0 )
293  return settings_target ( settings );
294  }
295 
296  return NULL;
297 }
const char * name
Definition: ath9k_hw.c:1984
struct settings * parent
Parent settings block.
Definition: settings.h:138
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

◆ autovivify_child_settings()

struct settings* autovivify_child_settings ( struct settings parent,
const char *  name 
)

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.

307  {
308  struct {
309  struct autovivified_settings autovivified;
310  char name[ strlen ( name ) + 1 /* NUL */ ];
311  } *new_child;
312  struct settings *settings;
313 
314  /* Find target parent settings block */
316 
317  /* Return existing settings, if existent */
318  if ( ( settings = find_child_settings ( parent, name ) ) != NULL )
319  return settings;
320 
321  /* Create new generic settings block */
322  new_child = zalloc ( sizeof ( *new_child ) );
323  if ( ! new_child ) {
324  DBGC ( parent, "Settings %p could not create child %s\n",
325  parent, name );
326  return NULL;
327  }
328  memcpy ( new_child->name, name, sizeof ( new_child->name ) );
329  ref_init ( &new_child->autovivified.refcnt,
331  generic_settings_init ( &new_child->autovivified.generic,
332  &new_child->autovivified.refcnt );
333  settings = &new_child->autovivified.generic.settings;
334  register_settings ( settings, parent, new_child->name );
335  ref_put ( settings->refcnt );
336  return settings;
337 }
const char * name
Definition: ath9k_hw.c:1984
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
struct settings * parent
Parent settings block.
Definition: settings.h:138
static void generic_settings_init(struct generic_settings *generics, struct refcnt *refcnt)
Initialise a settings block.
Definition: settings.h:517
#define DBGC(...)
Definition: compiler.h:505
Autovivified settings block.
Definition: settings.c:252
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
static void autovivified_settings_free(struct refcnt *refcnt)
Free autovivified settings block.
Definition: settings.c:264
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:475
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:279
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct refcnt * refcnt
Reference counter.
Definition: settings.h:134
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

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

Referenced by nslookup_resolv_done(), parse_autovivified_setting(), and parse_names().

◆ settings_name()

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.

345  {
346  static char buf[16];
347  char tmp[ 1 /* '.' */ + sizeof ( buf ) ];
348 
349  /* Find target settings block */
351 
352  /* Construct name */
353  buf[0] = '\0';
354  tmp[0] = '\0';
355  for ( ; settings->parent ; settings = settings->parent ) {
356  memcpy ( ( tmp + 1 ), buf, ( sizeof ( tmp ) - 1 ) );
357  snprintf ( buf, sizeof ( buf ), "%s%s", settings->name, tmp );
358  tmp[0] = '.';
359  }
360  return buf;
361 }
struct settings * parent
Parent settings block.
Definition: settings.h:138
unsigned long tmp
Definition: linux_pci.h:63
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References memcpy(), settings::name, settings::parent, settings_target(), snprintf(), and tmp.

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

◆ parse_settings_name()

static struct settings* parse_settings_name ( const char *  name,
get_child_settings_t  get_child 
)
static

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.

371  {
372  struct settings *settings = &settings_root;
373  char *name_copy;
374  char *subname;
375  char *remainder;
376 
377  /* Create modifiable copy of name */
378  name_copy = strdup ( name );
379  if ( ! name_copy )
380  return NULL;
381  remainder = name_copy;
382 
383  /* Parse each name component in turn */
384  while ( remainder ) {
385  subname = remainder;
386  remainder = strchr ( subname, '.' );
387  if ( remainder )
388  *(remainder++) = '\0';
389  settings = get_child ( settings, subname );
390  if ( ! settings )
391  break;
392  }
393 
394  /* Free modifiable copy of name */
395  free ( name_copy );
396 
397  return settings;
398 }
const char * name
Definition: ath9k_hw.c:1984
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
char * strdup(const char *src)
Duplicate string.
Definition: string.c:393
A settings block.
Definition: settings.h:132
#define settings_root
Root settings block.
Definition: settings.c:249
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References free, name, NULL, settings_root, strchr(), and strdup().

Referenced by find_settings(), and parse_setting_name().

◆ find_settings()

struct settings* find_settings ( const char *  name)

Find settings block.

Parameters
nameName
Return values
settingsSettings block, or NULL

Definition at line 406 of file settings.c.

406  {
407 
409 }
const char * name
Definition: ath9k_hw.c:1984
static struct settings * parse_settings_name(const char *name, get_child_settings_t get_child)
Parse settings block name.
Definition: settings.c:371
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:279

References find_child_settings(), name, and parse_settings_name().

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

◆ apply_settings()

static void apply_settings ( void  )
static

Apply all settings.

Definition at line 415 of file settings.c.

415  {
416  struct settings_applicator *applicator;
417  int rc;
418 
419  /* Call all settings applicators */
421  if ( ( rc = applicator->apply() ) != 0 ) {
422  DBG ( "Could not apply settings using applicator "
423  "%p: %s\n", applicator, strerror ( rc ) );
424  /* Continue to apply remaining settings */
425  }
426  }
427 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A settings applicator.
Definition: settings.h:251
#define SETTINGS_APPLICATORS
Settings applicator table.
Definition: settings.h:260
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
int(* apply)(void)
Apply updated settings.
Definition: settings.h:256
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

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

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

◆ reprioritise_settings()

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

437  {
438  struct settings *parent = settings->parent;
439  long priority;
440  struct settings *tmp;
441  long tmp_priority;
442 
443  /* Stop when we reach the top of the tree */
444  if ( ! parent )
445  return;
446 
447  /* Read priority, if present */
448  priority = fetch_intz_setting ( settings, &priority_setting );
449 
450  /* Remove from siblings list */
451  list_del ( &settings->siblings );
452 
453  /* Reinsert after any existing blocks which have a higher priority */
455  tmp_priority = fetch_intz_setting ( tmp, &priority_setting );
456  if ( priority > tmp_priority )
457  break;
458  if ( settings->order > tmp->order )
459  break;
460  }
461  list_add_tail ( &settings->siblings, &tmp->siblings );
462 
463  /* Recurse up the tree */
465 }
long fetch_intz_setting(struct settings *settings, const struct setting *setting)
Fetch value of signed integer setting, or zero.
Definition: settings.c:1053
struct settings * parent
Parent settings block.
Definition: settings.h:138
unsigned long tmp
Definition: linux_pci.h:63
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static void reprioritise_settings(struct settings *settings)
Reprioritise settings.
Definition: settings.c:437
A settings block.
Definition: settings.h:132
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
int order
Sibling ordering.
Definition: settings.h:148
uint16_t priority
Priotity.
Definition: stp.h:12
struct list_head children
Child settings blocks.
Definition: settings.h:142

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

Referenced by register_settings(), and store_setting().

◆ register_settings()

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

476  {
477  struct settings *old_settings;
478 
479  /* Sanity check */
480  assert ( settings != NULL );
481 
482  /* Find target parent settings block */
484 
485  /* Apply settings block name */
486  settings->name = name;
487 
488  /* Remove any existing settings with the same name */
489  if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
490  unregister_settings ( old_settings );
491 
492  /* Add to list of settings */
493  ref_get ( settings->refcnt );
494  ref_get ( parent->refcnt );
497  DBGC ( settings, "Settings %p (\"%s\") registered\n",
499 
500  /* Fix up settings priority */
502 
503  /* Apply potentially-updated settings */
504  apply_settings();
505 
506  return 0;
507 }
const char * name
Definition: ath9k_hw.c:1984
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:514
struct settings * parent
Parent settings block.
Definition: settings.h:138
#define DBGC(...)
Definition: compiler.h:505
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:345
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
static void apply_settings(void)
Apply all settings.
Definition: settings.c:415
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:92
static void reprioritise_settings(struct settings *settings)
Reprioritise settings.
Definition: settings.c:437
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
struct list_head children
Child settings blocks.
Definition: settings.h:142
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:279
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct refcnt * refcnt
Reference counter.
Definition: settings.h:134

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_apply(), cpuid_settings_init(), dhcp_proxy_rx(), dhcp_pxebs_rx(), dhcp_request_rx(), dhcpv6_register(), efi_path_net_probe(), efivars_init(), guestinfo_init(), guestinfo_net_probe(), ipv6_register_settings(), lldp_probe(), memmap_settings_init(), ndp_register_settings(), netdev_redirect_settings_init(), pci_settings_init(), phantom_probe(), register_netdev(), register_nvo(), settings_test_exec(), smbios_init(), and usb_settings_init().

◆ unregister_settings()

void unregister_settings ( struct settings settings)

Unregister settings block.

Parameters
settingsSettings block

Definition at line 514 of file settings.c.

514  {
515  struct settings *child;
516 
517  /* Unregister child settings */
518  while ( ( child = list_first_entry ( &settings->children,
519  struct settings, siblings ) ) ) {
520  unregister_settings ( child );
521  }
522 
523  DBGC ( settings, "Settings %p (\"%s\") unregistered\n",
525 
526  /* Remove from list of settings */
528  settings->parent = NULL;
529  list_del ( &settings->siblings );
530  ref_put ( settings->refcnt );
531 
532  /* Apply potentially-updated settings */
533  apply_settings();
534 }
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:514
struct settings * parent
Parent settings block.
Definition: settings.h:138
#define DBGC(...)
Definition: compiler.h:505
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:345
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void apply_settings(void)
Apply all settings.
Definition: settings.c:415
A settings block.
Definition: settings.h:132
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
struct refcnt * refcnt
Reference counter.
Definition: settings.h:134
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

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 cachedhcp_recycle(), dhcp_request_rx(), lldp_probe(), lldp_remove(), ndp_register_settings(), phantom_probe(), phantom_remove(), register_netdev(), register_settings(), settings_test_exec(), unregister_netdev(), unregister_nvo(), and unregister_settings().

◆ settings_target()

struct settings* settings_target ( struct settings settings)

Redirect to target settings block.

Parameters
settingsSettings block, or NULL
Return values
settingsUnderlying settings block

Definition at line 549 of file settings.c.

549  {
550 
551  /* NULL settings implies the global settings root */
552  if ( ! settings )
554 
555  /* Redirect to underlying settings block, if applicable */
556  if ( settings->op->redirect )
557  return settings->op->redirect ( settings );
558 
559  /* Otherwise, return this settings block */
560  return settings;
561 }
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
struct settings *(* redirect)(struct settings *settings)
Redirect to underlying settings block (if applicable)
Definition: settings.h:91
A settings block.
Definition: settings.h:132
#define settings_root
Root settings block.
Definition: settings.c:249

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().

◆ setting_applies()

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

571  {
572 
573  /* Find target settings block */
575 
576  /* Check applicability of setting */
577  return ( settings->op->applies ?
578  settings->op->applies ( settings, setting ) : 1 );
579 }
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
int(* applies)(struct settings *settings, const struct setting *setting)
Check applicability of setting.
Definition: settings.h:98

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

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

◆ applicable_setting()

static const struct setting* applicable_setting ( struct settings settings,
const struct setting setting 
)
static

Find setting applicable to settings block, if any.

Parameters
settingsSettings block
settingSetting
Return values
settingApplicable setting, if any

Definition at line 589 of file settings.c.

589  {
590  const struct setting *applicable;
591 
592  /* If setting is already applicable, use it */
593  if ( setting_applies ( settings, setting ) )
594  return setting;
595 
596  /* Otherwise, look for a matching predefined setting which does apply */
597  for_each_table_entry ( applicable, SETTINGS ) {
598  if ( ( setting_cmp ( setting, applicable ) == 0 ) &&
599  ( setting_applies ( settings, applicable ) ) )
600  return applicable;
601  }
602 
603  return NULL;
604 }
#define SETTINGS
Configuration setting table.
Definition: settings.h:53
int setting_applies(struct settings *settings, const struct setting *setting)
Check applicability of setting.
Definition: settings.c:570
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by fetch_setting().

◆ store_setting()

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

616  {
617  int rc;
618 
619  /* Find target settings block */
621 
622  /* Fail if setting does not apply to this settings block */
623  if ( ! setting_applies ( settings, setting ) )
624  return -ENOTTY;
625 
626  /* Sanity check */
627  if ( ! settings->op->store )
628  return -ENOTSUP;
629 
630  /* Store setting */
631  if ( ( rc = settings->op->store ( settings, setting,
632  data, len ) ) != 0 )
633  return rc;
634 
635  /* Reprioritise settings if necessary */
636  if ( setting_cmp ( setting, &priority_setting ) == 0 )
638 
639  /* If these settings are registered, apply potentially-updated
640  * settings
641  */
642  for ( ; settings ; settings = settings->parent ) {
643  if ( settings == &settings_root ) {
644  apply_settings();
645  break;
646  }
647  }
648 
649  return 0;
650 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct settings * parent
Parent settings block.
Definition: settings.h:138
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
static void apply_settings(void)
Apply all settings.
Definition: settings.c:415
int setting_applies(struct settings *settings, const struct setting *setting)
Check applicability of setting.
Definition: settings.c:570
static void reprioritise_settings(struct settings *settings)
Reprioritise settings.
Definition: settings.c:437
A settings block.
Definition: settings.h:132
#define settings_root
Root settings block.
Definition: settings.c:249
A setting.
Definition: settings.h:23
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int(* store)(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.h:108
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120
uint32_t len
Length.
Definition: ena.h:14

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

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

◆ fetch_setting()

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

668  {
669  const struct setting *applicable;
670  struct settings *child;
671  struct setting tmp;
672  int ret;
673 
674  /* Avoid returning uninitialised data on error */
675  memset ( data, 0, len );
676  if ( origin )
677  *origin = NULL;
678  if ( fetched )
679  memcpy ( fetched, setting, sizeof ( *fetched ) );
680 
681  /* Find target settings block */
683 
684  /* Sanity check */
685  if ( ! settings->op->fetch )
686  return -ENOTSUP;
687 
688  /* Try this block first, if an applicable setting exists */
689  if ( ( applicable = applicable_setting ( settings, setting ) ) ) {
690 
691  /* Create modifiable copy of setting */
692  memcpy ( &tmp, applicable, sizeof ( tmp ) );
693  if ( ( ret = settings->op->fetch ( settings, &tmp,
694  data, len ) ) >= 0 ) {
695 
696  /* Default to string type, if not yet specified */
697  if ( ! tmp.type )
698  tmp.type = &setting_type_string;
699 
700  /* Record origin, if applicable */
701  if ( origin )
702  *origin = settings;
703 
704  /* Record fetched setting, if applicable */
705  if ( fetched )
706  memcpy ( fetched, &tmp, sizeof ( *fetched ) );
707 
708  return ret;
709  }
710  }
711 
712  /* Recurse into each child block in turn */
713  list_for_each_entry ( child, &settings->children, siblings ) {
714  if ( ( ret = fetch_setting ( child, setting, origin, fetched,
715  data, len ) ) >= 0 )
716  return ret;
717  }
718 
719  return -ENOENT;
720 }
uint64_t origin
Origin.
Definition: hyperv.h:20
#define ENOENT
No such file or directory.
Definition: errno.h:514
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
unsigned long tmp
Definition: linux_pci.h:63
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:431
int fetch_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
Fetch setting.
Definition: settings.c:666
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static const struct setting * applicable_setting(struct settings *settings, const struct setting *setting)
Find setting applicable to settings block, if any.
Definition: settings.c:589
int(* fetch)(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.h:122
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct list_head children
Child settings blocks.
Definition: settings.h:142
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull

References applicable_setting(), settings::children, data, ENOENT, ENOTSUP, settings_operations::fetch, fetch_setting(), len, list_for_each_entry, memcpy(), memset(), NULL, settings::op, origin, settings_target(), and tmp.

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().

◆ fetch_setting_alloc()

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

741  {
742  struct settings *tmp_origin;
743  struct setting tmp_fetched;
744  int len;
745  int check_len;
746 
747  /* Use local buffers if necessary */
748  if ( ! origin )
749  origin = &tmp_origin;
750  if ( ! fetched )
751  fetched = &tmp_fetched;
752 
753  /* Avoid returning uninitialised data on error */
754  *data = NULL;
755 
756  /* Check existence, and fetch setting length */
757  len = fetch_setting ( settings, setting, origin, fetched, NULL, 0 );
758  if ( len < 0 )
759  return len;
760 
761  /* Allocate buffer */
762  *data = alloc ( len );
763  if ( ! *data )
764  return -ENOMEM;
765 
766  /* Fetch setting value */
767  check_len = fetch_setting ( *origin, fetched, NULL, NULL, *data, len );
768  assert ( check_len == len );
769  return len;
770 }
uint64_t origin
Origin.
Definition: hyperv.h:20
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int fetch_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
Fetch setting.
Definition: settings.c:666
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by fetch_setting_copy(), and fetch_string_setting_copy().

◆ fetch_setting_copy()

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

788  {
789 
790  return fetch_setting_alloc ( settings, setting, origin, fetched,
791  data, malloc );
792 }
uint64_t origin
Origin.
Definition: hyperv.h:20
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.
Definition: settings.c:736
A settings block.
Definition: settings.h:132
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, fetch_setting_alloc(), malloc(), and origin.

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

◆ fetch_raw_setting()

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

805  {
806 
807  return fetch_setting ( settings, setting, NULL, NULL, data, len );
808 }
int fetch_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
Fetch setting.
Definition: settings.c:666
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References data, fetch_setting(), len, 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().

◆ fetch_raw_setting_copy()

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

823  {
824 
826 }
A settings block.
Definition: settings.h:132
int fetch_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data)
Fetch copy of setting.
Definition: settings.c:785
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References data, fetch_setting_copy(), and NULL.

Referenced by apply_dns_search(), apply_dns_servers(), certstore_apply_settings(), copy_encap_settings(), dhcp_create_request(), eap_rx_identity(), eap_rx_md5(), privkey_apply_settings(), and rootcert_init().

◆ fetch_string_setting()

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

843  {
844 
845  memset ( data, 0, len );
847  ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
848 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
void * memset(void *dest, int character, size_t len) __nonnull

References data, fetch_raw_setting(), len, and memset().

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

◆ fetch_string_setting_copy_alloc()

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

856  {
857  return zalloc ( len + 1 /* NUL */ );
858 }
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
uint32_t len
Length.
Definition: ena.h:14

References len, and zalloc().

Referenced by fetch_string_setting_copy().

◆ fetch_string_setting_copy()

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

874  {
875 
877  ( ( void ** ) data ),
879 }
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.
Definition: settings.c:736
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static void * fetch_string_setting_copy_alloc(size_t len)
Allocate memory for copy of string setting.
Definition: settings.c:856
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

◆ fetch_ipv4_array_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.

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

892  {
893  int len;
894 
896  ( sizeof ( *inp ) * count ) );
897  if ( len < 0 )
898  return len;
899  if ( ( len % sizeof ( *inp ) ) != 0 )
900  return -ERANGE;
901  return len;
902 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
uint16_t count
Number of entries.
Definition: ena.h:22
#define ERANGE
Result too large.
Definition: errno.h:639
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14

References count, ERANGE, fetch_raw_setting(), and len.

Referenced by fetch_ipv4_setting(), and ibft_set_ipaddr_setting().

◆ fetch_ipv4_setting()

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

914  {
915 
916  return fetch_ipv4_array_setting ( settings, setting, inp, 1 );
917 }
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
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.
Definition: settings.c:890

References fetch_ipv4_array_setting().

Referenced by 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().

◆ fetch_ipv6_array_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.

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

930  {
931  int len;
932 
934  ( sizeof ( *inp ) * count ) );
935  if ( len < 0 )
936  return len;
937  if ( ( len % sizeof ( *inp ) ) != 0 )
938  return -ERANGE;
939  return len;
940 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
uint16_t count
Number of entries.
Definition: ena.h:22
#define ERANGE
Result too large.
Definition: errno.h:639
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14

References count, ERANGE, fetch_raw_setting(), and len.

Referenced by fetch_ipv6_setting().

◆ fetch_ipv6_setting()

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

952  {
953 
954  return fetch_ipv6_array_setting ( settings, setting, inp, 1 );
955 }
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.
Definition: settings.c:928
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_ipv6_array_setting().

Referenced by apply_syslog_settings().

◆ numeric_setting_value()

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

967  {
968  const uint8_t *unsigned_bytes = raw;
969  const int8_t *signed_bytes = raw;
970  int is_negative;
971  unsigned int i;
972  uint8_t pad;
973  uint8_t byte;
974 
975  /* Convert to host-ordered longs */
976  is_negative = ( len && ( signed_bytes[0] < 0 ) );
977  *value = ( ( is_signed && is_negative ) ? -1L : 0 );
978  pad = *value;
979  for ( i = 0 ; i < len ; i++ ) {
980  byte = unsigned_bytes[i];
981  *value = ( ( *value << 8 ) | byte );
982  if ( ( ( i + sizeof ( *value ) ) < len ) && ( byte != pad ) )
983  return -ERANGE;
984  }
985 
986  return len;
987 }
u32 pad[9]
Padding.
Definition: ar9003_mac.h:90
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
signed char int8_t
Definition: stdint.h:15
#define ERANGE
Result too large.
Definition: errno.h:639
unsigned char uint8_t
Definition: stdint.h:10
unsigned char byte
Definition: smc9000.h:38
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

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

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

◆ fetch_numeric_setting()

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

999  {
1000  unsigned long tmp;
1001  int len;
1002 
1003  /* Avoid returning uninitialised data on error */
1004  *value = 0;
1005 
1006  /* Fetch raw (network-ordered, variable-length) setting */
1007  len = fetch_raw_setting ( settings, setting, &tmp, sizeof ( tmp ) );
1008  if ( len < 0 )
1009  return len;
1010 
1011  /* Extract numeric value */
1012  return numeric_setting_value ( is_signed, &tmp, len, value );
1013 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
unsigned long tmp
Definition: linux_pci.h:63
static int numeric_setting_value(int is_signed, const void *raw, size_t len, unsigned long *value)
Extract numeric value of setting.
Definition: settings.c:966
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14

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

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

◆ fetch_int_setting()

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

1025  {
1026 
1028  ( ( unsigned long * ) value ), 1 );
1029 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

Referenced by apply_peerdist_settings().

◆ fetch_uint_setting()

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

1041  {
1042 
1043  return fetch_numeric_setting ( settings, setting, value, 0 );
1044 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

Referenced by san_default_drive(), and sandev_apply().

◆ fetch_intz_setting()

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

1054  {
1055  unsigned long value;
1056 
1058  return value;
1059 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

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

◆ fetch_uintz_setting()

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

1069  {
1070  unsigned long value;
1071 
1073  return value;
1074 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

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

◆ fetch_uuid_setting()

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

1086  {
1087  int len;
1088 
1089  len = fetch_raw_setting ( settings, setting, uuid, sizeof ( *uuid ) );
1090  if ( len < 0 )
1091  return len;
1092  if ( len != sizeof ( *uuid ) )
1093  return -ERANGE;
1094  return len;
1095 }
A universally unique ID.
Definition: uuid.h:15
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
#define ERANGE
Result too large.
Definition: errno.h:639
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14

References ERANGE, fetch_raw_setting(), and len.

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

◆ clear_settings()

void clear_settings ( struct settings settings)

Clear settings block.

Parameters
settingsSettings block

Definition at line 1102 of file settings.c.

1102  {
1103 
1104  /* Find target settings block */
1106 
1107  /* Clear settings, if applicable */
1108  if ( settings->op->clear )
1109  settings->op->clear ( settings );
1110 }
void(* clear)(struct settings *settings)
Clear settings block.
Definition: settings.h:128
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
A settings block.
Definition: settings.h:132

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

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

◆ setting_cmp()

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

1120  {
1121 
1122  /* If the settings have tags, compare them */
1123  if ( a->tag && ( a->tag == b->tag ) && ( a->scope == b->scope ) )
1124  return 0;
1125 
1126  /* Otherwise, if the settings have names, compare them */
1127  if ( a->name && b->name && a->name[0] )
1128  return strcmp ( a->name, b->name );
1129 
1130  /* Otherwise, return a non-match */
1131  return ( ! 0 );
1132 }
const char * name
Name.
Definition: settings.h:28
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49

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

Referenced by applicable_setting(), builtin_fetch(), dhcpv6_fetch(), efi_path_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().

◆ setting_format()

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

1152  {
1153 
1154  /* Sanity check */
1155  if ( ! type->format )
1156  return -ENOTSUP;
1157 
1158  return type->format ( type, raw, raw_len, buf, len );
1159 }
uint32_t type
Operating system type.
Definition: ena.h:12
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

References ENOTSUP, len, raw, raw_len, and type.

Referenced by fetchf_setting().

◆ setting_parse()

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

1171  {
1172 
1173  /* Sanity check */
1174  if ( ! type->parse )
1175  return -ENOTSUP;
1176 
1177  return type->parse ( type, value, buf, len );
1178 }
uint32_t type
Operating system type.
Definition: ena.h:12
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint32_t len
Length.
Definition: ena.h:14

References ENOTSUP, len, type, and value.

Referenced by guestinfo_fetch_type(), and storef_setting().

◆ setting_numerate()

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

1190  {
1191 
1192  /* Sanity check */
1193  if ( ! type->numerate )
1194  return -ENOTSUP;
1195 
1196  return type->numerate ( type, raw, raw_len, value );
1197 }
uint32_t type
Operating system type.
Definition: ena.h:12
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28

References ENOTSUP, raw, raw_len, type, and value.

Referenced by fetchn_setting().

◆ setting_denumerate()

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

1209  {
1210 
1211  /* Sanity check */
1212  if ( ! type->denumerate )
1213  return -ENOTSUP;
1214 
1215  return type->denumerate ( type, value, buf, len );
1216 }
uint32_t type
Operating system type.
Definition: ena.h:12
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint32_t len
Length.
Definition: ena.h:14

References ENOTSUP, len, type, and value.

Referenced by storen_setting().

◆ fetchf_setting()

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

1231  {
1232  struct setting tmp_fetched;
1233  void *raw;
1234  int raw_len;
1235  int ret;
1236 
1237  /* Use local buffers if necessary */
1238  if ( ! fetched )
1239  fetched = &tmp_fetched;
1240 
1241  /* Fetch raw value */
1243  &raw );
1244  if ( raw_len < 0 ) {
1245  ret = raw_len;
1246  goto err_fetch_copy;
1247  }
1248 
1249  /* Sanity check */
1250  assert ( fetched->type != NULL );
1251 
1252  /* Format setting */
1253  if ( ( ret = setting_format ( fetched->type, raw, raw_len, buf,
1254  len ) ) < 0 )
1255  goto err_format;
1256 
1257  err_format:
1258  free ( raw );
1259  err_fetch_copy:
1260  return ret;
1261 }
uint64_t origin
Origin.
Definition: hyperv.h:20
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.
Definition: settings.c:1151
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
const struct setting_type * type
Setting type.
Definition: settings.h:36
static size_t raw_len
Definition: base16.h:53
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
int fetch_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data)
Fetch copy of setting.
Definition: settings.c:785
A setting.
Definition: settings.h:23
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by efi_snp_hii_fetch(), and fetchf_setting_copy().

◆ fetchf_setting_copy()

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

1279  {
1280  struct settings *tmp_origin;
1281  struct setting tmp_fetched;
1282  int len;
1283  int check_len;
1284 
1285  /* Use local buffers if necessary */
1286  if ( ! origin )
1287  origin = &tmp_origin;
1288  if ( ! fetched )
1289  fetched = &tmp_fetched;
1290 
1291  /* Avoid returning uninitialised data on error */
1292  *value = NULL;
1293 
1294  /* Check existence, and fetch formatted value length */
1295  len = fetchf_setting ( settings, setting, origin, fetched, NULL, 0 );
1296  if ( len < 0 )
1297  return len;
1298 
1299  /* Allocate buffer */
1300  *value = zalloc ( len + 1 /* NUL */ );
1301  if ( ! *value )
1302  return -ENOMEM;
1303 
1304  /* Fetch formatted value */
1305  check_len = fetchf_setting ( *origin, fetched, NULL, NULL, *value,
1306  ( len + 1 /* NUL */ ) );
1307  assert ( check_len == len );
1308  return len;
1309 }
uint64_t origin
Origin.
Definition: hyperv.h:20
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.
Definition: settings.c:1229
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

◆ storef_setting()

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

1320  {
1321  void *raw;
1322  int raw_len;
1323  int check_len;
1324  int rc;
1325 
1326  /* NULL value or empty string implies deletion */
1327  if ( ( ! value ) || ( ! value[0] ) )
1328  return delete_setting ( settings, setting );
1329 
1330  /* Sanity check */
1331  assert ( setting->type != NULL );
1332 
1333  /* Get raw value length */
1335  if ( raw_len < 0 ) {
1336  rc = raw_len;
1337  goto err_raw_len;
1338  }
1339 
1340  /* Allocate buffer for raw value */
1341  raw = malloc ( raw_len );
1342  if ( ! raw ) {
1343  rc = -ENOMEM;
1344  goto err_alloc_raw;
1345  }
1346 
1347  /* Parse formatted value */
1348  check_len = setting_parse ( setting->type, value, raw, raw_len );
1349  assert ( check_len == raw_len );
1350 
1351  /* Store raw value */
1352  if ( ( rc = store_setting ( settings, setting, raw, raw_len ) ) != 0 )
1353  goto err_store;
1354 
1355  err_store:
1356  free ( raw );
1357  err_alloc_raw:
1358  err_raw_len:
1359  return rc;
1360 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static int delete_setting(struct settings *settings, const struct setting *setting)
Delete setting.
Definition: settings.h:531
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.c:615
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
const struct setting_type * type
Setting type.
Definition: settings.h:36
static size_t raw_len
Definition: base16.h:53
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
A setting.
Definition: settings.h:23
__be32 raw[7]
Definition: CIB_PRM.h:28
int setting_parse(const struct setting_type *type, const char *value, void *buf, size_t len)
Parse formatted string to setting value.
Definition: settings.c:1170
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

◆ fetchn_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.

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

1374  {
1375  struct setting tmp_fetched;
1376  void *raw;
1377  int raw_len;
1378  int rc;
1379 
1380  /* Use local buffers if necessary */
1381  if ( ! fetched )
1382  fetched = &tmp_fetched;
1383 
1384  /* Fetch raw value */
1386  &raw );
1387  if ( raw_len < 0 ) {
1388  rc = raw_len;
1389  goto err_fetch_copy;
1390  }
1391 
1392  /* Sanity check */
1393  assert ( fetched->type != NULL );
1394 
1395  /* Numerate setting */
1396  if ( ( rc = setting_numerate ( fetched->type, raw, raw_len,
1397  value ) ) < 0 )
1398  goto err_numerate;
1399 
1400  err_numerate:
1401  free ( raw );
1402  err_fetch_copy:
1403  return rc;
1404 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t origin
Origin.
Definition: hyperv.h:20
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
const struct setting_type * type
Setting type.
Definition: settings.h:36
static size_t raw_len
Definition: base16.h:53
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
int fetch_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data)
Fetch copy of setting.
Definition: settings.c:785
A setting.
Definition: settings.h:23
__be32 raw[7]
Definition: CIB_PRM.h:28
int setting_numerate(const struct setting_type *type, const void *raw, size_t raw_len, unsigned long *value)
Convert setting value to number.
Definition: settings.c:1189
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by inc_exec(), pciscan_exec(), and usbscan_exec().

◆ storen_setting()

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

1415  {
1416  void *raw;
1417  int raw_len;
1418  int check_len;
1419  int rc;
1420 
1421  /* Sanity check */
1422  assert ( setting->type != NULL );
1423 
1424  /* Get raw value length */
1426  if ( raw_len < 0 ) {
1427  rc = raw_len;
1428  goto err_raw_len;
1429  }
1430 
1431  /* Allocate buffer for raw value */
1432  raw = malloc ( raw_len );
1433  if ( ! raw ) {
1434  rc = -ENOMEM;
1435  goto err_alloc_raw;
1436  }
1437 
1438  /* Denumerate value */
1439  check_len = setting_denumerate ( setting->type, value, raw, raw_len );
1440  assert ( check_len == raw_len );
1441 
1442  /* Store raw value */
1443  if ( ( rc = store_setting ( settings, setting, raw, raw_len ) ) != 0 )
1444  goto err_store;
1445 
1446  err_store:
1447  free ( raw );
1448  err_alloc_raw:
1449  err_raw_len:
1450  return rc;
1451 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int setting_denumerate(const struct setting_type *type, unsigned long value, void *buf, size_t len)
Convert number to setting value.
Definition: settings.c:1208
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.c:615
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
const struct setting_type * type
Setting type.
Definition: settings.h:36
static size_t raw_len
Definition: base16.h:53
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
A setting.
Definition: settings.h:23
__be32 raw[7]
Definition: CIB_PRM.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by inc_exec(), pciscan_exec(), and usbscan_exec().

◆ find_setting()

struct setting* find_setting ( const char *  name)

Find predefined setting.

Parameters
nameName
Return values
settingSetting, or NULL

Definition at line 1466 of file settings.c.

1466  {
1467  struct setting *setting;
1468 
1470  if ( strcmp ( name, setting->name ) == 0 )
1471  return setting;
1472  }
1473  return NULL;
1474 }
const char * name
Definition: ath9k_hw.c:1984
const char * name
Name.
Definition: settings.h:28
#define SETTINGS
Configuration setting table.
Definition: settings.h:53
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
A setting.
Definition: settings.h:23
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

◆ parse_setting_tag()

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

1482  {
1483  char *tmp = ( ( char * ) name );
1484  uint64_t tag = 0;
1485 
1486  while ( 1 ) {
1487  tag = ( ( tag << 8 ) | strtoul ( tmp, &tmp, 0 ) );
1488  if ( *tmp == 0 )
1489  return tag;
1490  if ( *tmp != '.' )
1491  return 0;
1492  tmp++;
1493  }
1494 }
const char * name
Definition: ath9k_hw.c:1984
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:484
unsigned long long uint64_t
Definition: stdint.h:13
unsigned long tmp
Definition: linux_pci.h:63
uint64_t tag
Identity tag.
Definition: edd.h:30

References name, strtoul(), tag, and tmp.

Referenced by parse_setting_name().

◆ find_setting_type()

static const struct setting_type* find_setting_type ( const char *  name)
static

Find setting type.

Parameters
nameName
Return values
typeSetting type, or NULL

Definition at line 1502 of file settings.c.

1502  {
1503  const struct setting_type *type;
1504 
1506  if ( strcmp ( name, type->name ) == 0 )
1507  return type;
1508  }
1509  return NULL;
1510 }
const char * name
Definition: ath9k_hw.c:1984
uint32_t type
Operating system type.
Definition: ena.h:12
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
#define SETTING_TYPES
Configuration setting type table.
Definition: settings.h:242
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
A setting type.
Definition: settings.h:191

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

Referenced by parse_setting_name().

◆ parse_setting_name()

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

1529  {
1530  char *settings_name;
1531  char *setting_name;
1532  char *type_name;
1533  struct setting *predefined;
1534  int rc;
1535 
1536  /* Set defaults */
1537  *settings = &settings_root;
1538  memset ( setting, 0, sizeof ( *setting ) );
1539  setting->name = "";
1540 
1541  /* Split name into "[settings_name/]setting_name[:type_name]" */
1542  if ( ( setting_name = strchr ( name, '/' ) ) != NULL ) {
1543  *(setting_name++) = 0;
1544  settings_name = name;
1545  } else {
1546  setting_name = name;
1547  settings_name = NULL;
1548  }
1549  if ( ( type_name = strchr ( setting_name, ':' ) ) != NULL )
1550  *(type_name++) = 0;
1551 
1552  /* Identify settings block, if specified */
1553  if ( settings_name ) {
1554  *settings = parse_settings_name ( settings_name, get_child );
1555  if ( *settings == NULL ) {
1556  DBG ( "Unrecognised settings block \"%s\" in \"%s\"\n",
1557  settings_name, name );
1558  rc = -ENODEV;
1559  goto err;
1560  }
1561  }
1562 
1563  /* Identify setting */
1565  setting->scope = (*settings)->default_scope;
1567  for_each_table_entry ( predefined, SETTINGS ) {
1568  /* Matches a predefined setting; use that setting */
1569  if ( setting_cmp ( predefined, setting ) == 0 ) {
1570  memcpy ( setting, predefined, sizeof ( *setting ) );
1571  break;
1572  }
1573  }
1574 
1575  /* Identify setting type, if specified */
1576  if ( type_name ) {
1577  setting->type = find_setting_type ( type_name );
1578  if ( setting->type == NULL ) {
1579  DBG ( "Invalid setting type \"%s\" in \"%s\"\n",
1580  type_name, name );
1581  rc = -ENOTSUP;
1582  goto err;
1583  }
1584  }
1585 
1586  return 0;
1587 
1588  err:
1589  /* Restore original name */
1590  if ( settings_name )
1591  *( setting_name - 1 ) = '/';
1592  if ( type_name )
1593  *( type_name - 1 ) = ':';
1594  return rc;
1595 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
static struct settings * parse_settings_name(const char *name, get_child_settings_t get_child)
Parse settings block name.
Definition: settings.c:371
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:345
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
const char * name
Name.
Definition: settings.h:28
#define SETTINGS
Configuration setting table.
Definition: settings.h:53
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const struct setting_type * type
Setting type.
Definition: settings.h:36
static uint64_t parse_setting_tag(const char *name)
Parse setting name as tag number.
Definition: settings.c:1482
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:271
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
#define ENODEV
No such device.
Definition: errno.h:509
A settings block.
Definition: settings.h:132
#define settings_root
Root settings block.
Definition: settings.c:249
static const struct setting_type * find_setting_type(const char *name)
Find setting type.
Definition: settings.c:1502
A setting.
Definition: settings.h:23
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49
int setting_name(struct settings *settings, const struct setting *setting, char *buf, size_t len)
Return full setting name.
Definition: settings.c:1606
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
void * memset(void *dest, int character, size_t len) __nonnull

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(), parse_names(), and parse_setting().

◆ setting_name()

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

1607  {
1608  const char *name;
1609 
1611  name = settings_name ( settings );
1612  return snprintf ( buf, len, "%s%s%s:%s", name, ( name[0] ? "/" : "" ),
1613  setting->name, setting->type->name );
1614 }
const char * name
Definition: ath9k_hw.c:1984
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:345
const char * name
Name.
Definition: settings.h:28
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
const struct setting_type * type
Setting type.
Definition: settings.h:36
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
const char * name
Name.
Definition: settings.h:196
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
uint32_t len
Length.
Definition: ena.h:14

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

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

◆ parse_string_setting()

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

1633  {
1634  size_t raw_len = strlen ( value ); /* Exclude terminating NUL */
1635 
1636  /* Copy string to buffer */
1637  if ( len > raw_len )
1638  len = raw_len;
1639  memcpy ( buf, value, len );
1640 
1641  return raw_len;
1642 }
void * memcpy(void *dest, const void *src, size_t len) __nonnull
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:53
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint32_t len
Length.
Definition: ena.h:14

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

◆ format_string_setting()

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

1656  {
1657 
1658  /* Copy string to buffer, and terminate */
1659  memset ( buf, 0, len );
1660  if ( len > raw_len )
1661  len = raw_len;
1662  memcpy ( buf, raw, len );
1663 
1664  return raw_len;
1665 }
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14
void * memset(void *dest, int character, size_t len) __nonnull

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

◆ parse_uristring_setting()

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

1684  {
1685 
1686  return uri_decode ( value, buf, len );
1687 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
size_t uri_decode(const char *encoded, void *buf, size_t len)
Decode URI field.
Definition: uri.c:53
uint32_t len
Length.
Definition: ena.h:14

References len, uri_decode(), and value.

◆ format_uristring_setting()

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

1701  {
1702 
1703  return uri_encode ( 0, raw, raw_len, buf, len );
1704 }
size_t uri_encode(unsigned int field, const void *raw, size_t raw_len, char *buf, ssize_t len)
Encode URI field.
Definition: uri.c:200
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

References len, raw, raw_len, and uri_encode().

◆ parse_ipv4_setting()

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

1724  {
1725  return -ENOTSUP;
1726 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

◆ format_ipv4_setting()

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

1741  {
1742  return -ENOTSUP;
1743 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

◆ parse_ipv6_setting()

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

1763  {
1764  return -ENOTSUP;
1765 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

◆ format_ipv6_setting()

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

1780  {
1781  return -ENOTSUP;
1782 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589

References ENOTSUP.

◆ setting_type_int_index()

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

1843  {
1844 
1845  return ( ( type->name - setting_type_int_name[0] ) /
1846  sizeof ( setting_type_int_name[0] ) );
1847 }
uint32_t type
Operating system type.
Definition: ena.h:12
static const char setting_type_int_name[][8]
Integer setting type names.
Definition: settings.c:1815

References setting_type_int_name, and type.

◆ setting_type_int_width()

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

1855  {
1856 
1857  return ( 1 << setting_type_int_index ( type ) );
1858 }
uint32_t type
Operating system type.
Definition: ena.h:12
setting_type_int_index
Integer setting type indices.
Definition: settings.c:1800

References type.

Referenced by denumerate_int_setting().

◆ setting_type_int_is_signed()

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

1866  {
1867  return ( ( type->name - setting_type_int_name[0] ) & 1 );
1868 }
uint32_t type
Operating system type.
Definition: ena.h:12
static const char setting_type_int_name[][8]
Integer setting type names.
Definition: settings.c:1815

References setting_type_int_name, and type.

Referenced by numerate_int_setting().

◆ denumerate_int_setting()

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

1881  {
1882  unsigned int size = setting_type_int_width ( type );
1883  union {
1884  uint32_t num;
1885  uint8_t bytes[4];
1886  } u;
1887 
1888  u.num = htonl ( value );
1889  if ( len > size )
1890  len = size;
1891  memcpy ( buf, &u.bytes[ sizeof ( u ) - size ], len );
1892 
1893  return size;
1894 }
uint32_t type
Operating system type.
Definition: ena.h:12
#define htonl(value)
Definition: byteswap.h:133
uint32_t num
Definition: multiboot.h:12
void * memcpy(void *dest, const void *src, size_t len) __nonnull
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
unsigned char uint8_t
Definition: stdint.h:10
unsigned int uint32_t
Definition: stdint.h:12
union @17 u
uint8_t size
Entry size (in 32-bit words)
Definition: ena.h:16
static unsigned int setting_type_int_width(const struct setting_type *type)
Get integer setting type width.
Definition: settings.c:1855
uint8_t bytes[64]
Definition: ib_mad.h:16
uint32_t len
Length.
Definition: ena.h:14

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

◆ numerate_int_setting()

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

1907  {
1908  int is_signed = setting_type_int_is_signed ( type );
1909  int check_len;
1910 
1911  /* Extract numeric value */
1912  check_len = numeric_setting_value ( is_signed, raw, raw_len, value );
1913  if ( check_len < 0 )
1914  return check_len;
1915  assert ( check_len == ( int ) raw_len );
1916 
1917  return 0;
1918 }
uint32_t type
Operating system type.
Definition: ena.h:12
static int numeric_setting_value(int is_signed, const void *raw, size_t len, unsigned long *value)
Extract numeric value of setting.
Definition: settings.c:966
static int setting_type_int_is_signed(const struct setting_type *type)
Get integer setting type signedness.
Definition: settings.c:1866
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28

References assert(), numeric_setting_value(), raw, raw_len, setting_type_int_is_signed(), type, and value.

◆ parse_int_setting()

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

1930  {
1931  char *endp;
1932  unsigned long num_value;
1933 
1934  /* Parse value */
1935  num_value = strtoul ( value, &endp, 0 );
1936  if ( *endp )
1937  return -EINVAL;
1938 
1939  return type->denumerate ( type, num_value, buf, len );
1940 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
unsigned long strtoul(const char *string, char **endp, int base)
Convert string to numeric value.
Definition: string.c:484
uint32_t type
Operating system type.
Definition: ena.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint32_t len
Length.
Definition: ena.h:14

References EINVAL, len, strtoul(), type, and value.

◆ format_int_setting()

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

1954  {
1955  unsigned long value;
1956  int ret;
1957 
1958  /* Extract numeric value */
1959  if ( ( ret = type->numerate ( type, raw, raw_len, &value ) ) < 0 )
1960  return ret;
1961 
1962  /* Format value */
1963  return snprintf ( buf, len, "%ld", value );
1964 }
uint32_t type
Operating system type.
Definition: ena.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
uint32_t len
Length.
Definition: ena.h:14

References len, raw, raw_len, snprintf(), type, and value.

◆ format_uint_setting()

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

1978  {
1979  unsigned long value;
1980  int ret;
1981 
1982  /* Extract numeric value */
1983  if ( ( ret = type->numerate ( type, raw, raw_len, &value ) ) < 0 )
1984  return ret;
1985 
1986  /* Format value */
1987  return snprintf ( buf, len, "%#lx", value );
1988 }
uint32_t type
Operating system type.
Definition: ena.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
uint32_t len
Length.
Definition: ena.h:14

References len, raw, raw_len, snprintf(), type, and value.

◆ parse_hex_setting()

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

2053  {
2054  return hex_decode ( ':', value, buf, len );
2055 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int hex_decode(char separator, const char *encoded, void *data, size_t len)
Decode hexadecimal string (with optional byte separator character)
Definition: base16.c:76
uint32_t len
Length.
Definition: ena.h:14

References hex_decode(), len, and value.

◆ format_hex_colon_setting()

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

2069  {
2070  return hex_encode ( ':', raw, raw_len, buf, len );
2071 }
static size_t raw_len
Definition: base16.h:53
size_t hex_encode(char separator, const void *raw, size_t raw_len, char *data, size_t len)
Encode hexadecimal string (with optional byte separator character)
Definition: base16.c:50
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

References hex_encode(), len, raw, and raw_len.

◆ parse_hex_hyphen_setting()

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

2085  {
2086  return hex_decode ( '-', value, buf, len );
2087 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int hex_decode(char separator, const char *encoded, void *data, size_t len)
Decode hexadecimal string (with optional byte separator character)
Definition: base16.c:76
uint32_t len
Length.
Definition: ena.h:14

References hex_decode(), len, and value.

◆ format_hex_hyphen_setting()

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

2101  {
2102  return hex_encode ( '-', raw, raw_len, buf, len );
2103 }
static size_t raw_len
Definition: base16.h:53
size_t hex_encode(char separator, const void *raw, size_t raw_len, char *data, size_t len)
Encode hexadecimal string (with optional byte separator character)
Definition: base16.c:50
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

References hex_encode(), len, raw, and raw_len.

◆ parse_hex_raw_setting()

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

2116  {
2117  return hex_decode ( 0, value, buf, len );
2118 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int hex_decode(char separator, const char *encoded, void *data, size_t len)
Decode hexadecimal string (with optional byte separator character)
Definition: base16.c:76
uint32_t len
Length.
Definition: ena.h:14

References hex_decode(), len, and value.

◆ format_hex_raw_setting()

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

2132  {
2133  return hex_encode ( 0, raw, raw_len, buf, len );
2134 }
static size_t raw_len
Definition: base16.h:53
size_t hex_encode(char separator, const void *raw, size_t raw_len, char *data, size_t len)
Encode hexadecimal string (with optional byte separator character)
Definition: base16.c:50
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14

References hex_encode(), len, raw, and raw_len.

◆ parse_base64_setting()

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

2168  {
2169 
2170  return base64_decode ( value, buf, len );
2171 }
int base64_decode(const char *encoded, void *data, size_t len)
Base64-decode string.
Definition: base64.c:91
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint32_t len
Length.
Definition: ena.h:14

References base64_decode(), len, and value.

◆ format_base64_setting()

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

2185  {
2186 
2187  return base64_encode ( raw, raw_len, buf, len );
2188 }
static size_t raw_len
Definition: base16.h:53
__be32 raw[7]
Definition: CIB_PRM.h:28
uint32_t len
Length.
Definition: ena.h:14
size_t base64_encode(const void *raw, size_t raw_len, char *data, size_t len)
Base64-encode data.
Definition: base64.c:51

References base64_encode(), len, raw, and raw_len.

◆ parse_uuid_setting()

static int parse_uuid_setting ( const struct setting_type type,
const char *  value,
void *  buf,
size_t  len 
)
static

Parse UUID/GUID 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 2207 of file settings.c.

2208  {
2209  union uuid uuid;
2210  int rc;
2211 
2212  /* Parse UUID */
2213  if ( ( rc = uuid_aton ( value, &uuid ) ) != 0 )
2214  return rc;
2215 
2216  /* Mangle GUID byte ordering */
2217  if ( type == &setting_type_guid )
2218  uuid_mangle ( &uuid );
2219 
2220  /* Copy value */
2221  if ( len > sizeof ( uuid ) )
2222  len = sizeof ( uuid );
2223  memcpy ( buf, uuid.raw, len );
2224 
2225  return ( sizeof ( uuid ) );
2226 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A universally unique ID.
Definition: uuid.h:15
uint32_t type
Operating system type.
Definition: ena.h:12
static void uuid_mangle(union uuid *uuid)
Change UUID endianness.
Definition: uuid.h:43
int uuid_aton(const char *string, union uuid *uuid)
Parse UUID.
Definition: uuid.c:66
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t uuid[16]
UUID.
Definition: smbios.h:22
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint8_t raw[16]
Definition: uuid.h:29
uint32_t len
Length.
Definition: ena.h:14

References len, memcpy(), uuid::raw, rc, type, uuid, uuid_aton(), uuid_mangle(), and value.

◆ format_uuid_setting()

static int format_uuid_setting ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
)
static

Format UUID/GUID 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 2238 of file settings.c.

2240  {
2241  union uuid uuid;
2242 
2243  /* Range check */
2244  if ( raw_len != sizeof ( uuid ) )
2245  return -ERANGE;
2246 
2247  /* Copy value */
2248  memcpy ( &uuid, raw, sizeof ( uuid ) );
2249 
2250  /* Mangle GUID byte ordering */
2251  if ( type == &setting_type_guid )
2252  uuid_mangle ( &uuid );
2253 
2254  /* Format value */
2255  return snprintf ( buf, len, "%s", uuid_ntoa ( &uuid ) );
2256 }
A universally unique ID.
Definition: uuid.h:15
uint32_t type
Operating system type.
Definition: ena.h:12
static void uuid_mangle(union uuid *uuid)
Change UUID endianness.
Definition: uuid.h:43
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static size_t raw_len
Definition: base16.h:53
#define ERANGE
Result too large.
Definition: errno.h:639
const char * uuid_ntoa(const union uuid *uuid)
Convert UUID to printable string.
Definition: uuid.c:45
__be32 raw[7]
Definition: CIB_PRM.h:28
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
uint32_t len
Length.
Definition: ena.h:14

References ERANGE, len, memcpy(), raw, raw_len, snprintf(), type, uuid, uuid_mangle(), and uuid_ntoa().

◆ format_busdevfn_setting()

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

2284  {
2285  unsigned long busdevfn;
2286  unsigned int seg;
2287  unsigned int bus;
2288  unsigned int slot;
2289  unsigned int func;
2290  int check_len;
2291 
2292  /* Extract numeric value */
2293  check_len = numeric_setting_value ( 0, raw, raw_len, &busdevfn );
2294  if ( check_len < 0 )
2295  return check_len;
2296  assert ( check_len == ( int ) raw_len );
2297 
2298  /* Extract PCI address components */
2299  seg = PCI_SEG ( busdevfn );
2300  bus = PCI_BUS ( busdevfn );
2301  slot = PCI_SLOT ( busdevfn );
2302  func = PCI_FUNC ( busdevfn );
2303 
2304  /* Format value */
2305  return snprintf ( buf, len, "%04x:%02x:%02x.%x", seg, bus, slot, func );
2306 }
#define PCI_FUNC(busdevfn)
Definition: pci.h:281
#define PCI_BUS(busdevfn)
Definition: pci.h:279
static int numeric_setting_value(int is_signed, const void *raw, size_t len, unsigned long *value)
Extract numeric value of setting.
Definition: settings.c:966
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static size_t raw_len
Definition: base16.h:53
#define PCI_SLOT(busdevfn)
Definition: pci.h:280
uint8_t slot
Slot.
Definition: edd.h:16
__be32 raw[7]
Definition: CIB_PRM.h:28
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
struct golan_mkey_seg seg
Definition: CIB_PRM.h:28
#define PCI_SEG(busdevfn)
Definition: pci.h:278
uint32_t len
Length.
Definition: ena.h:14
uint8_t bus
Bus.
Definition: edd.h:14

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

◆ expand_settings()

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

2330  {
2331  struct settings *settings;
2332  struct setting setting;
2333  char *expstr;
2334  char *start;
2335  char *end;
2336  char *head;
2337  char *name;
2338  char *tail;
2339  char *value;
2340  char *tmp;
2341  int new_len;
2342  int rc;
2343 
2344  /* Obtain temporary modifiable copy of string */
2345  expstr = strdup ( string );
2346  if ( ! expstr )
2347  return NULL;
2348 
2349  /* Expand while expansions remain */
2350  while ( 1 ) {
2351 
2352  head = expstr;
2353 
2354  /* Locate setting to be expanded */
2355  start = NULL;
2356  end = NULL;
2357  for ( tmp = expstr ; *tmp ; tmp++ ) {
2358  if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
2359  start = tmp;
2360  if ( start && ( tmp[0] == '}' ) ) {
2361  end = tmp;
2362  break;
2363  }
2364  }
2365  if ( ! end )
2366  break;
2367  *start = '\0';
2368  name = ( start + 2 );
2369  *end = '\0';
2370  tail = ( end + 1 );
2371 
2372  /* Expand setting */
2374  &settings,
2375  &setting ) ) != 0 ) {
2376  /* Treat invalid setting names as empty */
2377  value = NULL;
2378  } else {
2379  /* Fetch and format setting value. Ignore
2380  * errors; treat non-existent settings as empty.
2381  */
2383  &value );
2384  }
2385 
2386  /* Construct expanded string and discard old string */
2387  tmp = expstr;
2388  new_len = asprintf ( &expstr, "%s%s%s",
2389  head, ( value ? value : "" ), tail );
2390  free ( value );
2391  free ( tmp );
2392  if ( new_len < 0 )
2393  return NULL;
2394  }
2395 
2396  return expstr;
2397 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
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.
Definition: settings.c:1276
uint8_t head
Head number.
Definition: int13.h:34
uint32_t start
Starting offset.
Definition: netvsc.h:12
unsigned long tmp
Definition: linux_pci.h:63
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
int asprintf(char **strp, const char *fmt,...)
Write a formatted string to newly allocated memory.
Definition: asprintf.c:41
char * strdup(const char *src)
Duplicate string.
Definition: string.c:393
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t end
Ending offset.
Definition: netvsc.h:18
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:279
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition: settings.c:1528

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

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

◆ __setting() [1/18]

const struct setting hostname_setting __setting ( SETTING_HOST  ,
hostname   
)

Hostname setting.

◆ __setting() [2/18]

const struct setting domain_setting __setting ( SETTING_IP_EXTRA  ,
domain   
)

Domain name setting.

◆ __setting() [3/18]

const struct setting next_server_setting __setting ( SETTING_BOOT  ,
next server 
)

TFTP server setting.

◆ __setting() [4/18]

const struct setting filename_setting __setting ( SETTING_BOOT  ,
filename   
)

Filename setting.

◆ __setting() [5/18]

const struct setting root_path_setting __setting ( SETTING_SANBOOT  ,
root path 
)

Root path setting.

◆ __setting() [6/18]

const struct setting san_filename_setting __setting ( SETTING_SANBOOT  ,
san-  filename 
)

SAN filename setting.

◆ __setting() [7/18]

const struct setting username_setting __setting ( SETTING_AUTH  ,
username   
)

Username setting.

◆ __setting() [8/18]

const struct setting password_setting __setting ( SETTING_AUTH  ,
password   
)

Password setting.

◆ __setting() [9/18]

const struct setting priority_setting __setting ( SETTING_MISC  ,
priority   
)

Priority setting.

◆ __setting() [10/18]

const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA  ,
user-  class 
)

DHCP user class setting.

◆ __setting() [11/18]

const struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA  ,
vendor class 
)

DHCP vendor class setting.

◆ errno_fetch()

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

2514  {
2515  uint32_t content;
2516 
2517  /* Return current error */
2518  content = htonl ( errno );
2519  if ( len > sizeof ( content ) )
2520  len = sizeof ( content );
2521  memcpy ( data, &content, len );
2522  return sizeof ( content );
2523 }
#define htonl(value)
Definition: byteswap.h:133
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int errno
Global "last error" number.
Definition: errno.c:20
unsigned int uint32_t
Definition: stdint.h:12
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References data, errno, htonl, len, and memcpy().

◆ __setting() [12/18]

const struct setting errno_setting __setting ( SETTING_MISC  ,
errno   
)

Error number setting.

◆ buildarch_fetch()

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

2546  {
2547  static const char buildarch[] = _S2 ( ARCH );
2548 
2549  strncpy ( data, buildarch, len );
2550  return ( sizeof ( buildarch ) - 1 /* NUL */ );
2551 }
#define _S2(x)
Stringify expanded argument.
Definition: compiler.h:53
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:360
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References _S2, data, len, and strncpy().

◆ __setting() [13/18]

const struct setting buildarch_setting __setting ( SETTING_MISC  ,
buildarch   
)

Build architecture setting.

◆ platform_fetch()

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

2574  {
2575  static const char platform[] = _S2 ( PLATFORM );
2576 
2577  strncpy ( data, platform, len );
2578  return ( sizeof ( platform ) - 1 /* NUL */ );
2579 }
#define _S2(x)
Stringify expanded argument.
Definition: compiler.h:53
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:360
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References _S2, data, len, and strncpy().

◆ __setting() [14/18]

const struct setting platform_setting __setting ( SETTING_MISC  ,
platform   
)

Platform setting.

◆ version_fetch()

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

2602  {
2604  return ( strlen ( product_version ) );
2605 }
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:360
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
const char product_version[]
Product version string.
Definition: version.c:70
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

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

◆ __setting() [15/18]

const struct setting version_setting __setting ( SETTING_MISC  ,
version   
)

Version setting.

◆ unixtime_fetch()

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

2628  {
2629  uint32_t content;
2630 
2631  /* Return current time */
2632  content = htonl ( time(NULL) );
2633  if ( len > sizeof ( content ) )
2634  len = sizeof ( content );
2635  memcpy ( data, &content, len );
2636  return sizeof ( content );
2637 }
#define htonl(value)
Definition: byteswap.h:133
void * memcpy(void *dest, const void *src, size_t len) __nonnull
unsigned int uint32_t
Definition: stdint.h:12
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References data, htonl, len, memcpy(), and NULL.

◆ __setting() [16/18]

const struct setting unixtime_setting __setting ( SETTING_MISC  ,
unixtime   
)

Current time setting.

◆ cwuri_fetch_uri()

static int cwuri_fetch_uri ( void *  data,
size_t  len,
const char *  rel 
)
static

Fetch current working URI-related setting.

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

Definition at line 2661 of file settings.c.

2661  {
2662  struct uri *reluri;
2663  struct uri *uri;
2664  char *uristring;
2665  int ret;
2666 
2667  /* Check that current working URI is set */
2668  if ( ! cwuri ) {
2669  ret = -ENOENT;
2670  goto err_unset;
2671  }
2672 
2673  /* Construct relative URI */
2674  reluri = parse_uri ( rel );
2675  if ( ! reluri ) {
2676  ret = -ENOMEM;
2677  goto err_parse;
2678  }
2679 
2680  /* Construct resolved URI */
2681  uri = resolve_uri ( cwuri, reluri );
2682  if ( ! uri ) {
2683  ret = -ENOMEM;
2684  goto err_resolve;
2685  }
2686 
2687  /* Format URI string into allocated buffer (with NUL) */
2688  uristring = format_uri_alloc ( uri );
2689  if ( ! uristring ) {
2690  ret = -ENOMEM;
2691  goto err_format;
2692  }
2693 
2694  /* Copy URI string to buffer */
2695  strncpy ( data, uristring, len );
2696  ret = strlen ( uristring );
2697 
2698  free ( uristring );
2699  err_format:
2700  uri_put ( uri );
2701  err_resolve:
2702  uri_put ( reluri );
2703  err_parse:
2704  err_unset:
2705  return ret;
2706 }
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
#define ENOENT
No such file or directory.
Definition: errno.h:514
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:360
#define ENOMEM
Not enough space.
Definition: errno.h:534
char * format_uri_alloc(const struct uri *uri)
Format URI.
Definition: uri.c:540
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint8_t data[48]
Additional event data.
Definition: ena.h:22
A Uniform Resource Identifier.
Definition: uri.h:64
struct uri * resolve_uri(const struct uri *base_uri, struct uri *relative_uri)
Resolve base+relative URI.
Definition: uri.c:694
struct uri * cwuri
Current working URI.
Definition: cwuri.c:38
uint32_t len
Length.
Definition: ena.h:14
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition: uri.c:296

References cwuri, data, ENOENT, ENOMEM, format_uri_alloc(), free, len, parse_uri(), resolve_uri(), strlen(), strncpy(), and uri_put().

Referenced by cwduri_fetch(), and cwuri_fetch().

◆ cwuri_fetch()

static int cwuri_fetch ( void *  data,
size_t  len 
)
static

Fetch current working URI setting.

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

Definition at line 2715 of file settings.c.

2715  {
2716 
2717  return cwuri_fetch_uri ( data, len, "" );
2718 }
static int cwuri_fetch_uri(void *data, size_t len, const char *rel)
Fetch current working URI-related setting.
Definition: settings.c:2661
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References cwuri_fetch_uri(), data, and len.

◆ cwduri_fetch()

static int cwduri_fetch ( void *  data,
size_t  len 
)
static

Fetch current working directory URI setting.

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

Definition at line 2727 of file settings.c.

2727  {
2728 
2729  return cwuri_fetch_uri ( data, len, "." );
2730 }
static int cwuri_fetch_uri(void *data, size_t len, const char *rel)
Fetch current working URI-related setting.
Definition: settings.c:2661
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint32_t len
Length.
Definition: ena.h:14

References cwuri_fetch_uri(), data, and len.

◆ __setting() [17/18]

const struct setting cwuri_setting __setting ( SETTING_MISC  ,
cwuri   
)

Current working URI setting.

◆ __setting() [18/18]

const struct setting cwduri_setting __setting ( SETTING_MISC  ,
cwduri   
)

Current working directory URI setting.

◆ builtin_fetch()

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

2771  {
2772  struct builtin_setting *builtin;
2773 
2774  for_each_table_entry ( builtin, BUILTIN_SETTINGS ) {
2775  if ( setting_cmp ( setting, builtin->setting ) == 0 )
2776  return builtin->fetch ( data, len );
2777  }
2778  return -ENOENT;
2779 }
#define ENOENT
No such file or directory.
Definition: errno.h:514
int(* fetch)(void *data, size_t len)
Fetch setting value.
Definition: settings.h:276
const struct setting * setting
Setting.
Definition: settings.h:269
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
A built-in setting.
Definition: settings.h:267
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120
uint32_t len
Length.
Definition: ena.h:14
#define BUILTIN_SETTINGS
Built-in settings table.
Definition: settings.h:280

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

◆ builtin_applies()

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

2789  {
2790 
2791  return ( setting->scope == &builtin_scope );
2792 }
A setting.
Definition: settings.h:23
const struct settings_scope builtin_scope
Built-in setting scope.
Definition: settings.c:2505
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49

References builtin_scope, and setting::scope.

◆ builtin_init()

static void builtin_init ( void  )
static

Initialise built-in settings.

Definition at line 2809 of file settings.c.

2809  {
2810  int rc;
2811 
2813  "builtin" ) ) != 0 ) {
2814  DBG ( "Could not register built-in settings: %s\n",
2815  strerror ( rc ) );
2816  return;
2817  }
2818 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static struct settings builtin_settings
Built-in settings.
Definition: settings.c:2801
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:475
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

◆ __init_fn()

struct init_fn builtin_init_fn __init_fn ( INIT_NORMAL  )

Built-in settings initialiser.

Variable Documentation

◆ generic_settings_operations

struct settings_operations generic_settings_operations
Initial value:
= {
}
void generic_settings_clear(struct settings *settings)
Clear generic settings block.
Definition: settings.c:207
int generic_settings_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of generic setting.
Definition: settings.c:178
int generic_settings_store(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of generic setting.
Definition: settings.c:126

Generic settings operations.

Definition at line 221 of file settings.c.

Referenced by generic_settings_init().

◆ generic_settings_root

struct generic_settings generic_settings_root
Initial value:
= {
.settings = {
.refcnt = NULL,
.name = "",
.siblings =
.children =
},
}
struct settings_operations generic_settings_operations
Generic settings operations.
Definition: settings.c:221
struct list_head list
List of generic settings.
Definition: settings.h:302
struct generic_settings generic_settings_root
Root generic settings block.
Definition: settings.c:235
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
struct settings settings
Settings block.
Definition: settings.h:300
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

Root generic settings block.

Definition at line 235 of file settings.c.

◆ __setting_type

const struct setting_type setting_type_busdevfn __setting_type
Initial value:
= {
.name = "string",
}
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.
Definition: settings.c:1654
static int parse_string_setting(const struct setting_type *type __unused, const char *value, void *buf, size_t len)
Parse string setting value.
Definition: settings.c:1632

A string setting type.

PCI bus:dev.fn setting type.

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

◆ dhcpv6_scope

const struct settings_scope dhcpv6_scope

IPv6 settings scope.

DHCPv6 setting scope.

Definition at line 1792 of file settings.c.

Referenced by dhcpv6_applies(), and dhcpv6_register().

◆ setting_type_int_name

const char setting_type_int_name[][8]
static
Initial value:

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

Referenced by setting_type_int_index(), and setting_type_int_is_signed().

◆ builtin_scope

const struct settings_scope builtin_scope

Built-in setting scope.

Definition at line 2505 of file settings.c.

Referenced by builtin_applies().

◆ __builtin_setting

struct builtin_setting cwduri_builtin_setting __builtin_setting
Initial value:
= {
.setting = &errno_setting,
.fetch = errno_fetch,
}
static int errno_fetch(void *data, size_t len)
Fetch error number setting.
Definition: settings.c:2514

Error number built-in setting.

Current working directory URI built-in setting.

Current working URI built-in setting.

Current time built-in setting.

Version built-in setting.

Platform built-in setting.

Build architecture built-in setting.

Definition at line 2534 of file settings.c.

◆ builtin_settings_operations

struct settings_operations builtin_settings_operations
static
Initial value:
= {
.applies = builtin_applies,
.fetch = builtin_fetch,
}
static int builtin_applies(struct settings *settings __unused, const struct setting *setting)
Check applicability of built-in setting.
Definition: settings.c:2788
static int builtin_fetch(struct settings *settings __unused, struct setting *setting, void *data, size_t len)
Fetch built-in setting.
Definition: settings.c:2769

Built-in settings operations.

Definition at line 2795 of file settings.c.

◆ builtin_settings

struct settings builtin_settings
static
Initial value:
= {
.refcnt = NULL,
}
static struct settings_operations builtin_settings_operations
Built-in settings operations.
Definition: settings.c:2795
static struct settings builtin_settings
Built-in settings.
Definition: settings.c:2801
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

Built-in settings.

Definition at line 2801 of file settings.c.

Referenced by builtin_init().