systemd-resolved-docker icon indicating copy to clipboard operation
systemd-resolved-docker copied to clipboard

Does not work with IPv6?

Open Olen opened this issue 3 years ago • 9 comments

systemd[1]: Starting systemd-resolved-docker.service - systemd-resolved and docker DNS integration...
systemd-resolved-docker[4018773]: Found gateway 172.17.0.1 for docker0
systemd-resolved-docker[4018773]: Found gateway fd00:ffff::1 for docker0 
systemd-resolved-docker[4018773]: Default domain: docker, allowed domains: .docker 
systemd-resolved-docker[4018773]: Traceback (most recent call last): 
systemd-resolved-docker[4018773]:   File "/usr/bin/systemd-resolved-docker", line 33, in <module>
systemd-resolved-docker[4018773]:     sys.exit(load_entry_point('systemd-resolved-docker==1.0.0', 'console_scripts', 'systemd-resolved-docker')())
systemd-resolved-docker[4018773]:   File "/usr/lib/python3.10/site-packages/systemd_resolved_docker/cli.py", line 60, in main
systemd-resolved-docker[4018773]:     docker_listen_addresses = parse_listen_address(docker_listen_address,
systemd-resolved-docker[4018773]:   File "/usr/lib/python3.10/site-packages/systemd_resolved_docker/utils.py", line 28, in parse_listen_address
systemd-resolved-docker[4018773]:     return default_value()   
systemd-resolved-docker[4018773]:   File "/usr/lib/python3.10/site-packages/systemd_resolved_docker/cli.py", line 61, in <lambda>
systemd-resolved-docker[4018773]:     lambda: [parse_ip_port(entry['gateway']) for entry in
systemd-resolved-docker[4018773]:   File "/usr/lib/python3.10/site-packages/systemd_resolved_docker/cli.py", line 61, in <listcomp>
systemd-resolved-docker[4018773]:     lambda: [parse_ip_port(entry['gateway']) for entry in
systemd-resolved-docker[4018773]:   File "/usr/lib/python3.10/site-packages/systemd_resolved_docker/utils.py", line 21, in parse_ip_port
systemd-resolved-docker[4018773]:     return IpAndPort(ip=ipaddress.ip_address(result.hostname), port=result.port or default_port)
systemd-resolved-docker[4018773]:   File "/usr/lib64/python3.10/ipaddress.py", line 54, in ip_address
systemd-resolved-docker[4018773]:     raise ValueError(f'{address!r} does not appear to be an IPv4 or IPv6 address')
systemd-resolved-docker[4018773]: ValueError: 'fd00' does not appear to be an IPv4 or IPv6 address

I had a quick look to try to find where the rest of the IPv6-address is stripped after it "found gateway", but did not see anything obvious.

Olen avatar Nov 29 '22 13:11 Olen

There is an issue with the use of urllib.parse:

>>> address="fd00:1:2:3"
>>> result = urllib.parse.urlsplit('//' + address)
>>> result.hostname
'fd00'
>>> address="[fd00:1:2:3]"
>>> result = urllib.parse.urlsplit('//' + address)
>>> result.hostname
'fd00:1:2:3'

Not really sure why urllib.parse is used here at all. Is there any chance the IP-address it finds as a gateway is an url or contains a port number?

Olen avatar Nov 29 '22 13:11 Olen

I've added functional IPv6 support in #6. @Olen, could you please take a look and see if it works for you?

DEB/RPM packages are in the artifacts here: https://github.com/flaktack/systemd-resolved-docker/actions/runs/3669375041

Not really sure why urllib.parse is used here at all. Is there any chance the IP-address it finds as a gateway is an url or contains a port number?

No, I've fixed it expect only an IP address as the gateway.

flaktack avatar Dec 11 '22 14:12 flaktack

The rpm requires python3.11. Is the srpm available, so I can rebuild it locally?

Olen avatar Dec 11 '22 14:12 Olen

Does the SRPM artifact attached to this action work? https://github.com/flaktack/systemd-resolved-docker/actions/runs/3670318687

flaktack avatar Dec 11 '22 18:12 flaktack

I was able to rebuild it, but I think it was the old version... The changes from the PR is not in the sources I get from that srpm

Olen avatar Dec 11 '22 19:12 Olen

I rebuilt it using the source here instead.

I think the issue comes from here: https://github.com/flaktack/systemd-resolved-docker/blob/43e9877f9ac0813d1b7aeed5e6d9b62277401a09/src/systemd_resolved_docker/utils.py#L26

Which again is called from here: https://github.com/flaktack/systemd-resolved-docker/blob/43e9877f9ac0813d1b7aeed5e6d9b62277401a09/src/systemd_resolved_docker/cli.py#L60

Olen avatar Dec 11 '22 19:12 Olen

The SRPM contained to wrong code, could you test the artifact here? https://github.com/flaktack/systemd-resolved-docker/actions/runs/3670518609

flaktack avatar Dec 11 '22 19:12 flaktack

The problem is that parse_ip_port is called from parse_listen_address.

https://github.com/flaktack/systemd-resolved-docker/blob/353cc031ce279741dc717719ac6a21c2468b45de/src/systemd_resolved_docker/utils.py#L28-L30

And parse_listen_address is used both for the systemd_resolved_listen_address (which contains a port):

https://github.com/flaktack/systemd-resolved-docker/blob/353cc031ce279741dc717719ac6a21c2468b45de/src/systemd_resolved_docker/cli.py#L57-L58

And for the docker_listen_addresses, in which docker_gateway do not contain a port:

https://github.com/flaktack/systemd-resolved-docker/blob/353cc031ce279741dc717719ac6a21c2468b45de/src/systemd_resolved_docker/cli.py#L59-L61

Olen avatar Dec 12 '22 08:12 Olen

Thanks for the links, I'll see what I can do :bow:

flaktack avatar Dec 12 '22 09:12 flaktack