added TNC_IMC_ReceiveMessageLong() and TNC_IMV_ReceiveMessageLong() support
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 8 Dec 2011 11:38:45 +0000 (12:38 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 8 Dec 2011 11:38:45 +0000 (12:38 +0100)
src/libcharon/plugins/tnc_imc/tnc_imc.c
src/libcharon/plugins/tnc_imc/tnc_imc_manager.c
src/libcharon/plugins/tnc_imv/tnc_imv.c
src/libcharon/plugins/tnc_imv/tnc_imv_manager.c
src/libcharon/plugins/tnccs_11/tnccs_11.c
src/libcharon/plugins/tnccs_20/tnccs_20.c
src/libtnccs/tnc/imc/imc.h
src/libtnccs/tnc/imc/imc_manager.h
src/libtnccs/tnc/imv/imv.h
src/libtnccs/tnc/imv/imv_manager.h

index 6bd69dc..dc326cf 100644 (file)
@@ -279,15 +279,12 @@ METHOD(imc_t, set_message_types_long, void,
 }
 
 METHOD(imc_t, type_supported, bool,
-       private_tnc_imc_t *this, TNC_MessageType message_type)
+       private_tnc_imc_t *this, TNC_VendorID msg_vid, TNC_MessageSubtype msg_subtype)
 {
-       TNC_VendorID msg_vid, vid;
-       TNC_MessageSubtype msg_subtype, subtype;
+       TNC_VendorID vid;
+       TNC_MessageSubtype subtype;
        int i;
 
-    msg_vid = (message_type >> 8) & TNC_VENDORID_ANY;
-       msg_subtype = message_type & TNC_SUBTYPE_ANY;
-
        for (i = 0; i < this->type_count; i++)
        {
            vid = this->supported_vids[i];
@@ -371,6 +368,8 @@ imc_t* tnc_imc_create(char *name, char *path)
        }
     this->public.receive_message =
                                                dlsym(this->handle, "TNC_IMC_ReceiveMessage");
+    this->public.receive_message_long =
+                                               dlsym(this->handle, "TNC_IMC_ReceiveMessageLong");
     this->public.batch_ending =
                                                dlsym(this->handle, "TNC_IMC_BatchEnding");
     this->public.terminate =
index 5e06d9e..4ea01e4 100644 (file)
@@ -253,28 +253,50 @@ METHOD(imc_manager_t, set_message_types_long, TNC_Result,
 
 METHOD(imc_manager_t, receive_message, void,
        private_tnc_imc_manager_t *this, TNC_ConnectionID connection_id,
-                                                                        TNC_BufferReference message,
-                                                                        TNC_UInt32 message_len,
-                                                                        TNC_MessageType message_type)
+                                                                        bool excl,
+                                                                        TNC_BufferReference msg,
+                                                                        TNC_UInt32 msg_len,
+                                                                        TNC_VendorID msg_vid,
+                                                                        TNC_MessageSubtype msg_subtype,
+                                                                        TNC_UInt32 src_imv_id,
+                                                                        TNC_UInt32 dst_imc_id)
 {
        bool type_supported = FALSE;
+       TNC_MessageType msg_type;
+       TNC_UInt32 msg_flags;
        enumerator_t *enumerator;
        imc_t *imc;
 
        enumerator = this->imcs->create_enumerator(this->imcs);
        while (enumerator->enumerate(enumerator, &imc))
        {
-               if (imc->receive_message && imc->type_supported(imc, message_type))
+               if (imc->type_supported(imc, msg_vid, msg_subtype) &&
+                  (!excl || (excl && imc->has_id(imc, dst_imc_id)) ))
                {
-                       type_supported = TRUE;
-                       imc->receive_message(imc->get_id(imc), connection_id,
-                                                                message, message_len, message_type);
+                       if (imc->receive_message_long && src_imv_id)
+                       {
+                               type_supported = TRUE;
+                               msg_flags = excl ? TNC_MESSAGE_FLAGS_EXCLUSIVE : 0;
+                               imc->receive_message_long(imc->get_id(imc), connection_id,
+                                                               msg_flags, msg, msg_len, msg_vid, msg_subtype,
+                                                               src_imv_id, dst_imc_id);
+
+                       }
+                       else if (imc->receive_message && msg_vid <= TNC_VENDORID_ANY &&
+                                        msg_subtype <= TNC_SUBTYPE_ANY)
+                       {
+                               type_supported = TRUE;
+                               msg_type = (msg_vid << 8) | msg_subtype;
+                               imc->receive_message(imc->get_id(imc), connection_id,
+                                                                        msg, msg_len, msg_type);
+                       }
                }
        }
        enumerator->destroy(enumerator);
        if (!type_supported)
        {
-               DBG2(DBG_TNC, "message type 0x%08x not supported by any IMC", message_type);
+               DBG2(DBG_TNC, "message type 0x%06x/0x%08x not supported by any IMC",
+                        msg_vid, msg_subtype);
        }
 }
 
index 7d7b668..7ea23f5 100644 (file)
@@ -279,15 +279,12 @@ METHOD(imv_t, set_message_types_long, void,
 }
 
 METHOD(imv_t, type_supported, bool,
-       private_tnc_imv_t *this, TNC_MessageType message_type)
+       private_tnc_imv_t *this, TNC_VendorID msg_vid, TNC_MessageSubtype msg_subtype)
 {
-       TNC_VendorID msg_vid, vid;
-       TNC_MessageSubtype msg_subtype, subtype;
+       TNC_VendorID vid;
+       TNC_MessageSubtype subtype;
        int i;
 
-       msg_vid = (message_type >> 8) & TNC_VENDORID_ANY;
-       msg_subtype = message_type & TNC_SUBTYPE_ANY;
-
        for (i = 0; i < this->type_count; i++)
        {
            vid = this->supported_vids[i];
index 3231248..10a4adc 100644 (file)
@@ -331,28 +331,52 @@ METHOD(imv_manager_t, solicit_recommendation, void,
 
 METHOD(imv_manager_t, receive_message, void,
        private_tnc_imv_manager_t *this, TNC_ConnectionID connection_id,
-                                                                        TNC_BufferReference message,
-                                                                        TNC_UInt32 message_len,
-                                                                        TNC_MessageType message_type)
+                                                                        bool excl,
+                                                                        TNC_BufferReference msg,
+                                                                        TNC_UInt32 msg_len,
+                                                                        TNC_VendorID msg_vid,
+                                                                        TNC_MessageSubtype msg_subtype,
+                                                                        TNC_UInt32 src_imc_id,
+                                                                        TNC_UInt32 dst_imv_id)
 {
        bool type_supported = FALSE;
+       TNC_MessageType msg_type;
+       TNC_UInt32 msg_flags;
        enumerator_t *enumerator;
        imv_t *imv;
 
+       msg_type = (msg_vid << 8) | msg_subtype;
+
        enumerator = this->imvs->create_enumerator(this->imvs);
        while (enumerator->enumerate(enumerator, &imv))
        {
-               if (imv->receive_message && imv->type_supported(imv, message_type))
+               if (imv->type_supported(imv, msg_vid, msg_subtype) &&
+                  (!excl || (excl && imv->has_id(imv, dst_imv_id)) ))
                {
-                       type_supported = TRUE;
-                       imv->receive_message(imv->get_id(imv), connection_id,
-                                                                message, message_len, message_type);
+                       if (imv->receive_message_long && src_imc_id)
+                       {
+                               type_supported = TRUE;
+                               msg_flags = excl ? TNC_MESSAGE_FLAGS_EXCLUSIVE : 0;
+                               imv->receive_message_long(imv->get_id(imv), connection_id,
+                                                               msg_flags, msg, msg_len, msg_vid, msg_subtype,
+                                                               src_imc_id, dst_imv_id);
+
+                       }
+                       else if (imv->receive_message && msg_vid <= TNC_VENDORID_ANY &&
+                                        msg_subtype <= TNC_SUBTYPE_ANY)
+                       {
+                               type_supported = TRUE;
+                               msg_type = (msg_vid << 8) | msg_subtype;
+                               imv->receive_message(imv->get_id(imv), connection_id,
+                                                                        msg, msg_len, msg_type);
+                       }
                }
        }
        enumerator->destroy(enumerator);
        if (!type_supported)
        {
-               DBG2(DBG_TNC, "message type 0x%08x not supported by any IMV", message_type);
+               DBG2(DBG_TNC, "message type 0x%06x/0x%08x not supported by any IMV",
+                        msg_vid, msg_subtype);
        }
 }
 
index 835ddf1..37ead6e 100644 (file)
@@ -160,38 +160,40 @@ static void handle_message(private_tnccs_11_t *this, tnccs_msg_t *msg)
                        imc_imv_msg_t *imc_imv_msg;
                        TNC_MessageType msg_type;
                        chunk_t msg_body;
-                       u_int32_t vendor_id, subtype;
+                       u_int32_t msg_vid, msg_subtype;
                        enum_name_t *pa_subtype_names;
 
                        imc_imv_msg = (imc_imv_msg_t*)msg;
                        msg_type = imc_imv_msg->get_msg_type(imc_imv_msg);
                        msg_body = imc_imv_msg->get_msg_body(imc_imv_msg);
-                       vendor_id = msg_type >> 8;
-                       subtype = msg_type & 0xff;
+                       msg_vid = (msg_type >> 8) & TNC_VENDORID_ANY;
+                       msg_subtype = msg_type & TNC_SUBTYPE_ANY;
 
-                       pa_subtype_names = get_pa_subtype_names(vendor_id);
+                       pa_subtype_names = get_pa_subtype_names(msg_vid);
                        if (pa_subtype_names)
                        {
                                DBG2(DBG_TNC, "handling IMC-IMV message type '%N/%N' 0x%06x/0x%02x",
-                                        pen_names, vendor_id, pa_subtype_names, subtype,
-                                        vendor_id, subtype);
+                                        pen_names, msg_vid, pa_subtype_names, msg_subtype,
+                                        msg_vid, msg_subtype);
                        }
                        else
                        {
                                DBG2(DBG_TNC, "handling IMC-IMV message type '%N' 0x%06x/0x%02x",
-                                        pen_names, vendor_id, vendor_id, subtype);
+                                        pen_names, msg_vid, msg_vid, msg_subtype);
                        }
 
                        this->send_msg = TRUE;
                        if (this->is_server)
                        {
-                               tnc->imvs->receive_message(tnc->imvs,
-                               this->connection_id, msg_body.ptr, msg_body.len, msg_type);
+                               tnc->imvs->receive_message(tnc->imvs, this->connection_id,
+                                                                                  FALSE, msg_body.ptr, msg_body.len,
+                                                                                  msg_vid, msg_subtype, 0, TNC_IMVID_ANY);
                        }
                        else
                        {
-                               tnc->imcs->receive_message(tnc->imcs,
-                               this->connection_id, msg_body.ptr, msg_body.len,msg_type);
+                               tnc->imcs->receive_message(tnc->imcs, this->connection_id,
+                                                                                  FALSE, msg_body.ptr, msg_body.len,
+                                                                                  msg_vid, msg_subtype, 0, TNC_IMCID_ANY);
                        }
                        this->send_msg = FALSE;
                        break;
