]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
sm-notify: Don't orphan addrinfo structs
authorChuck Lever <chuck.lever@oracle.com>
Mon, 18 May 2009 15:03:54 +0000 (11:03 -0400)
committerSteve Dickson <steved@redhat.com>
Mon, 18 May 2009 15:03:54 +0000 (11:03 -0400)
sm-notify orphans an addrinfo struct in its address list rotation
logic if only a single result was returned from getaddrinfo(3).

For each host, the first time through notify_host(), we want to
send a PMAP_GETPORT request.  ->ai is NULL, and retries is set to 100,
forcing a DNS lookup and an address rotation.  If only a single
addrinfo struct is returned, the rotation logic causes a NULL to be
planted in ->ai, copied from the ai_next field of the returned result.

This means that the second time through notify_host() (to perform the
actual SM_NOTIFY call) we do a second DNS lookup, since ->ai is NULL.
The result of the first lookup has been orphaned, and extra network
traffic is generated.

This scenario is actually fairly common.  Since we pass

  .ai_protocol = IPPROTO_UDP,

  to getaddrinfo(3), for most hosts, which have a single forward and
  reverse pointer in the DNS database, we get back a single addrinfo
  struct as a result.

  To address this problem, only perform the address list rotation if
  there is more than one element on the list returned by getaddrinfo(3).

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Steve Dickson <steved@redhat.com>
utils/statd/sm-notify.c

index f1fc619a9b4c3ab9398e27d073af588d81bdf31a..78d0a592bcf181eb09e4b3e61bb9708bf2915cd0 100644 (file)
@@ -424,19 +424,27 @@ notify_host(int sock, struct nsm_host *host)
         * point.
         */
        if (host->retries >= 4) {
-               struct addrinfo *first = host->ai;
-               struct addrinfo **next = &host->ai;
-
-               /* remove the first entry from the list */
-               host->ai = first->ai_next;
-               first->ai_next = NULL;
-               /* find the end of the list */
-               next = &first->ai_next;
-               while ( *next )
-                       next = & (*next)->ai_next;
-               /* put first entry at end */
-               *next = first;
-               memcpy(&host->addr, first->ai_addr, first->ai_addrlen);
+               /* don't rotate if there is only one addrinfo */
+               if (host->ai->ai_next == NULL)
+                       memcpy(&host->addr, host->ai->ai_addr,
+                                               host->ai->ai_addrlen);
+               else {
+                       struct addrinfo *first = host->ai;
+                       struct addrinfo **next = &host->ai;
+
+                       /* remove the first entry from the list */
+                       host->ai = first->ai_next;
+                       first->ai_next = NULL;
+                       /* find the end of the list */
+                       next = &first->ai_next;
+                       while ( *next )
+                               next = & (*next)->ai_next;
+                       /* put first entry at end */
+                       *next = first;
+                       memcpy(&host->addr, first->ai_addr,
+                                               first->ai_addrlen);
+               }
+
                smn_set_port((struct sockaddr *)&host->addr, 0);
                host->retries = 0;
        }