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

Bug #2000596 reported by Louis Sautier
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Undecided
Louis Sautier

Bug Description

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 (https://github.com/canonical/netplan/commit/7844058dde8e2df4c6b45d4f08d82832d7932bab) but I don't think that is a problem, we can specify the gateways manually in Netplan's "routes" section.

Revision history for this message
James Falcon (falcojr) wrote :

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 https://github.com/canonical/cloud-init/pull/1931 , so we'll track development there.

Changed in cloud-init:
status: New → Triaged
status: Triaged → In Progress
assignee: nobody → Louis Sautier (lesbraz)
James Falcon (falcojr)
Changed in cloud-init:
status: In Progress → Fix Committed
Revision history for this message
Alberto Contreras (aciba) wrote : Fixed in cloud-init version 23.1.

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.

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.