index fe0ba98..ca72b85 100644 (file)
@@ -167,39 +167,44 @@ static void handle_message(private_tnccs_20_t *this, pb_tnc_msg_t *msg)
                case PB_MSG_PA:
                {
                        pb_pa_msg_t *pa_msg;
-                       TNC_MessageType msg_type;
-                       u_int32_t vendor_id, subtype;
+                       u_int32_t msg_vid, msg_subtype;
+                       u_int16_t imc_id, imv_id;
                        chunk_t msg_body;
+                       bool excl;
                        enum_name_t *pa_subtype_names;
 
                        pa_msg = (pb_pa_msg_t*)msg;
-                       vendor_id = pa_msg->get_vendor_id(pa_msg, &subtype);
-                       msg_type = (vendor_id << 8) | (subtype & 0xff);
+                       msg_vid = pa_msg->get_vendor_id(pa_msg, &msg_subtype);
                        msg_body = pa_msg->get_body(pa_msg);
+                       imc_id = pa_msg->get_collector_id(pa_msg);
+                       imv_id = pa_msg->get_validator_id(pa_msg);
+                       excl = pa_msg->get_exclusive_flag(pa_msg);
 
-                       pa_subtype_names = get_pa_subtype_names(vendor_id);
+                       pa_subtype_names = get_pa_subtype_names(msg_vid);
                        if (pa_subtype_names)
                        {
                                DBG2(DBG_TNC, "handling PB-PA message type '%N/%N' 0x%06x/0x%08x",
-                                        pen_names, vendor_id, pa_subtype_names, subtype,
-                                        vendor_id, subtype);
+                                        pen_names, msg_vid, pa_subtype_names, msg_subtype,
+                                        msg_vid, msg_subtype);
                        }
                        else
                        {
                                DBG2(DBG_TNC, "handling PB-PA message type '%N' 0x%06x/0x%08x",
-                                        pen_names, vendor_id, vendor_id, subtype);
+                                        pen_names, msg_vid, msg_vid, msg_subtype);
                        }
 
                        this->send_msg = TRUE;
                        if (this->is_server)
                        {
-                               tnc->imvs->receive_message(tnc->imvs,
-                               this->connection_id, msg_body.ptr, msg_body.len, msg_type);
+                               tnc->imvs->receive_message(tnc->imvs, this->connection_id,
+                                                                                  excl, msg_body.ptr, msg_body.len,
+                                                                                  msg_vid, msg_subtype, imc_id, imv_id);
                        }
                        else
                        {
-                               tnc->imcs->receive_message(tnc->imcs,
-                               this->connection_id, msg_body.ptr, msg_body.len,msg_type);
+                               tnc->imcs->receive_message(tnc->imcs, this->connection_id,
+                                                                                  excl, msg_body.ptr, msg_body.len,
+                                                                                  msg_vid, msg_subtype, imv_id, imc_id);
                        }
                        this->send_msg = FALSE;
                        break;
