From 6352cb82cd1f66226aaf9b5645e996f6111a486e Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 11:09:55 +0300 Subject: [PATCH 01/13] utils.c : added miliseconds function --- lib/util.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/util.c b/lib/util.c index 1e0001ad..1e61b6eb 100644 --- a/lib/util.c +++ b/lib/util.c @@ -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 (seconds 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 * From 4f1daff6d0f1d97a2f85fc3dea3db0a96a0b7251 Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 11:11:49 +0300 Subject: [PATCH 02/13] freeradius-client.h : added timeout_ms added timeout_ms to SEND_DATA for miliseconds. --- include/freeradius-client.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/freeradius-client.h b/include/freeradius-client.h index e1c6a8f7..a2612b35 100644 --- a/include/freeradius-client.h +++ b/include/freeradius-client.h @@ -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 From 29807be8d8199d1057fba873bc8d3fdf317c5d28 Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 11:13:08 +0300 Subject: [PATCH 03/13] added timeout milisecond in configuration --- etc/radiusclient.conf.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/etc/radiusclient.conf.in b/etc/radiusclient.conf.in index 5db11cbe..1e8fc627 100644 --- a/etc/radiusclient.conf.in +++ b/etc/radiusclient.conf.in @@ -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 is suprass the radius_timeout. +radius_timeout_ms=0 From 455eb5627cda0649ba61cfa3f6fde86c004d7f35 Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 11:18:38 +0300 Subject: [PATCH 04/13] getting and setting timeout milisecond parameter --- lib/buildreq.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/buildreq.c b/lib/buildreq.c index fdcb2f4b..7f176239 100644 --- a/lib/buildreq.c +++ b/lib/buildreq.c @@ -25,7 +25,7 @@ * @param retries the number of retries. */ 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; @@ -34,6 +34,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 @@ -73,7 +74,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; @@ -129,7 +131,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; @@ -156,7 +158,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; @@ -258,7 +260,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; /* @@ -268,7 +271,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); From 687d899e54b61c353fa5a00a48ea005eb0b84da4 Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 11:23:55 +0300 Subject: [PATCH 05/13] sendserver.c : timeout with miliseconds --- lib/sendserver.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/sendserver.c b/lib/sendserver.c index ed9624ae..4ff065d7 100644 --- a/lib/sendserver.c +++ b/lib/sendserver.c @@ -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() - 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_ms() - 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)); From ce2e1ebbf04152188eb22e629e4b691c795c8a8d Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 11:28:16 +0300 Subject: [PATCH 06/13] buildreq.c : added comment --- lib/buildreq.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/buildreq.c b/lib/buildreq.c index 7f176239..adee9fae 100644 --- a/lib/buildreq.c +++ b/lib/buildreq.c @@ -23,6 +23,7 @@ * @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,int timeout_ms) From 4ee4ce28c8f0fa87b81974810b77492f11e5164f Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 11:47:41 +0300 Subject: [PATCH 07/13] rc_buildreq function added timeout miliseconds parameter --- include/freeradius-client.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/freeradius-client.h b/include/freeradius-client.h index a2612b35..a2d1dabb 100644 --- a/include/freeradius-client.h +++ b/include/freeradius-client.h @@ -472,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 *); From 888a3b75067bc3efc6f39b0daeb3b3b8043d859a Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 14:16:18 +0300 Subject: [PATCH 08/13] addition for miliseconds --- lib/options.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/options.h b/lib/options.h index 6587bdbc..64bb9136 100644 --- a/lib/options.h +++ b/lib/options.h @@ -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]))) From 9d0d7a52405eb41ec07b8ac554ffb1aab1cd9849 Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 14:20:25 +0300 Subject: [PATCH 09/13] testing configuration --- lib/config.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/config.c b/lib/config.c index a9ec2bdc..0721344e 100644 --- a/lib/config.c +++ b/lib/config.c @@ -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); From 92a09436850b8159c56f069f8bdc0c156b421762 Mon Sep 17 00:00:00 2001 From: Yasin Date: Wed, 7 Oct 2015 14:55:26 +0300 Subject: [PATCH 10/13] typo mistake --- etc/radiusclient.conf.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/radiusclient.conf.in b/etc/radiusclient.conf.in index 1e8fc627..4f4b8561 100644 --- a/etc/radiusclient.conf.in +++ b/etc/radiusclient.conf.in @@ -96,4 +96,4 @@ login_local /bin/login # radius_timeout with miliseconds. to active # this parameter needs to set bigger than 0 # it is suprass the radius_timeout. -radius_timeout_ms=0 +radius_timeout_ms 0 From 3b20391d4f51bbac3a006fe9fd4e8f44c19f0745 Mon Sep 17 00:00:00 2001 From: Yasin Date: Thu, 8 Oct 2015 08:59:04 +0300 Subject: [PATCH 11/13] fixed wrong function. --- lib/sendserver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sendserver.c b/lib/sendserver.c index 4ff065d7..5173b46c 100644 --- a/lib/sendserver.c +++ b/lib/sendserver.c @@ -399,14 +399,14 @@ int rc_send_server (rc_handle *rh, SEND_DATA *data, char *msg, unsigned flags) if(data->timeout_ms > 0){ start_time = rc_getctime_ms(); - for (timeout = data->timeout_ms; timeout > 0;timeout -= rc_getctime() - start_time) { + 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_ms() - start_time) { + for (timeout = data->timeout; timeout > 0;timeout -= rc_getctime() - start_time) { result = poll(&pfd, 1, timeout* 1000); if (result != -1 || errno != EINTR) break; From d71f0674668c789cb100d4cc2f950f50854f6ab1 Mon Sep 17 00:00:00 2001 From: Yasin Date: Thu, 8 Oct 2015 09:52:16 +0300 Subject: [PATCH 12/13] fixed description --- etc/radiusclient.conf.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/radiusclient.conf.in b/etc/radiusclient.conf.in index 4f4b8561..a2b34f35 100644 --- a/etc/radiusclient.conf.in +++ b/etc/radiusclient.conf.in @@ -95,5 +95,5 @@ login_local /bin/login # radius_timeout with miliseconds. to active # this parameter needs to set bigger than 0 -# it is suprass the radius_timeout. +# it suppress radius_timeout. radius_timeout_ms 0 From ad823806e2ee60aff3930aef3488411592d7b1b8 Mon Sep 17 00:00:00 2001 From: Yasin Date: Thu, 8 Oct 2015 09:53:20 +0300 Subject: [PATCH 13/13] fixed comment typo --- lib/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util.c b/lib/util.c index 1e61b6eb..737efd07 100644 --- a/lib/util.c +++ b/lib/util.c @@ -328,7 +328,7 @@ double rc_getctime(void) } /** Returns the current time as a double. * - * @return current time (seconds since epoch) expressed as + * @return current time (miliseconds since epoch) expressed as * double-precision floating point number. */ double rc_getctime_ms(void)