// 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 "dhcp/dhcp6.h" #include "dhcp/pkt6.h" #include "dhcp6/iface_mgr.h" #include "dhcp6/dhcp6_srv.h" #include "dhcp/option6_ia.h" #include "dhcp/option6_iaaddr.h" #include "io_address.h" using namespace std; using namespace isc; using namespace isc::dhcp; using namespace isc::asiolink; Dhcpv6Srv::Dhcpv6Srv() { cout << "Initialization" << endl; // first call to instance() will create IfaceMgr (it's a singleton) // it may throw something if things go wrong IfaceMgr::instance(); if (!setServerID()) { isc_throw(Unexpected, "Failed to set up server-id."); } } Dhcpv6Srv::~Dhcpv6Srv() { cout << "DHCPv6 Srv shutdown." << endl; } bool Dhcpv6Srv::run() { while (true) { boost::shared_ptr query; // client's message boost::shared_ptr rsp; // server's response query = IfaceMgr::instance().receive(); 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; 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 != boost::shared_ptr()) { 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); } boost::shared_ptr