Commit c7114bab authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[3316] Vendor class content is now prefixed with VENDOR_CLASS_PREFIX.

parent d1c6e7d8
......@@ -80,6 +80,8 @@ Dhcp4Hooks Hooks;
namespace isc {
namespace dhcp {
const std::string Dhcpv4Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
Dhcpv4Srv::Dhcpv4Srv(uint16_t port, const char* dbconfig, const bool use_bcast,
const bool direct_response_desired)
: shutdown_(true), alloc_engine_(), port_(port),
......@@ -1812,15 +1814,15 @@ void Dhcpv4Srv::classifyPacket(const Pkt4Ptr& pkt) {
// quals subscriber-id option that was inserted by the relay (CMTS).
// This kind of logic will appear here soon.
if (vendor_class->getValue().find(DOCSIS3_CLASS_MODEM) != std::string::npos) {
pkt->addClass(DOCSIS3_CLASS_MODEM);
classes += string(DOCSIS3_CLASS_MODEM) + " ";
pkt->addClass(VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_MODEM);
classes += string(VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_MODEM) + " ";
} else
if (vendor_class->getValue().find(DOCSIS3_CLASS_EROUTER) != std::string::npos) {
pkt->addClass(DOCSIS3_CLASS_EROUTER);
classes += string(DOCSIS3_CLASS_EROUTER) + " ";
pkt->addClass(VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_EROUTER);
classes += string(VENDOR_CLASS_PREFIX + DOCSIS3_CLASS_EROUTER) + " ";
} else {
classes += vendor_class->getValue();
pkt->addClass(vendor_class->getValue());
classes += VENDOR_CLASS_PREFIX + vendor_class->getValue();
pkt->addClass(VENDOR_CLASS_PREFIX + vendor_class->getValue());
}
if (!classes.empty()) {
......
......@@ -405,6 +405,14 @@ protected:
/// @param [out] answer A response message to be sent to a client.
void processClientName(const Pkt4Ptr& query, Pkt4Ptr& answer);
/// @brief this is a prefix added to the contend of vendor-class option
///
/// If incoming packet has a vendor class option, its content is
/// prepended with this prefix and then interpreted as a class.
/// For example, a packet that sends vendor class with value of "FOO"
/// will cause the packet to be assigned to class VENDOR_CLASS_FOO.
static const std::string VENDOR_CLASS_PREFIX;
private:
/// @brief Process Client FQDN %Option sent by a client.
///
......
......@@ -3294,8 +3294,8 @@ TEST_F(Dhcpv4SrvTest, clientClassification) {
srv.classifyPacket(dis1);
EXPECT_TRUE(dis1->inClass("docsis3.0"));
EXPECT_FALSE(dis1->inClass("eRouter1.0"));
EXPECT_TRUE(dis1->inClass(srv.VENDOR_CLASS_PREFIX + "docsis3.0"));
EXPECT_FALSE(dis1->inClass(srv.VENDOR_CLASS_PREFIX + "eRouter1.0"));
// Let's create a relayed DISCOVER. This particular relayed DISCOVER has
// vendor-class set to eRouter1.0
......@@ -3305,8 +3305,8 @@ TEST_F(Dhcpv4SrvTest, clientClassification) {
srv.classifyPacket(dis2);
EXPECT_TRUE(dis2->inClass("eRouter1.0"));
EXPECT_FALSE(dis2->inClass("docsis3.0"));
EXPECT_TRUE(dis2->inClass(srv.VENDOR_CLASS_PREFIX + "eRouter1.0"));
EXPECT_FALSE(dis2->inClass(srv.VENDOR_CLASS_PREFIX + "docsis3.0"));
}
// This test verifies that the direct message is dropped when it has been
......
......@@ -199,6 +199,8 @@ public:
using Dhcpv4Srv::classifyPacket;
using Dhcpv4Srv::accept;
using Dhcpv4Srv::acceptMessageType;
using Dhcpv4Srv::VENDOR_CLASS_PREFIX;
};
class Dhcpv4SrvTest : public ::testing::Test {
......
......@@ -100,6 +100,8 @@ Dhcp6Hooks Hooks;
namespace isc {
namespace dhcp {
const std::string Dhcpv6Srv::VENDOR_CLASS_PREFIX("VENDOR_CLASS_");
namespace {
// The following constants describe server's behavior with respect to the
......@@ -2447,10 +2449,10 @@ void Dhcpv6Srv::classifyPacket(const Pkt6Ptr& pkt) {
std::ostringstream classes;
if (vclass->hasTuple(DOCSIS3_CLASS_MODEM)) {
classes << "VENDOR_CLASS_" << DOCSIS3_CLASS_MODEM;
classes << VENDOR_CLASS_PREFIX << DOCSIS3_CLASS_MODEM;
} else if (vclass->hasTuple(DOCSIS3_CLASS_EROUTER)) {
classes << DOCSIS3_CLASS_EROUTER;
classes << VENDOR_CLASS_PREFIX << DOCSIS3_CLASS_EROUTER;
} else {
classes << vclass->getTuple(0).getText();
......
......@@ -536,6 +536,15 @@ protected:
/// @param pkt packet to be classified
void classifyPacket(const Pkt6Ptr& pkt);
/// @brief this is a prefix added to the contend of vendor-class option
///
/// If incoming packet has a vendor class option, its content is
/// prepended with this prefix and then interpreted as a class.
/// For example, a packet that sends vendor class with value of "FOO"
/// will cause the packet to be assigned to class VENDOR_CLASS_FOO.
static const std::string VENDOR_CLASS_PREFIX;
private:
/// @brief Implements the error handler for socket open failure.
......
......@@ -1734,8 +1734,8 @@ TEST_F(Dhcpv6SrvTest, clientClassification) {
srv.classifyPacket(sol2);
EXPECT_TRUE(sol2->inClass("eRouter1.0"));
EXPECT_FALSE(sol2->inClass("docsis3.0"));
EXPECT_TRUE(sol2->inClass(srv.VENDOR_CLASS_PREFIX + "eRouter1.0"));
EXPECT_FALSE(sol2->inClass(srv.VENDOR_CLASS_PREFIX + "docsis3.0"));
}
// This test checks that the server will handle a Solicit with the Vendor Class
......
......@@ -118,6 +118,7 @@ public:
using Dhcpv6Srv::writeServerID;
using Dhcpv6Srv::unpackOptions;
using Dhcpv6Srv::name_change_reqs_;
using Dhcpv6Srv::VENDOR_CLASS_PREFIX;
/// @brief packets we pretend to receive
///
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment