Skip to content
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

Fix snet.UDPAddress parsing & serialization #3650

Merged
merged 5 commits into from
Feb 3, 2020

Conversation

oncilla
Copy link
Contributor

@oncilla oncilla commented Jan 31, 2020

Allow :port without [] for IPv4.
Use net library functions instead of manual parsing.

Recommended:
  - isd-as,ipv4:port   (e.g., 1-ff00:0:300,192.168.1.1:8080)
  - isd-as,[ipv6]:port (e.g., 1-ff00:0:300,[f00d::1337]:808)

 Others:
  - isd-as,[ipv4]:port (e.g., 1-ff00:0:300,[192.168.1.1]:80)
  - isd-as,[ipv4]      (e.g., 1-ff00:0:300,[192.168.1.1])
  - isd-as,[ipv6]      (e.g., 1-ff00:0:300,[f00d::1337])
  - isd-as,ipv4        (e.g., 1-ff00:0:300,192.168.1.1)
  - isd-as,ipv6        (e.g., 1-ff00:0:300,f00d::1337)

 Not supported:
  - isd-as,ipv6:port    (caveat if ipv6:port builds a valid ipv6 address,
                         it will successfully parse as ipv6 without error)

Fixes #3647

based on #3648


This change is Reviewable

lukedirtwalker and others added 2 commits January 31, 2020 11:10
Allow <IPv4>:port without [].
Use net library functions instead of manual parsing.

Fixes scionproto#3647
Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r2.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @oncilla)


go/lib/snet/udpaddr.go, line 70 at r2 (raw file):

	}
	hostPortPart := parts["host"]
	host, portS, err := net.SplitHostPort(hostPortPart)

Just use net.ResolveUDPAddr(...) here then we can remove the code below.


go/lib/snet/udpaddr.go, line 151 at r2 (raw file):

I

lower case start of error message


go/lib/snet/udpaddr.go, line 165 at r2 (raw file):

// If the input is invalid, or also contains a port, nil is returned.
func hostOnly(s string) net.IP {
	left, right := strings.Count(s, "["), strings.Count(s, "]")

I think the bracket checks could be done separately in the beginning as a validation function. If any of those 2 conditions fail, it is an error and the format is wrong. SplitHostPort will also fail. hostOnly is really only the last line of this function, at which point I don't see the need for a separate function.

Copy link
Contributor Author

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @lukedirtwalker)


go/lib/snet/udpaddr.go, line 70 at r2 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

Just use net.ResolveUDPAddr(...) here then we can remove the code below.

Done.


go/lib/snet/udpaddr.go, line 151 at r2 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…
I

lower case start of error message

Done.


go/lib/snet/udpaddr.go, line 165 at r2 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

I think the bracket checks could be done separately in the beginning as a validation function. If any of those 2 conditions fail, it is an error and the format is wrong. SplitHostPort will also fail. hostOnly is really only the last line of this function, at which point I don't see the need for a separate function.

Done.

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r3.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @oncilla)


go/lib/snet/udpaddr.go, line 157 at r3 (raw file):

// hostOnly parses the input in the case it only contains a host.
// If the input is invalid, or also contains a port, nil is returned.
func hostOnly(s string) net.IP {

remove?

Copy link
Contributor Author

@oncilla oncilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 2 files reviewed, 1 unresolved discussion (waiting on @lukedirtwalker)


go/lib/snet/udpaddr.go, line 157 at r3 (raw file):

Previously, lukedirtwalker (Lukas Vogel) wrote…

remove?

Done.

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Collaborator

@lukedirtwalker lukedirtwalker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@oncilla oncilla merged commit ce1b818 into scionproto:master Feb 3, 2020
@oncilla oncilla deleted the pub-luke branch February 3, 2020 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IPv4 addresses enclosed in brackets against RFC3986
2 participants