iPXE
Data Structures | Defines | Functions
dhcpv6.h File Reference

Dynamic Host Configuration Protocol for IPv6. More...

#include <stdint.h>
#include <ipxe/in.h>
#include <ipxe/uuid.h>

Go to the source code of this file.

Data Structures

struct  dhcpv6_option
 A DHCPv6 option. More...
struct  dhcpv6_duid_uuid
 DHCP unique identifier based on UUID (DUID-UUID) More...
struct  dhcpv6_duid_option
 DHCPv6 client or server identifier option. More...
struct  dhcpv6_ia_na_option
 DHCPv6 identity association for non-temporary address (IA_NA) option. More...
struct  dhcpv6_iaaddr_option
 DHCPv6 identity association address (IAADDR) option. More...
struct  dhcpv6_option_request_option
 DHCPv6 option request option. More...
struct  dhcpv6_elapsed_time_option
 DHCPv6 elapsed time option. More...
struct  dhcpv6_status_code_option
 DHCPv6 status code option. More...
struct  dhcpv6_user_class
 DHCPv6 user class. More...
struct  dhcpv6_user_class_option
 DHCPv6 user class option. More...
union  dhcpv6_any_option
 Any DHCPv6 option. More...
struct  dhcpv6_header
 A DHCPv6 header. More...

Defines

#define DHCPV6_SERVER_PORT   547
 DHCPv6 server port.
#define DHCPV6_CLIENT_PORT   546
 DHCPv6 client port.
#define DHCPV6_DUID_UUID   4
 DHCP unique identifier based on UUID (DUID-UUID)
#define DHCPV6_CLIENT_ID   1
 DHCPv6 client identifier option.
#define DHCPV6_SERVER_ID   2
 DHCPv6 server identifier option.
#define DHCPV6_IA_NA   3
 DHCPv6 identity association for non-temporary address (IA_NA) option.
#define DHCPV6_IAADDR   5
 DHCPv6 identity association address (IAADDR) option.
#define DHCPV6_OPTION_REQUEST   6
 DHCPv6 option request option.
#define DHCPV6_ELAPSED_TIME   8
 DHCPv6 elapsed time option.
#define DHCPV6_STATUS_CODE   13
 DHCPv6 status code option.
#define DHCPV6_USER_CLASS   15
 DHCPv6 user class option.
#define DHCPV6_VENDOR_CLASS   16
 DHCPv6 vendor class option.
#define DHCPV6_VENDOR_CLASS_PXE   343
 DHCPv6 PXE vendor class.
#define DHCPV6_DNS_SERVERS   23
 DHCPv6 DNS recursive name server option.
#define DHCPV6_DOMAIN_LIST   24
 DHCPv6 domain search list option.
#define DHCPV6_BOOTFILE_URL   59
 DHCPv6 bootfile URI option.
#define DHCPV6_BOOTFILE_PARAM   60
 DHCPv6 bootfile parameters option.
#define DHCPV6_CLIENT_ARCHITECTURE   61
 DHCPv6 client system architecture option.
#define DHCPV6_CLIENT_NDI   62
 DHCPv6 client network interface identifier option.
#define DHCPV6_LOG_SERVERS   0xffffffffUL
 DHCPv6 syslog server option.
#define DHCPV6_BYTE_VALUE(value)   ( (value) & 0xff )
 Construct a DHCPv6 byte value.
#define DHCPV6_WORD_VALUE(value)   DHCPV6_BYTE_VALUE ( (value) >> 8 ), DHCPV6_BYTE_VALUE ( (value) >> 0 )
 Construct a DHCPv6 word value.
#define DHCPV6_DWORD_VALUE(value)   DHCPV6_WORD_VALUE ( (value) >> 16 ), DHCPV6_WORD_VALUE ( (value) >> 0 )
 Construct a DHCPv6 dword value.
#define DHCPV6_CODE(code)   DHCPV6_WORD_VALUE ( code )
 Construct a DHCPv6 option code.
#define DHCPV6_LEN(len)   DHCPV6_WORD_VALUE ( len )
 Construct a DHCPv6 option length.
#define DHCPV6_OPTION(...)   DHCPV6_LEN ( VA_ARG_COUNT ( __VA_ARGS__ ) ), __VA_ARGS__
 Construct a DHCPv6 option from a list of bytes.
#define DHCPV6_STRING(...)   DHCPV6_OPTION ( __VA_ARGS__ )
 Construct a DHCPv6 option from a list of characters.
#define DHCPV6_BYTE(value)   DHCPV6_OPTION ( DHCPV6_BYTE_VALUE ( value ) )
 Construct a byte-valued DHCPv6 option.
