ifcfg-rh: interpret DEFROUTE as never-default (rh #528281)

Testcases and cleanups by dcbw.
This commit is contained in:
Gene Czarcinski
2009-11-13 14:40:13 -08:00
committed by Dan Williams
parent 9253d1bc16
commit f7d7b3193d
7 changed files with 232 additions and 2 deletions

View File

@@ -623,6 +623,14 @@ make_ip4_setting (shvarFile *ifcfg,
return NULL; return NULL;
} }
/* First check if DEFROUTE is set for this device; DEFROUTE has the
* opposite meaning from never-default. The default if DEFROUTE is not
* specified is DEFROUTE=yes which means that this connection can be used
* as a default route
*/
never_default = !svTrueValue (ifcfg, "DEFROUTE", TRUE);
/* Then check if GATEWAYDEV; it's global and overrides DEFROUTE */
network_ifcfg = svNewFile (network_file); network_ifcfg = svNewFile (network_file);
if (network_ifcfg) { if (network_ifcfg) {
char *gatewaydev; char *gatewaydev;
@@ -634,8 +642,8 @@ make_ip4_setting (shvarFile *ifcfg,
/* If there was a global gateway device specified, then only connections /* If there was a global gateway device specified, then only connections
* for that device can be the default connection. * for that device can be the default connection.
*/ */
if (gatewaydev && value && strcmp (value, gatewaydev)) if (gatewaydev && value)
never_default = TRUE; never_default = !!strcmp (value, gatewaydev);
g_free (gatewaydev); g_free (gatewaydev);
g_free (value); g_free (value);

View File

@@ -8,6 +8,9 @@ EXTRA_DIST = \
network-test-wired-global-gateway \ network-test-wired-global-gateway \
ifcfg-test-wired-never-default \ ifcfg-test-wired-never-default \
network-test-wired-never-default \ network-test-wired-never-default \
ifcfg-test-wired-defroute-no \
ifcfg-test-wired-defroute-no-gatewaydev-yes \
network-test-wired-defroute-no-gatewaydev-yes \
ifcfg-test-wired-8021x-peap-mschapv2 \ ifcfg-test-wired-8021x-peap-mschapv2 \
keys-test-wired-8021x-peap-mschapv2 \ keys-test-wired-8021x-peap-mschapv2 \
ifcfg-test-onboot-no \ ifcfg-test-onboot-no \

View File

@@ -0,0 +1,11 @@
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
TYPE=Ethernet
DEVICE=eth4
HWADDR=00:11:22:33:44:ee
BOOTPROTO=dhcp
ONBOOT=yes
USERCTL=yes
NM_CONTROLLED=yes
PEERDNS=yes
DEFROUTE=no

View File

@@ -0,0 +1,11 @@
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
TYPE=Ethernet
DEVICE=eth0
HWADDR=00:11:22:33:44:ee
BOOTPROTO=dhcp
ONBOOT=yes
USERCTL=yes
NM_CONTROLLED=yes
PEERDNS=yes
DEFROUTE=no

View File

@@ -296,6 +296,12 @@ test_read_minimal (void)
NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_METHOD); NM_SETTING_IP4_CONFIG_METHOD);
ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE,
"minimal-wired-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_MINIMAL,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT);
g_object_unref (connection); g_object_unref (connection);
} }
@@ -992,6 +998,189 @@ test_read_wired_never_default (void)
g_object_unref (connection); g_object_unref (connection);
} }
#define TEST_IFCFG_WIRED_DEFROUTE_NO TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-defroute-no"
static void
test_read_wired_defroute_no (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingIP4Config *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
gboolean ignore_error = FALSE;
GError *error = NULL;
const char *tmp;
const char *expected_id = "System test-wired-defroute-no";
connection = connection_from_file (TEST_IFCFG_WIRED_DEFROUTE_NO,
NULL,
TYPE_ETHERNET,
NULL,
&unmanaged,
&keyfile,
&error,
&ignore_error);
ASSERT (connection != NULL,
"wired-defroute-no-read", "failed to read %s: %s", TEST_IFCFG_WIRED_DEFROUTE_NO, error->message);
ASSERT (nm_connection_verify (connection, &error),
"wired-defroute-no-verify", "failed to verify %s: %s", TEST_IFCFG_WIRED_DEFROUTE_NO, error->message);
ASSERT (unmanaged == FALSE,
"wired-defroute-no-verify", "failed to verify %s: unexpected unmanaged value", TEST_IFCFG_WIRED_DEFROUTE_NO);
/* ===== CONNECTION SETTING ===== */
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
ASSERT (s_con != NULL,
"wired-defroute-no-verify-connection", "failed to verify %s: missing %s setting",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_CONNECTION_SETTING_NAME);
/* ID */
tmp = nm_setting_connection_get_id (s_con);
ASSERT (tmp != NULL,
"wired-defroute-no-verify-connection", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_ID);
ASSERT (strcmp (tmp, expected_id) == 0,
"wired-defroute-no-verify-connection", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_ID);
/* ===== WIRED SETTING ===== */
s_wired = NM_SETTING_WIRED (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED));
ASSERT (s_wired != NULL,
"wired-defroute-no-verify-wired", "failed to verify %s: missing %s setting",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_WIRED_SETTING_NAME);
/* ===== IPv4 SETTING ===== */
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
ASSERT (s_ip4 != NULL,
"wired-defroute-no-verify-ip4", "failed to verify %s: missing %s setting",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
tmp = nm_setting_ip4_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wired-defroute-no-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_METHOD);
ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == TRUE,
"wired-defroute-no-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT);
g_object_unref (connection);
}
#define TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes"
#define TEST_NETWORK_WIRED_DEFROUTE_NO_GATEWAYDEV_YES TEST_IFCFG_DIR"/network-scripts/network-test-wired-defroute-no-gatewaydev-yes"
static void
test_read_wired_defroute_no_gatewaydev_yes (void)
{
NMConnection *connection;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingIP4Config *s_ip4;
char *unmanaged = NULL;
char *keyfile = NULL;
gboolean ignore_error = FALSE;
GError *error = NULL;
const char *tmp;
const char *expected_id = "System test-wired-defroute-no-gatewaydev-yes";
connection = connection_from_file (TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
TEST_NETWORK_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
TYPE_ETHERNET,
NULL,
&unmanaged,
&keyfile,
&error,
&ignore_error);
ASSERT (connection != NULL,
"wired-defroute-no-gatewaydev-yes-read",
"failed to read %s: %s",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
error->message);
ASSERT (nm_connection_verify (connection, &error),
"wired-defroute-no-gatewaydev-yes-verify",
"failed to verify %s: %s",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
error->message);
ASSERT (unmanaged == FALSE,
"wired-defroute-no-gatewaydev-yes-verify",
"failed to verify %s: unexpected unmanaged value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES);
/* ===== CONNECTION SETTING ===== */
s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
ASSERT (s_con != NULL,
"wired-defroute-no-gatewaydev-yes-verify-connection", "failed to verify %s: missing %s setting",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_CONNECTION_SETTING_NAME);
/* ID */
tmp = nm_setting_connection_get_id (s_con);
ASSERT (tmp != NULL,
"wired-defroute-no-gatewaydev-yes-verify-connection", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_ID);
ASSERT (strcmp (tmp, expected_id) == 0,
"wired-defroute-no-gatewaydev-yes-verify-connection", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_CONNECTION_SETTING_NAME,
NM_SETTING_CONNECTION_ID);
/* ===== WIRED SETTING ===== */
s_wired = NM_SETTING_WIRED (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED));
ASSERT (s_wired != NULL,
"wired-defroute-no-gatewaydev-yes-verify-wired", "failed to verify %s: missing %s setting",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_WIRED_SETTING_NAME);
/* ===== IPv4 SETTING ===== */
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
ASSERT (s_ip4 != NULL,
"wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: missing %s setting",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_IP4_CONFIG_SETTING_NAME);
/* Method */
tmp = nm_setting_ip4_config_get_method (s_ip4);
ASSERT (strcmp (tmp, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0,
"wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_METHOD);
ASSERT (nm_setting_ip4_config_get_never_default (s_ip4) == FALSE,
"wired-defroute-no-gatewaydev-yes-verify-ip4", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_DEFROUTE_NO_GATEWAYDEV_YES,
NM_SETTING_IP4_CONFIG_SETTING_NAME,
NM_SETTING_IP4_CONFIG_NEVER_DEFAULT);
g_object_unref (connection);
}
#define TEST_IFCFG_ONBOOT_NO TEST_IFCFG_DIR"/network-scripts/ifcfg-test-onboot-no" #define TEST_IFCFG_ONBOOT_NO TEST_IFCFG_DIR"/network-scripts/ifcfg-test-onboot-no"
static void static void
@@ -5780,6 +5969,8 @@ int main (int argc, char **argv)
test_read_wired_dhcp (); test_read_wired_dhcp ();
test_read_wired_global_gateway (); test_read_wired_global_gateway ();
test_read_wired_never_default (); test_read_wired_never_default ();
test_read_wired_defroute_no ();
test_read_wired_defroute_no_gatewaydev_yes ();
test_read_onboot_no (); test_read_onboot_no ();
test_read_wired_8021x_peap_mschapv2 (); test_read_wired_8021x_peap_mschapv2 ();
test_read_wifi_open (); test_read_wifi_open ();

View File

@@ -949,6 +949,11 @@ write_ip4_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
} else } else
svSetValue (ifcfg, "DOMAIN", NULL, FALSE); svSetValue (ifcfg, "DOMAIN", NULL, FALSE);
/* DEFROUTE; remember that it has the opposite meaning from never-default */
svSetValue (ifcfg, "DEFROUTE",
nm_setting_ip4_config_get_never_default (s_ip4) ? "no" : "yes",
FALSE);
svSetValue (ifcfg, "PEERDNS", NULL, FALSE); svSetValue (ifcfg, "PEERDNS", NULL, FALSE);
svSetValue (ifcfg, "PEERROUTES", NULL, FALSE); svSetValue (ifcfg, "PEERROUTES", NULL, FALSE);
svSetValue (ifcfg, "DHCP_HOSTNAME", NULL, FALSE); svSetValue (ifcfg, "DHCP_HOSTNAME", NULL, FALSE);