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)
 
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 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 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 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 53 of file settings.h.

◆ __setting

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

Declare a configuration setting.

Definition at line 56 of file settings.h.

◆ SETTING_TYPES

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

Configuration setting type table.

Definition at line 242 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.

UUID setting type.

A Base64-encoded setting.

A hex-string setting (non-delimited)

A hex-string setting (hyphen-delimited)

A hex-string setting (colon-delimited)

An unsigned 32-bit integer setting type.

An unsigned 16-bit integer setting type.

An unsigned 8-bit integer setting type.

A signed 32-bit integer setting type.

A signed 16-bit integer setting type.

A signed 8-bit integer setting type.

An IPv6 address setting type.

An IPv4 address setting type.

A URI-encoded string setting type.

Definition at line 245 of file settings.h.

◆ SETTINGS_APPLICATORS

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

Settings applicator table.

Definition at line 260 of file settings.h.

◆ __settings_applicator

#define __settings_applicator   __table_entry ( SETTINGS_APPLICATORS, 01 )

Declare a settings applicator.

Definition at line 264 of file settings.h.

◆ BUILTIN_SETTINGS

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

Built-in settings table.

Definition at line 280 of file settings.h.

◆ __builtin_setting

struct builtin_setting unixtime_builtin_setting __builtin_setting   __table_entry ( BUILTIN_SETTINGS, 01 )

Declare a built-in setting.

Current time built-in setting.

Version built-in setting.

Platform built-in setting.

Build architecture built-in setting.

Definition at line 283 of file settings.h.

Typedef Documentation

◆ 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 306 of file settings.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ generic_settings_store()

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

Store value of generic setting.

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

Definition at line 126 of file settings.c.

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

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

Referenced by netdev_store().

◆ generic_settings_fetch()

int generic_settings_fetch ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)

Fetch value of generic setting.

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

Definition at line 178 of file settings.c.

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

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

Referenced by netdev_fetch().

◆ generic_settings_clear()

void generic_settings_clear ( struct settings settings)

Clear generic settings block.

Parameters
settingsSettings block

Definition at line 207 of file settings.c.

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

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

Referenced by autovivified_settings_free(), and netdev_clear().

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

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

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

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

◆ unregister_settings()

void unregister_settings ( struct settings settings)

Unregister settings block.

Parameters
settingsSettings block

Definition at line 517 of file settings.c.

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

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

Referenced by guestinfo_net_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 552 of file settings.c.

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

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

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

◆ setting_applies()

int setting_applies ( struct settings settings,
const struct setting setting 
)

Check applicability of setting.

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

Definition at line 573 of file settings.c.

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

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

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

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

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

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

672  {
673  const struct setting *applicable;
674  struct settings *child;
675  struct setting tmp;
676  int ret;
677 
678  /* Avoid returning uninitialised data on error */
679  memset ( data, 0, len );
680  if ( origin )
681  *origin = NULL;
682  if ( fetched )
683  memcpy ( fetched, setting, sizeof ( *fetched ) );
684 
685  /* Find target settings block */
687 
688  /* Sanity check */
689  if ( ! settings->op->fetch )
690  return -ENOTSUP;
691 
692  /* Try this block first, if an applicable setting exists */
693  if ( ( applicable = applicable_setting ( settings, setting ) ) ) {
694 
695  /* Create modifiable copy of setting */
696  memcpy ( &tmp, applicable, sizeof ( tmp ) );
697  if ( ( ret = settings->op->fetch ( settings, &tmp,
698  data, len ) ) >= 0 ) {
699 
700  /* Default to string type, if not yet specified */
701  if ( ! tmp.type )
702  tmp.type = &setting_type_string;
703 
704  /* Record origin, if applicable */
705  if ( origin )
706  *origin = settings;
707 
708  /* Record fetched setting, if applicable */
709  if ( fetched )
710  memcpy ( fetched, &tmp, sizeof ( *fetched ) );
711 
712  return ret;
713  }
714  }
715 
716  /* Recurse into each child block in turn */
717  list_for_each_entry ( child, &settings->children, siblings ) {
718  if ( ( ret = fetch_setting ( child, setting, origin, fetched,
719  data, len ) ) >= 0 )
720  return ret;
721  }
722 
723  return -ENOENT;
724 }
uint64_t origin
Origin.
Definition: hyperv.h:20
#define ENOENT
No such file or directory.
Definition: errno.h:514
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
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:552
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
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:670
uint8_t * tmp
Definition: entropy.h:156
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static const struct setting * applicable_setting(struct settings *settings, const struct setting *setting)
Find setting applicable to settings block, if any.
Definition: settings.c:592
uint32_t len
Length.
Definition: ena.h:14
int(* fetch)(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.h:122
struct list_head children
Child settings blocks.
Definition: settings.h:142
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
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 789 of file settings.c.

792  {
793 
794  return fetch_setting_alloc ( settings, setting, origin, fetched,
795  data, malloc );
796 }
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:740
A settings block.
Definition: settings.h:132
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
A setting.
Definition: settings.h:23
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

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

Referenced by apply_dns_search(), 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 807 of file settings.c.

809  {
810 
811  return fetch_setting ( settings, setting, NULL, NULL, data, len );
812 }
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:670
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

827  {
828 
830 }
A settings block.
Definition: settings.h:132
int fetch_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data)
Fetch copy of setting.
Definition: settings.c:789
A setting.
Definition: settings.h:23
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References data, fetch_setting_copy(), and NULL.

