mirror of
https://github.com/xcat2/xNBA.git
synced 2024-12-14 07:11:32 +00:00
Tied NVO commands into the human-interactable settings code that I
completely forgot I'd written ages ago.
This commit is contained in:
parent
6842dd3222
commit
d041d74054
@ -6,20 +6,37 @@
|
||||
#include <command.h>
|
||||
#include <gpxe/nvo.h>
|
||||
#include <gpxe/dhcp.h>
|
||||
#include <gpxe/settings.h>
|
||||
|
||||
void nvo_cmd_req() {}
|
||||
|
||||
extern struct nvo_block *ugly_nvo_hack;
|
||||
|
||||
static int show_exec ( int argc, char **argv ) {
|
||||
struct config_context dummy_context;
|
||||
char buf[256];
|
||||
int rc;
|
||||
|
||||
if ( ! ugly_nvo_hack ) {
|
||||
printf ( "No non-volatile option storage available\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
hex_dump ( ugly_nvo_hack->options->data,
|
||||
ugly_nvo_hack->options->len );
|
||||
if ( argc != 2 ) {
|
||||
printf ( "Syntax: %s <identifier>\n", argv[0] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
dummy_context.options = ugly_nvo_hack->options;
|
||||
if ( ( rc = show_setting ( &dummy_context, argv[1], buf,
|
||||
sizeof ( buf ) ) ) != 0 ) {
|
||||
printf ( "Could not find \"%s\": %s\n",
|
||||
argv[1], strerror ( -rc ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf ( "%s = %s\n", argv[1], buf );
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct command show_command __command = {
|
||||
@ -30,8 +47,8 @@ struct command show_command __command = {
|
||||
};
|
||||
|
||||
static int set_exec ( int argc, char **argv ) {
|
||||
unsigned long tag;
|
||||
struct dhcp_option *option;
|
||||
struct config_context dummy_context;
|
||||
int rc;
|
||||
|
||||
if ( ! ugly_nvo_hack ) {
|
||||
printf ( "No non-volatile option storage available\n" );
|
||||
@ -39,19 +56,18 @@ static int set_exec ( int argc, char **argv ) {
|
||||
}
|
||||
|
||||
if ( argc != 3 ) {
|
||||
printf ( "Syntax: %s <option number> <option string>\n",
|
||||
printf ( "Syntax: %s <identifier> <value>\n",
|
||||
argv[0] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
tag = strtoul ( argv[1], NULL, 0 );
|
||||
option = set_dhcp_option ( ugly_nvo_hack->options, tag, argv[2],
|
||||
strlen ( argv[2] ) );
|
||||
if ( ! option ) {
|
||||
printf ( "Could not set option %ld\n", tag );
|
||||
dummy_context.options = ugly_nvo_hack->options;
|
||||
if ( ( rc = set_setting ( &dummy_context, argv[1], argv[2] ) ) != 0 ) {
|
||||
printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
||||
argv[1], argv[2], strerror ( -rc ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if ( nvo_save ( ugly_nvo_hack ) != 0 ) {
|
||||
printf ( "Could not save options to non-volatile storage\n" );
|
||||
return 1;
|
||||
|
@ -122,8 +122,8 @@ find_or_build_config_setting ( const char *name,
|
||||
* @v len Length of buffer
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int ( show_setting ) ( struct config_context *context, const char *name,
|
||||
char *buf, size_t len ) {
|
||||
int show_setting ( struct config_context *context, const char *name,
|
||||
char *buf, size_t len ) {
|
||||
struct config_setting *setting;
|
||||
struct config_setting tmp_setting;
|
||||
|
||||
@ -140,8 +140,8 @@ int ( show_setting ) ( struct config_context *context, const char *name,
|
||||
* @v value Setting value (as a string)
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int ( set_setting ) ( struct config_context *context, const char *name,
|
||||
const char *value ) {
|
||||
int set_setting ( struct config_context *context, const char *name,
|
||||
const char *value ) {
|
||||
struct config_setting *setting;
|
||||
struct config_setting tmp_setting;
|
||||
|
||||
@ -167,7 +167,7 @@ static int show_string ( struct config_context *context,
|
||||
|
||||
option = find_dhcp_option ( context->options, setting->tag );
|
||||
if ( ! option )
|
||||
return -ENOENT;
|
||||
return -ENODATA;
|
||||
dhcp_snprintf ( buf, len, option );
|
||||
return 0;
|
||||
}
|
||||
@ -215,7 +215,7 @@ static int show_ipv4 ( struct config_context *context,
|
||||
|
||||
option = find_dhcp_option ( context->options, setting->tag );
|
||||
if ( ! option )
|
||||
return -ENOENT;
|
||||
return -ENODATA;
|
||||
dhcp_ipv4_option ( option, &ipv4 );
|
||||
snprintf ( buf, len, inet_ntoa ( ipv4 ) );
|
||||
return 0;
|
||||
@ -252,35 +252,23 @@ struct config_setting_type config_setting_type_ipv4 __config_setting_type = {
|
||||
};
|
||||
|
||||
/** Some basic setting definitions */
|
||||
struct config_setting basic_config_settings[] __config_setting = {
|
||||
{
|
||||
.name = "hostname",
|
||||
.tag = DHCP_HOST_NAME,
|
||||
.type = &config_setting_type_string,
|
||||
},
|
||||
{
|
||||
.name = "ip",
|
||||
.tag = DHCP_EB_YIADDR,
|
||||
.type = &config_setting_type_ipv4,
|
||||
},
|
||||
struct config_setting ip_config_setting __config_setting = {
|
||||
.name = "ip",
|
||||
.tag = DHCP_EB_YIADDR,
|
||||
.type = &config_setting_type_ipv4,
|
||||
};
|
||||
struct config_setting hostname_config_setting __config_setting = {
|
||||
.name = "hostname",
|
||||
.tag = DHCP_HOST_NAME,
|
||||
.type = &config_setting_type_string,
|
||||
};
|
||||
struct config_setting username_config_setting __config_setting = {
|
||||
.name = "username",
|
||||
.tag = DHCP_EB_USERNAME,
|
||||
.type = &config_setting_type_string,
|
||||
};
|
||||
struct config_setting password_config_setting __config_setting = {
|
||||
.name = "password",
|
||||
.tag = DHCP_EB_PASSWORD,
|
||||
.type = &config_setting_type_string,
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* Quick and dirty proof of concept */
|
||||
int cmdl_show ( int argc, char **argv ) {
|
||||
char buf[256];
|
||||
struct config_context dummy_context = { NULL };
|
||||
int rc;
|
||||
|
||||
if ( argc < 2 )
|
||||
return -EINVAL;
|
||||
|
||||
if ( ( rc = show_setting ( &dummy_context, argv[1],
|
||||
buf, sizeof ( buf ) ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
printf ( "%s = %s\n", argv[1], buf );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -98,9 +98,9 @@ struct config_setting {
|
||||
|
||||
/* Function prototypes */
|
||||
|
||||
extern int ( show_setting ) ( struct config_context *context, const char *name,
|
||||
char *buf, size_t len );
|
||||
extern int ( set_setting ) ( struct config_context *context, const char *name,
|
||||
const char *value );
|
||||
extern int show_setting ( struct config_context *context, const char *name,
|
||||
char *buf, size_t len );
|
||||
extern int set_setting ( struct config_context *context, const char *name,
|
||||
const char *value );
|
||||
|
||||
#endif /* _GPXE_SETTINGS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user