const IfaceMgr::IfaceCollection& ifaces = IfaceMgr::instance().getIfaces();
// Let's find suitable interface.
- for (IfaceMgr::IfaceCollection::const_iterator iface = ifaces.begin();
- iface != ifaces.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces) {
// All the following checks could be merged into one multi-condition
// statement, but let's keep them separated as perhaps one day
// we will grow knobs to selectively turn them on or off. Also,
ADD_FAILURE() << "No interfaces detected.";
}
- valid_iface_ = ifaces.begin()->getName();
+ valid_iface_ = (*ifaces.begin())->getName();
bogus_iface_ = "nonexisting0";
if (IfaceMgr::instance().getIface(bogus_iface_)) {
ADD_FAILURE() << "No interfaces detected.";
}
- valid_iface_ = ifaces.begin()->getName();
+ valid_iface_ = (*ifaces.begin())->getName();
}
// Generate IA_NA or IA_PD option with specified parameters
-// Copyright (C) 2012-2014 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2014,2015 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
}
TestControl::TestControlSocket::~TestControlSocket() {
- Iface* iface = IfaceMgr::instance().getIface(ifindex_);
+ IfacePtr iface = IfaceMgr::instance().getIface(ifindex_);
if (iface) {
iface->delSocket(sockfd_);
}
void
TestControl::TestControlSocket::initSocketData() {
- const IfaceMgr::IfaceCollection& ifaces =
- IfaceMgr::instance().getIfaces();
- for (IfaceMgr::IfaceCollection::const_iterator it = ifaces.begin();
- it != ifaces.end();
- ++it) {
+ BOOST_FOREACH(IfacePtr iface, IfaceMgr::instance().getIfaces()) {
const Iface::SocketCollection& socket_collection =
- it->getSockets();
+ iface->getSockets();
for (Iface::SocketCollection::const_iterator s =
socket_collection.begin();
s != socket_collection.end();
++s) {
if (s->sockfd_ == sockfd_) {
- ifindex_ = it->getIndex();
+ ifindex_ = iface->getIndex();
addr_ = s->addr_;
return;
}
// If user specified interface name with '-l' the
// IPV6_MULTICAST_IF has to be set.
if ((ret >= 0) && options.isInterface()) {
- Iface* iface =
+ IfacePtr iface =
IfaceMgr::instance().getIface(options.getLocalName());
if (iface == NULL) {
isc_throw(Unexpected, "unknown interface "
const Pkt4Ptr& pkt) {
CommandOptions& options = CommandOptions::instance();
// Interface name.
- Iface* iface = IfaceMgr::instance().getIface(socket.ifindex_);
+ IfacePtr iface = IfaceMgr::instance().getIface(socket.ifindex_);
if (iface == NULL) {
isc_throw(BadValue, "unable to find interface with given index");
}
const Pkt6Ptr& pkt) {
CommandOptions& options = CommandOptions::instance();
// Interface name.
- Iface* iface = IfaceMgr::instance().getIface(socket.ifindex_);
+ IfacePtr iface = IfaceMgr::instance().getIface(socket.ifindex_);
if (iface == NULL) {
isc_throw(BadValue, "unable to find interface with given index");
}
-// Copyright (C) 2012-2013 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2013,2015 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
///
/// \return local loopback interface name.
std::string getLocalLoopback() const {
- const IfaceMgr::IfaceCollection& ifaces =
- IfaceMgr::instance().getIfaces();
- for (IfaceMgr::IfaceCollection::const_iterator iface = ifaces.begin();
- iface != ifaces.end();
- ++iface) {
+ BOOST_FOREACH(IfacePtr iface, IfaceMgr::instance().getIfaces()) {
if (iface->flag_loopback_) {
return (iface->getName());
}
#include <exceptions/exceptions.h>
#include <util/io/pktinfo_utilities.h>
+#include <boost/foreach.hpp>
+
#include <cstring>
#include <errno.h>
#include <fstream>
}
void IfaceMgr::closeSockets() {
- for (IfaceCollection::iterator iface = ifaces_.begin();
- iface != ifaces_.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
iface->closeSockets();
}
}
void
IfaceMgr::closeSockets(const uint16_t family) {
- for (IfaceCollection::iterator iface = ifaces_.begin();
- iface != ifaces_.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
iface->closeSockets(family);
}
}
bool
IfaceMgr::hasOpenSocket(const uint16_t family) const {
// Iterate over all interfaces and search for open sockets.
- for (IfaceCollection::const_iterator iface = ifaces_.begin();
- iface != ifaces_.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& sockets = iface->getSockets();
for (Iface::SocketCollection::const_iterator sock = sockets.begin();
sock != sockets.end(); ++sock) {
bool
IfaceMgr::hasOpenSocket(const IOAddress& addr) const {
// Iterate over all interfaces and search for open sockets.
- for (IfaceCollection::const_iterator iface = ifaces_.begin();
- iface != ifaces_.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& sockets = iface->getSockets();
for (Iface::SocketCollection::const_iterator sock = sockets.begin();
sock != sockets.end(); ++sock) {
"Interface detection on this OS is not supported.");
}
- Iface iface(ifaceName, if_nametoindex(ifaceName.c_str()));
- iface.flag_up_ = true;
- iface.flag_running_ = true;
+ IfacePtr iface(new 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->flag_loopback_ = false;
+ iface->flag_multicast_ = true;
+ iface->flag_broadcast_ = true;
+ iface->setHWType(HWTYPE_ETHERNET);
- iface.addAddress(IOAddress(v4addr));
- iface.addAddress(IOAddress(v6addr));
+ iface->addAddress(IOAddress(v4addr));
+ iface->addAddress(IOAddress(v6addr));
addInterface(iface);
}
int count = 0;
int bcast_num = 0;
- for (IfaceCollection::iterator iface = ifaces_.begin();
- iface != ifaces_.end();
- ++iface) {
-
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
// If the interface is inactive, there is nothing to do. Simply
// proceed to the next detected interface.
if (iface->inactive4_) {
IfaceMgrErrorMsgCallback error_handler) {
int count = 0;
- for (IfaceCollection::iterator iface = ifaces_.begin();
- iface != ifaces_.end();
- ++iface) {
-
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
if (iface->inactive6_) {
continue;
void
IfaceMgr::printIfaces(std::ostream& out /*= std::cout*/) {
- for (IfaceCollection::const_iterator iface=ifaces_.begin();
- iface!=ifaces_.end();
- ++iface) {
-
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::AddressCollection& addrs = iface->getAddresses();
out << "Detected interface " << iface->getFullName()
}
}
-Iface*
+IfacePtr
IfaceMgr::getIface(int ifindex) {
- for (IfaceCollection::iterator iface=ifaces_.begin();
- iface!=ifaces_.end();
- ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
if (iface->getIndex() == ifindex)
- return (&(*iface));
+ return (iface);
}
- return (NULL); // not found
+ return (IfacePtr()); // not found
}
-Iface*
+IfacePtr
IfaceMgr::getIface(const std::string& ifname) {
- for (IfaceCollection::iterator iface=ifaces_.begin();
- iface!=ifaces_.end();
- ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
if (iface->getName() == ifname)
- return (&(*iface));
+ return (iface);
}
- return (NULL); // not found
+ return (IfacePtr()); // not found
}
void
void
IfaceMgr::clearUnicasts() {
- for (IfaceCollection::iterator iface=ifaces_.begin();
- iface!=ifaces_.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
iface->clearUnicasts();
}
}
int IfaceMgr::openSocket(const std::string& ifname, const IOAddress& addr,
const uint16_t port, const bool receive_bcast,
const bool send_bcast) {
- Iface* iface = getIface(ifname);
+ IfacePtr iface = getIface(ifname);
if (!iface) {
isc_throw(BadValue, "There is no " << ifname << " interface present.");
}
const uint16_t port,
const uint8_t family) {
// Search for specified interface among detected interfaces.
- for (IfaceCollection::iterator iface = ifaces_.begin();
- iface != ifaces_.end();
- ++iface) {
-
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
if ((iface->getFullName() != ifname) &&
(iface->getName() != ifname)) {
continue;
const uint16_t port) {
// Search through detected interfaces and addresses to match
// local address we got.
- for (IfaceCollection::iterator iface = ifaces_.begin();
- iface != ifaces_.end();
- ++iface) {
-
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
Iface::AddressCollection addrs = iface->getAddresses();
for (Iface::AddressCollection::iterator addr_it = addrs.begin();
bool
IfaceMgr::send(const Pkt6Ptr& pkt) {
- Iface* iface = getIface(pkt->getIface());
+ IfacePtr iface = getIface(pkt->getIface());
if (!iface) {
isc_throw(BadValue, "Unable to send DHCPv6 message. Invalid interface ("
<< pkt->getIface() << ") specified.");
bool
IfaceMgr::send(const Pkt4Ptr& pkt) {
- Iface* iface = getIface(pkt->getIface());
+ IfacePtr iface = getIface(pkt->getIface());
if (!iface) {
isc_throw(BadValue, "Unable to send DHCPv4 message. Invalid interface ("
<< pkt->getIface() << ") specified.");
" one million microseconds");
}
const SocketInfo* candidate = 0;
- IfaceCollection::iterator iface;
+ IfacePtr iface;
fd_set sockets;
int maxfd = 0;
/// @todo: marginal performance optimization. We could create the set once
/// and then use its copy for select(). Please note that select() modifies
/// provided set to indicated which sockets have something to read.
- for (iface = ifaces_.begin(); iface != ifaces_.end(); ++iface) {
-
+ BOOST_FOREACH(iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
}
// Let's find out which interface/socket has the data
- for (iface = ifaces_.begin(); iface != ifaces_.end(); ++iface) {
+ BOOST_FOREACH(iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
/// @todo: marginal performance optimization. We could create the set once
/// and then use its copy for select(). Please note that select() modifies
/// provided set to indicated which sockets have something to read.
- IfaceCollection::const_iterator iface;
- for (iface = ifaces_.begin(); iface != ifaces_.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
}
// Let's find out which interface/socket has the data
- for (iface = ifaces_.begin(); iface != ifaces_.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces_) {
const Iface::SocketCollection& socket_collection = iface->getSockets();
for (Iface::SocketCollection::const_iterator s = socket_collection.begin();
s != socket_collection.end(); ++s) {
}
uint16_t IfaceMgr::getSocket(const isc::dhcp::Pkt6& pkt) {
- Iface* iface = getIface(pkt.getIface());
- if (iface == NULL) {
+ IfacePtr iface = getIface(pkt.getIface());
+ if (!iface) {
isc_throw(IfaceNotFound, "Tried to find socket for non-existent interface");
}
SocketInfo
IfaceMgr::getSocket(isc::dhcp::Pkt4 const& pkt) {
- Iface* iface = getIface(pkt.getIface());
+ IfacePtr iface = getIface(pkt.getIface());
if (iface == NULL) {
isc_throw(IfaceNotFound, "Tried to find socket for non-existent interface");
}
/// returned by the OS kernel when the socket is opened. Hence, it is
/// convenient to allocate the buffer when the socket is being opened and
/// utilze it throughout the lifetime of the socket.
-class Iface {
+class Iface : public boost::noncopyable {
public:
/// Maximum MAC address length (Infiniband uses 20 bytes)
std::vector<uint8_t> read_buffer_;
};
+typedef boost::shared_ptr<Iface> IfacePtr;
+
/// @brief This type describes the callback function invoked when error occurs
/// in the IfaceMgr.
///
// also hide it (make it public make tests easier for now)
/// Type that holds a list of interfaces.
- typedef std::list<Iface> IfaceCollection;
+ typedef std::list<IfacePtr> IfaceCollection;
/// IfaceMgr is a singleton class. This method returns reference
/// to its sole instance.
/// @return interface with requested index (or NULL if no such
/// interface is present)
///
- Iface* getIface(int ifindex);
+ IfacePtr getIface(int ifindex);
/// @brief Returns interface with specified interface name
///
/// @return interface with requested name (or NULL if no such
/// interface is present)
///
- Iface* getIface(const std::string& ifname);
+ IfacePtr getIface(const std::string& ifname);
/// @brief Returns container with all interfaces.
///
/// @param iface reference to Iface object.
/// @note This function must be public because it has to be callable
/// from unit tests.
- void addInterface(const Iface& iface) {
+ void addInterface(const IfacePtr& iface) {
ifaces_.push_back(iface);
}
isc_throw(Unexpected, "Network interfaces detection failed.");
}
- typedef map<string, Iface> ifaceLst;
- ifaceLst::iterator iface_iter;
- ifaceLst ifaces;
+ typedef map<string, IfacePtr> IfaceLst;
+ IfaceLst::iterator iface_iter;
+ IfaceLst ifaces;
// First lookup for getting interfaces ...
for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
continue;
}
- Iface iface(ifname, ifindex);
- iface.setFlags(ifptr->ifa_flags);
- ifaces.insert(pair<string, Iface>(ifname, iface));
+ IfacePtr iface(new Iface(ifname, ifindex));
+ iface->setFlags(ifptr->ifa_flags);
+ ifaces.insert(pair<string, IfacePtr>(ifname, iface));
}
// Second lookup to get MAC and IP addresses
reinterpret_cast<struct sockaddr_dl *>(ifptr->ifa_addr);
ptr = reinterpret_cast<uint8_t *>(LLADDR(ldata));
- iface_iter->second.setHWType(ldata->sdl_type);
- iface_iter->second.setMac(ptr, ldata->sdl_alen);
+ iface_iter->second->setHWType(ldata->sdl_type);
+ iface_iter->second->setMac(ptr, ldata->sdl_alen);
} else if(ifptr->ifa_addr->sa_family == AF_INET6) {
// IPv6 Addr
struct sockaddr_in6 * adata =
ptr = reinterpret_cast<uint8_t *>(&adata->sin6_addr);
IOAddress a = IOAddress::fromBytes(AF_INET6, ptr);
- iface_iter->second.addAddress(a);
+ iface_iter->second->addAddress(a);
} else {
// IPv4 Addr
struct sockaddr_in * adata =
ptr = reinterpret_cast<uint8_t *>(&adata->sin_addr);
IOAddress a = IOAddress::fromBytes(AF_INET, ptr);
- iface_iter->second.addAddress(a);
+ iface_iter->second->addAddress(a);
}
}
freeifaddrs(iflist);
// Interfaces registering
- for(ifaceLst::const_iterator iface_iter = ifaces.begin();
+ for(IfaceLst::const_iterator iface_iter = ifaces.begin();
iface_iter != ifaces.end(); ++iface_iter) {
- ifaces_.push_back(iface_iter->second);
+ addInterface(iface_iter->second);
}
}
// Let's get the interface this packet was received on. We need it to get
// hardware type
- Iface* iface = IfaceMgr::instance().getIface(iface_);
+ IfacePtr iface = IfaceMgr::instance().getIface(iface_);
uint16_t hwtype = 0; // not specified
if (iface) {
hwtype = iface->getHWType();
// Let's get the interface this packet was received on. We need it to get
// the hardware type.
- Iface* iface = IfaceMgr::instance().getIface(iface_);
+ IfacePtr iface = IfaceMgr::instance().getIface(iface_);
uint16_t hwtype = 0; // not specified
// If we get the interface HW type, great! If not, let's not panic.
pkt->setRemotePort(ntohs(from.sin6_port));
pkt->setIndex(ifindex);
- Iface* received = IfaceMgr::instance().getIface(pkt->getIndex());
+ IfacePtr received = IfaceMgr::instance().getIface(pkt->getIndex());
if (received) {
pkt->setIface(received->getName());
} else {
void
IfaceMgrTestConfig::addAddress(const std::string& iface_name,
const IOAddress& address) {
- Iface* iface = IfaceMgr::instance().getIface(iface_name);
- if (iface == NULL) {
+ IfacePtr iface = IfaceMgr::instance().getIface(iface_name);
+ if (!iface) {
isc_throw(isc::BadValue, "interface '" << iface_name
<< "' doesn't exist");
}
}
void
-IfaceMgrTestConfig::addIface(const Iface& iface) {
+IfaceMgrTestConfig::addIface(const IfacePtr& iface) {
IfaceMgr::instance().addInterface(iface);
}
IfaceMgr::instance().addInterface(createIface(name, ifindex));
}
-Iface
+IfacePtr
IfaceMgrTestConfig::createIface(const std::string &name, const int ifindex) {
- Iface iface(name, ifindex);
+ IfacePtr iface(new Iface(name, ifindex));
if (name == "lo") {
- iface.flag_loopback_ = true;
+ iface->flag_loopback_ = true;
// Don't open sockets on the loopback interface.
- iface.inactive4_ = true;
- iface.inactive6_ = true;
+ iface->inactive4_ = true;
+ iface->inactive6_ = true;
} else {
- iface.inactive4_ = false;
- iface.inactive6_ = false;
+ iface->inactive4_ = false;
+ iface->inactive6_ = false;
}
- iface.flag_multicast_ = true;
+ iface->flag_multicast_ = true;
// On BSD systems, the SO_BINDTODEVICE option is not supported.
// Therefore the IfaceMgr will throw an exception on attempt to
// open sockets on more than one broadcast-capable interface at
// the same time. In order to prevent this error, we mark all
// interfaces broadcast-incapable for unit testing.
- iface.flag_broadcast_ = false;
- iface.flag_up_ = true;
- iface.flag_running_ = true;
+ iface->flag_broadcast_ = false;
+ iface->flag_up_ = true;
+ iface->flag_running_ = true;
return (iface);
}
const FlagRunning& running,
const FlagInactive4& inactive4,
const FlagInactive6& inactive6) {
- Iface* iface = IfaceMgr::instance().getIface(name);
+ IfacePtr iface = IfaceMgr::instance().getIface(name);
if (iface == NULL) {
isc_throw(isc::BadValue, "interface '" << name << "' doesn't exist");
}
bool
IfaceMgrTestConfig::socketOpen(const std::string& iface_name,
const int family) const {
- Iface* iface = IfaceMgr::instance().getIface(iface_name);
+ IfacePtr iface = IfaceMgr::instance().getIface(iface_name);
if (iface == NULL) {
isc_throw(Unexpected, "No such interface '" << iface_name << "'");
}
bool
IfaceMgrTestConfig::socketOpen(const std::string& iface_name,
const std::string& address) const {
- Iface* iface = IfaceMgr::instance().getIface(iface_name);
- if (iface == NULL) {
+ IfacePtr iface = IfaceMgr::instance().getIface(iface_name);
+ if (!iface) {
isc_throw(Unexpected, "No such interface '" << iface_name << "'");
}
bool
IfaceMgrTestConfig::unicastOpen(const std::string& iface_name) const {
- Iface* iface = IfaceMgr::instance().getIface(iface_name);
- if (iface == NULL) {
+ IfacePtr iface = IfaceMgr::instance().getIface(iface_name);
+ if (!iface) {
isc_throw(Unexpected, "No such interface '" << iface_name << "'");
}
/// @brief Configures new interface for the @c IfaceMgr.
///
/// @param iface Object encapsulating interface to be added.
- void addIface(const Iface& iface);
+ void addIface(const IfacePtr& iface);
/// @brief Configures new interface for the @c IfaceMgr.
///
/// @param ifindex An index of the interface to be created.
///
/// @return An object representing interface.
- static Iface createIface(const std::string& name, const int ifindex);
+ static IfacePtr createIface(const std::string& name, const int ifindex);
/// @brief Creates a default (example) set of fake interfaces.
void createIfaces();
ifaces_.clear();
// local loopback
- Iface lo = createIface("lo", 0);
- lo.addAddress(IOAddress("127.0.0.1"));
- lo.addAddress(IOAddress("::1"));
+ IfacePtr lo = createIface("lo", 0);
+ lo->addAddress(IOAddress("127.0.0.1"));
+ lo->addAddress(IOAddress("::1"));
ifaces_.push_back(lo);
// eth0
- Iface eth0 = createIface("eth0", 1);
- eth0.addAddress(IOAddress("10.0.0.1"));
- eth0.addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
- eth0.addAddress(IOAddress("2001:db8:1::1"));
+ IfacePtr eth0 = createIface("eth0", 1);
+ eth0->addAddress(IOAddress("10.0.0.1"));
+ eth0->addAddress(IOAddress("fe80::3a60:77ff:fed5:cdef"));
+ eth0->addAddress(IOAddress("2001:db8:1::1"));
ifaces_.push_back(eth0);
// eth1
- Iface eth1 = createIface("eth1", 2);
- eth1.addAddress(IOAddress("192.0.2.3"));
- eth1.addAddress(IOAddress("fe80::3a60:77ff:fed5:abcd"));
+ IfacePtr eth1 = createIface("eth1", 2);
+ eth1->addAddress(IOAddress("192.0.2.3"));
+ eth1->addAddress(IOAddress("fe80::3a60:77ff:fed5:abcd"));
ifaces_.push_back(eth1);
}
/// @param ifindex An index of the interface to be created.
///
/// @return An object representing interface.
- static Iface createIface(const std::string& name, const int ifindex) {
- Iface iface(name, ifindex);
+ static IfacePtr createIface(const std::string& name, const int ifindex) {
+ IfacePtr iface(new Iface(name, ifindex));
if (name == "lo") {
- iface.flag_loopback_ = true;
+ iface->flag_loopback_ = true;
// Don't open sockets on loopback interface.
- iface.inactive4_ = true;
- iface.inactive6_ = true;
+ iface->inactive4_ = true;
+ iface->inactive6_ = true;
} else {
- iface.inactive4_ = false;
- iface.inactive6_ = false;
+ iface->inactive4_ = false;
+ iface->inactive6_ = false;
}
- iface.flag_multicast_ = true;
+ iface->flag_multicast_ = true;
// On BSD systems, the SO_BINDTODEVICE option is not supported.
// Therefore the IfaceMgr will throw an exception on attempt to
// open sockets on more than one broadcast-capable interface at
// the same time. In order to prevent this error, we mark all
// interfaces broadcast-incapable for unit testing.
- iface.flag_broadcast_ = false;
- iface.flag_up_ = true;
- iface.flag_running_ = true;
+ iface->flag_broadcast_ = false;
+ iface->flag_up_ = true;
+ iface->flag_running_ = true;
return (iface);
}
///
/// @return true if there is a socket bound to the specified address.
bool isBound(const std::string& iface_name, const std::string& addr) {
- Iface* iface = getIface(iface_name);
- if (iface == NULL) {
+ IfacePtr iface = getIface(iface_name);
+ if (!iface) {
ADD_FAILURE() << "the interface " << iface_name << " doesn't exist";
return (false);
}
const bool inactive6) {
for (IfaceMgr::IfaceCollection::iterator iface = ifaces_.begin();
iface != ifaces_.end(); ++iface) {
- if (iface->getName() == name) {
- iface->flag_loopback_ = loopback;
- iface->flag_up_ = up;
- iface->flag_running_ = running;
- iface->inactive4_ = inactive4;
- iface->inactive6_ = inactive6;
+ if ((*iface)->getName() == name) {
+ (*iface)->flag_loopback_ = loopback;
+ (*iface)->flag_up_ = up;
+ (*iface)->flag_running_ = running;
+ (*iface)->inactive4_ = inactive4;
+ (*iface)->inactive6_ = inactive6;
}
}
}
// to create one and add.
int ifindex = if_nametoindex(LOOPBACK);
ASSERT_GT(ifindex, 0);
- Iface lo_iface(LOOPBACK, ifindex);
+ IfacePtr lo_iface(new Iface(LOOPBACK, ifindex));
iface_mgr->getIfacesLst().push_back(lo_iface);
// Create set of V4 and V6 sockets on the loopback interface.
}
// At the end we should have 3 IPv4 and 3 IPv6 sockets open.
- Iface* iface = iface_mgr->getIface(LOOPBACK);
+ IfacePtr iface = iface_mgr->getIface(LOOPBACK);
ASSERT_TRUE(iface != NULL);
int v4_sockets_count = getOpenSocketsCount(*iface, AF_INET);
TEST_F(IfaceMgrTest, ifaceHasAddress) {
IfaceMgrTestConfig config(true);
- Iface* iface = IfaceMgr::instance().getIface("eth0");
- ASSERT_FALSE(iface == NULL);
+ IfacePtr iface = IfaceMgr::instance().getIface("eth0");
+ ASSERT_TRUE(iface);
EXPECT_TRUE(iface->hasAddress(IOAddress("10.0.0.1")));
EXPECT_FALSE(iface->hasAddress(IOAddress("10.0.0.2")));
EXPECT_TRUE(iface->hasAddress(IOAddress("fe80::3a60:77ff:fed5:cdef")));
scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
// Interface name, ifindex
- Iface iface1("lo1", 100);
- Iface iface2("eth9", 101);
- Iface iface3("en3", 102);
- Iface iface4("e1000g4", 103);
+ IfacePtr iface1(new Iface("lo1", 100));
+ IfacePtr iface2(new Iface("eth9", 101));
+ IfacePtr iface3(new Iface("en3", 102));
+ IfacePtr iface4(new Iface("e1000g4", 103));
cout << "This test assumes that there are less than 100 network interfaces"
<< " in the tested system and there are no lo1, eth9, en3, e1000g4"
<< " or wifi15 interfaces present." << endl;
for (IfaceMgr::IfaceCollection::iterator iface=ifacemgr->getIfacesLst().begin();
iface != ifacemgr->getIfacesLst().end();
++iface) {
- cout << " " << iface->getFullName() << endl;
+ cout << " " << (*iface)->getFullName() << endl;
}
// Check that interface can be retrieved by ifindex
- Iface* tmp = ifacemgr->getIface(102);
- ASSERT_TRUE(tmp != NULL);
+ IfacePtr tmp = ifacemgr->getIface(102);
+ ASSERT_TRUE(tmp);
EXPECT_EQ("en3", tmp->getName());
EXPECT_EQ(102, tmp->getIndex());
// Check that interface can be retrieved by name
tmp = ifacemgr->getIface("lo1");
- ASSERT_TRUE(tmp != NULL);
+ ASSERT_TRUE(tmp);
EXPECT_EQ("lo1", tmp->getName());
EXPECT_EQ(100, tmp->getIndex());
// Check that non-existing interfaces are not returned
- EXPECT_EQ(static_cast<void*>(NULL), ifacemgr->getIface("wifi15") );
+ EXPECT_FALSE(ifacemgr->getIface("wifi15") );
}
TEST_F(IfaceMgrTest, clearIfaces) {
// Get loopback interface. If we don't find one we are unable to run
// this test but we don't want to fail.
- Iface* iface_ptr = ifacemgr->getIface(LOOPBACK);
+ IfacePtr iface_ptr = ifacemgr->getIface(LOOPBACK);
if (iface_ptr == NULL) {
cout << "Local loopback interface not found. Skipping test. " << endl;
return;
// Now let's test if IfaceMgr handles socket info properly
scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
- Iface* loopback = ifacemgr->getIface(LOOPBACK);
+ IfacePtr loopback = ifacemgr->getIface(LOOPBACK);
ASSERT_TRUE(loopback);
loopback->addSocket(sock1);
loopback->addSocket(sock2);
// with the interface name held by IfaceMgr. Instead, we use the
// index of the interface because the virtual interfaces have the
// same indexes as the physical interfaces.
- Iface* i = ifacemgr.getIface(if_nametoindex(ifptr->ifa_name));
+ IfacePtr i = ifacemgr.getIface(if_nametoindex(ifptr->ifa_name));
// If the given interface was also detected by the IfaceMgr,
// check that its properties are correct.
scoped_ptr<NakedIfaceMgr> ifacemgr(new NakedIfaceMgr());
// Get the interface (todo: which interface)
- Iface* iface = ifacemgr->getIface("eth0");
+ IfacePtr iface = ifacemgr->getIface("eth0");
ASSERT_TRUE(iface);
iface->inactive6_ = false;
TEST_F(IfaceMgrTest, unicastDuplicates) {
NakedIfaceMgr ifacemgr;
- Iface* iface = ifacemgr.getIface(LOOPBACK);
- if (iface == NULL) {
+ IfacePtr iface = ifacemgr.getIface(LOOPBACK);
+ if (iface) {
cout << "Local loopback interface not found. Skipping test. " << endl;
return;
}
Pkt6 pkt(DHCPV6_ADVERTISE, 1234);
// Let's get the first interface
- Iface* iface = IfaceMgr::instance().getIface(1);
+ IfacePtr iface = IfaceMgr::instance().getIface(1);
ASSERT_TRUE(iface);
// and set source interface data properly. getMACFromIPv6LinkLocal attempts
ASSERT_EQ(1, pkt.relay_info_.size());
// Let's get the first interface
- Iface* iface = IfaceMgr::instance().getIface(1);
+ IfacePtr iface = IfaceMgr::instance().getIface(1);
ASSERT_TRUE(iface);
// and set source interface data properly. getMACFromIPv6LinkLocal attempts
ASSERT_EQ(3, pkt.relay_info_.size());
// Let's get the first interface
- Iface* iface = IfaceMgr::instance().getIface(1);
+ IfacePtr iface = IfaceMgr::instance().getIface(1);
ASSERT_TRUE(iface);
// and set source interface data properly. getMACFromIPv6LinkLocal attempts
EXPECT_FALSE(pkt.getMAC(HWAddr::HWADDR_SOURCE_REMOTE_ID));
// Let's get the first interface
- Iface* iface = IfaceMgr::instance().getIface(1);
+ IfacePtr iface = IfaceMgr::instance().getIface(1);
ASSERT_TRUE(iface);
// and set source interface data properly. getMACFromIPv6LinkLocal attempts
#include <dhcpsrv/cfg_iface.h>
#include <util/strutil.h>
#include <boost/bind.hpp>
+#include <boost/foreach.hpp>
#include <algorithm>
using namespace isc::asiolink;
bool
CfgIface::multipleAddressesPerInterfaceActive() const {
const IfaceMgr::IfaceCollection& ifaces = IfaceMgr::instance().getIfaces();
- for (IfaceMgr::IfaceCollection::const_iterator iface = ifaces.begin();
- iface != ifaces.end(); ++iface) {
+ BOOST_FOREACH(IfacePtr iface, ifaces) {
if (iface->countActive4() > 1) {
return (true);
}
if (!wildcard_used_) {
for (IfaceSet::const_iterator iface_name = iface_set_.begin();
iface_name != iface_set_.end(); ++iface_name) {
- Iface* iface = IfaceMgr::instance().getIface(*iface_name);
+ IfacePtr iface = IfaceMgr::instance().getIface(*iface_name);
// This shouldn't really happen because we are checking the
// names of interfaces when they are being added (use()
// function). But, if someone has triggered detection of
// for DHCPv4.
for (ExplicitAddressMap::const_iterator unicast = address_map_.begin();
unicast != address_map_.end(); ++unicast) {
- Iface* iface = IfaceMgr::instance().getIface(unicast->first);
+ IfacePtr iface = IfaceMgr::instance().getIface(unicast->first);
if (iface == NULL) {
isc_throw(Unexpected,
"fail to open unicast socket on interface '"
void
CfgIface::setState(const uint16_t family, const bool inactive,
const bool loopback_inactive) const {
- IfaceMgr::IfaceCollection ifaces = IfaceMgr::instance().getIfaces();
- for (IfaceMgr::IfaceCollection::iterator iface = ifaces.begin();
- iface != ifaces.end(); ++iface) {
- Iface* iface_ptr = IfaceMgr::instance().getIface(iface->getName());
- bool iface_inactive = iface_ptr->flag_loopback_ ?
- loopback_inactive : inactive;
+ const IfaceMgr::IfaceCollection& ifaces = IfaceMgr::instance().getIfaces();
+ BOOST_FOREACH(IfacePtr iface, ifaces) {
+ bool iface_inactive = iface->flag_loopback_ ? loopback_inactive : inactive;
if (family == AF_INET) {
- iface_ptr->inactive4_ = iface_inactive;
+ iface->inactive4_ = iface_inactive;
} else {
- iface_ptr->inactive6_ = iface_inactive;
+ iface->inactive6_ = iface_inactive;
}
// Activate/deactivate all addresses.
- setIfaceAddrsState(family, !inactive, *iface_ptr);
+ setIfaceAddrsState(family, !inactive, *iface);
}
}
}
// Interface must exist.
- Iface* iface = IfaceMgr::instance().getIface(name);
- if (iface == NULL) {
+ IfacePtr iface = IfaceMgr::instance().getIface(name);
+ if (!iface) {
isc_throw(NoSuchIface, "interface '" << name
<< "' doesn't exist in the system");
// If local interface name is known, use the local address on this
// interface.
} else if (!selector.iface_name_.empty()) {
- Iface* iface = IfaceMgr::instance().getIface(selector.iface_name_);
+ IfacePtr iface = IfaceMgr::instance().getIface(selector.iface_name_);
// This should never happen in the real life. Hence we throw an
// exception.
if (iface == NULL) {