WireGuard Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] wg-quick: use resolvectl if present to set dns
@ 2018-08-01 12:04 j
  2018-08-04  0:01 ` Nathan Chancellor
  0 siblings, 1 reply; 3+ messages in thread
From: j @ 2018-08-01 12:04 UTC (permalink / raw)
  To: wireguard

[-- Attachment #1: Type: text/plain, Size: 222 bytes --]


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(-)



[-- Attachment #2: 0001-use-resolvectl-if-present-to-set-dns.patch --]
[-- Type: text/x-patch, Size: 967 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wg-quick: use resolvectl if present to set dns
  2018-08-01 12:04 [PATCH] wg-quick: use resolvectl if present to set dns j
@ 2018-08-04  0:01 ` Nathan Chancellor
  2018-08-08 21:41   ` j
  0 siblings, 1 reply; 3+ messages in thread
From: Nathan Chancellor @ 2018-08-04  0:01 UTC (permalink / raw)
  To: j; +Cc: wireguard

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] wg-quick: use resolvectl if present to set dns
  2018-08-04  0:01 ` Nathan Chancellor
@ 2018-08-08 21:41   ` j
  0 siblings, 0 replies; 3+ messages in thread
From: j @ 2018-08-08 21:41 UTC (permalink / raw)
  To: Nathan Chancellor; +Cc: wireguard

[-- Attachment #1: Type: text/plain, Size: 318 bytes --]

Hi Nathan,

On 08/04/2018 01:01 AM, Nathan Chancellor wrote:
> 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

good point, updated patch and added support for systemd-resolve in case
resolvectl is not present.

j

[-- Attachment #2: 0001-use-resolvectl-or-systemd-resolve-to-configure-dns.patch --]
[-- Type: text/x-patch, Size: 1148 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-01 12:04 [PATCH] wg-quick: use resolvectl if present to set dns j
2018-08-04  0:01 ` Nathan Chancellor
2018-08-08 21:41   ` j

WireGuard Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/wireguard/0 wireguard/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 wireguard wireguard/ https://lore.kernel.org/wireguard \
		wireguard@lists.zx2c4.com zx2c4-wireguard@archiver.kernel.org
	public-inbox-index wireguard


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/com.zx2c4.lists.wireguard


AGPL code for this site: git clone https://public-inbox.org/ public-inbox