sing-box/common/process/searcher_linux.go

36 lines
792 B
Go
Raw Normal View History

//go:build linux && !android
package process
import (
"context"
"net/netip"
"github.com/sagernet/sing-box/log"
)
var _ Searcher = (*linuxSearcher)(nil)
type linuxSearcher struct {
logger log.ContextLogger
}
func NewSearcher(config Config) (Searcher, error) {
return &linuxSearcher{config.Logger}, nil
}
2022-08-20 10:38:12 +08:00
func (s *linuxSearcher) FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
2022-08-26 17:25:36 +08:00
inode, uid, err := resolveSocketByNetlink(network, source, destination)
if err != nil {
return nil, err
}
2022-08-26 17:25:36 +08:00
processPath, err := resolveProcessNameByProcSearch(inode, uid)
if err != nil {
s.logger.DebugContext(ctx, "find process path: ", err)
}
return &Info{
2022-08-26 17:25:36 +08:00
UserId: int32(uid),
ProcessPath: processPath,
}, nil
}