diff options
-rw-r--r-- | cpukit/ChangeLog | 10 | ||||
-rw-r--r-- | cpukit/libnetworking/nfs/bootp_subr.c | 24 | ||||
-rw-r--r-- | cpukit/libnetworking/rtems/rtems_dhcp.c | 43 |
3 files changed, 56 insertions, 21 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index 477ce23fda..0eccbe93ea 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,5 +1,15 @@ 2009-04-28 Chris Johns <chrisj@rtems.org> + * libnetworking/nfs/bootp_subr.c: Fixed PR1384. The route set in + the initialise pass is not deleted so an exists error is + returned. Ignore the error. Print the server address as an IP + address not hex digits. + + * libnetworking/rtems/rtems_dhcp.c: Fixed + PR1338. Close the socket, handle the returned event flags. + +2009-04-28 Chris Johns <chrisj@rtems.org> + * sapi/include/confdefs.h: Add a prototype for Init with C linkage and define Init task command line arguments if confdefs.h provides an Init entry point. diff --git a/cpukit/libnetworking/nfs/bootp_subr.c b/cpukit/libnetworking/nfs/bootp_subr.c index 4e8fc94d76..7a0e8901f6 100644 --- a/cpukit/libnetworking/nfs/bootp_subr.c +++ b/cpukit/libnetworking/nfs/bootp_subr.c @@ -464,10 +464,12 @@ bootpc_call( } /* while secs */ } /* forever send/receive */ - - printf("BOOTP timeout for server 0x%x\n", - (int)ntohl(sin->sin_addr.s_addr)); - + { + uint32_t addr = ntohl(sin->sin_addr.s_addr); + printf("BOOTP timeout for server %lu.%lu.%lu.%lu\n", + (addr >> 24) & 0xff, (addr >> 16) & 0xff, + (addr >> 8) & 0xff, addr & 0xff); + } error = ETIMEDOUT; goto out; @@ -518,7 +520,12 @@ bootpc_fakeup_interface(struct ifreq *ireq,struct socket *so, sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; error = ifioctl(so, SIOCSIFADDR, (caddr_t)ireq, procp); - if (error) { + /* + * Ignore a File already exists (EEXIST) error code. This means a + * route for the address is already present and is returned on + * a second pass to here. + */ + if (error && (error != EEXIST)) { printf("bootpc_fakeup_interface: set if addr, error=%s\n", strerror(error)); return error; } @@ -549,7 +556,6 @@ bootpc_fakeup_interface(struct ifreq *ireq,struct socket *so, return error; } - /* Add default route to 0.0.0.0 so we can send data */ bzero((caddr_t) &dst, sizeof(dst)); @@ -573,8 +579,10 @@ bootpc_fakeup_interface(struct ifreq *ireq,struct socket *so, (struct sockaddr *) &mask, RTF_UP | RTF_STATIC , NULL); - if (error) - printf("bootpc_fakeup_interface: add default route, error=%d\n", error); + if (error && error != EEXIST) + printf("bootpc_fakeup_interface: add default route, error=%s\n", + strerror(error)); + return error; } diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c index 6bf3c68d96..490c11611c 100644 --- a/cpukit/libnetworking/rtems/rtems_dhcp.c +++ b/cpukit/libnetworking/rtems/rtems_dhcp.c @@ -689,24 +689,31 @@ dhcp_task (rtems_task_argument _sdl) int error; struct proc *procp = NULL; int disconnected; + rtems_status_code ev_st; sdl = (struct sockaddr_dl *) _sdl; count = dhcp_elapsed_time; disconnected = 0; - - while (TRUE) + while (true) { /* * Sleep until the next poll */ timeout = TOD_MILLISECONDS_TO_TICKS (1000); - rtems_event_receive (RTEMS_EVENT_0, - RTEMS_WAIT | RTEMS_EVENT_ANY, - timeout, &event_out); + ev_st = rtems_event_receive (RTEMS_EVENT_0, + RTEMS_WAIT | RTEMS_EVENT_ANY, + timeout, &event_out); - if(event_out & RTEMS_EVENT_0) break; + /* + * Check if not a poll timeout. So when ANY event received, exit task. + * Actually, only event RTEMS_EVENT_0 sent from rtem_dhcp_failsafe.c + * if "failsafe" dhcp enabled when interface down. Otherwise, no + * event should occur, just timeout. + */ + if(ev_st != RTEMS_TIMEOUT) + break; count++; @@ -714,7 +721,7 @@ dhcp_task (rtems_task_argument _sdl) { rtems_bsdnet_semaphore_obtain (); - dhcp_request_req (&call, &dhcp_req, sdl, TRUE); + dhcp_request_req (&call, &dhcp_req, sdl, true); /* * Send the Request. @@ -878,7 +885,7 @@ dhcp_init (int update_files) sprintf (ireq.ifr_name, "%s%d", ifp->if_name, ifp->if_unit); if ((error = socreate (AF_INET, &so, SOCK_DGRAM, 0, procp)) != 0) { - printf ("dhcpc_init: socreate, error=%d\n", error); + printf ("dhcpc_init: socreate, error: %s\n", strerror(error)); return -1; } @@ -896,11 +903,13 @@ dhcp_init (int update_files) if (!sdl){ printf ("dhcpc_init: Unable to find HW address\n"); + soclose (so); return -1; } if (sdl->sdl_alen != EALEN) { printf ("dhcpc_init: HW address len is %d, expected value is %d\n", sdl->sdl_alen, EALEN); + soclose (so); return -1; } @@ -914,7 +923,8 @@ dhcp_init (int update_files) */ error = bootpc_call (&call, &reply, procp); if (error) { - printf ("BOOTP call failed -- error %d\n", error); + printf ("BOOTP call failed -- %s\n", strerror(error)); + soclose (so); return -1; } @@ -923,6 +933,7 @@ dhcp_init (int update_files) */ if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) { printf ("DHCP server did not send Magic Cookie.\n"); + soclose (so); return -1; } @@ -930,17 +941,19 @@ dhcp_init (int update_files) if (dhcp_message_type != DHCP_OFFER) { printf ("DHCP server did not send a DHCP Offer.\n"); + soclose (so); return -1; } /* * Send a DHCP REQUEST */ - dhcp_request_req (&call, &reply, sdl, TRUE); + dhcp_request_req (&call, &reply, sdl, true); error = bootpc_call (&call, &reply, procp); if (error) { - printf ("BOOTP call failed -- error %d\n", error); + printf ("BOOTP call failed -- %s\n", strerror(error)); + soclose (so); return -1; } @@ -949,6 +962,7 @@ dhcp_init (int update_files) */ if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) { printf ("DHCP server did not send Magic Cookie.\n"); + soclose (so); return -1; } @@ -956,6 +970,7 @@ dhcp_init (int update_files) if (dhcp_message_type != DHCP_ACK) { printf ("DHCP server did not accept the DHCP request\n"); + soclose (so); return -1; } @@ -1106,8 +1121,10 @@ dhcp_init (int update_files) */ void rtems_bsdnet_do_dhcp (void) { + bool update = true; rtems_bsdnet_semaphore_obtain (); - while( dhcp_init (TRUE) < 0 ) { + while( dhcp_init (update) < 0 ) { + update = false; rtems_bsdnet_semaphore_release(); rtems_task_wake_after(TOD_MILLISECONDS_TO_TICKS(1000)); rtems_bsdnet_semaphore_obtain (); @@ -1120,7 +1137,7 @@ int rtems_bsdnet_do_dhcp_timeout( void ) int return_value; rtems_bsdnet_semaphore_obtain (); - return_value = dhcp_init (FALSE); + return_value = dhcp_init (false); rtems_bsdnet_semaphore_release (); return return_value; |