From: JINMEI Tatuya Date: Sat, 19 May 2012 01:45:17 +0000 (-0700) Subject: [1539] set the ddns socket path appropriately. X-Git-Tag: trac2351_base~226^2~85^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0e0005991f6c606751ffbce90a285a03f714aa37;p=thirdparty%2Fkea.git [1539] set the ddns socket path appropriately. for now, just like what we do for xfrout. eventually we should get this from the ddns configuration. --- diff --git a/src/bin/auth/common.cc b/src/bin/auth/common.cc index 1602a1a3a4..2c21895b4a 100644 --- a/src/bin/auth/common.cc +++ b/src/bin/auth/common.cc @@ -33,7 +33,25 @@ getXfroutSocketPath() { if (getenv("BIND10_XFROUT_SOCKET_FILE") != NULL) { return (getenv("BIND10_XFROUT_SOCKET_FILE")); } else { - return (UNIX_SOCKET_FILE); + return (UNIX_XFROUT_SOCKET_FILE); + } + } +} + +string +getDDNSSocketPath() { + if (getenv("B10_FROM_BUILD") != NULL) { + if (getenv("B10_FROM_SOURCE_LOCALSTATEDIR") != NULL) { + return (string(getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) + + "/ddns_socket"); + } else { + return (string(getenv("B10_FROM_BUILD")) + "/ddns_socket"); + } + } else { + if (getenv("BIND10_DDNS_SOCKET_FILE") != NULL) { + return (getenv("BIND10_DDNS_SOCKET_FILE")); + } else { + return (UNIX_DDNS_SOCKET_FILE); } } } diff --git a/src/bin/auth/common.h b/src/bin/auth/common.h index cf71214a5c..48a47d17e8 100644 --- a/src/bin/auth/common.h +++ b/src/bin/auth/common.h @@ -38,6 +38,18 @@ public: /// The logic should be the same as in b10-xfrout, so they find each other. std::string getXfroutSocketPath(); +/// \brief Get the path of socket to talk to ddns +/// +/// It takes some environment variables into account (B10_FROM_BUILD, +/// B10_FROM_SOURCE_LOCALSTATEDIR and BIND10_DDNS_SOCKET_FILE). It +/// also considers the installation prefix. +/// +/// The logic should be the same as in b10-ddns, so they find each other. +/// +/// Note: eventually this should be retrieved from the ddns configuration, +/// at which point this function should be deprecated. +std::string getDDNSSocketPath(); + /// \brief The name used when identifieng the process /// /// This is currently b10-auth, but it can be changed easily in one place. diff --git a/src/bin/auth/main.cc b/src/bin/auth/main.cc index ed71db1789..67d0f3dcf6 100644 --- a/src/bin/auth/main.cc +++ b/src/bin/auth/main.cc @@ -132,7 +132,7 @@ main(int argc, char* argv[]) { bool statistics_session_established = false; // XXX (see Trac #287) ModuleCCSession* config_session = NULL; XfroutClient xfrout_client(getXfroutSocketPath()); - SocketSessionForwarder ddns_forwarder("dummy"); + SocketSessionForwarder ddns_forwarder(getDDNSSocketPath()); try { string specfile; if (getenv("B10_FROM_BUILD")) { diff --git a/src/bin/auth/spec_config.h.pre.in b/src/bin/auth/spec_config.h.pre.in index 1b1df19b0e..586ea7c984 100644 --- a/src/bin/auth/spec_config.h.pre.in +++ b/src/bin/auth/spec_config.h.pre.in @@ -13,4 +13,5 @@ // PERFORMANCE OF THIS SOFTWARE. #define AUTH_SPECFILE_LOCATION "@prefix@/share/@PACKAGE@/auth.spec" -#define UNIX_SOCKET_FILE "@@LOCALSTATEDIR@@/@PACKAGE@/auth_xfrout_conn" +#define UNIX_XFROUT_SOCKET_FILE "@@LOCALSTATEDIR@@/@PACKAGE@/auth_xfrout_conn" +#define UNIX_DDNS_SOCKET_FILE "@@LOCALSTATEDIR@@/@PACKAGE@/ddns_socket" diff --git a/src/bin/auth/tests/common_unittest.cc b/src/bin/auth/tests/common_unittest.cc index 184988d179..b2d072af32 100644 --- a/src/bin/auth/tests/common_unittest.cc +++ b/src/bin/auth/tests/common_unittest.cc @@ -60,37 +60,63 @@ protected: EXPECT_EQ(0, setenv(name.c_str(), value.c_str(), 1)); } } - // Test getXfroutSocketPath under given environment - void testXfrout(const string& fromBuild, const string& localStateDir, - const string& socketFile, const string& expected) + // Test getter functions for a socket file path under given environment + void testSocketPath(const string& fromBuild, const string& localStateDir, + const string& socketFile, const string& env_name, + const string& expected, string (*actual_fn)()) { setEnv("B10_FROM_BUILD", fromBuild); setEnv("B10_FROM_SOURCE_LOCALSTATEDIR", localStateDir); - setEnv("BIND10_XFROUT_SOCKET_FILE", socketFile); - EXPECT_EQ(expected, getXfroutSocketPath()); + setEnv(env_name, socketFile); + EXPECT_EQ(expected, actual_fn()); } }; // Test that when we have no special environment, we get the default from prefix TEST_F(Paths, xfroutNoEnv) { - testXfrout("", "", "", UNIX_SOCKET_FILE); + testSocketPath("", "", "", "BIND10_XFROUT_SOCKET_FILE", + UNIX_XFROUT_SOCKET_FILE, getXfroutSocketPath); +} + +TEST_F(Paths, ddnsNoEnv) { + testSocketPath("", "", "", "BIND10_DDNS_SOCKET_FILE", + UNIX_DDNS_SOCKET_FILE, getDDNSSocketPath); } // Override by B10_FROM_BUILD TEST_F(Paths, xfroutFromBuild) { - testXfrout("/from/build", "", "/wrong/path", - "/from/build/auth_xfrout_conn"); + testSocketPath("/from/build", "", "/wrong/path", + "BIND10_XFROUT_SOCKET_FILE", "/from/build/auth_xfrout_conn", + getXfroutSocketPath); +} + +TEST_F(Paths, ddnsFromBuild) { + testSocketPath("/from/build", "", "/wrong/path", "BIND10_DDNS_SOCKET_FILE", + "/from/build/ddns_socket", getDDNSSocketPath); } // Override by B10_FROM_SOURCE_LOCALSTATEDIR TEST_F(Paths, xfroutLocalStatedir) { - testXfrout("/wrong/path", "/state/dir", "/wrong/path", - "/state/dir/auth_xfrout_conn"); + testSocketPath("/wrong/path", "/state/dir", "/wrong/path", + "BIND10_XFROUT_SOCKET_FILE", "/state/dir/auth_xfrout_conn", + getXfroutSocketPath); } -// Override by BIND10_XFROUT_SOCKET_FILE explicitly +TEST_F(Paths, ddnsLocalStatedir) { + testSocketPath("/wrong/path", "/state/dir", "/wrong/path", + "BIND10_DDNS_SOCKET_FILE", "/state/dir/ddns_socket", + getDDNSSocketPath); +} + +// Override by BIND10_xxx_SOCKET_FILE explicitly TEST_F(Paths, xfroutFromEnv) { - testXfrout("", "", "/the/path/to/file", "/the/path/to/file"); + testSocketPath("", "", "/the/path/to/file", "BIND10_XFROUT_SOCKET_FILE", + "/the/path/to/file", getXfroutSocketPath); +} + +TEST_F(Paths, ddnsFromEnv) { + testSocketPath("", "", "/the/path/to/file", "BIND10_DDNS_SOCKET_FILE", + "/the/path/to/file", getDDNSSocketPath); } }