vector<uint8_t> packet;
ComboAddress rem;
DNSName qname;
- uint16_t qtype;
+ uint16_t qtype, qclass;
};
vector<item> items;
items.reserve(1000);
i.qname=DNSName(std::to_string(random()));
i.qname += suffix;
i.qtype = random() % 0xff;
+ i.qclass = 1;
i.rem=ComboAddress("127.0.0.1");
i.rem.sin4.sin_addr.s_addr = random();
DNSPacketWriter pw(i.packet, i.qname, i.qtype);
dt.set();
for(int n=0; n < times; ++n) {
const item& i = items[n % items.size()];
- DNSQuestion dq(&i.qname, i.qtype, &i.rem, &i.rem, (struct dnsheader*)&i.packet[0], i.packet.size(), i.packet.size(), false);
+ DNSQuestion dq(&i.qname, i.qtype, i.qclass, &i.rem, &i.rem, (struct dnsheader*)&i.packet[0], i.packet.size(), i.packet.size(), false);
if(rule->matches(&dq))
matches++;
}
}
return std::shared_ptr<DNSRule>(new QTypeRule(qtype));
});
+ g_lua.writeFunction("QClassRule", [](int c) {
+ return std::shared_ptr<DNSRule>(new QClassRule(c));
+ });
+
g_lua.writeFunction("AndRule", [](vector<pair<int, std::shared_ptr<DNSRule> > >a) {
return std::shared_ptr<DNSRule>(new AndRule(a));
g_lua.registerMember<const ComboAddress (DNSQuestion::*)>("localaddr", [](const DNSQuestion& dq) -> const ComboAddress { return *dq.local; }, [](DNSQuestion& dq, const ComboAddress newLocal) { (void) newLocal; });
g_lua.registerMember<const DNSName (DNSQuestion::*)>("qname", [](const DNSQuestion& dq) -> const DNSName { return *dq.qname; }, [](DNSQuestion& dq, const DNSName newName) { (void) newName; });
g_lua.registerMember<uint16_t (DNSQuestion::*)>("qtype", [](const DNSQuestion& dq) -> uint16_t { return dq.qtype; }, [](DNSQuestion& dq, uint16_t newType) { (void) newType; });
- g_lua.registerMember<uint16_t (DNSQuestion::*)>("qclass", [](const DNSQuestion& dq) -> uint16_t { return dq.qclass; });
+ g_lua.registerMember<uint16_t (DNSQuestion::*)>("qclass", [](const DNSQuestion& dq) -> uint16_t { return dq.qclass; }, [](DNSQuestion& dq, uint16_t newClass) { (void) newClass; });
g_lua.registerMember<int (DNSQuestion::*)>("rcode", [](const DNSQuestion& dq) -> int { return dq.dh->rcode; }, [](DNSQuestion& dq, int newRCode) { dq.dh->rcode = newRCode; });
g_lua.registerMember<const ComboAddress (DNSQuestion::*)>("remoteaddr", [](const DNSQuestion& dq) -> const ComboAddress { return *dq.remote; }, [](DNSQuestion& dq, const ComboAddress newRemote) { (void) newRemote; });
/* DNSDist DNSQuestion */
uint16_t d_qtype;
};
+class QClassRule : public DNSRule
+{
+public:
+ QClassRule(uint16_t qclass) : d_qclass(qclass)
+ {
+ }
+ bool matches(const DNSQuestion* dq) const override
+ {
+ return d_qclass == dq->qclass;
+ }
+ string toString() const override
+ {
+ return "qclass=="+std::to_string(d_qclass);
+ }
+private:
+ uint16_t d_qclass;
+};
+
+
class TCPRule : public DNSRule
{
public:
}
string toString() const override
{
- return "!"+ d_rule->toString();
+ return "!("+ d_rule->toString()+")";
}
private:
shared_ptr<DNSRule> d_rule;