From 78608c6c3a57151d9d2522b3fefe15f44c9e43a3 Mon Sep 17 00:00:00 2001 From: Filip Siroky Date: Mon, 22 Aug 2016 13:14:30 +0200 Subject: [PATCH] issue #476: fixed zero flag not being zeroed + added test --- src/libknot/packet/pkt.c | 1 + tests-extra/tests/basic/flags/test.py | 31 ++++++++++++++++----------- tests-extra/tools/dnstest/response.py | 10 +++++++-- tests-extra/tools/dnstest/server.py | 3 +++ 4 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/libknot/packet/pkt.c b/src/libknot/packet/pkt.c index ca9ffbb09..8e128f020 100644 --- a/src/libknot/packet/pkt.c +++ b/src/libknot/packet/pkt.c @@ -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); diff --git a/tests-extra/tests/basic/flags/test.py b/tests-extra/tests/basic/flags/test.py index 7d487a224..6370712ea 100644 --- a/tests-extra/tests/basic/flags/test.py +++ b/tests-extra/tests/basic/flags/test.py @@ -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() diff --git a/tests-extra/tools/dnstest/response.py b/tests-extra/tools/dnstest/response.py index fb32b6a71..2df0effb1 100644 --- a/tests-extra/tools/dnstest/response.py +++ b/tests-extra/tools/dnstest/response.py @@ -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): diff --git a/tests-extra/tools/dnstest/server.py b/tests-extra/tools/dnstest/server.py index 0ea2ca136..891806ed5 100644 --- a/tests-extra/tools/dnstest/server.py +++ b/tests-extra/tools/dnstest/server.py @@ -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: