Code: refresh code

This commit is contained in:
yaling888
2021-07-01 22:49:29 +08:00
parent 3ca5d17c40
commit d7732f6ebc
104 changed files with 11329 additions and 136 deletions

View File

@ -16,6 +16,7 @@ var processCache = cache.NewLRUCache(cache.WithAge(2), cache.WithSize(64))
type Process struct {
adapter string
process string
network C.NetWork
}
func (ps *Process) RuleType() C.RuleType {
@ -23,6 +24,17 @@ func (ps *Process) RuleType() C.RuleType {
}
func (ps *Process) Match(metadata *C.Metadata) bool {
if metadata.Process != "" {
//log.Debugln("Use cache process: %s", metadata.Process)
return strings.EqualFold(metadata.Process, ps.process)
}
// ignore match in proxy type "tproxy"
if metadata.Type == C.TPROXY {
return false
}
key := fmt.Sprintf("%s:%s:%s", metadata.NetWork.String(), metadata.SrcIP.String(), metadata.SrcPort)
cached, hit := processCache.Get(key)
if !hit {
@ -42,7 +54,9 @@ func (ps *Process) Match(metadata *C.Metadata) bool {
cached = name
}
return strings.EqualFold(cached.(string), ps.process)
metadata.Process = cached.(string)
return strings.EqualFold(metadata.Process, ps.process)
}
func (ps *Process) Adapter() string {
@ -57,9 +71,14 @@ func (ps *Process) ShouldResolveIP() bool {
return false
}
func NewProcess(process string, adapter string) (*Process, error) {
func (ps *Process) NetWork() C.NetWork {
return ps.network
}
func NewProcess(process string, adapter string, network C.NetWork) (*Process, error) {
return &Process{
adapter: adapter,
process: process,
network: network,
}, nil
}