All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Ponte <amigan@gmail.com>
To: wireguard@lists.zx2c4.com
Cc: Dan Ponte <amigan@gmail.com>
Subject: [PATCH] wg-quick: freebsd: save mask of interface in save_config
Date: Wed, 11 May 2022 09:48:28 -0400	[thread overview]
Message-ID: <20220511134827.81778-1-amigan@gmail.com> (raw)

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


                 reply	other threads:[~2022-05-13 23:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220511134827.81778-1-amigan@gmail.com \
    --to=amigan@gmail.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.