19#include <boost/pointer_cast.hpp>
22#include <netinet/in.h>
49 int sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
55 if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) {
58 "Failed to set O_NONBLOCK on DHCP4o6 socket.");
62 struct sockaddr_in6 local6;
63 memset(&local6, 0,
sizeof(local6));
64 local6.sin6_family = AF_INET6;
66 local6.sin6_len =
sizeof(local6);
69 local6.sin6_port = htons(port);
71 local6.sin6_port = htons(port + 1);
74 local6.sin6_addr.s6_addr[15] = 1;
75 if (::bind(sock, (
struct sockaddr *)&local6,
sizeof(local6)) < 0) {
81 struct sockaddr_in6 remote6;
82 memset(&remote6, 0,
sizeof(remote6));
83 remote6.sin6_family = AF_INET6;
85 remote6.sin6_len =
sizeof(remote6);
88 remote6.sin6_port = htons(port + 1);
90 remote6.sin6_port = htons(port);
94 remote6.sin6_addr.s6_addr[15] = 1;
95 if (connect(sock,
reinterpret_cast<const struct sockaddr*
>(&remote6),
96 sizeof(remote6)) < 0) {
129 ssize_t cc = recv(
socket_fd_, buf,
sizeof(buf), 0);
134 pkt->updateTimestamp();
145 for (
auto const& opt : vendor_options) {
146 option_vendor = boost::dynamic_pointer_cast<OptionVendor>(opt.second);
148 if (option_vendor->getVendorId() == ENTERPRISE_ID_ISC) {
151 option_vendor.reset();
156 if (!option_vendor) {
158 .arg(
"no ISC vendor option");
164 OptionString>(option_vendor->getOption(ISC_V6_4O6_INTERFACE));
167 .arg(
"no interface suboption");
169 "malformed packet (interface suboption missing "
170 "or has incorrect type)");
177 .arg(
"can't get interface " + ifname->getValue());
179 "malformed packet (unknown interface "
180 + ifname->getValue() +
")");
185 OptionCustom>(option_vendor->getOption(ISC_V6_4O6_SRC_ADDRESS));
188 .arg(
"no source address suboption");
190 "malformed packet (source address suboption missing "
191 "or has incorrect type)");
196 OptionUint16>(option_vendor->getOption(ISC_V6_4O6_SRC_PORT));
199 .arg(
"no source port suboption");
201 "malformed packet (source port suboption missing "
202 "or has incorrect type)");
206 pkt->setRemoteAddr(srcs->readAddress());
207 pkt->setRemotePort(sport->getValue());
208 pkt->setIface(iface->getName());
209 pkt->setIndex(iface->getIndex());
212 static_cast<void>(option_vendor->delOption(ISC_V6_4O6_INTERFACE));
213 static_cast<void>(option_vendor->delOption(ISC_V6_4O6_SRC_ADDRESS));
214 static_cast<void>(option_vendor->delOption(ISC_V6_4O6_SRC_PORT));
218 if (option_vendor->getOptions().empty()) {
230 " trying to send it over the IPC");
236 " IPC socket is closed");
246 for (
auto const& opt : vendor_options) {
247 option_vendor = boost::dynamic_pointer_cast<OptionVendor>(opt.second);
249 if (option_vendor->getVendorId() == ENTERPRISE_ID_ISC) {
252 option_vendor.reset();
258 if (!option_vendor) {
260 pkt->addOption(option_vendor);
265 ISC_V6_4O6_INTERFACE,
268 pkt->getRemoteAddr())));
271 pkt->getRemotePort())));
280 "failed to send DHCP4o6 message over the IPC: "
void send(const Pkt6Ptr &pkt)
Send message over IPC.
virtual ~Dhcp4o6IpcBase()
Destructor.
Pkt6Ptr receive()
Receive message over IPC.
uint16_t port_
Port number configured for IPC communication.
EndpointType
Endpoint type: DHCPv4 or DHCPv6 server.
void close()
Close communication socket.
virtual void open()=0
Open communication socket (for derived classes).
Dhcp4o6IpcBase()
Constructor.
int socket_fd_
Socket descriptor.
Exception thrown when error occurs as a result of use of IPC.
void deleteExternalSocket(int socketfd)
Deletes external socket.
IfacePtr getIface(const unsigned int ifindex)
Returns interface specified interface index.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
DHCPv6 Option class for handling list of IPv6 addresses.
Option with defined data fields represented as buffers that can be accessed using data field index.
Forward declaration to OptionInt.
Class which represents an option carrying a single string value.
This class represents vendor-specific information option.
Represents a DHCPv6 packet.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
const uint8_t * getData() const
Return a pointer to the head of the data stored in the buffer.
size_t getLength() const
Return the length of data written in the buffer.
void clear()
Clear buffer content.
Defines the Dhcp4o6IpcBase class.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
OptionInt< uint16_t > OptionUint16
boost::shared_ptr< OptionUint16 > OptionUint16Ptr
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
boost::shared_ptr< OptionVendor > OptionVendorPtr
Pointer to a vendor option.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
boost::shared_ptr< OptionCustom > OptionCustomPtr
A pointer to the OptionCustom object.
boost::shared_ptr< Iface > IfacePtr
Type definition for the pointer to an Iface object.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
boost::shared_ptr< Option6AddrLst > Option6AddrLstPtr
Pointer to the Option6AddrLst object.
const isc::log::MessageID DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET
boost::shared_ptr< OptionString > OptionStringPtr
Pointer to the OptionString object.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
Defines the logger used by the top-level component of kea-lfc.