IPv[46] parsing
Tollef Fog Heen
tfheen at fastly.com
Wed Oct 28 10:32:08 CET 2015
2015-10-28 9:58 GMT+01:00 Poul-Henning Kamp <phk at phk.freebsd.dk>:
> --------
> In message <CAJV_h0axHvroOtMPM83q=dCFHBtDL_XMzmGLu0q8mwWnCbSEZw at mail.gmail.com>
> , Federico Schwindt writes:
>
>>While moving from 4.0.x to 4.1 I noticed that std.ip(..., "::1") doesn't
>>work anymore.
>
> I agree this is very far from optimal, but adding special-casing
> IPv6 address by IPv6 address is certainly *not* the way forward.
>
> The real question is, what does "::1:8080" mean ?
It's the IPv6 address 0:0:0:0:0:0:1:8080. I don't see how it could
mean anything else.
> Please propose the exact algorithm you prose for turning strings
> into IP numbers, and bear in mind that we need to be able to
> include port numbers.
I'm not Federico, and this is not an exact algorithm, but:
If string contains four dots and 0 or 1 :-s → parse as v4 (with or
without port depending on presence of :)
If string contains four dots and more than 1 and no []: → parse as v4
mapped ipv6 (port is empty)
If string contains four dots and more than 1 and []: → parse as v4
mapped ipv6 with port
If string contains :: and no [] → parse as v6 (port is empty)
If string contains 7 :s and no [], parse as v6 (port is empty).
If string contains :: and [] → parse as v6 with port
If string contains 7 :s and [], parse as v6 with port
Yes, this means you can't use 127.1 and similar as valid IPs. Don't do
that, then.
IMO, etc.
--
Tollef Fog Heen | Engineer
fastly.com | @fastly | Linkedin
More information about the varnish-dev
mailing list