wg-quick: freebsd: save mask of interface in save_config

Other than the obvious benefits, this prevents "ifconfig: WARNING: setting interface
address without mask is deprecated, default mask may not be correct." from appearing
on the next start after save.

Signed-off-by: Dan Ponte <amigan@gmail.com>
This commit is contained in:
Dan Ponte 2022-05-11 08:52:37 -04:00
parent c0b68d2eaf
commit 4bba353ffc

View File

@ -341,13 +341,15 @@ set_config() {
} }
save_config() { save_config() {
local old_umask new_config current_config address cmd local old_umask new_config current_config network cidr address cmd
new_config=$'[Interface]\n' new_config=$'[Interface]\n'
{ read -r _; while read -r _ _ _ address _; do { read -r _; while read -r _ _ network address _; do
new_config+="Address = $address"$'\n' cidr=(${network//\// })
new_config+="Address = $address/${cidr[1]}"$'\n'
done } < <(netstat -I "$INTERFACE" -n -W -f inet) done } < <(netstat -I "$INTERFACE" -n -W -f inet)
{ read -r _; while read -r _ _ _ address _; do { read -r _; while read -r _ _ network address _; do
new_config+="Address = $address"$'\n' cidr=(${network//\// })
new_config+="Address = $address/${cidr[1]}"$'\n'
done } < <(netstat -I "$INTERFACE" -n -W -f inet6) 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'