chore: using uint16 for ports in Metadata
This commit is contained in:
@ -2,7 +2,6 @@ package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/Dreamacro/clash/common/utils"
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
@ -28,7 +27,7 @@ func (p *Port) Match(metadata *C.Metadata) (bool, string) {
|
||||
case C.SrcPort:
|
||||
targetPort = metadata.SrcPort
|
||||
}
|
||||
return p.matchPortReal(targetPort), p.adapter
|
||||
return p.portRanges.Check(targetPort), p.adapter
|
||||
}
|
||||
|
||||
func (p *Port) Adapter() string {
|
||||
@ -39,12 +38,6 @@ func (p *Port) Payload() string {
|
||||
return p.port
|
||||
}
|
||||
|
||||
func (p *Port) matchPortReal(portRef string) bool {
|
||||
port, _ := strconv.Atoi(portRef)
|
||||
|
||||
return p.portRanges.Check(uint16(port))
|
||||
}
|
||||
|
||||
func NewPort(port string, adapter string, ruleType C.RuleType) (*Port, error) {
|
||||
portRanges, err := utils.NewIntRanges[uint16](port)
|
||||
if err != nil {
|
||||
|
@ -20,7 +20,7 @@ func TestAND(t *testing.T) {
|
||||
m, _ := and.Match(&C.Metadata{
|
||||
Host: "baidu.com",
|
||||
NetWork: C.TCP,
|
||||
DstPort: "20000",
|
||||
DstPort: 20000,
|
||||
})
|
||||
assert.Equal(t, true, m)
|
||||
|
||||
@ -35,7 +35,7 @@ func TestNOT(t *testing.T) {
|
||||
not, err := NewNOT("((DST-PORT,6000-6500))", "REJECT", ParseRule)
|
||||
assert.Equal(t, nil, err)
|
||||
m, _ := not.Match(&C.Metadata{
|
||||
DstPort: "6100",
|
||||
DstPort: 6100,
|
||||
})
|
||||
assert.Equal(t, false, m)
|
||||
|
||||
|
Reference in New Issue
Block a user