client.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2018 Freie Universität Berlin
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
20 #ifndef NET_DHCPV6_CLIENT_H
21 #define NET_DHCPV6_CLIENT_H
22 
23 #include "byteorder.h"
24 #include "event.h"
25 #include "net/ipv6/addr.h"
26 #include "thread.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
36 #ifndef DHCPV6_CLIENT_STACK_SIZE
37 #define DHCPV6_CLIENT_STACK_SIZE (THREAD_STACKSIZE_DEFAULT)
38 #endif
39 
40 #ifndef DHCPV6_CLIENT_PRIORITY
41 #define DHCPV6_CLIENT_PRIORITY (THREAD_PRIORITY_MAIN - 2)
42 #endif
48 #define DHCPV6_CLIENT_DUID_LEN (sizeof(dhcpv6_duid_l2_t) + 8U)
49 #define DHCPV6_CLIENT_BUFLEN (256)
62 #ifndef CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX
63 #define CONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX (1U)
64 #endif
65 
69 #ifndef CONFIG_DHCPV6_CLIENT_ADDR_LEASE_MAX
70 #define CONFIG_DHCPV6_CLIENT_ADDR_LEASE_MAX (1U)
71 #endif
72 
79 #if defined(MODULE_DHCPV6_CLIENT_IA_NA) || defined(DOXYGEN)
80 #define DHCPV6_CLIENT_ADDRS_NUMOF ((int)(CONFIG_DHCPV6_CLIENT_ADDR_LEASE_MAX))
81 #else
82 #define DHCPV6_CLIENT_ADDRS_NUMOF (0)
83 #endif
84 
89 #ifndef CONFIG_DHCPV6_CLIENT_MUD_URL
90 #define CONFIG_DHCPV6_CLIENT_MUD_URL "https://example.org"
91 #endif
92 
103 typedef struct __attribute__((packed)) {
106  /* link-layer address follows this header */
108 
109 #if defined(MODULE_AUTO_INIT_DHCPV6_CLIENT) || defined(DOXYGEN)
117 #endif /* MODULE_DHCPV6_CLIENT_AUTO_INIT */
118 
129 void dhcpv6_client_init(event_queue_t *event_queue, uint16_t netif);
130 
141 
166 int dhcpv6_client_req_ia_pd(unsigned netif, unsigned pfx_len);
181 int dhcpv6_client_req_ia_na(unsigned netif);
200 unsigned dhcpv6_client_get_duid_l2(unsigned netif, dhcpv6_duid_l2_t *duid);
201 
211 void dhcpv6_client_conf_prefix(unsigned netif, const ipv6_addr_t *pfx,
212  unsigned pfx_len, uint32_t valid,
213  uint32_t pref);
214 
223 static inline void dhcpv6_client_conf_addr(unsigned netif, const ipv6_addr_t *addr,
224  uint32_t valid, uint32_t pref)
225 {
226  dhcpv6_client_conf_prefix(netif, addr, IPV6_ADDR_BIT_LEN, valid, pref);
227 }
228 
237 bool dhcpv6_client_check_ia_na(unsigned netif);
238 
248 uint32_t dhcpv6_client_prefix_valid_until(unsigned netif,
249  const ipv6_addr_t *pfx,
250  unsigned pfx_len);
251 
260 static inline uint32_t dhcpv6_client_addr_valid_until(unsigned netif,
261  const ipv6_addr_t *addr)
262 {
264 }
265 
280 #if defined(MODULE_DHCPV6_CLIENT_MUD_URL) || defined(DOXYGEN)
281 #define DHCPV6_CLIENT_SEND_BUFLEN (DHCPV6_CLIENT_BUFLEN + 256)
282 #else
283 #define DHCPV6_CLIENT_SEND_BUFLEN (DHCPV6_CLIENT_BUFLEN)
284 #endif
285 
289 #define MAX_MUD_URL_LENGTH (0xFF - sizeof(dhcpv6_opt_mud_url_t))
290 
294 enum {
295  DHCPV6_CLIENT_CONF_MODE_INACTIVE,
296  DHCPV6_CLIENT_CONF_MODE_STATEFUL,
297  DHCPV6_CLIENT_CONF_MODE_STATELESS,
298 };
299 
305 void dhcpv6_client_set_conf_mode(uint8_t configuration_mode);
306 
313 
316 #ifdef __cplusplus
317 }
318 #endif
319 
320 #endif /* NET_DHCPV6_CLIENT_H */
Functions to work with different byte orders.
uint8_t dhcpv6_client_get_conf_mode(void)
Retrieves the DHCPv6 client's current configuration mode.
bool dhcpv6_client_check_ia_na(unsigned netif)
Checks if the given network interface is configured to use DHCPv6 IA_NA.
unsigned dhcpv6_client_get_duid_l2(unsigned netif, dhcpv6_duid_l2_t *duid)
Get the link-layer address DUID for the client.
static void dhcpv6_client_conf_addr(unsigned netif, const ipv6_addr_t *addr, uint32_t valid, uint32_t pref)
Configures a address lease that is provided by the server.
Definition: client.h:223
uint32_t dhcpv6_client_prefix_valid_until(unsigned netif, const ipv6_addr_t *pfx, unsigned pfx_len)
Determines how long the prefix delegation lease is still valid.
void dhcpv6_client_set_conf_mode(uint8_t configuration_mode)
Changes the DHCPv6 client's configuration mode.
static uint32_t dhcpv6_client_addr_valid_until(unsigned netif, const ipv6_addr_t *addr)
Determines how long the address lease is still valid.
Definition: client.h:260
void dhcpv6_client_conf_prefix(unsigned netif, const ipv6_addr_t *pfx, unsigned pfx_len, uint32_t valid, uint32_t pref)
Configures a prefix delegation lease that is provided by the server.
int dhcpv6_client_req_ia_na(unsigned netif)
Configures the client to request non-temporary addresses for a network interface from a server.
void dhcpv6_client_auto_init(void)
Auto-initializes the client in its own thread.
void dhcpv6_client_start(void)
Let the server start listening.
void dhcpv6_client_init(event_queue_t *event_queue, uint16_t netif)
Initializes the client.
int dhcpv6_client_req_ia_pd(unsigned netif, unsigned pfx_len)
Configures the client to request prefix delegation for a network interface from a server.
#define IPV6_ADDR_BIT_LEN
Length of an IPv6 address in bit.
Definition: addr.h:42
Definitions for IPv6 addresses.
event queue structure
Definition: event.h:156
DUID based on link-layer address plus time.
Definition: client.h:103
network_uint16_t l2type
hardware type)
Definition: client.h:105
network_uint16_t type
DHCPV6_DUID_TYPE_L2
Definition: client.h:104
A 16 bit integer in big endian aka network byte order.
Definition: byteorder.h:74
Data type to represent an IPv6 address.
Definition: addr.h:72