Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
allow updating of peers removing a panic
  • Loading branch information
MemoryLeak55 committed Aug 29, 2023
commit e72992d06bade75cdd285b4205dc35ca10ae1e90
11 changes: 8 additions & 3 deletions boringtun/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,15 @@ impl Device {
return self.remove_peer(&pub_key);
}

// Update an existing peer
if self.peers.get(&pub_key).is_some() {
if let Some(peer) = self.peers.get(&pub_key) {
// We already have a peer, we need to merge the existing config into the newly created one
panic!("Modifying existing peers is not yet supported. Remove and add again instead.");
let mut peer_mut = peer.lock();

peer_mut.tunnel.set_persistent_keepalive(keepalive);
peer_mut.update(endpoint, allowed_ips, preshared_key);

tracing::info!("Peer updated");
return;
}

let next_index = self.next_index();
Expand Down
15 changes: 15 additions & 0 deletions boringtun/src/device/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ impl Peer {
}
}

pub fn update(
&mut self,
endpoint: Option<SocketAddr>,
allowed_ips: &[AllowedIP],
preshared_key: Option<[u8; 32]>,
) {

if let Some(addr) = endpoint {
self.set_endpoint(addr);
}
self.allowed_ips = allowed_ips.iter().map(|ip| (ip, ())).collect();
self.preshared_key = preshared_key;

}

pub fn update_timers<'a>(&mut self, dst: &'a mut [u8]) -> TunnResult<'a> {
self.tunnel.update_timers(dst)
}
Expand Down
4 changes: 4 additions & 0 deletions boringtun/src/noise/timers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,4 +332,8 @@ impl Tunn {
None
}
}

pub fn set_persistent_keepalive(&mut self, keepalive: Option<u16>) {
self.timers.persistent_keepalive = usize::from(keepalive.unwrap_or(0));
}
}