diff options
author | Jiří Klimeš <jklimes@redhat.com> | 2015-09-15 16:54:09 +0200 |
---|---|---|
committer | Jiří Klimeš <jklimes@redhat.com> | 2015-09-16 12:36:26 +0200 |
commit | e53df19ea0f2ff895f42845d440522e990720624 (patch) | |
tree | b8455b40daa94b97240773fe33da1faf460d42ce | |
parent | 4bc1fe9d4a801923d39b5a60daaff2ac4a0f865d (diff) | |
download | NetworkManager-jk/ifcfg-network-GATEWAY-rh1262972.tar.gz |
ifcfg-rh: ignore GATEWAY from network file for DHCP connections (rh #1262972)jk/ifcfg-network-GATEWAY-rh1262972
The GATEWAY from /etc/sysconfig/network file is used as a default value when
no GATEWAY is in ifcfg file. However, we have to ignore that GATEWAY for
connections without static addresses. Otherwise such connections would be
invalid and would disappear after restart/reaload.
Some notes:
Putting GATEWAY into /etc/sysconfig/network is not recommended, because it
inherently belongs to the ifcfg file as it is a per-interface property.
The recommended practice is to specify GATEWAY in individual ifcfg files and
define DEFROUTE=no if the interface should not get the default route.
But we continue to read GATEWAY from /etc/sysconfig/network for compatibility
reasons.
See also
https://bugzilla.redhat.com/show_bug.cgi?id=896198#c25
https://bugzilla.redhat.com/show_bug.cgi?id=896198#c27
Fixes: f17699f4e3dacb9358a8503c8b15efe3cb852b48
https://bugzilla.redhat.com/show_bug.cgi?id=1262972
5 files changed, 61 insertions, 0 deletions
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index 43cee19545..551c20b97b 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -1060,6 +1060,13 @@ make_ip4_setting (shvarFile *ifcfg, svCloseFile (network_ifcfg); if (!read_success) goto done; + + if (gateway && nm_setting_ip_config_get_num_addresses (s_ip4) == 0) { + gs_free char *f = g_path_get_basename (ifcfg->fileName); + PARSE_WARNING ("ignoring GATEWAY (/etc/sysconfig/network) for %s " + "because the connection has no static addresses", f); + g_clear_pointer (&gateway, g_free); + } } } g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL); diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am index e133f8d340..97705b2a9a 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am @@ -14,6 +14,8 @@ EXTRA_DIST = \ ifcfg-test-wired-dhcp6-only \ ifcfg-test-wired-global-gateway \ network-test-wired-global-gateway \ + ifcfg-test-wired-global-gateway-ignore \ + network-test-wired-global-gateway-ignore \ ifcfg-test-wired-obsolete-gateway-n \ ifcfg-test-wired-never-default \ network-test-wired-never-default \ diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway-ignore b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway-ignore new file mode 100644 index 0000000000..bb81399e52 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway-ignore @@ -0,0 +1,8 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +IPV6INIT=no + diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway-ignore b/src/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway-ignore new file mode 100644 index 0000000000..7987d1058e --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway-ignore @@ -0,0 +1 @@ +GATEWAY=192.168.1.2 diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index cbee786949..d7b8bd57aa 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -878,6 +878,48 @@ test_read_wired_global_gateway (void) g_object_unref (connection); } +/* Ignore GATEWAY from /etc/sysconfig/network for automatic connections */ +static void +test_read_wired_global_gateway_ignore (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + GError *error = NULL; + char *unmanaged = NULL; + + g_test_expect_message ("NetworkManager", G_LOG_LEVEL_WARNING, + "*ignoring GATEWAY (/etc/sysconfig/network) for * because the connection has no static addresses"); + connection = connection_from_file_test (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-global-gateway-ignore", + TEST_IFCFG_DIR"/network-scripts/network-test-wired-global-gateway-ignore", + TYPE_ETHERNET, &unmanaged, &error); + nmtst_assert_connection_verifies_without_normalization (connection); + g_assert (unmanaged == NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "System test-wired-global-gateway-ignore"); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + /* Addresses */ + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 0); + + /* Gateway */ + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, NULL); + + g_object_unref (connection); +} + static void test_read_wired_obsolete_gateway_n (void) { @@ -12760,6 +12802,7 @@ int main (int argc, char **argv) g_test_add_func (TPATH "read-shared-plus-ip", test_read_wired_shared_plus_ip); g_test_add_func (TPATH "read-dhcp-send-hostname", test_read_write_wired_dhcp_send_hostname); g_test_add_func (TPATH "read-global-gateway", test_read_wired_global_gateway); + g_test_add_func (TPATH "read-global-gateway-ignore", test_read_wired_global_gateway_ignore); g_test_add_func (TPATH "read-obsolete-gateway-n", test_read_wired_obsolete_gateway_n); g_test_add_func (TPATH "read-never-default", test_read_wired_never_default); test_read_wired_defroute_no (); |