aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_netsock2.c
diff options
context:
space:
mode:
authortwilson <twilson@f38db490-d61c-443f-a65b-d21fe96a405b>2011-06-22 19:12:24 +0000
committertwilson <twilson@f38db490-d61c-443f-a65b-d21fe96a405b>2011-06-22 19:12:24 +0000
commita475c6be815db27db330ce5f5dd942d91ed64b17 (patch)
tree7a6ec853f73b606503c37503da65c5f3c106c647 /tests/test_netsock2.c
parent7d3d6f4674630531f2d7d12ec55812215b41c79c (diff)
Merged revisions 324484 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r324484 | twilson | 2011-06-22 13:52:04 -0500 (Wed, 22 Jun 2011) | 20 lines Stop sending IPv6 link-local scope-ids in SIP messages The idea behind the patch listed below was used, but in a more targeted manner. There are now address stringification functions for addresses that are meant to be sent to a remote party. Link-local scope-ids only make sense on the machine from which they originate and so are stripped in the new functions. There is also a host sanitization function added to chan_sip which is used for when peer and dialog tohost fields or sip_registry hostnames are used to craft a SIP message. Also added are some basic unit tests for netsock2 address parsing. (closes issue ASTERISK-17711) Reported by: ch_djalel Patches: asterisk-1.8.3.2-ipv6_ll_scope.patch uploaded by ch_djalel (license 1251) Review: https://reviewboard.asterisk.org/r/1278/ ........ git-svn-id: http://svn.digium.com/svn/asterisk/trunk@324487 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'tests/test_netsock2.c')
-rw-r--r--tests/test_netsock2.c127
1 files changed, 127 insertions, 0 deletions
diff --git a/tests/test_netsock2.c b/tests/test_netsock2.c
new file mode 100644
index 000000000..bdc92fbed
--- /dev/null
+++ b/tests/test_netsock2.c
@@ -0,0 +1,127 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * Terry Wilson <twilson@digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Netsock2 Unit Tests
+ *
+ * \author Terry Wilson <twilson@digium.com>
+ *
+ */
+
+/*** MODULEINFO
+ <depend>TEST_FRAMEWORK</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "")
+
+#include "asterisk/test.h"
+#include "asterisk/module.h"
+#include "asterisk/netsock2.h"
+#include "asterisk/logger.h"
+struct parse_test {
+ const char *address;
+ int expected_result;
+};
+
+AST_TEST_DEFINE(parsing)
+{
+ int res = AST_TEST_PASS;
+ struct parse_test test_vals[] = {
+ { "192.168.1.0", 1 },
+ { "10.255.255.254", 1 },
+ { "172.18.5.4", 1 },
+ { "8.8.4.4", 1 },
+ { "0.0.0.0", 1 },
+ { "127.0.0.1", 1 },
+ { "1.256.3.4", 0 },
+ { "256.0.0.1", 0 },
+ { "1.2.3.4:5060", 1 },
+ { "1.2.3.4:99999", 0},
+ { "::ffff:5.6.7.8", 1 },
+ { "fdf8:f53b:82e4::53", 1 },
+ { "fe80::200:5aee:feaa:20a2", 1 },
+ { "2001::1", 1 },
+ { "2001:0000:4136:e378:8000:63bf:3fff:fdd2", 1 },
+ { "2001:0002:6c::430", 1 },
+ { "2001:10:240:ab::a", 1 },
+ { "2002:cb0a:3cdd:1::1", 1 },
+ { "2001:db8:8:4::2", 1 }, /* Documentation only, should never be used */
+ { "ff01:0:0:0:0:0:0:2", 1 }, /* Multicast */
+ { "[fdf8:f53b:82e4::53]", 1 },
+ { "[fe80::200:5aee:feaa:20a2]", 1 },
+ { "[2001::1]", 1 },
+ { "[2001:0000:4136:e378:8000:63bf:3fff:fdd2]:5060", 1 },
+ { "2001:0000:4136:e378:8000:63bf:3fff:fdd2:5060", 0 }, /* port, but no brackets */
+ { "[2001:0000:4136:e378:8000:63bf:3fff:fdd2]:90000", 0 },
+ { "[fe80::200:5aee:feaa:20a2%eth0]", 1 }, /* link-local with scope id */
+ { "[fe80::200::abcd", 0 }, /* multiple zero expansions */
+ };
+
+ size_t x;
+ struct ast_sockaddr addr = { { 0, 0, } };
+ int parse_result;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "parsing";
+ info->category = "/main/netsock2/";
+ info->summary = "netsock2 parsing unit test";
+ info->description =
+ "Test parsing of IPv4 and IPv6 network addresses";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ for (x = 0; x < ARRAY_LEN(test_vals); x++) {
+ if ((parse_result = ast_sockaddr_parse(&addr, test_vals[x].address, 0)) != test_vals[x].expected_result) {
+ ast_test_status_update(test, "On '%s' expected %d but got %d\n", test_vals[x].address, test_vals[x].expected_result, parse_result);
+ res = AST_TEST_FAIL;
+ }
+ if (parse_result) {
+ struct ast_sockaddr tmp_addr = { { 0, 0, } };
+ const char *tmp;
+
+ tmp = ast_sockaddr_stringify(&addr);
+ ast_sockaddr_parse(&tmp_addr, tmp, 0);
+ if (ast_sockaddr_cmp_addr(&addr, &tmp_addr)) {
+ ast_test_status_update(test, "Re-parsed stringification did not match: '%s' vs '%s'\n", ast_sockaddr_stringify(&addr), ast_sockaddr_stringify(&tmp_addr));
+ res = AST_TEST_FAIL;
+ }
+ }
+ }
+
+ return res;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(parsing);
+ return 0;
+}
+
+static int load_module(void)
+{
+ AST_TEST_REGISTER(parsing);
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Netsock2 test module");