2022-07-23 11:01:41 +00:00
|
|
|
//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
|
|
|
|
}
|
|
|
|
|
2022-08-15 03:40:49 +00:00
|
|
|
func NewSearcher(config Config) (Searcher, error) {
|
|
|
|
return &linuxSearcher{config.Logger}, nil
|
2022-07-23 11:01:41 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 02:38:12 +00:00
|
|
|
func (s *linuxSearcher) FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
|
2022-08-26 09:25:36 +00:00
|
|
|
inode, uid, err := resolveSocketByNetlink(network, source, destination)
|
2022-07-23 11:01:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-08-26 09:25:36 +00:00
|
|
|
processPath, err := resolveProcessNameByProcSearch(inode, uid)
|
2022-07-23 11:01:41 +00:00
|
|
|
if err != nil {
|
|
|
|
s.logger.DebugContext(ctx, "find process path: ", err)
|
|
|
|
}
|
|
|
|
return &Info{
|
2022-08-26 09:25:36 +00:00
|
|
|
UserId: int32(uid),
|
2022-07-23 11:01:41 +00:00
|
|
|
ProcessPath: processPath,
|
|
|
|
}, nil
|
|
|
|
}
|