feat: implement dual ipv[4-6] stack and allow newt to ipv6 hole punch #130
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.
Community Contribution License Agreement
By creating this pull request, I grant the project maintainers an unlimited,
perpetual license to use, modify, and redistribute these contributions under any terms they
choose, including both the AGPLv3 and the Fossorial Commercial license terms. I
represent that I have the right to grant this license for all contributed content.
Description
see newt issue #126 (base problem)
Refactored the Networking Layer for Dual-Stack Support
Problem: The core network package was the primary source of crashes. It was built exclusively for IPv4, using low-level raw sockets, manual packet building with gopacket, and IPv4-specific BPF filters. This design was fundamentally incompatible with IPv6.
Solution: The entire network/network.go file was rewritten to use standard, high-level UDP sockets (net.ListenPacket). This modern approach allows the operating system's kernel to handle the complexities of both IPv4 and IPv6 packet creation. This change simplified the code by removing the gopacket dependency and all the complex raw socket management logic.
This is a big change and i tested all my common uses-cases, but I am not sure it will not break edge cases.
Corrected Hole Punching Address Parsing
Problem: The initial hole punching logic failed because it used a simple strings.Split on colons (:) to find the port, which does not work for IPv6 addresses. It also attempted to perform DNS lookups on literal IP addresses.
Solution: Replaced the brittle string manipulation with net.SplitHostPort and added a check to correctly parse literal IP addresses without sending them to a DNS resolver.
Please see fosrl/olm#28 also, i made the same fix to prevent Olm from trying to nameresolve a litteral ipv6.
How to test?
Built with
GOOS=linux GOARCH=amd64 go build .
Successfully established a full ipv6 connection from Olm to Newt