Commit c8fe3bba authored by Jiří Klimeš's avatar Jiří Klimeš

ifcfg-rh: read custom IP address for shared connections (rh #1174632)

Custom IP ranges for shared connection were implemeted in bgo #6759732
(commit 32a001f5). The first IP address
is used and a range is calculated.
However, the commit missed to update ifcfg-rh plugin to read the address.

Test case:
* use ifcfg-rh plugin for NetworkManager
$ nmcli con add type eth con-name shared-ip ifname eth0
$ nmcli con mod shared-ip ipv4.addresses 9.8.7.6/24 ipv4.method shared
$ nmcli con show shared-ip
$ nmcli con show shared-ip  <--- ip address 9.8.7.6 was missing

https://bugzilla.redhat.com/show_bug.cgi?id=1174632
parent a169a79a
......@@ -291,9 +291,11 @@ get_numbered_tag (char *tag_name, int which)
}
static gboolean
is_any_ip4_address_defined (shvarFile *ifcfg)
is_any_ip4_address_defined (shvarFile *ifcfg, int *idx)
{
int i;
int i, ignore, *ret_idx;;
ret_idx = idx ? idx : &ignore;
for (i = -1; i <= 2; i++) {
char *tag;
......@@ -304,6 +306,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg)
g_free (tag);
if (value) {
g_free (value);
*ret_idx = i;
return TRUE;
}
......@@ -312,6 +315,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg)
g_free(tag);
if (value) {
g_free (value);
*ret_idx = i;
return TRUE;
}
......@@ -320,6 +324,7 @@ is_any_ip4_address_defined (shvarFile *ifcfg)
g_free(tag);
if (value) {
g_free (value);
*ret_idx = i;
return TRUE;
}
}
......@@ -924,7 +929,7 @@ make_ip4_setting (shvarFile *ifcfg,
value = svGetValue (ifcfg, "BOOTPROTO", FALSE);
if (!value || !*value || !g_ascii_strcasecmp (value, "none")) {
if (is_any_ip4_address_defined (ifcfg))
if (is_any_ip4_address_defined (ifcfg, NULL))
method = NM_SETTING_IP4_CONFIG_METHOD_MANUAL;
else
method = NM_SETTING_IP4_CONFIG_METHOD_DISABLED;
......@@ -940,11 +945,26 @@ make_ip4_setting (shvarFile *ifcfg,
NULL);
return NM_SETTING (s_ip4);
} else if (!g_ascii_strcasecmp (value, "shared")) {
int idx;
g_free (value);
g_object_set (s_ip4,
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_SHARED,
NM_SETTING_IP_CONFIG_NEVER_DEFAULT, never_default,
NULL);
/* 1 IP address is allowed for shared connections. Read it. */
if (is_any_ip4_address_defined (ifcfg, &idx)) {
NMIPAddress *addr = NULL;
if (!read_full_ip4_address (ifcfg, network_file, idx, NULL, &addr, NULL, error))
goto done;
if (!read_ip4_address (ifcfg, "GATEWAY", &gateway, error))
goto done;
(void) nm_setting_ip_config_add_address (s_ip4, addr);
nm_ip_address_unref (addr);
g_object_set (s_ip4, NM_SETTING_IP_CONFIG_GATEWAY, gateway, NULL);
g_free (gateway);
}
return NM_SETTING (s_ip4);
} else {
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
......
......@@ -9,6 +9,7 @@ EXTRA_DIST = \
ifcfg-test-wired-static-bootproto \
ifcfg-test-wired-dhcp \
ifcfg-test-wired-dhcp-plus-ip \
ifcfg-test-wired-shared-plus-ip \
ifcfg-test-wired-dhcp-send-hostname \
ifcfg-test-wired-dhcp6-only \
ifcfg-test-wired-global-gateway \
......
# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile)
TYPE=Ethernet
DEVICE=eth0
HWADDR=00:11:22:33:44:ee
BOOTPROTO=shared
ONBOOT=no
IPV6INIT=yes
# additional IPs
IPADDR=10.20.30.5
PREFIX=24
GATEWAY=1.1.1.1
# these are ignored for shared method
IPADDR1=6.7.8.9
PREFIX1=16
IPADDR2=3.3.3.3
PREFIX2=24
......@@ -793,6 +793,38 @@ test_read_wired_dhcp_plus_ip (void)
g_object_unref (connection);
}
static void
test_read_wired_shared_plus_ip (void)
{
NMConnection *connection;
NMSettingIPConfig *s_ip4;
GError *error = NULL;
NMIPAddress *ip4_addr;
connection = connection_from_file_test (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wired-shared-plus-ip",
NULL, TYPE_ETHERNET, NULL,
&error);
nmtst_assert_connection_verifies_without_normalization (connection);
/* ===== 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_SHARED);
g_assert (nm_setting_ip_config_get_may_fail (s_ip4));
/* IP addresses */
g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1);
ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0);
g_assert (ip4_addr);
g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 24);
g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "10.20.30.5");
/* Gateway */
g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "1.1.1.1");
g_object_unref (connection);
}
static void
test_read_wired_global_gateway (void)
{
......@@ -12386,6 +12418,7 @@ int main (int argc, char **argv)
test_read_wired_static (TEST_IFCFG_WIRED_STATIC_BOOTPROTO, "System test-wired-static-bootproto", FALSE);
test_read_wired_dhcp ();
g_test_add_func (TPATH "dhcp-plus-ip", test_read_wired_dhcp_plus_ip);
g_test_add_func (TPATH "shared-plus-ip", test_read_wired_shared_plus_ip);
g_test_add_func (TPATH "dhcp-send-hostname", test_read_write_wired_dhcp_send_hostname);
g_test_add_func (TPATH "global-gateway", test_read_wired_global_gateway);
g_test_add_func (TPATH "never-default", test_read_wired_never_default);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment