Data Structures | Macros | 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...


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


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

Detailed Description

Dynamic Host Configuration Protocol for IPv6.

Definition in file dhcpv6.h.

Macro Definition Documentation


#define DHCPV6_SERVER_PORT   547

DHCPv6 server port.

Definition at line 17 of file dhcpv6.h.


#define DHCPV6_CLIENT_PORT   546

DHCPv6 client port.

Definition at line 20 of file dhcpv6.h.


#define DHCPV6_DUID_UUID   4

DHCP unique identifier based on UUID (DUID-UUID)

Definition at line 44 of file dhcpv6.h.


#define DHCPV6_CLIENT_ID   1

DHCPv6 client identifier option.

Definition at line 55 of file dhcpv6.h.


#define DHCPV6_SERVER_ID   2

DHCPv6 server identifier option.

Definition at line 58 of file dhcpv6.h.


#define DHCPV6_IA_NA   3

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

Definition at line 75 of file dhcpv6.h.


#define DHCPV6_IAADDR   5

DHCPv6 identity association address (IAADDR) option.

Definition at line 92 of file dhcpv6.h.



DHCPv6 option request option.

Definition at line 103 of file dhcpv6.h.



DHCPv6 elapsed time option.

Definition at line 114 of file dhcpv6.h.


#define DHCPV6_STATUS_CODE   13

DHCPv6 status code option.

Definition at line 127 of file dhcpv6.h.


#define DHCPV6_USER_CLASS   15

DHCPv6 user class option.

Definition at line 146 of file dhcpv6.h.


#define DHCPV6_VENDOR_CLASS   16

DHCPv6 vendor class option.

Definition at line 149 of file dhcpv6.h.



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.



DHCPv6 bootfile parameters option.

Definition at line 173 of file dhcpv6.h.



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.


#define DHCPV6_DWORD (   value)    DHCPV6_OPTION ( DHCPV6_DWORD_VALUE ( value ) )

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.


#define DHCPV6_ADVERTISE   2

DHCPv6 advertisement.

Definition at line 253 of file dhcpv6.h.


#define DHCPV6_REQUEST   3

DHCPv6 request.

Definition at line 256 of file dhcpv6.h.


#define DHCPV6_REPLY   7

DHCPv6 reply.

Definition at line 259 of file dhcpv6.h.



DHCPv6 information request.

Definition at line 262 of file dhcpv6.h.


#define DHCPV6_SETTINGS_NAME   "dhcpv6"

DHCPv6 settings block name.

Definition at line 265 of file dhcpv6.h.

Function Documentation



◆ ipv6_all_dhcp_relay_and_servers()

static void ipv6_all_dhcp_relay_and_servers ( struct in6_addr addr)

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

addrZeroed address to construct

Definition at line 272 of file dhcpv6.h.

272  {
273  addr->s6_addr16[0] = htons ( 0xff02 );
274  addr->s6_addr[13] = 1;
275  addr->s6_addr[15] = 2;
276 }
u32 addr
Definition: sky2.h:8
#define htons(value)
Definition: byteswap.h:135

References addr, and htons.

Referenced by start_dhcpv6().

◆ start_dhcpv6()

