Support dual-stack UDP wildcard listeners - #200
Open
Mygod wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the server’s UDP bind behavior and documentation to better support dual-stack wildcard listeners (IPv4+IPv6) where the OS supports IPv4-mapped IPv6, while preserving explicit IPv6 wildcard behavior and improving IPv6 address formatting.
Changes:
- Treat
UDP_HOST = "0.0.0.0"as a generic wildcard (by letting Go choose the wildcard socket) to enable dual-stack where supported. - Format listener addresses correctly for IPv6 using
net.JoinHostPort, and add unit coverage for the address formatter. - Add Linux integration tests and update all README translations + sample config to document wildcard behavior.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| server_config.toml.simple | Documents dual-stack wildcard vs explicit IPv6 wildcard behavior for UDP_HOST. |
| README.MD | Updates UDP_HOST documentation to describe dual-stack behavior and explicit IPv6 wildcard usage. |
| README_ZH.MD | Same documentation update (Chinese translation). |
| README_RU.MD | Same documentation update (Russian translation). |
| README_IT.MD | Same documentation update (Italian translation). |
| README_FA.MD | Same documentation update (Persian translation). |
| README_ES.MD | Same documentation update (Spanish translation). |
| internal/udpserver/server_runtime.go | Adjusts wildcard handling so 0.0.0.0 can become a generic wildcard bind. |
| internal/udpserver/server_runtime_linux_test.go | Adds Linux-only integration coverage for dual-stack wildcard and explicit IPv6 wildcard preservation. |
| internal/config/server.go | Uses net.JoinHostPort for correct IPv6 address formatting. |
| internal/config/server_test.go | Adds unit tests for ServerConfig.Address() IPv4/IPv6 formatting. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+31
to
+35
| ip := net.ParseIP(s.cfg.UDPHost) | ||
| if ip != nil && ip.IsUnspecified() && ip.To4() != nil { | ||
| // Let Go select a dual-stack wildcard socket where the platform supports it. | ||
| ip = nil | ||
| } |
Comment on lines
475
to
+476
| func (c ServerConfig) Address() string { | ||
| return fmt.Sprintf("%s:%d", c.UDPHost, c.UDPPort) | ||
| return net.JoinHostPort(c.UDPHost, strconv.Itoa(c.UDPPort)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
UDP_HOSTas Go's family-neutral UDP wildcard.UDP_HOSTvalues instead of silently binding a wildcard address.net.JoinHostPort.Compatibility
The empty default maps to
UDPAddr.IP == nil, which is Go's family-neutral wildcard. On platforms supporting IPv4-mapped IPv6, it accepts IPv4 and IPv6 traffic through one socket. Otherwise Go selects an available address family.Non-empty
UDP_HOSTvalues must be unbracketed IP literals. Invalid values, hostnames, and bracketed IPv6 values fail configuration validation instead of expanding the listener to all interfaces.The integration test probes actual mapped-IPv6 capability before requiring both address families.
Validation
go test ./...go vet ./...go test -race ./internal/config ./internal/udpserver -run 'Test(ServerConfigAddress|ServerConfigUDPHostValidation|LoadServerConfigFromJSONBase64AppliesDefaults|OpenUDPListenersRejectsInvalidUDPHost|DefaultUDPListenerIsDualStack|ExplicitIPv6WildcardUsesIPv6Socket)$' -count=20