github.com/yaling888/clash@v1.53.0/constant/rule.go (about) 1 package constant 2 3 import ( 4 "fmt" 5 6 "github.com/yaling888/clash/component/geodata/router" 7 ) 8 9 // Rule Type 10 const ( 11 Domain RuleType = iota 12 DomainSuffix 13 DomainKeyword 14 GEOSITE 15 GEOIP 16 IPCIDR 17 SrcIPCIDR 18 SrcPort 19 DstPort 20 InboundPort 21 Process 22 ProcessPath 23 Script 24 UserAgent 25 IPSet 26 MATCH 27 Group 28 ) 29 30 type RuleType int 31 32 func (rt RuleType) String() string { 33 switch rt { 34 case Domain: 35 return "Domain" 36 case DomainSuffix: 37 return "DomainSuffix" 38 case DomainKeyword: 39 return "DomainKeyword" 40 case GEOSITE: 41 return "GeoSite" 42 case GEOIP: 43 return "GeoIP" 44 case IPCIDR: 45 return "IPCIDR" 46 case SrcIPCIDR: 47 return "SrcIPCIDR" 48 case SrcPort: 49 return "SrcPort" 50 case DstPort: 51 return "DstPort" 52 case InboundPort: 53 return "InboundPort" 54 case Process: 55 return "Process" 56 case ProcessPath: 57 return "ProcessPath" 58 case Script: 59 return "Script" 60 case UserAgent: 61 return "UserAgent" 62 case IPSet: 63 return "IPSet" 64 case MATCH: 65 return "Match" 66 case Group: 67 return "Group" 68 default: 69 return "Unknown" 70 } 71 } 72 73 type RuleGroup []string 74 75 func (rg RuleGroup) String() string { 76 l := len(rg) 77 switch l { 78 case 0: 79 return "" 80 case 1: 81 return rg[0] 82 default: 83 return fmt.Sprintf("%s[%s]", rg[l-1], rg[0]) 84 } 85 } 86 87 type LogRule struct { 88 R Rule 89 } 90 91 func (l LogRule) String() string { 92 return fmt.Sprintf("%s(%s)", l.R.RuleType().String(), l.R.Payload()) 93 } 94 95 type Rule interface { 96 RuleType() RuleType 97 Match(metadata *Metadata) bool 98 Adapter() string 99 Payload() string 100 ShouldResolveIP() bool 101 RuleExtra() *RuleExtra 102 SetRuleExtra(re *RuleExtra) 103 ShouldFindProcess() bool 104 SubRules() []Rule 105 RuleGroups() RuleGroup 106 AppendGroup(group string) 107 } 108 109 type RuleGeoSite interface { 110 GetDomainMatcher() *router.DomainMatcher 111 }