105 Commits
Author SHA1 Message Date
Parth SarthiandgVisor bot 1068b58c2a Nftables: Add iptables-nft integration test target and runner.
- Add iptables-nft test runner and integration test target.
- Makefile to run the tests; will add buildkite later.

PiperOrigin-RevId: 966434729
2026-08-18 01:09:40 -07:00
Parth SarthiandgVisor bot ea97d7f01d IPTables: Added support for Reject with TCP Reset.
iptables_test: Fixed some of the broken ipv6 tests.
PiperOrigin-RevId: 940087094
2026-06-29 16:13:02 -07:00
Nayana BidariandgVisor bot 1a93b02d30 Fix the owner matching in netstack iptables.
Before this change, gvisor dropped the packets if owner was marked nil in the
packet. Linux does not drop the packet in this case and allows the packet to
flow through the other rules. This changes fixes the behavior with gvisor and
makes it compatible with linux. Added an iptables test to verify the fix.

PiperOrigin-RevId: 937515484
2026-06-24 13:14:02 -07:00
Konstantin BogomolovandgVisor bot 4dfcd5e1ae nogo: Fix more analyzer findings.
PiperOrigin-RevId: 875246522
2026-02-25 11:07:15 -08:00
Alexander CuevaandgVisor bot c2d35c12f2 Move network utility functions to a util package.
This change refactors common network utility functions used in iptables tests
into a dedicated utils package to be shared with netfilter table tests.

PiperOrigin-RevId: 799318149
2025-08-25 16:46:54 -07:00
Ayush RanjanandgVisor bot 98e6c3a16b Fix handling of file capabilities.
All the following changes are compatible with what Linux does.
- Do not attempt to apply file capabilities when it is not present.
- If the rootID specified in v3 file capability struct does not own the
  current userns, then file capabilities are not applied.
- While applying file capabilities, EPERM is only returned if
  VFS_CAP_FLAGS_EFFECTIVE is set.
- Re-raise capabilities of root user as per capabilities(7). Compare
  security/commoncap.c:handle_privileged_root().

PiperOrigin-RevId: 761725759
2025-05-21 17:07:56 -07:00
Andrei Vagin 67266e9403 Fix a few typos 2025-01-29 21:16:51 -08:00
gVisor bot 3ba3590d04 Merge pull request #11298 from clickyotomy:multiport
PiperOrigin-RevId: 718479754
2025-01-22 12:16:08 -08:00
clickyotomy 75ac9bcc48 netfilter: Support multiport matching (-m multiport)
This set of changes adds:

  - support for `xt_multiport_{,v1}` matchers for matching for
    a range of ports and their inverse, i.e.,:

      ```
      -m multiport [!] --[s|d]ports (PORT,...|PORT:PORT,...)
      ```

  - support for `IP{,6}T_SO_GET_REVISION_MATCH` socket options,
    which allows `iptables` to query for the highest supported
    revision for a given matcher
2025-01-18 09:46:30 -05:00
Andrei VaginandgVisor bot 9368e6e408 netstack/iptables: don't require ports for snat rules
Ports will be set dynamically. It was implemented in
38548db5a9 ("Track UDP connections").

PiperOrigin-RevId: 642886517
2024-06-13 01:05:52 -07:00
Jing ChenandgVisor bot d56b30b38a Replace reflect.DeepEqual with [slices/maps].Equal.
They are faster on slice/map comparisons.

PiperOrigin-RevId: 633080355
2024-05-12 21:20:18 -07:00
Champ-Goblem 3961120d1e sentry/netfilter: support inverse dport/sport
Add support for inverting --dport and --sport matches in netfilter.
This allows support for istio versions 1.18 and higher

Fixes: #9865
Signed-off-by: Champ-Goblem <[email protected]>
2024-01-05 19:24:14 +00:00
Kevin KrakauerandgVisor bot 76c12d6ce1 iptables: use log package to get timestamps in tests
Useful in debugging buildkite flakes, e.g:

https://buildkite.com/gvisor/pipeline/builds/26145

PiperOrigin-RevId: 586125192
2023-11-28 15:44:49 -08:00
Kevin KrakauerandgVisor bot b81a51a99b iptables: account for old kernel being old
Our oldkernel test machines use an iptables binary so old that when we scrape
the rules, the newer iptables binary running inside gVisor doesn't support the
revision anymore. Account for that in the test so that nftables_test doesn't
fail every time it's run on oldkernel.

Example failure: https://buildkite.com/gvisor/pipeline/builds/25928#018bd63c-4ffe-43ee-bfb0-916766db35f2

PiperOrigin-RevId: 582897811
2023-11-15 21:00:44 -08:00
Kevin KrakauerandgVisor bot 80ed0eabef runsc: workaround for scraping nftables
This feature is flag-gated because it can increase runsc startup time by
spawning several child processes.

Testing is done via shell script rather than the usually-preferred Go Docker
API because `docker network create` installs a bunch of iptables rules, whereas
the analagous API calls do not.

