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

@ -16,6 +16,10 @@ bool RouterMac::routeAdd(const QString &ipWithSubnet, const QString &gw)
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);
#ifdef MZ_DEBUG
qDebug().noquote() << "RouterMac::routeAdd: " << ipWithSubnet << gw;
#endif
if (!Utils::checkIPv4Format(ip) || !Utils::checkIPv4Format(gw)) {
qCritical().noquote() << "Critical, trying to add invalid route: " << ip << gw;
return false;
@ -39,7 +43,9 @@ bool RouterMac::routeAdd(const QString &ipWithSubnet, const QString &gw)
strcpy(argv[i], parts.at(i).toStdString().c_str());
}
// TODO refactor
mainRouteIface(argc, argv);
m_addedRoutes.append({ipWithSubnet, gw});
for (int i = 0; i < argc; i++) {
delete [] argv[i];
@ -59,14 +65,13 @@ int RouterMac::routeAddList(const QString &gw, const QStringList &ips)
bool RouterMac::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 cnt = 0;
for (const Route &r: m_addedRoutes) {
if (routeDelete(r.dst, r.gw)) cnt++;
}
bool ret = (cnt == m_addedRoutes.count());
m_addedRoutes.clear();
return ret;
}
bool RouterMac::routeDelete(const QString &ipWithSubnet, const QString &gw)
@ -74,6 +79,10 @@ bool RouterMac::routeDelete(const QString &ipWithSubnet, const QString &gw)
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithSubnet);
QString mask = Utils::netMaskFromIpWithSubnet(ipWithSubnet);
#ifdef MZ_DEBUG
qDebug().noquote() << "RouterMac::routeDelete: " << ipWithSubnet << gw;
#endif
if (!Utils::checkIPv4Format(ip) || !Utils::checkIPv4Format(gw)) {
qCritical().noquote() << "Critical, trying to remove invalid route: " << ip << gw;
return false;