BIND 10 trac1230, updated. 7bf0432cb1f1b7777a25bfd8c0e3c1c8def9bf18 [1230] Initial support for DISCOVER messages (generates OFFER).
BIND 10 source code commits
bind10-changes at lists.isc.org
Tue Dec 20 18:59:43 UTC 2011
The branch, trac1230 has been updated
via 7bf0432cb1f1b7777a25bfd8c0e3c1c8def9bf18 (commit)
from f60bf56ebed7189ad71d6c4ed4044d97b5e5c7a5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 7bf0432cb1f1b7777a25bfd8c0e3c1c8def9bf18
Author: Tomek Mrugalski <tomasz at isc.org>
Date: Tue Dec 20 19:59:14 2011 +0100
[1230] Initial support for DISCOVER messages (generates OFFER).
-----------------------------------------------------------------------
Summary of changes:
src/bin/dhcp4/dhcp4_srv.cc | 78 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 74 insertions(+), 4 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/dhcp4/dhcp4_srv.cc b/src/bin/dhcp4/dhcp4_srv.cc
index 9e29059..38f3805 100644
--- a/src/bin/dhcp4/dhcp4_srv.cc
+++ b/src/bin/dhcp4/dhcp4_srv.cc
@@ -17,12 +17,17 @@
#include <dhcp/iface_mgr.h>
#include <dhcp4/dhcp4_srv.h>
#include <asiolink/io_address.h>
+#include <dhcp/option4_addrlst.h>
using namespace std;
using namespace isc;
using namespace isc::dhcp;
using namespace isc::asiolink;
+// This is the hardcoded lease. Currently this is a skeleton server that only
+// grants this option.
+#define HARDCODED_LEASE "10.3.2.222"
+
// #define ECHO_SERVER
Dhcpv4Srv::Dhcpv4Srv(uint16_t port) {
@@ -99,9 +104,16 @@ Dhcpv4Srv::run() {
cout << query->toText();
if (rsp) {
- rsp->setRemoteAddr(query->getRemoteAddr());
+ if (rsp->getRemoteAddr().toText() == "0.0.0.0") {
+ rsp->setRemoteAddr(query->getRemoteAddr());
+ }
+ if (!rsp->getHops()) {
+ rsp->setRemotePort(DHCP4_CLIENT_PORT);
+ } else {
+ rsp->setRemotePort(DHCP4_SERVER_PORT);
+ }
+
rsp->setLocalAddr(query->getLocalAddr());
- rsp->setRemotePort(DHCP4_CLIENT_PORT);
rsp->setLocalPort(DHCP4_SERVER_PORT);
rsp->setIface(query->getIface());
rsp->setIndex(query->getIndex());
@@ -142,8 +154,66 @@ Dhcpv4Srv::setServerID() {
boost::shared_ptr<Pkt4>
Dhcpv4Srv::processDiscover(boost::shared_ptr<Pkt4>& discover) {
- /// TODO: Currently implemented echo mode. Implement this for real
- return (discover);
+ boost::shared_ptr<Pkt4> offer = boost::shared_ptr<Pkt4>(new Pkt4(DHCPOFFER, discover->getTransid()));
+
+
+ offer->setIface(discover->getIface());
+ offer->setIndex(discover->getIndex());
+ offer->setCiaddr(discover->getCiaddr());
+
+ offer->setSiaddr(IOAddress("0.0.0.0")); // explictly set this to 0
+
+ offer->setHops(discover->getHops());
+
+ // copy MAC address
+ vector<uint8_t> mac;
+ mac.resize(Pkt4::MAX_CHADDR_LEN);
+ memcpy(&mac[0], discover->getChaddr(), Pkt4::MAX_CHADDR_LEN);
+ offer->setHWAddr(discover->getHtype(),
+ discover->getHlen(),
+ mac);
+
+ // relay address
+ offer->setGiaddr(discover->getGiaddr());
+ if (discover->getGiaddr().toText() != "0.0.0.0") {
+ // relayed traffic
+ offer->setRemoteAddr(discover->getGiaddr());
+ } else {
+ // direct traffic
+ offer->setRemoteAddr(discover->getRemoteAddr());
+ }
+
+ // TODO: Implement actual lease assignment here
+ offer->setYiaddr(IOAddress(HARDCODED_LEASE));
+
+ // add Message Type Option (type 53)
+ boost::shared_ptr<Option> opt;
+ std::vector<uint8_t> tmp;
+ tmp.push_back(static_cast<int>(DHCPOFFER));
+ opt = boost::shared_ptr<Option>(new Option(Option::V4, DHO_DHCP_MESSAGE_TYPE, tmp));
+ offer->addOption(opt);
+
+ // DHCP Server Identifier (type 54)
+ opt = boost::shared_ptr<Option>(new Option4AddrLst(54, IOAddress("10.3.1.1")));
+ offer->addOption(opt);
+
+ // IP Address Lease time (type 51)
+
+ // Subnet mask (type 1)
+ opt = boost::shared_ptr<Option>(new Option4AddrLst(1, IOAddress("255.255.255.0")));
+ offer->addOption(opt);
+
+ // Router (type 3)
+ opt = boost::shared_ptr<Option>(new Option4AddrLst(3, IOAddress("10.3.2.2")));
+ offer->addOption(opt);
+
+ // Domain name (type 15)
+
+ // DNS servers (type 6)
+ opt = boost::shared_ptr<Option>(new Option4AddrLst(6, IOAddress("8.8.8.8")));
+ offer->addOption(opt);
+
+ return (offer);
}
boost::shared_ptr<Pkt4>
More information about the bind10-changes
mailing list