Jelajahi Sumber

Merge branch 'master' of bitbucket.org:ikflowdat/kea

Espinoza Guillermo 6 tahun lalu
induk
melakukan
b45a8d4633

+ 16 - 1
.gitignore

@@ -31,4 +31,19 @@ hooks/mysql/src/mysql_connection.d
 hooks/mysql/src/mysql_connection.o
 hooks/mysql/src/version.d
 hooks/mysql/src/version.o
-hooks/mysql/core
+hooks/mysql/core
+hooks/kea-cm-hook/kea-hook-flowdat.so
+hooks/kea-cm-hook/s-messages
+hooks/kea-cm-hook/src/callouts.d
+hooks/kea-cm-hook/src/callouts.o
+hooks/kea-cm-hook/src/load.d
+hooks/kea-cm-hook/src/load.o
+hooks/kea-cm-hook/src/logger.d
+hooks/kea-cm-hook/src/logger.o
+hooks/kea-cm-hook/src/messages.cc
+hooks/kea-cm-hook/src/messages.d
+hooks/kea-cm-hook/src/messages.h
+hooks/kea-cm-hook/src/messages.o
+hooks/kea-cm-hook/src/version.d
+hooks/kea-cm-hook/src/version.o
+hooks/kea-cm-hook/core

+ 1 - 4
1.4.0/kea-ik/Dockerfile

@@ -4,7 +4,7 @@ FROM docker.infra.flowdat.com/fd3/kea-oss-1.4.0:latest
 
 RUN git clone git://github.com/alanxz/rabbitmq-c.git
 RUN apt-get update && apt-get install -yq cmake
-RUN cd rabbitmq-c && mkdir build && cd build && cmake .. && cmake --build . 
+RUN cd rabbitmq-c && mkdir build && cd build && cmake .. && cmake --build .
 RUN cd rabbitmq-c/build && make  && make install
 
 RUN git clone https://github.com/akalend/amqpcpp
@@ -29,9 +29,6 @@ RUN mkdir ~/.ssh
 RUN ssh-keyscan -H -p 22  bitbucket.org >> ~/.ssh/known_hosts
 COPY keys/ /opt/keys
 RUN chmod 0600 /opt/keys/bitbucket.id_rsa
-RUN eval $(ssh-agent) && ssh-add /opt/keys/bitbucket.id_rsa && git clone git@bitbucket.org:ikflowdat/kea-cm-hook.git
-
-RUN cd kea-cm-hook && git checkout kea-test && make
 
 COPY inotify.sh /usr/local/etc/kea/inotify.sh
 

+ 1 - 0
1.4.0/kea-ik/inotify.sh

@@ -1,5 +1,6 @@
 while true
 do
     inotifywait -e create -e modify /usr/local/etc/kea/kea-dhcp4.conf
+    sleep 10
     keactrl stop
 done

+ 1 - 0
1.4.0/kea-ik/script.sh

@@ -11,5 +11,6 @@ kea-admin lease-init mysql -h mysql -u $MYSQL_USER -p $MYSQL_ROOT_PASSWORD -n $D
 
 cd /opt/hooks/amqp && make
 cd /opt/hooks/mysql && make
+cd /opt/hooks/kea-cm-hook && make
 
 supervisord --configuration /etc/supervisord/supervisor.conf  --nodaemon

+ 99 - 99
hooks/kea-cm-hook/src/callouts.cc

