Improve IP address handling for v1 and version detection#169
Open
rbqvq wants to merge 2 commits intopires:mainfrom
Open
Improve IP address handling for v1 and version detection#169rbqvq wants to merge 2 commits intopires:mainfrom
rbqvq wants to merge 2 commits intopires:mainfrom
Conversation
The standard `net.IP` implementation can not represent IPv4-mapped IPv6 addresses, `String()` on IPv4-mapped-IPv6 addresses will return IPv4 addresses, which may lead to formatting issues in v1 headers [1]. Migrate from `net.IP` to `netip.Addr` for IP state management to ensure `String()` outputs strictly follow the expected version format. Link: [1]: pires#167 Signed-off-by: Coia Prant <coiaprant@gmail.com>
…atch The previous logic only checked the source IP version, which could lead to incorrect protocol family assignment if the destination IP used a different version. This change ensures that TCPv6/UDPv6 is used if either address is IPv6. The IPv4 address will be format as IPv4-mapped IPv6 address. Signed-off-by: Coia Prant <coiaprant@gmail.com>
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.
The standard
net.IPimplementation inconsistently represents IPv4-mapped IPv6 addresses; itsString()method returns an IPv4 string for mapped addresses, which causes formatting issues in v1 headers where strict version representation is required. (#167)This patch migrates IP state management to
netip.Addrto ensure thatString()outputs and byte representations strictly follow the expected protocol format.Additionally, this fix addresses a bug in the header construction logic.
The previous implementation only verified the source IP version, leading to incorrect protocol family assignments when source and destination address versions mismatched.
The logic now ensures that TCPv6/UDPv6 is selected if either address is IPv6, with IPv4 addresses correctly formatted as IPv4-mapped IPv6 addresses when necessary.
net.IPtonetip.Addrfor robust IP handlingMigrate from #115