Add Auto Transport Mode with IPv4/IPv6 probing and WSS support#5299
Add Auto Transport Mode with IPv4/IPv6 probing and WSS support#5299ming79486 wants to merge 10 commits intofatedier:devfrom
Conversation
| if protocol == "" { | ||
| protocol = "unknown" | ||
| } | ||
| m.autoRejects.WithLabelValues(protocol).Inc() |
There was a problem hiding this comment.
WARNING: Rejected protocol labels are client-controlled
protocol comes from SelectTransport before the client has completed login, so an unauthenticated peer can send many unique values and create unbounded Prometheus time series. Normalize this to a fixed label set, for example known protocols plus unknown, before calling WithLabelValues.
| } | ||
| m.mu.Lock() | ||
| defer m.mu.Unlock() | ||
| incCounterMap(m.info.AutoTransportIllegalSelections, protocol, 1) |
There was a problem hiding this comment.
WARNING: Rejected protocol names can grow this map without bound
This key is populated from the pre-login SelectTransport.Protocol value. A client can send arbitrary unique strings and permanently add entries to AutoTransportIllegalSelections, amplifying memory usage and /api/serverinfo responses. Bucket unknown protocols instead of storing the raw value.
| out.Transport.Auto.Enabled = lo.ToPtr(true) | ||
| } | ||
| out.Transport.Auto.Candidates = conf.AutoCandidates | ||
| if conf.AutoAllowUDP { |
There was a problem hiding this comment.
WARNING: Legacy auto_allow_udp = false is not preserved
The conversion only sets AllowUDP when the parsed value is true. When a legacy INI config explicitly sets auto_allow_udp = false, this remains nil and ClientAutoTransportConfig.Complete defaults it back to true, so users cannot disable UDP candidates through the legacy config path.
| if conf.AutoEnabled { | ||
| out.Transport.Auto.Enabled = lo.ToPtr(true) | ||
| } | ||
| if conf.AutoAllowDynamicSwitch { |
There was a problem hiding this comment.
WARNING: Legacy auto_allow_dynamic_switch = false is not preserved
This only writes AllowDynamicSwitch when the legacy value is true. For an explicit false value, the pointer stays nil and ServerAutoTransportConfig.Complete defaults it to true in auto mode, enabling dynamic switching despite the legacy config.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (13 files)
Reviewed by gpt-5.5-20260423 · 570,530 tokens |
WHY
This PR adds Auto Transport Mode for frp, allowing
frpcandfrpsto negotiate and select the best transport protocol when both sides settransport.protocol = "auto".Changes
tcp,kcp,quic,websocket, andwss.bindPortkcpBindPortquicBindPortbindPortfrpsandfrpc.Notes
transport.protocol = "auto".transport.proxyURLis configured on the client, candidates are restricted totcp.frps;frpclearns it from server advertisement during bootstrap.Tested
go test ./server -count=1go test ./client ./server ./pkg/config/v1 ./pkg/config/v1/validation -count=1go test ./pkg/config ./pkg/config/v1 ./pkg/config/v1/validation -count=1