Skip to content

Conversation

@MoeSalah1999
Copy link
Contributor

@MoeSalah1999 MoeSalah1999 commented Jan 14, 2026

Proposed Commit Message

On Azure FreeBSD images, cloud-init fails during early networking setup due to a combination of platform mismatches and incorrect assumptions:

- Azure exposes both a Hyper-V synthetic NIC (hn*) and an accelerated VF (mce*) that intentionally share the same MAC address.
- cloud-init assumes MAC addresses uniquely identify interfaces, causing one interface to be silently discarded during enumeration.
- FreeBSD lacked parity with Linux logic that filters Hyper-V accelerated VFs when a synthetic interface is present.
- Interface ordering on FreeBSD was undefined, allowing the VF to be selected as the primary NIC.
- BSD networking code did not fully match the netops API used by cloud-init core.
- Azure ephemeral networking logic hard-failed when DHCP context fields were not populated on non-Linux platforms.

In combination, these issues caused cloud-init to attempt DHCP on the wrong interface, invoke Linux-specific networking operations on FreeBSD, and abort instance initialization.

**Changes Made:**
**1. Tolerate duplicate MAC addresses on FreeBSD**

get_interfaces_by_mac_on_freebsd() now preserves the first discovered interface when duplicate MAC addresses are encountered and logs the event instead of overwriting or failing.

- Maintains the existing Dict[str, str] return contract.
- Prevents loss of the synthetic hn* interface when an accelerated VF shares its MAC.
- Aligns FreeBSD behavior with existing Linux duplicate-MAC tolerance.

**2. Correct FreeBSD device discovery**

get_devicelist() and FreeBSD NIC discovery paths were adjusted to avoid relying on MAC-keyed maps for interface enumeration.

- Ensures all candidate interfaces are discovered on FreeBSD.
- Prevents interface loss due to MAC collisions.
- Keeps Linux and BSD discovery paths separate and appropriate.

**3. Filter Hyper-V accelerated VFs on FreeBSD**

Added FreeBSD parity with existing Linux logic that filters Hyper-V accelerated virtual functions when a synthetic interface is present.

- On Azure FreeBSD:
                 - hn* interfaces are treated as synthetic.
                 - mce* interfaces are treated as accelerated VFs.
- Prevents cloud-init from selecting the VF as the primary interface.
- Mirrors established Linux behavior for Hyper-V environments.

**4. Prefer hn0 as the primary interface on FreeBSD**

Explicitly orders FreeBSD interfaces so that hn0 is preferred when present.

- Reflects Azure platform expectations.
- Ensures deterministic primary NIC selection.
- Avoids reliance on enumeration order or timing.

**5. Fix BSD netops API mismatch**

Updated BsdNetOps.link_down() to accept the family argument expected by the cloud-init netops API.

- Prevents runtime TypeError during network teardown/setup.
- Aligns BSD netops with other platform implementations.
- Does not alter behavior for existing callers.

Fixes GH-6657

Additional Context

Results:

With these changes applied:

  • The correct synthetic NIC (hn*) is consistently selected on Azure FreeBSD.
  • Duplicate MAC addresses no longer cause interface loss.
  • Accelerated VFs are ignored when inappropriate.
  • FreeBSD networking uses the correct netops implementation.
  • Azure datasource initialization completes successfully.
  • No public APIs or existing test expectations are broken.

Scope and Compatibility:

  • Changes are limited to FreeBSD and Azure-specific behavior.
  • Linux behavior remains unchanged.
  • Public helper function return types are preserved.
  • All existing unit tests remain valid.

Test Steps

Provided tests in tests/unittests/net/test_net_freebsd.py.

Log Evidence

This change is covered by new FreeBSD-specific unit tests which assert:

  • duplicate MAC detection
  • preservation of the synthetic hn* interface
  • emission of the expected debug log message

Example asserted log output:

                            Duplicate MAC aa:bb:cc:dd:ee:ff found on hn0 and mce0; keeping first

Merge type

  • Squash merge using "Proposed Commit Message"
  • Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

@MoeSalah1999
Copy link
Contributor Author

Would love to have your opinion on this if possible @blackboxsw

@holmanb
Copy link
Member

holmanb commented Jan 22, 2026

Thanks for this @MoeSalah1999. Please include logs to show that this works.

@holmanb holmanb self-assigned this Jan 22, 2026
@holmanb holmanb added the incomplete Action required by submitter label Jan 22, 2026
@MoeSalah1999
Copy link
Contributor Author

Thanks for this @MoeSalah1999. Please include logs to show that this works.

Thanks @holmanb for the review. I don’t currently have access to an Azure FreeBSD environment to collect live logs, but I’ve added FreeBSD-specific unit tests that exercise the affected code paths and assert the expected debug logging.

In particular, the tests verify that duplicate MAC addresses are detected, the synthetic hn* interface is preserved, accelerated VFs are filtered, and the corresponding debug logs are emitted. I’ve also referenced the asserted log output in the PR description.

@MoeSalah1999
Copy link
Contributor Author

CLA check is failing for some reason, even though I have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

incomplete Action required by submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants