Add Non-ESP marker in sender and not individual socket plugins.

This commit is contained in:
Tobias Brunner
2012-08-08 15:12:24 +02:00
parent 65da43e2fc
commit 064da8b96b
5 changed files with 23 additions and 39 deletions
+19
View File
@@ -1,4 +1,5 @@
/*
* Copyright (C) 2012 Tobias Brunner
* Copyright (C) 2005-2006 Martin Willi
* Copyright (C) 2005 Jan Hutter
* Hochschule fuer Technik Rapperswil
@@ -121,6 +122,7 @@ METHOD(sender_t, send_, void,
static job_requeue_t send_packets(private_sender_t * this)
{
packet_t *packet;
host_t *src, *dst;
bool oldstate;
this->mutex->lock(this->mutex);
@@ -139,6 +141,23 @@ static job_requeue_t send_packets(private_sender_t * this)
this->sent->signal(this->sent);
this->mutex->unlock(this->mutex);
/* if neither source nor destination port is 500 we add a Non-ESP marker */
dst = packet->get_destination(packet);
src = packet->get_source(packet);
if (dst->get_port(dst) != IKEV2_UDP_PORT &&
src->get_port(src) != IKEV2_UDP_PORT)
{
chunk_t marker = chunk_from_chars(0x00, 0x00, 0x00, 0x00), data;
data = packet->get_data(packet);
/* NAT keepalives have no marker prepended */
if (data.len != 1 || data.ptr[0] != 0xFF)
{
data = chunk_cat("cm", marker, data);
packet->set_data(packet, data);
}
}
charon->socket->send(charon->socket, packet);
packet->destroy(packet);
return JOB_REQUEUE_DIRECT;
+1 -1
View File
@@ -28,7 +28,7 @@ typedef struct sender_t sender_t;
#include <network/packet.h>
/**
* Thread responsible for sending packets over the socket.
* Callback job responsible for sending IKE packets over the socket.
*/
struct sender_t {
@@ -315,7 +315,7 @@ METHOD(socket_t, sender, status_t,
{
int sport, skt, family;
ssize_t bytes_sent;
chunk_t data, marked;
chunk_t data;
host_t *src, *dst;
struct msghdr msg;
struct cmsghdr *cmsg;
@@ -351,17 +351,6 @@ METHOD(socket_t, sender, status_t,
{
skt = this->ipv6_natt;
}
/* NAT keepalives without marker */
if (data.len != 1 || data.ptr[0] != 0xFF)
{
/* add non esp marker to packet */
marked = chunk_alloc(data.len + MARKER_LEN);
memset(marked.ptr, 0, MARKER_LEN);
memcpy(marked.ptr + MARKER_LEN, data.ptr, data.len);
/* let the packet do the clean up for us */
packet->set_data(packet, marked);
data = marked;
}
}
else
{
@@ -477,7 +477,7 @@ METHOD(socket_t, sender, status_t,
host_t *src, *dst;
int port, family;
ssize_t len;
chunk_t data, marked;
chunk_t data;
struct msghdr msg;
struct cmsghdr *cmsg;
struct iovec iov;
@@ -495,19 +495,6 @@ METHOD(socket_t, sender, status_t,
data = packet->get_data(packet);
DBG2(DBG_NET, "sending packet: from %#H to %#H", src, dst);
/* use non-ESP marker if none of the ports is 500, not for keep alives */
if (port != IKEV2_UDP_PORT && dst->get_port(dst) != IKEV2_UDP_PORT &&
!(data.len == 1 && data.ptr[0] == 0xFF))
{
/* add non esp marker to packet */
marked = chunk_alloc(data.len + MARKER_LEN);
memset(marked.ptr, 0, MARKER_LEN);
memcpy(marked.ptr + MARKER_LEN, data.ptr, data.len);
/* let the packet do the clean up for us */
packet->set_data(packet, marked);
data = marked;
}
memset(&msg, 0, sizeof(struct msghdr));
msg.msg_name = dst->get_sockaddr(dst);;
msg.msg_namelen = *dst->get_sockaddr_len(dst);
@@ -303,7 +303,7 @@ METHOD(socket_t, sender, status_t,
{
int sport, skt, family;
ssize_t bytes_sent;
chunk_t data, marked;
chunk_t data;
host_t *src, *dst;
struct msghdr msg;
struct cmsghdr *cmsg;
@@ -339,17 +339,6 @@ METHOD(socket_t, sender, status_t,
{
skt = this->send6_natt;
}
/* NAT keepalives without marker */
if (data.len != 1 || data.ptr[0] != 0xFF)
{
/* add non esp marker to packet */
marked = chunk_alloc(data.len + MARKER_LEN);
memset(marked.ptr, 0, MARKER_LEN);
memcpy(marked.ptr + MARKER_LEN, data.ptr, data.len);
/* let the packet do the clean up for us */
packet->set_data(packet, marked);
data = marked;
}
}
else
{