diff options
author | Michael Brown | 2008-03-21 01:49:44 +0100 |
---|---|---|
committer | Michael Brown | 2008-03-21 01:49:44 +0100 |
commit | a9b62cfe8c280a56da7c35faa58b5b2328da2cdd (patch) | |
tree | 13735edfda245c3947f87bed738a3a69639d40e9 /src/core | |
parent | [Settings] Use a settings applicator to set the default TFTP URI. (diff) | |
download | ipxe-a9b62cfe8c280a56da7c35faa58b5b2328da2cdd.tar.gz ipxe-a9b62cfe8c280a56da7c35faa58b5b2328da2cdd.tar.xz ipxe-a9b62cfe8c280a56da7c35faa58b5b2328da2cdd.zip |
[Settings] Use a settings applicator in ibft.c
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/ibft.c | 77 |
1 files changed, 46 insertions, 31 deletions
diff --git a/src/core/ibft.c b/src/core/ibft.c index 5f033672..61e00a8d 100644 --- a/src/core/ibft.c +++ b/src/core/ibft.c @@ -130,37 +130,29 @@ static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) { */ static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr, unsigned int tag ) { - struct in_addr in; - find_global_dhcp_ipv4_option ( tag, &in ); + struct in_addr in = { 0 }; + fetch_ipv4_setting ( NULL, tag, &in ); ibft_set_ipaddr ( ipaddr, in ); } /** - * Fill in a string field within iBFT + * Allocate a string within iBFT * * @v strings iBFT string block descriptor - * @v string String field - * @v data String to fill in - * @v len Length of string to fill in + * @v string String field to fill in + * @v len Length of string to allocate (excluding NUL) * @ret rc Return status code */ -static int ibft_set_string ( struct ibft_string_block *strings, - struct ibft_string *string, - const void *data, size_t len ) { +static int ibft_alloc_string ( struct ibft_string_block *strings, + struct ibft_string *string, size_t len ) { char *dest; - char *end; unsigned int remaining; dest = ( ( ( char * ) strings->table ) + strings->offset ); - end = ( ( ( char * ) strings->table ) + strings->table->acpi.length ); - remaining = ( end - dest ); - + remaining = ( strings->table->acpi.length - strings->offset ); if ( len >= remaining ) return -ENOMEM; - memcpy ( dest, data, len ); - dest[len] = '\0'; - string->offset = strings->offset; string->length = len; strings->offset += ( len + 1 ); @@ -168,6 +160,28 @@ static int ibft_set_string ( struct ibft_string_block *strings, } /** + * Fill in a string field within iBFT + * + * @v strings iBFT string block descriptor + * @v string String field + * @v data String to fill in + * @ret rc Return status code + */ +static int ibft_set_string ( struct ibft_string_block *strings, + struct ibft_string *string, const char *data ) { + size_t len = strlen ( data ); + char *dest; + int rc; + + if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 ) + return rc; + dest = ( ( ( char * ) strings->table ) + string->offset ); + strcpy ( dest, data ); + + return 0; +} + +/** * Fill in a string field within iBFT from DHCP option * * @v strings iBFT string block descriptor @@ -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, struct ibft_string *string, unsigned int tag ) { - struct dhcp_option *option; + int len; + char *dest; + int rc; - option = find_global_dhcp_option ( tag ); - if ( ! option ) { + len = fetch_setting_len ( NULL, tag ); + if ( len < 0 ) { string->offset = 0; string->length = 0; return 0; } - return ibft_set_string ( strings, string, option->data.string, - option->len ); + if ( ( rc = ibft_alloc_string ( strings, string, len ) ) != 0 ) + 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, struct ibft_string_block *strings, struct net_device *netdev ) { - struct in_addr netmask_addr; + struct in_addr netmask_addr = { 0 }; unsigned int netmask_count = 0; int rc; @@ -215,7 +234,7 @@ static int ibft_fill_nic ( struct ibft_nic *nic, return rc; /* 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 ) { if ( netmask_addr.s_addr & 0x1 ) netmask_count++; @@ -244,8 +263,7 @@ static int ibft_fill_initiator ( struct ibft_initiator *initiator, int rc; if ( ( rc = ibft_set_string ( strings, &initiator->initiator_name, - initiator_iqn, - strlen ( initiator_iqn ) ) ) != 0) + initiator_iqn ) ) != 0 ) return rc; 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 ); target->socket = ntohs ( sin_target->sin_port ); if ( ( rc = ibft_set_string ( strings, &target->target_name, - iscsi->target_iqn, - strlen ( iscsi->target_iqn ) ) ) != 0 ) + iscsi->target_iqn ) ) != 0 ) return rc; if ( iscsi->username ) { if ( ( rc = ibft_set_string ( strings, &target->chap_name, - iscsi->username, - strlen ( iscsi->username ) ))!=0) + iscsi->username ) ) != 0 ) return rc; } if ( iscsi->password ) { if ( ( rc = ibft_set_string ( strings, &target->chap_secret, - iscsi->password, - strlen ( iscsi->password ) ))!=0) + iscsi->password ) ) != 0 ) return rc; target->chap_type = IBFT_CHAP_ONE_WAY; } |