Skip to content

Commit a2da994

Browse files
committed
merge
2 parents 129fe9f + 9de9f1e commit a2da994

File tree

26 files changed

+223
-108
lines changed

26 files changed

+223
-108
lines changed

adapter/adapter.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,17 @@ func (p *Proxy) MarshalJSON() ([]byte, error) {
163163
mapping["alive"] = p.alive.Load()
164164
mapping["name"] = p.Name()
165165
mapping["udp"] = p.SupportUDP()
166-
mapping["xudp"] = p.SupportXUDP()
167-
mapping["tfo"] = p.SupportTFO()
168-
mapping["mptcp"] = p.SupportMPTCP()
169-
mapping["smux"] = p.SupportSMUX()
166+
mapping["uot"] = p.SupportUOT()
167+
168+
proxyInfo := p.ProxyInfo()
169+
mapping["xudp"] = proxyInfo.XUDP
170+
mapping["tfo"] = proxyInfo.TFO
171+
mapping["mptcp"] = proxyInfo.MPTCP
172+
mapping["smux"] = proxyInfo.SMUX
173+
mapping["interface"] = proxyInfo.Interface
174+
mapping["dialer-proxy"] = proxyInfo.DialerProxy
175+
mapping["routing-mark"] = proxyInfo.RoutingMark
176+
170177
return json.Marshal(mapping)
171178
}
172179

adapter/inbound/listen.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package inbound
22

