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 2 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
5 changes: 3 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,7 @@ setupUDPListeningSocket(int *listenerSocketFd, uint16 *listenerPort, int *txFami
uint32 socketSendBufferSize;
uint32 socketRecvBufferSize;

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 +1222,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
47 changes: 42 additions & 5 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,6 +273,36 @@ test_send_dummy_packet_ipv6_to_ipv4(void **state)
}


static void
test_send_dummy_packet_ipv4_to_ipv4_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);
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_ipv6_wildcard(void **state)
silent-observer marked this conversation as resolved.
Show resolved Hide resolved
{
Expand All @@ -277,7 +311,8 @@ test_send_dummy_packet_ipv6_to_ipv6_wildcard(void **state)
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);
Expand All @@ -288,10 +323,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 All @@ -317,6 +353,7 @@ 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_ipv4_to_ipv4_wildcard),
silent-observer marked this conversation as resolved.
Show resolved Hide resolved
unit_test(test_send_dummy_packet_ipv6_to_ipv6_wildcard),
};
return run_tests(tests);
Expand Down