@@ -669,7 +669,7 @@ static int ethernet_client_connect(struct perftest_comm *comm)
669669
670670 int sockfd = -1 ;
671671 memset (& hints , 0 , sizeof hints );
672- hints .ai_family = AF_INET ;
672+ hints .ai_family = comm -> rdma_params -> ai_family ;
673673 hints .ai_socktype = SOCK_STREAM ;
674674
675675 if (comm -> rdma_params -> has_source_ip ) {
@@ -726,7 +726,7 @@ static int ethernet_server_connect(struct perftest_comm *comm)
726726
727727 memset (& hints , 0 , sizeof hints );
728728 hints .ai_flags = AI_PASSIVE ;
729- hints .ai_family = AF_INET ;
729+ hints .ai_family = comm -> rdma_params -> ai_family ;
730730 hints .ai_socktype = SOCK_STREAM ;
731731
732732 if (check_add_port (& service ,comm -> rdma_params -> port ,src_ip ,& hints ,& res ))
@@ -736,6 +736,9 @@ static int ethernet_server_connect(struct perftest_comm *comm)
736736 }
737737
738738 for (t = res ; t ; t = t -> ai_next ) {
739+ if (t -> ai_family != comm -> rdma_params -> ai_family )
740+ continue ;
741+
739742 sockfd = socket (t -> ai_family , t -> ai_socktype , t -> ai_protocol );
740743
741744 if (sockfd >= 0 ) {
@@ -906,29 +909,30 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
906909{
907910 char * service ;
908911 int temp ,num_of_retry = NUM_OF_RETRIES ;
909- struct sockaddr_in sin , source_sin ;
912+ struct sockaddr_storage source_sin ;
913+ struct sockaddr * sin ;
910914 struct sockaddr * source_ptr = NULL ;
911915 struct addrinfo * res ;
912916 struct rdma_cm_event * event ;
913917 struct rdma_conn_param conn_param ;
914918 struct addrinfo hints ;
915919
916920 memset (& hints , 0 , sizeof hints );
917- hints .ai_family = AF_INET ;
921+ hints .ai_family = user_param -> ai_family ;
918922 hints .ai_socktype = SOCK_STREAM ;
919923
920924 if (check_add_port (& service ,user_param -> port ,user_param -> servername ,& hints ,& res )) {
921925 fprintf (stderr , "Problem in resolving basic address and port\n" );
922926 return FAILURE ;
923927 }
924928
925- if (res -> ai_family != PF_INET ) {
929+ if (res -> ai_family != user_param -> ai_family ) {
926930 freeaddrinfo (res );
927931 return FAILURE ;
928932 }
929- memcpy ( & sin , res -> ai_addr , sizeof ( sin ));
930- freeaddrinfo ( res ) ;
931- sin . sin_port = htons ( (unsigned short )user_param -> port );
933+
934+ sin = res -> ai_addr ;
935+ sockaddr_set_port ( sin , (unsigned short )user_param -> port );
932936
933937 if (user_param -> has_source_ip ) {
934938 if (check_add_port (& service , 0x0 , user_param -> source_ip , & hints , & res ))
@@ -940,7 +944,6 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
940944 //coverity[deref_after_free]
941945 memcpy (& source_sin , res -> ai_addr , sizeof (source_sin ));
942946 source_ptr = (struct sockaddr * )& source_sin ;
943- freeaddrinfo (res );
944947 }
945948 while (1 )
946949 {
@@ -950,12 +953,14 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
950953 return FAILURE ;
951954 }
952955
953- if (rdma_resolve_addr (ctx -> cm_id , source_ptr , (struct sockaddr * )& sin , 2000 )) {
956+ if (rdma_resolve_addr (ctx -> cm_id , source_ptr , sin , 2000 )) {
957+ freeaddrinfo (res );
954958 fprintf (stderr , "rdma_resolve_addr failed\n" );
955959 return FAILURE ;
956960 }
957961
958962 if (rdma_get_cm_event (ctx -> cm_channel ,& event )) {
963+ freeaddrinfo (res );
959964 fprintf (stderr , "rdma_get_cm_events failed\n" );
960965 return FAILURE ;
961966 }
@@ -969,6 +974,7 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
969974
970975 if (event -> event != RDMA_CM_EVENT_ADDR_RESOLVED ) {
971976 fprintf (stderr , "unexpected CM event %d\n" ,event -> event );
977+ freeaddrinfo (res );
972978 rdma_ack_cm_event (event );
973979 return FAILURE ;
974980 }
@@ -977,6 +983,8 @@ int rdma_client_connect(struct pingpong_context *ctx,struct perftest_parameters
977983 break ;
978984 }
979985
986+ freeaddrinfo (res );
987+
980988 if (user_param -> tos != DEF_TOS ) {
981989
982990 if (rdma_set_option (ctx -> cm_id ,RDMA_OPTION_ID ,RDMA_OPTION_ID_TOS ,& user_param -> tos ,sizeof (uint8_t ))) {
@@ -1124,35 +1132,36 @@ int rdma_server_connect(struct pingpong_context *ctx,
11241132 struct rdma_conn_param conn_param ;
11251133 struct addrinfo hints ;
11261134 char * service ;
1127- struct sockaddr_in sin ;
1135+ struct sockaddr * sin ;
11281136 char * src_ip = user_param -> has_source_ip ? user_param -> source_ip : NULL ;
11291137
11301138 memset (& hints , 0 , sizeof hints );
11311139 hints .ai_flags = AI_PASSIVE ;
1132- hints .ai_family = AF_INET ;
1140+ hints .ai_family = user_param -> ai_family ;
11331141 hints .ai_socktype = SOCK_STREAM ;
11341142
1135- memset (& sin , 0x0 , sizeof (sin ));
1136-
11371143 if (check_add_port (& service ,user_param -> port ,src_ip ,& hints ,& res ))
11381144 {
11391145 fprintf (stderr , "Problem in resolving basic address and port\n" );
11401146 return FAILURE ;
11411147 }
11421148
1143- if (res -> ai_family != PF_INET ) {
1149+ if (res -> ai_family != user_param -> ai_family ) {
11441150 freeaddrinfo (res );
11451151 return FAILURE ;
11461152 }
1147- memcpy (& sin , res -> ai_addr , sizeof (sin ));
1148- sin .sin_port = htons ((unsigned short )user_param -> port );
1149- freeaddrinfo (res );
11501153
1151- if (rdma_bind_addr (ctx -> cm_id_control ,(struct sockaddr * )& sin )) {
1154+ sin = res -> ai_addr ;
1155+ sockaddr_set_port (sin , (unsigned short )user_param -> port );
1156+
1157+ if (rdma_bind_addr (ctx -> cm_id_control , sin )) {
1158+ freeaddrinfo (res );
11521159 fprintf (stderr ," rdma_bind_addr failed\n" );
11531160 return 1 ;
11541161 }
11551162
1163+ freeaddrinfo (res );
1164+
11561165 if (rdma_listen (ctx -> cm_id_control , user_param -> num_of_qps )) {
11571166 fprintf (stderr , "rdma_listen failed\n" );
11581167 return 1 ;
@@ -1243,6 +1252,7 @@ int create_comm_struct(struct perftest_comm *comm,
12431252 memset (comm -> rdma_params , 0 , sizeof (struct perftest_parameters ));
12441253
12451254 comm -> rdma_params -> port = user_param -> port ;
1255+ comm -> rdma_params -> ai_family = user_param -> ai_family ;
12461256 comm -> rdma_params -> sockfd = -1 ;
12471257 comm -> rdma_params -> gid_index = user_param -> gid_index ;
12481258 comm -> rdma_params -> gid_index2 = user_param -> gid_index2 ;
@@ -2034,7 +2044,7 @@ int rdma_cm_get_rdma_address(struct perftest_parameters *user_param,
20342044 char port [6 ] = "" , error_message [ERROR_MSG_SIZE ] = "" ;
20352045
20362046 sprintf (port , "%d" , user_param -> port );
2037- hints -> ai_family = AF_INET ;
2047+ hints -> ai_family = user_param -> ai_family ;
20382048 // if we have servername specified, it is a client, we should use server name
20392049 // if it is not specified, we should use explicit source_ip if possible
20402050 if ((NULL != user_param -> servername ) || (!user_param -> has_source_ip )) {
0 commit comments