aboutsummaryrefslogtreecommitdiffstats
path: root/src/libpttls
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-01-17 15:16:03 +0100
committerMartin Willi <martin@revosec.ch>2013-01-17 16:34:34 +0100
commit16ef69d70a1c8d767ff690c5062a4837617da5d7 (patch)
tree26c36b59dc1c6f7a01af4461ff915451ac334719 /src/libpttls
parent04a9a99bc1902aed3793a605a700951558399edf (diff)
downloadstrongswan-16ef69d70a1c8d767ff690c5062a4837617da5d7.tar.bz2
strongswan-16ef69d70a1c8d767ff690c5062a4837617da5d7.tar.xz
Pass a constructor callback to create TNCCS server instances while dispatching
Diffstat (limited to 'src/libpttls')
-rw-r--r--src/libpttls/pt_tls_dispatcher.c16
-rw-r--r--src/libpttls/pt_tls_dispatcher.h9
-rw-r--r--src/libpttls/pt_tls_server.c15
-rw-r--r--src/libpttls/pt_tls_server.h6
4 files changed, 31 insertions, 15 deletions
diff --git a/src/libpttls/pt_tls_dispatcher.c b/src/libpttls/pt_tls_dispatcher.c
index adcf5b4bf..fab44596c 100644
--- a/src/libpttls/pt_tls_dispatcher.c
+++ b/src/libpttls/pt_tls_dispatcher.c
@@ -45,6 +45,11 @@ struct private_pt_tls_dispatcher_t {
* Server identity
*/
identification_t *server;
+
+ /**
+ * TNCCS protocol handler constructor
+ */
+ tnccs_t*(*create)();
};
/**
@@ -106,11 +111,12 @@ static void cleanup(pt_tls_server_t *connection)
}
METHOD(pt_tls_dispatcher_t, dispatch, void,
- private_pt_tls_dispatcher_t *this)
+ private_pt_tls_dispatcher_t *this, tnccs_t*(*create)())
{
while (TRUE)
{
pt_tls_server_t *connection;
+ tnccs_t *tnccs;
bool old;
int fd;
@@ -123,7 +129,13 @@ METHOD(pt_tls_dispatcher_t, dispatch, void,
continue;
}
- connection = pt_tls_server_create(this->server, fd);
+ tnccs = create();
+ if (!tnccs)
+ {
+ close(fd);
+ continue;
+ }
+ connection = pt_tls_server_create(this->server, fd, tnccs);
if (!connection)
{
close(fd);
diff --git a/src/libpttls/pt_tls_dispatcher.h b/src/libpttls/pt_tls_dispatcher.h
index 463bd6cc8..5d01f7fef 100644
--- a/src/libpttls/pt_tls_dispatcher.h
+++ b/src/libpttls/pt_tls_dispatcher.h
@@ -24,6 +24,8 @@
#include <networking/host.h>
#include <utils/identification.h>
+#include <tnc/tnccs/tnccs.h>
+
typedef struct pt_tls_dispatcher_t pt_tls_dispatcher_t;
/**
@@ -34,9 +36,12 @@ struct pt_tls_dispatcher_t {
/**
* Dispatch and handle PT-TLS connections.
*
- * This call is blocking and a thread cancellation point.
+ * This call is blocking and a thread cancellation point. The passed
+ * constructor gets called for each dispatched connection.
+ *
+ * @param create TNCCS constructor function to use
*/
- void (*dispatch)(pt_tls_dispatcher_t *this);
+ void (*dispatch)(pt_tls_dispatcher_t *this, tnccs_t*(*create)());
/**
* Destroy a pt_tls_dispatcher_t.
diff --git a/src/libpttls/pt_tls_server.c b/src/libpttls/pt_tls_server.c
index 2260d72ab..b525acb6f 100644
--- a/src/libpttls/pt_tls_server.c
+++ b/src/libpttls/pt_tls_server.c
@@ -18,8 +18,6 @@
#include <utils/debug.h>
-#include <tnc/tnc.h>
-
typedef struct private_pt_tls_server_t private_pt_tls_server_t;
/**
@@ -221,12 +219,6 @@ METHOD(pt_tls_server_t, handle, status_t,
return FAILED;
}
this->state = PT_TLS_SERVER_TNCCS;
- this->tnccs = (tls_t*)tnc->tnccs->create_instance(tnc->tnccs,
- TNCCS_2_0, TRUE);
- if (!this->tnccs)
- {
- return FAILED;
- }
break;
case PT_TLS_SERVER_TNCCS:
if (!assess(this, (tls_t*)this->tnccs))
@@ -250,7 +242,7 @@ METHOD(pt_tls_server_t, get_fd, int,
METHOD(pt_tls_server_t, destroy, void,
private_pt_tls_server_t *this)
{
- DESTROY_IF(this->tnccs);
+ this->tnccs->destroy(this->tnccs);
this->tls->destroy(this->tls);
free(this);
}
@@ -258,7 +250,8 @@ METHOD(pt_tls_server_t, destroy, void,
/**
* See header
*/
-pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd)
+pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd,
+ tnccs_t *tnccs)
{
private_pt_tls_server_t *this;
@@ -270,10 +263,12 @@ pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd)
},
.state = PT_TLS_SERVER_VERSION,
.tls = tls_socket_create(TRUE, server, NULL, fd, NULL),
+ .tnccs = (tls_t*)tnccs,
);
if (!this->tls)
{
+ this->tnccs->destroy(this->tnccs);
free(this);
return NULL;
}
diff --git a/src/libpttls/pt_tls_server.h b/src/libpttls/pt_tls_server.h
index 0d952c440..244111b43 100644
--- a/src/libpttls/pt_tls_server.h
+++ b/src/libpttls/pt_tls_server.h
@@ -23,6 +23,8 @@
#include <utils/identification.h>
+#include <tnc/tnccs/tnccs.h>
+
typedef struct pt_tls_server_t pt_tls_server_t;
/**
@@ -58,8 +60,10 @@ struct pt_tls_server_t {
*
* @param server TLS server identity
* @param fd client connection socket
+ * @param tnccs inner TNCCS protocol handler to use for this connection
* @return PT-TLS server
*/
-pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd);
+pt_tls_server_t *pt_tls_server_create(identification_t *server, int fd,
+ tnccs_t *tnccs);
#endif /** PT_TLS_SERVER_H_ @}*/