Skip to content

Commit

Permalink
Merge pull request MetaCubeX#58 from MetaCubeX/Alpha
Browse files Browse the repository at this point in the history
rm EBpf tun && disable android ebpf
  • Loading branch information
taamarin committed Aug 8, 2022
2 parents 7b65a62 + 93ea124 commit bc38aa9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
2 changes: 2 additions & 0 deletions component/ebpf/ebpf_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !android && linux

package ebpf

import (
Expand Down
2 changes: 1 addition & 1 deletion component/ebpf/ebpf_others.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !linux
//go:build !linux || android

package ebpf

Expand Down
1 change: 0 additions & 1 deletion hub/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ func updateGeneral(general *config.General, force bool) {
P.ReCreateTProxy(general.TProxyPort, tcpIn, udpIn)
P.ReCreateMixed(general.MixedPort, tcpIn, udpIn)
P.ReCreateAutoRedir(general.EBpf.AutoRedir, tcpIn, udpIn)
P.ReCreateRedirToTun(general.EBpf.RedirectToTun)
}

func updateUsers(users []auth.AuthUser) {
Expand Down
44 changes: 6 additions & 38 deletions listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ var (
mixedListener *mixed.Listener
mixedUDPLister *socks.UDPListener
tunStackListener ipstack.Stack
tcProgram *ebpf.TcEBpfProgram
autoRedirListener *autoredir.Listener
autoRedirProgram *ebpf.TcEBpfProgram

Expand Down Expand Up @@ -371,9 +370,9 @@ func ReCreateAutoRedir(ifaceNames []string, tcpIn chan<- C.ConnContext, _ chan<-
var err error
defer func() {
if err != nil {
if redirListener != nil {
_ = redirListener.Close()
redirListener = nil
if autoRedirListener != nil {
_ = autoRedirListener.Close()
autoRedirListener = nil
}
if autoRedirProgram != nil {
autoRedirProgram.Close()
Expand All @@ -387,10 +386,10 @@ func ReCreateAutoRedir(ifaceNames []string, tcpIn chan<- C.ConnContext, _ chan<-
slices.Sort(nicArr)
nicArr = slices.Compact(nicArr)

if redirListener != nil && autoRedirProgram != nil {
_ = redirListener.Close()
if autoRedirListener != nil && autoRedirProgram != nil {
_ = autoRedirListener.Close()
autoRedirProgram.Close()
redirListener = nil
autoRedirListener = nil
autoRedirProgram = nil
}

Expand Down Expand Up @@ -420,37 +419,6 @@ func ReCreateAutoRedir(ifaceNames []string, tcpIn chan<- C.ConnContext, _ chan<-
log.Infoln("Auto redirect proxy listening at: %s, attached tc ebpf program to interfaces %v", autoRedirListener.Address(), autoRedirProgram.RawNICs())
}

func ReCreateRedirToTun(ifaceNames []string) {
tcMux.Lock()
defer tcMux.Unlock()

nicArr := ifaceNames
slices.Sort(nicArr)
nicArr = slices.Compact(nicArr)

if tcProgram != nil {
tcProgram.Close()
tcProgram = nil
}

if len(nicArr) == 0 {
return
}

if lastTunConf == nil || !lastTunConf.Enable {
return
}

program, err := ebpf.NewTcEBpfProgram(nicArr, lastTunConf.Device)
if err != nil {
log.Errorln("Attached tc ebpf program error: %v", err)
return
}
tcProgram = program

log.Infoln("Attached tc ebpf program to interfaces %v", tcProgram.RawNICs())
}

// GetPorts return the ports of proxy servers
func GetPorts() *Ports {
ports := &Ports{}
Expand Down

0 comments on commit bc38aa9

Please sign in to comment.