@@ -97,6 +97,7 @@ type Config struct {
9797 TProxyMode string
9898 Auto bool
9999 Mark uint
100+ ARP bool
100101 LogFilePath string
101102 Debug bool
102103 JSON bool
@@ -120,6 +121,7 @@ type proxyapp struct {
120121 tproxyMode string
121122 auto bool
122123 mark uint
124+ arp bool
123125 user string
124126 pass string
125127 proxychain chain
@@ -1361,10 +1363,53 @@ func (p *proxyapp) applyRedirectRules() string {
13611363 cmdForward .Stdout = os .Stdout
13621364 cmdForward .Stderr = os .Stderr
13631365 _ = cmdForward .Run ()
1366+ if p .arp {
1367+ cmdClear := exec .Command ("bash" , "-c" , `
1368+ set -ex
1369+ iptables -t filter -F GOHPTS 2>/dev/null || true
1370+ iptables -t filter -D FORWARD -j GOHPTS 2>/dev/null || true
1371+ iptables -t filter -X GOHPTS 2>/dev/null || true
1372+ ` )
1373+ cmdClear .Stdout = os .Stdout
1374+ cmdClear .Stderr = os .Stderr
1375+ if err := cmdClear .Run (); err != nil {
1376+ p .logger .Fatal ().Err (err ).Msg ("Failed while configuring iptables. Are you root?" )
1377+ }
1378+ iface , err := getDefaultInterface ()
1379+ if err != nil {
1380+ p .logger .Fatal ().Err (err ).Msg ("failed getting default network interface" )
1381+ }
1382+ cmdForward := exec .Command ("bash" , "-c" , fmt .Sprintf (`
1383+ set -ex
1384+ iptables -t filter -N GOHPTS 2>/dev/null
1385+ iptables -t filter -F GOHPTS
1386+ iptables -t filter -A FORWARD -j GOHPTS
1387+ iptables -t filter -A GOHPTS -i %s -j ACCEPT
1388+ iptables -t filter -A GOHPTS -o %s -j ACCEPT
1389+ ` , iface .Name , iface .Name ))
1390+ cmdForward .Stdout = os .Stdout
1391+ cmdForward .Stderr = os .Stderr
1392+ if err := cmdForward .Run (); err != nil {
1393+ p .logger .Fatal ().Err (err ).Msg ("Failed while configuring iptables. Are you root?" )
1394+ }
1395+ }
13641396 return string (output )
13651397}
13661398
13671399func (p * proxyapp ) clearRedirectRules (output string ) error {
1400+ if p .arp {
1401+ cmdClear := exec .Command ("bash" , "-c" , `
1402+ set -ex
1403+ iptables -t filter -F GOHPTS 2>/dev/null || true
1404+ iptables -t filter -D FORWARD -j GOHPTS 2>/dev/null || true
1405+ iptables -t filter -X GOHPTS 2>/dev/null || true
1406+ ` )
1407+ cmdClear .Stdout = os .Stdout
1408+ cmdClear .Stderr = os .Stderr
1409+ if err := cmdClear .Run (); err != nil {
1410+ p .logger .Fatal ().Err (err ).Msg ("Failed while configuring iptables. Are you root?" )
1411+ }
1412+ }
13681413 var cmd * exec.Cmd
13691414 switch p .tproxyMode {
13701415 case "redirect" :
@@ -1701,7 +1746,7 @@ func New(conf *Config) *proxyapp {
17011746 p .tproxyMode = conf .TProxyMode
17021747 tproxyonly := conf .TProxyOnly != ""
17031748 if tproxyonly {
1704- if p .tproxyMode == "tproxy " {
1749+ if p .tproxyMode != " " {
17051750 p .tproxyAddr , err = getFullAddress (conf .TProxyOnly , true )
17061751 if err != nil {
17071752 p .logger .Fatal ().Err (err ).Msg ("" )
@@ -1713,7 +1758,7 @@ func New(conf *Config) *proxyapp {
17131758 }
17141759 }
17151760 } else {
1716- if p .tproxyMode == "tproxy " {
1761+ if p .tproxyMode != " " {
17171762 p .tproxyAddr , err = getFullAddress (conf .TProxy , true )
17181763 if err != nil {
17191764 p .logger .Fatal ().Err (err ).Msg ("" )
@@ -1739,6 +1784,12 @@ func New(conf *Config) *proxyapp {
17391784 if p .mark == 0 && p .tproxyMode == "tproxy" {
17401785 p .mark = 100
17411786 }
1787+ p .arp = conf .ARP
1788+ if p .arp && runtime .GOOS != "linux" {
1789+ p .logger .Fatal ().Msg ("ARP setup is available only for linux system" )
1790+ } else if p .arp && ! p .auto {
1791+ p .logger .Fatal ().Msg ("ARP setup requires auto configuration" )
1792+ }
17421793 var addrHTTP , addrSOCKS , certFile , keyFile string
17431794 if conf .ServerConfPath != "" {
17441795 var sconf serverConfig
0 commit comments