#define DHCPV6_WORD(value)   DHCPV6_OPTION ( DHCPV6_WORD_VALUE ( value ) )
 Construct a word-valued DHCPv6 option.
#define DHCPV6_DWORD(value)   DHCPV6_OPTION ( DHCPV6_DWORD_VALUE ( value ) )
 Construct a dword-valued DHCPv6 option.
#define DHCPV6_SOLICIT   1
 DHCPv6 solicitation.
#define DHCPV6_ADVERTISE   2
 DHCPv6 advertisement.
#define DHCPV6_REQUEST   3
 DHCPv6 request.
#define DHCPV6_REPLY   7
 DHCPv6 reply.
#define DHCPV6_INFORMATION_REQUEST   11
 DHCPv6 information request.
#define DHCPV6_SETTINGS_NAME   "dhcpv6"
 DHCPv6 settings block name.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void ipv6_all_dhcp_relay_and_servers (struct in6_addr *addr)
 Construct all-DHCP-relay-agents-and-servers multicast address.
int start_dhcpv6 (struct interface *job, struct net_device *netdev, int stateful)
 Start DHCPv6.

Detailed Description

Dynamic Host Configuration Protocol for IPv6.

Definition in file dhcpv6.h.


Define Documentation

#define DHCPV6_SERVER_PORT   547

DHCPv6 server port.

Definition at line 17 of file dhcpv6.h.

Referenced by start_dhcpv6().

#define DHCPV6_CLIENT_PORT   546

DHCPv6 client port.

Definition at line 20 of file dhcpv6.h.

Referenced by start_dhcpv6().

#define DHCPV6_DUID_UUID   4

DHCP unique identifier based on UUID (DUID-UUID)

Definition at line 44 of file dhcpv6.h.

Referenced by start_dhcpv6().

#define DHCPV6_CLIENT_ID   1

DHCPv6 client identifier option.

Definition at line 55 of file dhcpv6.h.

Referenced by dhcpv6_rx(), and dhcpv6_tx().

#define DHCPV6_SERVER_ID   2

DHCPv6 server identifier option.

Definition at line 58 of file dhcpv6.h.

Referenced by dhcpv6_rx(), and dhcpv6_tx().

#define DHCPV6_IA_NA   3

DHCPv6 identity association for non-temporary address (IA_NA) option.

Definition at line 75 of file dhcpv6.h.

Referenced by dhcpv6_iaaddr(), and dhcpv6_tx().

#define DHCPV6_IAADDR   5

DHCPv6 identity association address (IAADDR) option.

Definition at line 92 of file dhcpv6.h.

Referenced by dhcpv6_iaaddr(), and dhcpv6_tx().

#define DHCPV6_OPTION_REQUEST   6

DHCPv6 option request option.

Definition at line 103 of file dhcpv6.h.

#define DHCPV6_ELAPSED_TIME   8

DHCPv6 elapsed time option.

Definition at line 114 of file dhcpv6.h.

Referenced by dhcpv6_tx().

#define DHCPV6_STATUS_CODE   13

DHCPv6 status code option.

Definition at line 127 of file dhcpv6.h.

Referenced by dhcpv6_status_code().

#define DHCPV6_USER_CLASS   15

DHCPv6 user class option.

Definition at line 146 of file dhcpv6.h.

Referenced by dhcpv6_tx().

#define DHCPV6_VENDOR_CLASS   16

DHCPv6 vendor class option.

Definition at line 149 of file dhcpv6.h.

#define DHCPV6_VENDOR_CLASS_PXE   343

DHCPv6 PXE vendor class.

The DHCPv6 vendor class includes a field for an IANA enterprise number. The EDK2 codebase uses the value 343, with the comment:

TODO: IANA TBD: temporarily using Intel's

Since this "temporarily" has applied since at least 2010, we assume that it has become a de facto standard.

Definition at line 161 of file dhcpv6.h.

#define DHCPV6_DNS_SERVERS   23

DHCPv6 DNS recursive name server option.

Definition at line 164 of file dhcpv6.h.

#define DHCPV6_DOMAIN_LIST   24

DHCPv6 domain search list option.

Definition at line 167 of file dhcpv6.h.

#define DHCPV6_BOOTFILE_URL   59

DHCPv6 bootfile URI option.

Definition at line 170 of file dhcpv6.h.

#define DHCPV6_BOOTFILE_PARAM   60

DHCPv6 bootfile parameters option.

Definition at line 173 of file dhcpv6.h.

#define DHCPV6_CLIENT_ARCHITECTURE   61

DHCPv6 client system architecture option.

Definition at line 176 of file dhcpv6.h.

#define DHCPV6_CLIENT_NDI   62

DHCPv6 client network interface identifier option.

Definition at line 179 of file dhcpv6.h.

#define DHCPV6_LOG_SERVERS   0xffffffffUL

DHCPv6 syslog server option.

This option code has not yet been assigned by IANA. Please update this definition once an option code has been assigned.

Definition at line 186 of file dhcpv6.h.

#define DHCPV6_BYTE_VALUE (   value)    ( (value) & 0xff )

Construct a DHCPv6 byte value.

Definition at line 189 of file dhcpv6.h.

#define DHCPV6_WORD_VALUE (   value)    DHCPV6_BYTE_VALUE ( (value) >> 8 ), DHCPV6_BYTE_VALUE ( (value) >> 0 )

Construct a DHCPv6 word value.

Definition at line 192 of file dhcpv6.h.

#define DHCPV6_DWORD_VALUE (   value)    DHCPV6_WORD_VALUE ( (value) >> 16 ), DHCPV6_WORD_VALUE ( (value) >> 0 )

Construct a DHCPv6 dword value.

Definition at line 196 of file dhcpv6.h.

#define DHCPV6_CODE (   code)    DHCPV6_WORD_VALUE ( code )

Construct a DHCPv6 option code.

Definition at line 200 of file dhcpv6.h.

#define DHCPV6_LEN (   len)    DHCPV6_WORD_VALUE ( len )

Construct a DHCPv6 option length.

Definition at line 203 of file dhcpv6.h.

#define DHCPV6_OPTION (   ...)    DHCPV6_LEN ( VA_ARG_COUNT ( __VA_ARGS__ ) ), __VA_ARGS__

Construct a DHCPv6 option from a list of bytes.

Definition at line 206 of file dhcpv6.h.

#define DHCPV6_STRING (   ...)    DHCPV6_OPTION ( __VA_ARGS__ )

Construct a DHCPv6 option from a list of characters.

Definition at line 210 of file dhcpv6.h.

#define DHCPV6_BYTE (   value)    DHCPV6_OPTION ( DHCPV6_BYTE_VALUE ( value ) )

Construct a byte-valued DHCPv6 option.

Definition at line 213 of file dhcpv6.h.

#define DHCPV6_WORD (   value)    DHCPV6_OPTION ( DHCPV6_WORD_VALUE ( value ) )

Construct a word-valued DHCPv6 option.

Definition at line 216 of file dhcpv6.h.

Construct a dword-valued DHCPv6 option.

Definition at line 219 of file dhcpv6.h.

#define DHCPV6_SOLICIT   1

DHCPv6 solicitation.

Definition at line 250 of file dhcpv6.h.

Referenced by dhcpv6_type_name().

#define DHCPV6_ADVERTISE   2

DHCPv6 advertisement.

Definition at line 253 of file dhcpv6.h.

Referenced by dhcpv6_type_name().

#define DHCPV6_REQUEST   3

DHCPv6 request.

Definition at line 256 of file dhcpv6.h.

Referenced by dhcpv6_type_name().

#define DHCPV6_REPLY   7

DHCPv6 reply.

Definition at line 259 of file dhcpv6.h.

Referenced by dhcpv6_type_name().

#define DHCPV6_INFORMATION_REQUEST   11

DHCPv6 information request.

Definition at line 262 of file dhcpv6.h.

Referenced by dhcpv6_type_name().

#define DHCPV6_SETTINGS_NAME   "dhcpv6"

DHCPv6 settings block name.

Definition at line 265 of file dhcpv6.h.

Referenced by dhcpv6_register().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static void ipv6_all_dhcp_relay_and_servers ( struct in6_addr addr) [inline, static]

Construct all-DHCP-relay-agents-and-servers multicast address.

Parameters:
addrZeroed address to construct

Definition at line 272 of file dhcpv6.h.

References htons.

Referenced by start_dhcpv6().

                                                                             {
        addr->s6_addr16[0] = htons ( 0xff02 );
        addr->s6_addr[13] = 1;
        addr->s6_addr[15] = 2;
}
int start_dhcpv6 ( struct interface job,
struct net_device netdev,
int  stateful 
)

Start DHCPv6.

Parameters:
jobJob control interface
netdevNetwork device
statefulPerform stateful address autoconfiguration
Return values:
rcReturn status code

Definition at line 921 of file dhcpv6.c.

