kernel: Add an event kernel interfaces can raise if they create/destroy a TUN device

This commit is contained in:
Tobias Brunner
2013-06-21 17:03:21 +02:00
parent 0d2ad63fe2
commit 4868d1c3bc
3 changed files with 43 additions and 5 deletions
+21 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2012 Tobias Brunner
* Copyright (C) 2008-2013 Tobias Brunner
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2010 Martin Willi
* Copyright (C) 2010 revosec AG
@@ -644,6 +644,25 @@ METHOD(kernel_interface_t, roam, void,
this->mutex->unlock(this->mutex);
}
METHOD(kernel_interface_t, tun, void,
private_kernel_interface_t *this, tun_device_t *tun, bool created)
{
kernel_listener_t *listener;
enumerator_t *enumerator;
this->mutex->lock(this->mutex);
enumerator = this->listeners->create_enumerator(this->listeners);
while (enumerator->enumerate(enumerator, &listener))
{
if (listener->tun &&
!listener->tun(listener, tun, created))
{
this->listeners->remove_at(this->listeners, enumerator);
}
}
enumerator->destroy(enumerator);
this->mutex->unlock(this->mutex);
}
METHOD(kernel_interface_t, register_algorithm, void,
private_kernel_interface_t *this, u_int16_t alg_id, transform_type_t type,
u_int16_t kernel_id, char *kernel_name)
@@ -764,6 +783,7 @@ kernel_interface_t *kernel_interface_create()
.mapping = _mapping,
.migrate = _migrate,
.roam = _roam,
.tun = _tun,
.destroy = _destroy,
},
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
+9 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2012 Tobias Brunner
* Copyright (C) 2006-2013 Tobias Brunner
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005-2006 Martin Willi
* Copyright (C) 2005 Jan Hutter
@@ -561,6 +561,14 @@ struct kernel_interface_t {
*/
void (*roam)(kernel_interface_t *this, bool address);
/**
* Raise a tun event.
*
* @param tun TUN device
* @param created TRUE if created, FALSE if going to be destroyed
*/
void (*tun)(kernel_interface_t *this, tun_device_t *tun, bool created);
/**
* Register a new algorithm with the kernel interface.
*
+13 -3
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2010 Tobias Brunner
* Copyright (C) 2010-2013 Tobias Brunner
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -23,9 +23,10 @@
typedef struct kernel_listener_t kernel_listener_t;
#include <kernel/kernel_ipsec.h>
#include <selectors/traffic_selector.h>
#include <networking/host.h>
#include <networking/tun_device.h>
#include <selectors/traffic_selector.h>
#include <kernel/kernel_ipsec.h>
/**
* Interface for components interested in kernel events.
@@ -91,6 +92,15 @@ struct kernel_listener_t {
* @return TRUE to remain registered, FALSE to unregister
*/
bool (*roam)(kernel_listener_t *this, bool address);
/**
* Hook called after a TUN device was created for a virtual IP address, or
* before such a device gets destroyed.
*
* @param tun TUN device
* @param created TRUE if created, FALSE if going to be destroyed
*/
bool (*tun)(kernel_listener_t *this, tun_device_t *tun, bool created);
};
#endif /** KERNEL_LISTENER_H_ @}*/