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

Configuration settings. More...

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

Go to the source code of this file.

Data Structures

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

Macros

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

Typedefs

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

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
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...
 
struct settingsfind_settings (const char *name)
 Find settings block. More...
 
struct settingfind_setting (const char *name)
 Find predefined setting. 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...
 
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...
 
char * expand_settings (const char *string)
 Expand variables within string. More...
 
const struct setting ip_setting __setting (SETTING_IP4, ip)
 
const struct setting netmask_setting __setting (SETTING_IP4, netmask)
 
const struct setting gateway_setting __setting (SETTING_IP4, gateway)
 
const struct setting static_route_setting __setting (SETTING_IP4, static_routes)
 
const struct setting dns_setting __setting (SETTING_IP4_EXTRA, dns)
 
const struct setting ip6_setting __setting (SETTING_IP6, ip6)
 
const struct setting len6_setting __setting (SETTING_IP6, len6)
 
const struct setting gateway6_setting __setting (SETTING_IP6, gateway6)
 
const struct setting dns6_setting __setting (SETTING_IP6_EXTRA, dns6)
 
const struct setting hostname_setting __setting (SETTING_HOST, hostname)
 
const struct setting domain_setting __setting (SETTING_IP_EXTRA, domain)
 
const struct setting filename_setting __setting (SETTING_BOOT, filename)
 
const struct setting root_path_setting __setting (SETTING_SANBOOT, root-path)
 
const struct setting san_filename_setting __setting (SETTING_SANBOOT, san-filename)
 
const struct setting username_setting __setting (SETTING_AUTH, username)
 
const struct setting password_setting __setting (SETTING_AUTH, password)
 
const struct setting priority_setting __setting (SETTING_MISC, priority)
 
const struct setting uuid_setting __setting (SETTING_HOST, uuid)
 
const struct setting next_server_setting __setting (SETTING_BOOT, next-server)
 
const struct setting mac_setting __setting (SETTING_NETDEV, mac)
 
const struct setting busid_setting __setting (SETTING_NETDEV, busid)
 
const struct setting linktype_setting __setting (SETTING_NETDEV, linktype)
 
const struct setting user_class_setting __setting (SETTING_HOST_EXTRA, user-class)
 
const struct setting vendor_class_setting __setting (SETTING_HOST_EXTRA, vendor-class)
 
const struct setting manufacturer_setting __setting (SETTING_HOST_EXTRA, manufacturer)
 
const struct setting product_setting __setting (SETTING_HOST_EXTRA, product)
 
const struct setting serial_setting __setting (SETTING_HOST_EXTRA, serial)
 
const struct setting asset_setting __setting (SETTING_HOST_EXTRA, asset)
 
const struct setting board_serial_setting __setting (SETTING_HOST_EXTRA, board-serial)
 
const struct setting dhcp_server_setting __setting (SETTING_MISC, dhcp-server)
 
static void settings_init (struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
 Initialise a settings block. More...
 
static void generic_settings_init (struct generic_settings *generics, struct refcnt *refcnt)
 Initialise a settings block. More...
 
static int delete_setting (struct settings *settings, const struct setting *setting)
 Delete setting. More...
 
static int setting_exists (struct settings *settings, const struct setting *setting)
 Check existence of predefined setting. More...
 

Variables

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

Detailed Description

Configuration settings.

Definition in file settings.h.

Macro Definition Documentation

◆ SETTINGS

#define SETTINGS   __table ( struct setting, "settings" )

Configuration setting table.

Definition at line 54 of file settings.h.

◆ __setting

#define __setting (   setting_order,
  name 
)    __table_entry ( SETTINGS, setting_order.name )

Declare a configuration setting.

Definition at line 57 of file settings.h.

◆ SETTING_TYPES

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

Configuration setting type table.

Definition at line 243 of file settings.h.

◆ __setting_type

const struct setting_type setting_type_dnssl __setting_type   __table_entry ( SETTING_TYPES, 01 )

Declare a configuration 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 246 of file settings.h.

◆ SETTINGS_APPLICATORS

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

Settings applicator table.

Definition at line 261 of file settings.h.

◆ __settings_applicator

#define __settings_applicator   __table_entry ( SETTINGS_APPLICATORS, 01 )

Declare a settings applicator.

Definition at line 265 of file settings.h.

◆ BUILTIN_SETTINGS

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

Built-in settings table.

Definition at line 281 of file settings.h.

◆ __builtin_setting

struct builtin_setting cwduri_builtin_setting __builtin_setting   __table_entry ( BUILTIN_SETTINGS, 01 )

Declare a 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 284 of file settings.h.

Typedef Documentation

◆ get_child_settings_t

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

A child settings block locator function.

Definition at line 307 of file settings.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

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

