Skip to content

Commit 2f6501b

Browse files
base files
Signed-off-by: blackdragoon26 <[email protected]>
1 parent 6b44b7e commit 2f6501b

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

src/network/bridge.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl<'a> Bridge<'a> {
8585
}
8686
}
8787

88+
8889
impl driver::NetworkDriver for Bridge<'_> {
8990
fn network_name(&self) -> String {
9091
self.info.network.name.clone()
@@ -583,6 +584,19 @@ fn create_interfaces(
583584
}
584585

585586
if let BridgeMode::Unmanaged = data.mode {
587+
if let Some(vlan_id) = data.vlan {
588+
log::info!(
589+
"Configuring VLAN {} filtering rules for unmanaged bridge {}",
590+
vlan_id,
591+
data.bridge_interface_name
592+
);
593+
594+
595+
crate::utils::netlink::allow_dhcp_on_vlan(
596+
&data.bridge_interface_name,
597+
vlan_id,
598+
)?;
599+
}
586600
return Err(err)
587601
.wrap("in unmanaged mode, the bridge must already exist on the host");
588602
}

src/network/netlink.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::{
33
os::fd::{AsFd, AsRawFd, BorrowedFd},
44
};
55

6+
67
use crate::{
78
error::{ErrorWrap, NetavarkError, NetavarkResult},
89
network::constants,
@@ -612,3 +613,57 @@ pub fn parse_create_link_options(msg: &mut LinkMessage, options: CreateLinkOptio
612613
.push(LinkAttribute::NetNsFd(netns.as_raw_fd()));
613614
}
614615
}
616+
617+
618+
use log::{info, warn};
619+
use rtnetlink::{new_connection, Error};
620+
use futures::stream::TryStreamExt;
621+
622+
623+
pub fn allow_dhcp_on_vlan(bridge_name: &str, vlan_id: u16) -> Result<(), Error> {
624+
info!(
625+
"Applying DHCP allow rule on VLAN {} for bridge {}",
626+
vlan_id, bridge_name
627+
);
628+
629+
// Build VLAN subinterface name (e.g., br0.100)
630+
let vlan_iface = format!("{}.{}", bridge_name, vlan_id);
631+
632+
// Create netlink connection
633+
let (connection, handle, _) = new_connection()?;
634+
tokio::spawn(connection);
635+
636+
// Lookup VLAN interface by name
637+
let mut rt = tokio::runtime::Runtime::new().unwrap();
638+
let mut links = rt.block_on(
639+
handle
640+
.link()
641+
.get()
642+
.match_name(vlan_iface.clone())
643+
.execute()
644+
);
645+
646+
match rt.block_on(links.try_next()) {
647+
Ok(Some(_link)) => {
648+
info!(
649+
"Found VLAN interface {}, would configure bridge VLAN filtering to allow DHCP (UDP 67/68)",
650+
vlan_iface
651+
);
652+
// TODO: implement actual VLAN filtering adjustment here
653+
}
654+
Ok(None) => {
655+
warn!(
656+
"VLAN interface {} not found, skipping DHCP allow rule",
657+
vlan_iface
658+
);
659+
}
660+
Err(e) => {
661+
warn!(
662+
"Error looking up VLAN interface {}: {}",
663+
vlan_iface, e
664+
);
665+
}
666+
}
667+
668+
Ok(())
669+
}

0 commit comments

Comments
 (0)