| msg160226 - (view) |
Author: Ivan Sergeev (vsergeev) |
Date: 2012-05-08 21:15 |
| The SMTPServer class of the smtpd module creates a server socket with the IPv4 socket.AF_INET address family hardcoded, and this prevents it from later binding to an IPv6 local address. This occurs on line 282 of smtpd.py for the Python 2.7 branch: http://hg.python.org/cpython/file/5319a4bf72e7/Lib/smtpd.py#l282 And on line 435 of smtpd for the Python 3.2 branch ( Lib/smtpd.py:435 ): http://hg.python.org/cpython/file/d937b527b76e/Lib/smtpd.py#l435 One IPv4/IPv6 agnostic solution is to look up provided local address with getaddrinfo(), and use one of the result's address family, socket type and address tuple for create_socket() and bind() at those lines: ... try: gai_results = socket.getaddrinfo(localaddr[0], localaddr[1]) self.create_socket(gai_results[0][0], gai_results[0][1]) # try to re-use a server port if possible self.set_reuse_addr() self.bind(gai_results[0][4]) self.listen(5) ... |
|
|
| msg160233 - (view) |
Author: Giampaolo Rodola' (giampaolo.rodola) *  |
Date: 2012-05-08 23:47 |
| Agreed. The only problem I see is that unit tests rely on a mock socket object and should be rewritten by using an actual socket. |
|
|
| msg160235 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2012-05-08 23:58 |
| I don't think it is necessary to rewrite the existing tests, just add some that test the socket functionality. |
|
|
| msg160285 - (view) |
Author: Giampaolo Rodola' (giampaolo.rodola) *  |
Date: 2012-05-09 12:21 |
| Unfortunately unit tests overwrite the original smtpd.socket module object with test.mock_socket [1] and the latter one doesn't expose socket.getaddrinfo(). [1] http://hg.python.org/cpython/file/d937b527b76e/Lib/test/test_smtpd.py#l54 |
|
|
| msg160290 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2012-05-09 13:44 |
| Well, that should be fixed anyway (a cleanup added that restores the original value). Then a new TestCase can test the socket stuff. |
|
|
| msg212761 - (view) |
Author: Milan Oberkirch (zvyn) * |
Date: 2014-03-05 14:15 |
| I was going to work on #3461 where IPv6-tests are missing for smtplib and stumbled over this bug. I would be willing to work on this, since it's quiet clear what needs to be done to me: implement what (vsergeev) suggested and write tests (which includes fixing design flaws in current ones). It may be a good idea to teach mouckup_socket some IPv6, since it's needed for test_smtpd and test_smtplib, but IMHO that can be done as a extra task / will be easy after doing the above. |
|
|
| msg212764 - (view) |
Author: Milan Oberkirch (zvyn) * |
Date: 2014-03-05 16:58 |
| The cleaning up of smtpd.socket was already implemented, so there was nothing to do there. What I did: - Write two TestCases to check if the IP version is chosen depending on the host-parameter - Testing, that everything still works with an IPv6 address by inheriting from SMTPDChannelTest and overriding setUp with an IPv6-Server |
|
|
| msg215953 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-04-11 20:34 |
| I added some review comments. Since this is a new feature, the patch also needs a 'versionchanged' that indicates that ipv6 support was added. |
|
|
| msg220091 - (view) |
Author: Milan Oberkirch (zvyn) * |
Date: 2014-06-09 13:51 |
| I applied your suggestions. |
|
|
| msg220128 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-06-09 23:23 |
| When I run the modified test suite on a machine regrtest tells me that the test modified the environment, specifically the asyncore.socket_map. Presumably there is some missing cleanup logic. |
|
|
| msg220172 - (view) |
Author: Milan Oberkirch (zvyn) * |
Date: 2014-06-10 16:32 |
| Fixed it. |
|
|
| msg220291 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2014-06-11 17:49 |
| New changeset 1efbc86a200a by R David Murray in branch 'default': #14758: add IPv6 support to smtpd. http://hg.python.org/cpython/rev/1efbc86a200a |
|
|
| msg220292 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-06-11 17:52 |
| Thanks, Milan. I had to fix a couple things: you had left the "refactored" methods on the SMTPDServerTest, and somehow your new TestFamilyDetection class got indented under SMTPDServerTest in the new version of the patch. (I also had to update it to compensate for the decode_data patch, which copy-and-pasted the DummyServer calling bugs you fixed in the other tests...) |
|
|
| msg220300 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-06-11 18:53 |
| Hmm. Looks like the IPv6 support is making the FreeBSD and and OSX buildbots unhappy :(. |
|
|
| msg220302 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2014-06-11 19:18 |
| New changeset d8e0fca7cbe3 by R David Murray in branch 'default': #14758: Need to specify the desired socket type in the getaddrinfo call. http://hg.python.org/cpython/rev/d8e0fca7cbe3 |
|
|
| msg220305 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2014-06-11 20:21 |
| New changeset 9b0d58b0c712 by R David Murray in branch 'default': #14758: Fix the fix (fix getaddrinfo in mock_socket) http://hg.python.org/cpython/rev/9b0d58b0c712 |
|
|
| msg220308 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2014-06-11 20:36 |
| OK, I think this is fixed. |
|
|