References AF_INET6, dhcpv6_session::client_duid, crc32_le(), currticks(), DBGC, DHCPV6_CLIENT_PORT, DHCPV6_DUID_UUID, dhcpv6_finished(), dhcpv6_free(), DHCPV6_SERVER_PORT, dhcpv6_set_state(), dhcpv6_timer_expired(), ENOMEM, fetch_uuid_setting(), htons, dhcpv6_session::iaid, net_device::index, intf_init(), intf_plug_plug(), ipv6_all_dhcp_relay_and_servers(), dhcpv6_session::job, len, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memcpy(), memset(), net_device::name, dhcpv6_session::netdev, netdev_get(), NULL, random(), rc, ref_init, ref_put, dhcpv6_session::refcnt, SOCK_DGRAM, dhcpv6_session::start, strerror(), dhcpv6_session::timer, dhcpv6_duid_uuid::type, dhcpv6_duid_uuid::uuid, dhcpv6_session::xfer, xfer_open_socket(), dhcpv6_session::xid, and zalloc().

Referenced by ipv6conf_rx_router_advertisement().

                                  {
        struct ll_protocol *ll_protocol = netdev->ll_protocol;
        struct dhcpv6_session *dhcpv6;
        struct {
                union {
                        struct sockaddr_in6 sin6;
                        struct sockaddr sa;
                } client;
                union {
                        struct sockaddr_in6 sin6;
                        struct sockaddr sa;
                } server;
        } addresses;
        uint32_t xid;
        int len;
        int rc;

        /* Allocate and initialise structure */
        dhcpv6 = zalloc ( sizeof ( *dhcpv6 ) );
        if ( ! dhcpv6 )
                return -ENOMEM;
        ref_init ( &dhcpv6->refcnt, dhcpv6_free );
        intf_init ( &dhcpv6->job, &dhcpv6_job_desc, &dhcpv6->refcnt );
        intf_init ( &dhcpv6->xfer, &dhcpv6_xfer_desc, &dhcpv6->refcnt );
        dhcpv6->netdev = netdev_get ( netdev );
        xid = random();
        memcpy ( dhcpv6->xid, &xid, sizeof ( dhcpv6->xid ) );
        dhcpv6->start = currticks();
        timer_init ( &dhcpv6->timer, dhcpv6_timer_expired, &dhcpv6->refcnt );

        /* Construct client and server addresses */
        memset ( &addresses, 0, sizeof ( addresses ) );
        addresses.client.sin6.sin6_family = AF_INET6;
        addresses.client.sin6.sin6_port = htons ( DHCPV6_CLIENT_PORT );
        addresses.server.sin6.sin6_family = AF_INET6;
        ipv6_all_dhcp_relay_and_servers ( &addresses.server.sin6.sin6_addr );
        addresses.server.sin6.sin6_scope_id = netdev->index;
        addresses.server.sin6.sin6_port = htons ( DHCPV6_SERVER_PORT );

        /* Construct client DUID from system UUID */
        dhcpv6->client_duid.type = htons ( DHCPV6_DUID_UUID );
        if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
                                          &dhcpv6->client_duid.uuid ) ) < 0 ) {
                rc = len;
                DBGC ( dhcpv6, "DHCPv6 %s could not create DUID-UUID: %s\n",
                       dhcpv6->netdev->name, strerror ( rc ) );
                goto err_client_duid;
        }

        /* Construct IAID from link-layer address */
        dhcpv6->iaid = crc32_le ( 0, netdev->ll_addr, ll_protocol->ll_addr_len);
        DBGC ( dhcpv6, "DHCPv6 %s has XID %02x%02x%02x\n", dhcpv6->netdev->name,
               dhcpv6->xid[0], dhcpv6->xid[1], dhcpv6->xid[2] );

        /* Enter initial state */
        dhcpv6_set_state ( dhcpv6, ( stateful ? &dhcpv6_solicit :
                                     &dhcpv6_information_request ) );

        /* Open socket */
        if ( ( rc = xfer_open_socket ( &dhcpv6->xfer, SOCK_DGRAM,
                                       &addresses.server.sa,
                                       &addresses.client.sa ) ) != 0 ) {
                DBGC ( dhcpv6, "DHCPv6 %s could not open socket: %s\n",
                       dhcpv6->netdev->name, strerror ( rc ) );
                goto err_open_socket;
        }

        /* Attach parent interface, mortalise self, and return */
        intf_plug_plug ( &dhcpv6->job, job );
        ref_put ( &dhcpv6->refcnt );
        return 0;

 err_open_socket:
        dhcpv6_finished ( dhcpv6, rc );
 err_client_duid:
        ref_put ( &dhcpv6->refcnt );
        return rc;
}