@@ -52,6 +52,7 @@ const (
5252var (
5353 supportedChainTypes = []string {"strict" , "dynamic" , "random" , "round_robin" }
5454 SupportedTProxyModes = []string {"redirect" , "tproxy" }
55+ SupportedTProxyOS = []string {"linux" , "android" }
5556 errInvalidWrite = errors .New ("invalid write result" )
5657)
5758
@@ -258,16 +259,16 @@ func New(conf *Config) *proxyapp {
258259 sl := snifflogger .Level (lvl )
259260 p .logger = & l
260261 p .snifflogger = & sl
261- if runtime .GOOS == "linux" && conf .TProxy != "" && conf .TProxyOnly != "" {
262+ if slices . Contains ( SupportedTProxyOS , runtime .GOOS ) && conf .TProxy != "" && conf .TProxyOnly != "" {
262263 p .logger .Fatal ().Msg ("Cannot specify TPRoxy and TProxyOnly at the same time" )
263- } else if runtime .GOOS == "linux" && conf .TProxyMode != "" && ! slices .Contains (SupportedTProxyModes , conf .TProxyMode ) {
264+ } else if slices . Contains ( SupportedTProxyOS , runtime .GOOS ) && conf .TProxyMode != "" && ! slices .Contains (SupportedTProxyModes , conf .TProxyMode ) {
264265 p .logger .Fatal ().Msg ("Incorrect TProxyMode provided" )
265- } else if runtime .GOOS != "linux" && (conf .TProxy != "" || conf .TProxyOnly != "" || conf .TProxyMode != "" || conf .TProxyUDP != "" ) {
266+ } else if ! slices . Contains ( SupportedTProxyOS , runtime .GOOS ) && (conf .TProxy != "" || conf .TProxyOnly != "" || conf .TProxyMode != "" || conf .TProxyUDP != "" ) {
266267 conf .TProxy = ""
267268 conf .TProxyOnly = ""
268269 conf .TProxyMode = ""
269270 conf .TProxyUDP = ""
270- p .logger .Warn ().Msgf ("[%s] functionality only available on linux systems" , conf .TProxyMode )
271+ p .logger .Warn ().Msgf ("[%s] functionality only available on linux or android systems" , conf .TProxyMode )
271272 }
272273 p .tproxyMode = conf .TProxyMode
273274 tproxyonly := conf .TProxyOnly != ""
@@ -301,12 +302,12 @@ func New(conf *Config) *proxyapp {
301302 p .logger .Fatal ().Msgf ("%s: address already in use" , p .tproxyAddrUDP )
302303 }
303304 p .auto = conf .Auto
304- if p .auto && runtime .GOOS != "linux" {
305- p .logger .Fatal ().Msg ("Auto setup is available only on linux systems" )
305+ if p .auto && ! slices . Contains ( SupportedTProxyOS , runtime .GOOS ) {
306+ p .logger .Fatal ().Msg ("Auto setup is available only on linux/android systems" )
306307 }
307308 p .mark = conf .Mark
308- if p .mark > 0 && runtime .GOOS != "linux" {
309- p .logger .Fatal ().Msg ("SO_MARK is available only on linux systems" )
309+ if p .mark > 0 && ! slices . Contains ( SupportedTProxyOS , runtime .GOOS ) {
310+ p .logger .Fatal ().Msg ("SO_MARK is available only on linux/android systems" )
310311 }
311312 if p .mark > 0xFFFFFFFF {
312313 p .logger .Fatal ().Msg ("SO_MARK is out of range" )
@@ -469,8 +470,8 @@ func New(conf *Config) *proxyapp {
469470 }
470471 }
471472 if conf .ARPSpoof != "" {
472- if runtime .GOOS != "linux" {
473- p .logger .Fatal ().Msg ("ARP spoof setup is available only on linux systems" )
473+ if ! slices . Contains ( SupportedTProxyOS , runtime .GOOS ) {
474+ p .logger .Fatal ().Msg ("ARP spoof setup is available only on linux/android systems" )
474475 }
475476 if ! p .auto {
476477 p .logger .Warn ().Msg ("ARP spoof setup requires iptables configuration" )
@@ -1508,7 +1509,10 @@ func (p *proxyapp) applyCommonRedirectRules(opts map[string]string) {
15081509 } else {
15091510 iface , err = network .GetDefaultInterface ()
15101511 if err != nil {
1511- p .logger .Fatal ().Err (err ).Msg ("failed getting default network interface" )
1512+ iface , err = network .GetDefaultInterfaceFromRoute ()
1513+ if err != nil {
1514+ p .logger .Fatal ().Err (err ).Msg ("failed getting default network interface" )
1515+ }
15121516 }
15131517 }
15141518 cmdForwardFilter := exec .Command ("bash" , "-c" , fmt .Sprintf (`
0 commit comments