[Settings] Introduce settings applicators.
Convert DHCP option applicators in dns.c and iscsi.c to settings applicators. Kill off DHCP option applicators.
This commit is contained in:
@@ -37,12 +37,6 @@
|
||||
/** List of registered DHCP option blocks */
|
||||
LIST_HEAD ( dhcp_option_blocks );
|
||||
|
||||
/** Registered DHCP option applicators */
|
||||
static struct dhcp_option_applicator dhcp_option_applicators[0]
|
||||
__table_start ( struct dhcp_option_applicator, dhcp_applicators );
|
||||
static struct dhcp_option_applicator dhcp_option_applicators_end[0]
|
||||
__table_end ( struct dhcp_option_applicator, dhcp_applicators );
|
||||
|
||||
/**
|
||||
* Obtain printable version of a DHCP option tag
|
||||
*
|
||||
@@ -578,13 +572,9 @@ void delete_dhcp_option ( struct dhcp_option_block *options,
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int apply_dhcp_options ( struct dhcp_option_block *options ) {
|
||||
struct dhcp_option_applicator *applicator;
|
||||
struct dhcp_option *option;
|
||||
struct in_addr tftp_server;
|
||||
struct uri *uri;
|
||||
char uri_string[32];
|
||||
unsigned int tag;
|
||||
int rc;
|
||||
|
||||
/* Set current working URI based on TFTP server */
|
||||
find_dhcp_ipv4_option ( options, DHCP_EB_SIADDR, &tftp_server );
|
||||
@@ -596,20 +586,6 @@ int apply_dhcp_options ( struct dhcp_option_block *options ) {
|
||||
churi ( uri );
|
||||
uri_put ( uri );
|
||||
|
||||
/* Call all registered DHCP option applicators */
|
||||
for ( applicator = dhcp_option_applicators ;
|
||||
applicator < dhcp_option_applicators_end ; applicator++ ) {
|
||||
tag = applicator->tag;
|
||||
option = find_dhcp_option ( options, tag );
|
||||
if ( ! option )
|
||||
continue;
|
||||
if ( ( rc = applicator->apply ( tag, option ) ) != 0 ) {
|
||||
DBG ( "Could not apply DHCP option %s: %s\n",
|
||||
dhcp_tag_name ( tag ), strerror ( rc ) );
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+85
-56
@@ -31,7 +31,7 @@
|
||||
#include <gpxe/process.h>
|
||||
#include <gpxe/uaccess.h>
|
||||
#include <gpxe/tcpip.h>
|
||||
#include <gpxe/dhcp.h>
|
||||
#include <gpxe/settings.h>
|
||||
#include <gpxe/features.h>
|
||||
#include <gpxe/iscsi.h>
|
||||
|
||||
@@ -1591,80 +1591,109 @@ int iscsi_attach ( struct scsi_device *scsi, const char *root_path ) {
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* DHCP option applicators
|
||||
* Settings applicators
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Apply DHCP iSCSI option
|
||||
*
|
||||
* @v tag DHCP option tag
|
||||
* @v option DHCP option
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int apply_dhcp_iscsi_string ( unsigned int tag,
|
||||
struct dhcp_option *option ) {
|
||||
char *prefix = "";
|
||||
size_t prefix_len;
|
||||
size_t len;
|
||||
/** An iSCSI string setting */
|
||||
struct iscsi_string_setting {
|
||||
/** Setting tag number */
|
||||
unsigned int tag;
|
||||
/** String to update */
|
||||
char **string;
|
||||
char *p;
|
||||
/** String prefix */
|
||||
const char *prefix;
|
||||
};
|
||||
|
||||
/* Identify string and prefix */
|
||||
switch ( tag ) {
|
||||
case DHCP_ISCSI_INITIATOR_IQN:
|
||||
string = &iscsi_explicit_initiator_iqn;
|
||||
break;
|
||||
case DHCP_EB_USERNAME:
|
||||
string = &iscsi_username;
|
||||
break;
|
||||
case DHCP_EB_PASSWORD:
|
||||
string = &iscsi_password;
|
||||
break;
|
||||
case DHCP_HOST_NAME:
|
||||
string = &iscsi_default_initiator_iqn;
|
||||
prefix = "iqn.2000-09.org.etherboot:";
|
||||
break;
|
||||
default:
|
||||
assert ( 0 );
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Free old string */
|
||||
free ( *string );
|
||||
*string = NULL;
|
||||
|
||||
/* Allocate and fill new string */
|
||||
prefix_len = strlen ( prefix );
|
||||
len = ( prefix_len + option->len + 1 );
|
||||
p = *string = malloc ( len );
|
||||
if ( ! p )
|
||||
return -ENOMEM;
|
||||
strcpy ( p, prefix );
|
||||
dhcp_snprintf ( ( p + prefix_len ), ( len - prefix_len ), option );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** DHCP iSCSI option applicators */
|
||||
struct dhcp_option_applicator dhcp_iscsi_applicators[] __dhcp_applicator = {
|
||||
/** iSCSI string settings */
|
||||
static struct iscsi_string_setting iscsi_string_settings[] = {
|
||||
{
|
||||
.tag = DHCP_ISCSI_INITIATOR_IQN,
|
||||
.apply = apply_dhcp_iscsi_string,
|
||||
.string = &iscsi_explicit_initiator_iqn,
|
||||
.prefix = "",
|
||||
},
|
||||
{
|
||||
.tag = DHCP_EB_USERNAME,
|
||||
.apply = apply_dhcp_iscsi_string,
|
||||
.string = &iscsi_username,
|
||||
.prefix = "",
|
||||
},
|
||||
{
|
||||
.tag = DHCP_EB_PASSWORD,
|
||||
.apply = apply_dhcp_iscsi_string,
|
||||
.string = &iscsi_password,
|
||||
.prefix = "",
|
||||
},
|
||||
{
|
||||
.tag = DHCP_HOST_NAME,
|
||||
.apply = apply_dhcp_iscsi_string,
|
||||
.string = &iscsi_default_initiator_iqn,
|
||||
.prefix = "iqn.2000-09.org.etherboot:",
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply iSCSI setting
|
||||
*
|
||||
* @v setting iSCSI string setting
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int apply_iscsi_string_setting ( struct iscsi_string_setting *setting ){
|
||||
size_t prefix_len;
|
||||
int setting_len;
|
||||
size_t len;
|
||||
int check_len;
|
||||
char *p;
|
||||
|
||||
/* Free old string */
|
||||
free ( *setting->string );
|
||||
*setting->string = NULL;
|
||||
|
||||
/* Allocate new string */
|
||||
prefix_len = strlen ( setting->prefix );
|
||||
setting_len = fetch_setting_len ( NULL, setting->tag );
|
||||
if ( setting_len < 0 )
|
||||
return setting_len;
|
||||
len = ( prefix_len + setting_len + 1 );
|
||||
p = *setting->string = malloc ( len );
|
||||
if ( ! p )
|
||||
return -ENOMEM;
|
||||
|
||||
/* Fill new string */
|
||||
strcpy ( p, setting->prefix );
|
||||
check_len = fetch_string_setting ( NULL, setting->tag,
|
||||
( p + prefix_len ),
|
||||
( len - prefix_len ) );
|
||||
assert ( check_len == setting_len );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply iSCSI settings
|
||||
*
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int apply_iscsi_settings ( void ) {
|
||||
struct iscsi_string_setting *setting;
|
||||
unsigned int i;
|
||||
int rc;
|
||||
|
||||
for ( i = 0 ; i < ( sizeof ( iscsi_string_settings ) /
|
||||
sizeof ( iscsi_string_settings[0] ) ) ; i++ ) {
|
||||
setting = &iscsi_string_settings[i];
|
||||
if ( ( rc = apply_iscsi_string_setting ( setting ) ) != 0 ) {
|
||||
DBG ( "iSCSI could not apply setting %d\n",
|
||||
setting->tag );
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** iSCSI settings applicator */
|
||||
struct settings_applicator iscsi_settings_applicator __settings_applicator = {
|
||||
.apply = apply_iscsi_settings,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
*
|
||||
* Initiator name
|
||||
|
||||
+16
-17
@@ -30,7 +30,7 @@
|
||||
#include <gpxe/resolv.h>
|
||||
#include <gpxe/retry.h>
|
||||
#include <gpxe/tcpip.h>
|
||||
#include <gpxe/dhcp.h>
|
||||
#include <gpxe/settings.h>
|
||||
#include <gpxe/features.h>
|
||||
#include <gpxe/dns.h>
|
||||
|
||||
@@ -507,27 +507,26 @@ struct resolver dns_resolver __resolver ( RESOLV_NORMAL ) = {
|
||||
};
|
||||
|
||||
/**
|
||||
* Apply DHCP nameserver option
|
||||
* Apply nameserver setting
|
||||
*
|
||||
* @v tag DHCP option tag
|
||||
* @v option DHCP option
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int apply_dhcp_nameserver ( unsigned int tag __unused,
|
||||
struct dhcp_option *option ) {
|
||||
struct sockaddr_in *sin_nameserver;
|
||||
static int apply_nameserver_setting ( void ) {
|
||||
struct sockaddr_in *sin_nameserver =
|
||||
( struct sockaddr_in * ) &nameserver;
|
||||
int len;
|
||||
|
||||
sin_nameserver = ( struct sockaddr_in * ) &nameserver;
|
||||
sin_nameserver->sin_family = AF_INET;
|
||||
dhcp_ipv4_option ( option, &sin_nameserver->sin_addr );
|
||||
|
||||
DBG ( "DNS using nameserver %s\n",
|
||||
inet_ntoa ( sin_nameserver->sin_addr ) );
|
||||
if ( ( len = fetch_ipv4_setting ( NULL, DHCP_DNS_SERVERS,
|
||||
&sin_nameserver->sin_addr ) ) >= 0 ){
|
||||
sin_nameserver->sin_family = AF_INET;
|
||||
DBG ( "DNS using nameserver %s\n",
|
||||
inet_ntoa ( sin_nameserver->sin_addr ) );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** DHCP nameserver applicator */
|
||||
struct dhcp_option_applicator dhcp_nameserver_applicator __dhcp_applicator = {
|
||||
.tag = DHCP_DNS_SERVERS,
|
||||
.apply = apply_dhcp_nameserver,
|
||||
/** Nameserver setting applicator */
|
||||
struct settings_applicator nameserver_applicator __settings_applicator = {
|
||||
.apply = apply_nameserver_setting,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user