summaryrefslogtreecommitdiff
path: root/src/dhcp/nm-dhcp-nettools.c
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2019-12-17 18:18:48 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2019-12-23 16:19:35 +0100
commitc9fbdf3cb0d31e6ca24baa5a43a56d878317a620 (patch)
tree82479ce5385837b8859a1aacd2f330b9ec4f5ad7 /src/dhcp/nm-dhcp-nettools.c
parent36f8822c9b06a23b804ce8dcffa5726c7d14fb2f (diff)
downloadNetworkManager-c9fbdf3cb0d31e6ca24baa5a43a56d878317a620.tar.gz
dhcp: test parsing of domain-search option
Add a test for the parsing of the the domain-search option.
Diffstat (limited to 'src/dhcp/nm-dhcp-nettools.c')
-rw-r--r--src/dhcp/nm-dhcp-nettools.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 2cb7c51b61..f59b27e356 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -775,34 +775,57 @@ lease_parse_domainname (NDhcp4ClientLease *lease,
str->str);
}
+char **
+nm_dhcp_parse_search_list (guint8 *data, size_t n_data)
+{
+ GPtrArray *array = NULL;
+ guint8 *cache = data;
+ size_t n_cache = 0;
+
+ for (;;) {
+ nm_auto_free_gstring GString *domain = NULL;
+
+ nm_gstring_prepare (&domain);
+
+ if (!lease_option_print_domain_name (domain, cache, &n_cache, &data, &n_data))
+ break;
+
+ if (!array)
+ array = g_ptr_array_new ();
+
+ g_ptr_array_add (array, g_string_free (domain, FALSE));
+ domain = NULL;
+ }
+
+ if (array) {
+ g_ptr_array_add (array, NULL);
+ return (char **) g_ptr_array_free (array, FALSE);
+ } else
+ return NULL;
+}
+
static void
lease_parse_search_domains (NDhcp4ClientLease *lease,
NMIP4Config *ip4_config,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
- uint8_t *data, *cache;
- size_t n_data, n_cache = 0;
+ uint8_t *data;
+ size_t n_data;
+ gs_strfreev char **domains = NULL;
+ guint i;
int r;
r = n_dhcp4_client_lease_query (lease, NM_DHCP_OPTION_DHCP4_DOMAIN_SEARCH_LIST, &data, &n_data);
if (r)
return;
- cache = data;
-
+ domains = nm_dhcp_parse_search_list (data, n_data);
nm_gstring_prepare (&str);
- for (;;) {
- nm_auto_free_gstring GString *domain = NULL;
-
- nm_gstring_prepare (&domain);
-
- if (!lease_option_print_domain_name (domain, cache, &n_cache, &data, &n_data))
- break;
-
- g_string_append (nm_gstring_add_space_delimiter (str), domain->str);
- nm_ip4_config_add_search (ip4_config, domain->str);
+ for (i = 0; domains && domains[i]; i++) {
+ g_string_append (nm_gstring_add_space_delimiter (str), domains[i]);
+ nm_ip4_config_add_search (ip4_config, domains[i]);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,