resp_->addOption(client_id);
}
- // If this packet is relayed, we want to copy Relay Agent Info option
- // when it is not empty.
- OptionPtr rai = query_->getOption(DHO_DHCP_AGENT_OPTIONS);
- if (rai && (rai->len() > Option::OPTION4_HDR_LEN)) {
- resp_->addOption(rai);
- }
-
// RFC 3011 states about the Subnet Selection Option
// "Servers configured to support this option MUST return an
if (subnet_sel) {
resp_->addOption(subnet_sel);
}
+
+ // If this packet is relayed, we want to copy Relay Agent Info option
+ // when it is not empty.
+ OptionPtr rai = query_->getOption(DHO_DHCP_AGENT_OPTIONS);
+ if (!rai || (rai->len() <= Option::OPTION4_HDR_LEN)) {
+ return;
+ }
+ // Do not copy recovered stashed RAI.
+ ConstElementPtr sao = CfgMgr::instance().getCurrentCfg()->
+ getConfiguredGlobal(CfgGlobals::STASH_AGENT_OPTIONS);
+ if (sao && (sao->getType() == data::Element::boolean) &&
+ sao->boolValue() && query_->inClass("STASH_AGENT_OPTIONS")) {
+ return;
+ }
+ resp_->addOption(rai);
}
void
cfg_iface->use(AF_INET, "eth0");
cfg_iface->use(AF_INET, "eth1");
cfg_iface->setOutboundIface(CfgIface::USE_ROUTING);
- CfgMgr::instance().commit();;
+ CfgMgr::instance().commit();
// Create the instance of the incoming packet.
boost::shared_ptr<Pkt4> req(new Pkt4(DHCPDISCOVER, 1234));
EXPECT_EQ(IOAddress("192.0.2.3"), subnet_addr);
}
+// This test verifies that recovered stashed agent options are not copied
+// into responses.
+TEST_F(Dhcpv4SrvTest, stashAgentOption) {
+ // Get a DISCOVER with a RAI.
+ Pkt4Ptr query = PktCaptures::captureRelayedDiscover();
+ ASSERT_NO_THROW(query->unpack());
+
+ // Get Relay Agent Info from query...
+ OptionPtr rai_query = query->getOption(DHO_DHCP_AGENT_OPTIONS);
+ ASSERT_TRUE(rai_query);
+
+ // Create exchange and get Response.
+ Dhcpv4Exchange ex = createExchange(query);
+ Pkt4Ptr response = ex.getResponse();
+ ASSERT_TRUE(response);
+
+ // Get Relay Agent Info from response...
+ OptionPtr rai_response = response->getOption(DHO_DHCP_AGENT_OPTIONS);
+ ASSERT_TRUE(rai_response);
+ EXPECT_TRUE(rai_response->equals(rai_query));
+
+ // Set the stash-agent-options.
+ CfgMgr::instance().clear();
+ CfgMgr::instance().getStagingCfg()->
+ addConfiguredGlobal("stash-agent-options", Element::create(true));
+ CfgMgr::instance().commit();
+
+ // Create exchange and get Response.
+ ex = createExchange(query);
+ response = ex.getResponse();
+ ASSERT_TRUE(response);
+ rai_response = response->getOption(DHO_DHCP_AGENT_OPTIONS);
+ ASSERT_TRUE(rai_response);
+ EXPECT_TRUE(rai_response->equals(rai_query));
+
+ // Put the query in the STASH_AGENT_OPTIONS class.
+ query->addClass("STASH_AGENT_OPTIONS");
+
+ // Retry: this time the RAI is not copied.
+ ex = createExchange(query);
+ response = ex.getResponse();
+ ASSERT_TRUE(response);
+ rai_response = response->getOption(DHO_DHCP_AGENT_OPTIONS);
+ EXPECT_FALSE(rai_response);
+}
+
// This test verifies that the server identifier option is appended to
// a specified DHCPv4 message and the server identifier is correct.
TEST_F(Dhcpv4SrvTest, appendServerID) {