]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/sortlist.cc
2 #include "dnsrecords.hh"
9 int SortList::getMaxOrder(const Netmask
& formask
) const
13 auto place
= d_sortlist
.lookup(formask
);
14 if(place
&& place
->first
== formask
) {
15 for(const auto& o
: place
->second
.d_orders
)
16 order
= std::max(order
, o
->second
); // aki, shouldn't this be o.second?
22 void SortList::addEntry(const Netmask
& formask
, const Netmask
& valmask
, int order
)
25 order
=getMaxOrder(formask
);
28 // cout<<"Adding for netmask "<<formask.toString()<<" the order instruction that "<<valmask.toString()<<" is order "<<order<<endl;
29 d_sortlist
.insert(formask
).second
.d_orders
.insert(valmask
).second
=order
;
32 std::unique_ptr
<SortListOrderCmp
> SortList::getOrderCmp(const ComboAddress
& who
) const
34 if(!d_sortlist
.match(who
)) {
35 return std::unique_ptr
<SortListOrderCmp
>();
37 auto fnd
= d_sortlist
.lookup(who
);
38 // cerr<<"Returning sort order for "<<who.toString()<<", have "<<fnd->second.d_orders.size()<<" entries"<<endl;
39 return make_unique
<SortListOrderCmp
>(fnd
->second
);
42 // call this with **stable_sort**
43 bool SortListOrderCmp::operator()(const DNSRecord
& ar
, const DNSRecord
& br
) const
45 bool aAddr
= (ar
.d_type
== QType::A
|| ar
.d_type
== QType::AAAA
);
46 bool bAddr
= (br
.d_type
== QType::A
|| br
.d_type
== QType::AAAA
);
48 // anything address related is always 'larger', rest is equal
52 else if(!aAddr
&& bAddr
)
54 else if(!aAddr
&& !bAddr
)
58 int aOrder
=std::numeric_limits
<int>::max();
61 ComboAddress a
=getAddr(ar
), b
=getAddr(br
);
63 if(d_slo
.d_orders
.match(a
))
64 aOrder
= d_slo
.d_orders
.lookup(a
)->second
;
66 // cout<<"Could not find anything for "<<a.toString()<<" in our orders!"<<endl;
68 if(d_slo
.d_orders
.match(b
))
69 bOrder
= d_slo
.d_orders
.lookup(b
)->second
;
71 // cout<<"Could not find anything for "<<b.toString()<<" in our orders!"<<endl;
73 return aOrder
< bOrder
;