Skip to content

Commit

Permalink
Merge branch 'radsecproxy-12'
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Mauchle committed Jan 12, 2018
2 parents 1e8f4c7 + 62a452e commit 9efb193
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 5 deletions.
2 changes: 2 additions & 0 deletions radsecproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,7 @@ int confclient_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
#endif
"DuplicateInterval", CONF_LINT, &dupinterval,
"addTTL", CONF_LINT, &addttl,
"tcpKeepalive", CONF_BLN, &conf->keepalive,
"rewrite", CONF_STR, &rewriteinalias,
"rewriteIn", CONF_STR, &conf->confrewritein,
"rewriteOut", CONF_STR, &conf->confrewriteout,
Expand Down Expand Up @@ -2908,6 +2909,7 @@ int confserver_cb(struct gconffile **cf, void *arg, char *block, char *opt, char
"CertificateNameCheck", CONF_BLN, &conf->certnamecheck,
#endif
"addTTL", CONF_LINT, &addttl,
"tcpKeepalive", CONF_BLN, &conf->keepalive,
"rewrite", CONF_STR, &rewriteinalias,
"rewriteIn", CONF_STR, &conf->confrewritein,
"rewriteOut", CONF_STR, &conf->confrewriteout,
Expand Down
12 changes: 10 additions & 2 deletions radsecproxy.conf.5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ blocktype name {
<literal>certificateNameCheck</literal>,
<literal>matchCertificateAttribute</literal>,
<literal>duplicateInterval</literal>, <literal>AddTTL</literal>,
<literal>tcpKeepalive</literal>
<literal>fticksVISCOUNTRY</literal>,
<literal>fticksVISINST</literal>, <literal>rewrite</literal>,
<literal>rewriteIn</literal>, <literal>rewriteOut</literal>, and
Expand Down Expand Up @@ -587,6 +588,11 @@ blocktype name {
that for details. Any value configured here overrides the basic
one when sending messages to this client.
</para>
<para>
The <literal>tcpKeepalive</literal> option enables TCP keepalives. If
keepalives are not answered within 30s the connection is considered
lost.
</para>
<para>
The <literal>fticksVISCOUNTRY</literal> option configures
clients eligible to F-Ticks logging as defined by the
Expand Down Expand Up @@ -682,7 +688,8 @@ blocktype name {
<literal>type</literal>, <literal>secret</literal>,
<literal>tls</literal>, <literal>certificateNameCheck</literal>,
<literal>matchCertificateAttribute</literal>,
<literal>AddTTL</literal>, <literal>rewrite</literal>,
<literal>AddTTL</literal>, <literal>tcpKeepalive</literal>,
<literal>rewrite</literal>,
<literal>rewriteIn</literal>, <literal>rewriteOut</literal>,
<literal>statusServer</literal>, <literal>retryCount</literal>,
<literal>dynamicLookupCommand</literal> and
Expand All @@ -704,7 +711,8 @@ blocktype name {
<literal>type</literal>, <literal>secret</literal>,
<literal>tls</literal>, <literal>certificateNameCheck</literal>,
<literal>matchCertificateAttribute</literal>,
<literal>AddTTL</literal>, <literal>rewrite</literal>,
<literal>AddTTL</literal>, <literal>tcpKeepalive</literal>,
<literal>rewrite</literal>,
<literal>rewriteIn</literal> and <literal>rewriteOut</literal>
are just as specified for the <literal>client block</literal>
above, except that <literal>defaultServer</literal> (and not
Expand Down
1 change: 1 addition & 0 deletions radsecproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ struct clsrvconf {
uint8_t dupinterval;
uint8_t certnamecheck;
uint8_t addttl;
uint8_t keepalive;
uint8_t loopprevention;
struct rewrite *rewritein;
struct rewrite *rewriteout;
Expand Down
14 changes: 12 additions & 2 deletions tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ int tcpconnect(struct server *server, struct timeval *when, int timeout, char *t

if (server->sock >= 0)
close(server->sock);
if ((server->sock = connecttcphostlist(server->conf->hostports, srcres)) >= 0)
if ((server->sock = connecttcphostlist(server->conf->hostports, srcres)) >= 0) {
if (server->conf->keepalive)
enable_keepalive(server->sock);
break;
}
}
server->connectionok = 1;
gettimeofday(&server->lastconnecttry, NULL);
Expand Down Expand Up @@ -221,15 +224,20 @@ void *tcpclientrd(void *arg) {
for (;;) {
/* yes, lastconnecttry is really necessary */
lastconnecttry = server->lastconnecttry;
buf = radtcpget(server->sock, 0);
buf = radtcpget(server->sock, server->dynamiclookuparg ? IDLE_TIMEOUT : 0);
if (!buf) {
if (server->dynamiclookuparg)
break;
tcpconnect(server, &lastconnecttry, 0, "tcpclientrd");
continue;
}

replyh(server, buf);
}
server->clientrdgone = 1;
pthread_mutex_lock(&server->newrq_mutex);
pthread_cond_signal(&server->newrq_cond);
pthread_mutex_unlock(&server->newrq_mutex);
return NULL;
}

Expand Down Expand Up @@ -328,6 +336,8 @@ void *tcpservernew(void *arg) {
if (conf) {
client = addclient(conf, 1);
if (client) {
if(conf->keepalive)
enable_keepalive(s);
client->sock = s;
client->addr = addr_copy((struct sockaddr *)&from);
tcpserverrd(client);
Expand Down
7 changes: 6 additions & 1 deletion tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ int tlsconnect(struct server *server, struct timeval *when, int timeout, char *t
if ((server->sock = connecttcphostlist(server->conf->hostports, srcres)) < 0)
continue;

if (server->conf->keepalive)
enable_keepalive(server->sock);

SSL_free(server->ssl);
server->ssl = NULL;
ctx = tlsgetctx(handle, server->conf->tlsconf);
Expand Down Expand Up @@ -422,14 +425,16 @@ void *tlsservernew(void *arg) {
cert = verifytlscert(ssl);
if (!cert)
goto exit;
accepted_tls = conf->tlsconf;
accepted_tls = conf->tlsconf;
}

while (conf) {
if (accepted_tls == conf->tlsconf && verifyconfcert(cert, conf)) {
X509_free(cert);
client = addclient(conf, 1);
if (client) {
if (conf->keepalive)
enable_keepalive(s);
client->ssl = ssl;
client->addr = addr_copy((struct sockaddr *)&from);
tlsserverrd(client);
Expand Down
23 changes: 23 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -123,6 +124,28 @@ void disable_DF_bit(int socket, struct addrinfo *res) {
}
}

void enable_keepalive(int socket) {
int optval;
socklen_t optlen = sizeof(optval);

optval = 3;
if(setsockopt(socket, SOL_TCP, TCP_KEEPCNT, &optval, optlen) < 0) {
debug(DBG_ERR, "enable_keepalive: setsockopt TCP_KEEPCNT failed");
}
optval = 10;
if(setsockopt(socket, SOL_TCP, TCP_KEEPIDLE, &optval, optlen) < 0) {
debug(DBG_ERR, "enable_keepalive: setsockopt TCP_KEEPIDLE %d failed", optval);
}
optval = 10;
if(setsockopt(socket, SOL_TCP, TCP_KEEPINTVL, &optval, optlen) < 0) {
debug(DBG_ERR, "enable_keepalive: setsockopt TCP_KEEPINTVL failed");
}
optval = 1;
if(setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) {
debug(DBG_ERR, "enable_keepalive: setsockopt SO_KEEPALIVE failed");
}
}

int bindtoaddr(struct addrinfo *addrinfo, int family, int reuse) {
int s, on = 1;
struct addrinfo *res;
Expand Down
1 change: 1 addition & 0 deletions util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void port_set(struct sockaddr *sa, uint16_t port);

void printfchars(char *prefixfmt, char *prefix, char *charfmt, uint8_t *chars, int len);
void disable_DF_bit(int socket, struct addrinfo *res);
void enable_keepalive(int socket);
int bindtoaddr(struct addrinfo *addrinfo, int family, int reuse);
int connecttcp(struct addrinfo *addrinfo, struct addrinfo *src, uint16_t timeout);

Expand Down

0 comments on commit 9efb193

Please sign in to comment.