]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: make LLMNR checks conditional 576/head
authorDaniel Mack <daniel@zonque.org>
Sat, 11 Jul 2015 16:37:17 +0000 (12:37 -0400)
committerDaniel Mack <daniel@zonque.org>
Mon, 13 Jul 2015 15:28:30 +0000 (11:28 -0400)
Make all LLMNR related packet inspections conditional to p->protocol.
Use switch-case statements while at it, which will make future additions
more readable.

src/resolve/resolved-dns-packet.c

index 47cc9751ed6d38d3c28d487662df36c9ac52364a..fa0516f8a0c3235f84322c98dc49825003ae6f98 100644 (file)
@@ -166,10 +166,17 @@ int dns_packet_validate_reply(DnsPacket *p) {
         if (DNS_PACKET_OPCODE(p) != 0)
                 return -EBADMSG;
 
-        /* RFC 4795, Section 2.1.1. says to discard all replies with QDCOUNT != 1 */
-        if (p->protocol == DNS_PROTOCOL_LLMNR &&
-            DNS_PACKET_QDCOUNT(p) != 1)
-                return -EBADMSG;
+        switch (p->protocol) {
+        case DNS_PROTOCOL_LLMNR:
+                /* RFC 4795, Section 2.1.1. says to discard all replies with QDCOUNT != 1 */
+                if (DNS_PACKET_QDCOUNT(p) != 1)
+                        return -EBADMSG;
+
+                break;
+
+        default:
+                break;
+        }
 
         return 1;
 }
@@ -192,18 +199,25 @@ int dns_packet_validate_query(DnsPacket *p) {
         if (DNS_PACKET_TC(p))
                 return -EBADMSG;
 
-        /* RFC 4795, Section 2.1.1. says to discard all queries with QDCOUNT != 1 */
-        if (p->protocol == DNS_PROTOCOL_LLMNR &&
-            DNS_PACKET_QDCOUNT(p) != 1)
-                return -EBADMSG;
+        switch (p->protocol) {
+        case DNS_PROTOCOL_LLMNR:
+                /* RFC 4795, Section 2.1.1. says to discard all queries with QDCOUNT != 1 */
+                if (DNS_PACKET_QDCOUNT(p) != 1)
+                        return -EBADMSG;
 
-        /* RFC 4795, Section 2.1.1. says to discard all queries with ANCOUNT != 0 */
-        if (DNS_PACKET_ANCOUNT(p) > 0)
-                return -EBADMSG;
+                /* RFC 4795, Section 2.1.1. says to discard all queries with ANCOUNT != 0 */
+                if (DNS_PACKET_ANCOUNT(p) > 0)
+                        return -EBADMSG;
 
-        /* RFC 4795, Section 2.1.1. says to discard all queries with NSCOUNT != 0 */
-        if (DNS_PACKET_NSCOUNT(p) > 0)
-                return -EBADMSG;
+                /* RFC 4795, Section 2.1.1. says to discard all queries with NSCOUNT != 0 */
+                if (DNS_PACKET_NSCOUNT(p) > 0)
+                        return -EBADMSG;
+
+                break;
+
+        default:
+                break;
+        }
 
         return 1;
 }