canonical / canonical/cloud-init

Runtime error raised by get_interfaces_by_mac_on_linux() when multiple gre tunnels are configured

Open
#6,977 0 comments 0 reactions 0 assignees View on GitHub
bug new
Dominant language
Python
Stars
3.8k
Forks
1.1k
Avg merge
2d 23h
Merged PRs (30d)
18

Description

# Bug report
The get_interfaces_by_mac_on_linux() function lists the hex conversion from the source ip address as mac address for a gre tunnel, and raises a runtime error when multiple gre tunnels have the same source ip address.

## Steps to reproduce the problem
1. Use a cloud provider that calls net.get_interfaces_by_mac() in their hotplug script
2. Configure multiple gre tunnels with the same source ip address

## Environment details
- Cloud-init version: 26.1-0ubuntu2
- Operating System Distribution: Ubuntu 26.04 LTS
- Cloud provider, platform or installer type: Hetzner

## cloud-init logs
```
hotplug_hook.py[ERROR]:**` Received fatal exception handling hotplug!

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/cloudinit/cmd/devel/hotplug_hook.py", line 327, in handle_args
handle_hotplug(
~~~~~~~~~~~~~~^
hotplug_init=hotplug_init,
^^^^^^^^^^^^^^^^^^^^^^^^^^
...<2 lines>...
udevaction=args.udevaction,
^^^^^^^^^^^^^^^^^^^^^^^^^^^
--
private_network["mac_address"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
),
^
File "/usr/lib/python3/dist-packages/cloudinit/sources/helpers/hetzner.py", line 42, in get_interface_name_from_mac
mac_to_iface = net.get_interfaces_by_mac()
File "/usr/lib/python3/dist-packages/cloudinit/net/__init__.py", line 898, in get_interfaces_by_mac
return get_interfaces_by_mac_on_linux()
File "/usr/lib/python3/dist-packages/cloudinit/net/__init__.py", line 997, in get_interfaces_by_mac_on_linux
raise RuntimeError(msg)
RuntimeError: duplicate mac found! both 'gre_xx' and 'gre_yy' have mac 'xx:xx:xx:xx'.
```
## temporary workaround
As gre tunnels have not set driver or _devid, we can extend the test short-term fix of LP: #1997922 and replace

> if driver in ("fsl_enetc", "mscc_felix", "qmi_wwan"):

by
> if (driver is None and _devid is None) or driver in ("fsl_enetc", "mscc_felix", "qmi_wwan"): >

This can be done using a single sed command:
```
sed -ie '/if driver in ("fsl_enetc", "mscc_felix", "qmi_wwan"):/s/if/if (driver is None and _devid is None) or/' /usr/lib/python3/dist-packages/cloudinit/net/__init__.py
```

Contributor guide

Open the contributing guide

Research direction

Start in cloudinit/net/__init__.py at get_interfaces_by_mac_on_linux() and inspect the duplicate-MAC handling shown in the traceback. Reproduce the case with multiple GRE tunnels sharing a source IP, then verify that get_interfaces_by_mac() no longer raises a runtime error for those interfaces while preserving duplicate detection for real conflicts.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.