Dynamic Host Configuration Protocol client.
#include "lwip/opt.h"
#include "lwip/stats.h"
#include "lwip/mem.h"
#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/def.h"
#include "lwip/sys.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/dns.h"
#include "netif/etharp.h"
#include <string.h>
Functions | |
void | dhcp_arp_reply (struct netif *netif, ip_addr_t *addr) |
Match an ARP reply with the offered IP address. More... | |
static void | dhcp_bind (struct netif *netif) |
Bind the interface to the offered IP address. More... | |
static void | dhcp_check (struct netif *netif) |
Checks if the offered IP address is already in use. More... | |
void | dhcp_cleanup (struct netif *netif) |
Removes a struct dhcp from a netif. More... | |
void | dhcp_coarse_tmr () |
The DHCP timer that checks for lease renewal/rebind timeouts. More... | |
static err_t | dhcp_create_msg (struct netif *netif, struct dhcp *dhcp, u8_t message_type) |
Create a DHCP request, fill in common headers. More... | |
static err_t | dhcp_decline (struct netif *netif) |
Decline an offered lease. More... | |
static void | dhcp_delete_msg (struct dhcp *dhcp) |
Free previously allocated memory used to send a DHCP request. More... | |
static err_t | dhcp_discover (struct netif *netif) |
Start the DHCP process, discover a DHCP server. More... | |
void | dhcp_fine_tmr () |
DHCP transaction timeout handling. More... | |
static void | dhcp_handle_ack (struct netif *netif) |
Handle a DHCP ACK packet. More... | |
static void | dhcp_handle_nak (struct netif *netif) |
Back-off the DHCP client (because of a received NAK response). More... | |
static void | dhcp_handle_offer (struct netif *netif) |
Remember the configuration offered by a DHCP server. More... | |
void | dhcp_inform (struct netif *netif) |
Inform a DHCP server of our manual configuration. More... | |
void | dhcp_network_changed (struct netif *netif) |
Handle a possible change in the network configuration. More... | |
static void | dhcp_option (struct dhcp *dhcp, u8_t option_type, u8_t option_len) |
static void | dhcp_option_byte (struct dhcp *dhcp, u8_t value) |
static void | dhcp_option_long (struct dhcp *dhcp, u32_t value) |
static void | dhcp_option_short (struct dhcp *dhcp, u16_t value) |
static void | dhcp_option_trailer (struct dhcp *dhcp) |
Add a DHCP message trailer. More... | |
static err_t | dhcp_parse_reply (struct dhcp *dhcp, struct pbuf *p) |
Extract the DHCP message and the DHCP options. More... | |
static err_t | dhcp_rebind (struct netif *netif) |
Rebind with a DHCP server for an existing DHCP lease. More... | |
static err_t | dhcp_reboot (struct netif *netif) |
Enter REBOOTING state to verify an existing lease. More... | |
static void | dhcp_recv (void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port) |
If an incoming DHCP message is in response to us, then trigger the state machine. More... | |
err_t | dhcp_release (struct netif *netif) |
Release a DHCP lease. More... | |
err_t | dhcp_renew (struct netif *netif) |
Renew an existing DHCP lease at the involved DHCP server. More... | |
static err_t | dhcp_select (struct netif *netif) |
Select a DHCP server offer out of all offers. More... | |
static void | dhcp_set_state (struct dhcp *dhcp, u8_t new_state) |
void | dhcp_set_struct (struct netif *netif, struct dhcp *dhcp) |
Set a statically allocated struct dhcp to work with. More... | |
err_t | dhcp_start (struct netif *netif) |
Start DHCP negotiation for a network interface. More... | |
void | dhcp_stop (struct netif *netif) |
Remove the DHCP client from the interface. More... | |
static void | dhcp_t1_timeout (struct netif *netif) |
The renewal period has timed out. More... | |
static void | dhcp_t2_timeout (struct netif *netif) |
The rebind period has timed out. More... | |
static void | dhcp_timeout (struct netif *netif) |
A DHCP negotiation transaction, or ARP request, has timed out. More... | |
Variables | |
u8_t | dhcp_rx_options_given [DHCP_OPTION_IDX_MAX] |
Holds a flag which option was received and is contained in dhcp_rx_options_val, only valid while in dhcp_recv. More... | |
u32_t | dhcp_rx_options_val [DHCP_OPTION_IDX_MAX] |
Holds the decoded option values, only valid while in dhcp_recv. More... | |
#define dhcp_clear_all_options | ( | dhcp | ) | (memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given))) |
Referenced by dhcp_parse_reply().
#define dhcp_clear_option | ( | dhcp, | |
idx | |||
) | (dhcp_rx_options_given[idx] = 0) |
Referenced by dhcp_parse_reply().
#define dhcp_get_option_value | ( | dhcp, | |
idx | |||
) | (dhcp_rx_options_val[idx]) |
Referenced by dhcp_handle_ack(), dhcp_handle_offer(), dhcp_parse_reply(), and dhcp_recv().
#define dhcp_got_option | ( | dhcp, | |
idx | |||
) | (dhcp_rx_options_given[idx] = 1) |
Referenced by dhcp_parse_reply().
Default for DHCP_GLOBAL_XID is 0xABCD0000 This can be changed by defining DHCP_GLOBAL_XID and DHCP_GLOBAL_XID_HEADER, e.g.
#define DHCP_GLOBAL_XID_HEADER "stdlib.h" #define DHCP_GLOBAL_XID rand() DHCP_OPTION_MAX_MSG_SIZE is set to the MTU MTU is checked to be big enough in dhcp_start
Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_renew(), and dhcp_select().
#define DHCP_MAX_MSG_LEN_MIN_REQUIRED 576 |
Referenced by dhcp_start().
#define DHCP_MIN_REPLY_LEN 44 |
Minimum length for reply before packet is parsed.
Referenced by dhcp_recv().
#define dhcp_option_given | ( | dhcp, | |
idx | |||
) | (dhcp_rx_options_given[idx] != 0) |
Referenced by dhcp_handle_ack(), dhcp_handle_offer(), dhcp_parse_reply(), and dhcp_recv().
#define DHCP_OPTION_IDX_DNS_SERVER 8 |
Referenced by dhcp_handle_ack(), and dhcp_parse_reply().
#define DHCP_OPTION_IDX_LEASE_TIME 3 |
Referenced by dhcp_handle_ack(), and dhcp_parse_reply().
#define DHCP_OPTION_IDX_MAX (DHCP_OPTION_IDX_DNS_SERVER + DNS_MAX_SERVERS) |
Referenced by dhcp_parse_reply().
#define DHCP_OPTION_IDX_MSG_TYPE 1 |
Referenced by dhcp_parse_reply(), and dhcp_recv().
#define DHCP_OPTION_IDX_OVERLOAD 0 |
Option handling: options are parsed in dhcp_parse_reply and saved in an array where other functions can load them from.
This might be moved into the struct dhcp (not necessarily since lwIP is single-threaded and the array is only used while in recv callback).
Referenced by dhcp_parse_reply().
#define DHCP_OPTION_IDX_ROUTER 7 |
Referenced by dhcp_handle_ack(), and dhcp_parse_reply().
#define DHCP_OPTION_IDX_SERVER_ID 2 |
Referenced by dhcp_handle_offer(), and dhcp_parse_reply().
#define DHCP_OPTION_IDX_SUBNET_MASK 6 |
Referenced by dhcp_handle_ack(), and dhcp_parse_reply().
#define DHCP_OPTION_IDX_T1 4 |
Referenced by dhcp_handle_ack(), and dhcp_parse_reply().
#define DHCP_OPTION_IDX_T2 5 |
Referenced by dhcp_handle_ack(), and dhcp_parse_reply().
#define dhcp_set_option_value | ( | dhcp, | |
idx, | |||
val | |||
) | (dhcp_rx_options_val[idx] = (val)) |
Referenced by dhcp_parse_reply().
#define REBOOT_TRIES 2 |
Referenced by dhcp_timeout().
Match an ARP reply with the offered IP address.
if enabled, check whether the offered IP address is not in use, using ARP
netif | the network interface on which the reply was received |
addr | The IP address we received a reply from |
References netif::dhcp, DHCP_CHECKING, DHCP_DEBUG, dhcp_decline(), ip4_addr_get_u32, ip_addr_cmp, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), NULL, dhcp::offered_ip_addr, dhcp::state, and X32_F.
Referenced by etharp_arp_input().
Bind the interface to the offered IP address.
netif | network interface to bind to the offered address |
References netif::dhcp, DHCP_AUTOIP_COOP_STATE_OFF, DHCP_AUTOIP_COOP_STATE_ON, DHCP_BOUND, DHCP_COARSE_TIMER_SECS, DHCP_DEBUG, dhcp_set_state(), ip4_addr1, ip4_addr_get_u32, ip4_addr_set_u32, ip_addr_copy, ip_addr_get_network, ip_addr_isany, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), netif::name, netif_set_gw(), netif_set_ipaddr(), netif_set_netmask(), netif_set_up(), NULL, netif::num, PP_HTONL, timeout, U16_F, U32_F, and X32_F.
Referenced by dhcp_recv(), and dhcp_timeout().
Checks if the offered IP address is already in use.
It does so by sending an ARP request for the offered address and entering CHECKING state. If no ARP reply is received within a small interval, the address is assumed to be free for use by us.
netif | the netif under DHCP control |
References netif::dhcp, DHCP_CHECKING, DHCP_DEBUG, DHCP_FINE_TIMER_MSECS, dhcp_set_state(), ERR_OK, etharp_query(), LWIP_DBG_LEVEL_WARNING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, NULL, dhcp::offered_ip_addr, dhcp::request_timeout, dhcp::tries, and U16_F.
Referenced by dhcp_recv(), and dhcp_timeout().
Removes a struct dhcp from a netif.
ATTENTION: Only use this when not using dhcp_set_struct() to allocate the struct dhcp since the memory is passed back to the heap.
netif | the netif from which to remove the struct dhcp |
References netif::dhcp, LWIP_ASSERT, mem_free(), and NULL.
The DHCP timer that checks for lease renewal/rebind timeouts.
to be called every minute
References netif::dhcp, DHCP_DEBUG, dhcp_t1_timeout(), dhcp_t2_timeout(), LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif_list, netif::next, NULL, dhcp::t1_timeout, and dhcp::t2_timeout.
Referenced by dhcp_timer_coarse().
Create a DHCP request, fill in common headers.
netif | the netif under DHCP control |
dhcp | dhcp control struct |
message_type | message type of the request |
default global transaction identifier starting value (easy to match with a packet analyser). We simply increment for each new request. Predefine DHCP_GLOBAL_XID to a better value or a function call to generate one at runtime, any supporting function prototypes can be defined in DHCP_GLOBAL_XID_HEADER
References DHCP_BOOTREQUEST, DHCP_CHADDR_LEN, DHCP_DEBUG, DHCP_DECLINE, DHCP_FILE_LEN, DHCP_HTYPE_ETH, DHCP_INFORM, DHCP_MAGIC_COOKIE, dhcp_option(), dhcp_option_byte(), DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN, DHCP_OPTIONS_LEN, DHCP_REBINDING, DHCP_RENEWING, DHCP_REQUEST, DHCP_SNAME_LEN, ERR_ARG, ERR_MEM, ERR_OK, ERR_VAL, htonl, netif::hwaddr, netif::hwaddr_len, netif::ip_addr, ip_addr_copy, ip_addr_set_zero, pbuf::len, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), dhcp::msg_out, NULL, dhcp::options_out_len, dhcp::p_out, pbuf::payload, pbuf_alloc(), PBUF_RAM, PBUF_TRANSPORT, PP_HTONL, dhcp::state, dhcp::tries, X32_F, and dhcp::xid.
Referenced by dhcp_decline(), dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_reboot(), dhcp_release(), dhcp_renew(), and dhcp_select().
Decline an offered lease.
Tell the DHCP server we do not accept the offered address. One reason to decline the lease is when we find out the address is already in use by another host (through ARP).
netif | the netif under DHCP control |
References netif::dhcp, DHCP_BACKING_OFF, dhcp_create_msg(), DHCP_DEBUG, DHCP_DECLINE, dhcp_delete_msg(), DHCP_FINE_TIMER_MSECS, dhcp_option(), dhcp_option_long(), DHCP_OPTION_REQUESTED_IP, dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, ip4_addr_get_u32, IP_ADDR_BROADCAST, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, ntohl, dhcp::offered_ip_addr, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, dhcp::request_timeout, dhcp::tries, U16_F, and udp_sendto_if().
Referenced by dhcp_arp_reply().
Free previously allocated memory used to send a DHCP request.
dhcp | the dhcp struct to free the request from |
References LWIP_ASSERT, LWIP_ERROR(), dhcp::msg_out, NULL, dhcp::p_out, and pbuf_free().
Referenced by dhcp_decline(), dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_reboot(), dhcp_release(), dhcp_renew(), and dhcp_select().
Start the DHCP process, discover a DHCP server.
netif | the netif under DHCP control |
References netif::dhcp, DHCP_AUTOIP_COOP_STATE_OFF, DHCP_AUTOIP_COOP_STATE_ON, dhcp_create_msg(), DHCP_DEBUG, dhcp_delete_msg(), DHCP_DISCOVER, DHCP_FINE_TIMER_MSECS, DHCP_MAX_MSG_LEN, dhcp_option(), DHCP_OPTION_BROADCAST, dhcp_option_byte(), DHCP_OPTION_DNS_SERVER, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, DHCP_OPTION_PARAMETER_REQUEST_LIST, DHCP_OPTION_ROUTER, dhcp_option_short(), DHCP_OPTION_SUBNET_MASK, dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_SELECTING, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, IP_ADDR_BROADCAST, ip_addr_set_any, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_DHCP_AUTOIP_COOP_TRIES, dhcp::offered_ip_addr, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, dhcp::request_timeout, dhcp::tries, U16_F, and udp_sendto_if().
Referenced by dhcp_handle_nak(), dhcp_network_changed(), dhcp_start(), and dhcp_timeout().
DHCP transaction timeout handling.
to be called every half second
A DHCP server is expected to respond within a short period of time. This timer checks whether an outstanding DHCP request is timed out.
References netif::dhcp, DHCP_DEBUG, dhcp_timeout(), LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif_list, netif::next, NULL, and dhcp::request_timeout.
Referenced by dhcp_timer_fine().
Handle a DHCP ACK packet.
netif | the netif under DHCP control |
References netif::dhcp, dhcp_get_option_value, dhcp_option_given, DHCP_OPTION_IDX_DNS_SERVER, DHCP_OPTION_IDX_LEASE_TIME, DHCP_OPTION_IDX_ROUTER, DHCP_OPTION_IDX_SUBNET_MASK, DHCP_OPTION_IDX_T1, DHCP_OPTION_IDX_T2, DNS_MAX_SERVERS, htonl, ip4_addr_set_u32, ip_addr_copy, ip_addr_set_zero, dhcp::msg_in, dhcp::offered_gw_addr, dhcp::offered_ip_addr, dhcp::offered_sn_mask, dhcp::offered_t0_lease, dhcp::offered_t1_renew, dhcp::offered_t2_rebind, and dhcp::subnet_mask_given.
Referenced by dhcp_recv().
Back-off the DHCP client (because of a received NAK response).
Back-off the DHCP client because of a received NAK. Receiving a NAK means the client asked for something non-sensible, for example when it tries to renew a lease obtained on another network.
We clear any existing set IP address and restart DHCP negotiation afresh (as per RFC2131 3.2.3).
netif | the netif under DHCP control |
References netif::dhcp, DHCP_BACKING_OFF, DHCP_DEBUG, dhcp_discover(), dhcp_set_state(), IP_ADDR_ANY, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, netif_set_down(), netif_set_gw(), netif_set_ipaddr(), netif_set_netmask(), netif::num, and U16_F.
Referenced by dhcp_recv().
Remember the configuration offered by a DHCP server.
netif | the netif under DHCP control |
References netif::dhcp, DHCP_DEBUG, dhcp_get_option_value, dhcp_option_given, DHCP_OPTION_IDX_SERVER_ID, dhcp_select(), htonl, ip4_addr_get_u32, ip4_addr_set_u32, ip_addr_copy, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, dhcp::msg_in, netif::name, netif::num, dhcp::offered_ip_addr, dhcp::server_ip_addr, U16_F, and X32_F.
Referenced by dhcp_recv().
Inform a DHCP server of our manual configuration.
inform server of our manual IP address
This informs DHCP servers of our fixed IP address configuration by sending an INFORM message. It does not involve DHCP address configuration, it is just here to be nice to the network.
netif | The lwIP network interface |
References netif::dhcp, DHCP_CLIENT_PORT, dhcp_create_msg(), DHCP_DEBUG, dhcp_delete_msg(), DHCP_INFORM, DHCP_MAX_MSG_LEN, dhcp_option(), DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, dhcp_option_short(), dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, IP_ADDR_ANY, IP_ADDR_BROADCAST, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), NULL, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, SOF_BROADCAST, udp_bind(), udp_new(), udp_remove(), and udp_sendto_if().
Handle a possible change in the network configuration.
This enters the REBOOTING state to verify that the currently bound address is still valid.
References netif::dhcp, DHCP_AUTOIP_COOP_STATE_OFF, DHCP_AUTOIP_COOP_STATE_ON, DHCP_BOUND, dhcp_discover(), DHCP_OFF, DHCP_REBINDING, dhcp_reboot(), DHCP_REBOOTING, DHCP_RENEWING, netif_set_down(), dhcp::state, and dhcp::tries.
Referenced by netif_set_link_up().
References DHCP_OPTIONS_LEN, LWIP_ASSERT, dhcp::msg_out, and dhcp::options_out_len.
Referenced by dhcp_create_msg(), dhcp_decline(), dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_reboot(), dhcp_renew(), and dhcp_select().
References DHCP_OPTIONS_LEN, LWIP_ASSERT, dhcp::msg_out, and dhcp::options_out_len.
Referenced by dhcp_create_msg(), dhcp_discover(), dhcp_rebind(), dhcp_renew(), and dhcp_select().
References DHCP_OPTIONS_LEN, LWIP_ASSERT, dhcp::msg_out, and dhcp::options_out_len.
Referenced by dhcp_decline(), dhcp_rebind(), dhcp_reboot(), dhcp_renew(), and dhcp_select().
References DHCP_OPTIONS_LEN, LWIP_ASSERT, dhcp::msg_out, and dhcp::options_out_len.
Referenced by dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_reboot(), dhcp_renew(), and dhcp_select().
Add a DHCP message trailer.
Adds the END option to the DHCP message, and if necessary, up to three padding bytes.
dhcp | DHCP state structure |
References DHCP_MIN_OPTIONS_LEN, DHCP_OPTION_END, DHCP_OPTIONS_LEN, LWIP_ASSERT, LWIP_ERROR(), dhcp::msg_out, NULL, and dhcp::options_out_len.
Referenced by dhcp_decline(), dhcp_discover(), dhcp_inform(), dhcp_rebind(), dhcp_reboot(), dhcp_release(), dhcp_renew(), and dhcp_select().
Extract the DHCP message and the DHCP options.
Extract the DHCP message and the DHCP options, each into a contiguous piece of memory. As a DHCP message is variable sized by its options, and also allows overriding some fields for options, the easy approach is to first unfold the options into a conitguous piece of memory, and use that further on.
References DHCP_ACK, dhcp_clear_all_options, dhcp_clear_option, DHCP_DEBUG, DHCP_FILE_LEN, DHCP_FILE_OFS, dhcp_get_option_value, dhcp_got_option, DHCP_OPTION_DNS_SERVER, DHCP_OPTION_END, dhcp_option_given, DHCP_OPTION_IDX_DNS_SERVER, DHCP_OPTION_IDX_LEASE_TIME, DHCP_OPTION_IDX_MAX, DHCP_OPTION_IDX_MSG_TYPE, DHCP_OPTION_IDX_OVERLOAD, DHCP_OPTION_IDX_ROUTER, DHCP_OPTION_IDX_SERVER_ID, DHCP_OPTION_IDX_SUBNET_MASK, DHCP_OPTION_IDX_T1, DHCP_OPTION_IDX_T2, DHCP_OPTION_LEASE_TIME, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_OVERLOAD, DHCP_OPTION_PAD, DHCP_OPTION_ROUTER, DHCP_OPTION_SERVER_ID, DHCP_OPTION_SUBNET_MASK, DHCP_OPTION_T1, DHCP_OPTION_T2, DHCP_OPTIONS_OFS, DHCP_OVERLOAD_FILE, DHCP_OVERLOAD_SNAME, DHCP_OVERLOAD_SNAME_FILE, dhcp_set_option_value, DHCP_SNAME_LEN, DHCP_SNAME_OFS, DNS_MAX_SERVERS, ERR_BUF, ERR_OK, htonl, pbuf::len, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_MIN, dhcp::msg_in, pbuf::next, ntohl, NULL, pbuf::payload, pbuf_copy_partial(), pbuf::tot_len, and U16_F.
Referenced by dhcp_recv().
Rebind with a DHCP server for an existing DHCP lease.
netif | network interface which must rebind with a DHCP server |
References netif::dhcp, dhcp_create_msg(), DHCP_DEBUG, dhcp_delete_msg(), DHCP_FINE_TIMER_MSECS, DHCP_MAX_MSG_LEN, dhcp_option(), dhcp_option_byte(), DHCP_OPTION_HOSTNAME, dhcp_option_long(), DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, DHCP_OPTION_REQUESTED_IP, DHCP_OPTION_SERVER_ID, dhcp_option_short(), dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_REBINDING, DHCP_REQUEST, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, IP_ADDR_BROADCAST, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, ntohl, NULL, dhcp::offered_ip_addr, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, dhcp::request_timeout, dhcp::server_ip_addr, dhcp::tries, U16_F, and udp_sendto_if().
Referenced by dhcp_t2_timeout(), and dhcp_timeout().
Enter REBOOTING state to verify an existing lease.
netif | network interface which must reboot |
References netif::dhcp, dhcp_create_msg(), DHCP_DEBUG, dhcp_delete_msg(), DHCP_FINE_TIMER_MSECS, dhcp_option(), dhcp_option_long(), DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, DHCP_OPTION_REQUESTED_IP, dhcp_option_short(), dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_REBOOTING, DHCP_REQUEST, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, ip4_addr_get_u32, IP_ADDR_BROADCAST, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, ntohl, dhcp::offered_ip_addr, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, dhcp::request_timeout, dhcp::tries, U16_F, and udp_sendto_if().
Referenced by dhcp_network_changed(), and dhcp_timeout().
|
static |
If an incoming DHCP message is in response to us, then trigger the state machine.
References netif::dhcp, DHCP_ACK, dhcp_bind(), DHCP_BOOTREPLY, dhcp_check(), DHCP_DEBUG, dhcp_get_option_value, dhcp_handle_ack(), dhcp_handle_nak(), dhcp_handle_offer(), DHCP_MIN_REPLY_LEN, DHCP_NAK, DHCP_OFFER, dhcp_option_given, DHCP_OPTION_IDX_MSG_TYPE, dhcp_parse_reply(), DHCP_REBINDING, DHCP_REBOOTING, DHCP_RENEWING, DHCP_REQUESTING, DHCP_SELECTING, ERR_OK, netif::hwaddr, netif::hwaddr_len, ip4_addr1_16, ip4_addr2_16, ip4_addr3_16, ip4_addr4_16, pbuf::len, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_UNUSED_ARG, dhcp::msg_in, ntohl, NULL, pbuf::payload, pbuf_free(), dhcp::request_timeout, dhcp::state, pbuf::tot_len, U16_F, X16_F, X32_F, and dhcp::xid.
Referenced by dhcp_start().
Release a DHCP lease.
release the DHCP lease, usually called before dhcp_stop()
netif | network interface which must release its lease |
References netif::dhcp, dhcp_create_msg(), DHCP_DEBUG, dhcp_delete_msg(), DHCP_FINE_TIMER_MSECS, DHCP_OFF, dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_RELEASE, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, IP_ADDR_ANY, ip_addr_set_zero, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif_set_down(), netif_set_gw(), netif_set_ipaddr(), netif_set_netmask(), dhcp::offered_gw_addr, dhcp::offered_ip_addr, dhcp::offered_sn_mask, dhcp::offered_t0_lease, dhcp::offered_t1_renew, dhcp::offered_t2_rebind, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, dhcp::request_timeout, dhcp::server_ip_addr, dhcp::tries, U16_F, and udp_sendto_if().
Referenced by dhcp_timeout().
Renew an existing DHCP lease at the involved DHCP server.
enforce early lease renewal (not needed normally)
netif | network interface which must renew its lease |
References netif::dhcp, dhcp_create_msg(), DHCP_DEBUG, dhcp_delete_msg(), DHCP_FINE_TIMER_MSECS, DHCP_MAX_MSG_LEN, dhcp_option(), dhcp_option_byte(), DHCP_OPTION_HOSTNAME, dhcp_option_long(), DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, DHCP_OPTION_REQUESTED_IP, DHCP_OPTION_SERVER_ID, dhcp_option_short(), dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_RENEWING, DHCP_REQUEST, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, LWIP_ASSERT, LWIP_DBG_LEVEL_SERIOUS, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, ntohl, NULL, dhcp::offered_ip_addr, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, dhcp::request_timeout, dhcp::server_ip_addr, dhcp::tries, U16_F, and udp_sendto_if().
Referenced by dhcp_t1_timeout(), and dhcp_timeout().
Select a DHCP server offer out of all offers.
Simply select the first offer received.
netif | the netif under DHCP control |
References netif::dhcp, dhcp_create_msg(), DHCP_DEBUG, dhcp_delete_msg(), DHCP_FINE_TIMER_MSECS, DHCP_MAX_MSG_LEN, dhcp_option(), DHCP_OPTION_BROADCAST, dhcp_option_byte(), DHCP_OPTION_DNS_SERVER, DHCP_OPTION_HOSTNAME, dhcp_option_long(), DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN, DHCP_OPTION_PARAMETER_REQUEST_LIST, DHCP_OPTION_REQUESTED_IP, DHCP_OPTION_ROUTER, DHCP_OPTION_SERVER_ID, dhcp_option_short(), DHCP_OPTION_SUBNET_MASK, dhcp_option_trailer(), DHCP_OPTIONS_LEN, DHCP_REQUEST, DHCP_REQUESTING, DHCP_SERVER_PORT, dhcp_set_state(), ERR_OK, ip4_addr_get_u32, IP_ADDR_BROADCAST, LWIP_ASSERT, LWIP_DBG_LEVEL_WARNING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, netif::name, ntohl, NULL, netif::num, dhcp::offered_ip_addr, dhcp::options_out_len, dhcp::p_out, pbuf_realloc(), dhcp::pcb, dhcp::request_timeout, dhcp::server_ip_addr, dhcp::tries, U16_F, and udp_sendto_if().
Referenced by dhcp_handle_offer(), and dhcp_timeout().
References dhcp::request_timeout, dhcp::state, and dhcp::tries.
Referenced by dhcp_bind(), dhcp_check(), dhcp_decline(), dhcp_discover(), dhcp_handle_nak(), dhcp_inform(), dhcp_rebind(), dhcp_reboot(), dhcp_release(), dhcp_renew(), dhcp_select(), and dhcp_stop().
Set a statically allocated struct dhcp to work with.
Using this prevents dhcp_start to allocate it using mem_malloc.
netif | the netif for which to set the struct dhcp |
dhcp | (uninitialised) dhcp struct allocated by the application |
References netif::dhcp, LWIP_ASSERT, and NULL.
Start DHCP negotiation for a network interface.
start DHCP configuration
If no DHCP client instance was attached to this interface, a new client is created first. If a DHCP client instance was already present, it restarts negotiation.
netif | The lwIP network interface |
References netif::dhcp, DHCP_CLIENT_PORT, DHCP_DEBUG, dhcp_discover(), DHCP_MAX_MSG_LEN_MIN_REQUIRED, dhcp_recv(), DHCP_SERVER_PORT, dhcp_stop(), ERR_ARG, ERR_MEM, ERR_OK, netif::flags, IP_ADDR_ANY, LWIP_ASSERT, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), mem_malloc(), netif::mtu, netif::name, NETIF_FLAG_DHCP, NETIF_FLAG_ETHARP, NULL, netif::num, SOF_BROADCAST, U16_F, udp_bind(), udp_connect(), udp_new(), udp_recv(), and udp_remove().
Referenced by ethernet_configure_interface().
Remove the DHCP client from the interface.
stop DHCP configuration
netif | The network interface to stop DHCP on |
References netif::dhcp, DHCP_AUTOIP_COOP_STATE_OFF, DHCP_AUTOIP_COOP_STATE_ON, DHCP_DEBUG, DHCP_OFF, dhcp_set_state(), netif::flags, LWIP_ASSERT, LWIP_DBG_TRACE, LWIP_DEBUGF, LWIP_ERROR(), NETIF_FLAG_DHCP, NULL, and udp_remove().
Referenced by dhcp_start().
The renewal period has timed out.
netif | the netif under DHCP control |
References netif::dhcp, DHCP_BOUND, DHCP_DEBUG, dhcp_renew(), DHCP_RENEWING, DHCP_REQUESTING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, and dhcp::state.
Referenced by dhcp_coarse_tmr().
The rebind period has timed out.
netif | the netif under DHCP control |
References netif::dhcp, DHCP_BOUND, DHCP_DEBUG, dhcp_rebind(), DHCP_RENEWING, DHCP_REQUESTING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, and dhcp::state.
Referenced by dhcp_coarse_tmr().
A DHCP negotiation transaction, or ARP request, has timed out.
The timer that was started with the DHCP or ARP request has timed out, indicating no response was received in time.
netif | the netif under DHCP control |
References netif::dhcp, DHCP_BACKING_OFF, dhcp_bind(), dhcp_check(), DHCP_CHECKING, DHCP_DEBUG, dhcp_discover(), dhcp_rebind(), DHCP_REBINDING, dhcp_reboot(), DHCP_REBOOTING, dhcp_release(), dhcp_renew(), DHCP_RENEWING, DHCP_REQUESTING, dhcp_select(), DHCP_SELECTING, LWIP_DBG_STATE, LWIP_DBG_TRACE, LWIP_DEBUGF, REBOOT_TRIES, dhcp::state, and dhcp::tries.
Referenced by dhcp_fine_tmr().
u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX] |
Holds a flag which option was received and is contained in dhcp_rx_options_val, only valid while in dhcp_recv.
u32_t dhcp_rx_options_val[DHCP_OPTION_IDX_MAX] |
Holds the decoded option values, only valid while in dhcp_recv.