mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-03 00:00:24 -04:00
Merge branch 'whitelist-watcher'
Use watcher and non-blocking I/O for client connections to avoid issues with clients that stay connected for a long time. Closes strongswan/strongswan#2827
This commit is contained in:
commit
58c567da74
@ -92,19 +92,51 @@ static void list(private_whitelist_control_t *this,
|
|||||||
stream->write_all(stream, &msg, sizeof(msg));
|
stream->write_all(stream, &msg, sizeof(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Information about a client connection.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
private_whitelist_control_t *this;
|
||||||
|
whitelist_msg_t msg;
|
||||||
|
size_t read;
|
||||||
|
} whitelist_conn_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dispatch a received message
|
* Dispatch a received message
|
||||||
*/
|
*/
|
||||||
static bool on_accept(private_whitelist_control_t *this, stream_t *stream)
|
CALLBACK(on_read, bool,
|
||||||
|
whitelist_conn_t *conn, stream_t *stream)
|
||||||
{
|
{
|
||||||
|
private_whitelist_control_t *this = conn->this;
|
||||||
identification_t *id;
|
identification_t *id;
|
||||||
whitelist_msg_t msg;
|
ssize_t len;
|
||||||
|
|
||||||
while (stream->read_all(stream, &msg, sizeof(msg)))
|
while (TRUE)
|
||||||
{
|
{
|
||||||
msg.id[sizeof(msg.id) - 1] = 0;
|
while (conn->read < sizeof(conn->msg))
|
||||||
id = identification_create_from_string(msg.id);
|
{
|
||||||
switch (ntohl(msg.type))
|
len = stream->read(stream, (char*)&conn->msg + conn->read,
|
||||||
|
sizeof(conn->msg) - conn->read, FALSE);
|
||||||
|
if (len <= 0)
|
||||||
|
{
|
||||||
|
if (errno == EWOULDBLOCK)
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if (len != 0)
|
||||||
|
{
|
||||||
|
DBG1(DBG_CFG, "whitelist socket error: %s", strerror(errno));
|
||||||
|
}
|
||||||
|
stream->destroy(stream);
|
||||||
|
free(conn);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
conn->read += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
conn->msg.id[sizeof(conn->msg.id) - 1] = 0;
|
||||||
|
id = identification_create_from_string(conn->msg.id);
|
||||||
|
switch (ntohl(conn->msg.type))
|
||||||
{
|
{
|
||||||
case WHITELIST_ADD:
|
case WHITELIST_ADD:
|
||||||
this->listener->add(this->listener, id);
|
this->listener->add(this->listener, id);
|
||||||
@ -129,9 +161,22 @@ static bool on_accept(private_whitelist_control_t *this, stream_t *stream)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
id->destroy(id);
|
id->destroy(id);
|
||||||
|
conn->read = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
CALLBACK(on_accept, bool,
|
||||||
|
private_whitelist_control_t *this, stream_t *stream)
|
||||||
|
{
|
||||||
|
whitelist_conn_t *conn;
|
||||||
|
|
||||||
|
INIT(conn,
|
||||||
|
.this = this,
|
||||||
|
);
|
||||||
|
stream->on_read(stream, on_read, conn);
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(whitelist_control_t, destroy, void,
|
METHOD(whitelist_control_t, destroy, void,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user