index 3794fd2..3ff7d51 100644 (file)
@@ -95,6 +95,33 @@ struct imc_t {
                                                                  TNC_MessageType messageType);
 
        /**
+        * The TNC Client calls this function to deliver a message to the IMC.
+        * The message is contained in the buffer referenced by message and contains
+        * the number of octets indicated by messageLength. The type of the message
+        * is indicated by the message Vendor ID and message subtype.
+        *
+        * @param imcID                                 IMC ID assigned by TNCS
+        * @param connectionID                  network connection ID assigned by TNCC
+        * @param messageFlags                  message flags
+        * @param message                               reference to buffer containing message
+        * @param messageLength                 number of octets in message
+        * @param messageVendorID               message Vendor ID
+        * @param messageSubtype                message subtype
+        * @param sourceIMVID                   source IMV ID
+        * @param destinationIMCID              destination IMC ID
+        * @return                                              TNC result code
+        */
+       TNC_Result (*receive_message_long)(TNC_IMCID imcID,
+                                                                          TNC_ConnectionID connectionID,
+                                                                          TNC_UInt32 messageFlags,
+                                                                          TNC_BufferReference message,
+                                                                          TNC_UInt32 messageLength,
+                                                                          TNC_VendorID messageVendorID,
+                                                                          TNC_MessageSubtype messageSubtype,
+                                                                          TNC_UInt32 sourceIMVID,
+                                                                          TNC_UInt32 destinationIMCID);
+
+       /**
         * The TNC Client calls this function to notify IMCs that all IMV messages
         * received in a batch have been delivered and this is the IMC’s last chance
         * to send a message in the batch of IMC messages currently being collected.
@@ -187,10 +214,12 @@ struct imc_t {
        /**
         * Check if the IMC supports a given message type.
         *
-        * @param message_type                  message type
+        * @param msg_vid                               message vendor ID
+        * @param msg_subtype                   message subtype
         * @return                                              TRUE if supported
         */
-       bool (*type_supported)(imc_t *this, TNC_MessageType message_type);
+       bool (*type_supported)(imc_t *this, TNC_VendorID msg_vid,
+                                                                               TNC_MessageSubtype msg_subtype);
 
        /**
         * Destroys an imc_t object.
index ef2dcc6..25e0efe 100644 (file)
@@ -128,16 +128,24 @@ struct imc_manager_t {
        /**
         * Delivers a message to interested IMCs.
         *
-        * @param connection_id         ID of connection over which message was received
-        * @param message                       message
-        * @param message_len           message length
-        * @param message_type          message type
+        * @param connection_id                 connection ID
+        * @param excl                                  exclusive message flag
+        * @param msg                                   message
+        * @param msg_len                               message length
+        * @param msg_vid                               message Vendor ID
+        * @param msg_subtype                   message subtype
+        * @param src_imv_id                    source IMV ID
+        * @param dst_imc_id                    destination IMC ID
         */
        void (*receive_message)(imc_manager_t *this,
                                                        TNC_ConnectionID connection_id,
-                                                       TNC_BufferReference message,
-                                                       TNC_UInt32 message_len,
-                                                       TNC_MessageType message_type);
+                                                       bool excl,
+                                                       TNC_BufferReference msg,
+                                                       TNC_UInt32 msg_len,
+                                                       TNC_VendorID msg_vid,
+                                                       TNC_MessageSubtype msg_subtype,
+                                                       TNC_UInt32 src_imv_id,
+                                                       TNC_UInt32 dst_imc_id);
 
        /**
         * Notify all IMCs that all IMV messages received in a batch have been
index 67de8a4..3716532 100644 (file)
@@ -96,6 +96,33 @@ struct imv_t {
                                                                  TNC_MessageType messageType);
 
        /**
+        * The TNC Server calls this function to deliver a message to the IMV.
+        * The message is contained in the buffer referenced by message and contains
+        * the number of octets indicated by messageLength. The type of the message
+        * is indicated by the message Vendor ID and message subtype.
+        *
+        * @param imvID                                 IMV ID assigned by TNCS
+        * @param connectionID                  network connection ID assigned by TNCS
+        * @param messageFlags                  message flags
+        * @param message                               reference to buffer containing message
+        * @param messageLength                 number of octets in message
+        * @param messageVendorID               message Vendor ID
+        * @param messageSubtype                message subtype
+        * @param sourceIMCID                   source IMC ID
+        * @param destinationIMVID              destination IMV ID
+        * @return                                              TNC result code
+        */
+       TNC_Result (*receive_message_long)(TNC_IMVID imvID,
+                                                                          TNC_ConnectionID connectionID,
+                                                                          TNC_UInt32 messageFlags,
+                                                                          TNC_BufferReference message,
+                                                                          TNC_UInt32 messageLength,
+                                                                          TNC_VendorID messageVendorID,
+                                                                          TNC_MessageSubtype messageSubtype,
+                                                                          TNC_UInt32 sourceIMCID,
+                                                                          TNC_UInt32 destinationIMVID);
+
+       /**
         * The TNC Server calls this function to notify IMVs that all IMC messages
         * received in a batch have been delivered and this is the IMV’s last chance
         * to send a message in the batch of IMV messages currently being collected.
@@ -187,10 +214,12 @@ struct imv_t {
        /**
         * Check if the IMV supports a given message type.
         *
-        * @param message_type                  message type
+        * @param msg_vid                               message vendor ID
+        * @param msg_subtype                   message subtype
         * @return                                              TRUE if supported
         */
