Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Nathan Chancellor <natechancellor@gmail.com>
To: j@mailb.org
Cc: wireguard@lists.zx2c4.com
Subject: Re: [PATCH] wg-quick: use resolvectl if present to set dns
Date: Fri, 3 Aug 2018 17:01:12 -0700	[thread overview]
Message-ID: <20180804000112.GA12885@flashbox> (raw)
In-Reply-To: <d78ba489-ebc5-4769-610b-51529cc650ca@mailb.org>

On Wed, Aug 01, 2018 at 02:04:25PM +0200, j@mailb.org wrote:
> 
> only use resolvconf is available, fall back to resolvectl if present
> otherwise. don't set dns if both are missing.
> 
> ---
>  src/tools/wg-quick/linux.bash | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> 

> diff --git a/src/tools/wg-quick/linux.bash b/src/tools/wg-quick/linux.bash
> index 3f1976b..f86f0c8 100755
> --- a/src/tools/wg-quick/linux.bash
> +++ b/src/tools/wg-quick/linux.bash
> @@ -151,13 +151,21 @@ resolvconf_iface_prefix() {
>  HAVE_SET_DNS=0
>  set_dns() {
>  	[[ ${#DNS[@]} -gt 0 ]] || return 0
> -	printf 'nameserver %s\n' "${DNS[@]}" | cmd resolvconf -a "$(resolvconf_iface_prefix)$INTERFACE" -m 0 -x
> +	if [ -x /usr/bin/resolvconf ]; then
> +		printf 'nameserver %s\n' "${DNS[@]}" | cmd resolvconf -a "$(resolvconf_iface_prefix)$INTERFACE" -m 0 -x
> +	elif [ -x /usr/bin/resolvectl ]; then
> +		cmd resolvectl dns $INTERFACE "${DNS[@]}"
> +	fi
>  	HAVE_SET_DNS=1
>  }
>  
>  unset_dns() {
>  	[[ ${#DNS[@]} -gt 0 ]] || return 0
> -	cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE"
> +	if [ -x /usr/bin/resolvconf ]; then
> +		cmd resolvconf -d "$(resolvconf_iface_prefix)$INTERFACE"
> +	elif [ -x /usr/bin/resolvectl ]; then
> +		cmd resolvectl revert $INTERFACE
> +	fi
>  }
>  
>  add_route() {
> 

> _______________________________________________
> WireGuard mailing list
> WireGuard@lists.zx2c4.com
> https://lists.zx2c4.com/mailman/listinfo/wireguard

I'd argue a better way to check if a command is available is the command
built-in:

if command -v resolvconf >/dev/null; then
    do stuff
fi

The user may have resolvconf available in PATH but not in that location.

Jason can comment on if this makes sense, I don't use wg-quick on Linux.

Nathan

  reply	other threads:[~2018-08-03 23:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-01 12:04 j
2018-08-04  0:01 ` Nathan Chancellor [this message]
2018-08-08 21:41   ` j

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=20180804000112.GA12885@flashbox \
    --to=natechancellor@gmail.com \
    --cc=j@mailb.org \
    --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 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).