17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <net/if_dl.h>
33 IfaceMgr::detectIfaces() {
34 struct ifaddrs* iflist = 0;
35 struct ifaddrs* ifptr = 0;
38 if(getifaddrs(&iflist) != 0) {
42 typedef map<string, IfacePtr> IfaceLst;
43 IfaceLst::iterator iface_iter;
47 for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
48 const char * ifname = ifptr->ifa_name;
51 if (!(ifindex = if_nametoindex(ifname))) {
57 if ((iface_iter = ifaces.find(ifname)) != ifaces.end()) {
62 iface->setFlags(ifptr->ifa_flags);
63 ifaces.insert(pair<string, IfacePtr>(ifname, iface));
67 for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
68 if ((iface_iter = ifaces.find(ifptr->ifa_name)) == ifaces.end()) {
72 const uint8_t * ptr = 0;
73 if(ifptr->ifa_addr->sa_family == AF_LINK) {
75 struct sockaddr_dl * ldata =
76 reinterpret_cast<struct sockaddr_dl *
>(ifptr->ifa_addr);
77 ptr =
reinterpret_cast<uint8_t *
>(LLADDR(ldata));
79 iface_iter->second->setHWType(ldata->sdl_type);
80 iface_iter->second->setMac(ptr, ldata->sdl_alen);
81 }
else if(ifptr->ifa_addr->sa_family == AF_INET6) {
83 struct sockaddr_in6 * adata =
84 reinterpret_cast<struct sockaddr_in6 *
>(ifptr->ifa_addr);
85 ptr =
reinterpret_cast<uint8_t *
>(&adata->sin6_addr);
87 IOAddress a = IOAddress::fromBytes(AF_INET6, ptr);
88 iface_iter->second->addAddress(a);
91 struct sockaddr_in * adata =
92 reinterpret_cast<struct sockaddr_in *
>(ifptr->ifa_addr);
93 ptr =
reinterpret_cast<uint8_t *
>(&adata->sin_addr);
95 IOAddress a = IOAddress::fromBytes(AF_INET, ptr);
96 iface_iter->second->addAddress(a);
103 for(IfaceLst::const_iterator iface_iter = ifaces.begin();
104 iface_iter != ifaces.end(); ++iface_iter) {
105 addInterface(iface_iter->second);
114 void Iface::setFlags(uint64_t flags) {
117 flag_loopback_ = flags & IFF_LOOPBACK;
118 flag_up_ = flags & IFF_UP;
119 flag_running_ = flags & IFF_RUNNING;
120 flag_multicast_ = flags & IFF_MULTICAST;
121 flag_broadcast_ = flags & IFF_BROADCAST;
125 IfaceMgr::setMatchingPacketFilter(
const bool direct_response_desired) {
133 if (direct_response_desired) {
143 IfaceMgr::openMulticastSocket(
Iface& iface,
154 "Failed to open link-local socket on "
155 " interface " << iface.
getName() <<
": "
164 IfaceMgr::openSocket6(
Iface& iface,
const IOAddress& addr, uint16_t port,
165 const bool join_multicast) {
171 SocketInfo info = packet_filter6_->openSocket(iface, actual_address, port,
Packet handling class using Berkeley Packet Filtering (BPF)
IfaceMgr exception thrown thrown when socket opening or configuration failed.
void addSocket(const SocketInfo &sock)
Adds socket descriptor to an interface.
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.
Packet handling class using AF_INET socket family.
Represents a single network interface.
boost::shared_ptr< PktFilter > PktFilterPtr
Pointer to a PktFilter object.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
bool flag_multicast_
Flag specifies if selected interface is multicast capable.
A generic exception that is thrown when an unexpected error condition occurs.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::string getName() const
Returns interface name.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
#define IFACEMGR_ERROR(ex_type, handler, stream)
A macro which handles an error in IfaceMgr.
The IOAddress class represents an IP addresses (version agnostic)
Holds information about socket.