summaryrefslogtreecommitdiffstats
path: root/ffd/ffd.c
diff options
context:
space:
mode:
Diffstat (limited to 'ffd/ffd.c')
-rw-r--r--ffd/ffd.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/ffd/ffd.c b/ffd/ffd.c
index 592281a..1a31298 100644
--- a/ffd/ffd.c
+++ b/ffd/ffd.c
@@ -463,11 +463,14 @@ static void receive_packet(void) {
}
}
-void add_interval(struct timespec *time, int interval) {
- int cs = time->tv_nsec/1e7 + interval;
-
- time->tv_sec += cs/100;
- time->tv_nsec = time->tv_nsec%(long)1e7 + (cs%100)*1e7;
+static void send_updates(void) {
+ ffd_iface_t *iface;
+ for (iface = iface_list; iface; iface = iface->next) {
+ ffd_neigh_t *neigh;
+ for (neigh = iface->neigh_list; neigh; neigh = neigh->next) {
+ ffd_send_update(iface, neigh, NULL, false);
+ }
+ }
}
int main() {
@@ -483,25 +486,35 @@ int main() {
update_time();
struct timespec next_hello = now;
+ struct timespec next_update = now;
while (true) {
update_netifs();
- int timeout = timespec_diff(&next_hello, &now);
+ int hello_timeout = timespec_diff(&next_hello, &now);
+ int update_timeout = timespec_diff(&next_update, &now);
- if (timeout <= 0) {
+ if (hello_timeout <= 0) {
ffd_send_hellos();
add_interval(&next_hello, FFD_HELLO_INTERVAL);
continue;
}
+ if (update_timeout <= 0) {
+ fprintf(stderr, "Sending periodic update.\n");
+ send_updates();
+
+ add_interval(&next_update, FFD_UPDATE_INTERVAL);
+ continue;
+ }
+
struct pollfd fds[1];
fds[0].fd = sockfd;
fds[0].events = POLLIN;
- poll(fds, 1, timeout);
+ poll(fds, 1, min(hello_timeout, update_timeout));
update_time();