Referenced by certstore_apply_settings(), copy_encap_settings(), dhcp_create_request(), 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 845 of file settings.c.

847  {
848 
849  memset ( data, 0, len );
851  ( ( len > 0 ) ? ( len - 1 ) : 0 ) );
852 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:807
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
void * memset(void *dest, int character, size_t len) __nonnull

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

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

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

878  {
879 
881  ( ( void ** ) data ),
883 }
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:740
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static void * fetch_string_setting_copy_alloc(size_t len)
Allocate memory for copy of string setting.
Definition: settings.c:860
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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(), fetch_next_server_and_filename(), fetch_root_path(), fetch_san_filename(), ipxe(), iscsi_fetch_settings(), 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 894 of file settings.c.

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

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

918  {
919 
920  return fetch_ipv4_array_setting ( settings, setting, inp, 1 );
921 }
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
int fetch_ipv4_array_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp, unsigned int count)
Fetch value of IPv4 address setting.
Definition: settings.c:894

References fetch_ipv4_array_setting().

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

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

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

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

956  {
957 
958  return fetch_ipv6_array_setting ( settings, setting, inp, 1 );
959 }
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:932
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_ipv6_array_setting().

Referenced by apply_dns_settings(), and 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 1027 of file settings.c.

1029  {
1030 
1032  ( ( unsigned long * ) value ), 1 );
1033 }
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:1001
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

Referenced by apply_peerdist_settings().

◆ fetch_uint_setting()

int fetch_uint_setting ( struct settings settings,
const struct setting setting,
unsigned long *  value 
)

Fetch value of unsigned integer setting.

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

Definition at line 1043 of file settings.c.

1045  {
1046 
1047  return fetch_numeric_setting ( settings, setting, value, 0 );
1048 }
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:1001
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

Referenced by san_default_drive(), and sandev_apply().

◆ fetch_intz_setting()

long fetch_intz_setting ( struct settings settings,
const struct setting setting 
)

Fetch value of signed integer setting, or zero.

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

Definition at line 1057 of file settings.c.

1058  {
1059  unsigned long value;
1060 
1062  return value;
1063 }
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:1001
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

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

◆ fetch_uintz_setting()

unsigned long fetch_uintz_setting ( struct settings settings,
const struct setting setting 
)

Fetch value of unsigned integer setting, or zero.

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

Definition at line 1072 of file settings.c.

1073  {
1074  unsigned long value;
1075 
1077  return value;
1078 }
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:1001
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_numeric_setting(), and value.

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

◆ fetch_uuid_setting()

int fetch_uuid_setting ( struct settings settings,
const struct setting setting,
union uuid uuid 
)

Fetch value of UUID setting.

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

Definition at line 1088 of file settings.c.

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

References ERANGE, fetch_raw_setting(), and len.

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

◆ clear_settings()

void clear_settings ( struct settings settings)

Clear settings block.

Parameters
settingsSettings block

