19 #include <boost/pointer_cast.hpp>
22 #include <netinet/in.h>
33 Dhcp4o6IpcBase::Dhcp4o6IpcBase() : port_(0), socket_fd_(-1) {}
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 (OptionCollection::const_iterator opt = vendor_options.begin();
146 opt != vendor_options.end(); ++opt) {
147 option_vendor = boost::dynamic_pointer_cast<
OptionVendor>(opt->second);
149 if (option_vendor->getVendorId() == ENTERPRISE_ID_ISC) {
152 option_vendor.reset();
157 if (!option_vendor) {
159 .arg(
"no ISC vendor option");
165 OptionString>(option_vendor->getOption(ISC_V6_4O6_INTERFACE));
168 .arg(
"no interface suboption");
170 "malformed packet (interface suboption missing "
171 "or has incorrect type)");
178 .arg(
"can't get interface " + ifname->getValue());
180 "malformed packet (unknown interface "
181 + ifname->getValue() +
")");
186 OptionCustom>(option_vendor->getOption(ISC_V6_4O6_SRC_ADDRESS));
189 .arg(
"no source address suboption");
191 "malformed packet (source address suboption missing "
192 "or has incorrect type)");
197 OptionUint16>(option_vendor->getOption(ISC_V6_4O6_SRC_PORT));
200 .arg(
"no source port suboption");
202 "malformed packet (source port suboption missing "
203 "or has incorrect type)");
207 pkt->setRemoteAddr(srcs->readAddress());
208 pkt->setRemotePort(sport->getValue());
209 pkt->setIface(iface->getName());
210 pkt->setIndex(iface->getIndex());
213 static_cast<void>(option_vendor->delOption(ISC_V6_4O6_INTERFACE));
214 static_cast<void>(option_vendor->delOption(ISC_V6_4O6_SRC_ADDRESS));
215 static_cast<void>(option_vendor->delOption(ISC_V6_4O6_SRC_PORT));
219 if (option_vendor->getOptions().empty()) {
231 " trying to send it over the IPC");
237 " IPC socket is closed");
246 if (!option_vendor ||
247 (option_vendor->getVendorId() != ENTERPRISE_ID_ISC)) {
255 ISC_V6_4O6_INTERFACE,
258 ISC_V6_4O6_SRC_ADDRESS,
259 pkt->getRemoteAddr())));
262 pkt->getRemotePort())));
271 "failed to send DHCP4o6 message over the IPC: "
IfacePtr getIface(int ifindex)
Returns interface specified interface index.
#define LOG_WARN(LOGGER, MESSAGE)
Macro to conveniently test warn output and log it.
const void * getData() const
Return a pointer to the head of the data stored in the buffer.
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.
virtual void open()=0
Open communication socket (for derived classes).
Represents a DHCPv6 packet.
boost::shared_ptr< OptionString > OptionStringPtr
Pointer to the OptionString object.
DHCPv6 Option class for handling list of IPv6 addresses.
Forward declaration to OptionInt.
OptionInt< uint16_t > OptionUint16
const isc::log::MessageID DHCPSRV_DHCP4O6_RECEIVED_BAD_PACKET
boost::shared_ptr< Option6AddrLst > Option6AddrLstPtr
Pointer to the Option6AddrLst object.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the Dhcp4o6IpcBase class.
boost::shared_ptr< Pkt6 > Pkt6Ptr
A pointer to Pkt6 packet.
boost::shared_ptr< OptionUint16 > OptionUint16Ptr
int socket_fd_
Socket descriptor.
uint16_t port_
Port number configured for IPC communication.
void deleteExternalSocket(int socketfd)
Deletes external socket.
Exception thrown when error occurs as a result of use of IPC.
void clear()
Clear buffer content.
std::multimap< unsigned int, OptionPtr > OptionCollection
A collection of DHCP (v4 or v6) options.
void addOption(OptionPtr opt)
Adds a sub-option.
The OutputBuffer class is a buffer abstraction for manipulating mutable data.
Defines the logger used by the top-level component of kea-dhcp-ddns.
virtual ~Dhcp4o6IpcBase()
Destructor.
EndpointType
Endpoint type: DHCPv4 or DHCPv6 server.
static IfaceMgr & instance()
IfaceMgr is a singleton class.
Pkt6Ptr receive()
Receive message over IPC.
void close()
Close communication socket.
void send(const Pkt6Ptr &pkt)
Send message over IPC.
isc::log::Logger dhcpsrv_logger("dhcpsrv")
DHCP server library Logger.
Option with defined data fields represented as buffers that can be accessed using data field index...
boost::shared_ptr< OptionVendor > OptionVendorPtr
Pointer to a vendor option.
size_t getLength() const
Return the length of data written in the buffer.
Class which represents an option carrying a single string value.
This class represents vendor-specific information option.