summaryrefslogtreecommitdiff
path: root/tests/sockettest.c
diff options
context:
space:
mode:
authorMichal Privoznik <mprivozn@redhat.com>2013-06-05 17:05:50 +0200
committerMichal Privoznik <mprivozn@redhat.com>2013-06-06 08:31:09 +0200
commite5fa9db17ed9363f2f07080e92ffb67b12015f65 (patch)
tree48820238922f2d0c609cd243e791bc0d24407a96 /tests/sockettest.c
parente90a3598c79df141ee7fca5f669d841e049655f7 (diff)
downloadlibvirt-e5fa9db17ed9363f2f07080e92ffb67b12015f65.tar.gz
qemu: Reformat listen address prior to checking
Currently, a listen address for a SPICE server can be specified. Later, when the domain is migrated, we need to relocate the graphics which involves telling new destination to the SPICE server. However, we can't just assume the listen address is the new location, because the listen address can be ANYCAST (0.0.0.0 for IPv4, :: for IPv6). In which case, we want to pass the remote hostname. But there are some troubles with ANYCAST. In both IPv4 and IPv6 it has many ways for specifying such address. For instance, in IPv4: 0, 0.0, 0.0.0, 0.0.0.0. The number of variations gets bigger in IPv6 world. Hence, in order to check for ANYCAST address sanely, we should take the provided listen address, parse it and format back in it's full form. Which is exactly what this patch does.
Diffstat (limited to 'tests/sockettest.c')
-rw-r--r--tests/sockettest.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/sockettest.c b/tests/sockettest.c
index 156ef454c6..5b36a6c0bf 100644
--- a/tests/sockettest.c
+++ b/tests/sockettest.c
@@ -193,6 +193,20 @@ mymain(void)
ret = -1; \
} while (0)
+#define DO_TEST_PARSE_AND_CHECK_FORMAT(addrstr, addrformated, family, pass) \
+ do { \
+ virSocketAddr addr; \
+ struct testParseData data = { &addr, addrstr, family, true}; \
+ memset(&addr, 0, sizeof(addr)); \
+ if (virtTestRun("Test parse " addrstr " family " #family, \
+ 1, testParseHelper, &data) < 0) \
+ ret = -1; \
+ struct testFormatData data2 = { &addr, addrformated, pass }; \
+ if (virtTestRun("Test format " addrstr " family " #family, \
+ 1, testFormatHelper, &data2) < 0) \
+ ret = -1; \
+ } while (0)
+
#define DO_TEST_RANGE(saddr, eaddr, size, pass) \
do { \
struct testRangeData data = { saddr, eaddr, size, pass }; \
@@ -216,6 +230,16 @@ mymain(void)
DO_TEST_PARSE_AND_FORMAT("127.0.0.1", AF_UNIX, false);
DO_TEST_PARSE_AND_FORMAT("127.0.0.256", AF_UNSPEC, false);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("127.0.0.2", "127.0.0.2", AF_INET, true);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("127.0.0.2", "127.0.0.3", AF_INET, false);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("0", "0.0.0.0", AF_INET, true);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("127", "0.0.0.127", AF_INET, true);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("127", "127.0.0.0", AF_INET, false);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("127.2", "127.0.0.2", AF_INET, true);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("127.2", "127.2.0.0", AF_INET, false);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("1.2.3", "1.2.0.3", AF_INET, true);
+ DO_TEST_PARSE_AND_CHECK_FORMAT("1.2.3", "1.2.3.0", AF_INET, false);
+
DO_TEST_PARSE_AND_FORMAT("::1", AF_UNSPEC, true);
DO_TEST_PARSE_AND_FORMAT("::1", AF_INET, false);
DO_TEST_PARSE_AND_FORMAT("::1", AF_INET6, true);