iPXE
Data Structures | Functions
dhcppkt.h File Reference

DHCP packets. More...

#include <ipxe/dhcp.h>
#include <ipxe/dhcpopts.h>
#include <ipxe/refcnt.h>

Go to the source code of this file.

Data Structures

struct  dhcp_packet
 A DHCP packet. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static struct dhcp_packetdhcppkt_get (struct dhcp_packet *dhcppkt)
 Increment reference count on DHCP packet.
static void dhcppkt_put (struct dhcp_packet *dhcppkt)
 Decrement reference count on DHCP packet.
static int dhcppkt_len (struct dhcp_packet *dhcppkt)
 Get used length of DHCP packet.
int dhcppkt_store (struct dhcp_packet *dhcppkt, unsigned int tag, const void *data, size_t len)
 Store value of DHCP packet setting.
int dhcppkt_fetch (struct dhcp_packet *dhcppkt, unsigned int tag, void *data, size_t len)
 Fetch value of DHCP packet setting.
void dhcppkt_init (struct dhcp_packet *dhcppkt, struct dhcphdr *data, size_t len)
 Initialise DHCP packet.

Detailed Description

DHCP packets.

Definition in file dhcppkt.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static struct dhcp_packet* dhcppkt_get ( struct dhcp_packet dhcppkt) [static, read]

Increment reference count on DHCP packet.

Parameters:
dhcppktDHCP packet
Return values:
dhcppktDHCP packet

Definition at line 38 of file dhcppkt.h.

References ref_get.

Referenced by dhcp_discovery_rx().

                                            {
        ref_get ( &dhcppkt->refcnt );
        return dhcppkt;
}
static void dhcppkt_put ( struct dhcp_packet dhcppkt) [inline, static]

Decrement reference count on DHCP packet.

Parameters:
dhcppktDHCP packet

Definition at line 49 of file dhcppkt.h.

References ref_put.

Referenced by cachedhcp_probe(), cachedhcp_startup(), dhcp_deliver(), dhcp_discovery_rx(), and dhcp_free().

                                            {
        ref_put ( &dhcppkt->refcnt );
}
static int dhcppkt_len ( struct dhcp_packet dhcppkt) [inline, static]

Get used length of DHCP packet.

Parameters:
dhcppktDHCP packet
Return values:
lenUsed length

Definition at line 59 of file dhcppkt.h.

References offsetof, dhcp_packet::options, options, and dhcp_options::used_len.

Referenced by cachedhcp_init(), dhcp_tx(), and efi_pxe_fake().

                                                              {
        return ( offsetof ( struct dhcphdr, options ) +
                 dhcppkt->options.used_len );
}
int dhcppkt_store ( struct dhcp_packet dhcppkt,
unsigned int  tag,
const void *  data,
size_t  len 
)

Store value of DHCP packet setting.

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

Definition at line 164 of file dhcppkt.c.

References dhcp_packet_field(), dhcp_packet::dhcphdr, dhcpopt_store(), ENOSPC, find_dhcp_packet_field(), dhcp_packet_field::len, memcpy(), memset(), NULL, and dhcp_packet::options.

Referenced by copy_encap_settings(), dhcp_create_packet(), dhcp_create_request(), dhcp_proxy_tx(), dhcp_pxebs_tx(), dhcp_request_tx(), and dhcppkt_settings_store().

                                                   {
        struct dhcp_packet_field *field;
        void *field_data;

        /* If this is a special field, fill it in */
        if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
                if ( len > field->len )
                        return -ENOSPC;
                field_data = dhcp_packet_field ( dhcppkt->dhcphdr, field );
                memset ( field_data, 0, field->len );
                memcpy ( dhcp_packet_field ( dhcppkt->dhcphdr, field ),
                         data, len );
                /* Erase any equivalent option from the options block */
                dhcpopt_store ( &dhcppkt->options, tag, NULL, 0 );
                return 0;
        }

        /* Otherwise, use the generic options block */
        return dhcpopt_store ( &dhcppkt->options, tag, data, len );
}
int dhcppkt_fetch ( struct dhcp_packet dhcppkt,
unsigned int  tag,
void *  data,
size_t  len 
)

Fetch value of DHCP packet setting.

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

Definition at line 195 of file dhcppkt.c.

References dhcp_packet_field(), dhcp_packet::dhcphdr, dhcpopt_fetch(), find_dhcp_packet_field(), dhcp_packet_field::len, memcpy(), NULL, dhcp_packet::options, and dhcp_packet_field::used_len.

Referenced by dhcp_deliver(), dhcp_discovery_rx(), dhcp_has_pxeopts(), dhcp_pxebs_rx(), and dhcppkt_settings_fetch().

                                             {
        struct dhcp_packet_field *field;
        void *field_data;
        size_t field_len = 0;
        
        /* Identify special field, if any */
        if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
                field_data = dhcp_packet_field ( dhcppkt->dhcphdr, field );
                field_len = field->used_len ( field_data, field->len );
        }

        /* Return special field, if it exists and is populated */
        if ( field_len ) {
                if ( len > field_len )
                        len = field_len;
                memcpy ( data, field_data, len );
                return field_len;
        }

        /* Otherwise, use the generic options block */
        return dhcpopt_fetch ( &dhcppkt->options, tag, data, len );
}
void dhcppkt_init ( struct dhcp_packet dhcppkt,
struct dhcphdr data,
size_t  len 
)

Initialise DHCP packet.

Parameters:
dhcppktDHCP packet structure to fill in
dataDHCP packet raw data
max_lenLength of raw data buffer

Initialise a DHCP packet structure from a data buffer containing a DHCP packet.

Definition at line 300 of file dhcppkt.c.

References data, dhcp_packet::dhcphdr, dhcpopt_init(), dhcpopt_no_realloc(), NULL, offsetof, dhcp_packet::options, options, dhcphdr::options, ref_init, dhcp_packet::refcnt, dhcp_packet::settings, and settings_init().

Referenced by cachedhcp_init(), dhcp_create_packet(), dhcp_deliver(), and efi_pxe_fake().

                                 {
        ref_init ( &dhcppkt->refcnt, NULL );
        dhcppkt->dhcphdr = data;
        dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
                       ( len - offsetof ( struct dhcphdr, options ) ),
                       dhcpopt_no_realloc );
        settings_init ( &dhcppkt->settings, &dhcppkt_settings_operations,
                        &dhcppkt->refcnt, NULL );
}