Identify links by their index rather than by their MAC address to cope with name and MAC addresses changes properly in the main thread.
This commit is contained in:
parent
27b8836f74
commit
e40a511ee9
10
src/main.rs
10
src/main.rs
@ -588,7 +588,7 @@ fn zascii(slice: &[libc::c_char]) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut thread_map: HashMap<[u8; 6], libc::c_int> = HashMap::new();
|
let mut thread_map: HashMap<i32, libc::c_int> = HashMap::new();
|
||||||
let iterator = rtnetlink::new_interface_iterator().unwrap();
|
let iterator = rtnetlink::new_interface_iterator().unwrap();
|
||||||
|
|
||||||
for message in iterator {
|
for message in iterator {
|
||||||
@ -600,7 +600,7 @@ fn main() {
|
|||||||
let name = zascii(&interface.name);
|
let name = zascii(&interface.name);
|
||||||
println!("New Link");
|
println!("New Link");
|
||||||
|
|
||||||
if let None = thread_map.get(&interface.hwaddr) {
|
if let None = thread_map.get(&interface.index) {
|
||||||
println!("Starting DHCP on {}", name);
|
println!("Starting DHCP on {}", name);
|
||||||
unsafe {
|
unsafe {
|
||||||
match libc::fork() {
|
match libc::fork() {
|
||||||
@ -608,7 +608,7 @@ fn main() {
|
|||||||
0 => dhcp_client(name, interface.index, interface.hwaddr),
|
0 => dhcp_client(name, interface.index, interface.hwaddr),
|
||||||
pid => {
|
pid => {
|
||||||
println!("Started DHCP on {} PID {}", name, pid);
|
println!("Started DHCP on {} PID {}", name, pid);
|
||||||
thread_map.insert(interface.hwaddr, pid);
|
thread_map.insert(interface.index, pid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -619,12 +619,12 @@ fn main() {
|
|||||||
let name = zascii(&interface.name);
|
let name = zascii(&interface.name);
|
||||||
println!("Del Link");
|
println!("Del Link");
|
||||||
|
|
||||||
if let Some(pid) = thread_map.get(&interface.hwaddr) {
|
if let Some(pid) = thread_map.get(&interface.index) {
|
||||||
println!("Stopping DHCP on {}", name);
|
println!("Stopping DHCP on {}", name);
|
||||||
unsafe {
|
unsafe {
|
||||||
libc::kill(*pid, libc::SIGTERM);
|
libc::kill(*pid, libc::SIGTERM);
|
||||||
}
|
}
|
||||||
thread_map.remove(&interface.hwaddr);
|
thread_map.remove(&interface.index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user