int start_dhcpv6 ( struct interface job,
struct net_device netdev,
int  stateful 

Start DHCPv6.

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

Definition at line 921 of file dhcpv6.c.

922  {
924  struct dhcpv6_session *dhcpv6;
925  struct {
926  union {
927  struct sockaddr_in6 sin6;
928  struct sockaddr sa;
929  } client;
930  union {
931  struct sockaddr_in6 sin6;
932  struct sockaddr sa;
933  } server;
934  } addresses;
935  uint32_t xid;
936  int len;
937  int rc;
939  /* Allocate and initialise structure */
940  dhcpv6 = zalloc ( sizeof ( *dhcpv6 ) );
941  if ( ! dhcpv6 )
942  return -ENOMEM;
943  ref_init ( &dhcpv6->refcnt, dhcpv6_free );
944  intf_init ( &dhcpv6->job, &dhcpv6_job_desc, &dhcpv6->refcnt );
945  intf_init ( &dhcpv6->xfer, &dhcpv6_xfer_desc, &dhcpv6->refcnt );
946  dhcpv6->netdev = netdev_get ( netdev );
947  xid = random();
948  memcpy ( dhcpv6->xid, &xid, sizeof ( dhcpv6->xid ) );
949  dhcpv6->start = currticks();
950  timer_init ( &dhcpv6->timer, dhcpv6_timer_expired, &dhcpv6->refcnt );
952  /* Construct client and server addresses */
953  memset ( &addresses, 0, sizeof ( addresses ) );
954  addresses.client.sin6.sin6_family = AF_INET6;
955  addresses.client.sin6.sin6_port = htons ( DHCPV6_CLIENT_PORT );
956  addresses.server.sin6.sin6_family = AF_INET6;
957  ipv6_all_dhcp_relay_and_servers ( &addresses.server.sin6.sin6_addr );
958  addresses.server.sin6.sin6_scope_id = netdev->scope_id;
959  addresses.server.sin6.sin6_port = htons ( DHCPV6_SERVER_PORT );
961  /* Construct client DUID from system UUID */
962  dhcpv6->client_duid.type = htons ( DHCPV6_DUID_UUID );
963  if ( ( len = fetch_uuid_setting ( NULL, &uuid_setting,
964  &dhcpv6->client_duid.uuid ) ) < 0 ) {
965  rc = len;
966  DBGC ( dhcpv6, "DHCPv6 %s could not create DUID-UUID: %s\n",
967  dhcpv6->netdev->name, strerror ( rc ) );
968  goto err_client_duid;
969  }
971  /* Construct IAID from link-layer address */
972  dhcpv6->iaid = crc32_le ( 0, netdev->ll_addr, ll_protocol->ll_addr_len);
973  DBGC ( dhcpv6, "DHCPv6 %s has XID %02x%02x%02x\n", dhcpv6->netdev->name,
974  dhcpv6->xid[0], dhcpv6->xid[1], dhcpv6->xid[2] );
976  /* Enter initial state */
977  dhcpv6_set_state ( dhcpv6, ( stateful ? &dhcpv6_solicit :
980  /* Open socket */
981  if ( ( rc = xfer_open_socket ( &dhcpv6->xfer, SOCK_DGRAM,
982  &addresses.server.sa,
983  &addresses.client.sa ) ) != 0 ) {
984  DBGC ( dhcpv6, "DHCPv6 %s could not open socket: %s\n",
985  dhcpv6->netdev->name, strerror ( rc ) );
986  goto err_open_socket;
987  }
989  /* Attach parent interface, mortalise self, and return */
990  intf_plug_plug ( &dhcpv6->job, job );
991  ref_put ( &dhcpv6->refcnt );
992  return 0;
994  err_open_socket:
995  dhcpv6_finished ( dhcpv6, rc );
996  err_client_duid:
997  ref_put ( &dhcpv6->refcnt );
998  return rc;
999 }
static struct dhcpv6_session_state dhcpv6_solicit
DHCPv6 solicitation state.
Definition: dhcpv6.c:477
A DHCPv6 session.
Definition: dhcpv6.c:494
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define AF_INET6
IPv6 Internet addresses.
Definition: socket.h:64
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
static struct interface_descriptor dhcpv6_xfer_desc
DHCPv6 data transfer interface descriptor.
Definition: dhcpv6.c:910
struct interface xfer
Data transfer interface.
Definition: dhcpv6.c:500
struct interface job
Job control interface.
Definition: dhcpv6.c:498
static void dhcpv6_set_state(struct dhcpv6_session *dhcpv6, struct dhcpv6_session_state *state)
Transition to new DHCPv6 session state.
Definition: dhcpv6.c:564
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition: refcnt.h:64
int xfer_open_socket(struct interface *intf, int semantics, struct sockaddr *peer, struct sockaddr *local)
Open socket.
Definition: open.c:142
#define SOCK_DGRAM
Definition: socket.h:29
#define DBGC(...)
Definition: compiler.h:505
struct sockaddr_in6 sin6
Definition: syslog.c:58
uint32_t iaid
Identity association ID.
Definition: dhcpv6.c:507
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
struct net_device * netdev
Network device being configured.
Definition: dhcpv6.c:503
static void dhcpv6_finished(struct dhcpv6_session *dhcpv6, int rc)
Terminate DHCPv6 session.
Definition: dhcpv6.c:548
unsigned int scope_id
Scope ID.
Definition: netdevice.h:360
A link-layer protocol.
Definition: netdevice.h:114
u32 crc32_le(u32 seed, const void *data, size_t len)
Calculate 32-bit little-endian CRC checksum.
Definition: crc32.c:39
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
struct sockaddr sa
Definition: syslog.c:55
struct refcnt refcnt
Reference counter.
Definition: dhcpv6.c:496
static void dhcpv6_free(struct refcnt *refcnt)
Free DHCPv6 session.
Definition: dhcpv6.c:533
static void dhcpv6_timer_expired(struct retry_timer *timer, int fail)
Handle timer expiry.
Definition: dhcpv6.c:739
Generalized socket address structure.
Definition: socket.h:96
static struct dhcpv6_session_state dhcpv6_information_request
DHCPv6 information request state.
Definition: dhcpv6.c:486
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:31
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:561
struct retry_timer timer
Retransmission timer.
Definition: dhcpv6.c:520
unsigned int uint32_t
Definition: stdint.h:12
uint16_t type
Definition: dhcpv6.h:38
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
uint32_t len
Definition: ena.h:14
unsigned long start
Start time (in ticks)
Definition: dhcpv6.c:509
struct dhcpv6_duid_uuid client_duid
Client DUID.
Definition: dhcpv6.c:511
static void ipv6_all_dhcp_relay_and_servers(struct in6_addr *addr)
Construct all-DHCP-relay-agents-and-servers multicast address.
Definition: dhcpv6.h:272
uint8_t xid[3]
Transaction ID.
Definition: dhcpv6.c:505
DHCPv6 client port.
Definition: dhcpv6.h:20
static struct interface_descriptor dhcpv6_job_desc
DHCPv6 job control interface descriptor.
Definition: dhcpv6.c:901
IPv6 socket address.
Definition: in.h:115
DHCP unique identifier based on UUID (DUID-UUID)
Definition: dhcpv6.h:44
int fetch_uuid_setting(struct settings *settings, const struct setting *setting, union uuid *uuid)
Fetch value of UUID setting.
Definition: settings.c:1084
DHCPv6 server port.
Definition: dhcpv6.h:17
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
unsigned long currticks(void)
Get current system time in ticks.
Definition: timer.c:42
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition: interface.h:203
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define htons(value)
Definition: byteswap.h:135
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106
void * memset(void *dest, int character, size_t len) __nonnull
union uuid uuid
Definition: dhcpv6.h:40

References AF_INET6, dhcpv6_session::client_duid, crc32_le(), currticks(), DBGC, DHCPV6_CLIENT_PORT, DHCPV6_DUID_UUID, dhcpv6_finished(), dhcpv6_free(), dhcpv6_information_request, dhcpv6_job_desc, DHCPV6_SERVER_PORT, dhcpv6_set_state(), dhcpv6_solicit, dhcpv6_timer_expired(), dhcpv6_xfer_desc, ENOMEM, fetch_uuid_setting(), htons, dhcpv6_session::iaid, 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, netdev, dhcpv6_session::netdev, netdev_get(), NULL, random(), rc, ref_init, ref_put, dhcpv6_session::refcnt, sa, net_device::scope_id, sin6, 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().