Commit 22a8c0b3 authored by Francis Dupont's avatar Francis Dupont Committed by Tomek Mrugalski
Browse files

[4106] Changed to use the private options

parent 89c8c17a
......@@ -55,7 +55,6 @@ void Dhcp4o6Ipc::handler() {
return;
}
pkt->unpack();
OptionCollection msgs = pkt->getOptions(D6O_DHCPV4_MSG);
if (msgs.size() != 1) {
return;
......
......@@ -54,14 +54,18 @@ void Dhcp4o6Ipc::handler() {
if (!pkt) {
return;
}
isc::util::OutputBuffer& buf = pkt->getBuffer();
pkt->repack();
buf.clear();
pkt->pack();
uint8_t msg_type = buf[0];
if ((msg_type == DHCPV6_RELAY_FORW) || (msg_type == DHCPV6_RELAY_REPL)) {
pkt->setRemotePort(DHCP6_SERVER_PORT);
} else {
pkt->setRemotePort(DHCP6_CLIENT_PORT);
}
IfaceMgr::instance().send(pkt);
// processStatsSent(pkt);
}
......
......@@ -15,7 +15,7 @@ CLEANFILES = *.gcno *.gcda
lib_LTLIBRARIES = libkea-dhcp++.la
libkea_dhcp___la_SOURCES =
libkea_dhcp___la_SOURCES += classify.cc classify.h
libkea_dhcp___la_SOURCES += dhcp6.h dhcp4.h dhcp4o6.h
libkea_dhcp___la_SOURCES += dhcp6.h dhcp4.h
libkea_dhcp___la_SOURCES += duid.cc duid.h
libkea_dhcp___la_SOURCES += hwaddr.cc hwaddr.h
libkea_dhcp___la_SOURCES += iface_mgr.cc iface_mgr.h
......
// Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
#ifndef DHCP4O6_H
#define DHCP4O6_H
/* Offsets and sizes into interserver messages. */
#define DHCP4O6_IFNAME_OFFSET 0
#define DHCP4O6_IFNAME_SIZE 16
#define DHCP4O6_RADDR_OFFSET 16
#define DHCP4O6_RADDR_SIZE 16
#define DHCP4O6_DHCP6_OFFSET 32
#endif /* DHCP4O6_H */
......@@ -14,8 +14,11 @@
#include <config.h>
#include <dhcp/dhcp4o6.h>
#include <dhcp/dhcp6.h>
#include <dhcp/iface_mgr.h>
#include <dhcp/option6_addrlst.h>
#include <dhcp/option_string.h>
#include <dhcp/option_vendor.h>
#include <dhcpsrv/dhcp4o6_ipc.h>
#include <netinet/in.h>
......@@ -132,25 +135,38 @@ Pkt6Ptr Dhcp4o6IpcBase::receive() {
if (cc < 0) {
isc_throw(Unexpected, "Failed to receive on DHCP4o6 socket.");
}
if (cc < DHCP4O6_DHCP6_OFFSET + Pkt6::DHCPV6_PKT_HDR_LEN) {
// Ignore too short messages
Pkt6Ptr pkt = Pkt6Ptr(new Pkt6(buf, cc));
pkt->updateTimestamp();
// Get interface name and remote address
pkt->unpack();
OptionVendorPtr vendor =
boost::dynamic_pointer_cast<OptionVendor>(pkt->getOption(D6O_VENDOR_OPTS));
if (!vendor || vendor->getVendorId() != ENTERPRISE_ID_ISC) {
return (Pkt6Ptr());
}
OptionStringPtr ifname =
boost::dynamic_pointer_cast<OptionString>(vendor->getOption(ISC_V6_4O6_INTERFACE));
if (!ifname) {
return (Pkt6Ptr());
}
char name[DHCP4O6_IFNAME_SIZE + 1];
memcpy(name, buf, DHCP4O6_IFNAME_SIZE);
IfacePtr iface = IfaceMgr::instance().getIface(string(name));
IfacePtr iface = IfaceMgr::instance().getIface(ifname->getValue());
if (!iface) {
// Can't get the interface: ignore
return (Pkt6Ptr());
}
uint8_t raddr[DHCP4O6_RADDR_SIZE];
memcpy(raddr, buf + DHCP4O6_RADDR_OFFSET, DHCP4O6_RADDR_SIZE);
IOAddress from = IOAddress::fromBytes(AF_INET6, raddr);
Pkt6Ptr pkt;
pkt = Pkt6Ptr(new Pkt6(buf + DHCP4O6_DHCP6_OFFSET,
cc - DHCP4O6_DHCP6_OFFSET));
pkt->updateTimestamp();
pkt->setRemoteAddr(from);
Option6AddrLstPtr srcs =
boost::dynamic_pointer_cast<Option6AddrLst>(vendor->getOption(ISC_V6_4O6_SRC_ADDRESS));
if (!srcs) {
return (Pkt6Ptr());
}
Option6AddrLst::AddressContainer addrs = srcs->getAddresses();
if (addrs.size() != 1) {
return (Pkt6Ptr());
}
// Update the packet and return it
static_cast<void>(pkt->delOption(D6O_VENDOR_OPTS));
pkt->setRemoteAddr(addrs[0]);
pkt->setIface(iface->getName());
pkt->setIndex(iface->getIndex());
return (pkt);
......@@ -167,37 +183,24 @@ void Dhcp4o6IpcBase::send(Pkt6Ptr pkt) {
return;
}
// Get interface name
string name = pkt->getIface();
if (name.empty() || name.size() > DHCP4O6_IFNAME_SIZE) {
// Bad interface name: ignore
return;
}
name.resize(DHCP4O6_IFNAME_SIZE);
// Get a vendor option
OptionVendorPtr vendor(new OptionVendor(Option::V6, ENTERPRISE_ID_ISC));
// Get remote address
IOAddress from = pkt->getRemoteAddr();
vector<uint8_t> raddr = from.toBytes();
if (raddr.size() != DHCP4O6_RADDR_SIZE) {
// Bad remote address: ignore
return;
}
// Push interface name and source address in it
vendor->addOption(OptionPtr(new OptionString(Option::V6,
ISC_V6_4O6_INTERFACE,
pkt->getIface())));
vendor->addOption(OptionPtr(new Option6AddrLst(ISC_V6_4O6_SRC_ADDRESS,
pkt->getRemoteAddr())));
pkt->addOption(vendor);
// Get packet content
OutputBuffer& pbuf = pkt->getBuffer();
if (!pbuf.getLength()) {
// Empty buffer: content is not (yet) here, get it
pkt->repack();
}
// Fill buffer
vector<uint8_t> buf(DHCP4O6_DHCP6_OFFSET + pbuf.getLength());
memcpy(&buf[0], name.c_str(), DHCP4O6_IFNAME_SIZE);
memcpy(&buf[0] + DHCP4O6_RADDR_OFFSET, &raddr[0], DHCP4O6_RADDR_SIZE);
memcpy(&buf[0] + DHCP4O6_DHCP6_OFFSET, pbuf.getData(), pbuf.getLength());
OutputBuffer& buf = pkt->getBuffer();
buf.clear();
pkt->pack();
// Send
static_cast<void>(::send(socket_fd_, &buf[0], buf.size(), 0));
static_cast<void>(::send(socket_fd_, buf.getData(), buf.getLength(), 0));
return;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment