From 133724d95805142e29c6d34a7bc201368e7a9d05 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Sun, 29 Nov 2015 18:42:52 +0100 Subject: [PATCH] platform/tests: test IPIP links --- src/platform/tests/test-common.c | 30 ++++++++++++++++++++++++++++++ src/platform/tests/test-common.h | 3 +++ src/platform/tests/test-link.c | 26 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index c6b24720d2..8856b11a85 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -700,6 +700,36 @@ nmtstp_link_gre_add (gboolean external_command, const char *name, NMPlatformLnkG return success; } +gboolean +nmtstp_link_ipip_add (gboolean external_command, const char *name, NMPlatformLnkIpIp *lnk) +{ + gboolean success; + char buffer[INET_ADDRSTRLEN]; + + external_command = nmtstp_run_command_check_external (external_command); + + if (external_command) { + gs_free char *dev = NULL; + + if (lnk->parent_ifindex) + dev = g_strdup_printf ("dev %s", nm_platform_link_get_name (NM_PLATFORM_GET, lnk->parent_ifindex)); + + success = !nmtstp_run_command ("ip tunnel add %s mode ipip %s local %s remote %s ttl %u tos %02x %s", + name, + dev, + nm_utils_inet4_ntop (lnk->local, NULL), + nm_utils_inet4_ntop (lnk->remote, buffer), + lnk->ttl, + lnk->tos, + lnk->path_mtu_discovery ? "pmtudisc" : "nopmtudisc"); + if (success) + nmtstp_assert_wait_for_link (name, NM_LINK_TYPE_IPIP, 100); + } else + success = nm_platform_link_ipip_add (NM_PLATFORM_GET, name, lnk, NULL) == NM_PLATFORM_ERROR_SUCCESS; + + return success; +} + gboolean nmtstp_link_sit_add (gboolean external_command, const char *name, NMPlatformLnkSit *lnk) { diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index 4120a7f138..a3897f2d58 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -138,6 +138,9 @@ void nmtstp_link_set_updown (gboolean external_command, gboolean nmtstp_link_gre_add (gboolean external_command, const char *name, NMPlatformLnkGre *lnk); +gboolean nmtstp_link_ipip_add (gboolean external_command, + const char *name, + NMPlatformLnkIpIp *lnk); gboolean nmtstp_link_sit_add (gboolean external_command, const char *name, NMPlatformLnkSit *lnk); diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 25004b74bb..cee9d0a61c 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -690,6 +690,19 @@ test_software_detect (gconstpointer user_data) } break; } + case NM_LINK_TYPE_IPIP: { + NMPlatformLnkIpIp lnk_ipip = { }; + + inet_pton (AF_INET, "1.2.3.4", &lnk_ipip.local); + inet_pton (AF_INET, "5.6.7.8", &lnk_ipip.remote); + lnk_ipip.parent_ifindex = ifindex_parent; + lnk_ipip.tos = 32; + lnk_ipip.path_mtu_discovery = FALSE; + + if (!nmtstp_link_ipip_add (EX, DEVICE_NAME, &lnk_ipip)) + g_error ("Failed adding IPIP tunnel"); + break; + } case NM_LINK_TYPE_MACVLAN: nmtstp_run_command_check ("ip link add name %s link %s type macvlan", DEVICE_NAME, PARENT_NAME); break; @@ -786,6 +799,18 @@ test_software_detect (gconstpointer user_data) g_assert_cmpint (plnk->path_mtu_discovery, ==, TRUE); break; } + case NM_LINK_TYPE_IPIP: { + const NMPlatformLnkIpIp *plnk = &lnk->lnk_ipip; + + g_assert (plnk == nm_platform_link_get_lnk_ipip (NM_PLATFORM_GET, ifindex, NULL)); + g_assert_cmpint (plnk->parent_ifindex, ==, ifindex_parent); + nmtst_assert_ip4_address (plnk->local, "1.2.3.4"); + nmtst_assert_ip4_address (plnk->remote, "5.6.7.8"); + g_assert_cmpint (plnk->ttl, ==, 0); + g_assert_cmpint (plnk->tos, ==, 32); + g_assert_cmpint (plnk->path_mtu_discovery, ==, FALSE); + break; + } case NM_LINK_TYPE_MACVLAN: { const NMPlatformLnkMacvlan *plnk = &lnk->lnk_macvlan; @@ -1624,6 +1649,7 @@ setup_tests (void) g_test_add_func ("/link/external", test_external); test_software_detect_add ("/link/software/detect/gre", NM_LINK_TYPE_GRE, 0); + test_software_detect_add ("/link/software/detect/ipip", NM_LINK_TYPE_IPIP, 0); test_software_detect_add ("/link/software/detect/macvlan", NM_LINK_TYPE_MACVLAN, 0); test_software_detect_add ("/link/software/detect/sit", NM_LINK_TYPE_SIT, 0); test_software_detect_add ("/link/software/detect/vlan", NM_LINK_TYPE_VLAN, 0);