OpenSDN source code
dhcp_handler.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 "base/os.h"
8 #include "base/address_util.h"
9 #include "vr_defs.h"
10 #include "cmn/agent_cmn.h"
11 #include "oper/route_common.h"
12 #include "oper/vn.h"
13 #include "pkt/pkt_init.h"
14 #include "services/dhcp_proto.h"
15 #include "services/dhcp_lease_db.h"
16 #include "services/services_types.h"
17 #include "services/services_init.h"
18 #include "services/dns_proto.h"
20 #include "bind/bind_util.h"
21 #include "bind/xmpp_dns_agent.h"
22 
23 #include <boost/assign/list_of.hpp>
24 #include <bind/bind_util.h>
25 
26 using namespace boost::assign;
28  map_list_of<std::string, uint32_t>
29  ("subnet-mask", DHCP_OPTION_SUBNET_MASK)
30  ("time-offset", DHCP_OPTION_TIME_OFFSET)
31  ("routers", DHCP_OPTION_ROUTER)
32  ("time-servers", DHCP_OPTION_TIME_SERVER)
33  ("name-servers", DHCP_OPTION_NAME_SERVER)
34  ("domain-name-servers", DHCP_OPTION_DNS)
35  ("log-servers", DHCP_OPTION_LOG_SERVER)
36  ("quote-servers", DHCP_OPTION_QUOTE_SERVER)
37  ("lpr-servers", DHCP_OPTION_LPR_SERVER)
38  ("impress-servers", DHCP_OPTION_IMPRESS_SERVER)
39  ("resource-location-servers", DHCP_OPTION_RESOURCE_LOCATION_SERVER)
40  ("host-name", DHCP_OPTION_HOST_NAME)
41  ("boot-size", DHCP_OPTION_BOOT_FILE_SIZE)
42  ("merit-dump", DHCP_OPTION_MERIT_DUMP_FILE)
43  ("domain-name", DHCP_OPTION_DOMAIN_NAME)
44  ("swap-server", DHCP_OPTION_SWAP_SERVER)
45  ("root-path", DHCP_OPTION_ROOT_PATH)
46  ("extension-path", DHCP_OPTION_EXTENSION_PATH)
47  ("ip-forwarding", DHCP_OPTION_IP_FWD_CONTROL)
48  ("non-local-source-routing", DHCP_OPTION_NL_SRC_ROUTING)
49  ("policy-filter", DHCP_OPTION_POLICY_FILTER)
50  ("max-dgram-reassembly", DHCP_OPTION_MAX_DG_REASSEMBLY_SIZE)
51  ("default-ip-ttl", DHCP_OPTION_DEFAULT_IP_TTL)
52  ("path-mtu-aging-timeout", DHCP_OPTION_PATH_MTU_AGING_TIMEOUT)
53  ("path-mtu-plateau-table", DHCP_OPTION_PATH_MTU_PLATEAU_TABLE)
54  ("interface-mtu", DHCP_OPTION_INTERFACE_MTU)
55  ("all-subnets-local", DHCP_OPTION_ALL_SUBNETS_LOCAL)
56  ("broadcast-address", DHCP_OPTION_BCAST_ADDRESS)
57  ("perform-mask-discovery", DHCP_OPTION_PERFORM_MASK_DISCOVERY)
58  ("mask-supplier", DHCP_OPTION_MASK_SUPPLIER)
59  ("router-discovery", DHCP_OPTION_PERFORM_ROUTER_DISCOVERY)
60  ("router-solicitation-address", DHCP_OPTION_ROUTER_SOLICIT_ADDRESS)
61  ("static-routes", DHCP_OPTION_STATIC_ROUTING_TABLE)
62  ("trailer-encapsulation", DHCP_OPTION_TRAILER_ENCAP)
63  ("arp-cache-timeout", DHCP_OPTION_ARP_CACHE_TIMEOUT)
64  ("ieee802-3-encapsulation", DHCP_OPTION_ETHERNET_ENCAP)
65  ("default-tcp-ttl", DHCP_OPTION_DEFAULT_TCP_TTL)
66  ("tcp-keepalive-interval", DHCP_OPTION_TCP_KEEPALIVE_INTERVAL)
67  ("tcp-keepalive-garbage", DHCP_OPTION_TCP_KEEPALIVE_GARBAGE)
68  ("nis-domain", DHCP_OPTION_NIS_DOMAIN)
69  ("nis-servers", DHCP_OPTION_NIS_SERVERS)
70  ("ntp-servers", DHCP_OPTION_NTP_SERVERS)
71  ("vendor-encapsulated-options", DHCP_OPTION_VENDOR_SPECIFIC_INFO)
72  ("netbios-name-servers", DHCP_OPTION_NETBIOS_OVER_TCP_NS)
73  ("netbios-dd-server", DHCP_OPTION_NETBIOS_OVER_TCP_DG_DS)
74  ("netbios-node-type", DHCP_OPTION_NETBIOS_OVER_TCP_NODE_TYPE)
75  ("netbios-scope", DHCP_OPTION_NETBIOS_OVER_TCP_SCOPE)
76  ("font-servers", DHCP_OPTION_XWINDOW_FONT_SERVER)
77  ("x-display-manager", DHCP_OPTION_XWINDOW_SYSTEM_DISP_MGR)
78  ("dhcp-requested-address", DHCP_OPTION_REQ_IP_ADDRESS)
79  ("dhcp-lease-time", DHCP_OPTION_IP_LEASE_TIME)
80  ("dhcp-option-overload", DHCP_OPTION_OVERLOAD)
81  ("dhcp-message-type", DHCP_OPTION_MSG_TYPE)
82  ("dhcp-server-identifier", DHCP_OPTION_SERVER_IDENTIFIER)
83  ("dhcp-parameter-request-list", DHCP_OPTION_PARAMETER_REQUEST_LIST)
84  ("dhcp-message", DHCP_OPTION_MESSAGE)
85  ("dhcp-max-message-size", DHCP_OPTION_MAX_DHCP_MSG_SIZE)
86  ("dhcp-renewal-time", DHCP_OPTION_RENEW_TIME_VALUE)
87  ("dhcp-rebinding-time", DHCP_OPTION_REBIND_TIME_VALUE)
88  ("class-id", DHCP_OPTION_CLASS_ID)
89  ("dhcp-client-identifier", DHCP_OPTION_CLIENT_ID)
90  ("nwip-domain", DHCP_OPTION_NETWARE_IP_DOMAIN_NAME)
91  ("nwip-suboptions", DHCP_OPTION_NETWARE_IP_INFO)
92  ("nisplus-domain", DHCP_OPTION_NIS_PLUS_DOMAIN)
93  ("nisplus-servers", DHCP_OPTION_NIS_PLUS_SERVERS)
94  ("tftp-server-name", DHCP_OPTION_TFTP_SERVER_NAME)
95  ("bootfile-name", DHCP_OPTION_BOOTFILE_NAME)
96  ("mobile-ip-home-agent", DHCP_OPTION_MOBILE_IP_HA)
97  ("smtp-server", DHCP_OPTION_SMTP_SERVER)
98  ("pop-server", DHCP_OPTION_POP_SERVER)
99  ("nntp-server", DHCP_OPTION_NNTP_SERVER)
100  ("www-server", DHCP_OPTION_DEFAULT_WWW_SERVER)
101  ("finger-server", DHCP_OPTION_DEFAULT_FINGER_SERVER)
102  ("irc-server", DHCP_OPTION_DEFAULT_IRC_SERVER)
103  ("streettalk-server", DHCP_OPTION_STREETTALK_SERVER)
104  ("streettalk-directory-assistance-server", DHCP_OPTION_STREETTALK_DA_SERVER)
105  ("user-class", DHCP_OPTION_USER_CLASS_INFO)
106  ("slp-directory-agent", DHCP_OPTION_SLP_DIRECTORY_AGENT)
107  ("slp-service-scope", DHCP_OPTION_SLP_SERVICE_SCOPE)
108  ("rapid-commit", DHCP_OPTION_RAPID_COMMIT)
109  ("client-fqdn", DHCP_OPTION_CLIENT_FQDN)
110  ("storage-ns", DHCP_OPTION_STORAGE_NS)
111  // option 82 not required
112  ("nds-servers", DHCP_OPTION_NDS_SERVERS)
113  ("nds-tree-name", DHCP_OPTION_NDS_TREE_NAME)
114  ("nds-context", DHCP_OPTION_NDS_CONTEXT)
115  ("bcms-controller-names", DHCP_OPTION_BCMCS_DN_LIST)
116  ("bcms-controller-address", DHCP_OPTION_BCMCS_ADDR_LIST)
117  ("dhcp-auth", DHCP_OPTION_AUTH)
118  ("dhcp-client-last-time", DHCP_OPTION_CLIENT_LAST_XTIME)
119  ("associated-ip", DHCP_OPTION_ASSOCIATE_IP)
120  ("system-architecture", DHCP_OPTION_CLIENT_SYSARCH_TYPE)
121  ("interface-id", DHCP_OPTION_CLIENT_NW_INTERFACE_ID)
122  ("ldap-servers", DHCP_OPTION_LDAP)
123  ("machine-id", DHCP_OPTION_CLIENT_MACHINE_ID)
124  ("user-auth", DHCP_OPTION_OPENGROUP_USER_AUTH)
125  ("geoconf-civic", DHCP_OPTION_GEOCONF_CIVIC)
126  ("ieee-1003-1-tz", DHCP_OPTION_IEEE_1003_1_TZ)
127  ("ref-tz-db", DHCP_OPTION_REF_TZ_DB)
128  ("netinfo-server-address", DHCP_OPTION_NETINFO_PARENT_SERVER_ADDR)
129  ("netinfo-server-tag", DHCP_OPTION_NETINFO_PARENT_SERVER_TAG)
130  ("default-url", DHCP_OPTION_URL)
131  ("auto-configure", DHCP_OPTION_AUTO_CONFIGURE)
132  ("name-search", DHCP_OPTION_NAME_SERVICE_SEARCH)
133  ("subnet-selection", DHCP_OPTION_SUBNET_SELECTION)
134  ("domain-search", DHCP_OPTION_DNS_DOMAIN_SEARCH_LIST)
135  ("sip-servers", DHCP_OPTION_SIP_SERVERS)
136  ("classless-static-routes", DHCP_OPTION_CLASSLESS_ROUTE)
137  ("dhcp-ccc", DHCP_OPTION_CCC)
138  ("dhcp-geoconf", DHCP_OPTION_GEOCONF)
139  ("vendor-class-identifier", DHCP_OPTION_VENDOR_ID_VENDOR_CLASS)
141  ("tftp-server", DHCP_OPTION_TFTP_SERVER)
142  ("pxe-vendor-specific-129", DHCP_OPTION_PXE_VENDOR_SPECIFIC_129)
143  ("pxe-vendor-specific-130", DHCP_OPTION_PXE_VENDOR_SPECIFIC_130)
144  ("pxe-vendor-specific-131", DHCP_OPTION_PXE_VENDOR_SPECIFIC_131)
145  ("pxe-vendor-specific-132", DHCP_OPTION_PXE_VENDOR_SPECIFIC_132)
146  ("pxe-vendor-specific-133", DHCP_OPTION_PXE_VENDOR_SPECIFIC_133)
147  ("pxe-vendor-specific-134", DHCP_OPTION_PXE_VENDOR_SPECIFIC_134)
148  ("pxe-vendor-specific-135", DHCP_OPTION_PXE_VENDOR_SPECIFIC_135)
149  ("pana-agent", DHCP_OPTION_PANA_AUTH_AGENT)
150  ("lost-server", DHCP_OPTION_LOST_SERVER)
151  ("capwap-ac-v4", DHCP_OPTION_CAPWAP_AC_ADDRESS)
152  ("dhcp-mos", DHCP_OPTION_IPV4_ADDRESS_MOS)
153  ("dhcp-fqdn-mos", DHCP_OPTION_IPV4_FQDN_MOS)
154  ("sip-ua-config-domain", DHCP_OPTION_SIP_UA_CONFIG_DOMAIN)
155  ("andsf-servers", DHCP_OPTION_IPV4_ADDRESS_ANDSF)
156  ("dhcp-geoloc", DHCP_OPTION_GEOLOC)
157  ("force-renew-nonce-cap", DHCP_OPTION_FORCERENEW_NONCE_CAP)
158  ("rdnss-selection", DHCP_OPTION_RDNSS_SELECTION)
159  ("tftp-server-address", DHCP_OPTION_TFTP_SERVER_ADDRESS)
160  ("status-code", DHCP_OPTION_STATUS_CODE)
161  ("dhcp-base-time", DHCP_OPTION_BASE_TIME)
162  ("dhcp-state-start-time", DHCP_OPTION_START_TIME_OF_STATE)
163  ("dhcp-query-start-time", DHCP_OPTION_QUERY_START_TIME)
164  ("dhcp-query-end-time", DHCP_OPTION_QUERY_END_TIME)
165  ("dhcp-state", DHCP_OPTION_DHCP_STATE)
166  ("data-source", DHCP_OPTION_DATA_SOURCE)
167  ("pcp-server", DHCP_OPTION_PCP_SERVER)
168  ("dhcp-pxe-magic", DHCP_OPTION_PXELINUX_MAGIC)
169  ("config-file", DHCP_OPTION_CONFIG_FILE)
170  ("path-prefix", DHCP_OPTION_PATH_PREFIX)
171  ("reboot-time", DHCP_OPTION_REBOOT_TIME)
172  ("dhcp-6rd", DHCP_OPTION_6RD)
173  ("dhcp-access-domain", DHCP_OPTION_V4_ACCESS_DOMAIN)
174  ("subnet-allocation", DHCP_OPTION_SUBNET_ALLOCATION)
175  ("dhcp-vss", DHCP_OPTION_VSS);
176 
178  map_list_of<uint32_t, DhcpHandler::DhcpOptionCategory>
179  // (DHCP_OPTION_SUBNET_MASK, DhcpHandler::OneIPv4) // agent adds this option
206  // (DHCP_OPTION_BCAST_ADDRESS, DhcpHandler::OneIPv4) // agent adds this option
231  // (DHCP_OPTION_MSG_TYPE, DhcpHandler::Byte) // agent adds this option
232  // (DHCP_OPTION_SERVER_IDENTIFIER, DhcpHandler::OneIPv4) // agent adds this option
259  // (DHCP_OPTION_CLIENT_FQDN, DhcpHandler::ByteArray) // sent by clients
260  (DHCP_OPTION_STORAGE_NS, DhcpHandler::ByteArray) // send encoded data
262  (DHCP_OPTION_NDS_TREE_NAME, DhcpHandler::ByteArray) // send encoded data
263  (DHCP_OPTION_NDS_CONTEXT, DhcpHandler::ByteArray) // send encoded data
264  (DHCP_OPTION_BCMCS_DN_LIST, DhcpHandler::ByteArray) // send encoded data
266  (DHCP_OPTION_AUTH, DhcpHandler::ByteArray) // send encoded data
274  (DHCP_OPTION_GEOCONF_CIVIC, DhcpHandler::ByteArray) // send encoded data
284  (DHCP_OPTION_SIP_SERVERS, DhcpHandler::ByteArray) // send encoded data
286  (DHCP_OPTION_CCC, DhcpHandler::ByteArray) // send encoded data
287  (DHCP_OPTION_GEOCONF, DhcpHandler::ByteArray) // send encoded data
299  (DHCP_OPTION_LOST_SERVER, DhcpHandler::ByteArray) // send encoded data
302  (DHCP_OPTION_IPV4_FQDN_MOS, DhcpHandler::ByteArray) // send encoded data
305  (DHCP_OPTION_GEOLOC, DhcpHandler::ByteArray) // send encoded data
316  (DHCP_OPTION_PCP_SERVER, DhcpHandler::ByteArray) // send encoded data
321  (DHCP_OPTION_6RD, DhcpHandler::ByteArray) // send encoded data
327 
328 DhcpHandler::DhcpHandler(Agent *agent, boost::shared_ptr<PktInfo> info,
329  boost::asio::io_context &io)
330  : DhcpHandlerBase(agent, info, io), msg_type_(DHCP_UNKNOWN),
331  out_msg_type_(DHCP_UNKNOWN),
332  nak_msg_("cannot assign requested address") {
333  option_.reset(new Dhcpv4OptionHandler(NULL));
334 }
335 
337 }
338 
340  switch(pkt_info_->type) {
341  case PktType::MESSAGE:
342  return HandleMessage();
343 
344  default:
345  return HandleVmRequest();
346  }
347 }
348 
350  DhcpProto *dhcp_proto = agent()->GetDhcpProto();
351  // options length = pkt length - size of headers
352  int16_t options_len = pkt_info_->len -
353  (pkt_info_->data - (uint8_t *)pkt_info_->pkt)
354  - DHCP_FIXED_LEN;
355  if (options_len < 0) {
357  DHCP_TRACE(Error, "Improper DHCP packet length; vrf = " <<
358  pkt_info_->vrf << " ifindex = " << GetInterfaceIndex());
359  return true;
360  }
361 
362  dhcp_ = (dhcphdr *) pkt_info_->data;
363  option_->SetDhcpOptionPtr(dhcp_->options);
365  Interface *itf =
367  if (itf == NULL) {
368  dhcp_proto->IncrStatsOther();
369  DHCP_TRACE(Error, "Received DHCP packet on invalid interface : "
370  << GetInterfaceIndex());
371  return true;
372  }
373 
374  if (itf->type() != Interface::VM_INTERFACE) {
375  dhcp_proto->IncrStatsErrors();
376  DHCP_TRACE(Error, "Received DHCP packet on non VM port interface : "
377  << GetInterfaceIndex());
378  return true;
379  }
380  vm_itf_ = static_cast<VmInterface *>(itf);
381  if (!vm_itf_->dhcp_enable_config()) {
382  dhcp_proto->IncrDhcpDisabledDrops();
383  DHCP_TRACE(Error, "DHCP request on VM port with dhcp services disabled: "
384  << GetInterfaceIndex());
385  return true;
386  }
387 
388  if (vm_itf_->vm_mac() != request_.mac_addr) {
389  dhcp_proto->IncrIncorrectMac();
390  DHCP_TRACE(Error, "DHCP request for incorrect MAC: interface = "
391  << GetInterfaceIndex() << " interface MAC = "
392  << vm_itf_->vm_mac().ToString() << " requested MAC = "
393  << request_.mac_addr.ToString());
394  return true;
395  }
396 
397  // For VM interfaces in default VRF, if the config doesnt have IP address,
398  // send the request to fabric
399  if (dhcp_proto->dhcp_relay_mode() &&
400  vm_itf_->vrf() && vm_itf_->do_dhcp_relay()) {
402  return true;
403  }
404 
405  if (!ReadOptions(options_len))
406  return true;
407 
408  switch (msg_type_) {
409  case DHCP_DISCOVER:
411  dhcp_proto->IncrStatsDiscover();
412  DHCP_TRACE(Trace, "DHCP discover received on interface : "
413  << vm_itf_->name() << " Mac : " <<
415  break;
416 
417  case DHCP_REQUEST:
419  dhcp_proto->IncrStatsRequest();
420  DHCP_TRACE(Trace, "DHCP request received on interface : "
421  << vm_itf_->name() << " Mac : " <<
423  break;
424 
425  case DHCP_INFORM:
427  dhcp_proto->IncrStatsInform();
428  DHCP_TRACE(Trace, "DHCP inform received on interface : "
429  << vm_itf_->name() << " Mac : " <<
431  break;
432 
433  case DHCP_DECLINE:
434  dhcp_proto->IncrStatsDecline();
435  DHCP_TRACE(Error, "DHCP Client declined the offer : vrf = " <<
436  pkt_info_->vrf << " ifindex = " << GetInterfaceIndex() <<
437  " Mac : " << request_.mac_addr.ToString());
440  }
441  return true;
442 
443  case DHCP_RELEASE:
444  DHCP_TRACE(Error, "DHCP lease released : vrf = " <<
445  pkt_info_->vrf << " ifindex = " << GetInterfaceIndex() <<
446  " Mac : " << request_.mac_addr.ToString());
449  }
450  dhcp_proto->IncrStatsRelease();
451  return true;
452 
453  case DHCP_ACK:
454  case DHCP_NAK:
455  case DHCP_LEASE_QUERY:
457  case DHCP_LEASE_UNKNOWN:
458  case DHCP_LEASE_ACTIVE:
459  default:
461  " received on interface : " << vm_itf_->name() <<
462  " Mac : " << request_.mac_addr.ToString() <<
463  "; ignoring");
464  dhcp_proto->IncrStatsOther();
465  return true;
466  }
467 
468  if (FindLeaseData()) {
470  DHCP_TRACE(Trace, "DHCP response sent; message = " <<
472  "; ip = " << config_.ip_addr.to_string());
473  }
474 
475  return true;
476 }
477 
479  switch (pkt_info_->ipc->cmd) {
481  // DHCP message from DHCP server port that we listen on
482  if (agent()->GetDhcpProto()->dhcp_relay_mode())
483  return HandleDhcpFromFabric();
484 
485  default:
487  assert(0);
488  }
489 
490  return true;
491 }
492 
493 // Handle any DHCP response coming from fabric for a request that we relayed
495  DhcpProto::DhcpVhostMsg *ipc = static_cast<DhcpProto::DhcpVhostMsg *>(pkt_info_->ipc);
496  pkt_info_->len = ipc->len;
497  dhcp_ = reinterpret_cast<dhcphdr *>(ipc->pkt);
498  option_->SetDhcpOptionPtr(dhcp_->options);
500 
501  int16_t options_len = ipc->len - DHCP_FIXED_LEN;
502  if (ReadOptions(options_len) && vm_itf_ &&
504  // this is a DHCP relay response for our request
506  }
507 
508  delete ipc;
509  return true;
510 }
511 
512 // read DHCP options in the incoming packet
513 bool DhcpHandler::ReadOptions(int16_t opt_rem_len) {
514  // verify magic cookie
515  if ((opt_rem_len < 4) ||
516  memcmp(dhcp_->options, DHCP_OPTIONS_COOKIE, 4)) {
518  DHCP_TRACE(Error, "DHCP options cookie missing; vrf = " <<
519  pkt_info_->vrf << " ifindex = " << GetInterfaceIndex());
520  return false;
521  }
522 
523  opt_rem_len -= 4;
524  Dhcpv4Options *opt = (Dhcpv4Options *)(dhcp_->options + 4);
525  // parse thru the option fields
526  while ((opt_rem_len > 0) && (opt->code != DHCP_OPTION_END)) {
527  switch (opt->code) {
528  case DHCP_OPTION_PAD:
529  opt_rem_len -= 1;
530  opt = (Dhcpv4Options *)((uint8_t *)opt + 1);
531  continue;
532 
534  if (opt_rem_len >= opt->len + 2)
535  msg_type_ = *(uint8_t *)opt->data;
536  break;
537 
539  if (opt_rem_len >= opt->len + 2) {
540  union {
541  uint8_t data[sizeof(in_addr_t)];
542  in_addr_t addr;
543  } bytes;
544  memcpy(bytes.data, opt->data, sizeof(in_addr_t));
545  request_.ip_addr = ntohl(bytes.addr);
546  }
547  break;
548 
550  if (opt_rem_len >= opt->len + 2)
551  config_.client_name_.assign((char *)opt->data, opt->len);
552  break;
553 
555  if (opt_rem_len >= opt->len + 2)
556  config_.domain_name_.assign((char *)opt->data, opt->len);
557  break;
558 
560  if (opt_rem_len >= opt->len + 2)
561  parameters_.assign((char *)opt->data, opt->len);
562  break;
563 
564  case DHCP_OPTION_82:
565  ReadOption82(opt);
566  break;
567 
568  default:
569  break;
570  }
571  opt_rem_len -= (2 + opt->len);
572  opt = (Dhcpv4Options *)((uint8_t *)opt + 2 + opt->len);
573  }
574 
575  return true;
576 }
577 
579  Ip4Address &gw, Ip4Address &dns) {
580  config_.ip_addr = addr;
581  config_.plen = plen;
582  uint32_t mask = plen? (0xFFFFFFFF << (32 - plen)) : 0;
583  config_.subnet_mask = mask;
584  config_.bcast_addr = (addr.to_ulong() & mask) | ~mask;
585  config_.gw_addr = gw;
586  config_.dns_addr = dns;
587 }
588 
589 
591  DhcpLeaseDb *dhcp_lease_db = agent()->GetDhcpProto()->GetLeaseDb(vm_itf_);
592  if (dhcp_lease_db) {
593  Ip4Address ip;
594  const VnIpam *vn_ipam = (vm_itf_->vn()) ?
595  vm_itf_->vn()->GetIpam(IpAddress(vm_itf_->subnet())) : NULL;
596  if (!vn_ipam || !dhcp_lease_db->Allocate(request_.mac_addr, &ip,
599  DHCP_TRACE(Error, "DHCP request from Gateway interface failed :"
600  " could not allocate IP address for Mac : " <<
601  request_.mac_addr.ToString() << " on VMI : " <<
602  vm_itf_->name());
603  return false;
604  }
606  Ip4Address gw = vn_ipam->default_gw.to_v4();
607  Ip4Address dns = vn_ipam->dns_server.to_v4();
608  FillDhcpInfo(ip, dhcp_lease_db->plen(), gw, dns);
609  return true;
610  }
611 
612  DHCP_TRACE(Error, "DHCP request on VMI " << vm_itf_->name() <<
613  " could not be served - DHCP lease db is not created");
614  return false;
615 }
616 
618  DhcpLeaseDb *dhcp_lease_db = agent()->GetDhcpProto()->GetLeaseDb(vm_itf_);
619  if (!dhcp_lease_db || !dhcp_lease_db->Release(request_.mac_addr)) {
621  DHCP_TRACE(Error, "DHCP lease release failed : vrf = " <<
622  pkt_info_->vrf << " ifindex = " << GetInterfaceIndex() <<
623  " Mac : " << request_.mac_addr.ToString());
624  }
625 }
626 
628  Ip4Address unspecified;
630  // Change client name to VM name; this is the name assigned to the VM
632  FindDomainName(ip);
634  // if the request is from a Gateway interface, get an address from the
635  // relevant subnet
637  return GetGatewayInterfaceLease();
638  }
639 
640  if (vm_itf_->fabric_port()) {
643  vm_itf_->vrf()->GetName(), ip);
644  if (rt) {
646  boost::system::error_code ec;
647  if (IsIp4SubnetMember(rt->prefix_address().to_v4(),
648  Ip4Address::from_string("169.254.0.0", ec), rt->prefix_length())) {
649  gw = unspecified;
650  }
651  FillDhcpInfo(ip, rt->prefix_length(), gw, gw);
652  return true;
653  }
655  DHCP_TRACE(Error, "DHCP fabric port request failed : "
656  "could not find route for " << ip.to_string());
657  return false;
658  }
659 
660  const std::vector<VnIpam> &ipam = vm_itf_->vn()->GetVnIpam();
661  unsigned int i;
662  for (i = 0; i < ipam.size(); ++i) {
663  if (!ipam[i].IsV4()) {
664  continue;
665  }
666  if (IsIp4SubnetMember(ip, ipam[i].ip_prefix.to_v4(),
667  ipam[i].plen)) {
668  Ip4Address default_gw = ipam[i].default_gw.to_v4();
669  Ip4Address service_address = ipam[i].dns_server.to_v4();
670  if (service_address.is_unspecified())
671  service_address = default_gw;
672  FillDhcpInfo(ip, ipam[i].plen, default_gw, service_address);
673  return true;
674  }
675  }
676  }
677 
678  // We dont have the config yet; give a short lease
680  if (ip.to_ulong()) {
681  // Give address received from Nova
682  FillDhcpInfo(ip, 32, unspecified, unspecified);
683  } else {
684  // Give a link local address
685  boost::system::error_code ec;
686  Ip4Address gwip = Ip4Address::from_string
687  (agent()->v4_link_local_subnet(), ec);
688  gwip = Ip4Address((gwip.to_ulong() & 0xFFFF0000) | (vm_itf_->id() & 0xFF));
689  FillDhcpInfo(gwip, 16, unspecified, unspecified);
690  }
691  return true;
692 }
693 
694 void DhcpHandler::WriteOption82(Dhcpv4Options *opt, uint16_t *optlen) {
695  *optlen += 2;
696  opt->code = DHCP_OPTION_82;
697  opt->len = sizeof(uint32_t) + 2 + sizeof(VmInterface *) + 2;
698  Dhcpv4Options *subopt = reinterpret_cast<Dhcpv4Options *>(opt->data);
699  uint32_t value = htonl(vm_itf_->id());
700  subopt->WriteData(DHCP_SUBOP_CKTID, 4, &value, optlen);
701  subopt = subopt->GetNextOptionPtr();
702  subopt->WriteData(DHCP_SUBOP_REMOTEID, sizeof(VmInterface *),
703  &vm_itf_, optlen);
704 }
705 
707  if (opt->len != sizeof(uint32_t) + 2 + sizeof(VmInterface *) + 2)
708  return false;
709 
710  Dhcpv4Options *subopt = reinterpret_cast<Dhcpv4Options *>(opt->data);
711  for (int i = 0; i < 2; i++) {
712  switch (subopt->code) {
713  case DHCP_SUBOP_CKTID:
714  if (subopt->len != sizeof(uint32_t))
715  return false;
716  union {
717  uint8_t data[sizeof(uint32_t)];
718  uint32_t index;
719  } bytes;
720 
721  memcpy(bytes.data, subopt->data, sizeof(uint32_t));
722  vm_itf_index_ = ntohl(bytes.index);
723  break;
724 
725  case DHCP_SUBOP_REMOTEID:
726  if (subopt->len != sizeof(VmInterface *))
727  return false;
728  memcpy(&vm_itf_, subopt->data, subopt->len);
729  break;
730 
731  default:
732  return false;
733  }
734  subopt = subopt->GetNextOptionPtr();
735  }
736 
737  return true;
738 }
739 
741  PktInfo in_pkt_info = *pkt_info_.get();
742 
743  pkt_info_->AllocPacketBuffer(agent(), PktHandler::DHCP, DHCP_PKT_SIZE, 0);
744  memset(pkt_info_->pkt, 0, DHCP_PKT_SIZE);
745  pkt_info_->vrf = in_pkt_info.vrf;
746  pkt_info_->eth = (struct ether_header *)(pkt_info_->pkt);
747  int eth_len = 0;
748  eth_len = EthHdr((char *)pkt_info_->eth, DHCP_PKT_SIZE,
749  agent()->GetDhcpProto()->ip_fabric_interface_index(),
750  agent()->GetDhcpProto()->ip_fabric_interface_mac(),
751  MacAddress(in_pkt_info.eth->ether_dhost), ETHERTYPE_IP);
752 
753  pkt_info_->ip = (struct ip *)((char *)pkt_info_->eth + eth_len);
754  pkt_info_->transp.udp = (udphdr *)(pkt_info_->ip + 1);
755  dhcphdr *dhcp = (dhcphdr *)(pkt_info_->transp.udp + 1);
756 
757  memcpy((uint8_t *)dhcp, (uint8_t *)dhcp_, DHCP_FIXED_LEN);
758  memcpy(dhcp->options, DHCP_OPTIONS_COOKIE, 4);
759 
760  int16_t opt_rem_len = in_pkt_info.len - eth_len - sizeof(struct ip)
761  - sizeof(udphdr) - DHCP_FIXED_LEN - 4;
762  uint16_t opt_len = 4;
763  Dhcpv4Options *read_opt = (Dhcpv4Options *)(dhcp_->options + 4);
764  Dhcpv4Options *write_opt = (Dhcpv4Options *)(dhcp->options + 4);
765  while ((opt_rem_len > 0) && (read_opt->code != DHCP_OPTION_END)) {
766  switch (read_opt->code) {
767  case DHCP_OPTION_PAD:
768  write_opt->WriteByte(DHCP_OPTION_PAD, &opt_len);
769  write_opt = write_opt->GetNextOptionPtr();
770  opt_rem_len -= 1;
771  read_opt = read_opt->GetNextOptionPtr();
772  continue;
773 
774  case DHCP_OPTION_82:
775  break;
776 
778  msg_type_ = *(uint8_t *)read_opt->data;
779  write_opt->WriteData(read_opt->code, read_opt->len, &msg_type_, &opt_len);
780  write_opt = write_opt->GetNextOptionPtr();
781  break;
782 
785  write_opt->WriteData(DHCP_OPTION_HOST_NAME,
786  config_.client_name_.size(),
787  config_.client_name_.c_str(), &opt_len);
788  write_opt = write_opt->GetNextOptionPtr();
789  break;
790 
791  default:
792  write_opt->WriteData(read_opt->code, read_opt->len, &read_opt->data, &opt_len);
793  write_opt = write_opt->GetNextOptionPtr();
794  break;
795 
796  }
797  opt_rem_len -= (2 + read_opt->len);
798  read_opt = read_opt->GetNextOptionPtr();
799  }
800  dhcp_ = dhcp;
801  option_->SetDhcpOptionPtr(dhcp_->options);
802  dhcp->giaddr = htonl(agent()->router_id().to_ulong());
803  WriteOption82(write_opt, &opt_len);
804  write_opt = write_opt->GetNextOptionPtr();
805  pkt_info_->sport = DHCP_SERVER_PORT;
806  pkt_info_->dport = DHCP_SERVER_PORT;
807  write_opt->WriteByte(DHCP_OPTION_END, &opt_len);
808 
809  uint32_t len = DHCP_FIXED_LEN + opt_len + eth_len + sizeof(udphdr);
810 
811  UdpHdr(len, in_pkt_info.ip->ip_src.s_addr, pkt_info_->sport,
812  in_pkt_info.ip->ip_dst.s_addr, pkt_info_->dport);
813  len += sizeof(struct ip);
814  IpHdr(len, htonl(agent()->router_id().to_ulong()),
815  0xFFFFFFFF, IPPROTO_UDP, DEFAULT_IP_ID, DEFAULT_IP_TTL);
816 
817  pkt_info_->set_len(len);
818  return true;
819 }
820 
822  PktInfo in_pkt_info = *pkt_info_.get();
823  pkt_info_->AllocPacketBuffer(agent(), PktHandler::DHCP, DHCP_PKT_SIZE, 0);
824  memset(pkt_info_->pkt, 0, DHCP_PKT_SIZE);
825  pkt_info_->vrf = vm_itf_->vrf()->vrf_id();
826  pkt_info_->eth = (struct ether_header *)(pkt_info_->pkt);
827 
828  uint16_t eth_len = 0;
829  eth_len = EthHdr((char *)pkt_info_->eth, DHCP_PKT_SIZE, vm_itf_index_,
830  agent()->vhost_interface()->mac(),
831  MacAddress(dhcp_->chaddr), ETHERTYPE_IP);
832 
833  pkt_info_->ip = (struct ip *)((char *)pkt_info_->eth + eth_len);
834  pkt_info_->transp.udp = (udphdr *)(pkt_info_->ip + 1);
835  dhcphdr *dhcp = (dhcphdr *)(pkt_info_->transp.udp + 1);
836 
837  memcpy((uint8_t *)dhcp, (uint8_t *)dhcp_, DHCP_FIXED_LEN);
838  memcpy(dhcp->options, DHCP_OPTIONS_COOKIE, 4);
839 
840  int16_t opt_rem_len = in_pkt_info.len - DHCP_FIXED_LEN - 4;
841  uint16_t opt_len = 4;
842  Dhcpv4Options *read_opt = (Dhcpv4Options *)(dhcp_->options + 4);
843  Dhcpv4Options *write_opt = (Dhcpv4Options *)(dhcp->options + 4);
844  while ((opt_rem_len > 0) && (read_opt->code != DHCP_OPTION_END)) {
845  switch (read_opt->code) {
846  case DHCP_OPTION_PAD:
847  write_opt->WriteByte(DHCP_OPTION_PAD, &opt_len);
848  write_opt = write_opt->GetNextOptionPtr();
849  opt_rem_len -= 1;
850  read_opt = read_opt->GetNextOptionPtr();
851  continue;
852 
853  case DHCP_OPTION_82:
854  break;
855 
857  msg_type_ = *(uint8_t *)read_opt->data;
858  write_opt->WriteData(read_opt->code, read_opt->len, &msg_type_, &opt_len);
859  write_opt = write_opt->GetNextOptionPtr();
860  break;
861 
862  default:
863  write_opt->WriteData(read_opt->code, read_opt->len, &read_opt->data, &opt_len);
864  write_opt = write_opt->GetNextOptionPtr();
865  break;
866 
867  }
868  opt_rem_len -= (2 + read_opt->len);
869  read_opt = read_opt->GetNextOptionPtr();
870  }
871  dhcp_ = dhcp;
872  option_->SetDhcpOptionPtr(dhcp_->options);
873  dhcp->giaddr = 0;
876  config_.client_name_.c_str(), &opt_len);
877  write_opt = write_opt->GetNextOptionPtr();
878  pkt_info_->sport = DHCP_SERVER_PORT;
879  pkt_info_->dport = DHCP_CLIENT_PORT;
880  write_opt->WriteByte(DHCP_OPTION_END, &opt_len);
881 
882  uint32_t len = DHCP_FIXED_LEN + opt_len + sizeof(udphdr) + eth_len;
883 
884  UdpHdr(len, agent()->router_id().to_ulong(), pkt_info_->sport,
885  0xFFFFFFFF, pkt_info_->dport);
886  len += sizeof(struct ip);
887  IpHdr(len, htonl(agent()->router_id().to_ulong()),
888  0xFFFFFFFF, IPPROTO_UDP, DEFAULT_IP_ID, DEFAULT_IP_TTL);
889 
890  pkt_info_->set_len(len);
891  return true;
892 }
893 
896  DhcpProto *dhcp_proto = agent()->GetDhcpProto();
897  Send(dhcp_proto->ip_fabric_interface_index(), pkt_info_->vrf,
899  dhcp_proto->IncrStatsRelayReqs();
900 }
901 
903  if (!CreateRelayResponsePacket()) {
904  DHCP_TRACE(Trace, "Ignoring received DHCP packet from fabric interface");
905  return;
906  }
907 
908  if (msg_type_ == DHCP_ACK) {
909  // Populate the DHCP Snoop table
911  (vm_itf_->name(), Ip4Address(ntohl(dhcp_->yiaddr)));
912  // Enqueue RESYNC to update the IP address
915  vm_itf_->name()));
916  req.data.reset(new VmInterfaceIpAddressData());
917  agent()->interface_table()->Enqueue(&req);
918  }
919 
922 }
923 
924 // Add an IP address to the option
925 uint16_t DhcpHandler::AddIP(uint16_t opt_len, const std::string &input) {
926  boost::system::error_code ec;
927  uint32_t ip = Ip4Address::from_string(input, ec).to_ulong();
928  if (!ec.value() && ip) {
929  ip = htonl(ip);
930  option_->AppendData(4, &ip, &opt_len);
931  } else {
932  DHCP_TRACE(Error, "Invalid DHCP option " << option_->GetCode() <<
933  " data : " << input << " for VM " <<
934  config_.ip_addr.to_string() << "; has to be IP address");
935  }
936  return opt_len;
937 }
938 
939 // Add domain name from IPAM to the option
940 uint16_t DhcpHandler::AddDomainNameOption(uint16_t opt_len) {
941  if (ipam_type_.ipam_dns_method == "virtual-dns-server") {
942  if (is_dns_enabled() && config_.domain_name_.size()) {
943  option_->WriteData(DHCP_OPTION_DOMAIN_NAME, 0, NULL, &opt_len);
944  option_->AppendData(config_.domain_name_.size(),
945  config_.domain_name_.c_str(), &opt_len);
946  }
947  }
948  return opt_len;
949 }
950 
951 uint16_t DhcpHandler::DhcpHdr(in_addr_t yiaddr, in_addr_t siaddr) {
952  dhcp_->op = BOOT_REPLY;
954  dhcp_->hlen = ETHER_ADDR_LEN;
955  dhcp_->hops = 0;
956  dhcp_->xid = request_.xid;
957  dhcp_->secs = 0;
958  dhcp_->flags = htons(request_.flags);
959  dhcp_->ciaddr = 0;
960  dhcp_->yiaddr = yiaddr;
961  dhcp_->siaddr = siaddr;
962  dhcp_->giaddr = 0;
963  memset (dhcp_->chaddr, 0, DHCP_CHADDR_LEN);
964  request_.mac_addr.ToArray(dhcp_->chaddr, ETHER_ADDR_LEN);
965  // not supporting dhcp_->sname, dhcp_->file for now
966  memset(dhcp_->sname, '\0', DHCP_NAME_LEN);
967  memset(dhcp_->file, '\0', DHCP_FILE_LEN);
968 
969  memcpy(dhcp_->options, DHCP_OPTIONS_COOKIE, 4);
970 
971  uint16_t opt_len = 4;
972  option_->SetNextOptionPtr(opt_len);
973  option_->WriteData(DHCP_OPTION_MSG_TYPE, 1, &out_msg_type_, &opt_len);
974 
975  option_->SetNextOptionPtr(opt_len);
976  option_->WriteData(DHCP_OPTION_SERVER_IDENTIFIER, 4, &siaddr, &opt_len);
977 
978  if (out_msg_type_ == DHCP_NAK) {
979  option_->SetNextOptionPtr(opt_len);
980  option_->WriteData(DHCP_OPTION_MESSAGE, nak_msg_.size(),
981  nak_msg_.data(), &opt_len);
982  }
983  else {
984 
985  if (config_.subnet_mask) {
986  option_->SetNextOptionPtr(opt_len);
987  uint32_t value = htonl(config_.subnet_mask);
988  option_->WriteData(DHCP_OPTION_SUBNET_MASK, 4, &value, &opt_len);
989  }
990 
991  if (config_.bcast_addr) {
992  option_->SetNextOptionPtr(opt_len);
993  uint32_t value = htonl(config_.bcast_addr);
994  option_->WriteData(DHCP_OPTION_BCAST_ADDRESS, 4, &value, &opt_len);
995  }
996 
997  // Add dhcp options coming from Config
998  opt_len = AddConfigDhcpOptions(opt_len, false);
999 
1000  if (msg_type_ != DHCP_INFORM &&
1002  option_->SetNextOptionPtr(opt_len);
1003  uint32_t value = htonl(config_.lease_time);
1004  option_->WriteData(DHCP_OPTION_IP_LEASE_TIME, 4, &value, &opt_len);
1005  }
1006 
1007  // Add classless route option
1008  option_->SetNextOptionPtr(opt_len);
1009  opt_len = AddClasslessRouteOption(opt_len);
1010 
1011  if (IsRouterOptionNeeded()) {
1012  option_->SetNextOptionPtr(opt_len);
1013  opt_len = AddIpv4Option(DHCP_OPTION_ROUTER, opt_len,
1014  routers_, 1, 0, 0);
1015  }
1016 
1018  config_.client_name_.size()) {
1019  option_->SetNextOptionPtr(opt_len);
1021  config_.client_name_.c_str(), &opt_len);
1022  }
1023 
1024  if (!is_flag_set(DHCP_OPTION_DNS)) {
1025  uint16_t old_opt_len = opt_len;
1026  option_->SetNextOptionPtr(opt_len);
1027  option_->WriteData(DHCP_OPTION_DNS, 0, NULL, &opt_len);
1028  opt_len = AddDnsServers(opt_len);
1029  // if there was no DNS server, revert the option
1030  if (opt_len == old_opt_len + option_->GetFixedLen())
1031  opt_len = old_opt_len;
1032  }
1033 
1035  option_->SetNextOptionPtr(opt_len);
1036  opt_len = AddDomainNameOption(opt_len);
1037  }
1038 
1039  // update dhcp siaddr with stored value
1042  }
1043  }
1044 
1045  option_->SetNextOptionPtr(opt_len);
1046  option_->SetCode(DHCP_OPTION_END);
1047  opt_len += 1;
1048 
1049  return (DHCP_FIXED_LEN + opt_len);
1050 }
1051 
1053  in_addr_t src_ip, in_addr_t dest_ip,
1054  in_addr_t siaddr, in_addr_t yiaddr) {
1055  pkt_info_->eth = (struct ether_header *)(pkt_info_->pkt);
1056 
1057  uint16_t eth_len = 0;
1058  eth_len = EthHdr((char *)pkt_info_->eth,
1059  pkt_info_->packet_buffer()->data_len(),
1061  agent()->vhost_interface()->mac(), dest_mac, ETHERTYPE_IP);
1062 
1063  pkt_info_->ip = (struct ip *)((char *)pkt_info_->eth + eth_len);
1064  pkt_info_->transp.udp = (udphdr *)(pkt_info_->ip + 1);
1065  dhcphdr *dhcp = (dhcphdr *)(pkt_info_->transp.udp + 1);
1066  dhcp_ = dhcp;
1067  option_->SetDhcpOptionPtr(dhcp_->options);
1068 
1069  uint16_t len = DhcpHdr(yiaddr, siaddr);
1070  len += sizeof(udphdr);
1071  UdpHdr(len, src_ip, DHCP_SERVER_PORT, dest_ip, DHCP_CLIENT_PORT);
1072  len += sizeof(struct ip);
1073  IpHdr(len, src_ip, dest_ip, IPPROTO_UDP, DEFAULT_IP_ID, DEFAULT_IP_TTL);
1074 
1075  pkt_info_->set_len(len + eth_len);
1076  return pkt_info_->packet_buffer()->data_len();
1077 }
1078 
1080  // TODO: If giaddr is set, what to do ?
1081 
1082  // In TSN, the source address for DHCP response should be the address
1083  // in the subnet reserved for service node. Otherwise, it will be the
1084  // GW address. dns_addr field has this address, use it as the source IP.
1085  in_addr_t src_ip = htonl(config_.dns_addr.to_v4().to_ulong());
1086  in_addr_t dest_ip = 0xFFFFFFFF;
1087  in_addr_t yiaddr = htonl(config_.ip_addr.to_v4().to_ulong());
1088  in_addr_t siaddr = src_ip;
1089  MacAddress dest_mac = MacAddress::BroadcastMac();
1090 
1091  // If requested IP address is not available, send NAK
1092  if ((msg_type_ == DHCP_REQUEST) && (request_.ip_addr) &&
1093  (config_.ip_addr.to_v4().to_ulong() != request_.ip_addr)) {
1095  yiaddr = 0;
1096  siaddr = 0;
1097  }
1098 
1099  // send a unicast response when responding to INFORM
1100  // or when incoming giaddr is zero and ciaddr is set
1101  // or when incoming bcast flag is not set (with giaddr & ciaddr being zero)
1102  if ((msg_type_ == DHCP_INFORM) ||
1103  (!dhcp_->giaddr && (dhcp_->ciaddr ||
1104  !(request_.flags & DHCP_BCAST_FLAG)))) {
1105  dest_ip = yiaddr;
1106  dest_mac = dhcp_->chaddr;
1107  if (msg_type_ == DHCP_INFORM)
1108  yiaddr = 0;
1109  }
1110 
1111  UpdateStats();
1112 
1113  FillDhcpResponse(dest_mac, src_ip, dest_ip, siaddr, yiaddr);
1114  uint32_t interface =
1115  (pkt_info_->agent_hdr.cmd == AgentHdr::TRAP_TOR_CONTROL_PKT) ?
1117  uint16_t command =
1118  (pkt_info_->agent_hdr.cmd == AgentHdr::TRAP_TOR_CONTROL_PKT) ?
1120  Send(interface, pkt_info_->vrf, command, PktHandler::DHCP);
1121 }
1122 
1123 // Check if the option is requested by the client or not
1124 bool DhcpHandler::IsOptionRequested(uint8_t option) {
1125  for (uint32_t i = 0; i < parameters_.size(); i++) {
1126  if (parameters_[i] == option)
1127  return true;
1128  }
1129  return false;
1130 }
1131 
1133  // If GW is not configured, dont include
1134  if (config_.gw_addr.is_unspecified() && routers_.empty())
1135  return false;
1136 
1137  // When client requests Classless Static Routes option and this is
1138  // included in the response, Router option is not included (RFC3442)
1141  return false;
1142 
1143  return true;
1144 }
1145 
1147  DhcpProto *dhcp_proto = agent()->GetDhcpProto();
1148  (out_msg_type_ == DHCP_OFFER) ? dhcp_proto->IncrStatsOffers() :
1149  ((out_msg_type_ == DHCP_ACK) ? dhcp_proto->IncrStatsAcks() :
1150  dhcp_proto->IncrStatsNacks());
1151 }
1152 
1154 DhcpHandler::OptionCategory(uint32_t option) const {
1155  Dhcpv4CategoryIter iter = g_dhcpv4_category_map.find(option);
1156  if (iter == g_dhcpv4_category_map.end())
1157  return None;
1158  return iter->second;
1159 }
1160 
1161 uint32_t DhcpHandler::OptionCode(const std::string &option) const {
1162  // if the option name is a number, use it as DHCP code
1163  // otherwise, use it as option name
1164  std::stringstream str(option);
1165 
1166  uint32_t code = 0;
1167  str >> code;
1168  if (code) return code;
1169 
1170  Dhcpv4NameCodeIter iter =
1171  g_dhcpv4_namecode_map.find(boost::to_lower_copy(option));
1172 
1173  if(iter != g_dhcpv4_namecode_map.end()){
1174  return iter->second;
1175  }
1176 
1177  std::stringstream str_new(option);
1178  //Checking if there is comma in the option
1179  bool is_delimeter_set = false;
1180  while(!(str_new.eof())){
1181  str_new.get();
1182  if (str_new.peek() == ','){
1183  is_delimeter_set = true;
1184  }
1185  }
1186  std::stringstream str_orig(option);
1187  //If option name has a comma in it,
1188  //eg: tag:!ipxe,67 , we should pick 67
1189  if(is_delimeter_set){
1190  vector<string> v;
1191  while (str_orig.good()) {
1192  string substr;
1193  getline(str_orig, substr, ',');
1194  v.push_back(substr);
1195  }
1196  std::stringstream str_temp(v[1]);
1197  str_temp >> code;
1198  }
1199 
1200  return code;
1201 }
1202 
1203 
1204 void DhcpHandler::DhcpTrace(const std::string &msg) const {
1205  DHCP_TRACE(Error, "VM " << config_.ip_addr.to_string() << " : " << msg);
1206 }
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
Definition: address_util.cc:20
virtual const PrefixType & prefix_address() const
Returns the value of a stored prefix address (IPv4, IPv6 or MAC address)
Definition: agent_route.h:390
Definition: agent.h:361
InterfaceTable * interface_table() const
Definition: agent.h:468
AddressList vhost_default_gateway() const
Definition: agent.h:659
DhcpProto * GetDhcpProto() const
Definition: agent.h:984
bool Enqueue(DBRequest *req)
Definition: db_table.cc:221
uint16_t AddClasslessRouteOption(uint16_t opt_len)
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 AddDnsServers(uint16_t opt_len)
void FindDomainName(const IpAddress &vm_addr)
ConfigRecord config_
std::string routers_
VmInterface * vm_itf_
bool is_dns_enabled() const
uint16_t AddConfigDhcpOptions(uint16_t opt_len, bool is_v6)
bool is_flag_set(uint8_t flag) const
boost::scoped_ptr< DhcpOptionHandler > option_
autogen::IpamType ipam_type_
bool CreateRelayResponsePacket()
void RelayRequestToFabric()
uint8_t msg_type_
Definition: dhcp_handler.h:346
bool CreateRelayPacket()
void RelayResponseFromFabric()
void SendDhcpResponse()
bool ReadOption82(Dhcpv4Options *opt)
std::string parameters_
Definition: dhcp_handler.h:349
std::string nak_msg_
Definition: dhcp_handler.h:350
void UpdateStats()
dhcphdr * dhcp_
Definition: dhcp_handler.h:345
bool HandleVmRequest()
void ReleaseGatewayInterfaceLease()
bool ReadOptions(int16_t opt_rem_len)
uint16_t FillDhcpResponse(const MacAddress &dest_mac, in_addr_t src_ip, in_addr_t dest_ip, in_addr_t siaddr, in_addr_t yiaddr)
bool HandleMessage()
DhcpHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
void FillDhcpInfo(Ip4Address &addr, int plen, Ip4Address &gw, Ip4Address &dns)
bool HandleDhcpFromFabric()
bool IsRouterOptionNeeded()
uint16_t AddIP(uint16_t opt_len, const std::string &input)
DhcpHandler::DhcpOptionCategory OptionCategory(uint32_t option) const
void WriteOption82(Dhcpv4Options *opt, uint16_t *optlen)
uint8_t out_msg_type_
Definition: dhcp_handler.h:347
bool GetGatewayInterfaceLease()
void DhcpTrace(const std::string &msg) const
virtual ~DhcpHandler()
uint16_t AddDomainNameOption(uint16_t opt_len)
uint32_t OptionCode(const std::string &option) const
bool FindLeaseData()
bool IsOptionRequested(uint8_t option)
uint16_t DhcpHdr(in_addr_t, in_addr_t)
DhcpRequestData request_
Definition: dhcp_handler.h:351
bool Release(const MacAddress &mac)
bool Allocate(const MacAddress &mac, Ip4Address *address, uint64_t lease)
uint8_t plen() const
Definition: dhcp_lease_db.h:67
void IncrDhcpDisabledDrops()
Definition: dhcp_proto.h:115
void IncrIncorrectMac()
Definition: dhcp_proto.h:116
void IncrStatsOffers()
Definition: dhcp_proto.h:108
void IncrStatsRelease()
Definition: dhcp_proto.h:106
void IncrStatsOther()
Definition: dhcp_proto.h:107
bool dhcp_relay_mode() const
Definition: dhcp_proto.h:77
void IncrStatsRelayReqs()
Definition: dhcp_proto.h:111
void IncrStatsDiscover()
Definition: dhcp_proto.h:102
void IncrStatsAcks()
Definition: dhcp_proto.h:109
void IncrStatsRelayResps()
Definition: dhcp_proto.h:112
uint32_t pkt_interface_index() const
Definition: dhcp_proto.h:88
void IncrUnknownMsgDrops()
Definition: dhcp_proto.h:114
void IncrStatsInform()
Definition: dhcp_proto.h:104
void IncrStatsNacks()
Definition: dhcp_proto.h:110
@ DHCP_VHOST_MSG
Definition: dhcp_proto.h:30
DhcpLeaseDb * GetLeaseDb(Interface *intrface)
Definition: dhcp_proto.cc:227
void IncrStatsRequest()
Definition: dhcp_proto.h:103
void IncrStatsDecline()
Definition: dhcp_proto.h:105
void IncrStatsErrors()
Definition: dhcp_proto.h:113
uint32_t ip_fabric_interface_index() const
Definition: dhcp_proto.h:82
InetUnicastRouteEntry * FindResolveRoute(const Ip4Address &ip)
uint8_t prefix_length() const
!
const Interface * FindInterface(size_t index) const
Definition: interface.cc:323
void AddDhcpSnoopEntry(const std::string &ifname, const Ip4Address &addr)
Definition: interface.cc:750
@ VM_INTERFACE
Definition: interface.h:38
VrfEntry * vrf() const
Definition: interface.h:118
const std::string & name() const
Definition: interface.h:117
const boost::uuids::uuid & GetUuid() const
Definition: interface.h:116
Type type() const
Definition: interface.h:115
const uint32_t id() const
Definition: interface.h:126
std::string ToString() const
Definition: mac_address.cc:54
static const MacAddress & BroadcastMac()
Definition: mac_address.h:153
bool ToArray(u_int8_t *p, size_t s) const
Definition: mac_address.cc:94
Agent * agent() const
Definition: proto_handler.h:81
void Send(uint32_t itf, uint32_t vrf, uint16_t, PktHandler::PktModuleName)
void IpHdr(uint16_t len, in_addr_t src, in_addr_t dest, uint8_t protocol, uint16_t id, uint8_t ttl)
void UdpHdr(uint16_t len, in_addr_t src, uint16_t src_port, in_addr_t dest, uint16_t dest_port)
int EthHdr(const MacAddress &src, const MacAddress &dest, const uint16_t proto)
Agent * agent_
Definition: proto_handler.h:92
boost::shared_ptr< PktInfo > pkt_info_
Definition: proto_handler.h:93
uint32_t GetInterfaceIndex() const
Definition: proto_handler.h:83
static std::string & DhcpMsgType(uint32_t msg_type)
Definition: trace.h:289
VmInterface::VmiType vmi_type() const
bool IsActive() const
bool do_dhcp_relay() const
const MacAddress & vm_mac() const
VmInterface::DeviceType device_type() const
const VnEntry * vn() const
bool dhcp_enable_config() const
const Ip4Address & primary_ip_addr() const
const Ip4Address & subnet() const
const std::string & vm_name() const
bool fabric_port() const
const std::vector< VnIpam > & GetVnIpam() const
Definition: vn.h:172
const VnIpam * GetIpam(const IpAddress &ip) const
Definition: vn.cc:653
const string & GetName() const
Definition: vrf.h:104
const uint32_t vrf_id() const
Definition: vrf.h:103
Dhcpv4NameCodeMap g_dhcpv4_namecode_map
Definition: dhcp_handler.cc:27
Dhcpv4CategoryMap g_dhcpv4_category_map
#define DHCP_OPTION_MOBILE_IP_HA
Definition: dhcp_handler.h:85
#define DHCP_OPTION_DEFAULT_WWW_SERVER
Definition: dhcp_handler.h:89
#define DHCP_OPTION_ETHERNET_ENCAP
Definition: dhcp_handler.h:53
#define DHCP_OPTION_LOG_SERVER
Definition: dhcp_handler.h:24
std::map< uint32_t, DhcpHandler::DhcpOptionCategory >::const_iterator Dhcpv4CategoryIter
Definition: dhcp_handler.h:358
#define DHCP_OPTION_PXE_VENDOR_SPECIFIC_133
Definition: dhcp_handler.h:140
#define DHCP_OPTION_NDS_SERVERS
Definition: dhcp_handler.h:102
#define DHCP_LEASE_UNKNOWN
Definition: dhcp_handler.h:194
#define DHCP_OPTION_AUTH
Definition: dhcp_handler.h:107
#define DHCP_OPTION_PXE_VENDOR_SPECIFIC_134
Definition: dhcp_handler.h:141
std::map< std::string, uint32_t > Dhcpv4NameCodeMap
Definition: dhcp_handler.h:355
#define DHCP_OPTION_BCMCS_ADDR_LIST
Definition: dhcp_handler.h:106
#define DHCP_OPTION_BOOT_FILE_SIZE
Definition: dhcp_handler.h:30
#define DHCP_OPTION_DNS
Definition: dhcp_handler.h:23
#define DHCP_NAK
Definition: dhcp_handler.h:189
#define DHCP_CHADDR_LEN
Definition: dhcp_handler.h:197
#define DHCP_OPTION_CLASSLESS_ROUTE
Definition: dhcp_handler.h:128
#define DHCP_OPTION_NETWARE_IP_INFO
Definition: dhcp_handler.h:80
#define DHCP_OPTION_BCAST_ADDRESS
Definition: dhcp_handler.h:45
#define DHCP_OPTION_MESSAGE
Definition: dhcp_handler.h:73
#define DHCP_OPTION_IPV4_FQDN_MOS
Definition: dhcp_handler.h:147
#define DHCP_OPTION_SUBNET_ALLOCATION
Definition: dhcp_handler.h:174
#define DHCP_OPTION_TIME_OFFSET
Definition: dhcp_handler.h:19
#define DHCP_OPTION_NAME_SERVICE_SEARCH
Definition: dhcp_handler.h:124
#define DHCP_SUBOP_REMOTEID
Definition: dhcp_handler.h:180
#define DHCP_OPTION_LDAP
Definition: dhcp_handler.h:112
#define DHCP_OPTION_NETBIOS_OVER_TCP_NS
Definition: dhcp_handler.h:61
#define DHCP_PKT_SIZE
Definition: dhcp_handler.h:11
#define DHCP_OPTION_PANA_AUTH_AGENT
Definition: dhcp_handler.h:143
#define DHCP_OPTION_SLP_DIRECTORY_AGENT
Definition: dhcp_handler.h:95
#define DHCP_OPTION_TFTP_SERVER
Definition: dhcp_handler.h:135
#define DHCP_DISCOVER
Definition: dhcp_handler.h:184
#define DHCP_LEASE_UNASSIGNED
Definition: dhcp_handler.h:193
#define DHCP_OPTION_NIS_PLUS_DOMAIN
Definition: dhcp_handler.h:81
#define DHCP_OPTION_IMPRESS_SERVER
Definition: dhcp_handler.h:27
#define DHCP_ACK
Definition: dhcp_handler.h:188
#define DHCP_OPTION_PATH_MTU_AGING_TIMEOUT
Definition: dhcp_handler.h:41
#define DHCP_OPTION_NIS_PLUS_SERVERS
Definition: dhcp_handler.h:82
#define DHCP_OPTION_IP_FWD_CONTROL
Definition: dhcp_handler.h:36
#define DHCP_OPTION_VENDOR_ID_VENDOR_SPECIFIC
Definition: dhcp_handler.h:132
#define DHCP_OPTION_CLIENT_SYSARCH_TYPE
Definition: dhcp_handler.h:110
#define DHCP_OPTION_MAX_DG_REASSEMBLY_SIZE
Definition: dhcp_handler.h:39
#define DHCP_OPTION_BOOTFILE_NAME
Definition: dhcp_handler.h:84
#define DHCP_OPTION_REQ_IP_ADDRESS
Definition: dhcp_handler.h:67
#define DHCP_OFFER
Definition: dhcp_handler.h:185
#define DHCP_OPTION_SIP_UA_CONFIG_DOMAIN
Definition: dhcp_handler.h:148
#define DHCP_OPTION_BCMCS_DN_LIST
Definition: dhcp_handler.h:105
#define DHCP_OPTION_STATIC_ROUTING_TABLE
Definition: dhcp_handler.h:50
#define DHCP_OPTION_CAPWAP_AC_ADDRESS
Definition: dhcp_handler.h:145
#define DHCP_FILE_LEN
Definition: dhcp_handler.h:199
#define DHCP_OPTION_VENDOR_ID_VENDOR_CLASS
Definition: dhcp_handler.h:131
#define DHCP_OPTION_NAME_SERVER
Definition: dhcp_handler.h:22
#define DHCP_OPTION_STREETTALK_DA_SERVER
Definition: dhcp_handler.h:93
#define DHCP_OPTION_DOMAIN_NAME
Definition: dhcp_handler.h:32
#define DHCP_OPTION_STATUS_CODE
Definition: dhcp_handler.h:156
#define DHCP_OPTION_POP_SERVER
Definition: dhcp_handler.h:87
#define DHCP_OPTION_STREETTALK_SERVER
Definition: dhcp_handler.h:92
#define DHCP_OPTION_DHCP_STATE
Definition: dhcp_handler.h:161
#define DHCP_OPTION_DEFAULT_FINGER_SERVER
Definition: dhcp_handler.h:90
#define DHCP_OPTION_PXE_VENDOR_SPECIFIC_130
Definition: dhcp_handler.h:137
#define DHCP_OPTION_ROUTER_SOLICIT_ADDRESS
Definition: dhcp_handler.h:49
#define DHCP_OPTION_NIS_DOMAIN
Definition: dhcp_handler.h:57
#define DHCP_OPTION_NETBIOS_OVER_TCP_SCOPE
Definition: dhcp_handler.h:64
#define DHCP_OPTION_DEFAULT_IP_TTL
Definition: dhcp_handler.h:40
#define DHCP_OPTION_QUERY_START_TIME
Definition: dhcp_handler.h:159
#define DHCP_OPTION_GEOCONF
Definition: dhcp_handler.h:130
#define DHCP_OPTION_LPR_SERVER
Definition: dhcp_handler.h:26
#define DHCP_OPTION_IEEE_1003_1_TZ
Definition: dhcp_handler.h:117
#define DHCP_OPTION_STORAGE_NS
Definition: dhcp_handler.h:100
#define BOOT_REPLY
Definition: dhcp_handler.h:207
std::map< uint32_t, DhcpHandler::DhcpOptionCategory > Dhcpv4CategoryMap
Definition: dhcp_handler.h:357
#define DHCP_OPTION_USER_CLASS_INFO
Definition: dhcp_handler.h:94
#define DHCP_OPTION_IPV4_ADDRESS_MOS
Definition: dhcp_handler.h:146
#define DHCP_OPTION_CLIENT_FQDN
Definition: dhcp_handler.h:98
#define DHCP_OPTION_DEFAULT_IRC_SERVER
Definition: dhcp_handler.h:91
#define DHCP_OPTION_ROUTER
Definition: dhcp_handler.h:20
#define DHCP_OPTION_PERFORM_MASK_DISCOVERY
Definition: dhcp_handler.h:46
#define DHCP_OPTION_TIME_SERVER
Definition: dhcp_handler.h:21
#define DHCP_OPTION_PERFORM_ROUTER_DISCOVERY
Definition: dhcp_handler.h:48
#define DHCP_OPTION_MASK_SUPPLIER
Definition: dhcp_handler.h:47
#define DHCP_OPTION_ARP_CACHE_TIMEOUT
Definition: dhcp_handler.h:52
#define DHCP_OPTION_EXTENSION_PATH
Definition: dhcp_handler.h:35
#define DHCP_OPTION_NDS_TREE_NAME
Definition: dhcp_handler.h:103
std::map< std::string, uint32_t >::const_iterator Dhcpv4NameCodeIter
Definition: dhcp_handler.h:356
#define DHCP_OPTION_PXE_VENDOR_SPECIFIC_135
Definition: dhcp_handler.h:142
#define DHCP_OPTION_XWINDOW_FONT_SERVER
Definition: dhcp_handler.h:65
#define DHCP_OPTION_AUTO_CONFIGURE
Definition: dhcp_handler.h:123
#define DHCP_OPTION_VSS
Definition: dhcp_handler.h:175
#define DHCP_UNKNOWN
Definition: dhcp_handler.h:183
#define DHCP_OPTION_TCP_KEEPALIVE_INTERVAL
Definition: dhcp_handler.h:55
#define HW_TYPE_ETHERNET
Definition: dhcp_handler.h:209
#define DHCP_OPTION_MSG_TYPE
Definition: dhcp_handler.h:70
#define DHCP_OPTION_NETWARE_IP_DOMAIN_NAME
Definition: dhcp_handler.h:79
#define DHCP_OPTION_PARAMETER_REQUEST_LIST
Definition: dhcp_handler.h:72
#define DHCP_OPTION_CLIENT_LAST_XTIME
Definition: dhcp_handler.h:108
#define DHCP_OPTION_REF_TZ_DB
Definition: dhcp_handler.h:118
#define DHCP_OPTION_GEOLOC
Definition: dhcp_handler.h:150
#define DHCP_OPTION_REBIND_TIME_VALUE
Definition: dhcp_handler.h:76
#define DHCP_OPTION_INTERFACE_MTU
Definition: dhcp_handler.h:43
#define DHCP_OPTION_NDS_CONTEXT
Definition: dhcp_handler.h:104
#define DHCP_REQUEST
Definition: dhcp_handler.h:186
#define DHCP_OPTION_CONFIG_FILE
Definition: dhcp_handler.h:168
#define DHCP_OPTION_CCC
Definition: dhcp_handler.h:129
#define DHCP_OPTION_TCP_KEEPALIVE_GARBAGE
Definition: dhcp_handler.h:56
#define DHCP_OPTION_DNS_DOMAIN_SEARCH_LIST
Definition: dhcp_handler.h:126
#define DHCP_OPTION_6RD
Definition: dhcp_handler.h:171
#define DHCP_OPTION_TFTP_SERVER_ADDRESS
Definition: dhcp_handler.h:155
#define DHCP_OPTION_URL
Definition: dhcp_handler.h:122
#define DHCP_OPTION_NL_SRC_ROUTING
Definition: dhcp_handler.h:37
#define DHCP_OPTION_LOST_SERVER
Definition: dhcp_handler.h:144
#define DHCP_OPTION_XWINDOW_SYSTEM_DISP_MGR
Definition: dhcp_handler.h:66
#define DHCP_OPTIONS_COOKIE
Definition: dhcp_handler.h:14
#define DHCP_OPTION_NIS_SERVERS
Definition: dhcp_handler.h:58
#define DHCP_OPTION_PXE_VENDOR_SPECIFIC_131
Definition: dhcp_handler.h:138
#define DHCP_OPTION_MERIT_DUMP_FILE
Definition: dhcp_handler.h:31
#define DHCP_OPTION_BASE_TIME
Definition: dhcp_handler.h:157
#define DHCP_OPTION_ALL_SUBNETS_LOCAL
Definition: dhcp_handler.h:44
#define DHCP_INFORM
Definition: dhcp_handler.h:191
#define DHCP_OPTION_SMTP_SERVER
Definition: dhcp_handler.h:86
#define DHCP_OPTION_SLP_SERVICE_SCOPE
Definition: dhcp_handler.h:96
#define DHCP_OPTION_GEOCONF_CIVIC
Definition: dhcp_handler.h:116
#define DHCP_OPTION_RAPID_COMMIT
Definition: dhcp_handler.h:97
#define DHCP_SUBOP_CKTID
Definition: dhcp_handler.h:179
#define DHCP_OPTION_NETINFO_PARENT_SERVER_ADDR
Definition: dhcp_handler.h:120
#define DHCP_OPTION_NTP_SERVERS
Definition: dhcp_handler.h:59
#define DHCP_OPTION_PATH_PREFIX
Definition: dhcp_handler.h:169
#define DHCP_OPTION_RESOURCE_LOCATION_SERVER
Definition: dhcp_handler.h:28
#define DHCP_OPTION_SERVER_IDENTIFIER
Definition: dhcp_handler.h:71
#define DHCP_BCAST_FLAG
Definition: dhcp_handler.h:208
#define DHCP_OPTION_SIP_SERVERS
Definition: dhcp_handler.h:127
#define DHCP_OPTION_QUOTE_SERVER
Definition: dhcp_handler.h:25
#define DHCP_OPTION_NNTP_SERVER
Definition: dhcp_handler.h:88
#define DHCP_OPTION_PXE_VENDOR_SPECIFIC_132
Definition: dhcp_handler.h:139
#define DHCP_OPTION_ROOT_PATH
Definition: dhcp_handler.h:34
#define DHCP_OPTION_START_TIME_OF_STATE
Definition: dhcp_handler.h:158
#define DHCP_OPTION_QUERY_END_TIME
Definition: dhcp_handler.h:160
#define DHCP_GW_LEASE_TIME
Definition: dhcp_handler.h:212
#define DHCP_OPTION_IP_LEASE_TIME
Definition: dhcp_handler.h:68
#define DHCP_OPTION_SWAP_SERVER
Definition: dhcp_handler.h:33
#define DHCP_OPTION_PATH_MTU_PLATEAU_TABLE
Definition: dhcp_handler.h:42
#define DHCP_OPTION_ASSOCIATE_IP
Definition: dhcp_handler.h:109
#define DHCP_OPTION_VENDOR_SPECIFIC_INFO
Definition: dhcp_handler.h:60
#define DHCP_OPTION_SUBNET_MASK
Definition: dhcp_handler.h:18
#define DHCP_OPTION_CLIENT_ID
Definition: dhcp_handler.h:78
#define DHCP_OPTION_TRAILER_ENCAP
Definition: dhcp_handler.h:51
#define DHCP_OPTION_82
Definition: dhcp_handler.h:99
#define DHCP_LEASE_QUERY
Definition: dhcp_handler.h:192
#define DHCP_OPTION_RENEW_TIME_VALUE
Definition: dhcp_handler.h:75
#define DHCP_OPTION_PCP_SERVER
Definition: dhcp_handler.h:163
#define DHCP_LEASE_ACTIVE
Definition: dhcp_handler.h:195
#define DHCP_OPTION_TFTP_SERVER_NAME
Definition: dhcp_handler.h:83
#define DHCP_OPTION_V4_ACCESS_DOMAIN
Definition: dhcp_handler.h:172
#define DHCP_OPTION_CLIENT_MACHINE_ID
Definition: dhcp_handler.h:114
#define DHCP_NAME_LEN
Definition: dhcp_handler.h:198
#define DHCP_OPTION_CLASS_ID
Definition: dhcp_handler.h:77
#define DHCP_OPTION_PXE_VENDOR_SPECIFIC_129
Definition: dhcp_handler.h:136
#define DHCP_OPTION_CLIENT_NW_INTERFACE_ID
Definition: dhcp_handler.h:111
#define DHCP_RELEASE
Definition: dhcp_handler.h:190
#define DHCP_DECLINE
Definition: dhcp_handler.h:187
#define DHCP_OPTION_PXELINUX_MAGIC
Definition: dhcp_handler.h:167
#define DHCP_FIXED_LEN
Definition: dhcp_handler.h:200
#define DHCP_OPTION_END
Definition: dhcp_handler.h:177
#define DHCP_OPTION_NETBIOS_OVER_TCP_DG_DS
Definition: dhcp_handler.h:62
#define DHCP_OPTION_NETINFO_PARENT_SERVER_TAG
Definition: dhcp_handler.h:121
#define DHCP_OPTION_REBOOT_TIME
Definition: dhcp_handler.h:170
#define DHCP_OPTION_RDNSS_SELECTION
Definition: dhcp_handler.h:152
#define DHCP_OPTION_HOST_NAME
Definition: dhcp_handler.h:29
#define DHCP_OPTION_POLICY_FILTER
Definition: dhcp_handler.h:38
#define DHCP_OPTION_DEFAULT_TCP_TTL
Definition: dhcp_handler.h:54
#define DHCP_SHORTLEASE_TIME
Definition: dhcp_handler.h:211
#define DHCP_OPTION_OPENGROUP_USER_AUTH
Definition: dhcp_handler.h:115
#define DHCP_OPTION_MAX_DHCP_MSG_SIZE
Definition: dhcp_handler.h:74
#define DHCP_OPTION_NETBIOS_OVER_TCP_NODE_TYPE
Definition: dhcp_handler.h:63
#define DHCP_OPTION_IPV4_ADDRESS_ANDSF
Definition: dhcp_handler.h:149
#define DHCP_OPTION_DATA_SOURCE
Definition: dhcp_handler.h:162
#define DHCP_OPTION_OVERLOAD
Definition: dhcp_handler.h:69
#define DHCP_OPTION_SUBNET_SELECTION
Definition: dhcp_handler.h:125
#define DHCP_OPTION_PAD
Definition: dhcp_handler.h:17
#define DHCP_OPTION_FORCERENEW_NONCE_CAP
Definition: dhcp_handler.h:151
#define DHCP_TRACE(obj, arg)
Definition: dhcp_proto.h:12
Definition: io_utils.cc:12
#define DEFAULT_IP_ID
Definition: pkt_handler.h:48
#define DHCP_CLIENT_PORT
Definition: pkt_handler.h:30
#define DHCP_SERVER_PORT
Definition: pkt_handler.h:29
#define DEFAULT_IP_TTL
Definition: pkt_handler.h:44
@ TRAP_TOR_CONTROL_PKT
Definition: pkt_handler.h:143
@ RESYNC
Definition: agent_db.h:104
@ DB_ENTRY_ADD_CHANGE
Definition: db_table.h:39
std::unique_ptr< DBRequestKey > key
Definition: db_table.h:49
std::unique_ptr< DBRequestData > data
Definition: db_table.h:50
void UpdateData(uint32_t id, uint16_t fl, uint8_t *mac)
Definition: dhcp_handler.h:268
Dhcpv4Options * GetNextOptionPtr()
Definition: dhcp_handler.h:248
uint8_t data[0]
Definition: dhcp_handler.h:258
void WriteData(uint8_t c, uint8_t l, const void *d, uint16_t *optlen)
Definition: dhcp_handler.h:233
void WriteByte(uint8_t c, uint16_t *optlen)
Definition: dhcp_handler.h:239
uint32_t vrf
Definition: pkt_handler.h:391
uint16_t len
Definition: pkt_handler.h:380
struct ether_header * eth
Definition: pkt_handler.h:420
struct ip * ip
Definition: pkt_handler.h:423
Definition: vn.h:29
IpAddress dns_server
Definition: vn.h:34
IpAddress default_gw
Definition: vn.h:32
uint32_t xid
Definition: dhcp_handler.h:219
uint8_t op
Definition: dhcp_handler.h:215
in_addr_t yiaddr
Definition: dhcp_handler.h:223
uint16_t secs
Definition: dhcp_handler.h:220
uint8_t htype
Definition: dhcp_handler.h:216
in_addr_t ciaddr
Definition: dhcp_handler.h:222
uint8_t options[DHCP_MAX_OPTION_LEN]
Definition: dhcp_handler.h:229
uint8_t chaddr[DHCP_CHADDR_LEN]
Definition: dhcp_handler.h:226
in_addr_t siaddr
Definition: dhcp_handler.h:224
uint8_t hops
Definition: dhcp_handler.h:218
uint8_t sname[DHCP_NAME_LEN]
Definition: dhcp_handler.h:227
uint16_t flags
Definition: dhcp_handler.h:221
uint8_t hlen
Definition: dhcp_handler.h:217
uint8_t file[DHCP_FILE_LEN]
Definition: dhcp_handler.h:228
in_addr_t giaddr
Definition: dhcp_handler.h:225