parent
f6acec53c0
commit
ba4237f1dd
64 changed files with 1933 additions and 336 deletions
|
@ -1,5 +1,4 @@
|
|||
#include "router_win.h"
|
||||
#include "../client/utilities.h"
|
||||
|
||||
#include <string>
|
||||
#include <tlhelp32.h>
|
||||
|
@ -7,6 +6,8 @@
|
|||
|
||||
#include <QProcess>
|
||||
|
||||
#include <core/networkUtilities.h>
|
||||
|
||||
LONG (NTAPI * NtSuspendProcess)(HANDLE ProcessHandle) = NULL;
|
||||
LONG (NTAPI * NtResumeProcess)(HANDLE ProcessHandle) = NULL;
|
||||
|
||||
|
@ -35,7 +36,7 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
// .arg(ips.join("\n"));
|
||||
|
||||
|
||||
if (!Utils::checkIPv4Format(gw)) {
|
||||
if (!NetworkUtilities::checkIPv4Format(gw)) {
|
||||
qCritical().noquote() << "Trying to add invalid route, gw: " << gw;
|
||||
return 0;
|
||||
}
|
||||
|
@ -58,7 +59,6 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
dwStatus = GetIpForwardTable(pIpForwardTable, &dwSize, bOrder);
|
||||
}
|
||||
|
||||
|
||||
if (dwStatus != ERROR_SUCCESS) {
|
||||
qDebug() << "getIpForwardTable failed.";
|
||||
if (pIpForwardTable)
|
||||
|
@ -66,7 +66,6 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int success_count = 0;
|
||||
MIB_IPFORWARDROW ipfrow;
|
||||
|
||||
|
@ -77,7 +76,6 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
ipfrow.dwForwardType = MIB_IPROUTE_TYPE_INDIRECT; /* XXX - next hop != final dest */
|
||||
ipfrow.dwForwardProto = MIB_IPPROTO_NETMGMT; /* XXX - MIB_PROTO_NETMGMT */
|
||||
|
||||
|
||||
// Set iface for route
|
||||
IPAddr dwGwAddr = inet_addr(gw.toStdString().c_str());
|
||||
if (GetBestInterface(dwGwAddr, &ipfrow.dwForwardIfIndex) != NO_ERROR) {
|
||||
|
@ -105,14 +103,14 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
|
||||
for (int i = 0; i < ips.size(); ++i) {
|
||||
QString ipWithMask = ips.at(i);
|
||||
QString ip = Utils::ipAddressFromIpWithSubnet(ipWithMask);
|
||||
QString ip = NetworkUtilities::ipAddressFromIpWithSubnet(ipWithMask);
|
||||
|
||||
if (!Utils::checkIPv4Format(ip)) {
|
||||
if (!NetworkUtilities::checkIPv4Format(ip)) {
|
||||
qCritical().noquote() << "Critical, trying to add invalid route, ip: " << ip;
|
||||
continue;
|
||||
}
|
||||
|
||||
QString mask = Utils::netMaskFromIpWithSubnet(ipWithMask);
|
||||
QString mask = NetworkUtilities::netMaskFromIpWithSubnet(ipWithMask);
|
||||
|
||||
// address
|
||||
ipfrow.dwForwardDest = inet_addr(ip.toStdString().c_str());
|
||||
|
@ -137,7 +135,6 @@ int RouterWin::routeAddList(const QString &gw, const QStringList &ips)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// Free resources
|
||||
if (pIpForwardTable)
|
||||
free(pIpForwardTable);
|
||||
|
@ -215,8 +212,7 @@ int RouterWin::routeDeleteList(const QString &gw, const QStringList &ips)
|
|||
DWORD dwSize = 0;
|
||||
BOOL bOrder = FALSE;
|
||||
DWORD dwStatus = 0;
|
||||
ULONG gw_addr= inet_addr(gw.toStdString().c_str());
|
||||
|
||||
ULONG gw_addr = inet_addr(gw.toStdString().c_str());
|
||||
|
||||
// Find out how big our buffer needs to be.
|
||||
dwStatus = GetIpForwardTable(pIpForwardTable, &dwSize, bOrder);
|
||||
|
@ -230,7 +226,6 @@ int RouterWin::routeDeleteList(const QString &gw, const QStringList &ips)
|
|||
dwStatus = GetIpForwardTable(pIpForwardTable, &dwSize, bOrder);
|
||||
}
|
||||
|
||||
|
||||
if (dwStatus != ERROR_SUCCESS) {
|
||||
qDebug() << "getIpForwardTable failed.";
|
||||
if (pIpForwardTable)
|
||||
|
@ -244,8 +239,8 @@ int RouterWin::routeDeleteList(const QString &gw, const QStringList &ips)
|
|||
for (int i = 0; i < ips.size(); ++i) {
|
||||
QString ipMask = ips.at(i);
|
||||
if (ipMask.isEmpty()) continue;
|
||||
QString ip = Utils::ipAddressFromIpWithSubnet(ipMask);
|
||||
QString mask = Utils::netMaskFromIpWithSubnet(ipMask);
|
||||
QString ip = NetworkUtilities::ipAddressFromIpWithSubnet(ipMask);
|
||||
QString mask = NetworkUtilities::netMaskFromIpWithSubnet(ipMask);
|
||||
|
||||
if (ip.isEmpty()) continue;
|
||||
|
||||
|
@ -443,3 +438,53 @@ BOOL RouterWin::SuspendProcess(BOOL fSuspend, DWORD dwProcessId)
|
|||
return ok;
|
||||
}
|
||||
|
||||
bool RouterWin::updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers)
|
||||
{
|
||||
return m_dnsUtil->updateResolvers(ifname, resolvers);
|
||||
}
|
||||
|
||||
|
||||
void RouterWin::StopRoutingIpv6()
|
||||
{
|
||||
{
|
||||
QProcess p;
|
||||
QString command = QString("interface ipv6 add route fc00::/7 interface={NetworkInterface.IPv6LoopbackInterfaceIndex} metric=0 store=active");
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
{
|
||||
QProcess p;
|
||||
QString command = QString("interface ipv6 add route 2000::/4 interface={NetworkInterface.IPv6LoopbackInterfaceIndex} metric=0 store=active");
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
{
|
||||
QProcess p;
|
||||
QString command = QString("interface ipv6 add route 3000::/4 interface={NetworkInterface.IPv6LoopbackInterfaceIndex} metric=0 store=active");
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
void RouterWin::StartRoutingIpv6()
|
||||
{
|
||||
{
|
||||
QProcess p;
|
||||
QString command = QString("interface ipv6 delete route fc00::/7 interface={NetworkInterface.IPv6LoopbackInterfaceIndex}");
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
{
|
||||
QProcess p;
|
||||
QString command = QString("interface ipv6 delete route 2000::/4 interface={NetworkInterface.IPv6LoopbackInterfaceIndex}");
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
{
|
||||
QProcess p;
|
||||
QString command = QString("interface ipv6 delete route 3000::/4 interface={NetworkInterface.IPv6LoopbackInterfaceIndex}");
|
||||
p.start(command);
|
||||
p.waitForFinished();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue