diff --git a/CHANGELOG b/CHANGELOG index abf90e6e..ddb6b670 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/src/core/dhcp.c b/src/core/dhcp.c index 648f3b23..086649fe 100644 --- a/src/core/dhcp.c +++ b/src/core/dhcp.c @@ -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 */ /** diff --git a/src/core/ipv4/autoip.c b/src/core/ipv4/autoip.c index 77d91f69..7e6e949c 100644 --- a/src/core/ipv4/autoip.c +++ b/src/core/ipv4/autoip.c @@ -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 */ diff --git a/src/include/ipv4/lwip/autoip.h b/src/include/ipv4/lwip/autoip.h index 9171e644..5b77c5e8 100644 --- a/src/include/ipv4/lwip/autoip.h +++ b/src/include/ipv4/lwip/autoip.h @@ -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); diff --git a/src/include/lwip/dhcp.h b/src/include/lwip/dhcp.h index 1b90a807..6edc8fa7 100644 --- a/src/include/lwip/dhcp.h +++ b/src/include/lwip/dhcp.h @@ -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)*/