121 int *encap_offset ) {
126 unsigned int option_len;
133 while ( remaining ) {
140 remaining -= option_len;
155 DBGC (
options,
"DHCPOPT %p found %s (length %d)\n",
167 remaining = option_len;
185 return ( ( len <= options->alloc_len ) ? 0 : -
ENOSPC );
199 int offset,
int encap_offset,
200 size_t old_len,
size_t new_len ) {
203 ssize_t delta = ( new_len - old_len );
204 size_t old_alloc_len;
206 size_t new_encapsulator_len;
216 new_used_len = (
options->used_len + delta );
219 if ( new_used_len >
options->alloc_len ) {
221 old_alloc_len =
options->alloc_len;
223 DBGC (
options,
"DHCPOPT %p could not reallocate to " 224 "%zd bytes\n",
options, new_used_len );
229 (
options->alloc_len - old_alloc_len ) );
233 if ( encap_offset >= 0 ) {
235 new_encapsulator_len = ( encapsulator->
len + delta );
237 DBGC (
options,
"DHCPOPT %p overlength encapsulator\n",
241 encapsulator->
len = new_encapsulator_len;
245 options->used_len = new_used_len;
249 source = ( ( (
void * )
option ) + old_len );
254 if ( new_used_len < options->alloc_len ) {
256 DBGC (
options,
"DHCPOPT %p could not reallocate to " 257 "%zd bytes\n",
options, new_used_len );
283 const void *
data,
size_t len ) {
286 int encap_offset = -1;
300 if ( creation_offset < 0 )
301 creation_offset =
options->used_len;
306 DBGC (
options,
"DHCPOPT %p resizing %s from %zd to %zd\n",
309 DBGC (
options,
"DHCPOPT %p creating %s (length %zd)\n",
315 if ( encap_offset < 0 ) {
319 sizeof ( empty_encap ) );
321 if ( encap_offset < 0 )
332 old_len, new_len ) ) != 0 )
344 if ( encap_offset >= 0 ) {
375 const void *
data,
size_t len ) {
405 if (
len > option_len )
424 unsigned int option_len;
428 while ( remaining ) {
431 remaining -= option_len;
457 options->alloc_len = alloc_len;
463 DBGC (
options,
"DHCPOPT %p created (data %p lengths %#zx,%#zx)\n",
static struct dhcp_option * dhcp_option(struct dhcp_options *options, unsigned int offset)
Get pointer to DHCP option.
struct arbelprm_rc_send_wqe rc
Dynamic Host Configuration Protocol.
#define DHCP_OPTION_HEADER_LEN
Length of a DHCP option header.
#define DHCP_ENCAPSULATOR(encap_opt)
Extract encapsulating option block tag from encapsulated tag value.
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.
#define ENOENT
No such file or directory.
static int set_dhcp_option(struct dhcp_options *options, unsigned int tag, const void *data, size_t len)
Set value of DHCP option.
#define DHCP_MAX_OPTION
Maximum normal DHCP option.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static int dhcp_option_offset(struct dhcp_options *options, struct dhcp_option *option)
Get offset of a DHCP option.
A long option, as used for getopt_long()
static char * dhcp_tag_name(unsigned int tag)
Obtain printable version of a DHCP option tag.
#define DHCP_MAX_LEN
Maximum length for a single DHCP option.
static int find_dhcp_option_with_encap(struct dhcp_options *options, unsigned int tag, int *encap_offset)
Find DHCP option within DHCP options block, and its encapsulator (if any)
void * memmove(void *dest, const void *src, size_t len) __nonnull
static unsigned int dhcp_option_len(struct dhcp_option *option)
Calculate length of any DHCP option.
int dhcpopt_no_realloc(struct dhcp_options *options, size_t len)
Refuse to reallocate DHCP option block.
#define ENOSPC
No space left on device.
#define DHCP_ENCAPSULATED(encap_opt)
Extract encapsulated option tag from encapsulated tag value.
#define DHCP_IS_ENCAP_OPT(opt)
Option is encapsulated.
#define ENOTTY
Inappropriate I/O control operation.
void dhcpopt_update_used_len(struct dhcp_options *options)
Recalculate length of DHCP options block.
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
uint8_t data[48]
Additional event data.
int dhcpopt_store(struct dhcp_options *options, unsigned int tag, const void *data, size_t len)
Store value of DHCP option setting.
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
#define DHCP_END
End of options.
uint16_t offset
Offset to command line.
int dhcpopt_fetch(struct dhcp_options *options, unsigned int tag, void *data, size_t len)
Fetch value of DHCP option setting.
#define DHCP_ENCAP_OPT(encapsulator, encapsulated)
Construct a tag value for an encapsulated option.
static int resize_dhcp_option(struct dhcp_options *options, int offset, int encap_offset, size_t old_len, size_t new_len)
Resize a DHCP option.
uint64_t tag
Identity tag.
#define NULL
NULL pointer (VOID *)
int dhcpopt_applies(unsigned int tag)
Check applicability of DHCP option setting.
void * memset(void *dest, int character, size_t len) __nonnull