OpenSDN source code
dhcp_handler_base.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #include <stdint.h>
7 #include "vr_defs.h"
8 #include "cmn/agent_cmn.h"
9 #include "pkt/pkt_init.h"
10 #include "oper/vn.h"
11 #include "services/dhcp_proto.h"
12 #include "services/dhcpv6_proto.h"
13 #include "services/services_types.h"
14 #include "services/services_init.h"
15 #include "services/dns_proto.h"
17 #include "bind/bind_util.h"
18 
19 #include <boost/assign/list_of.hpp>
20 #include <boost/scoped_array.hpp>
21 #include <bind/bind_util.h>
22 
23 using namespace boost::assign;
24 
25 DhcpHandlerBase::DhcpHandlerBase(Agent *agent, boost::shared_ptr<PktInfo> info,
26  boost::asio::io_context &io)
27  : ProtoHandler(agent, info, io), vm_itf_(NULL), vm_itf_index_(-1),
28  option_(NULL), flags_(), dns_enable_(true),
29  host_routes_level_(Invalid) {
30  ipam_type_.ipam_dns_method = "none";
31 }
32 
34 }
35 
36 // Add option taking no data (length = 0)
37 uint16_t DhcpHandlerBase::AddNoDataOption(uint32_t option, uint16_t opt_len) {
38  option_->WriteData(option, 0, NULL, &opt_len);
39  return opt_len;
40 }
41 
42 // Add option taking a byte from input
43 uint16_t DhcpHandlerBase::AddByteOption(uint32_t option, uint16_t opt_len,
44  const std::string &input) {
45  std::stringstream value(input);
46  uint32_t data = 0;
47  value >> data;
48  if (value.bad() || value.fail() || data > 0xFF) {
49  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
50  input << "is invalid");
51  } else {
52  uint8_t byte = (uint8_t)data;
53  option_->WriteData(option, 1, &byte, &opt_len);
54  }
55  return opt_len;
56 }
57 
58 // Add option taking array of bytes from input
59 uint16_t DhcpHandlerBase::AddByteArrayOption(uint32_t option, uint16_t opt_len,
60  const std::string &input) {
61  option_->WriteData(option, 0, NULL, &opt_len);
62  std::stringstream value(input);
63  bool done = false;
64  uint32_t byte = 0;
65  value >> byte;
66  while (!value.bad() && !value.fail() && byte <= 0xFF) {
67  option_->AppendData(1, &byte, &opt_len);
68  if (value.eof()) {
69  done = true;
70  break;
71  }
72  value >> byte;
73  }
74 
75  // if atleast one byte is not added or in case of error, ignore this option
76  if (!option_->GetLen() || !done) {
77  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
78  input << "is invalid");
79  return opt_len - option_->GetLen() - option_->GetFixedLen();
80  }
81 
82  return opt_len;
83 }
84 
85 // Add option taking a byte followed by a string, from input
86 uint16_t DhcpHandlerBase::AddByteStringOption(uint32_t option, uint16_t opt_len,
87  const std::string &input) {
88  std::stringstream value(input);
89  uint32_t data = 0;
90  value >> data;
91  if (value.fail() || value.bad() || data > 0xFF) {
92  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
93  input << "is invalid");
94  return opt_len;
95  }
96 
97  uint8_t byte = (uint8_t)data;
98  std::string str;
99  value >> str;
100  option_->WriteData(option, 1, &byte, &opt_len);
101  option_->AppendData(str.length(), str.c_str(), &opt_len);
102 
103  return opt_len;
104 }
105 
106 // Add option taking a byte followed by one or more IPs, from input
107 uint16_t DhcpHandlerBase::AddByteIPOption(uint32_t option, uint16_t opt_len,
108  const std::string &input) {
109  std::stringstream value(input);
110  uint32_t data = 0;
111  value >> data;
112  uint8_t byte = (uint8_t)data;
113 
114  if (value.fail() || value.bad() || data > 0xFF) {
115  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
116  input << "is invalid");
117  return opt_len;
118  }
119 
120  option_->WriteData(option, 1, &byte, &opt_len);
121  while (value.good()) {
122  std::string ipstr;
123  value >> ipstr;
124  opt_len = AddIP(opt_len, ipstr);
125  }
126 
127  // if atleast one IP is not added, ignore this option
128  if (option_->GetLen() == 1) {
129  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
130  input << "is invalid");
131  return opt_len - option_->GetLen() - option_->GetFixedLen();
132  }
133 
134  return opt_len;
135 }
136 
137 // Add option taking string from input
138 uint16_t DhcpHandlerBase::AddStringOption(uint32_t option, uint16_t opt_len,
139  const std::string &input) {
140  option_->WriteData(option, input.length(), input.c_str(), &opt_len);
141  return opt_len;
142 }
143 
144 // Add option taking integer from input
145 uint16_t DhcpHandlerBase::AddIntegerOption(uint32_t option, uint16_t opt_len,
146  const std::string &input) {
147  std::stringstream value(input);
148  uint32_t data = 0;
149  value >> data;
150  if (value.bad() || value.fail()) {
151  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
152  input << "is invalid");
153  } else {
154  data = htonl(data);
155  option_->WriteData(option, 4, &data, &opt_len);
156  }
157  return opt_len;
158 }
159 
160 // Add option taking array of short from input
161 uint16_t DhcpHandlerBase::AddShortArrayOption(uint32_t option, uint16_t opt_len,
162  const std::string &input,
163  bool array) {
164  option_->WriteData(option, 0, NULL, &opt_len);
165  std::stringstream value(input);
166  uint16_t data = 0;
167  value >> data;
168  while (!value.bad() && !value.fail()) {
169  data = htons(data);
170  option_->AppendData(2, &data, &opt_len);
171  if (!array || value.eof()) break;
172  value >> data;
173  }
174 
175  // if atleast one short is not added, ignore this option
176  if (!option_->GetLen() || !value.eof()) {
177  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
178  input << "is invalid");
179  return opt_len - option_->GetLen() - option_->GetFixedLen();
180  }
181 
182  return opt_len;
183 }
184 
185 // Check for exceptions in handling IP options
186 bool DhcpHandlerBase::IsValidIpOption(uint32_t option, const std::string &ipstr,
187  bool is_v4) {
188  boost::system::error_code ec;
189  if (is_v4) {
190  if (option == DHCP_OPTION_DNS) {
191  return IsValidDnsOption(option, ipstr);
192  } else {
193  uint32_t ip = Ip4Address::from_string(ipstr, ec).to_ulong();
194  if(!ec.value() && !ip) {
195  return false;
196  }
197  }
198 
199  } else {
200  if (option == DHCPV6_OPTION_DNS_SERVERS) {
201  return IsValidDnsOption(option, ipstr);
202  } else {
203  IpAddress ip = IpAddress::from_string(ipstr, ec);
204  if (!ec.value() && ip.is_unspecified()) {
205  return false;
206  }
207  }
208  }
209 
210  return true;
211 }
212 
214  const std::string &ipstr) {
215  boost::system::error_code ec;
216  IpAddress ip = IpAddress::from_string(ipstr, ec);
217  if (!ec.value()) {
218  // when DNS server is present in DHCP option, disable vrouter
219  // proxying for DNS requests from VMs.
220  dns_enable_ = false;
221  if (ip.is_unspecified()) {
222  // Do not send the option when DNS servers have 0.0.0.0 or ::
223  // Set option flag so that they are not added later
224  set_flag(option);
225  return false;
226  }
227  }
228 
229  return true;
230 }
231 
232 // Add option taking number of Ipv4 addresses
233 uint16_t DhcpHandlerBase::AddIpv4Option(uint32_t option, uint16_t opt_len,
234  const std::string &input,
235  uint8_t min_count,
236  uint8_t max_count,
237  uint8_t multiples) {
238  option_->WriteData(option, 0, NULL, &opt_len);
239  std::stringstream value(input);
240  while (value.good()) {
241  std::string ipstr;
242  value >> ipstr;
243  if (!IsValidIpOption(option, ipstr, true)) {
244  return opt_len - option_->GetLen() - option_->GetFixedLen();
245  }
246  opt_len = AddIP(opt_len, ipstr);
247  }
248 
249  if (option == DHCP_OPTION_ROUTER) {
250  // Add our gw as well
251  if (!config_.gw_addr.is_unspecified()) {
252  opt_len = AddIP(opt_len, config_.gw_addr.to_string());
253  }
254  }
255 
256  // check that atleast min_count IP addresses are added
257  if (min_count && option_->GetLen() < min_count * 4) {
258  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
259  input << "is invalid");
260  return opt_len - option_->GetLen() - option_->GetFixedLen();
261  }
262 
263  // if specified, check that we dont add more than max_count IP addresses
264  if (max_count && option_->GetLen() > max_count * 4) {
265  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
266  input << "is invalid");
267  return opt_len - option_->GetLen() - option_->GetFixedLen();
268  }
269 
270  // if specified, check that we add in multiples of IP addresses
271  if (multiples && option_->GetLen() % (multiples * 4)) {
272  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
273  input << "is invalid");
274  return opt_len - option_->GetLen() - option_->GetFixedLen();
275  }
276 
277  return opt_len;
278 }
279 
280 // Add option taking number of Ipv6 addresses
281 uint16_t DhcpHandlerBase::AddIpv6Option(uint32_t option, uint16_t opt_len,
282  const std::string &input, bool list) {
283  option_->WriteData(option, 0, NULL, &opt_len);
284  std::stringstream value(input);
285  while (value.good()) {
286  std::string ipstr;
287  value >> ipstr;
288  if (!IsValidIpOption(option, ipstr, false)) {
289  return opt_len - option_->GetLen() - option_->GetFixedLen();
290  }
291  opt_len = AddIP(opt_len, ipstr);
292  if (!list) break;
293  }
294 
295  // check that atleast one IP address is added
296  if (option_->GetLen() < 16) {
297  DHCPV6_TRACE(Error, "Invalid DHCP option " << option << " for VM " <<
298  config_.ip_addr.to_string() << "; data missing");
299  return opt_len - option_->GetLen() - option_->GetFixedLen();
300  }
301 
302  return opt_len;
303 }
304 
305 // Add option taking compressed name
307  uint16_t opt_len,
308  const std::string &input,
309  bool list) {
310  option_->WriteData(option, 0, NULL, &opt_len);
311  std::stringstream value(input);
312  while (value.good()) {
313  std::string str;
314  value >> str;
315  if (str.size()) {
316  opt_len = AddCompressedName(opt_len, str);
317  if (!list) break;
318  }
319  }
320 
321  if (!option_->GetLen()) {
322  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
323  input << "is invalid");
324  return opt_len - option_->GetLen() - option_->GetFixedLen();
325  }
326 
327  return opt_len;
328 }
329 
330 // Add option taking a byte followed by a compressed name
332  uint16_t opt_len,
333  const std::string &input) {
334  option_->WriteData(option, 0, NULL, &opt_len);
335 
336  std::stringstream value(input);
337  uint32_t data = 0;
338  value >> data;
339  if (value.bad() || value.fail() || data > 0xFF) {
340  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
341  input << "is invalid");
342  return opt_len - option_->GetLen() - option_->GetFixedLen();
343  } else {
344  uint8_t byte = (uint8_t)data;
345  option_->WriteData(option, 1, &byte, &opt_len);
346  }
347 
348  std::string str;
349  value >> str;
350  if (value.bad() || value.fail() || !str.size()) {
351  DHCP_BASE_TRACE("Invalid DHCP option " << option << " data : " <<
352  input << "is invalid");
353  return opt_len - option_->GetLen() - option_->GetFixedLen();
354  }
355  return AddCompressedName(opt_len, str);
356 }
357 
358 uint16_t DhcpHandlerBase::AddCompressedName(uint16_t opt_len,
359  const std::string &input) {
360  boost::scoped_array<uint8_t> name(new uint8_t[input.size() * 2 + 2]);
361  uint16_t len = 0;
362  BindUtil::AddName(name.get(), input, 0, 0, len);
363  option_->AppendData(len, name.get(), &opt_len);
364  return opt_len;
365 }
366 
367 // Add an DNS server addresses from IPAM to the option
368 // Option code and len are added already; add only the addresses
369 uint16_t DhcpHandlerBase::AddDnsServers(uint16_t opt_len) {
370  if (ipam_type_.ipam_dns_method == "default-dns-server" ||
371  ipam_type_.ipam_dns_method == "virtual-dns-server" ||
372  ipam_type_.ipam_dns_method == "none" ||
373  ipam_type_.ipam_dns_method == "") {
374  if (!config_.dns_addr.is_unspecified()) {
375  opt_len = AddIP(opt_len, config_.dns_addr.to_string());
376  }
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) {
380  opt_len = AddIP(opt_len, ipam_type_.ipam_dns_server.
381  tenant_dns_server_address.ip_address[i]);
382  }
383  }
384  return opt_len;
385 }
386 
387 // Read the list of <subnet/plen, gw> from input and store them
388 // for later processing in AddClasslessRouteOption
389 void DhcpHandlerBase::ReadClasslessRoute(uint32_t option, uint16_t opt_len,
390  const std::string &input) {
391  std::stringstream value(input);
392  while (value.good()) {
393  std::string snetstr;
394  value >> snetstr;
395  OperDhcpOptions::HostRoute host_route;
396  boost::system::error_code ec = Ip4PrefixParse(snetstr, &host_route.prefix_,
397  (int *)&host_route.plen_);
398  if (ec || host_route.plen_ > 32 || !value.good()) {
399  DHCP_BASE_TRACE("Invalid Classless route DHCP option -"
400  "has to be list of <subnet/plen gw>");
401  break;
402  }
403 
404  value >> snetstr;
405  host_route.gw_ = Ip4Address::from_string(snetstr, ec);
406  if (ec) {
407  host_route.gw_ = Ip4Address();
408  }
409 
410  host_routes_.push_back(host_route);
411  }
412 }
413 
414 // Add host route options coming via config. Config priority is
415 // 1) options at VM interface level (host routes specifically set)
416 // 2) options at VM interface level (classless routes from --extra-dhcp-opts)
417 // 3) options at subnet level (host routes at subnet level - neutron config)
418 // 4) options at subnet level (classless routes from dhcp options)
419 // 5) options at IPAM level (host routes from IPAM)
420 // 6) options at IPAM level (classless routes from IPAM dhcp options)
421 // Add the options defined at the highest level in priority
422 uint16_t DhcpHandlerBase::AddClasslessRouteOption(uint16_t opt_len) {
423  std::vector<OperDhcpOptions::HostRoute> host_routes;
424  do {
425  // Port specific host route options
426  // TODO: should we remove host routes at port level from schema ?
428  host_routes = vm_itf_->oper_dhcp_options().host_routes();
429  break;
430  }
431  // Host routes from port specific DHCP options (neutron configuration)
433  host_routes.swap(host_routes_);
434  break;
435  }
436 
437  if (vm_itf_->vn()) {
438  Ip4Address ip = config_.ip_addr.to_v4();
439  const std::vector<VnIpam> &vn_ipam = vm_itf_->vn()->GetVnIpam();
440  uint32_t index;
441  for (index = 0; index < vn_ipam.size(); ++index) {
442  if (vn_ipam[index].IsSubnetMember(ip)) {
443  break;
444  }
445  }
446  if (index < vn_ipam.size()) {
447  // Subnet level host route options
448  // Preference to host routes at subnet (neutron configuration)
449  if (vn_ipam[index].oper_dhcp_options.are_host_routes_set()) {
450  host_routes = vn_ipam[index].oper_dhcp_options.host_routes();
451  break;
452  }
453  // Host route options from subnet level DHCP options
454  if (host_routes_level_ == SubnetLevel && host_routes_.size()) {
455  host_routes.swap(host_routes_);
456  break;
457  }
458  }
459 
460  // TODO: should remove host routes at VN level from schema ?
461  vm_itf_->vn()->GetVnHostRoutes(ipam_name_, &host_routes);
462  if (host_routes.size() > 0)
463  break;
464  }
465 
466  // IPAM level host route options
467  OperDhcpOptions oper_dhcp_options;
468  oper_dhcp_options.update_host_routes(ipam_type_.host_routes.route);
469  host_routes = oper_dhcp_options.host_routes();
470 
471  // Host route options from IPAM level DHCP options
472  if (!host_routes.size() && host_routes_.size()) {
473  host_routes.swap(host_routes_);
474  break;
475  }
476  } while (false);
477 
478  if (host_routes.size()) {
480  uint8_t *ptr = option_->GetData();
481  uint8_t len = 0;
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();
486  *ptr++ = plen;
487  len++;
488  for (unsigned int j = 0; plen && j <= (plen - 1) / 8; ++j) {
489  *ptr++ = (prefix >> 8 * (3 - j)) & 0xFF;
490  len++;
491  }
492  // if GW is not specified, set it to subnet's GW
493  if (gw)
494  *(uint32_t *)ptr = htonl(gw);
495  else
496  *(uint32_t *)ptr = htonl(config_.gw_addr.to_v4().to_ulong());
497  ptr += sizeof(uint32_t);
498  len += sizeof(uint32_t);
499  }
500  option_->SetLen(len);
501  opt_len += 2 + len;
503  }
504  return opt_len;
505 }
506 
508  uint16_t opt_len,
509  std::vector<autogen::DhcpOptionType> &options,
510  DhcpOptionLevel level) {
511  for (unsigned int i = 0; i < options.size(); ++i) {
512  // get the option code
513  uint32_t option = OptionCode(options[i].dhcp_option_name);
514  if (!option) {
515  DHCP_BASE_TRACE("Invalid DHCP option " <<
516  options[i].dhcp_option_name);
517  continue;
518  }
519 
520  // if option is already set in the response (from higher level), ignore
521  if (is_flag_set(option))
522  continue;
523 
524  uint16_t old_opt_len = opt_len;
525  DhcpOptionCategory category = OptionCategory(option);
526  option_->SetNextOptionPtr(opt_len);
527 
528  // if dhcp_option_value_bytes is set, use that for supported categories
529  std::string &opt_value = options[i].dhcp_option_value;
530  if (!options[i].dhcp_option_value_bytes.empty() &&
531  CanOverrideWithBytes(category)) {
532  category = ByteArray;
533  opt_value = options[i].dhcp_option_value_bytes;
534  }
535 
536  switch(category) {
537  case None:
538  break;
539 
540  case NoData:
541  opt_len = AddNoDataOption(option, opt_len);
542  break;
543 
544  case Bool:
545  case Byte:
546  opt_len = AddByteOption(option, opt_len,
547  options[i].dhcp_option_value);
548  break;
549 
550  case ByteArray:
551  opt_len = AddByteArrayOption(option, opt_len, opt_value);
552  break;
553 
554  case ByteString:
555  opt_len = AddByteStringOption(option, opt_len,
556  options[i].dhcp_option_value);
557  break;
558 
559  case ByteOneIPPlus:
560  opt_len = AddByteIPOption(option, opt_len,
561  options[i].dhcp_option_value);
562  break;
563 
564  case String:
565  opt_len = AddStringOption(option, opt_len,
566  options[i].dhcp_option_value);
567  break;
568 
569  case Int32bit:
570  case Uint32bit:
571  if (option == DHCP_OPTION_IP_LEASE_TIME) {
573  }
574  opt_len = AddIntegerOption(option, opt_len,
575  options[i].dhcp_option_value);
576  break;
577 
578  case Uint16bit:
579  opt_len = AddShortArrayOption(option, opt_len,
580  options[i].dhcp_option_value,
581  false);
582  break;
583 
584  case Uint16bitArray:
585  opt_len = AddShortArrayOption(option, opt_len,
586  options[i].dhcp_option_value,
587  true);
588  break;
589 
590  case OneIPv4:
591  opt_len = AddIpv4Option(option, opt_len,
592  options[i].dhcp_option_value, 1, 1, 0);
593  break;
594 
595  case ZeroIPv4Plus:
596  opt_len = AddIpv4Option(option, opt_len,
597  options[i].dhcp_option_value, 0, 0, 0);
598  break;
599 
600  case OneIPv4Plus:
601  if (option == DHCP_OPTION_ROUTER) {
602  // Router option is added later
603  routers_ = options[i].dhcp_option_value;
605  } else {
606  opt_len = AddIpv4Option(option, opt_len,
607  options[i].dhcp_option_value,
608  1, 0, 0);
609  }
610  break;
611 
612  case TwoIPv4Plus:
613  opt_len = AddIpv4Option(option, opt_len,
614  options[i].dhcp_option_value, 2, 0, 2);
615  break;
616 
617  case OneIPv6:
618  opt_len = AddIpv6Option(option, opt_len,
619  options[i].dhcp_option_value,
620  false);
621  break;
622 
623  case OneIPv6Plus:
624  opt_len = AddIpv6Option(option, opt_len,
625  options[i].dhcp_option_value,
626  true);
627  break;
628 
629  case ClasslessRoute:
630  ReadClasslessRoute(option, opt_len,
631  options[i].dhcp_option_value);
632  if (host_routes_.size()) {
633  // set flag & level for classless route so that we dont
634  // update these at other level (subnet or ipam)
636  host_routes_level_ = level;
637  }
638  break;
639 
640  case NameCompression:
641  opt_len = AddCompressedNameOption(option, opt_len,
642  options[i].dhcp_option_value,
643  false);
644  break;
645 
647  opt_len = AddCompressedNameOption(option, opt_len,
648  options[i].dhcp_option_value,
649  true);
650  break;
651 
652  case ByteNameCompression:
653  opt_len = AddByteCompressedNameOption(option, opt_len,
654  options[i].dhcp_option_value);
655  break;
656 
657  default:
658  DHCP_BASE_TRACE("Invalid DHCP option " <<
659  options[i].dhcp_option_name);
660  break;
661  }
662 
663  // store siaddr for tftp server name to apply it later
664  if (option == DHCP_OPTION_TFTP_SERVER_NAME) {
665  boost::system::error_code ec;
666  Ip4Address siaddr =
667  Ip4Address::from_string(options[i].dhcp_option_value, ec);
668  if (ec.value() == 0)
669  siaddr_tftp_ = htonl(siaddr.to_ulong());
670  }
671 
672  if (opt_len != old_opt_len)
673  set_flag(option);
674  }
675 
676  return opt_len;
677 }
678 
679 // Add the option defined at the highest level in priority
680 // Take all options defined at VM interface level, take those from subnet which
681 // are not configured at interface, then take those from ipam which are not
682 // configured at interface or subnet.
683 uint16_t DhcpHandlerBase::AddConfigDhcpOptions(uint16_t opt_len, bool is_v6) {
684  std::vector<autogen::DhcpOptionType> options;
686  opt_len = AddDhcpOptions(opt_len, options, InterfaceLevel);
687 
688  if (vm_itf_->GetSubnetDhcpOptions(&options, is_v6))
689  opt_len = AddDhcpOptions(opt_len, options, SubnetLevel);
690 
691  if (vm_itf_->GetIpamDhcpOptions(&options, is_v6))
692  opt_len = AddDhcpOptions(opt_len, options, IpamLevel);
693 
694  return opt_len;
695 }
696 
698  if (config_.lease_time != (uint32_t) -1 ||
699  config_.valid_time != (uint32_t) -1)
700  return;
701 
702  if (!vm_itf_->vn() ||
703  !vm_itf_->vn()->GetIpamData(vm_addr, &ipam_name_, &ipam_type_)) {
704  DHCP_BASE_TRACE("Ipam data not found");
705  return;
706  }
707 
708  if (ipam_type_.ipam_dns_method != "virtual-dns-server" ||
709  !agent()->domain_config_table()->GetVDns(ipam_type_.ipam_dns_server.
710  virtual_dns_server_name,
711  &vdns_type_))
712  return;
713 
714  if (config_.domain_name_.size() &&
715  config_.domain_name_ != vdns_type_.domain_name) {
716  DHCP_BASE_TRACE("Client domain " << config_.domain_name_ <<
717  " doesnt match with configured domain " <<
718  vdns_type_.domain_name);
719  }
720  std::size_t pos;
721  if (config_.client_name_.size() &&
722  ((pos = config_.client_name_.find('.', 0)) != std::string::npos) &&
723  (config_.client_name_.substr(pos + 1) != vdns_type_.domain_name)) {
724  DHCP_BASE_TRACE("Client domain doesnt match with configured domain "
725  << vdns_type_.domain_name << "; Client name = "
726  << config_.client_name_);
727  config_.client_name_.replace(config_.client_name_.begin() + pos + 1,
728  config_.client_name_.end(),
729  vdns_type_.domain_name);
730  }
731 
732  config_.domain_name_ = vdns_type_.domain_name;
733 }
734 
736  if (category == ByteArray ||
737  category == ByteString ||
738  category == String ||
739  category == NameCompression ||
740  category == NameCompressionArray ||
741  category == ByteNameCompression)
742  return true;
743 
744  return false;
745 }
boost::system::error_code Ip4PrefixParse(const string &str, Ip4Address *addr, int *plen)
Definition: address.cc:108
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
Definition: agent.h:361
static uint8_t * AddName(uint8_t *ptr, const std::string &addr, uint16_t plen, uint16_t offset, uint16_t &length)
Definition: bind_util.cc:147
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)
ConfigRecord config_
bool CanOverrideWithBytes(DhcpOptionCategory category)
uint16_t AddNoDataOption(uint32_t option, uint16_t opt_len)
std::string routers_
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)
VmInterface * vm_itf_
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)
std::string ipam_name_
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)
Agent * agent() const
Definition: proto_handler.h:81
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
Definition: vn.h:172
bool GetVnHostRoutes(const std::string &ipam, std::vector< OperDhcpOptions::HostRoute > *routes) const
Definition: vn.cc:622
bool GetIpamData(const IpAddress &vm_addr, std::string *ipam_name, autogen::IpamType *ipam_type) const
Definition: vn.cc:643
static Options options
#define DHCP_OPTION_DNS
Definition: dhcp_handler.h:23
#define DHCP_OPTION_CLASSLESS_ROUTE
Definition: dhcp_handler.h:128
#define DHCP_OPTION_ROUTER
Definition: dhcp_handler.h:20
#define DHCP_OPTION_IP_LEASE_TIME
Definition: dhcp_handler.h:68
#define DHCP_OPTION_TFTP_SERVER_NAME
Definition: dhcp_handler.h:83
#define DHCP_BASE_TRACE(arg)
#define DHCPV6_OPTION_DNS_SERVERS
#define DHCPV6_TRACE(obj, arg)
Definition: dhcpv6_proto.h:12
Definition: io_utils.cc:12