2019-12-02 13:37:09 +00:00
|
|
|
// Copyright 2019 The gVisor Authors.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#ifndef THIRD_PARTY_GOLANG_GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_
|
|
|
|
#define THIRD_PARTY_GOLANG_GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_
|
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2019-12-02 13:37:09 +00:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "test/syscalls/linux/socket_test_util.h"
|
2020-06-29 22:44:46 +00:00
|
|
|
#include "test/util/file_descriptor.h"
|
|
|
|
#include "test/util/posix_error.h"
|
2019-12-02 13:37:09 +00:00
|
|
|
|
|
|
|
namespace gvisor {
|
|
|
|
namespace testing {
|
|
|
|
|
|
|
|
// The initial port to be be used on gvisor.
|
|
|
|
constexpr int TestPort = 40000;
|
|
|
|
|
|
|
|
// Fixture for tests parameterized by the address family to use (AF_INET and
|
|
|
|
// AF_INET6) when creating sockets.
|
|
|
|
class UdpSocketTest
|
|
|
|
: public ::testing::TestWithParam<gvisor::testing::AddressFamily> {
|
|
|
|
protected:
|
|
|
|
// Creates two sockets that will be used by test cases.
|
|
|
|
void SetUp() override;
|
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Binds the socket bind_ to the loopback and updates bind_addr_.
|
|
|
|
PosixError BindLoopback();
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Binds the socket bind_ to Any and updates bind_addr_.
|
|
|
|
PosixError BindAny();
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Binds given socket to address addr and updates.
|
|
|
|
PosixError BindSocket(int socket, struct sockaddr* addr);
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Return initialized Any address to port 0.
|
|
|
|
struct sockaddr_storage InetAnyAddr();
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Return initialized Loopback address to port 0.
|
|
|
|
struct sockaddr_storage InetLoopbackAddr();
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Disconnects socket sockfd.
|
|
|
|
void Disconnect(int sockfd);
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Get family for the test.
|
|
|
|
int GetFamily();
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Socket used by Bind methods
|
|
|
|
FileDescriptor bind_;
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Second socket used for tests.
|
|
|
|
FileDescriptor sock_;
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Address for bind_ socket.
|
|
|
|
struct sockaddr* bind_addr_;
|
2019-12-02 13:37:09 +00:00
|
|
|
|
2020-06-29 22:44:46 +00:00
|
|
|
// Initialized to the length based on GetFamily().
|
|
|
|
socklen_t addrlen_;
|
|
|
|
|
|
|
|
// Storage for bind_addr_.
|
|
|
|
struct sockaddr_storage bind_addr_storage_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Helper to initialize addrlen_ for the test case.
|
|
|
|
socklen_t GetAddrLength();
|
|
|
|
};
|
2019-12-02 13:37:09 +00:00
|
|
|
} // namespace testing
|
|
|
|
} // namespace gvisor
|
|
|
|
|
|
|
|
#endif // THIRD_PARTY_GOLANG_GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_
|