[PATCH 3/3] ifcfg-rh: add ifcfg-dcb writer
- From: Weiping Pan <wpan redhat com>
- To: networkmanager-list gnome org
- Cc: tgraf redhat com
- Subject: [PATCH 3/3] ifcfg-rh: add ifcfg-dcb writer
- Date: Mon, 2 Jul 2012 17:59:37 +0800
Signed-off-by: Weiping Pan <wpan redhat com>
---
.../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 47 +++++-
src/settings/plugins/ifcfg-rh/writer.c | 189 ++++++++++++++++++++
2 files changed, 233 insertions(+), 3 deletions(-)
diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
index 9951d66..4d9a8fa 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -12754,6 +12754,46 @@ test_read_dcb_interface (void)
g_object_unref (connection);
}
+static void
+test_write_dcb (void)
+{
+ NMConnection *connection;
+ char *unmanaged = NULL;
+ char *keyfile = NULL;
+ char *routefile = NULL;
+ char *route6file = NULL;
+ char *written = NULL;
+ gboolean ignore_error = FALSE;
+ GError *error = NULL;
+ gboolean success = FALSE;
+
+ connection = connection_from_file (TEST_IFCFG_DCB_INTERFACE,
+ NULL,
+ TYPE_ETHERNET,
+ NULL,
+ &unmanaged,
+ &keyfile,
+ &routefile,
+ &route6file,
+ &error,
+ &ignore_error);
+ g_assert (connection != NULL);
+
+ success = writer_new_connection (connection,
+ TEST_SCRATCH_DIR "/network-scripts/",
+ &written,
+ &error);
+ g_assert (success);
+
+ unlink (written);
+ g_free (written);
+
+ g_free (unmanaged);
+ g_free (keyfile);
+ g_free (routefile);
+ g_free (route6file);
+}
+
#define TEST_IFCFG_WIFI_OPEN_SSID_BAD_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex"
#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted"
#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX TEST_IFCFG_DIR"/network-scripts/ifcfg-test-wifi-open-ssid-long-hex"
@@ -12779,9 +12819,6 @@ int main (int argc, char **argv)
if (!nm_utils_init (&error))
FAIL ("nm-utils-init", "failed to initialize libnm-util: %s", error->message);
- test_read_dcb_interface ();
- return 0;
-
/* The tests */
test_read_unmanaged ();
test_read_minimal ();
@@ -12941,6 +12978,10 @@ int main (int argc, char **argv)
test_read_bridge_main ();
test_read_bridge_component ();
+ /* DCB */
+ test_read_dcb_interface ();
+ test_write_dcb ();
+
base = g_path_get_basename (argv[0]);
fprintf (stdout, "%s: SUCCESS\n", base);
g_free (base);
diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c
index a431a30..70632da 100644
--- a/src/settings/plugins/ifcfg-rh/writer.c
+++ b/src/settings/plugins/ifcfg-rh/writer.c
@@ -38,6 +38,7 @@
#include <nm-setting-ip6-config.h>
#include <nm-setting-pppoe.h>
#include <nm-setting-vlan.h>
+#include <nm-setting-dcb.h>
#include <nm-utils.h>
#include "common.h"
@@ -1254,6 +1255,187 @@ write_bonding_setting (NMConnection *connection, shvarFile *ifcfg, GError **erro
return TRUE;
}
+static const char *app_subtype_array[APP_STYPE_MAX+1] = {"DCB_APP_FCOE","DCB_APP_ISCSI","DCB_APP_FIP"};
+
+static void
+write_dcb_setting_eaw (shvarFile *ifcfg, const char *type, GArray *array)
+{
+ int i;
+ char key[32] = {'\0'};
+ char value[32] = {'\0'};
+ char subtype[3][16] = {"_ENABLE","_ADVERTISE","_WILLING"};
+
+ for (i = 0; i < EAW_SIZE; i++) {
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strncpy (key, type, strlen (type));
+ strncat (key, subtype[i], 16);
+ sprintf (value, "%s",
+ g_array_index (array, guint8, i) == 1 ? "yes" : "no");
+ svSetValue (ifcfg, key, value, FALSE);
+ }
+}
+
+static gboolean
+write_dcb_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
+{
+ NMSettingDcb *s_dcb;
+ NMSettingConnection *s_con;
+ int i, num;
+ dcb_app *app = NULL;
+ const char *app_subtype = NULL;
+ char key[32] = {'\0'};
+ char value[32] = {'\0'};
+ char *p;
+ GArray *array = NULL;
+
+ s_con = nm_connection_get_setting_connection (connection);
+ if (!s_con) {
+ g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "Missing connection setting");
+ return FALSE;
+ }
+
+ s_dcb = nm_connection_get_setting_dcb (connection);
+ if (!s_dcb) {
+ g_set_error_literal (error, IFCFG_PLUGIN_ERROR, 0, "Missing DCB setting");
+ return FALSE;
+ }
+
+ if (nm_setting_dcb_get_dcb_enabled (s_dcb))
+ svSetValue (ifcfg, "DCB", "on", FALSE);
+ else
+ svSetValue (ifcfg, "DCB", "off", FALSE);
+
+ /* write app settings */
+ num = nm_setting_dcb_get_num_apps (s_dcb);
+ for (i = 0; i < num; ++i) {
+ app = nm_setting_dcb_get_app (s_dcb, i);
+ app_subtype = app_subtype_array[i];
+
+ svSetValue (ifcfg, app_subtype, "yes", FALSE);
+
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strncpy (key, app_subtype, strlen (app_subtype));
+ strcat (key, "_CFG");
+ p = value;
+ sprintf (p, "%0X", g_array_index (app->app_cfg, guint8, 0));
+ p = value + strlen(value);
+ sprintf (p, "%0X", g_array_index (app->app_cfg, guint8, 1));
+ svSetValue (ifcfg, key, value, FALSE);
+
+ write_dcb_setting_eaw (ifcfg, app_subtype, app->app_eaw);
+ }
+
+ /* write pg settings */
+ /* up2tc */
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strcat (key, "DCB_PG_UP2TC");
+ num = nm_setting_dcb_get_num_pg_up2tc (s_dcb);
+ p = value;
+ for (i = 0; i < num; ++i) {
+ sprintf (p, "%d",
+ nm_setting_dcb_get_pg_up2tc(s_dcb, i));
+ p = value + strlen(value);
+ }
+ svSetValue (ifcfg, key, value, FALSE);
+
+ /* pct */
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strcat (key, "DCB_PG_PCT");
+ num = nm_setting_dcb_get_num_pg_pct (s_dcb);
+ p = value;
+ for (i = 0; i < num; ++i) {
+ if (i == 0)
+ sprintf (p, "%d",
+ nm_setting_dcb_get_pg_pct (s_dcb, i));
+ else
+ sprintf (p, ",%d",
+ nm_setting_dcb_get_pg_pct (s_dcb, i));
+ p = value + strlen(value);
+ }
+ svSetValue (ifcfg, key, value, FALSE);
+
+ /* id */
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strcat (key, "DCB_PG_ID");
+ num = nm_setting_dcb_get_num_pg_pgid (s_dcb);
+ p = value;
+ for (i = 0; i < num; ++i) {
+ sprintf (p, "%d",
+ nm_setting_dcb_get_pg_pgid (s_dcb, i));
+ p = value + strlen(value);
+ }
+ svSetValue (ifcfg, key, value, FALSE);
+
+ /* uppct*/
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strcat (key, "DCB_PG_UPPCT");
+ num = nm_setting_dcb_get_num_pg_uppct (s_dcb);
+ p = value;
+ for (i = 0; i < num; ++i) {
+ if (i == 0)
+ sprintf (p, "%d",
+ nm_setting_dcb_get_pg_uppct (s_dcb, i));
+ else
+ sprintf (p, ",%d",
+ nm_setting_dcb_get_pg_uppct (s_dcb, i));
+ p = value + strlen(value);
+ }
+ svSetValue (ifcfg, key, value, FALSE);
+
+ /* strict */
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strcat (key, "DCB_PG_STRICT");
+ num = nm_setting_dcb_get_num_pg_strict (s_dcb);
+ p = value;
+ for (i = 0; i < num; ++i) {
+ sprintf (p, "%d",
+ nm_setting_dcb_get_pg_strict (s_dcb, i));
+ p = value + strlen(value);
+ }
+ svSetValue (ifcfg, key, value, FALSE);
+
+ /* pg eaw */
+ array = g_array_new (FALSE, TRUE, EAW_ELEMENT_SIZE);
+ num = nm_setting_dcb_get_num_pg_eaw (s_dcb);
+ for (i = 0; i < EAW_SIZE; i++) {
+ guint8 tmp = nm_setting_dcb_get_pg_eaw(s_dcb, i);
+ g_array_append_val (array, tmp);
+ }
+ write_dcb_setting_eaw (ifcfg, "DCB_PG", array);
+
+ /* write pfc settings */
+ memset (key, '\0', 32);
+ memset (value, '\0', 32);
+ strcat (key, "DCB_PFC_UP");
+ num = nm_setting_dcb_get_num_pfc_up (s_dcb);
+ p = value;
+ for (i = 0; i < num; ++i) {
+ sprintf (p, "%d",
+ nm_setting_dcb_get_pfc_up (s_dcb, i));
+ p = value + strlen(value);
+ }
+ svSetValue (ifcfg, key, value, FALSE);
+
+ /* pfc eaw */
+ array = g_array_new (FALSE, TRUE, EAW_ELEMENT_SIZE);
+ num = nm_setting_dcb_get_num_pfc_eaw (s_dcb);
+ for (i = 0; i < EAW_SIZE; i++) {
+ guint8 tmp = nm_setting_dcb_get_pfc_eaw (s_dcb, i);
+ g_array_append_val (array, tmp);
+ }
+ write_dcb_setting_eaw (ifcfg, "DCB_PFC", array);
+ g_array_free (array, TRUE);
+
+ return TRUE;
+}
+
static void
write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg)
{
@@ -1909,6 +2091,7 @@ write_connection (NMConnection *connection,
NMSettingConnection *s_con;
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
+ NMSettingDcb *s_dcb;
gboolean success = FALSE;
shvarFile *ifcfg = NULL;
char *ifcfg_name = NULL;
@@ -2021,6 +2204,12 @@ write_connection (NMConnection *connection,
goto out;
}
+ s_dcb = nm_connection_get_setting_dcb (connection);
+ if (s_dcb) {
+ if (!write_dcb_setting (connection, ifcfg, error))
+ goto out;
+ }
+
write_connection_setting (s_con, ifcfg);
if (svWriteFile (ifcfg, 0644)) {
--
1.7.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]