Opened 17 years ago
Last modified 14 months ago
#5820 new defect
[PATCH] standalone trac does not support IPv6
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | next-stable-1.6.x |
Component: | web frontend/tracd | Version: | 0.11 |
Severity: | normal | Keywords: | ipv6, patch |
Cc: | Thijs Triemstra | Branch: | |
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description (last modified by )
(error is: socket.gaierror: (-9, "Address family for hostname not supported")
The way sockets are initialized is wrong. trac (or the underlying wsgi code for python 2.4) is assuming socket.AF_INET before even knowing the server address.
Standard code for initializing a ipv6 aware socket, that will work in ipv4-only machines (see U. Drepper tutorial) is:
>>> import socket >>> gais = socket.getaddrinfo("::",8000, socket.AF_UNSPEC, socket.SOCK_STREAM) # host, port, af, tcp, ... >>> for gai in gais: ... try: ... sock = socket.socket(*gai[:2]) ... sock.bind(gai[4]) ... break ... except: ... continue ... else: ... sock = None ... raise "Error, couldn't bind"
or something similar. This code should work on any python having getaddrinfo, which means anything modern enough. In fact this code will try to bind in any different possibilities given.
None means localhost in the most general way (127.0.0.1 or ::1); "::" or "0.0.0.0" means any ipv6/ipv4 or any ipv4 address. For concrete addresses, getaddrinfo will parse and take care of the socket parameters.
Attachments (3)
Change History (30)
comment:1 by , 17 years ago
Component: | general → tracd |
---|
comment:2 by , 16 years ago
comment:3 by , 16 years ago
Keywords: | ipv6 added |
---|---|
Milestone: | → 1.0 |
Priority: | normal → low |
Version: | → 0.11 |
by , 16 years ago
Attachment: | t5820-rudimentary-ipv6-support-r7915.diff added |
---|
As we discussed r7915 on #irc, I came across this ticket and played around…
comment:4 by , 16 years ago
When I start tracd with -b ::1 -p 8000
, it seems I can successfully browser my Trac environment using http://[::1]:8000/devel
But then trying to connect http://127.0.0.1:8000/devel fails.
by , 16 years ago
Attachment: | t5820-rudimentary-ipv6-ipv4-support-r7915.diff added |
---|
attempts to listen on both ipv4 and ipv6 addresses
comment:5 by , 16 years ago
PythonBug:3213 and http://mail.python.org/pipermail/python-list/2008-May/489377.html were helpful here.
So with the second patch (which has to be applied in addition to the first), and starting tracd with -b :: -p 8000
, I was able to connect to both http://[::1]:8000/devel and http://127.0.0.1:8000/devel (on Windows Vista).
As expected the second request shows up as a mapped ipv4 address:
::ffff:127.0.0.1 Trac[...
comment:7 by , 14 years ago
Milestone: | triaging → next-major-0.1X |
---|---|
Priority: | low → lowest |
Severity: | normal → minor |
comment:8 by , 14 years ago
Cc: | added |
---|---|
Keywords: | review added |
Summary: | standalone trac does not accept -b "::" → [PATCH] standalone trac does not accept -b "::" |
Seems to me this patch needs a review, I'll check it out.
comment:10 by , 14 years ago
Cc: | added; removed |
---|
comment:11 by , 14 years ago
Description: | modified (diff) |
---|
follow-up: 13 comment:12 by , 14 years ago
Keywords: | patch added; review removed |
---|---|
Milestone: | next-major-0.1X → 0.13 |
Severity: | minor → normal |
Updated the patch which works fine for http://[::1]:8000/test2
:
$ tracd --port=8000 --hostname=::1 . Server starting in PID 14348. Serving on http://::1:8000/ Using HTTP/1.1 protocol version ::1 - - [30/Jan/2011 14:51:07] "GET /test2/wiki HTTP/1.1" 200 - ::1 - - [30/Jan/2011 14:51:07] "GET /test2/chrome/common/css/trac.css HTTP/1.1" 304 - ::1 - - [30/Jan/2011 14:51:07] "GET /test2/chrome/common/css/wiki.css HTTP/1.1" 304 - ::1 - - [30/Jan/2011 14:51:07] "GET /test2/chrome/common/js/jquery.js HTTP/1.1" 304 - ::1 - - [30/Jan/2011 14:51:08] "GET /test2/wiki HTTP/1.1" 200 - ::1 - - [30/Jan/2011 14:51:08] "GET /test2/chrome/common/css/trac.css HTTP/1.1" 304 -
but im not able to access it through http://127.0.0.1:8000
.
comment:13 by , 14 years ago
Replying to thijstriemstra:
but im not able to access it through
http://127.0.0.1:8000
.
There was an issue with the patch, added a new one, and it runs fine on both now (ubuntu 10.10).
comment:14 by , 14 years ago
Uploading files and modifying wiki pages, as described in #2491, also works fine with this patch.
comment:15 by , 14 years ago
Owner: | changed from | to
---|
I don't have a way of testing the patch, but if it works for you, I will apply it.
comment:16 by , 14 years ago
noticed that my patch forgot the url to the mailinglist post:
# in case Python doesn't know about the flags... ref. # http://mail.python.org/pipermail/python-list/2008-May/489377.html
comment:17 by , 14 years ago
Priority: | lowest → low |
---|---|
Summary: | [PATCH] standalone trac does not accept -b "::" → [PATCH] standalone trac does not support IPv6 |
comment:18 by , 14 years ago
Owner: | changed from | to
---|
Oh, sorry Christian, I hadn't noticed that those patches were yours.
comment:19 by , 14 years ago
Well, yes, I wrote that a while ago, but it was more to get a bit familiar with this API than a real need from my side to support IPv6. Also, I didn't test the patch besides trying with the IPv6 loopback interface on my Windows box…
Thijs or Remy, if you were able to test the patch in some real conditions (IPv6 URLs anyone?), and if it works fine for you, then sure we can commit it.
follow-up: 21 comment:20 by , 14 years ago
I don't have an IPv6 setup, so unfortunately I can't test the patch. But I have a few comments on it anyway:
- On my (Linux) box,
socket.IPV6_V6ONLY
is 26, not 27. - It feels strange to have to hardcode those numbers. Couldn't we just try to import them, and not support IPv6 if they aren't found? There's also the
socket.has_ipv6
flag that could be used to detect if IPv6 support is available. - If we don't bind the socket to a specific IP address, will
tracd
work through IPv4 and IPv6 at the same time?
comment:21 by , 14 years ago
Replying to rblank:
I don't have an IPv6 setup, so unfortunately I can't test the patch. But I have a few comments on it anyway:
- On my (Linux) box,
socket.IPV6_V6ONLY
is 26, not 27.
Right, that seems to be platform dependent.
- It feels strange to have to hardcode those numbers. Couldn't we just try to import them, and not support IPv6 if they aren't found? There's also the
socket.has_ipv6
flag that could be used to detect if IPv6 support is available.
Python 2.5 on Windows socket.has_ipv6
is True
, yet socket.IPV6_V6ONLY
is not defined.
We can play it safe and refuse to support IPV6 if that constant is not defined, even if by hardcoding the correct value we could make it work. It depends on how "critical" it is to support this feature for older versions of Python, which I suppose is "not at all critical" ;-)
- If we don't bind the socket to a specific IP address, will
tracd
work through IPv4 and IPv6 at the same time?
You mean, if the address is empty, we should do the same as if ::1
was specified, and we should activate IPv6 support? Why not, yes.
-
ipv6-5820.patch
a b 271 if ':' in options.hostname:271 if not options.hostname or ':' in options.hostname:
comment:22 by , 14 years ago
Instead of trying to guess the value of IPV6_IPV6ONLY
the patch could put the reference to those inside the try
: block, and capture any error and pass
if the machines doesn't know about this option.
Linux has IPV6_IPV6ONLY
to 0
by default, and I think this is also true in most OSes. Windows has it enabled, so only windows needs this block. The failure to set the option will only result in the socket listening only on IPv6, not too bad if the host requested contains ":"…
comment:24 by , 9 years ago
Owner: | removed |
---|
comment:25 by , 8 years ago
Milestone: | next-stable-1.0.x → next-stable-1.2.x |
---|
Moved ticket assigned to next-stable-1.0.x since maintenance of 1.0.x is coming to a close. Please move the ticket back if it's critical to fix on 1.0.x.
comment:26 by , 5 years ago
Milestone: | next-stable-1.2.x → next-stable-1.4.x |
---|
someone should change this ticket to "tracd doesn't support IPv6" -b "::" doesn't ring a bell for most people… BTW this ticket is still valid for trac 0.11