From 3cefbded6720892ede9a280241333646a8613a59 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Thu, 4 Sep 2014 21:21:29 -0500 Subject: [PATCH] ifcfg-rh: write GATEWAY instead of GATEWAY0 to be ifup-compatible (rh #1062409) --- 0074-rh1062409-ifcfg-rh-GATEWAY.patch | 235 ++++++++++++++++++++++++++ NetworkManager.spec | 9 +- 2 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 0074-rh1062409-ifcfg-rh-GATEWAY.patch diff --git a/0074-rh1062409-ifcfg-rh-GATEWAY.patch b/0074-rh1062409-ifcfg-rh-GATEWAY.patch new file mode 100644 index 0000000..2b49510 --- /dev/null +++ b/0074-rh1062409-ifcfg-rh-GATEWAY.patch @@ -0,0 +1,235 @@ +From e554ef606f0dfd5ab07057824bb3d3dd52170228 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= +Date: Thu, 19 Jun 2014 15:43:51 +0200 +Subject: [PATCH] ifcfg-rh: write GATEWAY instead of GATEWAY0 to be + ifup-compatible (rh #771673) + +https://bugzilla.redhat.com/show_bug.cgi?id=771673 +https://bugzilla.redhat.com/show_bug.cgi?id=1105770 +--- + .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 147 +++++++++++++++++++++ + src/settings/plugins/ifcfg-rh/writer.c | 25 +++- + 2 files changed, 168 insertions(+), 4 deletions(-) + +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 0e5be5d..ff45550 100644 +--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c ++++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +@@ -7408,6 +7408,153 @@ test_write_wired_8021x_tls (NMSetting802 + } + + static void ++test_write_gateway (void) ++{ ++ NMConnection *connection, *reread; ++ NMSettingConnection *s_con; ++ NMSettingWired *s_wired; ++ NMSettingIP4Config *s_ip4; ++ NMSettingIP6Config *s_ip6; ++ char *uuid, *testfile = NULL, *val; ++ gboolean success; ++ GError *error = NULL; ++ shvarFile *f; ++ NMIP4Address *addr; ++ const char *ip1_str = "1.1.1.3"; ++ const char *ip2_str = "2.2.2.5"; ++ const char *gw1_str = "1.1.1.254"; ++ const char *gw2_str = "2.2.2.254"; ++ struct in_addr ip1, ip2, gw1, gw2; ++ const guint32 prefix = 24; ++ ++ connection = nm_connection_new (); ++ ++ /* Connection setting */ ++ s_con = (NMSettingConnection *) nm_setting_connection_new (); ++ nm_connection_add_setting (connection, NM_SETTING (s_con)); ++ ++ uuid = nm_utils_uuid_generate (); ++ g_object_set (s_con, ++ NM_SETTING_CONNECTION_ID, "Test Write Static Addresses Gateway", ++ NM_SETTING_CONNECTION_UUID, uuid, ++ NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, ++ NULL); ++ g_free (uuid); ++ ++ /* Wired setting */ ++ s_wired = (NMSettingWired *) nm_setting_wired_new (); ++ nm_connection_add_setting (connection, NM_SETTING (s_wired)); ++ ++ /* IP4 setting */ ++ s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new (); ++ nm_connection_add_setting (connection, NM_SETTING (s_ip4)); ++ ++ g_object_set (s_ip4, ++ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL, ++ NM_SETTING_IP4_CONFIG_MAY_FAIL, TRUE, ++ NULL); ++ ++ inet_pton (AF_INET, ip1_str, &ip1); ++ inet_pton (AF_INET, ip2_str, &ip2); ++ inet_pton (AF_INET, gw1_str, &gw1); ++ inet_pton (AF_INET, gw2_str, &gw2); ++ ++ addr = nm_ip4_address_new (); ++ nm_ip4_address_set_address (addr, ip1.s_addr); ++ nm_ip4_address_set_prefix (addr, prefix); ++ nm_ip4_address_set_gateway (addr, gw1.s_addr); ++ nm_setting_ip4_config_add_address (s_ip4, addr); ++ nm_ip4_address_unref (addr); ++ ++ addr = nm_ip4_address_new (); ++ nm_ip4_address_set_address (addr, ip2.s_addr); ++ nm_ip4_address_set_prefix (addr, prefix); ++ nm_ip4_address_set_gateway (addr, gw2.s_addr); ++ nm_setting_ip4_config_add_address (s_ip4, addr); ++ nm_ip4_address_unref (addr); ++ ++ success = nm_connection_verify (connection, &error); ++ g_assert_no_error (error); ++ g_assert (success); ++ ++ /* IP6 setting */ ++ s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new (); ++ nm_connection_add_setting (connection, NM_SETTING (s_ip6)); ++ g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); ++ ++ /* Save the ifcfg */ ++ success = writer_new_connection (connection, ++ TEST_SCRATCH_DIR "/network-scripts/", ++ &testfile, ++ &error); ++ g_assert_no_error (error); ++ g_assert (success); ++ ++ f = svNewFile (testfile); ++ g_assert (f); ++ ++ /* re-read the file to check that the keys was written as IPADDR, GATEWAY and IPADDR1, GATEWAY1 */ ++ val = svGetValue (f, "IPADDR", FALSE); ++ g_assert (val); ++ g_assert_cmpstr (val, ==, ip1_str); ++ g_free (val); ++ ++ val = svGetValue (f, "IPADDR1", FALSE); ++ g_assert (val); ++ g_assert_cmpstr (val, ==, ip2_str); ++ g_free (val); ++ ++ val = svGetValue (f, "IPADDR0", FALSE); ++ g_assert (val == NULL); ++ ++ val = svGetValue (f, "PREFIX", FALSE); ++ g_assert (val); ++ g_assert_cmpstr (val, ==, "24"); ++ g_free (val); ++ ++ val = svGetValue (f, "PREFIX1", FALSE); ++ g_assert (val); ++ g_assert_cmpstr (val, ==, "24"); ++ g_free (val); ++ ++ val = svGetValue (f, "PREFIX0", FALSE); ++ g_assert (val == NULL); ++ ++ val = svGetValue (f, "GATEWAY", FALSE); ++ g_assert (val); ++ g_assert_cmpstr (val, ==, gw1_str); ++ g_free (val); ++ ++ val = svGetValue (f, "GATEWAY1", FALSE); ++ g_assert (val); ++ g_assert_cmpstr (val, ==, gw2_str); ++ g_free (val); ++ ++ val = svGetValue (f, "GATEWAY0", FALSE); ++ g_assert (val == NULL); ++ ++ svCloseFile (f); ++ ++ /* re-read the connection for comparison */ ++ reread = connection_from_file (testfile, NULL, TYPE_WIRELESS, NULL, ++ NULL, NULL, NULL, NULL, &error, NULL); ++ unlink (testfile); ++ g_assert_no_error (error); ++ g_assert (reread); ++ ++ success = nm_connection_verify (reread, &error); ++ g_assert_no_error (error); ++ g_assert (success); ++ ++ g_assert (nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); ++ ++ g_free (testfile); ++ g_object_unref (connection); ++ g_object_unref (reread); ++} ++ ++ ++static void + test_write_wifi_open (void) + { + NMConnection *connection; +@@ -12643,6 +12790,7 @@ int main (int argc, char **argv) + test_write_wired_8021x_tls (NM_SETTING_802_1X_CK_SCHEME_PATH, NM_SETTING_SECRET_FLAG_NOT_SAVED); + test_write_wired_8021x_tls (NM_SETTING_802_1X_CK_SCHEME_PATH, NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED); + test_write_wired_8021x_tls (NM_SETTING_802_1X_CK_SCHEME_BLOB, NM_SETTING_SECRET_FLAG_NONE); ++ g_test_add_func (TPATH "ipv4/write-static-addresses-GATEWAY", test_write_gateway); + test_write_wifi_open (); + test_write_wifi_open_hex_ssid (); + test_write_wifi_wep (); +diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c +index f583366..b9c108c 100644 +--- a/src/settings/plugins/ifcfg-rh/writer.c ++++ b/src/settings/plugins/ifcfg-rh/writer.c +@@ -1718,22 +1718,41 @@ write_ip4_setting (NMConnection *connect + else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) + svSetValue (ifcfg, "BOOTPROTO", "shared", FALSE); + +- /* Write out IPADDR0 .. IPADDR255, PREFIX0 .. PREFIX255, GATEWAY0 .. GATEWAY255 +- * Possible NETMASK is removed only (it's obsolete) */ +- num = nm_setting_ip4_config_get_num_addresses (s_ip4); ++ /* Clear out un-numbered IP address fields */ + svSetValue (ifcfg, "IPADDR", NULL, FALSE); + svSetValue (ifcfg, "PREFIX", NULL, FALSE); + svSetValue (ifcfg, "NETMASK", NULL, FALSE); + svSetValue (ifcfg, "GATEWAY", NULL, FALSE); ++ /* Clear out zero-indexed IP address fields */ ++ svSetValue (ifcfg, "IPADDR0", NULL, FALSE); ++ svSetValue (ifcfg, "PREFIX0", NULL, FALSE); ++ svSetValue (ifcfg, "NETMASK0", NULL, FALSE); ++ svSetValue (ifcfg, "GATEWAY0", NULL, FALSE); ++ ++ /* Write out IPADDR0 .. IPADDR255, PREFIX0 .. PREFIX255, GATEWAY0 .. GATEWAY255 ++ * Possible NETMASK is removed only (it's obsolete) */ ++ num = nm_setting_ip4_config_get_num_addresses (s_ip4); + for (i = 0; i < 256; i++) { + char buf[INET_ADDRSTRLEN]; + NMIP4Address *addr; + guint32 ip; + +- addr_key = g_strdup_printf ("IPADDR%d", i); +- prefix_key = g_strdup_printf ("PREFIX%d", i); +- netmask_key = g_strdup_printf ("NETMASK%d", i); +- gw_key = g_strdup_printf ("GATEWAY%d", i); ++ if (i == 0) { ++ /* Instead of index 0 use un-numbered variables. ++ * It's needed for compatibility with ifup that only recognizes 'GATEAWAY' ++ * See https://bugzilla.redhat.com/show_bug.cgi?id=771673 ++ * and https://bugzilla.redhat.com/show_bug.cgi?id=1105770 ++ */ ++ addr_key = g_strdup ("IPADDR"); ++ prefix_key = g_strdup ("PREFIX"); ++ netmask_key = g_strdup ("NETMASK"); ++ gw_key = g_strdup ("GATEWAY"); ++ } else { ++ addr_key = g_strdup_printf ("IPADDR%d", i); ++ prefix_key = g_strdup_printf ("PREFIX%d", i); ++ netmask_key = g_strdup_printf ("NETMASK%d", i); ++ gw_key = g_strdup_printf ("GATEWAY%d", i); ++ } + + if (i >= num) { + svSetValue (ifcfg, addr_key, NULL, FALSE); +-- +1.9.3 + diff --git a/NetworkManager.spec b/NetworkManager.spec index 2422d23..8b44901 100644 --- a/NetworkManager.spec +++ b/NetworkManager.spec @@ -46,7 +46,7 @@ Name: NetworkManager Summary: Network connection manager and user applications Epoch: 1 Version: 0.9.9.0 -Release: 43%{snapshot}%{?dist} +Release: 44%{snapshot}%{?dist} Group: System Environment/Base License: GPLv2+ URL: http://www.gnome.org/projects/NetworkManager/ @@ -129,6 +129,7 @@ Patch70: 0070-rh1047083-handle-mtu-for-ip4-config-merge-and-subtract.patch Patch71: 0071-fix-connectivity-notification.patch Patch72: 0072-rh1010288-nm_client_new-fix.patch Patch73: 0073-rh1018017-let-systemd-manage-mm.patch +Patch74: 0074-rh1062409-ifcfg-rh-GATEWAY.patch BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) @@ -196,7 +197,7 @@ BuildRequires: systemd >= 200-3 systemd-devel BuildRequires: libsoup-devel BuildRequires: libndp-devel >= 1.0 %if 0%{?rhel} || (0%{?fedora} && 0%{?fedora} > 19) -BuildRequires: ModemManager-glib-devel >= 1.0 +#BuildRequires: ModemManager-glib-devel >= 1.0 %endif %if 0%{?with_nmtui} BuildRequires: newt-devel @@ -376,6 +377,7 @@ by nm-connection-editor and nm-applet in a non-graphical environment. %patch71 -p1 -b .0071-fix-connectivity-notification.orig %patch72 -p1 -b .0072-rh1010288-nm_client_new-fix.orig %patch73 -p1 -b .0073-rh1018017-let-systemd-manage-mm.orig +%patch74 -p1 -b .0074-rh1062409-ifcfg-rh-GATEWAY.orig %build @@ -609,6 +611,9 @@ fi %endif %changelog +* Thu Sep 04 2014 Dan Williams - 0.9.9.0-44.git20131003 +- ifcfg-rh: write GATEWAY instead of GATEWAY0 to be ifup-compatible (rh #1062409) + * Tue Jul 29 2014 Dan Williams - 0.9.9.0-43.git20131003 - wwan: let systemd manage the ModemManager life-cycle (rh #1018017)