]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Notify clients when CSV data is updated
authorpcarana <pc.moreno2099@gmail.com>
Thu, 7 Mar 2019 23:24:57 +0000 (17:24 -0600)
committerpcarana <pc.moreno2099@gmail.com>
Thu, 7 Mar 2019 23:24:57 +0000 (17:24 -0600)
src/Makefile.am
src/csv.c
src/csv.h
src/notify.c [new file with mode: 0644]
src/notify.h [new file with mode: 0644]
src/rtr/pdu_sender.h
src/updates_daemon.c

index ea022a95e7cd4e0b16e771e0a85e1d421b44693f..a70f996a77d866e6f022ebfa37a5c4437fb8e3d1 100644 (file)
@@ -11,6 +11,7 @@ rtr_server_SOURCES += common.c common.h
 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
 
index c3b5bb64f902ca77b748a56ff55f7fc2d0a0183b..98720a0e5830723a52d0b43ca42fe32e1c85c673 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
@@ -2,7 +2,6 @@
 
 #include <err.h>
 #include <errno.h>
-#include <stdbool.h>
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
@@ -235,7 +234,7 @@ end:
 }
 
 static int
-load_vrps_file(bool check_update)
+load_vrps_file(bool check_update, bool *updated)
 {
 
        struct line_file *lfile;
@@ -270,6 +269,10 @@ load_vrps_file(bool check_update)
        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
 
@@ -282,11 +285,11 @@ end1:
 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);
 }
index 9b4b2d1c298ad972ae04257bad2eaa4035e99a3a..96661c1a596668e72a97b4167192cbbd4f48aea8 100644 (file)
--- a/src/csv.h
+++ b/src/csv.h
@@ -1,7 +1,9 @@
 #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_ */
diff --git a/src/notify.c b/src/notify.c
new file mode 100644 (file)
index 0000000..8a5e387
--- /dev/null
@@ -0,0 +1,37 @@
+#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");
+       }
+}
diff --git a/src/notify.h b/src/notify.h
new file mode 100644 (file)
index 0000000..d434877
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef SRC_NOTIFY_H_
+#define SRC_NOTIFY_H_
+
+void notify_clients();
+
+#endif /* SRC_NOTIFY_H_ */
index 607eb2a4654099b0ae94d629e246e8f37ca6d028..f7d767a6c0a6c98d94ae492663e2c59ddb7d50ec 100644 (file)
@@ -14,6 +14,7 @@ struct sender_common {
 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 *);
index 19657ef64fde6b656880af765c7de57f34bfeacd..fd4efbd60015aa78ac07e006de6e3b74dd319dc6 100644 (file)
@@ -8,11 +8,22 @@
 
 #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);