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 += notify.c notify.h
rtr_server_SOURCES += updates_daemon.c updates_daemon.h
rtr_server_SOURCES += vrps.c vrps.h
#include <err.h>
#include <errno.h>
-#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
}
static int
-load_vrps_file(bool check_update)
+load_vrps_file(bool check_update, bool *updated)
{
struct line_file *lfile;
error = load_vrps(lfile);
if (error)
goto end2;
+
+ if (updated != NULL)
+ *updated = check_update && last_update > get_vrps_last_modified_date();
+
set_vrps_last_modified_date(last_update);
// TODO Double check of date
int
csv_parse_vrps_file()
{
- return load_vrps_file(false);
+ return load_vrps_file(false, NULL);
}
int
-csv_check_vrps_file()
+csv_check_vrps_file(bool *updated)
{
- return load_vrps_file(true);
+ return load_vrps_file(true, updated);
}
#ifndef SRC_CSV_H_
#define SRC_CSV_H_
+#include <stdbool.h>
+
int csv_parse_vrps_file();
-int csv_check_vrps_file();
+int csv_check_vrps_file(bool *);
#endif /* SRC_CSV_H_ */
--- /dev/null
+#include "notify.h"
+
+#include <err.h>
+#include "rtr/pdu_sender.h"
+#include "clients.h"
+#include "vrps.h"
+
+static int
+send_notify(int fd, u_int8_t rtr_version)
+{
+ struct sender_common common;
+ u_int32_t serial;
+ u_int16_t session_id;
+
+ serial = last_serial_number();
+ session_id = current_session_id(rtr_version);
+ init_sender_common(&common, fd, rtr_version, &session_id, &serial, NULL);
+ return send_serial_notify_pdu(&common);
+}
+
+void
+notify_clients()
+{
+ struct client *clients, *ptr;
+ size_t clients_len;
+ int i, error;
+
+ clients_len = client_list(&clients);
+ ptr = clients;
+ for (i = 0; i < clients_len; i++, ptr++) {
+ /* Send Serial Notify PDU */
+ error = send_notify(ptr->fd, ptr->rtr_version);
+ /* Error? Log it */
+ if (error)
+ err(error, "Error sending notify PDU");
+ }
+}
--- /dev/null
+#ifndef SRC_NOTIFY_H_
+#define SRC_NOTIFY_H_
+
+void notify_clients();
+
+#endif /* SRC_NOTIFY_H_ */
void init_sender_common(struct sender_common *, int, u_int8_t, u_int16_t *,
u_int32_t *, u_int32_t *);
+int send_serial_notify_pdu(struct sender_common *);
int send_cache_reset_pdu(struct sender_common *);
int send_cache_response_pdu(struct sender_common *);
int send_payload_pdus(struct sender_common *);
#include "csv.h"
#include "configuration.h"
+#include "notify.h"
static void *
check_vrps_updates(void *param_void) {
+ int error;
+ bool updated;
do {
- csv_check_vrps_file();
+ updated = false;
+ error = csv_check_vrps_file(&updated);
+ if (error) {
+ err(error, "Error while searching CSV updates");
+ goto sleep;
+ }
+ if (updated)
+ notify_clients();
+sleep:
sleep(config_get_vrps_check_interval());
} while (true);