int clients_add(int, struct sockaddr_storage, pthread_t);
void clients_update_serial(int, serial_t);
void clients_forget(int);
-typedef int (*clients_foreach_cb)(struct client const *, void *);
+typedef int (*clients_foreach_cb)(struct client *, void *);
int clients_foreach(clients_foreach_cb, void *);
int clients_get_min_serial(serial_t *);
int clients_get_addr(int, struct sockaddr_storage *);
bool
log_debug_enabled(void)
{
- return config_get_log_level() == LOG_DEBUG;
+ return config_get_log_level() >= LOG_DEBUG;
+}
+
+bool
+log_info_enabled(void)
+{
+ return config_get_log_level() >= LOG_INFO;
}
void
* error stack) cannot exceed 512 bytes at present.
*/
-/* Check if debug is enabled, useful to avoid boilerplate code */
+/*
+ * Check if debug or info are enabled, useful to avoid boilerplate code
+ */
bool log_debug_enabled(void);
+bool log_info_enabled(void);
/* Debug messages, useful for devs or to track a specific problem */
void pr_debug(const char *, ...) CHECK_FORMAT(1, 2);
#include "rtr/db/vrps.h"
static int
-send_notify(struct client const *client, void *arg)
+send_notify(struct client *client, void *arg)
{
serial_t *serial = arg;
int error;
return resize_deltas_db(&state.deltas, group);
}
-int
-vrps_update(bool *changed)
+static int
+__vrps_update(bool *changed)
{
struct db_table *old_base;
struct db_table *new_base;
return error;
}
+int
+vrps_update(bool *changed)
+{
+ time_t start, finish, exec_time;
+ serial_t serial;
+ int error;
+
+ /*
+ * This wrapper is mainly for log informational data, so if there's no
+ * need don't do unnecessary calls
+ */
+ if (!log_info_enabled())
+ return __vrps_update(changed);
+
+ pr_info("Starting validation.");
+ if (config_get_mode() == SERVER) {
+ error = get_last_serial_number(&serial);
+ if (!error)
+ pr_info("- Current serial number is %u.", serial);
+ }
+
+ time(&start);
+ error = __vrps_update(changed);
+ time(&finish);
+ exec_time = finish - start;
+
+ pr_info("Validation finished:");
+ rwlock_read_lock(&state_lock);
+ do {
+ if (state.base == NULL) {
+ rwlock_unlock(&state_lock);
+ pr_info("- Valid ROAs: 0");
+ pr_info("- Valid Router Keys: 0");
+ if (config_get_mode() == SERVER)
+ pr_info("- No serial number.");
+ break;
+ }
+
+ pr_info("- Valid ROAs: %u", db_table_roa_count(state.base));
+ pr_info("- Valid Router Keys: %u",
+ db_table_router_key_count(state.base));
+ if (config_get_mode() == SERVER) {
+ pr_info("- %s serial number is %u.",
+ serial == state.next_serial - 1 ? "Current" : "New",
+ state.next_serial - 1);
+ }
+ rwlock_unlock(&state_lock);
+ } while(0);
+ pr_info("- Real execution time: %ld secs.", exec_time);
+
+ return error;
+}
/**
* Please keep in mind that there is at least one errcode-aware caller. The most
* important ones are
print_close_failure(errno, fd);
}
+static void
+print_client_addr(struct sockaddr_storage *addr, char const *action, int fd)
+{
+ char buffer[INET6_ADDRSTRLEN];
+ pr_info("Client %s [ID %d]: %s", action, fd,
+ sockaddr2str(addr, buffer));
+}
+
/*
* The client socket threads' entry routine.
* @arg must be released.
break;
}
+ print_client_addr(¶m.addr, "closed", param.fd);
end_client(param.fd);
clients_forget(param.fd);
return -EINVAL;
}
- if (log_debug_enabled()) {
- char buffer[INET6_ADDRSTRLEN];
- pr_debug("Client accepted: %s",
- sockaddr2str(&client_addr, buffer));
- }
+ print_client_addr(&client_addr, "accepted", client_fd);
/*
* Note: My gut says that errors from now on (even the unknown
* Receive @arg to be called as a clients_foreach_cb
*/
static int
-kill_client(struct client const *client, void *arg)
+kill_client(struct client *client, void *arg)
{
end_client(client->fd);
+ print_client_addr(&(client->addr), "terminated", client->fd);
/* Don't call clients_forget to avoid deadlock! */
return 0;
}
if (error)
pr_err("Error %d while trying to update the ROA database.",
error);
- else
- pr_info("Validation finished.");
goto revert_clients_db; /* Error 0 it's ok */
}