Encode a single IP traffic selector as ID_IPV?_ADDRESS identity
authorMartin Willi <martin@revosec.ch>
Mon, 5 Dec 2011 15:20:56 +0000 (16:20 +0100)
committerMartin Willi <martin@revosec.ch>
Tue, 20 Mar 2012 16:31:12 +0000 (17:31 +0100)
src/libcharon/encoding/payloads/id_payload.c

index 2d27021..4d5cd05 100755 (executable)
@@ -391,7 +391,19 @@ id_payload_t *id_payload_create_from_ts(traffic_selector_t *ts)
 
        this = (private_id_payload_t*)id_payload_create(ID_V1);
 
-       if (ts->to_subnet(ts, &net, &mask))
+       if (ts->is_host(ts, NULL))
+       {
+               if (ts->get_type(ts) == TS_IPV4_ADDR_RANGE)
+               {
+                       this->id_type = ID_IPV4_ADDR;
+               }
+               else
+               {
+                       this->id_type = ID_IPV6_ADDR;
+               }
+               this->id_data = chunk_clone(ts->get_from_address(ts));
+       }
+       else if (ts->to_subnet(ts, &net, &mask))
        {
                u_int8_t netmask[16], len, byte;
 
@@ -418,6 +430,7 @@ id_payload_t *id_payload_create_from_ts(traffic_selector_t *ts)
                }
                this->id_data = chunk_cat("cc", net->get_address(net),
                                                                  chunk_create(netmask, len));
+               net->destroy(net);
        }
        else
        {
@@ -431,12 +444,12 @@ id_payload_t *id_payload_create_from_ts(traffic_selector_t *ts)
                }
                this->id_data = chunk_cat("cc",
                                                        ts->get_from_address(ts), ts->get_to_address(ts));
+               net->destroy(net);
        }
        this->port = ts->get_from_port(ts);
        this->protocol_id = ts->get_protocol(ts);
        this->payload_length += this->id_data.len;
 
-       net->destroy(net);
-
        return &this->public;
 }
+