add initial support for stateless DHCPv6

Signed-off-by: goldsimon <goldsimon@gmx.de>
This commit is contained in:
goldsimon
2018-02-22 22:33:16 +01:00
parent 37b4494921
commit 76a13054ee
7 changed files with 909 additions and 28 deletions

View File

@@ -1,11 +1,13 @@
/**
* @file
*
* IPv6 address autoconfiguration as per RFC 4862.
* DHCPv6 client: IPv6 address autoconfiguration as per
* RFC 3315 (stateful DHCPv6) and
* RFC 3736 (stateless DHCPv6).
*/
/*
* Copyright (c) 2010 Inico Technologies Ltd.
* Copyright (c) 2018 Simon Goldschmidt
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@@ -32,12 +34,7 @@
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Ivan Delamer <delamer@inicotech.com>
*
* IPv6 address autoconfiguration as per RFC 4862.
*
* Please coordinate changes and requests with Ivan Delamer
* <delamer@inicotech.com>
* Author: Simon Goldschmidt <goldsimon@gmx.de>
*/
#ifndef LWIP_HDR_IP6_DHCP6_H
@@ -47,12 +44,53 @@
#if LWIP_IPV6_DHCP6 /* don't build if not configured for use in lwipopts.h */
#include "lwip/err.h"
#include "lwip/netif.h"
/** period (in milliseconds) of the application calling dhcp6_tmr() */
#define DHCP6_TIMER_MSECS 500
struct dhcp6
{
/*@todo: implement DHCP6*/
/** transaction identifier of last sent request */
u32_t xid;
/** track PCB allocation state */
u8_t pcb_allocated;
/** current DHCPv6 state machine state */
u8_t state;
/** retries of current request */
u8_t tries;
/** if request config is triggered while another action is active, this keeps track of it */
u8_t request_config_pending;
/** #ticks with period DHCP6_TIMER_MSECS for request timeout */
u16_t request_timeout;
#if LWIP_IPV6_DHCP6_STATEFUL
/* @todo: add more members here to keep track of stateful DHCPv6 data, like lease times */
#endif /* LWIP_IPV6_DHCP6_STATEFUL */
};
void dhcp6_set_struct(struct netif *netif, struct dhcp6 *dhcp6);
/** Remove a struct dhcp6 previously set to the netif using dhcp6_set_struct() */
#define dhcp6_remove_struct(netif) netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6, NULL)
void dhcp6_cleanup(struct netif *netif);
err_t dhcp6_enable_stateful(struct netif *netif);
err_t dhcp6_enable_stateless(struct netif *netif);
void dhcp6_disable(struct netif *netif);
void dhcp6_tmr(void);
void dhcp6_nd6_ra_trigger(struct netif *netif, u8_t managed_addr_config, u8_t other_config);
#if LWIP_DHCP6_GET_NTP_SRV
/** This function must exist, in other to add offered NTP servers to
* the NTP (or SNTP) engine.
* See LWIP_DHCP6_MAX_NTP_SERVERS */
extern void dhcp6_set_ntp_servers(u8_t num_ntp_servers, const ip_addr_t* ntp_server_addrs);
#endif /* LWIP_DHCP6_GET_NTP_SRV */
#define netif_dhcp6_data(netif) ((struct dhcp6*)netif_get_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6))
#endif /* LWIP_IPV6_DHCP6 */
#endif /* LWIP_HDR_IP6_DHCP6_H */

View File

@@ -112,6 +112,7 @@ extern "C" {
enum lwip_internal_netif_client_data_index
{
#if LWIP_IPV4
#if LWIP_DHCP
LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
#endif
@@ -121,9 +122,15 @@ enum lwip_internal_netif_client_data_index
#if LWIP_IGMP
LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
#endif
#endif /* LWIP_IPV4 */
#if LWIP_IPV6
#if LWIP_IPV6_DHCP6
LWIP_NETIF_CLIENT_DATA_INDEX_DHCP6,
#endif
#if LWIP_IPV6_MLD
LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
#endif
#endif /* LWIP_IPV6 */
LWIP_NETIF_CLIENT_DATA_INDEX_MAX
};

View File

@@ -963,7 +963,7 @@
/**
* LWIP_DHCP_MAX_DNS_SERVERS > 0: Request DNS servers with discover/select.
* DHCP servers received in the response are passed to DNS via @ref dns_setserver()
* DNS servers received in the response are passed to DNS via @ref dns_setserver()
* (up to the maximum limit defined here).
*/
#if !defined LWIP_DHCP_MAX_DNS_SERVERS || defined __DOXYGEN__
@@ -2657,12 +2657,51 @@
*/
/**
* LWIP_IPV6_DHCP6==1: enable DHCPv6 stateful address autoconfiguration.
* LWIP_IPV6_DHCP6==1: enable DHCPv6 stateful/stateless address autoconfiguration.
*/
#if !defined LWIP_IPV6_DHCP6 || defined __DOXYGEN__
#define LWIP_IPV6_DHCP6 0
#endif
/**
* LWIP_IPV6_DHCP6_STATEFUL==1: enable DHCPv6 stateful address autoconfiguration.
*/
#if !defined LWIP_IPV6_DHCP6_STATEFUL || defined __DOXYGEN__
#define LWIP_IPV6_DHCP6_STATEFUL 0
#endif
/**
* LWIP_IPV6_DHCP6_STATELESS==1: enable DHCPv6 stateless address autoconfiguration.
*/
#if !defined LWIP_IPV6_DHCP6_STATELESS || defined __DOXYGEN__
#define LWIP_IPV6_DHCP6_STATELESS 0
#endif
/**
* LWIP_DHCP6_GETS_NTP==1: Request NTP servers via DHCPv6. For each
* response packet, a callback is called, which has to be provided by the port:
* void dhcp6_set_ntp_servers(u8_t num_ntp_servers, ip_addr_t* ntp_server_addrs);
*/
#if !defined LWIP_DHCP6_GET_NTP_SRV || defined __DOXYGEN__
#define LWIP_DHCP6_GET_NTP_SRV 0
#endif
/**
* The maximum of NTP servers requested
*/
#if !defined LWIP_DHCP6_MAX_NTP_SERVERS || defined __DOXYGEN__
#define LWIP_DHCP6_MAX_NTP_SERVERS 1
#endif
/**
* LWIP_DHCP6_MAX_DNS_SERVERS > 0: Request DNS servers via DHCPv6.
* DNS servers received in the response are passed to DNS via @ref dns_setserver()
* (up to the maximum limit defined here).
*/
#if !defined LWIP_DHCP6_MAX_DNS_SERVERS || defined __DOXYGEN__
#define LWIP_DHCP6_MAX_DNS_SERVERS DNS_MAX_SERVERS
#endif
/*
---------------------------------------
---------- Hook options ---------------
@@ -3047,6 +3086,34 @@
#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset)
#endif
/**
* LWIP_HOOK_DHCP6_APPEND_OPTIONS(netif, dhcp6, state, msg, msg_type, options_len_ptr, max_len):
* Called from various dhcp6 functions when sending a DHCP6 message.
* This hook is called just before the DHCP6 message is sent, so the
* options are at the end of a DHCP6 message.
* Signature:\code{.c}
* void my_hook(struct netif *netif, struct dhcp6 *dhcp, u8_t state, struct dhcp6_msg *msg,
* u8_t msg_type, u16_t *options_len_ptr);
* \endcode
* Arguments:
* - netif: struct netif that the packet will be sent through
* - dhcp6: struct dhcp6 on that netif
* - state: current dhcp6 state (dhcp6_state_enum_t as an u8_t)
* - msg: struct dhcp6_msg that will be sent
* - msg_type: dhcp6 message type to be sent (u8_t)
* - options_len_ptr: pointer to the current length of options in the dhcp6_msg "msg"
* (must be increased when options are added!)
*
* Options need to appended like this:
* u8_t *options = (u8_t *)(msg + 1);
* LWIP_ASSERT("dhcp option overflow", sizeof(struct dhcp6_msg) + *options_len_ptr + newoptlen <= max_len);
* options[(*options_len_ptr)++] = &lt;option_data&gt;;
* [...]
*/
#ifdef __DOXYGEN__
#define LWIP_HOOK_DHCP6_APPEND_OPTIONS(netif, dhcp6, state, msg, msg_type, options_len_ptr, max_len)
#endif
/**
* LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, err)
* Called from socket API to implement setsockopt() for options not provided by lwIP.
@@ -3372,6 +3439,13 @@
#if !defined IP6_DEBUG || defined __DOXYGEN__
#define IP6_DEBUG LWIP_DBG_OFF
#endif
/**
* DHCP6_DEBUG: Enable debugging in dhcp6.c.
*/
#if !defined DHCP6_DEBUG || defined __DOXYGEN__
#define DHCP6_DEBUG LWIP_DBG_OFF
#endif
/**
* @}
*/

View File

@@ -49,12 +49,6 @@ extern "C" {
/* DHCPv6 message item offsets and length */
#define DHCP6_TRANSACTION_ID_LEN 3
#define DHCP_SNAME_OFS 44U
#define DHCP_SNAME_LEN 64U
#define DHCP_FILE_OFS 108U
#define DHCP_FILE_LEN 128U
#define DHCP_MSG_LEN 236U
#define DHCP_OPTIONS_OFS (DHCP_MSG_LEN + 4U)*/ /* 4 byte: cookie */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
@@ -76,8 +70,9 @@ PACK_STRUCT_END
/* DHCP6 client states */
typedef enum {
DHCP6_STATE_OFF = 0,
DHCP6_STATE_REQUESTING_CONFIG = 1
} dhcp_state_enum_t;
DHCP6_STATE_STATELESS_IDLE = 1,
DHCP6_STATE_REQUESTING_CONFIG = 2
} dhcp6_state_enum_t;
/* DHCPv6 message types */
#define DHCP6_SOLICIT 1
@@ -93,6 +88,7 @@ typedef enum {
#define DHCP6_INFOREQUEST 11
#define DHCP6_RELAYFORW 12
#define DHCP6_RELAYREPL 13
/* More message types see https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml */
/** DHCPv6 status codes */
#define DHCP6_STATUS_SUCCESS 0 /* Success. */
@@ -101,11 +97,13 @@ typedef enum {
#define DHCP6_STATUS_NOBINDING 3 /* Client record (binding) unavailable. */
#define DHCP6_STATUS_NOTONLINK 4 /* The prefix for the address is not appropriate for the link to which the client is attached. */
#define DHCP6_STATUS_USEMULTICAST 5 /* Sent by a server to a client to force the client to send messages to the server using the All_DHCP_Relay_Agents_and_Servers address. */
/* More status codes see https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml */
/** DHCPv6 DUID types */
#define DHCP6_DUID_LLT 1 /* LLT: Link-layer Address Plus Time */
#define DHCP6_DUID_EN 2 /* EN: Enterprise number */
#define DHCP6_DUID_LL 3 /* LL: Link-layer Address */
#define DHCP6_DUID_UUID 4 /* UUID (RFC 6355) */
/* DHCPv6 options */
#define DHCP6_OPTION_CLIENTID 1
@@ -126,7 +124,11 @@ typedef enum {
#define DHCP6_OPTION_VENDOR_OPTS 17
#define DHCP6_OPTION_INTERFACE_ID 18
#define DHCP6_OPTION_RECONF_MSG 19
#define DHCP6_OPTION_ACCEPT 20
#define DHCP6_OPTION_RECONF_ACCEPT 20
/* More options see https://www.iana.org/assignments/dhcpv6-parameters/dhcpv6-parameters.xhtml */
#define DHCP6_OPTION_DNS_SERVERS 23 /* RFC 3646 */
#define DHCP6_OPTION_DOMAIN_LIST 24 /* RFC 3646 */
#define DHCP6_OPTION_SNTP_SERVERS 31 /* RFC 4075 */
#ifdef __cplusplus