Systemd-networkd generated configuration is wrong when both ipv4 and ipv6 addresses are used

Bug #1973724 reported by Rémy Grünblatt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
High
Alberto Contreras

Bug Description

Hello,

I'm using cloud-init in a proxmox environment, which exposes the configuration as a /dev/sr0.

The generated network-config looks like this:

```

[root@newgate:~]# more /mnt/*|cat
::::::::::::::
/mnt/meta-data
::::::::::::::
instance-id: 550761acf2ff3ad63bf33cab486c12131f73f405
::::::::::::::
/mnt/network-config
::::::::::::::
version: 1
config:
    - type: physical
      name: eth0
      mac_address: 'ae:98:25:fa:36:9e'
      subnets:
      - type: static
        address: '10.0.0.2'
        netmask: '255.255.255.255'
        gateway: '10.0.0.1'
      - type: static6
        address: '2a01:4f8:10a:19d2::4/64'
        gateway: '2a01:4f8:10a:19d2::2'
    - type: nameserver
      address:
      - '100.100.100.100'
      search:
      - 'rgrunbla.github.beta.tailscale.net'
::::::::::::::
/mnt/user-data
::::::::::::::
#cloud-config
hostname: newgate
manage_etc_hosts: true
ssh_authorized_keys:
  - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDwZm6kUsK/FrgJPzFi5AgvqIIYfy5S/Se4/rZgB4Edx remy@typhoon
chpasswd:
  expire: False
users:
  - default
package_upgrade: true
::::::::::::::
/mnt/vendor-data
::::::::::::::

```

The problem is that the generated systemd-networkd configuration is wrong. It looks like this:

```

[root@newgate:~]# cat /etc/systemd/network/10-cloud-init-eth0.network
[Match]
MACAddress=ae:98:25:fa:36:9e
Name=eth0

[Network]
DHCP=no
DNS=100.100.100.100
Domains=rgrunbla.github.beta.tailscale.net

[Address]
Address=10.0.0.2/32
Address=2a01:4f8:10a:19d2::4/64

[Route]
Gateway=10.0.0.1
Gateway=2a01:4f8:10a:19d2::2

```

In particular, the systemd-networkd manual says: "As in the [Network] section. This setting is mandatory. Each [Address] section can contain one Address= setting".

This results in errors in systemd:

```

[root@newgate:~]# systemctl status systemd-networkd --no-pager --all
● systemd-networkd.service - Network Configuration
     Loaded: loaded (/etc/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
    Drop-In: /nix/store/5bj0s92f35hwc06mgjp9dzc0inncva6d-system-units/systemd-networkd.service.d
             └─overrides.conf
     Active: active (running) since Tue 2022-05-17 07:46:48 UTC; 5min ago
TriggeredBy: ● systemd-networkd.socket
       Docs: man:systemd-networkd.service(8)
   Main PID: 643 (systemd-network)
     Status: "Processing requests..."
         IP: 0B in, 392B out
         IO: 1.6M read, 0B written
      Tasks: 1 (limit: 2354)
     Memory: 2.9M
        CPU: 25ms
     CGroup: /system.slice/systemd-networkd.service
             └─643 /nix/store/9c90b5pmgj1pbdvgnalhldhfcj98p400-systemd-250.4/li…

May 17 07:46:48 newgate systemd[1]: Starting Network Configuration...
May 17 07:46:48 newgate systemd-networkd[643]: /etc/systemd/network/10-cloud-init-eth0.network:12: Address is incompatible, ignoring assignment: 2a01:4f8:10a:19d2::4/64
May 17 07:46:48 newgate systemd-networkd[643]: /etc/systemd/network/10-cloud-init-eth0.network: Gateway= without static address configured. Enabling GatewayOnLink= option.
May 17 07:46:48 newgate systemd-networkd[643]: lo: Link UP
May 17 07:46:48 newgate systemd-networkd[643]: lo: Gained carrier
May 17 07:46:48 newgate systemd-networkd[643]: Enumeration completed
May 17 07:46:48 newgate systemd[1]: Started Network Configuration.
May 17 07:46:48 newgate systemd-networkd[643]: eth0: Link UP
May 17 07:46:48 newgate systemd-networkd[643]: eth0: Gained carrier
May 17 07:46:49 newgate systemd-networkd[643]: eth0: Gained IPv6LL

```

Tags: bitesize
Revision history for this message
Rémy Grünblatt (remygrunblatt) wrote :
Revision history for this message
Chad Smith (chad.smith) wrote :

Thanks for the background and analysis and making cloud-init better.
I can confirm the failure using the following steps:

cat > net.cfg <<EOF
version: 1
config:
    - type: physical
      name: eth0
      mac_address: 'ae:98:25:fa:36:9e'
      subnets:
      - type: static
        address: '10.0.0.2'
        netmask: '255.255.255.255'
        gateway: '10.0.0.1'
      - type: static6
        address: '2a01:4f8:10a:19d2::4/64'
        gateway: '2a01:4f8:10a:19d2::2'
    - type: nameserver
      address:
      - '100.100.100.100'
      search:
      - 'rgrunbla.github.beta.tailscale.net'
EOF

cloud-init devel net-convert -k yaml -p net.cfg -O networkd -d data -D ubuntu
cat data/etc/systemd/network/10-cloud-init-eth0.network
etc/systemd/network/10-cloud-init-eth0.network
[Match]
MACAddress=00:16:3e:76:25:ac
Name=eth0

[Network]
DHCP=no
DNS=100.100.100.100
Domains=rgrunbla.github.beta.tailscale.net

[Address]
Address=10.0.0.2/32
Address=2a01:4f8:10a:19d2::4/64

[Route]
Gateway=10.0.0.1
Gateway=2a01:4f8:10a:19d2::2

cp etc/systemd/network/10-cloud-init-eth0.network /lib/systemd/networkd

sudo service systemd-networkd restart
sudo service systemd-networkd status
..
May 19 20:04:06 dev-bb systemd[1]: Starting Network Service...
May 19 20:04:06 dev-bb systemd-networkd[769]: /lib/systemd/network/10-cloud-init
May 19 20:04:06 dev-bb systemd-networkd[769]: eth0: IPv6 successfully enabled
May 19 20:04:06 dev-bb systemd-networkd[769]: eth0: Gained IPv6LL
May 19 20:04:06 dev-bb systemd-networkd[769]: Enumeration completed
May 19 20:04:06 dev-bb systemd[1]: Started Network Service.
May 19 20:04:06 dev-bb systemd-networkd[769]: eth0: Could not set route: No rout
May 19 20:04:06 dev-bb systemd-networkd[769]: eth0: Configured
lines 1-18/18 (END)

```

Changed in cloud-init:
status: New → Triaged
tags: added: bitesize
Changed in cloud-init:
importance: Undecided → High
Changed in cloud-init:
assignee: nobody → Alberto Contreras (aciba)
Revision history for this message
Alberto Contreras (aciba) wrote :
Changed in cloud-init:
status: Triaged → Fix Committed
Revision history for this message
Showfom (showfom) wrote :

We have the same problem with IPv4 and IPv6 both enabled

We should add another [Route] for the IPv4 gateway, or IPv4 is not working

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

Showfom, are you saying there's still related work to be done here? If so, can you please open a new bug for it?

Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
Showfom (showfom) wrote :

James, I have submitted a new bug

https://bugs.launchpad.net/cloud-init/+bug/2003363

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.