2006-08-11 20:00:22 +02:00
|
|
|
#ifndef _GPXE_SETTINGS_H
|
|
|
|
#define _GPXE_SETTINGS_H
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* Configuration settings
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <gpxe/dhcp.h>
|
|
|
|
#include <gpxe/tables.h>
|
|
|
|
|
|
|
|
struct config_setting;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A configuration context
|
|
|
|
*
|
|
|
|
* This identifies the context within which settings are inspected and
|
|
|
|
* changed. For example, the context might be global, or might be
|
|
|
|
* restricted to the settings stored in NVS on a particular device.
|
|
|
|
*/
|
|
|
|
struct config_context {
|
|
|
|
/** DHCP options block, or NULL
|
|
|
|
*
|
|
|
|
* If NULL, all registered DHCP options blocks will be used.
|
|
|
|
*/
|
|
|
|
struct dhcp_option_block *options;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A configuration setting type
|
|
|
|
*
|
|
|
|
* This represents a type of configuration setting (e.g. string, IPv4
|
|
|
|
* address, etc.).
|
|
|
|
*/
|
|
|
|
struct config_setting_type {
|
|
|
|
/** Name
|
|
|
|
*
|
|
|
|
* This is the name exposed to the user (e.g. "string").
|
|
|
|
*/
|
|
|
|
const char *name;
|
2006-12-20 05:58:26 +01:00
|
|
|
/** Description */
|
|
|
|
const char *description;
|
2006-08-11 20:00:22 +02:00
|
|
|
/** Show value of setting
|
|
|
|
*
|
|
|
|
* @v context Configuration context
|
|
|
|
* @v setting Configuration setting
|
2006-08-11 20:16:57 +02:00
|
|
|
* @v buf Buffer to contain value
|
|
|
|
* @v len Length of buffer
|
|
|
|
* @ret rc Return status code
|
2006-08-11 20:00:22 +02:00
|
|
|
*/
|
2006-08-11 20:16:57 +02:00
|
|
|
int ( * show ) ( struct config_context *context,
|
|
|
|
struct config_setting *setting,
|
|
|
|
char *buf, size_t len );
|
2006-08-11 20:00:22 +02:00
|
|
|
/** Set value of setting
|
|
|
|
*
|
|
|
|
* @v context Configuration context
|
|
|
|
* @v setting Configuration setting
|
|
|
|
* @v value Setting value (as a string)
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
int ( * set ) ( struct config_context *context,
|
|
|
|
struct config_setting *setting,
|
|
|
|
const char *value );
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Declare a configuration setting type */
|
2007-01-10 05:22:09 +01:00
|
|
|
#define __config_setting_type \
|
|
|
|
__table ( struct config_setting_type, config_setting_types, 01 )
|
2006-08-11 20:00:22 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A configuration setting
|
|
|
|
*
|
|
|
|
* This represents a single configuration setting (e.g. "hostname").
|
|
|
|
*/
|
|
|
|
struct config_setting {
|
|
|
|
/** Name
|
|
|
|
*
|
|
|
|
* This is the human-readable name for the setting. Where
|
|
|
|
* possible, it should match the name used in dhcpd.conf (see
|
|
|
|
* dhcp-options(5)).
|
|
|
|
*/
|
|
|
|
const char *name;
|
2006-12-20 05:58:26 +01:00
|
|
|
/** Description */
|
|
|
|
const char *description;
|
2006-08-11 20:00:22 +02:00
|
|
|
/** DHCP option tag
|
|
|
|
*
|
|
|
|
* This is the DHCP tag used to identify the option in DHCP
|
|
|
|
* packets and stored option blocks.
|
|
|
|
*/
|
|
|
|
unsigned int tag;
|
|
|
|
/** Configuration setting type
|
|
|
|
*
|
|
|
|
* This identifies the type of setting (e.g. string, IPv4
|
|
|
|
* address, etc.).
|
|
|
|
*/
|
|
|
|
struct config_setting_type *type;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Declare a configuration setting */
|
2007-01-10 05:22:09 +01:00
|
|
|
#define __config_setting __table ( struct config_setting, config_settings, 01 )
|
2006-08-11 20:00:22 +02:00
|
|
|
|
2006-12-20 05:20:13 +01:00
|
|
|
/**
|
|
|
|
* Show value of setting
|
|
|
|
*
|
|
|
|
* @v context Configuration context
|
|
|
|
* @v setting Configuration setting
|
|
|
|
* @v buf Buffer to contain value
|
|
|
|
* @v len Length of buffer
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static inline int show_setting ( struct config_context *context,
|
|
|
|
struct config_setting *setting,
|
|
|
|
char *buf, size_t len ) {
|
|
|
|
return setting->type->show ( context, setting, buf, len );
|
|
|
|
}
|
2006-08-11 20:00:22 +02:00
|
|
|
|
2006-12-20 05:20:13 +01:00
|
|
|
extern int set_setting ( struct config_context *context,
|
|
|
|
struct config_setting *setting,
|
2006-12-05 03:40:03 +01:00
|
|
|
const char *value );
|
2006-12-20 05:20:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear setting
|
|
|
|
*
|
|
|
|
* @v context Configuration context
|
|
|
|
* @v setting Configuration setting
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static inline int clear_setting ( struct config_context *context,
|
|
|
|
struct config_setting *setting ) {
|
|
|
|
delete_dhcp_option ( context->options, setting->tag );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Function prototypes */
|
|
|
|
extern int show_named_setting ( struct config_context *context,
|
|
|
|
const char *name, char *buf, size_t len );
|
|
|
|
extern int set_named_setting ( struct config_context *context,
|
|
|
|
const char *name, const char *value );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear named setting
|
|
|
|
*
|
|
|
|
* @v context Configuration context
|
|
|
|
* @v name Configuration setting name
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
static inline int clear_named_setting ( struct config_context *context,
|
|
|
|
const char *name ) {
|
|
|
|
return set_named_setting ( context, name, NULL );
|
|
|
|
}
|
2006-08-11 20:00:22 +02:00
|
|
|
|
|
|
|
#endif /* _GPXE_SETTINGS_H */
|