Fixes for split tunneling (#272)

Fixes for split tunneling
This commit is contained in:
pokamest 2023-08-08 16:41:00 -07:00 committed by GitHub
parent b71b87e6e9
commit a1a6185fd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 175 additions and 61 deletions

View file

@ -50,7 +50,6 @@ bool RouterLinux::routeAdd(const QString &ipWithSubnet, const QString &gw, const
route.rt_flags = RTF_UP | RTF_GATEWAY;
route.rt_metric = 0;
//route.rt_dev = "ens33";
if (int err = ioctl(sock, SIOCADDRT, &route) < 0)
{
@ -60,6 +59,8 @@ bool RouterLinux::routeAdd(const QString &ipWithSubnet, const QString &gw, const
<< " mask " << ((struct sockaddr_in *)&route.rt_genmask)->sin_addr.s_addr << " " << err;
return false;
}
m_addedRoutes.append({ipWithSubnet, gw});
return true;
}
@ -76,18 +77,23 @@ int RouterLinux::routeAddList(const QString &gw, const QStringList &ips)
bool RouterLinux::clearSavedRoutes()
{
// No need to delete routes after iface down
return true;
// int cnt = 0;
// for (const QString &ip: m_addedRoutes) {
// if (routeDelete(ip)) cnt++;
// }
// return (cnt == m_addedRoutes.count());
int temp_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
int cnt = 0;
for (const Route &r: m_addedRoutes) {
if (routeDelete(r.dst, r.gw, temp_sock)) cnt++;
}
bool ret = (cnt == m_addedRoutes.count());
m_addedRoutes.clear();
close(temp_sock);
return ret;
}
bool RouterLinux::routeDelete(const QString &ipWithSubnet, const QString &gw, const int &sock)
{
#ifdef MZ_DEBUG
qDebug().noquote() << "RouterMac::routeDelete: " << ipWithSubnet << gw;
#endif
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);