rtr_server_SOURCES += configuration.c configuration.h
rtr_server_SOURCES += csv.c csv.h
rtr_server_SOURCES += line_file.c line_file.h
+rtr_server_SOURCES += updates_daemon.c updates_daemon.h
rtr_server_SOURCES += vrps.c vrps.h
rtr_server_SOURCES += rtr/pdu_handler.c rtr/pdu_handler.h
#define OPTNAME_LISTEN "listen"
#define OPTNAME_LISTEN_ADDRESS "address"
#define OPTNAME_LISTEN_PORT "port"
-#define OPTNAME_VRPS_LOCATION "vrpsLocation"
+#define OPTNAME_VRPS "vrps"
+#define OPTNAME_VRPS_LOCATION "location"
+#define OPTNAME_VRPS_CHECK_INTERVAL "checkInterval"
#define OPTNAME_RTR_INTERVAL "rtrInterval"
#define OPTNAME_RTR_INTERVAL_REFRESH "refresh"
#define OPTNAME_RTR_INTERVAL_RETRY "retry"
#define DEFAULT_ADDR NULL
#define DEFAULT_PORT "323"
-#define DEFAULT_VRPS NULL
+#define DEFAULT_VRPS_LOCATION NULL
+#define DEFAULT_VRPS_CHECK_INTERVAL 60
#define DEFAULT_REFRESH_INTERVAL 3600
#define DEFAULT_RETRY_INTERVAL 600
#define DEFAULT_EXPIRE_INTERVAL 7200
/* Protocol timing parameters ranges */
+#define MIN_VRPS_CHECK_INTERVAL 1
+#define MAX_VRPS_CHECK_INTERVAL 7200
#define MIN_REFRESH_INTERVAL 1
#define MAX_REFRESH_INTERVAL 86400
#define MIN_RETRY_INTERVAL 1
char *port;
/** VRPs (Validated ROA Payload) location */
char *vrps_location;
+ /** Interval used to look for updates at VRPs location */
+ int vrps_check_interval;
/** Intervals use at RTR v1 End of data PDU **/
int refresh_interval;
int retry_interval;
handle_json(json_t *root)
{
json_t *listen;
+ json_t *vrps;
json_t *interval;
char const *address;
char const *port;
- char const *vrps;
+ char const *vrps_location;
+ int vrps_check_interval;
int refresh_interval;
int retry_interval;
int expire_interval;
port = DEFAULT_PORT;
}
- error = json_get_string(root, OPTNAME_VRPS_LOCATION,
- DEFAULT_VRPS, &vrps);
- if (error)
- return error;
- config.vrps_location = str_clone(vrps);
+ vrps = json_object_get(root, OPTNAME_VRPS);
+ if (vrps != NULL) {
+ if (!json_is_object(vrps)) {
+ warnx("The '%s' element is not a JSON object.",
+ OPTNAME_VRPS);
+ return -EINVAL;
+ }
+
+ error = json_get_string(vrps, OPTNAME_VRPS_LOCATION,
+ DEFAULT_VRPS_LOCATION, &vrps_location);
+ if (error)
+ return error;
+ config.vrps_location = str_clone(vrps_location);
+
+ error = load_interval(vrps, OPTNAME_VRPS_CHECK_INTERVAL,
+ DEFAULT_VRPS_CHECK_INTERVAL, &vrps_check_interval,
+ MIN_VRPS_CHECK_INTERVAL, MAX_VRPS_CHECK_INTERVAL);
+ if (error)
+ return error;
+ config.vrps_check_interval = vrps_check_interval;
+ } else {
+ config.vrps_location = DEFAULT_VRPS_LOCATION;
+ config.vrps_check_interval = DEFAULT_VRPS_CHECK_INTERVAL;
+ }
interval = json_object_get(root, OPTNAME_RTR_INTERVAL);
if (interval != NULL) {
return config.vrps_location;
}
+int
+config_get_vrps_check_interval(void)
+{
+ return config.vrps_check_interval;
+}
+
int
config_get_refresh_interval(void)
{
struct addrinfo const *config_get_server_addrinfo(void);
char const *config_get_server_port(void);
char const *config_get_vrps_location(void);
+int config_get_vrps_check_interval(void);
int config_get_refresh_interval(void);
int config_get_retry_interval(void);
int config_get_expire_interval(void);
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
+#include <sys/stat.h>
#include "configuration.h"
#include "address.h"
return error;
}
-int
-csv_parse_vrps_file()
+static int
+load_vrps_file(bool check_update)
{
+
struct line_file *lfile;
+ struct stat attr;
+ time_t last_update;
char const *location;
int error;
if (error)
goto end1; /* Error msg already printed. */
+ // Look for the last update date
+ error = stat(location, &attr);
+ if (error) {
+ warn("Couldn't get last modified date of %s, skip update",
+ location);
+ goto end2;
+ }
+
+ last_update = attr.st_mtim.tv_nsec;
+ if (check_update && last_update <= get_vrps_last_modified_date())
+ goto end2;
+
error = load_vrps(lfile);
if (error)
goto end2;
+ set_vrps_last_modified_date(last_update);
+ // TODO Double check of date
end2:
lfile_close(lfile);
end1:
return error;
}
+
+int
+csv_parse_vrps_file()
+{
+ return load_vrps_file(false);
+}
+
+int
+csv_check_vrps_file()
+{
+ return load_vrps_file(true);
+}
#define SRC_CSV_H_
int csv_parse_vrps_file();
+int csv_check_vrps_file();
#endif /* SRC_CSV_H_ */
#include "rtr/rtr.h"
#include "configuration.h"
#include "csv.h"
+#include "updates_daemon.h"
#include "vrps.h"
/*
if (err)
goto end2;
+ err = updates_daemon_init();
+ if (err)
+ goto end2;
+
err = rtr_listen();
end2:
--- /dev/null
+#include "updates_daemon.h"
+
+#include <err.h>
+#include <errno.h>
+#include <pthread.h>
+#include <stdbool.h>
+#include <unistd.h>
+
+#include "csv.h"
+#include "configuration.h"
+
+static void *
+check_vrps_updates(void *param_void) {
+ do {
+ csv_check_vrps_file();
+ sleep(config_get_vrps_check_interval());
+ } while (true);
+
+ return NULL;
+}
+
+int
+updates_daemon_init(void) {
+ pthread_t thread;
+ errno = pthread_create(&thread, NULL, check_vrps_updates, NULL);
+ if (errno) {
+ warn("Could not spawn the update daemon thread");
+ return errno;
+ }
+ pthread_detach(thread);
+ return 0;
+}
--- /dev/null
+#ifndef SRC_UPDATES_DAEMON_H_
+#define SRC_UPDATES_DAEMON_H_
+
+int updates_daemon_init(void);
+
+#endif /* SRC_UPDATES_DAEMON_H_ */
#include "vrps.h"
-#include <time.h>
#include "array_list.h"
#define FLAG_WITHDRAWAL 0
u_int32_t current_serial;
u_int16_t v0_session_id;
u_int16_t v1_session_id;
+time_t last_modified_date;
int
deltas_db_init(void)
return get_delta_diff(delta0, delta1, result);
}
+void
+set_vrps_last_modified_date(time_t new_date)
+{
+ last_modified_date = new_date;
+}
+
u_int32_t
last_serial_number(void)
{
return v1_session_id;
return v0_session_id;
}
+
+time_t
+get_vrps_last_modified_date(void)
+{
+ return last_modified_date;
+}
#ifndef SRC_VRPS_H_
#define SRC_VRPS_H_
+#include <time.h>
#include <netinet/ip.h>
#define NO_DATA_AVAILABLE -2
void vrp_destroy(struct vrp *);
void delta_destroy(struct delta *);
void deltas_db_destroy(void);
+void set_vrps_last_modified_date(time_t);
u_int32_t last_serial_number(void);
u_int16_t current_session_id(u_int8_t);
+time_t get_vrps_last_modified_date(void);
#endif /* SRC_VRPS_H_ */