mirror of
https://github.com/amnezia-vpn/amneziawg-tools.git
synced 2025-04-11 11:36:54 +02:00
* UAPI changes for Amnezia kernel module * Fix indents * Fix indents * Fix indents * Change protocol type * Change protocol type * Change protocol type * Change protocol type * Revert "Change protocol type" * K * Fix wg-quick * Prepare packaging * Prepare packaging * Prepare packaging * Prepare packaging * naming convention fix * Bash completions * Naming unify * Naming unify * SPEC file for RPM build * SPEC file for RPM build * SPEC file for RPM build * SPEC file for RPM build --------- Co-authored-by: Mark Puha <marko10@inf.elte.hu>
55 lines
1.7 KiB
Bash
Executable file
55 lines
1.7 KiB
Bash
Executable file
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
# Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
|
set -e
|
|
|
|
exec 3>&1
|
|
netns0="wg-test-$$-0"
|
|
netns1="wg-test-$$-1"
|
|
netns2="wg-test-$$-2"
|
|
pretty() { echo -e "\x1b[32m\x1b[1m[+] ${1:+NS$1: }${2}\x1b[0m" >&3; }
|
|
pp() { pretty "" "$*"; "$@"; }
|
|
n1() { pretty 1 "$*"; ip netns exec $netns1 "$@"; }
|
|
n2() { pretty 2 "$*"; ip netns exec $netns2 "$@"; }
|
|
ip0() { pretty 0 "ip $*"; ip -n $netns0 "$@"; }
|
|
ip1() { pretty 1 "ip $*"; ip -n $netns1 "$@"; }
|
|
ip2() { pretty 2 "ip $*"; ip -n $netns2 "$@"; }
|
|
|
|
cleanup() {
|
|
set +e
|
|
exec 2>/dev/null
|
|
ip0 link del dev wg0
|
|
ip1 link del dev wg0
|
|
ip2 link del dev wg0
|
|
local to_kill="$(ip netns pids $netns0) $(ip netns pids $netns1) $(ip netns pids $netns2)"
|
|
[[ -n $to_kill ]] && kill $to_kill
|
|
pp ip netns del $netns1
|
|
pp ip netns del $netns2
|
|
pp ip netns del $netns0
|
|
exit
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
ip netns del $netns0 2>/dev/null || true
|
|
ip netns del $netns1 2>/dev/null || true
|
|
ip netns del $netns2 2>/dev/null || true
|
|
pp ip netns add $netns0
|
|
pp ip netns add $netns1
|
|
pp ip netns add $netns2
|
|
ip0 link set up dev lo
|
|
ip0 link add dev wg0 type wireguard
|
|
ip0 link set wg0 netns $netns1
|
|
ip0 link add dev wg0 type wireguard
|
|
ip0 link set wg0 netns $netns2
|
|
ip1 addr add 192.168.241.1/24 dev wg0
|
|
ip2 addr add 192.168.241.2/24 dev wg0
|
|
key1="$(pp wg genkey)"
|
|
key2="$(pp wg genkey)"
|
|
pub1="$(pp wg pubkey <<<"$key1")"
|
|
pub2="$(pp wg pubkey <<<"$key2")"
|
|
n1 wg set wg0 private-key <(echo "$key1") listen-port 1 peer "$pub2" allowed-ips 192.168.241.2/32
|
|
n2 wg set wg0 private-key <(echo "$key2") listen-port 2 peer "$pub1" allowed-ips 192.168.241.1/32
|
|
ip1 link set up dev wg0
|
|
ip2 link set up dev wg0
|
|
n2 wg set wg0 peer "$pub1" endpoint 127.0.0.1:1
|
|
n2 ping -c 10 -f -W 1 192.168.241.1
|