core: handle s390 options more cleanly
There are so many... so handle them as a table of key/value pairs instead of having separate functions for each one. At the moment nothing but subchannels is used internally, but this allows plugins to preserve options that NM doesn't care about when reading/writing system configuration.
This commit is contained in:
@@ -2926,35 +2926,6 @@ 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,
|
||||
@@ -2965,7 +2936,7 @@ make_wired_setting (shvarFile *ifcfg,
|
||||
{
|
||||
NMSettingWired *s_wired;
|
||||
char *value = NULL;
|
||||
int mtu, portno, layer2;
|
||||
int mtu;
|
||||
GByteArray *mac = NULL;
|
||||
char *nettype;
|
||||
|
||||
@@ -3046,8 +3017,9 @@ make_wired_setting (shvarFile *ifcfg,
|
||||
}
|
||||
|
||||
value = svGetValue (ifcfg, "PORTNAME", FALSE);
|
||||
if (value && strlen (value))
|
||||
g_object_set (s_wired, NM_SETTING_WIRED_S390_PORT_NAME, value, NULL);
|
||||
if (value && strlen (value)) {
|
||||
nm_setting_wired_add_s390_option (s_wired, "portname", value);
|
||||
}
|
||||
g_free (value);
|
||||
|
||||
nettype = svGetValue (ifcfg, "NETTYPE", FALSE);
|
||||
@@ -3064,17 +3036,15 @@ make_wired_setting (shvarFile *ifcfg,
|
||||
|
||||
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);
|
||||
char *equals = strchr (*iter, '=');
|
||||
gboolean valid = FALSE;
|
||||
|
||||
if (equals) {
|
||||
*equals = '\0';
|
||||
valid = nm_setting_wired_add_s390_option (s_wired, *iter, equals + 1);
|
||||
}
|
||||
if (!valid)
|
||||
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: invalid s390 OPTION '%s'", *iter);
|
||||
iter++;
|
||||
}
|
||||
g_strfreev (options);
|
||||
|
@@ -5368,7 +5368,6 @@ 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,
|
||||
@@ -5468,33 +5467,37 @@ test_read_wired_qeth_static (void)
|
||||
NM_SETTING_WIRED_S390_NETTYPE);
|
||||
|
||||
/* port name */
|
||||
tmp = nm_setting_wired_get_s390_port_name (s_wired);
|
||||
tmp = nm_setting_wired_get_s390_option_by_key (s_wired, "portname");
|
||||
ASSERT (tmp != NULL,
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: missing %s / %s key",
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: missing %s s390 option 'portname'",
|
||||
TEST_IFCFG_WIRED_QETH_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_S390_PORT_NAME);
|
||||
NM_SETTING_WIRED_SETTING_NAME);
|
||||
ASSERT (strcmp (tmp, "OSAPORT") == 0,
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s / %s key value",
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s s390 option 'portname' value",
|
||||
TEST_IFCFG_WIRED_QETH_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_S390_PORT_NAME);
|
||||
NM_SETTING_WIRED_SETTING_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",
|
||||
tmp = nm_setting_wired_get_s390_option_by_key (s_wired, "portno");
|
||||
ASSERT (tmp != NULL,
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: missing %s s390 option 'portno'",
|
||||
TEST_IFCFG_WIRED_QETH_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_S390_PORT_NUMBER);
|
||||
NM_SETTING_WIRED_SETTING_NAME);
|
||||
ASSERT (strcmp (tmp, "0") == 0,
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s s390 option 'portno' value",
|
||||
TEST_IFCFG_WIRED_QETH_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME);
|
||||
|
||||
/* 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",
|
||||
tmp = nm_setting_wired_get_s390_option_by_key (s_wired, "layer2");
|
||||
ASSERT (tmp != NULL,
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: missing %s s390 option 'layer2'",
|
||||
TEST_IFCFG_WIRED_QETH_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME,
|
||||
NM_SETTING_WIRED_S390_QETH_LAYER);
|
||||
NM_SETTING_WIRED_SETTING_NAME);
|
||||
ASSERT (strcmp (tmp, "1") == 0,
|
||||
"wired-qeth-static-verify-wired", "failed to verify %s: unexpected %s s390 option 'layer2' value",
|
||||
TEST_IFCFG_WIRED_QETH_STATIC,
|
||||
NM_SETTING_WIRED_SETTING_NAME);
|
||||
|
||||
/* ===== IPv4 SETTING ===== */
|
||||
|
||||
@@ -8937,12 +8940,14 @@ test_write_wired_qeth_dhcp (void)
|
||||
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);
|
||||
|
||||
nm_setting_wired_add_s390_option (s_wired, "portname", "FOOBAR");
|
||||
nm_setting_wired_add_s390_option (s_wired, "portno", "1");
|
||||
nm_setting_wired_add_s390_option (s_wired, "layer2", "0");
|
||||
nm_setting_wired_add_s390_option (s_wired, "protocol", "blahbalh");
|
||||
|
||||
/* IP4 setting */
|
||||
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
|
||||
ASSERT (s_ip4 != NULL,
|
||||
|
@@ -842,8 +842,8 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
||||
NMSettingWired *s_wired;
|
||||
const GByteArray *device_mac, *cloned_mac;
|
||||
char *tmp;
|
||||
const char *nettype, *portname;
|
||||
guint32 mtu, layer, portno;
|
||||
const char *nettype, *portname, *s390_key, *s390_val;
|
||||
guint32 mtu, num_opts, i;
|
||||
const GPtrArray *s390_subchannels;
|
||||
GString *str;
|
||||
|
||||
@@ -904,21 +904,27 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
||||
svSetValue (ifcfg, "NETTYPE", nettype, FALSE);
|
||||
|
||||
svSetValue (ifcfg, "PORTNAME", NULL, FALSE);
|
||||
portname = nm_setting_wired_get_s390_port_name (s_wired);
|
||||
portname = nm_setting_wired_get_s390_option_by_key (s_wired, "portname");
|
||||
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);
|
||||
num_opts = nm_setting_wired_get_num_s390_options (s_wired);
|
||||
if (s390_subchannels && num_opts) {
|
||||
str = g_string_sized_new (30);
|
||||
for (i = 0; i < num_opts; i++) {
|
||||
nm_setting_wired_get_s390_option (s_wired, i, &s390_key, &s390_val);
|
||||
|
||||
svSetValue (ifcfg, "OPTIONS", str->str, FALSE);
|
||||
/* portname is handled separately */
|
||||
if (!strcmp (s390_key, "portname"))
|
||||
continue;
|
||||
|
||||
if (str->len)
|
||||
g_string_append_c (str, ' ');
|
||||
g_string_append_printf (str, "%s=%s", s390_key, s390_val);
|
||||
}
|
||||
if (str->len)
|
||||
svSetValue (ifcfg, "OPTIONS", str->str, FALSE);
|
||||
g_string_free (str, TRUE);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user