Definition at line 1106 of file settings.c.

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

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

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

◆ setting_cmp()

int setting_cmp ( const struct setting a,
const struct setting b 
)

Compare two settings.

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

Definition at line 1124 of file settings.c.

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

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

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

◆ find_child_settings()

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

Find child settings block.

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

Definition at line 279 of file settings.c.

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

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

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

◆ autovivify_child_settings()

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

Find or create child settings block.

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

Definition at line 306 of file settings.c.

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

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

Referenced by nslookup_resolv_done(), and parse_autovivified_setting().

◆ settings_name()

const char* settings_name ( struct settings settings)

Return settings block name.

Parameters
settingsSettings block
Return values
nameSettings block name

Definition at line 345 of file settings.c.

345  {
346  static char buf[16];
347  char tmp[ 1 /* '.' */ + sizeof ( buf ) ];
348 
349  /* Find target settings block */
351 
352  /* Construct name */
353  buf[0] = '\0';
354  tmp[0] = '\0';
355  for ( ; settings->parent ; settings = settings->parent ) {
356  memcpy ( ( tmp + 1 ), buf, ( sizeof ( tmp ) - 1 ) );
357  snprintf ( buf, sizeof ( buf ), "%s%s", settings->name, tmp );
358  tmp[0] = '.';
359  }
360  return buf;
361 }
struct settings * parent
Parent settings block.
Definition: settings.h:138
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:552
uint8_t * tmp
Definition: entropy.h:156
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

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

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

◆ find_settings()

struct settings* find_settings ( const char *  name)

Find settings block.

Parameters
nameName
Return values
settingsSettings block, or NULL

Definition at line 406 of file settings.c.

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

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

Referenced by create_fakepxebsack(), 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 1470 of file settings.c.

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

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

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

◆ setting_name()

int setting_name ( struct settings settings,
const struct setting setting,
char *  buf,
size_t  len 
)

Return full setting name.

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

Definition at line 1610 of file settings.c.

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

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

1156  {
1157 
1158  /* Sanity check */
1159  if ( ! type->format )
1160  return -ENOTSUP;
1161 
1162  return type->format ( type, raw, raw_len, buf, len );
1163 }
uint8_t type
Type.
Definition: ena.h:16
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static size_t raw_len
Definition: base16.h:50
uint32_t len
Length.
Definition: ena.h:14
__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 1174 of file settings.c.

1175  {
1176 
1177  /* Sanity check */
1178  if ( ! type->parse )
1179  return -ENOTSUP;
1180 
1181  return type->parse ( type, value, buf, len );
1182 }
uint8_t type
Type.
Definition: ena.h:16
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint32_t len
Length.
Definition: ena.h:14

References ENOTSUP, len, type, and value.

Referenced by guestinfo_fetch_type(), and storef_setting().

◆ setting_numerate()

int setting_numerate ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
unsigned long *  value 
)

Convert setting value to number.

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

Definition at line 1193 of file settings.c.

1194  {
1195 
1196  /* Sanity check */
1197  if ( ! type->numerate )
1198  return -ENOTSUP;
1199 
1200  return type->numerate ( type, raw, raw_len, value );
1201 }
uint8_t type
Type.
Definition: ena.h:16
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:50
__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 1212 of file settings.c.

1213  {
1214 
1215  /* Sanity check */
1216  if ( ! type->denumerate )
1217  return -ENOTSUP;
1218 
1219  return type->denumerate ( type, value, buf, len );
1220 }
uint8_t type
Type.
Definition: ena.h:16
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
uint32_t len
Length.
Definition: ena.h:14

References ENOTSUP, len, type, and value.

Referenced by storen_setting().

◆ fetchf_setting()

int fetchf_setting ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
char *  buf,
size_t  len 
)

Fetch formatted value of setting.

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

Definition at line 1233 of file settings.c.

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

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

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

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

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

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

Referenced by expand_settings(), read_value(), 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 1323 of file settings.c.

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

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

◆ fetchn_setting()

int fetchn_setting ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
unsigned long *  value 
)

Fetch numeric value of setting.

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

Definition at line 1376 of file settings.c.

