}
bool Iface::delAddress(const isc::asiolink::IOAddress& addr) {
- for (AddressCollection::iterator a = addrs_.begin();
- a!=addrs_.end(); ++a) {
+ for (AddressCollection::iterator a = addrs_.begin(); a != addrs_.end(); ++a) {
if (a->get() == addr) {
addrs_.erase(a);
return (true);
bool Iface::delSocket(const uint16_t sockfd) {
list<SocketInfo>::iterator sock = sockets_.begin();
- while (sock!=sockets_.end()) {
+ while (sock != sockets_.end()) {
if (sock->sockfd_ == sockfd) {
close(sockfd);
// Close fallback socket if open.
}
void Iface::addUnicast(const isc::asiolink::IOAddress& addr) {
- for (Address a : unicasts_) {
+ for (const Address& a : unicasts_) {
if (a.get() == addr) {
isc_throw(BadValue, "Address " << addr
<< " already defined on the " << name_ << " interface.");
Iface::getAddress4(isc::asiolink::IOAddress& address) const {
// Iterate over existing addresses assigned to the interface.
// Try to find the one that is IPv4.
- for (Address addr : getAddresses()) {
+ for (const Address& addr : getAddresses()) {
// If address is IPv4, we assign it to the function argument
// and return true.
if (addr.get().isV4()) {
bool
Iface::hasAddress(const isc::asiolink::IOAddress& address) const {
- for (Address addr : getAddresses()) {
+ for (const Address& addr : getAddresses()) {
if (address == addr.get()) {
return (true);
}
void
Iface::setActive(const IOAddress& address, const bool active) {
- for (AddressCollection::iterator addr_it = addrs_.begin();
- addr_it != addrs_.end(); ++addr_it) {
- if (address == addr_it->get()) {
- addr_it->unspecified(!active);
+ for (auto& addr : addrs_) {
+ if (address == addr.get()) {
+ addr.unspecified(!active);
return;
}
}
void
Iface::setActive(const bool active) {
- for (AddressCollection::iterator addr_it = addrs_.begin();
- addr_it != addrs_.end(); ++addr_it) {
- addr_it->unspecified(!active);
+ for (auto& addr : addrs_) {
+ addr.unspecified(!active);
}
}
unsigned int
Iface::countActive4() const {
uint16_t count = 0;
- for (Address addr : addrs_) {
+ for (const Address& addr : addrs_) {
if (!addr.unspecified() && addr.get().isV4()) {
++count;
}
// Stops the receiver thread if there is one.
stopDHCPReceiver();
- for (IfacePtr iface : ifaces_) {
+ for (const IfacePtr& iface : ifaces_) {
iface->closeSockets();
}
}
<< socketfd);
}
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo s : callbacks_) {
+ for (SocketCallbackInfo& s : callbacks_) {
// There's such a socket description there already.
// Update the callback and we're done
if (s.socket_ == socketfd) {
bool
IfaceMgr::isExternalSocket(int fd) {
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
if (s.socket_ == fd) {
return (true);
}
IfaceMgr::purgeBadSockets() {
std::lock_guard<std::mutex> lock(callbacks_mutex_);
std::vector<int> bad_fds;
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
errno = 0;
if (fcntl(s.socket_, F_GETFD) < 0 && (errno == EBADF)) {
bad_fds.push_back(s.socket_);
bool
IfaceMgr::hasOpenSocket(const uint16_t family) const {
// Iterate over all interfaces and search for open sockets.
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo sock : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& sock : iface->getSockets()) {
// Check if the socket matches specified family.
if (sock.family_ == family) {
// There is at least one socket open, so return.
return (bound_address_.count(addr.toUint32()) != 0);
}
// Iterate over all interfaces and search for open sockets.
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo sock : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& sock : iface->getSockets()) {
// Check if the socket address matches the specified address or
// if address is unspecified (in6addr_any).
if (sock.addr_ == addr) {
// This happens only with IPv6 so we do not check IPv4.
// In this case, we should check if the specified address
// belongs to any of the interfaces.
- for (IfacePtr it : ifaces_) {
- for (Iface::Address a : it->getAddresses()) {
+ for (const IfacePtr& it : ifaces_) {
+ for (const Iface::Address& a : it->getAddresses()) {
if (addr == a.get()) {
return (true);
}
int count = 0;
int bcast_num = 0;
- for (IfacePtr iface : ifaces_) {
+ for (const IfacePtr& iface : ifaces_) {
// Clear any errors from previous socket opening.
iface->clearErrors();
continue;
}
- for (Iface::Address addr : iface->getAddresses()) {
+ for (const Iface::Address& addr : iface->getAddresses()) {
// Skip non-IPv4 addresses and those that weren't selected..
if (addr.unspecified() || !addr.get().isV4()) {
continue;
const bool skip_opened) {
int count = 0;
- for (IfacePtr iface : ifaces_) {
+ for (const IfacePtr& iface : ifaces_) {
// Clear any errors from previous socket opening.
iface->clearErrors();
}
// Open unicast sockets if there are any unicast addresses defined
- for (Iface::Address addr : iface->getUnicasts()) {
+ for (const Iface::Address& addr : iface->getUnicasts()) {
// Skip the address that already has a bound socket. It allows
// for preventing bind errors or re-opening sockets.
// The @ref IfaceMgr::hasOpenSocket(addr) does match the "::"
count++;
}
- for (Iface::Address addr : iface->getAddresses()) {
-
+ for (const Iface::Address& addr : iface->getAddresses()) {
// Skip all but V6 addresses.
if (!addr.get().isV6()) {
continue;
void
IfaceMgr::printIfaces(std::ostream& out /*= std::cout*/) {
- for (IfacePtr iface : ifaces_) {
+ for (const IfacePtr& iface : ifaces_) {
const Iface::AddressCollection& addrs = iface->getAddresses();
out << "Detected interface " << iface->getFullName()
<< ")" << endl;
out << " " << addrs.size() << " addr(s):";
- for (Iface::Address addr : addrs) {
+ for (const Iface::Address& addr : addrs) {
out << " " << addr.get().toText();
}
out << endl;
void
IfaceMgr::collectBoundAddresses() {
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo sock : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& sock : iface->getSockets()) {
const IOAddress& addr = sock.addr_;
if (!addr.isV4()) {
continue;
void
IfaceMgr::clearUnicasts() {
- for (IfacePtr iface : ifaces_) {
+ for (const IfacePtr& iface : ifaces_) {
iface->clearUnicasts();
}
}
const uint16_t port,
const uint8_t family) {
// Search for specified interface among detected interfaces.
- for (IfacePtr iface : ifaces_) {
+ for (const 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 (IfacePtr iface : ifaces_) {
- for (Iface::Address a : iface->getAddresses()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const Iface::Address& a : iface->getAddresses()) {
// Local address must match one of the addresses
// on detected interfaces. If it does, we have
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
// Add this socket to listening set
addFDtoSet(s.socket_, maxfd, &sockets);
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
if (!FD_ISSET(s.socket_, &sockets)) {
continue;
}
/// @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 (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
// Only deal with IPv4 addresses.
if (s.addr_.isV4()) {
// Add this socket to listening set
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
// Add this socket to listening set
addFDtoSet(s.socket_, maxfd, &sockets);
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
if (!FD_ISSET(s.socket_, &sockets)) {
continue;
}
// Let's find out which interface/socket has the data
IfacePtr recv_if;
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
if (FD_ISSET(s.sockfd_, &sockets)) {
candidate.reset(new SocketInfo(s));
break;
/// @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 (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
// Only deal with IPv6 addresses.
if (s.addr_.isV6()) {
// Add this socket to listening set
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
// Add this socket to listening set
addFDtoSet(s.socket_, maxfd, &sockets);
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
if (!FD_ISSET(s.socket_, &sockets)) {
continue;
}
}
// Let's find out which interface/socket has the data
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
if (FD_ISSET(s.sockfd_, &sockets)) {
candidate.reset(new SocketInfo(s));
break;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
if (!callbacks_.empty()) {
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
// Add this socket to listening set
addFDtoSet(s.socket_, maxfd, &sockets);
}
bool found = false;
{
std::lock_guard<std::mutex> lock(callbacks_mutex_);
- for (SocketCallbackInfo s : callbacks_) {
+ for (const SocketCallbackInfo& s : callbacks_) {
if (!FD_ISSET(s.socket_, &sockets)) {
continue;
}
addFDtoSet(dhcp_receiver_->getWatchFd(WatchedThread::TERMINATE), maxfd, &sockets);
// Add Interface sockets.
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
// Only deal with IPv4 addresses.
if (s.addr_.isV4()) {
// Add this socket to listening set.
}
// Let's find out which interface/socket has data.
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
if (FD_ISSET(s.sockfd_, &sockets)) {
receiveDHCP4Packet(*iface, s);
// Can take time so check one more time the watch socket.
addFDtoSet(dhcp_receiver_->getWatchFd(WatchedThread::TERMINATE), maxfd, &sockets);
// Add Interface sockets.
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
// Only deal with IPv6 addresses.
if (s.addr_.isV6()) {
// Add this socket to listening set.
}
// Let's find out which interface/socket has data.
- for (IfacePtr iface : ifaces_) {
- for (SocketInfo s : iface->getSockets()) {
+ for (const IfacePtr& iface : ifaces_) {
+ for (const SocketInfo& s : iface->getSockets()) {
if (FD_ISSET(s.sockfd_, &sockets)) {
receiveDHCP6Packet(s);
// Can take time so check one more time the watch socket.