129  {
130  struct generic_settings *generics =
132  struct generic_setting *old;
133  struct generic_setting *new = NULL;
134  size_t name_len;
135 
136  /* Identify existing generic setting, if any */
137  old = find_generic_setting ( generics, setting );
138 
139  /* Create new generic setting, if required */
140  if ( len ) {
141  /* Allocate new generic setting */
142  name_len = ( strlen ( setting->name ) + 1 );
143  new = zalloc ( sizeof ( *new ) + name_len + len );
144  if ( ! new )
145  return -ENOMEM;
146 
147  /* Populate new generic setting */
148  new->name_len = name_len;
149  new->data_len = len;
150  memcpy ( &new->setting, setting, sizeof ( new->setting ) );
151  new->setting.name = generic_setting_name ( new );
152  memcpy ( generic_setting_name ( new ),
153  setting->name, name_len );
154  memcpy ( generic_setting_data ( new ), data, len );
155  }
156 
157  /* Delete existing generic setting, if any */
158  if ( old ) {
159  list_del ( &old->list );
160  free ( old );
161  }
162 
163  /* Add new setting to list, if any */
164  if ( new )
165  list_add ( &new->list, &generics->list );
166 
167  return 0;
168 }
size_t name_len
Size of setting name.
Definition: settings.c:73
static struct generic_setting * find_generic_setting(struct generic_settings *generics, const struct setting *setting)
Find generic setting.
Definition: settings.c:107
static void * generic_setting_name(struct generic_setting *generic)
Get generic setting name.
Definition: settings.c:84
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:70
int old
Definition: bitops.h:65
const char * name
Name.
Definition: settings.h:29
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
#define ENOMEM
Not enough space.
Definition: errno.h:535
struct list_head list
List of generic settings.
Definition: settings.h:303
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
ring len
Length.
Definition: dwmac.h:231
A generic setting.
Definition: settings.c:67
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
static void * generic_setting_data(struct generic_setting *generic)
Get generic setting data.
Definition: settings.c:94
A generic settings block.
Definition: settings.h:299
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

181  {
182  struct generic_settings *generics =
184  struct generic_setting *generic;
185 
186  /* Find generic setting */
187  generic = find_generic_setting ( generics, setting );
188  if ( ! generic )
189  return -ENOENT;
190 
191  /* Copy out generic setting data */
192  if ( len > generic->data_len )
193  len = generic->data_len;
194  memcpy ( data, generic_setting_data ( generic ), len );
195 
196  /* Set setting type, if not yet specified */
197  if ( ! setting->type )
198  setting->type = generic->setting.type;
199 
200  return generic->data_len;
201 }
static struct generic_setting * find_generic_setting(struct generic_settings *generics, const struct setting *setting)
Find generic setting.
Definition: settings.c:107
#define ENOENT
No such file or directory.
Definition: errno.h:515
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:36
ring len
Length.
Definition: dwmac.h:231
const struct setting_type * type
Setting type.
Definition: settings.h:37
A generic setting.
Definition: settings.c:67
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
static void * generic_setting_data(struct generic_setting *generic)
Get generic setting data.
Definition: settings.c:94
A generic settings block.
Definition: settings.h:299
uint8_t data[48]
Additional event data.
Definition: ena.h:22

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

208  {
209  struct generic_settings *generics =
211  struct generic_setting *generic;
212  struct generic_setting *tmp;
213 
214  list_for_each_entry_safe ( generic, tmp, &generics->list, list ) {
215  list_del ( &generic->list );
216  free ( generic );
217  }
218  assert ( list_empty ( &generics->list ) );
219 }
struct arbelprm_event_queue_entry generic
Definition: arbel.h:11
struct list_head list
List of generic settings.
Definition: settings.c:69
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:137
unsigned long tmp
Definition: linux_pci.h:65
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
struct list_head list
List of generic settings.
Definition: settings.h:303
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:36
#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:459
A generic setting.
Definition: settings.c:67
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A settings block.
Definition: settings.h:133
A generic settings block.
Definition: settings.h:299

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

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

477  {
478  struct settings *old_settings;
479 
480  /* Sanity check */
481  assert ( settings != NULL );
482 
483  /* Find target parent settings block */
485 
486  /* Apply settings block name */
487  settings->name = name;
488 
489  /* Remove any existing settings with the same name */
490  if ( ( old_settings = find_child_settings ( parent, settings->name ) ))
491  unregister_settings ( old_settings );
492 
493  /* Add to list of settings */
494  ref_get ( settings->refcnt );
495  ref_get ( parent->refcnt );
498  DBGC ( settings, "Settings %p (\"%s\") registered\n",
500 
501  /* Fix up settings priority */
503 
504  /* Apply potentially-updated settings */
505  apply_settings();
506 
507  return 0;
508 }
const char * name
Definition: ath9k_hw.c:1986
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:515
struct settings * parent
Parent settings block.
Definition: settings.h:139
#define DBGC(...)
Definition: compiler.h:505
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:346
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:550
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:94
static void apply_settings(void)
Apply all settings.
Definition: settings.c:416
#define ref_get(refcnt)
Get additional reference to object.
Definition: refcnt.h:93
static void reprioritise_settings(struct settings *settings)
Reprioritise settings.
Definition: settings.c:438
A settings block.
Definition: settings.h:133
const char * name
Name.
Definition: settings.h:137
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:141
struct list_head children
Child settings blocks.
Definition: settings.h:143
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:280
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct refcnt * refcnt
Reference counter.
Definition: settings.h:135

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

515  {
516  struct settings *child;
517 
518  /* Unregister child settings */
519  while ( ( child = list_first_entry ( &settings->children,
520  struct settings, siblings ) ) ) {
521  unregister_settings ( child );
522  }
523 
524  DBGC ( settings, "Settings %p (\"%s\") unregistered\n",
526 
527  /* Remove from list of settings */
529  settings->parent = NULL;
530  list_del ( &settings->siblings );
531  ref_put ( settings->refcnt );
532 
533  /* Apply potentially-updated settings */
534  apply_settings();
535 }
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:515
struct settings * parent
Parent settings block.
Definition: settings.h:139
#define DBGC(...)
Definition: compiler.h:505
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:346
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:334
#define list_del(list)
Delete an entry from a list.
Definition: list.h:120
static void apply_settings(void)
Apply all settings.
Definition: settings.c:416
A settings block.
Definition: settings.h:133
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:141
struct list_head children
Child settings blocks.
Definition: settings.h:143
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct refcnt * refcnt
Reference counter.
Definition: settings.h:135
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107

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

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

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

572  {
573 
574  /* Find target settings block */
576 
577  /* Check applicability of setting */
578  return ( settings->op->applies ?
579  settings->op->applies ( settings, setting ) : 1 );
580 }
struct settings_operations * op
Settings block operations.
Definition: settings.h:145
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:550
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
int(* applies)(struct settings *settings, const struct setting *setting)
Check applicability of setting.
Definition: settings.h:99

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

Referenced by applicable_setting(), select_setting_row(), and store_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 616 of file settings.c.

617  {
618  int rc;
619 
620  /* Find target settings block */
622 
623  /* Fail if setting does not apply to this settings block */
624  if ( ! setting_applies ( settings, setting ) )
625  return -ENOTTY;
626 
627  /* Sanity check */
628  if ( ! settings->op->store )
629  return -ENOTSUP;
630 
631  /* Store setting */
632  if ( ( rc = settings->op->store ( settings, setting,
633  data, len ) ) != 0 )
634  return rc;
635 
636  /* Reprioritise settings if necessary */
637  if ( setting_cmp ( setting, &priority_setting ) == 0 )
639 
640  /* If these settings are registered, apply potentially-updated
641  * settings
642  */
643  for ( ; settings ; settings = settings->parent ) {
644  if ( settings == &settings_root ) {
645  apply_settings();
646  break;
647  }
648  }
649 
650  return 0;
651 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct settings * parent
Parent settings block.
Definition: settings.h:139
struct settings_operations * op
Settings block operations.
Definition: settings.h:145
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:550
ring len
Length.
Definition: dwmac.h:231
static void apply_settings(void)
Apply all settings.
Definition: settings.c:416
int setting_applies(struct settings *settings, const struct setting *setting)
Check applicability of setting.
Definition: settings.c:571
static void reprioritise_settings(struct settings *settings)
Reprioritise settings.
Definition: settings.c:438
A settings block.
Definition: settings.h:133
#define settings_root
Root settings block.
Definition: settings.c:250
A setting.
Definition: settings.h:24
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:595
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:109
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1121

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(), digest_exec(), 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 667 of file settings.c.

669  {
670  const struct setting *applicable;
671  struct settings *child;
672  struct setting tmp;
673  int ret;
674 
675  /* Avoid returning uninitialised data on error */
676  memset ( data, 0, len );
677  if ( origin )
678  *origin = NULL;
679  if ( fetched )
680  memcpy ( fetched, setting, sizeof ( *fetched ) );
681 
682  /* Find target settings block */
684 
685  /* Sanity check */
686  if ( ! settings->op->fetch )
687  return -ENOTSUP;
688 
689  /* Try this block first, if an applicable setting exists */
690  if ( ( applicable = applicable_setting ( settings, setting ) ) ) {
691 
692  /* Create modifiable copy of setting */
693  memcpy ( &tmp, applicable, sizeof ( tmp ) );
694  if ( ( ret = settings->op->fetch ( settings, &tmp,
695  data, len ) ) >= 0 ) {
696 
697  /* Default to string type, if not yet specified */
698  if ( ! tmp.type )
699  tmp.type = &setting_type_string;
700 
701  /* Record origin, if applicable */
702  if ( origin )
703  *origin = settings;
704 
705  /* Record fetched setting, if applicable */
706  if ( fetched )
707  memcpy ( fetched, &tmp, sizeof ( *fetched ) );
708 
709  return ret;
710  }
711  }
712 
713  /* Recurse into each child block in turn */
714  list_for_each_entry ( child, &settings->children, siblings ) {
715  if ( ( ret = fetch_setting ( child, setting, origin, fetched,
716  data, len ) ) >= 0 )
717  return ret;
718  }
719 
720  return -ENOENT;
721 }
uint64_t origin
Origin.
Definition: hyperv.h:20
#define ENOENT
No such file or directory.
Definition: errno.h:515
struct settings_operations * op
Settings block operations.
Definition: settings.h:145
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
unsigned long tmp
Definition: linux_pci.h:65
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:550
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
ring len
Length.
Definition: dwmac.h:231
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:667
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
static const struct setting * applicable_setting(struct settings *settings, const struct setting *setting)
Find setting applicable to settings block, if any.
Definition: settings.c:590
int(* fetch)(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.h:123
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct list_head children
Child settings blocks.
Definition: settings.h:143
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
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_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 786 of file settings.c.

789  {
790 
791  return fetch_setting_alloc ( settings, setting, origin, fetched,
792  data, malloc );
793 }
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:737
A settings block.
Definition: settings.h:133
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
A setting.
Definition: settings.h:24
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 804 of file settings.c.

806  {
807 
808  return fetch_setting ( settings, setting, NULL, NULL, data, len );
809 }
ring len
Length.
Definition: dwmac.h:231
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:667
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

824  {
825 
827 }
A settings block.
Definition: settings.h:133
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:786
A setting.
Definition: settings.h:24
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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(), ipv4_add_miniroutes(), 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 842 of file settings.c.

844  {
845 
846  memset ( data, 0, len );
848  ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
849 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:804
ring len
Length.
Definition: dwmac.h:231
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
uint8_t data[48]
Additional event data.
Definition: ena.h:22
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()

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

875  {
876 
878  ( ( void ** ) data ),
880 }
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:737
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
static void * fetch_string_setting_copy_alloc(size_t len)
Allocate memory for copy of string setting.
Definition: settings.c:857
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

893  {
894  int len;
895 
897  ( sizeof ( *inp ) * count ) );
898  if ( len < 0 )
899  return len;
900  if ( ( len % sizeof ( *inp ) ) != 0 )
901  return -ERANGE;
902  return len;
903 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:804
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define ERANGE
Result too large.
Definition: errno.h:640
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

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

915  {
916 
917  return fetch_ipv4_array_setting ( settings, setting, inp, 1 );
918 }
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
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:891

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_add_miniroutes(), 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 929 of file settings.c.

931  {
932  int len;
933 
935  ( sizeof ( *inp ) * count ) );
936  if ( len < 0 )
937  return len;
938  if ( ( len % sizeof ( *inp ) ) != 0 )
939  return -ERANGE;
940  return len;
941 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:804
ring len
Length.
Definition: dwmac.h:231
static unsigned int count
Number of entries.
Definition: dwmac.h:225
#define ERANGE
Result too large.
Definition: errno.h:640
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

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

953  {
954 
955  return fetch_ipv6_array_setting ( settings, setting, inp, 1 );
956 }
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:929
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

References fetch_ipv6_array_setting().

Referenced by apply_syslog_settings().

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

1026  {
1027 
1029  ( ( unsigned long * ) value ), 1 );
1030 }
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:998
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

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

1042  {
1043 
1044  return fetch_numeric_setting ( settings, setting, value, 0 );
1045 }
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:998
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

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

1055  {
1056  unsigned long value;
1057 
1059  return value;
1060 }
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:998
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

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

1070  {
1071  unsigned long value;
1072 
1074  return value;
1075 }
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:998
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

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

1087  {
1088  int len;
1089 
1090  len = fetch_raw_setting ( settings, setting, uuid, sizeof ( *uuid ) );
1091  if ( len < 0 )
1092  return len;
1093  if ( len != sizeof ( *uuid ) )
1094  return -ERANGE;
1095  return len;
1096 }
A universally unique ID.
Definition: uuid.h:16
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:804
ring len
Length.
Definition: dwmac.h:231
#define ERANGE
Result too large.
Definition: errno.h:640
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24

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

1103  {
1104 
1105  /* Find target settings block */
1107 
1108  /* Clear settings, if applicable */
1109  if ( settings->op->clear )
1110  settings->op->clear ( settings );
1111 }
void(* clear)(struct settings *settings)
Clear settings block.
Definition: settings.h:129
struct settings_operations * op
Settings block operations.
Definition: settings.h:145
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:550
A settings block.
Definition: settings.h:133

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

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

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

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

281  {
282  struct settings *settings;
283 
284  /* Find target parent settings block */
286 
287  /* Treat empty name as meaning "this block" */
288  if ( ! *name )
289  return parent;
290 
291  /* Look for child with matching name */
293  if ( strcmp ( settings->name, name ) == 0 )
294  return settings_target ( settings );
295  }
296 
297  return NULL;
298 }
const char * name
Definition: ath9k_hw.c:1986
struct settings * parent
Parent settings block.
Definition: settings.h:139
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:550
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:432
A settings block.
Definition: settings.h:133
const char * name
Name.
Definition: settings.h:137
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:141
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:174
struct list_head children
Child settings blocks.
Definition: settings.h:143
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

308  {
309  struct {
310  struct autovivified_settings autovivified;
311  char name[ strlen ( name ) + 1 /* NUL */ ];
312  } *new_child;
313  struct settings *settings;
314 
315  /* Find target parent settings block */
317 
318  /* Return existing settings, if existent */
319  if ( ( settings = find_child_settings ( parent, name ) ) != NULL )
320  return settings;
321 
322  /* Create new generic settings block */
323  new_child = zalloc ( sizeof ( *new_child ) );
324  if ( ! new_child ) {
325  DBGC ( parent, "Settings %p could not create child %s\n",
326  parent, name );
327  return NULL;
328  }
329  memcpy ( new_child->name, name, sizeof ( new_child->name ) );
330  ref_init ( &new_child->autovivified.refcnt,
332  generic_settings_init ( &new_child->autovivified.generic,
333  &new_child->autovivified.refcnt );
334  settings = &new_child->autovivified.generic.settings;
335  register_settings ( settings, parent, new_child->name );
336  ref_put ( settings->refcnt );
337  return settings;
338 }
const char * name
Definition: ath9k_hw.c:1986
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:65
struct settings * parent
Parent settings block.
Definition: settings.h:139
static void generic_settings_init(struct generic_settings *generics, struct refcnt *refcnt)
Initialise a settings block.
Definition: settings.h:520
#define DBGC(...)
Definition: compiler.h:505
Autovivified settings block.
Definition: settings.c:253
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:550
static void autovivified_settings_free(struct refcnt *refcnt)
Free autovivified settings block.
Definition: settings.c:265
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:662
size_t strlen(const char *src)
Get length of string.
Definition: string.c:244
A settings block.
Definition: settings.h:133
const char * name
Name.
Definition: settings.h:137
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:476
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:280
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
struct refcnt * refcnt
Reference counter.
Definition: settings.h:135
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:107

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

◆ settings_name()

const char* settings_name ( struct settings settings)

Return settings block name.

Parameters
settingsSettings block
Return values
nameSettings block name

Definition at line 346 of file settings.c.

346  {
347  static char buf[16];
348  char tmp[ 1 /* '.' */ + sizeof ( buf ) ];
349 
350  /* Find target settings block */
352 
353  /* Construct name */
354  buf[0] = '\0';
355  tmp[0] = '\0';
356  for ( ; settings->parent ; settings = settings->parent ) {
357  memcpy ( ( tmp + 1 ), buf, ( sizeof ( tmp ) - 1 ) );
358  snprintf ( buf, sizeof ( buf ), "%s%s", settings->name, tmp );
359  tmp[0] = '.';
360  }
361  return buf;
362 }
struct settings * parent
Parent settings block.
Definition: settings.h:139
unsigned long tmp
Definition: linux_pci.h:65
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:550
A settings block.
Definition: settings.h:133
const char * name
Name.
Definition: settings.h:137
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383

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

◆ find_settings()

struct settings* find_settings ( const char *  name)

Find settings block.

Parameters
nameName
Return values
settingsSettings block, or NULL

Definition at line 407 of file settings.c.

407  {
408 
410 }
const char * name
Definition: ath9k_hw.c:1986
static struct settings * parse_settings_name(const char *name, get_child_settings_t get_child)
Parse settings block name.
Definition: settings.c:372
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:280

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

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

◆ find_setting()

struct setting* find_setting ( const char *  name)

Find predefined setting.

Parameters
nameName
Return values
settingSetting, or NULL

Definition at line 1467 of file settings.c.

1467  {
1468  struct setting *setting;
1469 
1471  if ( strcmp ( name, setting->name ) == 0 )
1472  return setting;
1473  }
1474  return NULL;
1475 }
const char * name
Definition: ath9k_hw.c:1986
const char * name
Name.
Definition: settings.h:29
#define SETTINGS
Configuration setting table.
Definition: settings.h:54
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:386
A setting.
Definition: settings.h:24
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:174
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

1530  {
1531  char *settings_name;
1532  char *setting_name;
1533  char *type_name;
1534  struct setting *predefined;
1535  int rc;
1536 
1537  /* Set defaults */
1538  *settings = &settings_root;
1539  memset ( setting, 0, sizeof ( *setting ) );
1540  setting->name = "";
1541 
1542  /* Split name into "[settings_name/]setting_name[:type_name]" */
1543  if ( ( setting_name = strchr ( name, '/' ) ) != NULL ) {
1544  *(setting_name++) = 0;
1545  settings_name = name;
1546  } else {
1547  setting_name = name;
1548  settings_name = NULL;
1549  }
1550  if ( ( type_name = strchr ( setting_name, ':' ) ) != NULL )
1551  *(type_name++) = 0;
1552 
1553  /* Identify settings block, if specified */
1554  if ( settings_name ) {
1555  *settings = parse_settings_name ( settings_name, get_child );
1556  if ( *settings == NULL ) {
1557  DBG ( "Unrecognised settings block \"%s\" in \"%s\"\n",
1558  settings_name, name );
1559  rc = -ENODEV;
1560  goto err;
1561  }
1562  }
1563 
1564  /* Identify setting */
1566  setting->scope = (*settings)->default_scope;
1568  for_each_table_entry ( predefined, SETTINGS ) {
1569  /* Matches a predefined setting; use that setting */
1570  if ( setting_cmp ( predefined, setting ) == 0 ) {
1571  memcpy ( setting, predefined, sizeof ( *setting ) );
1572  break;
1573  }
1574  }
1575 
1576  /* Identify setting type, if specified */
1577  if ( type_name ) {
1578  setting->type = find_setting_type ( type_name );
1579  if ( setting->type == NULL ) {
1580  DBG ( "Invalid setting type \"%s\" in \"%s\"\n",
1581  type_name, name );
1582  rc = -ENOTSUP;
1583  goto err;
1584  }
1585  }
1586 
1587  return 0;
1588 
1589  err:
1590  /* Restore original name */
1591  if ( settings_name )
1592  *( setting_name - 1 ) = '/';
1593  if ( type_name )
1594  *( type_name - 1 ) = ':';
1595  return rc;
1596 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
static struct settings * parse_settings_name(const char *name, get_child_settings_t get_child)
Parse settings block name.
Definition: settings.c:372
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:346
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
const char * name
Name.
Definition: settings.h:29
#define SETTINGS
Configuration setting table.
Definition: settings.h:54
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:44
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const struct setting_type * type
Setting type.
Definition: settings.h:37
static uint64_t parse_setting_tag(const char *name)
Parse setting name as tag number.
Definition: settings.c:1483
char * strchr(const char *src, int character)
Find character within a string.
Definition: string.c:272
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:386
#define ENODEV
No such device.
Definition: errno.h:510
A settings block.
Definition: settings.h:133
#define settings_root
Root settings block.
Definition: settings.c:250
static const struct setting_type * find_setting_type(const char *name)
Find setting type.
Definition: settings.c:1503
A setting.
Definition: settings.h:24
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:50
int setting_name(struct settings *settings, const struct setting *setting, char *buf, size_t len)
Return full setting name.
Definition: settings.c:1607
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1121
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
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(), parse_setting(), and testnet_set_okx().

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

1608  {
1609  const char *name;
1610 
1612  name = settings_name ( settings );
1613  return snprintf ( buf, len, "%s%s%s:%s", name, ( name[0] ? "/" : "" ),
1614  setting->name, setting->type->name );
1615 }
const char * name
Definition: ath9k_hw.c:1986
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:346
const char * name
Name.
Definition: settings.h:29
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:550
ring len
Length.
Definition: dwmac.h:231
const struct setting_type * type
Setting type.
Definition: settings.h:37
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
const char * name
Name.
Definition: settings.h:197
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:383

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

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

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

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

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

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

1191  {
1192 
1193  /* Sanity check */
1194  if ( ! type->numerate )
1195  return -ENOTSUP;
1196 
1197  return type->numerate ( type, raw, raw_len, value );
1198 }
uint32_t type
Operating system type.
Definition: ena.h:12
#define ENOTSUP
Operation not supported.
Definition: errno.h:590
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:54
__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 1209 of file settings.c.

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

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

1232  {
1233  struct setting tmp_fetched;
1234  void *raw;
1235  int raw_len;
1236  int ret;
1237 
1238  /* Use local buffers if necessary */
1239  if ( ! fetched )
1240  fetched = &tmp_fetched;
1241 
1242  /* Fetch raw value */
1244  &raw );
1245  if ( raw_len < 0 ) {
1246  ret = raw_len;
1247  goto err_fetch_copy;
1248  }
1249 
1250  /* Sanity check */
1251  assert ( fetched->type != NULL );
1252 
1253  /* Format setting */
1254  if ( ( ret = setting_format ( fetched->type, raw, raw_len, buf,
1255  len ) ) < 0 )
1256  goto err_format;
1257 
1258  err_format:
1259  free ( raw );
1260  err_fetch_copy:
1261  return ret;
1262 }
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:1152
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
ring len
Length.
Definition: dwmac.h:231
const struct setting_type * type
Setting type.
Definition: settings.h:37
static size_t raw_len
Definition: base16.h:54
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A settings block.
Definition: settings.h:133
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:786
A setting.
Definition: settings.h:24
__be32 raw[7]
Definition: CIB_PRM.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

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

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

1321  {
1322  void *raw;
1323  int raw_len;
1324  int check_len;
1325  int rc;
1326 
1327  /* NULL value or empty string implies deletion */
1328  if ( ( ! value ) || ( ! value[0] ) )
1329  return delete_setting ( settings, setting );
1330 
1331  /* Sanity check */
1332  assert ( setting->type != NULL );
1333 
1334  /* Get raw value length */
1336  if ( raw_len < 0 ) {
1337  rc = raw_len;
1338  goto err_raw_len;
1339  }
1340 
1341  /* Allocate buffer for raw value */
1342  raw = malloc ( raw_len );
1343  if ( ! raw ) {
1344  rc = -ENOMEM;
1345  goto err_alloc_raw;
1346  }
1347 
1348  /* Parse formatted value */
1349  check_len = setting_parse ( setting->type, value, raw, raw_len );
1350  assert ( check_len == raw_len );
1351 
1352  /* Store raw value */
1353  if ( ( rc = store_setting ( settings, setting, raw, raw_len ) ) != 0 )
1354  goto err_store;
1355 
1356  err_store:
1357  free ( raw );
1358  err_alloc_raw:
1359  err_raw_len:
1360  return rc;
1361 }
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:534
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.c:616
#define ENOMEM
Not enough space.
Definition: errno.h:535
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:37
static size_t raw_len
Definition: base16.h:54
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A settings block.
Definition: settings.h:133
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
A setting.
Definition: settings.h:24
__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:1171
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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(), set_core_exec(), and testnet_set_okx().

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

1375  {
1376  struct setting tmp_fetched;
1377  void *raw;
1378  int raw_len;
1379  int rc;
1380 
1381  /* Use local buffers if necessary */
1382  if ( ! fetched )
1383  fetched = &tmp_fetched;
1384 
1385  /* Fetch raw value */
1387  &raw );
1388  if ( raw_len < 0 ) {
1389  rc = raw_len;
1390  goto err_fetch_copy;
1391  }
1392 
1393  /* Sanity check */
1394  assert ( fetched->type != NULL );
1395 
1396  /* Numerate setting */
1397  if ( ( rc = setting_numerate ( fetched->type, raw, raw_len,
1398  value ) ) < 0 )
1399  goto err_numerate;
1400 
1401  err_numerate:
1402  free ( raw );
1403  err_fetch_copy:
1404  return rc;
1405 }
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:37
static size_t raw_len
Definition: base16.h:54
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A settings block.
Definition: settings.h:133
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:786
A setting.
Definition: settings.h:24
__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:1190
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

1416  {
1417  void *raw;
1418  int raw_len;
1419  int check_len;
1420  int rc;
1421 
1422  /* Sanity check */
1423  assert ( setting->type != NULL );
1424 
1425  /* Get raw value length */
1427  if ( raw_len < 0 ) {
1428  rc = raw_len;
1429  goto err_raw_len;
1430  }
1431 
1432  /* Allocate buffer for raw value */
1433  raw = malloc ( raw_len );
1434  if ( ! raw ) {
1435  rc = -ENOMEM;
1436  goto err_alloc_raw;
1437  }
1438 
1439  /* Denumerate value */
1440  check_len = setting_denumerate ( setting->type, value, raw, raw_len );
1441  assert ( check_len == raw_len );
1442 
1443  /* Store raw value */
1444  if ( ( rc = store_setting ( settings, setting, raw, raw_len ) ) != 0 )
1445  goto err_store;
1446 
1447  err_store:
1448  free ( raw );
1449  err_alloc_raw:
1450  err_raw_len:
1451  return rc;
1452 }
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:1209
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.c:616
#define ENOMEM
Not enough space.
Definition: errno.h:535
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:37
static size_t raw_len
Definition: base16.h:54
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
A settings block.
Definition: settings.h:133
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:621
A setting.
Definition: settings.h:24
__be32 raw[7]
Definition: CIB_PRM.h:28
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

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

2331  {
2332  struct settings *settings;
2333  struct setting setting;
2334  char *expstr;
2335  char *start;
2336  char *end;
2337  char *head;
2338  char *name;
2339  char *tail;
2340  char *value;
2341  char *tmp;
2342  int new_len;
2343  int rc;
2344 
2345  /* Obtain temporary modifiable copy of string */
2346  expstr = strdup ( string );
2347  if ( ! expstr )
2348  return NULL;
2349 
2350  /* Expand while expansions remain */
2351  while ( 1 ) {
2352 
2353  head = expstr;
2354 
2355  /* Locate setting to be expanded */
2356  start = NULL;
2357  end = NULL;
2358  for ( tmp = expstr ; *tmp ; tmp++ ) {
2359  if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
2360  start = tmp;
2361  if ( start && ( tmp[0] == '}' ) ) {
2362  end = tmp;
2363  break;
2364  }
2365  }
2366  if ( ! end )
2367  break;
2368  *start = '\0';
2369  name = ( start + 2 );
2370  *end = '\0';
2371  tail = ( end + 1 );
2372 
2373  /* Expand setting */
2375  &settings,
2376  &setting ) ) != 0 ) {
2377  /* Treat invalid setting names as empty */
2378  value = NULL;
2379  } else {
2380  /* Fetch and format setting value. Ignore
2381  * errors; treat non-existent settings as empty.
2382  */
2384  &value );
2385  }
2386 
2387  /* Construct expanded string and discard old string */
2388  tmp = expstr;
2389  new_len = asprintf ( &expstr, "%s%s%s",
2390  head, ( value ? value : "" ), tail );
2391  free ( value );
2392  free ( tmp );
2393  if ( new_len < 0 )
2394  return NULL;
2395  }
2396 
2397  return expstr;
2398 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1986
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:1277
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:65
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
int asprintf(char **strp, const char *fmt,...)
Write a formatted string to newly allocated memory.
Definition: asprintf.c:42
char * strdup(const char *src)
Duplicate string.
Definition: string.c:394
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
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:280
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition: settings.c:1529

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/30]

