 |
Kea
1.5.0
|
Go to the documentation of this file.
23 #include <boost/function.hpp>
24 #include <boost/noncopyable.hpp>
25 #include <boost/scoped_array.hpp>
26 #include <boost/shared_ptr.hpp>
114 class Iface :
public boost::noncopyable {
143 Iface(
const std::string& name,
int ifindex);
186 void setMac(
const uint8_t* mac,
size_t macLen);
372 if (read_buffer_.empty()) {
375 return (&read_buffer_[0]);
380 return (read_buffer_.size());
387 read_buffer_.resize(new_size);
454 std::vector<uint8_t> read_buffer_;
544 test_mode_ = test_mode;
560 allow_loopback_ = allow_loopback;
725 const bool receive_bcast =
false,
726 const bool send_bcast =
false);
747 const uint8_t family);
764 const uint16_t port);
781 const uint16_t port);
829 bool openSockets6(
const uint16_t port = DHCP6_SERVER_PORT,
900 bool openSockets4(
const uint16_t port = DHCP4_SERVER_PORT,
901 const bool use_bcast =
true,
1023 return (packet_queue_mgr4_);
1033 return (packet_queue_mgr4_->getPacketQueue());
1040 return (packet_queue_mgr6_);
1050 return (packet_queue_mgr6_->getPacketQueue());
1074 return (dhcp_receiver_ != 0 && dhcp_receiver_->isRunning());
1100 static void addFDtoSet(
int fd,
int& maxfd, fd_set* sockets);
1125 const uint16_t port,
const bool receive_bcast =
false,
1126 const bool send_bcast =
false);
1187 uint16_t port,
const bool join_multicast);
1275 const uint16_t port);
1295 bool openMulticastSocket(
Iface& iface,
1297 const uint16_t port,
1309 void receiveDHCP4Packets();
1332 void receiveDHCP6Packets();
1343 void receiveDHCP6Packet(
const SocketInfo& socket_info);
1368 bool allow_loopback_;
1383 #endif // IFACE_MGR_H
Iface(const std::string &name, int ifindex)
Iface constructor.
Represents a DHCPv6 packet.
void setFlags(uint64_t flags)
Sets flag_*_ fields based on bitmask value returned by OS.
boost::shared_ptr< PacketQueue< Pkt4Ptr > > PacketQueue4Ptr
Defines pointer to the DHCPv4 queue interface used at the application level.
void stopDHCPReceiver()
Stops the DHCP packet receiver.
Simple class representing an optional value.
int openSocketFromRemoteAddress(const isc::asiolink::IOAddress &remote_addr, const uint16_t port)
Opens UDP/IP socket to be used to connect to remote address.
bool send(const Pkt6Ptr &pkt)
Sends an IPv6 packet.
std::string getName() const
Returns interface name.
size_t getReadBufferSize() const
Returns the current size of the socket read buffer.
void setTestMode(const bool test_mode)
Sets or clears the test mode for IfaceMgr.
Pkt6Ptr receive6Indirect(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv6 packets indirectly or data from 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.
Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
boost::shared_ptr< PktFilter6 > PktFilter6Ptr
Pointer to a PktFilter object.
IfaceMgr exception thrown thrown when socket opening or configuration failed.
The IOAddress class represents an IP addresses (version agnostic)
PacketQueue4Ptr getPacketQueue4()
Fetches the DHCPv4 receiver packet queue.
uint8_t mac_[MAX_MAC_LEN]
Link-layer address.
void closeSockets()
Closes all open sockets on interface.
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.
uint64_t flags_
Interface flags (this value is as is returned by OS, it may mean different things on different OSes).
bool openSockets4(const uint16_t port=DHCP4_SERVER_PORT, const bool use_bcast=true, IfaceMgrErrorMsgCallback error_handler=0)
Opens IPv4 sockets on detected interfaces.
void clearUnicasts()
Removes any unicast addresses.
void detectIfaces()
Detects network interfaces.
SocketNotFound(const char *file, size_t line, const char *what)
void deleteExternalSocket(int socketfd)
Deletes external socket.
Pkt4Ptr receive4Indirect(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets indirectly or data from external sockets.
void setPacketFilter(const PktFilterPtr &packet_filter)
Set packet filter object to handle sending and receiving DHCPv4 messages.
bool hasAddress(const isc::asiolink::IOAddress &address) const
Check if the interface has the specified address assigned.
boost::shared_ptr< IfaceMgr > IfaceMgrPtr
Type definition for the pointer to the IfaceMgr.
void clearUnicasts()
Clears unicast addresses on all interfaces.
size_t getMacLen() const
Returns MAC length.
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
virtual ~IfaceMgr()
Destructor.
int openSocket6(Iface &iface, const isc::asiolink::IOAddress &addr, uint16_t port, const bool join_multicast)
Opens IPv6 socket.
bool hasOpenSocket(const uint16_t family) const
Checks if there is at least one socket of the specified family open.
util::OptionalValue< asiolink::IOAddress > Address
Address type.
Represents a single network interface.
bool delAddress(const isc::asiolink::IOAddress &addr)
Deletes an address from an interface.
std::list< Address > AddressCollection
Type that defines list of addresses.
boost::shared_ptr< PacketQueue< Pkt6Ptr > > PacketQueue6Ptr
Defines pointer to the DHCPv6 queue interface used at the application level.
IfaceMgr exception thrown when there is no suitable socket found.
PacketFilterChangeDenied(const char *file, size_t line, const char *what)
std::string name_
Network interface name.
Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets or data from external sockets.
void setActive(const isc::asiolink::IOAddress &address, const bool active)
Activates or deactivates address for the interface.
This is a base class for exceptions thrown from the DNS library module.
uint8_t * getReadBuffer()
Returns the pointer to the buffer used for data reading.
boost::function< void(const std::string &errmsg)> IfaceMgrErrorMsgCallback
This type describes the callback function invoked when error occurs in the IfaceMgr.
SocketWriteError(const char *file, size_t line, const char *what)
IfaceDetectError(const char *file, size_t line, const char *what)
SocketConfigError(const char *file, size_t line, const char *what)
const AddressCollection & getUnicasts() const
Returns a container of addresses the server should listen on.
static const unsigned int MAX_MAC_LEN
Maximum MAC address length (Infiniband uses 20 bytes)
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
bool isDHCPReceiverRunning() const
Returns true if there is a receiver exists and its thread is currently running.
bool flag_multicast_
Flag specifies if selected interface is multicast capable.
Pkt6Ptr receive6Direct(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv6 packets directly or data from external sockets.
void resizeReadBuffer(const size_t new_size)
Reallocates the socket read buffer.
uint16_t countIfaces()
Returns number of detected interfaces.
boost::shared_ptr< PacketQueueMgr6 > PacketQueueMgr6Ptr
Defines a shared pointer to PacketQueueMgr6.
bool getAddress4(isc::asiolink::IOAddress &address) const
Returns IPv4 address assigned to the interface.
void setAllowLoopBack(const bool allow_loopback)
Allows or disallows the loopback interface.
boost::shared_ptr< PktFilter > PktFilterPtr
Pointer to a PktFilter object.
void setMatchingPacketFilter(const bool direct_response_desired=false)
Set Packet Filter object to handle send/receive packets.
Pkt4Ptr receive4Direct(uint32_t timeout_sec, uint32_t timeout_usec=0)
Receive IPv4 packets directly or data from external sockets.
Exception thrown when it is not allowed to set new Packet Filter.
unsigned int countActive4() const
Returns a number of activated IPv4 addresses on the interface.
int openSocketFromAddress(const isc::asiolink::IOAddress &addr, const uint16_t port)
Opens UDP/IP socket and binds to address specified.
void closeSockets()
Closes all open sockets.
bool isDirectResponseSupported() const
Check if packet be sent directly to the client having no address.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
AddressCollection unicasts_
List of unicast addresses the server should listen on.
Keeps callback information for external sockets.
const IfaceCollection & getIfaces()
Returns container with all interfaces.
int socket_
Socket descriptor of the external socket.
static const uint32_t RCVBUFSIZE
Packet reception buffer size.
PacketQueueMgr4Ptr getPacketQueueMgr4()
Fetches the DHCPv4 packet queue manager.
int ifindex_
Interface index (a value that uniquely identifies an interface).
bool flag_broadcast_
Flag specifies if selected interface is broadcast capable.
AddressCollection addrs_
List of assigned addresses.
bool flag_loopback_
Specifies if selected interface is loopback.
IfaceMgr exception thrown thrown when interface detection fails.
std::list< SocketInfo > SocketCollection
Type that holds a list of socket information.
void addAddress(const isc::asiolink::IOAddress &addr)
Adds an address to an interface.
Represents DHCPv4 packet.
const uint8_t * getMac() const
Returns pointer to MAC address.
std::string getFullName() const
Returns full interface name as "ifname/ifindex" string.
bool flag_up_
Specifies if selected interface is up.
Handles network interfaces, transmission and reception.
size_t mac_len_
Length of link-layer address (usually 6).
PacketQueue6Ptr getPacketQueue6()
Fetches the DHCPv6 receiver packet queue.
Exception thrown when a call to select is interrupted by a signal.
void addUnicast(const isc::asiolink::IOAddress &addr)
Adds unicast the server should listen on.
boost::shared_ptr< WatchedThread > WatchedThreadPtr
Defines a pointer to a WatchedThread.
std::string getPlainMac() const
Returns link-layer address a plain text.
Holds information about socket.
void addInterface(const IfacePtr &iface)
Adds an interface to list of known interfaces.
const SocketCollection & getSockets() const
Returns collection of all sockets added to interface.
bool configureDHCPPacketQueue(const uint16_t family, data::ConstElementPtr queue_control)
Configures DHCP packet queue.
bool inactive4_
Indicates that IPv4 sockets should (true) or should not (false) be opened on this interface.
SocketReadError(const char *file, size_t line, const char *what)
uint16_t hardware_type_
Hardware type.
uint16_t getIndex() const
Returns interface index.
void addExternalSocket(int socketfd, SocketCallback callback)
Adds external socket and a callback.
IfaceCollection ifaces_
List of available interfaces.
IfaceNotFound(const char *file, size_t line, const char *what)
boost::shared_ptr< PacketQueueMgr4 > PacketQueueMgr4Ptr
Defines a shared pointer to PacketQueueMgr4.
void setHWType(uint16_t type)
Sets up hardware type of the interface.
std::list< SocketCallbackInfo > SocketCallbackInfoContainer
Defines storage container for callbacks for external sockets.
boost::function< void()> SocketCallback
Defines callback used when data is received over external sockets.
IfaceMgr exception thrown thrown when error occurred during reading data from socket.
IfaceMgr exception thrown when there is no suitable interface.
SignalInterruptOnSelect(const char *file, size_t line, const char *what)
uint16_t getSocket(const isc::dhcp::Pkt6 &pkt)
Return most suitable socket for transmitting specified IPv6 packet.
bool delSocket(uint16_t sockfd)
Closes socket.
bool openSockets6(const uint16_t port=DHCP6_SERVER_PORT, IfaceMgrErrorMsgCallback error_handler=0)
Opens IPv6 sockets on detected interfaces.
boost::shared_ptr< const Element > ConstElementPtr
SocketCallback callback_
A callback that will be called when data arrives over socket_.
SocketCollection sockets_
Socket used to send data.
uint16_t getHWType() const
Returns hardware type of the interface.
void printIfaces(std::ostream &out=std::cout)
Debugging method that prints out all available interfaces.
std::list< IfacePtr > IfaceCollection
Type that holds a list of pointers to interfaces.
void stubDetectIfaces()
Stub implementation of network interface detection.
PacketQueueMgr6Ptr getPacketQueueMgr6()
Fetches the DHCPv6 packet queue manager.
void addSocket(const SocketInfo &sock)
Adds socket descriptor to an interface.
static const IfaceMgrPtr & instancePtr()
Returns pointer to the sole instance of the interface manager.
bool flag_running_
Flag specifies if selected interface is running (e.g.
static void addFDtoSet(int fd, int &maxfd, fd_set *sockets)
Convenience method for adding an descriptor to a set.
IfaceMgr exception thrown thrown when error occurred during sending data through socket.
boost::shared_ptr< Iface > IfacePtr
const AddressCollection & getAddresses() const
Returns all addresses available on an interface.
void deleteAllExternalSockets()
Deletes all external sockets.
IfaceMgr()
Protected constructor.
bool isTestMode() const
Checks if the IfaceMgr is in the test mode.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
void startDHCPReceiver(const uint16_t family)
Starts DHCP packet receiver.
int openSocketFromIface(const std::string &ifname, const uint16_t port, const uint8_t family)
Opens UDP/IP socket and binds it to interface specified.
void clearIfaces()
Removes detected interfaces.
void setMac(const uint8_t *mac, size_t macLen)
Sets MAC address of the interface.
bool inactive6_
Indicates that IPv6 sockets should (true) or should not (false) be opened on this interface.