Luciano Andrade 6 vuotta sitten
vanhempi
commit
c6745ef9c9
3 muutettua tiedostoa jossa 43 lisäystä ja 12 poistoa
  1. 6 1
      hooks/README.md
  2. 4 4
      hooks/mysql/Makefile
  3. 33 7
      hooks/mysql/src/callouts.cc

+ 6 - 1
hooks/README.md

@@ -44,7 +44,12 @@ Configuración (/usr/local/etc/kea/kea-dhcp4.conf):
             },
             {
                 "library": "\/opt/hooks\/mysql\/kea-hook-flowdat3-mysql.so",
-                "parameters": ""
+                "parameters": {
+			"host": "mysql",
+			"database": "fd3_dhcp",
+			"password": "root",
+			"password": null
+		}
             },
             {
                 "library": "\/kea-cm-hook\/kea-hook-flowdat.so",

+ 4 - 4
hooks/mysql/Makefile

@@ -1,7 +1,7 @@
-
-KEA_MSG_COMPILER ?= /opt/kea/bin/kea-msg-compiler
-KEA_INCLUDE ?= ~/kea-1.3.0/src/lib
-KEA_LIB ?= /opt/kea/lib/
+KEA_PREFIX ?= /opt/kea.1.4
+KEA_MSG_COMPILER ?= ${KEA_PREFIX}/bin/kea-msg-compiler
+KEA_INCLUDE ?= ${KEA_PREFIX}/include/kea
+KEA_LIB ?= ${KEA_PREFIX}/lib/
 
 OBJECTS = src/messages.o src/logger.o src/load.o src/callouts.o src/version.o src/mysql_connection.o
 DEPS = $(OBJECTS:.o=.d)

+ 33 - 7
hooks/mysql/src/callouts.cc

@@ -5,6 +5,7 @@
 #include <dhcpsrv/lease.h>
 #include <dhcpsrv/host.h>
 #include <util/strutil.h>
+#include <util/encode/hex.h>
 #include <dhcp/option_string.h>
 #include <dhcp/option4_addrlst.h>
 #include <dhcp/docsis3_option_defs.h>
@@ -13,6 +14,7 @@
 #include <dhcp/pkt6.h>
 #include <dhcp/option6_ia.h>
 
+
 #include <boost/foreach.hpp>
 
 #include "logger.h"
@@ -58,6 +60,7 @@ std::string getMacFromPacket(Pkt4Ptr pkt)
 
 enum HostType{ CABLEMODEM, EMTA, CPE };
 std::string HostClass[] = { "cm", "mta", "cpe" };
+std::string HexHostClass[] = { "636d2d", "6d74612d", "6370652d" };
 
 HostType getHostType(Pkt4Ptr pkt)
 {
@@ -118,6 +121,35 @@ HostType getHostType(Pkt4Ptr pkt)
     return rtr;
 }
 
+
+/// @brief  This callout is called at the "host4_identifier" hook.
+///
+/// It retrieves v4 packet and then generates flexible identifier for it.
+///
+/// @param handle CalloutHandle which provides access to context.
+///
+/// @return 0 upon success, non-zero otherwise.
+int host4_identifier(CalloutHandle& handle) 
+{
+    Pkt4Ptr query;
+    handle.getArgument("query4", query);
+    
+    std::string mac = getMacFromPacket(query);
+
+    HostType ht = getHostType(query);
+    Host::IdentifierType type = Host::IDENT_FLEX;
+    //std::vector<uint8_t> id((me + "-" + mac).begin(), (me + "-" + mac).end());
+    std::string flex_id = std::string(HexHostClass[ht] + mac);
+    std::vector<uint8_t> id;
+    id.assign(flex_id.begin(), flex_id.end());
+
+    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 + ").");
+
+    return CalloutHandle::NEXT_STEP_CONTINUE;
+}
+
 /* IPv4 callouts */
 int pkt4_receive(CalloutHandle& handle) 
 {
@@ -163,14 +195,8 @@ int pkt4_receive(CalloutHandle& handle)
 
          query->addClass(me);
          
-         Host::IdentifierType type;
-         std::vector<uint8_t> id((me + "-" + mac).begin(), (me + "-" + mac).end());
-         type = Host::IDENT_FLEX;
-         
-         handle.setArgument("id_value", id);
-         handle.setArgument("id_type", type);
     }
-
+         
     return 0;
 }