prevent dhcp from starting when netif link is down (only when LWIP_DHCP_CHECK_LINK_UP==1, which is disabled by default for compatibility reasons)

This commit is contained in:
goldsimon 2014-12-19 16:04:48 +01:00
parent a883fe7b8e
commit 32c6f96000
4 changed files with 36 additions and 8 deletions

View File

@ -143,6 +143,11 @@ HISTORY
++ Bugfixes:
2014-12-19: Simon Goldschmidt
* opt.h, dhcp.h/.c: prevent dhcp from starting when netif link is down (only
when LWIP_DHCP_CHECK_LINK_UP==1, which is disabled by default for
compatibility reasons)
2014-12-17: Simon Goldschmidt
* tcp_out.c: fixed bug #43840 Checksum error for TCP_CHECKSUM_ON_COPY==1 for
no-copy data with odd length

View File

@ -627,14 +627,11 @@ err_t
dhcp_start(struct netif *netif)
{
struct dhcp *dhcp;
err_t result = ERR_OK;
err_t result;
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
dhcp = netif->dhcp;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void*)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
/* Remove the flag that says this netif is handled by DHCP,
it is set when we succeeded starting. */
netif->flags &= ~NETIF_FLAG_DHCP;
/* check hwtype of the netif */
if ((netif->flags & NETIF_FLAG_ETHARP) == 0) {
@ -648,6 +645,10 @@ dhcp_start(struct netif *netif)
return ERR_MEM;
}
/* Remove the flag that says this netif is handled by DHCP,
it is set when we succeeded starting. */
netif->flags &= ~NETIF_FLAG_DHCP;
/* no DHCP client attached yet? */
if (dhcp == NULL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): starting new DHCP client\n"));
@ -668,7 +669,7 @@ dhcp_start(struct netif *netif)
LWIP_ASSERT("pbuf p_out wasn't freed", dhcp->p_out == NULL);
LWIP_ASSERT("reply wasn't freed", dhcp->msg_in == NULL );
}
/* clear data structure */
memset(dhcp, 0, sizeof(struct dhcp));
/* dhcp_set_state(&dhcp, DHCP_OFF); */
@ -685,6 +686,16 @@ dhcp_start(struct netif *netif)
/* set up the recv callback and argument */
udp_recv(dhcp->pcb, dhcp_recv, netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): starting DHCP configuration\n"));
#if LWIP_DHCP_CHECK_LINK_UP
if (!netif_is_link_up(netif)) {
/* set state INIT and wait for dhcp_network_changed() to call dhcp_discover() */
dhcp_set_state(dhcp, DHCP_INIT);
netif->flags |= NETIF_FLAG_DHCP;
return ERR_OK;
}
#endif /* LWIP_DHCP_CHECK_LINK_UP */
/* (re)start the DHCP negotiation */
result = dhcp_discover(netif);
if (result != ERR_OK) {
@ -779,7 +790,9 @@ dhcp_network_changed(struct netif *netif)
/* stay off */
break;
default:
dhcp->tries = 0;
/* INIT/REQUESTING/CHECKING/BACKING_OFF restart with new 'rid' because the
state changes, SELECTING: continue with current 'rid' as we stay in the
same state */
#if LWIP_DHCP_AUTOIP_COOP
if(dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
autoip_stop(netif);

View File

@ -161,9 +161,9 @@ void dhcp_fine_tmr(void);
#define DHCP_REBINDING 4
#define DHCP_RENEWING 5
#define DHCP_SELECTING 6
#define DHCP_INFORMING 7
/* not yet implemented #define DHCP_INFORMING 7*/
#define DHCP_CHECKING 8
#define DHCP_PERMANENT 9
/* not yet implemented #define DHCP_PERMANENT 9*/
#define DHCP_BOUND 10
/** not yet implemented #define DHCP_RELEASING 11 */
#define DHCP_BACKING_OFF 12

View File

@ -751,6 +751,16 @@
#define DHCP_DOES_ARP_CHECK ((LWIP_DHCP) && (LWIP_ARP))
#endif
/**
* LWIP_DHCP_CHECK_LINK_UP==1: dhcp_start() only really starts if the netif has
* NETIF_FLAG_LINK_UP set in its flags. As this is only an optimization and
* netif drivers might not set this flag, the default is off. If enabled,
* netif_set_link_up() must be called to continue dhcp starting.
*/
#ifndef LWIP_DHCP_CHECK_LINK_UP
#define LWIP_DHCP_CHECK_LINK_UP 0
#endif
/**
* LWIP_DHCP_BOOTP_FILE==1: Store offered_si_addr and boot_file_name.
*/