mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-26 17:50:25 +01:00
core: merge branch 'th/ipv6-ll-reapply-rh1552069' (#75)
A larger branch of refactoring and cleanups. This was a spin-off of pr#75, as the branch grew too large. https://github.com/NetworkManager/NetworkManager/pull/75
This commit is contained in:
commit
217a7ad55a
32 changed files with 825 additions and 2005 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -266,7 +266,6 @@ test-*.trs
|
|||
/src/tests/test-general-with-expect
|
||||
/src/tests/test-ip4-config
|
||||
/src/tests/test-ip6-config
|
||||
/src/tests/test-resolvconf-capture
|
||||
/src/tests/test-route-manager-fake
|
||||
/src/tests/test-route-manager-linux
|
||||
/src/tests/test-systemd
|
||||
|
|
@ -313,3 +312,4 @@ test-*.trs
|
|||
/libnm-core/tests/test-setting-bond
|
||||
/libnm-core/tests/test-setting-dcb
|
||||
/src/settings/plugins/ifnet
|
||||
/src/tests/test-resolvconf-capture
|
||||
|
|
|
|||
10
Makefile.am
10
Makefile.am
|
|
@ -1791,10 +1791,6 @@ $(src_dhcp_tests_test_dhcp_utils_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
|||
EXTRA_DIST += \
|
||||
src/dhcp/tests/test-dhclient-duid.leases \
|
||||
src/dhcp/tests/test-dhclient-commented-duid.leases \
|
||||
src/dhcp/tests/leases/basic.leases \
|
||||
src/dhcp/tests/leases/malformed1.leases \
|
||||
src/dhcp/tests/leases/malformed2.leases \
|
||||
src/dhcp/tests/leases/malformed3.leases \
|
||||
src/dhcp/tests/meson.build
|
||||
|
||||
###############################################################################
|
||||
|
|
@ -3101,7 +3097,6 @@ check_programs += \
|
|||
src/tests/test-ip6-config \
|
||||
src/tests/test-dcb \
|
||||
src/tests/test-systemd \
|
||||
src/tests/test-resolvconf-capture \
|
||||
src/tests/test-wired-defname \
|
||||
src/tests/test-utils
|
||||
|
||||
|
|
@ -3117,10 +3112,6 @@ src_tests_test_dcb_CPPFLAGS = $(src_tests_cppflags)
|
|||
src_tests_test_dcb_LDFLAGS = $(src_tests_ldflags)
|
||||
src_tests_test_dcb_LDADD = $(src_tests_ldadd)
|
||||
|
||||
src_tests_test_resolvconf_capture_CPPFLAGS = $(src_tests_cppflags)
|
||||
src_tests_test_resolvconf_capture_LDFLAGS = $(src_tests_ldflags)
|
||||
src_tests_test_resolvconf_capture_LDADD = $(src_tests_ldadd)
|
||||
|
||||
src_tests_test_general_CPPFLAGS = $(src_tests_cppflags)
|
||||
src_tests_test_general_LDFLAGS = $(src_tests_ldflags)
|
||||
src_tests_test_general_LDADD = $(src_tests_ldadd)
|
||||
|
|
@ -3140,7 +3131,6 @@ src_tests_test_utils_LDADD = $(src_tests_ldadd)
|
|||
$(src_tests_test_ip4_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
||||
$(src_tests_test_ip6_config_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
||||
$(src_tests_test_dcb_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
||||
$(src_tests_test_resolvconf_capture_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
||||
$(src_tests_test_general_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
||||
$(src_tests_test_general_with_expect_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
||||
$(src_tests_test_wired_defname_OBJECTS): $(libnm_core_lib_h_pub_mkenums)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -194,13 +194,6 @@ typedef struct {
|
|||
GType (*get_type)(void);
|
||||
const char *name;
|
||||
const char *(*get_path) (void);
|
||||
GSList *(*get_lease_ip_configs) (struct _NMDedupMultiIndex *multi_idx,
|
||||
int addr_family,
|
||||
const char *iface,
|
||||
int ifindex,
|
||||
const char *uuid,
|
||||
guint32 route_table,
|
||||
guint32 route_metric);
|
||||
} NMDhcpClientFactory;
|
||||
|
||||
extern const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon;
|
||||
|
|
|
|||
|
|
@ -643,259 +643,3 @@ nm_dhcp_dhclient_save_duid (const char *leasefile,
|
|||
g_string_free (s, TRUE);
|
||||
return success;
|
||||
}
|
||||
|
||||
static void
|
||||
add_lease_option (GHashTable *hash, char *line)
|
||||
{
|
||||
char *spc;
|
||||
size_t len;
|
||||
|
||||
/* Find the space after "option" */
|
||||
spc = strchr (line, ' ');
|
||||
if (!spc)
|
||||
return;
|
||||
|
||||
/* Find the option tag's data, which is after the second space */
|
||||
if (g_str_has_prefix (line, "option ")) {
|
||||
while (g_ascii_isspace (*spc))
|
||||
spc++;
|
||||
spc = strchr (spc + 1, ' ');
|
||||
if (!spc)
|
||||
return;
|
||||
}
|
||||
|
||||
/* Split the line at the space */
|
||||
*spc = '\0';
|
||||
spc++;
|
||||
|
||||
/* Kill the ';' at the end of the line, if any */
|
||||
len = strlen (spc);
|
||||
if (*(spc + len - 1) == ';')
|
||||
*(spc + len - 1) = '\0';
|
||||
|
||||
/* Strip leading quote */
|
||||
while (g_ascii_isspace (*spc))
|
||||
spc++;
|
||||
if (*spc == '"')
|
||||
spc++;
|
||||
|
||||
/* Strip trailing quote */
|
||||
len = strlen (spc);
|
||||
if (len > 0 && spc[len - 1] == '"')
|
||||
spc[len - 1] = '\0';
|
||||
|
||||
if (spc[0])
|
||||
g_hash_table_insert (hash, g_strdup (line), g_strdup (spc));
|
||||
}
|
||||
|
||||
#define LEASE_INVALID G_MININT64
|
||||
static GTimeSpan
|
||||
lease_validity_span (const char *str_expire, GDateTime *now)
|
||||
{
|
||||
GDateTime *expire = NULL;
|
||||
struct tm expire_tm;
|
||||
GTimeSpan span;
|
||||
|
||||
g_return_val_if_fail (now != NULL, LEASE_INVALID);
|
||||
g_return_val_if_fail (str_expire != NULL, LEASE_INVALID);
|
||||
|
||||
/* Skip initial number (day of week?) */
|
||||
if (!isdigit (*str_expire++))
|
||||
return LEASE_INVALID;
|
||||
if (!isspace (*str_expire++))
|
||||
return LEASE_INVALID;
|
||||
/* Read lease expiration (in UTC) */
|
||||
if (!strptime (str_expire, "%t%Y/%m/%d %H:%M:%S", &expire_tm))
|
||||
return LEASE_INVALID;
|
||||
|
||||
expire = g_date_time_new_utc (expire_tm.tm_year + 1900,
|
||||
expire_tm.tm_mon + 1,
|
||||
expire_tm.tm_mday,
|
||||
expire_tm.tm_hour,
|
||||
expire_tm.tm_min,
|
||||
expire_tm.tm_sec);
|
||||
if (!expire)
|
||||
return LEASE_INVALID;
|
||||
|
||||
span = g_date_time_difference (expire, now);
|
||||
g_date_time_unref (expire);
|
||||
|
||||
/* GDateTime only supports a range of less then 10000 years, so span can
|
||||
* not overflow or be equal to LEASE_INVALID */
|
||||
return span;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_dhcp_dhclient_read_lease_ip_configs:
|
||||
* @multi_idx: the multi index instance for the ip config object
|
||||
* @addr_family: whether to read IPv4 or IPv6 leases
|
||||
* @iface: the interface name to match leases with
|
||||
* @ifindex: interface index of @iface
|
||||
* @route_table: the route table for the default route.
|
||||
* @route_metric: the route metric for the default route.
|
||||
* @contents: the contents of a dhclient leasefile
|
||||
* @now: the current UTC date/time; pass %NULL to automatically use current
|
||||
* UTC time. Testcases may need a different value for 'now'
|
||||
*
|
||||
* Reads dhclient leases from @contents and parses them into either
|
||||
* #NMIP4Config or #NMIP6Config objects depending on the value of @addr_family.
|
||||
*
|
||||
* Returns: a #GSList of #NMIP4Config objects (if @addr_family is %AF_INET) or a list of
|
||||
* #NMIP6Config objects (if @addr_family is %AF_INET6) containing the lease data.
|
||||
*/
|
||||
GSList *
|
||||
nm_dhcp_dhclient_read_lease_ip_configs (NMDedupMultiIndex *multi_idx,
|
||||
int addr_family,
|
||||
const char *iface,
|
||||
int ifindex,
|
||||
guint32 route_table,
|
||||
guint32 route_metric,
|
||||
const char *contents,
|
||||
GDateTime *now)
|
||||
{
|
||||
GSList *parsed = NULL, *iter, *leases = NULL;
|
||||
char **line, **split = NULL;
|
||||
GHashTable *hash = NULL;
|
||||
gint32 now_monotonic_ts;
|
||||
|
||||
g_return_val_if_fail (contents != NULL, NULL);
|
||||
nm_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6));
|
||||
|
||||
split = g_strsplit_set (contents, "\n\r", -1);
|
||||
if (!split)
|
||||
return NULL;
|
||||
|
||||
for (line = split; line && *line; line++) {
|
||||
*line = g_strstrip (*line);
|
||||
|
||||
if (*line[0] == '#') {
|
||||
/* Comment */
|
||||
} else if (!strcmp (*line, "}")) {
|
||||
/* Lease ends */
|
||||
parsed = g_slist_append (parsed, hash);
|
||||
hash = NULL;
|
||||
} else if (!strcmp (*line, "lease {")) {
|
||||
/* Beginning of a new lease */
|
||||
if (hash) {
|
||||
/* Ignore malformed lease that doesn't end before new one starts */
|
||||
g_hash_table_destroy (hash);
|
||||
}
|
||||
|
||||
hash = g_hash_table_new_full (nm_str_hash, g_str_equal, g_free, g_free);
|
||||
} else if (hash && strlen (*line))
|
||||
add_lease_option (hash, *line);
|
||||
}
|
||||
g_strfreev (split);
|
||||
|
||||
/* Check if the last lease in the file was properly ended */
|
||||
if (hash) {
|
||||
/* Ignore malformed lease that doesn't end before new one starts */
|
||||
g_hash_table_destroy (hash);
|
||||
hash = NULL;
|
||||
}
|
||||
|
||||
if (now)
|
||||
g_date_time_ref (now);
|
||||
else
|
||||
now = g_date_time_new_now_utc ();
|
||||
now_monotonic_ts = nm_utils_get_monotonic_timestamp_s ();
|
||||
|
||||
for (iter = parsed; iter; iter = g_slist_next (iter)) {
|
||||
NMIP4Config *ip4;
|
||||
NMPlatformIP4Address address;
|
||||
const char *value;
|
||||
GTimeSpan expiry;
|
||||
guint32 tmp, gw = 0;
|
||||
|
||||
hash = iter->data;
|
||||
|
||||
/* Make sure this lease is for the interface we want */
|
||||
value = g_hash_table_lookup (hash, "interface");
|
||||
if (!value || strcmp (value, iface))
|
||||
continue;
|
||||
|
||||
value = g_hash_table_lookup (hash, "expire");
|
||||
if (!value)
|
||||
continue;
|
||||
expiry = lease_validity_span (value, now);
|
||||
if (expiry == LEASE_INVALID)
|
||||
continue;
|
||||
|
||||
/* scale expiry to seconds (and CLAMP into the range of guint32) */
|
||||
expiry = CLAMP (expiry / G_TIME_SPAN_SECOND, 0, NM_PLATFORM_LIFETIME_PERMANENT-1);
|
||||
if (expiry <= 0) {
|
||||
/* the address is already expired. Don't even add it. */
|
||||
continue;
|
||||
}
|
||||
|
||||
memset (&address, 0, sizeof (address));
|
||||
|
||||
/* IP4 address */
|
||||
value = g_hash_table_lookup (hash, "fixed-address");
|
||||
if (!value)
|
||||
continue;
|
||||
if (!inet_pton (AF_INET, value, &address.address))
|
||||
continue;
|
||||
address.peer_address = address.address;
|
||||
|
||||
/* Gateway */
|
||||
value = g_hash_table_lookup (hash, "option routers");
|
||||
if (!value)
|
||||
continue;
|
||||
if (!inet_pton (AF_INET, value, &gw))
|
||||
continue;
|
||||
|
||||
/* Netmask */
|
||||
value = g_hash_table_lookup (hash, "option subnet-mask");
|
||||
if (value && inet_pton (AF_INET, value, &tmp))
|
||||
address.plen = nm_utils_ip4_netmask_to_prefix (tmp);
|
||||
|
||||
/* Get default netmask for the IP according to appropriate class. */
|
||||
if (!address.plen)
|
||||
address.plen = _nm_utils_ip4_get_default_prefix (address.address);
|
||||
|
||||
address.timestamp = now_monotonic_ts;
|
||||
address.lifetime = address.preferred = expiry;
|
||||
address.addr_source = NM_IP_CONFIG_SOURCE_DHCP;
|
||||
|
||||
ip4 = nm_ip4_config_new (multi_idx, ifindex);
|
||||
nm_ip4_config_add_address (ip4, &address);
|
||||
|
||||
{
|
||||
const NMPlatformIP4Route r = {
|
||||
.rt_source = NM_IP_CONFIG_SOURCE_DHCP,
|
||||
.gateway = gw,
|
||||
.table_coerced = nm_platform_route_table_coerce (route_table),
|
||||
.metric = route_metric,
|
||||
};
|
||||
|
||||
nm_ip4_config_add_route (ip4, &r, NULL);
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup (hash, "option domain-name-servers");
|
||||
if (value) {
|
||||
char **dns, **dns_iter;
|
||||
|
||||
dns = g_strsplit_set (value, ",", -1);
|
||||
for (dns_iter = dns; dns_iter && *dns_iter; dns_iter++) {
|
||||
if (inet_pton (AF_INET, *dns_iter, &tmp))
|
||||
nm_ip4_config_add_nameserver (ip4, tmp);
|
||||
}
|
||||
if (dns)
|
||||
g_strfreev (dns);
|
||||
}
|
||||
|
||||
value = g_hash_table_lookup (hash, "option domain-name");
|
||||
if (value && value[0])
|
||||
nm_ip4_config_add_domain (ip4, value);
|
||||
|
||||
/* FIXME: static routes */
|
||||
|
||||
leases = g_slist_append (leases, ip4);
|
||||
}
|
||||
|
||||
g_date_time_unref (now);
|
||||
g_slist_free_full (parsed, (GDestroyNotify) g_hash_table_destroy);
|
||||
return leases;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,15 +43,6 @@ gboolean nm_dhcp_dhclient_save_duid (const char *leasefile,
|
|||
const char *escaped_duid,
|
||||
GError **error);
|
||||
|
||||
GSList *nm_dhcp_dhclient_read_lease_ip_configs (struct _NMDedupMultiIndex *multi_idx,
|
||||
int addr_family,
|
||||
const char *iface,
|
||||
int ifindex,
|
||||
guint32 route_table,
|
||||
guint32 route_metric,
|
||||
const char *contents,
|
||||
GDateTime *now);
|
||||
|
||||
GBytes *nm_dhcp_dhclient_get_client_id_from_config_file (const char *path);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DHCP_DHCLIENT_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -158,32 +158,6 @@ get_dhclient_leasefile (int addr_family,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static GSList *
|
||||
nm_dhcp_dhclient_get_lease_ip_configs (NMDedupMultiIndex *multi_idx,
|
||||
int addr_family,
|
||||
const char *iface,
|
||||
int ifindex,
|
||||
const char *uuid,
|
||||
guint32 route_table,
|
||||
guint32 route_metric)
|
||||
{
|
||||
gs_free char *contents = NULL;
|
||||
gs_free char *leasefile = NULL;
|
||||
|
||||
leasefile = get_dhclient_leasefile (addr_family, iface, uuid, NULL);
|
||||
if (!leasefile)
|
||||
return NULL;
|
||||
|
||||
if ( g_file_test (leasefile, G_FILE_TEST_EXISTS)
|
||||
&& g_file_get_contents (leasefile, &contents, NULL, NULL)
|
||||
&& contents
|
||||
&& contents[0]) {
|
||||
return nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, addr_family, iface, ifindex,
|
||||
route_table, route_metric, contents, NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
merge_dhclient_config (NMDhcpDhclient *self,
|
||||
int addr_family,
|
||||
|
|
@ -721,7 +695,6 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_dhclient = {
|
|||
.name = "dhclient",
|
||||
.get_type = nm_dhcp_dhclient_get_type,
|
||||
.get_path = nm_dhcp_dhclient_get_path,
|
||||
.get_lease_ip_configs = nm_dhcp_dhclient_get_lease_ip_configs,
|
||||
};
|
||||
|
||||
#endif /* WITH_DHCLIENT */
|
||||
|
|
|
|||
|
|
@ -265,7 +265,6 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcanon = {
|
|||
.name = "dhcpcanon",
|
||||
.get_type = nm_dhcp_dhcpcanon_get_type,
|
||||
.get_path = nm_dhcp_dhcpcanon_get_path,
|
||||
.get_lease_ip_configs = NULL,
|
||||
};
|
||||
|
||||
#endif /* WITH_DHCPCANON */
|
||||
|
|
|
|||
|
|
@ -251,7 +251,6 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_dhcpcd = {
|
|||
.name = "dhcpcd",
|
||||
.get_type = nm_dhcp_dhcpcd_get_type,
|
||||
.get_path = nm_dhcp_dhcpcd_get_path,
|
||||
.get_lease_ip_configs = NULL,
|
||||
};
|
||||
|
||||
#endif /* WITH_DHCPCD */
|
||||
|
|
|
|||
|
|
@ -333,31 +333,6 @@ nm_dhcp_manager_set_default_hostname (NMDhcpManager *manager, const char *hostna
|
|||
priv->default_hostname = g_strdup (hostname);
|
||||
}
|
||||
|
||||
GSList *
|
||||
nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
|
||||
NMDedupMultiIndex *multi_idx,
|
||||
int addr_family,
|
||||
const char *iface,
|
||||
int ifindex,
|
||||
const char *uuid,
|
||||
guint32 route_table,
|
||||
guint32 route_metric)
|
||||
{
|
||||
NMDhcpManagerPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DHCP_MANAGER (self), NULL);
|
||||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
g_return_val_if_fail (ifindex >= -1, NULL);
|
||||
g_return_val_if_fail (uuid != NULL, NULL);
|
||||
g_return_val_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6), NULL);
|
||||
|
||||
priv = NM_DHCP_MANAGER_GET_PRIVATE (self);
|
||||
if ( priv->client_factory
|
||||
&& priv->client_factory->get_lease_ip_configs)
|
||||
return priv->client_factory->get_lease_ip_configs (multi_idx, addr_family, iface, ifindex, uuid, route_table, route_metric);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_dhcp_manager_get_config (NMDhcpManager *self)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -78,15 +78,6 @@ NMDhcpClient * nm_dhcp_manager_start_ip6 (NMDhcpManager *manager,
|
|||
NMSettingIP6ConfigPrivacy privacy,
|
||||
guint needed_prefixes);
|
||||
|
||||
GSList * nm_dhcp_manager_get_lease_ip_configs (NMDhcpManager *self,
|
||||
struct _NMDedupMultiIndex *multi_idx,
|
||||
int addr_family,
|
||||
const char *iface,
|
||||
int ifindex,
|
||||
const char *uuid,
|
||||
guint32 route_table,
|
||||
guint32 route_metric);
|
||||
|
||||
/* For testing only */
|
||||
extern const char* nm_dhcp_helper_path;
|
||||
|
||||
|
|
|
|||
|
|
@ -450,36 +450,6 @@ get_leasefile_path (int addr_family, const char *iface, const char *uuid)
|
|||
iface);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
nm_dhcp_systemd_get_lease_ip_configs (NMDedupMultiIndex *multi_idx,
|
||||
int addr_family,
|
||||
const char *iface,
|
||||
int ifindex,
|
||||
const char *uuid,
|
||||
guint32 route_table,
|
||||
guint32 route_metric)
|
||||
{
|
||||
GSList *leases = NULL;
|
||||
gs_free char *path = NULL;
|
||||
sd_dhcp_lease *lease = NULL;
|
||||
NMIP4Config *ip4_config;
|
||||
int r;
|
||||
|
||||
if (addr_family != AF_INET)
|
||||
return NULL;
|
||||
|
||||
path = get_leasefile_path (addr_family, iface, uuid);
|
||||
r = dhcp_lease_load (&lease, path);
|
||||
if (r == 0 && lease) {
|
||||
ip4_config = lease_to_ip4_config (multi_idx, iface, ifindex, lease, NULL, route_table, route_metric, FALSE, NULL);
|
||||
if (ip4_config)
|
||||
leases = g_slist_append (leases, ip4_config);
|
||||
sd_dhcp_lease_unref (lease);
|
||||
}
|
||||
|
||||
return leases;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
|
|
@ -1091,5 +1061,4 @@ const NMDhcpClientFactory _nm_dhcp_client_factory_internal = {
|
|||
.name = "internal",
|
||||
.get_type = nm_dhcp_systemd_get_type,
|
||||
.get_path = NULL,
|
||||
.get_lease_ip_configs = nm_dhcp_systemd_get_lease_ip_configs,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
lease {
|
||||
interface "wlan0";
|
||||
fixed-address 192.168.1.180;
|
||||
option subnet-mask 255.255.255.0;
|
||||
option routers 192.168.1.1;
|
||||
option dhcp-lease-time 600;
|
||||
option dhcp-message-type 5;
|
||||
option domain-name-servers 192.168.1.1;
|
||||
option dhcp-server-identifier 192.168.1.1;
|
||||
option broadcast-address 192.168.1.255;
|
||||
renew 5 2013/11/01 19:56:15;
|
||||
rebind 5 2013/11/01 20:00:44;
|
||||
expire 5 2013/11/01 20:01:59;
|
||||
}
|
||||
lease {
|
||||
interface "wlan0";
|
||||
fixed-address 10.77.52.141;
|
||||
option subnet-mask 255.0.0.0;
|
||||
option dhcp-lease-time 1200;
|
||||
option routers 10.77.52.254;
|
||||
option dhcp-message-type 5;
|
||||
option dhcp-server-identifier 10.77.52.254;
|
||||
option domain-name-servers 8.8.8.8,8.8.4.4;
|
||||
option dhcp-renewal-time 600;
|
||||
option dhcp-rebinding-time 1050;
|
||||
option domain-name "morriesguest.local";
|
||||
renew 5 2013/11/01 20:01:08;
|
||||
rebind 5 2013/11/01 20:05:00;
|
||||
expire 5 2013/11/01 20:06:15;
|
||||
}
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
# missing fixed-address option
|
||||
lease {
|
||||
interface "wlan0";
|
||||
option subnet-mask 255.255.255.0;
|
||||
option routers 192.168.1.1;
|
||||
option dhcp-lease-time 600;
|
||||
option dhcp-message-type 5;
|
||||
option domain-name-servers 192.168.1.1;
|
||||
option dhcp-server-identifier 192.168.1.1;
|
||||
option broadcast-address 192.168.1.255;
|
||||
renew 5 2013/11/01 19:56:15;
|
||||
rebind 5 2013/11/01 20:00:44;
|
||||
expire 5 2013/11/01 20:01:59;
|
||||
}
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
# missing routers option
|
||||
lease {
|
||||
interface "wlan0";
|
||||
fixed-address 192.168.1.180;
|
||||
option subnet-mask 255.255.255.0;
|
||||
option dhcp-lease-time 600;
|
||||
option dhcp-message-type 5;
|
||||
option domain-name-servers 192.168.1.1;
|
||||
option dhcp-server-identifier 192.168.1.1;
|
||||
option broadcast-address 192.168.1.255;
|
||||
renew 5 2013/11/01 19:56:15;
|
||||
rebind 5 2013/11/01 20:00:44;
|
||||
expire 5 2013/11/01 20:01:59;
|
||||
}
|
||||
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
# missing expire time
|
||||
lease {
|
||||
interface "wlan0";
|
||||
fixed-address 192.168.1.180;
|
||||
option subnet-mask 255.255.255.0;
|
||||
option routers 192.168.1.1;
|
||||
option dhcp-lease-time 600;
|
||||
option dhcp-message-type 5;
|
||||
option domain-name-servers 192.168.1.1;
|
||||
option dhcp-server-identifier 192.168.1.1;
|
||||
option broadcast-address 192.168.1.255;
|
||||
renew 5 2013/11/01 19:56:15;
|
||||
rebind 5 2013/11/01 20:00:44;
|
||||
}
|
||||
|
||||
|
|
@ -36,12 +36,6 @@
|
|||
|
||||
#include "nm-test-utils-core.h"
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
static const int IFINDEX = 5;
|
||||
static const guint32 ROUTE_TABLE = RT_TABLE_MAIN;
|
||||
static const guint32 ROUTE_METRIC = 100;
|
||||
|
||||
static void
|
||||
test_config (const char *orig,
|
||||
const char *expected,
|
||||
|
|
@ -993,133 +987,6 @@ test_config_req_intf (void)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
test_read_lease_ip4_config_basic (void)
|
||||
{
|
||||
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new ();
|
||||
GError *error = NULL;
|
||||
char *contents = NULL;
|
||||
gboolean success;
|
||||
const char *path = TESTDIR "/leases/basic.leases";
|
||||
GSList *leases;
|
||||
GDateTime *now;
|
||||
NMIP4Config *config;
|
||||
const NMPlatformIP4Address *addr;
|
||||
guint32 expected_addr;
|
||||
|
||||
success = g_file_get_contents (path, &contents, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
/* Date from before the least expiration */
|
||||
now = g_date_time_new_utc (2013, 11, 1, 19, 55, 32);
|
||||
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now);
|
||||
g_assert_cmpint (g_slist_length (leases), ==, 2);
|
||||
|
||||
/* IP4Config #1 */
|
||||
config = g_slist_nth_data (leases, 0);
|
||||
g_assert (NM_IS_IP4_CONFIG (config));
|
||||
|
||||
/* Address */
|
||||
g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1);
|
||||
expected_addr = nmtst_inet4_from_string ("192.168.1.180");
|
||||
addr = _nmtst_ip4_config_get_address (config, 0);
|
||||
g_assert_cmpint (addr->address, ==, expected_addr);
|
||||
g_assert_cmpint (addr->peer_address, ==, expected_addr);
|
||||
g_assert_cmpint (addr->plen, ==, 24);
|
||||
|
||||
/* Gateway */
|
||||
expected_addr = nmtst_inet4_from_string ("192.168.1.1");
|
||||
g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr);
|
||||
|
||||
/* DNS */
|
||||
g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 1);
|
||||
expected_addr = nmtst_inet4_from_string ("192.168.1.1");
|
||||
g_assert_cmpint (nm_ip4_config_get_nameserver (config, 0), ==, expected_addr);
|
||||
|
||||
g_assert_cmpint (nm_ip4_config_get_num_domains (config), ==, 0);
|
||||
|
||||
/* IP4Config #2 */
|
||||
config = g_slist_nth_data (leases, 1);
|
||||
g_assert (NM_IS_IP4_CONFIG (config));
|
||||
|
||||
/* Address */
|
||||
g_assert_cmpint (nm_ip4_config_get_num_addresses (config), ==, 1);
|
||||
expected_addr = nmtst_inet4_from_string ("10.77.52.141");
|
||||
addr = _nmtst_ip4_config_get_address (config, 0);
|
||||
g_assert_cmpint (addr->address, ==, expected_addr);
|
||||
g_assert_cmpint (addr->peer_address, ==, expected_addr);
|
||||
g_assert_cmpint (addr->plen, ==, 8);
|
||||
|
||||
/* Gateway */
|
||||
expected_addr = nmtst_inet4_from_string ("10.77.52.254");
|
||||
g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr);
|
||||
|
||||
/* DNS */
|
||||
g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 2);
|
||||
expected_addr = nmtst_inet4_from_string ("8.8.8.8");
|
||||
g_assert_cmpint (nm_ip4_config_get_nameserver (config, 0), ==, expected_addr);
|
||||
expected_addr = nmtst_inet4_from_string ("8.8.4.4");
|
||||
g_assert_cmpint (nm_ip4_config_get_nameserver (config, 1), ==, expected_addr);
|
||||
|
||||
/* Domains */
|
||||
g_assert_cmpint (nm_ip4_config_get_num_domains (config), ==, 1);
|
||||
g_assert_cmpstr (nm_ip4_config_get_domain (config, 0), ==, "morriesguest.local");
|
||||
|
||||
g_slist_free_full (leases, g_object_unref);
|
||||
g_date_time_unref (now);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_lease_ip4_config_expired (void)
|
||||
{
|
||||
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new ();
|
||||
GError *error = NULL;
|
||||
char *contents = NULL;
|
||||
gboolean success;
|
||||
const char *path = TESTDIR "/leases/basic.leases";
|
||||
GSList *leases;
|
||||
GDateTime *now;
|
||||
|
||||
success = g_file_get_contents (path, &contents, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
/* Date from *after* the lease expiration */
|
||||
now = g_date_time_new_utc (2013, 12, 1, 19, 55, 32);
|
||||
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now);
|
||||
g_assert (leases == NULL);
|
||||
|
||||
g_date_time_unref (now);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
static void
|
||||
test_read_lease_ip4_config_expect_failure (gconstpointer user_data)
|
||||
{
|
||||
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new ();
|
||||
GError *error = NULL;
|
||||
char *contents = NULL;
|
||||
gboolean success;
|
||||
GSList *leases;
|
||||
GDateTime *now;
|
||||
|
||||
success = g_file_get_contents ((const char *) user_data, &contents, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
g_assert (success);
|
||||
|
||||
/* Date from before the least expiration */
|
||||
now = g_date_time_new_utc (2013, 11, 1, 1, 1, 1);
|
||||
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now);
|
||||
g_assert (leases == NULL);
|
||||
|
||||
g_date_time_unref (now);
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMTST_DEFINE ();
|
||||
|
||||
int
|
||||
|
|
@ -1157,18 +1024,6 @@ main (int argc, char **argv)
|
|||
g_test_add_func ("/dhcp/dhclient/write_existing_duid", test_write_existing_duid);
|
||||
g_test_add_func ("/dhcp/dhclient/write_existing_commented_duid", test_write_existing_commented_duid);
|
||||
|
||||
g_test_add_func ("/dhcp/dhclient/leases/ip4-config/basic", test_read_lease_ip4_config_basic);
|
||||
g_test_add_func ("/dhcp/dhclient/leases/ip4-config/expired", test_read_lease_ip4_config_expired);
|
||||
g_test_add_data_func ("/dhcp/dhclient/leases/ip4-config/missing-address",
|
||||
TESTDIR "/leases/malformed1.leases",
|
||||
test_read_lease_ip4_config_expect_failure);
|
||||
g_test_add_data_func ("/dhcp/dhclient/leases/ip4-config/missing-gateway",
|
||||
TESTDIR "/leases/malformed2.leases",
|
||||
test_read_lease_ip4_config_expect_failure);
|
||||
g_test_add_data_func ("/dhcp/dhclient/leases/ip4-config/missing-expire",
|
||||
TESTDIR "/leases/malformed3.leases",
|
||||
test_read_lease_ip4_config_expect_failure);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1474,23 +1474,6 @@ nm_dns_manager_set_hostname (NMDnsManager *self,
|
|||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_dns_manager_get_resolv_conf_explicit (NMDnsManager *self)
|
||||
{
|
||||
NMDnsManagerPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (NM_IS_DNS_MANAGER (self), FALSE);
|
||||
|
||||
priv = NM_DNS_MANAGER_GET_PRIVATE (self);
|
||||
|
||||
if ( NM_IN_SET (priv->rc_manager, NM_DNS_MANAGER_RESOLV_CONF_MAN_UNMANAGED,
|
||||
NM_DNS_MANAGER_RESOLV_CONF_MAN_IMMUTABLE)
|
||||
|| priv->plugin)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
nm_dns_manager_begin_updates (NMDnsManager *self, const char *func)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -123,8 +123,6 @@ typedef enum {
|
|||
NM_DNS_MANAGER_RESOLV_CONF_MAN_NETCONFIG,
|
||||
} NMDnsManagerResolvConfManager;
|
||||
|
||||
gboolean nm_dns_manager_get_resolv_conf_explicit (NMDnsManager *self);
|
||||
|
||||
void nm_dns_manager_stop (NMDnsManager *self);
|
||||
|
||||
#endif /* __NETWORKMANAGER_DNS_MANAGER_H__ */
|
||||
|
|
|
|||
|
|
@ -195,6 +195,10 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data)
|
|||
continue;
|
||||
nm_utils_ip6_address_clear_host_address (&r_network, ndp_msg_opt_prefix (msg, offset), r_plen);
|
||||
|
||||
if ( IN6_IS_ADDR_UNSPECIFIED (&r_network)
|
||||
|| IN6_IS_ADDR_LINKLOCAL (&r_network))
|
||||
continue;
|
||||
|
||||
if (ndp_msg_opt_prefix_flag_on_link (msg, offset)) {
|
||||
NMNDiscRoute route = {
|
||||
.network = r_network,
|
||||
|
|
|
|||
|
|
@ -351,6 +351,8 @@ nm_ndisc_add_address (NMNDisc *ndisc, const NMNDiscAddress *new)
|
|||
|
||||
nm_assert (new);
|
||||
nm_assert (new->timestamp > 0 && new->timestamp < G_MAXINT32);
|
||||
nm_assert (!IN6_IS_ADDR_UNSPECIFIED (&new->address));
|
||||
nm_assert (!IN6_IS_ADDR_LINKLOCAL (&new->address));
|
||||
|
||||
for (i = 0; i < rdata->addresses->len; i++) {
|
||||
NMNDiscAddress *item = &g_array_index (rdata->addresses, NMNDiscAddress, i);
|
||||
|
|
|
|||
|
|
@ -1877,110 +1877,6 @@ nm_utils_new_infiniband_name (char *name, const char *parent_name, int p_key)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean
|
||||
nm_utils_resolve_conf_parse (int addr_family,
|
||||
const char *rc_contents,
|
||||
GArray *nameservers,
|
||||
GPtrArray *dns_options)
|
||||
{
|
||||
guint i;
|
||||
gboolean changed = FALSE;
|
||||
gs_free const char **lines = NULL;
|
||||
gsize l;
|
||||
|
||||
g_return_val_if_fail (rc_contents, FALSE);
|
||||
g_return_val_if_fail (nameservers, FALSE);
|
||||
g_return_val_if_fail ( ( addr_family == AF_INET
|
||||
&& g_array_get_element_size (nameservers) == sizeof (in_addr_t))
|
||||
|| ( addr_family == AF_INET6
|
||||
&& g_array_get_element_size (nameservers) == sizeof (struct in6_addr)), FALSE);
|
||||
|
||||
lines = nm_utils_strsplit_set (rc_contents, "\r\n");
|
||||
if (!lines)
|
||||
return FALSE;
|
||||
|
||||
/* like glibc's MATCH() macro in resolv/res_init.c. */
|
||||
#define RC_MATCH(line, option, out_arg) \
|
||||
({ \
|
||||
const char *const _line = (line); \
|
||||
gboolean _match = FALSE; \
|
||||
\
|
||||
if ( (strncmp (_line, option, NM_STRLEN (option)) == 0) \
|
||||
&& (NM_IN_SET (_line[NM_STRLEN (option)], ' ', '\t'))) { \
|
||||
_match = TRUE;\
|
||||
(out_arg) = &_line[NM_STRLEN (option) + 1]; \
|
||||
} \
|
||||
_match; \
|
||||
})
|
||||
|
||||
for (l = 0; lines[l]; l++) {
|
||||
const char *const line = lines[l];
|
||||
const char *s = NULL;
|
||||
|
||||
if (RC_MATCH (line, "nameserver", s)) {
|
||||
gs_free char *s_cpy = NULL;
|
||||
NMIPAddr ns;
|
||||
|
||||
s = nm_strstrip_avoid_copy (s, &s_cpy);
|
||||
if (inet_pton (addr_family, s, &ns) != 1)
|
||||
continue;
|
||||
|
||||
if (addr_family == AF_INET) {
|
||||
if (!ns.addr4)
|
||||
continue;
|
||||
for (i = 0; i < nameservers->len; i++) {
|
||||
if (g_array_index (nameservers, guint32, i) == ns.addr4)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (IN6_IS_ADDR_UNSPECIFIED (&ns.addr6))
|
||||
continue;
|
||||
for (i = 0; i < nameservers->len; i++) {
|
||||
struct in6_addr *t = &g_array_index (nameservers, struct in6_addr, i);
|
||||
|
||||
if (IN6_ARE_ADDR_EQUAL (t, &ns.addr6))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == nameservers->len) {
|
||||
g_array_append_val (nameservers, ns);
|
||||
changed = TRUE;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (RC_MATCH (line, "options", s)) {
|
||||
if (!dns_options)
|
||||
continue;
|
||||
|
||||
s = nm_str_skip_leading_spaces (s);
|
||||
if (s[0]) {
|
||||
gs_free const char **tokens = NULL;
|
||||
gsize i_tokens;
|
||||
|
||||
tokens = nm_utils_strsplit_set (s, " \t");
|
||||
for (i_tokens = 0; tokens && tokens[i_tokens]; i_tokens++) {
|
||||
gs_free char *t = g_strstrip (g_strdup (tokens[i_tokens]));
|
||||
|
||||
if ( _nm_utils_dns_option_validate (t, NULL, NULL,
|
||||
addr_family == AF_INET6,
|
||||
_nm_utils_dns_option_descs)
|
||||
&& _nm_utils_dns_option_find_idx (dns_options, t) < 0) {
|
||||
g_ptr_array_add (dns_options, g_steal_pointer (&t));
|
||||
changed = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* nm_utils_cmp_connection_by_autoconnect_priority:
|
||||
* @a:
|
||||
|
|
|
|||
|
|
@ -229,11 +229,6 @@ gboolean nm_utils_connection_has_default_route (NMConnection *connection,
|
|||
char *nm_utils_new_vlan_name (const char *parent_iface, guint32 vlan_id);
|
||||
const char *nm_utils_new_infiniband_name (char *name, const char *parent_name, int p_key);
|
||||
|
||||
gboolean nm_utils_resolve_conf_parse (int addr_family,
|
||||
const char *rc_contents,
|
||||
GArray *nameservers,
|
||||
GPtrArray *dns_options);
|
||||
|
||||
int nm_utils_cmp_connection_by_autoconnect_priority (NMConnection *a, NMConnection *b);
|
||||
|
||||
void nm_utils_log_connection_diff (NMConnection *connection, NMConnection *diff_base, guint32 level, guint64 domain, const char *name, const char *prefix);
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ dhcp4_state_changed (NMDhcpClient *client,
|
|||
g_assert (nm_ip4_config_get_ifindex (ip4_config) == gl.ifindex);
|
||||
|
||||
existing = nm_ip4_config_capture (nm_platform_get_multi_idx (NM_PLATFORM_GET),
|
||||
NM_PLATFORM_GET, gl.ifindex, FALSE);
|
||||
NM_PLATFORM_GET, gl.ifindex);
|
||||
if (last_config)
|
||||
nm_ip4_config_subtract (existing, last_config, 0);
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in
|
|||
NMIP6Config *existing;
|
||||
|
||||
existing = nm_ip6_config_capture (nm_platform_get_multi_idx (NM_PLATFORM_GET),
|
||||
NM_PLATFORM_GET, gl.ifindex, FALSE, global_opt.tempaddr);
|
||||
NM_PLATFORM_GET, gl.ifindex, global_opt.tempaddr);
|
||||
if (ndisc_config)
|
||||
nm_ip6_config_subtract (existing, ndisc_config, 0);
|
||||
else {
|
||||
|
|
|
|||
|
|
@ -593,14 +593,13 @@ nm_ip4_config_clone (const NMIP4Config *self)
|
|||
}
|
||||
|
||||
NMIP4Config *
|
||||
nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf)
|
||||
nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex)
|
||||
{
|
||||
NMIP4Config *self;
|
||||
NMIP4ConfigPrivate *priv;
|
||||
const NMDedupMultiHeadEntry *head_entry;
|
||||
NMDedupMultiIter iter;
|
||||
const NMPObject *plobj = NULL;
|
||||
gboolean has_addresses = FALSE;
|
||||
|
||||
nm_assert (ifindex > 0);
|
||||
|
||||
|
|
@ -632,7 +631,6 @@ nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i
|
|||
nm_dedup_multi_head_entry_sort (head_entry,
|
||||
sort_captured_addresses,
|
||||
NULL);
|
||||
has_addresses = TRUE;
|
||||
_notify_addresses (self);
|
||||
}
|
||||
|
||||
|
|
@ -644,23 +642,6 @@ nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i
|
|||
nmp_cache_iter_for_each (&iter, head_entry, &plobj)
|
||||
_add_route (self, plobj, NULL, NULL);
|
||||
|
||||
/* If the interface has the default route, and has IPv4 addresses, capture
|
||||
* nameservers from /etc/resolv.conf.
|
||||
*/
|
||||
if ( has_addresses
|
||||
&& priv->best_default_route
|
||||
&& capture_resolv_conf) {
|
||||
gs_free char *rc_contents = NULL;
|
||||
|
||||
if (g_file_get_contents (_PATH_RESCONF, &rc_contents, NULL, NULL)) {
|
||||
if (nm_utils_resolve_conf_parse (AF_INET,
|
||||
rc_contents,
|
||||
priv->nameservers,
|
||||
priv->dns_options))
|
||||
_notify (self, PROP_NAMESERVERS);
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ int nm_ip4_config_get_ifindex (const NMIP4Config *self);
|
|||
|
||||
NMDedupMultiIndex *nm_ip4_config_get_multi_idx (const NMIP4Config *self);
|
||||
|
||||
NMIP4Config *nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf);
|
||||
NMIP4Config *nm_ip4_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex);
|
||||
|
||||
void nm_ip4_config_add_dependent_routes (NMIP4Config *self,
|
||||
guint32 route_table,
|
||||
|
|
@ -397,12 +397,38 @@ nm_ip_config_add_address (NMIPConfig *self, const NMPlatformIPAddress *address)
|
|||
_NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_add_address, nm_ip6_config_add_address, (gconstpointer) address);
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_ip_config_reset_addresses (NMIPConfig *self)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_reset_addresses, nm_ip6_config_reset_addresses);
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_ip_config_add_route (NMIPConfig *self,
|
||||
const NMPlatformIPRoute *new,
|
||||
const NMPObject **out_obj_new)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_add_route, nm_ip6_config_add_route, (gpointer) new, out_obj_new);
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_ip_config_reset_routes (NMIPConfig *self)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_reset_routes, nm_ip6_config_reset_routes);
|
||||
}
|
||||
|
||||
static inline int
|
||||
nm_ip_config_get_dns_priority (const NMIPConfig *self)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH (self, nm_ip4_config_get_dns_priority, nm_ip6_config_get_dns_priority);
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_ip_config_set_dns_priority (NMIPConfig *self, gint priority)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_VOID (self, nm_ip4_config_set_dns_priority, nm_ip6_config_set_dns_priority, priority);
|
||||
}
|
||||
|
||||
static inline void
|
||||
nm_ip_config_add_nameserver (NMIPConfig *self, const NMIPAddr *ns)
|
||||
{
|
||||
|
|
@ -475,18 +501,17 @@ nm_ip_config_get_dns_option (const NMIPConfig *self, guint i)
|
|||
_NM_IP_CONFIG_DISPATCH (self, nm_ip4_config_get_dns_option, nm_ip6_config_get_dns_option, i);
|
||||
}
|
||||
|
||||
#define _NM_IP_CONFIG_DISPATCH_SET_OP(dst, src, v4_func, v6_func, ...) \
|
||||
#define _NM_IP_CONFIG_DISPATCH_SET_OP(_return, dst, src, v4_func, v6_func, ...) \
|
||||
G_STMT_START { \
|
||||
gpointer _dst = (dst); \
|
||||
gconstpointer _src = (src); \
|
||||
int family = nm_ip_config_get_addr_family (_dst); \
|
||||
\
|
||||
nm_assert (family == nm_ip_config_get_addr_family (_src)); \
|
||||
if (family == AF_INET) { \
|
||||
v4_func ((NMIP4Config *) _dst, (const NMIP4Config *) _src, ##__VA_ARGS__); \
|
||||
if (NM_IS_IP4_CONFIG (_dst)) { \
|
||||
nm_assert (NM_IS_IP4_CONFIG (_src)); \
|
||||
_return v4_func ((NMIP4Config *) _dst, (const NMIP4Config *) _src, ##__VA_ARGS__); \
|
||||
} else { \
|
||||
nm_assert (family == AF_INET6); \
|
||||
v6_func ((NMIP6Config *) _dst, (const NMIP6Config *) _src, ##__VA_ARGS__); \
|
||||
nm_assert (NM_IS_IP6_CONFIG (_src)); \
|
||||
_return v6_func ((NMIP6Config *) _dst, (const NMIP6Config *) _src, ##__VA_ARGS__); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
|
||||
|
|
@ -495,7 +520,7 @@ nm_ip_config_intersect (NMIPConfig *dst,
|
|||
const NMIPConfig *src,
|
||||
guint32 default_route_metric_penalty)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_SET_OP (dst, src,
|
||||
_NM_IP_CONFIG_DISPATCH_SET_OP (, dst, src,
|
||||
nm_ip4_config_intersect,
|
||||
nm_ip6_config_intersect,
|
||||
default_route_metric_penalty);
|
||||
|
|
@ -506,7 +531,7 @@ nm_ip_config_subtract (NMIPConfig *dst,
|
|||
const NMIPConfig *src,
|
||||
guint32 default_route_metric_penalty)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_SET_OP (dst, src,
|
||||
_NM_IP_CONFIG_DISPATCH_SET_OP (, dst, src,
|
||||
nm_ip4_config_subtract,
|
||||
nm_ip6_config_subtract,
|
||||
default_route_metric_penalty);
|
||||
|
|
@ -518,30 +543,41 @@ nm_ip_config_merge (NMIPConfig *dst,
|
|||
NMIPConfigMergeFlags merge_flags,
|
||||
guint32 default_route_metric_penalty)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_SET_OP (dst, src,
|
||||
_NM_IP_CONFIG_DISPATCH_SET_OP (, dst, src,
|
||||
nm_ip4_config_merge,
|
||||
nm_ip6_config_merge,
|
||||
merge_flags,
|
||||
default_route_metric_penalty);
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
nm_ip_config_replace (NMIPConfig *dst,
|
||||
const NMIPConfig *src,
|
||||
gboolean *relevant_changes)
|
||||
{
|
||||
_NM_IP_CONFIG_DISPATCH_SET_OP (return, dst, src,
|
||||
nm_ip4_config_replace,
|
||||
nm_ip6_config_replace,
|
||||
relevant_changes);
|
||||
}
|
||||
|
||||
static inline NMIPConfig *
|
||||
nm_ip_config_intersect_alloc (const NMIPConfig *a,
|
||||
const NMIPConfig *b,
|
||||
guint32 default_route_metric_penalty)
|
||||
{
|
||||
int family;
|
||||
|
||||
family = nm_ip_config_get_addr_family (a);
|
||||
nm_assert (family == nm_ip_config_get_addr_family (b));
|
||||
|
||||
if (family == AF_INET)
|
||||
if (NM_IS_IP4_CONFIG (a)) {
|
||||
nm_assert (NM_IS_IP4_CONFIG (b));
|
||||
return (NMIPConfig *) nm_ip4_config_intersect_alloc ((const NMIP4Config *) a,
|
||||
(const NMIP4Config *) b,
|
||||
default_route_metric_penalty);
|
||||
else
|
||||
} else {
|
||||
nm_assert (NM_IS_IP6_CONFIG (a));
|
||||
nm_assert (NM_IS_IP6_CONFIG (b));
|
||||
return (NMIPConfig *) nm_ip6_config_intersect_alloc ((const NMIP6Config *) a,
|
||||
(const NMIP6Config *) b,
|
||||
default_route_metric_penalty);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __NETWORKMANAGER_IP4_CONFIG_H__ */
|
||||
|
|
|
|||
|
|
@ -376,14 +376,13 @@ nm_ip6_config_clone (const NMIP6Config *self)
|
|||
}
|
||||
|
||||
NMIP6Config *
|
||||
nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary)
|
||||
nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex, NMSettingIP6ConfigPrivacy use_temporary)
|
||||
{
|
||||
NMIP6Config *self;
|
||||
NMIP6ConfigPrivate *priv;
|
||||
const NMDedupMultiHeadEntry *head_entry;
|
||||
NMDedupMultiIter iter;
|
||||
const NMPObject *plobj = NULL;
|
||||
gboolean has_addresses = FALSE;
|
||||
|
||||
nm_assert (ifindex > 0);
|
||||
|
||||
|
|
@ -409,7 +408,6 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i
|
|||
NULL,
|
||||
NULL))
|
||||
nm_assert_not_reached ();
|
||||
has_addresses = TRUE;
|
||||
}
|
||||
head_entry = nm_ip6_config_lookup_addresses (self);
|
||||
nm_assert (head_entry);
|
||||
|
|
@ -426,23 +424,6 @@ nm_ip6_config_capture (NMDedupMultiIndex *multi_idx, NMPlatform *platform, int i
|
|||
nmp_cache_iter_for_each (&iter, head_entry, &plobj)
|
||||
_add_route (self, plobj, NULL, NULL);
|
||||
|
||||
/* If the interface has the default route, and has IPv6 addresses, capture
|
||||
* nameservers from /etc/resolv.conf.
|
||||
*/
|
||||
if ( has_addresses
|
||||
&& priv->best_default_route
|
||||
&& capture_resolv_conf) {
|
||||
gs_free char *rc_contents = NULL;
|
||||
|
||||
if (g_file_get_contents (_PATH_RESCONF, &rc_contents, NULL, NULL)) {
|
||||
if (nm_utils_resolve_conf_parse (AF_INET6,
|
||||
rc_contents,
|
||||
priv->nameservers,
|
||||
priv->dns_options))
|
||||
_notify (self, PROP_NAMESERVERS);
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
@ -1691,19 +1672,43 @@ nm_ip6_config_lookup_address (const NMIP6Config *self,
|
|||
}
|
||||
|
||||
const NMPlatformIP6Address *
|
||||
nm_ip6_config_get_address_first_nontentative (const NMIP6Config *self, gboolean linklocal)
|
||||
nm_ip6_config_find_first_address (const NMIP6Config *self,
|
||||
NMPlatformMatchFlags match_flag)
|
||||
{
|
||||
const NMPlatformIP6Address *addr;
|
||||
NMDedupMultiIter iter;
|
||||
|
||||
g_return_val_if_fail (NM_IS_IP6_CONFIG (self), NULL);
|
||||
|
||||
linklocal = !!linklocal;
|
||||
nm_assert (!NM_FLAGS_ANY (match_flag, ~( NM_PLATFORM_MATCH_WITH_ADDRTYPE__ANY
|
||||
| NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY)));
|
||||
|
||||
nm_assert (NM_FLAGS_ANY (match_flag, NM_PLATFORM_MATCH_WITH_ADDRTYPE__ANY));
|
||||
nm_assert (NM_FLAGS_ANY (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY));
|
||||
|
||||
nm_ip_config_iter_ip6_address_for_each (&iter, self, &addr) {
|
||||
if ( ((!!IN6_IS_ADDR_LINKLOCAL (&addr->address)) == linklocal)
|
||||
&& !(addr->n_ifa_flags & IFA_F_TENTATIVE))
|
||||
return addr;
|
||||
|
||||
if (IN6_IS_ADDR_LINKLOCAL (&addr->address)) {
|
||||
if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL))
|
||||
continue;
|
||||
} else {
|
||||
if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NM_FLAGS_HAS (addr->n_ifa_flags, IFA_F_DADFAILED)) {
|
||||
if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED))
|
||||
continue;
|
||||
} else if ( NM_FLAGS_HAS (addr->n_ifa_flags, IFA_F_TENTATIVE)
|
||||
&& !NM_FLAGS_HAS (addr->n_ifa_flags, IFA_F_OPTIMISTIC)) {
|
||||
if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE))
|
||||
continue;
|
||||
} else {
|
||||
if (!NM_FLAGS_HAS (match_flag, NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL))
|
||||
continue;
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ int nm_ip6_config_get_ifindex (const NMIP6Config *self);
|
|||
struct _NMDedupMultiIndex *nm_ip6_config_get_multi_idx (const NMIP6Config *self);
|
||||
|
||||
NMIP6Config *nm_ip6_config_capture (struct _NMDedupMultiIndex *multi_idx, NMPlatform *platform, int ifindex,
|
||||
gboolean capture_resolv_conf, NMSettingIP6ConfigPrivacy use_temporary);
|
||||
NMSettingIP6ConfigPrivacy use_temporary);
|
||||
|
||||
void nm_ip6_config_add_dependent_routes (NMIP6Config *self,
|
||||
guint32 route_table,
|
||||
|
|
@ -149,7 +149,8 @@ void _nmtst_ip6_config_del_address (NMIP6Config *self, guint i);
|
|||
guint nm_ip6_config_get_num_addresses (const NMIP6Config *self);
|
||||
const NMPlatformIP6Address *nm_ip6_config_get_first_address (const NMIP6Config *self);
|
||||
const NMPlatformIP6Address *_nmtst_ip6_config_get_address (const NMIP6Config *self, guint i);
|
||||
const NMPlatformIP6Address *nm_ip6_config_get_address_first_nontentative (const NMIP6Config *self, gboolean linklocal);
|
||||
const NMPlatformIP6Address *nm_ip6_config_find_first_address (const NMIP6Config *self,
|
||||
NMPlatformMatchFlags match_flag);
|
||||
gboolean nm_ip6_config_address_exists (const NMIP6Config *self, const NMPlatformIP6Address *address);
|
||||
const NMPlatformIP6Address *nm_ip6_config_lookup_address (const NMIP6Config *self,
|
||||
const struct in6_addr *addr);
|
||||
|
|
|
|||
|
|
@ -83,6 +83,16 @@ typedef enum { /*< skip >*/
|
|||
LOGD_IP = LOGD_IP4 | LOGD_IP6,
|
||||
} NMLogDomain;
|
||||
|
||||
static inline NMLogDomain
|
||||
LOGD_IP_from_af (int addr_family)
|
||||
{
|
||||
switch (addr_family) {
|
||||
case AF_INET: return LOGD_IP4;
|
||||
case AF_INET6: return LOGD_IP6;
|
||||
}
|
||||
g_return_val_if_reached (LOGD_NONE);
|
||||
}
|
||||
|
||||
/* Log levels */
|
||||
typedef enum { /*< skip >*/
|
||||
LOGL_TRACE,
|
||||
|
|
|
|||
|
|
@ -171,6 +171,34 @@ typedef enum { /*< skip >*/
|
|||
NM_PLATFORM_ERROR_CANT_SET_MTU,
|
||||
} NMPlatformError;
|
||||
|
||||
typedef enum {
|
||||
|
||||
/* match-flags are strictly inclusive. That means,
|
||||
* by default nothing is matched, but if you enable a particular
|
||||
* flag, a candidate that matches passes the check.
|
||||
*
|
||||
* In other words: adding more flags can only extend the result
|
||||
* set of matching objects.
|
||||
*
|
||||
* Also, the flags form partitions. Like, an address can be either of
|
||||
* ADDRTYPE_NORMAL or ADDRTYPE_LINKLOCAL, but never both. Same for
|
||||
* the ADDRSTATE match types.
|
||||
*/
|
||||
NM_PLATFORM_MATCH_WITH_NONE = 0,
|
||||
|
||||
NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL = (1LL << 0),
|
||||
NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL = (1LL << 1),
|
||||
NM_PLATFORM_MATCH_WITH_ADDRTYPE__ANY = NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL
|
||||
| NM_PLATFORM_MATCH_WITH_ADDRTYPE_LINKLOCAL,
|
||||
|
||||
NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL = (1LL << 2),
|
||||
NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE = (1LL << 3),
|
||||
NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED = (1LL << 4),
|
||||
NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY = NM_PLATFORM_MATCH_WITH_ADDRSTATE_NORMAL
|
||||
| NM_PLATFORM_MATCH_WITH_ADDRSTATE_TENTATIVE
|
||||
| NM_PLATFORM_MATCH_WITH_ADDRSTATE_DADFAILED,
|
||||
} NMPlatformMatchFlags;
|
||||
|
||||
#define NM_PLATFORM_LINK_OTHER_NETNS (-1)
|
||||
|
||||
#define __NMPlatformObject_COMMON \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ test_units = [
|
|||
'test-ip4-config',
|
||||
'test-ip6-config',
|
||||
'test-dcb',
|
||||
'test-resolvconf-capture',
|
||||
'test-wired-defname',
|
||||
'test-utils'
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,298 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2013 Red Hat, Inc.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-ip4-config.h"
|
||||
#include "nm-ip6-config.h"
|
||||
#include "platform/nm-platform.h"
|
||||
|
||||
#include "nm-test-utils-core.h"
|
||||
|
||||
static void
|
||||
test_capture_empty (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr));
|
||||
|
||||
g_assert (!nm_utils_resolve_conf_parse (AF_INET, "", ns4, NULL));
|
||||
g_assert_cmpint (ns4->len, ==, 0);
|
||||
|
||||
g_assert (!nm_utils_resolve_conf_parse (AF_INET6, "", ns6, NULL));
|
||||
g_assert_cmpint (ns6->len, ==, 0);
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
g_array_free (ns6, TRUE);
|
||||
}
|
||||
|
||||
#define assert_dns4_entry(a, i, s) \
|
||||
g_assert_cmpint ((g_array_index ((a), guint32, (i))), ==, nmtst_inet4_from_string (s));
|
||||
|
||||
#define assert_dns6_entry(a, i, s) \
|
||||
g_assert (IN6_ARE_ADDR_EQUAL (&g_array_index ((a), struct in6_addr, (i)), nmtst_inet6_from_string (s)))
|
||||
|
||||
#define assert_dns_option(a, i, s) \
|
||||
g_assert_cmpstr ((a)->pdata[(i)], ==, (s));
|
||||
|
||||
static void
|
||||
test_capture_basic4 (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
const char *rc =
|
||||
"# neato resolv.conf\r\n"
|
||||
"domain foobar.com\r\n"
|
||||
"search foobar.com\r\n"
|
||||
"nameserver 4.2.2.1\r\n"
|
||||
"nameserver 4.2.2.2\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL));
|
||||
g_assert_cmpint (ns4->len, ==, 2);
|
||||
assert_dns4_entry (ns4, 0, "4.2.2.1");
|
||||
assert_dns4_entry (ns4, 1, "4.2.2.2");
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_dup4 (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
const char *rc =
|
||||
"# neato resolv.conf\r\n"
|
||||
"domain foobar.com\r\n"
|
||||
"search foobar.com\r\n"
|
||||
"nameserver 4.2.2.1\r\n"
|
||||
"nameserver 4.2.2.1\r\n"
|
||||
"nameserver 4.2.2.2\r\n";
|
||||
|
||||
/* Check that duplicates are ignored */
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL));
|
||||
g_assert_cmpint (ns4->len, ==, 2);
|
||||
assert_dns4_entry (ns4, 0, "4.2.2.1");
|
||||
assert_dns4_entry (ns4, 1, "4.2.2.2");
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_basic6 (void)
|
||||
{
|
||||
GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr));
|
||||
const char *rc =
|
||||
"# neato resolv.conf\r\n"
|
||||
"domain foobar.com\r\n"
|
||||
"search foobar.com\r\n"
|
||||
"nameserver 2001:4860:4860::8888\r\n"
|
||||
"nameserver 2001:4860:4860::8844\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, NULL));
|
||||
g_assert_cmpint (ns6->len, ==, 2);
|
||||
assert_dns6_entry (ns6, 0, "2001:4860:4860::8888");
|
||||
assert_dns6_entry (ns6, 1, "2001:4860:4860::8844");
|
||||
|
||||
g_array_free (ns6, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_dup6 (void)
|
||||
{
|
||||
GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr));
|
||||
const char *rc =
|
||||
"# neato resolv.conf\r\n"
|
||||
"domain foobar.com\r\n"
|
||||
"search foobar.com\r\n"
|
||||
"nameserver 2001:4860:4860::8888\r\n"
|
||||
"nameserver 2001:4860:4860::8888\r\n"
|
||||
"nameserver 2001:4860:4860::8844\r\n";
|
||||
|
||||
/* Check that duplicates are ignored */
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, NULL));
|
||||
g_assert_cmpint (ns6->len, ==, 2);
|
||||
assert_dns6_entry (ns6, 0, "2001:4860:4860::8888");
|
||||
assert_dns6_entry (ns6, 1, "2001:4860:4860::8844");
|
||||
|
||||
g_array_free (ns6, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_addr4_with_6 (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
const char *rc =
|
||||
"# neato resolv.conf\r\n"
|
||||
"domain foobar.com\r\n"
|
||||
"search foobar.com\r\n"
|
||||
"nameserver 4.2.2.1\r\n"
|
||||
"nameserver 4.2.2.2\r\n"
|
||||
"nameserver 2001:4860:4860::8888\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL));
|
||||
g_assert_cmpint (ns4->len, ==, 2);
|
||||
assert_dns4_entry (ns4, 0, "4.2.2.1");
|
||||
assert_dns4_entry (ns4, 1, "4.2.2.2");
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_addr6_with_4 (void)
|
||||
{
|
||||
GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr));
|
||||
const char *rc =
|
||||
"# neato resolv.conf\r\n"
|
||||
"domain foobar.com\r\n"
|
||||
"search foobar.com\r\n"
|
||||
"nameserver 4.2.2.1\r\n"
|
||||
"nameserver 2001:4860:4860::8888\r\n"
|
||||
"nameserver 2001:4860:4860::8844\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, NULL));
|
||||
g_assert_cmpint (ns6->len, ==, 2);
|
||||
assert_dns6_entry (ns6, 0, "2001:4860:4860::8888");
|
||||
assert_dns6_entry (ns6, 1, "2001:4860:4860::8844");
|
||||
|
||||
g_array_free (ns6, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_format (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
const char *rc =
|
||||
" nameserver 4.2.2.1\r\n" /* bad */
|
||||
"nameserver4.2.2.1\r\n" /* bad */
|
||||
"nameserver 4.2.2.3\r" /* good */
|
||||
"nameserver\t\t4.2.2.4\r\n" /* good */
|
||||
"nameserver 4.2.2.5\t\t\r\n" /* good */
|
||||
"nameserver 4.2.2.6 \r\n"; /* good */
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, NULL));
|
||||
g_assert_cmpint (ns4->len, ==, 4);
|
||||
assert_dns4_entry (ns4, 0, "4.2.2.3");
|
||||
assert_dns4_entry (ns4, 1, "4.2.2.4");
|
||||
assert_dns4_entry (ns4, 2, "4.2.2.5");
|
||||
assert_dns4_entry (ns4, 3, "4.2.2.6");
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_dns_options (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
const char *rc =
|
||||
"nameserver 4.2.2.1\r\n"
|
||||
"options debug rotate timeout:5 \r\n"
|
||||
"options edns0\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, dns_options));
|
||||
g_assert_cmpint (dns_options->len, ==, 4);
|
||||
assert_dns_option (dns_options, 0, "debug");
|
||||
assert_dns_option (dns_options, 1, "rotate");
|
||||
assert_dns_option (dns_options, 2, "timeout:5");
|
||||
assert_dns_option (dns_options, 3, "edns0");
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
g_ptr_array_free (dns_options, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_dns_options_dup (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
const char *rc =
|
||||
"options debug rotate timeout:3\r\n"
|
||||
"options edns0 debug\r\n"
|
||||
"options timeout:5\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, dns_options));
|
||||
g_assert_cmpint (dns_options->len, ==, 4);
|
||||
assert_dns_option (dns_options, 0, "debug");
|
||||
assert_dns_option (dns_options, 1, "rotate");
|
||||
assert_dns_option (dns_options, 2, "timeout:3");
|
||||
assert_dns_option (dns_options, 3, "edns0");
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
g_ptr_array_free (dns_options, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_dns_options_valid4 (void)
|
||||
{
|
||||
GArray *ns4 = g_array_new (FALSE, FALSE, sizeof (guint32));
|
||||
GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
const char *rc =
|
||||
"options debug: rotate:yes edns0 foobar : inet6\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET, rc, ns4, dns_options));
|
||||
g_assert_cmpint (dns_options->len, ==, 1);
|
||||
assert_dns_option (dns_options, 0, "edns0");
|
||||
|
||||
g_array_free (ns4, TRUE);
|
||||
g_ptr_array_free (dns_options, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
test_capture_dns_options_valid6 (void)
|
||||
{
|
||||
GArray *ns6 = g_array_new (FALSE, FALSE, sizeof (struct in6_addr));
|
||||
GPtrArray *dns_options = g_ptr_array_new_with_free_func (g_free);
|
||||
const char *rc =
|
||||
"options inet6 debug foobar rotate:\r\n";
|
||||
|
||||
g_assert (nm_utils_resolve_conf_parse (AF_INET6, rc, ns6, dns_options));
|
||||
g_assert_cmpint (dns_options->len, ==, 2);
|
||||
assert_dns_option (dns_options, 0, "inet6");
|
||||
assert_dns_option (dns_options, 1, "debug");
|
||||
|
||||
g_array_free (ns6, TRUE);
|
||||
g_ptr_array_free (dns_options, TRUE);
|
||||
}
|
||||
/*****************************************************************************/
|
||||
|
||||
NMTST_DEFINE ();
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT");
|
||||
|
||||
g_test_add_func ("/resolvconf-capture/empty", test_capture_empty);
|
||||
g_test_add_func ("/resolvconf-capture/basic4", test_capture_basic4);
|
||||
g_test_add_func ("/resolvconf-capture/dup4", test_capture_dup4);
|
||||
g_test_add_func ("/resolvconf-capture/basic6", test_capture_basic6);
|
||||
g_test_add_func ("/resolvconf-capture/dup6", test_capture_dup6);
|
||||
g_test_add_func ("/resolvconf-capture/addr4-with-6", test_capture_addr4_with_6);
|
||||
g_test_add_func ("/resolvconf-capture/addr6-with-4", test_capture_addr6_with_4);
|
||||
g_test_add_func ("/resolvconf-capture/format", test_capture_format);
|
||||
g_test_add_func ("/resolvconf-capture/dns-options", test_capture_dns_options);
|
||||
g_test_add_func ("/resolvconf-capture/dns-options-dup", test_capture_dns_options_dup);
|
||||
g_test_add_func ("/resolvconf-capture/dns-options-valid4", test_capture_dns_options_valid4);
|
||||
g_test_add_func ("/resolvconf-capture/dns-options-valid6", test_capture_dns_options_valid6);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
Loading…
Add table
Reference in a new issue