providers/rdns: add configuration interface for rDNS timeout
This commit is contained in:
parent
3f2695ac86
commit
646e6567c7
2 changed files with 75 additions and 48 deletions
|
@ -496,7 +496,7 @@ add_conf_blacklist_timeout(const char *key, int parc, const char **parv)
|
|||
|
||||
if(timeout < 0)
|
||||
{
|
||||
warn_opers(L_CRIT, "BUG: timeout < 0 (value: %d)", timeout);
|
||||
warn_opers(L_CRIT, "BUG: blacklist timeout < 0 (value: %d)", timeout);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,50 +57,6 @@ static struct ev_entry *timeout_ev;
|
|||
static EVH timeout_dns_queries_event;
|
||||
static int rdns_timeout = 15;
|
||||
|
||||
|
||||
bool client_dns_init(void)
|
||||
{
|
||||
timeout_ev = rb_event_addish("timeout_dns_queries_event", timeout_dns_queries_event, NULL, 1);
|
||||
return (timeout_ev != NULL);
|
||||
}
|
||||
|
||||
void client_dns_destroy(void)
|
||||
{
|
||||
struct auth_client *auth;
|
||||
rb_dictionary_iter iter;
|
||||
|
||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||
{
|
||||
if(auth->data[PROVIDER_RDNS] != NULL)
|
||||
client_fail(auth, REPORT_FAIL);
|
||||
}
|
||||
|
||||
rb_event_delete(timeout_ev);
|
||||
}
|
||||
|
||||
bool client_dns_start(struct auth_client *auth)
|
||||
{
|
||||
struct user_query *query = rb_malloc(sizeof(struct user_query));
|
||||
|
||||
query->timeout = rb_current_time() + rdns_timeout;
|
||||
|
||||
auth->data[PROVIDER_RDNS] = query;
|
||||
|
||||
query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth);
|
||||
|
||||
notice_client(auth->cid, messages[REPORT_LOOKUP]);
|
||||
set_provider_on(auth, PROVIDER_RDNS);
|
||||
return true;
|
||||
}
|
||||
|
||||
void client_dns_cancel(struct auth_client *auth)
|
||||
{
|
||||
struct user_query *query = auth->data[PROVIDER_RDNS];
|
||||
|
||||
if(query != NULL)
|
||||
client_fail(auth, REPORT_FAIL);
|
||||
}
|
||||
|
||||
static void
|
||||
dns_answer_callback(const char *res, bool status, query_type type, void *data)
|
||||
{
|
||||
|
@ -119,7 +75,8 @@ dns_answer_callback(const char *res, bool status, query_type type, void *data)
|
|||
}
|
||||
|
||||
/* Timeout outstanding queries */
|
||||
static void timeout_dns_queries_event(void *notused)
|
||||
static void
|
||||
timeout_dns_queries_event(void *notused)
|
||||
{
|
||||
struct auth_client *auth;
|
||||
rb_dictionary_iter iter;
|
||||
|
@ -136,7 +93,8 @@ static void timeout_dns_queries_event(void *notused)
|
|||
}
|
||||
}
|
||||
|
||||
static void client_fail(struct auth_client *auth, dns_message report)
|
||||
static void
|
||||
client_fail(struct auth_client *auth, dns_message report)
|
||||
{
|
||||
struct user_query *query = auth->data[PROVIDER_RDNS];
|
||||
|
||||
|
@ -154,7 +112,8 @@ static void client_fail(struct auth_client *auth, dns_message report)
|
|||
provider_done(auth, PROVIDER_RDNS);
|
||||
}
|
||||
|
||||
static void client_success(struct auth_client *auth)
|
||||
static void
|
||||
client_success(struct auth_client *auth)
|
||||
{
|
||||
struct user_query *query = auth->data[PROVIDER_RDNS];
|
||||
|
||||
|
@ -167,6 +126,73 @@ static void client_success(struct auth_client *auth)
|
|||
provider_done(auth, PROVIDER_RDNS);
|
||||
}
|
||||
|
||||
static bool
|
||||
client_dns_init(void)
|
||||
{
|
||||
timeout_ev = rb_event_addish("timeout_dns_queries_event", timeout_dns_queries_event, NULL, 1);
|
||||
return (timeout_ev != NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
client_dns_destroy(void)
|
||||
{
|
||||
struct auth_client *auth;
|
||||
rb_dictionary_iter iter;
|
||||
|
||||
RB_DICTIONARY_FOREACH(auth, &iter, auth_clients)
|
||||
{
|
||||
if(auth->data[PROVIDER_RDNS] != NULL)
|
||||
client_fail(auth, REPORT_FAIL);
|
||||
}
|
||||
|
||||
rb_event_delete(timeout_ev);
|
||||
}
|
||||
|
||||
static bool
|
||||
client_dns_start(struct auth_client *auth)
|
||||
{
|
||||
struct user_query *query = rb_malloc(sizeof(struct user_query));
|
||||
|
||||
query->timeout = rb_current_time() + rdns_timeout;
|
||||
|
||||
auth->data[PROVIDER_RDNS] = query;
|
||||
|
||||
query->query = lookup_hostname(auth->c_ip, dns_answer_callback, auth);
|
||||
|
||||
notice_client(auth->cid, messages[REPORT_LOOKUP]);
|
||||
set_provider_on(auth, PROVIDER_RDNS);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
client_dns_cancel(struct auth_client *auth)
|
||||
{
|
||||
struct user_query *query = auth->data[PROVIDER_RDNS];
|
||||
|
||||
if(query != NULL)
|
||||
client_fail(auth, REPORT_FAIL);
|
||||
}
|
||||
|
||||
static void
|
||||
add_conf_dns_timeout(const char *key, int parc, const char **parv)
|
||||
{
|
||||
int timeout = atoi(parv[0]);
|
||||
|
||||
if(timeout < 0)
|
||||
{
|
||||
warn_opers(L_CRIT, "BUG: DNS timeout < 0 (value: %d)", timeout);
|
||||
return;
|
||||
}
|
||||
|
||||
rdns_timeout = timeout;
|
||||
}
|
||||
|
||||
struct auth_opts_handler rdns_options[] =
|
||||
{
|
||||
{ "dns_timeout", 1, add_conf_dns_timeout },
|
||||
{ NULL, 0, NULL },
|
||||
};
|
||||
|
||||
struct auth_provider rdns_provider =
|
||||
{
|
||||
.id = PROVIDER_RDNS,
|
||||
|
@ -175,4 +201,5 @@ struct auth_provider rdns_provider =
|
|||
.start = client_dns_start,
|
||||
.cancel = client_dns_cancel,
|
||||
.completed = NULL,
|
||||
.opt_handlers = rdns_options,
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue