fix AllowIps and Address fields for WireGuard client (#99)

- add Wireguard client cidr into AllowIps
- change subnet number to 32 in Address field
This commit is contained in:
Yumin Wu
2024-05-09 22:01:55 +08:00
committed by GitHub
parent 7d3b8e42fe
commit 4da7f4ec20
5 changed files with 32 additions and 19 deletions
+9 -2
View File
@@ -360,8 +360,15 @@ async fn main() -> Result<(), Error> {
.into_inner()
.vpn_portal_info
.unwrap_or_default();
println!("portal_name: {}\n", resp.vpn_type);
println!("client_config:{}", resp.client_config);
println!("portal_name: {}", resp.vpn_type);
println!(
r#"
############### client_config_start ###############
{}
############### client_config_end ###############
"#,
resp.client_config
);
println!("connected_clients:\n{:#?}", resp.connected_clients);
}
}
+1 -1
View File
@@ -428,7 +428,7 @@ pub async fn async_main(cli: Cli) {
});
println!("Starting easytier with config:");
println!("############### TOML ##############\n");
println!("############### TOML ###############\n");
println!("{}", cfg.dump());
println!("-----------------------------------");
+8 -6
View File
@@ -264,33 +264,35 @@ impl VpnPortal for WireGuard {
break;
}
let vpn_cfg = global_ctx.config.get_vpn_portal_config().unwrap();
let client_cidr = vpn_cfg.client_cidr;
allow_ips.push(client_cidr.to_string());
let allow_ips = allow_ips
.into_iter()
.map(|x| x.to_string())
.collect::<Vec<_>>()
.join(",");
let vpn_cfg = global_ctx.config.get_vpn_portal_config().unwrap();
let client_cidr = vpn_cfg.client_cidr;
let cfg = self.inner.as_ref().unwrap().wg_config.clone();
let cfg_str = format!(
r#"
[Interface]
PrivateKey = {peer_secret_key}
Address = {client_cidr} # should assign an ip from this cidr manually
Address = {address} # should assign an ip from this cidr manually
[Peer]
PublicKey = {my_public_key}
AllowedIPs = {allow_ips}
Endpoint = {listenr_addr} # should be the public ip of the vpn server
Endpoint = {listenr_addr} # should be the public ip(or domain) of the vpn server
PersistentKeepalive = 25
"#,
peer_secret_key = BASE64_STANDARD.encode(cfg.peer_secret_key()),
my_public_key = BASE64_STANDARD.encode(cfg.my_public_key()),
listenr_addr = self.inner.as_ref().unwrap().listenr_addr,
allow_ips = allow_ips,
client_cidr = client_cidr,
address = client_cidr.first_address().to_string() + "/32",
);
cfg_str