Skip to content

Commit

Permalink
Make response_window a struct timeval
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed May 20, 2014
1 parent 6596cbc commit 7af114b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 13 deletions.
2 changes: 2 additions & 0 deletions raddb/proxy.conf
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ home_server localhost {
#
# If the home server does not respond to a request within
# this time, this server will initiate "zombie_period".
# The response window can be a number between 0.001 and 60.000
# Though values on the low end are discouraged.
#
# The response window is large because responses MAY be slow,
# especially when proxying across the Internet.
Expand Down
2 changes: 1 addition & 1 deletion src/include/realms.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ typedef struct home_server {
fr_event_t *ev;
struct timeval when;

int response_window;
struct timeval response_window;
int max_outstanding; /* don't overload it */
int currently_outstanding;

Expand Down
11 changes: 6 additions & 5 deletions src/main/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ STATE_MACHINE_DECL(request_done)
when.tv_sec += request->home_server->coa_mrd;
} else
#endif
when.tv_sec += request->home_server->response_window;
timeradd(&when, &request->home_server->response_window, &when);

/*
* We haven't received all responses, AND there's still
Expand Down Expand Up @@ -3086,10 +3086,10 @@ static void mark_home_server_zombie(home_server_t *home, struct timeval *now)
home->num_sent_pings = 0;
home->num_received_pings = 0;

PROXY( "Marking home server %s port %d as zombie (it has not responded in %d seconds).",
PROXY( "Marking home server %s port %d as zombie (it has not responded in %d.%06d seconds).",
inet_ntop(home->ipaddr.af, &home->ipaddr.ipaddr,
buffer, sizeof(buffer)),
home->port, home->response_window);
home->port, (int) home->response_window.tv_sec, (int) home->response_window.tv_usec);

ping_home_server(home);
}
Expand Down Expand Up @@ -3289,14 +3289,15 @@ STATE_MACHINE_DECL(proxy_wait_for_reply)
* responding to other (better looking) packets.
*/
when = request->proxy->timestamp;
when.tv_sec += home->response_window;
timeradd(&when, &home->response_window, &when);

/*
* Not at the response window. Set the timer for
* that.
*/
if (timercmp(&when, &now, >)) {
RDEBUG("Expecting proxy response no later than %d seconds from now", home->response_window);
RDEBUG("Expecting proxy response no later than %d.%06d seconds from now",
(int) home->response_window.tv_sec, (int) home->response_window.tv_usec);
STATE_MACHINE_TIMER(FR_ACTION_TIMER);
return;
}
Expand Down
30 changes: 23 additions & 7 deletions src/main/realms.c
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ static CONF_PARSER home_server_config[] = {
{ "src_ipaddr", PW_TYPE_STRING_PTR,
0, &hs_srcipaddr, NULL },

{ "response_window", PW_TYPE_INTEGER,
{ "response_window", PW_TYPE_TIMEVAL,
offsetof(home_server_t,response_window), NULL, "30" },
{ "max_outstanding", PW_TYPE_INTEGER,
offsetof(home_server_t,max_outstanding), NULL, "65536" },
Expand Down Expand Up @@ -725,13 +725,28 @@ static int home_server_add(realm_config_t *rc, CONF_SECTION *cs)
FR_INTEGER_BOUND_CHECK("ping_interval", home->ping_interval, >=, 6);
FR_INTEGER_BOUND_CHECK("ping_interval", home->ping_interval, <=, 120);

FR_INTEGER_BOUND_CHECK("response_window", home->response_window, >=, 1);
FR_INTEGER_BOUND_CHECK("response_window", home->response_window, <=, 60);
FR_INTEGER_BOUND_CHECK("response_window", home->response_window, <=, main_config.max_request_time);
if (!home->response_window.tv_sec) {
int tmp = home->response_window.tv_usec; /* which isn't an integer */

FR_INTEGER_BOUND_CHECK("response_window microseconds", tmp, >=, 1000);
home->response_window.tv_usec = tmp;

} else {
int tmp = home->response_window.tv_sec; /* which isn't an integer */

FR_INTEGER_BOUND_CHECK("response_window", tmp, <=, 60);
FR_INTEGER_BOUND_CHECK("response_window", tmp, <=, main_config.max_request_time);
FR_INTEGER_BOUND_CHECK("response_window", tmp, <=, main_config.max_request_time);

if (home->response_window.tv_sec != tmp) {
home->response_window.tv_sec = tmp;
home->response_window.tv_usec = 0;
}
}

FR_INTEGER_BOUND_CHECK("zombie_period", home->zombie_period, >=, 1);
FR_INTEGER_BOUND_CHECK("zombie_period", home->zombie_period, <=, 120);
FR_INTEGER_BOUND_CHECK("zombie_period", home->zombie_period, >=, home->response_window);
FR_INTEGER_BOUND_CHECK("zombie_period", home->zombie_period, >=, (int) home->response_window.tv_sec);

FR_INTEGER_BOUND_CHECK("num_pings_to_alive", home->num_pings_to_alive, >=, 3);
FR_INTEGER_BOUND_CHECK("num_pings_to_alive", home->num_pings_to_alive, <=, 10);
Expand Down Expand Up @@ -1241,8 +1256,9 @@ static int old_server_add(realm_config_t *rc, CONF_SECTION *cs,
*/
home->max_outstanding = 65535*16;
home->zombie_period = rc->retry_delay * rc->retry_count;
if (home->zombie_period == 0) home->zombie_period =30;
home->response_window = home->zombie_period - 1;
if (home->zombie_period == 0) home->zombie_period = 30;
home->response_window.tv_sec = home->zombie_period - 1;
home->response_window.tv_usec = 0;

home->ping_check = HOME_PING_CHECK_NONE;

Expand Down

0 comments on commit 7af114b

Please sign in to comment.