|
@@ -23,8 +23,8 @@ using namespace isc;
|
|
using namespace isc::dhcp;
|
|
using namespace isc::dhcp;
|
|
using namespace isc::asiolink;
|
|
using namespace isc::asiolink;
|
|
|
|
|
|
-Dhcpv4Srv::Dhcpv4Srv() {
|
|
|
|
- cout << "Initialization" << endl;
|
|
|
|
|
|
+Dhcpv4Srv::Dhcpv4Srv(uint16_t port) {
|
|
|
|
+ cout << "Initialization: opening sockets on port " << port << endl;
|
|
|
|
|
|
// first call to instance() will create IfaceMgr (it's a singleton)
|
|
// first call to instance() will create IfaceMgr (it's a singleton)
|
|
// it may throw something if things go wrong
|
|
// it may throw something if things go wrong
|
|
@@ -34,7 +34,7 @@ Dhcpv4Srv::Dhcpv4Srv() {
|
|
|
|
|
|
setServerID();
|
|
setServerID();
|
|
|
|
|
|
- shutdown = false;
|
|
|
|
|
|
+ shutdown_ = false;
|
|
}
|
|
}
|
|
|
|
|
|
Dhcpv4Srv::~Dhcpv4Srv() {
|
|
Dhcpv4Srv::~Dhcpv4Srv() {
|
|
@@ -43,11 +43,12 @@ Dhcpv4Srv::~Dhcpv4Srv() {
|
|
|
|
|
|
bool
|
|
bool
|
|
Dhcpv4Srv::run() {
|
|
Dhcpv4Srv::run() {
|
|
- while (!shutdown) {
|
|
|
|
|
|
+ while (!shutdown_) {
|
|
boost::shared_ptr<Pkt4> query; // client's message
|
|
boost::shared_ptr<Pkt4> query; // client's message
|
|
boost::shared_ptr<Pkt4> rsp; // server's response
|
|
boost::shared_ptr<Pkt4> rsp; // server's response
|
|
|
|
|
|
#if 0
|
|
#if 0
|
|
|
|
+ // uncomment this once ticket 1239 is merged.
|
|
query = IfaceMgr::instance().receive4();
|
|
query = IfaceMgr::instance().receive4();
|
|
#endif
|
|
#endif
|
|
|
|
|
|
@@ -80,25 +81,26 @@ Dhcpv4Srv::run() {
|
|
cout << "Received " << query->len() << " bytes packet type="
|
|
cout << "Received " << query->len() << " bytes packet type="
|
|
<< query->getType() << endl;
|
|
<< query->getType() << endl;
|
|
|
|
|
|
- /// DEBUG
|
|
|
|
|
|
+ // TODO: print out received packets only if verbose (or debug)
|
|
|
|
+ // mode is enabled
|
|
cout << query->toText();
|
|
cout << query->toText();
|
|
|
|
|
|
if (rsp) {
|
|
if (rsp) {
|
|
-#if 0
|
|
|
|
- rsp->remote_addr_ = query->remote_addr_;
|
|
|
|
- rsp->local_addr_ = query->local_addr_;
|
|
|
|
- rsp->remote_port_ = DHCP6_CLIENT_PORT;
|
|
|
|
- rsp->local_port_ = DHCP6_SERVER_PORT;
|
|
|
|
- rsp->ifindex_ = query->ifindex_;
|
|
|
|
- rsp->iface_ = query->iface_;
|
|
|
|
-#endif
|
|
|
|
|
|
+ rsp->setRemoteAddr(query->getRemoteAddr());
|
|
|
|
+ rsp->setLocalAddr(query->getLocalAddr());
|
|
|
|
+ rsp->setRemotePort(DHCP4_CLIENT_PORT);
|
|
|
|
+ rsp->setLocalPort(DHCP4_SERVER_PORT);
|
|
|
|
+ rsp->setIface(query->getIface());
|
|
|
|
+ rsp->setIndex(query->getIndex());
|
|
|
|
+
|
|
cout << "Replying with:" << rsp->getType() << endl;
|
|
cout << "Replying with:" << rsp->getType() << endl;
|
|
cout << rsp->toText();
|
|
cout << rsp->toText();
|
|
cout << "----" << endl;
|
|
cout << "----" << endl;
|
|
if (rsp->pack()) {
|
|
if (rsp->pack()) {
|
|
- cout << "#### pack successful." << endl;
|
|
|
|
|
|
+ cout << "Packet assembled correctly." << endl;
|
|
}
|
|
}
|
|
#if 0
|
|
#if 0
|
|
|
|
+ // uncomment this once ticket 1240 is merged.
|
|
IfaceMgr::instance().send4(rsp);
|
|
IfaceMgr::instance().send4(rsp);
|
|
#endif
|
|
#endif
|
|
}
|
|
}
|
|
@@ -113,9 +115,11 @@ Dhcpv4Srv::run() {
|
|
|
|
|
|
void
|
|
void
|
|
Dhcpv4Srv::setServerID() {
|
|
Dhcpv4Srv::setServerID() {
|
|
- /// TODO implement this for real once interface detection is done.
|
|
|
|
- /// Use hardcoded server-id for now
|
|
|
|
|
|
+ /// TODO implement this for real once interface detection (ticket 1237)
|
|
|
|
+ /// is done. Use hardcoded server-id for now.
|
|
|
|
+
|
|
#if 0
|
|
#if 0
|
|
|
|
+ // uncomment this once ticket 1350 is merged.
|
|
IOAddress srvId("127.0.0.1");
|
|
IOAddress srvId("127.0.0.1");
|
|
serverid_ = boost::shared_ptr<Option>(
|
|
serverid_ = boost::shared_ptr<Option>(
|
|
new Option4AddrLst(Option::V4, DHO_DHCP_SERVER_IDENTIFIER, srvId));
|
|
new Option4AddrLst(Option::V4, DHO_DHCP_SERVER_IDENTIFIER, srvId));
|
|
@@ -123,29 +127,28 @@ Dhcpv4Srv::setServerID() {
|
|
}
|
|
}
|
|
|
|
|
|
boost::shared_ptr<Pkt4>
|
|
boost::shared_ptr<Pkt4>
|
|
-Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4> discover) {
|
|
|
|
- /// TODO: Echo mode. Implement this for real
|
|
|
|
|
|
+Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) {
|
|
|
|
+ /// TODO: Currently implemented echo mode. Implement this for real
|
|
return (discover);
|
|
return (discover);
|
|
}
|
|
}
|
|
|
|
|
|
boost::shared_ptr<Pkt4>
|
|
boost::shared_ptr<Pkt4>
|
|
-Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4> request) {
|
|
|
|
- /// TODO: Echo mode. Implement this for real
|
|
|
|
|
|
+Dhcpv4Srv::processRequest(boost::shared_ptr<Pkt4>& request) {
|
|
|
|
+ /// TODO: Currently implemented echo mode. Implement this for real
|
|
return (request);
|
|
return (request);
|
|
}
|
|
}
|
|
|
|
|
|
-void Dhcpv4Srv::processRelease(boost::shared_ptr<Pkt4> release) {
|
|
|
|
|
|
+void Dhcpv4Srv::processRelease(boost::shared_ptr<Pkt4>& release) {
|
|
/// TODO: Implement this.
|
|
/// TODO: Implement this.
|
|
cout << "Received RELEASE on " << release->getIface() << " interface." << endl;
|
|
cout << "Received RELEASE on " << release->getIface() << " interface." << endl;
|
|
}
|
|
}
|
|
-
|
|
|
|
-void Dhcpv4Srv::processDecline(boost::shared_ptr<Pkt4> decline) {
|
|
|
|
|
|
+
|
|
|
|
+void Dhcpv4Srv::processDecline(boost::shared_ptr<Pkt4>& decline) {
|
|
/// TODO: Implement this.
|
|
/// TODO: Implement this.
|
|
cout << "Received DECLINE on " << decline->getIface() << " interface." << endl;
|
|
cout << "Received DECLINE on " << decline->getIface() << " interface." << endl;
|
|
}
|
|
}
|
|
|
|
|
|
-boost::shared_ptr<Pkt4> processInform(boost::shared_ptr<Pkt4> inform) {
|
|
|
|
- /// TODO: Echo mode. Implement this for real
|
|
|
|
|
|
+boost::shared_ptr<Pkt4> Dhcpv4Srv::processInform(boost::shared_ptr<Pkt4>& inform) {
|
|
|
|
+ /// TODO: Currently implemented echo mode. Implement this for real
|
|
return (inform);
|
|
return (inform);
|
|
}
|
|
}
|
|
-
|
|
|