Create pt_tls_dispatcher with separate server address and identity
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
#include <threading/thread.h>
|
#include <threading/thread.h>
|
||||||
#include <utils/debug.h>
|
#include <utils/debug.h>
|
||||||
#include <networking/host.h>
|
|
||||||
#include <processing/jobs/callback_job.h>
|
#include <processing/jobs/callback_job.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -51,22 +50,14 @@ struct private_pt_tls_dispatcher_t {
|
|||||||
/**
|
/**
|
||||||
* Open listening server socket
|
* Open listening server socket
|
||||||
*/
|
*/
|
||||||
static bool open_socket(private_pt_tls_dispatcher_t *this,
|
static bool open_socket(private_pt_tls_dispatcher_t *this, host_t *host)
|
||||||
char *server, u_int16_t port)
|
|
||||||
{
|
{
|
||||||
host_t *host;
|
|
||||||
|
|
||||||
this->fd = socket(AF_INET, SOCK_STREAM, 0);
|
this->fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (this->fd == -1)
|
if (this->fd == -1)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "opening PT-TLS socket failed: %s", strerror(errno));
|
DBG1(DBG_TNC, "opening PT-TLS socket failed: %s", strerror(errno));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
host = host_create_from_dns(server, AF_UNSPEC, port);
|
|
||||||
if (!host)
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (bind(this->fd, host->get_sockaddr(host),
|
if (bind(this->fd, host->get_sockaddr(host),
|
||||||
*host->get_sockaddr_len(host)) == -1)
|
*host->get_sockaddr_len(host)) == -1)
|
||||||
{
|
{
|
||||||
@@ -160,7 +151,8 @@ METHOD(pt_tls_dispatcher_t, destroy, void,
|
|||||||
/**
|
/**
|
||||||
* See header
|
* See header
|
||||||
*/
|
*/
|
||||||
pt_tls_dispatcher_t *pt_tls_dispatcher_create(char *server, u_int16_t port)
|
pt_tls_dispatcher_t *pt_tls_dispatcher_create(host_t *address,
|
||||||
|
identification_t *id)
|
||||||
{
|
{
|
||||||
private_pt_tls_dispatcher_t *this;
|
private_pt_tls_dispatcher_t *this;
|
||||||
|
|
||||||
@@ -169,15 +161,17 @@ pt_tls_dispatcher_t *pt_tls_dispatcher_create(char *server, u_int16_t port)
|
|||||||
.dispatch = _dispatch,
|
.dispatch = _dispatch,
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.server = identification_create_from_string(server),
|
.server = id,
|
||||||
.fd = -1,
|
.fd = -1,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!open_socket(this, server, port))
|
if (!open_socket(this, address))
|
||||||
{
|
{
|
||||||
|
address->destroy(address);
|
||||||
destroy(this);
|
destroy(this);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
address->destroy(address);
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
#ifndef PT_TLS_DISPATCHER_H_
|
#ifndef PT_TLS_DISPATCHER_H_
|
||||||
#define PT_TLS_DISPATCHER_H_
|
#define PT_TLS_DISPATCHER_H_
|
||||||
|
|
||||||
#include <utils/utils.h>
|
#include <networking/host.h>
|
||||||
|
#include <utils/identification.h>
|
||||||
|
|
||||||
typedef struct pt_tls_dispatcher_t pt_tls_dispatcher_t;
|
typedef struct pt_tls_dispatcher_t pt_tls_dispatcher_t;
|
||||||
|
|
||||||
@@ -46,10 +47,11 @@ struct pt_tls_dispatcher_t {
|
|||||||
/**
|
/**
|
||||||
* Create a pt_tls_dispatcher instance.
|
* Create a pt_tls_dispatcher instance.
|
||||||
*
|
*
|
||||||
* @param server server address
|
* @param address server address with port to listen on, gets owned
|
||||||
* @param port server port to listen
|
* @param id TLS server identity, gets owned
|
||||||
* @return dispatcher service
|
* @return dispatcher service
|
||||||
*/
|
*/
|
||||||
pt_tls_dispatcher_t *pt_tls_dispatcher_create(char *server, u_int16_t port);
|
pt_tls_dispatcher_t *pt_tls_dispatcher_create(host_t *address,
|
||||||
|
identification_t *id);
|
||||||
|
|
||||||
#endif /** PT_TLS_DISPATCHER_H_ @}*/
|
#endif /** PT_TLS_DISPATCHER_H_ @}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user