aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-04-18 16:08:12 +0200
committerMartin Willi <martin@revosec.ch>2013-05-06 16:10:12 +0200
commit0e107f03ac05f3a09f17a4c53c241578443ba830 (patch)
treed98333cde263e26fd0c5db32db4f29eeee7c4b26 /src
parente8002956c996e63830ea1d7026090cd0bd907abb (diff)
downloadstrongswan-0e107f03ac05f3a09f17a4c53c241578443ba830.tar.bz2
strongswan-0e107f03ac05f3a09f17a4c53c241578443ba830.tar.xz
kernel-pfroute: use only a single PF_ROUTE socket for both events and queries
Diffstat (limited to 'src')
-rw-r--r--src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c b/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c
index 7e26cc37b..84d370bb8 100644
--- a/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c
+++ b/src/libhydra/plugins/kernel_pfroute/kernel_pfroute_net.c
@@ -207,11 +207,6 @@ struct private_kernel_pfroute_net_t
int socket;
/**
- * PF_ROUTE socket to receive events
- */
- int socket_events;
-
- /**
* sequence number for messages sent to the kernel
*/
int seq;
@@ -455,7 +450,7 @@ static job_requeue_t receive_events(private_kernel_pfroute_net_t *this)
bool oldstate;
oldstate = thread_cancelability(TRUE);
- len = recvfrom(this->socket_events, buf, sizeof(buf), 0, NULL, 0);
+ len = recvfrom(this->socket, buf, sizeof(buf), 0, NULL, 0);
thread_cancelability(oldstate);
if (len < 0)
@@ -760,14 +755,10 @@ METHOD(kernel_net_t, destroy, void,
enumerator_t *enumerator;
addr_entry_t *addr;
- if (this->socket > 0)
+ if (this->socket != -1)
{
close(this->socket);
}
- if (this->socket_events)
- {
- close(this->socket_events);
- }
enumerator = this->addrs->create_enumerator(this->addrs);
while (enumerator->enumerate(enumerator, NULL, (void**)&addr))
{
@@ -787,7 +778,6 @@ METHOD(kernel_net_t, destroy, void,
kernel_pfroute_net_t *kernel_pfroute_net_create()
{
private_kernel_pfroute_net_t *this;
- bool register_for_events = TRUE;
INIT(this,
.public = {
@@ -811,37 +801,31 @@ kernel_pfroute_net_t *kernel_pfroute_net_create()
.mutex_pfroute = mutex_create(MUTEX_TYPE_DEFAULT),
);
- if (streq(hydra->daemon, "starter"))
- { /* starter has no threads, so we do not register for kernel events */
- register_for_events = FALSE;
- }
-
/* create a PF_ROUTE socket to communicate with the kernel */
this->socket = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
- if (this->socket < 0)
+ if (this->socket == -1)
{
DBG1(DBG_KNL, "unable to create PF_ROUTE socket");
destroy(this);
return NULL;
}
- if (register_for_events)
+ if (streq(hydra->daemon, "starter"))
{
- /* create a PF_ROUTE socket to receive events */
- this->socket_events = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
- if (this->socket_events < 0)
+ /* starter has no threads, so we do not register for kernel events */
+ if (shutdown(this->socket, SHUT_RD) != 0)
{
- DBG1(DBG_KNL, "unable to create PF_ROUTE event socket");
- destroy(this);
- return NULL;
+ DBG1(DBG_KNL, "closing read end of PF_ROUTE socket failed: %s",
+ strerror(errno));
}
-
+ }
+ else
+ {
lib->processor->queue_job(lib->processor,
(job_t*)callback_job_create_with_prio(
(callback_job_cb_t)receive_events, this, NULL,
(callback_job_cancel_t)return_false, JOB_PRIO_CRITICAL));
}
-
if (init_address_list(this) != SUCCESS)
{
DBG1(DBG_KNL, "unable to get interface list");