|
@@ -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;
|
|
|
}
|
|
|
|