Implemented encoding of additional IKEv1 proposal attributes
[strongswan.git] / src / libcharon / encoding / payloads / transform_attribute.c
index 97bde8b..7e8a9c7 100644 (file)
@@ -134,12 +134,17 @@ METHOD(payload_t, verify, status_t,
        return SUCCESS;
 }
 
-METHOD(payload_t, get_encoding_rules, void,
-       private_transform_attribute_t *this, encoding_rule_t **rules,
-       size_t *rule_count)
+METHOD(payload_t, get_encoding_rules, int,
+       private_transform_attribute_t *this, encoding_rule_t **rules)
 {
        *rules = encodings;
-       *rule_count = countof(encodings);
+       return countof(encodings);
+}
+
+METHOD(payload_t, get_header_length, int,
+       private_transform_attribute_t *this)
+{
+       return 0;
 }
 
 METHOD(payload_t, get_type, payload_type_t,
@@ -259,6 +264,7 @@ transform_attribute_t *transform_attribute_create(payload_type_t type)
                        .payload_interface = {
                                .verify = _verify,
                                .get_encoding_rules = _get_encoding_rules,
+                               .get_header_length = _get_header_length,
                                .get_length = _get_length,
                                .get_next_type = _get_next_type,
                                .set_next_type = _set_next_type,
@@ -284,13 +290,28 @@ transform_attribute_t *transform_attribute_create(payload_type_t type)
  * Described in header.
  */
 transform_attribute_t *transform_attribute_create_value(payload_type_t type,
-                                                       transform_attribute_type_t kind, u_int16_t value)
+                                                       transform_attribute_type_t kind, u_int64_t value)
 {
        transform_attribute_t *attribute;
 
        attribute = transform_attribute_create(type);
        attribute->set_attribute_type(attribute, kind);
-       attribute->set_value(attribute, value);
 
+       if (value <= UINT16_MAX)
+       {
+               attribute->set_value(attribute, value);
+       }
+       else if (value <= UINT32_MAX)
+       {
+               u_int32_t val32;
+
+               val32 = htonl(value);
+               attribute->set_value_chunk(attribute, chunk_from_thing(val32));
+       }
+       else
+       {
+               value = htobe64(value);
+               attribute->set_value_chunk(attribute, chunk_from_thing(value));
+       }
        return attribute;
 }