|
Packit Service |
a1bd4f |
/* SPDX-License-Identifier: GPL-2.0+ */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2013 - 2014 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-default.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include <arpa/inet.h>
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-ip4-config.h"
|
|
Packit |
5756e2 |
#include "platform/nm-platform.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-test-utils-core.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static NMIP4Config *
|
|
Packit Service |
a1bd4f |
build_test_config(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMIP4Config * config;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Address addr;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Route route;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Build up the config to subtract */
|
|
Packit Service |
a1bd4f |
config = nmtst_ip4_config_new(1);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_assert(NM_IP_CONFIG_CAST(config));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address("192.168.1.10", "1.2.3.4", 24);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(config, &addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
route = *nmtst_platform_ip4_route("10.0.0.0", 8, "192.168.1.1");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(config, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
route = *nmtst_platform_ip4_route("172.16.0.0", 16, "192.168.1.1");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(config, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
{
|
|
Packit Service |
a1bd4f |
const NMPlatformIP4Route r = {
|
|
Packit Service |
a1bd4f |
.rt_source = NM_IP_CONFIG_SOURCE_DHCP,
|
|
Packit Service |
a1bd4f |
.gateway = nmtst_inet4_from_string("192.168.1.1"),
|
|
Packit Service |
a1bd4f |
.table_coerced = 0,
|
|
Packit Service |
a1bd4f |
.metric = 100,
|
|
Packit Service |
a1bd4f |
};
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(config, &r, NULL);
|
|
Packit Service |
a1bd4f |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_nameserver(config, nmtst_inet4_from_string("4.2.2.1"));
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_nameserver(config, nmtst_inet4_from_string("4.2.2.2"));
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_domain(config, "foobar.com");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_domain(config, "baz.com");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "blahblah.com");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "beatbox.com");
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_nis_server(config, nmtst_inet4_from_string("1.2.3.9"));
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_nis_server(config, nmtst_inet4_from_string("1.2.3.10"));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_wins(config, nmtst_inet4_from_string("4.2.3.9"));
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_wins(config, nmtst_inet4_from_string("4.2.3.10"));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return config;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_replace(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
gs_unref_object NMIP4Config *config1 = NULL;
|
|
Packit Service |
a1bd4f |
gs_unref_object NMIP4Config *config2 = NULL;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Address addr;
|
|
Packit Service |
a1bd4f |
gboolean relevant_changes;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
config1 = nmtst_ip4_config_new(1);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address("172.16.0.1", NULL, 24);
|
|
Packit Service |
a1bd4f |
addr.timestamp = 10;
|
|
Packit Service |
a1bd4f |
addr.preferred = 3600;
|
|
Packit Service |
a1bd4f |
addr.lifetime = 7200;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(config1, &addr);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address("172.16.0.2", NULL, 24);
|
|
Packit Service |
a1bd4f |
addr.timestamp = 10;
|
|
Packit Service |
a1bd4f |
addr.preferred = 3600;
|
|
Packit Service |
a1bd4f |
addr.lifetime = 7200;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(config1, &addr);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
config2 = nmtst_ip4_config_new(1);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address("192.168.1.1", NULL, 24);
|
|
Packit Service |
a1bd4f |
addr.timestamp = 40;
|
|
Packit Service |
a1bd4f |
addr.preferred = 60;
|
|
Packit Service |
a1bd4f |
addr.lifetime = 120;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(config2, &addr);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address("172.16.0.2", NULL, 24);
|
|
Packit Service |
a1bd4f |
addr.timestamp = 40;
|
|
Packit Service |
a1bd4f |
addr.preferred = 60;
|
|
Packit Service |
a1bd4f |
addr.lifetime = 120;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(config2, &addr);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(nm_ip4_config_replace(config2, config1, &relevant_changes));
|
|
Packit Service |
a1bd4f |
g_assert(relevant_changes);
|
|
Packit Service |
a1bd4f |
g_assert(nm_ip4_config_equal(config1, config2));
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_subtract(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMIP4Config * src, *dst;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Address addr;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Route route;
|
|
Packit Service |
a1bd4f |
const NMPlatformIP4Address *test_addr;
|
|
Packit Service |
a1bd4f |
const NMPlatformIP4Route * test_route;
|
|
Packit Service |
a1bd4f |
const char * expected_addr = "192.168.1.12";
|
|
Packit Service |
a1bd4f |
guint32 expected_addr_plen = 24;
|
|
Packit Service |
a1bd4f |
const char * expected_route_dest = "8.0.0.0";
|
|
Packit Service |
a1bd4f |
guint32 expected_route_plen = 8;
|
|
Packit Service |
a1bd4f |
const char * expected_route_next_hop = "192.168.1.1";
|
|
Packit Service |
a1bd4f |
guint32 expected_ns1 = nmtst_inet4_from_string("8.8.8.8");
|
|
Packit Service |
a1bd4f |
guint32 expected_ns2 = nmtst_inet4_from_string("8.8.8.9");
|
|
Packit Service |
a1bd4f |
const char * expected_domain = "wonderfalls.com";
|
|
Packit Service |
a1bd4f |
const char * expected_search = "somewhere.com";
|
|
Packit Service |
a1bd4f |
guint32 expected_nis = nmtst_inet4_from_string("1.2.3.13");
|
|
Packit Service |
a1bd4f |
guint32 expected_wins = nmtst_inet4_from_string("2.3.4.5");
|
|
Packit Service |
a1bd4f |
guint32 expected_mtu = 1492;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
src = build_test_config();
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* add a couple more things to the test config */
|
|
Packit Service |
a1bd4f |
dst = build_test_config();
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address(expected_addr, NULL, expected_addr_plen);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(dst, &addr);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
route = *nmtst_platform_ip4_route(expected_route_dest,
|
|
Packit Service |
a1bd4f |
expected_route_plen,
|
|
Packit Service |
a1bd4f |
expected_route_next_hop);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(dst, &route, NULL);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_nameserver(dst, expected_ns1);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_nameserver(dst, expected_ns2);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_domain(dst, expected_domain);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(dst, expected_search);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_nis_server(dst, expected_nis);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_wins(dst, expected_wins);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_set_mtu(dst, expected_mtu, NM_IP_CONFIG_SOURCE_UNKNOWN);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_subtract(dst, src, 0);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* ensure what's left is what we expect */
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_addresses(dst), ==, 1);
|
|
Packit Service |
a1bd4f |
test_addr = _nmtst_ip4_config_get_address(dst, 0);
|
|
Packit Service |
a1bd4f |
g_assert(test_addr != NULL);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(test_addr->address, ==, nmtst_inet4_from_string(expected_addr));
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(test_addr->peer_address, ==, test_addr->address);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(test_addr->plen, ==, expected_addr_plen);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert(!nm_ip4_config_best_default_route_get(dst));
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nmtst_ip4_config_get_gateway(dst), ==, 0);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_routes(dst), ==, 1);
|
|
Packit Service |
a1bd4f |
test_route = _nmtst_ip4_config_get_route(dst, 0);
|
|
Packit Service |
a1bd4f |
g_assert(test_route != NULL);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(test_route->network, ==, nmtst_inet4_from_string(expected_route_dest));
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(test_route->plen, ==, expected_route_plen);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(test_route->gateway, ==, nmtst_inet4_from_string(expected_route_next_hop));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_nameservers(dst), ==, 2);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_nameserver(dst, 0), ==, expected_ns1);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_nameserver(dst, 1), ==, expected_ns2);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_domains(dst), ==, 1);
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr(nm_ip4_config_get_domain(dst, 0), ==, expected_domain);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_searches(dst), ==, 1);
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr(nm_ip4_config_get_search(dst, 0), ==, expected_search);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_nis_servers(dst), ==, 1);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_nis_server(dst, 0), ==, expected_nis);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_wins(dst), ==, 1);
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_wins(dst, 0), ==, expected_wins);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_mtu(dst), ==, expected_mtu);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_unref(src);
|
|
Packit Service |
a1bd4f |
g_object_unref(dst);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_compare_with_source(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMIP4Config * a, *b;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Address addr;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Route route;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
a = nmtst_ip4_config_new(1);
|
|
Packit Service |
a1bd4f |
b = nmtst_ip4_config_new(2);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Address */
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address("1.2.3.4", NULL, 24);
|
|
Packit Service |
a1bd4f |
addr.addr_source = NM_IP_CONFIG_SOURCE_USER;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(a, &addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
addr.addr_source = NM_IP_CONFIG_SOURCE_VPN;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(b, &addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Route */
|
|
Packit Service |
a1bd4f |
route = *nmtst_platform_ip4_route("10.0.0.0", 8, "192.168.1.1");
|
|
Packit Service |
a1bd4f |
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(a, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
route.rt_source = NM_IP_CONFIG_SOURCE_VPN;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(b, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Assert that the configs are basically the same, eg that the source is ignored */
|
|
Packit Service |
a1bd4f |
g_assert(nm_ip4_config_equal(a, b));
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_object_unref(a);
|
|
Packit Service |
a1bd4f |
g_object_unref(b);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_add_address_with_source(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMIP4Config * a;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Address addr;
|
|
Packit Service |
a1bd4f |
const NMPlatformIP4Address *test_addr;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
a = nmtst_ip4_config_new(1);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Test that a higher priority source is not overwritten */
|
|
Packit Service |
a1bd4f |
addr = *nmtst_platform_ip4_address("1.2.3.4", NULL, 24);
|
|
Packit Service |
a1bd4f |
addr.addr_source = NM_IP_CONFIG_SOURCE_USER;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(a, &addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
test_addr = _nmtst_ip4_config_get_address(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
addr.addr_source = NM_IP_CONFIG_SOURCE_VPN;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(a, &addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
test_addr = _nmtst_ip4_config_get_address(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Test that a lower priority address source is overwritten */
|
|
Packit Service |
a1bd4f |
_nmtst_ip4_config_del_address(a, 0);
|
|
Packit Service |
a1bd4f |
addr.addr_source = NM_IP_CONFIG_SOURCE_KERNEL;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(a, &addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
test_addr = _nmtst_ip4_config_get_address(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_KERNEL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
addr.addr_source = NM_IP_CONFIG_SOURCE_USER;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_address(a, &addr);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
test_addr = _nmtst_ip4_config_get_address(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_addr->addr_source, ==, NM_IP_CONFIG_SOURCE_USER);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_object_unref(a);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_add_route_with_source(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
gs_unref_object NMIP4Config *a = NULL;
|
|
Packit Service |
a1bd4f |
NMPlatformIP4Route route;
|
|
Packit Service |
a1bd4f |
const NMPlatformIP4Route * test_route;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
a = nmtst_ip4_config_new(1);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Test that a higher priority source is not overwritten */
|
|
Packit Service |
a1bd4f |
route = *nmtst_platform_ip4_route("1.2.3.0", 24, "1.2.3.1");
|
|
Packit Service |
a1bd4f |
route.rt_source = NM_IP_CONFIG_SOURCE_USER;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(a, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1);
|
|
Packit Service |
a1bd4f |
test_route = _nmtst_ip4_config_get_route(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
route.rt_source = NM_IP_CONFIG_SOURCE_VPN;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(a, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1);
|
|
Packit Service |
a1bd4f |
test_route = _nmtst_ip4_config_get_route(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_USER);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
_nmtst_ip4_config_del_route(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* Test that a lower priority address source is overwritten */
|
|
Packit Service |
a1bd4f |
route.rt_source = NM_IP_CONFIG_SOURCE_RTPROT_KERNEL;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(a, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1);
|
|
Packit Service |
a1bd4f |
test_route = _nmtst_ip4_config_get_route(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_RTPROT_KERNEL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
route.rt_source = NM_IP_CONFIG_SOURCE_KERNEL;
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_route(a, &route, NULL);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(nm_ip4_config_get_num_routes(a), ==, 1);
|
|
Packit Service |
a1bd4f |
test_route = _nmtst_ip4_config_get_route(a, 0);
|
|
Packit Service |
a1bd4f |
g_assert_cmpint(test_route->rt_source, ==, NM_IP_CONFIG_SOURCE_KERNEL);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_merge_subtract_mtu(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMIP4Config *cfg1, *cfg2, *cfg3;
|
|
Packit Service |
a1bd4f |
guint32 expected_mtu2 = 1492;
|
|
Packit Service |
a1bd4f |
guint32 expected_mtu3 = 666;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
cfg1 = build_test_config();
|
|
Packit Service |
a1bd4f |
cfg2 = build_test_config();
|
|
Packit Service |
a1bd4f |
cfg3 = build_test_config();
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
/* add MSS, MTU to configs to test them */
|
|
Packit Service |
a1bd4f |
nm_ip4_config_set_mtu(cfg2, expected_mtu2, NM_IP_CONFIG_SOURCE_UNKNOWN);
|
|
Packit Service |
a1bd4f |
nm_ip4_config_set_mtu(cfg3, expected_mtu3, NM_IP_CONFIG_SOURCE_UNKNOWN);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_merge(cfg1, cfg2, NM_IP_CONFIG_MERGE_DEFAULT, 0);
|
|
Packit Service |
a1bd4f |
/* ensure MSS and MTU are in cfg1 */
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_mtu(cfg1), ==, expected_mtu2);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_merge(cfg1, cfg3, NM_IP_CONFIG_MERGE_DEFAULT, 0);
|
|
Packit Service |
a1bd4f |
/* ensure again the MSS and MTU in cfg1 got overridden */
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_mtu(cfg1), ==, expected_mtu3);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_subtract(cfg1, cfg3, 0);
|
|
Packit Service |
a1bd4f |
/* ensure MSS and MTU are zero in cfg1 */
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_mtu(cfg1), ==, 0);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_object_unref(cfg1);
|
|
Packit Service |
a1bd4f |
g_object_unref(cfg2);
|
|
Packit Service |
a1bd4f |
g_object_unref(cfg3);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static void
|
|
Packit Service |
a1bd4f |
test_strip_search_trailing_dot(void)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
NMIP4Config *config;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
config = nmtst_ip4_config_new(1);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, ".");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "foo");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "bar.");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "baz.com");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "baz.com.");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "foobar..");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, ".foobar");
|
|
Packit Service |
a1bd4f |
nm_ip4_config_add_search(config, "~.");
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_assert_cmpuint(nm_ip4_config_get_num_searches(config), ==, 4);
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr(nm_ip4_config_get_search(config, 0), ==, "foo");
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr(nm_ip4_config_get_search(config, 1), ==, "bar");
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr(nm_ip4_config_get_search(config, 2), ==, "baz.com");
|
|
Packit Service |
a1bd4f |
g_assert_cmpstr(nm_ip4_config_get_search(config, 3), ==, "~");
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
g_object_unref(config);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
NMTST_DEFINE();
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
int
|
|
Packit Service |
a1bd4f |
main(int argc, char **argv)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nmtst_init_with_logging(&argc, &argv, NULL, "DEFAULT");
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
g_test_add_func("/ip4-config/replace", test_replace);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/ip4-config/subtract", test_subtract);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/ip4-config/compare-with-source", test_compare_with_source);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/ip4-config/add-address-with-source", test_add_address_with_source);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/ip4-config/add-route-with-source", test_add_route_with_source);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/ip4-config/merge-subtract-mtu", test_merge_subtract_mtu);
|
|
Packit Service |
a1bd4f |
g_test_add_func("/ip4-config/strip-search-trailing-dot", test_strip_search_trailing_dot);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
return g_test_run();
|
|
Packit |
5756e2 |
}
|