2022-12-05 00:20:50 +08:00
|
|
|
package inbound
|
|
|
|
|
|
|
|
import (
|
2023-09-28 18:59:31 +08:00
|
|
|
"net"
|
|
|
|
|
2022-12-05 00:20:50 +08:00
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
|
|
)
|
|
|
|
|
2022-12-05 10:12:53 +08:00
|
|
|
type Addition func(metadata *C.Metadata)
|
2022-12-05 00:20:50 +08:00
|
|
|
|
|
|
|
func (a Addition) Apply(metadata *C.Metadata) {
|
2022-12-05 10:12:53 +08:00
|
|
|
a(metadata)
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithInName(name string) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
|
|
|
metadata.InName = name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-28 17:19:57 +08:00
|
|
|
func WithInUser(user string) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
|
|
|
metadata.InUser = user
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 10:12:53 +08:00
|
|
|
func WithSpecialRules(specialRules string) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
|
|
|
metadata.SpecialRules = specialRules
|
|
|
|
}
|
2022-12-05 00:20:50 +08:00
|
|
|
}
|
2022-12-05 17:53:54 +08:00
|
|
|
|
|
|
|
func WithSpecialProxy(specialProxy string) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
|
|
|
metadata.SpecialProxy = specialProxy
|
|
|
|
}
|
|
|
|
}
|
2023-09-28 18:59:31 +08:00
|
|
|
|
|
|
|
func WithSrcAddr(addr net.Addr) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
2023-10-11 18:17:39 +08:00
|
|
|
addrPort := parseAddr(addr)
|
|
|
|
metadata.SrcIP = addrPort.Addr().Unmap()
|
|
|
|
metadata.SrcPort = addrPort.Port()
|
2023-10-10 19:43:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithDstAddr(addr net.Addr) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
2023-10-11 18:17:39 +08:00
|
|
|
addrPort := parseAddr(addr)
|
|
|
|
metadata.DstIP = addrPort.Addr().Unmap()
|
|
|
|
metadata.DstPort = addrPort.Port()
|
2023-10-10 19:43:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithInAddr(addr net.Addr) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
2023-10-11 18:17:39 +08:00
|
|
|
addrPort := parseAddr(addr)
|
|
|
|
metadata.InIP = addrPort.Addr().Unmap()
|
|
|
|
metadata.InPort = addrPort.Port()
|
2023-09-28 18:59:31 +08:00
|
|
|
}
|
|
|
|
}
|