Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADBDEV-6534: Fix IPv6 checking in cdbsenddummypacket unit test #1102

Open
wants to merge 1 commit into
base: adb-7.2.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/backend/cdb/motion/test/cdbsenddummypacket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,21 +296,46 @@ test_send_dummy_packet_ipv6_to_ipv6_wildcard(void **state)
wait_for_receiver(false);
}


/*
* Test if IPv6 is supported.
*
* Sometimes even if IPv6 socket is successfully created it is not possible
* to bind an address to it (if IPv6 is disabled).
*
* Note: this is not a general solution and should only be used for this
* specific test. It is theoretically possible that loopback IPv6 address
* is available but real IPv6 addresses aren't. However, checking for that
* would be a lot more complicated
*/
static bool is_ipv6_supported(void) {
int sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
if (sockfd < 0 && errno == EAFNOSUPPORT)
return false;

struct sockaddr_in6 socket_struct;
socket_struct.sin6_family = AF_INET6;
socket_struct.sin6_addr = in6addr_loopback;
socket_struct.sin6_port = 0;
socket_struct.sin6_scope_id = 0;
int res = bind(sockfd, (struct sockaddr*) &socket_struct, sizeof(socket_struct));
if (res < 0 && errno == EADDRNOTAVAIL)
return false;

closesocket(sockfd);
return true;
}

int
main(int argc, char* argv[])
{
cmockery_parse_arguments(argc, argv);

int is_ipv6_supported = true;
int sockfd = socket(AF_INET6, SOCK_DGRAM, 0);
if (sockfd < 0 && errno == EAFNOSUPPORT)
is_ipv6_supported = false;

log_min_messages = DEBUG1;

start_receiver();

if (is_ipv6_supported)
if (is_ipv6_supported())
{
const UnitTest tests[] = {
unit_test(test_send_dummy_packet_ipv4_to_ipv4),
Expand Down
Loading