6a78bca9fb
1.Add Network rule, match network type(TCP/UDP) 2.Add logic rules(NOT,OR,AND) -AND,((DOMAIN,baidu.com),(NETWORK,UDP)),REJECT (cherry picked from commit d7092e2e37f2c48282c878edea1b2ebc2912b09a)
53 lines
775 B
Go
53 lines
775 B
Go
package common
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
var (
|
|
errPayload = errors.New("payload error")
|
|
|
|
noResolve = "no-resolve"
|
|
)
|
|
|
|
func HasNoResolve(params []string) bool {
|
|
for _, p := range params {
|
|
if p == noResolve {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func FindNetwork(params []string) C.NetWork {
|
|
for _, p := range params {
|
|
if p == "tcp" {
|
|
return C.TCP
|
|
} else if p == "udp" {
|
|
return C.UDP
|
|
}
|
|
}
|
|
return C.ALLNet
|
|
}
|
|
|
|
func FindSourceIPs(params []string) []*net.IPNet {
|
|
var ips []*net.IPNet
|
|
for _, p := range params {
|
|
if p == noResolve || len(p) < 7 {
|
|
continue
|
|
}
|
|
_, ipnet, err := net.ParseCIDR(p)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
ips = append(ips, ipnet)
|
|
}
|
|
|
|
if len(ips) > 0 {
|
|
return ips
|
|
}
|
|
return nil
|
|
}
|