mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 03:40:11 +01:00
ifcfg-rh: ignore GATEWAY from network file for DHCP connections (rh #1262972)
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: f17699f4e3
https://bugzilla.redhat.com/show_bug.cgi?id=1262972
This commit is contained in:
parent
64e3873faf
commit
ed85fcc711
5 changed files with 61 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 \
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
TYPE=Ethernet
|
||||
DEVICE=eth0
|
||||
HWADDR=00:11:22:33:44:ee
|
||||
BOOTPROTO=dhcp
|
||||
ONBOOT=yes
|
||||
USERCTL=yes
|
||||
IPV6INIT=no
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
GATEWAY=192.168.1.2
|
||||
|
|
@ -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 ();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue