From bb53b46bd1affc78e4bf77f719432715f2cd6688 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Jun 2017 13:20:49 +0200 Subject: [PATCH 1/5] shared: add nm_gstring_prepare() util --- shared/nm-utils/nm-macros-internal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 44f57e858a..011f45d0ee 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -420,6 +420,16 @@ fcn (void) \ /*****************************************************************************/ +static inline GString * +nm_gstring_prepare (GString **l) +{ + if (*l) + g_string_set_size (*l, 0); + else + *l = g_string_sized_new (30); + return *l; +} + static inline const char * nm_str_not_empty (const char *str) { From 3c1466b7de03345a3fe3de5548c5313b405fd8a4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Jun 2017 13:32:55 +0200 Subject: [PATCH 2/5] dhcp/trivial: rename local variables lease_to_ip6_config() calls the GString temporary buffer "str". That makes sense, use the same name in lease_to_ip4_config(). For that, we have to rename other local variables too. --- src/dhcp/nm-dhcp-systemd.c | 82 +++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index aa90270101..b938acb9ff 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -229,10 +229,10 @@ lease_to_ip4_config (const char *iface, struct in_addr tmp_addr; const struct in_addr *addr_list; char buf[INET_ADDRSTRLEN]; - const char *str; + const char *s; guint32 lifetime = 0, i; NMPlatformIP4Address address; - GString *l; + GString *str; gs_free sd_dhcp_route **routes = NULL; guint16 mtu; int r, num; @@ -251,9 +251,9 @@ lease_to_ip4_config (const char *iface, memset (&address, 0, sizeof (address)); address.address = tmp_addr.s_addr; address.peer_address = tmp_addr.s_addr; - str = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL); - LOG_LEASE (LOGD_DHCP4, " address %s", str); - add_option (options, dhcp4_requests, DHCP_OPTION_IP_ADDRESS, str); + s = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL); + LOG_LEASE (LOGD_DHCP4, " address %s", s); + add_option (options, dhcp4_requests, DHCP_OPTION_IP_ADDRESS, s); /* Prefix/netmask */ sd_dhcp_lease_get_netmask (lease, &tmp_addr); @@ -281,47 +281,47 @@ lease_to_ip4_config (const char *iface, /* DNS Servers */ num = sd_dhcp_lease_get_dns (lease, &addr_list); if (num > 0) { - l = g_string_sized_new (30); + str = g_string_sized_new (30); for (i = 0; i < num; i++) { if (addr_list[i].s_addr) { nm_ip4_config_add_nameserver (ip4_config, addr_list[i].s_addr); - str = nm_utils_inet4_ntop (addr_list[i].s_addr, NULL); - LOG_LEASE (LOGD_DHCP4, " nameserver '%s'", str); - g_string_append_printf (l, "%s%s", l->len ? " " : "", str); + s = nm_utils_inet4_ntop (addr_list[i].s_addr, NULL); + LOG_LEASE (LOGD_DHCP4, " nameserver '%s'", s); + g_string_append_printf (str, "%s%s", str->len ? " " : "", s); } } - if (l->len) - add_option (options, dhcp4_requests, SD_DHCP_OPTION_DOMAIN_NAME_SERVER, l->str); - g_string_free (l, TRUE); + if (str->len) + add_option (options, dhcp4_requests, SD_DHCP_OPTION_DOMAIN_NAME_SERVER, str->str); + g_string_free (str, TRUE); } /* Domain Name */ - r = sd_dhcp_lease_get_domainname (lease, &str); + r = sd_dhcp_lease_get_domainname (lease, &s); if (r == 0) { /* Multiple domains sometimes stuffed into option 15 "Domain Name". * As systemd escapes such characters, split them at \\032. */ - char **domains = g_strsplit (str, "\\032", 0); - char **s; + char **domains = g_strsplit (s, "\\032", 0); + char **d; - for (s = domains; *s; s++) { - LOG_LEASE (LOGD_DHCP4, " domain name '%s'", *s); - nm_ip4_config_add_domain (ip4_config, *s); + for (d = domains; *d; d++) { + LOG_LEASE (LOGD_DHCP4, " domain name '%s'", *d); + nm_ip4_config_add_domain (ip4_config, *d); } g_strfreev (domains); - add_option (options, dhcp4_requests, SD_DHCP_OPTION_DOMAIN_NAME, str); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_DOMAIN_NAME, s); } /* Hostname */ - r = sd_dhcp_lease_get_hostname (lease, &str); + r = sd_dhcp_lease_get_hostname (lease, &s); if (r == 0) { - LOG_LEASE (LOGD_DHCP4, " hostname '%s'", str); - add_option (options, dhcp4_requests, SD_DHCP_OPTION_HOST_NAME, str); + LOG_LEASE (LOGD_DHCP4, " hostname '%s'", s); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_HOST_NAME, s); } /* Routes */ num = sd_dhcp_lease_get_routes (lease, &routes); if (num > 0) { - l = g_string_sized_new (30); + str = g_string_sized_new (30); for (i = 0; i < num; i++) { NMPlatformIP4Route route = { 0 }; const char *gw_str; @@ -346,25 +346,25 @@ lease_to_ip4_config (const char *iface, route.metric = default_priority; nm_ip4_config_add_route (ip4_config, &route); - str = nm_utils_inet4_ntop (route.network, buf); + s = nm_utils_inet4_ntop (route.network, buf); gw_str = nm_utils_inet4_ntop (route.gateway, NULL); - LOG_LEASE (LOGD_DHCP4, " static route %s/%d gw %s", str, route.plen, gw_str); + LOG_LEASE (LOGD_DHCP4, " static route %s/%d gw %s", s, route.plen, gw_str); - g_string_append_printf (l, "%s%s/%d %s", l->len ? " " : "", str, route.plen, gw_str); + g_string_append_printf (str, "%s%s/%d %s", str->len ? " " : "", s, route.plen, gw_str); } else { if (!static_default_gateway) { static_default_gateway = TRUE; nm_ip4_config_set_gateway (ip4_config, route.gateway); - str = nm_utils_inet4_ntop (route.gateway, NULL); - LOG_LEASE (LOGD_DHCP4, " gateway %s", str); - add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, str); + s = nm_utils_inet4_ntop (route.gateway, NULL); + LOG_LEASE (LOGD_DHCP4, " gateway %s", s); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, s); } } } - if (l->len) - add_option (options, dhcp4_requests, SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE, l->str); - g_string_free (l, TRUE); + if (str->len) + add_option (options, dhcp4_requests, SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE, str->str); + g_string_free (str, TRUE); } /* If the DHCP server returns both a Classless Static Routes option and a @@ -377,9 +377,9 @@ lease_to_ip4_config (const char *iface, r = sd_dhcp_lease_get_router (lease, &tmp_addr); if (r == 0) { nm_ip4_config_set_gateway (ip4_config, tmp_addr.s_addr); - str = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL); - LOG_LEASE (LOGD_DHCP4, " gateway %s", str); - add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, str); + s = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL); + LOG_LEASE (LOGD_DHCP4, " gateway %s", s); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, s); } } @@ -394,14 +394,14 @@ lease_to_ip4_config (const char *iface, /* NTP servers */ num = sd_dhcp_lease_get_ntp (lease, &addr_list); if (num > 0) { - l = g_string_sized_new (30); + str = g_string_sized_new (30); for (i = 0; i < num; i++) { - str = nm_utils_inet4_ntop (addr_list[i].s_addr, buf); - LOG_LEASE (LOGD_DHCP4, " ntp server '%s'", str); - g_string_append_printf (l, "%s%s", l->len ? " " : "", str); + s = nm_utils_inet4_ntop (addr_list[i].s_addr, buf); + LOG_LEASE (LOGD_DHCP4, " ntp server '%s'", s); + g_string_append_printf (str, "%s%s", str->len ? " " : "", s); } - add_option (options, dhcp4_requests, SD_DHCP_OPTION_NTP_SERVER, l->str); - g_string_free (l, TRUE); + add_option (options, dhcp4_requests, SD_DHCP_OPTION_NTP_SERVER, str->str); + g_string_free (str, TRUE); } r = sd_dhcp_lease_get_vendor_specific (lease, &data, &data_len); From 4fd023b617ce02a517ea062f631e20be38a72b9d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Jun 2017 13:21:04 +0200 Subject: [PATCH 3/5] dhcp: reuse string buffer in lease_to_ip4_config() In lease_to_ip4_config() avoid creating multiple GString buffers. Just reuse it. --- src/dhcp/nm-dhcp-systemd.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index b938acb9ff..8add09e982 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -232,7 +232,7 @@ lease_to_ip4_config (const char *iface, const char *s; guint32 lifetime = 0, i; NMPlatformIP4Address address; - GString *str; + nm_auto_free_gstring GString *str = NULL; gs_free sd_dhcp_route **routes = NULL; guint16 mtu; int r, num; @@ -281,7 +281,7 @@ lease_to_ip4_config (const char *iface, /* DNS Servers */ num = sd_dhcp_lease_get_dns (lease, &addr_list); if (num > 0) { - str = g_string_sized_new (30); + nm_gstring_prepare (&str); for (i = 0; i < num; i++) { if (addr_list[i].s_addr) { nm_ip4_config_add_nameserver (ip4_config, addr_list[i].s_addr); @@ -292,7 +292,6 @@ lease_to_ip4_config (const char *iface, } if (str->len) add_option (options, dhcp4_requests, SD_DHCP_OPTION_DOMAIN_NAME_SERVER, str->str); - g_string_free (str, TRUE); } /* Domain Name */ @@ -321,7 +320,7 @@ lease_to_ip4_config (const char *iface, /* Routes */ num = sd_dhcp_lease_get_routes (lease, &routes); if (num > 0) { - str = g_string_sized_new (30); + nm_gstring_prepare (&str); for (i = 0; i < num; i++) { NMPlatformIP4Route route = { 0 }; const char *gw_str; @@ -364,7 +363,6 @@ lease_to_ip4_config (const char *iface, } if (str->len) add_option (options, dhcp4_requests, SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE, str->str); - g_string_free (str, TRUE); } /* If the DHCP server returns both a Classless Static Routes option and a @@ -394,14 +392,13 @@ lease_to_ip4_config (const char *iface, /* NTP servers */ num = sd_dhcp_lease_get_ntp (lease, &addr_list); if (num > 0) { - str = g_string_sized_new (30); + nm_gstring_prepare (&str); for (i = 0; i < num; i++) { s = nm_utils_inet4_ntop (addr_list[i].s_addr, buf); LOG_LEASE (LOGD_DHCP4, " ntp server '%s'", s); g_string_append_printf (str, "%s%s", str->len ? " " : "", s); } add_option (options, dhcp4_requests, SD_DHCP_OPTION_NTP_SERVER, str->str); - g_string_free (str, TRUE); } r = sd_dhcp_lease_get_vendor_specific (lease, &data, &data_len); @@ -729,17 +726,17 @@ lease_to_ip6_config (const char *iface, NMIP6Config *ip6_config; const char *addr_str; char **domains; - GString *str; + nm_auto_free_gstring GString *str = NULL; int num, i; gint32 ts; g_return_val_if_fail (lease, NULL); ip6_config = nm_ip6_config_new (ifindex); ts = nm_utils_get_monotonic_timestamp_s (); - str = g_string_sized_new (30); /* Addresses */ sd_dhcp6_lease_reset_address_iter (lease); + nm_gstring_prepare (&str); while (sd_dhcp6_lease_get_address (lease, &tmp_addr, &lft_pref, &lft_valid) >= 0) { NMPlatformIP6Address address = { .plen = 128, @@ -760,13 +757,10 @@ lease_to_ip6_config (const char *iface, nm_platform_ip6_address_to_string (&address, NULL, 0)); }; - if (str->len) { + if (str->len) add_option (options, dhcp6_requests, DHCP6_OPTION_IP_ADDRESS, str->str); - g_string_set_size (str , 0); - } if (!info_only && nm_ip6_config_get_num_addresses (ip6_config) == 0) { - g_string_free (str, TRUE); g_object_unref (ip6_config); g_set_error_literal (error, NM_MANAGER_ERROR, @@ -778,6 +772,7 @@ lease_to_ip6_config (const char *iface, /* DNS servers */ num = sd_dhcp6_lease_get_dns (lease, &dns); if (num > 0) { + nm_gstring_prepare (&str); for (i = 0; i < num; i++) { nm_ip6_config_add_nameserver (ip6_config, &dns[i]); addr_str = nm_utils_inet6_ntop (&dns[i], NULL); @@ -785,23 +780,20 @@ lease_to_ip6_config (const char *iface, LOG_LEASE (LOGD_DHCP6, " nameserver %s", addr_str); } add_option (options, dhcp6_requests, SD_DHCP6_OPTION_DNS_SERVERS, str->str); - g_string_set_size (str, 0); } /* Search domains */ num = sd_dhcp6_lease_get_domains (lease, &domains); if (num > 0) { + nm_gstring_prepare (&str); for (i = 0; i < num; i++) { nm_ip6_config_add_search (ip6_config, domains[i]); g_string_append_printf (str, "%s%s", str->len ? " " : "", domains[i]); LOG_LEASE (LOGD_DHCP6, " domain name '%s'", domains[i]); } add_option (options, dhcp6_requests, SD_DHCP6_OPTION_DOMAIN_LIST, str->str); - g_string_set_size (str, 0); } - g_string_free (str, TRUE); - return ip6_config; } From e02f5454fd92488d456594c6f520512cdf1d009a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Jun 2017 13:40:07 +0200 Subject: [PATCH 4/5] dhcp: cleanup formatting of LOG_LEASE() macro in lease_to_ip4_config() and lease_to_ip6_config(). The use of a prefix should be done by LOG_LEASE() macro, instead of each caller individually. --- src/dhcp/nm-dhcp-systemd.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index 8add09e982..6fb09907f0 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -212,7 +212,7 @@ add_requests_to_options (GHashTable *options, const ReqOption *requests) #define LOG_LEASE(domain, ...) \ G_STMT_START { \ if (log_lease) { \ - _LOG2I ((domain), (iface), __VA_ARGS__); \ + _LOG2I ((domain), (iface), " "__VA_ARGS__); \ } \ } G_STMT_END @@ -252,13 +252,13 @@ lease_to_ip4_config (const char *iface, address.address = tmp_addr.s_addr; address.peer_address = tmp_addr.s_addr; s = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL); - LOG_LEASE (LOGD_DHCP4, " address %s", s); + LOG_LEASE (LOGD_DHCP4, "address %s", s); add_option (options, dhcp4_requests, DHCP_OPTION_IP_ADDRESS, s); /* Prefix/netmask */ sd_dhcp_lease_get_netmask (lease, &tmp_addr); address.plen = nm_utils_ip4_netmask_to_prefix (tmp_addr.s_addr); - LOG_LEASE (LOGD_DHCP4, " plen %d", address.plen); + LOG_LEASE (LOGD_DHCP4, "plen %d", address.plen); add_option (options, dhcp4_requests, SD_DHCP_OPTION_SUBNET_MASK, @@ -269,7 +269,7 @@ lease_to_ip4_config (const char *iface, address.timestamp = nm_utils_get_monotonic_timestamp_s (); address.lifetime = address.preferred = lifetime; end_time = (guint64) time (NULL) + lifetime; - LOG_LEASE (LOGD_DHCP4, " expires in %" G_GUINT32_FORMAT " seconds", lifetime); + LOG_LEASE (LOGD_DHCP4, "expires in %" G_GUINT32_FORMAT " seconds", lifetime); add_option_u64 (options, dhcp4_requests, SD_DHCP_OPTION_IP_ADDRESS_LEASE_TIME, @@ -286,7 +286,7 @@ lease_to_ip4_config (const char *iface, if (addr_list[i].s_addr) { nm_ip4_config_add_nameserver (ip4_config, addr_list[i].s_addr); s = nm_utils_inet4_ntop (addr_list[i].s_addr, NULL); - LOG_LEASE (LOGD_DHCP4, " nameserver '%s'", s); + LOG_LEASE (LOGD_DHCP4, "nameserver '%s'", s); g_string_append_printf (str, "%s%s", str->len ? " " : "", s); } } @@ -303,7 +303,7 @@ lease_to_ip4_config (const char *iface, char **d; for (d = domains; *d; d++) { - LOG_LEASE (LOGD_DHCP4, " domain name '%s'", *d); + LOG_LEASE (LOGD_DHCP4, "domain name '%s'", *d); nm_ip4_config_add_domain (ip4_config, *d); } g_strfreev (domains); @@ -313,7 +313,7 @@ lease_to_ip4_config (const char *iface, /* Hostname */ r = sd_dhcp_lease_get_hostname (lease, &s); if (r == 0) { - LOG_LEASE (LOGD_DHCP4, " hostname '%s'", s); + LOG_LEASE (LOGD_DHCP4, "hostname '%s'", s); add_option (options, dhcp4_requests, SD_DHCP_OPTION_HOST_NAME, s); } @@ -347,7 +347,7 @@ lease_to_ip4_config (const char *iface, s = nm_utils_inet4_ntop (route.network, buf); gw_str = nm_utils_inet4_ntop (route.gateway, NULL); - LOG_LEASE (LOGD_DHCP4, " static route %s/%d gw %s", s, route.plen, gw_str); + LOG_LEASE (LOGD_DHCP4, "static route %s/%d gw %s", s, route.plen, gw_str); g_string_append_printf (str, "%s%s/%d %s", str->len ? " " : "", s, route.plen, gw_str); } else { @@ -356,7 +356,7 @@ lease_to_ip4_config (const char *iface, nm_ip4_config_set_gateway (ip4_config, route.gateway); s = nm_utils_inet4_ntop (route.gateway, NULL); - LOG_LEASE (LOGD_DHCP4, " gateway %s", s); + LOG_LEASE (LOGD_DHCP4, "gateway %s", s); add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, s); } } @@ -376,7 +376,7 @@ lease_to_ip4_config (const char *iface, if (r == 0) { nm_ip4_config_set_gateway (ip4_config, tmp_addr.s_addr); s = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL); - LOG_LEASE (LOGD_DHCP4, " gateway %s", s); + LOG_LEASE (LOGD_DHCP4, "gateway %s", s); add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, s); } } @@ -386,7 +386,7 @@ lease_to_ip4_config (const char *iface, if (r == 0 && mtu) { nm_ip4_config_set_mtu (ip4_config, mtu, NM_IP_CONFIG_SOURCE_DHCP); add_option_u32 (options, dhcp4_requests, SD_DHCP_OPTION_INTERFACE_MTU, mtu); - LOG_LEASE (LOGD_DHCP4, " mtu %u", mtu); + LOG_LEASE (LOGD_DHCP4, "mtu %u", mtu); } /* NTP servers */ @@ -395,7 +395,7 @@ lease_to_ip4_config (const char *iface, nm_gstring_prepare (&str); for (i = 0; i < num; i++) { s = nm_utils_inet4_ntop (addr_list[i].s_addr, buf); - LOG_LEASE (LOGD_DHCP4, " ntp server '%s'", s); + LOG_LEASE (LOGD_DHCP4, "ntp server '%s'", s); g_string_append_printf (str, "%s%s", str->len ? " " : "", s); } add_option (options, dhcp4_requests, SD_DHCP_OPTION_NTP_SERVER, str->str); @@ -753,7 +753,7 @@ lease_to_ip6_config (const char *iface, g_string_append_printf (str, "%s%s", str->len ? " " : "", addr_str); LOG_LEASE (LOGD_DHCP6, - " address %s", + "address %s", nm_platform_ip6_address_to_string (&address, NULL, 0)); }; @@ -777,7 +777,7 @@ lease_to_ip6_config (const char *iface, nm_ip6_config_add_nameserver (ip6_config, &dns[i]); addr_str = nm_utils_inet6_ntop (&dns[i], NULL); g_string_append_printf (str, "%s%s", str->len ? " " : "", addr_str); - LOG_LEASE (LOGD_DHCP6, " nameserver %s", addr_str); + LOG_LEASE (LOGD_DHCP6, "nameserver %s", addr_str); } add_option (options, dhcp6_requests, SD_DHCP6_OPTION_DNS_SERVERS, str->str); } @@ -789,7 +789,7 @@ lease_to_ip6_config (const char *iface, for (i = 0; i < num; i++) { nm_ip6_config_add_search (ip6_config, domains[i]); g_string_append_printf (str, "%s%s", str->len ? " " : "", domains[i]); - LOG_LEASE (LOGD_DHCP6, " domain name '%s'", domains[i]); + LOG_LEASE (LOGD_DHCP6, "domain name '%s'", domains[i]); } add_option (options, dhcp6_requests, SD_DHCP6_OPTION_DOMAIN_LIST, str->str); } From 203ffede01a1295ce711e543eae87dbb00c287b0 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 14 Jun 2017 14:14:56 +0200 Subject: [PATCH 5/5] dhcp/systemd: add support for DHCPv4 domain search list (option 119) --- src/dhcp/nm-dhcp-systemd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index 6fb09907f0..b909475552 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -79,7 +79,6 @@ G_DEFINE_TYPE (NMDhcpSystemd, nm_dhcp_systemd, NM_TYPE_DHCP_CLIENT) #define DHCP_OPTION_NIS_DOMAIN 40 #define DHCP_OPTION_NIS_SERVERS 41 -#define DHCP_OPTION_DOMAIN_SEARCH 119 #define DHCP_OPTION_MS_ROUTES 249 #define DHCP_OPTION_WPAD 252 @@ -118,7 +117,7 @@ static const ReqOption dhcp4_requests[] = { { DHCP_OPTION_NIS_SERVERS, REQPREFIX "nis_servers", TRUE }, { SD_DHCP_OPTION_NTP_SERVER, REQPREFIX "ntp_servers", TRUE }, { SD_DHCP_OPTION_SERVER_IDENTIFIER, REQPREFIX "dhcp_server_identifier", TRUE }, - { DHCP_OPTION_DOMAIN_SEARCH, REQPREFIX "domain_search", TRUE }, + { SD_DHCP_OPTION_DOMAIN_SEARCH_LIST, REQPREFIX "domain_search", TRUE }, { SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE, REQPREFIX "rfc3442_classless_static_routes", TRUE }, { DHCP_OPTION_MS_ROUTES, REQPREFIX "ms_classless_static_routes", TRUE }, { DHCP_OPTION_WPAD, REQPREFIX "wpad", TRUE }, @@ -234,6 +233,7 @@ lease_to_ip4_config (const char *iface, NMPlatformIP4Address address; nm_auto_free_gstring GString *str = NULL; gs_free sd_dhcp_route **routes = NULL; + const char *const*search_domains = NULL; guint16 mtu; int r, num; guint64 end_time; @@ -294,6 +294,18 @@ lease_to_ip4_config (const char *iface, add_option (options, dhcp4_requests, SD_DHCP_OPTION_DOMAIN_NAME_SERVER, str->str); } + /* Search domains */ + num = sd_dhcp_lease_get_search_domains (lease, (char ***) &search_domains); + if (num > 0) { + nm_gstring_prepare (&str); + for (i = 0; i < num; i++) { + nm_ip4_config_add_search (ip4_config, search_domains[i]); + g_string_append_printf (str, "%s%s", str->len ? " " : "", search_domains[i]); + LOG_LEASE (LOGD_DHCP4, "domain search '%s'", search_domains[i]); + } + add_option (options, dhcp4_requests, SD_DHCP_OPTION_DOMAIN_SEARCH_LIST, str->str); + } + /* Domain Name */ r = sd_dhcp_lease_get_domainname (lease, &s); if (r == 0) {