Skip to content

Commit eeba013

Browse files
committed
a vDNS improvement: a bug associated with requests to partial names (e.g., yandex.) has been fixed, support for resolution of IPv6 FIP addresses
Change-Id: I427c5358e8951dab176fb161e9dae8b02063e14e Signed-off-by: Matvey Kraposhin <mkraposhin@gmail.com>
1 parent 6a68c0f commit eeba013

File tree

6 files changed

+78
-39
lines changed

6 files changed

+78
-39
lines changed

src/vnsw/agent/oper/interface.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ class InterfaceTable : public AgentOperDBTable {
322322
// floating ip in-sync. This callback is defined to avoid linking error
323323
// when DNS is not enabled
324324
typedef boost::function<void(VmInterface *, const VnEntry *,
325-
const Ip4Address &, bool)> UpdateFloatingIpFn;
325+
const IpAddress &, bool)> UpdateFloatingIpFn;
326326

327327
InterfaceTable(DB *db, const std::string &name);
328328
virtual ~InterfaceTable() { }

src/vnsw/agent/oper/vm_interface.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -2155,9 +2155,9 @@ bool VmInterface::FloatingIp::AddL3(const Agent *agent,
21552155
CommunityList(), vmi->label(), kInterface);
21562156

21572157
InterfaceTable *table = static_cast<InterfaceTable *>(vmi->get_table());
2158-
if (floating_ip_.is_v4() && table->update_floatingip_cb().empty()==false) {
2159-
table->update_floatingip_cb()(vmi, vn_.get(), floating_ip_.to_v4(),
2160-
false);
2158+
if (table->update_floatingip_cb().empty()==false) {
2159+
table->update_floatingip_cb()(vmi, vn_.get(), floating_ip_,
2160+
false);
21612161
//TODO:: callback for DNS handling
21622162
}
21632163

@@ -2174,9 +2174,9 @@ bool VmInterface::FloatingIp::DeleteL3(const Agent *agent,
21742174
vmi->DeleteRoute(vrf_.get()->GetName(), floating_ip_, plen);
21752175

21762176
InterfaceTable *table = static_cast<InterfaceTable *>(vmi->get_table());
2177-
if (floating_ip_.is_v4() && table->update_floatingip_cb().empty()==false) {
2178-
table->update_floatingip_cb()(vmi, vn_.get(), floating_ip_.to_v4(),
2179-
true);
2177+
if (table->update_floatingip_cb().empty()==false) {
2178+
table->update_floatingip_cb()(vmi, vn_.get(), floating_ip_,
2179+
true);
21802180
//TODO:: callback for DNS handling
21812181
}
21822182
return true;

src/vnsw/agent/services/dns_handler.cc

+10
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,16 @@ void DnsHandler::SendDnsResponse() {
970970

971971
void DnsHandler::UpdateQueryNames() {
972972
for (DnsItems::iterator it = items_.begin(); it != items_.end(); ++it) {
973+
// do not append domain for empty string (request to root ns)
974+
if (it->name.size() == 0) {
975+
return;
976+
}
977+
978+
// do not append domain in case of NS query
979+
if (it->type == DNS_NS_RECORD) {
980+
return;
981+
}
982+
973983
if (it->name.find('.', 0) == std::string::npos) {
974984
it->name.append(".");
975985
it->name.append(vdns_type_.domain_name);

src/vnsw/agent/services/dns_proto.cc

+51-26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include "oper/route_common.h"
2020
#include <fstream>
2121

22+
const Ip4Address DnsProto::ip4_unspec_(0);
23+
const Ip6Address DnsProto::ip6_unspec_ = Ip6Address::from_string("::");
24+
2225
void DnsProto::IoShutdown() {
2326
BindResolver::Shutdown();
2427

@@ -138,12 +141,7 @@ void DnsProto::InterfaceNotify(DBEntryBase *entry) {
138141
for (VmInterface::FloatingIpSet::iterator it = fip.list_.begin(),
139142
next = fip.list_.begin(); it != fip.list_.end(); it = next) {
140143
++next;
141-
if (it->floating_ip_.is_v4()) {
142-
UpdateFloatingIp(vmitf, it->vn_.get(), it->floating_ip_.to_v4(),
143-
true);
144-
} else {
145-
//TODO: Ipv6 handling
146-
}
144+
UpdateFloatingIp(vmitf, it->vn_.get(), it->floating_ip_,true);
147145
}
148146
} else {
149147
autogen::VirtualDnsType vdns_type;
@@ -177,10 +175,8 @@ void DnsProto::InterfaceNotify(DBEntryBase *entry) {
177175
for (VmInterface::FloatingIpSet::iterator it = fip.list_.begin();
178176
it != fip.list_.end(); ++it) {
179177
if (it->Installed()) {
180-
if (it->floating_ip_.is_v4()) {
181-
UpdateFloatingIp(vmitf, it->vn_.get(),
182-
it->floating_ip_.to_v4(), false);
183-
}
178+
UpdateFloatingIp(vmitf, it->vn_.get(),
179+
it->floating_ip_, false);
184180
}
185181
}
186182
}
@@ -191,7 +187,8 @@ void DnsProto::VnNotify(DBEntryBase *entry) {
191187
const VnEntry *vn = static_cast<const VnEntry *>(entry);
192188
if (vn->IsDeleted()) {
193189
// remove floating ip entries from this vn in floating ip list
194-
Ip4Address ip_key(0);
190+
// Ip4Address is the smallest address
191+
IpAddress ip_key = Ip4Address(0);
195192
DnsFipEntryPtr key(new DnsFipEntry(vn, ip_key, NULL));
196193
DnsFipSet::iterator it = fip_list_.upper_bound(key);
197194
while (it != fip_list_.end()) {
@@ -221,7 +218,7 @@ void DnsProto::VnNotify(DBEntryBase *entry) {
221218
vdns_name, vdns_type);
222219
}
223220
}
224-
Ip4Address ip_key(0);
221+
IpAddress ip_key = Ip4Address(0);
225222
DnsFipEntryPtr key(new DnsFipEntry(vn, ip_key, NULL));
226223
DnsFipSet::iterator it = fip_list_.upper_bound(key);
227224
while (it != fip_list_.end()) {
@@ -231,8 +228,15 @@ void DnsProto::VnNotify(DBEntryBase *entry) {
231228
break;
232229
}
233230
autogen::VirtualDnsType fip_vdns_type;
234-
Ip6Address ip6; // TODO: update once floating ipv6 support is added
235-
GetVdnsData(entry->vn_, entry->floating_ip_, ip6,
231+
Ip4Address ip4 = ip4_unspec_;
232+
Ip6Address ip6 = ip6_unspec_;
233+
if (entry->floating_ip_.is_v4()) {
234+
ip4 = entry->floating_ip_.to_v4();
235+
}
236+
if (entry->floating_ip_.is_v6()) {
237+
ip6 = entry->floating_ip_.to_v6();
238+
}
239+
GetVdnsData(entry->vn_, ip4, ip6,
236240
fip_vdns_name, fip_vdns_type);
237241
CheckForFipUpdate(entry, fip_vdns_name, fip_vdns_type);
238242
++it;
@@ -299,8 +303,15 @@ void DnsProto::ProcessNotify(std::string name, bool is_deleted, bool is_ipam) {
299303
std::string fip_vdns_name;
300304
DnsFipEntry *entry = (*it).get();
301305
autogen::VirtualDnsType fip_vdns_type;
302-
Ip6Address ip6; // TODO: update once floating ipv6 support is added
303-
GetVdnsData(entry->vn_, entry->floating_ip_, ip6,
306+
Ip4Address ip4 = ip4_unspec_;
307+
Ip6Address ip6 = ip6_unspec_;
308+
if (entry->floating_ip_.is_v4()) {
309+
ip4 = entry->floating_ip_.to_v4();
310+
}
311+
if (entry->floating_ip_.is_v6()) {
312+
ip6 = entry->floating_ip_.to_v6();
313+
}
314+
GetVdnsData(entry->vn_, ip4, ip6,
304315
fip_vdns_name, fip_vdns_type);
305316
CheckForFipUpdate(entry, fip_vdns_name, fip_vdns_type);
306317
++it;
@@ -338,10 +349,17 @@ void DnsProto::CheckForFipUpdate(DnsFipEntry *entry, std::string &vdns_name,
338349
if (!GetFipName(entry->interface_, vdns_type,
339350
entry->floating_ip_, fip_name))
340351
vdns_name = "";
341-
// TODO: update once floating ipv6 support is added
342-
Ip6Address ip6;
352+
353+
Ip4Address ip4 = ip4_unspec_;
354+
Ip6Address ip6 = ip6_unspec_;
355+
if (entry->floating_ip_.is_v4()) {
356+
ip4 = entry->floating_ip_.to_v4();
357+
}
358+
if (entry->floating_ip_.is_v6()) {
359+
ip6 = entry->floating_ip_.to_v6();
360+
}
343361
if (UpdateDnsEntry(entry->interface_, entry->vn_, fip_name,
344-
vdns_name, entry->floating_ip_, ip6, true, false)) {
362+
vdns_name, ip4, ip6, true, false)) {
345363
entry->vdns_name_.assign(vdns_name);
346364
entry->fip_name_ = fip_name;
347365
}
@@ -446,12 +464,19 @@ bool DnsProto::SendUpdateDnsEntry(const VmInterface *vmitf,
446464

447465
// Update the floating ip entries
448466
bool DnsProto::UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn,
449-
const Ip4Address &ip, bool is_deleted) {
450-
Ip6Address ip6; // TODO: update once floating ipv6 support is added
467+
const IpAddress &ip, bool is_deleted) {
468+
Ip4Address ip4 = ip4_unspec_;
469+
Ip6Address ip6 = ip6_unspec_;
470+
if (ip.is_v6()) {
471+
ip6 = ip.to_v6();
472+
}
473+
if (ip.is_v4()) {
474+
ip4 = ip.to_v4();
475+
}
451476
bool is_floating = true;
452477
std::string vdns_name;
453478
autogen::VirtualDnsType vdns_type;
454-
GetVdnsData(vn, ip, ip6, vdns_name, vdns_type);
479+
GetVdnsData(vn, ip4, ip6, vdns_name, vdns_type);
455480
DnsFipEntryPtr key(new DnsFipEntry(vn, ip, vmitf));
456481
DnsFipSet::iterator it = fip_list_.find(key);
457482
if (it == fip_list_.end()) {
@@ -461,7 +486,7 @@ bool DnsProto::UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn,
461486
if (!GetFipName(vmitf, vdns_type, ip, fip_name))
462487
vdns_name = "";
463488
if (!UpdateDnsEntry(vmitf, vn, fip_name,
464-
vdns_name, ip, ip6, is_floating, false))
489+
vdns_name, ip4, ip6, is_floating, false))
465490
vdns_name = "";
466491
key.get()->vdns_name_ = vdns_name;
467492
key.get()->fip_name_ = fip_name;
@@ -470,7 +495,7 @@ bool DnsProto::UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn,
470495
if (is_deleted) {
471496
std::string fip_name;
472497
UpdateDnsEntry(vmitf, vn, (*it)->fip_name_,
473-
(*it)->vdns_name_, ip, ip6, is_floating, true);
498+
(*it)->vdns_name_, ip4, ip6, is_floating, true);
474499
fip_list_.erase(key);
475500
} else {
476501
DnsFipEntry *entry = (*it).get();
@@ -583,7 +608,7 @@ bool DnsProto::GetVdnsData(const VnEntry *vn, const Ip4Address &v4_addr,
583608

584609
bool DnsProto::GetFipName(const VmInterface *vmitf,
585610
const autogen::VirtualDnsType &vdns_type,
586-
const Ip4Address &ip, std::string &fip_name) const {
611+
const IpAddress &ip, std::string &fip_name) const {
587612
std::string fip_name_notation =
588613
boost::to_lower_copy(vdns_type.floating_ip_record);
589614

@@ -714,7 +739,7 @@ bool DnsProto::IsVmRequestDuplicate(DnsHandler::QueryKey *key) {
714739
return curr_vm_requests_.find(*key) != curr_vm_requests_.end();
715740
}
716741

717-
DnsProto::DnsFipEntry::DnsFipEntry(const VnEntry *vn, const Ip4Address &fip,
742+
DnsProto::DnsFipEntry::DnsFipEntry(const VnEntry *vn, const IpAddress &fip,
718743
const VmInterface *itf)
719744
: vn_(vn), floating_ip_(fip), interface_(itf) {
720745
}

src/vnsw/agent/services/dns_proto.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class VmInterface;
1313
class IFMapNode;
1414

1515
class DnsProto : public Proto {
16+
17+
static const Ip4Address ip4_unspec_;
18+
static const Ip6Address ip6_unspec_;
19+
1620
public:
1721
static const uint32_t kDnsDefaultTtl = 84600;
1822
static const uint32_t kDnsDefaultSlistInterval =
@@ -114,12 +118,12 @@ class DnsProto : public Proto {
114118
};
115119

116120
struct DnsFipEntry {
117-
DnsFipEntry(const VnEntry *vn, const Ip4Address &fip,
121+
DnsFipEntry(const VnEntry *vn, const IpAddress &fip,
118122
const VmInterface *itf);
119123
virtual ~DnsFipEntry();
120124
bool IsLess(const DnsFipEntry *rhs) const;
121125
const VnEntry *vn_;
122-
Ip4Address floating_ip_;
126+
IpAddress floating_ip_;
123127
const VmInterface *interface_;
124128
std::string vdns_name_;
125129
std::string fip_name_;
@@ -159,7 +163,7 @@ class DnsProto : public Proto {
159163
const autogen::VirtualDnsType &vdns_type,
160164
bool is_floating, bool is_delete);
161165
bool UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn,
162-
const Ip4Address &ip, bool is_deleted);
166+
const IpAddress &ip, bool is_deleted);
163167
void IpamNotify(IFMapNode *node);
164168
void VdnsNotify(IFMapNode *node);
165169
uint16_t GetTransId();
@@ -246,7 +250,7 @@ class DnsProto : public Proto {
246250
autogen::VirtualDnsType &vdns_type);
247251
bool GetFipName(const VmInterface *vmitf,
248252
const autogen::VirtualDnsType &vdns_type,
249-
const Ip4Address &ip, std::string &fip_name) const;
253+
const IpAddress &ip, std::string &fip_name) const;
250254

251255
uint16_t xid_;
252256
DnsUpdateSet update_set_;

src/vnsw/agent/services/services_sandesh.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1271,9 +1271,9 @@ void FipVdnsDataReq::HandleRequest() const {
12711271
while (it != fip_list.end()) {
12721272
FipVdnsEntry entry;
12731273
const DnsProto::DnsFipEntry *fip = (*it).get();
1274-
Ip4Address ip4(fip->floating_ip_);
1274+
IpAddress ip(fip->floating_ip_);
12751275
entry.set_vn(fip->vn_->GetName());
1276-
entry.set_ip(ip4.to_string());
1276+
entry.set_ip(ip.to_string());
12771277
entry.set_vm_interface(fip->interface_->name());
12781278
entry.set_vdns_name(fip->vdns_name_);
12791279
list.push_back(entry);

0 commit comments

Comments
 (0)