parent
b53376b9c8
commit
9829b4b3e9
|
@ -250,17 +250,19 @@ struct ApplyPayload {
|
||||||
iface: String,
|
iface: String,
|
||||||
nlas: Vec<WgDeviceAttrs>,
|
nlas: Vec<WgDeviceAttrs>,
|
||||||
current_buffer_len: usize,
|
current_buffer_len: usize,
|
||||||
messages: Vec<GenlMessage<Wireguard>>,
|
queue: Vec<GenlMessage<Wireguard>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApplyPayload {
|
impl ApplyPayload {
|
||||||
fn new(iface: &InterfaceName) -> Self {
|
fn new(iface: &InterfaceName) -> Self {
|
||||||
let iface_str = iface.as_str_lossy().to_string();
|
let iface_str = iface.as_str_lossy().to_string();
|
||||||
|
let nlas = vec![WgDeviceAttrs::IfName(iface_str.clone())];
|
||||||
|
let current_buffer_len = nlas.as_slice().buffer_len();
|
||||||
Self {
|
Self {
|
||||||
iface: iface_str.clone(),
|
iface: iface_str,
|
||||||
nlas: vec![WgDeviceAttrs::IfName(iface_str)],
|
nlas,
|
||||||
messages: vec![],
|
queue: vec![],
|
||||||
current_buffer_len: 0,
|
current_buffer_len,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,14 +272,15 @@ impl ApplyPayload {
|
||||||
.retain(|nla| !matches!(nla, WgDeviceAttrs::Peers(peers) if peers.is_empty()));
|
.retain(|nla| !matches!(nla, WgDeviceAttrs::Peers(peers) if peers.is_empty()));
|
||||||
|
|
||||||
let name = WgDeviceAttrs::IfName(self.iface.clone());
|
let name = WgDeviceAttrs::IfName(self.iface.clone());
|
||||||
self.current_buffer_len = name.buffer_len();
|
let template = vec![name];
|
||||||
|
|
||||||
if !self.nlas.is_empty() {
|
if !self.nlas.is_empty() && self.nlas != template {
|
||||||
|
self.current_buffer_len = template.as_slice().buffer_len();
|
||||||
let message = GenlMessage::from_payload(Wireguard {
|
let message = GenlMessage::from_payload(Wireguard {
|
||||||
cmd: WireguardCmd::SetDevice,
|
cmd: WireguardCmd::SetDevice,
|
||||||
nlas: std::mem::replace(&mut self.nlas, vec![name]),
|
nlas: std::mem::replace(&mut self.nlas, template),
|
||||||
});
|
});
|
||||||
self.messages.push(message);
|
self.queue.push(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,7 +355,7 @@ impl ApplyPayload {
|
||||||
|
|
||||||
pub fn finish(mut self) -> Vec<GenlMessage<Wireguard>> {
|
pub fn finish(mut self) -> Vec<GenlMessage<Wireguard>> {
|
||||||
self.flush_nlas();
|
self.flush_nlas();
|
||||||
self.messages
|
self.queue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue