add dns intercept and route for tproxy

This commit is contained in:
fancy 2020-04-24 00:26:32 +08:00 committed by Qv2ray-dev
parent 7262983e02
commit 518f672bbe
6 changed files with 46 additions and 5 deletions

View File

@ -84,18 +84,19 @@ namespace Qv2ray::base::config
bool tproxy_followRedirect;
/*redirect or tproxy way, and tproxy need cap_net_admin*/
QString tproxy_mode;
bool dnsIntercept;
Qv2rayInboundsConfig()
: listenip("127.0.0.1"), setSystemProxy(true), useSocks(true), socks_port(1088), socks_useAuth(false), socksUDP(true),
socksLocalIP("127.0.0.1"), socksAccount(), useHTTP(true), http_port(8888), http_useAuth(false), httpAccount(), useTPROXY(false),
tproxy_ip("127.0.0.1"), tproxy_port(12345), tproxy_use_tcp(true), tproxy_use_udp(false), tproxy_followRedirect(true),
tproxy_mode("tproxy")
tproxy_mode("tproxy"),dnsIntercept(true)
{
}
XTOSTRUCT(O(setSystemProxy, listenip, useSocks, useHTTP, socks_port, socks_useAuth, socksAccount, socksUDP, socksLocalIP, http_port,
http_useAuth, httpAccount, useTPROXY, tproxy_ip, tproxy_port, tproxy_use_tcp, tproxy_use_udp, tproxy_followRedirect,
tproxy_mode))
tproxy_mode,dnsIntercept))
};
struct Qv2rayOutboundsConfig

View File

@ -515,6 +515,9 @@ namespace Qv2ray::core::connection
{
OutboundMarkSettingFilter(GlobalConfig.outboundConfig.mark, root);
}
if (GlobalConfig.inboundConfig.useTPROXY && GlobalConfig.inboundConfig.dnsIntercept){
DNSInterceptFilter(root);
}
}
// Let's process some api features.
@ -599,5 +602,22 @@ namespace Qv2ray::core::connection
root["outbounds"] = outbounds;
}
void DNSInterceptFilter(CONFIGROOT &root){
// dns outBound
QJsonObject dnsOutboundObj{{"protocol","dns"},{"tag","dns-out"}};
OUTBOUNDS outbounds(root["outbounds"].toArray());
outbounds.append(dnsOutboundObj);
root["outbounds"] = outbounds;
//dns route
QJsonObject dnsRoutingRuleObj{{"outboundTag", "dns-out"},{"port","53"},{"type", "field"}};
ROUTING routing(root["routing"].toObject());
QJsonArray _rules(routing["rules"].toArray());
_rules.insert(0,dnsRoutingRuleObj);
routing["rules"]=_rules;
root["routing"]=routing;
}
} // namespace Generation
} // namespace Qv2ray::core::connection

View File

@ -40,6 +40,8 @@ namespace Qv2ray::core::connection
// mark all outbound
void OutboundMarkSettingFilter(const int mark, CONFIGROOT &root);
void DNSInterceptFilter(CONFIGROOT &root);
} // namespace Generation
} // namespace Qv2ray::core::connection

View File

@ -128,6 +128,7 @@ PreferencesWindow::PreferencesWindow(QWidget *parent) : QDialog(parent), Current
tproxyFollowRedirect->setChecked(CurrentConfig.inboundConfig.tproxy_followRedirect);
tproxyMode->setCurrentText(CurrentConfig.inboundConfig.tproxy_mode);
outboundMark->setValue(CurrentConfig.outboundConfig.mark);
dnsIntercept->setChecked(CurrentConfig.inboundConfig.dnsIntercept);
//
//
vCorePathTxt->setText(CurrentConfig.kernelConfig.KernelPath());
@ -1262,3 +1263,11 @@ void PreferencesWindow::on_outboundMark_valueChanged(int arg1)
NEEDRESTART
CurrentConfig.outboundConfig.mark=arg1;
}
void PreferencesWindow::on_dnsIntercept_toggled(bool checked)
{
NEEDRESTART
CurrentConfig.inboundConfig.dnsIntercept=checked;
}

View File

@ -196,6 +196,8 @@ class PreferencesWindow
void on_outboundMark_valueChanged(int arg1);
void on_dnsIntercept_toggled(bool checked);
private:
//
RouteSettingsMatrixWidget *routeSettingsWidget;

View File

@ -705,8 +705,8 @@ Custom DNS Settings</string>
<rect>
<x>0</x>
<y>0</y>
<width>710</width>
<height>520</height>
<width>703</width>
<height>524</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
@ -1013,6 +1013,13 @@ Custom DNS Settings</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="dnsIntercept">
<property name="text">
<string>DNS Intercept</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">