diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-03-26 11:13:29 +0100 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2015-05-13 17:15:34 +0200 |
commit | e7ff906f910e948f3a0b0ddd08f7c645c9a09cc4 (patch) | |
tree | adee00605c9a3d3a43c96bb04548fed8ed4aaf76 | |
parent | b02f59d4a459cb1f0a4d5cac014f595ff008fe0e (diff) | |
download | NetworkManager-e7ff906f910e948f3a0b0ddd08f7c645c9a09cc4.tar.gz |
dns-manager: add support for DNS options
-rw-r--r-- | src/dns-manager/nm-dns-manager.c | 62 |
1 files changed, 54 insertions, 8 deletions
diff --git a/src/dns-manager/nm-dns-manager.c b/src/dns-manager/nm-dns-manager.c index 430df122fa..caa1c2c69a 100644 --- a/src/dns-manager/nm-dns-manager.c +++ b/src/dns-manager/nm-dns-manager.c @@ -40,6 +40,7 @@ #include <glib/gi18n.h> #include "nm-utils.h" +#include "nm-utils-private.h" #include "nm-dns-manager.h" #include "nm-ip4-config.h" #include "nm-ip6-config.h" @@ -118,6 +119,7 @@ static guint signals[LAST_SIGNAL] = { 0 }; typedef struct { GPtrArray *nameservers; GPtrArray *searches; + GPtrArray *options; const char *nis_domain; GPtrArray *nis_servers; } NMResolvConfData; @@ -143,6 +145,13 @@ add_string_item (GPtrArray *array, const char *str) } static void +add_dns_option_item (GPtrArray *array, const char *str, gboolean ipv6) +{ + if (_nm_utils_dns_option_find_idx (array, str) < 0) + g_ptr_array_add (array, g_strdup (str)); +} + +static void merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src) { guint32 num, num_domains, num_searches, i; @@ -176,6 +185,14 @@ merge_one_ip4_config (NMResolvConfData *rc, NMIP4Config *src) } } + num = nm_ip4_config_get_num_dns_options (src); + for (i = 0; i < num; i++) { + const char *option; + + option = nm_ip4_config_get_dns_option (src, i); + add_dns_option_item (rc->options, option, FALSE); + } + /* NIS stuff */ num = nm_ip4_config_get_num_nis_servers (src); for (i = 0; i < num; i++) { @@ -240,8 +257,15 @@ merge_one_ip6_config (NMResolvConfData *rc, NMIP6Config *src) add_string_item (rc->searches, domain); } } -} + num = nm_ip6_config_get_num_dns_options (src); + for (i = 0; i < num; i++) { + const char *option; + + option = nm_ip6_config_get_dns_option (src, i); + add_dns_option_item (rc->options, option, TRUE); + } +} static GPid run_netconfig (GError **error, gint *stdin_fd) @@ -347,10 +371,12 @@ static gboolean write_resolv_conf (FILE *f, char **searches, char **nameservers, + char **options, GError **error) { char *searches_str = NULL; char *nameservers_str = NULL; + char *options_str = NULL; gboolean retval = FALSE; char *tmp_str; GString *str; @@ -362,6 +388,12 @@ write_resolv_conf (FILE *f, g_free (tmp_str); } + if (options) { + tmp_str = g_strjoinv (" ", options); + options_str = g_strconcat ("option ", tmp_str, "\n", NULL); + g_free (tmp_str); + } + str = g_string_new (""); if (nameservers) { @@ -384,9 +416,10 @@ write_resolv_conf (FILE *f, nameservers_str = g_string_free (str, FALSE); - if (fprintf (f, "# Generated by NetworkManager\n%s%s", + if (fprintf (f, "# Generated by NetworkManager\n%s%s%s", searches_str ? searches_str : "", - nameservers_str) > 0) + nameservers_str, + options_str ? options_str : "") > 0) retval = TRUE; else { g_set_error (error, @@ -398,6 +431,7 @@ write_resolv_conf (FILE *f, g_free (searches_str); g_free (nameservers_str); + g_free (options_str); return retval; } @@ -405,6 +439,7 @@ write_resolv_conf (FILE *f, static gboolean dispatch_resolvconf (char **searches, char **nameservers, + char **options, GError **error) { char *cmd; @@ -431,7 +466,7 @@ dispatch_resolvconf (char **searches, RESOLVCONF_PATH, g_strerror (errno)); else { - retval = write_resolv_conf (f, searches, nameservers, error); + retval = write_resolv_conf (f, searches, nameservers, options, error); err = pclose (f); if (err < 0) { errnosv = errno; @@ -462,6 +497,7 @@ dispatch_resolvconf (char **searches, static gboolean update_resolv_conf (char **searches, char **nameservers, + char **options, GError **error, gboolean install_etc) { @@ -498,7 +534,7 @@ update_resolv_conf (char **searches, return FALSE; } - write_resolv_conf (f, searches, nameservers, error); + write_resolv_conf (f, searches, nameservers, options, error); if (fclose (f) < 0) { if (*error == NULL) { @@ -683,6 +719,7 @@ update_dns (NMDnsManager *self, GSList *iter; const char *nis_domain = NULL; char **searches = NULL; + char **options = NULL; char **nameservers = NULL; char **nis_servers = NULL; int num, i, len; @@ -705,6 +742,7 @@ update_dns (NMDnsManager *self, rc.nameservers = g_ptr_array_new (); rc.searches = g_ptr_array_new (); + rc.options = g_ptr_array_new (); rc.nis_domain = NULL; rc.nis_servers = g_ptr_array_new (); @@ -772,6 +810,12 @@ update_dns (NMDnsManager *self, } else g_ptr_array_free (rc.searches, TRUE); + if (rc.options->len) { + g_ptr_array_add (rc.options, NULL); + options = (char **) g_ptr_array_free (rc.options, FALSE); + } else + g_ptr_array_free (rc.options, TRUE); + if (rc.nameservers->len) { g_ptr_array_add (rc.nameservers, NULL); nameservers = (char **) g_ptr_array_free (rc.nameservers, FALSE); @@ -838,10 +882,10 @@ update_dns (NMDnsManager *self, if (update) { switch (priv->rc_manager) { case NM_DNS_MANAGER_RESOLV_CONF_MAN_NONE: - success = update_resolv_conf (searches, nameservers, error, TRUE); + success = update_resolv_conf (searches, nameservers, options, error, TRUE); break; case NM_DNS_MANAGER_RESOLV_CONF_MAN_RESOLVCONF: - success = dispatch_resolvconf (searches, nameservers, error); + success = dispatch_resolvconf (searches, nameservers, options, error); break; case NM_DNS_MANAGER_RESOLV_CONF_MAN_NETCONFIG: success = dispatch_netconfig (searches, nameservers, nis_domain, @@ -856,7 +900,7 @@ update_dns (NMDnsManager *self, ignoring any errors */ if (!(update && priv->rc_manager == NM_DNS_MANAGER_RESOLV_CONF_MAN_NONE)) { g_clear_error (error); - update_resolv_conf (searches, nameservers, error, FALSE); + update_resolv_conf (searches, nameservers, options, error, FALSE); } /* signal that resolv.conf was changed */ @@ -865,6 +909,8 @@ update_dns (NMDnsManager *self, if (searches) g_strfreev (searches); + if (options) + g_strfreev (options); if (nameservers) g_strfreev (nameservers); if (nis_servers) |