iPXE
Data Structures | Functions
dhcpopts.h File Reference

DHCP options. More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  dhcp_options
 A DHCP options block. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
int dhcpopt_applies (unsigned int tag)
 Check applicability of DHCP option setting.
int dhcpopt_store (struct dhcp_options *options, unsigned int tag, const void *data, size_t len)
 Store value of DHCP option setting.
int dhcpopt_fetch (struct dhcp_options *options, unsigned int tag, void *data, size_t len)
 Fetch value of DHCP option setting.
void dhcpopt_init (struct dhcp_options *options, void *data, size_t alloc_len, int(*realloc)(struct dhcp_options *options, size_t len))
 Initialise prepopulated block of DHCP options.
void dhcpopt_update_used_len (struct dhcp_options *options)
 Recalculate length of DHCP options block.
int dhcpopt_no_realloc (struct dhcp_options *options, size_t len)
 Refuse to reallocate DHCP option block.

Detailed Description

DHCP options.

Definition in file dhcpopts.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
int dhcpopt_applies ( unsigned int  tag)

Check applicability of DHCP option setting.

Parameters:
tagSetting tag number
Return values:
appliesSetting applies to this option block

Definition at line 359 of file dhcpopts.c.

References DHCP_ENCAP_OPT, and DHCP_MAX_OPTION.

Referenced by dhcppkt_applies(), and nvo_applies().

                                         {

        return ( tag && ( tag <= DHCP_ENCAP_OPT ( DHCP_MAX_OPTION,
                                                  DHCP_MAX_OPTION ) ) );
}
int dhcpopt_store ( struct dhcp_options options,
unsigned int  tag,
const void *  data,
size_t  len 
)

Store value of DHCP option setting.

Parameters:
optionsDHCP option block
tagSetting tag number
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values:
rcReturn status code

Definition at line 374 of file dhcpopts.c.

References offset, and set_dhcp_option().

Referenced by dhcppkt_store(), and nvo_store().

                                                   {
        int offset;

        offset = set_dhcp_option ( options, tag, data, len );
        if ( offset < 0 )
                return offset;
        return 0;
}
int dhcpopt_fetch ( struct dhcp_options options,
unsigned int  tag,
void *  data,
size_t  len 
)

Fetch value of DHCP option setting.

Parameters:
optionsDHCP option block
tagSetting tag number
dataBuffer to fill with setting data
lenLength of buffer
Return values:
lenLength of setting data, or negative error

Definition at line 393 of file dhcpopts.c.

References dhcp_option::data, dhcp_option(), find_dhcp_option_with_encap(), dhcp_option::len, memcpy(), NULL, and offset.

Referenced by dhcppkt_fetch(), and nvo_fetch().

                                             {
        int offset;
        struct dhcp_option *option;
        size_t option_len;

        offset = find_dhcp_option_with_encap ( options, tag, NULL );
        if ( offset < 0 )
                return offset;

        option = dhcp_option ( options, offset );
        option_len = option->len;
        if ( len > option_len )
                len = option_len;
        memcpy ( data, option->data, len );

        return option_len;
}
void dhcpopt_init ( struct dhcp_options options,
void *  data,
size_t  alloc_len,
int(*)(struct dhcp_options *options, size_t len realloc 
)

Initialise prepopulated block of DHCP options.

Parameters:
optionsUninitialised DHCP option block
dataMemory for DHCP option data
alloc_lenLength of memory for DHCP option data
reallocDHCP option block reallocator

The memory content must already be filled with valid DHCP options. A zeroed block counts as a block of valid DHCP options.

Definition at line 451 of file dhcpopts.c.

References dhcp_options::alloc_len, dhcp_options::data, data, DBGC, dhcpopt_update_used_len(), dhcp_options::realloc, realloc(), and dhcp_options::used_len.

Referenced by dhcppkt_init(), and nvo_init().

                                                       {

        /* Fill in fields */
        options->data = data;
        options->alloc_len = alloc_len;
        options->realloc = realloc;

        /* Update length */
        dhcpopt_update_used_len ( options );

        DBGC ( options, "DHCPOPT %p created (data %p lengths %#zx,%#zx)\n",
               options, options->data, options->used_len, options->alloc_len );
}
void dhcpopt_update_used_len ( struct dhcp_options options)

Recalculate length of DHCP options block.

Parameters:
optionsUninitialised DHCP option block

The "used length" field will be updated based on scanning through the block to find the end of the options.

Definition at line 420 of file dhcpopts.c.

References dhcp_options::alloc_len, dhcp_option(), dhcp_option_len(), DHCP_PAD, offset, dhcp_option::tag, and dhcp_options::used_len.

Referenced by dhcpopt_init(), and nvo_load().

                                                              {
        struct dhcp_option *option;
        int offset = 0;
        ssize_t remaining = options->alloc_len;
        unsigned int option_len;

        /* Find last non-pad option */
        options->used_len = 0;
        while ( remaining ) {
                option = dhcp_option ( options, offset );
                option_len = dhcp_option_len ( option );
                remaining -= option_len;
                if ( remaining < 0 )
                        break;
                offset += option_len;
                if ( option->tag != DHCP_PAD )
                        options->used_len = offset;
        }
}
int dhcpopt_no_realloc ( struct dhcp_options options,
size_t  len 
)

Refuse to reallocate DHCP option block.

Parameters:
optionsDHCP option block
lenNew length
Return values:
rcReturn status code

Definition at line 184 of file dhcpopts.c.

References ENOSPC.

Referenced by dhcppkt_init(), and nvo_realloc_dhcpopt().

                                                                    {
        return ( ( len <= options->alloc_len ) ? 0 : -ENOSPC );
}