ifcfg-rh: read and write various s390 settings

This commit is contained in:
Dan Williams 2010-06-25 23:46:47 -07:00
parent 7975295442
commit cdf8c079ef
4 changed files with 146 additions and 2 deletions

View file

@ -2926,6 +2926,35 @@ wireless_connection_from_ifcfg (const char *file,
return connection;
}
#define LAYER2_TAG "layer2="
#define PORTNO_TAG "portno="
static gboolean
get_s390_option (const char *tag,
guint32 min,
guint32 max,
const char *value,
int *out_int_val)
{
g_return_val_if_fail (tag != NULL, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
if (strncmp (value, tag, strlen (tag)))
return FALSE;
if (get_int (value + strlen (tag), out_int_val)) {
if (*out_int_val < min || *out_int_val > max) {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid s390 %s value '%d'", tag, *out_int_val);
return FALSE;
}
} else {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid s390 %s '%s'", tag, value);
return FALSE;
}
return TRUE;
}
static NMSetting *
make_wired_setting (shvarFile *ifcfg,
const char *file,
@ -2936,8 +2965,9 @@ make_wired_setting (shvarFile *ifcfg,
{
NMSettingWired *s_wired;
char *value = NULL;
int mtu;
int mtu, portno, layer2;
GByteArray *mac = NULL;
char *nettype;
s_wired = NM_SETTING_WIRED (nm_setting_wired_new ());
@ -3015,6 +3045,44 @@ make_wired_setting (shvarFile *ifcfg,
g_free (value);
}
value = svGetValue (ifcfg, "PORTNAME", FALSE);
if (value && strlen (value))
g_object_set (s_wired, NM_SETTING_WIRED_S390_PORT_NAME, value, NULL);
g_free (value);
nettype = svGetValue (ifcfg, "NETTYPE", FALSE);
if (nettype && strlen (nettype)) {
if (!strcmp (nettype, "qeth") || !strcmp (nettype, "lcs") || !strcmp (nettype, "ctc"))
g_object_set (s_wired, NM_SETTING_WIRED_S390_NETTYPE, nettype, NULL);
else
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: unknown s390 NETTYPE '%s'", nettype);
}
value = svGetValue (ifcfg, "OPTIONS", FALSE);
if (value && strlen (value)) {
char **options, **iter;
iter = options = g_strsplit_set (value, " ", 0);
while (iter && *iter) {
if (get_s390_option (LAYER2_TAG, 0, 1, *iter, &layer2)) {
if (!nettype || strcmp (nettype, "qeth")) {
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: s390 layer2 set but NETTYPE not 'qeth'");
} else {
if (layer2 == 0)
g_object_set (s_wired, NM_SETTING_WIRED_S390_QETH_LAYER, 3, NULL);
else if (layer2 == 1)
g_object_set (s_wired, NM_SETTING_WIRED_S390_QETH_LAYER, 2, NULL);
}
} else if (get_s390_option (PORTNO_TAG, 0, 100, *iter, &portno))
g_object_set (s_wired, NM_SETTING_WIRED_S390_PORT_NUMBER, portno, NULL);
iter++;
}
g_strfreev (options);
}
g_free (value);
g_free (nettype);
if (!nm_controlled && !*unmanaged) {
/* If NM_CONTROLLED=no but there wasn't a MAC address or z/VM
* subchannels, notify the user that the device cannot be unmanaged.

View file

@ -7,4 +7,7 @@ ONBOOT=yes
NETTYPE=qeth
SUBCHANNELS=0.0.0600,0.0.0601,0.0.0602
TYPE=Ethernet
PORTNAME=OSAPORT
OPTIONS='layer2=1 portno=0'
MACADDR=02:00:00:23:65:1a

View file

@ -5368,6 +5368,7 @@ test_read_wired_qeth_static (void)
const char *expected_channel1 = "0.0.0601";
const char *expected_channel2 = "0.0.0602";
const GPtrArray *subchannels;
guint32 num;
connection = connection_from_file (TEST_IFCFG_WIRED_QETH_STATIC,
NULL,
@ -5453,6 +5454,48 @@ test_read_wired_qeth_static (void)
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected subchannel #2",
TEST_IFCFG_WIRED_QETH_STATIC);
/* Nettype */
tmp = nm_setting_wired_get_s390_nettype (s_wired);
ASSERT (tmp != NULL,
"wired-qeth-static-verify-wired", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_QETH_STATIC,
NM_SETTING_WIRED_SETTING_NAME,
NM_SETTING_WIRED_S390_NETTYPE);
ASSERT (strcmp (tmp, "qeth") == 0,
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_QETH_STATIC,
NM_SETTING_WIRED_SETTING_NAME,
NM_SETTING_WIRED_S390_NETTYPE);
/* port name */
tmp = nm_setting_wired_get_s390_port_name (s_wired);
ASSERT (tmp != NULL,
"wired-qeth-static-verify-wired", "failed to verify %s: missing %s / %s key",
TEST_IFCFG_WIRED_QETH_STATIC,
NM_SETTING_WIRED_SETTING_NAME,
NM_SETTING_WIRED_S390_PORT_NAME);
ASSERT (strcmp (tmp, "OSAPORT") == 0,
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_QETH_STATIC,
NM_SETTING_WIRED_SETTING_NAME,
NM_SETTING_WIRED_S390_PORT_NAME);
/* port number */
num = nm_setting_wired_get_s390_port_number (s_wired);
ASSERT (num == 0,
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_QETH_STATIC,
NM_SETTING_WIRED_SETTING_NAME,
NM_SETTING_WIRED_S390_PORT_NUMBER);
/* layer */
num = nm_setting_wired_get_s390_qeth_layer (s_wired);
ASSERT (num == 2,
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s / %s key value",
TEST_IFCFG_WIRED_QETH_STATIC,
NM_SETTING_WIRED_SETTING_NAME,
NM_SETTING_WIRED_S390_QETH_LAYER);
/* ===== IPv4 SETTING ===== */
s_ip4 = NM_SETTING_IP4_CONFIG (nm_connection_get_setting (connection, NM_TYPE_SETTING_IP4_CONFIG));
@ -8893,6 +8936,10 @@ test_write_wired_qeth_dhcp (void)
g_ptr_array_add (subchans, "0.0.602");
g_object_set (s_wired,
NM_SETTING_WIRED_S390_SUBCHANNELS, subchans,
NM_SETTING_WIRED_S390_NETTYPE, "qeth",
NM_SETTING_WIRED_S390_PORT_NAME, "OSAPORT",
NM_SETTING_WIRED_S390_PORT_NUMBER, 5,
NM_SETTING_WIRED_S390_QETH_LAYER, 3,
NULL);
g_ptr_array_free (subchans, TRUE);

View file

@ -842,8 +842,10 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
NMSettingWired *s_wired;
const GByteArray *device_mac, *cloned_mac;
char *tmp;
guint32 mtu;
const char *nettype, *portname;
guint32 mtu, layer, portno;
const GPtrArray *s390_subchannels;
GString *str;
s_wired = (NMSettingWired *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRED);
if (!s_wired) {
@ -896,6 +898,30 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
g_free (tmp);
}
svSetValue (ifcfg, "NETTYPE", NULL, FALSE);
nettype = nm_setting_wired_get_s390_nettype (s_wired);
if (nettype)
svSetValue (ifcfg, "NETTYPE", nettype, FALSE);
svSetValue (ifcfg, "PORTNAME", NULL, FALSE);
portname = nm_setting_wired_get_s390_port_name (s_wired);
if (portname)
svSetValue (ifcfg, "PORTNAME", portname, FALSE);
svSetValue (ifcfg, "OPTIONS", NULL, FALSE);
if (s390_subchannels && nettype) {
str = g_string_sized_new (20);
if (!strcmp (nettype, "qeth")) {
layer = nm_setting_wired_get_s390_qeth_layer (s_wired);
g_string_append_printf (str, "layer2=%d ", layer == 2 ? 1 : 0);
}
portno = nm_setting_wired_get_s390_port_number (s_wired);
g_string_append_printf (str, "portno=%d", portno);
svSetValue (ifcfg, "OPTIONS", str->str, FALSE);
g_string_free (str, TRUE);
}
svSetValue (ifcfg, "TYPE", TYPE_ETHERNET, FALSE);
return TRUE;