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

[1230] Changes after review:

- appendRequestedOptions(), assignLease() added in dhcpv4_srv class.
- dhcpv4_srv now uses hardcoded values from 192.0.2.0/24 range.
parent 01a1b2f4
......@@ -28,13 +28,13 @@ using namespace isc::asiolink;
// These are hardcoded parameters. Currently this is a skeleton server that only
// grants those options and a single, fixed, hardcoded lease.
const std::string HARDCODED_LEASE = "10.3.2.222"; // assigned lease
const std::string HARDCODED_LEASE = "192.0.2.222"; // assigned lease
const std::string HARDCODED_NETMASK = "255.255.255.0";
const uint32_t HARDCODED_LEASE_TIME = 60; // in seconds
const std::string HARDCODED_GATEWAY = "10.3.2.2";
const std::string HARDCODED_DNS_SERVER = "8.8.8.8";
const std::string HARDCODED_DOMAIN_NAME = "isc.example.org";
const std::string HARDCODED_SERVER_ID = "10.3.1.1";
const std::string HARDCODED_GATEWAY = "192.0.2.1";
const std::string HARDCODED_DNS_SERVER = "192.0.2.2";
const std::string HARDCODED_DOMAIN_NAME = "isc.example.com";
const std::string HARDCODED_SERVER_ID = "192.0.2.1";
Dhcpv4Srv::Dhcpv4Srv(uint16_t port) {
cout << "Initialization: opening sockets on port " << port << endl;
......@@ -188,62 +188,72 @@ void Dhcpv4Srv::copyDefaultFields(const boost::shared_ptr<Pkt4>& question,
}
void Dhcpv4Srv::appendDefaultOptions(boost::shared_ptr<Pkt4>& msg, uint8_t msg_type) {
boost::shared_ptr<Option> opt;
// add Message Type Option (type 53)
boost::shared_ptr<Option> opt;
std::vector<uint8_t> tmp;
tmp.push_back(static_cast<uint8_t>(msg_type));
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_MESSAGE_TYPE, tmp));
msg->addOption(opt);
// DHCP Server Identifier (type 54)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_DHCP_SERVER_IDENTIFIER, IOAddress(HARDCODED_SERVER_ID)));
msg->addOption(opt);
// more options will be added here later
}
boost::shared_ptr<Pkt4>
Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) {
boost::shared_ptr<Pkt4> offer = boost::shared_ptr<Pkt4>
(new Pkt4(DHCPOFFER, discover->getTransid()));
void Dhcpv4Srv::appendRequestedOptions(boost::shared_ptr<Pkt4>& msg) {
boost::shared_ptr<Option> opt;
copyDefaultFields(discover, offer);
// Domain name (type 15)
vector<uint8_t> domain(HARDCODED_DOMAIN_NAME.begin(), HARDCODED_DOMAIN_NAME.end());
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DOMAIN_NAME, domain));
msg->addOption(opt);
// TODO: Add Option_String class
appendDefaultOptions(offer, DHCPOFFER);
// DNS servers (type 6)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS, IOAddress(HARDCODED_DNS_SERVER)));
msg->addOption(opt);
}
// TODO: Implement actual lease assignment here
offer->setYiaddr(IOAddress(HARDCODED_LEASE));
void Dhcpv4Srv::assignLease(boost::shared_ptr<Pkt4>& msg) {
boost::shared_ptr<Option> opt;
// DHCP Server Identifier (type 54)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_DHCP_SERVER_IDENTIFIER, IOAddress(HARDCODED_SERVER_ID)));
offer->addOption(opt);
// TODO: Implement actual lease assignment here
msg->setYiaddr(IOAddress(HARDCODED_LEASE));
// IP Address Lease time (type 51)
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_LEASE_TIME));
opt->setUint32(HARDCODED_LEASE_TIME);
offer->addOption(opt);
msg->addOption(opt);
// Subnet mask (type 1)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_SUBNET_MASK, IOAddress(HARDCODED_NETMASK)));
offer->addOption(opt);
msg->addOption(opt);
// Router (type 3)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_ROUTERS, IOAddress(HARDCODED_GATEWAY)));
offer->addOption(opt);
msg->addOption(opt);
}
// Domain name (type 15)
vector<uint8_t> domain(HARDCODED_DOMAIN_NAME.begin(), HARDCODED_DOMAIN_NAME.end());
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DOMAIN_NAME, domain));
offer->addOption(opt);
// TODO: Add Option_String class
boost::shared_ptr<Pkt4>
Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) {
boost::shared_ptr<Pkt4> offer = boost::shared_ptr<Pkt4>
(new Pkt4(DHCPOFFER, discover->getTransid()));
// DNS servers (type 6)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS, IOAddress(HARDCODED_DNS_SERVER)));
offer->addOption(opt);
boost::shared_ptr<Option> opt;
copyDefaultFields(discover, offer);
appendDefaultOptions(offer, DHCPOFFER);
appendRequestedOptions(offer);
assignLease(offer);
return (offer);
}
......@@ -256,17 +266,12 @@ Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4>& request) {
boost::shared_ptr<Option> opt;
copyDefaultFields(request, ack);
appendDefaultOptions(ack, DHCPACK);
appendRequestedOptions(ack);
// TODO: Implement actual lease assignment here
ack->setYiaddr(IOAddress(HARDCODED_LEASE));
// DHCP Server Identifier (type 54)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_DHCP_SERVER_IDENTIFIER, IOAddress(HARDCODED_SERVER_ID)));
ack->addOption(opt);
// IP Address Lease time (type 51)
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_LEASE_TIME));
opt->setUint32(HARDCODED_LEASE_TIME);
......@@ -282,17 +287,6 @@ Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4>& request) {
opt = boost::shared_ptr<Option>(new Option4AddrLst(DHO_ROUTERS, IOAddress(HARDCODED_GATEWAY)));
ack->addOption(opt);
// Domain name (type 15)
vector<uint8_t> domain(HARDCODED_DOMAIN_NAME.begin(), HARDCODED_DOMAIN_NAME.end());
opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DOMAIN_NAME, domain));
ack->addOption(opt);
// TODO: Add Option_String class
// DNS servers (type 6)
opt = boost::shared_ptr<Option>
(new Option4AddrLst(DHO_DOMAIN_NAME_SERVERS, IOAddress(HARDCODED_DNS_SERVER)));
ack->addOption(opt);
return (ack);
}
......
......@@ -116,6 +116,29 @@ protected:
void copyDefaultFields(const boost::shared_ptr<Pkt4>& question,
boost::shared_ptr<Pkt4>& answer);
/// @brief Appends options requested by client.
///
/// This method assigns options that were requested by client
/// or are enforced by server (sent out to all clients).
///
/// @param msg outgoing message (options will be added here)
void appendRequestedOptions(boost::shared_ptr<Pkt4>& msg);
/// @brief Assigns a lease and appends corresponding options
///
/// This method chooses the most appropriate lease for reqesting
/// client and assigning it. Options corresponding to the lease
/// are added to specific message.
///
/// Note: Lease manager is not implemented yet, so this method
/// used fixed, hardcoded lease.
///
/// @param msg OFFER or ACK message (lease options will be added here)
void assignLease(boost::shared_ptr<Pkt4>& msg);
/// @brief Appends default options to a message
///
/// @param msg message object (options will be added to it)
......
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