david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[Settings] DHCP is now working using the new settings API.

This commit is contained in:
Michael Brown 2008-03-21 22:55:59 +00:00
parent 8afb36c3bc
commit a462c96ffc
4 changed files with 29 additions and 18 deletions

View File

@ -91,13 +91,11 @@ int simple_settings_store ( struct settings *settings, unsigned int tag,
// Dummy routine just for testing // Dummy routine just for testing
int simple_settings_fetch ( struct settings *settings, unsigned int tag, int simple_settings_fetch ( struct settings *settings, unsigned int tag,
void *data, size_t len ) { void *data, size_t len ) {
unsigned int i; ( void ) settings;
( void ) tag;
DBGC ( settings, "Settings %p: fetch %s\n", ( void ) data;
settings, setting_tag_name ( tag ) ); ( void ) len;
for ( i = 0 ; i < len ; i++ ) return -ENOENT;
*( ( ( uint8_t * ) data ) + i ) = i;
return ( len ? len : 8 );
} }
/** Simple settings operations */ /** Simple settings operations */
@ -337,7 +335,7 @@ int fetch_setting ( struct settings *settings, unsigned int tag,
/* Recurse into each child block in turn */ /* Recurse into each child block in turn */
list_for_each_entry ( child, &settings->children, siblings ) { list_for_each_entry ( child, &settings->children, siblings ) {
if ( ( ret = fetch_setting ( settings, tag, data, len ) ) >= 0) if ( ( ret = fetch_setting ( child, tag, data, len ) ) >= 0)
return ret; return ret;
} }

View File

@ -180,26 +180,36 @@ static int resize_dhcp_option ( struct dhcp_options *options,
void *end; void *end;
/* Check for sufficient space, and update length fields */ /* Check for sufficient space, and update length fields */
if ( new_len > DHCP_MAX_LEN ) if ( new_len > DHCP_MAX_LEN ) {
DBGC ( options, "DHCPOPT %p overlength option\n", options );
return -ENOSPC; return -ENOSPC;
}
new_options_len = ( options->len + delta ); new_options_len = ( options->len + delta );
if ( new_options_len > options->max_len ) { if ( new_options_len > options->max_len ) {
/* Reallocate options block if allowed to do so. */ /* Reallocate options block if allowed to do so. */
if ( can_realloc ) { if ( can_realloc ) {
new_data = realloc ( options->data, new_options_len ); new_data = realloc ( options->data, new_options_len );
if ( ! new_data ) if ( ! new_data ) {
DBGC ( options, "DHCPOPT %p could not "
"reallocate to %zd bytes\n", options,
new_options_len );
return -ENOMEM; return -ENOMEM;
}
options->data = new_data; options->data = new_data;
options->max_len = new_options_len; options->max_len = new_options_len;
} else { } else {
DBGC ( options, "DHCPOPT %p out of space\n", options );
return -ENOMEM; return -ENOMEM;
} }
} }
if ( encap_offset >= 0 ) { if ( encap_offset >= 0 ) {
encapsulator = dhcp_option ( options, encap_offset ); encapsulator = dhcp_option ( options, encap_offset );
new_encapsulator_len = ( encapsulator->len + delta ); new_encapsulator_len = ( encapsulator->len + delta );
if ( new_encapsulator_len > DHCP_MAX_LEN ) if ( new_encapsulator_len > DHCP_MAX_LEN ) {
DBGC ( options, "DHCPOPT %p overlength encapsulator\n",
options );
return -ENOSPC; return -ENOSPC;
}
encapsulator->len = new_encapsulator_len; encapsulator->len = new_encapsulator_len;
} }
options->len = new_options_len; options->len = new_options_len;
@ -253,7 +263,7 @@ static int set_dhcp_option ( struct dhcp_options *options, unsigned int tag,
options, dhcp_tag_name ( tag ), old_len, new_len ); options, dhcp_tag_name ( tag ), old_len, new_len );
} else { } else {
DBGC ( options, "DHCPOPT %p creating %s (length %zd)\n", DBGC ( options, "DHCPOPT %p creating %s (length %zd)\n",
options, dhcp_tag_name ( tag ), len ); options, dhcp_tag_name ( tag ), new_len );
} }
/* Ensure that encapsulator exists, if required */ /* Ensure that encapsulator exists, if required */
@ -353,7 +363,7 @@ int dhcpopt_fetch ( struct dhcp_options *options, unsigned int tag,
return offset; return offset;
option = dhcp_option ( options, offset ); option = dhcp_option ( options, offset );
option_len = dhcp_option_len ( option ); option_len = option->len;
if ( len > option_len ) if ( len > option_len )
len = option_len; len = option_len;
memcpy ( data, option->data, len ); memcpy ( data, option->data, len );

View File

@ -1649,8 +1649,10 @@ static int apply_iscsi_string_setting ( struct iscsi_string_setting *setting ){
/* Allocate new string */ /* Allocate new string */
prefix_len = strlen ( setting->prefix ); prefix_len = strlen ( setting->prefix );
setting_len = fetch_setting_len ( NULL, setting->tag ); setting_len = fetch_setting_len ( NULL, setting->tag );
if ( setting_len < 0 ) if ( setting_len < 0 ) {
return setting_len; /* Missing settings are not errors; leave strings as NULL */
return 0;
}
len = ( prefix_len + setting_len + 1 ); len = ( prefix_len + setting_len + 1 );
p = *setting->string = malloc ( len ); p = *setting->string = malloc ( len );
if ( ! p ) if ( ! p )

View File

@ -175,7 +175,7 @@ static int create_dhcp_packet ( struct dhcp_packet *dhcppkt,
} }
dhcphdr->hlen = hlen; dhcphdr->hlen = hlen;
memcpy ( dhcphdr->chaddr, netdev->ll_addr, hlen ); memcpy ( dhcphdr->chaddr, netdev->ll_addr, hlen );
memcpy ( dhcphdr->options, options, options_len ); memcpy ( dhcphdr->options, options->data, options_len );
/* Initialise DHCP packet structure and settings interface */ /* Initialise DHCP packet structure and settings interface */
dhcppkt_init ( dhcppkt, NULL, data, max_len ); dhcppkt_init ( dhcppkt, NULL, data, max_len );
@ -258,9 +258,10 @@ int create_dhcp_request ( struct dhcp_packet *dhcppkt,
"option: %s\n", strerror ( rc ) ); "option: %s\n", strerror ( rc ) );
return rc; return rc;
} }
if ( ( rc = copy_setting ( &dhcppkt->settings, DHCP_EB_YIADDR, if ( ( rc = copy_setting ( &dhcppkt->settings,
DHCP_REQUESTED_ADDRESS,
offer_settings, offer_settings,
DHCP_REQUESTED_ADDRESS ) ) != 0 ) { DHCP_EB_YIADDR ) ) != 0 ) {
DBG ( "DHCP could not set requested address " DBG ( "DHCP could not set requested address "
"option: %s\n", strerror ( rc ) ); "option: %s\n", strerror ( rc ) );
return rc; return rc;