// Dummy routine just for testing
int simple_settings_fetch ( struct settings *settings, unsigned int tag,
void *data, size_t len ) {
- unsigned int i;
-
- DBGC ( settings, "Settings %p: fetch %s\n",
- settings, setting_tag_name ( tag ) );
- for ( i = 0 ; i < len ; i++ )
- *( ( ( uint8_t * ) data ) + i ) = i;
- return ( len ? len : 8 );
+ ( void ) settings;
+ ( void ) tag;
+ ( void ) data;
+ ( void ) len;
+ return -ENOENT;
}
/** Simple settings operations */
/* Recurse into each child block in turn */
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;
}
void *end;
/* 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;
+ }
new_options_len = ( options->len + delta );
if ( new_options_len > options->max_len ) {
/* Reallocate options block if allowed to do so. */
if ( can_realloc ) {
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;
+ }
options->data = new_data;
options->max_len = new_options_len;
} else {
+ DBGC ( options, "DHCPOPT %p out of space\n", options );
return -ENOMEM;
}
}
if ( encap_offset >= 0 ) {
encapsulator = dhcp_option ( options, encap_offset );
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;
+ }
encapsulator->len = new_encapsulator_len;
}
options->len = new_options_len;
options, dhcp_tag_name ( tag ), old_len, new_len );
} else {
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 */
return offset;
option = dhcp_option ( options, offset );
- option_len = dhcp_option_len ( option );
+ option_len = option->len;
if ( len > option_len )
len = option_len;
memcpy ( data, option->data, len );
/* Allocate new string */
prefix_len = strlen ( setting->prefix );
setting_len = fetch_setting_len ( NULL, setting->tag );
- if ( setting_len < 0 )
- return setting_len;
+ if ( setting_len < 0 ) {
+ /* Missing settings are not errors; leave strings as NULL */
+ return 0;
+ }
len = ( prefix_len + setting_len + 1 );
p = *setting->string = malloc ( len );
if ( ! p )
}
dhcphdr->hlen = 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 */
dhcppkt_init ( dhcppkt, NULL, data, max_len );
"option: %s\n", strerror ( rc ) );
return rc;
}
- if ( ( rc = copy_setting ( &dhcppkt->settings, DHCP_EB_YIADDR,
+ if ( ( rc = copy_setting ( &dhcppkt->settings,
+ DHCP_REQUESTED_ADDRESS,
offer_settings,
- DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
+ DHCP_EB_YIADDR ) ) != 0 ) {
DBG ( "DHCP could not set requested address "
"option: %s\n", strerror ( rc ) );
return rc;