mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-07 03:17:44 +00:00
wireguard: initialize timekeeping with RTC
This commit fixes the "Invalid handshake initiation" error when the client restarts. Fixes genodelabs/genode#4957
This commit is contained in:
parent
f66a7db87f
commit
37a7119eb3
@ -4,9 +4,12 @@ LIBS += base net jitterentropy wireguard_lx_inc_dirs
|
||||
|
||||
DDE_LINUX_DIR := $(subst /src/include/lx_kit,,$(call select_from_repositories,src/include/lx_kit))
|
||||
|
||||
MUSL_TM_DIR = $(call select_from_repositories,src/lib/musl_tm)
|
||||
|
||||
INC_DIR += $(REP_DIR)/src/app/wireguard
|
||||
INC_DIR += $(DDE_LINUX_DIR)/src/include/virt_linux
|
||||
INC_DIR += $(DDE_LINUX_DIR)/src/include
|
||||
INC_DIR += $(MUSL_TM_DIR)
|
||||
|
||||
ifeq ($(filter-out $(SPECS),x86_64),)
|
||||
SPEC_ARCH := x86_64
|
||||
@ -17,6 +20,7 @@ endif
|
||||
|
||||
INC_DIR += $(DDE_LINUX_DIR)/src/include/spec/$(SPEC_ARCH)
|
||||
|
||||
SRC_C += tm_to_secs.c
|
||||
|
||||
SRC_CC += arp_cache.cc
|
||||
SRC_CC += arp_waiter.cc
|
||||
@ -30,5 +34,6 @@ SRC_CC += main.cc
|
||||
SRC_CC += nic_connection.cc
|
||||
SRC_CC += uplink_connection.cc
|
||||
|
||||
vpath tm_to_secs.c $(MUSL_TM_DIR)
|
||||
vpath %.cc $(REP_DIR)/src/app/wireguard
|
||||
vpath %.cc $(DDE_LINUX_DIR)/src/lib
|
||||
|
@ -12,6 +12,11 @@ content: $(MIRRORED_FROM_REP_DIR)
|
||||
$(MIRRORED_FROM_REP_DIR):
|
||||
$(mirror_from_rep_dir)
|
||||
|
||||
content: src/lib/musl_tm
|
||||
src/lib/musl_tm:
|
||||
mkdir -p src/lib
|
||||
cp -r $(GENODE_DIR)/repos/libports/$@ $@
|
||||
|
||||
content: LICENSE
|
||||
LICENSE:
|
||||
( echo "GNU General Public License version 2, see:"; \
|
||||
|
@ -1,8 +1,9 @@
|
||||
base
|
||||
os
|
||||
nic_session
|
||||
uplink_session
|
||||
timer_session
|
||||
jitterentropy
|
||||
net
|
||||
nic_session
|
||||
os
|
||||
rtc_session
|
||||
timer_session
|
||||
uplink_session
|
||||
virt_linux
|
||||
|
@ -19,13 +19,18 @@
|
||||
#include <base/component.h>
|
||||
#include <base/attached_rom_dataspace.h>
|
||||
#include <base/session_label.h>
|
||||
#include <rtc_session/connection.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
/* musl-tm includes */
|
||||
#include <tm.h>
|
||||
|
||||
/* lx-kit includes */
|
||||
#include <lx_kit/env.h>
|
||||
|
||||
/* lx-emul includes */
|
||||
#include <lx_emul/init.h>
|
||||
#include <lx_emul/time.h>
|
||||
|
||||
/* lx-user includes */
|
||||
#include <lx_user/io.h>
|
||||
@ -62,10 +67,13 @@ class Wireguard::Main : private Entrypoint::Io_progress_handler,
|
||||
Lx_kit::env().scheduler.execute();
|
||||
}
|
||||
|
||||
void _handle_config() { _config_rom.update(); }
|
||||
void _set_initial_time_only_once();
|
||||
void _handle_config();
|
||||
|
||||
void _handle_nic_ip_config();
|
||||
|
||||
int64_t _rtc_timestamp_to_seconds(Rtc::Timestamp const &ts);
|
||||
|
||||
|
||||
/*****************************
|
||||
** Nic_connection_notifier **
|
||||
@ -140,6 +148,49 @@ class Wireguard::Main : private Entrypoint::Io_progress_handler,
|
||||
};
|
||||
|
||||
|
||||
int64_t Wireguard::Main::_rtc_timestamp_to_seconds(Rtc::Timestamp const &ts)
|
||||
{
|
||||
tm tm { .tm_sec = static_cast<int>(ts.second),
|
||||
.tm_min = static_cast<int>(ts.minute),
|
||||
.tm_hour = static_cast<int>(ts.hour),
|
||||
.tm_mday = static_cast<int>(ts.day),
|
||||
.tm_mon = static_cast<int>(ts.month - 1),
|
||||
.tm_year = static_cast<int>(ts.year - 1900),
|
||||
.tm_wday = 0,
|
||||
.tm_yday = 0,
|
||||
.tm_isdst = 0,
|
||||
.__tm_gmtoff = 0,
|
||||
.__tm_zone = 0 };
|
||||
|
||||
return tm_to_secs(&tm);
|
||||
}
|
||||
|
||||
void Wireguard::Main::_set_initial_time_only_once()
|
||||
{
|
||||
static bool time_already_set { false };
|
||||
|
||||
if (!time_already_set) {
|
||||
Rtc::Connection rtc { _env };
|
||||
Rtc::Timestamp const rtc_current_time { rtc.current_time() };
|
||||
|
||||
lx_emul_time_initial(_rtc_timestamp_to_seconds(rtc_current_time));
|
||||
time_already_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Wireguard::Main::_handle_config()
|
||||
{
|
||||
_config_rom.update();
|
||||
|
||||
if (!_config_rom.valid()) return;
|
||||
|
||||
if (_config_rom.xml().attribute_value("use_rtc", false) == true) {
|
||||
_set_initial_time_only_once();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Wireguard::Main::_handle_nic_ip_config()
|
||||
{
|
||||
if (_nic_connection.ip_config().valid()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user