Commit Graph

39 Commits

Author SHA1 Message Date
Kevin Krakauer 792ebbff8e netstack: make tcpip.Address hold a []byte
tcp_benchmark throughput increase 2-3%, but allocations go down (25% in the
download benchmark, only 2% in the upload path).

PiperOrigin-RevId: 532523146
2023-05-16 11:40:49 -07:00
Kevin Krakauer 64268c8483 netstack: make tcpip.Address an opaque type
The important change here is in tcpip/tcpip.go, where tcpip.Address is defined.
The rest is updating uses of tcpip.Address.

This is preparation for netip.Addr or []byte based addresses, which should save
us a bunch of allocations. Currently, we allocate every time we want to, say,
get a tcpip.Address from a header. This is because the header is a byte slice,
but Address is a string. Strings are immutable, so Go allocates and copies.

PiperOrigin-RevId: 532284732
2023-05-15 18:07:03 -07:00
Ghanan Gowripalan 8b0c4c6408 Use tcpip.NICID when get/set-ing GRO timeout
PiperOrigin-RevId: 529535113
2023-05-04 15:47:28 -07:00
Andrei Vagin 1338761211 Fix reference leaks
PiperOrigin-RevId: 494027351
2022-12-08 16:38:26 -08:00
Ghanan Gowripalan d947422655 Don't prevent removing loopback in core netstack
Implement this check in netstack integration (in sentry) so that the
core netstack does not prevent an integrator from removing loopback.

PiperOrigin-RevId: 493992707
2022-12-08 14:23:45 -08:00
Kevin Krakauer 901d9a75d3 netstack: add gro_flush_timeout
Makes a per-interface file available to configure the GRO timeout, e.g.
/sys/class/net/eth0/gro_flush_timeout

PiperOrigin-RevId: 487082821
2022-11-08 16:34:55 -08:00
Kevin Krakauer d8aa09e04c convert uses of interface{} to any
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
2022-11-08 13:14:06 -08:00
Andrei Vagin 5ffcc1f799 Don't leak network namespaces
PiperOrigin-RevId: 454707336
2022-06-13 15:05:21 -07:00
Bhasker Hariharan 74a1820ceb Remove TCP endpoint goroutines.
This change removes all endpoint goroutines and all TCP processing is now done
inline in the TCP processor loop. TCP timers directly invoke handlers as
required rather than assert a waker.

UnlockUser is also simplified to just queue the endpoint to the processor
instead of trying to process segments inline. This allows us to centralize logic
for TCP state handling in the processor. This potentially could involve an extra
wakeup but now that endpoint goroutines do not exist this is not such a big
concern as in case of busy servers the processor goroutines will already be
running anyway.

This change also allows us to clean up S/R as now restoring a TCP endpoint does
not require restarting a goroutine and moving it to the right logical point but
only requires that we restart any timers that may have been running when the
save was done and restore any port bindings as required.

Endpoint.Release is now removed in favor of Endpoint.Abort by using Abort in
places where we use Endpoint.Release.

Updates #231

PiperOrigin-RevId: 442673015
2022-04-18 17:35:36 -07:00
Kevin Krakauer ce194f2c1c Automated rollback of changelist 407638912
PiperOrigin-RevId: 410665707
2021-11-17 17:07:05 -08:00
Zach Koopmans 23a115dae8 [syserr] Reverse dependency for tcpip.Error
PiperOrigin-RevId: 407638912
2021-11-04 12:11:41 -07:00
Tony Gong 8b56b6b83b Pass address properties in a single struct
Replaced the current AddAddressWithOptions method with
AddAddressWithProperties which passes all address properties in
a single AddressProperties type. More properties that need to be
configured in the future are expected, so adding a type makes adding
them easier.

PiperOrigin-RevId: 396930729
2021-09-15 15:00:01 -07:00
Zeling Feng 979d6e7d77 Support RTM_DELLINK
This change will allow us to remove the default link in a packetimpact test so
we can reduce indeterministic behaviors as required in https://fxbug.dev/78430.
This will also help with testing #1388.

Updates #578, #1388.

PiperOrigin-RevId: 387896847
2021-07-30 15:41:36 -07:00
Zach Koopmans 590b8d3e99 [syserror] Update several syserror errors to linuxerr equivalents.
Update/remove most syserror errors to linuxerr equivalents. For list
of removed errors, see //pkg/syserror/syserror.go.

PiperOrigin-RevId: 382574582
2021-07-01 12:05:19 -07:00
Zach Koopmans 54b71221c0 [syserror] Change syserror to linuxerr for E2BIG, EADDRINUSE, and EINVAL
Remove three syserror entries duplicated in linuxerr. Because of the
linuxerr.Equals method, this is a mere change of return values from
syserror to linuxerr definitions.

Done with only these three errnos as CLs removing all grow to a significantly
large size.

PiperOrigin-RevId: 382173835
2021-06-29 15:08:46 -07:00
Ghanan Gowripalan 600d14f83e Don't read forwarding from netstack in sentry
https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt:
  /proc/sys/net/ipv4/* Variables:

  ip_forward - BOOLEAN
    0 - disabled (default)
    not 0 - enabled

    Forward Packets between interfaces.

    This variable is special, its change resets all configuration
    parameters to their default state (RFC1122 for hosts, RFC1812
    for routers)

/proc/sys/net/ipv4/ip_forward only does work when its value is changed
and always returns the last written value. The last written value may
not reflect the current state of the netstack (e.g. when `ip_forward`
was written a value of "1" then disable forwarding on an interface)
so there is no need for sentry to probe netstack to get the current
forwarding state of interfaces.

```
~$ cat /proc/sys/net/ipv4/ip_forward
0
~$ sudo bash -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
~$ cat /proc/sys/net/ipv4/ip_forward
1
~$ sudo sysctl -a | grep ipv4 | grep forward
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.default.forwarding = 1
net.ipv4.conf.eno1.forwarding = 1
net.ipv4.conf.lo.forwarding = 1
net.ipv4.conf.wlp1s0.forwarding = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
~$ sudo sysctl -w net.ipv4.conf.wlp1s0.forwarding=0
net.ipv4.conf.wlp1s0.forwarding = 0
~$ sudo sysctl -a | grep ipv4 | grep forward
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.default.forwarding = 1
net.ipv4.conf.eno1.forwarding = 1
net.ipv4.conf.lo.forwarding = 1
net.ipv4.conf.wlp1s0.forwarding = 0
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
~$ cat /proc/sys/net/ipv4/ip_forward
1
~$ sudo bash -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
~$ sudo sysctl -a | grep ipv4 | grep forward
net.ipv4.conf.all.forwarding = 1
net.ipv4.conf.default.forwarding = 1
net.ipv4.conf.eno1.forwarding = 1
net.ipv4.conf.lo.forwarding = 1
net.ipv4.conf.wlp1s0.forwarding = 0
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
~$ sudo bash -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
~$ sudo sysctl -a | grep ipv4 | grep forward
sysctl: unable to open directory "/proc/sys/fs/binfmt_misc/"
net.ipv4.conf.all.forwarding = 0
net.ipv4.conf.default.forwarding = 0
net.ipv4.conf.eno1.forwarding = 0
net.ipv4.conf.lo.forwarding = 0
net.ipv4.conf.wlp1s0.forwarding = 0
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
~$ cat /proc/sys/net/ipv4/ip_forward
0
```

In the above example we can see that writing "1" to
/proc/sys/net/ipv4/ip_forward configures the stack to be a router (all
interfaces are configured to enable forwarding). However, if we manually
update an interace (`wlp1s0`) to not forward packets,
/proc/sys/net/ipv4/ip_forward continues to return the last written value
of "1", even though not all interfaces will forward packets.

Also note that writing the same value twice has no effect; work is
performed iff the value changes.

This change also removes the 'unset' state from sentry's ip forwarding
data structures as an 'unset' ip forwarding value is the same as leaving
forwarding disabled as the stack is always brought up with forwarding
initially disabled; disabling forwarding on a newly created stack is a
no-op.

PiperOrigin-RevId: 373853106
2021-05-14 13:22:58 -07:00
Ghanan Gowripalan baa0888f11 Rename SetForwarding to SetForwardingDefaultAndAllNICs
...to make it clear to callers that all interfaces are updated with the
forwarding flag and that future NICs will be created with the new
forwarding state.

PiperOrigin-RevId: 373618435
2021-05-13 11:24:20 -07:00
Kevin Krakauer abbdcebc54 Implement /proc/sys/net/ipv4/ip_local_port_range
Speeds up the socket stress tests by a couple orders of magnitude.

PiperOrigin-RevId: 361721050
2021-03-08 20:40:34 -08:00
Arthur Sfez 80bc67c268 Export stats that were forgotten
While I'm here, simplify the comments and unify naming of certain stats
across protocols.

PiperOrigin-RevId: 360728849
2021-03-03 12:18:55 -08:00
Arthur Sfez bdaae08ee2 Extract ICMPv4/v6 specific stats to their own types
This change lets us split the v4 stats from the v6 stats, which will be
useful when adding stats for each network endpoint.

PiperOrigin-RevId: 345322615
2020-12-02 15:17:20 -08:00
Ian Lewis 59e2c9f16a Add basic address deletion to netlink
Updates #3921

PiperOrigin-RevId: 339195417
2020-10-27 00:18:10 -07:00
gVisor bot ca30874720 Merge pull request #3651 from ianlewis:ip-forwarding
PiperOrigin-RevId: 332760843
2020-09-20 18:17:20 -07:00
Ghanan Gowripalan d35f07b36a Improve type safety for transport protocol options
The existing implementation for TransportProtocol.{Set}Option take
arguments of an empty interface type which all types (implicitly)
implement; any type may be passed to the functions.

This change introduces marker interfaces for transport protocol options
that may be set or queried which transport protocol option types
implement to ensure that invalid types are caught at compile time.
Different interfaces are used to allow the compiler to enforce read-only
or set-only socket options.

RELNOTES: n/a
PiperOrigin-RevId: 330559811
2020-09-08 12:17:39 -07:00
Ian Lewis ac324f646e Merge branch 'master' into ip-forwarding
- Merges aleksej-paschenko's with HEAD
- Adds vfs2 support for ip_forward
2020-08-17 21:44:31 -04:00
Nayana Bidari 35312a95c4 Add loss recovery option for TCP.
/proc/sys/net/ipv4/tcp_recovery is used to enable RACK loss
recovery in TCP.

PiperOrigin-RevId: 325157807
2020-08-05 20:50:06 -07:00