Merge branch 'zero-flag' into 'master'

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

See merge request !580
This commit is contained in:
Daniel Salzman 2016-08-22 14:12:04 +02:00
commit fa85543516
4 changed files with 30 additions and 15 deletions

View file

@ -328,6 +328,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. */
knot_pkt_clear_payload(pkt);

View file

@ -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()

View file

@ -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):

View file

@ -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: