ifcfg-rh: merge branch 'bg/ifcfg-rh-dns-rh1517794'

https://bugzilla.redhat.com/show_bug.cgi?id=1517794
This commit is contained in:
Beniamino Galvani 2017-11-30 23:56:00 +01:00
commit 6f5f1b2d29
10 changed files with 96 additions and 126 deletions

View file

@ -3467,6 +3467,13 @@ DEFINE_REMOVER_INDEX_OR_VALUE (_remove_fcn_ipv6_config_dns_options,
nm_setting_ip_config_remove_dns_option,
_validate_and_remove_ipv6_dns_option)
static gboolean
_dns_options_is_default (NMSettingIPConfig *setting)
{
return nm_setting_ip_config_has_dns_options (setting)
&& !nm_setting_ip_config_get_num_dns_options (setting);
}
static gboolean
_set_fcn_ip6_config_addresses (ARGS_SET_FCN)
{
@ -5367,7 +5374,7 @@ static const NMMetaPropertyInfo *const property_infos_IP4_CONFIG[] = {
.remove_fcn = _remove_fcn_ipv4_config_dns_options,
),
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (get_with_default,
.fcn = GET_FCN_WITH_DEFAULT (NMSettingIPConfig, nm_setting_ip_config_has_dns_options),
.fcn = GET_FCN_WITH_DEFAULT (NMSettingIPConfig, _dns_options_is_default),
),
),
PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_PRIORITY, DESCRIBE_DOC_NM_SETTING_IP4_CONFIG_DNS_PRIORITY,
@ -5530,7 +5537,7 @@ static const NMMetaPropertyInfo *const property_infos_IP6_CONFIG[] = {
.remove_fcn = _remove_fcn_ipv6_config_dns_options,
),
.property_typ_data = DEFINE_PROPERTY_TYP_DATA_SUBTYPE (get_with_default,
.fcn = GET_FCN_WITH_DEFAULT (NMSettingIPConfig, nm_setting_ip_config_has_dns_options),
.fcn = GET_FCN_WITH_DEFAULT (NMSettingIPConfig, _dns_options_is_default),
),
),
PROPERTY_INFO (NM_SETTING_IP_CONFIG_DNS_PRIORITY, DESCRIBE_DOC_NM_SETTING_IP6_CONFIG_DNS_PRIORITY,

View file

@ -1791,7 +1791,7 @@ nm_setting_ip_config_get_num_dns_options (NMSettingIPConfig *setting)
* or the options are left undefined. The latter means to use
* a default configuration, while the former explicitly means "no-options".
*
* Returns: whether DNS options are initalized or left unset (the default).
* Returns: whether DNS options are initialized or left unset (the default).
**/
gboolean
nm_setting_ip_config_has_dns_options (NMSettingIPConfig *setting)

View file

@ -688,6 +688,14 @@ nm_setting_ip4_config_class_init (NMSettingIP4ConfigClass *ip4_class)
* ---end---
*/
/* ---ifcfg-rh---
* property: dns-options
* variable: RES_OPTIONS(+)
* description: List of DNS options to be added to /etc/resolv.conf
* example: RES_OPTIONS=ndots:2 timeout:3
* ---end---
*/
/* ---ifcfg-rh---
* property: dns-priority
* variable: IPV4_DNS_PRIORITY(+)

View file

@ -671,6 +671,14 @@ nm_setting_ip6_config_class_init (NMSettingIP6ConfigClass *ip6_class)
* ---end---
*/
/* ---ifcfg-rh---
* property: dns-options
* variable: IPV6_RES_OPTIONS(+)
* description: List of DNS options to be added to /etc/resolv.conf
* example: IPV6_RES_OPTIONS=ndots:2 timeout:3
* ---end---
*/
/**
* NMSettingIP6Config:ip6-privacy:
*

View file

@ -351,8 +351,8 @@ typedef struct _NMDevicePrivate {
NMDeviceSysIfaceState sys_iface_state:2;
bool v4_route_table_initalized:1;
bool v6_route_table_initalized:1;
bool v4_route_table_initialized:1;
bool v6_route_table_initialized:1;
NMDeviceAutoconnectBlockedFlags autoconnect_blocked_flags:4;
@ -1487,7 +1487,7 @@ _stats_set_refresh_rate (NMDevice *self, guint refresh_rate_ms)
if (!refresh_rate_ms)
return;
/* trigger an inital refresh of the data whenever the refresh-rate changes.
/* trigger an initial refresh of the data whenever the refresh-rate changes.
* As we process the result in an idle handler with device_link_changed(),
* we don't get the result right away. */
ifindex = nm_device_get_ip_ifindex (self);
@ -1789,10 +1789,10 @@ nm_device_get_route_table (NMDevice *self,
/* the route table setting affects how we sync routes. We shall
* not change it while the device is active, hence, cache it. */
if (addr_family == AF_INET) {
if (priv->v4_route_table_initalized)
if (priv->v4_route_table_initialized)
return priv->v4_route_table ?: (fallback_main ? RT_TABLE_MAIN : 0);
} else {
if (priv->v6_route_table_initalized)
if (priv->v6_route_table_initialized)
return priv->v6_route_table ?: (fallback_main ? RT_TABLE_MAIN : 0);
}
@ -1822,10 +1822,10 @@ nm_device_get_route_table (NMDevice *self,
}
if (addr_family == AF_INET) {
priv->v4_route_table_initalized = TRUE;
priv->v4_route_table_initialized = TRUE;
priv->v4_route_table = route_table;
} else {
priv->v6_route_table_initalized = TRUE;
priv->v6_route_table_initialized = TRUE;
priv->v6_route_table = route_table;
}
@ -12420,8 +12420,8 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type)
priv->v4_commit_first_time = TRUE;
priv->v6_commit_first_time = TRUE;
priv->v4_route_table_initalized = FALSE;
priv->v6_route_table_initalized = FALSE;
priv->v4_route_table_initialized = FALSE;
priv->v6_route_table_initialized = FALSE;
priv->default_route_metric_penalty_ip4_has = FALSE;
priv->default_route_metric_penalty_ip6_has = FALSE;
@ -13386,7 +13386,7 @@ nm_device_update_hw_address (NMDevice *self)
&& !nm_device_is_activating (self))) {
/* when we get a hw_addr the first time or while the device
* is not activated (with no explict hw address set), always
* update our inital hw-address as well. */
* update our initial hw-address as well. */
nm_device_update_initial_hw_address (self);
}
return TRUE;

