forked from MatsuriDayo/Matsuri
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuid.go
41 lines (34 loc) · 948 Bytes
/
uid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package libcore
import (
"syscall"
"github.com/v2fly/v2ray-core/v5/common/net"
)
var (
uidDumper UidDumper
useProcfs bool
)
type UidInfo struct {
PackageName string
Label string
}
type UidDumper interface {
DumpUid(ipProto int32, srcIp string, srcPort int32, destIp string, destPort int32) (int32, error)
GetUidInfo(uid int32) (*UidInfo, error)
}
func SetUidDumper(dumper UidDumper, procfs bool) {
uidDumper = dumper
useProcfs = procfs
}
func dumpUid(source net.Destination, destination net.Destination) (int32, error) {
if useProcfs || uidDumper == nil {
return querySocketUidFromProcFs(source, destination), nil
} else {
var ipProto int32
if destination.Network == net.Network_TCP {
ipProto = syscall.IPPROTO_TCP
} else {
ipProto = syscall.IPPROTO_UDP
}
return uidDumper.DumpUid(ipProto, source.Address.IP().String(), int32(source.Port), destination.Address.IP().String(), int32(destination.Port))
}
}