Backport a pending PR to add nftables support. Upstream PR: https://github.com/v2rayA/v2rayA/pull/805 As nftables merged ipv4/ipv6 support into a single command, so simply enable ipv6 support by default. While at it, backport a upstreamed fix for simple-obfs plugin. Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
88 lines
2.2 KiB
Diff
88 lines
2.2 KiB
Diff
From 58a6cf270e43ec3eaeef7d1c65de76278dd6d349 Mon Sep 17 00:00:00 2001
|
|
From: mzz2017 <2017@duck.com>
|
|
Date: Mon, 13 Feb 2023 14:42:07 +0800
|
|
Subject: [PATCH] fix: simple-obfs
|
|
|
|
---
|
|
service/pkg/plugin/simpleobfs/http.go | 8 +++++++-
|
|
service/pkg/plugin/simpleobfs/tls.go | 7 +++++++
|
|
2 files changed, 14 insertions(+), 1 deletion(-)
|
|
|
|
--- a/pkg/plugin/simpleobfs/http.go
|
|
+++ b/pkg/plugin/simpleobfs/http.go
|
|
@@ -12,6 +12,7 @@ import (
|
|
"net"
|
|
"net/http"
|
|
"strings"
|
|
+ "sync"
|
|
)
|
|
|
|
// HTTPObfs is shadowsocks http simple-obfs implementation
|
|
@@ -24,9 +25,13 @@ type HTTPObfs struct {
|
|
offset int
|
|
firstRequest bool
|
|
firstResponse bool
|
|
+ rMu sync.Mutex
|
|
+ wMu sync.Mutex
|
|
}
|
|
|
|
func (ho *HTTPObfs) Read(b []byte) (int, error) {
|
|
+ ho.rMu.Lock()
|
|
+ defer ho.rMu.Unlock()
|
|
if ho.buf != nil {
|
|
n := copy(b, ho.buf[ho.offset:])
|
|
ho.offset += n
|
|
@@ -64,6 +69,8 @@ func (ho *HTTPObfs) Read(b []byte) (int,
|
|
}
|
|
|
|
func (ho *HTTPObfs) Write(b []byte) (int, error) {
|
|
+ ho.wMu.Lock()
|
|
+ defer ho.wMu.Unlock()
|
|
if ho.firstRequest {
|
|
randBytes := make([]byte, 16)
|
|
rand.Read(randBytes)
|
|
@@ -71,7 +78,6 @@ func (ho *HTTPObfs) Write(b []byte) (int
|
|
req.Header.Set("User-Agent", fmt.Sprintf("curl/7.%d.%d", rand.Int()%54, rand.Int()%2))
|
|
req.Header.Set("Upgrade", "websocket")
|
|
req.Header.Set("Connection", "Upgrade")
|
|
- req.Host = ho.host
|
|
if ho.port != "80" {
|
|
req.Host = fmt.Sprintf("%s:%s", ho.host, ho.port)
|
|
}
|
|
--- a/pkg/plugin/simpleobfs/tls.go
|
|
+++ b/pkg/plugin/simpleobfs/tls.go
|
|
@@ -8,6 +8,7 @@ import (
|
|
"io"
|
|
"math/rand"
|
|
"net"
|
|
+ "sync"
|
|
"time"
|
|
)
|
|
|
|
@@ -26,6 +27,8 @@ type TLSObfs struct {
|
|
remain int
|
|
firstRequest bool
|
|
firstResponse bool
|
|
+ rMu sync.Mutex
|
|
+ wMu sync.Mutex
|
|
}
|
|
|
|
func (to *TLSObfs) read(b []byte, discardN int) (int, error) {
|
|
@@ -54,6 +57,8 @@ func (to *TLSObfs) read(b []byte, discar
|
|
}
|
|
|
|
func (to *TLSObfs) Read(b []byte) (int, error) {
|
|
+ to.rMu.Lock()
|
|
+ defer to.rMu.Unlock()
|
|
if to.remain > 0 {
|
|
length := to.remain
|
|
if length > len(b) {
|
|
@@ -77,6 +82,8 @@ func (to *TLSObfs) Read(b []byte) (int,
|
|
return to.read(b, 3)
|
|
}
|
|
func (to *TLSObfs) Write(b []byte) (int, error) {
|
|
+ to.wMu.Lock()
|
|
+ defer to.wMu.Unlock()
|
|
length := len(b)
|
|
for i := 0; i < length; i += chunkSize {
|
|
end := i + chunkSize
|