const struct setting ip_setting __setting ( SETTING_IP4  ,
ip   
)

◆ __setting() [2/30]

const struct setting netmask_setting __setting ( SETTING_IP4  ,
netmask   
)

◆ __setting() [3/30]

const struct setting gateway_setting __setting ( SETTING_IP4  ,
gateway   
)

◆ __setting() [4/30]

const struct setting static_route_setting __setting ( SETTING_IP4  ,
static_routes   
)

◆ __setting() [5/30]

const struct setting dns_setting __setting ( SETTING_IP4_EXTRA  ,
dns   
)

◆ __setting() [6/30]

const struct setting ip6_setting __setting ( SETTING_IP6  ,
ip6   
)

◆ __setting() [7/30]

const struct setting len6_setting __setting ( SETTING_IP6  ,
len6   
)

◆ __setting() [8/30]

const struct setting gateway6_setting __setting ( SETTING_IP6  ,
gateway6   
)

◆ __setting() [9/30]

const struct setting dns6_setting __setting ( SETTING_IP6_EXTRA  ,
dns6   
)

◆ __setting() [10/30]

const struct setting hostname_setting __setting ( SETTING_HOST  ,
hostname   
)

◆ __setting() [11/30]

const struct setting domain_setting __setting ( SETTING_IP_EXTRA  ,
domain   
)

