if(ret.size()) {
orderAndShuffle(ret);
if(auto sl = luaconfsLocal->sortlist.getOrderCmp(dc->d_remote)) {
- sort(ret.begin(), ret.end(), *sl);
+ stable_sort(ret.begin(), ret.end(), *sl);
variableAnswer=true;
}
}
return aOrder < bOrder;
}
+// call this with **stable_sort**
bool SortListOrderCmp::operator()(const DNSRecord& ar, const DNSRecord& br) const
{
- if(ar.d_type < br.d_type)
- return true;
- if(ar.d_type > br.d_type)
- return false;
+ bool aAddr = (ar.d_type == QType::A || ar.d_type == QType::AAAA);
+ bool bAddr = (br.d_type == QType::A || br.d_type == QType::AAAA);
- if(ar.d_type != QType::A && ar.d_type != QType::AAAA)
- return false; // all other types are equal among themselves
+ // anything address related is always 'larger', rest is equal
+
+ if(aAddr && !bAddr)
+ return false;
+ else if(!aAddr && bAddr)
+ return true;
+ else if(!aAddr && !bAddr)
+ return true;
+
int aOrder=std::numeric_limits<int>::max();
int bOrder=aOrder;