// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC") // // Permission to use, copy, modify, and/or distribute this software for any // purpose with or without fee is hereby granted, provided that the above // copyright notice and this permission notice appear in all copies. // // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. #include #include #include #include #include #include #include #include using namespace std; using namespace isc; using namespace isc::dhcp; using namespace isc::asiolink; Dhcpv6Srv::Dhcpv6Srv(uint16_t port) { //void Dhcpv6Srv::Dhcpv6Srv_impl(uint16_t port) { cout << "Initialization" << endl; // First call to instance() will create IfaceMgr (it's a singleton). // It may throw something if things go wrong. IfaceMgr::instance(); // Now try to open IPv6 sockets on detected interfaces. IfaceMgr::instance().openSockets(port); /// @todo: instantiate LeaseMgr here once it is imlpemented. setServerID(); shutdown = false; } Dhcpv6Srv::~Dhcpv6Srv() { cout << "DHCPv6 Srv shutdown." << endl; IfaceMgr::instance().closeSockets(); } bool Dhcpv6Srv::run() { while (!shutdown) { boost::shared_ptr query; // client's message boost::shared_ptr rsp; // server's response query = IfaceMgr::instance().receive6(); if (query) { if (!query->unpack()) { cout << "Failed to parse incoming packet" << endl; continue; } switch (query->getType()) { case DHCPV6_SOLICIT: rsp = processSolicit(query); break; case DHCPV6_REQUEST: rsp = processRequest(query); break; case DHCPV6_RENEW: rsp = processRenew(query); break; case DHCPV6_REBIND: rsp = processRebind(query); break; case DHCPV6_CONFIRM: rsp = processConfirm(query); break; case DHCPV6_RELEASE: rsp = processRelease(query); break; case DHCPV6_DECLINE: rsp = processDecline(query); break; case DHCPV6_INFORMATION_REQUEST: rsp = processInfRequest(query); break; default: cout << "Unknown pkt type received:" << query->getType() << endl; } cout << "Received " << query->data_len_ << " bytes packet type=" << query->getType() << endl; cout << query->toText(); if (rsp) { 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_; cout << "Replying with:" << rsp->getType() << endl; cout << rsp->toText(); cout << "----" << endl; if (rsp->pack()) { cout << "#### pack successful." << endl; } IfaceMgr::instance().send(rsp); } } // TODO add support for config session (see src/bin/auth/main.cc) // so this daemon can be controlled from bob } return (true); } void Dhcpv6Srv::setServerID() { /// TODO implement this for real once interface detection is done. /// Use hardcoded server-id for now boost::shared_array srvid(new uint8_t[14]); srvid[0] = 0; srvid[1] = 1; // DUID type 1 = DUID-LLT (see section 9.2 of RFC3315) srvid[2] = 0; srvid[3] = 6; // HW type = ethernet (I think. I'm typing this from my head // in hotel, without Internet connection) for (int i=4; i<14; i++) { srvid[i]=i-4; } serverid_ = boost::shared_ptr