Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Janne Johansson <icepic.dz@gmail.com>
To: WireGuard mailing list <wireguard@lists.zx2c4.com>
Subject: Re: Source IP incorrect on multi homed systems
Date: Mon, 20 Feb 2023 12:09:25 +0100	[thread overview]
Message-ID: <CAA6-MF8wNMCDkfWiB96W5pwL+YwMgPCCOn1s1B2YQ_zy_V6U-A@mail.gmail.com> (raw)

rewriting for the lists, managed to bold some pasted text and hence
get blocked due to html-mails not allowed on list.

Den sön 19 feb. 2023 kl 21:17 skrev Nico Schottelius
<nico.schottelius@ungleich.ch>:
> Janne Johansson <icepic.dz@gmail.com> writes:
> > *) https://en.wiktionary.org/wiki/Chesterton%27s_fence
>
> I am happy to have learned a new principle today, thanks for that.
>
> And to be sure that everyone is on the same page:
>
>     Wireguard should reply by default with the source address that
>     used to be the destination address, but at the moment wireguard is not
>     doing that at the moment.
>
> If anyone disagrees with above statement, please let me know.

I disagree, but perhaps only because that statement is slightly too short.

Let's assume I have two ISPs and hence a multihomed wg peer, with ip
A.x.x.x from isp A, and ip B.x.x.x from isp B. For some reason, this
box has a routing table that says "prefer link A to reach the
internet", but I set up client C to set up wireguard to B.1.2.3 and
client C sends it udp packet with src ip C and dest IP B.x.x.x. Since
UDP is stateless, the "response" from the multihomed server is created
"out of thin air" as a random UDP packet destined for C. We don't feel
it is unrelated to the previous received packet, but from the tcp
stack perspective it is.

The routing table now decides that interface A will be the awesomest
for sending UDP to C, and therefore creates a packet with source ip
A.x.x.x and dest ip C.x.x.x and sends it off. This surprise seems to
be the main issue in this thread. Perhaps we see this multihomed box
as slightly misconfigured as far as wireguard goes, perhaps it should
have posted A.x.x.x instead of B.x.x.x as the wg endpoint to the
client or whatever, but the facts remain.

Now, in your above statement you hope to get everyone to agree on,
this would need to also include "sending it back on interface B, to
the gw used by interface B to ISP B if there is one" or else isp A
might drop the packet as being sent from a "forged" address since it
looks like a fake source ip from isp As perspective. The routing
lookups - before any applied tricks - will look at destination IPs
only and make the decision based on that.

I think the proposed solution, while attractive at first glance, may
be trading one kind of "surprise" behaviour to another where the
interface B might be less useful than A which would explain why the
default route is set to use A. If you look at the many posts on the
internet over many years about "why udp source ip got chosen wrong on
multihomed boxes" you see answers like:
"You either bind(2) to each interface address and manage multiple
sockets, or let the kernel do the implicit source IP assignment with
INADDR_ANY. There is no other way."
( https://stackoverflow.com/questions/3062205/setting-the-source-ip-for-a-udp-socket
, not about vpns and lots older than wireguard)

What this means is that if you have a box where links and interfaces
come and go (usb wifi dongles, tethered cell phones..) then wireguard
now has to make a lot of extra work, trying to keep tabs on what
interfaces exist or not, instead of just binding to port 0 and letting
the kernel handle this by itself in the normal but to some, surprising
way for udp packets.

My gut feeling is that if you have a setup like this example
multihomed peer, you get to do some extra steps, which may include the
aforementioned firewall mark "tricks", use VRFs/Namespaced
interfaces/routing domains, add a specific route to client C ip over
link B, bind wg to a loopback interface or source-nat on outgoing wg
traffic or something along those lines in order to have a wg endpoint
on a less-preferred interface and not cause issues with
stateful-nat-gws at client C.

--
May the most significant bit of your life be positive.

             reply	other threads:[~2023-02-20 11:09 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-20 11:09 Janne Johansson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-02-18 20:14 Nico Schottelius
     [not found] ` <CAHx9msc1cNV80YU7HRmQ9gsjSEiVZ=pb31aYqfP62hy8DeuGZA@mail.gmail.com>
2023-02-18 22:34   ` Nico Schottelius
2023-02-19  0:45 ` Mike O'Connor
2023-02-19  8:01   ` Nico Schottelius
2023-02-19  9:19     ` Mikma
2023-02-19 12:04       ` Nico Schottelius
2023-02-19 12:10     ` Nico Schottelius
2023-02-19 18:59       ` Peter Linder
     [not found]     ` <2ed829aaed9fec59ac2a9b32c4ce0a9005b8d8b850be81c81a226791855fe4eb@mu.id>
2023-02-19 12:13       ` Nico Schottelius
2023-02-19 14:39         ` Christoph Loesch
2023-02-19 16:32           ` David Kerr
2023-02-19 16:54             ` Sebastian Hyrvall
2023-02-19 18:04               ` Janne Johansson
2023-02-19 18:08                 ` Sebastian Hyrvall
2023-02-19 20:11                 ` Nico Schottelius
2023-02-19 17:05             ` tlhackque
2023-02-19 18:37               ` David Kerr
2023-02-19 18:52                 ` tlhackque
2023-02-19 18:42               ` tlhackque
2023-02-19 20:18                 ` Nico Schottelius
2023-02-19 20:42                   ` Roman Mamedov
2023-02-19 21:19                     ` Nico Schottelius
2023-02-19 22:06                       ` tlhackque
2023-02-19 21:39                     ` tlhackque
     [not found]               ` <CADGd2DoE6TCtCxxWL7JWyNW5+yy_Pe+9MNzHznbudMWLTXQreA@mail.gmail.com>
2023-02-19 22:28                 ` tlhackque
2023-02-20  0:58                   ` Luiz Angelo Daros de Luca
2023-02-19 20:02           ` Nico Schottelius

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=CAA6-MF8wNMCDkfWiB96W5pwL+YwMgPCCOn1s1B2YQ_zy_V6U-A@mail.gmail.com \
    --to=icepic.dz@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 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).