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

ENI and Network-Manager renderers create wrong IPv6 routes #4518

Closed
karibou opened this issue Oct 17, 2023 · 8 comments
Closed

ENI and Network-Manager renderers create wrong IPv6 routes #4518

karibou opened this issue Oct 17, 2023 · 8 comments
Assignees
Labels
bug Something isn't working correctly priority Fix soon

Comments

@karibou
Copy link
Contributor

karibou commented Oct 17, 2023

Bug report

When defining IPv6 route in the v2 network config yaml, the IPv6 route is wrongly defined. The Network-Manager renderer adds it to the [ipv4] section.

Steps to reproduce the problem

Using the following network-config :

# cat config.yaml
version: 2
ethernets:
  eth0:
    dhcp4: true
    routes:
      - to: 169.254.42.42/32
        via: 62.210.0.1
      - via: fe80::dc00:ff:fe20:186
        to: ::/0
    addresses:
      - 2001:bc8:1210:232:dc00:ff:fe20:185/64

when creating a Network-Manager configuration using :

cloud-init devel net-convert -p config.yaml -k yaml -d . -D centos -O network-manager

The [ipv4] section has :

[ipv4]
method=auto
may-fail=false
route1=169.254.42.42/32,62.210.0.1
route2=::/0,fe80::dc00:ff:fe20:186

As seen the IPv6 route gets added to the IPv4 section

Environment details

  • Cloud-init version: 23.3.1-0ubuntu1~22.04.1
  • Operating System Distribution: Ubuntu Jammy
  • Cloud provider, platform or installer type: Scaleway

cloud-init logs

No logs are necessary, the behavior can be reproduced at will using the cloud-init command

@karibou karibou added bug Something isn't working correctly new An issue that still needs triage labels Oct 17, 2023
@TheRealFalcon TheRealFalcon added priority Fix soon and removed new An issue that still needs triage labels Oct 17, 2023
@TheRealFalcon
Copy link
Member

@karibou , thanks for the bug report. I can confirm the problem in versions of cloud-init supporting network-manager.

@karibou

This comment was marked as off-topic.

@karibou
Copy link
Contributor Author

karibou commented Oct 17, 2023

Hello,
I've been peeking at the code and might have an idea of what is happening.
At line https://github.com/canonical/cloud-init/blob/d0f00bd54649e527d69ad597cbcad6efa8548e58/cloudinit/net/network_manager.py#L256C9-L256C9 we have :

        # Deal with Layer 3 configuration
        for subnet in iface["subnets"]:
            family = "ipv6" if subnet_is_ipv6(subnet) else "ipv4"

            self._set_ip_method(family, subnet["type"])
            if "address" in subnet:
                self._add_address(family, subnet)
            if "gateway" in subnet:
                self.config[family]["gateway"] = subnet["gateway"]

With the data given in config.yaml above we get :

iface["subnets"]
[{'type': 'dhcp4', 'routes': [{'gateway': 'fe80::dc00:ff:fe20:23f0', 'network': '169.254.42.42', 'prefix': 32, 'netmask': '255.255.255.255'}, {'network': '::', 'prefix': 0}]}, {'type': 'static', 'address': '2001:bc8:1210:299:dc00:ff:fe20:23ef', 'prefix': 64, 'routes': []}]

The subnet_is_ipv6 is detecting a family of ipv4. when self._add_route(family,route) is executed, it also adds the route pointed to by gateway even if it is an IPv6 route as an IPv4 route.

It looks like embedding IPv6 gateway in the routes section is not taken into account

@TheRealFalcon
Copy link
Member

@karibou , thanks. I'll try to get a fix up soon.

@TheRealFalcon TheRealFalcon self-assigned this Oct 19, 2023
holmanb added a commit to holmanb/cloud-init that referenced this issue Oct 19, 2023
@holmanb
Copy link
Member

holmanb commented Oct 19, 2023

@karibou , thanks. I'll try to get a fix up soon.

Bah, sorry @TheRealFalcon, I had just started working on this when you grabbed this.

The subnet_is_ipv6 is detecting a family of ipv4. when self._add_route(family,route) is executed, it also adds the route pointed to by gateway even if it is an IPv6 route as an IPv4 route.

Nice evaluation @karibou, that looks to be the issue. I have a wip branch to get this fixed, will try to get this fixed soon.

Aside: subnet_is_ipv6() has no place in net/__init__.py. It belongs to, and should be a part of, the renderer code that it introspects. It is utterly useless without the data structures that it reads from.

@TheRealFalcon
Copy link
Member

TheRealFalcon commented Oct 23, 2023

Just a heads up that I'm going to leave this assigned to me, but I did have another issue come up that takes priority, so if somebody else wants to grab it in the meantime, feel free to comment here. Otherwise, I'll pick it up when I can.

@karibou
Copy link
Contributor Author

karibou commented Nov 27, 2023

Hello,
Any chance of getting some attention on this issue ? While we have a workaround, it would be nice to have it solved officially.
TIA,
...Louis

@TheRealFalcon
Copy link
Member

@karibou , this one hasn't fallen off my radar. I just haven't had the time to get back to it. I'm hoping to get back to it this week.

TheRealFalcon added a commit to TheRealFalcon/cloud-init that referenced this issue Nov 28, 2023
Because network v2 route defintions can have mixed v4 and v6 routes, we
need to determine the IP family per route rather than per subnet.

Similar, ensure dns-search is rendered correctly.

Fixes canonicalGH-4518
TheRealFalcon added a commit to TheRealFalcon/cloud-init that referenced this issue Dec 7, 2023
Because network v2 route defintions can have mixed v4 and v6 routes, we
need to determine the IP family per route rather than per subnet.

Similar, ensure dns-search is rendered correctly.

Fixes canonicalGH-4518
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly priority Fix soon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants