Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] wg-quick: freebsd: save mask of interface in save_config
@ 2022-05-11 13:48 Dan Ponte
  0 siblings, 0 replies; only message in thread
From: Dan Ponte @ 2022-05-11 13:48 UTC (permalink / raw)
  To: wireguard; +Cc: Dan Ponte

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>
---
 src/wg-quick/freebsd.bash | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/wg-quick/freebsd.bash b/src/wg-quick/freebsd.bash
index b529ab2..5864a17 100755
--- a/src/wg-quick/freebsd.bash
+++ b/src/wg-quick/freebsd.bash
@@ -341,13 +341,15 @@ set_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'
-	{ read -r _; while read -r _ _ _ address _; do
-		new_config+="Address = $address"$'\n'
+	{ read -r _; while read -r _ _ network address _; do
+		cidr=(${network//\// })
+		new_config+="Address = $address/${cidr[1]}"$'\n'
 	done } < <(netstat -I "$INTERFACE" -n -W -f inet)
-	{ read -r _; while read -r _ _ _ address _; do
-		new_config+="Address = $address"$'\n'
+	{ read -r _; while read -r _ _ network address _; do
+		cidr=(${network//\// })
+		new_config+="Address = $address/${cidr[1]}"$'\n'
 	done } < <(netstat -I "$INTERFACE" -n -W -f inet6)
 	while read -r address; do
 		[[ $address =~ ^nameserver\ ([a-zA-Z0-9_=+:%.-]+)$ ]] && new_config+="DNS = ${BASH_REMATCH[1]}"$'\n'
-- 
2.36.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-13 23:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11 13:48 [PATCH] wg-quick: freebsd: save mask of interface in save_config Dan Ponte

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).