Skip to content

Conversation

emersion
Copy link
Contributor

Addresses like 0:0:0:0:0:ffff:7f00:1 should be allowed when parsing
IPv6 protocols.


Not sure how to make this work, so submitting as a draft so that we're at least aware of the issue...

Addresses like 0:0:0:0:0:ffff:7f00:1 should be allowed when parsing
IPv6 protocols.
@emersion emersion changed the title Allow IPv6 compat addresses when parsing TCPv6 Allow IPv6 compat addresses when parsing TCPv6 in V1 header Oct 28, 2020
@pires pires mentioned this pull request Oct 28, 2020
@pires
Copy link
Owner

pires commented Oct 28, 2020

Wait, didn't #49 fix this?

@pires
Copy link
Owner

pires commented Oct 28, 2020

Ah, this is about IP4to6 where an IPv4 address can be encoded in IPv6, as the example you show up above. I think this is a good-to-have and not blocking 0.3.0 on it.

@emersion
Copy link
Contributor Author

Yes, I agree

Base automatically changed from master to main January 18, 2021 10:29
@isedev
Copy link

isedev commented Mar 2, 2021

How about logic along these lines?

func parseV1IPAddress(v6 bool, addr string) (ip net.IP, err error) {
	ip := net.ParseIP(addr)
	tryV4 := ip.To4()
	hasDot := (strings.Index(addr, ".") != -1)
	hasColon := (strings.Index(addr, ":") != -1)
	if (!v6 && (tryV4 == nil || hasColon)) || (v6 && hasDot) {
		err = errors.New("no good")
	}
	return
}

Which give these results:

addr                 error with v6=false?     error with v6=true?
8912:adfb::0124      yes                      no
10.10.0.10           no                       yes
::ffff:0a0a:0a0a     yes                      no
::ffff:10.10.10.10   yes                      yes

The ParseIP() and To4() outputs:

addr                 ParseIP                                       To4
8912:adfb::0124      len=16  ip=8912adfb000000000000000000000124   len=0  ip=
10.10.0.10           len=16  ip=00000000000000000000ffff0a0a000a   len=4  ip=0a0a000a
::ffff:0a0a:0a0a     len=16  ip=00000000000000000000ffff0a0a0a0a   len=4  ip=0a0a0a0a
::ffff:10.10.10.10   len=16  ip=00000000000000000000ffff0a0a0a0a   len=4  ip=0a0a0a0a

The ::ffff:10.10.10.10 is legal IPv6 text but not supported by the proxy protocol standard, as I read it.

If you agree, I can work up a PR.

@isedev
Copy link

isedev commented Mar 2, 2021

On similar note, HeaderProxyFromAddrs will silently assume TCP4 if given a IP4to6 address as source.
Not convinced that's proper behaviour. Can't see how to change that though without also changing function signature...

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.

3 participants