19
19
#include " oper/route_common.h"
20
20
#include < fstream>
21
21
22
+ const Ip4Address DnsProto::ip4_unspec_ (0 );
23
+ const Ip6Address DnsProto::ip6_unspec_ = Ip6Address::from_string(" ::" );
24
+
22
25
void DnsProto::IoShutdown () {
23
26
BindResolver::Shutdown ();
24
27
@@ -138,12 +141,7 @@ void DnsProto::InterfaceNotify(DBEntryBase *entry) {
138
141
for (VmInterface::FloatingIpSet::iterator it = fip.list_ .begin (),
139
142
next = fip.list_ .begin (); it != fip.list_ .end (); it = next) {
140
143
++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 );
147
145
}
148
146
} else {
149
147
autogen::VirtualDnsType vdns_type;
@@ -177,10 +175,8 @@ void DnsProto::InterfaceNotify(DBEntryBase *entry) {
177
175
for (VmInterface::FloatingIpSet::iterator it = fip.list_ .begin ();
178
176
it != fip.list_ .end (); ++it) {
179
177
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 );
184
180
}
185
181
}
186
182
}
@@ -191,7 +187,8 @@ void DnsProto::VnNotify(DBEntryBase *entry) {
191
187
const VnEntry *vn = static_cast <const VnEntry *>(entry);
192
188
if (vn->IsDeleted ()) {
193
189
// 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 );
195
192
DnsFipEntryPtr key (new DnsFipEntry (vn, ip_key, NULL ));
196
193
DnsFipSet::iterator it = fip_list_.upper_bound (key);
197
194
while (it != fip_list_.end ()) {
@@ -221,7 +218,7 @@ void DnsProto::VnNotify(DBEntryBase *entry) {
221
218
vdns_name, vdns_type);
222
219
}
223
220
}
224
- Ip4Address ip_key (0 );
221
+ IpAddress ip_key = Ip4Address (0 );
225
222
DnsFipEntryPtr key (new DnsFipEntry (vn, ip_key, NULL ));
226
223
DnsFipSet::iterator it = fip_list_.upper_bound (key);
227
224
while (it != fip_list_.end ()) {
@@ -231,8 +228,15 @@ void DnsProto::VnNotify(DBEntryBase *entry) {
231
228
break ;
232
229
}
233
230
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,
236
240
fip_vdns_name, fip_vdns_type);
237
241
CheckForFipUpdate (entry, fip_vdns_name, fip_vdns_type);
238
242
++it;
@@ -299,8 +303,15 @@ void DnsProto::ProcessNotify(std::string name, bool is_deleted, bool is_ipam) {
299
303
std::string fip_vdns_name;
300
304
DnsFipEntry *entry = (*it).get ();
301
305
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,
304
315
fip_vdns_name, fip_vdns_type);
305
316
CheckForFipUpdate (entry, fip_vdns_name, fip_vdns_type);
306
317
++it;
@@ -338,10 +349,17 @@ void DnsProto::CheckForFipUpdate(DnsFipEntry *entry, std::string &vdns_name,
338
349
if (!GetFipName (entry->interface_ , vdns_type,
339
350
entry->floating_ip_ , fip_name))
340
351
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
+ }
343
361
if (UpdateDnsEntry (entry->interface_ , entry->vn_ , fip_name,
344
- vdns_name, entry-> floating_ip_ , ip6, true , false )) {
362
+ vdns_name, ip4 , ip6, true , false )) {
345
363
entry->vdns_name_ .assign (vdns_name);
346
364
entry->fip_name_ = fip_name;
347
365
}
@@ -446,12 +464,19 @@ bool DnsProto::SendUpdateDnsEntry(const VmInterface *vmitf,
446
464
447
465
// Update the floating ip entries
448
466
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
+ }
451
476
bool is_floating = true ;
452
477
std::string vdns_name;
453
478
autogen::VirtualDnsType vdns_type;
454
- GetVdnsData (vn, ip , ip6, vdns_name, vdns_type);
479
+ GetVdnsData (vn, ip4 , ip6, vdns_name, vdns_type);
455
480
DnsFipEntryPtr key (new DnsFipEntry (vn, ip, vmitf));
456
481
DnsFipSet::iterator it = fip_list_.find (key);
457
482
if (it == fip_list_.end ()) {
@@ -461,7 +486,7 @@ bool DnsProto::UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn,
461
486
if (!GetFipName (vmitf, vdns_type, ip, fip_name))
462
487
vdns_name = " " ;
463
488
if (!UpdateDnsEntry (vmitf, vn, fip_name,
464
- vdns_name, ip , ip6, is_floating, false ))
489
+ vdns_name, ip4 , ip6, is_floating, false ))
465
490
vdns_name = " " ;
466
491
key.get ()->vdns_name_ = vdns_name;
467
492
key.get ()->fip_name_ = fip_name;
@@ -470,7 +495,7 @@ bool DnsProto::UpdateFloatingIp(const VmInterface *vmitf, const VnEntry *vn,
470
495
if (is_deleted) {
471
496
std::string fip_name;
472
497
UpdateDnsEntry (vmitf, vn, (*it)->fip_name_ ,
473
- (*it)->vdns_name_ , ip , ip6, is_floating, true );
498
+ (*it)->vdns_name_ , ip4 , ip6, is_floating, true );
474
499
fip_list_.erase (key);
475
500
} else {
476
501
DnsFipEntry *entry = (*it).get ();
@@ -583,7 +608,7 @@ bool DnsProto::GetVdnsData(const VnEntry *vn, const Ip4Address &v4_addr,
583
608
584
609
bool DnsProto::GetFipName (const VmInterface *vmitf,
585
610
const autogen::VirtualDnsType &vdns_type,
586
- const Ip4Address &ip, std::string &fip_name) const {
611
+ const IpAddress &ip, std::string &fip_name) const {
587
612
std::string fip_name_notation =
588
613
boost::to_lower_copy (vdns_type.floating_ip_record );
589
614
@@ -714,7 +739,7 @@ bool DnsProto::IsVmRequestDuplicate(DnsHandler::QueryKey *key) {
714
739
return curr_vm_requests_.find (*key) != curr_vm_requests_.end ();
715
740
}
716
741
717
- DnsProto::DnsFipEntry::DnsFipEntry (const VnEntry *vn, const Ip4Address &fip,
742
+ DnsProto::DnsFipEntry::DnsFipEntry (const VnEntry *vn, const IpAddress &fip,
718
743
const VmInterface *itf)
719
744
: vn_(vn), floating_ip_(fip), interface_(itf) {
720
745
}
0 commit comments