[openib-general] Usermode cm_id definition

Tom Tucker tom at opengridcomputing.com
Fri Oct 13 08:36:01 PDT 2006


Sean:

The definition of rdma_cm_id in usermode defines the src and dst addresses
as sockaddr_in6. I understand that the reason you did this is because this
guarantees that enough space is allocated. The problem is that the user will
assume that a structure defined as sockaddr_in6 is in fact an in6 address
and as such that if it is a ipv4 compatibility address that the ipv4 address
is in sin6_addr.s6_addr32[3]. In our case, however, you're really treating
the address as a sockaddr, that is, a generic address structure that needs
to be cast based on the sa_family.

There is a structure, sockaddr_storage, that is guaranteed to be big enough.
The screwed up thing about this (IMO) is that the family field is defined to
be ss_family, NOT sa_family, so the user can't treat it like a generic
sockaddr. This is not particularly clever in my opinion. So we're left with

 if (sin6.sin6_family == AF_INET4)
    sin4 = (struct sockaddr_in*)&sin6;  /* yuck */

 or if we change it to struct sockaddr_storage ss;

 if (ss.ss_family == AF_INET4)          /* erf */
    sin4 = (struct sockaddr_in*)&ss;
 else if (ss.ss_family == AF_INET6)
    sin6 = (struct sockaddr_in6*)ss;

The only "correct" way would be to declare a sockaddr structure * to a
struct socket_storage allocated buffer and waste 4 bytes in the rdma_cm_id
structure.

Anyway, it's buggin' me...Maybe I'm being anal...

Thoughts?

Tom






More information about the general mailing list