diff --git a/src/relay.cpp b/src/relay.cpp index 1da41f1..5966d10 100644 --- a/src/relay.cpp +++ b/src/relay.cpp @@ -1297,9 +1297,13 @@ void loop_relay(std::unordered_map &vlans) { timer_event = event_new(base, -1, EV_PERSIST, lla_check_callback, timer_args); std::get<7>(*timer_args) = timer_event; evutil_timerclear(&tv); - tv.tv_sec = 5; + tv.tv_sec = 60; event_add(timer_event, &tv); + // We set check timer to be executed every 60s, it would case that its first excution be delayed 60s, + // hence manually invoke it here to immediate execute it + lla_check_callback(-1, 0, timer_args); + if(signal_init() == 0 && signal_start() == 0) { shutdown_relay(); for(std::size_t i = 0; i < sockets.size(); i++) { @@ -1334,9 +1338,8 @@ void shutdown_relay() { * @return none */ void lla_check_callback(evutil_socket_t fd, short event, void *arg) { - syslog(LOG_WARNING, "Timer event"); auto args = reinterpret_cast &, + std::unordered_map *, std::shared_ptr, std::shared_ptr, std::shared_ptr, @@ -1354,12 +1357,14 @@ void lla_check_callback(evutil_socket_t fd, short event, void *arg) { auto filter = std::get<6>(*args); auto timer_event = std::get<7>(*args); - for(auto &vlan : vlans) { + bool all_llas_are_ready = true; + for(auto &vlan : *vlans) { if (vlan.second.is_lla_ready) { continue; } if (!check_is_lla_ready(vlan.first)) { syslog(LOG_WARNING, "Link local address for %s is not ready\n", vlan.first.c_str()); + all_llas_are_ready = false; continue; } vlan.second.is_lla_ready = true; @@ -1396,5 +1401,9 @@ void lla_check_callback(evutil_socket_t fd, short event, void *arg) { exit(EXIT_FAILURE); } } + if (all_llas_are_ready) { + syslog(LOG_INFO, "All Vlans' lla are ready, terminate check timer"); + event_del(timer_event); + } }