gvisor/test/iptables
Kevin Krakauer 31f2182cd3 iptables: add instructions for runsc building.
The readme didn't mention that users need to:
- `bazel build` when working on iptables tests
- enable raw sockets in /etc/docker/daemon.json.

PiperOrigin-RevId: 294260169
2020-02-10 11:09:19 -08:00
..
runner Standardize on tools directory. 2020-01-27 12:21:00 -08:00
BUILD Standardize on tools directory. 2020-01-27 12:21:00 -08:00
README.md iptables: add instructions for runsc building. 2020-02-10 11:09:19 -08:00
filter_input.go Merge pull request #1683 from kevinGC:ipt-udp-matchers 2020-02-04 16:20:16 -08:00
filter_output.go Merge pull request #1541 from nybidari:iptables 2020-01-17 08:38:25 -08:00
iptables.go Add iptables testing framework. 2019-12-12 14:42:11 -08:00
iptables_test.go Fix iptables tests that were broken by rename. 2020-01-29 16:27:12 -08:00
iptables_util.go Merge pull request #1617 from kevinGC:iptables-write-filter-proto 2020-01-23 14:48:39 -08:00
nat.go Merge pull request #1541 from nybidari:iptables 2020-01-17 08:38:25 -08:00

README.md

iptables Tests

iptables tests are run via scripts/iptables_test.sh.

iptables requires raw socket support, so you must add the --net-raw=true flag to /etc/docker/daemon.json in order to use it.

Test Structure

Each test implements TestCase, providing (1) a function to run inside the container and (2) a function to run locally. Those processes are given each others' IP addresses. The test succeeds when both functions succeed.

The function inside the container (ContainerAction) typically sets some iptables rules and then tries to send or receive packets. The local function (LocalAction) will typically just send or receive packets.

Adding Tests

  1. Add your test to the iptables package.

  2. Register the test in an init function via RegisterTestCase (see filter_input.go as an example).

  3. Add it to iptables_test.go (see the other tests in that file).

Your test is now runnable with bazel!

Run individual tests

Build and install runsc. Re-run this when you modify gVisor:

$ bazel build //runsc && sudo cp bazel-bin/runsc/linux_amd64_pure_stripped/runsc $(which runsc)

Build the testing Docker container. Re-run this when you modify the test code in this directory:

$ bazel run //test/iptables/runner:runner-image -- --norun

Run an individual test via:

$ bazel test //test/iptables:iptables_test --test_filter=<TESTNAME>

To run an individual test with runc:

$ bazel test //test/iptables:iptables_test --test_filter=<TESTNAME> --test_arg=--runtime=runc