Commit Graph

8149 Commits

Author SHA1 Message Date
Jason Rhinelander
1f9779cdcd
Windows compilation fix 2022-09-19 20:26:41 -03:00
Jason Rhinelander
b2cd9a9eec
openssl 3 build fixes
SYSTEM/MACHINE apparently doesn't work anymore and you have to pass the
system-machine value into the (cursed nasty hacky perl) configure
script.
2022-09-19 20:26:40 -03:00
Jason Rhinelander
7078ab06bc
compiler warnings cmake 3.13 compatibility fix 2022-09-19 20:26:40 -03:00
Jason Rhinelander
93c01623b0
Format fixes & fix warning in format script
- Don't escape '#' in the greps in format.sh: they warn about a spurious
  `\` in the latest grep.
- reformat
2022-09-19 20:26:40 -03:00
Jason Rhinelander
ec91a6db05
ReconfigureDNS fixes, fixes macos exit mode
- ReconfigureDNS wasn't returning the old servers; made it void instead
  (the Apple code can just store a copy of the original upstream
  servers instead).
- Reconfiguring DNS reset the unbound context but didn't replace it, so
  a Down()/Up() would crash.
- Simplify Resolver() destructor to just call Down(), and make it final
  just so that no one tries to inherit from us (so that calling a
  virtual function from the destructor is safe).
- Rename CancelPendingQueries() to Down(); the former cancelled but also
  shut down the object, so the name seemed a bit misleading.
- Rename SetInternalState in Resolver_Base to ResetResolver, so that we
  aren't conflicting with ResetInternalState from Endpoint (which was a
  problem because TunEndpoint inherited from both; it could be resolved
  through the different argument type if we removed the default, but
  that seems gross).
- Make Resolver use a bare unbound context pointer rather than a
  shared_ptr; since Resolver (now) entirely manages it already we don't
  need an extra management layer, and it saves a bunch of `.get()`s.
2022-09-19 20:26:40 -03:00
Jason Rhinelander
2ccc518849
Fix apple dns, part 817 2022-09-19 20:26:40 -03:00
Jeff Becker
bd09f7716d
override method 2022-09-19 20:26:40 -03:00
Jeff Becker
13d1301e08
rewire up dns reconfiguration for macos 2022-09-19 20:26:40 -03:00
Jason Rhinelander
52c6cd497f
Apple DNS fix WIP 2022-09-19 20:26:40 -03:00
Jason Rhinelander
2aae56b0e0
Apple DNS configuration fix: don't obliterate trampoline
On Apple, the network extension is outside the tunnel routing, so we
cannot have libunbound talk directly to upstream (it would leak DNS when
exit mode is enabled).  Instead unbound *always* talks to a localhost
port where we have a "dns trampoline" that takes UDP packets and shoves
them through the tunnel.

We were doing that already, but recent changes here were overwriting the
libunbound settings with.

This also moves the upstream DNS configuration part of `Up()` into its
own method.
2022-09-19 20:26:40 -03:00
Jason Rhinelander
4d920bb2e2
Fix macos
We don't have a resolver on macos, so we were running through this loop
with fails == 0 == m_Impls.size() and throwing, crashing the process.

Early return to avoid the failure and fix macos crash.
2022-09-19 20:26:39 -03:00
Jeff Becker
b81ae95246
remove hunk of win32 specific code, it is dead in this codepath 2022-09-19 20:26:39 -03:00
Jason Rhinelander
27d58044c7
macos compilation fixes 2022-09-19 20:26:39 -03:00
Jason Rhinelander
a82907bc6c
Set various -W flags on apple
Apple supports anything here that Clang supports and should have them
set the same as everywhere else.

Most importantly this gives apple the -Wno-deprecated-declarations flag
which has been driving me nuts on macos.

This also version-gates the -Wno-deprecated-declarations so that it
will turn on again when we bump the version beyond .10.
2022-09-19 20:26:39 -03:00
Jason Rhinelander
c7597c1abd
OpenSSL 1.1.1 -> 3.0.5 2022-09-19 20:26:39 -03:00
Jeff Becker
379ac755ec
make unit tests pass
changes to how config defaults, specifically allowing defaults to be a
vector, broke unit test compilation. this makes them compile again.
2022-09-19 20:26:39 -03:00
Jason Rhinelander
291f311259
Fix linked list iteration for windows ip/gateways
We were requiring `->Next` be true, which means we skipped the last (and
often only) entry of the linked lists and so never properly found the
gateway.
2022-09-19 20:26:39 -03:00
Jason Rhinelander
9097435f64
Refactor/fix GetAdaptersAddresses
- We need to pass a flag to get Windows to include gateway info.
- Refactor it to use microsoft's recommended magic default 15000 buffer
  size and repeat in a loop a few times until it works.  Developers,
  developers, developers, developers!
2022-09-19 20:26:39 -03:00
Jason Rhinelander
d1e997177d
Add missing != operator to nuint_t 2022-09-19 20:26:38 -03:00
Jason Rhinelander
613459401d
Linux route poker fixes
- don't add routes when not in exit mode
- don't call Up() from rpc code (the RouterPoker itself decides when to
  call Up())
2022-09-19 20:26:38 -03:00
Jason Rhinelander
e9554c7c5e
Don't do route poking when disabled
IsEnabled() is a bit broader than just IsServiceNode, so use it instead.
2022-09-19 20:26:38 -03:00
Jason Rhinelander
45b3365002
Simplifications
- a `static` is less verbose and otherwise identical to an empty
  namespace for a single declaration like this.
- operator== on two optionals already does exactly what the `is_equal`
  lambda here is doing.
- formatting
2022-09-19 20:26:38 -03:00
Jason Rhinelander
517911b499
Fix crash on shutdown
For some (wrong) reason this chunk of code was here.  Removed it to stop
a crash on shutdown.
2022-09-19 20:26:38 -03:00
Jeff Becker
0fb639db53
idempotent dns 2022-09-19 20:26:38 -03:00
Jeff Becker
26c1336517
limit route poker 2022-09-19 20:26:38 -03:00
Jeff Becker
61f66ac1ec
fix up win32 route poker a bit 2022-09-19 20:26:38 -03:00
Jason Rhinelander
15144f193c
cleanups/simplifications 2022-09-19 20:26:38 -03:00
Jason Rhinelander
9ddf7413af
Windows DNS fixes
- windivert was being set up *before* DNS is set up, so the DNS port was
  nullopt and thus we couldn't properly identify upstream DNS traffic.
- close() doesn't close a socket on Windows, so the socket-bind-close
  approach to get a free UDP port wasn't actually closing, and thus
  unbound upstream constrained to the given port were completely
  failing.
- The unbound thread was accessing the same shared_ptr instance as the
  outer code, which isn't thread-safe; changed it to copy a weak_ptr
  into the lambda instead.
- Exclude upstream DNS traffic in the filter rather than capturing and
  reinjecting it.
2022-09-19 20:26:37 -03:00
Jason Rhinelander
c470349fb3
Log upstream DNS servers when setting it up 2022-09-19 20:26:37 -03:00
Jason Rhinelander
ab2177bee9
Restore Apple hax 2022-09-19 20:26:37 -03:00
Jason Rhinelander
de4bce1d96
Disable upstream TCP DNS
windivert, in particular, will get filtered by this and it almost
certainly won't work.
2022-09-19 20:26:37 -03:00
Jason Rhinelander
d32a37e30b
Upgrade unbound to latest stable 2022-09-19 20:26:37 -03:00
Jason Rhinelander
bb85ec4595
De-inline vpn/win32.hpp 2022-09-19 20:26:37 -03:00
Jason Rhinelander
2a27698016
Fix backwards from/to in PacketSource_Wrapper
This resulted in DNS responses in Windows having reversed direction when
reinjected, and thus not arriving as expected.
2022-09-19 20:26:37 -03:00
Jason Rhinelander
7a0d4a905e
fix speeling 2022-09-19 20:26:37 -03:00
Jason Rhinelander
07231dd9e1
Fixed crash in DNS resolving
The inner lambda here wasn't keeping the `Query` (`this`) alive, so
`src` wasn't valid anymore.  This changes it to copy the `src`
shared_ptr into the lambda instead of capturing `this`, and fixes it.
2022-09-19 20:26:36 -03:00
Jason Rhinelander
d4739d5d47
Fix sockaddr_len initial value 2022-09-19 20:26:36 -03:00
Jason Rhinelander
b856b78de3
format 2022-09-19 20:26:36 -03:00
Jason Rhinelander
05ed9d6de0
llarp/dns logging refactor
Convert everything in llarp/dns to new-style logging.
2022-09-19 20:26:36 -03:00
Jason Rhinelander
49223a7853
bind/close to find free UDP port
The current code isn't working and gives a 0 (which then fails unbound
initialization).  This replaces it by doing a socket+bind to find a free
port then immediately closes (but passes the port we got into unbound).
2022-09-19 20:26:36 -03:00
Jason Rhinelander
9921dd6c77
Simplify dll loading via static function pointers
- Replaces RAII handling of DLLs with global function pointers.  (We
  don't unload the dll this way, but that seems unnecessary anyway).
- Simplifies code by just needing to call an init function, but not
  needing to pass around an object holding the function pointers.
- Adds a templated dll loader that takes the dll and a list of
  name/pointer pairs to load the dll and set the pointers in one shot.
2022-09-19 20:26:36 -03:00
Jeff Becker
281fbe57f7
promote log statement 2022-09-19 20:26:36 -03:00
Jason Rhinelander
aee618e0d7
Fail if wintun can't retrieve its version 2022-09-19 20:26:36 -03:00
Jason Rhinelander
84ad0ab4d3
Slightly DRY thread-setting code, fix warning
There were warnings from the rc variable being unused; this DRYes it to
use the same code as linux (including the failure check on rc).
2022-09-19 20:26:36 -03:00
Jason Rhinelander
4065413977
Simplify/fix ip_header layout
ip_header wasn't 20 bytes on windows compilations for some unholy
reason.  This restructures it to avoid the template and just use two
different structs for le/be with a condition_t for the ifdef, which
resolves it (and *also* apparently avoids the need for the pack).

Also add a static_assert to check the size.

Also do the same for ipv6.
2022-09-19 20:26:35 -03:00
Jason Rhinelander
58eec9ed11
Avoid strict aliasing warning on function pointers
Cast via an ordinary function pointer rather than a function pointer
reference to avoid the warning.

Also make the pointer in `Func_t` explicit rather than implicit (deduced
into the `Func_t` type) to make it clearer what is going on here.
2022-09-19 20:26:35 -03:00
Jason Rhinelander
ef4e720890
Bump cmake min to 3.13 and adopt policies up to 3.24
3.13...3.xx means "minimum is 3.13, but use any new cmake policies
introduced up to 3.xx".

There was, in particular, a policy w.r.t.  external project timestamps
causing warnings under 3.24.
2022-09-19 20:26:35 -03:00
Jason Rhinelander
dd16158081
DNS: default to 127.3.2.1 & high port on Linux
Lots of tools struggle with non-default DNS port, so keep a listener on
127.3.2.1:53 (by default).

This required various changes to the config handling to hold a vector
(instead of an optional) of defaults and values, and now allows passing
in an array of defaults instead of just a single default.
2022-09-19 20:26:35 -03:00
Jeff Becker
beb07bf46f
small optimizations and fixes
- Ensure ip header struct is packed
- Use fmt
- add missing header
2022-09-19 20:26:28 -03:00
Jason Rhinelander
cfd80f6a17
Fix buffer_printer overflow 2022-09-19 20:25:52 -03:00