-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add internal/net test #615
Conversation
Best reviewed: commit by commit
Optimal code review plan
|
[CHATOPS:HELP] ChatOps commands.
|
/rebase |
[REBASE] Rebase triggered by kevindiu for branch: test/internal/net |
ff38768
to
b792c14
Compare
Codecov Report
@@ Coverage Diff @@
## master #615 +/- ##
==========================================
+ Coverage 13.73% 13.99% +0.25%
==========================================
Files 409 409
Lines 21516 21519 +3
==========================================
+ Hits 2956 3011 +55
+ Misses 18285 18229 -56
- Partials 275 279 +4
Continue to review full report at Codecov.
|
internal/net/net.go
Outdated
func SplitHostPort(hostport string) (host string, port uint16, err error) { | ||
switch { | ||
case strings.HasPrefix(hostport, "::"): | ||
hostport = localIPv6 + hostport | ||
hostport = localIPv6 + hostport[2:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or if the hostport
do not contains port number, there are no []
to wrap the address, instead the host should use the hostport
with port defaultPort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest:
switch {
case hostport == "::1":
hostport = "[" + localIPv6 + "]:" + defaultPort
........
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or we can return directly.
switch {
case hostport == "::1":
return localIPv6, defaultPort, nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to make 2 changes, this case was implemented for detecting loopback address, if there is no port definition on hostport string, we can use default port but in this case we have to check there is a port in hostport string or not, and if exists we have to parse it.
one more thing as you mentioned, loopback addr is ::1
but it also can be written as ::
or 0:0:0:0:0:0:0:1
. so we have to check them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please read RFC more carefully, In RFC5952 (https://tools.ietf.org/html/rfc5952#section-6) there are 6 types of ipv6 w/ port format we should support them.
Your code seems support only 1 format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kpango
May I confirm that this switch case statement is checking if hostport
contains hostname or port number only and use the default value if not exists?
For example, line 98-99 use the default local IPv4 address if the host is missing.
I think IPv6 do not have empty host
case so we don't need to support it.
But I think IPv6 have empty port
, so I wrote the logic above.
BTW net.SplitHostPort
doesn't support all RFC format.
https://golang.org/src/net/ipsock.go?s=4766:4832#L146
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how should we work on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hostport = localIPv6 + hostport[2:] | |
// hostport = localIPv6 + hostport[2:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/rebase |
[REBASE] Rebase triggered by kevindiu for branch: test/internal/net |
3d43512
to
1c943d0
Compare
/rebase |
[REBASE] Rebase triggered by kevindiu for branch: test/internal/net |
33c62ed
to
bcfb14e
Compare
/rebase |
[REBASE] Rebase triggered by kevindiu for branch: test/internal/net |
bcfb14e
to
eb9810f
Compare
/rebase |
[REBASE] Rebase triggered by kpango for branch: test/internal/net |
b39d571
to
229127e
Compare
[FORMAT] Updating license headers and formatting go codes triggered by kpango. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[APPROVED] This PR is approved by kpango.
Author review required.
Description:
This PR implements test case for internal/net/net.go.
This PR also include the following changes:
Bug fix:
In ScanPorts(), when
start > end
, unexpected ports will be scannedFix: https://github.com/vdaas/vald/pull/615/files#diff-111853981bfa0f81d6c8945300daf97bR122-R124
In ScanPorts(), when
end
is 65535, theScanPorts()
will never return due to golang bug or behaviorFix: https://github.com/vdaas/vald/pull/615/files#diff-111853981bfa0f81d6c8945300daf97bR134
Ref: Add internal/net test #615 (comment)
In ScanPorts(), scanning ports in range, with some ports are failed but some success, the error will be returned instead of returning succeed ports
Fix: https://github.com/vdaas/vald/pull/615/files#diff-111853981bfa0f81d6c8945300daf97bR143-R144
https://github.com/vdaas/vald/pull/615/files#diff-111853981bfa0f81d6c8945300daf97bR163-R165
Refactor:
In ScanPorts(), do not return connection close error.
Ref: https://github.com/vdaas/vald/pull/615/files#diff-111853981bfa0f81d6c8945300daf97bR151-R153
In SplitHostPort(), commented out the
::
support due to invalid implementation, which always return error.To support loopback IPv6 address please read the function comment.
Ref: https://github.com/vdaas/vald/pull/615/files#diff-111853981bfa0f81d6c8945300daf97bR98-R101
Related Issue:
How Has This Been Tested?:
Environment:
Types of changes:
Changes to Core Features:
Checklist: