Function added to send packets without Non-ESP marker.
authorTobias Brunner <tobias@strongswan.org>
Fri, 24 Feb 2012 12:01:51 +0000 (13:01 +0100)
committerTobias Brunner <tobias@strongswan.org>
Wed, 8 Aug 2012 13:12:25 +0000 (15:12 +0200)
src/libcharon/network/sender.c
src/libcharon/network/sender.h

index b62185f..c12941e 100644 (file)
@@ -80,7 +80,7 @@ struct private_sender_t {
        bool send_delay_response;
 };
 
-METHOD(sender_t, send_, void,
+METHOD(sender_t, send_no_marker, void,
        private_sender_t *this, packet_t *packet)
 {
        host_t *src, *dst;
@@ -116,13 +116,37 @@ METHOD(sender_t, send_, void,
        this->mutex->unlock(this->mutex);
 }
 
+METHOD(sender_t, send_, void,
+       private_sender_t *this, packet_t *packet)
+{
+       host_t *src, *dst;
+
+       /* if neither source nor destination port is 500 we add a Non-ESP marker */
+       src = packet->get_source(packet);
+       dst = packet->get_destination(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);
+               }
+       }
+
+       send_no_marker(this, packet);
+}
+
 /**
  * Job callback function to send packets
  */
-static job_requeue_t send_packets(private_sender_t * this)
+static job_requeue_t send_packets(private_sender_t *this)
 {
        packet_t *packet;
-       host_t *src, *dst;
        bool oldstate;
 
        this->mutex->lock(this->mutex);
@@ -141,23 +165,6 @@ 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;
@@ -195,6 +202,7 @@ sender_t * sender_create()
        INIT(this,
                .public = {
                        .send = _send_,
+                       .send_no_marker = _send_no_marker,
                        .flush = _flush,
                        .destroy = _destroy,
                },
index d8ff8c8..c4f18d7 100644 (file)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2012 Tobias Brunner
  * Copyright (C) 2005-2007 Martin Willi
  * Copyright (C) 2005 Jan Hutter
  * Hochschule fuer Technik Rapperswil
@@ -44,6 +45,13 @@ struct sender_t {
        void (*send) (sender_t *this, packet_t *packet);
 
        /**
+        * The same as send() but does not add Non-ESP markers automatically.
+        *
+        * @param packet        packet to send
+        */
+       void (*send_no_marker) (sender_t *this, packet_t *packet);
+
+       /**
         * Enforce a flush of the send queue.
         *
         * This function blocks until all queued packets have been sent.