]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
sm-notify: IPv6 support in reserved port binding in smn_create_socket()
authorChuck Lever <chuck.lever@oracle.com>
Thu, 14 Jan 2010 17:22:42 +0000 (12:22 -0500)
committerSteve Dickson <steved@redhat.com>
Fri, 15 Jan 2010 19:55:51 +0000 (14:55 -0500)
This patch updates the "bind to an arbitrary privileged port" arm of
smn_create_socket() so it can deal with IPv6 bind addresses.

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

index 0ba817a431a225cab45ab083d62688780b449af5..928d1c56f03bff687ec90adef071d78a0313720b 100644 (file)
@@ -215,6 +215,26 @@ static int smn_socket(void)
 }
 #endif /* !IPV6_SUPPORTED */
 
+#ifdef HAVE_LIBTIRPC
+static int
+smn_bindresvport(int sock, struct sockaddr *sap)
+{
+       return bindresvport_sa(sock, sap);
+}
+
+#else  /* !HAVE_LIBTIRPC */
+static int
+smn_bindresvport(int sock, struct sockaddr *sap)
+{
+       if (sap->sa_family != AF_INET) {
+               errno = EAFNOSUPPORT;
+               return -1;
+       }
+
+       return bindresvport(sock, (struct sockaddr_in *)(char *)sap);
+}
+#endif /* !HAVE_LIBTIRPC */
+
 /*
  * Prepare a socket for sending RPC requests
  *
@@ -265,7 +285,14 @@ retry:
        } else {
                struct servent *se;
                struct sockaddr_in *sin = (struct sockaddr_in *)local_addr;
-               (void) bindresvport(sock, sin);
+
+               if (smn_bindresvport(sock, local_addr) == -1) {
+                       xlog(L_ERROR,
+                               "bindresvport on RPC socket failed: %m");
+                       (void)close(sock);
+                       return -1;
+               }
+
                /* try to avoid known ports */
                se = getservbyport(sin->sin_port, "udp");
                if (se && retry_cnt < 100) {