samuong / alpaca

A local HTTP proxy for command-line tools. Supports PAC scripts and NTLM authentication.
Apache License 2.0
196 stars 35 forks source link

IPv6 Support #10

Open samuong opened 5 years ago

samuong commented 5 years ago

The PAC "standard" as defined by Netscape includes a few functions that assume IPv4, so Alpaca currently only supports IPv4.

Microsoft has a few extensions which work better for IPv6 and Google has implemented some of these functions into Chrome (although they make these functions available in the regular FindProxyForURL function, rather than just scoping it to FindProxyForURLEx). These include dnsResolveEx() and myIpAddressEx(), and they both replace functions that return IPv4 addresses only with functions that could return either (or both).

There are also other functions that accept IPv4 addresses, and should be extended to accept IPv6 addresses as well. These include isResolvable() and isInNet().

The only remaining function is convert_addr(). There doesn't appear to be an IPv6 version in Mozilla, Microsoft or Google's implementations, and it doesn't make sense for Alpaca to implement its own extension to the standard, so I'll leave this as it is.

samuong commented 4 months ago

For some reason I closed this when #105 was merged, which was a mistake. That PR was about listening on a local IPv6 port, whereas this issue is about supporting IPv6-aware functions for PAC scripts to call.

As of #123, it is now possible for myIpAddress() to return an IPv6 address. If Alpaca isn't consistent about this, it might break PAC scripts that expect an IPv4 address (e.g. myIpAddress() returns an IPv6 address but the script passes the result to isInNet() rather than isInNetEx()). This should be considered before the next release.

Some references:

  1. Microsoft's IPv6 Extensions to Navigator Auto-Config File Format: https://learn.microsoft.com/en-us/windows/win32/winhttp/ipv6-extensions-to-navigator-auto-config-file-format
  2. A table from the Chromium source code showing IPv6 support in Firefox 3, Internet Explorer 8 and Chrome: https://source.chromium.org/chromium/chromium/src/+/main:services/proxy_resolver/proxy_resolver_v8.cc;l=75-86;drc=8788592a9d2efcececd4f8cfacc174671b265ad2
samuong commented 4 months ago

As I mentioned in my previous comment, I'm inclined to keep all the functions IPv4-only, and build support for IPv6 only in the *Ex() functions, which would be IPv4/IPv6.

I've reproduced the table from the Chromium source code below, and added a row for isInNet() and a column for what I think Alpaca should do:

Firefox 3 Internet Explorer 8 Chrome Alpaca
myIpAddress() IPv4/IPv6 IPv4 IPv4/IPv6 IPv4
dnsResolve() IPv4/IPv6 IPv4 IPv4 IPv4
isResolvable() IPv4/IPv6 IPv4 IPv4 IPv4
isInNet() ? ? IPv4 IPv4 IPv4
myIpAddressEx() N/A IPv4/IPv6 IPv4/IPv6 IPv4/IPv6
dnsResolveEx() N/A IPv4/IPv6 IPv4/IPv6 IPv4/IPv6
sortIpAddressList() N/A IPv4/IPv6 IPv4/IPv6 IPv4/IPv6
isResolvableEx() N/A IPv4/IPv6 IPv4/IPv6 IPv4/IPv6
isInNetEx() N/A IPv4/IPv6 IPv4/IPv6 IPv4/IPv6