optimize: tproxy

This commit is contained in:
mzz2017 committed 2020-05-02 01:32:24 +08:00
1 parent 410d7e8e66
commit 3be2dfa8ee
3 files changed
+22 -9

No files matched your search

+2 -2
View File
@@ -14,8 +14,7 @@ RUN export VERSION=$(cat ./version) && go build -ldflags="-X v2rayA/global.Versi
FROM v2fly/v2fly-core AS v2ray
FROM alpine:latest
RUN apk --no-cache add iptables
FROM bgiddings/iptables:latest
WORKDIR /v2raya
COPY --from=builder /build/service/v2rayA .
COPY --from=v2ray /usr/bin/v2ray/* /etc/v2ray/
@@ -23,3 +22,4 @@ ENV PATH=$PATH:/etc/v2ray
ENV GIN_MODE=release
EXPOSE 2017
ENTRYPOINT ["./v2rayA","--mode=universal"]
+10
View File
@@ -15,7 +15,9 @@ ip route add local 0.0.0.0/0 dev lo table 100
# 建链
iptables -t mangle -N SSTP_OUT
iptables -t mangle -N SSTP_PRE
iptables -t mangle -N SSTP_ONCE
iptables -t mangle -A OUTPUT -j SSTP_OUT
iptables -t mangle -A PREROUTING -m socket --transparent -j SSTP_ONCE
iptables -t mangle -A PREROUTING -j SSTP_PRE
# 打上 iptables 标记,mark 了的会走代理
@@ -59,6 +61,11 @@ iptables -t mangle -A SSTP_PRE -p udp -m mark ! --mark 1 -j SETMARK
# 将所有打了标记的 TCP 和 UDP 包透明地转发到代理的监听端口
iptables -t mangle -A SSTP_PRE -m mark --mark 1 -p tcp -j TPROXY --on-port 12345
iptables -t mangle -A SSTP_PRE -m mark --mark 1 -p udp -j TPROXY --on-port 12345
# 略过已建立且被tproxy标记的的socket
iptables -t mangle -A SSTP_ONCE -j MARK --set-mark 1
iptables -t mangle -A SSTP_ONCE -j ACCEPT
`
if cmds.IsCommandValid("sysctl") {
commands += `
@@ -75,6 +82,9 @@ func (t *tproxy) GetCleanCommands() CleanCommands {
ip rule del fwmark 1 table 100
ip route del local 0.0.0.0/0 dev lo table 100
iptables -t mangle -F SSTP_ONCE
iptables -t mangle -D PREROUTING -m socket --transparent -j SSTP_ONCE
iptables -t mangle -X SSTP_ONCE
iptables -t mangle -F SSTP_OUT
iptables -t mangle -D OUTPUT -j SSTP_OUT
iptables -t mangle -X SSTP_OUT
+10 -7
View File
@@ -1,17 +1,17 @@
package service
import (
"v2rayA/common"
"v2rayA/common/httpClient"
"v2rayA/core/nodeData"
"v2rayA/core/touch"
"v2rayA/persistence/configure"
"bytes"
"log"
"net/http"
"strings"
"time"
"v2ray.com/core/common/errors"
"v2rayA/common"
"v2rayA/common/httpClient"
"v2rayA/core/nodeData"
"v2rayA/core/touch"
"v2rayA/persistence/configure"
)
func ResolveSubscription(source string) (infos []*nodeData.NodeData, err error) {
@@ -29,8 +29,11 @@ func ResolveSubscriptionWithClient(source string, client *http.Client) (infos []
buf := new(bytes.Buffer)
_, _ = buf.ReadFrom(res.Body)
defer res.Body.Close()
// base64解码, raw是多行vmess
raw, _ := common.Base64StdDecode(buf.String())
// base64解码, raw是多行vmess/ss/ssr/trojan
raw, err := common.Base64StdDecode(buf.String())
if err != nil {
raw, _ = common.Base64URLDecode(buf.String())
}
// 切分raw
rows := strings.Split(strings.TrimSpace(raw), "\n")
// 解析