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

IPv6 #29

Open
wants to merge 5 commits into
base: IPv6
Choose a base branch
from
Open

IPv6 #29

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
87 changes: 48 additions & 39 deletions src/tools/perf/perftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,37 +290,48 @@ static ucx_perf_rte_t sock_rte = {

static ucs_status_t setup_sock_rte(struct perftest_context *ctx)
{
struct sockaddr_in inaddr;
struct hostent *he;
struct addrinfo hints, *res, *t;
ucs_status_t status;
int optval = 1;
int sockfd, connfd;
int ret;

sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
ucs_error("socket() failed: %m");
status = UCS_ERR_IO_ERROR;
int ret, n;
char service[8];

sprintf(service, "%d", ctx->port);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_flags = (ctx->server_addr == NULL) ? AI_PASSIVE : 0;
hints.ai_family = ctx->ai_family;
hints.ai_socktype = SOCK_STREAM;

n = getaddrinfo(ctx->server_addr, service, &hints, &res);
if (n < 0) {
ucs_error("getaddrinfo error:: [%s]", gai_strerror(n));
goto err;
}

if (ctx->server_addr == NULL) {
optval = 1;
status = ucs_socket_setopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
&optval, sizeof(optval));
if (status != UCS_OK) {
goto err_close_sockfd;
for (t = res; t; t = t->ai_next) {
sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
if (sockfd >= 0) {
status = ucs_socket_setopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
&optval, sizeof(optval));
if (status != UCS_OK) {
goto err_close_sockfd;
}

if (!bind(sockfd, t->ai_addr, t->ai_addrlen)) {
break;
}

close(sockfd);
sockfd = -1;
}
}

inaddr.sin_family = AF_INET;
inaddr.sin_port = htons(ctx->port);
inaddr.sin_addr.s_addr = INADDR_ANY;
memset(inaddr.sin_zero, 0, sizeof(inaddr.sin_zero));
ret = bind(sockfd, (struct sockaddr*)&inaddr, sizeof(inaddr));
if (ret < 0) {
ucs_error("bind() failed: %m");
status = UCS_ERR_INVALID_ADDR;
goto err_close_sockfd;
if (sockfd < 0) {
ucs_error("socket() failed: %m");
status = UCS_ERR_IO_ERROR;
goto err;
}

ret = listen(sockfd, 10);
Expand Down Expand Up @@ -375,25 +386,21 @@ static ucs_status_t setup_sock_rte(struct perftest_context *ctx)
ctx->sock_rte_group.connfd = connfd;
ctx->sock_rte_group.is_server = 1;
} else {
he = gethostbyname(ctx->server_addr);
if (he == NULL || he->h_addr_list == NULL) {
ucs_error("host %s not found: %s", ctx->server_addr,
hstrerror(h_errno));
status = UCS_ERR_INVALID_ADDR;
goto err_close_sockfd;
for (t = res; t; t = t->ai_next) {
sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
if (sockfd >= 0) {
if (!connect(sockfd, t->ai_addr, t->ai_addrlen)) {
break;
}
close(sockfd);
sockfd = -1;
}
}

inaddr.sin_family = he->h_addrtype;
inaddr.sin_port = htons(ctx->port);
ucs_assert(he->h_length == sizeof(inaddr.sin_addr));
memcpy(&inaddr.sin_addr, he->h_addr_list[0], he->h_length);
memset(inaddr.sin_zero, 0, sizeof(inaddr.sin_zero));

ret = connect(sockfd, (struct sockaddr*)&inaddr, sizeof(inaddr));
if (ret < 0) {
ucs_error("connect() failed: %m");
status = UCS_ERR_UNREACHABLE;
goto err_close_sockfd;
if (sockfd < 0) {
ucs_error("socket() failed: %m");
status = UCS_ERR_IO_ERROR;
goto err;
}

safe_send(sockfd, &ctx->params, sizeof(ctx->params), NULL, NULL);
Expand All @@ -417,6 +424,8 @@ static ucs_status_t setup_sock_rte(struct perftest_context *ctx)
ctx->params.super.rte_group = &ctx->sock_rte_group;
ctx->params.super.rte = &sock_rte;
ctx->params.super.report_arg = ctx;

freeaddrinfo(res);
return UCS_OK;

err_close_connfd:
Expand Down
1 change: 1 addition & 0 deletions src/tools/perf/perftest.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ struct perftest_context {
perftest_params_t params;
const char *server_addr;
int port;
uint8_t ai_family;
int mpi;
unsigned num_cpus;
unsigned cpus[MAX_CPUS];
Expand Down
7 changes: 6 additions & 1 deletion src/tools/perf/perftest_params.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ static void usage(const struct perftest_context *ctx, const char *program)
printf(" -R <rank> percentile rank of the percentile data in latency tests (%.1f)\n",
ctx->params.super.percentile_rank);
printf(" -p <port> TCP port to use for data exchange (%d)\n", ctx->port);
printf(" -I Use IPv6 address for TCP connection in data exchange\n");
#ifdef HAVE_MPI
printf(" -P <0|1> disable/enable MPI mode (%d)\n", ctx->mpi);
#endif
Expand Down Expand Up @@ -523,15 +524,19 @@ ucs_status_t parse_opts(struct perftest_context *ctx, int mpi_initialized,
ctx->server_addr = NULL;
ctx->num_batch_files = 0;
ctx->port = 13337;
ctx->ai_family = AF_INET;
ctx->flags = 0;
ctx->mpi = mpi_initialized;

optind = 1;
while ((c = getopt (argc, argv, "p:b:Nfvc:P:h" TEST_PARAMS_ARGS)) != -1) {
while ((c = getopt (argc, argv, "p:b:INfvc:P:h" TEST_PARAMS_ARGS)) != -1) {
switch (c) {
case 'p':
ctx->port = atoi(optarg);
break;
case 'I':
ctx->ai_family = AF_INET6;
break;
case 'b':
if (ctx->num_batch_files < MAX_BATCH_FILES) {
ctx->batch_files[ctx->num_batch_files++] = optarg;
Expand Down
81 changes: 54 additions & 27 deletions src/ucs/sys/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,59 @@ ucs_status_t ucs_netif_ioctl(const char *if_name, unsigned long request,
return status;
}

int ucs_netif_get_addr(const char *if_name, uint8_t sa_family,
struct sockaddr *saddr, int is_netmask)
{
ucs_status_t status = UCS_ERR_NO_DEVICE;
struct ifaddrs *ifa;
struct ifaddrs *ifaddrs;
const struct sockaddr_in6 *saddr6;

if(getifaddrs(&ifaddrs)) {
ucs_warn("getifaddrs error: %m");
return UCS_ERR_IO_ERROR;
}

for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if(if_name && (0 != strcmp(if_name, ifa->ifa_name))) {
continue;
}

if(ifa->ifa_addr == NULL) {
return UCS_ERR_IO_ERROR;
}

if (ifa->ifa_addr->sa_family == AF_INET6) {
saddr6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
if (IN6_IS_ADDR_LOOPBACK(&saddr6->sin6_addr) ||
IN6_IS_ADDR_LINKLOCAL(&saddr6->sin6_addr)) {
continue;
}
}

if (sa_family == AF_UNSPEC || ifa->ifa_addr->sa_family == sa_family) {
if (saddr) {
if (!is_netmask) {
memcpy(saddr, ifa->ifa_addr, sizeof(struct sockaddr_storage));
} else {
memcpy(saddr, ifa->ifa_netmask, sizeof(struct sockaddr_storage));
}
}

status = UCS_OK;
}
}

freeifaddrs(ifaddrs);
return status;
}

int ucs_netif_is_active(const char *if_name)
{
ucs_status_t status;
struct ifreq ifr;

status = ucs_netif_ioctl(if_name, SIOCGIFADDR, &ifr);
status = ucs_netif_get_addr(if_name, AF_UNSPEC, NULL, 0);
if (status != UCS_OK) {
return 0;
}
Expand Down Expand Up @@ -920,38 +967,18 @@ ucs_status_t ucs_sockaddr_get_ifname(int fd, char *ifname_str, size_t max_strlen
return status;
}

static ucs_status_t ucs_sockaddr_ifreq(const char *if_name,
unsigned long request,
struct sockaddr_in *dest)
{
ucs_status_t status;
struct ifreq ifr;

status = ucs_netif_ioctl(if_name, request, &ifr);
if (status != UCS_OK) {
return status;
}

if (ifr.ifr_addr.sa_family != AF_INET) {
ucs_error("%s address is not INET", if_name);
return UCS_ERR_INVALID_ADDR;
}

memcpy(dest, &ifr.ifr_addr, sizeof(*dest));

return UCS_OK;
}

ucs_status_t
ucs_sockaddr_get_ifaddr(const char *if_name, struct sockaddr_in *addr)
ucs_sockaddr_get_ifaddr(const char *if_name, sa_family_t af,
struct sockaddr *addr)
{
return ucs_sockaddr_ifreq(if_name, SIOCGIFADDR, addr);
return ucs_netif_get_addr(if_name, af, addr, 0);
}

ucs_status_t
ucs_sockaddr_get_ifmask(const char *if_name, struct sockaddr_in *mask)
ucs_sockaddr_get_ifmask(const char *if_name, sa_family_t af,
struct sockaddr *mask)
{
return ucs_sockaddr_ifreq(if_name, SIOCGIFNETMASK, mask);
return ucs_netif_get_addr(if_name, af, mask, 1);
}

const char *ucs_sockaddr_address_family_str(sa_family_t af)
Expand Down
8 changes: 6 additions & 2 deletions src/ucs/sys/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -540,19 +540,23 @@ ucs_sockaddr_get_ifname(int fd, char *ifname_str, size_t max_strlen);
* Copy the IP address associated with the given network interface.
*
* @param [in] if_name Interface name.
* @param [in] af Address family to check.
* @param [out] addr The IP address of the given interface.
*/
ucs_status_t
ucs_sockaddr_get_ifaddr(const char *if_name, struct sockaddr_in *addr);
ucs_sockaddr_get_ifaddr(const char *if_name, sa_family_t af,
struct sockaddr *addr);

/**
* Copy the IP subnet mask associated with the given network interface.
*
* @param [in] if_name Interface name.
* @param [in] af Address family to check.
* @param [out] addr The IP address of the given interface.
*/
ucs_status_t
ucs_sockaddr_get_ifmask(const char *if_name, struct sockaddr_in *mask);
ucs_sockaddr_get_ifmask(const char *if_name, sa_family_t af,
struct sockaddr *mask);


/**
Expand Down
4 changes: 2 additions & 2 deletions src/uct/ib/base/ib_iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ uct_ib_iface_init_roce_mask_info(uct_ib_iface_t *iface, size_t md_config_index)
uct_ib_device_t *dev = uct_ib_iface_device(iface);
uint8_t port_num = iface->config.port_num;

struct sockaddr_in mask;
struct sockaddr_storage mask;
char ndev_name[IFNAMSIZ];
ucs_status_t status;
size_t addr_size;
Expand All @@ -1214,7 +1214,7 @@ uct_ib_iface_init_roce_mask_info(uct_ib_iface_t *iface, size_t md_config_index)
goto mask_info_failed;
}

status = ucs_sockaddr_get_ifmask(ndev_name, &mask);
status = ucs_sockaddr_get_ifmask(ndev_name, AF_UNSPEC, (struct sockaddr*)&mask);
if (status != UCS_OK) {
goto mask_info_failed;
}
Expand Down
Loading