21#include <boost/scoped_ptr.hpp>
31#include <netinet/in.h>
34#include <sys/select.h>
37#define FD_COPY(orig, copy) \
39 memmove(copy, orig, sizeof(fd_set)); \
48namespace ph = std::placeholders;
65 :
name_(name), ifindex_(ifindex), mac_len_(0), hardware_type_(0),
66 flag_loopback_(false), flag_up_(false), flag_running_(false),
67 flag_multicast_(false), flag_broadcast_(false), flags_(0),
68 inactive4_(false), inactive6_(false) {
95 if ((family != AF_INET) && (family != AF_INET6)) {
97 <<
" specified when requested to close all sockets"
98 <<
" which belong to this family");
102 SocketCollection::iterator sock =
sockets_.begin();
104 if (sock->family_ == family) {
107 close(sock->sockfd_);
109 if (sock->fallbackfd_ >= 0) {
110 close(sock->fallbackfd_);
135 for (
int i = 0; i <
mac_len_; i++) {
137 tmp << static_cast<int>(
mac_[i]);
148 <<
" was detected to have link address of length "
149 << len <<
", but maximum supported length is "
154 memcpy(
mac_, mac, len);
159 for (AddressCollection::iterator a =
addrs_.begin();
161 if (a->get() == addr) {
170 list<SocketInfo>::iterator sock =
sockets_.begin();
172 if (sock->sockfd_ == sockfd) {
175 if (sock->fallbackfd_ >= 0) {
176 close(sock->fallbackfd_);
189 test_mode_(false), allow_loopback_(false) {
196 }
catch (
const std::exception& ex) {
209 }
catch (
const std::exception& ex) {
216 if (a.get() == addr) {
218 <<
" already defined on the " <<
name_ <<
" interface.");
231 if (addr.get().isV4()) {
232 address = addr.get();
243 if (address == addr.get()) {
259 for (AddressCollection::iterator addr_it =
addrs_.begin();
260 addr_it !=
addrs_.end(); ++addr_it) {
261 if (address == addr_it->get()) {
262 addr_it->unspecified(!active);
267 " found on the interface " <<
getName());
272 for (AddressCollection::iterator addr_it =
addrs_.begin();
273 addr_it !=
addrs_.end(); ++addr_it) {
274 addr_it->unspecified(!active);
282 if (!addr.unspecified() && addr.get().isV4()) {
297 iface->closeSockets();
303 dhcp_receiver_->stop();
306 dhcp_receiver_.reset();
323 return (packet_filter_->isDirectResponseSupported());
332 std::lock_guard<std::mutex> lock(callbacks_mutex_);
336 if (s.socket_ == socketfd) {
337 s.callback_ = callback;
346 callbacks_.push_back(x);
351 std::lock_guard<std::mutex> lock(callbacks_mutex_);
352 deleteExternalSocketInternal(socketfd);
356IfaceMgr::deleteExternalSocketInternal(
int socketfd) {
357 for (SocketCallbackInfoContainer::iterator s = callbacks_.begin();
358 s != callbacks_.end(); ++s) {
359 if (s->socket_ == socketfd) {
368 std::lock_guard<std::mutex> lock(callbacks_mutex_);
369 std::vector<int> bad_fds;
372 if (fcntl(s.socket_, F_GETFD) < 0 && (errno == EBADF)) {
373 bad_fds.push_back(s.socket_);
377 for (
auto bad_fd : bad_fds) {
378 deleteExternalSocketInternal(bad_fd);
381 return (bad_fds.size());
386 std::lock_guard<std::mutex> lock(callbacks_mutex_);
393 if (!packet_filter) {
406 "it is not allowed to set new packet"
407 <<
" filter when there are open IPv4 sockets - need"
408 <<
" to close them first");
411 packet_filter_ = packet_filter;
416 if (!packet_filter) {
424 "it is not allowed to set new packet"
425 <<
" filter when there are open IPv6 sockets - need"
426 <<
" to close them first");
429 packet_filter6_ = packet_filter;
438 if (sock.family_ == family) {
459 if (sock.addr_ == addr) {
461 }
else if (sock.addr_.isV6Zero()) {
468 if (addr == a.get()) {
485 const bool skip_opened) {
491 iface->clearErrors();
495 if (iface->inactive4_) {
506 if (iface->flag_loopback_ && !allow_loopback_) {
508 "must not open socket on the loopback"
509 " interface " << iface->getName());
513 if (!iface->flag_up_) {
515 "the interface " << iface->getName()
520 if (!iface->flag_running_) {
522 "the interface " << iface->getName()
523 <<
" is not running");
528 if (!iface->getAddress4(out_address)) {
530 "the interface " << iface->getName()
531 <<
" has no usable IPv4 addresses configured");
537 if (addr.unspecified() || !addr.get().isV4()) {
544 bool is_open_as_broadcast = iface->flag_broadcast_ && use_bcast;
561 "Binding socket to an interface is not"
562 " supported on this OS; therefore only"
563 " one socket listening to broadcast traffic"
564 " can be opened. Sockets will not be opened"
565 " on remaining interfaces");
577 is_open_as_broadcast,
578 is_open_as_broadcast);
581 "Failed to open socket on interface "
589 if (is_open_as_broadcast) {
615 const bool skip_opened) {
620 iface->clearErrors();
624 if (iface->inactive6_) {
635 if (iface->flag_loopback_ && !allow_loopback_) {
637 "must not open socket on the loopback"
638 " interface " << iface->getName());
640 }
else if (!iface->flag_up_) {
642 "the interface " << iface->getName()
645 }
else if (!iface->flag_running_) {
647 "the interface " << iface->getName()
648 <<
" is not running");
661 !iface->getSockets().size()) {
666 "Failed to open unicast socket on interface "
668 <<
", reason: " << ex.
what());
679 if (!addr.get().isV6()) {
688 if (!addr.get().isV6LinkLocal()){
703 !iface->getSockets().size()) {
707 IfaceMgr::openMulticastSocket(*iface, addr, port);
710 "Failed to open multicast socket on interface "
711 << iface->getName() <<
", reason: " << ex.
what());
743 dhcp_receiver_->start(std::bind(&IfaceMgr::receiveDHCP4Packets,
this));
753 dhcp_receiver_->start(std::bind(&IfaceMgr::receiveDHCP6Packets,
this));
764 if ((existing->getName() == iface->getName()) ||
765 (existing->getIndex() == iface->getIndex())) {
767 " when " << existing->getFullName() <<
779 out <<
"Detected interface " << iface->getFullName()
780 <<
", hwtype=" << iface->getHWType()
781 <<
", mac=" << iface->getPlainMac();
782 out <<
", flags=" << hex << iface->flags_ << dec <<
"("
783 << (iface->flag_loopback_?
"LOOPBACK ":
"")
784 << (iface->flag_up_?
"UP ":
"")
785 << (iface->flag_running_?
"RUNNING ":
"")
786 << (iface->flag_multicast_?
"MULTICAST ":
"")
787 << (iface->flag_broadcast_?
"BROADCAST ":
"")
789 out <<
" " << addrs.size() <<
" addr(s):";
792 out <<
" " << addr.get().toText();
800 return (getIfaceInternal(ifindex, MultiThreadingMgr::instance().getMode()));
805 return (getIfaceInternal(ifname, MultiThreadingMgr::instance().getMode()));
809IfaceCollection::getIfaceInternal(
const unsigned int ifindex,
const bool need_lock) {
814 lock_guard<mutex> lock(mutex_);
815 if (cache_ && (cache_->getIndex() == ifindex)) {
819 if (cache_ && (cache_->getIndex() == ifindex)) {
823 const auto& idx = ifaces_container_.get<1>();
824 auto it = idx.find(ifindex);
825 if (it == idx.end()) {
829 lock_guard<mutex> lock(mutex_);
839IfaceCollection::getIfaceInternal(
const std::string& ifname,
const bool need_lock) {
841 lock_guard<mutex> lock(mutex_);
842 if (cache_ && (cache_->getName() == ifname)) {
846 if (cache_ && (cache_->getName() == ifname)) {
850 const auto& idx = ifaces_container_.get<2>();
851 auto it = idx.find(ifname);
852 if (it == idx.end()) {
856 lock_guard<mutex> lock(mutex_);
872 if (ifname.empty()) {
880 if (pkt->indexSet()) {
915 iface->clearUnicasts();
920 const uint16_t port,
const bool receive_bcast,
921 const bool send_bcast) {
927 return openSocket4(*iface, addr, port, receive_bcast, send_bcast);
929 }
else if (addr.
isV6()) {
930 return openSocket6(*iface, addr, port, receive_bcast);
940 const uint8_t family) {
943 if ((iface->getFullName() != ifname) &&
944 (iface->getName() != ifname)) {
951 Iface::AddressCollection::iterator addr_it = addrs.begin();
952 while (addr_it != addrs.end()) {
953 if (addr_it->get().getFamily() == family) {
956 return (
openSocket(iface->getName(), *addr_it, port,
false));
962 if (addr_it == addrs.end()) {
964 std::string family_name(
"AF_INET");
965 if (family == AF_INET6) {
966 family_name =
"AF_INET6";
970 << ifname <<
", port: " << port <<
", address "
971 " family: " << family_name);
980 const uint16_t port) {
990 if (a.get() == addr) {
993 return (
openSocket(iface->getName(), a, port,
false));
1003 const uint16_t port) {
1006 IOAddress local_address(getLocalAddress(remote_addr, port));
1014IfaceMgr::getLocalAddress(
const IOAddress& remote_addr,
const uint16_t port) {
1016 boost::scoped_ptr<const UDPEndpoint>
1019 if (!remote_endpoint) {
1024 boost::asio::io_service io_service;
1025 boost::asio::ip::udp::socket sock(io_service);
1027 boost::system::error_code err_code;
1030 if (remote_addr.
isV4() &&
1043 sock.open(boost::asio::ip::udp::v4(), err_code);
1045 const char* errstr = strerror(errno);
1049 sock.set_option(boost::asio::socket_base::broadcast(
true), err_code);
1057 sock.connect(remote_endpoint->getASIOEndpoint(), err_code);
1064 boost::asio::ip::udp::socket::endpoint_type local_endpoint =
1065 sock.local_endpoint();
1066 boost::asio::ip::address local_address(local_endpoint.address());
1077 const bool receive_bcast,
const bool send_bcast) {
1080 receive_bcast, send_bcast);
1083 return (
info.sockfd_);
1091 << pkt->getIface() <<
") specified.");
1096 return (packet_filter6_->send(*iface,
getSocket(pkt), pkt) == 0);
1104 << pkt->getIface() <<
") specified.");
1109 return (packet_filter_->send(*iface,
getSocket(pkt).sockfd_, pkt) == 0);
1122 if (timeout_usec >= 1000000) {
1124 " one million microseconds");
1134 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1135 if (!callbacks_.empty()) {
1144 addFDtoSet(dhcp_receiver_->getWatchFd(WatchedThread::READY), maxfd, &sockets);
1155 struct timeval select_timeout;
1157 select_timeout.tv_sec = timeout_sec;
1158 select_timeout.tv_usec = timeout_usec;
1160 select_timeout.tv_sec = 0;
1161 select_timeout.tv_usec = 0;
1167 int result = select(maxfd + 1, &sockets, 0, 0, &select_timeout);
1172 }
else if (result < 0) {
1180 if (errno == EINTR) {
1182 }
else if (errno == EBADF) {
1185 "SELECT interrupted by one invalid sockets, purged "
1186 << cnt <<
" socket descriptors");
1196 string msg = dhcp_receiver_->getLastError();
1205 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1207 if (!FD_ISSET(s.socket_, &sockets)) {
1236 dhcp_receiver_->clearReady(WatchedThread::READY);
1244 if (timeout_usec >= 1000000) {
1246 " one million microseconds");
1248 boost::scoped_ptr<SocketInfo> candidate;
1260 if (s.addr_.isV4()) {
1269 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1270 if (!callbacks_.empty()) {
1278 struct timeval select_timeout;
1279 select_timeout.tv_sec = timeout_sec;
1280 select_timeout.tv_usec = timeout_usec;
1285 int result = select(maxfd + 1, &sockets, 0, 0, &select_timeout);
1291 }
else if (result < 0) {
1299 if (errno == EINTR) {
1301 }
else if (errno == EBADF) {
1304 "SELECT interrupted by one invalid sockets, purged "
1305 << cnt <<
" socket descriptors");
1315 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1317 if (!FD_ISSET(s.socket_, &sockets)) {
1346 if (FD_ISSET(s.sockfd_, &sockets)) {
1357 if (!candidate || !recv_if) {
1363 return (packet_filter_->receive(*recv_if, *candidate));
1381 FD_SET(fd, sockets);
1390 if (timeout_usec >= 1000000) {
1392 " one million microseconds");
1395 boost::scoped_ptr<SocketInfo> candidate;
1407 if (s.addr_.isV6()) {
1416 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1417 if (!callbacks_.empty()) {
1425 struct timeval select_timeout;
1426 select_timeout.tv_sec = timeout_sec;
1427 select_timeout.tv_usec = timeout_usec;
1432 int result = select(maxfd + 1, &sockets, 0, 0, &select_timeout);
1438 }
else if (result < 0) {
1446 if (errno == EINTR) {
1448 }
else if (errno == EBADF) {
1451 "SELECT interrupted by one invalid sockets, purged "
1452 << cnt <<
" socket descriptors");
1462 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1464 if (!FD_ISSET(s.socket_, &sockets)) {
1492 if (FD_ISSET(s.sockfd_, &sockets)) {
1506 return (packet_filter6_->receive(*candidate));
1512 if (timeout_usec >= 1000000) {
1514 " one million microseconds");
1524 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1525 if (!callbacks_.empty()) {
1534 addFDtoSet(dhcp_receiver_->getWatchFd(WatchedThread::READY), maxfd, &sockets);
1545 struct timeval select_timeout;
1547 select_timeout.tv_sec = timeout_sec;
1548 select_timeout.tv_usec = timeout_usec;
1550 select_timeout.tv_sec = 0;
1551 select_timeout.tv_usec = 0;
1557 int result = select(maxfd + 1, &sockets, 0, 0, &select_timeout);
1562 }
else if (result < 0) {
1570 if (errno == EINTR) {
1572 }
else if (errno == EBADF) {
1575 "SELECT interrupted by one invalid sockets, purged "
1576 << cnt <<
" socket descriptors");
1586 string msg = dhcp_receiver_->getLastError();
1595 std::lock_guard<std::mutex> lock(callbacks_mutex_);
1597 if (!FD_ISSET(s.socket_, &sockets)) {
1626 dhcp_receiver_->clearReady(WatchedThread::READY);
1633IfaceMgr::receiveDHCP4Packets() {
1640 addFDtoSet(dhcp_receiver_->getWatchFd(WatchedThread::TERMINATE), maxfd, &sockets);
1646 if (s.addr_.isV4()) {
1655 if (dhcp_receiver_->shouldTerminate()) {
1666 int result = select(maxfd + 1, &rd_set, 0, 0, 0);
1669 if (dhcp_receiver_->shouldTerminate()) {
1677 }
else if (result < 0) {
1679 if (errno != EINTR) {
1681 dhcp_receiver_->setError(strerror(errno));
1692 for (SocketInfo s : iface->getSockets()) {
1693 if (FD_ISSET(s.sockfd_, &sockets)) {
1694 receiveDHCP4Packet(*iface, s);
1696 if (dhcp_receiver_->shouldTerminate()) {
1707IfaceMgr::receiveDHCP6Packets() {
1714 addFDtoSet(dhcp_receiver_->getWatchFd(WatchedThread::TERMINATE), maxfd, &sockets);
1718 for (SocketInfo s : iface->getSockets()) {
1720 if (s.addr_.isV6()) {
1729 if (dhcp_receiver_->shouldTerminate()) {
1740 int result = select(maxfd + 1, &rd_set, 0, 0, 0);
1743 if (dhcp_receiver_->shouldTerminate()) {
1750 }
else if (result < 0) {
1752 if (errno != EINTR) {
1754 dhcp_receiver_->setError(strerror(errno));
1765 for (SocketInfo s : iface->getSockets()) {
1766 if (FD_ISSET(s.sockfd_, &sockets)) {
1767 receiveDHCP6Packet(s);
1769 if (dhcp_receiver_->shouldTerminate()) {
1779IfaceMgr::receiveDHCP4Packet(Iface& iface,
const SocketInfo& socket_info) {
1782 int result = ioctl(socket_info.sockfd_, FIONREAD, &len);
1785 dhcp_receiver_->setError(strerror(errno));
1796 pkt = packet_filter_->receive(iface, socket_info);
1797 }
catch (
const std::exception& ex) {
1798 dhcp_receiver_->setError(strerror(errno));
1800 dhcp_receiver_->setError(
"packet filter receive() failed");
1805 dhcp_receiver_->markReady(WatchedThread::READY);
1810IfaceMgr::receiveDHCP6Packet(
const SocketInfo& socket_info) {
1813 int result = ioctl(socket_info.sockfd_, FIONREAD, &len);
1816 dhcp_receiver_->setError(strerror(errno));
1827 pkt = packet_filter6_->receive(socket_info);
1828 }
catch (
const std::exception& ex) {
1829 dhcp_receiver_->setError(ex.what());
1831 dhcp_receiver_->setError(
"packet filter receive() failed");
1836 dhcp_receiver_->markReady(WatchedThread::READY);
1849 Iface::SocketCollection::const_iterator candidate = socket_collection.end();
1851 Iface::SocketCollection::const_iterator s;
1852 for (s = socket_collection.begin(); s != socket_collection.end(); ++s) {
1857 if (s->family_ != AF_INET6) {
1862 if (s->addr_.isV6Multicast()) {
1866 if (s->addr_ == pkt->getLocalAddr()) {
1869 return (s->sockfd_);
1873 if (candidate == socket_collection.end()) {
1879 if ( (pkt->getRemoteAddr().isV6LinkLocal() &&
1880 s->addr_.isV6LinkLocal()) ||
1881 (!pkt->getRemoteAddr().isV6LinkLocal() &&
1882 !s->addr_.isV6LinkLocal()) ) {
1888 if (candidate != socket_collection.end()) {
1889 return (candidate->sockfd_);
1893 <<
" does not have any suitable IPv6 sockets open.");
1907 Iface::SocketCollection::const_iterator candidate = socket_collection.end();
1908 Iface::SocketCollection::const_iterator s;
1909 for (s = socket_collection.begin(); s != socket_collection.end(); ++s) {
1910 if (s->family_ == AF_INET) {
1911 if (s->addr_ == pkt->getLocalAddr()) {
1915 if (candidate == socket_collection.end()) {
1921 if (candidate == socket_collection.end()) {
1923 <<
" does not have any suitable IPv4 sockets open.");
1926 return (*candidate);
1933 " while DHCP receiver thread is running");
1936 bool enable_queue =
false;
1937 if (queue_control) {
1948 if (family == AF_INET) {
1949 packet_queue_mgr4_->createPacketQueue(queue_control);
1951 packet_queue_mgr6_->createPacketQueue(queue_control);
1955 if (family == AF_INET) {
1956 packet_queue_mgr4_->destroyPacketQueue();
1958 packet_queue_mgr6_->destroyPacketQueue();
1962 return (enable_queue);
1967 errors_.push_back(message);
1982 if (test_mode_ && update_only) {
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown if a parameter given to a method would refer to or modify out-of-r...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
bool isV6() const
Convenience function to check for an IPv6 address.
bool isV4() const
Convenience function to check for an IPv4 address.
static const IOEndpoint * create(const int protocol, const IOAddress &address, const unsigned short port)
A polymorphic factory of endpoint from address and port.
The UDPEndpoint class is a concrete derived class of IOEndpoint that represents an endpoint of a UDP ...
static bool getBoolean(isc::data::ConstElementPtr scope, const std::string &name)
Returns a boolean parameter from a scope.
IfacePtr getIface(const unsigned int ifindex)
Lookup by interface index.
void clear()
Clear the collection.
void push_back(const IfacePtr &iface)
Adds an interface to the collection.
IfaceMgr exception thrown thrown when interface detection fails.
void clearIfaces()
Removes detected interfaces.
static void addFDtoSet(int fd, int &maxfd, fd_set *sockets)
Convenience method for adding an descriptor to a set.
int purgeBadSockets()
Scans registered socket set and removes any that are invalid.
void deleteExternalSocket(int socketfd)
Deletes external socket.
Pkt6Ptr receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv6 packets indirectly or data from external sockets.
bool openSockets4(const uint16_t port=DHCP4_SERVER_PORT, const bool use_bcast=true, IfaceMgrErrorMsgCallback error_handler=0, const bool skip_opened=false)
Opens IPv4 sockets on detected interfaces.
std::function< void(int fd)> SocketCallback
Defines callback used when data is received over external sockets.
int openSocket(const std::string &ifname, const isc::asiolink::IOAddress &addr, const uint16_t port, const bool receive_bcast=false, const bool send_bcast=false)
Opens UDP/IP socket and binds it to address, interface and port.
int openSocketFromAddress(const isc::asiolink::IOAddress &addr, const uint16_t port)
Opens UDP/IP socket and binds to address specified.
void printIfaces(std::ostream &out=std::cout)
Debugging method that prints out all available interfaces.
IfacePtr getIface(const unsigned int ifindex)
Returns interface specified interface index.
int openSocket4(Iface &iface, const isc::asiolink::IOAddress &addr, const uint16_t port, const bool receive_bcast=false, const bool send_bcast=false)
Opens IPv4 socket.
bool openSockets6(const uint16_t port=DHCP6_SERVER_PORT, IfaceMgrErrorMsgCallback error_handler=0, const bool skip_opened=false)
Opens IPv6 sockets on detected interfaces.
BoundAddresses bound_address_
Unordered set of IPv4 bound addresses.
void setPacketFilter(const PktFilterPtr &packet_filter)
Set packet filter object to handle sending and receiving DHCPv4 messages.
int openSocketFromIface(const std::string &ifname, const uint16_t port, const uint8_t family)
Opens UDP/IP socket and binds it to interface specified.
Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
void detectIfaces(bool update_only=false)
Detects network interfaces.
IfaceCollection ifaces_
List of available interfaces.
void startDHCPReceiver(const uint16_t family)
Starts DHCP packet receiver.
void clearUnicasts()
Clears unicast addresses on all interfaces.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
bool isDHCPReceiverRunning() const
Returns true if there is a receiver exists and its thread is currently running.
bool hasOpenSocket(const uint16_t family) const
Checks if there is at least one socket of the specified family open.
virtual ~IfaceMgr()
Destructor.
void collectBoundAddresses()
Collect the addresses all sockets are bound to.
int openSocket6(Iface &iface, const isc::asiolink::IOAddress &addr, uint16_t port, const bool join_multicast)
Opens IPv6 socket.
bool configureDHCPPacketQueue(const uint16_t family, data::ConstElementPtr queue_control)
Configures DHCP packet queue.
int openSocketFromRemoteAddress(const isc::asiolink::IOAddress &remote_addr, const uint16_t port)
Opens UDP/IP socket to be used to connect to remote address.
Pkt6Ptr receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv6 packets directly or data from external sockets.
bool checkDetectIfaces(bool update_only)
Check if the specific system calls used to detect interfaces should be executed.
bool isDirectResponseSupported() const
Check if packet be sent directly to the client having no address.
void clearBoundAddresses()
Clears the addresses all sockets are bound to.
void addExternalSocket(int socketfd, SocketCallback callback)
Adds external socket and a callback.
void addInterface(const IfacePtr &iface)
Adds an interface to list of known interfaces.
IfaceMgr()
Protected constructor.
bool send(const Pkt6Ptr &pkt)
Sends an IPv6 packet.
Pkt4Ptr receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets indirectly or data from external sockets.
void closeSockets()
Closes all open sockets.
PacketQueue6Ptr getPacketQueue6()
Fetches the DHCPv6 receiver packet queue.
static const IfaceMgrPtr & instancePtr()
Returns pointer to the sole instance of the interface manager.
void deleteAllExternalSockets()
Deletes all external sockets.
void stopDHCPReceiver()
Stops the DHCP packet receiver.
Pkt4Ptr receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets directly or data from external sockets.
PacketQueue4Ptr getPacketQueue4()
Fetches the DHCPv4 receiver packet queue.
uint16_t getSocket(const isc::dhcp::Pkt6Ptr &pkt)
Return most suitable socket for transmitting specified IPv6 packet.
Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
IfaceMgr exception thrown when there is no suitable interface.
Represents a single network interface.
std::string getPlainMac() const
Returns link-layer address a plain text.
size_t mac_len_
Length of link-layer address (usually 6).
void clearErrors()
Clears all errors.
AddressCollection addrs_
List of assigned addresses.
ErrorBuffer const & getErrors() const
Get the consistent list of error messages.
std::vector< std::string > ErrorBuffer
Type definition for a list of error messages.
std::string getFullName() const
Returns full interface name as "ifname/ifindex" string.
unsigned int ifindex_
Interface index (a value that uniquely identifies an interface).
std::string name_
Network interface name.
SocketCollection sockets_
Socket used to send data.
const AddressCollection & getAddresses() const
Returns all addresses available on an interface.
void setActive(const isc::asiolink::IOAddress &address, const bool active)
Activates or deactivates address for the interface.
void addError(std::string const &message)
Add an error to the list of messages.
std::string getName() const
Returns interface name.
Iface(const std::string &name, unsigned int ifindex)
Iface constructor.
bool delAddress(const isc::asiolink::IOAddress &addr)
Deletes an address from an interface.
bool hasAddress(const isc::asiolink::IOAddress &address) const
Check if the interface has the specified address assigned.
void setMac(const uint8_t *mac, size_t macLen)
Sets MAC address of the interface.
bool delSocket(uint16_t sockfd)
Closes socket.
std::list< Address > AddressCollection
Type that defines list of addresses.
std::list< SocketInfo > SocketCollection
Type that holds a list of socket information.
static const unsigned int MAX_MAC_LEN
Maximum MAC address length (Infiniband uses 20 bytes)
void addUnicast(const isc::asiolink::IOAddress &addr)
Adds unicast the server should listen on.
unsigned int countActive4() const
Returns a number of activated IPv4 addresses on the interface.
uint8_t mac_[MAX_MAC_LEN]
Link-layer address.
util::Optional< asiolink::IOAddress > Address
Address type.
void addAddress(const isc::asiolink::IOAddress &addr)
Adds an address to an interface.
void closeSockets()
Closes all open sockets on interface.
void addSocket(const SocketInfo &sock)
Adds socket descriptor to an interface.
AddressCollection unicasts_
List of unicast addresses the server should listen on.
bool getAddress4(isc::asiolink::IOAddress &address) const
Returns IPv4 address assigned to the interface.
Exception thrown when invalid packet filter object specified.
Exception thrown when it is not allowed to set new Packet Filter.
Packet Queue Manager for DHPCv4 servers.
Packet Queue Manager for DHPCv6 servers.
A DHCPv6 packet handling class using datagram sockets.
Packet handling class using AF_INET socket family.
Exception thrown when a call to select is interrupted by a signal.
IfaceMgr exception thrown thrown when socket opening or configuration failed.
IfaceMgr exception thrown when there is no suitable socket found.
IfaceMgr exception thrown thrown when error occurred during reading data from socket.
A template representing an optional value.
Provides a thread and controls for monitoring its activities.
#define DHCP_IPV4_BROADCAST_ADDRESS
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define FD_COPY(orig, copy)
#define IFACEMGR_ERROR(ex_type, handler, iface, stream)
A macro which handles an error in IfaceMgr.
boost::shared_ptr< const Element > ConstElementPtr
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
boost::shared_ptr< IfaceMgr > IfaceMgrPtr
Type definition for the pointer to the IfaceMgr.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< PktFilter > PktFilterPtr
Pointer to a PktFilter object.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
std::function< void(const std::string &errmsg)> IfaceMgrErrorMsgCallback
This type describes the callback function invoked when error occurs in the IfaceMgr.
constexpr unsigned int UNSET_IFINDEX
A value used to signal that the interface index was not set.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
boost::shared_ptr< PktFilter6 > PktFilter6Ptr
Pointer to a PktFilter object.
Defines the logger used by the top-level component of kea-lfc.
Keeps callback information for external sockets.
SocketCallback callback_
A callback that will be called when data arrives over socket_.
int socket_
Socket descriptor of the external socket.
Holds information about socket.