Skip to content

Commit a7ec687

Browse files
Merge pull request #18 from shadowy-pycoder/reuseport
added logic for SO_REUSEPORT
2 parents d719919 + b91d597 commit a7ec687

10 files changed

Lines changed: 234 additions & 107 deletions

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ You can download the binary for your platform from [Releases](https://github.com
107107
Example:
108108

109109
```shell
110-
GOHPTS_RELEASE=v1.11.0; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$GOHPTS_RELEASE/gohpts-$GOHPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$GOHPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
110+
GOHPTS_RELEASE=v1.11.1; wget -v https://github.com/shadowy-pycoder/go-http-proxy-to-socks/releases/download/$GOHPTS_RELEASE/gohpts-$GOHPTS_RELEASE-linux-amd64.tar.gz -O gohpts && tar xvzf gohpts && mv -f gohpts-$GOHPTS_RELEASE-linux-amd64 gohpts && ./gohpts -h
111111
```
112112

113113
Alternatively, you can install it using `go install` command (requires Go [1.24](https://go.dev/doc/install) or later):
@@ -145,6 +145,7 @@ GitHub: https://github.com/shadowy-pycoder/go-http-proxy-to-socks
145145

146146
Usage: gohpts [OPTIONS]
147147
OPTIONS:
148+
General:
148149
-h Show this help message and exit
149150
-v Show version and build information
150151
-D Run as a daemon (provide -logfile to see logs)
@@ -177,6 +178,8 @@ OPTIONS:
177178
-T Address of transparent proxy server (no HTTP)
178179
-Tu Address of transparent UDP proxy server
179180
-M Transparent proxy mode: (redirect, tproxy)
181+
-w Number of instances of transparent proxy server (Default: number of CPU cores)
182+
-wu Number of instances of transparent UDP proxy server (Default: number of CPU cores)
180183
-auto Automatically setup iptables for transparent proxy (requires elevated privileges)
181184
-arpspoof Enable ARP spoof proxy for selected targets (Example: "targets 10.0.0.1,10.0.0.5-10,192.168.1.*,192.168.10.0/24;fullduplex false;debug true")
182185
-mark Set mark for each packet sent through transparent proxy (Default: redirect 0, tproxy 100)

cmd/gohpts/cli.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ GitHub: https://github.com/shadowy-pycoder/go-http-proxy-to-socks
3030
3131
Usage: gohpts [OPTIONS]
3232
OPTIONS:
33+
General:
3334
-h Show this help message and exit
3435
-v Show version and build information
3536
-D Run as a daemon (provide -logfile to see logs)
@@ -64,6 +65,8 @@ const usageTproxy string = `
6465
-T Address of transparent proxy server (no HTTP)
6566
-Tu Address of transparent UDP proxy server
6667
-M Transparent proxy mode: (redirect, tproxy)
68+
-w Number of instances of transparent proxy server (Default: number of CPU cores)
69+
-wu Number of instances of transparent UDP proxy server (Default: number of CPU cores)
6770
-auto Automatically setup iptables for transparent proxy (requires elevated privileges)
6871
-arpspoof Enable ARP spoof proxy for selected targets (Example: "targets 10.0.0.1,10.0.0.5-10,192.168.1.*,192.168.10.0/24;fullduplex false;debug true")
6972
-mark Set mark for each packet sent through transparent proxy (Default: redirect 0, tproxy 100)
@@ -117,6 +120,18 @@ func root(args []string) error {
117120
conf.TProxyMode = flagValue
118121
return nil
119122
})
123+
flags.UintVar(
124+
&conf.TProxyWorkers,
125+
"w",
126+
0,
127+
"Number of instances of transparent proxy server (Default: number of CPU cores)",
128+
)
129+
flags.UintVar(
130+
&conf.TProxyUDPWorkers,
131+
"wu",
132+
0,
133+
"Number of instances of transparent UDP proxy server (Default: number of CPU cores)",
134+
)
120135
flags.BoolVar(
121136
&conf.Auto,
122137
"auto",
@@ -199,9 +214,14 @@ func root(args []string) error {
199214
return fmt.Errorf("transparent proxy mode requires -t, -T or -Tu flag")
200215
}
201216
}
202-
if seen["auto"] {
203-
if !seen["t"] && !seen["T"] && !seen["Tu"] {
204-
return fmt.Errorf("-auto requires -t, -T or -Tu flag")
217+
if seen["w"] {
218+
if !seen["t"] && !seen["T"] {
219+
return fmt.Errorf("-w requires -t, or -T flag")
220+
}
221+
}
222+
if seen["wu"] {
223+
if !seen["Tu"] {
224+
return fmt.Errorf("-wu requires -Tu flag")
205225
}
206226
}
207227
if seen["mark"] {

dialer_linux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build linux
2-
// +build linux
32

43
package gohpts
54

dialer_nonlinux.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !linux
2-
// +build !linux
32

43
package gohpts
54

0 commit comments

Comments
 (0)