Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only support IPv6 socket? #459

Closed
lastpepole opened this issue Jan 23, 2024 · 2 comments
Closed

only support IPv6 socket? #459

lastpepole opened this issue Jan 23, 2024 · 2 comments

Comments

@lastpepole
Copy link

in aioquic/asyncio/client.py file, line 70

# explicitly enable IPv4/IPv6 dual stack
sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)         // **only support IPv6 socket ?**
completed = False
try:
    sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
    sock.bind((local_host, local_port, 0, 0))
    completed = True
finally:
    if not completed:
        sock.close()
@rthalley
Copy link
Contributor

This is not v6-only. IPv6 can do both v4 and v6 on one socket via IPv4-mapped IPv6 addresses provided it's enabled. This code is explicitly enabling the IPv4 mapped addresses just in case the default has been set to off on a platform. Basically it's ensuring the IPv6-only option is off. If you look a bit above, you can see it constructing an IPv4 mapped address if needed:

if len(addr) == 2:
        addr = ("::ffff:" + addr[0], addr[1], 0, 0)

So, all is ok!

@catap
Copy link

catap commented Jun 22, 2024

@rthalley I'd like you to reconsider this issue. I'm porting it to OpenBSD and OpenBSD has different stack for IPv4 and IPv6.

So, current code is really IPv6 only on OpenBSD and on machine which has only IPv4 it fails as:

aioquic $ python3 examples/http3_client.py https://google.com/     
Traceback (most recent call last):
  File "/home/catap/src/aioquic/examples/http3_client.py", line 564, in <module>
    asyncio.run(
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/catap/src/aioquic/examples/http3_client.py", line 387, in main
    async with connect(
  File "/usr/local/lib/python3.11/contextlib.py", line 210, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aioquic/asyncio/client.py", line 73, in connect
    sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
OSError: [Errno 22] Invalid argument
aioquic $ 

A PR which fixes it: #516

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

No branches or pull requests

3 participants