Changeset 53914f2 in rtems-libbsd


Ignore:
Timestamp:
Apr 27, 2017, 4:58:09 AM (2 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
fd86c091b97759106da7355ce1dd81ebe030e285, f020f08430150c1656a0ad0a1de13699db9b980b
Children:
67cd18e
Parents:
4437573
Message:

rc_conf: Move the defaultroute_delay to the defaultroute processing.

If no default route is found atfer the delay timeout set the
defaultrouter value if present.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtemsbsd/rtems/rtems-bsd-rc-conf-net.c

    r4437573 r53914f2  
    341341 */
    342342static int
    343 defaultrouter(rtems_bsd_rc_conf* rc_conf, rtems_bsd_rc_conf_argc_argv* aa)
     343defaultrouter(rtems_bsd_rc_conf* rc_conf, rtems_bsd_rc_conf_argc_argv* aa, bool dhcp)
    344344{
    345345  int r;
     346
     347  if (dhcp) {
     348    char* end = NULL;
     349    int   delay = 30;
     350
     351    /*
     352     * See if a delay is specified else use default to 30 seconds. Wait for a
     353     * valid default route.
     354     */
     355    r = rtems_bsd_rc_conf_find(rc_conf, "defaultroute_delay", aa);
     356    if (r == 0 && aa->argc == 2) {
     357      delay = (int) strtol(aa->argv[1], &end, 10);
     358      if (*end != '\0') {
     359        fprintf(stderr, "error: defaultroute_delay: invalid delay value\n");
     360        delay = 30;
     361      }
     362    }
     363
     364    printf("Waiting %ds for default route interface: ", delay);
     365    fflush(stdout);
     366
     367    while (delay > 0) {
     368      struct sockaddr_in sin;
     369      struct sockaddr*   rti_info[RTAX_MAX];
     370
     371      --delay;
     372
     373      memset(&sin, 0, sizeof(sin));
     374      memset(&rti_info[0], 0, sizeof(rti_info));
     375      sin.sin_family = AF_INET;
     376      inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
     377
     378      r = rtems_get_route(&sin, rti_info);
     379      if (r == 0 && rti_info[RTAX_GATEWAY] != NULL) {
     380        break;
     381      }
     382      else if (r < 0 && errno != ESRCH) {
     383        fprintf(stderr,
     384                "error: get routes %d: %d %s\n", r, errno, strerror(errno));
     385      }
     386
     387      sleep(1);
     388    }
     389
     390    /*
     391     * We should print the interface but I cannot see how to get the interface
     392     * with the default route without a lot of code.
     393     */
     394    if (delay > 0) {
     395      printf("found.\n");
     396      return 0;
     397    }
     398
     399    printf("\nerror: no default route found, try defaultrouter\n");
     400  }
    346401
    347402  r = rtems_bsd_rc_conf_find(rc_conf, "defaultrouter", aa);
     
    357412    if (strcasecmp(aa->argv[1], "NO") != 0) {
    358413      const char* args[] = { "route", "add", "default", aa->argv[1], NULL };
    359       int         r;
    360414
    361415      rtems_bsd_rc_conf_print_cmd(rc_conf, "defaultrouter", 4, args);
     
    631685  rtems_task_priority priority = RTEMS_MAXIMUM_PRIORITY - 1;
    632686  char*               end = NULL;
    633   int                 delay = 30;
    634687  int                 r;
    635688
     
    693746
    694747  /*
    695    * See if a delay is specified else use default to 30 seconds. Wait for a
    696    * valid default route.
     748   * Let it run before moving on.
    697749   */
    698   r = rtems_bsd_rc_conf_find(rc_conf, "defaultroute_delay", aa);
    699   if (r == 0 && aa->argc == 2) {
    700     delay = (int) strtol(aa->argv[1], &end, 10);
    701     if (*end != '\0') {
    702       fprintf(stderr, "error: defaultroute_delay: invalid delay value\n");
    703       delay = 30;
    704     }
    705   }
    706 
    707   printf("Waiting %ds for default route interface: ", delay);
    708   fflush(stdout);
    709 
    710   while (delay > 0) {
    711     struct sockaddr_in sin;
    712     struct sockaddr*   rti_info[RTAX_MAX];
    713 
    714     --delay;
    715 
    716     memset(&sin, 0, sizeof(sin));
    717     memset(&rti_info[0], 0, sizeof(rti_info));
    718     sin.sin_family = AF_INET;
    719     inet_pton(AF_INET, "0.0.0.0", &sin.sin_addr);
    720 
    721     r = rtems_get_route(&sin, rti_info);
    722     if (r == 0 && rti_info[RTAX_GATEWAY] != NULL) {
    723       break;
    724     }
    725     else if (r < 0 && errno != ESRCH) {
    726       fprintf(stderr,
    727               "error: get routes %d: %d %s\n", r, errno, strerror(errno));
    728     }
    729 
    730     sleep(1);
    731   }
    732 
    733   /*
    734    * We should print the interface but I cannot see how to get the interface
    735    * with the default route without a lot of code.
    736    */
    737   if (delay > 0)
    738     printf("found.\n");
    739   else
    740     printf("\nerror: no default route found\n");
     750  sleep(1);
    741751
    742752  return 0;
     
    759769  show_result("ifaces", setup_interfaces(rc_conf, aa, ifap, &dhcp));
    760770  show_result("vlans", setup_vlans(rc_conf, aa, ifap, &dhcp));
    761   show_result("defaultrouter", defaultrouter(rc_conf, aa));
    762771  show_interfaces(ifap);
     772
    763773  if (dhcp)
    764774    show_result("dhcp", run_dhcp(rc_conf, aa));
     775  show_result("defaultrouter", defaultrouter(rc_conf, aa, dhcp));
    765776
    766777  free(ifap);
Note: See TracChangeset for help on using the changeset viewer.