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

prov/rxm: Enable IPv6 support in RxM #10

Closed
wants to merge 3 commits into from
Closed
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
7 changes: 7 additions & 0 deletions include/ofi_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ static inline int ofi_sendall_socket(SOCKET sock, const void *buf, size_t len)
#define AF_IB 27
#endif

union ofi_sock_ip {
struct sockaddr sa;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
uint8_t align[32];
};

int ofi_addr_cmp(const struct fi_provider *prov, const struct sockaddr *sa1,
const struct sockaddr *sa2);
int ofi_getifaddrs(struct ifaddrs **ifap);
Expand Down
2 changes: 1 addition & 1 deletion prov/rxm/src/rxm.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct rxm_ep_wire_proto {
};

struct rxm_cm_data {
struct sockaddr name;
union ofi_sock_ip name;
uint64_t conn_id;
struct rxm_ep_wire_proto proto;
};
Expand Down
3 changes: 1 addition & 2 deletions prov/rxm/src/rxm_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ static void *rxm_conn_event_handler(void *arg)
}

static int rxm_prepare_cm_data(struct fid_pep *pep, struct util_cmap_handle *handle,
struct rxm_cm_data *cm_data)
struct rxm_cm_data *cm_data)
{
size_t cm_data_size = 0;
size_t name_size = sizeof(cm_data->name);
Expand All @@ -449,7 +449,6 @@ static int rxm_prepare_cm_data(struct fid_pep *pep, struct util_cmap_handle *han
FI_WARN(&rxm_prov, FI_LOG_EP_CTRL, "MSG EP CM data size too small\n");
return -FI_EOTHER;
}

ret = fi_getname(&pep->fid, &cm_data->name, &name_size);
if (ret) {
FI_WARN(&rxm_prov, FI_LOG_EP_CTRL, "Unable to get msg pep name\n");
Expand Down
30 changes: 15 additions & 15 deletions prov/sockets/include/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ enum {
#define SOCK_MAJOR_VERSION 2
#define SOCK_MINOR_VERSION 0

#define SOCK_WIRE_PROTO_VERSION (1)
#define SOCK_WIRE_PROTO_VERSION (2)

struct sock_service_entry {
int service;
Expand All @@ -200,7 +200,7 @@ struct sock_conn {
int sock_fd;
int connected;
int address_published;
struct sockaddr_in addr;
union ofi_sock_ip addr;
struct sock_pe_entry *rx_pe_entry;
struct sock_pe_entry *tx_pe_entry;
struct sock_ep_attr *ep_attr;
Expand Down Expand Up @@ -349,7 +349,7 @@ struct sock_mr {
};

struct sock_av_addr {
struct sockaddr_storage addr;
union ofi_sock_ip addr;
uint8_t valid;
uint8_t reserved[7];
};
Expand Down Expand Up @@ -543,7 +543,6 @@ struct sock_ep_cm_entry {
struct sock_conn_handle {
int sock;
int do_listen;
char service[NI_MAXSERV];
};

struct sock_ep_attr {
Expand Down Expand Up @@ -574,8 +573,8 @@ struct sock_ep_attr {
struct fi_ep_attr ep_attr;

enum fi_ep_type ep_type;
struct sockaddr_in *src_addr;
struct sockaddr_in *dest_addr;
union ofi_sock_ip *src_addr;
union ofi_sock_ip *dest_addr;
uint16_t msg_src_port;
uint16_t msg_dest_port;

Expand Down Expand Up @@ -604,7 +603,7 @@ struct sock_pep {

struct sock_ep_cm_head cm_head;
struct sock_pep_cm_entry cm;
struct sockaddr_in src_addr;
union ofi_sock_ip src_addr;
struct fi_info info;
struct sock_eq *eq;
int name_set;
Expand Down Expand Up @@ -924,7 +923,7 @@ struct sock_conn_hdr {

struct sock_conn_req {
struct sock_conn_hdr hdr;
struct sockaddr_in src_addr;
union ofi_sock_ip src_addr;
uint64_t caps;
char cm_data[0];
};
Expand Down Expand Up @@ -956,14 +955,14 @@ struct sock_conn_req_handle {
struct sock_pep *pep;
struct sock_ep *ep;
size_t paramlen;
struct sockaddr_in dest_addr;
union ofi_sock_ip dest_addr;
struct dlist_entry entry;
char cm_data[SOCK_EP_MAX_CM_DATA_SZ];
};

struct sock_host_list_entry {
char ipstr[INET6_ADDRSTRLEN];
struct sockaddr_in ipaddr;
union ofi_sock_ip ipaddr;
struct slist_entry entry;
};

Expand Down Expand Up @@ -1018,9 +1017,10 @@ int sock_dgram_verify_ep_attr(const struct fi_ep_attr *ep_attr,
int sock_msg_verify_ep_attr(const struct fi_ep_attr *ep_attr,
const struct fi_tx_attr *tx_attr,
const struct fi_rx_attr *rx_attr);
int sock_get_src_addr(struct sockaddr_in *dest_addr,
struct sockaddr_in *src_addr);
int sock_get_src_addr_from_hostname(struct sockaddr_in *src_addr, const char *service);
int sock_get_src_addr(union ofi_sock_ip *dest_addr,
union ofi_sock_ip *src_addr);
int sock_get_src_addr_from_hostname(union ofi_sock_ip *src_addr,
const char *service, uint16_t sa_family);

struct fi_info *sock_fi_info(uint32_t version, enum fi_ep_type ep_type,
const struct fi_info *hints, void *src_addr,
Expand Down Expand Up @@ -1153,10 +1153,10 @@ int sock_wait_close(fid_t fid);
int sock_av_open(struct fid_domain *domain, struct fi_av_attr *attr,
struct fid_av **av, void *context);
int sock_av_compare_addr(struct sock_av *av, fi_addr_t addr1, fi_addr_t addr2);
int sock_av_get_addr_index(struct sock_av *av, struct sockaddr_in *addr);
int sock_av_get_addr_index(struct sock_av *av, union ofi_sock_ip *addr);

struct sock_conn *sock_ep_lookup_conn(struct sock_ep_attr *attr, fi_addr_t index,
struct sockaddr_in *addr);
union ofi_sock_ip *addr);
int sock_ep_get_conn(struct sock_ep_attr *ep_attr, struct sock_tx_ctx *tx_ctx,
fi_addr_t index, struct sock_conn **pconn);
void sock_ep_remove_conn(struct sock_ep_attr *ep_attr, struct sock_conn *conn);
Expand Down
52 changes: 29 additions & 23 deletions prov/sockets/src/sock_av.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
count * sizeof(struct sock_av_addr))
#define SOCK_IS_SHARED_AV(av_name) ((av_name) ? 1 : 0)

int sock_av_get_addr_index(struct sock_av *av, struct sockaddr_in *addr)
int sock_av_get_addr_index(struct sock_av *av, union ofi_sock_ip *addr)
{
int i;
struct sock_av_addr *av_addr;
Expand All @@ -73,8 +73,8 @@ int sock_av_get_addr_index(struct sock_av *av, struct sockaddr_in *addr)
if (!av_addr->valid)
continue;

if (ofi_equals_sockaddr((struct sockaddr *) addr,
(struct sockaddr *) &av_addr->addr))
if (ofi_equals_sockaddr((const struct sockaddr *) addr,
(const struct sockaddr *) &av_addr->addr))
return i;
}
SOCK_LOG_DBG("failed to get index in AV\n");
Expand All @@ -99,8 +99,8 @@ int sock_av_compare_addr(struct sock_av *av,
av_addr1 = &av->table[index1];
av_addr2 = &av->table[index2];

return memcmp(&av_addr1->addr, &av_addr2->addr,
sizeof(struct sockaddr_in));
/* Return 0 if the addresses match */
return !ofi_equals_sockaddr(&av_addr1->addr.sa, &av_addr2->addr.sa);
}

static inline void sock_av_report_success(struct sock_av *av, void *context,
Expand Down Expand Up @@ -128,9 +128,9 @@ static inline void sock_av_report_error(struct sock_av *av,
context, index, err, -err, NULL, 0);
}

static int sock_av_is_valid_address(struct sockaddr_in *addr)
static int sock_av_is_valid_address(const struct sockaddr *addr)
{
return addr->sin_family == AF_INET ? 1 : 0;
return ofi_sizeofaddr(addr);
}

static void sock_update_av_table(struct sock_av *_av, size_t count)
Expand Down Expand Up @@ -181,13 +181,13 @@ static int sock_av_get_next_index(struct sock_av *av)
return -1;
}

static int sock_check_table_in(struct sock_av *_av, struct sockaddr_in *addr,
static int sock_check_table_in(struct sock_av *_av, const struct sockaddr *addr,
fi_addr_t *fi_addr, int count, uint64_t flags,
void *context)
{
int i, ret = 0;
uint64_t j;
char sa_ip[INET_ADDRSTRLEN];
char sa_ip[INET6_ADDRSTRLEN];
struct sock_av_addr *av_addr;
int index;

Expand All @@ -208,7 +208,7 @@ static int sock_check_table_in(struct sock_av *_av, struct sockaddr_in *addr,

av_addr = &_av->table[j];
if (memcmp(&av_addr->addr, &addr[i],
sizeof(struct sockaddr_in)) == 0) {
ofi_sizeofaddr(&addr[i])) == 0) {
SOCK_LOG_DBG("Found addr in shared av\n");
if (fi_addr)
fi_addr[i] = (fi_addr_t)j;
Expand Down Expand Up @@ -243,12 +243,13 @@ static int sock_check_table_in(struct sock_av *_av, struct sockaddr_in *addr,
}

av_addr = &_av->table[index];
inet_ntop(addr[i].sin_family, &addr[i].sin_addr, sa_ip, INET_ADDRSTRLEN);
inet_ntop(addr[i].sa_family, ofi_get_ipaddr(&addr[i]),
sa_ip, sizeof sa_ip);
SOCK_LOG_DBG("AV-INSERT: dst_addr family: %d, IP %s, port: %d\n",
((struct sockaddr_in *)&addr[i])->sin_family,
sa_ip, ntohs(((struct sockaddr_in *)&addr[i])->sin_port));
(&addr[i])->sa_family, sa_ip,
ofi_addr_get_port(&addr[i]));

memcpy(&av_addr->addr, &addr[i], sizeof(struct sockaddr_in));
memcpy(&av_addr->addr, &addr[i], ofi_sizeofaddr(&addr[i]));
if (fi_addr)
fi_addr[i] = (fi_addr_t)index;

Expand All @@ -264,7 +265,7 @@ static int sock_av_insert(struct fid_av *av, const void *addr, size_t count,
{
struct sock_av *_av;
_av = container_of(av, struct sock_av, av_fid);
return sock_check_table_in(_av, (struct sockaddr_in *)addr,
return sock_check_table_in(_av, (const struct sockaddr *) addr,
fi_addr, count, flags, context);
}

Expand Down Expand Up @@ -299,6 +300,7 @@ static int _sock_av_insertsvc(struct fid_av *av, const char *node,

_av = container_of(av, struct sock_av, av_fid);
memset(&sock_hints, 0, sizeof(struct addrinfo));
/* Map all services to IPv4 addresses -- for compatibility */
sock_hints.ai_family = AF_INET;
sock_hints.ai_socktype = SOCK_STREAM;

Expand All @@ -311,7 +313,7 @@ static int _sock_av_insertsvc(struct fid_av *av, const char *node,
return -ret;
}

ret = sock_check_table_in(_av, (struct sockaddr_in *)result->ai_addr,
ret = sock_check_table_in(_av, result->ai_addr,
fi_addr, 1, flags, context);
freeaddrinfo(result);
return ret;
Expand Down Expand Up @@ -427,15 +429,16 @@ static int sock_av_remove(struct fid_av *av, fi_addr_t *fi_addr, size_t count,
static const char *sock_av_straddr(struct fid_av *av, const void *addr,
char *buf, size_t *len)
{
const struct sockaddr_in *sin;
char straddr[24];
char ipaddr[24];
const struct sockaddr *sa = addr;
char straddr[OFI_ADDRSTRLEN];
char ipaddr[INET6_ADDRSTRLEN];
int size;

sin = addr;
inet_ntop(sin->sin_family, (void*)&sin->sin_addr, ipaddr, sizeof(ipaddr));
if (!inet_ntop(sa->sa_family, ofi_get_ipaddr(sa), ipaddr, sizeof(ipaddr)))
return NULL;

size = snprintf(straddr, sizeof(straddr), "%s:%d",
ipaddr, ntohs(sin->sin_port));
ipaddr, ofi_addr_get_port(sa));
snprintf(buf, *len, "%s", straddr);
*len = size + 1;
return buf;
Expand Down Expand Up @@ -612,8 +615,11 @@ int sock_av_open(struct fid_domain *domain, struct fi_av_attr *attr,
case FI_SOCKADDR_IN:
_av->addrlen = sizeof(struct sockaddr_in);
break;
case FI_SOCKADDR_IN6:
_av->addrlen = sizeof(struct sockaddr_in6);
break;
default:
SOCK_LOG_ERROR("Invalid address format: only IPv4 supported\n");
SOCK_LOG_ERROR("Invalid address format: only IP supported\n");
ret = -FI_EINVAL;
goto err2;
}
Expand Down
10 changes: 4 additions & 6 deletions prov/sockets/src/sock_comm.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ static ssize_t sock_comm_send_socket(struct sock_conn *conn,
ret = 0;
} else if (ofi_sockerr() == EPIPE) {
conn->connected = 0;
SOCK_LOG_DBG("Disconnected: %s:%d\n",
inet_ntoa(conn->addr.sin_addr),
ntohs(conn->addr.sin_port));
SOCK_LOG_DBG("Disconnected port: %d\n",
ofi_addr_get_port(&conn->addr.sa));
} else {
SOCK_LOG_DBG("write error: %s\n",
strerror(ofi_sockerr()));
Expand Down Expand Up @@ -136,9 +135,8 @@ static ssize_t sock_comm_recv_socket(struct sock_conn *conn,
ret = ofi_recv_socket(conn->sock_fd, buf, len, 0);
if (ret == 0) {
conn->connected = 0;
SOCK_LOG_DBG("Disconnected: %s:%d\n",
inet_ntoa(conn->addr.sin_addr),
ntohs(conn->addr.sin_port));
SOCK_LOG_DBG("Disconnected: port %d\n",
ofi_addr_get_port(&conn->addr.sa));
return ret;
}

Expand Down
Loading