PiperOrigin-RevId: 582848436
2023-11-15 16:53:23 -08:00
Kevin KrakauerandgVisor bot 418748248f iptables: support address-only and port-only nat
Also fix the way we return target revision numbers.

Also also change some incorrect receiver names.

PiperOrigin-RevId: 582789755
2023-11-15 13:38:48 -08:00
Kevin KrakauerandgVisor bot c8f57b46d2 netstack: iptables DNAT revision 2
With this change, we support all the DNS rules intalled by Docker when using
custom networks.

PiperOrigin-RevId: 582073741
2023-11-13 13:57:05 -08:00
Kevin KrakauerandgVisor bot ecdf37f822 netstack: add iptables DNAT revision 0 support
PiperOrigin-RevId: 581468023
2023-11-10 23:51:22 -08:00
Kevin KrakauerandgVisor bot f425ec7b9b update the iptables test image to get a newer iptables binary
PiperOrigin-RevId: 581274930
2023-11-10 08:59:16 -08:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Kevin KrakauerandgVisor bot 3a76efe831 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
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
Adin ScannellandgVisor bot 4b3911824d Validate flags during install.
First, this change moves the internal config API to use flag.FlagSet, which
allows more flexibility and fixes many test usages.

Second, the runtime flags are validated during install. The platform is opened
and a warning issued if this fails, but this is not fatal.

This change requires moving the Makefile to --test_env, since the attribute
is not properly supported by test targets. Therefore, the targets can use args
while the Makefile must pass in configuration via --test_env.

