about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-05-06 08:03:24 +0000
committerUlrich Drepper <drepper@redhat.com>2006-05-06 08:03:24 +0000
commit697e162863c5e32a5de03688d47151851ab21eb9 (patch)
treeec41be6cad6a29041fcc56424352b7282815930f
parentacf82eaf270b410e49dfe45fa836f1ba41b62bb6 (diff)
downloadglibc-697e162863c5e32a5de03688d47151851ab21eb9.tar.gz
glibc-697e162863c5e32a5de03688d47151851ab21eb9.tar.xz
glibc-697e162863c5e32a5de03688d47151851ab21eb9.zip
* include/arpa/nameser.h: Add optimizations for NS_GET16 and NS_GET32.
	* resolv/res_send.c (res_nameinquery): Use NS_GET16 directly
	instead of ns_get16.
	(res_queriesmatch): Likewise.  Minor optimization.
-rw-r--r--ChangeLog6
-rw-r--r--include/arpa/nameser.h27
-rw-r--r--resolv/res_send.c21
3 files changed, 46 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 3d8a63fc71..065f64d007 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2006-05-06  Ulrich Drepper  <drepper@redhat.com>
 
+	* include/arpa/nameser.h: Add optimizations for NS_GET16 and NS_GET32.
+
+	* resolv/res_send.c (res_nameinquery): Use NS_GET16 directly
+	instead of ns_get16.
+	(res_queriesmatch): Likewise.  Minor optimization.
+
 	[BZ #2499]
 	* resolv/res_query.c (__libc_res_nquery): If answerp != NULL,
 	__libc_res_nsend might reallocate the buffer for the answer.  In
diff --git a/include/arpa/nameser.h b/include/arpa/nameser.h
index 944fe732a6..09bd504754 100644
--- a/include/arpa/nameser.h
+++ b/include/arpa/nameser.h
@@ -1 +1,28 @@
 #include <resolv/arpa/nameser.h>
+
+/* If the machine allows unaligned access we can do better than using
+   the NS_GET16, NS_GET32, NS_PUT16, and NS_PUT32 macros from the
+   installed header.  */
+#include <string.h>
+#include <stdint.h>
+#include <netinet/in.h>
+
+#if _STRING_ARCH_unaligned
+
+# undef NS_GET16
+# define NS_GET16(s, cp) \
+  do {									      \
+    uint16_t *t_cp = (uint16_t *) (cp);					      \
+    (s) = ntohs (*t_cp);						      \
+    (cp) += NS_INT16SZ;							      \
+  } while (0)
+
+# undef NS_GET32
+# define NS_GET32(s, cp) \
+  do {									      \
+    uint32_t *t_cp = (uint32_t *) (cp);					      \
+    (s) = ntohl (*t_cp);						      \
+    (cp) += NS_INT32SZ;							      \
+  } while (0)
+
+#endif
diff --git a/resolv/res_send.c b/resolv/res_send.c
index ff7be11509..4bcb746159 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -267,8 +267,8 @@ res_nameinquery(const char *name, int type, int class,
 		cp += n;
 		if (cp + 2 * INT16SZ > eom)
 			return (-1);
-		ttype = ns_get16(cp); cp += INT16SZ;
-		tclass = ns_get16(cp); cp += INT16SZ;
+		NS_GET16(ttype, cp);
+		NS_GET16(tclass, cp);
 		if (ttype == type && tclass == class &&
 		    ns_samename(tname, name) == 1)
 			return (1);
@@ -292,9 +292,6 @@ int
 res_queriesmatch(const u_char *buf1, const u_char *eom1,
 		 const u_char *buf2, const u_char *eom2)
 {
-	const u_char *cp = buf1 + HFIXEDSZ;
-	int qdcount = ntohs(((HEADER*)buf1)->qdcount);
-
 	if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
 		return (-1);
 
@@ -306,8 +303,16 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1,
 	    (((HEADER *)buf2)->opcode == ns_o_update))
 		return (1);
 
-	if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
+	/* Note that we initially do not convert QDCOUNT to the host byte
+	   order.  We can compare it with the second buffers QDCOUNT
+	   value without doing this.  */
+	int qdcount = ((HEADER*)buf1)->qdcount;
+	if (qdcount != ((HEADER*)buf2)->qdcount)
 		return (0);
+
+	qdcount = htons (qdcount);
+	const u_char *cp = buf1 + HFIXEDSZ;
+
 	while (qdcount-- > 0) {
 		char tname[MAXDNAME+1];
 		int n, ttype, tclass;
@@ -318,8 +323,8 @@ res_queriesmatch(const u_char *buf1, const u_char *eom1,
 		cp += n;
 		if (cp + 2 * INT16SZ > eom1)
 			return (-1);
-		ttype = ns_get16(cp);	cp += INT16SZ;
-		tclass = ns_get16(cp); cp += INT16SZ;
+		NS_GET16(ttype, cp);
+		NS_GET16(tclass, cp);
 		if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
 			return (0);
 	}