Kea: iface_mgr.h Source File

| Kea 3.0.0

iface_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef IFACE_MGR_H
8#define IFACE_MGR_H
9
10#include <asiolink/io_address.h>
11#include <dhcp/dhcp4.h>
12#include <dhcp/dhcp6.h>
13#include <dhcp/pkt4.h>
14#include <dhcp/pkt6.h>
15#include <dhcp/packet_queue_mgr4.h>
16#include <dhcp/packet_queue_mgr6.h>
17#include <dhcp/pkt_filter.h>
18#include <dhcp/pkt_filter6.h>
19#include <util/optional.h>
20#include <util/watch_socket.h>
21#include <util/watched_thread.h>
22
23#include <boost/multi_index/hashed_index.hpp>
24#include <boost/multi_index/mem_fun.hpp>
25#include <boost/multi_index/sequenced_index.hpp>
26#include <boost/multi_index_container.hpp>
27#include <boost/noncopyable.hpp>
28#include <boost/scoped_array.hpp>
29#include <boost/shared_ptr.hpp>
30
31#include <functional>
32#include <list>
33#include <vector>
34#include <mutex>
35
36namespace isc {
37
38namespace dhcp {
39
41 class IfaceDetectError : public Exception {
42public:
43 IfaceDetectError(const char* file, size_t line, const char* what) :
44 isc::Exception(file, line, what) { }
45};
46
48 class PacketFilterChangeDenied : public Exception {
49public:
50 PacketFilterChangeDenied(const char* file, size_t line, const char* what) :
51 isc::Exception(file, line, what) { }
52};
53
55 class SignalInterruptOnSelect : public Exception {
56public:
57 SignalInterruptOnSelect(const char* file, size_t line, const char* what) :
58 isc::Exception(file, line, what) { }
59};
60
63 class SocketConfigError : public Exception {
64public:
65 SocketConfigError(const char* file, size_t line, const char* what) :
66 isc::Exception(file, line, what) { }
67};
68
71 class SocketReadError : public Exception {
72public:
73 SocketReadError(const char* file, size_t line, const char* what) :
74 isc::Exception(file, line, what) { }
75};
76
79 class SocketWriteError : public Exception {
80public:
81 SocketWriteError(const char* file, size_t line, const char* what) :
82 isc::Exception(file, line, what) { }
83};
84
86 class IfaceNotFound : public Exception {
87public:
88 IfaceNotFound(const char* file, size_t line, const char* what) :
89 isc::Exception(file, line, what) { }
90};
91
93 class SocketNotFound : public Exception {
94public:
95 SocketNotFound(const char* file, size_t line, const char* what) :
96 isc::Exception(file, line, what) { }
97};
98
118 class Iface : public boost::noncopyable {
119public:
120
122 static const unsigned int MAX_MAC_LEN = 20;
123
125 typedef util::Optional<asiolink::IOAddress> Address;
126
128 typedef std::list<Address> AddressCollection;
129
139 typedef std::list<SocketInfo> SocketCollection;
140
142 using ErrorBuffer = std::vector<std::string>;
143
151 Iface(const std::string& name, unsigned int ifindex);
152
154 ~Iface() { }
155
157 void closeSockets();
158
178 void closeSockets(const uint16_t family);
179
183 std::string getFullName() const;
184
188 std::string getPlainMac() const;
189
194 void setMac(const uint8_t* mac, size_t macLen);
195
199 size_t getMacLen() const { return mac_len_; }
200
205 const uint8_t* getMac() const { return mac_; }
206
214 void setFlags(uint64_t flags);
215
219 unsigned int getIndex() const { return ifindex_; }
220
224 std::string getName() const { return name_; }
225
229 void setHWType(uint16_t type ) { hardware_type_ = type; }
230
234 uint16_t getHWType() const { return hardware_type_; }
235
254 const AddressCollection& getAddresses() const { return addrs_; }
255
265 bool getAddress4(isc::asiolink::IOAddress& address) const;
266
271 bool hasAddress(const isc::asiolink::IOAddress& address) const;
272
279 void addAddress(const isc::asiolink::IOAddress& addr);
280
292 void setActive(const isc::asiolink::IOAddress& address, const bool active);
293
302 void setActive(const bool active);
303
305 unsigned int countActive4() const;
306
316 bool delAddress(const isc::asiolink::IOAddress& addr);
317
321 void addSocket(const SocketInfo& sock) {
322 sockets_.push_back(sock);
323 }
324
332 bool delSocket(uint16_t sockfd);
333
347 const SocketCollection& getSockets() const { return sockets_; }
348
353 void clearUnicasts() {
354 unicasts_.clear();
355 }
356
361 void addUnicast(const isc::asiolink::IOAddress& addr);
362
366 const AddressCollection& getUnicasts() const {
367 return unicasts_;
368 }
369
379 uint8_t* getReadBuffer() {
380 if (read_buffer_.empty()) {
381 return (0);
382 }
383 return (&read_buffer_[0]);
384 }
385
387 size_t getReadBufferSize() const {
388 return (read_buffer_.size());
389 }
390
394 void resizeReadBuffer(const size_t new_size) {
395 read_buffer_.resize(new_size);
396 }
397
401 void addError(std::string const& message);
402
404 void clearErrors();
405
409 ErrorBuffer const& getErrors() const;
410
411protected:
413 SocketCollection sockets_;
414
416 std::string name_;
417
419 unsigned int ifindex_;
420
422 AddressCollection addrs_;
423
425 AddressCollection unicasts_;
426
428 uint8_t mac_[MAX_MAC_LEN];
429
431 size_t mac_len_;
432
434 uint16_t hardware_type_;
435
436public:
439
441 bool flag_loopback_;
442
444 bool flag_up_;
445
448 bool flag_running_;
449
451 bool flag_multicast_;
452
454 bool flag_broadcast_;
455
460 uint64_t flags_;
461
464 bool inactive4_;
465
468 bool inactive6_;
469
470private:
471
475 std::vector<uint8_t> read_buffer_;
476
483 ErrorBuffer errors_;
484};
485
487 typedef boost::shared_ptr<Iface> IfacePtr;
488
490 class IfaceCollection {
491public:
492
502 typedef boost::multi_index_container<
503 // Container comprises elements of IfacePtr type.
504 IfacePtr,
505 // Here we start enumerating various indexes.
506 boost::multi_index::indexed_by<
507 // Sequenced index allows accessing elements in the same way
508 // as elements in std::list. Sequenced is the index #0.
509 boost::multi_index::sequenced<>,
510 // Start definition of index #1.
511 boost::multi_index::hashed_unique<
512 // Use the interface index as the key.
513 boost::multi_index::const_mem_fun<
514 Iface, unsigned int, &Iface::getIndex
515 >
516 >,
517 // Start definition of index #2.
518 boost::multi_index::hashed_unique<
519 // Use the interface name as the key.
520 boost::multi_index::const_mem_fun<
521 Iface, std::string, &Iface::getName
522 >
523 >
524 >
525 > IfaceContainer;
526
530 IfaceContainer::const_iterator begin() const {
531 return (ifaces_container_.begin());
532 }
533
537 IfaceContainer::const_iterator end() const {
538 return (ifaces_container_.end());
539 }
540
544 bool empty() const {
545 return (ifaces_container_.empty());
546 }
547
551 size_t size() const {
552 return (ifaces_container_.size());
553 }
554
556 void clear() {
557 cache_.reset();
558 ifaces_container_.clear();
559 }
560
566 void push_back(const IfacePtr& iface) {
567 ifaces_container_.push_back(iface);
568 }
569
574 IfacePtr getIface(const unsigned int ifindex);
575
580 IfacePtr getIface(const std::string& ifname);
581
582private:
588 IfacePtr getIfaceInternal(const unsigned int ifindex, const bool need_lock);
589
597 IfacePtr getIfaceInternal(const std::string& ifname, const bool need_lock);
598
601 std::mutex mutex_;
602
612 IfacePtr cache_;
613
615 IfaceContainer ifaces_container_;
616};
617
622typedef boost::multi_index_container<
624 asiolink::IOAddress,
625 // Here we start enumerating the only index.
626 boost::multi_index::indexed_by<
627 // Start definition of index #0.
628 boost::multi_index::hashed_unique<
629 // Use the address in its network order integer form as the key.
630 boost::multi_index::const_mem_fun<
631 asiolink::IOAddress, uint32_t, &asiolink::IOAddress::toUint32
632 >
633 >
634 >
635> BoundAddresses;
636
638class IfaceMgr;
639
641 typedef boost::shared_ptr<IfaceMgr> IfaceMgrPtr;
642
647typedef
648std::function<void(const std::string& errmsg)> IfaceMgrErrorMsgCallback;
649
656 class IfaceMgr : public boost::noncopyable {
657public:
661 typedef std::function<void (int fd)> SocketCallback;
662
670 typedef std::function<bool (bool)> DetectCallback;
671
673 struct SocketCallbackInfo {
675 int socket_;
676
678 SocketCallback callback_;
679 };
680
682 typedef std::list<SocketCallbackInfo> SocketCallbackInfoContainer;
683
691 static const uint32_t RCVBUFSIZE = 1500;
692
697 static IfaceMgr& instance();
698
709 static const IfaceMgrPtr& instancePtr();
710
714 virtual ~IfaceMgr();
715
725 void setTestMode(const bool test_mode) {
726 test_mode_ = test_mode;
727 }
728
732 bool isTestMode() const {
733 return (test_mode_);
734 }
735
741 void setAllowLoopBack(const bool allow_loopback) {
742 allow_loopback_ = allow_loopback;
743 }
744
753 bool isDirectResponseSupported() const;
754
761 virtual bool isSocketReceivedTimeSupported() const;
762
770 IfacePtr getIface(const unsigned int ifindex);
771
778 IfacePtr getIface(const std::string& ifname);
779
790 IfacePtr getIface(const PktPtr& pkt);
791
799 const IfaceCollection& getIfaces() { return (ifaces_); }
800
807 void clearIfaces();
808
813 void setDetectCallback(const DetectCallback& cb) {
814 detect_callback_ = cb;
815 }
816
825 bool checkDetectIfaces(bool update_only);
826
834 void detectIfaces(bool update_only = false);
835
837 void clearUnicasts();
838
840 void clearBoundAddresses();
841
843 void collectBoundAddresses();
844
858 uint16_t getSocket(const isc::dhcp::Pkt6Ptr& pkt);
859
873 SocketInfo getSocket(const isc::dhcp::Pkt4Ptr& pkt);
874
878 void printIfaces(std::ostream& out = std::cout);
879
891 bool send(const Pkt6Ptr& pkt);
892
904 bool send(const Pkt4Ptr& pkt);
905
917 Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec = 0);
918
930 Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec = 0);
931
950 int openSocket(const std::string& ifname,
951 const isc::asiolink::IOAddress& addr,
952 const uint16_t port,
953 const bool receive_bcast = false,
954 const bool send_bcast = false);
955
973 int openSocketFromIface(const std::string& ifname,
974 const uint16_t port,
975 const uint8_t family);
976
991 int openSocketFromAddress(const isc::asiolink::IOAddress& addr,
992 const uint16_t port);
993
1008 int openSocketFromRemoteAddress(const isc::asiolink::IOAddress& remote_addr,
1009 const uint16_t port);
1010
1057 bool openSockets6(const uint16_t port = DHCP6_SERVER_PORT,
1058 IfaceMgrErrorMsgCallback error_handler = 0,
1059 const bool skip_opened = false);
1060
1130 bool openSockets4(const uint16_t port = DHCP4_SERVER_PORT,
1131 const bool use_bcast = true,
1132 IfaceMgrErrorMsgCallback error_handler = 0,
1133 const bool skip_opened = false);
1134
1141 void closeSockets();
1142
1146 uint16_t countIfaces() { return ifaces_.size(); }
1147
1155 void addExternalSocket(int socketfd, SocketCallback callback);
1156
1160 bool isExternalSocket(int fd);
1161
1165 void deleteExternalSocket(int socketfd);
1166
1176 int purgeBadSockets();
1177
1179 void deleteAllExternalSockets();
1180
1196 void setPacketFilter(const PktFilterPtr& packet_filter);
1197
1218 void setPacketFilter(const PktFilter6Ptr& packet_filter);
1219
1236 void setMatchingPacketFilter(const bool direct_response_desired = false);
1237
1244 void addInterface(const IfacePtr& iface);
1245
1252 bool hasOpenSocket(const uint16_t family) const;
1253
1270 bool hasOpenSocket(const isc::asiolink::IOAddress& addr) const;
1271
1275 PacketQueueMgr4Ptr getPacketQueueMgr4() {
1276 return (packet_queue_mgr4_);
1277 }
1278
1285 PacketQueue4Ptr getPacketQueue4() {
1286 return (packet_queue_mgr4_->getPacketQueue());
1287 }
1288
1292 PacketQueueMgr6Ptr getPacketQueueMgr6() {
1293 return (packet_queue_mgr6_);
1294 }
1295
1302 PacketQueue6Ptr getPacketQueue6() {
1303 return (packet_queue_mgr6_->getPacketQueue());
1304 }
1305
1316 void startDHCPReceiver(const uint16_t family);
1317
1322 void stopDHCPReceiver();
1323
1326 bool isDHCPReceiverRunning() const {
1327 return (dhcp_receiver_ != 0 && dhcp_receiver_->isRunning());
1328 }
1329
1343 bool configureDHCPPacketQueue(const uint16_t family,
1344 data::ConstElementPtr queue_control);
1345
1353 static void addFDtoSet(int fd, int& maxfd, fd_set* sockets);
1354
1355 // don't use private, we need derived classes in tests
1356protected:
1357
1362 IfaceMgr();
1363
1377 int openSocket4(Iface& iface, const isc::asiolink::IOAddress& addr,
1378 const uint16_t port, const bool receive_bcast = false,
1379 const bool send_bcast = false);
1380
1401 Pkt4Ptr receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec = 0);
1402
1423 Pkt4Ptr receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec = 0);
1424
1439 int openSocket6(Iface& iface, const isc::asiolink::IOAddress& addr,
1440 uint16_t port, const bool join_multicast);
1441
1462 Pkt6Ptr receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec = 0);
1463
1484 Pkt6Ptr receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec = 0);
1485
1487 IfaceCollection ifaces_;
1488
1490 BoundAddresses bound_address_;
1491
1492 // TODO: Also keep this interface on Iface once interface detection
1493 // is implemented. We may need it e.g. to close all sockets on
1494 // specific interface
1495 //int recvsock_; // TODO: should be fd_set eventually, but we have only
1496 //int sendsock_; // 2 sockets for now. Will do for until next release
1497
1498 // We can't use the same socket, as receiving socket
1499 // is bound to multicast address. And we all know what happens
1500 // to people who try to use multicast as source address.
1501
1502private:
1517 isc::asiolink::IOAddress
1518 getLocalAddress(const isc::asiolink::IOAddress& remote_addr,
1519 const uint16_t port);
1520
1538 bool openMulticastSocket(Iface& iface,
1539 const isc::asiolink::IOAddress& addr,
1540 const uint16_t port,
1541 IfaceMgrErrorMsgCallback error_handler = 0);
1542
1552 void receiveDHCP4Packets();
1553
1564 void receiveDHCP4Packet(Iface& iface, const SocketInfo& socket_info);
1565
1575 void receiveDHCP6Packets();
1576
1586 void receiveDHCP6Packet(const SocketInfo& socket_info);
1587
1591 void deleteExternalSocketInternal(int socketfd);
1592
1601 PktFilterPtr packet_filter_;
1602
1607 PktFilter6Ptr packet_filter6_;
1608
1610 SocketCallbackInfoContainer callbacks_;
1611
1613 std::mutex callbacks_mutex_;
1614
1616 bool test_mode_;
1617
1623 DetectCallback detect_callback_;
1624
1626 bool allow_loopback_;
1627
1629 PacketQueueMgr4Ptr packet_queue_mgr4_;
1630
1632 PacketQueueMgr6Ptr packet_queue_mgr6_;
1633
1635 isc::util::WatchedThreadPtr dhcp_receiver_;
1636};
1637
1638} // namespace isc::dhcp
1639} // namespace isc
1640
1641#endif // IFACE_MGR_H
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::asiolink::IOAddress
The IOAddress class represents an IP addresses (version agnostic)
Definition io_address.h:45
isc::asiolink::IOAddress::toUint32
uint32_t toUint32() const
Converts IPv4 address to uint32_t.
Definition io_address.cc:121
isc::dhcp::IfaceCollection
Collection of pointers to network interfaces.
Definition iface_mgr.h:490
isc::dhcp::IfaceCollection::IfaceContainer
boost::multi_index_container< IfacePtr, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::hashed_unique< boost::multi_index::const_mem_fun< Iface, unsigned int, &Iface::getIndex > >, boost::multi_index::hashed_unique< boost::multi_index::const_mem_fun< Iface, std::string, &Iface::getName > > > > IfaceContainer
Multi index container for network interfaces.
Definition iface_mgr.h:525
isc::dhcp::IfaceCollection::getIface
IfacePtr getIface(const unsigned int ifindex)
Lookup by interface index.
Definition iface_mgr.cc:812
isc::dhcp::IfaceCollection::end
IfaceContainer::const_iterator end() const
End iterator.
Definition iface_mgr.h:537
isc::dhcp::IfaceCollection::clear
void clear()
Clear the collection.
Definition iface_mgr.h:556
isc::dhcp::IfaceCollection::begin
IfaceContainer::const_iterator begin() const
Begin iterator.
Definition iface_mgr.h:530
isc::dhcp::IfaceCollection::size
size_t size() const
Return the number of interfaces.
Definition iface_mgr.h:551
isc::dhcp::IfaceCollection::push_back
void push_back(const IfacePtr &iface)
Adds an interface to the collection.
Definition iface_mgr.h:566
isc::dhcp::IfaceCollection::empty
bool empty() const
Empty predicate.
Definition iface_mgr.h:544
isc::dhcp::IfaceDetectError::IfaceDetectError
IfaceDetectError(const char *file, size_t line, const char *what)
Definition iface_mgr.h:43
isc::dhcp::IfaceMgr
Handles network interfaces, transmission and reception.
Definition iface_mgr.h:656
isc::dhcp::IfaceMgr::clearIfaces
void clearIfaces()
Removes detected interfaces.
Definition iface_mgr.cc:901
isc::dhcp::IfaceMgr::getIfaces
const IfaceCollection & getIfaces()
Returns container with all interfaces.
Definition iface_mgr.h:799
isc::dhcp::IfaceMgr::addFDtoSet
static void addFDtoSet(int fd, int &maxfd, fd_set *sockets)
Convenience method for adding an descriptor to a set.
Definition iface_mgr.cc:1389
isc::dhcp::IfaceMgr::isExternalSocket
bool isExternalSocket(int fd)
Checks if socket's file description is registered.
Definition iface_mgr.cc:369
isc::dhcp::IfaceMgr::purgeBadSockets
int purgeBadSockets()
Scans registered socket set and removes any that are invalid.
Definition iface_mgr.cc:381
isc::dhcp::IfaceMgr::deleteExternalSocket
void deleteExternalSocket(int socketfd)
Deletes external socket.
Definition iface_mgr.cc:352
isc::dhcp::IfaceMgr::receive6Indirect
Pkt6Ptr receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv6 packets indirectly or data from external sockets.
Definition iface_mgr.cc:1523
isc::dhcp::IfaceMgr::getPacketQueueMgr6
PacketQueueMgr6Ptr getPacketQueueMgr6()
Fetches the DHCPv6 packet queue manager.
Definition iface_mgr.h:1292
isc::dhcp::IfaceMgr::openSockets4
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.
Definition iface_mgr.cc:497
isc::dhcp::IfaceMgr::SocketCallback
std::function< void(int fd)> SocketCallback
Defines callback used when data is received over external sockets.
Definition iface_mgr.h:661
isc::dhcp::IfaceMgr::openSocket
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.
Definition iface_mgr.cc:932
isc::dhcp::IfaceMgr::openSocketFromAddress
int openSocketFromAddress(const isc::asiolink::IOAddress &addr, const uint16_t port)
Opens UDP/IP socket and binds to address specified.
Definition iface_mgr.cc:992
isc::dhcp::IfaceMgr::printIfaces
void printIfaces(std::ostream &out=std::cout)
Debugging method that prints out all available interfaces.
Definition iface_mgr.cc:788
isc::dhcp::IfaceMgr::countIfaces
uint16_t countIfaces()
Returns number of detected interfaces.
Definition iface_mgr.h:1146
isc::dhcp::IfaceMgr::getIface
IfacePtr getIface(const unsigned int ifindex)
Returns interface specified interface index.
Definition iface_mgr.cc:879
isc::dhcp::IfaceMgr::openSocket4
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.
Definition iface_mgr.cc:1089
isc::dhcp::IfaceMgr::openSockets6
bool openSockets6(const uint16_t port=DHCP6_SERVER_PORT, IfaceMgrErrorMsgCallback error_handler=0, const bool skip_opened=false)
Opens IPv6 sockets on detected interfaces.
Definition iface_mgr.cc:627
isc::dhcp::IfaceMgr::bound_address_
BoundAddresses bound_address_
Unordered set of IPv4 bound addresses.
Definition iface_mgr.h:1490
isc::dhcp::IfaceMgr::setPacketFilter
void setPacketFilter(const PktFilterPtr &packet_filter)
Set packet filter object to handle sending and receiving DHCPv4 messages.
Definition iface_mgr.cc:405
isc::dhcp::IfaceMgr::openSocketFromIface
int openSocketFromIface(const std::string &ifname, const uint16_t port, const uint8_t family)
Opens UDP/IP socket and binds it to interface specified.
Definition iface_mgr.cc:951
isc::dhcp::IfaceMgr::receive6
Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
Definition iface_mgr.cc:1380
isc::dhcp::IfaceMgr::detectIfaces
void detectIfaces(bool update_only=false)
Detects network interfaces.
isc::dhcp::IfaceMgr::setDetectCallback
void setDetectCallback(const DetectCallback &cb)
Set a callback to perform operations before executing specific system calls.
Definition iface_mgr.h:813
isc::dhcp::IfaceMgr::ifaces_
IfaceCollection ifaces_
List of available interfaces.
Definition iface_mgr.h:1487
isc::dhcp::IfaceMgr::startDHCPReceiver
void startDHCPReceiver(const uint16_t family)
Starts DHCP packet receiver.
Definition iface_mgr.cc:742
isc::dhcp::IfaceMgr::getPacketQueueMgr4
PacketQueueMgr4Ptr getPacketQueueMgr4()
Fetches the DHCPv4 packet queue manager.
Definition iface_mgr.h:1275
isc::dhcp::IfaceMgr::clearUnicasts
void clearUnicasts()
Clears unicast addresses on all interfaces.
Definition iface_mgr.cc:926
isc::dhcp::IfaceMgr::isSocketReceivedTimeSupported
virtual bool isSocketReceivedTimeSupported() const
Check if the socket received time is supported.
Definition iface_mgr.cc:324
isc::dhcp::IfaceMgr::instance
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Definition iface_mgr.cc:54
isc::dhcp::IfaceMgr::isDHCPReceiverRunning
bool isDHCPReceiverRunning() const
Returns true if there is a receiver exists and its thread is currently running.
Definition iface_mgr.h:1326
isc::dhcp::IfaceMgr::hasOpenSocket
bool hasOpenSocket(const uint16_t family) const
Checks if there is at least one socket of the specified family open.
Definition iface_mgr.cc:447
isc::dhcp::IfaceMgr::~IfaceMgr
virtual ~IfaceMgr()
Destructor.
Definition iface_mgr.cc:314
isc::dhcp::IfaceMgr::collectBoundAddresses
void collectBoundAddresses()
Collect the addresses all sockets are bound to.
Definition iface_mgr.cc:911
isc::dhcp::IfaceMgr::openSocket6
int openSocket6(Iface &iface, const isc::asiolink::IOAddress &addr, uint16_t port, const bool join_multicast)
Opens IPv6 socket.
isc::dhcp::IfaceMgr::isTestMode
bool isTestMode() const
Checks if the IfaceMgr is in the test mode.
Definition iface_mgr.h:732
isc::dhcp::IfaceMgr::configureDHCPPacketQueue
bool configureDHCPPacketQueue(const uint16_t family, data::ConstElementPtr queue_control)
Configures DHCP packet queue.
Definition iface_mgr.cc:1943
isc::dhcp::IfaceMgr::openSocketFromRemoteAddress
int openSocketFromRemoteAddress(const isc::asiolink::IOAddress &remote_addr, const uint16_t port)
Opens UDP/IP socket to be used to connect to remote address.
Definition iface_mgr.cc:1015
isc::dhcp::IfaceMgr::SocketCallbackInfoContainer
std::list< SocketCallbackInfo > SocketCallbackInfoContainer
Defines storage container for callbacks for external sockets.
Definition iface_mgr.h:682
isc::dhcp::IfaceMgr::receive6Direct
Pkt6Ptr receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv6 packets directly or data from external sockets.
Definition iface_mgr.cc:1401
isc::dhcp::IfaceMgr::checkDetectIfaces
bool checkDetectIfaces(bool update_only)
Check if the specific system calls used to detect interfaces should be executed.
Definition iface_mgr.cc:1994
isc::dhcp::IfaceMgr::isDirectResponseSupported
bool isDirectResponseSupported() const
Check if packet be sent directly to the client having no address.
Definition iface_mgr.cc:319
isc::dhcp::IfaceMgr::clearBoundAddresses
void clearBoundAddresses()
Clears the addresses all sockets are bound to.
Definition iface_mgr.cc:906
isc::dhcp::IfaceMgr::addExternalSocket
void addExternalSocket(int socketfd, SocketCallback callback)
Adds external socket and a callback.
Definition iface_mgr.cc:329
isc::dhcp::IfaceMgr::addInterface
void addInterface(const IfacePtr &iface)
Adds an interface to list of known interfaces.
Definition iface_mgr.cc:775
isc::dhcp::IfaceMgr::IfaceMgr
IfaceMgr()
Protected constructor.
Definition iface_mgr.cc:185
isc::dhcp::IfaceMgr::send
bool send(const Pkt6Ptr &pkt)
Sends an IPv6 packet.
Definition iface_mgr.cc:1100
isc::dhcp::IfaceMgr::receive4Indirect
Pkt4Ptr receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets indirectly or data from external sockets.
Definition iface_mgr.cc:1133
isc::dhcp::IfaceMgr::closeSockets
void closeSockets()
Closes all open sockets.
Definition iface_mgr.cc:286
isc::dhcp::IfaceMgr::getPacketQueue6
PacketQueue6Ptr getPacketQueue6()
Fetches the DHCPv6 receiver packet queue.
Definition iface_mgr.h:1302
isc::dhcp::IfaceMgr::instancePtr
static const IfaceMgrPtr & instancePtr()
Returns pointer to the sole instance of the interface manager.
Definition iface_mgr.cc:59
isc::dhcp::IfaceMgr::RCVBUFSIZE
static const uint32_t RCVBUFSIZE
Packet reception buffer size.
Definition iface_mgr.h:691
isc::dhcp::IfaceMgr::deleteAllExternalSockets
void deleteAllExternalSockets()
Deletes all external sockets.
Definition iface_mgr.cc:399
isc::dhcp::IfaceMgr::setMatchingPacketFilter
void setMatchingPacketFilter(const bool direct_response_desired=false)
Set Packet Filter object to handle send/receive packets.
isc::dhcp::IfaceMgr::stopDHCPReceiver
void stopDHCPReceiver()
Stops the DHCP packet receiver.
Definition iface_mgr.cc:298
isc::dhcp::IfaceMgr::receive4Direct
Pkt4Ptr receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets directly or data from external sockets.
Definition iface_mgr.cc:1255
isc::dhcp::IfaceMgr::setTestMode
void setTestMode(const bool test_mode)
Sets or clears the test mode for IfaceMgr.
Definition iface_mgr.h:725
isc::dhcp::IfaceMgr::getPacketQueue4
PacketQueue4Ptr getPacketQueue4()
Fetches the DHCPv4 receiver packet queue.
Definition iface_mgr.h:1285
isc::dhcp::IfaceMgr::getSocket
uint16_t getSocket(const isc::dhcp::Pkt6Ptr &pkt)
Return most suitable socket for transmitting specified IPv6 packet.
Definition iface_mgr.cc:1854
isc::dhcp::IfaceMgr::setAllowLoopBack
void setAllowLoopBack(const bool allow_loopback)
Allows or disallows the loopback interface.
Definition iface_mgr.h:741
isc::dhcp::IfaceMgr::receive4
Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
Definition iface_mgr.cc:1125
isc::dhcp::IfaceMgr::DetectCallback
std::function< bool(bool)> DetectCallback
Defines callback used when detecting interfaces.
Definition iface_mgr.h:670
isc::dhcp::IfaceNotFound::IfaceNotFound
IfaceNotFound(const char *file, size_t line, const char *what)
Definition iface_mgr.h:88
isc::dhcp::Iface
Represents a single network interface.
Definition iface_mgr.h:118
isc::dhcp::Iface::getReadBufferSize
size_t getReadBufferSize() const
Returns the current size of the socket read buffer.
Definition iface_mgr.h:387
isc::dhcp::Iface::getPlainMac
std::string getPlainMac() const
Returns link-layer address a plain text.
Definition iface_mgr.cc:131
isc::dhcp::Iface::getMacLen
size_t getMacLen() const
Returns MAC length.
Definition iface_mgr.h:199
isc::dhcp::Iface::flags_
uint64_t flags_
Interface flags (this value is as is returned by OS, it may mean different things on different OSes).
Definition iface_mgr.h:460
isc::dhcp::Iface::inactive4_
bool inactive4_
Indicates that IPv4 sockets should (true) or should not (false) be opened on this interface.
Definition iface_mgr.h:464
isc::dhcp::Iface::mac_len_
size_t mac_len_
Length of link-layer address (usually 6).
Definition iface_mgr.h:431
isc::dhcp::Iface::~Iface
~Iface()
Destructor.
Definition iface_mgr.h:154
isc::dhcp::Iface::clearErrors
void clearErrors()
Clears all errors.
Definition iface_mgr.cc:1984
isc::dhcp::Iface::addrs_
AddressCollection addrs_
List of assigned addresses.
Definition iface_mgr.h:422
isc::dhcp::Iface::getErrors
ErrorBuffer const & getErrors() const
Get the consistent list of error messages.
Definition iface_mgr.cc:1989
isc::dhcp::Iface::ErrorBuffer
std::vector< std::string > ErrorBuffer
Type definition for a list of error messages.
Definition iface_mgr.h:142
isc::dhcp::Iface::getFullName
std::string getFullName() const
Returns full interface name as "ifname/ifindex" string.
Definition iface_mgr.cc:124
isc::dhcp::Iface::ifindex_
unsigned int ifindex_
Interface index (a value that uniquely identifies an interface).
Definition iface_mgr.h:419
isc::dhcp::Iface::name_
std::string name_
Network interface name.
Definition iface_mgr.h:416
isc::dhcp::Iface::getUnicasts
const AddressCollection & getUnicasts() const
Returns a container of addresses the server should listen on.
Definition iface_mgr.h:366
isc::dhcp::Iface::hardware_type_
uint16_t hardware_type_
Hardware type.
Definition iface_mgr.h:434
isc::dhcp::Iface::sockets_
SocketCollection sockets_
Socket used to send data.
Definition iface_mgr.h:413
isc::dhcp::Iface::getAddresses
const AddressCollection & getAddresses() const
Returns all addresses available on an interface.
Definition iface_mgr.h:254
isc::dhcp::Iface::getReadBuffer
uint8_t * getReadBuffer()
Returns the pointer to the buffer used for data reading.
Definition iface_mgr.h:379
isc::dhcp::Iface::flag_multicast_
bool flag_multicast_
Flag specifies if selected interface is multicast capable.
Definition iface_mgr.h:451
isc::dhcp::Iface::setActive
void setActive(const isc::asiolink::IOAddress &address, const bool active)
Activates or deactivates address for the interface.
Definition iface_mgr.cc:257
isc::dhcp::Iface::addError
void addError(std::string const &message)
Add an error to the list of messages.
Definition iface_mgr.cc:1979
isc::dhcp::Iface::getName
std::string getName() const
Returns interface name.
Definition iface_mgr.h:224
isc::dhcp::Iface::setFlags
void setFlags(uint64_t flags)
Sets flag_*_ fields based on bitmask value returned by OS.
isc::dhcp::Iface::clearUnicasts
void clearUnicasts()
Removes any unicast addresses.
Definition iface_mgr.h:353
isc::dhcp::Iface::Iface
Iface(const std::string &name, unsigned int ifindex)
Iface constructor.
Definition iface_mgr.cc:64
isc::dhcp::Iface::getHWType
uint16_t getHWType() const
Returns hardware type of the interface.
Definition iface_mgr.h:234
isc::dhcp::Iface::delAddress
bool delAddress(const isc::asiolink::IOAddress &addr)
Deletes an address from an interface.
Definition iface_mgr.cc:158
isc::dhcp::Iface::getIndex
unsigned int getIndex() const
Returns interface index.
Definition iface_mgr.h:219
isc::dhcp::Iface::hasAddress
bool hasAddress(const isc::asiolink::IOAddress &address) const
Check if the interface has the specified address assigned.
Definition iface_mgr.cc:240
isc::dhcp::Iface::setMac
void setMac(const uint8_t *mac, size_t macLen)
Sets MAC address of the interface.
Definition iface_mgr.cc:145
isc::dhcp::Iface::flag_running_
bool flag_running_
Flag specifies if selected interface is running (e.g.
Definition iface_mgr.h:448
isc::dhcp::Iface::resizeReadBuffer
void resizeReadBuffer(const size_t new_size)
Reallocates the socket read buffer.
Definition iface_mgr.h:394
isc::dhcp::Iface::delSocket
bool delSocket(uint16_t sockfd)
Closes socket.
Definition iface_mgr.cc:168
isc::dhcp::Iface::AddressCollection
std::list< Address > AddressCollection
Type that defines list of addresses.
Definition iface_mgr.h:128
isc::dhcp::Iface::getSockets
const SocketCollection & getSockets() const
Returns collection of all sockets added to interface.
Definition iface_mgr.h:347
isc::dhcp::Iface::inactive6_
bool inactive6_
Indicates that IPv6 sockets should (true) or should not (false) be opened on this interface.
Definition iface_mgr.h:468
isc::dhcp::Iface::SocketCollection
std::list< SocketInfo > SocketCollection
Type that holds a list of socket information.
Definition iface_mgr.h:139
isc::dhcp::Iface::MAX_MAC_LEN
static const unsigned int MAX_MAC_LEN
Maximum MAC address length (Infiniband uses 20 bytes)
Definition iface_mgr.h:122
isc::dhcp::Iface::flag_loopback_
bool flag_loopback_
Specifies if selected interface is loopback.
Definition iface_mgr.h:441
isc::dhcp::Iface::addUnicast
void addUnicast(const isc::asiolink::IOAddress &addr)
Adds unicast the server should listen on.
Definition iface_mgr.cc:213
isc::dhcp::Iface::countActive4
unsigned int countActive4() const
Returns a number of activated IPv4 addresses on the interface.
Definition iface_mgr.cc:276
isc::dhcp::Iface::mac_
uint8_t mac_[MAX_MAC_LEN]
Link-layer address.
Definition iface_mgr.h:428
isc::dhcp::Iface::Address
util::Optional< asiolink::IOAddress > Address
Address type.
Definition iface_mgr.h:125
isc::dhcp::Iface::addAddress
void addAddress(const isc::asiolink::IOAddress &addr)
Adds an address to an interface.
Definition iface_mgr.cc:250
isc::dhcp::Iface::closeSockets
void closeSockets()
Closes all open sockets on interface.
Definition iface_mgr.cc:77
isc::dhcp::Iface::addSocket
void addSocket(const SocketInfo &sock)
Adds socket descriptor to an interface.
Definition iface_mgr.h:321
isc::dhcp::Iface::flag_up_
bool flag_up_
Specifies if selected interface is up.
Definition iface_mgr.h:444
isc::dhcp::Iface::flag_broadcast_
bool flag_broadcast_
Flag specifies if selected interface is broadcast capable.
Definition iface_mgr.h:454
isc::dhcp::Iface::setHWType
void setHWType(uint16_t type)
Sets up hardware type of the interface.
Definition iface_mgr.h:229
isc::dhcp::Iface::getMac
const uint8_t * getMac() const
Returns pointer to MAC address.
Definition iface_mgr.h:205
isc::dhcp::Iface::unicasts_
AddressCollection unicasts_
List of unicast addresses the server should listen on.
Definition iface_mgr.h:425
isc::dhcp::Iface::getAddress4
bool getAddress4(isc::asiolink::IOAddress &address) const
Returns IPv4 address assigned to the interface.
Definition iface_mgr.cc:224
isc::dhcp::PacketFilterChangeDenied::PacketFilterChangeDenied
PacketFilterChangeDenied(const char *file, size_t line, const char *what)
Definition iface_mgr.h:50
isc::dhcp::SignalInterruptOnSelect::SignalInterruptOnSelect
SignalInterruptOnSelect(const char *file, size_t line, const char *what)
Definition iface_mgr.h:57
isc::dhcp::SocketConfigError::SocketConfigError
SocketConfigError(const char *file, size_t line, const char *what)
Definition iface_mgr.h:65
isc::dhcp::SocketNotFound::SocketNotFound
SocketNotFound(const char *file, size_t line, const char *what)
Definition iface_mgr.h:95
isc::dhcp::SocketReadError::SocketReadError
SocketReadError(const char *file, size_t line, const char *what)
Definition iface_mgr.h:73
isc::dhcp::SocketWriteError::SocketWriteError
SocketWriteError(const char *file, size_t line, const char *what)
Definition iface_mgr.h:81
isc::util::Optional
A template representing an optional value.
Definition optional.h:36
dhcp4.h
dhcp6.h
io_address.h
isc::cb
Definition base_config_backend.h:18
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::dhcp
Definition dhcp4/client_handler.cc:20
isc::dhcp::PktPtr
boost::shared_ptr< isc::dhcp::Pkt > PktPtr
A pointer to either Pkt4 or Pkt6 packet.
Definition pkt.h:998
isc::dhcp::IfaceMgrPtr
boost::shared_ptr< IfaceMgr > IfaceMgrPtr
Type definition for the pointer to the IfaceMgr.
Definition iface_mgr.h:641
isc::dhcp::PacketQueue4Ptr
boost::shared_ptr< PacketQueue< Pkt4Ptr > > PacketQueue4Ptr
Defines pointer to the DHCPv4 queue interface used at the application level.
Definition packet_queue.h:131
isc::dhcp::Pkt4Ptr
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
Definition pkt4.h:555
isc::dhcp::PktFilterPtr
boost::shared_ptr< PktFilter > PktFilterPtr
Pointer to a PktFilter object.
Definition pkt_filter.h:144
isc::dhcp::IfacePtr
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
Definition iface_mgr.h:487
isc::dhcp::BoundAddresses
boost::multi_index_container< asiolink::IOAddress, boost::multi_index::indexed_by< boost::multi_index::hashed_unique< boost::multi_index::const_mem_fun< asiolink::IOAddress, uint32_t, &asiolink::IOAddress::toUint32 > > > > BoundAddresses
Type definition for the unordered set of IPv4 bound addresses.
Definition iface_mgr.h:635
isc::dhcp::IfaceMgrErrorMsgCallback
std::function< void(const std::string &errmsg)> IfaceMgrErrorMsgCallback
This type describes the callback function invoked when error occurs in the IfaceMgr.
Definition iface_mgr.h:648
isc::dhcp::PacketQueue6Ptr
boost::shared_ptr< PacketQueue< Pkt6Ptr > > PacketQueue6Ptr
Defines pointer to the DHCPv6 queue interface used at the application level.
Definition packet_queue.h:136
isc::dhcp::Pkt6Ptr
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Definition pkt6.h:31
isc::dhcp::PktFilter6Ptr
boost::shared_ptr< PktFilter6 > PktFilter6Ptr
Pointer to a PktFilter object.
Definition pkt_filter6.h:136
isc::dhcp::PacketQueueMgr4Ptr
boost::shared_ptr< PacketQueueMgr4 > PacketQueueMgr4Ptr
Defines a shared pointer to PacketQueueMgr4.
Definition packet_queue_mgr4.h:36
isc::dhcp::PacketQueueMgr6Ptr
boost::shared_ptr< PacketQueueMgr6 > PacketQueueMgr6Ptr
Defines a shared pointer to PacketQueueMgr6.
Definition packet_queue_mgr6.h:38
isc::util::file
Definition filesystem.cc:28
isc::util::WatchedThreadPtr
boost::shared_ptr< WatchedThread > WatchedThreadPtr
Defines a pointer to a WatchedThread.
Definition watched_thread.h:140
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148
optional.h
packet_queue_mgr4.h
packet_queue_mgr6.h
pkt4.h
pkt6.h
pkt_filter6.h
pkt_filter.h
isc::dhcp::IfaceMgr::SocketCallbackInfo
Keeps callback information for external sockets.
Definition iface_mgr.h:673
isc::dhcp::IfaceMgr::SocketCallbackInfo::callback_
SocketCallback callback_
A callback that will be called when data arrives over socket_.
Definition iface_mgr.h:678
isc::dhcp::IfaceMgr::SocketCallbackInfo::socket_
int socket_
Socket descriptor of the external socket.
Definition iface_mgr.h:675
isc::dhcp::SocketInfo
Holds information about socket.
Definition socket_info.h:19
watch_socket.h
Defines the class, WatchSocket.
watched_thread.h