Skip to content

Fix: Allow DHCP traffic on unmanaged VLAN bridges #1307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

blackdragoon26
Copy link

@blackdragoon26 blackdragoon26 commented Aug 11, 2025

In this patch, I am attempting to work on issue of #1294,
Detect unmanaged bridges with VLAN IDs during network setup.
Add netlink rule to allow DHCP broadcast packets (UDP ports 67/68) to pass on VLAN subinterfaces.
Avoids DHCP client timeouts when containers are connected to VLAN-tagged bridge networks

Summary by Sourcery

Apply DHCP allow rules on VLAN-tagged unmanaged bridges to prevent DHCP client timeouts by permitting UDP ports 67/68 on VLAN subinterfaces.

Bug Fixes:

  • Prevent DHCP client timeouts on VLAN-tagged unmanaged bridge networks by allowing DHCP broadcast traffic.

Enhancements:

  • Add allow_dhcp_on_vlan function in netlink module to lookup VLAN subinterfaces and configure DHCP allow rules for UDP ports 67/68.
  • Invoke allow_dhcp_on_vlan in Bridge driver when creating unmanaged bridges with VLAN IDs to insert the DHCP allow rule.

Copy link

sourcery-ai bot commented Aug 11, 2025

Reviewer's Guide

This PR introduces a netlink-based helper to allow DHCP broadcast packets on VLAN-tagged subinterfaces and integrates its invocation into unmanaged bridge setup when a VLAN ID is specified.

Sequence diagram for DHCP allow rule on VLAN during unmanaged bridge setup

sequenceDiagram
    participant BridgeSetup
    participant NetlinkHelper
    participant Netlink
    BridgeSetup->>NetlinkHelper: Call allow_dhcp_on_vlan(bridge_name, vlan_id)
    NetlinkHelper->>Netlink: Create netlink connection
    NetlinkHelper->>Netlink: Lookup VLAN interface by name
    alt VLAN interface found
        NetlinkHelper->>Netlink: (Would) configure VLAN filtering to allow DHCP
    else VLAN interface not found or error
        NetlinkHelper->>BridgeSetup: Log warning
    end
Loading

Class diagram for new allow_dhcp_on_vlan helper and Bridge integration

classDiagram
    class Bridge {
        +create_interfaces(...)
    }
    class NetlinkHelper {
        +allow_dhcp_on_vlan(bridge_name: str, vlan_id: u16)
    }
    Bridge --> NetlinkHelper : uses
    NetlinkHelper : +allow_dhcp_on_vlan(bridge_name, vlan_id)
Loading

File-Level Changes

Change Details Files
Add helper to configure DHCP allow rules on VLAN subinterfaces
  • Define allow_dhcp_on_vlan function
  • Establish a netlink connection and spawn its task
  • Lookup VLAN interface by name and log status
  • Provide info/warn logs based on lookup outcome
  • Return Result<(), Error>
src/network/netlink.rs
Invoke DHCP-allow helper for unmanaged bridges with VLAN IDs
  • Log configuration intent for VLAN-filtered unmanaged bridge
  • Call allow_dhcp_on_vlan with bridge name and VLAN ID
  • Wrap invocation in error context
src/network/bridge.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Signed-off-by: blackdragoon26 <[email protected]>
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @blackdragoon26 - I've reviewed your changes - here's some feedback:

  • allow_dhcp_on_vlan currently spins up its own Tokio runtime and netlink connection per call—consider making it async and reusing the existing runtime/handle to avoid nested runtimes.
  • The allow_dhcp_on_vlan function has a TODO for actually configuring the VLAN filter—either implement that logic now or remove the placeholder to prevent silent misconfigurations.
  • In the unmanaged bridge setup you still hit the Err(err) return even after calling allow_dhcp_on_vlan, so the control flow never proceeds; adjust the early return so VLAN handling completes as intended.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- allow_dhcp_on_vlan currently spins up its own Tokio runtime and netlink connection per call—consider making it async and reusing the existing runtime/handle to avoid nested runtimes.
- The allow_dhcp_on_vlan function has a TODO for actually configuring the VLAN filter—either implement that logic now or remove the placeholder to prevent silent misconfigurations.
- In the unmanaged bridge setup you still hit the `Err(err)` return even after calling allow_dhcp_on_vlan, so the control flow never proceeds; adjust the early return so VLAN handling completes as intended.

## Individual Comments

### Comment 1
<location> `src/network/netlink.rs:637` </location>
<code_context>
+    tokio::spawn(connection);
+
+    // Lookup VLAN interface by name
+    let mut rt = tokio::runtime::Runtime::new().unwrap();
+    let mut links = rt.block_on(
+        handle
+            .link()
</code_context>

<issue_to_address>
Using a new Tokio runtime inside an async context can lead to resource issues.

Instead of creating a new runtime, pass an existing handle or refactor to prevent nested runtimes and potential thread pool contention.
</issue_to_address>

### Comment 2
<location> `src/network/netlink.rs:652` </location>
<code_context>
+                "Found VLAN interface {}, would configure bridge VLAN filtering to allow DHCP (UDP 67/68)",
+                vlan_iface
+            );
+            // TODO: implement actual VLAN filtering adjustment here
+        }
+        Ok(None) => {
</code_context>

<issue_to_address>
Missing implementation for VLAN filtering adjustment.

If this is meant to be a stub, clarify its status or return an error to indicate the feature is not yet implemented.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
            info!(
                "Found VLAN interface {}, would configure bridge VLAN filtering to allow DHCP (UDP 67/68)",
                vlan_iface
            );
            // TODO: implement actual VLAN filtering adjustment here
=======
            info!(
                "Found VLAN interface {}, would configure bridge VLAN filtering to allow DHCP (UDP 67/68)",
                vlan_iface
            );
            warn!(
                "VLAN filtering adjustment for interface {} is not yet implemented.",
                vlan_iface
            );
            return Err(anyhow::anyhow!(
                "VLAN filtering adjustment for interface {} is not yet implemented.",
                vlan_iface
            ));
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +637 to +638
let mut rt = tokio::runtime::Runtime::new().unwrap();
let mut links = rt.block_on(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Using a new Tokio runtime inside an async context can lead to resource issues.

Instead of creating a new runtime, pass an existing handle or refactor to prevent nested runtimes and potential thread pool contention.

Comment on lines +648 to +652
info!(
"Found VLAN interface {}, would configure bridge VLAN filtering to allow DHCP (UDP 67/68)",
vlan_iface
);
// TODO: implement actual VLAN filtering adjustment here
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Missing implementation for VLAN filtering adjustment.

If this is meant to be a stub, clarify its status or return an error to indicate the feature is not yet implemented.

Suggested change
info!(
"Found VLAN interface {}, would configure bridge VLAN filtering to allow DHCP (UDP 67/68)",
vlan_iface
);
// TODO: implement actual VLAN filtering adjustment here
info!(
"Found VLAN interface {}, would configure bridge VLAN filtering to allow DHCP (UDP 67/68)",
vlan_iface
);
warn!(
"VLAN filtering adjustment for interface {} is not yet implemented.",
vlan_iface
);
return Err(anyhow::anyhow!(
"VLAN filtering adjustment for interface {} is not yet implemented.",
vlan_iface
));

Copy link
Contributor

openshift-ci bot commented Aug 11, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: blackdragoon26, sourcery-ai[bot]
Once this PR has been reviewed and has the lgtm label, please assign luap99 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant