6 #include <boost/uuid/uuid_io.hpp>
31 DnsBindQueryMap::iterator next = it++;
47 std::vector<BindResolver::DnsServer> dns_servers;
52 server,
agent()->dns_server_port(i)));
63 agent()->params()->dns_client_port(),
69 xid_(0), timeout_(agent->params()->dns_timeout()),
70 max_retries_(agent->params()->dns_max_retries()) {
124 boost::asio::io_context &
io) {
142 for (VmInterface::FloatingIpSet::iterator it = fip.
list_.begin(),
143 next = fip.
list_.begin(); it != fip.
list_.end(); it = next) {
148 autogen::VirtualDnsType vdns_type;
149 std::string vdns_name;
152 vdns_name, vdns_type);
153 VmDataMap::iterator it =
all_vms_.find(vmitf);
167 vdns_name, vdns_type);
180 for (VmInterface::FloatingIpSet::iterator it = fip.
list_.begin();
181 it != fip.
list_.end(); ++it) {
188 if (it->del_pending() ==
false && it->vn_.get() != NULL &&
189 it->vn_->IsDeleted() ==
false) {
191 it->floating_ip_,
false);
205 DnsFipSet::iterator it =
fip_list_.upper_bound(key);
208 if (entry->
vn_ != vn) {
220 for (VmDataMap::iterator it =
all_vms_.begin(); it !=
all_vms_.end(); ++it) {
221 if (it->first->vn() == vn) {
222 std::string vdns_name;
223 autogen::VirtualDnsType vdns_type;
225 it->first->primary_ip6_addr(),
226 vdns_name, vdns_type);
228 it->first->primary_ip_addr(),
229 it->first->primary_ip6_addr(),
230 vdns_name, vdns_type);
235 DnsFipSet::iterator it =
fip_list_.upper_bound(key);
237 std::string fip_vdns_name;
239 if (entry->
vn_ != vn) {
242 autogen::VirtualDnsType fip_vdns_type;
252 fip_vdns_name, fip_vdns_type);
290 autogen::VirtualDns *virtual_dns =
291 static_cast <autogen::VirtualDns *
> (node->
GetObject());
292 autogen::VirtualDnsType vdns_type = virtual_dns->data();
293 std::string name = node->
name();
300 for (VmDataMap::iterator it =
all_vms_.begin(); it !=
all_vms_.end(); ++it) {
301 std::string vdns_name;
302 autogen::VirtualDnsType vdns_type;
303 GetVdnsData(it->first->vn(), it->first->primary_ip_addr(),
304 it->first->primary_ip6_addr(), vdns_name, vdns_type);
306 if (!is_ipam && is_deleted && vdns_name == name)
309 it->first->primary_ip_addr(),
310 it->first->primary_ip6_addr(),
311 vdns_name, vdns_type);
313 DnsFipSet::iterator it =
fip_list_.begin();
315 std::string fip_vdns_name;
317 autogen::VirtualDnsType fip_vdns_type;
327 fip_vdns_name, fip_vdns_type);
335 const Ip6Address &ip6, std::string &vdns_name,
336 const autogen::VirtualDnsType &vdns_type) {
337 IpVdnsMap::iterator vmdata_it = ipvdns.find(ip.to_ulong());
338 if (vmdata_it == ipvdns.end()) {
340 vdns_name, ip, ip6,
false,
false))
341 ipvdns.insert(
IpVdnsPair(ip.to_ulong(), vdns_name));
346 if (vmdata_it->second.empty() && vmdata_it->second != vdns_name) {
348 vdns_name, ip, ip6,
false,
false))
349 vmdata_it->second = vdns_name;
350 }
else if (vmdata_it->second != vdns_name) {
353 vmdata_it->second = vdns_name;
358 const autogen::VirtualDnsType &vdns_type) {
360 std::string fip_name;
374 vdns_name, ip4, ip6,
true,
false)) {
388 const std::string &name,
391 const std::string &vdns_name,
392 const autogen::VirtualDnsType &vdns_type,
393 bool is_floating,
bool is_delete) {
394 if (!name.size() || !vdns_type.dynamic_records_from_client) {
396 name <<
"Dynamic records allowed = " <<
397 (vdns_type.dynamic_records_from_client ?
"yes" :
"no"));
403 data->
zone = vdns_type.domain_name;
407 vm_uuid = boost::uuids::to_string(vmitf->
GetUuid());
412 if (!ip.is_unspecified()) {
415 item.
ttl = is_delete ? 0 : vdns_type.default_ttl_seconds;
418 boost::system::error_code ec;
419 item.
data = ip.to_string(ec);
420 data->
items.push_back(item);
424 if (!ip6.is_unspecified()) {
427 ip6_item.
ttl = is_delete ? 0 : vdns_type.default_ttl_seconds;
428 ip6_item.
name = name;
430 boost::system::error_code ec;
431 ip6_item.
data = ip6.to_string(ec);
432 data->
items.push_back(ip6_item);
435 if (data->
items.size()) {
437 "DNS update sent for : " << item.
ToString() <<
438 " IPv6 : " << ip6_item.
ToString() <<
440 " Zone : " << data->
zone);
444 name <<
"Address unspecified");
456 ptr_data->
items.push_back(item);
460 " Zone : " << ptr_data->
zone);
464 if (!ip6.is_unspecified()) {
473 ptr6_data->
items.push_back(ip6_item);
477 " Zone : " << ptr6_data->
zone);
495 bool is_floating =
true;
496 std::string vdns_name;
497 autogen::VirtualDnsType vdns_type;
500 DnsFipSet::iterator it =
fip_list_.find(key);
504 std::string fip_name;
505 if (!
GetFipName(vmitf, vdns_type, ip, fip_name))
508 vdns_name, ip4, ip6, is_floating,
false))
510 key.get()->vdns_name_ = vdns_name;
511 key.get()->fip_name_ = fip_name;
515 std::string fip_name;
517 (*it)->vdns_name_, ip4, ip6, is_floating,
true);
528 const std::string &vm_name,
529 const std::string &vdns_name,
532 bool is_floating,
bool is_deleted) {
533 if (!vdns_name.empty()) {
535 const std::vector<VnIpam> &ipam = vn->
GetVnIpam();
537 if (!ip.is_unspecified()) {
538 for (i = 0; i < ipam.size(); ++i) {
539 if (ipam[i].IsV4() &&
545 if (i == ipam.size()) {
547 vm_name <<
"> not done for vn <" <<
548 vn->
GetName() <<
"> IPAM doesnt have Ipv4 subnet; " <<
549 ((is_deleted)?
"delete" :
"update"));
555 if (!ip6.is_unspecified()) {
556 for (i = 0; i < ipam.size(); ++i) {
557 if (ipam[i].IsV6() &&
559 plen6 = ipam[i].plen;
563 if (i == ipam.size()) {
565 vm_name <<
"> not done for vn <" <<
566 vn->
GetName() <<
"> IPAM doesnt have Ipv6 subnet; " <<
567 ((is_deleted)?
"delete" :
"update"));
572 autogen::VirtualDnsType vdns_type;
575 vdns_name, vdns_type, is_floating,
579 vm_name <<
"> entry not " <<
580 ((is_deleted)?
"deleted; " :
"updated; ") <<
581 "VDNS info for " << vdns_name <<
" not present");
591 std::string &new_vdns_name,
592 std::string &old_vdns_name,
593 const autogen::VirtualDnsType &vdns_type,
595 std::string name = (vmitf ? vmitf->
vm_name() :
"All Vms");
597 " old VDNS : " << old_vdns_name <<
598 " new VDNS : " << new_vdns_name <<
599 " ttl : " << vdns_type.default_ttl_seconds <<
600 " floating : " << (is_floating ?
"yes" :
"no"));
602 old_vdns_name, vdns_type.domain_name,
603 (uint32_t)vdns_type.default_ttl_seconds, is_floating);
608 const Ip6Address &v6_addr, std::string &vdns_name,
609 autogen::VirtualDnsType &vdns_type) {
613 autogen::IpamType ipam_type;
614 if ((!v4_addr.to_ulong() ||
616 (v6_addr.is_unspecified() ||
618 DNS_BIND_TRACE(DnsBindTrace,
"Unable to retrieve VDNS data; VN : " <<
619 vn->
GetName() <<
" IPv4 : " << v4_addr.to_string() <<
620 " IPv6 : " << v6_addr.to_string());
624 vdns_name = ipam_type.ipam_dns_server.virtual_dns_server_name;
629 const autogen::VirtualDnsType &vdns_type,
630 const IpAddress &ip, std::string &fip_name)
const {
631 std::string fip_name_notation =
632 boost::to_lower_copy(vdns_type.floating_ip_record);
635 if (fip_name_notation ==
"" ||
636 fip_name_notation ==
"dashed-ip" ||
637 fip_name_notation ==
"dashed-ip-tenant-name") {
638 name = ip.to_string();
639 boost::replace_all(name,
".",
"-");
644 if (fip_name_notation ==
"" ||
645 fip_name_notation ==
"dashed-ip-tenant-name" ||
646 fip_name_notation ==
"vm-name-tenant-name") {
679 const std::string &new_vdns,
680 const std::string &old_vdns,
681 const std::string &new_dom,
682 uint32_t ttl,
bool is_floating) {
708 if (it->second == handler) {
718 if (it->second == handler) {
763 : vn_(vn), floating_ip_(fip), interface_(itf) {
771 return lhs->IsLess(rhs.get());
775 if (vn_ != rhs->
vn_) {
776 return vn_ < rhs->
vn_;
boost::asio::ip::address_v6 Ip6Address
boost::asio::ip::address IpAddress
boost::asio::ip::address_v4 Ip4Address
bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet, uint8_t plen)
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
#define DNS_BIND_TRACE(obj, arg)
static void set_dns_message_handler_cb(DnsMessageHandler cb)
static void set_dns_xmpp_event_handler_cb(DnsXmppEventHandler cb)
uint32_t services_queue_limit()
InterfaceTable * interface_table() const
DomainConfig * domain_config_table() const
const std::string & dns_server(uint8_t idx) const
AgentParam * params() const
VrfTable * vrf_table() const
const Peer * local_peer() const
VnTable * vn_table() const
const Interface * vhost_interface() const
const std::string & fabric_vrf_name() const
static void Init(boost::asio::io_context &io, const std::vector< DnsServer > &dns_servers, uint16_t client_port, Callback cb, uint8_t dscp)
static std::string GetPtrNameFromAddr(const Ip4Address &ip)
static void GetReverseZone(const Ip4Address &addr, uint32_t plen, std::string &zone)
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 void Delete(const Peer *peer, const std::string &vrf_name, const MacAddress &mac, uint32_t ethernet_tag)
ListenerId Register(ChangeCallback callback, const std::string &name="unspecified")
void Unregister(ListenerId listener)
bool operator()(const DnsFipEntryPtr &lhs, const DnsFipEntryPtr &rhs) const
std::pair< uint32_t, int16_t > DnsBindQueryIndexPair
void DelDnsQuery(uint16_t xid)
DefaultServerList GetDefaultServerList()
void InterfaceNotify(DBEntryBase *entry)
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)
void CheckForFipUpdate(DnsFipEntry *entry, std::string &vdns_name, const autogen::VirtualDnsType &vdns_type)
DBTableBase::ListenerId vrf_table_listener_id_
void AddDnsQueryIndex(uint16_t xid, int16_t srv_idx)
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)
DBTableBase::ListenerId lid_
DefaultServerList BuildDefaultServerListImpl()
bool IsDnsQueryInProgress(uint16_t xid)
void SendDnsIpc(uint8_t *pkt, std::size_t length)
void VdnsNotify(IFMapNode *node)
DnsHandler * GetDnsQueryHandler(uint16_t xid)
std::pair< uint32_t, DnsHandler * > DnsBindQueryPair
bool BuildDefaultServerList()
void SendDnsUpdateIpc(DnsUpdateData *data, DnsAgentXmpp::XmppType type, const VmInterface *vm, bool floating)
void AddVmRequest(DnsHandler::QueryKey *key)
ProtoHandler * AllocProtoHandler(boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
void DelDnsQueryIndex(uint16_t xid)
bool GetFipName(const VmInterface *vmitf, const autogen::VirtualDnsType &vdns_type, const IpAddress &ip, std::string &fip_name) const
std::map< uint32_t, std::string > IpVdnsMap
bool MoveVDnsEntry(const VmInterface *vmitf, std::string &new_vdns_name, std::string &old_vdns_name, const autogen::VirtualDnsType &vdns_type, bool is_floating)
bool IsDnsHandlerInUse(DnsHandler *handler)
DnsVmRequestSet curr_vm_requests_
void VnNotify(DBEntryBase *entry)
static const Ip4Address ip4_unspec_
DnsBindQueryIndexMap dns_query_index_map_
void ProcessNotify(std::string name, bool is_deleted, bool is_ipam)
bool GetVdnsData(const VnEntry *vn, const Ip4Address &v4_addr, const Ip6Address &v6_addr, std::string &vdns_name, autogen::VirtualDnsType &vdns_type)
bool IsVmRequestDuplicate(DnsHandler::QueryKey *key)
void AddDnsQuery(uint16_t xid, DnsHandler *handler)
DnsBindQueryMap dns_query_map_
void IpamNotify(IFMapNode *node)
DBTableBase::ListenerId Vnlid_
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)
std::pair< uint32_t, std::string > IpVdnsPair
bool UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn, const IpAddress &ip, bool is_deleted)
boost::shared_ptr< DnsFipEntry > DnsFipEntryPtr
DnsProto(Agent *agent, boost::asio::io_context &io)
DefaultServerList def_server_list_
int16_t GetDnsQueryServerIndex(uint16_t xid)
Timer * default_slist_timer_
static const Ip6Address ip6_unspec_
void VrfNotify(DBEntryBase *entry)
std::pair< const VmInterface *, IpVdnsMap > VmDataPair
void DelDnsQueryHandler(DnsHandler *handler)
static const uint32_t kDnsDefaultSlistInterval
void DelVmRequest(DnsHandler::QueryKey *key)
void RegisterIpamCb(Callback cb)
bool GetVDns(const std::string &vdns, autogen::VirtualDnsType *vdns_type)
void RegisterVdnsCb(Callback cb)
const std::string & name() const
IFMapObject * GetObject()
void set_update_floatingip_cb(UpdateFloatingIpFn fn)
const MacAddress & mac() const
const boost::uuids::uuid & GetUuid() const
GlobalQosConfig * global_qos_config() const
void SendMessage(PktModuleName mod, InterTaskMsg *msg)
PktHandler * pkt_handler() const
ProtoWorkQueue work_queue_
static TaskScheduler * GetInstance()
static bool DeleteTimer(Timer *Timer)
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)
bool Start(int time, Handler handler, ErrorHandler error_handler=NULL)
const FloatingIpList & floating_ip_list() const
const VnEntry * vn() const
const Ip4Address & primary_ip_addr() const
const std::string & vm_name() const
const Ip6Address & primary_ip6_addr() const
bool GetIpamVdnsData(const IpAddress &vm_addr, autogen::IpamType *ipam_type, autogen::VirtualDnsType *vdns_type) const
const std::vector< VnIpam > & GetVnIpam() const
const string & GetName() const
std::string GetProject() const
const string & GetName() const
void SetBounded(bool bounded)
void SetSize(size_t size)
std::string ToString() const
bool IsLess(const DnsFipEntry *rhs) const
const VmInterface * interface_
DnsFipEntry(const VnEntry *vn, const IpAddress &fip, const VmInterface *itf)
static const uint8_t kInvalidDscp
uint8_t control_dscp() const