canonical / canonical/cloud-init

bsd.py not configuring IPv6 with network-config version: 2

Open
#5,319 2 comments 0 reactions 1 assignee Claimed by @a-dubs View on GitHub
bug
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Bug report

When configuring static IPv4 and IPv6 on FreeBSD 14-RELEASE with py39-cloud-init-24.1.4, the IPv6 address is not properly detected.
The same problem with IPv6 gateway.

I believe this is because the bsd.py network configuration code is not updated to work with the `version: 2` syntax.

## Steps to reproduce the problem

```
instance-id: 42021adc-80ed-33e0-02d7-8534efa70ec9
local-hostname: freebsd14
cloud-name: mycloud
network:
version: 2
ethernets:
ens192:
gateway4: 10.0.0.1
gateway6: '2a02:abc:9::1'
addresses: [10.0.0.5/24, 2a02:abc:9::7e6/64]
nameservers:
addresses:
- 10.0.0.1
- '2a02:123:aaaa::1'
```

## Environment details
- Cloud-init version: 24.1.4
- Operating System Distribution: FreeBSD 14
- Cloud provider, platform or installer type: other, VMware with guestinfo.metadata as source

## cloud-init logs

```
2024-05-21 11:54:49,174 - network_state.py[DEBUG]: v2(ethernets) -> v1(physical):
{'type': 'physical', 'mac_address': None, 'name': 'ens192', 'subnets': [{'type': 'static', 'address': '10.0.0.5/24', 'gateway': '10.0.0.1', 'dns_nameservers': ['10.0.0.1', '2a02:abc:aaaa::1']}, {'type': 'static', 'address': '2a02:abc:9::7e6/64', 'gateway': '2a02:abc:9::1'}]}
2024-05-21 11:54:49,177 - network_state.py[DEBUG]: v2_common: handling config:
{'ens192': {'gateway4': '10.0.0.1', 'gateway6': '2a02:abc:9::1', 'addresses': ['10.0.0.5/24', '2a02:abc:9::7e6/64'], 'nameservers': {'addresses': ['10.0.0.1', '2a02:abc:aaaa::1']}}}
2024-05-21 11:54:49,177 - subp.py[DEBUG]: Running command ['ifconfig', '-a', 'ether'] with allowed return codes [0] (shell=False, capture=True)
2024-05-21 11:54:49,180 - bsd.py[INFO]: Cannot find any device with MAC None
2024-05-21 11:54:49,180 - bsd.py[INFO]: Configuring interface ens192
2024-05-21 11:54:49,180 - bsd.py[DEBUG]: Configuring dev ens192 with 10.0.0.5 / 255.255.255.0
2024-05-21 11:54:49,180 - bsd.py[DEBUG]: Skipping IP 2a02:abc:9::7e6, because there is no netmask
2024-05-21 11:54:49,180 - util.py[DEBUG]: Reading from /etc/rc.conf (quiet=False)
2024-05-21 11:54:49,180 - util.py[DEBUG]: Read 389 bytes from /etc/rc.conf
```

## Local patch
```
--- /usr/local/lib/python3.9/site-packages/cloudinit/net/bsd.py 2024-04-03 14:29:07.000000000 +0000
+++ bsd.py.patch 2024-05-23 14:29:53.327390000 +0000
@@ -67,24 +67,39 @@

for subnet in interface.get("subnets", []):
if subnet.get("type") == "static":
- if not subnet.get("netmask"):
+ if not subnet.get("netmask") and not subnet.get("prefix"):
LOG.debug(
"Skipping IP %s, because there is no netmask",
subnet.get("address"),
)
continue
- LOG.debug(
- "Configuring dev %s with %s / %s",
- device_name,
- subnet.get("address"),
- subnet.get("netmask"),
- )
+ if subnet.get("netmask"):
+ LOG.debug(
+ "Configuring dev %s with %s / %s",
+ device_name,
+ subnet.get("address"),
+ subnet.get("netmask"),
+ )
+ self.interface_configurations[device_name] = {
+ "address": subnet.get("address"),
+ "netmask": subnet.get("netmask"),
+ "mtu": subnet.get("mtu") or interface.get("mtu"),
+ }
+ elif subnet.get("prefix"):
+ # IPv6 here
+ LOG.debug(
+ "Configuring dev %s with %s / %s",
+ device_name,
+ subnet.get("address"),
+ subnet.get("prefix"),
+ )

- self.interface_configurations[device_name] = {
- "address": subnet.get("address"),
- "netmask": subnet.get("netmask"),
- "mtu": subnet.get("mtu") or interface.get("mtu"),
- }
+ self.interface_configurations_ipv6[device_name] = {
+ "address": subnet.get("address"),
+ "prefix": subnet.get("prefix"),
+ "mtu": subnet.get("mtu") or interface.get("mtu"),
+ }
+ #END IPv6

elif subnet.get("type") == "static6":
if not subnet.get("prefix"):
@@ -123,6 +138,14 @@
{
"network": "0.0.0.0",
"netmask": "0.0.0.0",
+ "gateway": gateway,
+ }
+ )
+ if gateway and len(gateway.split(":")) > 1:
+ routes.append(
+ {
+ "network": "::",
+ "prefix": "0",
"gateway": gateway,
}
)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.