Refactor ParsePortSpec to handle IPv6 addresses, and improve validation#213
Merged
Merged
Conversation
The PortSpec uses colons a delimiter between parts. If an IPv6 address is used, this leads to the colons in the IP-address to be handled as delimiter. Commit 1d78bed also added support for "ChildIP" to the portspec format, which (adding to the above) made parsing the format even more ambiguous. This patch rewrites ParsePortSpec to handle IPv6 addresses, but requires those addresses to be wrapped by square brackes. Signed-off-by: Sebastiaan van Stijn <[email protected]>
There was an inconsistency between ParsePortSpec and ValidatePortSpec; ParsePortSpec accepted "sctp" as a valid proto, whereas ValidatePortSpec did not. This patch re-uses the `validateProto()` function to validate. Signed-off-by: Sebastiaan van Stijn <[email protected]>
The function already validated ParentIP, but did not validate ChildIP; also added a minimal test Signed-off-by: Sebastiaan van Stijn <[email protected]>
This makes sure the IPv6 addresses are wrapped with square brackets (e.g., [::1]:8080) Signed-off-by: Sebastiaan van Stijn <[email protected]>
Member
|
Thanks! |
Contributor
Author
|
Testing it on the moby PR to see if there's things missing still, but I think remaining failures are not in this code (will have to check though) |
thaJeztah
marked this pull request as ready for review
February 13, 2021 15:08
Contributor
Author
|
Moved out of draft; tried this branch separate from the libnetwork changes, and rootless CI on moby passes with this; moby/moby#42021 Well can look into the failures with the libnetwork update separately |
AkihiroSuda
reviewed
Feb 15, 2021
| "socat", | ||
| fmt.Sprintf("%s-LISTEN:%d,bind=%s,reuseaddr,fork,rcvbuf=65536,sndbuf=65536", proto, spec.ParentPort, ipStr), | ||
| fmt.Sprintf(`EXEC:"%s",nofork`, | ||
| fmt.Sprintf("nsenter -U -n --preserve-credentials -t %d socat STDIN %s4:%s", childPID, proto, hp))) |
Member
There was a problem hiding this comment.
I don't understand why this sprintf is nested, but not new in this PR 🤷♂️
Contributor
Author
There was a problem hiding this comment.
Oh! I was also looking at that; at first thought there was a reason, but didn't see any either. Should've changed it while I was modifying the code; let me do a follow-up
5 tasks
Merged
5 tasks
13 tasks
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.
Refactor of portutil, related to moby/moby#41908 and #207
Refactor ParsePortSpec to handle IPv6 addresses
The PortSpec uses colons a delimiter between parts. If an IPv6 address is used, this leads to the colons in the IP-address to be handled as delimiter.
Commit 1d78bed (#207) also added support for "ChildIP" to the portspec format, which (adding to the above) made parsing the format even more ambiguous.
This patch rewrites ParsePortSpec to handle IPv6 addresses, but requires those addresses to be wrapped by square brackes.
ValidatePortSpec: accept sctp as valid proto
There was an inconsistency between ParsePortSpec and ValidatePortSpec; ParsePortSpec accepted "sctp" as a valid proto, whereas ValidatePortSpec did not.
This patch re-uses the
validateProto()function to validate.ValidatePortSpec: validate ChildIP (if set)
The function already validated ParentIP, but did not validate ChildIP; also added a minimal test
Use net.JoinHostPort() to join IP-addresses with port
This makes sure the IPv6 addresses are wrapped with square brackets (e.g.,
[::1]:8080)