feat: RESTful API support disable sniffer
This commit is contained in:
parent
c0eb9aac1c
commit
149b4b5b43
5 changed files with 35 additions and 16 deletions
|
@ -47,13 +47,14 @@ type General struct {
|
|||
UnifiedDelay bool
|
||||
LogLevel log.LogLevel `json:"log-level"`
|
||||
IPv6 bool `json:"ipv6"`
|
||||
Interface string `json:"-"`
|
||||
Interface string `json:"interface-name"`
|
||||
RoutingMark int `json:"-"`
|
||||
GeodataMode bool `json:"geodata-mode"`
|
||||
GeodataLoader string `json:"geodata-loader"`
|
||||
TCPConcurrent bool `json:"tcp-concurrent"`
|
||||
EnableProcess bool `json:"enable-process"`
|
||||
Tun Tun `json:"tun"`
|
||||
Sniffing bool `json:"sniffing"`
|
||||
}
|
||||
|
||||
// Inbound config
|
||||
|
|
|
@ -119,6 +119,8 @@ func GetGeneral() *config.General {
|
|||
IPv6: !resolver.DisableIPv6,
|
||||
GeodataLoader: G.LoaderName(),
|
||||
Tun: P.GetTunConf(),
|
||||
Interface: dialer.DefaultInterface.Load(),
|
||||
Sniffing: tunnel.IsSniffing(),
|
||||
}
|
||||
|
||||
return general
|
||||
|
|
|
@ -36,6 +36,7 @@ type configSchema struct {
|
|||
Mode *tunnel.TunnelMode `json:"mode"`
|
||||
LogLevel *log.LogLevel `json:"log-level"`
|
||||
IPv6 *bool `json:"ipv6"`
|
||||
Sniffing *bool `json:"sniffing"`
|
||||
}
|
||||
|
||||
func getConfigs(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -67,6 +68,10 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
|||
P.SetBindAddress(*general.BindAddress)
|
||||
}
|
||||
|
||||
if general.Sniffing != nil {
|
||||
tunnel.SetSniffing(*general.Sniffing)
|
||||
}
|
||||
|
||||
ports := P.GetPorts()
|
||||
|
||||
tcpIn := tunnel.TCPIn()
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/Dreamacro/clash/listener/inner"
|
||||
"github.com/Dreamacro/clash/listener/tun/ipstack/commons"
|
||||
"net"
|
||||
"net/netip"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
@ -26,10 +25,9 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
allowLan = false
|
||||
bindAddress = "*"
|
||||
lastTunConf *config.Tun
|
||||
lastTunAddressPrefix *netip.Prefix
|
||||
allowLan = false
|
||||
bindAddress = "*"
|
||||
lastTunConf *config.Tun
|
||||
|
||||
socksListener *socks.Listener
|
||||
socksUDPListener *socks.UDPListener
|
||||
|
@ -467,5 +465,4 @@ func Cleanup(wait bool) {
|
|||
}
|
||||
tunStackListener = nil
|
||||
lastTunConf = nil
|
||||
lastTunAddressPrefix = nil
|
||||
}
|
||||
|
|
|
@ -25,14 +25,15 @@ import (
|
|||
)
|
||||
|
||||
var (
|
||||
tcpQueue = make(chan C.ConnContext, 200)
|
||||
udpQueue = make(chan *inbound.PacketAdapter, 200)
|
||||
natTable = nat.New()
|
||||
rules []C.Rule
|
||||
proxies = make(map[string]C.Proxy)
|
||||
providers map[string]provider.ProxyProvider
|
||||
ruleProviders map[string]provider.RuleProvider
|
||||
configMux sync.RWMutex
|
||||
tcpQueue = make(chan C.ConnContext, 200)
|
||||
udpQueue = make(chan *inbound.PacketAdapter, 200)
|
||||
natTable = nat.New()
|
||||
rules []C.Rule
|
||||
proxies = make(map[string]C.Proxy)
|
||||
providers map[string]provider.ProxyProvider
|
||||
ruleProviders map[string]provider.RuleProvider
|
||||
sniffingEnable bool
|
||||
configMux sync.RWMutex
|
||||
|
||||
// Outbound Rule
|
||||
mode = Rule
|
||||
|
@ -43,6 +44,18 @@ var (
|
|||
failTotal int
|
||||
)
|
||||
|
||||
func SetSniffing(b bool) {
|
||||
if sniffer.Dispatcher.Enable() {
|
||||
configMux.Lock()
|
||||
sniffingEnable = b
|
||||
configMux.Unlock()
|
||||
}
|
||||
}
|
||||
|
||||
func IsSniffing() bool {
|
||||
return sniffingEnable
|
||||
}
|
||||
|
||||
func init() {
|
||||
go process()
|
||||
}
|
||||
|
@ -96,6 +109,7 @@ func UpdateProxies(newProxies map[string]C.Proxy, newProviders map[string]provid
|
|||
func UpdateSniffer(dispatcher *sniffer.SnifferDispatcher) {
|
||||
configMux.Lock()
|
||||
sniffer.Dispatcher = *dispatcher
|
||||
sniffingEnable = true
|
||||
configMux.Unlock()
|
||||
}
|
||||
|
||||
|
@ -325,7 +339,7 @@ func handleTCPConn(connCtx C.ConnContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if sniffer.Dispatcher.Enable() {
|
||||
if sniffer.Dispatcher.Enable() && sniffingEnable {
|
||||
sniffer.Dispatcher.TCPSniff(connCtx.Conn(), metadata)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue