Fix broken hdrincl test

Fixes #3159.

PiperOrigin-RevId: 379814096
This commit is contained in:
Kevin Krakauer
2021-06-16 14:43:10 -07:00
committed by gVisor bot
parent 63b4f6e296
commit 34152da7e5
2 changed files with 2 additions and 23 deletions
-20
View File
@@ -286,26 +286,6 @@ func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, tcp
return nil, nil, nil, &tcpip.ErrBadBuffer{}
}
// If this is an unassociated socket and callee provided a nonzero
// destination address, route using that address.
if e.ops.GetHeaderIncluded() {
ip := header.IPv4(payloadBytes)
if !ip.IsValid(len(payloadBytes)) {
return nil, nil, nil, &tcpip.ErrInvalidOptionValue{}
}
dstAddr := ip.DestinationAddress()
// Update dstAddr with the address in the IP header, unless
// opts.To is set (e.g. if sendto specifies a specific
// address).
if dstAddr != tcpip.Address([]byte{0, 0, 0, 0}) && opts.To == nil {
opts.To = &tcpip.FullAddress{
NIC: 0, // NIC is unset.
Addr: dstAddr, // The address from the payload.
Port: 0, // There are no ports here.
}
}
}
// Did the user caller provide a destination? If not, use the connected
// destination.
if opts.To == nil {
+2 -3
View File
@@ -177,11 +177,10 @@ TEST_F(RawHDRINCL, ConnectToLoopback) {
SyscallSucceeds());
}
// FIXME(gvisor.dev/issue/3159): Test currently flaky.
TEST_F(RawHDRINCL, DISABLED_SendWithoutConnectSucceeds) {
TEST_F(RawHDRINCL, SendWithoutConnectFails) {
struct iphdr hdr = LoopbackHeader();
ASSERT_THAT(send(socket_, &hdr, sizeof(hdr), 0),
SyscallSucceedsWithValue(sizeof(hdr)));
SyscallFailsWithErrno(EDESTADDRREQ));
}
// HDRINCL implies write-only. Verify that we can't read a packet sent to