searcher_linux.go 792 B

1234567891011121314151617181920212223242526272829303132333435
  1. //go:build linux && !android
  2. package process
  3. import (
  4. "context"
  5. "net/netip"
  6. "github.com/sagernet/sing-box/log"
  7. )
  8. var _ Searcher = (*linuxSearcher)(nil)
  9. type linuxSearcher struct {
  10. logger log.ContextLogger
  11. }
  12. func NewSearcher(config Config) (Searcher, error) {
  13. return &linuxSearcher{config.Logger}, nil
  14. }
  15. func (s *linuxSearcher) FindProcessInfo(ctx context.Context, network string, source netip.AddrPort, destination netip.AddrPort) (*Info, error) {
  16. inode, uid, err := resolveSocketByNetlink(network, source, destination)
  17. if err != nil {
  18. return nil, err
  19. }
  20. processPath, err := resolveProcessNameByProcSearch(inode, uid)
  21. if err != nil {
  22. s.logger.DebugContext(ctx, "find process path: ", err)
  23. }
  24. return &Info{
  25. UserId: int32(uid),
  26. ProcessPath: processPath,
  27. }, nil
  28. }