1 #ifndef _GPXE_SETTINGS_H
2 #define _GPXE_SETTINGS_H
6 * Configuration settings
11 #include <gpxe/dhcp.h>
12 #include <gpxe/tables.h>
14 struct config_setting;
17 * A configuration context
19 * This identifies the context within which settings are inspected and
20 * changed. For example, the context might be global, or might be
21 * restricted to the settings stored in NVS on a particular device.
23 struct config_context {
24 /** DHCP options block, or NULL
26 * If NULL, all registered DHCP options blocks will be used.
28 struct dhcp_option_block *options;
32 * A configuration setting type
34 * This represents a type of configuration setting (e.g. string, IPv4
37 struct config_setting_type {
40 * This is the name exposed to the user (e.g. "string").
44 const char *description;
45 /** Show value of setting
47 * @v context Configuration context
48 * @v setting Configuration setting
49 * @v buf Buffer to contain value
50 * @v len Length of buffer
51 * @ret rc Return status code
53 int ( * show ) ( struct config_context *context,
54 struct config_setting *setting,
55 char *buf, size_t len );
56 /** Set value of setting
58 * @v context Configuration context
59 * @v setting Configuration setting
60 * @v value Setting value (as a string)
61 * @ret rc Return status code
63 int ( * set ) ( struct config_context *context,
64 struct config_setting *setting,
68 /** Declare a configuration setting type */
69 #define __config_setting_type \
70 __table ( struct config_setting_type, config_setting_types, 01 )
73 * A configuration setting
75 * This represents a single configuration setting (e.g. "hostname").
77 struct config_setting {
80 * This is the human-readable name for the setting. Where
81 * possible, it should match the name used in dhcpd.conf (see
86 const char *description;
89 * This is the DHCP tag used to identify the option in DHCP
90 * packets and stored option blocks.
93 /** Configuration setting type
95 * This identifies the type of setting (e.g. string, IPv4
98 struct config_setting_type *type;
101 /** Declare a configuration setting */
102 #define __config_setting __table ( struct config_setting, config_settings, 01 )
105 * Show value of setting
107 * @v context Configuration context
108 * @v setting Configuration setting
109 * @v buf Buffer to contain value
110 * @v len Length of buffer
111 * @ret rc Return status code
113 static inline int show_setting ( struct config_context *context,
114 struct config_setting *setting,
115 char *buf, size_t len ) {
116 return setting->type->show ( context, setting, buf, len );
119 extern int set_setting ( struct config_context *context,
120 struct config_setting *setting,
126 * @v context Configuration context
127 * @v setting Configuration setting
128 * @ret rc Return status code
130 static inline int clear_setting ( struct config_context *context,
131 struct config_setting *setting ) {
132 delete_dhcp_option ( context->options, setting->tag );
136 /* Function prototypes */
137 extern int show_named_setting ( struct config_context *context,
138 const char *name, char *buf, size_t len );
139 extern int set_named_setting ( struct config_context *context,
140 const char *name, const char *value );
143 * Clear named setting
145 * @v context Configuration context
146 * @v name Configuration setting name
147 * @ret rc Return status code
149 static inline int clear_named_setting ( struct config_context *context,
151 return set_named_setting ( context, name, NULL );
154 #endif /* _GPXE_SETTINGS_H */