Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

radius_timeout_ms parameter added #67

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions etc/radiusclient.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,8 @@ bindaddr *
# program to execute for local login
# it must support the -f flag for preauthenticated login
login_local /bin/login

# radius_timeout with miliseconds. to active
# this parameter needs to set bigger than 0
# it suppress radius_timeout.
radius_timeout_ms 0
3 changes: 2 additions & 1 deletion include/freeradius-client.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ typedef struct send_data /* Used to pass information to sendserver() function */
int retries;
VALUE_PAIR *send_pairs; //!< More a/v pairs to send.
VALUE_PAIR *receive_pairs; //!< Where to place received a/v pairs.
int timeout_ms; //!< Session timeout in miliseconds
} SEND_DATA;

#ifndef MIN
Expand Down Expand Up @@ -471,7 +472,7 @@ VALUE_PAIR *rc_avpair_readin(rc_handle const *, FILE *);

/* buildreq.c */

void rc_buildreq(rc_handle const *, SEND_DATA *, int, char *, unsigned short, char *, int, int);
void rc_buildreq(rc_handle const *, SEND_DATA *, int, char *, unsigned short, char *, int, int,int);
unsigned char rc_get_id();
int rc_auth(rc_handle *, uint32_t, VALUE_PAIR *, VALUE_PAIR **, char *);
int rc_auth_proxy(rc_handle *, VALUE_PAIR *, VALUE_PAIR **, char *);
Expand Down
16 changes: 10 additions & 6 deletions lib/buildreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@
* @param secret the secret used by the server.
* @param timeout the timeout in seconds of a message.
* @param retries the number of retries.
* @param timeout_ms the timeout in miliseconds of a message.
*/
void rc_buildreq(rc_handle const *rh, SEND_DATA *data, int code, char *server, unsigned short port,
char *secret, int timeout, int retries)
char *secret, int timeout, int retries,int timeout_ms)
{
data->server = server;
data->secret = secret;
Expand All @@ -34,6 +35,7 @@ void rc_buildreq(rc_handle const *rh, SEND_DATA *data, int code, char *server, u
data->timeout = timeout;
data->retries = retries;
data->code = code;
data->timeout_ms=timeout_ms;
}

/** Generates a random ID
Expand Down Expand Up @@ -73,7 +75,8 @@ int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **r
double now = 0;
time_t dtime;
unsigned type;

int timeout_ms = rc_conf_int(rh, "radius_timeout_ms");

if (request_type != PW_ACCOUNTING_REQUEST) {
aaaserver = rc_conf_srv(rh, "authserver");
type = AUTH;
Expand Down Expand Up @@ -129,7 +132,7 @@ int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **r
data.receive_pairs = NULL;
}
rc_buildreq(rh, &data, request_type, aaaserver->name[i],
aaaserver->port[i], aaaserver->secret[i], timeout, retries);
aaaserver->port[i], aaaserver->secret[i], timeout, retries,timeout_ms);

if (request_type == PW_ACCOUNTING_REQUEST) {
dtime = now - start_time;
Expand All @@ -156,7 +159,7 @@ int rc_aaa(rc_handle *rh, uint32_t client_port, VALUE_PAIR *send, VALUE_PAIR **r
data.receive_pairs = NULL;
}
rc_buildreq(rh, &data, request_type, aaaserver->name[i],
aaaserver->port[i], aaaserver->secret[i], timeout, retries);
aaaserver->port[i], aaaserver->secret[i], timeout, retries,timeout_ms);

if (request_type == PW_ACCOUNTING_REQUEST) {
dtime = rc_getctime() - start_time;
Expand Down Expand Up @@ -258,7 +261,8 @@ int rc_check(rc_handle *rh, char *host, char *secret, unsigned short port, char
uint32_t service_type;
int timeout = rc_conf_int(rh, "radius_timeout");
int retries = rc_conf_int(rh, "radius_retries");

int timeout_ms = rc_conf_int(rh, "radius_timeout_ms");

data.send_pairs = data.receive_pairs = NULL;

/*
Expand All @@ -268,7 +272,7 @@ int rc_check(rc_handle *rh, char *host, char *secret, unsigned short port, char
service_type = PW_ADMINISTRATIVE;
rc_avpair_add(rh, &(data.send_pairs), PW_SERVICE_TYPE, &service_type, 0, 0);

rc_buildreq(rh, &data, PW_STATUS_SERVER, host, port, secret, timeout, retries);
rc_buildreq(rh, &data, PW_STATUS_SERVER, host, port, secret, timeout, retries,timeout_ms);
result = rc_send_server (rh, &data, msg, ACCT);

rc_avpair_free(data.receive_pairs);
Expand Down
5 changes: 5 additions & 0 deletions lib/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,11 @@ int test_config(rc_handle const *rh, char const *filename)
rc_log(LOG_ERR,"%s: radius_timeout <= 0 is illegal", filename);
return -1;
}
if (rc_conf_int(rh, "radius_timeout_ms") < 0)
{
rc_log(LOG_ERR,"%s: radius_timeout_ms < 0 is illegal", filename);
return -1;
}
if (rc_conf_int(rh, "radius_retries") <= 0)
{
rc_log(LOG_ERR,"%s: radius_retries <= 0 is illegal", filename);
Expand Down
1 change: 1 addition & 0 deletions lib/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ static OPTION config_options_default[] = {
{"bindaddr", OT_STR, ST_UNDEF, NULL},
/* local options */
{"login_local", OT_STR, ST_UNDEF, NULL},
{"radius_timeout_ms", OT_INT, ST_UNDEF, NULL},
};

#define NUM_OPTIONS ((sizeof(config_options_default))/(sizeof(config_options_default[0])))
24 changes: 17 additions & 7 deletions lib/sendserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,23 @@ int rc_send_server (rc_handle *rh, SEND_DATA *data, char *msg, unsigned flags)
pfd.fd = sockfd;
pfd.events = POLLIN;
pfd.revents = 0;
start_time = rc_getctime();
for (timeout = data->timeout; timeout > 0;
timeout -= rc_getctime() - start_time) {
result = poll(&pfd, 1, timeout * 1000);
if (result != -1 || errno != EINTR)
break;
}

if(data->timeout_ms > 0){
start_time = rc_getctime_ms();
for (timeout = data->timeout_ms; timeout > 0;timeout -= rc_getctime_ms() - start_time) {
result = poll(&pfd, 1, timeout );
if (result != -1 || errno != EINTR)
break;
}
}else{
start_time = rc_getctime();
for (timeout = data->timeout; timeout > 0;timeout -= rc_getctime() - start_time) {
result = poll(&pfd, 1, timeout* 1000);
if (result != -1 || errno != EINTR)
break;
}
}

if (result == -1)
{
rc_log(LOG_ERR, "rc_send_server: poll: %s", strerror(errno));
Expand Down
13 changes: 13 additions & 0 deletions lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,20 @@ double rc_getctime(void)

return timev.tv_sec + ((double)timev.tv_usec) / 1000000.0;
}
/** Returns the current time as a double.
*
* @return current time (miliseconds since epoch) expressed as
* double-precision floating point number.
*/
double rc_getctime_ms(void)
{
struct timeval timev;

if (gettimeofday(&timev, NULL) == -1)
return -1;

return (timev.tv_sec + ((double)timev.tv_usec) / 1000000.0)*1000.0;
}
/*
* Copyright (c) 1998 Todd C. Miller <[email protected]>
*
Expand Down