-       bool (*type_supported)(imv_t *this, TNC_MessageType message_type);
+       bool (*type_supported)(imv_t *this, TNC_VendorID msg_vid,
+                                                                               TNC_MessageSubtype msg_subtype);
 
        /**
         * Destroys an imv_t object.
index 780d0f6..43f4097 100644 (file)
@@ -149,16 +149,24 @@ struct imv_manager_t {
        /**
         * Delivers a message to interested IMVs.
         *
-        * @param connection_id         ID of connection over which message was received
-        * @param message                       message
-        * @param message_len           message length
-        * @param message_type          message type
+        * @param connection_id                 connection ID
+        * @param excl                                  exclusive message flag
+        * @param msg                                   message
+        * @param msg_len                               message length
+        * @param msg_vid                               message Vendor ID
+        * @param msg_subtype                   message subtype
+        * @param src_imc_id                    source IMC ID
+        * @param dst_imv_id                    destination IMV ID
         */
        void (*receive_message)(imv_manager_t *this,
                                                        TNC_ConnectionID connection_id,
-                                                       TNC_BufferReference message,
-                                                       TNC_UInt32 message_len,
-                                                       TNC_MessageType message_type);
+                                                       bool excl,
+                                                       TNC_BufferReference msg,
+                                                       TNC_UInt32 msg_len,
+                                                       TNC_VendorID msg_vid,
+                                                       TNC_MessageSubtype msg_subtype,
+                                                       TNC_UInt32 src_imc_id,
+                                                       TNC_UInt32 dst_imv_id);
 
        /**
         * Notify all IMVs that all IMC messages received in a batch have been