Use the payloads actual type in unknown_payload_t
authorMartin Willi <martin@revosec.ch>
Wed, 10 Nov 2010 13:17:03 +0000 (14:17 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 5 Jan 2011 15:45:43 +0000 (16:45 +0100)
src/libcharon/encoding/message.c
src/libcharon/encoding/parser.c
src/libcharon/encoding/payloads/payload.c
src/libcharon/encoding/payloads/payload.h
src/libcharon/encoding/payloads/unknown_payload.c
src/libcharon/encoding/payloads/unknown_payload.h

index 06198d9..f4cb5b0 100644 (file)
@@ -1273,7 +1273,7 @@ static status_t decrypt_payloads(private_message_t *this, aead_t *aead)
                        }
                        encryption->destroy(encryption);
                }
-               if (type != UNKNOWN_PAYLOAD && !was_encrypted)
+               if (payload_is_known(type) && !was_encrypted)
                {
                        rule = get_payload_rule(this, type);
                        if (!rule || rule->encrypted)
@@ -1315,14 +1315,13 @@ static status_t verify(private_message_t *this)
                        unknown_payload_t *unknown;
 
                        type = payload->get_type(payload);
-                       if (type == UNKNOWN_PAYLOAD)
+                       if (!payload_is_known(type))
                        {
-                               /* unknown payloads are ignored if they are not critical */
                                unknown = (unknown_payload_t*)payload;
                                if (unknown->is_critical(unknown))
                                {
-                                       DBG1(DBG_ENC, "%N is not supported, but its critical!",
-                                                payload_type_names, type);
+                                       DBG1(DBG_ENC, "payload type %N is not supported, "
+                                                "but its critical!", payload_type_names, type);
                                        enumerator->destroy(enumerator);
                                        return NOT_SUPPORTED;
                                }
index 9aa34b1..0993134 100644 (file)
@@ -387,12 +387,6 @@ static status_t parse_payload(private_parser_t *this,
        DBG3(DBG_ENC, "parsing payload from %b",
                 this->byte_pos, this->input_roof - this->byte_pos);
 
-       if (pld->get_type(pld) == UNKNOWN_PAYLOAD)
-       {
-               DBG1(DBG_ENC, "  payload type %d is unknown, handling as %N",
-                        payload_type, payload_type_names, UNKNOWN_PAYLOAD);
-       }
-
        /* base pointer for output, avoids casting in every rule */
        output = pld;
 
index 1cee6d2..188dd1c 100644 (file)
@@ -59,25 +59,23 @@ 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",
        "TRANSFORM_SUBSTRUCTURE",
        "TRANSFORM_ATTRIBUTE",
        "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",
        "TRANSFORM_SUBSTRUCTURE",
        "TRANSFORM_ATTRIBUTE",
        "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,
@@ -102,25 +100,23 @@ 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",
        "TRANS",
        "TRANSATTR",
        "TSSUB",
-       "CPATTR",
-       "??");
+       "CPATTR");
 #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",
        "TRANS",
        "TRANSATTR",
        "TSSUB",
-       "CPATTR",
-       "??");
+       "CPATTR");
 #endif /* ME */
-ENUM_END(payload_type_short_names, UNKNOWN_PAYLOAD);
+ENUM_END(payload_type_short_names, CONFIGURATION_ATTRIBUTE);
 
 /*
  * see header
@@ -178,7 +174,25 @@ 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 ||
+               (type >= SECURITY_ASSOCIATION && type <= EXTENSIBLE_AUTHENTICATION))
+       {
+               return TRUE;
+       }
+#ifdef ME
+       if (type == ID_PEER)
+       {
+               return TRUE;
+       }
+#endif
+       return FALSE;
+}
index 2e783cb..dbdae34 100644 (file)
@@ -178,17 +178,8 @@ enum payload_type_t{
         * used internally to handle a transform attribute like a payload.
         */
        CONFIGURATION_ATTRIBUTE = 145,
-
-       /**
-        * A unknown payload has a value of PRIVATE USE space.
-        *
-        * This payload type is not sent over wire and just
-        * used internally to handle a unknown payload.
-        */
-       UNKNOWN_PAYLOAD = 146,
 };
 
-
 /**
  * enum names for payload_type_t.
  */
@@ -269,4 +260,12 @@ struct payload_t {
  */
 payload_t *payload_create(payload_type_t type);
 
+/**
+ * Check if a specific payload is implemented, or handled as unkown payload.
+ *
+ * @param type         type of the payload to check
+ * @return                     FALSE if payload type handled as unkown payload
+ */
+bool payload_is_known(payload_type_t type);
+
 #endif /** PAYLOAD_H_ @}*/
index 06e5754..defc5d3 100644 (file)
@@ -31,6 +31,11 @@ struct private_unknown_payload_t {
        unknown_payload_t public;
 
        /**
+        * Type of this payload
+        */
+       payload_type_t type;
+
+       /**
         * Next payload type.
         */
        u_int8_t next_payload;
@@ -105,7 +110,7 @@ METHOD(payload_t, get_encoding_rules, void,
 METHOD(payload_t, get_payload_type, payload_type_t,
        private_unknown_payload_t *this)
 {
-       return UNKNOWN_PAYLOAD;
+       return this->type;
 }
 
 METHOD(payload_t, get_next_type, payload_type_t,
@@ -148,7 +153,7 @@ METHOD2(payload_t, unknown_payload_t, destroy, void,
 /*
  * Described in header
  */
-unknown_payload_t *unknown_payload_create()
+unknown_payload_t *unknown_payload_create(payload_type_t type)
 {
        private_unknown_payload_t *this;
 
@@ -169,6 +174,7 @@ unknown_payload_t *unknown_payload_create()
                },
                .next_payload = NO_PAYLOAD,
                .payload_length = UNKNOWN_PAYLOAD_HEADER_LENGTH,
+               .type = type,
        );
 
        return &this->public;
index c761ed2..1f42fcf 100644 (file)
@@ -70,10 +70,11 @@ struct unknown_payload_t {
 };
 
 /**
- * Creates an empty unknown_payload_t object.
+ * Creates an empty unknown_payload_t.
  *
- * @return unknown_payload_t object
+ * @param              type of the payload
+ * @return             unknown_payload_t object
  */
-unknown_payload_t *unknown_payload_create(void);
+unknown_payload_t *unknown_payload_create(payload_type_t type);
 
 #endif /** UNKNOWN_PAYLOAD_H_ @}*/