Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Saeid Akbari <saeidscorp@yahoo.com>
To: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Some potential bug in wg-quick re. fwmark and default route
Date: Mon, 12 Mar 2018 17:47:10 +0330	[thread overview]
Message-ID: <4993616.ZASKD2KPVS@scorpbook> (raw)

Hi,

Straight to the point :)
Suppose the following scenario:

On a client system I have 2 interfaces:
wg0 -> which has allowedips of 0.0.0.0; so it gets special treatment by wg-
quick -> so `ip rule add not fwmark 51820 table 51820`
wg1 -> which has a restrictive allowedips of 192.168.255.10/32 (not important)

also each one have a FwMark set in their config file:
wg0 -> 51800
wg1 -> 51820

Then: `wg-quick up wg0` and `wg-quick up wg1`

Now the problem is, when I do `wg-quick down wg1` it also deletes the default 
rules for wg0, as its fwmark is 51820 which belongs to table of wg0. I see 
that this might seem a little bit weird to do, but why rely on hard-coded 
numbers if we can use the ones provided by the user...

So wouldn't be better if `add_default()` function first checks if fwmark is 
present on device (thus config file) and use that as fwmark and table-id?

Like what `del_if()` does, borrowing its code:

```DEFAULT_TABLE=
add_default() {
	local fwmark
	fwmark="$(wg show "$INTERFACE" fwmark)"
	[[ $fwmark != off ]] && DEFAULT_TABLE=$(( fwmark )) # borrowed
	if [[ -z $DEFAULT_TABLE ]]; then
		DEFAULT_TABLE=51820
		while [[ -n $(ip -4 route show table $DEFAULT_TABLE) || -n $(ip -6 route 
show table $DEFAULT_TABLE) ]]; do
			((DEFAULT_TABLE++))
		done
	fi```

This way, default interface (the one having allowedips of 0.0.0.0) would 
register its own fwmark, and bringing down other interfaces, doesn't delete 
its rule.


+ But another issue, `del_if()` seems to assume that the interface is used as 
default route when a fwmark is present on it. This causes deletion of "from 
all lookup main suppress_prefixlength 0" when bringing down a non-default 
interface (in this scenario, wg1).

Any ideas?

Thanks.

             reply	other threads:[~2018-03-12 14:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-12 14:17 Saeid Akbari [this message]
2018-03-26 20:53 ` Luis Ressel
2018-04-14  0:41   ` Jason A. Donenfeld

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=4993616.ZASKD2KPVS@scorpbook \
    --to=saeidscorp@yahoo.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 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).