Commit ecc6d5a0 authored by venaas's avatar venaas Committed by venaas
Browse files

cleaning up code

git-svn-id: https://svn.testnett.uninett.no/radsecproxy/trunk@428 e88ac4ed-0b26-0410-9574-a7f39faa03bf
parent f0728262
...@@ -82,7 +82,7 @@ static struct list *clconfs, *srvconfs; ...@@ -82,7 +82,7 @@ static struct list *clconfs, *srvconfs;
struct list *realms; struct list *realms;
struct hash *tlsconfs, *rewriteconfs; struct hash *tlsconfs, *rewriteconfs;
static struct addrinfo *srcprotores[4] = { NULL, NULL, NULL, NULL }; static struct addrinfo *srcprotores[RAD_PROTOCOUNT];
static pthread_mutex_t *ssl_locks = NULL; static pthread_mutex_t *ssl_locks = NULL;
static long *ssl_lock_count; static long *ssl_lock_count;
...@@ -116,6 +116,7 @@ static const struct protodefs protodefs[] = { ...@@ -116,6 +116,7 @@ static const struct protodefs protodefs[] = {
clientradputudp, /* clientradput */ clientradputudp, /* clientradput */
addclientudp, /* addclient */ addclientudp, /* addclient */
addserverextraudp, /* addserverextra */ addserverextraudp, /* addserverextra */
1, /* freesrcprotores */
initextraudp /* initextra */ initextraudp /* initextra */
}, },
{ "tls", /* TLS, assuming RAD_TLS defined as 1 */ { "tls", /* TLS, assuming RAD_TLS defined as 1 */
...@@ -134,6 +135,7 @@ static const struct protodefs protodefs[] = { ...@@ -134,6 +135,7 @@ static const struct protodefs protodefs[] = {
clientradputtls, /* clientradput */ clientradputtls, /* clientradput */
NULL, /* addclient */ NULL, /* addclient */
NULL, /* addserverextra */ NULL, /* addserverextra */
0, /* freesrcprotores */
NULL /* initextra */ NULL /* initextra */
}, },
{ "tcp", /* TCP, assuming RAD_TCP defined as 2 */ { "tcp", /* TCP, assuming RAD_TCP defined as 2 */
...@@ -152,6 +154,7 @@ static const struct protodefs protodefs[] = { ...@@ -152,6 +154,7 @@ static const struct protodefs protodefs[] = {
clientradputtcp, /* clientradput */ clientradputtcp, /* clientradput */
NULL, /* addclient */ NULL, /* addclient */
NULL, /* addserverextra */ NULL, /* addserverextra */
0, /* freesrcprotores */
NULL /* initextra */ NULL /* initextra */
}, },
{ "dtls", /* DTLS, assuming RAD_DTLS defined as 3 */ { "dtls", /* DTLS, assuming RAD_DTLS defined as 3 */
...@@ -170,6 +173,7 @@ static const struct protodefs protodefs[] = { ...@@ -170,6 +173,7 @@ static const struct protodefs protodefs[] = {
clientradputdtls, /* clientradput */ clientradputdtls, /* clientradput */
NULL, /* addclient */ NULL, /* addclient */
addserverextradtls, /* addserverextra */ addserverextradtls, /* addserverextra */
1, /* freesrcprotores */
initextradtls /* initextra */ initextradtls /* initextra */
}, },
{ NULL { NULL
...@@ -3545,11 +3549,10 @@ void getmainconfig(const char *configfile) { ...@@ -3545,11 +3549,10 @@ void getmainconfig(const char *configfile) {
debugx(1, DBG_ERR, "malloc failed"); debugx(1, DBG_ERR, "malloc failed");
if (!getgenericconfig(&cfs, NULL, if (!getgenericconfig(&cfs, NULL,
"ListenUDP", CONF_MSTR, &options.listenudp, "ListenUDP", CONF_MSTR, &options.listenargs[RAD_UDP],
"ListenTCP", CONF_MSTR, &options.listentcp, "ListenTCP", CONF_MSTR, &options.listenargs[RAD_TCP],
"ListenTLS", CONF_MSTR, &options.listentls, "ListenTLS", CONF_MSTR, &options.listenargs[RAD_TLS],
"ListenDTLS", CONF_MSTR, &options.listendtls, "ListenDTLS", CONF_MSTR, &options.listenargs[RAD_DTLS],
"ListenAccountingUDP", CONF_MSTR, &options.listenaccudp,
"SourceUDP", CONF_STR, &options.sourceudp, "SourceUDP", CONF_STR, &options.sourceudp,
"SourceTCP", CONF_STR, &options.sourcetcp, "SourceTCP", CONF_STR, &options.sourcetcp,
"SourceTLS", CONF_STR, &options.sourcetls, "SourceTLS", CONF_STR, &options.sourcetls,
...@@ -3655,7 +3658,7 @@ int main(int argc, char **argv) { ...@@ -3655,7 +3658,7 @@ int main(int argc, char **argv) {
debug_init("radsecproxy"); debug_init("radsecproxy");
debug_set_level(DEBUG_LEVEL); debug_set_level(DEBUG_LEVEL);
getargs(argc, argv, &foreground, &pretend, &loglevel, &configfile); getargs(argc, argv, &foreground, &pretend, &loglevel, &configfile);
if (loglevel) if (loglevel)
debug_set_level(loglevel); debug_set_level(loglevel);
...@@ -3688,6 +3691,7 @@ int main(int argc, char **argv) { ...@@ -3688,6 +3691,7 @@ int main(int argc, char **argv) {
pthread_sigmask(SIG_BLOCK, &sigset, NULL); pthread_sigmask(SIG_BLOCK, &sigset, NULL);
pthread_create(&sigth, NULL, sighandler, NULL); pthread_create(&sigth, NULL, sighandler, NULL);
memset(srcprotores, 0, sizeof(srcprotores));
for (entry = list_first(srvconfs); entry; entry = list_next(entry)) { for (entry = list_first(srvconfs); entry; entry = list_next(entry)) {
srvconf = (struct clsrvconf *)entry->data; srvconf = (struct clsrvconf *)entry->data;
if (srvconf->dynamiclookupcommand) if (srvconf->dynamiclookupcommand)
...@@ -3698,29 +3702,16 @@ int main(int argc, char **argv) { ...@@ -3698,29 +3702,16 @@ int main(int argc, char **argv) {
(void *)(srvconf->servers))) (void *)(srvconf->servers)))
debugx(1, DBG_ERR, "pthread_create failed"); debugx(1, DBG_ERR, "pthread_create failed");
} }
/* srcprotores for UDP no longer needed */
if (srcprotores[RAD_UDP]) {
freeaddrinfo(srcprotores[RAD_UDP]);
srcprotores[RAD_UDP] = NULL;
}
for (i = 0; protodefs[i].name; i++) for (i = 0; protodefs[i].name; i++) {
if (protodefs[i].freesrcprotores && srcprotores[i]) {
freeaddrinfo(srcprotores[i]);
srcprotores[i] = NULL;
}
if (protodefs[i].initextra) if (protodefs[i].initextra)
protodefs[i].initextra(); protodefs[i].initextra();
if (find_clconf_type(i, NULL))
if (find_clconf_type(RAD_TCP, NULL)) createlisteners(i, options.listenargs[i]);
createlisteners(RAD_TCP, options.listentcp);
if (find_clconf_type(RAD_TLS, NULL))
createlisteners(RAD_TLS, options.listentls);
if (find_clconf_type(RAD_DTLS, NULL))
createlisteners(RAD_DTLS, options.listendtls);
if (find_clconf_type(RAD_UDP, NULL)) {
createlisteners(RAD_UDP, options.listenudp);
if (options.listenaccudp)
createlisteners(RAD_UDP, options.listenaccudp);
} }
/* just hang around doing nothing, anything to do here? */ /* just hang around doing nothing, anything to do here? */
......
...@@ -26,13 +26,10 @@ ...@@ -26,13 +26,10 @@
#define RAD_TLS 1 #define RAD_TLS 1
#define RAD_TCP 2 #define RAD_TCP 2
#define RAD_DTLS 3 #define RAD_DTLS 3
#define RAD_PROTOCOUNT 4
struct options { struct options {
char **listenudp; char **listenargs[RAD_PROTOCOUNT];
char **listentcp;
char **listentls;
char **listendtls;
char **listenaccudp;
char *sourceudp; char *sourceudp;
char *sourcetcp; char *sourcetcp;
char *sourcetls; char *sourcetls;
...@@ -194,6 +191,7 @@ struct protodefs { ...@@ -194,6 +191,7 @@ struct protodefs {
int (*clientradput)(struct server *, unsigned char *); int (*clientradput)(struct server *, unsigned char *);
void (*addclient)(struct client *); void (*addclient)(struct client *);
void (*addserverextra)(struct clsrvconf *); void (*addserverextra)(struct clsrvconf *);
uint8_t freesrcprotores;
void (*initextra)(); void (*initextra)();
}; };
......
...@@ -169,23 +169,11 @@ unsigned char *radudpget(int s, struct client **client, struct server **server, ...@@ -169,23 +169,11 @@ unsigned char *radudpget(int s, struct client **client, struct server **server,
int clientradputudp(struct server *server, unsigned char *rad) { int clientradputudp(struct server *server, unsigned char *rad) {
size_t len; size_t len;
struct sockaddr_storage sa;
struct sockaddr *sap;
struct clsrvconf *conf = server->conf; struct clsrvconf *conf = server->conf;
uint16_t port;
len = RADLEN(rad); len = RADLEN(rad);
port = port_get(conf->addrinfo->ai_addr); if (sendto(server->sock, rad, len, 0, conf->addrinfo->ai_addr, conf->addrinfo->ai_addrlen) >= 0) {
debug(DBG_DBG, "clienradputudp: sent UDP of length %d to %s port %d", len, conf->host, port_get(conf->addrinfo->ai_addr));
if (*rad == RAD_Accounting_Request) {
sap = (struct sockaddr *)&sa;
memcpy(sap, conf->addrinfo->ai_addr, conf->addrinfo->ai_addrlen);
port_set(sap, ++port);
} else
sap = conf->addrinfo->ai_addr;
if (sendto(server->sock, rad, len, 0, sap, conf->addrinfo->ai_addrlen) >= 0) {
debug(DBG_DBG, "clienradputudp: sent UDP of length %d to %s port %d", len, conf->host, port);
return 1; return 1;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment