Skip to content

Commit 69f1ff7

Browse files
authored
Update dependences; small cleanups; now builds on NetBSD (#89)
1 parent 5ab60ce commit 69f1ff7

File tree

9 files changed

+150
-112
lines changed

9 files changed

+150
-112
lines changed

Cargo.lock

Lines changed: 27 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "defguard_wireguard_rs"
3-
version = "0.7.2"
3+
version = "0.7.3"
44
edition = "2021"
55
rust-version = "1.80"
66
description = "A unified multi-platform high-level API for managing WireGuard interfaces"
@@ -22,17 +22,9 @@ x25519-dalek = { version = "2.0", features = ["getrandom", "static_secrets"] }
2222
env_logger = "0.11"
2323
serde_test = "1.0"
2424

25-
[target.'cfg(target_os = "freebsd")'.dependencies]
25+
[target.'cfg(any(target_os = "freebsd", target_os = "macos", target_os = "netbsd"))'.dependencies]
2626
libc = { version = "0.2", default-features = false }
27-
nix = { version = "0.29", features = ["ioctl", "socket"] }
28-
29-
[target.'cfg(target_os = "macos")'.dependencies]
30-
libc = { version = "0.2", default-features = false }
31-
nix = { version = "0.29", features = ["ioctl", "socket"] }
32-
33-
[target.'cfg(target_os = "netbsd")'.dependencies]
34-
libc = { version = "0.2", default-features = false }
35-
nix = { version = "0.29", features = ["ioctl", "socket"] }
27+
nix = { version = "0.30", features = ["ioctl", "socket"] }
3628

3729
[target.'cfg(target_os = "linux")'.dependencies]
3830
netlink-packet-core = "0.7"
@@ -48,5 +40,7 @@ check_dependencies = []
4840
serde = ["dep:serde"]
4941

5042
[profile.release]
43+
codegen-units = 1
44+
panic = "abort"
5145
lto = "thin"
5246
strip = "symbols"

src/bsd/ifconfig.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,8 @@ type IfName = [u8; IF_NAMESIZE];
7070

7171
fn make_ifr_name(if_name: &str) -> IfName {
7272
let mut ifr_name = [0u8; IF_NAMESIZE];
73-
if_name
74-
.bytes()
75-
.take(IF_NAMESIZE - 1)
76-
.enumerate()
77-
.for_each(|(i, b)| ifr_name[i] = b);
73+
let len = if_name.len().min(IF_NAMESIZE - 1);
74+
ifr_name[..len].copy_from_slice(&if_name.as_bytes()[..len]);
7875
ifr_name
7976
}
8077

src/bsd/nvlist.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{error::Error, ffi::CStr, fmt};
55
/// `NV_HEADER_SIZE` is for both: `nvlist_header` and `nvpair_header`.
66
const NV_HEADER_SIZE: usize = 19;
77
const NV_NAME_MAX: usize = 2048;
8-
const NVLIST_HEADER_MAGIC: u8 = 0x6c; // 'l'
8+
const NVLIST_HEADER_MAGIC: u8 = b'l';
99
const NVLIST_HEADER_VERSION: u8 = 0;
1010
// Public flags
1111
// Perform case-insensitive lookups of provided names.
@@ -186,7 +186,7 @@ impl<'a> NvList<'a> {
186186
self.items.iter().find(|(n, _)| n == &name).map(|(_, v)| v)
187187
}
188188

189-
/// Get value as `bool`.
189+
// Get value as `bool`.
190190
// pub fn get_bool(&self, name: &str) -> Option<bool> {
191191
// self.get(name).and_then(|value| match value {
192192
// NvValue::Bool(boolean) => Some(*boolean),
@@ -202,7 +202,7 @@ impl<'a> NvList<'a> {
202202
})
203203
}
204204

205-
/// Get value as `&str`.
205+
// Get value as `&str`.
206206
// pub fn get_string(&self, name: &str) -> Option<&str> {
207207
// self.get(name).and_then(|value| match value {
208208
// NvValue::String(string) => Some(*string),
@@ -242,7 +242,7 @@ impl<'a> NvList<'a> {
242242
self.items.push((name, NvValue::Number(number)));
243243
}
244244

245-
/// Append `String` value to the list.
245+
// Append `String` value to the list.
246246
// pub fn append_string(&mut self, name: &'a str, string: &'a str) {
247247
// self.items.push((name, NvValue::String(string)));
248248
// }

src/bsd/route.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<Payload> RtMessage<Payload> {
373373
}
374374

375375
let mut buf = [0u8; 256]; // FIXME: fixed buffer size
376-
let len = read(socket.as_raw_fd(), &mut buf).map_err(IoError::ReadIo)?;
376+
let len = read(socket.as_fd(), &mut buf).map_err(IoError::ReadIo)?;
377377
if len < size_of::<Self>() {
378378
return Err(IoError::Unpack);
379379
}

src/host.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ impl Host {
314314
break;
315315
}
316316
}
317-
return Err(io::Error::new(io::ErrorKind::Other, "error reading UAPI"));
317+
return Err(io::Error::other("error reading UAPI"));
318318
}
319-
_ => error!("Unknown UAPI keyword {}", keyword),
319+
_ => error!("Unknown UAPI keyword {keyword}"),
320320
}
321321
}
322322
}

0 commit comments

Comments
 (0)