feat(gateway): bridge relay and LAN frames
The gateway now runs the actual frame bridge after relay admission. It registers the AF_PACKET socket with Tokio using AsyncFd, reads valid LAN Ethernet frames and forwards them as relay datagrams, and writes valid relay Ethernet datagrams back to the LAN socket. The packet socket is opened nonblocking so the bridge can shut down cleanly on Ctrl-C without leaving a blocking recv thread behind. Existing send_ethernet and recv_ethernet helpers now share the same validation and encoding helpers used by the bridge. This still needs a privileged LAN-host smoke test with a real wired interface, but the compile-time and loopback coverage now include the gateway relay side of the bridge and the non-root-safe packet-socket validation. Test Plan: - cargo fmt --check - cargo test --workspace - cargo clippy --workspace --all-targets -- -D warnings Refs: PLAN.md gateway AF_PACKET to relay bridge loop
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{
|
||||
ffi::CString,
|
||||
io,
|
||||
os::fd::{AsRawFd, FromRawFd, OwnedFd},
|
||||
os::fd::{AsRawFd, FromRawFd, OwnedFd, RawFd},
|
||||
};
|
||||
|
||||
const ETH_P_ALL: u16 = libc::ETH_P_ALL as u16;
|
||||
@@ -22,7 +22,7 @@ impl PacketSocket {
|
||||
// a new file descriptor or -1 without aliasing Rust-owned memory.
|
||||
libc::socket(
|
||||
libc::AF_PACKET,
|
||||
libc::SOCK_RAW | libc::SOCK_CLOEXEC,
|
||||
libc::SOCK_RAW | libc::SOCK_CLOEXEC | libc::SOCK_NONBLOCK,
|
||||
protocol,
|
||||
)
|
||||
};
|
||||
@@ -110,6 +110,12 @@ impl PacketSocket {
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRawFd for PacketSocket {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
self.fd.as_raw_fd()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn interface_index(interface: &str) -> io::Result<u32> {
|
||||
if interface.trim().is_empty() {
|
||||
return Err(io::Error::new(
|
||||
|
||||
Reference in New Issue
Block a user