30 DnsBindQueryMap::iterator next = it++;
46 std::vector<BindResolver::DnsServer> dns_servers;
51 server,
agent()->dns_server_port(i)));
62 agent()->params()->dns_client_port(),
68 xid_(0), timeout_(agent->params()->dns_timeout()),
69 max_retries_(agent->params()->dns_max_retries()) {
123 boost::asio::io_context &io) {
141 for (VmInterface::FloatingIpSet::iterator it = fip.list_.begin(),
142 next = fip.list_.begin(); it != fip.list_.end(); it = next) {
147 autogen::VirtualDnsType vdns_type;
148 std::string vdns_name;
151 vdns_name, vdns_type);
152 VmDataMap::iterator it =
all_vms_.find(vmitf);
166 vdns_name, vdns_type);
175 for (VmInterface::FloatingIpSet::iterator it = fip.
list_.begin();
176 it != fip.
list_.end(); ++it) {
177 if (it->Installed()) {
179 it->floating_ip_,
false);
193 DnsFipSet::iterator it =
fip_list_.upper_bound(key);
196 if (entry->
vn_ != vn) {
208 for (VmDataMap::iterator it =
all_vms_.begin(); it !=
all_vms_.end(); ++it) {
209 if (it->first->vn() == vn) {
210 std::string vdns_name;
211 autogen::VirtualDnsType vdns_type;
213 it->first->primary_ip6_addr(),
214 vdns_name, vdns_type);
216 it->first->primary_ip_addr(),
217 it->first->primary_ip6_addr(),
218 vdns_name, vdns_type);
223 DnsFipSet::iterator it =
fip_list_.upper_bound(key);
225 std::string fip_vdns_name;
227 if (entry->
vn_ != vn) {
230 autogen::VirtualDnsType fip_vdns_type;
240 fip_vdns_name, fip_vdns_type);
278 autogen::VirtualDns *virtual_dns =
279 static_cast <autogen::VirtualDns *> (node->
GetObject());
280 autogen::VirtualDnsType vdns_type = virtual_dns->data();
281 std::string name = node->
name();
288 for (VmDataMap::iterator it =
all_vms_.begin(); it !=
all_vms_.end(); ++it) {
289 std::string vdns_name;
290 autogen::VirtualDnsType vdns_type;
291 GetVdnsData(it->first->vn(), it->first->primary_ip_addr(),
292 it->first->primary_ip6_addr(), vdns_name, vdns_type);
294 if (!is_ipam && is_deleted && vdns_name == name)
297 it->first->primary_ip_addr(),
298 it->first->primary_ip6_addr(),
299 vdns_name, vdns_type);
301 DnsFipSet::iterator it =
fip_list_.begin();
303 std::string fip_vdns_name;
305 autogen::VirtualDnsType fip_vdns_type;
315 fip_vdns_name, fip_vdns_type);
323 const Ip6Address &ip6, std::string &vdns_name,
324 const autogen::VirtualDnsType &vdns_type) {
325 IpVdnsMap::iterator vmdata_it = ipvdns.find(ip.to_ulong());
326 if (vmdata_it == ipvdns.end()) {
328 vdns_name, ip, ip6,
false,
false))
329 ipvdns.insert(
IpVdnsPair(ip.to_ulong(), vdns_name));
334 if (vmdata_it->second.empty() && vmdata_it->second != vdns_name) {
336 vdns_name, ip, ip6,
false,
false))
337 vmdata_it->second = vdns_name;
338 }
else if (vmdata_it->second != vdns_name) {
341 vmdata_it->second = vdns_name;
346 const autogen::VirtualDnsType &vdns_type) {
348 std::string fip_name;
362 vdns_name, ip4, ip6,
true,
false)) {
376 const std::string &name,
379 const std::string &vdns_name,
380 const autogen::VirtualDnsType &vdns_type,
381 bool is_floating,
bool is_delete) {
382 if (!name.size() || !vdns_type.dynamic_records_from_client) {
384 name <<
"Dynamic records allowed = " <<
385 (vdns_type.dynamic_records_from_client ?
"yes" :
"no"));
391 data->
zone = vdns_type.domain_name;
395 if (!ip.is_unspecified()) {
398 item.
ttl = is_delete ? 0 : vdns_type.default_ttl_seconds;
400 boost::system::error_code ec;
401 item.
data = ip.to_string(ec);
402 data->
items.push_back(item);
406 if (!ip6.is_unspecified()) {
409 ip6_item.
ttl = is_delete ? 0 : vdns_type.default_ttl_seconds;
410 ip6_item.
name = name;
411 boost::system::error_code ec;
412 ip6_item.
data = ip6.to_string(ec);
413 data->
items.push_back(ip6_item);
416 if (data->
items.size()) {
418 "DNS update sent for : " << item.
ToString() <<
419 " IPv6 : " << ip6_item.
ToString() <<
421 " Zone : " << data->
zone);
425 name <<
"Address unspecified");
437 ptr_data->
items.push_back(item);
441 " Zone : " << ptr_data->
zone);
445 if (!ip6.is_unspecified()) {
454 ptr6_data->
items.push_back(ip6_item);
458 " Zone : " << ptr6_data->
zone);
476 bool is_floating =
true;
477 std::string vdns_name;
478 autogen::VirtualDnsType vdns_type;
481 DnsFipSet::iterator it =
fip_list_.find(key);
485 std::string fip_name;
486 if (!
GetFipName(vmitf, vdns_type, ip, fip_name))
489 vdns_name, ip4, ip6, is_floating,
false))
491 key.get()->vdns_name_ = vdns_name;
492 key.get()->fip_name_ = fip_name;
496 std::string fip_name;
498 (*it)->vdns_name_, ip4, ip6, is_floating,
true);
509 const std::string &vm_name,
510 const std::string &vdns_name,
513 bool is_floating,
bool is_deleted) {
514 if (!vdns_name.empty()) {
516 const std::vector<VnIpam> &ipam = vn->
GetVnIpam();
518 if (!ip.is_unspecified()) {
519 for (i = 0; i < ipam.size(); ++i) {
520 if (ipam[i].IsV4() &&
526 if (i == ipam.size()) {
528 vm_name <<
"> not done for vn <" <<
529 vn->
GetName() <<
"> IPAM doesnt have Ipv4 subnet; " <<
530 ((is_deleted)?
"delete" :
"update"));
536 if (!ip6.is_unspecified()) {
537 for (i = 0; i < ipam.size(); ++i) {
538 if (ipam[i].IsV6() &&
540 plen6 = ipam[i].plen;
544 if (i == ipam.size()) {
546 vm_name <<
"> not done for vn <" <<
547 vn->
GetName() <<
"> IPAM doesnt have Ipv6 subnet; " <<
548 ((is_deleted)?
"delete" :
"update"));
553 autogen::VirtualDnsType vdns_type;
556 vdns_name, vdns_type, is_floating,
560 vm_name <<
"> entry not " <<
561 ((is_deleted)?
"deleted; " :
"updated; ") <<
562 "VDNS info for " << vdns_name <<
" not present");
572 std::string &new_vdns_name,
573 std::string &old_vdns_name,
574 const autogen::VirtualDnsType &vdns_type,
576 std::string name = (vmitf ? vmitf->
vm_name() :
"All Vms");
578 " old VDNS : " << old_vdns_name <<
579 " new VDNS : " << new_vdns_name <<
580 " ttl : " << vdns_type.default_ttl_seconds <<
581 " floating : " << (is_floating ?
"yes" :
"no"));
583 old_vdns_name, vdns_type.domain_name,
584 (uint32_t)vdns_type.default_ttl_seconds, is_floating);
589 const Ip6Address &v6_addr, std::string &vdns_name,
590 autogen::VirtualDnsType &vdns_type) {
594 autogen::IpamType ipam_type;
595 if ((!v4_addr.to_ulong() ||
597 (v6_addr.is_unspecified() ||
599 DNS_BIND_TRACE(DnsBindTrace,
"Unable to retrieve VDNS data; VN : " <<
600 vn->
GetName() <<
" IPv4 : " << v4_addr.to_string() <<
601 " IPv6 : " << v6_addr.to_string());
605 vdns_name = ipam_type.ipam_dns_server.virtual_dns_server_name;
610 const autogen::VirtualDnsType &vdns_type,
611 const IpAddress &ip, std::string &fip_name)
const {
612 std::string fip_name_notation =
613 boost::to_lower_copy(vdns_type.floating_ip_record);
616 if (fip_name_notation ==
"" ||
617 fip_name_notation ==
"dashed-ip" ||
618 fip_name_notation ==
"dashed-ip-tenant-name") {
619 name = ip.to_string();
620 boost::replace_all(name,
".",
"-");
625 if (fip_name_notation ==
"" ||
626 fip_name_notation ==
"dashed-ip-tenant-name" ||
627 fip_name_notation ==
"vm-name-tenant-name") {
660 const std::string &new_vdns,
661 const std::string &old_vdns,
662 const std::string &new_dom,
663 uint32_t ttl,
bool is_floating) {
689 if (it->second == handler) {
699 if (it->second == handler) {
744 : vn_(vn), floating_ip_(fip), interface_(itf) {
752 return lhs->IsLess(rhs.get());
756 if (vn_ != rhs->
vn_) {
757 return vn_ < rhs->
vn_;
void SetBounded(bool bounded)
bool IsLess(const DnsFipEntry *rhs) const
bool UpdateDnsEntry(const VmInterface *vmitf, const VnEntry *vn, const std::string &vm_name, const std::string &vdns_name, const Ip4Address &ip, const Ip6Address &ip6, bool is_floating, bool is_deleted)
void DelVmRequest(DnsHandler::QueryKey *key)
ProtoWorkQueue work_queue_
#define DNS_BIND_TRACE(obj, arg)
void SendMessage(PktModuleName mod, InterTaskMsg *msg)
void set_update_floatingip_cb(UpdateFloatingIpFn fn)
static const uint8_t kInvalidDscp
static void Delete(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, uint32_t ethernet_tag)
DomainConfig * domain_config_table() const
bool GetVdnsData(const VnEntry *vn, const Ip4Address &v4_addr, const Ip6Address &v6_addr, std::string &vdns_name, autogen::VirtualDnsType &vdns_type)
int16_t GetDnsQueryServerIndex(uint16_t xid)
bool SendUpdateDnsEntry(const VmInterface *vmitf, const std::string &name, const Ip4Address &ip, uint32_t plen, const Ip6Address &ip6, uint32_t plen6, const std::string &vdns_name, const autogen::VirtualDnsType &vdns_type, bool is_floating, bool is_delete)
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
void DelDnsQuery(uint16_t xid)
const Interface * vhost_interface() const
DnsProto(Agent *agent, boost::asio::io_context &io)
const std::string & dns_server(uint8_t idx) const
boost::asio::ip::address IpAddress
GlobalQosConfig * global_qos_config() const
void VnNotify(DBEntryBase *entry)
uint8_t control_dscp() const
void InterfaceNotify(DBEntryBase *entry)
void DelDnsQueryIndex(uint16_t xid)
InterfaceTable * interface_table() const
VnTable * vn_table() const
void IpamNotify(IFMapNode *node)
void DelDnsQueryHandler(DnsHandler *handler)
const string & GetName() const
const MacAddress & mac() const
DBTableBase::ListenerId lid_
std::pair< uint32_t, std::string > IpVdnsPair
DnsFipEntry(const VnEntry *vn, const IpAddress &fip, const VmInterface *itf)
void AddDnsQueryIndex(uint16_t xid, int16_t srv_idx)
DnsVmRequestSet curr_vm_requests_
void VrfNotify(DBEntryBase *entry)
bool MoveVDnsEntry(const VmInterface *vmitf, std::string &new_vdns_name, std::string &old_vdns_name, const autogen::VirtualDnsType &vdns_type, bool is_floating)
bool GetIpamVdnsData(const IpAddress &vm_addr, autogen::IpamType *ipam_type, autogen::VirtualDnsType *vdns_type) const
void Unregister(ListenerId listener)
const VmInterface * interface_
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
std::string GetProject() const
const std::string & fabric_vrf_name() const
bool IsDnsQueryInProgress(uint16_t xid)
static void set_dns_xmpp_event_handler_cb(DnsXmppEventHandler cb)
bool IsDnsHandlerInUse(DnsHandler *handler)
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
void SendDnsIpc(uint8_t *pkt, std::size_t length)
bool BuildDefaultServerList()
void SetSize(size_t size)
void ProcessNotify(std::string name, bool is_deleted, bool is_ipam)
DefaultServerList def_server_list_
static TaskScheduler * GetInstance()
static void set_dns_message_handler_cb(DnsMessageHandler cb)
boost::asio::ip::address_v6 Ip6Address
DBTableBase::ListenerId vrf_table_listener_id_
std::pair< uint32_t, int16_t > DnsBindQueryIndexPair
std::string ToString() const
void AddDnsQuery(uint16_t xid, DnsHandler *handler)
static std::string GetPtrNameFromAddr(const Ip4Address &ip)
DnsHandler * GetDnsQueryHandler(uint16_t xid)
const Peer * local_peer() const
PktHandler * pkt_handler() const
std::pair< uint32_t, DnsHandler * > DnsBindQueryPair
std::pair< const VmInterface *, IpVdnsMap > VmDataPair
const std::vector< VnIpam > & GetVnIpam() const
const VnEntry * vn() const
AgentParam * params() const
static Timer * CreateTimer(boost::asio::io_context &service, const std::string &name, int task_id=Timer::GetTimerTaskId(), int task_instance=Timer::GetTimerInstanceId(), bool delete_on_completion=false)
const std::string & name() const
bool operator()(const DnsFipEntryPtr &lhs, const DnsFipEntryPtr &rhs) const
boost::asio::ip::address_v4 Ip4Address
void AddVmRequest(DnsHandler::QueryKey *key)
void SendDnsUpdateIpc(DnsUpdateData *data, DnsAgentXmpp::XmppType type, const VmInterface *vm, bool floating)
DefaultServerList GetDefaultServerList()
VrfTable * vrf_table() const
const Ip4Address & primary_ip_addr() const
DefaultServerList BuildDefaultServerListImpl()
IFMapObject * GetObject()
const FloatingIpList & floating_ip_list() const
uint32_t services_queue_limit()
const std::string & vm_name() const
bool UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn, const IpAddress &ip, bool is_deleted)
const Ip6Address & primary_ip6_addr() const
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
static const Ip6Address ip6_unspec_
static void AddBridgeReceiveRoute(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, const std::string &vn_name, const std::string &interface, bool policy)
static const Ip4Address ip4_unspec_
boost::shared_ptr< DnsFipEntry > DnsFipEntryPtr
bool GetFipName(const VmInterface *vmitf, const autogen::VirtualDnsType &vdns_type, const IpAddress &ip, std::string &fip_name) const
void RegisterIpamCb(Callback cb)
static const uint32_t kDnsDefaultSlistInterval
Timer * default_slist_timer_
const string & GetName() const
bool GetVDns(const std::string &vdns, autogen::VirtualDnsType *vdns_type)
DnsBindQueryMap dns_query_map_
void CheckForFipUpdate(DnsFipEntry *entry, std::string &vdns_name, const autogen::VirtualDnsType &vdns_type)
static void GetReverseZone(const Ip4Address &addr, uint32_t plen, std::string &zone)
std::map< uint32_t, std::string > IpVdnsMap
DBTableBase::ListenerId Vnlid_
static void Init(boost::asio::io_context &io, const std::vector< DnsServer > &dns_servers, uint16_t client_port, Callback cb, uint8_t dscp)
bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet, uint8_t plen)
DnsBindQueryIndexMap dns_query_index_map_
static bool DeleteTimer(Timer *Timer)
void RegisterVdnsCb(Callback cb)
bool IsVmRequestDuplicate(DnsHandler::QueryKey *key)
void CheckForUpdate(IpVdnsMap &ipvdns, const VmInterface *vmitf, const VnEntry *vn, const Ip4Address &ip, const Ip6Address &ip6, std::string &vdns_name, const autogen::VirtualDnsType &vdns_type)
void VdnsNotify(IFMapNode *node)