mirror of
https://github.com/fatedier/frp.git
synced 2026-01-10 10:13:16 +00:00
xtcp: add configuration to disable assisted addresses in NAT traversal (#4951)
This commit is contained in:
@@ -96,6 +96,14 @@ type TLSConfig struct {
|
||||
ServerName string `json:"serverName,omitempty"`
|
||||
}
|
||||
|
||||
// NatTraversalConfig defines configuration options for NAT traversal
|
||||
type NatTraversalConfig struct {
|
||||
// DisableAssistedAddrs disables the use of local network interfaces
|
||||
// for assisted connections during NAT traversal. When enabled,
|
||||
// only STUN-discovered public addresses will be used.
|
||||
DisableAssistedAddrs bool `json:"disableAssistedAddrs,omitempty"`
|
||||
}
|
||||
|
||||
type LogConfig struct {
|
||||
// This is destination where frp should write the logs.
|
||||
// If "console" is used, logs will be printed to stdout, otherwise,
|
||||
|
||||
@@ -422,6 +422,9 @@ type XTCPProxyConfig struct {
|
||||
|
||||
Secretkey string `json:"secretKey,omitempty"`
|
||||
AllowUsers []string `json:"allowUsers,omitempty"`
|
||||
|
||||
// NatTraversal configuration for NAT traversal
|
||||
NatTraversal *NatTraversalConfig `json:"natTraversal,omitempty"`
|
||||
}
|
||||
|
||||
func (c *XTCPProxyConfig) MarshalToMsg(m *msg.NewProxy) {
|
||||
|
||||
@@ -160,6 +160,9 @@ type XTCPVisitorConfig struct {
|
||||
MinRetryInterval int `json:"minRetryInterval,omitempty"`
|
||||
FallbackTo string `json:"fallbackTo,omitempty"`
|
||||
FallbackTimeoutMs int `json:"fallbackTimeoutMs,omitempty"`
|
||||
|
||||
// NatTraversal configuration for NAT traversal
|
||||
NatTraversal *NatTraversalConfig `json:"natTraversal,omitempty"`
|
||||
}
|
||||
|
||||
func (c *XTCPVisitorConfig) Complete(g *ClientCommonConfig) {
|
||||
|
||||
@@ -68,6 +68,13 @@ var (
|
||||
DetectRoleReceiver = "receiver"
|
||||
)
|
||||
|
||||
// PrepareOptions defines options for NAT traversal preparation
|
||||
type PrepareOptions struct {
|
||||
// DisableAssistedAddrs disables the use of local network interfaces
|
||||
// for assisted connections during NAT traversal
|
||||
DisableAssistedAddrs bool
|
||||
}
|
||||
|
||||
type PrepareResult struct {
|
||||
Addrs []string
|
||||
AssistedAddrs []string
|
||||
@@ -108,7 +115,7 @@ func PreCheck(
|
||||
}
|
||||
|
||||
// Prepare is used to do some preparation work before penetration.
|
||||
func Prepare(stunServers []string) (*PrepareResult, error) {
|
||||
func Prepare(stunServers []string, opts PrepareOptions) (*PrepareResult, error) {
|
||||
// discover for Nat type
|
||||
addrs, localAddr, err := Discover(stunServers, "")
|
||||
if err != nil {
|
||||
@@ -133,9 +140,13 @@ func Prepare(stunServers []string) (*PrepareResult, error) {
|
||||
return nil, fmt.Errorf("listen local udp addr error: %v", err)
|
||||
}
|
||||
|
||||
assistedAddrs := make([]string, 0, len(localIPs))
|
||||
for _, ip := range localIPs {
|
||||
assistedAddrs = append(assistedAddrs, net.JoinHostPort(ip, strconv.Itoa(laddr.Port)))
|
||||
// Apply NAT traversal options
|
||||
var assistedAddrs []string
|
||||
if !opts.DisableAssistedAddrs {
|
||||
assistedAddrs = make([]string, 0, len(localIPs))
|
||||
for _, ip := range localIPs {
|
||||
assistedAddrs = append(assistedAddrs, net.JoinHostPort(ip, strconv.Itoa(laddr.Port)))
|
||||
}
|
||||
}
|
||||
return &PrepareResult{
|
||||
Addrs: addrs,
|
||||
|
||||
Reference in New Issue
Block a user