From: pcarana Date: Thu, 7 Mar 2019 23:24:57 +0000 (-0600) Subject: Notify clients when CSV data is updated X-Git-Tag: v0.0.2~52^2~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=88040e9ad158db8d09e9f1ad7825f6300845178d;p=thirdparty%2FFORT-validator.git Notify clients when CSV data is updated --- diff --git a/src/Makefile.am b/src/Makefile.am index ea022a95..a70f996a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 diff --git a/src/csv.c b/src/csv.c index c3b5bb64..98720a0e 100644 --- a/src/csv.c +++ b/src/csv.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -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); } diff --git a/src/csv.h b/src/csv.h index 9b4b2d1c..96661c1a 100644 --- a/src/csv.h +++ b/src/csv.h @@ -1,7 +1,9 @@ #ifndef SRC_CSV_H_ #define SRC_CSV_H_ +#include + 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 index 00000000..8a5e3876 --- /dev/null +++ b/src/notify.c @@ -0,0 +1,37 @@ +#include "notify.h" + +#include +#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 index 00000000..d4348778 --- /dev/null +++ b/src/notify.h @@ -0,0 +1,6 @@ +#ifndef SRC_NOTIFY_H_ +#define SRC_NOTIFY_H_ + +void notify_clients(); + +#endif /* SRC_NOTIFY_H_ */ diff --git a/src/rtr/pdu_sender.h b/src/rtr/pdu_sender.h index 607eb2a4..f7d767a6 100644 --- a/src/rtr/pdu_sender.h +++ b/src/rtr/pdu_sender.h @@ -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 *); diff --git a/src/updates_daemon.c b/src/updates_daemon.c index 19657ef6..fd4efbd6 100644 --- a/src/updates_daemon.c +++ b/src/updates_daemon.c @@ -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);