Add a DSCP value with getter/setter on packet_t
authorMartin Willi <martin@revosec.ch>
Wed, 6 Feb 2013 10:56:27 +0000 (11:56 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 6 Feb 2013 14:20:32 +0000 (15:20 +0100)
src/libipsec/esp_packet.c
src/libstrongswan/networking/packet.c
src/libstrongswan/networking/packet.h

index 16cc687..43a3c2a 100644 (file)
@@ -97,6 +97,18 @@ METHOD(packet_t, set_data, void,
        return this->packet->set_data(this->packet, data);
 }
 
+METHOD(packet_t, get_dscp, u_int8_t,
+       private_esp_packet_t *this)
+{
+       return this->packet->get_dscp(this->packet);
+}
+
+METHOD(packet_t, set_dscp, void,
+       private_esp_packet_t *this, u_int8_t value)
+{
+       this->packet->set_dscp(this->packet, value);
+}
+
 METHOD(packet_t, skip_bytes, void,
        private_esp_packet_t *this, size_t bytes)
 {
@@ -411,6 +423,8 @@ static private_esp_packet_t *esp_packet_create_internal(packet_t *packet)
                                .get_destination = _get_destination,
                                .get_data = _get_data,
                                .set_data = _set_data,
+                               .get_dscp = _get_dscp,
+                               .set_dscp = _set_dscp,
                                .skip_bytes = _skip_bytes,
                                .clone = _clone,
                                .destroy = _destroy,
index a2c329d..4ff7fc4 100644 (file)
@@ -39,6 +39,11 @@ struct private_packet_t {
         */
        host_t *destination;
 
+       /**
+        * DSCP value on packet
+        */
+       u_int8_t dscp;
+
         /**
          * message data
          */
@@ -89,6 +94,17 @@ METHOD(packet_t, set_data, void,
        this->adjusted_data = this->data = data;
 }
 
+METHOD(packet_t, get_dscp, u_int8_t,
+       private_packet_t *this)
+{
+       return this->dscp;
+}
+METHOD(packet_t, set_dscp, void,
+       private_packet_t *this, u_int8_t value)
+{
+       this->dscp = value;
+}
+
 METHOD(packet_t, skip_bytes, void,
        private_packet_t *this, size_t bytes)
 {
@@ -123,6 +139,7 @@ METHOD(packet_t, clone_, packet_t*,
        {
                other->set_data(other, chunk_clone(this->adjusted_data));
        }
+       other->set_dscp(other, this->dscp);
        return other;
 }
 
@@ -141,6 +158,8 @@ packet_t *packet_create_from_data(host_t *src, host_t *dst, chunk_t data)
                        .get_source = _get_source,
                        .set_destination = _set_destination,
                        .get_destination = _get_destination,
+                       .get_dscp = _get_dscp,
+                       .set_dscp = _set_dscp,
                        .skip_bytes = _skip_bytes,
                        .clone = _clone_,
                        .destroy = _destroy,
index 6fb9cec..a96a4b8 100644 (file)
@@ -76,6 +76,20 @@ struct packet_t {
        void (*set_data)(packet_t *packet, chunk_t data);
 
        /**
+        * Get the DiffServ Code Point set on this packet.
+        *
+        * @return                      DSCP value
+        */
+       u_int8_t (*get_dscp)(packet_t *this);
+
+       /**
+        * Set the DiffServ Code Point to use on this packet.
+        *
+        * @param value         DSCP value
+        */
+       void (*set_dscp)(packet_t *this, u_int8_t value);
+
+       /**
         * Increase the offset where the actual packet data starts.
         *
         * The total offset applies to future calls of get_data() and clone().