From 64165c5fbd71d4326aa523dd0572e064341da9e5 Mon Sep 17 00:00:00 2001 From: James Valleroy Date: Sun, 15 Sep 2019 12:29:19 -0400 Subject: [PATCH] wireguard: Create network manager connection Signed-off-by: James Valleroy Reviewed-by: Sunil Mohan Adapa --- actions/wireguard | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/actions/wireguard b/actions/wireguard index 1de862a35..0a4dc5c42 100755 --- a/actions/wireguard +++ b/actions/wireguard @@ -159,6 +159,28 @@ def subcommand_add_server(arguments): ['ip', 'link', 'add', 'dev', new_interface_name, 'type', 'wireguard'], check=True) + connection_name = 'WireGuard-' + new_interface_name + subprocess.run(['nmcli', 'con', 'add', + 'con-name', connection_name, + 'ifname', new_interface_name, + 'type', 'wireguard'], check=True) + + subprocess.run(['nmcli', 'con', 'modify', connection_name, + 'connection.autoconnect', 'TRUE'], check=True) + + subprocess.run(['nmcli', 'con', 'modify', connection_name, + 'connection.zone', 'internal'], check=True) + + subprocess.run(['nmcli', 'con', 'modify', connection_name, + 'ipv4.method', 'manual', + 'ipv4.addresses', arguments.client_ip + '/24'], check=True) + + with open('/var/lib/freedombox/wireguard/privatekey') as private_key_file: + private_key = private_key_file.read().strip() + + subprocess.run(['nmcli', 'con', 'modify', connection_name, + 'wireguard.private-key', private_key], check=True) + args = ['wg', 'set', new_interface_name, 'peer', arguments.public_key] if arguments.pre_shared_key: args += ['preshared-key', arguments.pre_shared_key]