diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/error.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/src/error.rs b/src/error.rs index 3aed7c8..0d133d6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -33,6 +33,8 @@ pub enum Error { Io(#[from] io::Error), #[error("linkaddrs error")] LinkAddrs(#[from] linkaddrs::Error), + #[error("rsdsl_netlinkd error")] + RsdslNetlinkd(#[from] rsdsl_netlinkd::error::Error), #[error("serde_json error")] SerdeJson(#[from] serde_json::Error), #[error("ip addr parse error")] diff --git a/src/main.rs b/src/main.rs index ce0619c..2f8bfe5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,20 +10,33 @@ use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4}; use std::os::fd::AsRawFd; use std::str::FromStr; use std::sync::{Arc, Mutex}; +use std::thread; use std::time::Duration; use dhcproto::v4::{DhcpOption, Flags, Message, MessageType, Opcode, OptionCode}; use dhcproto::{Decodable, Decoder, Encodable, Encoder}; +use rsdsl_netlinkd::link; use socket2::{Domain, Socket, Type}; const BUFSIZE: usize = 1500; fn main() -> Result<()> { - run("eth0".into(), 0)?; + thread::spawn(|| run("eth0".into(), 0).unwrap()); + + for i in 1..=4 { + let subnet_id = 10 * i; + let vlan_name = format!("eth0.{}", subnet_id); + + thread::spawn(move || run(vlan_name, subnet_id).unwrap()); + } + Ok(()) } fn run(link: String, subnet_id: u8) -> Result<()> { + println!("[dhcp4d] wait for interface {}", link); + link::wait(link.clone())?; + println!("[dhcp4d] init interface {}", link); let config = LeaseFileManagerConfig { |