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