1378  {
1379  struct setting tmp_fetched;
1380  void *raw;
1381  int raw_len;
1382  int rc;
1383 
1384  /* Use local buffers if necessary */
1385  if ( ! fetched )
1386  fetched = &tmp_fetched;
1387 
1388  /* Fetch raw value */
1390  &raw );
1391  if ( raw_len < 0 ) {
1392  rc = raw_len;
1393  goto err_fetch_copy;
1394  }
1395 
1396  /* Sanity check */
1397  assert ( fetched->type != NULL );
1398 
1399  /* Numerate setting */
1400  if ( ( rc = setting_numerate ( fetched->type, raw, raw_len,
1401  value ) ) < 0 )
1402  goto err_numerate;
1403 
1404  err_numerate:
1405  free ( raw );
1406  err_fetch_copy:
1407  return rc;
1408 }
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)
const struct setting_type * type
Setting type.
Definition: settings.h:36
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static size_t raw_len
Definition: base16.h:50
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
int fetch_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data)
Fetch copy of setting.
Definition: settings.c:789
A setting.
Definition: settings.h:23
__be32 raw[7]
Definition: CIB_PRM.h:28
int setting_numerate(const struct setting_type *type, const void *raw, size_t raw_len, unsigned long *value)
Convert setting value to number.
Definition: settings.c:1193
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by inc_exec(), and pciscan_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 1418 of file settings.c.

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

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

Referenced by inc_exec(), and pciscan_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 2288 of file settings.c.

2288  {
2289  struct settings *settings;
2290  struct setting setting;
2291  char *expstr;
2292  char *start;
2293  char *end;
2294  char *head;
2295  char *name;
2296  char *tail;
2297  char *value;
2298  char *tmp;
2299  int new_len;
2300  int rc;
2301 
2302  /* Obtain temporary modifiable copy of string */
2303  expstr = strdup ( string );
2304  if ( ! expstr )
2305  return NULL;
2306 
2307  /* Expand while expansions remain */
2308  while ( 1 ) {
2309 
2310  head = expstr;
2311 
2312  /* Locate setting to be expanded */
2313  start = NULL;
2314  end = NULL;
2315  for ( tmp = expstr ; *tmp ; tmp++ ) {
2316  if ( ( tmp[0] == '$' ) && ( tmp[1] == '{' ) )
2317  start = tmp;
2318  if ( start && ( tmp[0] == '}' ) ) {
2319  end = tmp;
2320  break;
2321  }
2322  }
2323  if ( ! end )
2324  break;
2325  *start = '\0';
2326  name = ( start + 2 );
2327  *end = '\0';
2328  tail = ( end + 1 );
2329 
2330  /* Expand setting */
2332  &settings,
2333  &setting ) ) != 0 ) {
2334  /* Treat invalid setting names as empty */
2335  value = NULL;
2336  } else {
2337  /* Fetch and format setting value. Ignore
2338  * errors; treat non-existent settings as empty.
2339  */
2341  &value );
2342  }
2343 
2344  /* Construct expanded string and discard old string */
2345  tmp = expstr;
2346  new_len = asprintf ( &expstr, "%s%s%s",
2347  head, ( value ? value : "" ), tail );
2348  free ( value );
2349  free ( tmp );
2350  if ( new_len < 0 )
2351  return NULL;
2352  }
2353 
2354  return expstr;
2355 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Definition: ath9k_hw.c:1984
int fetchf_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char **value)
Fetch copy of formatted value of setting.
Definition: settings.c:1280
uint8_t head
Head number.
Definition: int13.h:34
uint32_t start
Starting offset.
Definition: netvsc.h:12
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
int asprintf(char **strp, const char *fmt,...)
Write a formatted string to newly allocated memory.
Definition: asprintf.c:41
uint8_t * tmp
Definition: entropy.h:156
char * strdup(const char *src)
Duplicate string.
Definition: string.c:350
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t end
Ending offset.
Definition: netvsc.h:18
struct settings * find_child_settings(struct settings *parent, const char *name)
Find child settings block.
Definition: settings.c:279
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
int parse_setting_name(char *name, get_child_settings_t get_child, struct settings **settings, struct setting *setting)
Parse setting name.
Definition: settings.c:1532

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

const struct setting ip_setting __setting ( SETTING_IP4  ,
ip   
)

◆ __setting() [2/27]

const struct setting netmask_setting __setting ( SETTING_IP4  ,
netmask   
)

◆ __setting() [3/27]

const struct setting gateway_setting __setting ( SETTING_IP4  ,
gateway   
)

◆ __setting() [4/27]

const struct setting dns_setting __setting ( SETTING_IP4_EXTRA  ,
dns   
)

◆ __setting() [5/27]

const struct setting ip6_setting __setting ( SETTING_IP6  ,
ip6   
)

◆ __setting() [6/27]

const struct setting len6_setting __setting ( SETTING_IP6  ,
len6   
)

◆ __setting() [7/27]

const struct setting gateway6_setting __setting ( SETTING_IP6  ,
gateway6   
)

◆ __setting() [8/27]

const struct setting hostname_setting __setting ( SETTING_HOST  ,
hostname   
)

◆ __setting() [9/27]

const struct setting domain_setting __setting ( SETTING_IP_EXTRA  ,
domain   
)

◆ __setting() [10/27]

const struct setting filename_setting __setting ( SETTING_BOOT  ,
filename   
)

◆ __setting() [11/27]

const struct setting root_path_setting __setting ( SETTING_SANBOOT  ,
root path 
)

◆ __setting() [12/27]

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

◆ __setting() [13/27]

const struct setting username_setting __setting ( SETTING_AUTH  ,
username   
)

◆ __setting() [14/27]

const struct setting password_setting __setting ( SETTING_AUTH  ,
password   
)

◆ __setting() [15/27]

const struct setting priority_setting __setting ( SETTING_MISC  ,
priority   
)

◆ __setting() [16/27]

const struct setting uuid_setting __setting ( SETTING_HOST  ,
uuid   
)

◆ __setting() [17/27]

const struct setting next_server_setting __setting ( SETTING_BOOT  ,
next server 
)

◆ __setting() [18/27]

const struct setting mac_setting __setting ( SETTING_NETDEV  ,
mac   
)

◆ __setting() [19/27]

const struct setting busid_setting __setting ( SETTING_NETDEV  ,
busid   
)

◆ __setting() [20/27]

const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA  ,
user class 
)

◆ __setting() [21/27]

const struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA  ,
vendor class 
)

◆ __setting() [22/27]

const struct setting manufacturer_setting __setting ( SETTING_HOST_EXTRA  ,
manufacturer   
)

◆ __setting() [23/27]

const struct setting product_setting __setting ( SETTING_HOST_EXTRA  ,
product   
)

◆ __setting() [24/27]

const struct setting serial_setting __setting ( SETTING_HOST_EXTRA  ,
serial   
)

◆ __setting() [25/27]

const struct setting asset_setting __setting ( SETTING_HOST_EXTRA  ,
asset   
)

◆ __setting() [26/27]

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

◆ __setting() [27/27]

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 495 of file settings.h.

498  {
501  settings->op = op;
503  settings->default_scope = default_scope;
504 }
static void(*) struct refcnt refcnt)
Definition: pool.h:62
const struct settings_scope * default_scope
Default scope for numerical settings constructed for this block.
Definition: settings.h:146
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
A settings block.
Definition: settings.h:132
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
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:45
struct list_head children
Child settings blocks.
Definition: settings.h:142
struct refcnt * refcnt
Reference counter.
Definition: settings.h:134

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

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

◆ 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 512 of file settings.h.

513  {
515  refcnt, NULL );
516  INIT_LIST_HEAD ( &generics->list );
517 }
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:495
A reference counter.
Definition: refcnt.h:26
struct list_head list
List of generic settings.
Definition: settings.h:302
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
struct settings settings
Settings block.
Definition: settings.h:300
struct settings_operations generic_settings_operations
Generic settings operations.
Definition: settings.c:221
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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 526 of file settings.h.

527  {
528  return store_setting ( settings, setting, NULL, 0 );
529 }
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition: settings.c:618
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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 538 of file settings.h.

539  {
540  return ( fetch_setting ( settings, setting, NULL, NULL,
541  NULL, 0 ) >= 0 );
542 }
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:670
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

Referenced by 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 1796 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 221 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.

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 415 of file settings.h.