mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-06 07:00:33 +01:00
core: strip trailing dot from domain search list
dhclient adds a trailing dot to domain search list entries received from the server, while the same domains received by other means (dhcpcd on RA) don't have the final dot. The result is that resolv.conf can be populated with duplicated entries. Fix this by stripping the trailing dot when a new search domain is added to a IP configuration. https://bugzilla.gnome.org/show_bug.cgi?id=758777
This commit is contained in:
parent
f740c54936
commit
6e990cf97b
4 changed files with 84 additions and 10 deletions
|
|
@ -1707,16 +1707,31 @@ void
|
|||
nm_ip4_config_add_search (NMIP4Config *config, const char *new)
|
||||
{
|
||||
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (config);
|
||||
int i;
|
||||
char *search;
|
||||
size_t len;
|
||||
|
||||
g_return_if_fail (new != NULL);
|
||||
g_return_if_fail (new[0] != '\0');
|
||||
|
||||
for (i = 0; i < priv->searches->len; i++)
|
||||
if (!g_strcmp0 (g_ptr_array_index (priv->searches, i), new))
|
||||
return;
|
||||
search = g_strdup (new);
|
||||
|
||||
g_ptr_array_add (priv->searches, g_strdup (new));
|
||||
/* Remove trailing dot as it has no effect */
|
||||
len = strlen (search);
|
||||
if (search[len - 1] == '.')
|
||||
search[len - 1] = 0;
|
||||
|
||||
if (!search[0]) {
|
||||
g_free (search);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_nm_utils_strv_find_first ((char **) priv->searches->pdata,
|
||||
priv->searches->len, search) >= 0) {
|
||||
g_free (search);
|
||||
return;
|
||||
}
|
||||
|
||||
g_ptr_array_add (priv->searches, search);
|
||||
_NOTIFY (config, PROP_SEARCHES);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1633,16 +1633,31 @@ void
|
|||
nm_ip6_config_add_search (NMIP6Config *config, const char *new)
|
||||
{
|
||||
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (config);
|
||||
int i;
|
||||
char *search;
|
||||
size_t len;
|
||||
|
||||
g_return_if_fail (new != NULL);
|
||||
g_return_if_fail (new[0] != '\0');
|
||||
|
||||
for (i = 0; i < priv->searches->len; i++)
|
||||
if (!g_strcmp0 (g_ptr_array_index (priv->searches, i), new))
|
||||
return;
|
||||
search = g_strdup (new);
|
||||
|
||||
g_ptr_array_add (priv->searches, g_strdup (new));
|
||||
/* Remove trailing dot as it has no effect */
|
||||
len = strlen (search);
|
||||
if (search[len - 1] == '.')
|
||||
search[len - 1] = 0;
|
||||
|
||||
if (!search[0]) {
|
||||
g_free (search);
|
||||
return;
|
||||
}
|
||||
|
||||
if (_nm_utils_strv_find_first ((char **) priv->searches->pdata,
|
||||
priv->searches->len, search) >= 0) {
|
||||
g_free (search);
|
||||
return;
|
||||
}
|
||||
|
||||
g_ptr_array_add (priv->searches, search);
|
||||
_NOTIFY (config, PROP_SEARCHES);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -340,6 +340,27 @@ test_merge_subtract_mss_mtu (void)
|
|||
g_object_unref (cfg3);
|
||||
}
|
||||
|
||||
static void
|
||||
test_strip_search_trailing_dot (void)
|
||||
{
|
||||
NMIP4Config *config;
|
||||
|
||||
config = nm_ip4_config_new (1);
|
||||
|
||||
nm_ip4_config_add_search (config, ".");
|
||||
nm_ip4_config_add_search (config, "foo");
|
||||
nm_ip4_config_add_search (config, "bar.");
|
||||
nm_ip4_config_add_search (config, "baz.com");
|
||||
nm_ip4_config_add_search (config, "baz.com.");
|
||||
|
||||
g_assert_cmpuint (nm_ip4_config_get_num_searches (config), ==, 3);
|
||||
g_assert_cmpstr (nm_ip4_config_get_search (config, 0), ==, "foo");
|
||||
g_assert_cmpstr (nm_ip4_config_get_search (config, 1), ==, "bar");
|
||||
g_assert_cmpstr (nm_ip4_config_get_search (config, 2), ==, "baz.com");
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
|
||||
NMTST_DEFINE ();
|
||||
|
|
@ -354,6 +375,7 @@ main (int argc, char **argv)
|
|||
g_test_add_func ("/ip4-config/add-address-with-source", test_add_address_with_source);
|
||||
g_test_add_func ("/ip4-config/add-route-with-source", test_add_route_with_source);
|
||||
g_test_add_func ("/ip4-config/merge-subtract-mss-mtu", test_merge_subtract_mss_mtu);
|
||||
g_test_add_func ("/ip4-config/strip-search-trailing-dot", test_strip_search_trailing_dot);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -320,6 +320,27 @@ test_nm_ip6_config_addresses_sort (void)
|
|||
g_object_unref (config);
|
||||
}
|
||||
|
||||
static void
|
||||
test_strip_search_trailing_dot (void)
|
||||
{
|
||||
NMIP6Config *config;
|
||||
|
||||
config = nm_ip6_config_new (1);
|
||||
|
||||
nm_ip6_config_add_search (config, ".");
|
||||
nm_ip6_config_add_search (config, "foo");
|
||||
nm_ip6_config_add_search (config, "bar.");
|
||||
nm_ip6_config_add_search (config, "baz.com");
|
||||
nm_ip6_config_add_search (config, "baz.com.");
|
||||
|
||||
g_assert_cmpuint (nm_ip6_config_get_num_searches (config), ==, 3);
|
||||
g_assert_cmpstr (nm_ip6_config_get_search (config, 0), ==, "foo");
|
||||
g_assert_cmpstr (nm_ip6_config_get_search (config, 1), ==, "bar");
|
||||
g_assert_cmpstr (nm_ip6_config_get_search (config, 2), ==, "baz.com");
|
||||
|
||||
g_object_unref (config);
|
||||
}
|
||||
|
||||
/*******************************************/
|
||||
|
||||
NMTST_DEFINE();
|
||||
|
|
@ -334,6 +355,7 @@ main (int argc, char **argv)
|
|||
g_test_add_func ("/ip6-config/add-address-with-source", test_add_address_with_source);
|
||||
g_test_add_func ("/ip6-config/add-route-with-source", test_add_route_with_source);
|
||||
g_test_add_func ("/ip6-config/test_nm_ip6_config_addresses_sort", test_nm_ip6_config_addresses_sort);
|
||||
g_test_add_func ("/ip6-config/strip-search-trailing-dot", test_strip_search_trailing_dot);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue