Extended nonce payload for IKEv1 support
[strongswan.git] / src / libcharon / encoding / payloads / payload.c
index 1cee6d2..56563ac 100644 (file)
 
 ENUM_BEGIN(payload_type_names, NO_PAYLOAD, NO_PAYLOAD,
        "NO_PAYLOAD");
-ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
+ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION_V1, VENDOR_ID_V1, NO_PAYLOAD,
+       "SECURITY_ASSOCIATION_V1",
+       "PROPOSAL_V1",
+       "TRANSFORM_V1",
+       "KEY_EXCHANGE_V1",
+       "ID_V1",
+       "CERTIFICATE_V1",
+       "CERTIFICATE_REQUEST_V1",
+       "HASH_V1",
+       "SIGNATURE_V1",
+       "NONCE_V1",
+       "NOTIFICATION_V1",
+       "DELETE_V1",
+       "VENDOR_ID_V1");
+ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, VENDOR_ID_V1,
        "SECURITY_ASSOCIATION",
        "KEY_EXCHANGE",
        "ID_INITIATOR",
@@ -59,30 +73,48 @@ ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, N
 #ifdef ME
 ENUM_NEXT(payload_type_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
        "ID_PEER");
-ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
+ENUM_NEXT(payload_type_names, HEADER, CONFIGURATION_ATTRIBUTE, ID_PEER,
        "HEADER",
        "PROPOSAL_SUBSTRUCTURE",
+       "PROPOSAL_SUBSTRUCTURE_V1",
        "TRANSFORM_SUBSTRUCTURE",
+       "TRANSFORM_SUBSTRUCTURE_V1",
        "TRANSFORM_ATTRIBUTE",
+       "TRANSFORM_ATTRIBUTE_V1",
        "TRAFFIC_SELECTOR_SUBSTRUCTURE",
-       "CONFIGURATION_ATTRIBUTE",
-       "UNKNOWN_PAYLOAD");
+       "CONFIGURATION_ATTRIBUTE");
 #else
-ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
+ENUM_NEXT(payload_type_names, HEADER, CONFIGURATION_ATTRIBUTE, EXTENSIBLE_AUTHENTICATION,
        "HEADER",
        "PROPOSAL_SUBSTRUCTURE",
+       "PROPOSAL_SUBSTRUCTURE_V1",
        "TRANSFORM_SUBSTRUCTURE",
+       "TRANSFORM_SUBSTRUCTURE_V1",
        "TRANSFORM_ATTRIBUTE",
+       "TRANSFORM_ATTRIBUTE_V1",
        "TRAFFIC_SELECTOR_SUBSTRUCTURE",
-       "CONFIGURATION_ATTRIBUTE",
-       "UNKNOWN_PAYLOAD");
+       "CONFIGURATION_ATTRIBUTE");
 #endif /* ME */
-ENUM_END(payload_type_names, UNKNOWN_PAYLOAD);
+ENUM_END(payload_type_names, CONFIGURATION_ATTRIBUTE);
 
 /* short forms of payload names */
 ENUM_BEGIN(payload_type_short_names, NO_PAYLOAD, NO_PAYLOAD,
        "--");
-ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
+ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION_V1, VENDOR_ID_V1, NO_PAYLOAD,
+       "SA",
+       "PROP",
+       "TRANS",
+       "KE",
+       "ID",
+       "CERT",
+       "CERTREQ",
+       "HASH",
+       "SIG",
+       "No",
+       "NO",
+       "D",
+       "V");
+ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, VENDOR_ID_V1,
        "SA",
        "KE",
        "IDi",
@@ -102,25 +134,29 @@ ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICAT
 #ifdef ME
 ENUM_NEXT(payload_type_short_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
        "IDp");
-ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
+ENUM_NEXT(payload_type_short_names, HEADER, CONFIGURATION_ATTRIBUTE, ID_PEER,
        "HDR",
        "PROP",
+       "PROP",
        "TRANS",
+       "TRANS",
+       "TRANSATTR",
        "TRANSATTR",
        "TSSUB",
-       "CPATTR",
-       "??");
+       "CATTR");
 #else
-ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
+ENUM_NEXT(payload_type_short_names, HEADER, CONFIGURATION_ATTRIBUTE, EXTENSIBLE_AUTHENTICATION,
        "HDR",
        "PROP",
+       "PROP",
+       "TRANS",
        "TRANS",
        "TRANSATTR",
+       "TRANSATTR",
        "TSSUB",
-       "CPATTR",
-       "??");
+       "CATTR");
 #endif /* ME */
-ENUM_END(payload_type_short_names, UNKNOWN_PAYLOAD);
+ENUM_END(payload_type_short_names, CONFIGURATION_ATTRIBUTE);
 
 /*
  * see header
@@ -132,23 +168,26 @@ payload_t *payload_create(payload_type_t type)
                case HEADER:
                        return (payload_t*)ike_header_create();
                case SECURITY_ASSOCIATION:
-                       return (payload_t*)sa_payload_create();
+               case SECURITY_ASSOCIATION_V1:
+                       return (payload_t*)sa_payload_create(type);
                case PROPOSAL_SUBSTRUCTURE:
-                       return (payload_t*)proposal_substructure_create();
+               case PROPOSAL_SUBSTRUCTURE_V1:
+                       return (payload_t*)proposal_substructure_create(type);
                case TRANSFORM_SUBSTRUCTURE:
-                       return (payload_t*)transform_substructure_create();
+               case TRANSFORM_SUBSTRUCTURE_V1:
+                       return (payload_t*)transform_substructure_create(type);
                case TRANSFORM_ATTRIBUTE:
-                       return (payload_t*)transform_attribute_create();
+               case TRANSFORM_ATTRIBUTE_V1:
+                       return (payload_t*)transform_attribute_create(type);
                case NONCE:
-                       return (payload_t*)nonce_payload_create();
+               case NONCE_V1:
+                       return (payload_t*)nonce_payload_create(type);
                case ID_INITIATOR:
-                       return (payload_t*)id_payload_create(ID_INITIATOR);
                case ID_RESPONDER:
-                       return (payload_t*)id_payload_create(ID_RESPONDER);
 #ifdef ME
                case ID_PEER:
-                       return (payload_t*)id_payload_create(ID_PEER);
 #endif /* ME */
+                       return (payload_t*)id_payload_create(type);
                case AUTHENTICATION:
                        return (payload_t*)auth_payload_create();
                case CERTIFICATE:
@@ -168,7 +207,8 @@ payload_t *payload_create(payload_type_t type)
                case DELETE:
                        return (payload_t*)delete_payload_create(0);
                case VENDOR_ID:
-                       return (payload_t*)vendor_id_payload_create();
+               case VENDOR_ID_V1:
+                       return (payload_t*)vendor_id_payload_create(type);
                case CONFIGURATION:
                        return (payload_t*)cp_payload_create();
                case CONFIGURATION_ATTRIBUTE:
@@ -178,7 +218,52 @@ payload_t *payload_create(payload_type_t type)
                case ENCRYPTED:
                        return (payload_t*)encryption_payload_create();
                default:
-                       return (payload_t*)unknown_payload_create();
+                       return (payload_t*)unknown_payload_create(type);
        }
 }
 
+/**
+ * See header.
+ */
+bool payload_is_known(payload_type_t type)
+{
+       if (type == HEADER)
+       {
+               return TRUE;
+       }
+       if (type >= SECURITY_ASSOCIATION && type <= EXTENSIBLE_AUTHENTICATION)
+       {
+               return TRUE;
+       }
+       if (type >= SECURITY_ASSOCIATION_V1 && type <= VENDOR_ID_V1)
+       {
+               return TRUE;
+       }
+#ifdef ME
+       if (type == ID_PEER)
+       {
+               return TRUE;
+       }
+#endif
+       return FALSE;
+}
+
+/**
+ * See header.
+ */
+void* payload_get_field(payload_t *payload, encoding_type_t type, u_int skip)
+{
+       encoding_rule_t *rule;
+       size_t count;
+       int i;
+
+       payload->get_encoding_rules(payload, &rule, &count);
+       for (i = 0; i < count; i++)
+       {
+               if (rule[i].type == type && skip-- == 0)
+               {
+                       return ((char*)payload) + rule[i].offset;
+               }
+       }
+       return NULL;
+}