Brad Fitzpatrick
8725b14056
all: migrate more code code to net/netip directly
...
Instead of going through the tailscale.com/net/netaddr transitional
wrappers.
Updates #5162
Change-Id: I3dafd1c2effa1a6caa9b7151ecf6edd1a3fda3dd
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-08-02 13:59:57 -07:00
Brad Fitzpatrick
a12aad6b47
all: convert more code to use net/netip directly
...
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-25 21:53:49 -07:00
Brad Fitzpatrick
6a396731eb
all: use various net/netip parse funcs directly
...
Mechanical change with perl+goimports.
Changed {Must,}Parse{IP,IPPrefix,IPPort} to their netip variants, then
goimports -d .
Finally, removed the net/netaddr wrappers, to prevent future use.
Updates #5162
Change-Id: I59c0e38b5fbca5a935d701645789cddf3d7863ad
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-25 21:12:28 -07:00
Brad Fitzpatrick
7eaf5e509f
net/netaddr: start migrating to net/netip via new netaddr adapter package
...
Updates #5162
Change-Id: Id7bdec303b25471f69d542f8ce43805328d56c12
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-25 16:20:43 -07:00
Josh Bleecher Snyder
0868329936
all: use any instead of interface{}
...
My favorite part of generics.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2022-03-17 11:35:09 -07:00
slowy07
ac0353e982
fix: typo spelling grammar
...
Signed-off-by: slowy07 <slowy.arfy@gmail.com>
2021-08-24 07:55:04 -07:00
David Crawshaw
297b3d6fa4
staticcheck.conf: turn off noisy lint errors
...
Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
2021-06-18 15:48:20 -07:00
Josh Bleecher Snyder
25df067dd0
all: adapt to opaque netaddr types
...
This commit is a mishmash of automated edits using gofmt:
gofmt -r 'netaddr.IPPort{IP: a, Port: b} -> netaddr.IPPortFrom(a, b)' -w .
gofmt -r 'netaddr.IPPrefix{IP: a, Port: b} -> netaddr.IPPrefixFrom(a, b)' -w .
gofmt -r 'a.IP.Is4 -> a.IP().Is4' -w .
gofmt -r 'a.IP.As16 -> a.IP().As16' -w .
gofmt -r 'a.IP.Is6 -> a.IP().Is6' -w .
gofmt -r 'a.IP.As4 -> a.IP().As4' -w .
gofmt -r 'a.IP.String -> a.IP().String' -w .
And regexps:
\w*(.*)\.Port = (.*) -> $1 = $1.WithPort($2)
\w*(.*)\.IP = (.*) -> $1 = $1.WithIP($2)
And lots of manual fixups.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-05-16 14:52:00 -07:00
Josh Bleecher Snyder
d31eff8473
tstest/natlab: use net.ErrClosed
...
We are now on 1.16.
And wgconn.NetErrClosed has been removed upstream.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-03-24 09:46:36 -07:00
Josh Bleecher Snyder
138055dd70
tstest/natlab: use net.ErrClosed instead of a new error
...
Upstream wireguard-go decided to use errors.Is(err, net.ErrClosed)
instead of checking the error string.
It also provided an unsafe linknamed version of net.ErrClosed
for clients running Go 1.15. Switch to that.
This reduces the time required for the wgengine/magicsock tests
on my machine from ~35s back to the ~13s it was before
456cf8a376
.
Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
2021-02-05 13:44:46 -08:00
David Anderson
f794493b4f
wgengine/magicsock: explicitly check path discovery, add a firewall test.
...
The test proves that active discovery can traverse two facing firewalls.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-27 14:09:54 -07:00
David Anderson
5a370d545a
tstest/natlab: drop packets that can't be routed in a LAN.
...
LANs are authoritative for their prefixes, so we should not bounce
packets back and forth to the default gateway in that case.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-27 14:09:54 -07:00
David Anderson
45578b47f3
tstest/natlab: refactor PacketHandler into a larger interface.
...
The new interface lets implementors more precisely distinguish
local traffic from forwarded traffic, and applies different
forwarding logic within Machines for each type. This allows
Machines to be packet forwarders, which didn't quite work
with the implementation of Inject.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-15 14:38:33 -07:00
David Anderson
23123907c0
tstest/natlab: add a configurable SNAT44 translator.
...
This lets us implement the most common kinds of NAT in the wild.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-14 12:17:47 -07:00
David Anderson
39ecb37fd6
tstest/natlab: support different firewall selectivities.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-13 10:52:46 -07:00
David Anderson
88e8456e9b
wgengine/magicsock: add a connectivity test for facing firewalls.
...
The test demonstrates that magicsock can traverse two stateful
firewalls facing each other, that each require localhost to
initiate connections.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-11 07:04:08 +00:00
David Anderson
b3d65ba943
tstest/natlab: refactor, expose a Packet type.
...
HandlePacket and Inject now receive/take Packets. This is a handy
container for the packet, and the attached Trace method can be used
to print traces from custom packet handlers that integrate nicely
with natlab's internal traces.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-11 06:33:01 +00:00
David Anderson
5eedbcedd1
tstest/natlab: add a stateful firewall.
...
The firewall provides a ProcessPacket handler, and implements an
address-and-port endpoint dependent firewall that allows all
traffic to egress from the trusted interface, and only allows
inbound traffic if corresponding outbound traffic was previously
seen.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-11 05:17:38 +00:00
David Anderson
0ed9f62ed0
tstest/natlab: provide inbound interface to HandlePacket.
...
Requires a bunch of refactoring so that Networks only ever
refer to Interfaces that have been attached to them, and
Interfaces know about both their Network and Machine.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-10 20:08:48 -07:00
Brad Fitzpatrick
6c74065053
wgengine/magicsock, tstest/natlab: start hooking up natlab to magicsock
...
Also adds ephemeral port support to natlab.
Work in progress.
Pairing with @danderson.
2020-07-10 14:32:58 -07:00
David Anderson
0aea087766
tstest/natlab: add PacketHandler and Inject.
...
Together, they can be used to plug custom packet processors into
Machines.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-02 21:51:09 -07:00
David Anderson
73db7e99ab
tstest/natlab: make Machine constructible directly.
...
This is a prelude to adding more fields, which would otherwise
become more unnamed function params.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-02 21:51:09 -07:00
David Anderson
d94593e884
tstest/natlab: unregister conn4 if registration of conn6 fails.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-03 02:27:31 +00:00
David Anderson
d7bc4ec029
tstest/natlab: use common helper for conn registration.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-03 02:26:54 +00:00
David Anderson
80a14c49c6
tstest/natlab: add comments to conns4/conns6.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-03 02:23:01 +00:00
David Anderson
c53b154171
tstest/natlab: use &Network in test.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-03 02:22:06 +00:00
David Anderson
622c0d0cb3
tstest/natlab: print trace data when NATLAB_TRACE is set.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-03 02:10:41 +00:00
David Anderson
1d4f9852a7
tstest/natlab: correctly handle dual-stacked PacketConns.
...
Adds a test with multiple networks, one of which is v4-only.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-02 19:09:31 -07:00
David Anderson
771eb05bcb
tstest/natlab: first network attached becomes the default route.
...
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-03 01:03:05 +00:00
David Anderson
f2e5da916a
tstest/natlab: allow sensible default construction of networks.
...
Add a test for LAN->LAN traffic.
Signed-off-by: David Anderson <danderson@tailscale.com>
2020-07-03 00:53:24 +00:00
Brad Fitzpatrick
97910ce712
tstest/natlab: remove unused PacketConner type
2020-07-02 14:50:04 -07:00
Brad Fitzpatrick
14b4213c17
tstest/natlab: add missing tests from earlier commits
...
Now you can actually see that packet delivery works.
Pairing with @danderson
2020-07-02 14:19:43 -07:00
Brad Fitzpatrick
3f4f1cfe66
tstest/natlab: basic NAT-free packet delivery works
...
Pairing with @danderson
2020-07-02 14:18:36 -07:00
Brad Fitzpatrick
a477e70632
tstest/natlab: network address allocation
...
Pairing with @danderson
2020-07-02 13:39:41 -07:00
Brad Fitzpatrick
bb1a9e4700
tstest/natlab: bit more of in-memory network testing package
...
Pairing with @danderson
2020-07-02 13:02:13 -07:00
Brad Fitzpatrick
23c93da942
tstest/natlab: start of in-memory network testing package
...
Pairing with @danderson
2020-07-02 12:36:12 -07:00