chiark / gitweb /
noip.c (fixup_client_socket): Reorder the preflight checks.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 6 Jun 2018 19:25:51 +0000 (20:25 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 6 Jun 2018 19:25:51 +0000 (20:25 +0100)
Superficially, it looks as if `acl_allows_p' will be cheaper than
`real_getsockname'.  But actually, if `acl_allows_p' passes the remote
address then we'll end up doing a `real_getsockname' anyway in order to
decide whether we need to substitute an unfaked socket, so this is a
false economy.

This shouldn't actually change the effective behaviour, but it will
improve performance -- not that this hack is especially performance
critical.

noip.c

diff --git a/noip.c b/noip.c
index fd86cb342e7154894338b0997b0b8fca4b78ec09..66c6ba5aab2e8db701c21602e98ec7253bde42f5 100644 (file)
--- a/noip.c
+++ b/noip.c
@@ -1002,6 +1002,11 @@ static int fixup_client_socket(int sk, const struct sockaddr **sa_r,
   socklen_t mylen = sizeof(*sun);
   const struct sockaddr *sa = *sa_r;
 
+  /* If this isn't a Unix-domain socket then there's nothing to do. */
+  if (real_getsockname(sk, SA(sun), &mylen) < 0) return (-1);
+  if (sun->sun_family != AF_UNIX) return (0);
+  if (mylen < sizeof(*sun)) ((char *)sun)[mylen] = 0;
+
   /* If we're allowed to talk to a real remote endpoint, then fix things up
    * as necessary and proceed.
    */
@@ -1010,11 +1015,6 @@ static int fixup_client_socket(int sk, const struct sockaddr **sa_r,
     return (0);
   }
 
-  /* If this isn't a Unix-domain socket then there's nothing to do. */
-  if (real_getsockname(sk, SA(sun), &mylen) < 0) return (-1);
-  if (sun->sun_family != AF_UNIX) return (0);
-  if (mylen < sizeof(*sun)) ((char *)sun)[mylen] = 0;
-
   /* Speaking of which, if we don't have a local address, then we should
    * arrange one now.
    */