Ticket #1384: dhcp-init-fail.diff

File dhcp-init-fail.diff, 6.4 KB (added by Chris Johns, on 02/20/09 at 08:40:35)

Fix dhcp init failure.

  • cpukit/libnetworking/nfs/bootp_subr.c

    RCS file: /usr1/CVS/rtems/cpukit/libnetworking/nfs/bootp_subr.c,v
    retrieving revision 1.25
    diff -p -u -u -r1.25 bootp_subr.c
    bootpc_call( 
    456456
    457457                } /* while secs */
    458458        } /* forever send/receive */
    459 
    460         printf("BOOTP timeout for server 0x%x\n",
    461                (int)ntohl(sin->sin_addr.s_addr));
    462 
     459        {
     460                uint32_t addr = ntohl(sin->sin_addr.s_addr);
     461        printf("BOOTP timeout for server %lu.%lu.%lu.%lu\n",
     462               (addr >> 24) & 0xff, (addr >> 16) & 0xff,
     463               (addr >> 8) & 0xff, addr & 0xff);
     464        }
    463465        error = ETIMEDOUT;
    464466        goto out;
    465467
    bootpc_fakeup_interface(struct ifreq *ir 
    510512  sin->sin_family = AF_INET;
    511513  sin->sin_addr.s_addr = INADDR_ANY;
    512514  error = ifioctl(so, SIOCSIFADDR, (caddr_t)ireq, procp);
    513   if (error) {
     515  /*
     516   * Ignore a File already exists (EEXIST) error code. This means a
     517   * route for the address is already present and is returned on
     518   * a second pass to here.
     519   */
     520  if (error && (error != EEXIST)) {
    514521    printf("bootpc_fakeup_interface: set if addr, error=%s\n", strerror(error));
    515522    return error;
    516523  }
    bootpc_fakeup_interface(struct ifreq *ir 
    541548    return error;
    542549  }
    543550 
    544  
    545551  /* Add default route to 0.0.0.0 so we can send data */
    546552 
    547553  bzero((caddr_t) &dst, sizeof(dst));
    bootpc_fakeup_interface(struct ifreq *ir 
    565571                    (struct sockaddr *) &mask,
    566572                    RTF_UP | RTF_STATIC
    567573                    , NULL);
    568   if (error)
    569     printf("bootpc_fakeup_interface: add default route, error=%d\n", error);
     574  if (error && error != EEXIST)
     575    printf("bootpc_fakeup_interface: add default route, error=%s\n",
     576           strerror(error));
     577 
    570578  return error;
    571579}
    572580
  • cpukit/libnetworking/rtems/rtems_dhcp.c

    RCS file: /usr1/CVS/rtems/cpukit/libnetworking/rtems/rtems_dhcp.c,v
    retrieving revision 1.2
    diff -p -u -u -r1.2 rtems_dhcp.c
    dhcp_task (rtems_task_argument _sdl) 
    697697  int                 error;
    698698  struct proc *procp = NULL;
    699699  int                 disconnected;
     700  rtems_status_code   ev_st;
    700701 
    701702  sdl = (struct sockaddr_dl *) _sdl;
    702703 
    703704  count = dhcp_elapsed_time;
    704705  disconnected = 0;
    705706 
    706 
    707   while (TRUE)
     707  while (true)
    708708  {
    709709    /*
    710710     * Sleep until the next poll
    711711     */
    712712    timeout = TOD_MILLISECONDS_TO_TICKS (1000);
    713     rtems_event_receive (RTEMS_EVENT_0,
    714                          RTEMS_WAIT | RTEMS_EVENT_ANY,
    715                          timeout, &event_out);
     713    ev_st = rtems_event_receive (RTEMS_EVENT_0,
     714                                 RTEMS_WAIT | RTEMS_EVENT_ANY,
     715                                 timeout, &event_out);
    716716
    717     if(event_out & RTEMS_EVENT_0) break;
     717    /*
     718     * Check if not a poll timeout. So when ANY event received, exit task.
     719     * Actually, only event RTEMS_EVENT_0 sent from rtem_dhcp_failsafe.c
     720     * if "failsafe" dhcp enabled when interface down.  Otherwise, no
     721     * event should occur, just timeout.
     722     */
     723    if(ev_st != RTEMS_TIMEOUT)
     724        break;
    718725
    719726    count++;
    720727
    dhcp_task (rtems_task_argument _sdl) 
    722729    {
    723730      rtems_bsdnet_semaphore_obtain ();
    724731     
    725       dhcp_request_req (&call, &dhcp_req, sdl, TRUE);
     732      dhcp_request_req (&call, &dhcp_req, sdl, true);
    726733
    727734      /*
    728735       * Send the Request.
    dhcp_init (int update_files) 
    886893  sprintf (ireq.ifr_name, "%s%d", ifp->if_name, ifp->if_unit);
    887894
    888895  if ((error = socreate (AF_INET, &so, SOCK_DGRAM, 0, procp)) != 0) {
    889     printf ("dhcpc_init: socreate, error=%d\n", error);
     896    printf ("dhcpc_init: socreate, error: %s\n", strerror(error));
    890897    return -1;
    891898  }
    892899
    dhcp_init (int update_files) 
    904911
    905912  if (!sdl){
    906913    printf ("dhcpc_init: Unable to find HW address\n");
     914    soclose (so);
    907915    return -1;
    908916  }
    909917  if (sdl->sdl_alen != EALEN) {
    910918    printf ("dhcpc_init: HW address len is %d, expected value is %d\n",
    911919           sdl->sdl_alen, EALEN);
     920    soclose (so);
    912921    return -1;
    913922  }
    914923
    dhcp_init (int update_files) 
    922931   */
    923932  error = bootpc_call (&call, &reply, procp);
    924933  if (error) {
    925     printf ("BOOTP call failed -- error %d\n", error);
     934    printf ("BOOTP call failed -- %s\n", strerror(error));
     935    soclose (so);
    926936    return -1;
    927937  }
    928938
    dhcp_init (int update_files) 
    931941   */
    932942  if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) {
    933943    printf ("DHCP server did not send Magic Cookie.\n");
     944    soclose (so);
    934945    return -1;
    935946  }
    936947
    dhcp_init (int update_files) 
    938949 
    939950  if (dhcp_message_type != DHCP_OFFER) {
    940951    printf ("DHCP server did not send a DHCP Offer.\n");
     952    soclose (so);
    941953    return -1;
    942954  }
    943955
    944956  /*
    945957   * Send a DHCP REQUEST
    946958   */
    947   dhcp_request_req (&call, &reply, sdl, TRUE);
     959  dhcp_request_req (&call, &reply, sdl, true);
    948960 
    949961  error = bootpc_call (&call, &reply, procp);
    950962  if (error) {
    951     printf ("BOOTP call failed -- error %d\n", error);
     963    printf ("BOOTP call failed -- %s\n", strerror(error));
     964    soclose (so);
    952965    return -1;
    953966  }
    954967
    dhcp_init (int update_files) 
    957970   */
    958971  if (memcmp (&reply.vend[0], dhcp_magic_cookie, sizeof (dhcp_magic_cookie)) != 0) {
    959972    printf ("DHCP server did not send Magic Cookie.\n");
     973    soclose (so);
    960974    return -1;
    961975  }
    962976 
    dhcp_init (int update_files) 
    964978 
    965979  if (dhcp_message_type != DHCP_ACK) {
    966980    printf ("DHCP server did not accept the DHCP request\n");
     981    soclose (so);
    967982    return -1;
    968983  }
    969984
    dhcp_init (int update_files) 
    11141129 */
    11151130void rtems_bsdnet_do_dhcp (void)
    11161131{
     1132  bool update = true;
    11171133  rtems_bsdnet_semaphore_obtain ();
    1118   while( dhcp_init (TRUE) < 0 ) {
     1134  while( dhcp_init (update) < 0 ) {
     1135    update = false;
    11191136    rtems_bsdnet_semaphore_release();
    11201137    rtems_task_wake_after(TOD_MILLISECONDS_TO_TICKS(1000));
    11211138    rtems_bsdnet_semaphore_obtain ();
    int rtems_bsdnet_do_dhcp_timeout( void ) 
    11281145  int return_value;
    11291146
    11301147  rtems_bsdnet_semaphore_obtain ();
    1131   return_value = dhcp_init (FALSE);
     1148  return_value = dhcp_init (false);
    11321149  rtems_bsdnet_semaphore_release ();
    11331150
    11341151  return return_value;