diff --git a/src/core/client.cc b/src/core/client.cc index fc030d2..839781e 100644 --- a/src/core/client.cc +++ b/src/core/client.cc @@ -582,6 +582,10 @@ void Client::handleSysRtMessage(WebSocketMessage &message) { entry.mask = Address::netToHost(rt[idx].mask); entry.next = Address::netToHost(rt[idx].nexthop); + if (entry.next == this->tun.getIP()) { + continue; + } + std::string dstStr = Address::ipToStr(entry.dst); std::string maskStr = Address::ipToStr(entry.mask); std::string nextStr = Address::ipToStr(entry.next); diff --git a/src/tun/linux.cc b/src/tun/linux.cc index 84476e7..81fb287 100644 --- a/src/tun/linux.cc +++ b/src/tun/linux.cc @@ -179,9 +179,6 @@ class LinuxTun { } int setSysRtTable(uint32_t dst, uint32_t mask, uint32_t nexthop) { - if (nexthop == this->ip) { - return 0; - } int sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd == -1) { spdlog::error("set route failed: create socket failed"); diff --git a/src/tun/windows.cc b/src/tun/windows.cc index 04133af..543a6be 100644 --- a/src/tun/windows.cc +++ b/src/tun/windows.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include // clang-format off #include @@ -174,6 +175,11 @@ class WindowsTun { } int down() { + while (!routes.empty()) { + DeleteIpForwardEntry(&routes.top()); + routes.pop(); + } + if (this->session) { WintunEndSession(this->session); this->session = NULL; @@ -234,9 +240,12 @@ class WindowsTun { route.dwForwardMetric5 = MIB_IPROUTE_METRIC_UNUSED; DWORD result = CreateIpForwardEntry(&route); - if (result != NO_ERROR) { + if (result == NO_ERROR) { + routes.push(route); + } else { spdlog::error("add route failed: {}", result); } + return 0; } @@ -247,6 +256,7 @@ class WindowsTun { int mtu; int timeout; NET_IFINDEX ifindex; + std::stack routes; WINTUN_ADAPTER_HANDLE adapter = NULL; WINTUN_SESSION_HANDLE session = NULL;