Commit Graph

482 Commits

Author SHA1 Message Date
Nayana Bidari acc405ba60 Add nat table support for iptables.
- commit the changes for the comments.
2020-02-25 15:03:51 -08:00
Nayana Bidari b30b7f3422 Add nat table support for iptables.
Add nat table support for Prerouting hook with Redirect option.
Add tests to check redirect of ports.
2020-02-18 11:30:42 -08:00
gVisor bot 16308b9dc1 Merge pull request #1791 from kevinGC:uchains
PiperOrigin-RevId: 294957297
2020-02-13 11:19:09 -08:00
gVisor bot 69bf39e8a4 Internal change.
PiperOrigin-RevId: 294952610
2020-02-13 10:59:52 -08:00
Kevin Krakauer 6fdf2c53a1 iptables: User chains
- Adds creation of user chains via `-N <chainname>`
- Adds `-j RETURN` support for built-in chains, which triggers the
  chain's underflow rule (usually the default policy).
- Adds tests for chain creation, default policies, and `-j RETURN' from
  built-in chains.
2020-02-12 15:02:47 -08:00
gVisor bot b8e22e241c Disallow duplicate NIC names.
PiperOrigin-RevId: 294500858
2020-02-11 12:59:11 -08:00
gVisor bot 0dd9ee0d1e Merge pull request #1775 from kevinGC:tcp-matchers-submit
PiperOrigin-RevId: 294340468
2020-02-10 17:21:13 -08:00
Ghanan Gowripalan ca30dfa065 Send DAD event when DAD resolves immediately
Previously, a DAD event would not be sent if DAD was disabled.

This allows integrators to do some work when an IPv6 address is bound to
a NIC without special logic that checks if DAD is enabled.

Without this change, integrators would need to check if a NIC has DAD
enabled when an address is auto-generated. If DAD is enabled, it would
need to delay the work until the DAD completion event; otherwise, it
would need to do the work in the address auto-generated event handler.

Test: stack_test.TestDADDisabled
PiperOrigin-RevId: 293732914
2020-02-06 19:50:34 -08:00
Kevin Krakauer d98287f5eb Merge branch 'master' into tcp-matchers-submit 2020-02-06 17:07:04 -08:00
Ghanan Gowripalan 3700221b1f Auto-generate link-local address as a SLAAC address
Auto-generated link-local addresses should have the same lifecycle hooks
as global SLAAC addresses.

The Stack's NDP dispatcher should be notified when link-local addresses
are auto-generated and invalidated. They should also be removed when a
NIC is disabled (which will be supported in a later change).

Tests:
- stack_test.TestNICAutoGenAddrWithOpaque
- stack_test.TestNICAutoGenAddr
PiperOrigin-RevId: 293706760
2020-02-06 16:43:39 -08:00
Ghanan Gowripalan 940d255971 Perform DAD on IPv6 addresses when enabling a NIC
Addresses may be added before a NIC is enabled. Make sure DAD is
performed on the permanent IPv6 addresses when they get enabled.

Test:
- stack_test.TestDoDADWhenNICEnabled
- stack.TestDisabledRxStatsWhenNICDisabled
PiperOrigin-RevId: 293697429
2020-02-06 15:58:16 -08:00
Ian Gudger 736775e0ac Make gonet consistent both internally and with the net package.
The types gonet.Conn and gonet.PacketConn were confusingly named as both
implemented net.Conn. Further, gonet.Conn was perhaps unexpectedly
TCP-specific (net.Conn is not). This change renames them to gonet.TCPConn and
gonet.UDPConn.

Renames gonet.NewListener to gonet.ListenTCP and adds a new gonet.NewTCPListner
function to be consistent with both the gonet.DialXxx and gonet.NewXxxConn
functions as well as net.ListenTCP.

Updates #1632

PiperOrigin-RevId: 293671303
2020-02-06 14:07:04 -08:00
Ghanan Gowripalan 6bd59b4e08 Update link address for targets of Neighbor Adverts
Get the link address for the target of an NDP Neighbor Advertisement
from the NDP Target Link Layer Address option.

Tests:
- ipv6.TestNeighorAdvertisementWithTargetLinkLayerOption
- ipv6.TestNeighorAdvertisementWithInvalidTargetLinkLayerOption
PiperOrigin-RevId: 293632609
2020-02-06 11:13:29 -08:00
Adin Scannell 1b6a12a768 Add notes to relevant tests.
These were out-of-band notes that can help provide additional context
and simplify automated imports.

PiperOrigin-RevId: 293525915
2020-02-05 22:46:35 -08:00
Eyal Soha f3d9560703 recv() on a closed TCP socket returns ENOTCONN
From RFC 793 s3.9 p58 Event Processing:

If RECEIVE Call arrives in CLOSED state and the user has access to such a
connection, the return should be "error: connection does not exist"

Fixes #1598

PiperOrigin-RevId: 293494287
2020-02-05 17:56:42 -08:00
Kevin Krakauer bf0ea204e9 Merge branch 'master' into tcp-matchers-submit 2020-02-05 14:43:11 -08:00
Ting-Yu Wang 665b614e4a Support RTM_NEWADDR and RTM_GETLINK in (rt)netlink.
PiperOrigin-RevId: 293271055
2020-02-04 18:05:03 -08:00
gVisor bot b29aeebaf6 Merge pull request #1683 from kevinGC:ipt-udp-matchers
PiperOrigin-RevId: 293243342
2020-02-04 16:20:16 -08:00
Ian Gudger a26a954946 Add socket connection stress test.
Tests 65k connection attempts on common types of sockets to check for port
leaks.

Also fixes a bug where dual-stack sockets wouldn't properly re-queue
segments received while closing.

PiperOrigin-RevId: 293241166
2020-02-04 15:54:49 -08:00
Ian Gudger 02997af5ab Fix method comment to match method name.
PiperOrigin-RevId: 292624867
2020-01-31 15:09:13 -08:00
Ghanan Gowripalan 77bf586db7 Use multicast Ethernet address for multicast NDP
As per RFC 2464 section 7, an IPv6 packet with a multicast destination
address is transmitted to the mapped Ethernet multicast address.

Test:
- ipv6.TestLinkResolution
- stack_test.TestDADResolve
- stack_test.TestRouterSolicitation
PiperOrigin-RevId: 292610529
2020-01-31 13:55:46 -08:00
Kevin Krakauer eba7bdc24d iptables: enable TCP matching with "-m tcp".
A couple other things that changed:

- There's a proper extension registration system for matchers. Anyone
  adding another matcher can use tcp_matcher.go or udp_matcher.go as a
  template.
- All logging and use of syserr.Error in the netfilter package happens at the
  highest possible level (public functions). Lower-level functions just
  return normal, descriptive golang errors.
2020-01-31 13:46:13 -08:00
Ghanan Gowripalan 528dd1ec72 Extract multicast IP to Ethernet address mapping
Test: header.TestEthernetAddressFromMulticastIPAddress
PiperOrigin-RevId: 292604649
2020-01-31 13:25:48 -08:00
Kevin Krakauer 2142c70118 Merge branch 'master' into ipt-udp-matchers 2020-01-30 14:56:50 -08:00
Bhasker Hariharan 4ee64a248e Fix for panic in endpoint.Close().
When sending a RST on shutdown we need to double check the
state after acquiring the work mutex as the endpoint could
have transitioned out of a connected state from the time
we checked it and we acquired the workMutex.

I added two tests but sadly neither reproduce the panic. I am
going to leave the tests in as they are good to have anyway.

PiperOrigin-RevId: 292393800
2020-01-30 12:00:35 -08:00
Ghanan Gowripalan ec0679737e Do not include the Source Link Layer option with an unspecified source address
When sending NDP messages with an unspecified source address, the Source
Link Layer address must not be included.

Test: stack_test.TestDADResolve
PiperOrigin-RevId: 292341334
2020-01-30 07:12:52 -08:00
Ghanan Gowripalan 6f841c304d Do not spawn a goroutine when calling stack.NDPDispatcher's methods
Do not start a new goroutine when calling
stack.NDPDispatcher.OnDuplicateAddressDetectionStatus.

PiperOrigin-RevId: 292268574
2020-01-29 19:55:00 -08:00
Bhasker Hariharan 51b783505b Add support for TCP_DEFER_ACCEPT.
PiperOrigin-RevId: 292233574
2020-01-29 15:53:45 -08:00
Kevin Krakauer b615f94aea Merge branch 'master' into ipt-udp-matchers 2020-01-29 13:21:12 -08:00
Ghanan Gowripalan 431ff52768 Update link address for senders of Neighbor Solicitations
Update link address for senders of NDP Neighbor Solicitations when the NS
contains an NDP Source Link Layer Address option.

Tests:
- ipv6.TestNeighorSolicitationWithSourceLinkLayerOption
- ipv6.TestNeighorSolicitationWithInvalidSourceLinkLayerOption
PiperOrigin-RevId: 292028553
2020-01-28 15:45:36 -08:00
Ghanan Gowripalan ce0bac4be9 Include the NDP Source Link Layer option when sending DAD messages
Test: stack_test.TestDADResolve
PiperOrigin-RevId: 292003124
2020-01-28 13:52:04 -08:00
Ghanan Gowripalan 2a2da5be31 Add a type to represent the NDP Source Link Layer Address option
Tests:
- header.TestNDPSourceLinkLayerAddressOptionEthernetAddress
- header.TestNDPSourceLinkLayerAddressOptionSerialize
- header.TestNDPOptionsIterCheck
- header.TestNDPOptionsIter
PiperOrigin-RevId: 291856429
2020-01-27 20:51:28 -08:00
gVisor bot 60d7ff73e1 Merge pull request #1676 from majek:marek/FIX-1632-expose-NewPacketConn
PiperOrigin-RevId: 291803499
2020-01-27 15:30:32 -08:00
Adin Scannell 90ec596166 Fix licenses.
The preferred Copyright holder is "The gVisor Authors".

PiperOrigin-RevId: 291786657
2020-01-27 13:23:57 -08:00
Bhasker Hariharan fbfcfcf5b0 Update ChecksumVVWithoffset to use unrolled version.
Fixes #1656

PiperOrigin-RevId: 291777279
2020-01-27 13:05:26 -08:00
Ting-Yu Wang 6b14be4246 Refactor to hide C from channel.Endpoint.
This is to aid later implementation for /dev/net/tun device.

PiperOrigin-RevId: 291746025
2020-01-27 12:31:47 -08:00
Kevin Krakauer e889f95671 More cleanup. 2020-01-27 12:30:06 -08:00
Kevin Krakauer 29316e66ad Cleanup for GH review. 2020-01-27 12:27:04 -08:00
Adin Scannell d29e59af9f Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Kevin Krakauer 67243ca51c Merge branch 'master' into ipt-udp-matchers 2020-01-27 10:09:51 -08:00
Marek Majkowski 45398b160f Expose gonet.NewPacketConn, for parity with gonet.NewConn API
gonet.Conn can be created with both gonet.NewConn and gonet.Dial.
gonet.PacketConn was created only by gonet.DialUDP. This prevented
us from being able to use PacketConn in udp.NewForwarder() context.

This simple constructor - NewPacketConn, allows user to create
correct structure from that context.
2020-01-27 13:51:15 +00:00
Bhasker Hariharan 6b43cf791a Replace calculateChecksum w/ the unrolled version.
Fixes #1656

PiperOrigin-RevId: 291703760
2020-01-27 05:34:34 -08:00
Bhasker Hariharan 68514d4ba3 Unroll checksum computation loop.
Checksum computation is one of the most expensive bits of
packet processing. Manual unrolling of the loop provides
significant improvement in checksum speed.

Updates #1656

BenchmarkChecksum/checksum_64-12                49834124                23.6 ns/op
BenchmarkChecksum/checksum_128-12               27111997                44.1 ns/op
BenchmarkChecksum/checksum_256-12               11416683                91.5 ns/op
BenchmarkChecksum/checksum_512-12                6375298               174 ns/op
BenchmarkChecksum/checksum_1024-12               3403852               338 ns/op
BenchmarkChecksum/checksum_1500-12               2343576               493 ns/op
BenchmarkChecksum/checksum_2048-12               1730521               656 ns/op
BenchmarkChecksum/checksum_4096-12                920469              1327 ns/op
BenchmarkChecksum/checksum_8192-12                445885              2637 ns/op
BenchmarkChecksum/checksum_16384-12               226342              5268 ns/op
BenchmarkChecksum/checksum_32767-12               114210             10503 ns/op
BenchmarkChecksum/checksum_32768-12                99138             10610 ns/op
BenchmarkChecksum/checksum_65535-12                53438             21158 ns/op
BenchmarkChecksum/checksum_65536-12                52993             21067 ns/op
BenchmarkUnrolledChecksum/checksum_64-12        61035639                19.1 ns/op
BenchmarkUnrolledChecksum/checksum_128-12               36067015                33.6 ns/op
BenchmarkUnrolledChecksum/checksum_256-12               19731220                60.4 ns/op
BenchmarkUnrolledChecksum/checksum_512-12                9091291               116 ns/op
BenchmarkUnrolledChecksum/checksum_1024-12               4976406               226 ns/op
BenchmarkUnrolledChecksum/checksum_1500-12               3685224               328 ns/op
BenchmarkUnrolledChecksum/checksum_2048-12               2579108               447 ns/op
BenchmarkUnrolledChecksum/checksum_4096-12               1350475               887 ns/op
BenchmarkUnrolledChecksum/checksum_8192-12                658248              1780 ns/op
BenchmarkUnrolledChecksum/checksum_16384-12               335869              3534 ns/op
BenchmarkUnrolledChecksum/checksum_32767-12               168650              7095 ns/op
BenchmarkUnrolledChecksum/checksum_32768-12               168075              7098 ns/op
BenchmarkUnrolledChecksum/checksum_65535-12                75085             14277 ns/op
BenchmarkUnrolledChecksum/checksum_65536-12                75921             14127 ns/op

PiperOrigin-RevId: 291643290
2020-01-26 18:35:01 -08:00
Ghanan Gowripalan 878bda6e19 Lock the NIC when checking if an address is tentative
PiperOrigin-RevId: 291426657
2020-01-24 13:10:08 -08:00
Ghanan Gowripalan fb80979e3f Increase timeouts for NDP tests' async events
Increase the timeout to 1s when waiting for async NDP events to help
reduce flakiness. This will not significantly increase test times as the
async events continue to receive an event on a channel. The increased
timeout allows more time for an event to be sent on the channel as the
previous timeout of 100ms caused some flakes.

Test: Existing tests pass
PiperOrigin-RevId: 291420936
2020-01-24 12:30:23 -08:00
Kevin Krakauer 7636478a31 Merge branch 'master' into ipt-udp-matchers 2020-01-24 10:42:43 -08:00
gVisor bot 3d10edc942 Merge pull request #1617 from kevinGC:iptables-write-filter-proto
PiperOrigin-RevId: 291249314
2020-01-23 14:48:39 -08:00
Ghanan Gowripalan 1d97adaa6d Use embedded mutex pattern for stack.NIC
- Wrap NIC's fields that should only be accessed while holding the mutex in
  an anonymous struct with the embedded mutex.
- Make sure NIC's spoofing and promiscuous mode flags are only read while
  holding the NIC's mutex.
- Use the correct endpoint when sending DAD messages.
- Do not hold the NIC's lock when sending DAD messages.

This change does not introduce any behaviour changes.

Tests: Existing tests continue to pass.
PiperOrigin-RevId: 291036251
2020-01-22 14:51:53 -08:00
Kevin Krakauer b7853f688b Error marshalling the matcher.
The iptables binary is looking for libxt_.so when it should be looking
for libxt_udp.so, so it's having an issue reading the data in
xt_match_entry. I think it may be an alignment issue.

Trying to fix this is leading to me fighting with the metadata struct,
so I'm gonna go kill that.
2020-01-22 14:46:15 -08:00
Kevin Krakauer 747137c120 Address GitHub comments. 2020-01-22 10:23:44 -08:00