mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-23 19:03:11 +03:00
Update sing-box core
This commit is contained in:
@@ -424,6 +424,7 @@ func (r *NetworkManager) WIFIState() adapter.WIFIState {
|
||||
}
|
||||
|
||||
func (r *NetworkManager) onWIFIStateChanged(state adapter.WIFIState) {
|
||||
state.BSSID = adapter.NormalizeWIFIBSSID(state.BSSID)
|
||||
r.wifiStateMutex.Lock()
|
||||
if state != r.wifiState {
|
||||
r.wifiState = state
|
||||
|
||||
@@ -3,6 +3,7 @@ package route
|
||||
import (
|
||||
"context"
|
||||
"net/netip"
|
||||
"strings"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/process"
|
||||
@@ -32,3 +33,60 @@ func (r *Router) findProcessInfoCached(ctx context.Context, network string, sour
|
||||
r.processCache.Add(key, processCacheEntry{result: result, err: err})
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *Router) searchProcessInfo(ctx context.Context, metadata *adapter.InboundContext) {
|
||||
if r.processSearcher == nil || metadata.ProcessInfo != nil || !r.isLocalSource(metadata.Source.Addr) {
|
||||
return
|
||||
}
|
||||
var originDestination netip.AddrPort
|
||||
if metadata.OriginDestination.IsValid() {
|
||||
originDestination = metadata.OriginDestination.AddrPort()
|
||||
} else if metadata.Destination.IsIP() {
|
||||
originDestination = metadata.Destination.AddrPort()
|
||||
}
|
||||
processInfo, err := r.findProcessInfoCached(ctx, metadata.Network, metadata.Source.AddrPort(), originDestination)
|
||||
if err != nil {
|
||||
r.logger.InfoContext(ctx, "failed to search process: ", err)
|
||||
return
|
||||
}
|
||||
metadata.ProcessInfo = processInfo
|
||||
if processInfo.ProcessPath != "" {
|
||||
if processInfo.UserName != "" {
|
||||
r.logger.InfoContext(ctx, "found process path: ", processInfo.ProcessPath, ", user: ", processInfo.UserName)
|
||||
} else if processInfo.UserId != -1 {
|
||||
r.logger.InfoContext(ctx, "found process path: ", processInfo.ProcessPath, ", user id: ", processInfo.UserId)
|
||||
} else {
|
||||
r.logger.InfoContext(ctx, "found process path: ", processInfo.ProcessPath)
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(processInfo.AndroidPackageNames) > 0 {
|
||||
r.logger.InfoContext(ctx, "found package name: ", strings.Join(processInfo.AndroidPackageNames, ", "))
|
||||
return
|
||||
}
|
||||
if processInfo.UserId != -1 {
|
||||
if processInfo.UserName != "" {
|
||||
r.logger.InfoContext(ctx, "found user: ", processInfo.UserName)
|
||||
} else {
|
||||
r.logger.InfoContext(ctx, "found user id: ", processInfo.UserId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Router) isLocalSource(source netip.Addr) bool {
|
||||
if !source.IsValid() {
|
||||
return false
|
||||
}
|
||||
source = source.Unmap()
|
||||
if source.IsLoopback() {
|
||||
return true
|
||||
}
|
||||
for _, netInterface := range r.network.InterfaceFinder().Interfaces() {
|
||||
for _, prefix := range netInterface.Addresses {
|
||||
if prefix.Addr().Unmap() == source {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -405,37 +405,7 @@ func (r *Router) matchRule(
|
||||
selectedRule adapter.Rule, selectedRuleIndex int,
|
||||
buffers []*buf.Buffer, packetBuffers []*N.PacketBuffer, fatalErr error,
|
||||
) {
|
||||
if r.processSearcher != nil && metadata.ProcessInfo == nil {
|
||||
var originDestination netip.AddrPort
|
||||
if metadata.OriginDestination.IsValid() {
|
||||
originDestination = metadata.OriginDestination.AddrPort()
|
||||
} else if metadata.Destination.IsIP() {
|
||||
originDestination = metadata.Destination.AddrPort()
|
||||
}
|
||||
processInfo, fErr := r.findProcessInfoCached(ctx, metadata.Network, metadata.Source.AddrPort(), originDestination)
|
||||
if fErr != nil {
|
||||
r.logger.InfoContext(ctx, "failed to search process: ", fErr)
|
||||
} else {
|
||||
if processInfo.ProcessPath != "" {
|
||||
if processInfo.UserName != "" {
|
||||
r.logger.InfoContext(ctx, "found process path: ", processInfo.ProcessPath, ", user: ", processInfo.UserName)
|
||||
} else if processInfo.UserId != -1 {
|
||||
r.logger.InfoContext(ctx, "found process path: ", processInfo.ProcessPath, ", user id: ", processInfo.UserId)
|
||||
} else {
|
||||
r.logger.InfoContext(ctx, "found process path: ", processInfo.ProcessPath)
|
||||
}
|
||||
} else if len(processInfo.AndroidPackageNames) > 0 {
|
||||
r.logger.InfoContext(ctx, "found package name: ", strings.Join(processInfo.AndroidPackageNames, ", "))
|
||||
} else if processInfo.UserId != -1 {
|
||||
if processInfo.UserName != "" {
|
||||
r.logger.InfoContext(ctx, "found user: ", processInfo.UserName)
|
||||
} else {
|
||||
r.logger.InfoContext(ctx, "found user id: ", processInfo.UserId)
|
||||
}
|
||||
}
|
||||
metadata.ProcessInfo = processInfo
|
||||
}
|
||||
}
|
||||
r.searchProcessInfo(ctx, metadata)
|
||||
if metadata.Destination.Addr.IsValid() && r.dnsTransport.FakeIP() != nil && r.dnsTransport.FakeIP().Store().Contains(metadata.Destination.Addr) {
|
||||
domain, loaded := r.dnsTransport.FakeIP().Store().Lookup(metadata.Destination.Addr)
|
||||
if !loaded {
|
||||
|
||||
@@ -18,7 +18,7 @@ type WIFIBSSIDItem struct {
|
||||
func NewWIFIBSSIDItem(networkManager adapter.NetworkManager, bssidList []string) *WIFIBSSIDItem {
|
||||
bssidMap := make(map[string]bool)
|
||||
for _, bssid := range bssidList {
|
||||
bssidMap[bssid] = true
|
||||
bssidMap[adapter.NormalizeWIFIBSSID(bssid)] = true
|
||||
}
|
||||
return &WIFIBSSIDItem{
|
||||
bssidList,
|
||||
|
||||
@@ -40,9 +40,13 @@ func NewNetworkInterfaceAddressItem(networkManager adapter.NetworkManager, inter
|
||||
|
||||
func (r *NetworkInterfaceAddressItem) Match(metadata *adapter.InboundContext) bool {
|
||||
interfaces := r.networkManager.NetworkInterfaces()
|
||||
myInterface := r.networkManager.InterfaceMonitor().MyInterface()
|
||||
match:
|
||||
for ifType, addresses := range r.interfaceAddresses {
|
||||
for _, networkInterface := range interfaces {
|
||||
if networkInterface.Name == myInterface {
|
||||
continue
|
||||
}
|
||||
if networkInterface.Type != ifType {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user