PiperOrigin-RevId: 428048274
2022-02-11 11:24:01 -08:00
Nayana BidariandgVisor bot 6d5f386c02 Fix typo and bazel output binary path.
PiperOrigin-RevId: 409224559
2021-11-11 13:12:55 -08:00
Toshi KikuchiandgVisor bot 44b1243904 iptables: support postrouting hook and SNAT target
The current SNAT implementation has several limitations:
- SNAT source port has to be specified. It is not optional.
- SNAT source port range is not supported.
- SNAT for UDP is a one-way translation. No response packets
  are handled (because conntrack doesn't support UDP currently).
- SNAT and REDIRECT can't work on the same connection.

Fixes #5489

PiperOrigin-RevId: 367750325
2021-04-09 21:11:26 -07:00
Zach KoopmansandgVisor bot d8f34027b3 [syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal.
New hostarch package contains code not dependent on syserror.

PiperOrigin-RevId: 365651233
2021-03-29 13:30:21 -07:00
Ayush RanjanandgVisor bot c650f6a0e7 [op] Replace syscall package usage with golang.org/x/sys/unix in test/.
The syscall package has been deprecated in favor of golang.org/x/sys.

Note that syscall is still used in some places because the following don't seem
to have an equivalent in unix package:
- syscall.SysProcIDMap
- syscall.Credential

Updates #214

PiperOrigin-RevId: 361332034
2021-03-06 09:54:09 -08:00
Kevin KrakauerandgVisor bot bff1001803 Deflake //test/iptables:iptables_test
We were opening dual-stack sockets, but tests only set iptables rules for a
single network protocol. Thus, packets (probably sent by previous tests) could
sneak in and break tests.

Tested with:
bazel test ///test/iptables:iptables_test
--test_arg=--runtime=runsc --nocache_test_results --test_output=errors
--runs_per_test=1000 --test_filter=TestFilterInputDropUDP
PiperOrigin-RevId: 357972385
2021-02-17 10:02:02 -08:00
Toshi KikuchiandgVisor bot cde8d6050b iptables test: Implement testCase interface on pointers
Implementing interfaces on value types causes the interface to be
implemented by both the value type and the pointer type of the
implementer. This complicates type assertion as it requires the
assertion to check for both the pointer type and the value type.

PiperOrigin-RevId: 357061063
2021-02-11 14:39:41 -08:00
Toshi KikuchiandgVisor bot 19d27d5a02 iptables: support matching the input interface name
We have support for the output interface name, but not for the input
interface name.
This change adds the support for the input interface name, and adds the
test cases for it.

Fixes #5300

PiperOrigin-RevId: 353179389
2021-01-21 23:19:19 -08:00
Kevin KrakauerandgVisor bot c6ddb50e50 Ensure that IP{V6}_RECVORIGDSTADDR yields the post-NAT address and port.
PiperOrigin-RevId: 352624174
2021-01-19 12:14:08 -08:00
Adin ScannellandgVisor bot 0dab30d83f Fix simple mistakes identified by goreportcard.
These are primarily simplification and lint mistakes. However, minor
fixes are also included and tests added where appropriate.

PiperOrigin-RevId: 351425971
2021-01-12 12:38:22 -08:00
Adin ScannellandgVisor bot 69f0412910 Remove existing nogo exceptions.
PiperOrigin-RevId: 347047550
2020-12-11 12:06:49 -08:00
Adin ScannellandgVisor bot cd577716bf Fail gracefully if Docker is not configured with ipv6.
PiperOrigin-RevId: 343927315
2020-11-23 14:24:27 -08:00
Kevin KrakauerandgVisor bot 7171e7e794 iptables: add documentation about enabing docker ipv6
PiperOrigin-RevId: 341439435
2020-11-09 10:50:43 -08:00
Kevin KrakauerandNicolas Lacasse 33a2d2df62 iptables testing: handle EINTR on calls to accept().
This caused test flakes.

PiperOrigin-RevId: 338758723
2020-10-23 16:13:01 -07:00
Ghanan GowripalanandgVisor bot 7ce7966301 Pass NetworkInterface to LinkAddressRequest
Previously a link endpoint was passed to
stack.LinkAddressResolver.LinkAddressRequest. With this change,
implementations that want a route for the link address request may
find one through the stack. Other implementations that want to send
a packet without a route may continue to do so using the network
interface directly.

Test: - arp_test.TestLinkAddressRequest
      - ipv6.TestLinkAddressRequest
PiperOrigin-RevId: 338577474
2020-10-22 17:02:29 -07:00
Kevin KrakauerandgVisor bot a52404d864 Remove reference to deleted script
PiperOrigin-RevId: 335516625
2020-10-05 15:49:14 -07:00
Kevin KrakauerandgVisor bot 3273db6579 ip6tables: redirect support
Adds support for the IPv6-compatible redirect target. Redirection is a limited
form of DNAT, where the destination is always the localhost.

Updates #3549.

PiperOrigin-RevId: 334698344
2020-09-30 16:04:26 -07:00
Kevin KrakauerandgVisor bot afcb0762ed ip6tables: filter table support
`ip6tables -t filter` is now usable. NAT support will come in a future CL.

#3549

PiperOrigin-RevId: 332381801
2020-09-17 21:54:48 -07:00
Kevin Krakauer f2755f0bf9 Speed up iptables tests
//test/iptables:iptables_test runs 30 seconds faster on my machine.

* Using contexts instead of many smaller timeouts makes the tests less
  likely to flake and removes unnecessary complexity.
* We also use context to properly shut down concurrent goroutines and
  the test container.
* Container logs are always logged.
2020-08-10 17:50:01 -07:00
Kevin Krakauer bad4fe1ade iptables: support SO_ORIGINAL_DST
Envoy (#170) uses this to get the original destination of redirected
packets.
2020-07-31 10:47:26 -07:00
Kevin Krakauer f5f34a3863 ip6tables testing
We skip gVisor tests for now, as ip6tables aren't yet implemented.
2020-07-28 10:51:14 -07:00
Kevin Krakauer 2f0210af59 Speed up some iptables tests
Sending UDP packets in a loop can be done in a separate goroutine. We
can't do this in ContainerAction because the container will terminate
early.

Locally, scripts/iptables_tests.sh runs ~40 seconds faster.
2020-07-24 15:06:07 -07:00
Kevin Krakauer 0d4b34cd6a iptables: don't NAT existing connections
Fixes a NAT bug that manifested as:
- A SYN was sent from gVisor to another host, unaffected by iptables.
- The corresponding SYN/ACK was NATted by a PREROUTING REDIRECT rule
  despite being part of the existing connection.
- The socket that sent the SYN never received the SYN/ACK and thus a
  connection could not be established.

We handle this (as Linux does) by tracking all connections, inserting a
no-op conntrack rule for new connections with no rules of their own.

Needed for istio support (#170).
2020-07-22 16:49:11 -07:00
gVisor bot 3a28d5f9f8 Merge pull request #3171 from kevinGC:ipv6-kokoro
PiperOrigin-RevId: 320290162
2020-07-08 16:36:33 -07:00
Kevin Krakauer d4e149297e ip6tables: handle both IPv4 and v6 addresses
Enabling IPv6 in Docker caused IPv4 tests to fail because localAddrs
didn't distinguish between address types. Example failure:
https://source.cloud.google.com/results/invocations/203b2401-3333-4bec-9a56-72cc53d68ddd/log
2020-07-08 15:14:29 -07:00
Zach KoopmansandgVisor bot c5a0007cec Move all tests to new docker API.
Moves following to new dockerutil API:
- //test/e2e:integration_test
- //test/image:image_test
- //test/iptables:iptables_test
- //test/root:root_test
- //test/packetimpact:packetimpact_test

PiperOrigin-RevId: 320253118
2020-07-08 13:26:23 -07:00
Fabricio VoznikaandgVisor bot 52335056f7 Move mount configutation to RunOpts
Separate mount configuration from links and move it to
RunOpts, like the other options.

PiperOrigin-RevId: 317010158
2020-06-17 18:43:26 -07:00
Kevin Krakauer b9762e741e iptables: loopback traffic skips prerouting chain
Loopback traffic is not affected by rules in the PREROUTING chain.

This change is also necessary for istio's envoy to talk to other
components in the same pod.
2020-06-05 16:43:50 -07:00