18#include <sys/socket.h>
34 if (detect_callback_) {
35 if (!detect_callback_(update_only)) {
40 struct ifaddrs* iflist = 0;
41 struct ifaddrs* ifptr = 0;
44 if (getifaddrs(&iflist) != 0) {
48 typedef map<string, IfacePtr> IfaceLst;
49 IfaceLst::iterator iface_iter;
53 for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
54 const char * ifname = ifptr->ifa_name;
57 if (!(ifindex = if_nametoindex(ifname))) {
63 iface_iter = ifaces.find(ifname);
64 if (iface_iter != ifaces.end()) {
73 iface.reset(
new Iface(ifname, ifindex));
75 iface->setFlags(ifptr->ifa_flags);
76 ifaces.insert(pair<string, IfacePtr>(ifname, iface));
80 for (ifptr = iflist; ifptr != 0; ifptr = ifptr->ifa_next) {
81 iface_iter = ifaces.find(ifptr->ifa_name);
82 if (iface_iter == ifaces.end()) {
86 const uint8_t * ptr = 0;
87 if (ifptr->ifa_addr->sa_family == AF_LINK) {
89 struct sockaddr_dl * ldata =
90 reinterpret_cast<struct sockaddr_dl *
>(ifptr->ifa_addr);
91 ptr =
reinterpret_cast<uint8_t *
>(LLADDR(ldata));
93 iface_iter->second->setHWType(ldata->sdl_type);
94 iface_iter->second->setMac(ptr, ldata->sdl_alen);
95 }
else if (ifptr->ifa_addr->sa_family == AF_INET6) {
97 struct sockaddr_in6 * adata =
98 reinterpret_cast<struct sockaddr_in6 *
>(ifptr->ifa_addr);
99 ptr =
reinterpret_cast<uint8_t *
>(&adata->sin6_addr);
102 iface_iter->second->addAddress(a);
105 struct sockaddr_in * adata =
106 reinterpret_cast<struct sockaddr_in *
>(ifptr->ifa_addr);
107 ptr =
reinterpret_cast<uint8_t *
>(&adata->sin_addr);
110 iface_iter->second->addAddress(a);
117 for (
auto const& iface_it : ifaces) {
152 if (direct_response_desired) {
162IfaceMgr::openMulticastSocket(
Iface& iface,
173 "Failed to open link-local socket on "
174 "interface " << iface.
getName() <<
": "
184 const bool join_multicast) {
190 SocketInfo info = packet_filter6_->openSocket(iface, actual_address, port,
193 return (
info.sockfd_);
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 when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
static IOAddress fromBytes(short family, const uint8_t *data)
Creates an address from over wire data.
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.
IfacePtr getIface(const unsigned int ifindex)
Returns interface specified interface index.
void setPacketFilter(const PktFilterPtr &packet_filter)
Set packet filter object to handle sending and receiving DHCPv4 messages.
void detectIfaces(bool update_only=false)
Detects network interfaces.
int openSocket6(Iface &iface, const isc::asiolink::IOAddress &addr, uint16_t port, const bool join_multicast)
Opens IPv6 socket.
void addInterface(const IfacePtr &iface)
Adds an interface to list of known interfaces.
void setMatchingPacketFilter(const bool direct_response_desired=false)
Set Packet Filter object to handle send/receive packets.
Represents a single network interface.
uint64_t flags_
Interface flags (this value is as is returned by OS, it may mean different things on different OSes).
bool flag_multicast_
Flag specifies if selected interface is multicast capable.
std::string getName() const
Returns interface name.
void setFlags(uint64_t flags)
Sets flag_*_ fields based on bitmask value returned by OS.
bool flag_running_
Flag specifies if selected interface is running (e.g.
bool flag_loopback_
Specifies if selected interface is loopback.
void addSocket(const SocketInfo &sock)
Adds socket descriptor to an interface.
bool flag_up_
Specifies if selected interface is up.
bool flag_broadcast_
Flag specifies if selected interface is broadcast capable.
Packet handling class using Berkeley Packet Filtering (BPF)
Packet handling class using AF_INET socket family.
IfaceMgr exception thrown thrown when socket opening or configuration failed.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define IFACEMGR_ERROR(ex_type, handler, iface, stream)
A macro which handles an error in IfaceMgr.
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.
Defines the logger used by the top-level component of kea-lfc.
Holds information about socket.