Make HS ConfD client IPv6 compatible
authorMichele Tartara <mtartara@google.com>
Tue, 14 May 2013 11:04:33 +0000 (12:04 +0100)
committerMichele Tartara <mtartara@google.com>
Tue, 14 May 2013 17:06:58 +0000 (18:06 +0100)
The Haskell ConfD client was assuming internet addresses to be IPv4. This
patch modifies the client so that it is able to automatically detect the
protocol it should use by analyzing the address it is told to connect to.

Signed-off-by: Michele Tartara <mtartara@google.com>
Reviewed-by: Helga Velroyen <helgav@google.com>

src/Ganeti/Confd/Client.hs

index d7a5ea0..8bd7613 100644 (file)
@@ -42,6 +42,7 @@ import Ganeti.Confd.Utils
 import qualified Ganeti.Constants as C
 import Ganeti.Hash
 import Ganeti.Ssconf
+import Ganeti.Utils
 
 -- | Builds a properly initialized ConfdClient.
 -- The parameters (an IP address and the port number for the Confd client
@@ -117,9 +118,11 @@ queryOneServer semaphore answer crType cQuery hmac (host, port) = do
   let signedMsg =
         signMessage hmac timestamp (J.encodeStrict request)
       completeMsg = C.confdMagicFourcc ++ J.encodeStrict signedMsg
-  s <- S.socket S.AF_INET S.Datagram S.defaultProtocol
-  hostAddr <- S.inet_addr host
-  _ <- S.sendTo s completeMsg $ S.SockAddrInet port hostAddr
+  addr <- resolveAddr (fromIntegral port) host
+  (af_family, sockaddr) <-
+    exitIfBad "Unable to resolve the IP address" addr
+  s <- S.socket af_family S.Datagram S.defaultProtocol
+  _ <- S.sendTo s completeMsg sockaddr
   replyMsg <- S.recv s C.maxUdpDataSize
   parsedReply <-
     if C.confdMagicFourcc `isPrefixOf` replyMsg