|
@@ -122,8 +122,6 @@ IfaceMgr::IfaceMgr()
|
|
|
session_socket_(INVALID_SOCKET), session_callback_(NULL)
|
|
|
{
|
|
|
|
|
|
- cout << "IfaceMgr initialization." << endl;
|
|
|
-
|
|
|
try {
|
|
|
// required for sending/receiving packets
|
|
|
// let's keep it in front, just in case someone
|
|
@@ -134,13 +132,7 @@ IfaceMgr::IfaceMgr()
|
|
|
detectIfaces();
|
|
|
|
|
|
} catch (const std::exception& ex) {
|
|
|
- cout << "IfaceMgr creation failed:" << ex.what() << endl;
|
|
|
-
|
|
|
- // TODO Uncomment this (or call LOG_FATAL) once
|
|
|
- // interface detection is implemented. Otherwise
|
|
|
- // it is not possible to run tests in a portable
|
|
|
- // way (see detectIfaces() method).
|
|
|
- throw;
|
|
|
+ isc_throw(IfaceDetectError, ex.what());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -166,51 +158,34 @@ void IfaceMgr::stubDetectIfaces() {
|
|
|
// is faked by detecting loopback interface (lo or lo0). It will eventually
|
|
|
// be removed once we have actual implementations for all supported systems.
|
|
|
|
|
|
- cout << "Interface detection is not implemented on this Operating System yet. "
|
|
|
- << endl;
|
|
|
-
|
|
|
- try {
|
|
|
- if (if_nametoindex("lo") > 0) {
|
|
|
- ifaceName = "lo";
|
|
|
- // this is Linux-like OS
|
|
|
- } else if (if_nametoindex("lo0") > 0) {
|
|
|
- ifaceName = "lo0";
|
|
|
- // this is BSD-like OS
|
|
|
- } else {
|
|
|
- // we give up. What OS is this, anyway? Solaris? Hurd?
|
|
|
- isc_throw(NotImplemented,
|
|
|
- "Interface detection on this OS is not supported.");
|
|
|
- }
|
|
|
-
|
|
|
- Iface iface(ifaceName, if_nametoindex(ifaceName.c_str()));
|
|
|
- iface.flag_up_ = true;
|
|
|
- iface.flag_running_ = true;
|
|
|
-
|
|
|
- // Note that we claim that this is not a loopback. iface_mgr tries to open a
|
|
|
- // socket on all interaces that are up, running and not loopback. As this is
|
|
|
- // the only interface we were able to detect, let's pretend this is a normal
|
|
|
- // interface.
|
|
|
- iface.flag_loopback_ = false;
|
|
|
- iface.flag_multicast_ = true;
|
|
|
- iface.flag_broadcast_ = true;
|
|
|
- iface.setHWType(HWTYPE_ETHERNET);
|
|
|
-
|
|
|
- iface.addAddress(IOAddress(v4addr));
|
|
|
- iface.addAddress(IOAddress(v6addr));
|
|
|
- addInterface(iface);
|
|
|
-
|
|
|
- cout << "Detected interface " << ifaceName << "/" << v4addr << "/"
|
|
|
- << v6addr << endl;
|
|
|
- } catch (const std::exception& ex) {
|
|
|
- // TODO: deallocate whatever memory we used
|
|
|
- // not that important, since this function is going to be
|
|
|
- // thrown away as soon as we get proper interface detection
|
|
|
- // implemented
|
|
|
-
|
|
|
- // TODO Do LOG_FATAL here
|
|
|
- std::cerr << "Interface detection failed." << std::endl;
|
|
|
- throw;
|
|
|
+ if (if_nametoindex("lo") > 0) {
|
|
|
+ ifaceName = "lo";
|
|
|
+ // this is Linux-like OS
|
|
|
+ } else if (if_nametoindex("lo0") > 0) {
|
|
|
+ ifaceName = "lo0";
|
|
|
+ // this is BSD-like OS
|
|
|
+ } else {
|
|
|
+ // we give up. What OS is this, anyway? Solaris? Hurd?
|
|
|
+ isc_throw(NotImplemented,
|
|
|
+ "Interface detection on this OS is not supported.");
|
|
|
}
|
|
|
+
|
|
|
+ Iface iface(ifaceName, if_nametoindex(ifaceName.c_str()));
|
|
|
+ iface.flag_up_ = true;
|
|
|
+ iface.flag_running_ = true;
|
|
|
+
|
|
|
+ // Note that we claim that this is not a loopback. iface_mgr tries to open a
|
|
|
+ // socket on all interaces that are up, running and not loopback. As this is
|
|
|
+ // the only interface we were able to detect, let's pretend this is a normal
|
|
|
+ // interface.
|
|
|
+ iface.flag_loopback_ = false;
|
|
|
+ iface.flag_multicast_ = true;
|
|
|
+ iface.flag_broadcast_ = true;
|
|
|
+ iface.setHWType(HWTYPE_ETHERNET);
|
|
|
+
|
|
|
+ iface.addAddress(IOAddress(v4addr));
|
|
|
+ iface.addAddress(IOAddress(v6addr));
|
|
|
+ addInterface(iface);
|
|
|
}
|
|
|
|
|
|
bool IfaceMgr::openSockets4(const uint16_t port) {
|
|
@@ -221,13 +196,9 @@ bool IfaceMgr::openSockets4(const uint16_t port) {
|
|
|
iface != ifaces_.end();
|
|
|
++iface) {
|
|
|
|
|
|
- cout << "Trying opening socket on interface " << iface->getFullName() << endl;
|
|
|
-
|
|
|
if (iface->flag_loopback_ ||
|
|
|
!iface->flag_up_ ||
|
|
|
!iface->flag_running_) {
|
|
|
- cout << "Interface " << iface->getFullName()
|
|
|
- << " not suitable: is loopback, is down or not running" << endl;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -243,15 +214,13 @@ bool IfaceMgr::openSockets4(const uint16_t port) {
|
|
|
|
|
|
sock = openSocket(iface->getName(), *addr, port);
|
|
|
if (sock < 0) {
|
|
|
- cout << "Failed to open unicast socket." << endl;
|
|
|
- return (false);
|
|
|
+ isc_throw(SocketConfigError, "failed to open unicast socket");
|
|
|
}
|
|
|
|
|
|
count++;
|
|
|
}
|
|
|
}
|
|
|
return (count > 0);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
bool IfaceMgr::openSockets6(const uint16_t port) {
|
|
@@ -280,8 +249,7 @@ bool IfaceMgr::openSockets6(const uint16_t port) {
|
|
|
|
|
|
sock = openSocket(iface->getName(), *addr, port);
|
|
|
if (sock < 0) {
|
|
|
- cout << "Failed to open unicast socket." << endl;
|
|
|
- return (false);
|
|
|
+ isc_throw(SocketConfigError, "failed to open unicast socket");
|
|
|
}
|
|
|
|
|
|
// Binding socket to unicast address and then joining multicast group
|
|
@@ -290,7 +258,8 @@ bool IfaceMgr::openSockets6(const uint16_t port) {
|
|
|
if ( !joinMulticast(sock, iface->getName(),
|
|
|
string(ALL_DHCP_RELAY_AGENTS_AND_SERVERS))) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "Failed to join " << ALL_DHCP_RELAY_AGENTS_AND_SERVERS
|
|
|
+ isc_throw(SocketConfigError, "Failed to join "
|
|
|
+ << ALL_DHCP_RELAY_AGENTS_AND_SERVERS
|
|
|
<< " multicast group.");
|
|
|
}
|
|
|
|
|
@@ -305,7 +274,7 @@ bool IfaceMgr::openSockets6(const uint16_t port) {
|
|
|
IOAddress(ALL_DHCP_RELAY_AGENTS_AND_SERVERS),
|
|
|
port);
|
|
|
if (sock2 < 0) {
|
|
|
- isc_throw(Unexpected, "Failed to open multicast socket on "
|
|
|
+ isc_throw(SocketConfigError, "Failed to open multicast socket on "
|
|
|
<< " interface " << iface->getFullName());
|
|
|
iface->delSocket(sock); // delete previously opened socket
|
|
|
}
|
|
@@ -418,7 +387,7 @@ int IfaceMgr::openSocketFromIface(const std::string& ifname,
|
|
|
family_name = "AF_INET6";
|
|
|
}
|
|
|
// We did not find address on the interface.
|
|
|
- isc_throw(BadValue, "There is no address for interface: "
|
|
|
+ isc_throw(SocketConfigError, "There is no address for interface: "
|
|
|
<< ifname << ", port: " << port << ", address "
|
|
|
" family: " << family_name);
|
|
|
}
|
|
@@ -460,9 +429,13 @@ int IfaceMgr::openSocketFromAddress(const IOAddress& addr,
|
|
|
|
|
|
int IfaceMgr::openSocketFromRemoteAddress(const IOAddress& remote_addr,
|
|
|
const uint16_t port) {
|
|
|
- // Get local address to be used to connect to remote location.
|
|
|
- IOAddress local_address(getLocalAddress(remote_addr, port).getAddress());
|
|
|
- return openSocketFromAddress(local_address, port);
|
|
|
+ try {
|
|
|
+ // Get local address to be used to connect to remote location.
|
|
|
+ IOAddress local_address(getLocalAddress(remote_addr, port).getAddress());
|
|
|
+ return openSocketFromAddress(local_address, port);
|
|
|
+ } catch (const Exception& e) {
|
|
|
+ isc_throw(SocketConfigError, e.what());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
isc::asiolink::IOAddress
|
|
@@ -506,7 +479,7 @@ IfaceMgr::getLocalAddress(const IOAddress& remote_addr, const uint16_t port) {
|
|
|
sock.connect(remote_endpoint->getASIOEndpoint(), err_code);
|
|
|
if (err_code) {
|
|
|
sock.close();
|
|
|
- isc_throw(Unexpected,"failed to connect to remote endpoint.");
|
|
|
+ isc_throw(Unexpected, "failed to connect to remote endpoint.");
|
|
|
}
|
|
|
|
|
|
// Once we are connected socket object holds local endpoint.
|
|
@@ -523,9 +496,6 @@ IfaceMgr::getLocalAddress(const IOAddress& remote_addr, const uint16_t port) {
|
|
|
|
|
|
int IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
|
|
|
- cout << "Creating UDP4 socket on " << iface.getFullName()
|
|
|
- << " " << addr.toText() << "/port=" << port << endl;
|
|
|
-
|
|
|
struct sockaddr_in addr4;
|
|
|
memset(&addr4, 0, sizeof(sockaddr));
|
|
|
addr4.sin_family = AF_INET;
|
|
@@ -537,12 +507,12 @@ int IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
|
|
|
int sock = socket(AF_INET, SOCK_DGRAM, 0);
|
|
|
if (sock < 0) {
|
|
|
- isc_throw(Unexpected, "Failed to create UDP6 socket.");
|
|
|
+ isc_throw(SocketConfigError, "Failed to create UDP6 socket.");
|
|
|
}
|
|
|
|
|
|
if (bind(sock, (struct sockaddr *)&addr4, sizeof(addr4)) < 0) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "Failed to bind socket " << sock << " to " << addr.toText()
|
|
|
+ isc_throw(SocketConfigError, "Failed to bind socket " << sock << " to " << addr.toText()
|
|
|
<< "/port=" << port);
|
|
|
}
|
|
|
|
|
@@ -552,13 +522,10 @@ int IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
int flag = 1;
|
|
|
if (setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &flag, sizeof(flag)) != 0) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "setsockopt: IP_PKTINFO: failed.");
|
|
|
+ isc_throw(SocketConfigError, "setsockopt: IP_PKTINFO: failed.");
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
- cout << "Created socket " << sock << " on " << iface.getName() << "/" <<
|
|
|
- addr.toText() << "/port=" << port << endl;
|
|
|
-
|
|
|
SocketInfo info(sock, addr, port);
|
|
|
iface.addSocket(info);
|
|
|
|
|
@@ -567,9 +534,6 @@ int IfaceMgr::openSocket4(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
|
|
|
int IfaceMgr::openSocket6(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
|
|
|
- cout << "Creating UDP6 socket on " << iface.getFullName()
|
|
|
- << " " << addr.toText() << "/port=" << port << endl;
|
|
|
-
|
|
|
struct sockaddr_in6 addr6;
|
|
|
memset(&addr6, 0, sizeof(addr6));
|
|
|
addr6.sin6_family = AF_INET6;
|
|
@@ -590,7 +554,7 @@ int IfaceMgr::openSocket6(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
// make a socket
|
|
|
int sock = socket(AF_INET6, SOCK_DGRAM, 0);
|
|
|
if (sock < 0) {
|
|
|
- isc_throw(Unexpected, "Failed to create UDP6 socket.");
|
|
|
+ isc_throw(SocketConfigError, "Failed to create UDP6 socket.");
|
|
|
}
|
|
|
|
|
|
// Set the REUSEADDR option so that we don't fail to start if
|
|
@@ -599,12 +563,12 @@ int IfaceMgr::openSocket6(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
|
|
|
(char *)&flag, sizeof(flag)) < 0) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "Can't set SO_REUSEADDR option on dhcpv6 socket.");
|
|
|
+ isc_throw(SocketConfigError, "Can't set SO_REUSEADDR option on dhcpv6 socket.");
|
|
|
}
|
|
|
|
|
|
if (bind(sock, (struct sockaddr *)&addr6, sizeof(addr6)) < 0) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "Failed to bind socket " << sock << " to " << addr.toText()
|
|
|
+ isc_throw(SocketConfigError, "Failed to bind socket " << sock << " to " << addr.toText()
|
|
|
<< "/port=" << port);
|
|
|
}
|
|
|
#ifdef IPV6_RECVPKTINFO
|
|
@@ -612,14 +576,14 @@ int IfaceMgr::openSocket6(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
if (setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO,
|
|
|
&flag, sizeof(flag)) != 0) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "setsockopt: IPV6_RECVPKTINFO failed.");
|
|
|
+ isc_throw(SocketConfigError, "setsockopt: IPV6_RECVPKTINFO failed.");
|
|
|
}
|
|
|
#else
|
|
|
// RFC2292 - an old way
|
|
|
if (setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO,
|
|
|
&flag, sizeof(flag)) != 0) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "setsockopt: IPV6_PKTINFO: failed.");
|
|
|
+ isc_throw(SocketConfigError, "setsockopt: IPV6_PKTINFO: failed.");
|
|
|
}
|
|
|
#endif
|
|
|
|
|
@@ -632,14 +596,11 @@ int IfaceMgr::openSocket6(Iface& iface, const IOAddress& addr, uint16_t port) {
|
|
|
if ( !joinMulticast( sock, iface.getName(),
|
|
|
string(ALL_DHCP_RELAY_AGENTS_AND_SERVERS) ) ) {
|
|
|
close(sock);
|
|
|
- isc_throw(Unexpected, "Failed to join " << ALL_DHCP_RELAY_AGENTS_AND_SERVERS
|
|
|
+ isc_throw(SocketConfigError, "Failed to join " << ALL_DHCP_RELAY_AGENTS_AND_SERVERS
|
|
|
<< " multicast group.");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- cout << "Created socket " << sock << " on " << iface.getName() << "/" <<
|
|
|
- addr.toText() << "/port=" << port << endl;
|
|
|
-
|
|
|
SocketInfo info(sock, addr, port);
|
|
|
iface.addSocket(info);
|
|
|
|
|
@@ -654,20 +615,15 @@ const std::string & mcast) {
|
|
|
|
|
|
if (inet_pton(AF_INET6, mcast.c_str(),
|
|
|
&mreq.ipv6mr_multiaddr) <= 0) {
|
|
|
- cout << "Failed to convert " << ifname
|
|
|
- << " to IPv6 multicast address." << endl;
|
|
|
return (false);
|
|
|
}
|
|
|
|
|
|
mreq.ipv6mr_interface = if_nametoindex(ifname.c_str());
|
|
|
if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
|
|
|
&mreq, sizeof(mreq)) < 0) {
|
|
|
- cout << "Failed to join " << mcast << " multicast group." << endl;
|
|
|
return (false);
|
|
|
}
|
|
|
|
|
|
- cout << "Joined multicast " << mcast << " group." << endl;
|
|
|
-
|
|
|
return (true);
|
|
|
}
|
|
|
|
|
@@ -746,13 +702,8 @@ IfaceMgr::send(const Pkt6Ptr& pkt) {
|
|
|
|
|
|
result = sendmsg(getSocket(*pkt), &m, 0);
|
|
|
if (result < 0) {
|
|
|
- isc_throw(Unexpected, "Pkt6 send failed: sendmsg() returned " << result);
|
|
|
+ isc_throw(SocketWriteError, "Pkt6 send failed: sendmsg() returned " << result);
|
|
|
}
|
|
|
- cout << "Sent " << pkt->getBuffer().getLength() << " bytes over socket " << getSocket(*pkt)
|
|
|
- << " on " << iface->getFullName() << " interface: "
|
|
|
- << " dst=[" << pkt->getRemoteAddr().toText() << "]:" << pkt->getRemotePort()
|
|
|
- << ", src=" << pkt->getLocalAddr().toText() << "]:" << pkt->getLocalPort()
|
|
|
- << endl;
|
|
|
|
|
|
return (result);
|
|
|
}
|
|
@@ -797,24 +748,13 @@ IfaceMgr::send(const Pkt4Ptr& pkt)
|
|
|
// call OS-specific routines (like setting interface index)
|
|
|
os_send4(m, control_buf_, control_buf_len_, pkt);
|
|
|
|
|
|
- cout << "Trying to send " << pkt->getBuffer().getLength() << " bytes to "
|
|
|
- << pkt->getRemoteAddr().toText() << ":" << pkt->getRemotePort()
|
|
|
- << " over socket " << getSocket(*pkt) << " on interface "
|
|
|
- << getIface(pkt->getIface())->getFullName() << endl;
|
|
|
-
|
|
|
pkt->updateTimestamp();
|
|
|
|
|
|
int result = sendmsg(getSocket(*pkt), &m, 0);
|
|
|
if (result < 0) {
|
|
|
- isc_throw(Unexpected, "Pkt4 send failed.");
|
|
|
+ isc_throw(SocketWriteError, "pkt4 send failed");
|
|
|
}
|
|
|
|
|
|
- cout << "Sent " << pkt->getBuffer().getLength() << " bytes over socket " << getSocket(*pkt)
|
|
|
- << " on " << iface->getFullName() << " interface: "
|
|
|
- << " dst=" << pkt->getRemoteAddr().toText() << ":" << pkt->getRemotePort()
|
|
|
- << ", src=" << pkt->getLocalAddr().toText() << ":" << pkt->getLocalPort()
|
|
|
- << endl;
|
|
|
-
|
|
|
return (result);
|
|
|
}
|
|
|
|
|
@@ -869,27 +809,18 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
|
|
|
select_timeout.tv_sec = timeout_sec;
|
|
|
select_timeout.tv_usec = timeout_usec;
|
|
|
|
|
|
- cout << "Trying to receive data on sockets: " << names.str()
|
|
|
- << ". Timeout is " << timeout_sec << "." << setw(6) << setfill('0')
|
|
|
- << timeout_usec << " seconds." << endl;
|
|
|
int result = select(maxfd + 1, &sockets, NULL, NULL, &select_timeout);
|
|
|
- cout << "select returned " << result << endl;
|
|
|
|
|
|
if (result == 0) {
|
|
|
// nothing received and timeout has been reached
|
|
|
return (Pkt4Ptr()); // NULL
|
|
|
} else if (result < 0) {
|
|
|
- cout << "Socket read error: " << strerror(errno) << endl;
|
|
|
-
|
|
|
- /// @todo: perhaps throw here?
|
|
|
- return (Pkt4Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, strerror(errno));
|
|
|
}
|
|
|
|
|
|
// Let's find out which socket has the data
|
|
|
if ((session_socket_ != INVALID_SOCKET) && (FD_ISSET(session_socket_, &sockets))) {
|
|
|
// something received over session socket
|
|
|
- cout << "BIND10 command or config available over session socket." << endl;
|
|
|
-
|
|
|
if (session_callback_) {
|
|
|
// in theory we could call io_service.run_one() here, instead of
|
|
|
// implementing callback mechanism, but that would introduce
|
|
@@ -918,14 +849,9 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
|
|
|
}
|
|
|
|
|
|
if (!candidate) {
|
|
|
- cout << "Received data over unknown socket." << endl;
|
|
|
- return (Pkt4Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, "received data over unknown socket");
|
|
|
}
|
|
|
|
|
|
- cout << "Trying to receive over UDP4 socket " << candidate->sockfd_ << " bound to "
|
|
|
- << candidate->addr_.toText() << "/port=" << candidate->port_ << " on "
|
|
|
- << iface->getFullName() << endl;
|
|
|
-
|
|
|
// Now we have a socket, let's get some data from it!
|
|
|
struct sockaddr_in from_addr;
|
|
|
uint8_t buf[RCVBUFSIZE];
|
|
@@ -958,8 +884,7 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
|
|
|
|
|
|
result = recvmsg(candidate->sockfd_, &m, 0);
|
|
|
if (result < 0) {
|
|
|
- cout << "Failed to receive UDP4 data." << endl;
|
|
|
- return (Pkt4Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, "failed to receive UDP4 data");
|
|
|
}
|
|
|
|
|
|
// We have all data let's create Pkt4 object.
|
|
@@ -982,15 +907,9 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) {
|
|
|
pkt->setLocalPort(candidate->port_);
|
|
|
|
|
|
if (!os_receive4(m, pkt)) {
|
|
|
- cout << "Unable to find pktinfo" << endl;
|
|
|
- return (boost::shared_ptr<Pkt4>()); // NULL
|
|
|
+ isc_throw(SocketReadError, "unable to find pktinfo");
|
|
|
}
|
|
|
|
|
|
- cout << "Received " << result << " bytes from " << from.toText()
|
|
|
- << "/port=" << from_port
|
|
|
- << " sent to " << pkt->getLocalAddr().toText() << " over interface "
|
|
|
- << iface->getFullName() << endl;
|
|
|
-
|
|
|
return (pkt);
|
|
|
}
|
|
|
|
|
@@ -1039,10 +958,6 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
|
|
|
names << session_socket_ << "(session)";
|
|
|
}
|
|
|
|
|
|
- cout << "Trying to receive data on sockets: " << names.str()
|
|
|
- << ". Timeout is " << timeout_sec << "." << setw(6) << setfill('0')
|
|
|
- << timeout_usec << " seconds." << endl;
|
|
|
-
|
|
|
struct timeval select_timeout;
|
|
|
select_timeout.tv_sec = timeout_sec;
|
|
|
select_timeout.tv_usec = timeout_usec;
|
|
@@ -1053,17 +968,12 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
|
|
|
// nothing received and timeout has been reached
|
|
|
return (Pkt6Ptr()); // NULL
|
|
|
} else if (result < 0) {
|
|
|
- cout << "Socket read error: " << strerror(errno) << endl;
|
|
|
-
|
|
|
- /// @todo: perhaps throw here?
|
|
|
- return (Pkt6Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, strerror(errno));
|
|
|
}
|
|
|
|
|
|
// Let's find out which socket has the data
|
|
|
if ((session_socket_ != INVALID_SOCKET) && (FD_ISSET(session_socket_, &sockets))) {
|
|
|
// something received over session socket
|
|
|
- cout << "BIND10 command or config available over session socket." << endl;
|
|
|
-
|
|
|
if (session_callback_) {
|
|
|
// in theory we could call io_service.run_one() here, instead of
|
|
|
// implementing callback mechanism, but that would introduce
|
|
@@ -1092,14 +1002,9 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
|
|
|
}
|
|
|
|
|
|
if (!candidate) {
|
|
|
- cout << "Received data over unknown socket." << endl;
|
|
|
- return (Pkt6Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, "received data over unknown socket");
|
|
|
}
|
|
|
|
|
|
- cout << "Trying to receive over UDP6 socket " << candidate->sockfd_ << " bound to "
|
|
|
- << candidate->addr_.toText() << "/port=" << candidate->port_ << " on "
|
|
|
- << iface->getFullName() << endl;
|
|
|
-
|
|
|
// Now we have a socket, let's get some data from it!
|
|
|
uint8_t buf[RCVBUFSIZE];
|
|
|
memset(&control_buf_[0], 0, control_buf_len_);
|
|
@@ -1163,12 +1068,10 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
|
|
|
cmsg = CMSG_NXTHDR(&m, cmsg);
|
|
|
}
|
|
|
if (!found_pktinfo) {
|
|
|
- cout << "Unable to find pktinfo" << endl;
|
|
|
- return (Pkt6Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, "unable to find pktinfo");
|
|
|
}
|
|
|
} else {
|
|
|
- cout << "Failed to receive data." << endl;
|
|
|
- return (Pkt6Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, "failed to receive data");
|
|
|
}
|
|
|
|
|
|
// Let's create a packet.
|
|
@@ -1176,8 +1079,7 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
|
|
|
try {
|
|
|
pkt = Pkt6Ptr(new Pkt6(buf, result));
|
|
|
} catch (const std::exception& ex) {
|
|
|
- cout << "Failed to create new packet." << endl;
|
|
|
- return (Pkt6Ptr()); // NULL
|
|
|
+ isc_throw(SocketReadError, "failed to create new packet");
|
|
|
}
|
|
|
|
|
|
pkt->updateTimestamp();
|
|
@@ -1193,18 +1095,10 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */
|
|
|
if (received) {
|
|
|
pkt->setIface(received->getName());
|
|
|
} else {
|
|
|
- cout << "Received packet over unknown interface (ifindex="
|
|
|
- << pkt->getIndex() << ")." << endl;
|
|
|
- return (boost::shared_ptr<Pkt6>()); // NULL
|
|
|
+ isc_throw(SocketReadError, "received packet over unknown interface"
|
|
|
+ << "(ifindex=" << pkt->getIndex() << ")");
|
|
|
}
|
|
|
|
|
|
- /// @todo: Move this to LOG_DEBUG
|
|
|
- cout << "Received " << pkt->getBuffer().getLength() << " bytes over "
|
|
|
- << pkt->getIface() << "/" << pkt->getIndex() << " interface: "
|
|
|
- << " src=" << pkt->getRemoteAddr().toText()
|
|
|
- << ", dst=" << pkt->getLocalAddr().toText()
|
|
|
- << endl;
|
|
|
-
|
|
|
return (pkt);
|
|
|
}
|
|
|
|