diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2020-07-28 17:04:13 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2020-08-24 16:51:53 +0200 |
commit | 5fbc967fb8c00dedb7d70d0b4c0b5d582e7577e3 (patch) | |
tree | c5cf3f52564145110ac7911920481b083651e9ef | |
parent | 8113069062e5eb9e255725d6833981552e699584 (diff) | |
download | NetworkManager-5fbc967fb8c00dedb7d70d0b4c0b5d582e7577e3.tar.gz |
dhcp: nettools: use generic function to parse address lists
-rw-r--r-- | src/dhcp/nm-dhcp-nettools.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c index 8d7d021710..7906759f30 100644 --- a/src/dhcp/nm-dhcp-nettools.c +++ b/src/dhcp/nm-dhcp-nettools.c @@ -468,9 +468,10 @@ lease_parse_address (NDhcp4ClientLease *lease, } static void -lease_parse_domain_name_servers (NDhcp4ClientLease *lease, - NMIP4Config *ip4_config, - GHashTable *options) +lease_parse_address_list (NDhcp4ClientLease *lease, + NMIP4Config *ip4_config, + NMDhcpOptionDhcp4Options option, + GHashTable *options) { nm_auto_free_gstring GString *str = NULL; char addr_str[NM_UTILS_INET_ADDRSTRLEN]; @@ -479,7 +480,7 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease, size_t n_data; int r; - r = n_dhcp4_client_lease_query (lease, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, &data, &n_data); + r = n_dhcp4_client_lease_query (lease, option, &data, &n_data); if (r) return; @@ -490,18 +491,24 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease, _nm_utils_inet4_ntop (addr.s_addr, addr_str); g_string_append (nm_gstring_add_space_delimiter (str), addr_str); - if ( addr.s_addr == 0 - || nm_ip4_addr_is_localhost (addr.s_addr)) { - /* Skip localhost addresses, like also networkd does. - * See https://github.com/systemd/systemd/issues/4524. */ - continue; + switch (option) { + case NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER: + if ( addr.s_addr == 0 + || nm_ip4_addr_is_localhost (addr.s_addr)) { + /* Skip localhost addresses, like also networkd does. + * See https://github.com/systemd/systemd/issues/4524. */ + continue; + } + nm_ip4_config_add_nameserver (ip4_config, addr.s_addr); + break; + default: + nm_assert_not_reached (); } - nm_ip4_config_add_nameserver (ip4_config, addr.s_addr); } nm_dhcp_option_add_option (options, _nm_dhcp_option_dhcp4_options, - NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, + option, str->str); } @@ -942,7 +949,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx, return NULL; lease_parse_routes (lease, ip4_config, options, route_table, route_metric); - lease_parse_domain_name_servers (lease, ip4_config, options); + lease_parse_address_list (lease, ip4_config, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, options); lease_parse_domainname (lease, ip4_config, options); lease_parse_search_domains (lease, ip4_config, options); lease_parse_mtu (lease, ip4_config, options); |