]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
traffic-selector: Add a hash() method
authorMartin Willi <martin@revosec.ch>
Thu, 23 Oct 2014 09:19:03 +0000 (11:19 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 20 Feb 2015 12:34:48 +0000 (13:34 +0100)
src/libstrongswan/selectors/traffic_selector.c
src/libstrongswan/selectors/traffic_selector.h

index 1cfa3ae481655b261edd18b0afb4c21b8d7438dd..3b7f8c5a0d157040e29c7dbc23f41a87315fbc00 100644 (file)
@@ -685,6 +685,17 @@ METHOD(traffic_selector_t, clone_, traffic_selector_t*,
        }
 }
 
+METHOD(traffic_selector_t, hash, u_int,
+       private_traffic_selector_t *this, u_int hash)
+{
+       return chunk_hash_inc(get_from_address(this),
+                       chunk_hash_inc(get_to_address(this),
+                        chunk_hash_inc(chunk_from_thing(this->from_port),
+                         chunk_hash_inc(chunk_from_thing(this->to_port),
+                          chunk_hash_inc(chunk_from_thing(this->protocol),
+                               hash)))));
+}
+
 METHOD(traffic_selector_t, destroy, void,
        private_traffic_selector_t *this)
 {
@@ -974,6 +985,7 @@ static private_traffic_selector_t *traffic_selector_create(u_int8_t protocol,
                        .set_address = _set_address,
                        .to_subnet = _to_subnet,
                        .clone = _clone_,
+                       .hash = _hash,
                        .destroy = _destroy,
                },
                .from_port = from_port,
index 93300460e41587fadd787bedb3a7a22f972fdb4e..cf9a2861bbc696ebfed18fc4f61d9e897db0c299 100644 (file)
@@ -220,6 +220,14 @@ struct traffic_selector_t {
         */
        bool (*to_subnet) (traffic_selector_t *this, host_t **net, u_int8_t *mask);
 
+       /**
+        * Create a hash value for the traffic selector.
+        *
+        * @param inc           optional value for incremental hashing
+        * @return                      calculated hash value for the traffic selector
+        */
+       u_int (*hash)(traffic_selector_t *this, u_int inc);
+
        /**
         * Destroys the ts object
         */