1479 }
1480 kmem_free(in_pdu, in_pdu_size);
1481 in_pdu = NULL;
1482 break;
1483 }
1484
1485 iscsi_net->close(so);
1486
1487 return (rval);
1488 }
1489
1490 static
1491 void
1492 *isns_open(iscsi_addr_t *isns_server_addr)
1493 {
1494 int rval = 0;
1495 union {
1496 struct sockaddr sin;
1497 struct sockaddr_in s_in4;
1498 struct sockaddr_in6 s_in6;
1499 } sa_rsvr = { 0 };
1500 void *so;
1501 struct sockaddr_in6 t_addr;
1502 socklen_t t_addrlen;
1503
1504 bzero(&t_addr, sizeof (struct sockaddr_in6));
1505 t_addrlen = sizeof (struct sockaddr_in6);
1506 if (isns_server_addr->a_addr.i_insize == sizeof (struct in_addr)) {
1507 /* IPv4 */
1508 sa_rsvr.s_in4.sin_family = AF_INET;
1509 sa_rsvr.s_in4.sin_port = htons(isns_server_addr->a_port);
1510 sa_rsvr.s_in4.sin_addr.s_addr =
1511 isns_server_addr->a_addr.i_addr.in4.s_addr;
1512
1513 /* Create socket */
1514 so = iscsi_net->socket(AF_INET, SOCK_STREAM, 0);
1515 } else {
1516 /* IPv6 */
1517 sa_rsvr.s_in6.sin6_family = AF_INET6;
1518 bcopy(&(isns_server_addr->a_addr.i_addr.in6),
1519 sa_rsvr.s_in6.sin6_addr.s6_addr,
2965
2966 return (0);
2967 }
2968
2969 /* ARGSUSED */
2970 static
2971 void
2972 isns_service_esi_scn(iscsi_thread_t *thread, void *arg)
2973 {
2974 int clnt_len;
2975 isns_async_thread_arg_t *larg;
2976 isns_pdu_t *in_pdu;
2977 size_t bytes_received, in_pdu_size = 0;
2978 uint8_t *lhba_handle;
2979 struct sockaddr_in6 t_addr;
2980 socklen_t t_addrlen;
2981 union {
2982 struct sockaddr sin;
2983 struct sockaddr_in s_in4;
2984 struct sockaddr_in6 s_in6;
2985 } clnt_addr = { 0 };
2986 union {
2987 struct sockaddr_in soa4;
2988 struct sockaddr_in6 soa6;
2989 } local_conn_prop;
2990 void *listening_so, *connecting_so;
2991
2992 larg = (isns_async_thread_arg_t *)arg;
2993 listening_so = larg->listening_so;
2994 lhba_handle = larg->lhba_handle;
2995
2996 /* Done using the argument - free it */
2997 kmem_free(larg, sizeof (*larg));
2998 bzero(&t_addr, sizeof (struct sockaddr_in6));
2999 t_addrlen = sizeof (struct sockaddr_in6);
3000
3001 (void) iscsi_net->getsockname(listening_so,
3002 (struct sockaddr *)&t_addr, &t_addrlen);
3003 if (t_addrlen <= sizeof (local_conn_prop)) {
3004 bcopy(&t_addr, &local_conn_prop, t_addrlen);
3005 }
3083 in_pdu = NULL;
3084
3085 iscsi_net->close(connecting_so);
3086 break;
3087
3088 default:
3089 kmem_free(in_pdu, in_pdu_size);
3090 in_pdu = NULL;
3091 continue;
3092 }
3093 }
3094 }
3095
3096 static
3097 boolean_t
3098 find_listening_addr(iscsi_addr_t *local_addr, void *listening_so)
3099 {
3100 union {
3101 struct sockaddr_in soa4;
3102 struct sockaddr_in6 soa6;
3103 } local_conn_prop = { 0 };
3104
3105 struct sockaddr_in6 t_addr;
3106 socklen_t t_addrlen;
3107
3108 if (local_addr == NULL || listening_so == NULL) {
3109 return (B_FALSE);
3110 }
3111
3112 bzero(&t_addr, sizeof (struct sockaddr_in6));
3113 t_addrlen = sizeof (struct sockaddr_in6);
3114
3115 (void) iscsi_net->getsockname(listening_so, (struct sockaddr *)&t_addr,
3116 &t_addrlen);
3117 if (t_addrlen > sizeof (local_conn_prop)) {
3118 return (B_FALSE);
3119 }
3120 bcopy(&t_addr, &local_conn_prop, t_addrlen);
3121 if (local_conn_prop.soa4.sin_family == AF_INET) {
3122 local_addr->a_addr.i_addr.in4.s_addr =
3123 local_conn_prop.soa4.sin_addr.s_addr;
3125 } else if (local_conn_prop.soa4.sin_family == AF_INET6) {
3126 /* Currently, IPv6 is not supported */
3127 return (B_FALSE);
3128 } else {
3129 return (B_FALSE);
3130 }
3131
3132 local_addr->a_port = ntohs(local_conn_prop.soa4.sin_port);
3133
3134 return (B_TRUE);
3135 }
3136
3137 static
3138 boolean_t
3139 find_local_portal(iscsi_addr_t *isns_server_addr,
3140 iscsi_addr_t **local_addr, void **listening_so)
3141 {
3142 union {
3143 struct sockaddr_in soa4;
3144 struct sockaddr_in6 soa6;
3145 } local_conn_prop = { 0 };
3146 union {
3147 struct sockaddr sin;
3148 struct sockaddr_in s_in4;
3149 struct sockaddr_in6 s_in6;
3150 } serv_addr = { 0 };
3151 void *so;
3152 struct sockaddr_in6 t_addr;
3153 socklen_t t_addrlen;
3154
3155 if (listening_so == NULL) {
3156 return (B_FALSE);
3157 }
3158
3159 if (local_addr != NULL) {
3160 *local_addr = NULL;
3161 }
3162
3163 *listening_so = NULL;
3164 bzero(&t_addr, sizeof (struct sockaddr_in6));
3165 t_addrlen = sizeof (struct sockaddr_in6);
3166
3167 /*
3168 * Determine the local IP address.
3169 */
3170 if (local_addr != NULL) {
|
1479 }
1480 kmem_free(in_pdu, in_pdu_size);
1481 in_pdu = NULL;
1482 break;
1483 }
1484
1485 iscsi_net->close(so);
1486
1487 return (rval);
1488 }
1489
1490 static
1491 void
1492 *isns_open(iscsi_addr_t *isns_server_addr)
1493 {
1494 int rval = 0;
1495 union {
1496 struct sockaddr sin;
1497 struct sockaddr_in s_in4;
1498 struct sockaddr_in6 s_in6;
1499 } sa_rsvr = {{0}};
1500 void *so;
1501 struct sockaddr_in6 t_addr;
1502 socklen_t t_addrlen;
1503
1504 bzero(&t_addr, sizeof (struct sockaddr_in6));
1505 t_addrlen = sizeof (struct sockaddr_in6);
1506 if (isns_server_addr->a_addr.i_insize == sizeof (struct in_addr)) {
1507 /* IPv4 */
1508 sa_rsvr.s_in4.sin_family = AF_INET;
1509 sa_rsvr.s_in4.sin_port = htons(isns_server_addr->a_port);
1510 sa_rsvr.s_in4.sin_addr.s_addr =
1511 isns_server_addr->a_addr.i_addr.in4.s_addr;
1512
1513 /* Create socket */
1514 so = iscsi_net->socket(AF_INET, SOCK_STREAM, 0);
1515 } else {
1516 /* IPv6 */
1517 sa_rsvr.s_in6.sin6_family = AF_INET6;
1518 bcopy(&(isns_server_addr->a_addr.i_addr.in6),
1519 sa_rsvr.s_in6.sin6_addr.s6_addr,
2965
2966 return (0);
2967 }
2968
2969 /* ARGSUSED */
2970 static
2971 void
2972 isns_service_esi_scn(iscsi_thread_t *thread, void *arg)
2973 {
2974 int clnt_len;
2975 isns_async_thread_arg_t *larg;
2976 isns_pdu_t *in_pdu;
2977 size_t bytes_received, in_pdu_size = 0;
2978 uint8_t *lhba_handle;
2979 struct sockaddr_in6 t_addr;
2980 socklen_t t_addrlen;
2981 union {
2982 struct sockaddr sin;
2983 struct sockaddr_in s_in4;
2984 struct sockaddr_in6 s_in6;
2985 } clnt_addr = {{0}};
2986 union {
2987 struct sockaddr_in soa4;
2988 struct sockaddr_in6 soa6;
2989 } local_conn_prop;
2990 void *listening_so, *connecting_so;
2991
2992 larg = (isns_async_thread_arg_t *)arg;
2993 listening_so = larg->listening_so;
2994 lhba_handle = larg->lhba_handle;
2995
2996 /* Done using the argument - free it */
2997 kmem_free(larg, sizeof (*larg));
2998 bzero(&t_addr, sizeof (struct sockaddr_in6));
2999 t_addrlen = sizeof (struct sockaddr_in6);
3000
3001 (void) iscsi_net->getsockname(listening_so,
3002 (struct sockaddr *)&t_addr, &t_addrlen);
3003 if (t_addrlen <= sizeof (local_conn_prop)) {
3004 bcopy(&t_addr, &local_conn_prop, t_addrlen);
3005 }
3083 in_pdu = NULL;
3084
3085 iscsi_net->close(connecting_so);
3086 break;
3087
3088 default:
3089 kmem_free(in_pdu, in_pdu_size);
3090 in_pdu = NULL;
3091 continue;
3092 }
3093 }
3094 }
3095
3096 static
3097 boolean_t
3098 find_listening_addr(iscsi_addr_t *local_addr, void *listening_so)
3099 {
3100 union {
3101 struct sockaddr_in soa4;
3102 struct sockaddr_in6 soa6;
3103 } local_conn_prop = {{0}};
3104
3105 struct sockaddr_in6 t_addr;
3106 socklen_t t_addrlen;
3107
3108 if (local_addr == NULL || listening_so == NULL) {
3109 return (B_FALSE);
3110 }
3111
3112 bzero(&t_addr, sizeof (struct sockaddr_in6));
3113 t_addrlen = sizeof (struct sockaddr_in6);
3114
3115 (void) iscsi_net->getsockname(listening_so, (struct sockaddr *)&t_addr,
3116 &t_addrlen);
3117 if (t_addrlen > sizeof (local_conn_prop)) {
3118 return (B_FALSE);
3119 }
3120 bcopy(&t_addr, &local_conn_prop, t_addrlen);
3121 if (local_conn_prop.soa4.sin_family == AF_INET) {
3122 local_addr->a_addr.i_addr.in4.s_addr =
3123 local_conn_prop.soa4.sin_addr.s_addr;
3125 } else if (local_conn_prop.soa4.sin_family == AF_INET6) {
3126 /* Currently, IPv6 is not supported */
3127 return (B_FALSE);
3128 } else {
3129 return (B_FALSE);
3130 }
3131
3132 local_addr->a_port = ntohs(local_conn_prop.soa4.sin_port);
3133
3134 return (B_TRUE);
3135 }
3136
3137 static
3138 boolean_t
3139 find_local_portal(iscsi_addr_t *isns_server_addr,
3140 iscsi_addr_t **local_addr, void **listening_so)
3141 {
3142 union {
3143 struct sockaddr_in soa4;
3144 struct sockaddr_in6 soa6;
3145 } local_conn_prop = {{0}};
3146 union {
3147 struct sockaddr sin;
3148 struct sockaddr_in s_in4;
3149 struct sockaddr_in6 s_in6;
3150 } serv_addr = {{0}};
3151 void *so;
3152 struct sockaddr_in6 t_addr;
3153 socklen_t t_addrlen;
3154
3155 if (listening_so == NULL) {
3156 return (B_FALSE);
3157 }
3158
3159 if (local_addr != NULL) {
3160 *local_addr = NULL;
3161 }
3162
3163 *listening_so = NULL;
3164 bzero(&t_addr, sizeof (struct sockaddr_in6));
3165 t_addrlen = sizeof (struct sockaddr_in6);
3166
3167 /*
3168 * Determine the local IP address.
3169 */
3170 if (local_addr != NULL) {
|