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
|
|
|
|
2023-10-11 22:54:19 +08:00
|
|
|
func ApplyAdditions(metadata *C.Metadata, additions ...Addition) {
|
|
|
|
for _, addition := range additions {
|
|
|
|
addition(metadata)
|
|
|
|
}
|
2022-12-05 10:12:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2023-10-11 22:54:19 +08:00
|
|
|
func WithDstAddr(addr net.Addr) Addition {
|
2023-09-28 18:59:31 +08:00
|
|
|
return func(metadata *C.Metadata) {
|
2023-10-11 22:54:19 +08:00
|
|
|
_ = metadata.SetRemoteAddr(addr)
|
2023-10-10 19:43:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-11 22:54:19 +08:00
|
|
|
func WithSrcAddr(addr net.Addr) Addition {
|
2023-10-10 19:43:26 +08:00
|
|
|
return func(metadata *C.Metadata) {
|
2023-10-11 22:54:19 +08:00
|
|
|
m := C.Metadata{}
|
|
|
|
if err := m.SetRemoteAddr(addr);err ==nil{
|
|
|
|
metadata.SrcIP = m.DstIP
|
|
|
|
metadata.SrcPort = m.DstPort
|
|
|
|
}
|
2023-10-10 19:43:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithInAddr(addr net.Addr) Addition {
|
|
|
|
return func(metadata *C.Metadata) {
|
2023-10-11 22:54:19 +08:00
|
|
|
m := C.Metadata{}
|
|
|
|
if err := m.SetRemoteAddr(addr);err ==nil{
|
|
|
|
metadata.InIP = m.DstIP
|
|
|
|
metadata.InPort = m.DstPort
|
|
|
|
}
|
2023-09-28 18:59:31 +08:00
|
|
|
}
|
|
|
|
}
|