mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-03 15:10:14 +01:00
dhcp: remove unused nm_utils_resolve_conf_parse() function
This commit is contained in:
parent
c77784b5ea
commit
868c3cedfd
6 changed files with 1 additions and 415 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
|
||||
|
|
|
|||
|
|
@ -3097,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
|
||||
|
||||
|
|
@ -3113,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)
|
||||
|
|
@ -3136,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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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