Commit e9f4d7e5 authored by Marcin Siodelski's avatar Marcin Siodelski
Browse files

[3200] Respond with requested options only if lease has been assigned.

Conflicts:
	src/bin/dhcp4/dhcp4_srv.cc
	src/lib/dhcp/libdhcp++.cc
parent beac4c1b
......@@ -754,13 +754,6 @@ Dhcpv4Srv::assignLease(const Pkt4Ptr& question, Pkt4Ptr& answer) {
opt->setUint32(lease->valid_lft_);
answer->addOption(opt);
// Router (type 3)
Subnet::OptionDescriptor opt_routers =
subnet->getOptionDescriptor("dhcp4", DHO_ROUTERS);
if (opt_routers.option) {
answer->addOption(opt_routers.option);
}
// Subnet mask (type 1)
answer->addOption(getNetmaskOption(subnet));
......@@ -857,14 +850,17 @@ Dhcpv4Srv::processDiscover(Pkt4Ptr& discover) {
copyDefaultFields(discover, offer);
appendDefaultOptions(offer, DHCPOFFER);
appendRequestedOptions(discover, offer);
assignLease(discover, offer);
// There are a few basic options that we always want to
// include in the response. If client did not request
// them we append them for him.
appendBasicOptions(discover, offer);
// Adding any other options makes sense only when we got the lease.
if (offer->getYiaddr() != IOAddress("0.0.0.0")) {
appendRequestedOptions(discover, offer);
// There are a few basic options that we always want to
// include in the response. If client did not request
// them we append them for him.
appendBasicOptions(discover, offer);
}
return (offer);
}
......@@ -880,17 +876,20 @@ Dhcpv4Srv::processRequest(Pkt4Ptr& request) {
copyDefaultFields(request, ack);
appendDefaultOptions(ack, DHCPACK);
appendRequestedOptions(request, ack);
// Note that we treat REQUEST message uniformly, regardless if this is a
// first request (requesting for new address), renewing existing address
// or even rebinding.
assignLease(request, ack);
// There are a few basic options that we always want to
// include in the response. If client did not request
// them we append them for him.
appendBasicOptions(request, ack);
// Adding any other options makes sense only when we got the lease.
if (ack->getYiaddr() != IOAddress("0.0.0.0")) {
appendRequestedOptions(request, ack);
// There are a few basic options that we always want to
// include in the response. If client did not request
// them we append them for him.
appendBasicOptions(request, ack);
}
return (ack);
}
......
......@@ -321,7 +321,7 @@ void Dhcpv4SrvTest::testDiscoverRequest(const uint8_t msg_type) {
if (msg_type == DHCPDISCOVER) {
ASSERT_NO_THROW(
rsp = srv->processDiscover(req);
);
);
// Should return OFFER
ASSERT_TRUE(rsp);
......
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