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 dns6_setting __setting (SETTING_IP6_EXTRA, dns6)
 
const struct setting hostname_setting __setting (SETTING_HOST, hostname)
 
const struct setting domain_setting __setting (SETTING_IP_EXTRA, domain)
 
const struct setting filename_setting __setting (SETTING_BOOT, filename)
 
const struct setting root_path_setting __setting (SETTING_SANBOOT, root-path)
 
const struct setting san_filename_setting __setting (SETTING_SANBOOT, san-filename)
 
const struct setting username_setting __setting (SETTING_AUTH, username)
 
const struct setting password_setting __setting (SETTING_AUTH, password)
 
const struct setting priority_setting __setting (SETTING_MISC, priority)
 
const struct setting uuid_setting __setting (SETTING_HOST, uuid)
 
const struct setting next_server_setting __setting (SETTING_BOOT, next-server)
 
const struct setting mac_setting __setting (SETTING_NETDEV, mac)
 
const struct setting busid_setting __setting (SETTING_NETDEV, busid)
 
const struct setting linktype_setting __setting (SETTING_NETDEV, linktype)
 
const struct setting user_class_setting __setting (SETTING_HOST_EXTRA, user-class)
 
const struct setting vendor_class_setting __setting (SETTING_HOST_EXTRA, vendor-class)
 
const struct setting manufacturer_setting __setting (SETTING_HOST_EXTRA, manufacturer)
 
const struct setting product_setting __setting (SETTING_HOST_EXTRA, product)
 
const struct setting serial_setting __setting (SETTING_HOST_EXTRA, serial)
 
const struct setting asset_setting __setting (SETTING_HOST_EXTRA, asset)
 
const struct setting board_serial_setting __setting (SETTING_HOST_EXTRA, board-serial)
 
const struct setting dhcp_server_setting __setting (SETTING_MISC, dhcp-server)
 
static void settings_init (struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
 Initialise a settings block. More...
 
static void generic_settings_init (struct generic_settings *generics, struct refcnt *refcnt)
 Initialise a settings block. More...
 
static int delete_setting (struct settings *settings, const struct setting *setting)
 Delete setting. More...
 
static int setting_exists (struct settings *settings, const struct setting *setting)
 Check existence of predefined setting. More...
 

Variables

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

Detailed Description

Configuration settings.

Definition in file settings.h.

Macro Definition Documentation

◆ SETTINGS

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

Configuration setting table.

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

GUID setting type.

UUID setting type.

A Base64-encoded setting.

A hex-string setting (non-delimited)

A hex-string setting (hyphen-delimited)

A hex-string setting (colon-delimited)

An unsigned 32-bit integer setting type.

An unsigned 16-bit integer setting type.

An unsigned 8-bit integer setting type.

A signed 32-bit integer setting type.

A signed 16-bit integer setting type.

A signed 8-bit integer setting type.

An IPv6 address setting type.

An IPv4 address setting type.

A URI-encoded string setting type.

Definition at line 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 cwduri_builtin_setting __builtin_setting   __table_entry ( BUILTIN_SETTINGS, 01 )

Declare a built-in setting.

Current working directory URI built-in setting.

Current working URI built-in setting.

Current time built-in setting.

Version built-in setting.

Platform built-in setting.

Build architecture built-in setting.

Definition at line 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:243
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static void * generic_setting_data(struct generic_setting *generic)
Get generic setting data.
Definition: settings.c:93
A generic settings block.
Definition: settings.h:298
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by netdev_store().

◆ generic_settings_fetch()

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

Fetch value of generic setting.

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

Definition at line 178 of file settings.c.

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

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

Referenced by netdev_fetch().

◆ generic_settings_clear()

void generic_settings_clear ( struct settings settings)

Clear generic settings block.

Parameters
settingsSettings block

Definition at line 207 of file settings.c.

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

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

Referenced by autovivified_settings_free(), and netdev_clear().

◆ register_settings()

int register_settings ( struct settings settings,
struct settings parent,
const char *  name 
)

Register settings block.

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

Definition at line 475 of file settings.c.

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

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

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

◆ unregister_settings()

void unregister_settings ( struct settings settings)

Unregister settings block.

Parameters
settingsSettings block

Definition at line 514 of file settings.c.

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

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

Referenced by cachedhcp_recycle(), dhcp_request_rx(), lldp_probe(), lldp_remove(), ndp_register_settings(), phantom_probe(), phantom_remove(), register_netdev(), register_settings(), settings_test_exec(), unregister_netdev(), unregister_nvo(), and unregister_settings().

◆ settings_target()

struct settings* settings_target ( struct settings settings)

Redirect to target settings block.

Parameters
settingsSettings block, or NULL
Return values
settingsUnderlying settings block

Definition at line 549 of file settings.c.

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

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

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

◆ setting_applies()

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

Check applicability of setting.

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

Definition at line 570 of file settings.c.

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

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

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

◆ store_setting()

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

Store value of setting.

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

Definition at line 615 of file settings.c.

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

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

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

◆ fetch_setting()

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

Fetch setting.

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

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

Definition at line 666 of file settings.c.

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

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

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

◆ fetch_setting_copy()

int fetch_setting_copy ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
void **  data 
)

Fetch copy of setting.

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

The caller is responsible for eventually freeing the allocated buffer.

Definition at line 785 of file settings.c.

788  {
789 
790  return fetch_setting_alloc ( settings, setting, origin, fetched,
791  data, malloc );
792 }
uint64_t origin
Origin.
Definition: hyperv.h:20
static int fetch_setting_alloc(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data, void *(*alloc)(size_t len))
Fetch allocated copy of setting.
Definition: settings.c:736
A settings block.
Definition: settings.h:132
void * malloc(size_t size)
Allocate memory.
Definition: malloc.c:583
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22

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

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

◆ fetch_raw_setting()

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

Fetch value of setting.

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

Definition at line 803 of file settings.c.

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

References data, fetch_setting(), len, and NULL.

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

◆ fetch_raw_setting_copy()

int fetch_raw_setting_copy ( struct settings settings,
const struct setting setting,
void **  data 
)

Fetch value of setting.

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

The caller is responsible for eventually freeing the allocated buffer.

Definition at line 821 of file settings.c.

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

References data, fetch_setting_copy(), and NULL.

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

◆ fetch_string_setting()

int fetch_string_setting ( struct settings settings,
const struct setting setting,
char *  data,
size_t  len 
)

Fetch value of string setting.

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

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

Definition at line 841 of file settings.c.

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

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

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

◆ fetch_string_setting_copy()

int fetch_string_setting_copy ( struct settings settings,
const struct setting setting,
char **  data 
)

Fetch value of string setting.

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

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

Definition at line 873 of file settings.c.

874  {
875 
877  ( ( void ** ) data ),
879 }
static int fetch_setting_alloc(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void **data, void *(*alloc)(size_t len))
Fetch allocated copy of setting.
Definition: settings.c:736
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static void * fetch_string_setting_copy_alloc(size_t len)
Allocate memory for copy of string setting.
Definition: settings.c:856
uint8_t data[48]
Additional event data.
Definition: ena.h:22
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

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

◆ fetch_ipv4_array_setting()

int fetch_ipv4_array_setting ( struct settings settings,
const struct setting setting,
struct in_addr inp,
unsigned int  count 
)

Fetch value of IPv4 address setting.

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

Definition at line 890 of file settings.c.

892  {
893  int len;
894 
896  ( sizeof ( *inp ) * count ) );
897  if ( len < 0 )
898  return len;
899  if ( ( len % sizeof ( *inp ) ) != 0 )
900  return -ERANGE;
901  return len;
902 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
#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 912 of file settings.c.

914  {
915 
916  return fetch_ipv4_array_setting ( settings, setting, inp, 1 );
917 }
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
int fetch_ipv4_array_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp, unsigned int count)
Fetch value of IPv4 address setting.
Definition: settings.c:890

References fetch_ipv4_array_setting().

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

◆ fetch_ipv6_array_setting()

int fetch_ipv6_array_setting ( struct settings settings,
const struct setting setting,
struct in6_addr inp,
unsigned int  count 
)

Fetch value of IPv6 address setting.

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

Definition at line 928 of file settings.c.

930  {
931  int len;
932 
934  ( sizeof ( *inp ) * count ) );
935  if ( len < 0 )
936  return len;
937  if ( ( len % sizeof ( *inp ) ) != 0 )
938  return -ERANGE;
939  return len;
940 }
int fetch_raw_setting(struct settings *settings, const struct setting *setting, void *data, size_t len)
Fetch value of setting.
Definition: settings.c:803
#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 950 of file settings.c.

952  {
953 
954  return fetch_ipv6_array_setting ( settings, setting, inp, 1 );
955 }
int fetch_ipv6_array_setting(struct settings *settings, const struct setting *setting, struct in6_addr *inp, unsigned int count)
Fetch value of IPv6 address setting.
Definition: settings.c:928
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23

References fetch_ipv6_array_setting().

Referenced by apply_syslog_settings().

◆ fetch_int_setting()

int fetch_int_setting ( struct settings settings,
const struct setting setting,
long *  value 
)

Fetch value of signed integer setting.

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

Definition at line 1023 of file settings.c.

1025  {
1026 
1028  ( ( unsigned long * ) value ), 1 );
1029 }
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
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 1039 of file settings.c.

1041  {
1042 
1043  return fetch_numeric_setting ( settings, setting, value, 0 );
1044 }
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
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 1053 of file settings.c.

1054  {
1055  unsigned long value;
1056 
1058  return value;
1059 }
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
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 1068 of file settings.c.

1069  {
1070  unsigned long value;
1071 
1073  return value;
1074 }
int fetch_numeric_setting(struct settings *settings, const struct setting *setting, unsigned long *value, int is_signed)
Fetch value of numeric setting.
Definition: settings.c:997
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 1084 of file settings.c.

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

References ERANGE, fetch_raw_setting(), and len.

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

◆ clear_settings()

void clear_settings ( struct settings settings)

Clear settings block.

Parameters
settingsSettings block

Definition at line 1102 of file settings.c.

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

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

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

◆ setting_cmp()

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

Compare two settings.

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

Definition at line 1120 of file settings.c.

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

References a, b, and strcmp().

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

◆ find_child_settings()

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

Find child settings block.

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

Definition at line 279 of file settings.c.

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

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

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

◆ autovivify_child_settings()

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

Find or create child settings block.

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

Definition at line 306 of file settings.c.

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

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

Referenced by nslookup_resolv_done(), 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
unsigned long tmp
Definition: linux_pci.h:53
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

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

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

◆ find_settings()

struct settings* find_settings ( const char *  name)

Find settings block.

Parameters
nameName
Return values
settingsSettings block, or NULL

Definition at line 406 of file settings.c.

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

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

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

◆ find_setting()

struct setting* find_setting ( const char *  name)

Find predefined setting.

Parameters
nameName
Return values
settingSetting, or NULL

Definition at line 1466 of file settings.c.

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

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

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

◆ parse_setting_name()

int parse_setting_name ( char *  name,
get_child_settings_t  get_child,
struct settings **  settings,
struct setting setting 
)

Parse setting name.

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

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

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

Definition at line 1528 of file settings.c.

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

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

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

◆ setting_name()

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

Return full setting name.

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

Definition at line 1606 of file settings.c.

1607  {
1608  const char *name;
1609 
1611  name = settings_name ( settings );
1612  return snprintf ( buf, len, "%s%s%s:%s", name, ( name[0] ? "/" : "" ),
1613  setting->name, setting->type->name );
1614 }
const char * name
Definition: ath9k_hw.c:1984
const char * settings_name(struct settings *settings)
Return settings block name.
Definition: settings.c:345
const char * name
Name.
Definition: settings.h:28
struct settings * settings_target(struct settings *settings)
Redirect to target settings block.
Definition: settings.c:549
const struct setting_type * type
Setting type.
Definition: settings.h:36
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
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 1151 of file settings.c.

1152  {
1153 
1154  /* Sanity check */
1155  if ( ! type->format )
1156  return -ENOTSUP;
1157 
1158  return type->format ( type, raw, raw_len, buf, len );
1159 }
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static size_t raw_len
Definition: base16.h:53
uint32_t len
Length.
Definition: ena.h:14
uint32_t type
Operating system type.
Definition: ena.h:12
__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 1170 of file settings.c.

1171  {
1172 
1173  /* Sanity check */
1174  if ( ! type->parse )
1175  return -ENOTSUP;
1176 
1177  return type->parse ( type, value, buf, len );
1178 }
#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
uint32_t type
Operating system type.
Definition: ena.h:12

References ENOTSUP, len, type, and value.

Referenced by guestinfo_fetch_type(), and storef_setting().

◆ setting_numerate()

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

Convert setting value to number.

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

Definition at line 1189 of file settings.c.

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

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

Referenced by fetchn_setting().

◆ setting_denumerate()

int setting_denumerate ( const struct setting_type type,
unsigned long  value,
void *  buf,
size_t  len 
)

Convert number to setting value.

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

Definition at line 1208 of file settings.c.

1209  {
1210 
1211  /* Sanity check */
1212  if ( ! type->denumerate )
1213  return -ENOTSUP;
1214 
1215  return type->denumerate ( type, value, buf, len );
1216 }
#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
uint32_t type
Operating system type.
Definition: ena.h:12

References ENOTSUP, len, type, and value.

Referenced by storen_setting().

◆ fetchf_setting()

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

Fetch formatted value of setting.

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

Definition at line 1229 of file settings.c.

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

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

Referenced by efi_snp_hii_fetch(), and fetchf_setting_copy().

◆ fetchf_setting_copy()

int fetchf_setting_copy ( struct settings settings,
const struct setting setting,
struct settings **  origin,
struct setting fetched,
char **  value 
)

Fetch copy of formatted value of setting.

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

The caller is responsible for eventually freeing the allocated buffer.

Definition at line 1276 of file settings.c.

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

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

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

◆ storef_setting()

int storef_setting ( struct settings settings,
const struct setting setting,
const char *  value 
)

Store formatted value of setting.

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

Definition at line 1319 of file settings.c.

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

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

