summaryrefslogtreecommitdiff
path: root/src/libcharon/network
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-08-25 15:37:26 +0200
committerYves-Alexis Perez <corsac@debian.org>2013-08-25 15:37:26 +0200
commit6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349 (patch)
tree009fc492961e13860d2a4bc2de8caf2bbe2975e7 /src/libcharon/network
parentc83921a2b566aa9d55d8ccc7258f04fca6292ee6 (diff)
downloadvyos-strongswan-6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349.tar.gz
vyos-strongswan-6b99c8d9cff7b3e8ae8f3204b99e7ea40f791349.zip
Imported Upstream version 5.1.0
Diffstat (limited to 'src/libcharon/network')
-rw-r--r--src/libcharon/network/receiver.c6
-rw-r--r--src/libcharon/network/socket.h43
-rw-r--r--src/libcharon/network/socket_manager.c14
-rw-r--r--src/libcharon/network/socket_manager.h15
4 files changed, 64 insertions, 14 deletions
diff --git a/src/libcharon/network/receiver.c b/src/libcharon/network/receiver.c
index 2ca721a85..b8eb8419d 100644
--- a/src/libcharon/network/receiver.c
+++ b/src/libcharon/network/receiver.c
@@ -261,15 +261,13 @@ static bool cookie_verify(private_receiver_t *this, message_t *message,
*/
static bool check_cookie(private_receiver_t *this, message_t *message)
{
- packet_t *packet;
chunk_t data;
/* check for a cookie. We don't use our parser here and do it
* quick and dirty for performance reasons.
* we assume the cookie is the first payload (which is a MUST), and
* the cookie's SPI length is zero. */
- packet = message->get_packet(message);
- data = packet->get_data(packet);
+ data = message->get_packet_data(message);
if (data.len <
IKE_HEADER_LENGTH + NOTIFY_PAYLOAD_HEADER_LENGTH +
sizeof(u_int32_t) + this->hasher->get_hash_size(this->hasher) ||
@@ -277,7 +275,6 @@ static bool check_cookie(private_receiver_t *this, message_t *message)
*(u_int16_t*)(data.ptr + IKE_HEADER_LENGTH + 6) != htons(COOKIE))
{
/* no cookie found */
- packet->destroy(packet);
return FALSE;
}
data.ptr += IKE_HEADER_LENGTH + NOTIFY_PAYLOAD_HEADER_LENGTH;
@@ -285,7 +282,6 @@ static bool check_cookie(private_receiver_t *this, message_t *message)
if (!cookie_verify(this, message, data))
{
DBG2(DBG_NET, "found cookie, but content invalid");
- packet->destroy(packet);
return FALSE;
}
return TRUE;
diff --git a/src/libcharon/network/socket.h b/src/libcharon/network/socket.h
index f6c8a8660..e3cda3bea 100644
--- a/src/libcharon/network/socket.h
+++ b/src/libcharon/network/socket.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2006-2012 Tobias Brunner
+ * Copyright (C) 2006-2013 Tobias Brunner
* Copyright (C) 2005-2010 Martin Willi
* Copyright (C) 2006 Daniel Roethlisberger
* Copyright (C) 2005 Jan Hutter
@@ -25,6 +25,7 @@
#define SOCKET_H_
typedef struct socket_t socket_t;
+typedef enum socket_family_t socket_family_t;
#include <library.h>
#include <networking/packet.h>
@@ -37,6 +38,31 @@ typedef struct socket_t socket_t;
typedef socket_t *(*socket_constructor_t)();
/**
+ * Address families supported by socket implementations.
+ */
+enum socket_family_t {
+ /**
+ * No address families supported
+ */
+ SOCKET_FAMILY_NONE = 0,
+
+ /**
+ * IPv4
+ */
+ SOCKET_FAMILY_IPV4 = (1 << 0),
+
+ /**
+ * IPv6
+ */
+ SOCKET_FAMILY_IPV6 = (1 << 1),
+
+ /**
+ * Both address families supported
+ */
+ SOCKET_FAMILY_BOTH = (1 << 2) - 1,
+};
+
+/**
* Socket interface definition.
*/
struct socket_t {
@@ -52,7 +78,7 @@ struct socket_t {
* - SUCCESS when packet successfully received
* - FAILED when unable to receive
*/
- status_t (*receive) (socket_t *this, packet_t **packet);
+ status_t (*receive)(socket_t *this, packet_t **packet);
/**
* Send a packet.
@@ -65,7 +91,7 @@ struct socket_t {
* - SUCCESS when packet successfully sent
* - FAILED when unable to send
*/
- status_t (*send) (socket_t *this, packet_t *packet);
+ status_t (*send)(socket_t *this, packet_t *packet);
/**
* Get the port this socket is listening on.
@@ -73,12 +99,19 @@ struct socket_t {
* @param nat_t TRUE to get the port used to float in case of NAT-T
* @return the port
*/
- u_int16_t (*get_port) (socket_t *this, bool nat_t);
+ u_int16_t (*get_port)(socket_t *this, bool nat_t);
+
+ /**
+ * Get the address families this socket is listening on.
+ *
+ * @return supported families
+ */
+ socket_family_t (*supported_families)(socket_t *this);
/**
* Destroy a socket implementation.
*/
- void (*destroy) (socket_t *this);
+ void (*destroy)(socket_t *this);
};
/**
diff --git a/src/libcharon/network/socket_manager.c b/src/libcharon/network/socket_manager.c
index bf1fe5ba2..2a07e503c 100644
--- a/src/libcharon/network/socket_manager.c
+++ b/src/libcharon/network/socket_manager.c
@@ -102,6 +102,19 @@ METHOD(socket_manager_t, get_port, u_int16_t,
return port;
}
+METHOD(socket_manager_t, supported_families, socket_family_t,
+ private_socket_manager_t *this)
+{
+ socket_family_t families = SOCKET_FAMILY_NONE;
+ this->lock->read_lock(this->lock);
+ if (this->socket)
+ {
+ families = this->socket->supported_families(this->socket);
+ }
+ this->lock->unlock(this->lock);
+ return families;
+}
+
static void create_socket(private_socket_manager_t *this)
{
socket_constructor_t create;
@@ -167,6 +180,7 @@ socket_manager_t *socket_manager_create()
.send = _sender,
.receive = _receiver,
.get_port = _get_port,
+ .supported_families = _supported_families,
.add_socket = _add_socket,
.remove_socket = _remove_socket,
.destroy = _destroy,
diff --git a/src/libcharon/network/socket_manager.h b/src/libcharon/network/socket_manager.h
index 1909d1f25..a07d0804c 100644
--- a/src/libcharon/network/socket_manager.h
+++ b/src/libcharon/network/socket_manager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2012 Tobias Brunner
+ * Copyright (C) 2010-2013 Tobias Brunner
* Hochschule fuer Technik Rapperswil
* Copyright (C) 2010 Martin Willi
* Copyright (C) 2010 revosec AG
@@ -40,7 +40,7 @@ struct socket_manager_t {
* - SUCCESS when packet successfully received
* - FAILED when unable to receive
*/
- status_t (*receive) (socket_manager_t *this, packet_t **packet);
+ status_t (*receive)(socket_manager_t *this, packet_t **packet);
/**
* Send a packet using the registered socket.
@@ -50,7 +50,7 @@ struct socket_manager_t {
* - SUCCESS when packet successfully sent
* - FAILED when unable to send
*/
- status_t (*send) (socket_manager_t *this, packet_t *packet);
+ status_t (*send)(socket_manager_t *this, packet_t *packet);
/**
* Get the port the registered socket is listening on.
@@ -58,7 +58,14 @@ struct socket_manager_t {
* @param nat_t TRUE to get the port used to float in case of NAT-T
* @return the port, or 0, if no socket is registered
*/
- u_int16_t (*get_port) (socket_manager_t *this, bool nat_t);
+ u_int16_t (*get_port)(socket_manager_t *this, bool nat_t);
+
+ /**
+ * Get the address families the registered socket is listening on.
+ *
+ * @return address families
+ */
+ socket_family_t (*supported_families)(socket_manager_t *this);
/**
* Register a socket constructor.