summaryrefslogtreecommitdiffstats
path: root/ffd/ffd.c
diff options
context:
space:
mode:
Diffstat (limited to 'ffd/ffd.c')
-rw-r--r--ffd/ffd.c37
1 files changed, 30 insertions, 7 deletions
diff --git a/ffd/ffd.c b/ffd/ffd.c
index e878eb5..9af9598 100644
--- a/ffd/ffd.c
+++ b/ffd/ffd.c
@@ -215,7 +215,7 @@ static void handle_tlv_hello(const ffd_tlv_hello_t *tlv_hello, size_t len, handl
uint16_t seqno = ntohs(tlv_hello->seqno);
if (neigh->last_hello.tv_sec) {
- int timediff = timespec_diff(&now, &neigh->last_hello)/10;
+ int timediff = timespec_diff(&now, &neigh->last_hello);
uint16_t seqexp = neigh->last_seqno + (timediff - neigh->hello_interval/2)/neigh->hello_interval;
/* cast to int16_t to ensure correct handling of seqno wrapping */
@@ -268,10 +268,11 @@ static void handle_tlv_ihu(const ffd_tlv_ihu_t *tlv_ihu, size_t len, handle_tlv_
}
ffd_neigh_t *neigh = get_tlv_neigh(arg);
+ neigh->ihu_interval = ntohs(tlv_ihu->interval);
neigh->last_ihu = now;
neigh->txcost = ntohs(tlv_ihu->rxcost);
- fprintf(stderr, "debug: accepted IHU, txcost is %u, cost is %u now.\n", neigh->txcost, ffd_neigh_get_cost(neigh));
+ fprintf(stderr, "debug: accepted IHU, txcost is %u, cost is %u now.\n", ffd_neigh_get_txcost(neigh), ffd_neigh_get_cost(neigh));
}
static void handle_tlv_node_id(const ffd_tlv_node_id_t *tlv_node_id, size_t len, handle_tlv_arg_t *arg) {
@@ -470,6 +471,19 @@ static void send_updates(void) {
}
}
+static void maintenance(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) {
+ fprintf(stderr, "debug: maintenance: %02x:%02x:%02x:%02x:%02x:%02x[%s]: %u (rx %u/tx %u)\n",
+ neigh->addr.d[0], neigh->addr.d[1], neigh->addr.d[2],
+ neigh->addr.d[3], neigh->addr.d[4], neigh->addr.d[5],
+ iface->name, ffd_neigh_get_cost(neigh), ffd_neigh_get_rxcost(neigh), ffd_neigh_get_txcost(neigh));
+ }
+ }
+}
+
int main() {
if (!check_config())
return 1;
@@ -484,34 +498,43 @@ int main() {
struct timespec next_hello = now;
struct timespec next_update = now;
+ struct timespec next_maintenance = now;
while (true) {
update_netifs();
int hello_timeout = timespec_diff(&next_hello, &now);
- int update_timeout = timespec_diff(&next_update, &now);
-
if (hello_timeout <= 0) {
ffd_send_hellos();
add_interval(&next_hello, FFD_HELLO_INTERVAL);
- continue;
}
+ int update_timeout = timespec_diff(&next_update, &now);
if (update_timeout <= 0) {
fprintf(stderr, "Sending periodic update.\n");
send_updates();
add_interval(&next_update, FFD_UPDATE_INTERVAL);
- continue;
}
+ int maintenance_timeout = timespec_diff(&next_maintenance, &now);
+ if (maintenance_timeout <= 0) {
+ maintenance();
+
+ add_interval(&next_maintenance, FFD_MAINTENANCE_INTERVAL);
+ }
+
+ int timeout = min(min(hello_timeout, update_timeout), maintenance_timeout);
+ if (timeout <= 0)
+ continue;
+
struct pollfd fds[1];
fds[0].fd = sockfd;
fds[0].events = POLLIN;
- poll(fds, 1, min(hello_timeout, update_timeout));
+ poll(fds, 1, 10*timeout);
update_time();