Changeset da10694 in rtems


Ignore:
Timestamp:
Dec 24, 2014, 3:14:50 AM (7 years ago)
Author:
Peter Dufault <dufault@…>
Branches:
4.11, 5, master
Children:
2573e69
Parents:
0a78992
git-author:
Peter Dufault <dufault@…> (12/24/14 03:14:50)
git-committer:
Gedare Bloom <gedare@…> (12/24/14 03:14:50)
Message:

libnetworking: Make rtems_dhcp_failsafe() run time configurable

rtems_dhcp_failsafe() can be configured at compile time with
various options. This change makes it possible to instead configure
it at runtime.

This will make it marginally larger. I haven't measured the difference
but I'll guess it's in the lower hundreds of bytes. The change could be
modified to leave it either compile time or run time configurable,
I prefer the simplicity of a single method.

closes #1905

Location:
cpukit/libnetworking/rtems
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/rtems/rtems_dhcp_failsafe.c

    r0a78992 rda10694  
    3131  * Optionally, after the interface is configured (either with DHCP or
    3232    statically), a task is started to monitor it.  When the interface remains
    33     disconnected (i.e. its IFF_RUNNING flag is off) for NETWORK_FAIL_TIMEOUT
     33    disconnected (i.e. its IFF_RUNNING flag is off) for network_fail_timeout
    3434    seconds, the dhcp lease renewal is stopped.  As soon as the interface is
    3535    connected again, DHCP is started again as above.
    36     If NETWORK_FAIL_TIMEOUT is set to 0, the monitor task is not started.
     36    If network_fail_timeout is set to 0, the monitor task is not started.
    3737
    3838  * Optionally, when the interface is disconnected, it is also brought down
    39     for NETWORK_DOWN_TIME seconds.  Since this possibly makes the IFF_RUNNING
     39    for network_down_time seconds.  Since this possibly makes the IFF_RUNNING
    4040    flag unuseable, the interface is brought up again before the flag is
    4141    polled.
    42     If NETWORK_DOWN_TIME is set to 0, the interface is not brought down.
    43 
    44   * Optionally, before DHCP is started, we wait for BROADCAST_DELAY seconds.
     42    If network_down_time is set to 0, the interface is not brought down.
     43
     44  * Optionally, before DHCP is started, we wait for broadcast_delay seconds.
    4545    This is necessary to allow some routers to perform spanning tree discovery.
    4646
     
    6161
    6262#include <rtems/dhcp.h>
     63#include <rtems/rtems_dhcp_failsafe.h>
    6364
    6465struct  proc;                   /* Unused parameter of some functions. */
     
    7475
    7576
    76 #define NETWORK_FAIL_TIMEOUT 5     /* the number of seconds before the interface is considered disconnected */
    77 #define NETWORK_DOWN_TIME 30       /* number of seconds the interface remains down */
    78 #define BROADCAST_DELAY 0          /* Delay (seconds) before broadcasts are sent */
    79 #define DHCP_MONITOR_PRIORITY 250  /* Low priority */
     77static int network_fail_timeout = RTEMS_DHCP_FAILSAFE_NETWORK_FAIL_TIMEOUT;
     78static int network_down_time = RTEMS_DHCP_FAILSAFE_NETWORK_DOWN_TIME;
     79static int broadcast_delay = RTEMS_DHCP_FAILSAFE_BROADCAST_DELAY;
     80static int dhcp_monitor_priority = RTEMS_DHCP_FAILSAFE_DHCP_MONITOR_PRIORITY;
     81
     82void rtems_bsdnet_dhcp_failsafe_config(
     83  int network_fail_timeout_,
     84  int network_down_time_,
     85  int broadcast_delay_,
     86  int dhcp_monitor_priority_
     87)
     88{
     89  network_fail_timeout = network_fail_timeout_;
     90  network_down_time = network_down_time_;
     91  broadcast_delay = broadcast_delay_;
     92  dhcp_monitor_priority = dhcp_monitor_priority_;
     93}
    8094
    8195/*
     
    118132
    119133
    120 #if NETWORK_DOWN_TIME
    121134static int
    122135dhcp_if_down (const char* ifname)
    123136{
    124   int flags;
     137  int16_t flags;
    125138  if (rtems_bsdnet_ifconfig (ifname, SIOCGIFFLAGS, &flags) < 0) {
    126139    printf ("Can't get flags for %s: %s\n", ifname, strerror (errno));
     
    137150  return 0;
    138151}
    139 #endif
    140152
    141153static int
    142154dhcp_if_up (const char* ifname)
    143155{
    144   int flags;
     156  int16_t flags;
    145157  if (rtems_bsdnet_ifconfig (ifname, SIOCGIFFLAGS, &flags) < 0) {
    146158    printf ("Can't get flags for %s: %s\n", ifname, strerror (errno));
     
    162174set_static_address (struct rtems_bsdnet_ifconfig *ifp)
    163175{
    164   short flags;
     176  int16_t flags;
    165177  struct sockaddr_in address;
    166178  struct sockaddr_in netmask;
     
    256268do_dhcp_init (struct rtems_bsdnet_ifconfig *ifp)
    257269{
    258 #if BROADCAST_DELAY
    259   /* Wait before sending broadcast. */
    260   rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(BROADCAST_DELAY * 1000));
    261 #endif
     270  if (broadcast_delay) {
     271    /* Wait before sending broadcast. */
     272    rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(broadcast_delay * 1000));
     273  }
    262274
    263275  printf ("starting dhcp client...\n");
     
    279291  char                         *ifname = ifp->name;
    280292  unsigned int                  downcount = 0;
    281   int                           ifflags;
     293  int16_t                       ifflags;
    282294  int                           must_renew = FALSE;
    283295
     
    295307      downcount = 0;
    296308    } else {
    297       if (downcount < NETWORK_FAIL_TIMEOUT) {
     309      if (downcount < network_fail_timeout) {
    298310        downcount++;
    299311
    300         if (downcount == NETWORK_FAIL_TIMEOUT) {
     312        if (downcount == network_fail_timeout) {
    301313          printf ("lost network connection...\n");
    302314          rtems_bsdnet_dhcp_down ();
    303315          must_renew = TRUE;
    304 #if NETWORK_DOWN_TIME
    305316          dhcp_if_down(ifname);
    306           rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(NETWORK_DOWN_TIME * 1000));
     317          rtems_task_wake_after(RTEMS_MILLISECONDS_TO_TICKS(network_down_time * 1000));
    307318          dhcp_if_up(ifname);
    308319          downcount = 0;
    309 #endif
    310320        }
    311321      }
     
    329339  rtems_id                      id;
    330340  struct rtems_bsdnet_ifconfig *ifp;
    331   int                           ifflags;
     341  int16_t                       ifflags;
    332342
    333343  /* Find a suitable interface */
     
    345355  do_dhcp_init(ifp);
    346356
    347 #if NETWORK_FAIL_TIMEOUT
    348   sc = rtems_task_create (rtems_build_name ('d','h','c','m'),
    349                           DHCP_MONITOR_PRIORITY,
    350                           2048,
    351                           RTEMS_PREEMPT |
    352                           RTEMS_NO_TIMESLICE |
    353                           RTEMS_NO_ASR |
    354                           RTEMS_INTERRUPT_LEVEL (0),
    355                           RTEMS_LOCAL,
    356                           &id);
    357 
    358   if (sc != RTEMS_SUCCESSFUL) {
    359     printf ("Failed to create dhcp monitor task, code %d\n", sc);
    360     return;
    361   }
    362 
    363   sc = rtems_task_start (id, dhcp_monitor_task, (rtems_task_argument) ifp);
    364 
    365   if (sc != RTEMS_SUCCESSFUL) {
    366     printf ("Failed to start dhcp monitor task, code %d\n", sc);
    367   }
    368 #endif
    369 }
    370 
     357  if (network_fail_timeout) {
     358    sc = rtems_task_create (rtems_build_name ('d','h','c','m'),
     359                            dhcp_monitor_priority,
     360                            2048,
     361                            RTEMS_PREEMPT |
     362                            RTEMS_NO_TIMESLICE |
     363                            RTEMS_NO_ASR |
     364                            RTEMS_INTERRUPT_LEVEL (0),
     365                            RTEMS_LOCAL,
     366                            &id);
     367
     368    if (sc != RTEMS_SUCCESSFUL) {
     369      printf ("Failed to create dhcp monitor task, code %d\n", sc);
     370      return;
     371    }
     372
     373    sc = rtems_task_start (id, dhcp_monitor_task, (rtems_task_argument) ifp);
     374
     375    if (sc != RTEMS_SUCCESSFUL) {
     376      printf ("Failed to start dhcp monitor task, code %d\n", sc);
     377    }
     378  }
     379}
     380
  • cpukit/libnetworking/rtems/rtems_dhcp_failsafe.h

    r0a78992 rda10694  
    1919#endif
    2020
     21/* Default settings for the DHCP failsafe.  They can be overridden
     22 * using rtems_bsdnet_dhcp_failsafe_config(); see that for descriptions.
     23 */
     24#ifndef RTEMS_DHCP_FAILSAFE_NETWORK_FAIL_TIMEOUT
     25#define RTEMS_DHCP_FAILSAFE_NETWORK_FAIL_TIMEOUT 5
     26#endif
     27
     28#ifndef RTEMS_DHCP_FAILSAFE_NETWORK_DOWN_TIME
     29#define RTEMS_DHCP_FAILSAFE_NETWORK_DOWN_TIME 30
     30#endif
     31
     32#ifndef RTEMS_DHCP_FAILSAFE_BROADCAST_DELAY
     33#define RTEMS_DHCP_FAILSAFE_BROADCAST_DELAY 0
     34#endif
     35
     36#ifndef RTEMS_DHCP_FAILSAFE_DHCP_MONITOR_PRIORITY
     37#define RTEMS_DHCP_FAILSAFE_DHCP_MONITOR_PRIORITY 250
     38#endif
     39
     40
    2141void rtems_bsdnet_do_dhcp_failsafe (void);
     42
     43/** Set the DHCP fallback options.  See the commentary at the top of the
     44 * implementation.
     45 @note Some of these options can be compile-time disabled - see the code.
     46 */
     47void rtems_bsdnet_dhcp_failsafe_config(
     48  int network_fail_timeout, /**< The number of seconds before the interface is
     49                              *  considered disconnected
     50                              */
     51  int network_down_time,    /**< The number of seconds the interface
     52                              *  remains down.
     53                              */
     54  int broadcast_delay,      /**< The delay in seconds before broadcasts
     55                              * are sent.
     56                              */
     57  int dhcp_monitor_priority /**< The monitor priority.*/
     58);
    2259
    2360#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.