Commit 78608c6c authored by Filip Siroky's avatar Filip Siroky

issue #476: fixed zero flag not being zeroed + added test

parent 54c46b59
......@@ -326,6 +326,7 @@ int knot_pkt_init_response(knot_pkt_t *pkt, const knot_pkt_t *query)
knot_wire_clear_ad(pkt->wire);
knot_wire_clear_ra(pkt->wire);
knot_wire_clear_aa(pkt->wire);
knot_wire_clear_z(pkt->wire);
/* Clear payload. */
pkt_clear_payload(pkt);
......
......@@ -20,67 +20,72 @@ t.start()
# RD flag preservation.
resp = knot.dig("flags", "NS", flags="RD")
resp.check(flags="QR AA RD", noflags="TC RA AD CD")
resp.check(flags="QR AA RD", noflags="TC RA AD CD Z")
resp.cmp(bind)
# CD flag preservation.
resp = knot.dig("flags", "NS", flags="CD")
resp.check(flags="QR AA CD", noflags="TC RA AD RD")
resp.check(flags="QR AA CD", noflags="TC RA AD RD Z")
resp.cmp(bind)
# TC flag must be cleared
resp = knot.dig("flags", "NS", flags="TC")
resp.check(flags="QR AA", noflags="TC RA AD CD RD")
resp.check(flags="QR AA", noflags="TC RA AD CD RD Z")
resp.cmp(bind)
# AD flag must be cleared
resp = knot.dig("flags", "NS", flags="AD")
resp.check(flags="QR AA", noflags="TC RA AD CD RD")
resp.check(flags="QR AA", noflags="TC RA AD CD RD Z")
resp.cmp(bind)
# AA flag must be cleared
resp = knot.dig("sub.flags", "NS", flags="AA")
resp.check(flags="QR", noflags="AA TC RD RA AD CD")
resp.check(flags="QR", noflags="AA TC RD RA AD CD Z")
resp.cmp(bind, additional=True)
# RA flag must be cleared
resp = knot.dig("flags", "NS", flags="RA")
resp.check(flags="QR AA", noflags="TC RA AD CD RD")
resp.check(flags="QR AA", noflags="TC RA AD CD RD Z")
resp.cmp(bind)
# Z flag must be cleared
resp = knot.dig("flags", "NS", flags="Z")
resp.check(flags="QR AA", noflags="TC RA AD CD RD Z")
resp.cmp(bind)
# NS record for delegated subdomain (not authoritative).
resp = knot.dig("sub.flags", "NS")
resp.check(flags="QR", noflags="AA TC RD RA AD CD")
resp.check(flags="QR", noflags="AA TC RD RA AD CD Z")
resp.cmp(bind, additional=True)
# Glue record for delegated subdomain (not authoritative).
resp = knot.dig("ns.sub.flags", "A")
resp.check(flags="QR", noflags="AA TC RD RA AD CD")
resp.check(flags="QR", noflags="AA TC RD RA AD CD Z")
resp.cmp(bind)
# Check maximal UDP payload which fits into a response message.
resp = knot.dig("512resp.flags", "TXT", udp=True)
resp.check(flags="QR AA", noflags="TC RD RA AD CD")
resp.check(flags="QR AA", noflags="TC RD RA AD CD Z")
resp.cmp(bind)
# TC bit - UDP.
resp = knot.dig("513resp.flags", "TXT", udp=True)
resp.check(flags="QR AA TC", noflags="RD RA AD CD")
resp.check(flags="QR AA TC", noflags="RD RA AD CD Z")
resp.cmp(bind)
# No TC bit - TCP.
resp = knot.dig("513resp.flags", "TXT", udp=False)
resp.check(flags="QR AA", noflags="TC RD RA AD CD")
resp.check(flags="QR AA", noflags="TC RD RA AD CD Z")
resp.cmp(bind)
# Check ANY over UDP (expects TC=1)
resp = knot.dig("flags", "ANY", udp=True)
resp.check(flags="QR AA TC", noflags="RD RA AD CD")
resp.check(flags="QR AA TC", noflags="RD RA AD CD Z")
# nothing to compare
# Check ANY over TCP (expects TC=0)
resp = knot.dig("flags", "ANY", udp=False)
resp.check(flags="QR AA", noflags="TC RD RA AD CD")
resp.check(flags="QR AA", noflags="TC RD RA AD CD Z")
resp.cmp(bind)
t.end()
......@@ -37,12 +37,18 @@ class Response(object):
def _check_flags(self, flags, noflags):
flag_names = flags.split()
for flag in flag_names:
flag_val = dns.flags.from_text(flag)
if flag == "Z":
flag_val = 64
else:
flag_val = dns.flags.from_text(flag)
isset(self.resp.flags & flag_val, "%s FLAG" % flag)
flag_names = noflags.split()
for flag in flag_names:
flag_val = dns.flags.from_text(flag)
if flag == "Z":
flag_val = 64
else:
flag_val = dns.flags.from_text(flag)
isset(not(self.resp.flags & flag_val), "NO %s FLAG" % flag)
def _check_eflags(self, eflags, noeflags):
......
......@@ -434,6 +434,9 @@ class Server(object):
elif flag == "CD":
query.flags |= dns.flags.CD
dig_flags += " +cd"
elif flag == "Z":
query.flags |= 64
dig_flags += " +z"
# Set EDNS.
if edns != None or bufsize or nsid:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment