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);
|
||||
|
Reference in New Issue
Block a user