mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-11-04 14:29:39 +00:00
task #10139 (Prefer statically allocated memory): added autoip_set_struct() and dhcp_set_struct() to let autoip and dhcp work with user-allocated structs instead of callin mem_malloc
This commit is contained in:
parent
8768e4488a
commit
2e795d2706
@ -19,6 +19,11 @@ HISTORY
|
||||
|
||||
++ New features:
|
||||
|
||||
2010-02-12: Simon Goldschmidt
|
||||
* dhcp.c/.h, autoip.c/.h: task #10139 (Prefer statically allocated
|
||||
memory): added autoip_set_struct() and dhcp_set_struct() to let autoip
|
||||
and dhcp work with user-allocated structs instead of callin mem_malloc
|
||||
|
||||
2010-02-12: Simon Goldschmidt/Jeff Barber
|
||||
* tcp.c/h: patch #6865 (SO_REUSEADDR for TCP): if pcb.so_options has
|
||||
SOF_REUSEADDR set, allow binding to endpoint in TIME_WAIT
|
||||
|
@ -569,6 +569,25 @@ dhcp_handle_ack(struct netif *netif)
|
||||
#endif /* LWIP_DNS */
|
||||
}
|
||||
|
||||
/** Set a statically allocated struct dhcp to work with.
|
||||
* Using this prevents dhcp_start to allocate it using mem_malloc.
|
||||
*
|
||||
* @param netif the netif for which to set the struct dhcp
|
||||
* @param dhcp (uninitialised) dhcp struct allocated by the application
|
||||
*/
|
||||
void
|
||||
dhcp_set_struct(struct netif *netif, struct dhcp *dhcp)
|
||||
{
|
||||
LWIP_ASSERT("netif != NULL", netif != NULL);
|
||||
LWIP_ASSERT("dhcp != NULL", dhcp != NULL);
|
||||
LWIP_ASSERT("netif already has a struct dhcp set", netif->dhcp == NULL);
|
||||
|
||||
/* clear data structure */
|
||||
memset(dhcp, 0, sizeof(struct dhcp));
|
||||
/* dhcp_set_state(&dhcp, DHCP_OFF); */
|
||||
netif->dhcp = dhcp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start DHCP negotiation for a network interface.
|
||||
*
|
||||
@ -636,9 +655,7 @@ dhcp_start(struct netif *netif)
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): could not obtain pcb\n"));
|
||||
return ERR_MEM;
|
||||
}
|
||||
#if IP_SOF_BROADCAST
|
||||
dhcp->pcb->so_options |= SOF_BROADCAST;
|
||||
#endif /* IP_SOF_BROADCAST */
|
||||
/* set up local and remote port for the pcb */
|
||||
udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
|
||||
udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT);
|
||||
@ -688,9 +705,7 @@ dhcp_inform(struct netif *netif)
|
||||
return;
|
||||
}
|
||||
dhcp.pcb = pcb;
|
||||
#if IP_SOF_BROADCAST
|
||||
dhcp.pcb->so_options |= SOF_BROADCAST;
|
||||
#endif /* IP_SOF_BROADCAST */
|
||||
udp_bind(dhcp.pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_inform(): created new udp pcb\n"));
|
||||
}
|
||||
@ -821,7 +836,7 @@ dhcp_decline(struct netif *netif)
|
||||
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline(): set request timeout %"U16_F" msecs\n", msecs));
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
#endif /* DHCP_DOES_ARP_CHECK */
|
||||
|
||||
|
||||
/**
|
||||
|
@ -131,6 +131,25 @@ autoip_init(void)
|
||||
LWIP_DEBUGF(AUTOIP_DEBUG | LWIP_DBG_TRACE, ("autoip_init()\n"));
|
||||
}
|
||||
|
||||
/** Set a statically allocated struct autoip to work with.
|
||||
* Using this prevents autoip_start to allocate it using mem_malloc.
|
||||
*
|
||||
* @param netif the netif for which to set the struct autoip
|
||||
* @param dhcp (uninitialised) dhcp struct allocated by the application
|
||||
*/
|
||||
void
|
||||
autoip_set_struct(struct netif *netif, struct autoip *autoip)
|
||||
{
|
||||
LWIP_ASSERT("netif != NULL", netif != NULL);
|
||||
LWIP_ASSERT("autoip != NULL", autoip != NULL);
|
||||
LWIP_ASSERT("netif already has a struct autoip set", netif->autoip == NULL);
|
||||
|
||||
/* clear data structure */
|
||||
memset(autoip, 0, sizeof(struct autoip));
|
||||
/* autoip->state = AUTOIP_STATE_OFF; */
|
||||
netif->autoip = autoip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a IP address conflict after an ARP conflict detection
|
||||
*/
|
||||
|
@ -92,6 +92,9 @@ struct autoip
|
||||
/** Init srand, has to be called before entering mainloop */
|
||||
void autoip_init(void);
|
||||
|
||||
/** Set a struct autoip allocated by the application to work with */
|
||||
void autoip_set_struct(struct netif *netif, struct autoip *autoip);
|
||||
|
||||
/** Start AutoIP client */
|
||||
err_t autoip_start(struct netif *netif);
|
||||
|
||||
|
@ -105,6 +105,7 @@ PACK_STRUCT_END
|
||||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
void dhcp_set_struct(struct netif *netif, struct dhcp *dhcp);
|
||||
/** start DHCP configuration */
|
||||
err_t dhcp_start(struct netif *netif);
|
||||
/** enforce early lease renewal (not needed normally)*/
|
||||
|
Loading…
Reference in New Issue
Block a user