@@ -22,7 +22,7 @@ extern "C" {
 
 #include <numeric>    //inner_product
 #include <functional> //plus, equal_to, not2
-#include <string>   
+#include <string>
 #include <stdexcept>
 
 std::string getMacFromPacket(Pkt4Ptr);
@@ -30,60 +30,60 @@ std::string getMacFromPacket(Pkt4Ptr);
 enum HostType{ CABLEMODEM, EMTA, CPE};
 std::string HostClass[] = { "cm", "mta", "cpe"};
 
-HostType getHostType(Pkt4Ptr pkt){
+HostType getHostType(Pkt4Ptr pkt)
+{
     HostType rtr = CPE;
     std::string cm_mac = getMacFromPacket(pkt);
 
     //Non Empty MAC
-    if(cm_mac.size() != 0){
-
-	//std::string chwdr = pkt->getMAC(HWAddr::HWADDR_SOURCE_RAW)->toText(false);
-	std::string chwdr = pkt->getHWAddr()->toText(false);
-	isc::util::str::uppercase(chwdr);
-	chwdr.erase(std::remove(chwdr.begin(), chwdr.end(), ':'), chwdr.end());
-
-	std::string opt82mac = "";
-
-        if(pkt->getOption(DHO_DHCP_AGENT_OPTIONS)){
-	    opt82mac = pkt->getOption(DHO_DHCP_AGENT_OPTIONS)->toHexString(false).substr(6,12);
-
-	    std::vector<uint8_t> binary;
-	    isc::util::str::decodeFormattedHexString(opt82mac, binary);
-	}
-		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("hwaddr: " + chwdr);
-		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("remoteid: "+opt82mac);
-
-	if(chwdr == opt82mac){
-		rtr = CABLEMODEM;
-
-		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("option 82 mac == chwdr ==> CABLEMODEM");
-	}else {
-		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("dou't " + chwdr + " !== " + opt82mac);
-
-		if(pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)){
-			std::string docsis_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(0,6);
-			std::string pktc_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(0,4);
-
-			LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("Checking Vendor Class ID");
-			if(docsis_vendor_class.compare("docsis") == 0){
-				rtr = CABLEMODEM;
-				LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("docsis en vendor class ==> CABLEMODEM");
-			} else {
-				if(pktc_vendor_class.compare("pktc") == 0){
-					rtr = EMTA;
-					LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pktc en vendor class ==> EMTA");
-				} else {
-					LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("vendor class unknown");
-				}
-			}
-		}else{
-					LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("no vendor class");
-		}
-	}
+    if (cm_mac.size() != 0) {
+    	//std::string chwdr = pkt->getMAC(HWAddr::HWADDR_SOURCE_RAW)->toText(false);
+    	std::string chwdr = pkt->getHWAddr()->toText(false);
+    	isc::util::str::uppercase(chwdr);
+    	chwdr.erase(std::remove(chwdr.begin(), chwdr.end(), ':'), chwdr.end());
+
+    	std::string opt82mac = "";
+
+        if (pkt->getOption(DHO_DHCP_AGENT_OPTIONS)) {
+    	    opt82mac = pkt->getOption(DHO_DHCP_AGENT_OPTIONS)->toHexString(false).substr(6,12);
+
+    	    std::vector<uint8_t> binary;
+    	    isc::util::str::decodeFormattedHexString(opt82mac, binary);
+    	}
+		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> hwaddr: " + chwdr);
+		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> remoteid: " + opt82mac);
+
+    	if (chwdr == opt82mac) {
+    		rtr = CABLEMODEM;
+
+    		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> option 82 mac == chwdr ==> CABLEMODEM");
+    	} else {
+    		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> dou't " + chwdr + " !== " + opt82mac);
+
+    		if (pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)) {
+    			std::string docsis_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(0,6);
+    			std::string pktc_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(0,4);
+
+    			LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> Checking Vendor Class ID");
+    			if (docsis_vendor_class.compare("docsis") == 0) {
+    				rtr = CABLEMODEM;
+    				LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> docsis en vendor class ==> CABLEMODEM");
+    			} else {
+    				if (pktc_vendor_class.compare("pktc") == 0) {
+    					rtr = EMTA;
+    					LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> pktc en vendor class ==> EMTA");
+    				} else {
+    					LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> vendor class unknown");
+    				}
+    			}
+    		} else {
+                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> no vendor class");
+    		}
+    	}
     } else {
-	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("Empty MAC fomr getMacFromPacket ==> CPE " + std::to_string(cm_mac.size()));
-	    if(pkt->isRelayed()){
-		    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("Pakcet Relayed");
+	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> Empty MAC fomr getMacFromPacket ==> CPE " + std::to_string(cm_mac.size()));
+	    if (pkt->isRelayed()) {
+		    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> Packet Relayed");
 	    }
 	    //LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("HWAddr " + pkt->getMAC(HWAddr::HWADDR_SOURCE_ANY)->toText());
     }
@@ -94,67 +94,69 @@ HostType getHostType(Pkt4Ptr pkt){
 /**
  * 	Get the cablemodem mac from (option 82) or if vendor_class is *docsis* get the c_hwaddr
  */
-std::string getMacFromPacket(Pkt4Ptr pkt){
+std::string getMacFromPacket(Pkt4Ptr pkt)
+{
     std::string rtr = "";
-    if(pkt->getOption(DHO_DHCP_AGENT_OPTIONS)){
-	    //rtr = pkt->getOption(DHO_DHCP_AGENT_OPTIONS)->toHexString(false).substr(26,12);
+    if (pkt->getOption(DHO_DHCP_AGENT_OPTIONS)) {
+        //rtr = pkt->getOption(DHO_DHCP_AGENT_OPTIONS)->toHexString(false).substr(26,12);
 	    rtr = pkt->getOption(DHO_DHCP_AGENT_OPTIONS)->toHexString(false).substr(6,12);
 
 	    std::vector<uint8_t> binary;
 	    isc::util::str::decodeFormattedHexString(rtr, binary);
 
-	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket... from option 82 " + rtr);
-    }else if(pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)){
-	std::string docsis_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(2,6);
-	if(docsis_vendor_class.compare("docsis") == 0){
-		rtr = pkt->getMAC(HWAddr::HWADDR_SOURCE_RAW)->toText(false);
-		isc::util::str::uppercase(rtr);
-		rtr.erase(std::remove(rtr.begin(), rtr.end(), ':'), rtr.end());
-		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket is vendor class 'docsis' chwaddr..." + rtr);
-	}
+	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket -> from option 82 " + rtr);
+    } else if(pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)) {
+        std::string docsis_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(2,6);
+        if (docsis_vendor_class.compare("docsis") == 0) {
+            rtr = pkt->getMAC(HWAddr::HWADDR_SOURCE_RAW)->toText(false);
+            isc::util::str::uppercase(rtr);
+            rtr.erase(std::remove(rtr.begin(), rtr.end(), ':'), rtr.end());
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket -> is vendor class 'docsis' chwaddr..." + rtr);
+        }
     }
 
     return rtr;
 }
 
 /* IPv4 callouts */
-int pkt4_receive(CalloutHandle& handle) {
+int pkt4_receive(CalloutHandle& handle)
+{
     Pkt4Ptr query;
     handle.getArgument("query4", query);
 
     std::vector<std::string> list_class;
 
-
     std::string mac = getMacFromPacket(query);
     HWAddrPtr remote_id;
-   
+
     HostType ht = getHostType(query);
-	
+
     list_class.push_back(HostClass[ht]);
     std::map<std::string,std::string>::iterator it = cm_map.find(mac);
-    if (it != cm_map.end()){
-	list_class.push_back(cm_map[mac]);
+    if (it != cm_map.end()) {
+    	list_class.push_back(cm_map[mac]);
     }
 
     std::string me, me2;
 
     BOOST_FOREACH(me, list_class) {
-         LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("class  : " + me);
+        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_receive -> class  : " + me);
 
-         BOOST_FOREACH(me2, list_class) {
-         	if(me.compare(me2) != 0){
-         		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("class  : " + me + "-" + me2);
+        BOOST_FOREACH(me2, list_class) {
+         	if (me.compare(me2) != 0) {
+                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_receive -> class  : " + me + "-" + me2);
          		query->addClass(me + "-" + me2);
          	}
-         }
+        }
 
-         query->addClass(me);
+        query->addClass(me);
     }
 
     return 0;
 }
 
-int pkt4_send(CalloutHandle& handle) {
+int pkt4_send(CalloutHandle& handle)
+{
     Pkt4Ptr response;
     Pkt4Ptr query;
     handle.getArgument("response4", response);
@@ -164,10 +166,10 @@ int pkt4_send(CalloutHandle& handle) {
     std::string mac;
 
     HostType ht = getHostType(query);
-    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("ht : " + std::to_string(ht));
+    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> HostType : " + std::to_string(ht));
 
-    if(ht == CABLEMODEM or ht == EMTA){
-	mac = getMacFromPacket(query);
+    if (ht == CABLEMODEM or ht == EMTA) {
+        mac = getMacFromPacket(query);
     }
 
     //OptionStringPtr asc1(new OptionString(Option::V4, 43, "http://asc-test.org:7547/"));
@@ -177,53 +179,51 @@ int pkt4_send(CalloutHandle& handle) {
     //response->addOption(asc2);
 
 
-    if(ht == CABLEMODEM){
+    if (ht == CABLEMODEM) {
 	    std::string file = mac + ".bin";
 	    isc::util::str::lowercase(file);
 
-	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("file : " + file);
+	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> CM file : " + file);
 	    strcpy((char*)ufile_name, file.c_str());
-    	    response->setFile(ufile_name, strlen((char *)ufile_name));
+        response->setFile(ufile_name, strlen((char *)ufile_name));
 
 	    std::map<std::string,std::string>::iterator it = option122_map.find(mac);
 
-	    if (it != option122_map.end()){
-                  LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("cablemodem " + mac + " found for MTA Activation on " + option122_map[mac]);
-		  OptionPtr option1(new Option(Option::V4, 122));
-
+	    if (it != option122_map.end()) {
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> cablemodem " + mac + " found for MTA Activation on " + option122_map[mac]);
 
- 		  Option4AddrLstPtr opt_server(new Option4AddrLst(1));
-		  opt_server->setAddress(isc::asiolink::IOAddress("255.255.255.255"));//option122_map[mac]));
-	
- 		  OptionStringPtr opt_basic1(new OptionString(Option::V4, 6, "BASIC.1"));
+            Option4AddrLstPtr opt_server(new Option4AddrLst(1));
+            opt_server->setAddress(isc::asiolink::IOAddress("255.255.255.255"));
 
-		  option1->addOption(opt_server);
-		  option1->addOption(opt_basic1);
+            OptionStringPtr opt_basic1(new OptionString(Option::V4, 6, "BASIC.1"));
 
-		  response->addOption(option1);
-	    }else{
+            OptionPtr option1(new Option(Option::V4, 122));
+            option1->addOption(opt_server);
+            option1->addOption(opt_basic1);
 
-            	  LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("cablemodem " + mac + " not found for MTA Activation");
+            response->addOption(option1);
+	    } else {
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> cablemodem " + mac + " not found for MTA Activation");
 	    }
     }
 
-    if(ht == EMTA){
+    if (ht == EMTA) {
 	    std::string file = mac + ".mta.bin";
 	    isc::util::str::lowercase(file);
 
 	    std::map<std::string,std::string>::iterator it = option122_map.find(mac);
 
-	    if (it != option122_map.end()){
+	    if (it != option122_map.end()) {
 	        std::string file = mac + ".mta.bin";
 	        isc::util::str::lowercase(file);
 
-	        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("file : " + file);
+	        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> EMTA file : " + file);
 	        strcpy((char*)ufile_name, file.c_str());
 	        response->setFile(ufile_name, strlen((char *)ufile_name));
 
 	        isc::util::str::lowercase(mac);
- 		OptionStringPtr opt_domain(new OptionString(Option::V4, DHO_HOST_NAME, mac));
-		response->addOption(opt_domain);
+            OptionStringPtr opt_domain(new OptionString(Option::V4, DHO_HOST_NAME, mac));
+            response->addOption(opt_domain);
 	    }
     }
 

+ 6 - 1
hooks/kea-cm-hook/src/load.cc

@@ -17,12 +17,17 @@ extern "C" {
 int loadMappging(std::string base_map_config, LibraryHandle& handle, std::map<std::string, std::string>& map){
 
     ConstElementPtr curr_map = handle.getParameter(base_map_config);
+    // no viene definido el parametro
+    if (!curr_map) {
+        return 0;
+    }
+
     if (Element::map != curr_map->getType()){
         LOG_ERROR(runscript_logger, RUNSCRIPT_MISTYPED_PARAM).arg(base_map_config);
         return 1;
     }
 
-    std::map<std::string, ConstElementPtr> map_config = curr_map->mapValue();;
+    std::map<std::string, ConstElementPtr> map_config = curr_map->mapValue();
     std::pair<std::string, ConstElementPtr> me; 
 
     BOOST_FOREACH(me, map_config) {

+ 64 - 51
hooks/mysql/src/callouts.cc

@@ -28,7 +28,7 @@ extern "C" {
 #include <numeric>    //inner_product
 #include <functional> //plus, equal_to, not2
 #include <algorithm>
-#include <string>   
+#include <string>
 #include <stdexcept>
 
 #include "mysql_connection.h"
@@ -39,23 +39,23 @@ std::string getMacFromPacket(Pkt4Ptr);
 /**
  * 	Get the cablemodem mac from (option 82) or if vendor_class is *docsis* get the c_hwaddr
  */
-std::string getMacFromPacket(Pkt4Ptr pkt) 
+std::string getMacFromPacket(Pkt4Ptr pkt)
 {
     std::string rtr = "";
     if (pkt->getOption(DHO_DHCP_AGENT_OPTIONS)) {
 	    rtr = pkt->getOption(DHO_DHCP_AGENT_OPTIONS)->toHexString(false).substr(6,12);
 	    std::vector<uint8_t> binary;
 	    isc::util::str::decodeFormattedHexString(rtr, binary);
-        
-        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket... from option 82 " + rtr);
+
+        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket -> from option 82 " + rtr);
     } else if (pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)) {
         std::string docsis_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(2,6);
         if (docsis_vendor_class.compare("docsis") == 0) {
     		rtr = pkt->getMAC(HWAddr::HWADDR_SOURCE_RAW)->toText(false);
     		isc::util::str::uppercase(rtr);
     		rtr.erase(std::remove(rtr.begin(), rtr.end(), ':'), rtr.end());
-            
-            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket is vendor class 'docsis' chwaddr..." + rtr);
+
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getMacFromPacket -> is vendor class 'docsis' chwaddr..." + rtr);
         }
     }
 
@@ -76,51 +76,51 @@ HostType getHostType(Pkt4Ptr pkt)
         std::string chwdr = pkt->getHWAddr()->toText(false);
         isc::util::str::uppercase(chwdr);
         chwdr.erase(std::remove(chwdr.begin(), chwdr.end(), ':'), chwdr.end());
-        
+
         std::string opt82mac = "";
 
         if (pkt->getOption(DHO_DHCP_AGENT_OPTIONS)) {
             opt82mac = pkt->getOption(DHO_DHCP_AGENT_OPTIONS)->toHexString(false).substr(6,12);
-            
+
             std::vector<uint8_t> binary;
             isc::util::str::decodeFormattedHexString(opt82mac, binary);
         }
-		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("hwaddr: " + chwdr);
-		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("remoteid: " + opt82mac);
-        
+		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> hwaddr: " + chwdr);
+		LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> remoteid: " + opt82mac);
+
         if (chwdr == opt82mac) {
             rtr = CABLEMODEM;
-            
-            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("option 82 mac == chwdr ==> CABLEMODEM");
+
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> option 82 mac == chwdr ==> CABLEMODEM");
         } else {
-            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("dou't " + chwdr + " !== " + opt82mac);
-            
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> dou't " + chwdr + " !== " + opt82mac);
+
             if (pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)) {
                 std::string docsis_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(0,6);
                 std::string pktc_vendor_class = pkt->getOption(DHO_VENDOR_CLASS_IDENTIFIER)->toString().substr(0,4);
-                
-                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("docsis_vendor_class: " + docsis_vendor_class);
-                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pktc_vendor_class: " + pktc_vendor_class);
-                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("Checking Vendor Class ID");
+
+                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> docsis_vendor_class: " + docsis_vendor_class);
+                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> pktc_vendor_class: " + pktc_vendor_class);
+                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> Checking Vendor Class ID");
                 if (docsis_vendor_class.compare("docsis") == 0) {
                     rtr = CABLEMODEM;
-                    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("docsis en vendor class ==> CABLEMODEM");
+                    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> docsis en vendor class ==> CABLEMODEM");
                 } else {
                     if (pktc_vendor_class.compare("pktc") == 0) {
                         rtr = EMTA;
-                        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pktc en vendor class ==> EMTA");
+                        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> pktc en vendor class ==> EMTA");
                     } else {
-                        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("vendor class unknown");
+                        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> vendor class unknown");
                     }
                 }
             } else {
-                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("no vendor class");
+                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> no vendor class");
             }
         }
     } else {
-	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("Empty MAC fomr getMacFromPacket ==> CPE " + std::to_string(cm_mac.size()));
+	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> Empty MAC from getMacFromPacket ==> CPE " + std::to_string(cm_mac.size()));
 	    if (pkt->isRelayed()) {
-		    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("Pakcet Relayed");
+		    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("getHostType -> Packet Relayed");
 	    }
     }
 
@@ -135,11 +135,11 @@ HostType getHostType(Pkt4Ptr pkt)
 /// @param handle CalloutHandle which provides access to context.
 ///
 /// @return 0 upon success, non-zero otherwise.
-int host4_identifier(CalloutHandle& handle) 
+int host4_identifier(CalloutHandle& handle)
 {
     Pkt4Ptr query;
     handle.getArgument("query4", query);
-    
+
     std::string mac = getMacFromPacket(query);
 
     HostType ht = getHostType(query);
@@ -151,37 +151,37 @@ int host4_identifier(CalloutHandle& handle)
 
     handle.setArgument("id_value", id);
     handle.setArgument("id_type", type);
-    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("cablemodem flex_id = " + isc::util::encode::encodeHex(id)  + "(" + HostClass[ht] + "*-*" + mac + ").");
+    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("host4_identifier -> cablemodem flex_id = " + isc::util::encode::encodeHex(id)  + "(" + HostClass[ht] + "*-*" + mac + ").");
 
     return CalloutHandle::NEXT_STEP_CONTINUE;
 }
 
 /* IPv4 callouts */
-int pkt4_receive(CalloutHandle& handle) 
+int pkt4_receive(CalloutHandle& handle)
 {
     Pkt4Ptr query;
     handle.getArgument("query4", query);
-    
+
     // Busco la class para la mac que viene en el paquete
     // en fd3_dhcp.host, si no existe el host cargado no tiene class
     std::string mac = getMacFromPacket(query);
     std::string MAC = mac;
     std::transform(mac.begin(), mac.end(), mac.begin(), ::tolower);
-    
+
     std::string sql_query = "SELECT state FROM `host` WHERE `mac` LIKE '" + mac + "';";
     std::string class_map = conn.executeQuery((sql_query).c_str());
     if (class_map != "") {
         cm_map[MAC] = class_map;
-        
-        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("cablemodem " + mac + " class " + class_map);
+
+        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_receive -> cablemodem " + mac + " class " + class_map);
     } else {
-        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("cablemodem " + mac + " class not found ");
+        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_receive -> cablemodem " + mac + " class not found ");
     }
-    
+
     std::vector<std::string> list_class;
     HWAddrPtr remote_id;
     HostType ht = getHostType(query);
-	
+
     list_class.push_back(HostClass[ht]);
     std::map<std::string,std::string>::iterator it = cm_map.find(MAC);
     if (it != cm_map.end()) {
@@ -190,23 +190,23 @@ int pkt4_receive(CalloutHandle& handle)
 
     std::string me, me2;
     BOOST_FOREACH(me, list_class) {
-         LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("class  : " + me);
+         LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_receive -> class  : " + me);
 
          BOOST_FOREACH(me2, list_class) {
          	if (me.compare(me2) != 0) {
-                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("class  : " + me + "-" + me2);
+                LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_receive -> class  : " + me + "-" + me2);
          		query->addClass(me + "-" + me2);
          	}
          }
 
          query->addClass(me);
-         
+
     }
-         
+
     return 0;
 }
 
-int pkt4_send(CalloutHandle& handle) 
+int pkt4_send(CalloutHandle& handle)
 {
     Pkt4Ptr response;
     Pkt4Ptr query;
@@ -217,7 +217,7 @@ int pkt4_send(CalloutHandle& handle)
     std::string mac;
 
     HostType ht = getHostType(query);
-    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("ht : " + std::to_string(ht));
+    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> HostType : " + std::to_string(ht));
 
     if (ht == CABLEMODEM or ht == EMTA) {
         mac = getMacFromPacket(query);
@@ -227,27 +227,27 @@ int pkt4_send(CalloutHandle& handle)
 	    std::string file = mac + ".bin";
 	    isc::util::str::lowercase(file);
 
-	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("file : " + file);
+	    LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> file : " + file);
 	    strcpy((char*)ufile_name, file.c_str());
     	    response->setFile(ufile_name, strlen((char *)ufile_name));
 
 	    std::map<std::string,std::string>::iterator it = option122_map.find(mac);
 
 	    if (it != option122_map.end()) {
-            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("cablemodem " + mac + " found for MTA Activation on " + option122_map[mac]);
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> cablemodem " + mac + " found for MTA Activation on " + option122_map[mac]);
             OptionPtr option1(new Option(Option::V4, 122));
-            
+
             Option4AddrLstPtr opt_server(new Option4AddrLst(1));
             opt_server->setAddress(isc::asiolink::IOAddress("255.255.255.255"));//option122_map[mac]));
-            
+
             OptionStringPtr opt_basic1(new OptionString(Option::V4, 6, "BASIC.1"));
-            
+
             option1->addOption(opt_server);
             option1->addOption(opt_basic1);
-            
+
             response->addOption(option1);
 	    } else {
-            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("cablemodem " + mac + " not found for MTA Activation");
+            LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> cablemodem " + mac + " not found for MTA Activation");
 	    }
     }
 
@@ -256,6 +256,19 @@ int pkt4_send(CalloutHandle& handle)
 	    isc::util::str::lowercase(file);
 
 	    std::map<std::string,std::string>::iterator it = option122_map.find(mac);
+
+        if (it != option122_map.end()) {
+	        std::string file = mac + ".mta.bin";
+	        isc::util::str::lowercase(file);
+
+	        LOG_INFO(runscript_logger, FLOWDAT_DEBUG_STRING).arg("pkt4_send -> EMTA file : " + file);
+	        strcpy((char*)ufile_name, file.c_str());
+	        response->setFile(ufile_name, strlen((char *)ufile_name));
+
+	        isc::util::str::lowercase(mac);
+            OptionStringPtr opt_domain(new OptionString(Option::V4, DHO_HOST_NAME, mac));
+            response->addOption(opt_domain);
+	    }
     }
 
     return 0;
@@ -267,11 +280,11 @@ int pkt6_receive(CalloutHandle& handle) {
     std::vector<std::string> env;
     Pkt6Ptr query;
     handle.getArgument("query6", query);
-    
+
     // std::string mac = getMacFromPacket(query);
     // std::string class_map = conn->executeQuery("SELECT state FROM fd3_dhcp.host WHERE mac=" + string(mac));
     // cm_map[mac] = class_map;
-    
+
     return 0;
 }