// ------------------------------------------------------------------------
// The management thread function
+//
+// Note: 2007-01-15
+// This single management thread attempts to keep all configured
+// interfaces alive via DHCP. While this may be sufficient for
+// many systems, it falls short of perfect. There should probably
+// be a separate thread for each possible interface, along with
+// appropriate CDL to control how each inteface is managed.
+//
void dhcp_mgt_entry( cyg_addrword_t loop_on_failure )
{
int j;
+ bool any_interfaces_up;
+
while ( 1 ) {
while ( 1 ) {
cyg_semaphore_wait( &dhcp_needs_attention );
dhcp_halt(); // tear everything down
if ( !loop_on_failure )
return; // exit the thread/return
- init_all_network_interfaces(); // re-initialize
+ do {
+ init_all_network_interfaces(); // re-initialize
+ // If at least one interface is up, then the DHCP machine will run
+ any_interfaces_up = false;
+#ifdef CYGHWR_NET_DRIVER_ETH0
+ any_interfaces_up |= eth0_up;
+#endif
+#ifdef CYGHWR_NET_DRIVER_ETH1
+ any_interfaces_up |= eth1_up;
+#endif
+ } while (!any_interfaces_up);
for ( j = 0; j < CYGPKG_NET_NLOOP; j++ )
init_loopback_interface( j );
#ifdef CYGPKG_SNMPAGENT
cyg_handle_t dhcp_mgt_thread_h = 0;
cyg_thread dhcp_mgt_thread;
-#define STACK_SIZE (CYGNUM_HAL_STACK_SIZE_TYPICAL + sizeof(struct bootp))
-static cyg_uint8 dhcp_mgt_stack[ STACK_SIZE ];
+static cyg_uint8 dhcp_mgt_stack[ CYGPKG_NET_DHCP_THREAD_STACK_SIZE ];
void dhcp_start_dhcp_mgt_thread( void )
{
if ( ! dhcp_mgt_thread_h ) {
cyg_semaphore_init( &dhcp_needs_attention, 0 );
cyg_thread_create(
- CYGPKG_NET_DHCP_THREAD_PRIORITY, /* scheduling info (eg pri) */
- dhcp_mgt_entry, /* entry point function */
+ CYGPKG_NET_DHCP_THREAD_PRIORITY, /* scheduling info (eg pri) */
+ dhcp_mgt_entry, /* entry point function */
CYGOPT_NET_DHCP_DHCP_THREAD_PARAM, /* entry data */
- "DHCP lease mgt", /* optional thread name */
- dhcp_mgt_stack, /* stack base, NULL = alloc */
- STACK_SIZE, /* stack size, 0 = default */
- &dhcp_mgt_thread_h, /* returned thread handle */
- &dhcp_mgt_thread /* put thread here */
+ "DHCP lease mgt", /* optional thread name */
+ dhcp_mgt_stack, /* stack base, NULL = alloc */
+ CYGPKG_NET_DHCP_THREAD_STACK_SIZE, /* stack size, 0 = default */
+ &dhcp_mgt_thread_h, /* returned thread handle */
+ &dhcp_mgt_thread /* put thread here */
);
cyg_thread_resume(dhcp_mgt_thread_h);