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

Netplan: Improve support for directly (on-link) connected gateways #4060

Closed
ubuntu-server-builder opened this issue May 12, 2023 · 3 comments
Labels
launchpad Migrated from Launchpad

Comments

@ubuntu-server-builder
Copy link
Collaborator

This bug was originally filed in Launchpad as LP: #2000596

Launchpad details
affected_projects = []
assignee = lesbraz
assignee_name = Louis Sautier
date_closed = 2023-02-22T16:52:39.882333+00:00
date_created = 2022-12-27T20:07:44.718227+00:00
date_fix_committed = 2023-01-09T19:24:24.674052+00:00
date_fix_released = 2023-02-22T16:52:39.882333+00:00
id = 2000596
importance = undecided
is_complete = True
lp_url = https://bugs.launchpad.net/cloud-init/+bug/2000596
milestone = None
owner = lesbraz
owner_name = Louis Sautier
private = False
status = fix_released
submitter = lesbraz
submitter_name = Louis Sautier
tags = []
duplicates = []

Launchpad user Louis Sautier(lesbraz) wrote on 2022-12-27T20:07:44.718227+00:00

Hi,
I am having trouble configuring my directly connected IPv6 gateway via cloud-init when generating configuration for Netplan.

I'll focus on IPv6 but I think IPv4 shares the same code. Let's assume my network_data.json contains the following network (and no extra routes):
"ip_address": "2001:cafe::/64",
"gateway": "2001:ffff::"

First off, let me explain what works with other renderers.
On AlmaLinux 9, the sysconfig renderer generates an ifcfg file that, when read by NetworkManager, result in one route to reach the gateway and a default route, something like this:
2001:ffff:: dev eno1 proto static metric 100 pref medium
default via 2001:ffff:: dev eno1 proto static metric 100 pref medium

On Debian 11, the eni renderer generates a working configuration too, because ifupdown always adds the "onlink" flag to the gateway, see https://salsa.debian.org/debian/ifupdown/-/commit/8b7bca9597d2f75670b182f0fc149cdbaec3544c.
I get something like this:
default via 2001:ffff:: dev eno1 metric 1024 onlink pref medium

However, on Ubuntu 22.10, no route gets created. This is because Netplan acts as a thin wrapper for systemd-networkd, so it doesn't try to automatically guess that the route is on-link.
The resulting Netplan config looks like:
gateway6: 2001:ffff::

Which Netplan turns into a systemd-networkd .network that contains this:
[Network]
[…]
Gateway=2001:ffff::

systemd-networkd debug logs show:
eno1: Requesting static route (n/a): dst: n/a, src: n/a, gw: 2001:ffff::, prefsrc: n/a, scope: global, table: main(254), proto: static, type: unicast, nexthop: 0, priority: 1024, flags: n/a

In order to get a working route via cloud-init, I had to add a route to the gateway in my network_data.json:
"routes": [
{
"network": "2001:ffff::",
"netmask": 128,
"gateway": "::0"
}
],

This way, I get a behaviour similar to AlmaLinux 9's: one route to the gateway in addition to the default route.

What I would like to see is an option to generate this kind of Netplan config:
routes:

  • to: default
    via: 2001:ffff::
    on-link: true

This results in the following .network file:
[Route]
Destination=::/0
Gateway=2001:ffff::
GatewayOnLink=true

Logs show:
eno1: Configuring static route (requesting): dst: n/a, src: n/a, gw: 2001:ffff::, prefsrc: n/a, scope: global, table: main(254), proto: static, type: unicast, nexthop: 0, priority: 1024, flags: onlink
And the route looks like this:
default via 2001:ffff:: dev eno1 proto static metric 1024 onlink pref medium

I don't know how cloud-init could handle this, maybe it could perform some kind of check:
if gateway not in ip_subnet:
# add on-link to config

If this is acceptable, I can file a PR that does it. It'll require migrating away from the deprecated "gateway4" and "gateway6" options (canonical/netplan@7844058) but I don't think that is a problem, we can specify the gateways manually in Netplan's "routes" section.

@ubuntu-server-builder ubuntu-server-builder added the launchpad Migrated from Launchpad label May 12, 2023
@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user James Falcon(falcojr) wrote on 2023-01-04T16:34:07.672154+00:00

Thanks for the thorough bug report. After some conversation in our IRC channel, we agree that your proposed idea of doing a check similar to:

if gateway not in ip_subnet:
# add on-link to config

would be a good addition.

I noticed that you already submitted a PR at #1931 , so we'll track development there.

@ubuntu-server-builder
Copy link
Collaborator Author

Launchpad user Alberto Contreras(aciba) wrote on 2023-02-22T16:52:40.695982+00:00

This bug is believed to be fixed in cloud-init in version 23.1. If this is still a problem for you, please make a comment and set the state back to New

Thank you.

@sbraz
Copy link
Contributor

sbraz commented May 13, 2023

I'm not sure why this was opened, the PR that fixed this was #1931
EDIT: ah I guess maybe an issue was required here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
launchpad Migrated from Launchpad
Projects
None yet
Development

No branches or pull requests

2 participants