util_port.c revision 36c5fee33fa8b822175d410202aebcf592c8d342
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>
#include <syslog.h>
#include <unistd.h>
#include "queue.h"
#include "port.h"
#include "iscsi_conn.h"
#include "utility.h"
int port_conn_num;
void
{
port_conn_num = 0;
}
void *
port_watcher(void *v)
{
int s,
fd,
on = 1;
char debug[80];
struct sockaddr_in sin_ip;
struct sockaddr_in6 sin6_ip;
struct sockaddr_storage st;
port_args_t *p = (port_args_t *)v;
target_queue_t *q = p->port_mgmtq;
int l,
accept_err_sleep = 1;
/*
* Try creating an IPv6 socket first
* If failed, try creating an IPv4 socket
*/
"Can't open socket");
return (NULL);
} else {
sizeof (sin_ip))) < 0) {
"bind on port %d failed, errno %d",
return (NULL);
}
}
} else {
sizeof (on));
< 0) {
"bind on port %d failed, errno %d",
return (NULL);
}
}
if (listen(s, 5) < 0) {
return (NULL);
}
/*CONSTANTCONDITION*/
while (1) {
&socklen)) < 0) {
accept_err_sleep *= 2;
(void) sleep(accept_err_sleep);
if (accept_err_sleep > 60) {
accept_err_sleep = 1;
queue_prt(q, Q_GEN_ERRS,
"accept failed, errno %d", errno);
}
continue;
}
l = 128 * 1024;
sizeof (l)) < 0)
"setsockopt failed");
sizeof (l)) < 0)
"setsockopt failed");
l = 1;
sizeof (l)) < 0)
"setsockopt keepalive failed");
1)) == NULL) {
/*
* If we fail to get memory this is all rather
* pointless, since it's unlikely that queue_str
* could malloc memory to send a message.
*/
"connection malloc failed");
return (NULL);
}
/*
* Save initiator sockaddr for future use
*/
&socklen) == 0) {
/*
* Save target sockaddr for future use
*/
/*
* If target address is IPv4 mapped IPv6 address
* convert it to IPv4 address
*/
}
}
(void) pthread_mutex_lock(&port_mutex);
} else {
}
(void) pthread_mutex_unlock(&port_mutex);
}
return (NULL);
}
void
{
iscsi_conn_t *n;
(void) pthread_mutex_lock(&port_mutex);
if (conn_head == c) {
else
} else {
n = c->c_prev;
else {
conn_tail = n;
}
}
/*
* The connection queue is freed here so that it's protected by
* locks. The main thread of the deamon when processing incoming
* management requests will send them on the connection queues.
* The main thread will grab the port_mutex so that we know the
* queue is still valid.
*/
(void) pthread_mutex_unlock(&port_mutex);
}