aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-11-18 13:01:34 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-11-18 13:01:34 +0100
commit0daa42d9fd9b331878cc74e54751432641121e82 (patch)
treeae3a2ee655fa481a2ad4061a746c456e5806f349
parenta11f7c5a0cf3ffa816e433b2c844e0c9abf2ab03 (diff)
update netlinklib0.2.5
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml4
-rw-r--r--src/main.rs15
-rw-r--r--src/util.rs6
4 files changed, 18 insertions, 14 deletions
diff --git a/Cargo.lock b/Cargo.lock
index e0b3023..43808b0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -531,7 +531,7 @@ dependencies = [
[[package]]
name = "rsdsl_dhcp4d"
-version = "0.2.4"
+version = "0.2.5"
dependencies = [
"dhcproto",
"ipnet",
@@ -548,12 +548,13 @@ dependencies = [
[[package]]
name = "rsdsl_netlinklib"
-version = "0.3.0"
-source = "git+https://github.com/rsdsl/netlinklib.git#2c20dc2932696cb87ea7e6eb5327b7dccf0e9b1b"
+version = "0.4.2"
+source = "git+https://github.com/rsdsl/netlinklib.git#1954c7c7e975104fa651ccded4358826e8b3c8d8"
dependencies = [
"futures",
"libc",
"netlink-packet-route",
+ "netlink-proto",
"rtnetlink",
"thiserror",
"tokio",
diff --git a/Cargo.toml b/Cargo.toml
index 412f305..2b3ddfe 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rsdsl_dhcp4d"
-version = "0.2.4"
+version = "0.2.5"
authors = ["HimbeerserverDE <himbeerserverde@gmail.com>"]
license = "MIT"
edition = "2021"
@@ -12,7 +12,7 @@ dhcproto = "0.8.0"
ipnet = "2.7.1"
libc = "0.2"
rand = "0.8.5"
-rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git", version = "0.3.0", default-features = false, features = ["addr", "blocking", "status"] }
+rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git", version = "0.4.2", default-features = false, features = ["addr", "blocking", "status"] }
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
diff --git a/src/main.rs b/src/main.rs
index 5a9ae42..e3b0629 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,7 +15,7 @@ use std::time::Duration;
use dhcproto::v4::{DhcpOption, Flags, Message, MessageType, Opcode, OptionCode};
use dhcproto::{Decodable, Decoder, Encodable, Encoder};
-use rsdsl_netlinklib::blocking::link;
+use rsdsl_netlinklib::blocking::Connection;
use socket2::{Domain, Socket, Type};
use sysinfo::{ProcessExt, Signal, System, SystemExt};
@@ -42,8 +42,10 @@ fn run_supervised(link: String, subnet_id: u8) -> ! {
}
fn run(link: String, subnet_id: u8) -> Result<()> {
+ let conn = Connection::new()?;
+
println!("[info] wait for up {}", link);
- link::wait_up(link.clone())?;
+ conn.link_wait_up(link.clone())?;
println!("[info] init {}", link);
@@ -112,7 +114,7 @@ fn run(link: String, subnet_id: u8) -> Result<()> {
let remote = remote.as_socket_ipv4().unwrap();
- match handle_request(&sock, lease_mgr.clone(), buf, link.clone()) {
+ match handle_request(&conn, &sock, lease_mgr.clone(), buf, link.clone()) {
Ok(_) => {}
Err(e) => println!("[info] pkt from {} on {}: {}", remote, link, e),
}
@@ -120,6 +122,7 @@ fn run(link: String, subnet_id: u8) -> Result<()> {
}
fn handle_request<T: LeaseManager>(
+ conn: &Connection,
sock: &Socket,
lease_mgr: Arc<Mutex<T>>,
buf: &[u8],
@@ -159,7 +162,7 @@ fn handle_request<T: LeaseManager>(
.persistent_free_address(client_id, hostname)
.ok_or(Error::PoolExhausted)?;
- let own_addr = local_ip(link.clone())?;
+ let own_addr = local_ip(conn, link.clone())?;
let mut resp = Message::default();
let opts = resp
@@ -233,7 +236,7 @@ fn handle_request<T: LeaseManager>(
};
if !lease_mgr.request(requested_addr, client_id, hostname)? {
- let own_addr = local_ip(link.clone())?;
+ let own_addr = local_ip(conn, link.clone())?;
let mut resp = Message::default();
let opts = resp
@@ -271,7 +274,7 @@ fn handle_request<T: LeaseManager>(
}
} else {
let lease_time = lease_mgr.lease_time();
- let own_addr = local_ip(link.clone())?;
+ let own_addr = local_ip(conn, link.clone())?;
let mut resp = Message::default();
let opts = resp
diff --git a/src/util.rs b/src/util.rs
index 974c273..26ac950 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -4,7 +4,7 @@ use std::ffi::{c_char, c_int};
use std::io;
use std::net::{IpAddr, Ipv4Addr};
-use rsdsl_netlinklib::blocking::addr;
+use rsdsl_netlinklib::blocking::Connection;
/// Helper macro to execute a system call that returns an `io::Result`.
macro_rules! syscall {
@@ -27,8 +27,8 @@ pub fn format_client_id(client_id: &[u8]) -> Result<String> {
.ok_or(Error::EmptyClientId)
}
-pub fn local_ip(link: String) -> Result<Ipv4Addr> {
- addr::get(link.clone())?
+pub fn local_ip(conn: &Connection, link: String) -> Result<Ipv4Addr> {
+ conn.address_get(link.clone())?
.into_iter()
.filter_map(|addr| {
if let IpAddr::V4(v4) = addr {