36 uint8_t family = (options.
getIpVersion() == 6) ? AF_INET6 : AF_INET;
42 "Values for IP version: " <<
44 " and server address: " << servername <<
" are mismatched.");
48 if (family == AF_INET6) {
50 port = DHCP6_CLIENT_PORT;
53 port = DHCP6_SERVER_PORT;
62 if (!localname.empty()) {
67 sock = IfaceMgr::instance().openSocketFromIface(localname,
72 sock = IfaceMgr::instance().openSocketFromAddress(localaddr,
75 }
else if (!servername.empty()) {
78 sock = IfaceMgr::instance().openSocketFromRemoteAddress(remoteaddr,
90 int broadcast_enable = 1;
91 int ret = setsockopt(sock, SOL_SOCKET, SO_BROADCAST,
92 &broadcast_enable,
sizeof(broadcast_enable));
95 "unable to set broadcast option on the socket");
102 int ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
103 &hops,
sizeof(hops));
113 int idx = iface->getIndex();
114 ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_IF,
119 "unable to enable multicast on socket " << sock
120 <<
". errno = " << errno);
137 for (
IfacePtr iface : IfaceMgr::instance().getIfaces()) {
151 Pkt4Ptr pkt = IfaceMgr::instance().receive4(timeout_sec, timeout_usec);
155 }
catch (
const std::exception &e) {
157 std::cout <<
"Incorrect DHCP packet received"
158 << e.what() << std::endl;
166 Pkt6Ptr pkt = IfaceMgr::instance().receive6(timeout_sec, timeout_usec);
170 }
catch (
const std::exception &e) {
172 std::cout <<
"Incorrect DHCP packet received"
173 << e.what() << std::endl;
181 return IfaceMgr::instance().send(pkt);
186 return IfaceMgr::instance().send(pkt);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
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 or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
The IOAddress class represents an IP addresses (version agnostic)
bool isV6Multicast() const
checks whether and address is IPv6 and is multicast
short getFamily() const
Returns the address family.
unsigned int ifindex_
Interface index.
uint8_t getIpVersion() const
Returns IP version.
std::string getLocalName() const
Returns local address or interface name.
int getLocalPort() const
Returns local port number.
bool isBroadcast() const
Checks if broadcast address is to be used.
std::string getServerName() const
Returns server name.
bool isUseRelayedV6() const
Check if generated DHCPv6 messages should appear as relayed.
bool isInterface() const
Checks if interface name was used.
static int malformed_pkts_
virtual ~PerfSocket()
Destructor of the socket wrapper class.
PerfSocket(CommandOptions &options)
Constructor of socket wrapper class.
virtual dhcp::Pkt6Ptr receive6(uint32_t timeout_sec, uint32_t timeout_usec) override
Receive DHCPv6 packet from interface.
virtual dhcp::IfacePtr getIface() override
Get interface from IfaceMgr.
virtual bool send(const dhcp::Pkt4Ptr &pkt) override
Send DHCPv4 packet through interface.
int openSocket(CommandOptions &options) const
Open socket to communicate with DHCP server.
void initSocketData()
Initialize socket data.
virtual dhcp::Pkt4Ptr receive4(uint32_t timeout_sec, uint32_t timeout_usec) override
Receive DHCPv4 packet from interface.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< Pkt4 > Pkt4Ptr
A pointer to Pkt4 object.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Defines the logger used by the top-level component of kea-lfc.
Holds information about socket.
isc::asiolink::IOAddress addr_