13 #include "services/services_types.h"
19 #include <boost/assign/list_of.hpp>
20 #include <boost/scoped_array.hpp>
23 using namespace boost::assign;
26 boost::asio::io_context &
io)
28 option_(NULL), flags_(), dns_enable_(true),
29 host_routes_level_(Invalid) {
38 option_->WriteData(option, 0, NULL, &opt_len);
44 const std::string &input) {
45 std::stringstream value(input);
48 if (value.bad() || value.fail() || data > 0xFF) {
50 input <<
"is invalid");
52 uint8_t
byte = (uint8_t)data;
53 option_->WriteData(option, 1, &
byte, &opt_len);
60 const std::string &input) {
61 option_->WriteData(option, 0, NULL, &opt_len);
62 std::stringstream value(input);
66 while (!value.bad() && !value.fail() &&
byte <= 0xFF) {
67 option_->AppendData(1, &
byte, &opt_len);
76 if (!
option_->GetLen() || !done) {
78 input <<
"is invalid");
87 const std::string &input) {
88 std::stringstream value(input);
91 if (value.fail() || value.bad() || data > 0xFF) {
93 input <<
"is invalid");
97 uint8_t
byte = (uint8_t)data;
100 option_->WriteData(option, 1, &
byte, &opt_len);
101 option_->AppendData(str.length(), str.c_str(), &opt_len);
108 const std::string &input) {
109 std::stringstream value(input);
112 uint8_t
byte = (uint8_t)data;
114 if (value.fail() || value.bad() || data > 0xFF) {
116 input <<
"is invalid");
120 option_->WriteData(option, 1, &
byte, &opt_len);
121 while (value.good()) {
124 opt_len =
AddIP(opt_len, ipstr);
130 input <<
"is invalid");
139 const std::string &input) {
140 option_->WriteData(option, input.length(), input.c_str(), &opt_len);
146 const std::string &input) {
147 std::stringstream value(input);
150 if (value.bad() || value.fail()) {
152 input <<
"is invalid");
155 option_->WriteData(option, 4, &data, &opt_len);
162 const std::string &input,
164 option_->WriteData(option, 0, NULL, &opt_len);
165 std::stringstream value(input);
168 while (!value.bad() && !value.fail()) {
170 option_->AppendData(2, &data, &opt_len);
171 if (!array || value.eof())
break;
176 if (!
option_->GetLen() || !value.eof()) {
178 input <<
"is invalid");
188 boost::system::error_code ec;
193 uint32_t ip = Ip4Address::from_string(ipstr, ec).to_ulong();
194 if(!ec.value() && !ip) {
203 IpAddress ip = IpAddress::from_string(ipstr, ec);
204 if (!ec.value() && ip.is_unspecified()) {
214 const std::string &ipstr) {
215 boost::system::error_code ec;
216 IpAddress ip = IpAddress::from_string(ipstr, ec);
221 if (ip.is_unspecified()) {
234 const std::string &input,
238 option_->WriteData(option, 0, NULL, &opt_len);
239 std::stringstream value(input);
240 while (value.good()) {
246 opt_len =
AddIP(opt_len, ipstr);
257 if (min_count &&
option_->GetLen() < min_count * 4) {
259 input <<
"is invalid");
264 if (max_count &&
option_->GetLen() > max_count * 4) {
266 input <<
"is invalid");
271 if (multiples &&
option_->GetLen() % (multiples * 4)) {
273 input <<
"is invalid");
282 const std::string &input,
bool list) {
283 option_->WriteData(option, 0, NULL, &opt_len);
284 std::stringstream value(input);
285 while (value.good()) {
291 opt_len =
AddIP(opt_len, ipstr);
297 DHCPV6_TRACE(Error,
"Invalid DHCP option " << option <<
" for VM " <<
308 const std::string &input,
310 option_->WriteData(option, 0, NULL, &opt_len);
311 std::stringstream value(input);
312 while (value.good()) {
323 input <<
"is invalid");
333 const std::string &input) {
334 option_->WriteData(option, 0, NULL, &opt_len);
336 std::stringstream value(input);
339 if (value.bad() || value.fail() || data > 0xFF) {
341 input <<
"is invalid");
344 uint8_t
byte = (uint8_t)data;
345 option_->WriteData(option, 1, &
byte, &opt_len);
350 if (value.bad() || value.fail() || !str.size()) {
352 input <<
"is invalid");
359 const std::string &input) {
360 boost::scoped_array<uint8_t> name(
new uint8_t[input.size() * 2 + 2]);
363 option_->AppendData(len, name.get(), &opt_len);
370 if (
ipam_type_.ipam_dns_method ==
"default-dns-server" ||
371 ipam_type_.ipam_dns_method ==
"virtual-dns-server" ||
377 }
else if (
ipam_type_.ipam_dns_method ==
"tenant-dns-server") {
378 for (
unsigned int i = 0; i <
ipam_type_.ipam_dns_server.
379 tenant_dns_server_address.ip_address.size(); ++i) {
381 tenant_dns_server_address.ip_address[i]);
390 const std::string &input) {
391 std::stringstream value(input);
392 while (value.good()) {
397 (
int *)&host_route.
plen_);
398 if (ec || host_route.
plen_ > 32 || !value.good()) {
400 "has to be list of <subnet/plen gw>");
405 host_route.
gw_ = Ip4Address::from_string(snetstr, ec);
423 std::vector<OperDhcpOptions::HostRoute> host_routes;
441 for (index = 0; index < vn_ipam.size(); ++index) {
442 if (vn_ipam[index].IsSubnetMember(ip)) {
446 if (index < vn_ipam.size()) {
449 if (vn_ipam[index].oper_dhcp_options.are_host_routes_set()) {
450 host_routes = vn_ipam[index].oper_dhcp_options.host_routes();
462 if (host_routes.size() > 0)
478 if (host_routes.size()) {
480 uint8_t *ptr =
option_->GetData();
482 for (uint32_t i = 0; i < host_routes.size(); ++i) {
483 uint32_t prefix = host_routes[i].prefix_.to_ulong();
484 uint32_t plen = host_routes[i].plen_;
485 uint32_t gw = host_routes[i].gw_.to_ulong();
488 for (
unsigned int j = 0; plen && j <= (plen - 1) / 8; ++j) {
489 *ptr++ = (prefix >> 8 * (3 - j)) & 0xFF;
494 *(uint32_t *)ptr = htonl(gw);
497 ptr +=
sizeof(uint32_t);
498 len +=
sizeof(uint32_t);
509 std::vector<autogen::DhcpOptionType> &
options,
511 for (
unsigned int i = 0; i <
options.size(); ++i) {
524 uint16_t old_opt_len = opt_len;
526 option_->SetNextOptionPtr(opt_len);
529 std::string &opt_value =
options[i].dhcp_option_value;
530 if (!
options[i].dhcp_option_value_bytes.empty() &&
533 opt_value =
options[i].dhcp_option_value_bytes;
592 options[i].dhcp_option_value, 1, 1, 0);
597 options[i].dhcp_option_value, 0, 0, 0);
614 options[i].dhcp_option_value, 2, 0, 2);
665 boost::system::error_code ec;
667 Ip4Address::from_string(
options[i].dhcp_option_value, ec);
672 if (opt_len != old_opt_len)
684 std::vector<autogen::DhcpOptionType>
options;
708 if (
ipam_type_.ipam_dns_method !=
"virtual-dns-server" ||
710 virtual_dns_server_name,
717 " doesnt match with configured domain " <<
725 <<
vdns_type_.domain_name <<
"; Client name = "
boost::system::error_code Ip4PrefixParse(const string &str, Ip4Address *addr, int *plen)
boost::asio::ip::address IpAddress
boost::asio::ip::address_v4 Ip4Address
static uint8_t * AddName(uint8_t *ptr, const std::string &addr, uint16_t plen, uint16_t offset, uint16_t &length)
uint16_t AddClasslessRouteOption(uint16_t opt_len)
uint16_t AddByteOption(uint32_t option, uint16_t opt_len, const std::string &input)
uint16_t AddIpv4Option(uint32_t option, uint16_t opt_len, const std::string &input, uint8_t min_count, uint8_t max_count, uint8_t multiples)
uint16_t AddDhcpOptions(uint16_t opt_len, std::vector< autogen::DhcpOptionType > &options, DhcpOptionLevel level)
bool IsValidDnsOption(uint32_t option, const std::string &ipstr)
virtual uint32_t OptionCode(const std::string &option) const =0
uint16_t AddByteArrayOption(uint32_t option, uint16_t opt_len, const std::string &input)
uint16_t AddDnsServers(uint16_t opt_len)
void FindDomainName(const IpAddress &vm_addr)
DhcpOptionLevel host_routes_level_
void set_flag(uint8_t flag)
uint16_t AddCompressedName(uint16_t opt_len, const std::string &input)
bool CanOverrideWithBytes(DhcpOptionCategory category)
uint16_t AddNoDataOption(uint32_t option, uint16_t opt_len)
uint16_t AddIntegerOption(uint32_t option, uint16_t opt_len, const std::string &input)
bool IsValidIpOption(uint32_t option, const std::string &ipstr, bool is_v4)
uint16_t AddByteCompressedNameOption(uint32_t option, uint16_t opt_len, const std::string &input)
std::vector< OperDhcpOptions::HostRoute > host_routes_
virtual ~DhcpHandlerBase()
DhcpHandlerBase(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
uint16_t AddByteIPOption(uint32_t option, uint16_t opt_len, const std::string &input)
autogen::VirtualDnsType vdns_type_
virtual uint16_t AddIP(uint16_t opt_len, const std::string &input)=0
uint16_t AddConfigDhcpOptions(uint16_t opt_len, bool is_v6)
uint16_t AddStringOption(uint32_t option, uint16_t opt_len, const std::string &input)
bool is_flag_set(uint8_t flag) const
uint16_t AddByteStringOption(uint32_t option, uint16_t opt_len, const std::string &input)
boost::scoped_ptr< DhcpOptionHandler > option_
autogen::IpamType ipam_type_
uint16_t AddShortArrayOption(uint32_t option, uint16_t opt_len, const std::string &input, bool array)
void ReadClasslessRoute(uint32_t option, uint16_t opt_len, const std::string &input)
uint16_t AddIpv6Option(uint32_t option, uint16_t opt_len, const std::string &input, bool list)
uint16_t AddCompressedNameOption(uint32_t option, uint16_t opt_len, const std::string &input, bool list)
virtual DhcpOptionCategory OptionCategory(uint32_t option) const =0
const std::vector< HostRoute > & host_routes() const
bool are_host_routes_set() const
void update_host_routes(const HostOptionsList &host_routes)
bool GetInterfaceDhcpOptions(std::vector< autogen::DhcpOptionType > *options) const
bool GetSubnetDhcpOptions(std::vector< autogen::DhcpOptionType > *options, bool ipv6) const
const OperDhcpOptions & oper_dhcp_options() const
const VnEntry * vn() const
bool GetIpamDhcpOptions(std::vector< autogen::DhcpOptionType > *options, bool ipv6) const
const std::vector< VnIpam > & GetVnIpam() const
bool GetVnHostRoutes(const std::string &ipam, std::vector< OperDhcpOptions::HostRoute > *routes) const
bool GetIpamData(const IpAddress &vm_addr, std::string *ipam_name, autogen::IpamType *ipam_type) const
#define DHCP_OPTION_CLASSLESS_ROUTE
#define DHCP_OPTION_ROUTER
#define DHCP_OPTION_IP_LEASE_TIME
#define DHCP_OPTION_TFTP_SERVER_NAME
#define DHCP_BASE_TRACE(arg)
#define DHCPV6_OPTION_DNS_SERVERS
#define DHCPV6_TRACE(obj, arg)