33
import (
44
"context"
5+
"fmt"
56
"net"
7+
"net/netip"
68
"sync"
79

810
"github.com/metacubex/mihomo/component/keepalive"
@@ -42,6 +44,27 @@ func MPTCP() bool {
4244
}
4345

4446
func ListenContext(ctx context.Context, network, address string) (net.Listener, error) {
47+
switch network { // like net.Resolver.internetAddrList but filter domain to avoid call net.Resolver.lookupIPAddr
48+
case "tcp", "tcp4", "tcp6", "udp", "udp4", "udp6", "ip", "ip4", "ip6":
49+
if host, port, err := net.SplitHostPort(address); err == nil {
50+
switch host {
51+
case "localhost":
52+
switch network {
53+
case "tcp6", "udp6", "ip6":
54+
address = net.JoinHostPort("::1", port)
55+
default:
56+
address = net.JoinHostPort("127.0.0.1", port)
57+
}
58+
case "": // internetAddrList can handle this special case
59+
break
60+
default:
61+
if _, err := netip.ParseAddr(host); err != nil { // not ip
62+
return nil, fmt.Errorf("invalid network address: %s", address)
63+
}
64+
}
65+
}
66+
}
67+
4568
mutex.RLock()
4669
defer mutex.RUnlock()
4770
return lc.Listen(ctx, network, address)

adapter/outbound/base.go

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,24 +85,15 @@ func (b *Base) SupportUDP() bool {
8585
return b.udp
8686
}
8787

88-
// SupportXUDP implements C.ProxyAdapter
89-
func (b *Base) SupportXUDP() bool {
90-
return b.xudp
91-
}
92-
93-
// SupportTFO implements C.ProxyAdapter
94-
func (b *Base) SupportTFO() bool {
95-
return b.tfo
96-
}
97-
98-
// SupportMPTCP implements C.ProxyAdapter
99-
func (b *Base) SupportMPTCP() bool {
100-
return b.mpTcp
101-
}
102-
103-
// SupportSMUX implements C.ProxyAdapter
104-
func (b *Base) SupportSMUX() bool {
105-
return false
88+
// ProxyInfo implements C.ProxyAdapter
89+
func (b *Base) ProxyInfo() (info C.ProxyInfo) {
90+
info.XUDP = b.xudp
91+
info.TFO = b.tfo
92+
info.MPTCP = b.mpTcp
93+
info.SMUX = false
94+
info.Interface = b.iface
95+
info.RoutingMark = b.rmark
96+
return
10697
}
10798

10899
// IsL3Protocol implements C.ProxyAdapter

adapter/outbound/http.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ func (h *Http) SupportWithDialer() C.NetWork {
9292
return C.TCP
9393
}
9494

95+
// ProxyInfo implements C.ProxyAdapter
96+
func (h *Http) ProxyInfo() C.ProxyInfo {
97+
info := h.Base.ProxyInfo()
98+
info.DialerProxy = h.option.DialerProxy
99+
return info
100+
}
101+
95102
func (h *Http) shakeHand(metadata *C.Metadata, rw io.ReadWriter) error {
96103
addr := metadata.RemoteAddress()
97104
HeaderString := "CONNECT " + addr + " HTTP/1.1\r\n"

adapter/outbound/hysteria.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ func (h *Hysteria) genHdc(ctx context.Context, opts ...dialer.Option) utils.Pack
8787
}
8888
}
8989

90+
// ProxyInfo implements C.ProxyAdapter
91+
func (h *Hysteria) ProxyInfo() C.ProxyInfo {
92+
info := h.Base.ProxyInfo()
93+
info.DialerProxy = h.option.DialerProxy
94+
return info
95+
}
96+
9097
type HysteriaOption struct {
9198
BasicOption
9299
Name string `proxy:"name"`

adapter/outbound/hysteria2.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func closeHysteria2(h *Hysteria2) {
9696
}
9797
}
9898

99+
// ProxyInfo implements C.ProxyAdapter
100+
func (h *Hysteria2) ProxyInfo() C.ProxyInfo {
101+
info := h.Base.ProxyInfo()
102+
info.DialerProxy = h.option.DialerProxy
103+
return info
104+
}
105+
99106
func NewHysteria2(option Hysteria2Option) (*Hysteria2, error) {
100107
addr := net.JoinHostPort(option.Server, strconv.Itoa(option.Port))
101108
var salamanderPassword string

adapter/outbound/mieru.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ func (m *Mieru) DialContext(ctx context.Context, metadata *C.Metadata, _ ...dial
6262
return NewConn(c, m), nil
6363
}
6464

65+
// ProxyInfo implements C.ProxyAdapter
66+
func (m *Mieru) ProxyInfo() C.ProxyInfo {
67+
info := m.Base.ProxyInfo()
68+
info.DialerProxy = m.option.DialerProxy
69+
return info
70+
}
71+
6572
func NewMieru(option MieruOption) (*Mieru, error) {
6673
config, err := buildMieruClientConfig(option)
6774
if err != nil {

adapter/outbound/shadowsocks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ func (ss *ShadowSocks) SupportWithDialer() C.NetWork {
197197
return C.ALLNet
198198
}
199199

200+
// ProxyInfo implements C.ProxyAdapter
201+
func (ss *ShadowSocks) ProxyInfo() C.ProxyInfo {
202+
info := ss.Base.ProxyInfo()
203+
info.DialerProxy = ss.option.DialerProxy
204+
return info
205+
}
206+
200207
// ListenPacketOnStreamConn implements C.ProxyAdapter
201208
func (ss *ShadowSocks) ListenPacketOnStreamConn(ctx context.Context, c net.Conn, metadata *C.Metadata) (_ C.PacketConn, err error) {
202209
if ss.option.UDPOverTCP {

adapter/outbound/shadowsocksr.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ func (ssr *ShadowSocksR) SupportWithDialer() C.NetWork {
122122
return C.ALLNet
123123
}
124124

125+
// ProxyInfo implements C.ProxyAdapter
126+
func (ssr *ShadowSocksR) ProxyInfo() C.ProxyInfo {
127+
info := ssr.Base.ProxyInfo()
128+
info.DialerProxy = ssr.option.DialerProxy
129+
return info
130+
}
131+
125132
func NewShadowSocksR(option ShadowSocksROption) (*ShadowSocksR, error) {
126133
// SSR protocol compatibility
127134
// https://github.com/metacubex/mihomo/pull/2056

adapter/outbound/singmux.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ func (s *SingMux) SupportUOT() bool {
9797
return true
9898
}
9999

100-
func (s *SingMux) SupportSMUX() bool {
101-
return true
100+
func (s *SingMux) ProxyInfo() C.ProxyInfo {
101+
info := s.ProxyAdapter.ProxyInfo()
102+
info.SMUX = true
103+
return info
102104
}
103105

104106
func closeSingMux(s *SingMux) {

0 commit comments

Comments
 (0)