kernel-interface: Raise mapping event with a proto/SPI/dst tuple

This commit is contained in:
Martin Willi
2015-02-20 13:34:51 +01:00
parent 85ace154d8
commit b125839a1a
8 changed files with 75 additions and 41 deletions
+4 -3
View File
@@ -836,17 +836,18 @@ METHOD(kernel_interface_t, expire, void,
}
METHOD(kernel_interface_t, mapping, void,
private_kernel_interface_t *this, u_int32_t reqid, u_int32_t spi,
host_t *remote)
private_kernel_interface_t *this, u_int8_t protocol, u_int32_t spi,
host_t *dst, host_t *remote)
{
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->mapping &&
!listener->mapping(listener, reqid, spi, remote))
!listener->mapping(listener, protocol, spi, dst, remote))
{
this->listeners->remove_at(this->listeners, enumerator);
}
+4 -3
View File
@@ -570,12 +570,13 @@ struct kernel_interface_t {
/**
* Raise a mapping event.
*
* @param reqid reqid of the SA
* @param protocol protocol of affected SA
* @param spi spi of the SA
* @param dst original destination address of SA
* @param remote new remote host
*/
void (*mapping)(kernel_interface_t *this, u_int32_t reqid, u_int32_t spi,
host_t *remote);
void (*mapping)(kernel_interface_t *this, u_int8_t protocol, u_int32_t spi,
host_t *dst, host_t *remote);
/**
* Raise a migrate event.
+4 -3
View File
@@ -61,13 +61,14 @@ struct kernel_listener_t {
/**
* Hook called if the NAT mappings of an IPsec SA changed.
*
* @param reqid reqid of the SA
* @param protocol IPsec protocol of affected SA
* @param spi spi of the SA
* @param dst old destinatino address of SA
* @param remote new remote host
* @return TRUE to remain registered, FALSE to unregister
*/
bool (*mapping)(kernel_listener_t *this, u_int32_t reqid, u_int32_t spi,
host_t *remote);
bool (*mapping)(kernel_listener_t *this, u_int8_t protocol, u_int32_t spi,
host_t *dst, host_t *remote);
/**
* Hook called if a migrate event for a policy is received.
@@ -973,23 +973,29 @@ static void process_mapping(private_kernel_netlink_ipsec_t *this,
struct nlmsghdr *hdr)
{
struct xfrm_user_mapping *mapping;
u_int32_t spi, reqid;
u_int32_t spi;
mapping = NLMSG_DATA(hdr);
spi = mapping->id.spi;
reqid = mapping->reqid;
DBG2(DBG_KNL, "received a XFRM_MSG_MAPPING");
if (mapping->id.proto == IPPROTO_ESP)
{
host_t *host;
host = xfrm2host(mapping->id.family, &mapping->new_saddr,
mapping->new_sport);
if (host)
host_t *dst, *new;
dst = xfrm2host(mapping->id.family, &mapping->id.daddr, 0);
if (dst)
{
hydra->kernel_interface->mapping(hydra->kernel_interface, reqid,
spi, host);
new = xfrm2host(mapping->id.family, &mapping->new_saddr,
mapping->new_sport);
if (new)
{
hydra->kernel_interface->mapping(hydra->kernel_interface,
IPPROTO_ESP, spi, dst, new);
new->destroy(new);
}
dst->destroy(dst);
}
}
}
@@ -1388,9 +1388,9 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this,
struct sadb_msg* msg)
{
pfkey_msg_t response;
u_int32_t spi, reqid;
u_int32_t spi;
sockaddr_t *sa;
host_t *host;
host_t *dst, *new;
DBG2(DBG_KNL, "received an SADB_X_NAT_T_NEW_MAPPING");
@@ -1408,7 +1408,6 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this,
}
spi = response.sa->sadb_sa_spi;
reqid = response.x_sa2->sadb_x_sa2_reqid;
if (satype2proto(msg->sadb_msg_satype) != IPPROTO_ESP)
{
@@ -1416,6 +1415,7 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this,
}
sa = (sockaddr_t*)(response.dst + 1);
dst = host_create_from_sockaddr(sa);
switch (sa->sa_family)
{
case AF_INET:
@@ -1433,12 +1433,16 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this,
default:
break;
}
host = host_create_from_sockaddr(sa);
if (host)
if (dst)
{
hydra->kernel_interface->mapping(hydra->kernel_interface, reqid,
spi, host);
new = host_create_from_sockaddr(sa);
if (new)
{
hydra->kernel_interface->mapping(hydra->kernel_interface,
IPPROTO_ESP, spi, dst, new);
new->destroy(new);
}
dst->destroy(dst);
}
}
#endif /*SADB_X_NAT_T_NEW_MAPPING*/