fix regressions from upgrading dependency in wireguard/

This commit is contained in:
Ilka Schulz
2026-06-20 15:24:16 +02:00
parent 0145565d59
commit aca3df0e45
3 changed files with 15 additions and 14 deletions
+6 -5
View File
@@ -170,8 +170,8 @@ where
let typ = msgs::MsgType::try_from(*typ)?;
let msgs::MsgType::SetPsk = typ; // Assert type
let res = zerocopy::Ref::<&[u8], Envelope<SetPskResponse>>::new(res)
.ok_or(invalid_msg_poller())?;
let res = zerocopy::Ref::<&[u8], Envelope<SetPskResponse>>::from_bytes(res)
.map_err(|_| invalid_msg_poller())?;
let res: &msgs::SetPskResponse = &res.payload;
let res: msgs::SetPskResponseReturnCode = res
.return_code
@@ -200,8 +200,9 @@ where
let mut req = [0u8; BUF_SIZE];
// Construct message view
let mut req = zerocopy::Ref::<&mut [u8], Envelope<msgs::SetPskRequest>>::new(&mut req)
.ok_or(MsgError)?;
let mut req =
zerocopy::Ref::<&mut [u8], Envelope<msgs::SetPskRequest>>::from_bytes(&mut req)
.map_err(|_| MsgError)?;
// Populate envelope
req.msg_type = msgs::MsgType::SetPsk as u8;
@@ -219,7 +220,7 @@ where
// Send message
self.io
.borrow_mut()
.send_msg(req.bytes())
.send_msg(zerocopy::Ref::bytes(&req))
.map_err(IoError)?;
Ok(())
+5 -5
View File
@@ -3,7 +3,7 @@
use std::str::{Utf8Error, from_utf8};
use zerocopy::{AsBytes, FromBytes, FromZeroes};
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
/// The number of bytes reserved for overhead when packaging data.
pub const ENVELOPE_OVERHEAD: usize = 1 + 3;
@@ -15,8 +15,8 @@ pub const RESPONSE_MSG_BUFFER_SIZE: usize = ENVELOPE_OVERHEAD + 1;
/// Envelope for messages being passed around.
#[repr(packed)]
#[derive(AsBytes, FromBytes, FromZeroes)]
pub struct Envelope<M: AsBytes + FromBytes> {
#[derive(IntoBytes, FromBytes, KnownLayout, Immutable)]
pub struct Envelope<M: IntoBytes + FromBytes + KnownLayout + Immutable> {
/// [MsgType] of this message
pub msg_type: u8,
/// Reserved for future use
@@ -29,7 +29,7 @@ pub struct Envelope<M: AsBytes + FromBytes> {
/// # Example
///
#[repr(packed)]
#[derive(AsBytes, FromBytes, FromZeroes)]
#[derive(IntoBytes, FromBytes, KnownLayout, Immutable)]
pub struct SetPskRequest {
/// The pre-shared key.
pub psk: [u8; 32],
@@ -85,7 +85,7 @@ impl SetPskRequest {
/// Message format for response to the set pre-shared key operation.
#[repr(packed)]
#[derive(AsBytes, FromBytes, FromZeroes)]
#[derive(IntoBytes, FromBytes, KnownLayout, Immutable)]
pub struct SetPskResponse {
pub return_code: u8,
}
+4 -4
View File
@@ -79,13 +79,13 @@ where
let msgs::MsgType::SetPsk = typ; // Assert type
let req =
zerocopy::Ref::<&[u8], Envelope<SetPskRequest>>::new(req).ok_or(InvalidMessage)?;
zerocopy::Ref::<&[u8], Envelope<SetPskRequest>>::from_bytes(req).map_err(|_| InvalidMessage)?;
let mut res =
zerocopy::Ref::<&mut [u8], Envelope<SetPskResponse>>::new(res).ok_or(InvalidMessage)?;
zerocopy::Ref::<&mut [u8], Envelope<SetPskResponse>>::from_bytes(res).map_err(|_| InvalidMessage)?;
res.msg_type = msgs::MsgType::SetPsk as u8;
self.handle_set_psk(&req.payload, &mut res.payload)?;
Ok(res.bytes().len())
Ok(zerocopy::Ref::bytes(&res).len())
}
/// Sets the pre-shared key for the interface identified in `req` to the pre-shared key
@@ -138,7 +138,7 @@ mod tests {
use crate::brokers::netlink::SetPskError;
use crate::{SerializedBrokerConfig, WireGuardBroker};
use rosenpass_secret_memory::{Secret, secret_policy_use_only_malloc_secrets};
use zerocopy::AsBytes;
use zerocopy::IntoBytes;
#[derive(Debug, Clone)]
struct MockWireGuardBroker {