Referenced by choose_exec(), efi_snp_hii_store(), login_ui(), 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 1372 of file settings.c.

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

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

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

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

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

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

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

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

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

◆ __setting() [1/29]

const struct setting ip_setting __setting ( SETTING_IP4  ,
ip   
)

◆ __setting() [2/29]

const struct setting netmask_setting __setting ( SETTING_IP4  ,
netmask   
)

◆ __setting() [3/29]

const struct setting gateway_setting __setting ( SETTING_IP4  ,
gateway   
)

◆ __setting() [4/29]

const struct setting dns_setting __setting ( SETTING_IP4_EXTRA  ,
dns   
)

◆ __setting() [5/29]

const struct setting ip6_setting __setting ( SETTING_IP6  ,
ip6   
)

◆ __setting() [6/29]

const struct setting len6_setting __setting ( SETTING_IP6  ,
len6   
)

◆ __setting() [7/29]

const struct setting gateway6_setting __setting ( SETTING_IP6  ,
gateway6   
)

◆ __setting() [8/29]

const struct setting dns6_setting __setting ( SETTING_IP6_EXTRA  ,
dns6   
)

◆ __setting() [9/29]

const struct setting hostname_setting __setting ( SETTING_HOST  ,
hostname   
)

◆ __setting() [10/29]

const struct setting domain_setting __setting ( SETTING_IP_EXTRA  ,
domain   
)

◆ __setting() [11/29]

const struct setting filename_setting __setting ( SETTING_BOOT  ,
filename   
)

◆ __setting() [12/29]

const struct setting root_path_setting __setting ( SETTING_SANBOOT  ,
root path 
)

◆ __setting() [13/29]

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

◆ __setting() [14/29]

const struct setting username_setting __setting ( SETTING_AUTH  ,
username   
)

◆ __setting() [15/29]

const struct setting password_setting __setting ( SETTING_AUTH  ,
password   
)

◆ __setting() [16/29]

const struct setting priority_setting __setting ( SETTING_MISC  ,
priority   
)

◆ __setting() [17/29]

const struct setting uuid_setting __setting ( SETTING_HOST  ,
uuid   
)

◆ __setting() [18/29]

const struct setting next_server_setting __setting ( SETTING_BOOT  ,
next server 
)

◆ __setting() [19/29]

const struct setting mac_setting __setting ( SETTING_NETDEV  ,
mac   
)

◆ __setting() [20/29]

const struct setting busid_setting __setting ( SETTING_NETDEV  ,
busid   
)

◆ __setting() [21/29]

const struct setting linktype_setting __setting ( SETTING_NETDEV  ,
linktype   
)

◆ __setting() [22/29]

const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA  ,
user class 
)

◆ __setting() [23/29]

const struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA  ,
vendor class 
)

◆ __setting() [24/29]

const struct setting manufacturer_setting __setting ( SETTING_HOST_EXTRA  ,
manufacturer   
)

◆ __setting() [25/29]

const struct setting product_setting __setting ( SETTING_HOST_EXTRA  ,
product   
)

◆ __setting() [26/29]

const struct setting serial_setting __setting ( SETTING_HOST_EXTRA  ,
serial   
)

◆ __setting() [27/29]

const struct setting asset_setting __setting ( SETTING_HOST_EXTRA  ,
asset   
)

◆ __setting() [28/29]

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

◆ __setting() [29/29]

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

503  {
506  settings->op = op;
508  settings->default_scope = default_scope;
509 }
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(), efi_path_net_probe(), generic_settings_init(), guestinfo_net_probe(), ipv6_register_settings(), lldp_probe(), ndp_register_settings(), nvo_init(), and phantom_probe().

◆ generic_settings_init()

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

Initialise a settings block.

Parameters
genericsGeneric settings block
refcntContaining object reference counter, or NULL

Definition at line 517 of file settings.h.

518  {
520  refcnt, NULL );
521  INIT_LIST_HEAD ( &generics->list );
522 }
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:500
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:321

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

532  {
533  return store_setting ( settings, setting, NULL, 0 );
534 }
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:615
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

544  {
545  return ( fetch_setting ( settings, setting, NULL, NULL,
546  NULL, 0 ) >= 0 );
547 }
int fetch_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
Fetch setting.
Definition: settings.c:666
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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 2505 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 1792 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.

GUID setting type.

UUID setting type.

A Base64-encoded setting.

A hex-string setting (non-delimited)

A hex-string setting (hyphen-delimited)

A hex-string setting (colon-delimited)

An unsigned 32-bit integer setting type.

An unsigned 16-bit integer setting type.

An unsigned 8-bit integer setting type.

A signed 32-bit integer setting type.

A signed 16-bit integer setting type.

A signed 8-bit integer setting type.

An IPv6 address setting type.

An IPv4 address setting type.

A URI-encoded string setting type.

A string setting type.

Definition at line 415 of file settings.h.