david/ipxe
Archived
1
0

[Settings] Use a settings applicator in ibft.c

This commit is contained in:
Michael Brown 2008-03-21 00:49:44 +00:00
parent 1edbcd4246
commit a9b62cfe8c

View File

@ -130,40 +130,54 @@ static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
*/ */
static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr, static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
unsigned int tag ) { unsigned int tag ) {
struct in_addr in; struct in_addr in = { 0 };
find_global_dhcp_ipv4_option ( tag, &in ); fetch_ipv4_setting ( NULL, tag, &in );
ibft_set_ipaddr ( ipaddr, in ); ibft_set_ipaddr ( ipaddr, in );
} }
/**
* Allocate a string within iBFT
*
* @v strings iBFT string block descriptor
* @v string String field to fill in
* @v len Length of string to allocate (excluding NUL)
* @ret rc Return status code
*/
static int ibft_alloc_string ( struct ibft_string_block *strings,
struct ibft_string *string, size_t len ) {
char *dest;
unsigned int remaining;
dest = ( ( ( char * ) strings->table ) + strings->offset );
remaining = ( strings->table->acpi.length - strings->offset );
if ( len >= remaining )
return -ENOMEM;
string->offset = strings->offset;
string->length = len;
strings->offset += ( len + 1 );
return 0;
}
/** /**
* Fill in a string field within iBFT * Fill in a string field within iBFT
* *
* @v strings iBFT string block descriptor * @v strings iBFT string block descriptor
* @v string String field * @v string String field
* @v data String to fill in * @v data String to fill in
* @v len Length of string to fill in
* @ret rc Return status code * @ret rc Return status code
*/ */
static int ibft_set_string ( struct ibft_string_block *strings, static int ibft_set_string ( struct ibft_string_block *strings,
struct ibft_string *string, struct ibft_string *string, const char *data ) {
const void *data, size_t len ) { size_t len = strlen ( data );
char *dest; char *dest;
char *end; int rc;
unsigned int remaining;
dest = ( ( ( char * ) strings->table ) + strings->offset ); if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 )
end = ( ( ( char * ) strings->table ) + strings->table->acpi.length ); return rc;
remaining = ( end - dest ); dest = ( ( ( char * ) strings->table ) + string->offset );
strcpy ( dest, data );
if ( len >= remaining )
return -ENOMEM;
memcpy ( dest, data, len );
dest[len] = '\0';
string->offset = strings->offset;
string->length = len;
strings->offset += ( len + 1 );
return 0; return 0;
} }
@ -178,17 +192,22 @@ static int ibft_set_string ( struct ibft_string_block *strings,
static int ibft_set_string_option ( struct ibft_string_block *strings, static int ibft_set_string_option ( struct ibft_string_block *strings,
struct ibft_string *string, struct ibft_string *string,
unsigned int tag ) { unsigned int tag ) {
struct dhcp_option *option; int len;
char *dest;
int rc;
option = find_global_dhcp_option ( tag ); len = fetch_setting_len ( NULL, tag );
if ( ! option ) { if ( len < 0 ) {
string->offset = 0; string->offset = 0;
string->length = 0; string->length = 0;
return 0; return 0;
} }
return ibft_set_string ( strings, string, option->data.string, if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 )
option->len ); return rc;
dest = ( ( ( char * ) strings->table ) + string->offset );
fetch_string_setting ( NULL, tag, dest, ( len + 1 ) );
return 0;
} }
/** /**
@ -202,7 +221,7 @@ static int ibft_set_string_option ( struct ibft_string_block *strings,
static int ibft_fill_nic ( struct ibft_nic *nic, static int ibft_fill_nic ( struct ibft_nic *nic,
struct ibft_string_block *strings, struct ibft_string_block *strings,
struct net_device *netdev ) { struct net_device *netdev ) {
struct in_addr netmask_addr; struct in_addr netmask_addr = { 0 };
unsigned int netmask_count = 0; unsigned int netmask_count = 0;
int rc; int rc;
@ -215,7 +234,7 @@ static int ibft_fill_nic ( struct ibft_nic *nic,
return rc; return rc;
/* Derive subnet mask prefix from subnet mask */ /* Derive subnet mask prefix from subnet mask */
find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask_addr ); fetch_ipv4_setting ( NULL, DHCP_SUBNET_MASK, &netmask_addr );
while ( netmask_addr.s_addr ) { while ( netmask_addr.s_addr ) {
if ( netmask_addr.s_addr & 0x1 ) if ( netmask_addr.s_addr & 0x1 )
netmask_count++; netmask_count++;
@ -244,8 +263,7 @@ static int ibft_fill_initiator ( struct ibft_initiator *initiator,
int rc; int rc;
if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name, if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name,
initiator_iqn, initiator_iqn ) ) != 0 )
strlen ( initiator_iqn ) ) ) != 0)
return rc; return rc;
return 0; return 0;
@ -270,19 +288,16 @@ static int ibft_fill_target ( struct ibft_target *target,
ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr ); ibft_set_ipaddr ( &target->ip_address, sin_target->sin_addr );
target->socket = ntohs ( sin_target->sin_port ); target->socket = ntohs ( sin_target->sin_port );
if ( ( rc = ibft_set_string ( strings, &target->target_name, if ( ( rc = ibft_set_string ( strings, &target->target_name,
iscsi->target_iqn, iscsi->target_iqn ) ) != 0 )
strlen ( iscsi->target_iqn ) ) ) != 0 )
return rc; return rc;
if ( iscsi->username ) { if ( iscsi->username ) {
if ( ( rc = ibft_set_string ( strings, &target->chap_name, if ( ( rc = ibft_set_string ( strings, &target->chap_name,
iscsi->username, iscsi->username ) ) != 0 )
strlen ( iscsi->username ) ))!=0)
return rc; return rc;
} }
if ( iscsi->password ) { if ( iscsi->password ) {
if ( ( rc = ibft_set_string ( strings, &target->chap_secret, if ( ( rc = ibft_set_string ( strings, &target->chap_secret,
iscsi->password, iscsi->password ) ) != 0 )
strlen ( iscsi->password ) ))!=0)
return rc; return rc;
target->chap_type = IBFT_CHAP_ONE_WAY; target->chap_type = IBFT_CHAP_ONE_WAY;
} }