mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-22 17:46:48 +08:00
Router: Add localIP
and localPort
; Add sourceIP
as an alias of source
(#4992)
https://github.com/XTLS/Xray-core/discussions/4984#discussioncomment-13990687 Closes https://github.com/XTLS/Xray-core/issues/4993
This commit is contained in:
@@ -23,6 +23,12 @@ type Context interface {
|
||||
// GetTargetPort returns the target port of the connection.
|
||||
GetTargetPort() net.Port
|
||||
|
||||
// GetLocalIPs returns the local IPs bound to the connection.
|
||||
GetLocalIPs() []net.IP
|
||||
|
||||
// GetLocalPort returns the local port of the connection.
|
||||
GetLocalPort() net.Port
|
||||
|
||||
// GetTargetDomain returns the target domain of the connection, if exists.
|
||||
GetTargetDomain() string
|
||||
|
||||
|
@@ -28,12 +28,13 @@ func (ctx *Context) GetSourceIPs() []net.IP {
|
||||
if ctx.Inbound == nil || !ctx.Inbound.Source.IsValid() {
|
||||
return nil
|
||||
}
|
||||
dest := ctx.Inbound.Source
|
||||
if dest.Address.Family().IsDomain() {
|
||||
return nil
|
||||
|
||||
if ctx.Inbound.Source.Address.Family().IsIP() {
|
||||
return []net.IP{ctx.Inbound.Source.Address.IP()}
|
||||
}
|
||||
|
||||
return []net.IP{dest.Address.IP()}
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
// GetSourcePort implements routing.Context.
|
||||
@@ -65,6 +66,27 @@ func (ctx *Context) GetTargetPort() net.Port {
|
||||
return ctx.Outbound.Target.Port
|
||||
}
|
||||
|
||||
// GetLocalIPs implements routing.Context.
|
||||
func (ctx *Context) GetLocalIPs() []net.IP {
|
||||
if ctx.Inbound == nil || !ctx.Inbound.Local.IsValid() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if ctx.Inbound.Local.Address.Family().IsIP() {
|
||||
return []net.IP{ctx.Inbound.Local.Address.IP()}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLocalPort implements routing.Context.
|
||||
func (ctx *Context) GetLocalPort() net.Port {
|
||||
if ctx.Inbound == nil || !ctx.Inbound.Local.IsValid() {
|
||||
return 0
|
||||
}
|
||||
return ctx.Inbound.Local.Port
|
||||
}
|
||||
|
||||
// GetTargetDomain implements routing.Context.
|
||||
func (ctx *Context) GetTargetDomain() string {
|
||||
if ctx.Outbound == nil || !ctx.Outbound.Target.IsValid() {
|
||||
|
Reference in New Issue
Block a user