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

fix wildcard interconnect address type #936

Open
wants to merge 4 commits into
base: adb-7.2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions src/backend/cdb/motion/ic_udpifc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ setupUDPListeningSocket(int *listenerSocketFd, uint16 *listenerPort, int *txFami
struct addrinfo *addrs = NULL;
struct addrinfo *addr;
struct addrinfo hints;
char service[32];
whitehawk marked this conversation as resolved.
Show resolved Hide resolved
int ret;
int ic_socket = PGINVALID_SOCKET;
struct sockaddr_storage ic_socket_addr;
Expand All @@ -1185,6 +1186,11 @@ setupUDPListeningSocket(int *listenerSocketFd, uint16 *listenerPort, int *txFami
uint32 socketSendBufferSize;
uint32 socketRecvBufferSize;

/*
* we let the system pick the UDP port here so we don't have to manage
* port resources ourselves. So set the port to 0 (any port)
*/
snprintf(service, 32, "%d", 0);
whitehawk marked this conversation as resolved.
Show resolved Hide resolved
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
Expand Down Expand Up @@ -1220,8 +1226,7 @@ setupUDPListeningSocket(int *listenerSocketFd, uint16 *listenerPort, int *txFami
* Restrict what IP address we will listen on to just the one that was
* used to create this QE session.
*/
Assert(interconnect_address && strlen(interconnect_address) > 0);
ret = pg_getaddrinfo_all(interconnect_address, NULL, &hints, &addrs);
ret = pg_getaddrinfo_all(interconnect_address, service, &hints, &addrs);
if (ret || !addrs)
{
ereport(LOG,
Expand Down
59 changes: 52 additions & 7 deletions src/backend/cdb/motion/test/cdbsenddummypacket_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ test_send_dummy_packet_ipv4_to_ipv4(void **state)
int txFamily;

interconnect_address = "0.0.0.0";
Gp_interconnect_address_type = INTERCONNECT_ADDRESS_TYPE_UNICAST;
setupUDPListeningSocket(&listenerSocketFd, &listenerPort, &txFamily, &udp_dummy_packet_sockaddr);

Gp_listener_port = (listenerPort << 16);
Expand Down Expand Up @@ -195,6 +196,7 @@ test_send_dummy_packet_ipv4_to_ipv6_should_fail(void **state)
int txFamily;

interconnect_address = "::";
Gp_interconnect_address_type = INTERCONNECT_ADDRESS_TYPE_UNICAST;
setupUDPListeningSocket(&listenerSocketFd, &listenerPort, &txFamily, &udp_dummy_packet_sockaddr);

Gp_listener_port = (listenerPort << 16);
Expand Down Expand Up @@ -222,6 +224,7 @@ test_send_dummy_packet_ipv6_to_ipv6(void **state)
int txFamily;

interconnect_address = "::1";
Gp_interconnect_address_type = INTERCONNECT_ADDRESS_TYPE_UNICAST;
setupUDPListeningSocket(&listenerSocketFd, &listenerPort, &txFamily, &udp_dummy_packet_sockaddr);

Gp_listener_port = (listenerPort << 16);
Expand Down Expand Up @@ -249,6 +252,7 @@ test_send_dummy_packet_ipv6_to_ipv4(void **state)
int txFamily;

interconnect_address = "0.0.0.0";
Gp_interconnect_address_type = INTERCONNECT_ADDRESS_TYPE_UNICAST;
setupUDPListeningSocket(&listenerSocketFd, &listenerPort, &txFamily, &udp_dummy_packet_sockaddr);

Gp_listener_port = (listenerPort << 16);
Expand All @@ -269,15 +273,53 @@ test_send_dummy_packet_ipv6_to_ipv4(void **state)
}


/*
* These tests check possibility to send dummy packets in the wildcard mode
* Actual Linux distributions return addresses for both families on dual-stack
* machines when the exact family isn't requested, but the IPv6 address follows
* the IPv4 one. GPDB 7 uses first availble address in the current
* implementaton in opposite to GPDB 6 that reorders list in favor of IPv6
*/
static void
test_send_dummy_packet_ipv6_to_ipv6_wildcard(void **state)
test_send_dummy_packet_ipv4_to_wildcard(void **state)
{
break_loop = false;
int listenerSocketFd;
uint16 listenerPort;
int txFamily;

interconnect_address = "::";
interconnect_address = NULL;
Gp_interconnect_address_type = INTERCONNECT_ADDRESS_TYPE_WILDCARD;
setupUDPListeningSocket(&listenerSocketFd, &listenerPort, &txFamily, &udp_dummy_packet_sockaddr);

Gp_listener_port = (listenerPort << 16);
UDP_listenerFd = listenerSocketFd;

ICSenderSocket = create_sender_socket(AF_INET);
ICSenderFamily = AF_INET;

SendDummyPacket();

const struct sockaddr_in *in = (const struct sockaddr_in *) &udp_dummy_packet_sockaddr;
assert_true(txFamily == AF_INET);
assert_true(in->sin_family == AF_INET);
assert_true(listenerPort == ntohs(in->sin_port));
assert_true(strcmp("0.0.0.0", inet_ntoa(in->sin_addr)) == 0);

wait_for_receiver(false);
}


static void
test_send_dummy_packet_ipv6_to_wildcard(void **state)
{
break_loop = false;
int listenerSocketFd;
uint16 listenerPort;
int txFamily;

interconnect_address = NULL;
Gp_interconnect_address_type = INTERCONNECT_ADDRESS_TYPE_WILDCARD;
setupUDPListeningSocket(&listenerSocketFd, &listenerPort, &txFamily, &udp_dummy_packet_sockaddr);

Gp_listener_port = (listenerPort << 16);
Expand All @@ -288,10 +330,11 @@ test_send_dummy_packet_ipv6_to_ipv6_wildcard(void **state)

SendDummyPacket();

const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) &udp_dummy_packet_sockaddr;
assert_true(txFamily == AF_INET6);
assert_true(in6->sin6_family == AF_INET6);
assert_true(listenerPort == ntohs(in6->sin6_port));
const struct sockaddr_in *in = (const struct sockaddr_in *) &udp_dummy_packet_sockaddr;
assert_true(txFamily == AF_INET);
assert_true(in->sin_family == AF_INET);
assert_true(listenerPort == ntohs(in->sin_port));
assert_true(strcmp("0.0.0.0", inet_ntoa(in->sin_addr)) == 0);

wait_for_receiver(false);
}
Expand Down Expand Up @@ -338,7 +381,8 @@ main(int argc, char* argv[])
unit_test(test_send_dummy_packet_ipv4_to_ipv6_should_fail),
unit_test(test_send_dummy_packet_ipv6_to_ipv6),
unit_test(test_send_dummy_packet_ipv6_to_ipv4),
unit_test(test_send_dummy_packet_ipv6_to_ipv6_wildcard),
unit_test(test_send_dummy_packet_ipv4_to_wildcard),
unit_test(test_send_dummy_packet_ipv6_to_wildcard),
};
return run_tests(tests);
}
Expand All @@ -347,6 +391,7 @@ main(int argc, char* argv[])
printf("WARNING: IPv6 is not supported, skipping unittest\n");
const UnitTest tests[] = {
unit_test(test_send_dummy_packet_ipv4_to_ipv4),
unit_test(test_send_dummy_packet_ipv4_to_wildcard),
};
return run_tests(tests);
}
Expand Down
Loading