Skip to content

Commit

Permalink
[Settings] Remove assumption that all settings have DHCP tag values
Browse files Browse the repository at this point in the history
Allow for settings to be described by something other than a DHCP option
tag if desirable.  Currently used only for the MAC address setting.

Separate out fake DHCP packet creation code from dhcp.c to fakedhcp.c.

Remove notion of settings from dhcppkt.c.

Rationalise dhcp.c to use settings API only for final registration of the
DHCP options, rather than using {store,fetch}_setting throughout.
  • Loading branch information
Michael Brown committed Mar 25, 2008
1 parent ee5bdb0 commit 92d15ef
Show file tree
Hide file tree
Showing 24 changed files with 854 additions and 709 deletions.
7 changes: 3 additions & 4 deletions src/arch/i386/image/nbi.c
Expand Up @@ -8,8 +8,7 @@
#include <gpxe/segment.h>
#include <gpxe/init.h>
#include <gpxe/netdevice.h>
#include <gpxe/dhcp.h>
#include <gpxe/dhcppkt.h>
#include <gpxe/fakedhcp.h>
#include <gpxe/image.h>
#include <gpxe/features.h>

Expand Down Expand Up @@ -400,8 +399,8 @@ static int nbi_prepare_dhcp ( struct image *image ) {
return -ENODEV;
}

if ( ( rc = create_dhcpack ( boot_netdev, basemem_packet,
sizeof ( basemem_packet ) ) ) != 0 ) {
if ( ( rc = create_fakedhcpack ( boot_netdev, basemem_packet,
sizeof ( basemem_packet ) ) ) != 0 ) {
DBGC ( image, "NBI %p failed to build DHCP packet\n", image );
return rc;
}
Expand Down
27 changes: 14 additions & 13 deletions src/core/ibft.c
Expand Up @@ -123,15 +123,16 @@ static void ibft_set_ipaddr ( struct ibft_ipaddr *ipaddr, struct in_addr in ) {
}

/**
* Fill in an IP address within iBFT from DHCP option
* Fill in an IP address within iBFT from configuration setting
*
* @v ipaddr IP address field
* @v setting Configuration setting
* @v tag DHCP option tag
*/
static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
unsigned int tag ) {
struct setting *setting ) {
struct in_addr in = { 0 };
fetch_ipv4_setting ( NULL, tag, &in );
fetch_ipv4_setting ( NULL, setting, &in );
ibft_set_ipaddr ( ipaddr, in );
}

Expand Down Expand Up @@ -182,21 +183,21 @@ static int ibft_set_string ( struct ibft_string_block *strings,
}

/**
* Fill in a string field within iBFT from DHCP option
* Fill in a string field within iBFT from configuration setting
*
* @v strings iBFT string block descriptor
* @v string String field
* @v tag DHCP option tag
* @v setting Configuration setting
* @ret rc Return status code
*/
static int ibft_set_string_option ( struct ibft_string_block *strings,
struct ibft_string *string,
unsigned int tag ) {
struct setting *setting ) {
int len;
char *dest;
int rc;

len = fetch_setting_len ( NULL, tag );
len = fetch_setting_len ( NULL, setting );
if ( len < 0 ) {
string->offset = 0;
string->length = 0;
Expand All @@ -206,7 +207,7 @@ static int ibft_set_string_option ( struct ibft_string_block *strings,
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 ) );
fetch_string_setting ( NULL, setting, dest, ( len + 1 ) );
return 0;
}

Expand All @@ -226,15 +227,15 @@ static int ibft_fill_nic ( struct ibft_nic *nic,
int rc;

/* Extract values from DHCP configuration */
ibft_set_ipaddr_option ( &nic->ip_address, DHCP_EB_YIADDR );
ibft_set_ipaddr_option ( &nic->gateway, DHCP_ROUTERS );
ibft_set_ipaddr_option ( &nic->dns[0], DHCP_DNS_SERVERS );
ibft_set_ipaddr_option ( &nic->ip_address, &ip_setting );
ibft_set_ipaddr_option ( &nic->gateway, &gateway_setting );
ibft_set_ipaddr_option ( &nic->dns[0], &dns_setting );
if ( ( rc = ibft_set_string_option ( strings, &nic->hostname,
DHCP_HOST_NAME ) ) != 0 )
&hostname_setting ) ) != 0 )
return rc;

/* Derive subnet mask prefix from subnet mask */
fetch_ipv4_setting ( NULL, DHCP_SUBNET_MASK, &netmask_addr );
fetch_ipv4_setting ( NULL, &netmask_setting, &netmask_addr );
while ( netmask_addr.s_addr ) {
if ( netmask_addr.s_addr & 0x1 )
netmask_count++;
Expand Down
13 changes: 7 additions & 6 deletions src/core/nvo.c
Expand Up @@ -138,19 +138,20 @@ static void nvo_init_dhcpopts ( struct nvo_block *nvo ) {
* Store value of NVO setting
*
* @v settings Settings block
* @v tag Setting tag number
* @v setting Setting to store
* @v data Setting data, or NULL to clear setting
* @v len Length of setting data
* @ret rc Return status code
*/
static int nvo_store ( struct settings *settings, unsigned int tag,
static int nvo_store ( struct settings *settings, struct setting *setting,
const void *data, size_t len ) {
struct nvo_block *nvo =
container_of ( settings, struct nvo_block, settings );
int rc;

/* Update stored options */
if ( ( rc = dhcpopt_store ( &nvo->dhcpopts, tag, data, len ) ) != 0 ) {
if ( ( rc = dhcpopt_store ( &nvo->dhcpopts, setting->tag,
data, len ) ) != 0 ) {
DBGC ( nvo, "NVO %p could not store %zd bytes: %s\n",
nvo, len, strerror ( rc ) );
return rc;
Expand All @@ -167,20 +168,20 @@ static int nvo_store ( struct settings *settings, unsigned int tag,
* Fetch value of NVO setting
*
* @v settings Settings block
* @v tag Setting tag number
* @v setting Setting to fetch
* @v data Buffer to fill with setting data
* @v len Length of buffer
* @ret len Length of setting data, or negative error
*
* The actual length of the setting will be returned even if
* the buffer was too small.
*/
static int nvo_fetch ( struct settings *settings, unsigned int tag,
static int nvo_fetch ( struct settings *settings, struct setting *setting,
void *data, size_t len ) {
struct nvo_block *nvo =
container_of ( settings, struct nvo_block, settings );

return dhcpopt_fetch ( &nvo->dhcpopts, tag, data, len );
return dhcpopt_fetch ( &nvo->dhcpopts, setting->tag, data, len );
}

/** NVO settings operations */
Expand Down

0 comments on commit 92d15ef

Please sign in to comment.