Commit 16bccfd6 authored by Dan Williams's avatar Dan Williams

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.
parent e04281fd
......@@ -290,11 +290,13 @@ global:
nm_setting_wired_get_mac_address;
nm_setting_wired_get_cloned_mac_address;
nm_setting_wired_get_mtu;
nm_setting_wired_get_s390_subchannels;
nm_setting_wired_get_s390_port_name;
nm_setting_wired_get_s390_port_number;
nm_setting_wired_get_s390_qeth_layer;
nm_setting_wired_get_num_s390_options;
nm_setting_wired_get_s390_nettype;
nm_setting_wired_get_s390_option;
nm_setting_wired_get_s390_option_by_key;
nm_setting_wired_add_s390_option;
nm_setting_wired_get_s390_subchannels;
nm_setting_wired_remove_s390_option;
nm_setting_wireless_ap_security_compatible;
nm_setting_wireless_error_get_type;
nm_setting_wireless_error_quark;
......
This diff is collapsed.
......@@ -60,10 +60,8 @@ GQuark nm_setting_wired_error_quark (void);
#define NM_SETTING_WIRED_CLONED_MAC_ADDRESS "cloned-mac-address"
#define NM_SETTING_WIRED_MTU "mtu"
#define NM_SETTING_WIRED_S390_SUBCHANNELS "s390-subchannels"
#define NM_SETTING_WIRED_S390_PORT_NAME "s390-port-name"
#define NM_SETTING_WIRED_S390_PORT_NUMBER "s390-port-number"
#define NM_SETTING_WIRED_S390_QETH_LAYER "s390-qeth-layer"
#define NM_SETTING_WIRED_S390_NETTYPE "s390-nettype"
#define NM_SETTING_WIRED_S390_OPTIONS "s390-options"
typedef struct {
NMSetting parent;
......@@ -89,12 +87,23 @@ gboolean nm_setting_wired_get_auto_negotiate (NMSettingWired *setting
const GByteArray *nm_setting_wired_get_mac_address (NMSettingWired *setting);
const GByteArray *nm_setting_wired_get_cloned_mac_address (NMSettingWired *setting);
guint32 nm_setting_wired_get_mtu (NMSettingWired *setting);
const GPtrArray * nm_setting_wired_get_s390_subchannels (NMSettingWired *setting);
const char * nm_setting_wired_get_s390_port_name (NMSettingWired *setting);
guint32 nm_setting_wired_get_s390_port_number (NMSettingWired *setting);
guint32 nm_setting_wired_get_s390_qeth_layer (NMSettingWired *setting);
const char * nm_setting_wired_get_s390_nettype (NMSettingWired *setting);
guint32 nm_setting_wired_get_num_s390_options (NMSettingWired *setting);
gboolean nm_setting_wired_get_s390_option (NMSettingWired *setting,
guint32 idx,
const char **out_key,
const char **out_value);
const char * nm_setting_wired_get_s390_option_by_key (NMSettingWired *setting,
const char *key);
gboolean nm_setting_wired_add_s390_option (NMSettingWired *setting,
const char *key,
const char *item);
gboolean nm_setting_wired_remove_s390_option (NMSettingWired *setting,
const char *key);
G_END_DECLS
#endif /* NM_SETTING_WIRED_H */
......@@ -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);
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);
/* 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);
}
portno = nm_setting_wired_get_s390_port_number (s_wired);
g_string_append_printf (str, "portno=%d", portno);
svSetValue (ifcfg, "OPTIONS", str->str, FALSE);
if (str->len)
svSetValue (ifcfg, "OPTIONS", str->str, FALSE);
g_string_free (str, TRUE);
}
......
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