View file

@ -1244,7 +1244,7 @@ make_proxy_setting (shvarFile *ifcfg, GError **error)
static NMSetting *
make_ip4_setting (shvarFile *ifcfg,
const char *network_file,
shvarFile *network_ifcfg,
gboolean routes_read,
gboolean *out_has_defroute,
GError **error)
@ -1260,7 +1260,6 @@ make_ip4_setting (shvarFile *ifcfg,
int i;
guint32 a;
gboolean has_key;
shvarFile *network_ifcfg;
shvarFile *route_ifcfg;
gboolean never_default;
gint64 timeout;
@ -1287,7 +1286,6 @@ make_ip4_setting (shvarFile *ifcfg,
}
/* Then check if GATEWAYDEV; it's global and overrides DEFROUTE */
network_ifcfg = svOpenFile (network_file, NULL);
if (network_ifcfg) {
gs_free char *gatewaydev_value = NULL;
const char *gatewaydev;
@ -1304,7 +1302,6 @@ make_ip4_setting (shvarFile *ifcfg,
never_default = !!strcmp (v, gatewaydev);
nm_clear_g_free (&value);
svCloseFile (network_ifcfg);
}
v = svGetValueStr (ifcfg, "BOOTPROTO", &value);
@ -1429,12 +1426,10 @@ make_ip4_setting (shvarFile *ifcfg,
/* Gateway */
if (!gateway) {
network_ifcfg = svOpenFile (network_file, NULL);
if (network_ifcfg) {
gboolean read_success;
read_success = read_ip4_address (network_ifcfg, "GATEWAY", &has_key, &a, error);
svCloseFile (network_ifcfg);
if (!read_success)
return NULL;
if (has_key) {
@ -1670,7 +1665,7 @@ read_aliases (NMSettingIPConfig *s_ip4, gboolean read_defroute, const char *file
static NMSetting *
make_ip6_setting (shvarFile *ifcfg,
const char *network_file,
shvarFile *network_ifcfg,
gboolean routes_read,
GError **error)
{
@ -1678,8 +1673,6 @@ make_ip6_setting (shvarFile *ifcfg,
char *value = NULL;
char *str_value;
char *route6_path = NULL;
gs_free char *dns_options_free = NULL;
const char *dns_options = NULL;
gboolean ipv6init, ipv6forwarding, dhcp6 = FALSE;
char *method = NM_SETTING_IP6_CONFIG_METHOD_MANUAL;
char *ipv6addr, *ipv6addr_secondaries;
@ -1689,7 +1682,6 @@ make_ip6_setting (shvarFile *ifcfg,
int i_val;
GError *local = NULL;
gint priority;
shvarFile *network_ifcfg;
gboolean never_default = FALSE;
gboolean ip6_privacy = FALSE, ip6_privacy_prefer_public_ip;
NMSettingIP6ConfigPrivacy ip6_privacy_val;
@ -1708,7 +1700,6 @@ make_ip6_setting (shvarFile *ifcfg,
* they are global and override IPV6_DEFROUTE
* When both are set, the device specified in IPV6_DEFAULTGW takes preference.
*/
network_ifcfg = svOpenFile (network_file, NULL);
if (network_ifcfg) {
char *ipv6_defaultgw, *ipv6_defaultdev;
char *default_dev = NULL;
@ -1717,7 +1708,6 @@ make_ip6_setting (shvarFile *ifcfg,
value = svGetValueStr_cp (ifcfg, "DEVICE");
ipv6_defaultgw = svGetValueStr_cp (network_ifcfg, "IPV6_DEFAULTGW");
ipv6_defaultdev = svGetValueStr_cp (network_ifcfg, "IPV6_DEFAULTDEV");
dns_options = svGetValue (network_ifcfg, "RES_OPTIONS", &dns_options_free);
if (ipv6_defaultgw) {
default_dev = strchr (ipv6_defaultgw, '%');
@ -1736,7 +1726,6 @@ make_ip6_setting (shvarFile *ifcfg,
g_free (ipv6_defaultgw);
g_free (ipv6_defaultdev);
g_free (value);
svCloseFile (network_ifcfg);
}
/* Find out method property */
@ -1744,11 +1733,8 @@ make_ip6_setting (shvarFile *ifcfg,
str_value = svGetValueStr_cp (ifcfg, "IPV6INIT");
ipv6init = svGetValueBoolean (ifcfg, "IPV6INIT", FALSE);
if (!str_value) {
network_ifcfg = svOpenFile (network_file, NULL);
if (network_ifcfg) {
if (network_ifcfg)
ipv6init = svGetValueBoolean (network_ifcfg, "IPV6INIT", FALSE);
svCloseFile (network_ifcfg);
}
}
g_free (str_value);
@ -1870,11 +1856,8 @@ make_ip6_setting (shvarFile *ifcfg,
value = svGetValueStr_cp (ifcfg, "IPV6_DEFAULTGW");
if (!value) {
/* If no gateway in the ifcfg, try global /etc/sysconfig/network instead */
network_ifcfg = svOpenFile (network_file, NULL);
if (network_ifcfg) {
if (network_ifcfg)
value = svGetValueStr_cp (network_ifcfg, "IPV6_DEFAULTGW");
svCloseFile (network_ifcfg);
}
}
if (value) {
char *ptr;
@ -1948,8 +1931,7 @@ make_ip6_setting (shvarFile *ifcfg,
}
/* DNS options */
parse_dns_options (s_ip6, svGetValue (ifcfg, "RES_OPTIONS", &value));
parse_dns_options (s_ip6, dns_options);
parse_dns_options (s_ip6, svGetValue (ifcfg, "IPV6_RES_OPTIONS", &value));
g_free (value);
/* DNS priority */
@ -2200,7 +2182,6 @@ read_dcb_percent_array (shvarFile *ifcfg,
static gboolean
make_dcb_setting (shvarFile *ifcfg,
const char *network_file,
NMSetting **out_setting,
GError **error)
{
@ -5237,6 +5218,7 @@ connection_from_file_full (const char *filename,
gboolean *out_ignore_error)
{
nm_auto_shvar_file_close shvarFile *parsed = NULL;
nm_auto_shvar_file_close shvarFile *network_ifcfg = NULL;
gs_unref_object NMConnection *connection = NULL;
gs_free char *type = NULL;
char *devtype, *bootproto;
@ -5264,6 +5246,8 @@ connection_from_file_full (const char *filename,
if (!parsed)
return NULL;
network_ifcfg = svOpenFile (network_file, NULL);
if (!svGetValueBoolean (parsed, "NM_CONTROLLED", TRUE)) {
connection = create_unhandled_connection (filename, parsed, "unmanaged", out_unhandled);
if (!connection) {
@ -5473,7 +5457,7 @@ connection_from_file_full (const char *filename,
}
s_ip6 = make_ip6_setting (parsed,
network_file,
network_ifcfg,
!has_complex_routes_v4 && !has_complex_routes_v6,
error);
if (!s_ip6)
@ -5482,7 +5466,7 @@ connection_from_file_full (const char *filename,
nm_connection_add_setting (connection, s_ip6);
s_ip4 = make_ip4_setting (parsed,
network_file,
network_ifcfg,
!has_complex_routes_v4 && !has_complex_routes_v6,
&has_ip4_defroute,
error);
@ -5519,7 +5503,7 @@ connection_from_file_full (const char *filename,
if (s_port)
nm_connection_add_setting (connection, s_port);
if (!make_dcb_setting (parsed, network_file, &s_dcb, error))
if (!make_dcb_setting (parsed, &s_dcb, error))
return NULL;
if (s_dcb)
nm_connection_add_setting (connection, s_dcb);

View file

@ -2112,6 +2112,28 @@ write_user_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
return TRUE;
}
static void
write_res_options (shvarFile *ifcfg, NMSettingIPConfig *s_ip, const char *var)
{
nm_auto_free_gstring GString *value = NULL;
guint i, num_options;
if (!nm_setting_ip_config_has_dns_options (s_ip)) {
svUnsetValue (ifcfg, var);
return;
}
value = g_string_new (NULL);
num_options = nm_setting_ip_config_get_num_dns_options (s_ip);
for (i = 0; i < num_options; i++) {
if (i > 0)
g_string_append_c (value, ' ');
g_string_append (value, nm_setting_ip_config_get_dns_option (s_ip, i));
}
svSetValue (ifcfg, var, value->str);
}
static gboolean
write_ip4_setting (NMConnection *connection,
shvarFile *ifcfg,
@ -2143,6 +2165,7 @@ write_ip4_setting (NMConnection *connection,
* Some IPv4 setting related options are not cleared,
* for no strong reason. */
svUnsetValue (ifcfg, "BOOTPROTO");
svUnsetValue (ifcfg, "RES_OPTIONS");
svUnsetAll (ifcfg, SV_KEY_TYPE_IP4_ADDRESS);
return TRUE;
}
@ -2339,6 +2362,8 @@ write_ip4_setting (NMConnection *connection,
else
svUnsetValue (ifcfg, "IPV4_DNS_PRIORITY");
write_res_options (ifcfg, s_ip4, "RES_OPTIONS");
return TRUE;
}
@ -2480,6 +2505,7 @@ write_ip6_setting (NMConnection *connection,
svUnsetValue (ifcfg, "IPV6_FAILURE_FATAL");
svUnsetValue (ifcfg, "IPV6_ROUTE_METRIC");
svUnsetValue (ifcfg, "IPV6_ADDR_GEN_MODE");
svUnsetValue (ifcfg, "IPV6_RES_OPTIONS");
return TRUE;
}
@ -2635,70 +2661,13 @@ write_ip6_setting (NMConnection *connection,
else
svUnsetValue (ifcfg, "IPV6_DNS_PRIORITY");
write_res_options (ifcfg, s_ip6, "IPV6_RES_OPTIONS");
NM_SET_OUT (out_route6_content, write_route_file (s_ip6));
return TRUE;
}
static void
add_dns_option (GPtrArray *array, const char *option)
{
if (_nm_utils_dns_option_find_idx (array, option) < 0)
g_ptr_array_add (array, (gpointer) option);
}
static gboolean
write_res_options (NMConnection *connection, shvarFile *ifcfg, GError **error)
{
NMSettingIPConfig *s_ip6;
NMSettingIPConfig *s_ip4;
const char *method;
int i, num_options;
gs_unref_ptrarray GPtrArray *array = NULL;
GString *value;
s_ip4 = nm_connection_get_setting_ip4_config (connection);
if (!s_ip4) {
/* slave-type: clear res-options */
svUnsetValue (ifcfg, "RES_OPTIONS");
return TRUE;
}
array = g_ptr_array_new ();
method = nm_setting_ip_config_get_method (s_ip4);
if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED)) {
num_options = nm_setting_ip_config_get_num_dns_options (s_ip4);
for (i = 0; i < num_options; i++)
add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip4, i));
}
s_ip6 = nm_connection_get_setting_ip6_config (connection);
method = nm_setting_ip_config_get_method (s_ip6);
if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE)) {
num_options = nm_setting_ip_config_get_num_dns_options (s_ip6);
for (i = 0; i < num_options; i++)
add_dns_option (array, nm_setting_ip_config_get_dns_option (s_ip6, i));
}
if ( array->len > 0
|| nm_setting_ip_config_has_dns_options (s_ip4)
|| nm_setting_ip_config_has_dns_options (s_ip6)) {
value = g_string_new (NULL);
for (i = 0; i < array->len; i++) {
if (i > 0)
g_string_append_c (value, ' ');
g_string_append (value, array->pdata[i]);
}
svSetValue (ifcfg, "RES_OPTIONS", value->str);
g_string_free (value, TRUE);
} else
svUnsetValue (ifcfg, "RES_OPTIONS");
return TRUE;
}
static char *
escape_id (const char *id)
{
@ -2927,9 +2896,6 @@ do_write_construct (NMConnection *connection,
error))
return FALSE;
if (!write_res_options (connection, ifcfg, error))
return FALSE;
write_connection_setting (s_con, ifcfg);
NM_SET_OUT (out_ifcfg, g_steal_pointer (&ifcfg));

View file

@ -8,7 +8,8 @@ NM_CONTROLLED=yes
PEERDNS=yes
DNS1=10.2.0.4
DOMAIN="lorem.com ipsum.org dolor.edu"
RES_OPTIONS="ndots:3 single-request-reopen inet6"
RES_OPTIONS="ndots:3 single-request-reopen"
IPV6_RES_OPTIONS="inet6"
IPV6INIT=yes
IPV6_AUTOCONF=no
IPV6ADDR="1001:abba::1234/56"

View file

@ -19,3 +19,4 @@ IPV6ADDR_SECONDARIES="dead:beaf::2/56"
DNS3=1:2:3:4::a
DNS4=1:2:3:4::b
RES_OPTIONS=
IPV6_RES_OPTIONS=

View file

@ -2162,8 +2162,9 @@ test_read_dns_options (void)
NMSettingIPConfig *s_ip4, *s_ip6;
char *unmanaged = NULL;
const char *option;
const char *options[] = { "ndots:3", "single-request-reopen", "inet6" };
guint32 i, options_len = sizeof (options) / sizeof (options[0]);
const char *options4[] = { "ndots:3", "single-request-reopen" };
const char *options6[] = { "inet6" };
guint32 i, num;
connection = _connection_from_file (TEST_IFCFG_DIR "/network-scripts/ifcfg-test-dns-options",
NULL, TYPE_ETHERNET, &unmanaged);
@ -2175,18 +2176,20 @@ test_read_dns_options (void)
s_ip6 = nm_connection_get_setting_ip6_config (connection);
g_assert (s_ip6);
i = nm_setting_ip_config_get_num_dns_options (s_ip4);
g_assert_cmpint (i, ==, options_len);
num = nm_setting_ip_config_get_num_dns_options (s_ip4);
g_assert_cmpint (num, ==, G_N_ELEMENTS (options4));
i = nm_setting_ip_config_get_num_dns_options (s_ip6);
g_assert_cmpint (i, ==, options_len);
for (i = 0; i < options_len; i++) {
for (i = 0; i < num; i++) {
option = nm_setting_ip_config_get_dns_option (s_ip4, i);
g_assert_cmpstr (options[i], ==, option);
g_assert_cmpstr (options4[i], ==, option);
}
num = nm_setting_ip_config_get_num_dns_options (s_ip6);
g_assert_cmpint (num, ==, G_N_ELEMENTS (options6));
for (i = 0; i < num; i++) {
option = nm_setting_ip_config_get_dns_option (s_ip6, i);
g_assert_cmpstr (options[i], ==, option);
g_assert_cmpstr (options6[i], ==, option);
}
g_object_unref (connection);
@ -2297,6 +2300,8 @@ test_write_dns_options (void)
nm_setting_ip_config_add_address (s_ip4, addr);
nm_ip_address_unref (addr);
nm_setting_ip_config_add_dns_option (s_ip4, "debug");
/* IP6 setting */
s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
@ -2312,26 +2317,16 @@ test_write_dns_options (void)
nm_setting_ip_config_add_address (s_ip6, addr6);
nm_ip_address_unref (addr6);
nm_setting_ip_config_add_dns_option (s_ip4, "debug");
nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3");
nmtst_assert_connection_verifies (connection);
_writer_new_connection_FIXME (connection,
TEST_SCRATCH_DIR "/network-scripts/",
&testfile);
_writer_new_connection (connection,
TEST_SCRATCH_DIR "/network-scripts/",
&testfile);
reread = _connection_from_file (testfile, NULL, TYPE_ETHERNET, NULL);
/* RES_OPTIONS is copied to both IPv4 and IPv6 settings */
nm_setting_ip_config_clear_dns_options (s_ip4, TRUE);
nm_setting_ip_config_add_dns_option (s_ip4, "debug");
nm_setting_ip_config_add_dns_option (s_ip4, "timeout:3");
nm_setting_ip_config_clear_dns_options (s_ip6, TRUE);
nm_setting_ip_config_add_dns_option (s_ip6, "debug");
nm_setting_ip_config_add_dns_option (s_ip6, "timeout:3");
nmtst_assert_connection_equals (connection, TRUE, reread, FALSE);
}