wg-quick: determine IPs when saving interface
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
c99e6beecb
commit
19ce650fb6
|
@ -335,12 +335,12 @@ set_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
save_config() {
|
save_config() {
|
||||||
# TODO: actually save addresses and DNS by running ifconfig and networksetup
|
|
||||||
local old_umask new_config current_config address cmd
|
local old_umask new_config current_config address cmd
|
||||||
new_config=$'[Interface]\n'
|
new_config=$'[Interface]\n'
|
||||||
for address in "${ADDRESSES[@]}"; do
|
while read -r address; do
|
||||||
new_config+="Address = $address"$'\n'
|
[[ $address =~ inet6?\ ([^ ]+) ]] && new_config+="Address = ${BASH_REMATCH[1]}"$'\n'
|
||||||
done
|
done < <(ifconfig "$REAL_INTERFACE")
|
||||||
|
# TODO: actually determine current DNS for interface
|
||||||
for address in "${DNS[@]}"; do
|
for address in "${DNS[@]}"; do
|
||||||
new_config+="DNS = $address"$'\n'
|
new_config+="DNS = $address"$'\n'
|
||||||
done
|
done
|
||||||
|
|
|
@ -309,12 +309,14 @@ set_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
save_config() {
|
save_config() {
|
||||||
# TODO: actually save addresses by running ifconfig
|
|
||||||
local old_umask new_config current_config address cmd
|
local old_umask new_config current_config address cmd
|
||||||
new_config=$'[Interface]\n'
|
new_config=$'[Interface]\n'
|
||||||
for address in "${ADDRESSES[@]}"; do
|
{ read -r _; while read -r _ _ _ address _; do
|
||||||
new_config+="Address = $address"$'\n'
|
new_config+="Address = $address"$'\n'
|
||||||
done
|
done } < <(netstat -I "$INTERFACE" -n -W -f inet)
|
||||||
|
{ read -r _; while read -r _ _ _ address _; do
|
||||||
|
new_config+="Address = $address"$'\n'
|
||||||
|
done } < <(netstat -I "$INTERFACE" -n -W -f inet6)
|
||||||
while read -r address; do
|
while read -r address; do
|
||||||
[[ $address =~ ^nameserver\ ([a-zA-Z0-9_=+:%.-]+)$ ]] && new_config+="DNS = ${BASH_REMATCH[1]}"$'\n'
|
[[ $address =~ ^nameserver\ ([a-zA-Z0-9_=+:%.-]+)$ ]] && new_config+="DNS = ${BASH_REMATCH[1]}"$'\n'
|
||||||
done < <(resolvconf -l "$INTERFACE" 2>/dev/null)
|
done < <(resolvconf -l "$INTERFACE" 2>/dev/null)
|
||||||
|
|
|
@ -315,12 +315,12 @@ set_config() {
|
||||||
}
|
}
|
||||||
|
|
||||||
save_config() {
|
save_config() {
|
||||||
# TODO: actually save addresses by running ifconfig and dnses too
|
local old_umask new_config current_config address network cmd
|
||||||
local old_umask new_config current_config address cmd
|
|
||||||
new_config=$'[Interface]\n'
|
new_config=$'[Interface]\n'
|
||||||
for address in "${ADDRESSES[@]}"; do
|
{ read -r _; while read -r _ _ network address _; do
|
||||||
new_config+="Address = $address"$'\n'
|
[[ $network == *Link* ]] || new_config+="Address = $address"$'\n'
|
||||||
done
|
done } < <(netstat -I "$REAL_INTERFACE" -n -v)
|
||||||
|
# TODO: actually determine current DNS for interface
|
||||||
for address in "${DNS[@]}"; do
|
for address in "${DNS[@]}"; do
|
||||||
new_config+="DNS = $address"$'\n'
|
new_config+="DNS = $address"$'\n'
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in New Issue