◆ __setting() [12/30]

const struct setting filename_setting __setting ( SETTING_BOOT  ,
filename   
)

◆ __setting() [13/30]

const struct setting root_path_setting __setting ( SETTING_SANBOOT  ,
root path 
)

◆ __setting() [14/30]

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

◆ __setting() [15/30]

const struct setting username_setting __setting ( SETTING_AUTH  ,
username   
)

◆ __setting() [16/30]

const struct setting password_setting __setting ( SETTING_AUTH  ,
password   
)

◆ __setting() [17/30]

const struct setting priority_setting __setting ( SETTING_MISC  ,
priority   
)

◆ __setting() [18/30]

const struct setting uuid_setting __setting ( SETTING_HOST  ,
uuid   
)

◆ __setting() [19/30]

const struct setting next_server_setting __setting ( SETTING_BOOT  ,
next server 
)

◆ __setting() [20/30]

const struct setting mac_setting __setting ( SETTING_NETDEV  ,
mac   
)

◆ __setting() [21/30]

const struct setting busid_setting __setting ( SETTING_NETDEV  ,
busid   
)

◆ __setting() [22/30]

const struct setting linktype_setting __setting ( SETTING_NETDEV  ,
linktype   
)

◆ __setting() [23/30]

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

◆ __setting() [24/30]

const struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA  ,
vendor class 
)

◆ __setting() [25/30]

const struct setting manufacturer_setting __setting ( SETTING_HOST_EXTRA  ,
manufacturer   
)

◆ __setting() [26/30]

const struct setting product_setting __setting ( SETTING_HOST_EXTRA  ,
product   
)

◆ __setting() [27/30]

const struct setting serial_setting __setting ( SETTING_HOST_EXTRA  ,
serial   
)

◆ __setting() [28/30]

const struct setting asset_setting __setting ( SETTING_HOST_EXTRA  ,
asset   
)

◆ __setting() [29/30]

const struct setting board_serial_setting __setting ( SETTING_HOST_EXTRA  ,
board-  serial 
)

◆ __setting() [30/30]

const struct setting dhcp_server_setting __setting ( SETTING_MISC  ,
dhcp-  server 
)

◆ settings_init()

static void settings_init ( struct settings settings,
struct settings_operations op,
struct refcnt refcnt,
const struct settings_scope default_scope 
)
inlinestatic

Initialise a settings block.

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

Definition at line 503 of file settings.h.

506  {
509  settings->op = op;
511  settings->default_scope = default_scope;
512 }
static void(*) struct refcnt refcnt)
Definition: pool.h:63
const struct settings_scope * default_scope
Default scope for numerical settings constructed for this block.
Definition: settings.h:147
struct settings_operations * op
Settings block operations.
Definition: settings.h:145
A settings block.
Definition: settings.h:133
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:141
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
struct list_head children
Child settings blocks.
Definition: settings.h:143
struct refcnt * refcnt
Reference counter.
Definition: settings.h:135

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

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

◆ generic_settings_init()

static void generic_settings_init ( struct generic_settings generics,
struct refcnt refcnt 
)
inlinestatic

Initialise a settings block.

Parameters
genericsGeneric settings block
refcntContaining object reference counter, or NULL

Definition at line 520 of file settings.h.

521  {
523  refcnt, NULL );
524  INIT_LIST_HEAD ( &generics->list );
525 }
static void settings_init(struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
Initialise a settings block.
Definition: settings.h:503
A reference counter.
Definition: refcnt.h:27
struct list_head list
List of generic settings.
Definition: settings.h:303
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:46
struct settings settings
Settings block.
Definition: settings.h:301
struct settings_operations generic_settings_operations
Generic settings operations.
Definition: settings.c:222
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

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

Referenced by autovivify_child_settings(), and netdev_settings_init().

◆ delete_setting()

static int delete_setting ( struct settings settings,
const struct setting setting 
)
inlinestatic

Delete setting.

Parameters
settingsSettings block
settingSetting to delete
Return values
rcReturn status code

Definition at line 534 of file settings.h.

535  {
536  return store_setting ( settings, setting, NULL, 0 );
537 }
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.c:616
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References NULL, and store_setting().

Referenced by main_loop(), and storef_setting().

◆ setting_exists()

static int setting_exists ( struct settings settings,
const struct setting setting 
)
inlinestatic

Check existence of predefined setting.

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

Definition at line 546 of file settings.h.

547  {
548  return ( fetch_setting ( settings, setting, NULL, NULL,
549  NULL, 0 ) >= 0 );
550 }
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:667
A settings block.
Definition: settings.h:133
A setting.
Definition: settings.h:24
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References fetch_setting(), and NULL.

Referenced by efi_snp_hii_fetch(), and have_pxe_menu().

Variable Documentation

◆ builtin_scope

const struct settings_scope builtin_scope

Built-in setting scope.

Definition at line 2506 of file settings.c.

Referenced by builtin_applies().

◆ ipv6_settings_scope

const struct settings_scope ipv6_settings_scope

IPv6 setting scope.

IPv6 setting scope.

Definition at line 1121 of file ipv6.c.

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

◆ dhcpv6_scope

const struct settings_scope dhcpv6_scope

DHCPv6 setting scope.

DHCPv6 setting scope.

Definition at line 1793 of file settings.c.

Referenced by dhcpv6_applies(), and dhcpv6_register().

◆ generic_settings_operations

struct settings_operations generic_settings_operations

Generic settings operations.

Definition at line 222 of file settings.c.

Referenced by generic_settings_init().

◆ __setting_type

const struct setting_type setting_type_dnssl __setting_type

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.

A string setting type.

Definition at line 416 of file settings.h.