[PATCH 1/2] ifcfg-rh: add ifcfg-dcb parser
- From: Weiping Pan <wpan redhat com>
- To: dcbw redhat com
- Cc: tgraf redhat com, networkmanager-list gnome org
- Subject: [PATCH 1/2] ifcfg-rh: add ifcfg-dcb parser
- Date: Wed, 20 Jun 2012 15:34:44 +0800
The example of ifcfg-dcb is as followed:
TYPE=Ethernet
DEVICE=eth0
HWADDR=00:11:22:33:44:ee
BOOTPROTO=none
IPADDR=1.2.3.4
PREFIX=24
GATEWAY=1.1.1.1
# dcb global switch
# use DCB=off to turn it off
DCB=on
# application settings
# It also supports DCB_APP_ISCSI_XXX and DCB_APP_FIP_XXX.
DCB_APP_FCOE=yes
DCB_APP_FCOE_CFG=08
DCB_APP_FCOE_ENABLE=yes
DCB_APP_FCOE_ADVERTISE=yes
DCB_APP_FCOE_WILLING=yes
# priority group settings
DCB_PG_UP2TC=76543210
DCB_PG_PCT=25,0,0,75,0,0,0,0
DCB_PG_ID=0000111f
DCB_PG_UPPCT=25,25,25,25,50,25,25,0
DCB_PG_STRICT=01010101
DCB_PG_ENABLE=yes
DCB_PG_ADVERTISE=yes
DCB_PG_WILLING=yes
# priority flow control settings
DCB_PFC_UP=00010000
DCB_PFC_ENABLE=yes
DCB_PFC_ADVERTISE=yes
DCB_PFC_WILLING=no
Note:
1 What forms a minimum valid ifcfg for DCB?
DCB=on
DCB_APP_FCOE=yes
DCB_APP_FCOE_ENABLE=yes
DCB_APP_FCOE_ADVERTISE=yes
DCB_APP_FCOE_WILLING=yes
DCB_PFC_ENABLE=yes
DCB_PFC_ADVERTISE=yes
DCB_PFC_WILLING=yes
2 For application settings, it also supports DCB_APP_ISCSI_XXX and
DCB_APP_FIP_XXX.
Signed-off-by: Weiping Pan <wpan redhat com>
---
docs/api/generate-settings-spec.c | 2 +
docs/libnm-util/libnm-util-docs.sgml | 1 +
libnm-util/Makefile.am | 2 +
libnm-util/libnm-util.ver | 28 +
libnm-util/nm-connection.c | 24 +-
libnm-util/nm-connection.h | 2 +
libnm-util/nm-setting-dcb.c | 1062 ++++++++++++++++++++
libnm-util/nm-setting-dcb.h | 159 +++
src/settings/plugins/ifcfg-rh/reader.c | 427 ++++++++-
.../ifcfg-rh/tests/network-scripts/ifcfg-test-dcb | 35 +
.../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 43 +
11 files changed, 1783 insertions(+), 2 deletions(-)
create mode 100644 libnm-util/nm-setting-dcb.c
create mode 100644 libnm-util/nm-setting-dcb.h
create mode 100644 src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb
diff --git a/docs/api/generate-settings-spec.c b/docs/api/generate-settings-spec.c
index 7a540e3..48b3be9 100644
--- a/docs/api/generate-settings-spec.c
+++ b/docs/api/generate-settings-spec.c
@@ -49,6 +49,7 @@
#include <nm-setting-infiniband.h>
#include <nm-setting-bond.h>
#include <nm-setting-vlan.h>
+#include <nm-setting-dcb.h>
#include <nm-utils.h>
@@ -64,6 +65,7 @@ static SettingNewFunc funcs[] = {
nm_setting_infiniband_new,
nm_setting_ip4_config_new,
nm_setting_ip6_config_new,
+ nm_setting_dcb_new,
nm_setting_olpc_mesh_new,
nm_setting_ppp_new,
nm_setting_pppoe_new,
diff --git a/docs/libnm-util/libnm-util-docs.sgml b/docs/libnm-util/libnm-util-docs.sgml
index f389971..8da2d52 100644
--- a/docs/libnm-util/libnm-util-docs.sgml
+++ b/docs/libnm-util/libnm-util-docs.sgml
@@ -30,6 +30,7 @@
<xi:include href="xml/nm-setting-bond.xml"/>
<xi:include href="xml/nm-setting-infiniband.xml"/>
<xi:include href="xml/nm-setting-vlan.xml"/>
+ <xi:include href="xml/nm-setting-dcb.xml"/>
<xi:include href="xml/nm-setting-olpc-mesh.xml"/>
<xi:include href="xml/nm-setting-8021x.xml"/>
<xi:include href="xml/nm-setting-ip4-config.xml"/>
diff --git a/libnm-util/Makefile.am b/libnm-util/Makefile.am
index 76acd99..9242918 100644
--- a/libnm-util/Makefile.am
+++ b/libnm-util/Makefile.am
@@ -23,6 +23,7 @@ libnm_util_include_HEADERS = \
nm-setting-infiniband.h \
nm-setting-ip4-config.h \
nm-setting-vlan.h \
+ nm-setting-dcb.h \
nm-setting-ip6-config.h \
nm-setting-ppp.h \
nm-setting-pppoe.h \
@@ -57,6 +58,7 @@ libnm_util_la_csources = \
nm-setting-infiniband.c \
nm-setting-ip4-config.c \
nm-setting-vlan.c \
+ nm-setting-dcb.c \
nm-setting-ip6-config.c \
nm-setting-ppp.c \
nm-setting-pppoe.c \
diff --git a/libnm-util/libnm-util.ver b/libnm-util/libnm-util.ver
index 9eec05c..3651a32 100644
--- a/libnm-util/libnm-util.ver
+++ b/libnm-util/libnm-util.ver
@@ -21,6 +21,7 @@ global:
nm_connection_get_setting_by_name;
nm_connection_get_setting_cdma;
nm_connection_get_setting_connection;
+ nm_connection_get_setting_dcb;
nm_connection_get_setting_gsm;
nm_connection_get_setting_infiniband;
nm_connection_get_setting_ip4_config;
@@ -232,6 +233,33 @@ global:
nm_setting_connection_new;
nm_setting_connection_permissions_user_allowed;
nm_setting_connection_remove_permission;
+ nm_setting_dcb_error_get_type;
+ nm_setting_dcb_error_quark;
+ nm_setting_dcb_get_app_cfg;
+ nm_setting_dcb_get_app_eaw;
+ nm_setting_dcb_get_app_subtype;
+ nm_setting_dcb_get_dcb_enabled;
+ nm_setting_dcb_get_interface_name;
+ nm_setting_dcb_get_num_app_cfg;
+ nm_setting_dcb_get_num_app_eaw;
+ nm_setting_dcb_get_num_pfc_eaw;
+ nm_setting_dcb_get_num_pfc_up;
+ nm_setting_dcb_get_num_pg_eaw;
+ nm_setting_dcb_get_num_pg_pct;
+ nm_setting_dcb_get_num_pg_pgid;
+ nm_setting_dcb_get_num_pg_strict;
+ nm_setting_dcb_get_num_pg_up2tc;
+ nm_setting_dcb_get_num_pg_uppct;
+ nm_setting_dcb_get_pfc_eaw;
+ nm_setting_dcb_get_pfc_up;
+ nm_setting_dcb_get_pg_eaw;
+ nm_setting_dcb_get_pg_pct;
+ nm_setting_dcb_get_pg_pgid;
+ nm_setting_dcb_get_pg_strict;
+ nm_setting_dcb_get_pg_up2tc;
+ nm_setting_dcb_get_pg_uppct;
+ nm_setting_dcb_get_type;
+ nm_setting_dcb_new;
nm_setting_diff;
nm_setting_diff_result_get_type;
nm_setting_duplicate;
diff --git a/libnm-util/nm-connection.c b/libnm-util/nm-connection.c
index 80a4996..3172197 100644
--- a/libnm-util/nm-connection.c
+++ b/libnm-util/nm-connection.c
@@ -49,6 +49,7 @@
#include "nm-setting-olpc-mesh.h"
#include "nm-setting-bond.h"
#include "nm-setting-vlan.h"
+#include "nm-setting-dcb.h"
#include "nm-setting-serial.h"
#include "nm-setting-gsm.h"
#include "nm-setting-cdma.h"
@@ -118,7 +119,7 @@ static guint signals[LAST_SIGNAL] = { 0 };
static GHashTable *registered_settings = NULL;
-#define DEFAULT_MAP_SIZE 20
+#define DEFAULT_MAP_SIZE 21
static struct SettingInfo {
const char *name;
@@ -240,6 +241,11 @@ register_default_settings (void)
NM_SETTING_VLAN_ERROR,
1, TRUE);
+ register_one_setting (NM_SETTING_DCB_SETTING_NAME,
+ NM_TYPE_SETTING_DCB,
+ NM_SETTING_DCB_ERROR,
+ 1, TRUE);
+
register_one_setting (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME,
NM_TYPE_SETTING_WIRELESS_SECURITY,
NM_SETTING_WIRELESS_SECURITY_ERROR,
@@ -1698,6 +1704,22 @@ nm_connection_get_setting_vlan (NMConnection *connection)
return (NMSettingVlan *) nm_connection_get_setting (connection, NM_TYPE_SETTING_VLAN);
}
+/**
+ * nm_connection_get_setting_dcb:
+ * @connection: the #NMConnection
+ *
+ * A shortcut to return any #NMSettingDcb the connection might contain.
+ *
+ * Returns: (transfer none): an #NMSettingDcb if the connection contains one, otherwise NULL
+ **/
+NMSettingDcb *
+nm_connection_get_setting_dcb (NMConnection *connection)
+{
+ g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+ return (NMSettingDcb *) nm_connection_get_setting (connection, NM_TYPE_SETTING_DCB);
+}
/*************************************************************/
static void
diff --git a/libnm-util/nm-connection.h b/libnm-util/nm-connection.h
index ca29d15..7deaa32 100644
--- a/libnm-util/nm-connection.h
+++ b/libnm-util/nm-connection.h
@@ -50,6 +50,7 @@
#include <nm-setting-wireless.h>
#include <nm-setting-wireless-security.h>
#include <nm-setting-vlan.h>
+#include <nm-setting-dcb.h>
G_BEGIN_DECLS
@@ -205,6 +206,7 @@ NMSettingWired * nm_connection_get_setting_wired (NMConnec
NMSettingWireless * nm_connection_get_setting_wireless (NMConnection *connection);
NMSettingWirelessSecurity *nm_connection_get_setting_wireless_security (NMConnection *connection);
NMSettingVlan * nm_connection_get_setting_vlan (NMConnection *connection);
+NMSettingDcb * nm_connection_get_setting_dcb (NMConnection *connection);
G_END_DECLS
diff --git a/libnm-util/nm-setting-dcb.c b/libnm-util/nm-setting-dcb.c
new file mode 100644
index 0000000..6d62847
--- /dev/null
+++ b/libnm-util/nm-setting-dcb.c
@@ -0,0 +1,1062 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * Weiping Pan <wpan redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2012 Red Hat, Inc.
+ */
+
+#include <stdio.h>
+#include <ctype.h>
+#include <dbus/dbus-glib.h>
+#include "nm-setting-dcb.h"
+#include "nm-param-spec-specialized.h"
+#include "nm-utils.h"
+#include "nm-dbus-glib-types.h"
+#include "nm-setting-connection.h"
+
+/**
+ * SECTION:nm-setting-dcb
+ * @short_description: Describes properties for DCB setttings
+ * @include: nm-setting-dcb.h
+ *
+ * The #NMSettingDcb object is a #NMSetting subclass that describes properties
+ * necessary for DCB setttings.
+ **/
+
+/**
+ * nm_setting_dcb_error_quark:
+ *
+ * Registers an error quark for #NMSettingDcb if necessary.
+ *
+ * Returns: the error quark used for #NMSettingDcb errors.
+ **/
+GQuark
+nm_setting_dcb_error_quark (void)
+{
+ static GQuark quark;
+
+ if (G_UNLIKELY (!quark))
+ quark = g_quark_from_static_string ("nm-setting-dcb-error-quark");
+ return quark;
+}
+
+G_DEFINE_TYPE (NMSettingDcb, nm_setting_dcb, NM_TYPE_SETTING)
+
+#define NM_SETTING_DCB_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_DCB, NMSettingDcbPrivate))
+
+typedef struct {
+ char *interface_name;
+ gboolean dcb_enabled;
+
+ gint32 app_subtype;
+ GArray *app_eaw;
+ GArray *app_cfg;
+
+ GArray *pg_eaw;
+ GArray *pg_up2tc;
+ GArray *pg_pct;
+ GArray *pg_pgid;
+ GArray *pg_uppct;
+ GArray *pg_strict;
+
+ GArray *pfc_eaw;
+ GArray *pfc_up;
+} NMSettingDcbPrivate;
+
+enum {
+ PROP_0,
+ PROP_INTERFACE_NAME,
+ PROP_DCB_ENABLED,
+ PROP_APP_SUBTYPE,
+ PROP_APP_EAW,
+ PROP_APP_CFG,
+ PROP_PG_EAW,
+ PROP_PG_UP2TC,
+ PROP_PG_PCT,
+ PROP_PG_PGID,
+ PROP_PG_UPPCT,
+ PROP_PG_STRICT,
+ PROP_PFC_EAW,
+ PROP_PFC_UP,
+ LAST_PROP
+};
+
+/**
+ * nm_setting_dcb_new:
+ *
+ * Creates a new #NMSettingDcb object with default values.
+ *
+ * Returns: (transfer full): the new empty #NMSettingDcb object
+ **/
+NMSetting *
+nm_setting_dcb_new (void)
+{
+ return (NMSetting *) g_object_new (NM_TYPE_SETTING_DCB, NULL);
+}
+
+/**
+ * nm_setting_dcb_get_interface_name
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the #NMSettingDcb:interface-name property of the setting
+ **/
+const char *
+nm_setting_dcb_get_interface_name (NMSettingDcb *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ return NM_SETTING_DCB_GET_PRIVATE (setting)->interface_name;
+}
+
+gboolean
+nm_setting_dcb_get_dcb_enabled (NMSettingDcb *setting)
+{
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), FALSE);
+
+ return NM_SETTING_DCB_GET_PRIVATE (setting)->dcb_enabled;
+}
+
+/**
+ * nm_setting_dcb_get_app_subtype:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the subtype of #NMSettingDcb:app_subtype, or APP_STYPE_ERROR on error
+ **/
+gint32
+nm_setting_dcb_get_app_subtype (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), APP_STYPE_ERROR);
+
+ return priv->app_subtype;
+}
+
+/**
+ * nm_setting_dcb_get_num_app_eaw:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:app_eaw
+ **/
+guint32
+nm_setting_dcb_get_num_app_eaw (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ return priv->app_eaw->len;
+}
+
+/**
+ * nm_setting_dcb_get_app_eaw:
+ *
+ * @setting: the #NMSettingDcb
+ * @eaw_index: the index of app_eaw array
+ *
+ * Returns: the value of #NMSettingDcb:app_eaw[eaw_index]
+ **/
+guint8
+nm_setting_dcb_get_app_eaw (NMSettingDcb *setting, guint32 eaw_index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), DCB_NOT_SUPPLIED);
+
+ return g_array_index (priv->app_eaw, guint8, eaw_index);
+}
+
+/**
+ * nm_setting_dcb_get_num_app_cfg:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:app_cfg
+ **/
+guint32
+nm_setting_dcb_get_num_app_cfg (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ return priv->app_cfg ? priv->app_cfg->len : 0;
+}
+
+/**
+ * nm_setting_dcb_get_app_cfg:
+ *
+ * @setting: the #NMSettingDcb
+ * @cfg_index: the index of app_cfg array
+ *
+ * Returns: the value of #NMSettingDcb:app_cfg[cfg_index]
+ **/
+guint8
+nm_setting_dcb_get_app_cfg (NMSettingDcb *setting, guint32 cfg_index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), DCB_NOT_SUPPLIED);
+
+ return g_array_index (priv->app_cfg, guint8, cfg_index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pg_eaw:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pg_eaw
+ **/
+guint32 nm_setting_dcb_get_num_pg_eaw (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pg_eaw;
+ g_return_val_if_fail (array != NULL, 0);
+ return priv->pg_eaw->len;
+}
+
+/**
+ * nm_setting_dcb_get_pg_eaw:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pg eaw array
+ *
+ * Returns: the value of #NMSettingDcb:pg_eaw[index]
+ **/
+guint8
+nm_setting_dcb_get_pg_eaw (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pg_eaw (setting), 0);
+
+ array = priv->pg_eaw;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pg_up2tc:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pg_up2tc
+ **/
+guint32
+nm_setting_dcb_get_num_pg_up2tc (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pg_up2tc;
+ g_return_val_if_fail (array != NULL, 0);
+ return priv->pg_up2tc->len;
+}
+
+/**
+ * nm_setting_dcb_get_pg_up2tc:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pg up2tc array
+ *
+ * Returns: the value of #NMSettingDcb:pg_up2tc[index]
+ **/
+guint8
+nm_setting_dcb_get_pg_up2tc (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pg_up2tc (setting), 0);
+
+ array = priv->pg_up2tc;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pg_pct:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pg_pct
+ **/
+guint32
+nm_setting_dcb_get_num_pg_pct (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pg_pct;
+ g_return_val_if_fail (array != NULL, 0);
+ return priv->pg_pct->len;
+}
+
+/**
+ * nm_setting_dcb_get_pg_pct:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pg pct array
+ *
+ * Returns: the value of #NMSettingDcb:pg_pct[index]
+ **/
+guint8
+nm_setting_dcb_get_pg_pct (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pg_pct (setting), 0);
+
+ array = priv->pg_pct;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pg_pgid:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pg_pgid
+ **/
+guint32
+nm_setting_dcb_get_num_pg_pgid (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pg_pgid;
+ g_return_val_if_fail (array != NULL, 0);
+ return priv->pg_pgid->len;
+}
+
+/**
+ * nm_setting_dcb_get_pg_pgid:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pg pgid array
+ *
+ * Returns: the value of #NMSettingDcb:pg_pgid[index]
+ **/
+guint8
+nm_setting_dcb_get_pg_pgid (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pg_pgid (setting), 0);
+
+ array = priv->pg_pgid;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pg_uppct:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pg_uppct
+ **/
+guint32
+nm_setting_dcb_get_num_pg_uppct (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pg_uppct;
+ g_return_val_if_fail (array != NULL, 0);
+ return priv->pg_uppct->len;
+}
+
+/**
+ * nm_setting_dcb_get_pg_uppct:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pg uppct array
+ *
+ * Returns: the value of #NMSettingDcb:pg_uppct[index]
+ **/
+guint8
+nm_setting_dcb_get_pg_uppct (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pg_uppct (setting), 0);
+
+ array = priv->pg_uppct;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pg_strict
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pg_strict
+ **/
+guint32
+nm_setting_dcb_get_num_pg_strict (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pg_strict;
+ g_return_val_if_fail (array != NULL, 0);
+ return priv->pg_strict->len;
+}
+
+/**
+ * nm_setting_dcb_get_pg_strict:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pg strict array
+ *
+ * Returns: the value of #NMSettingDcb:pg_strict[index]
+ **/
+guint8
+nm_setting_dcb_get_pg_strict (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pg_strict (setting), 0);
+
+ array = priv->pg_strict;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pfc_eaw:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pfc_eaw
+ **/
+guint32
+nm_setting_dcb_get_num_pfc_eaw (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pfc_eaw;
+ g_return_val_if_fail (array != NULL, 0);
+ return priv->pfc_eaw->len;
+}
+
+/**
+ * nm_setting_dcb_get_pfc_eaw:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pfc eaw array
+ *
+ * Returns: the value of #NMSettingDcb:pfc_eaw[index]
+ **/
+guint8
+nm_setting_dcb_get_pfc_eaw (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pfc_eaw (setting), 0);
+
+ array = priv->pfc_eaw;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/**
+ * nm_setting_dcb_get_num_pfc_up:
+ *
+ * @setting: the #NMSettingDcb
+ *
+ * Returns: the number of #NMSettingDcb:pfc_up
+ **/
+guint32
+nm_setting_dcb_get_num_pfc_up (NMSettingDcb *setting)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+
+ array = priv->pfc_up;
+ g_return_val_if_fail (array != NULL, 0);
+
+ return priv->pfc_up ? priv->pfc_up->len : 0;
+}
+
+/**
+ * nm_setting_dcb_get_pfc_up:
+ *
+ * @setting: the #NMSettingDcb
+ * @index: the index of pfc up array
+ *
+ * Returns: the value of #NMSettingDcb:pfc_up[index]
+ **/
+guint8
+nm_setting_dcb_get_pfc_up (NMSettingDcb *setting, guint32 index)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ GArray *array = NULL;
+
+ g_return_val_if_fail (NM_IS_SETTING_DCB (setting), 0);
+ g_return_val_if_fail (index < nm_setting_dcb_get_num_pfc_up (setting), 0);
+
+ array = priv->pfc_up;
+ g_return_val_if_fail (array != NULL, 0);
+ return g_array_index (array, guint8, index);
+}
+
+/*********************************************************************/
+
+static void
+nm_setting_dcb_init (NMSettingDcb *setting)
+{
+ g_object_set (setting, NM_SETTING_NAME, NM_SETTING_DCB_SETTING_NAME, NULL);
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ NMSettingDcb *setting = NM_SETTING_DCB (object);
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ switch (prop_id) {
+ case PROP_INTERFACE_NAME:
+ priv->interface_name = g_value_dup_string (value);
+ break;
+
+ case PROP_DCB_ENABLED:
+ priv->dcb_enabled = g_value_get_boolean (value);
+ break;
+
+ case PROP_APP_SUBTYPE:
+ priv->app_subtype = g_value_get_uint (value);
+ break;
+ case PROP_APP_EAW:
+ if (priv->app_eaw)
+ g_array_free (priv->app_eaw, TRUE);
+ priv->app_eaw = g_value_dup_boxed (value);
+ break;
+ case PROP_APP_CFG:
+ if (priv->app_cfg)
+ g_array_free (priv->app_cfg, TRUE);
+ priv->app_cfg = g_value_dup_boxed (value);
+ break;
+
+ case PROP_PG_EAW:
+ if (priv->pg_eaw)
+ g_array_free (priv->pg_eaw, TRUE);
+ priv->pg_eaw = g_value_dup_boxed (value);
+ break;
+ case PROP_PG_UP2TC:
+ if (priv->pg_up2tc)
+ g_array_free (priv->pg_up2tc, TRUE);
+ priv->pg_up2tc = g_value_dup_boxed (value);
+ break;
+ case PROP_PG_PCT:
+ if (priv->pg_pct)
+ g_array_free (priv->pg_pct, TRUE);
+ priv->pg_pct = g_value_dup_boxed (value);
+ break;
+ case PROP_PG_PGID:
+ if (priv->pg_pgid)
+ g_array_free (priv->pg_pgid, TRUE);
+ priv->pg_pgid = g_value_dup_boxed (value);
+ break;
+ case PROP_PG_UPPCT:
+ if (priv->pg_uppct)
+ g_array_free (priv->pg_uppct, TRUE);
+ priv->pg_uppct = g_value_dup_boxed (value);
+ break;
+ case PROP_PG_STRICT:
+ if (priv->pg_strict)
+ g_array_free (priv->pg_strict, TRUE);
+ priv->pg_strict = g_value_dup_boxed (value);
+ break;
+
+ case PROP_PFC_EAW:
+ if (priv->pfc_eaw)
+ g_array_free (priv->pfc_eaw, TRUE);
+ priv->pfc_eaw = g_value_dup_boxed (value);
+ break;
+ case PROP_PFC_UP:
+ if (priv->pfc_up)
+ g_array_free (priv->pfc_up, TRUE);
+ priv->pfc_up = g_value_dup_boxed (value);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ NMSettingDcb *setting = NM_SETTING_DCB (object);
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ switch (prop_id) {
+ case PROP_INTERFACE_NAME:
+ g_value_set_string (value, nm_setting_dcb_get_interface_name (setting));
+ break;
+
+ case PROP_DCB_ENABLED:
+ g_value_set_boolean (value, priv->dcb_enabled);
+ break;
+
+ case PROP_APP_SUBTYPE:
+ g_value_set_uint (value, priv->app_subtype);
+ break;
+ case PROP_APP_EAW:
+ g_value_set_boxed (value, priv->app_eaw);
+ break;
+ case PROP_APP_CFG:
+ g_value_set_boxed (value, priv->app_cfg);
+ break;
+
+ case PROP_PG_EAW:
+ g_value_set_boxed (value, priv->pg_eaw);
+ break;
+ case PROP_PG_UP2TC:
+ g_value_set_boxed (value, priv->pg_up2tc);
+ break;
+ case PROP_PG_PCT:
+ g_value_set_boxed (value, priv->pg_pct);
+ break;
+ case PROP_PG_PGID:
+ g_value_set_boxed (value, priv->pg_pgid);
+ break;
+ case PROP_PG_UPPCT:
+ g_value_set_boxed (value, priv->pg_uppct);
+ break;
+ case PROP_PG_STRICT:
+ g_value_set_boxed (value, priv->pg_strict);
+ break;
+
+ case PROP_PFC_EAW:
+ g_value_set_boxed (value, priv->pfc_eaw);
+ break;
+ case PROP_PFC_UP:
+ g_value_set_boxed (value, priv->pfc_up);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+finalize (GObject *object)
+{
+ NMSettingDcb *setting = NM_SETTING_DCB (object);
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+
+ if (priv->app_eaw)
+ g_array_free (priv->app_eaw, TRUE);
+ if (priv->app_cfg)
+ g_array_free (priv->app_cfg, TRUE);
+
+ if (priv->pg_eaw)
+ g_array_free (priv->pg_eaw, TRUE);
+ if (priv->pg_up2tc)
+ g_array_free (priv->pg_up2tc, TRUE);
+ if (priv->pg_pct)
+ g_array_free (priv->pg_pct, TRUE);
+ if (priv->pg_pgid)
+ g_array_free (priv->pg_pgid, TRUE);
+ if (priv->pg_uppct)
+ g_array_free (priv->pg_uppct, TRUE);
+ if (priv->pg_strict)
+ g_array_free (priv->pg_strict, TRUE);
+
+ if (priv->pfc_eaw)
+ g_array_free (priv->pfc_eaw, TRUE);
+ if (priv->pfc_up)
+ g_array_free (priv->pfc_up, TRUE);
+}
+
+static gboolean
+verify_eaw (GArray *arr)
+{
+ int i;
+ for (i = 0; i < 3; ++i) {
+ guint8 value = g_array_index (arr, guint8, i);
+ if ((value != 0) && (value != 1) && (value != EAW_ERROR))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean
+verify (NMSetting *setting, GSList *all_settings, GError **error)
+{
+ NMSettingDcbPrivate *priv = NM_SETTING_DCB_GET_PRIVATE (setting);
+ int i, sum[DCB_MAX_PRIORITY_GROUPS] = {0};
+
+ /* verify app setting */
+ if (priv->app_subtype == APP_STYPE_ERROR) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_APP_SUBTYPE);
+ return FALSE;
+ }
+
+ if (priv->app_cfg) {
+ if ((g_array_index (priv->app_cfg, guint8, 0) > 15)
+ || (g_array_index (priv->app_cfg, guint8, 1) > 15)) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_APP_CFG);
+ return FALSE;
+ }
+ }
+
+ if (!priv->app_eaw) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_MISSING_PROPERTY,
+ NM_SETTING_DCB_APP_EAW);
+ return FALSE;
+ } else if (!verify_eaw (priv->app_eaw)) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_APP_EAW);
+ return FALSE;
+ }
+
+ /* verify pg setting */
+ if (!priv->pg_eaw) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_MISSING_PROPERTY,
+ NM_SETTING_DCB_PG_EAW);
+ return FALSE;
+ } else if (!verify_eaw (priv->pg_eaw)) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PG_EAW);
+ return FALSE;
+ }
+
+ for (i = 0; i < DCB_MAX_USER_PRIORITIES; ++i) {
+ guint8 value = g_array_index (priv->pg_up2tc, guint8, i);
+ if (value >= DCB_MAX_TRAFFIC_CLASSES && value != DCB_NOT_SUPPLIED) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PG_UP2TC);
+ return FALSE;
+ }
+ }
+
+ sum[0] = 0;
+ for (i = 0; i < DCB_MAX_PRIORITY_GROUPS; ++i) {
+ guint8 value = g_array_index (priv->pg_pct, guint8, i);
+ if (value == DCB_NOT_SUPPLIED)
+ break;
+ sum[0] += value;
+ if (sum[0] > 100 ) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PG_PCT);
+ return FALSE;
+ }
+ }
+
+ for (i = 0; i < DCB_MAX_USER_PRIORITIES; ++i) {
+ guint8 value = g_array_index (priv->pg_pgid, guint8, i);
+ if (value >= DCB_MAX_PRIORITY_GROUPS
+ && value != DCB_UNLIMITED_PRIORITY_GROUP
+ && value != DCB_NOT_SUPPLIED) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PG_PGID);
+ return FALSE;
+ }
+ }
+
+ if (g_array_index (priv->pg_uppct, guint8, 0) != DCB_NOT_SUPPLIED) {
+ for (i = 0; i < DCB_MAX_PRIORITY_GROUPS; ++i)
+ sum[i] = 0;
+ for (i = 0; i < DCB_MAX_USER_PRIORITIES; ++i) {
+ guint8 value = g_array_index (priv->pg_uppct, guint8, i);
+ guint8 index = g_array_index (priv->pg_pgid, guint8, i);
+ if (value > 100) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PG_UPPCT);
+ return FALSE;
+ }
+
+ if (index != DCB_NOT_SUPPLIED)
+ sum[index] += value;
+ }
+
+ for (i = 0; i < DCB_MAX_PRIORITY_GROUPS; ++i)
+ if (sum[i] != 100 && sum[i] != 0) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PG_UPPCT);
+ return FALSE;
+ }
+ }
+
+ for (i = 0; i < DCB_MAX_USER_PRIORITIES; ++i) {
+ guint8 value = g_array_index (priv->pg_strict, guint8, i);
+ if (value != 0 && value != 1 && value != DCB_NOT_SUPPLIED) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PG_STRICT);
+ return FALSE;
+ }
+ }
+
+ /* verify pfc setting */
+ if (!priv->pfc_eaw) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_MISSING_PROPERTY,
+ NM_SETTING_DCB_PFC_EAW);
+ return FALSE;
+ } else if (!verify_eaw (priv->pfc_eaw)) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PFC_EAW);
+ return FALSE;
+ }
+
+ if (priv->pfc_up) {
+ for (i = 0; i < DCB_MAX_USER_PRIORITIES; ++i) {
+ guint8 value = g_array_index (priv->pfc_up, guint8, i);
+ if (value != 0 && value != 1 && value != DCB_NOT_SUPPLIED) {
+ g_set_error (error,
+ NM_SETTING_DCB_ERROR,
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY,
+ NM_SETTING_DCB_PFC_UP);
+ return FALSE;
+ }
+ }
+ }
+
+ return TRUE;
+}
+
+static void
+nm_setting_dcb_class_init (NMSettingDcbClass *setting_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
+ NMSettingClass *parent_class = NM_SETTING_CLASS (setting_class);
+
+ g_type_class_add_private (setting_class, sizeof (NMSettingDcbPrivate));
+
+ /* virtual methods */
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+ object_class->finalize = finalize;
+ parent_class->verify = verify;
+
+ /* Properties */
+ /**
+ * NMSettingDcb:interface-name:
+ *
+ * The name of the network interface
+ **/
+ g_object_class_install_property
+ (object_class, PROP_INTERFACE_NAME,
+ g_param_spec_string (NM_SETTING_DCB_INTERFACE_NAME,
+ "InterfaceName",
+ "The name of the network interface",
+ NULL,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_DCB_ENABLED,
+ g_param_spec_boolean (NM_SETTING_DCB_ENABLED,
+ "DCB enabled",
+ "Is DCB enabled",
+ FALSE,
+ G_PARAM_READWRITE));
+
+ g_object_class_install_property
+ (object_class, PROP_APP_SUBTYPE,
+ g_param_spec_uint (NM_SETTING_DCB_APP_SUBTYPE,
+ "Application subtype",
+ "Now fcoe, iscsi and fip are supported",
+ 0, APP_FIP_STYPE, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_APP_EAW,
+ _nm_param_spec_specialized (NM_SETTING_DCB_APP_EAW,
+ "Application eaw",
+ "Control whether this feature is enabled, advertised via DCBX to peer,"
+ "or willing to change operational configuration based on "
+ "what is received from the peer.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_APP_CFG,
+ _nm_param_spec_specialized (NM_SETTING_DCB_APP_CFG,
+ "Application cfg",
+ "It is a hexadecimal value representing an 8 bit bitmap"
+ "where 1 bits indicate the priorities which frames for the applications"
+ "specified by subtype should use. The lowest order bit maps to priority 0.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PG_EAW,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PG_EAW,
+ "Priority group eaw",
+ "Control whether this feature is enabled, advertised via DCBX to peer,"
+ "or willing to change operational configuration based on "
+ "what is received from the peer.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PG_UP2TC,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PG_UP2TC,
+ "Priority group up2tc",
+ "Priority to traffic class mapping."
+ "From left to right (priorities 0-7),"
+ "x is the traffic class (0-7)"
+ "to which the priority is mapped.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PG_PCT,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PG_PCT,
+ "Priority group pgpct",
+ "Priority group percentage of link bandwidth."
+ "From left to right (priority groups 0-7),"
+ "x is the percentage of link bandwidth allocated to"
+ "the corresponding priority group."
+ "The total bandwidth must equal 100%.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PG_PGID,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PG_PGID,
+ "Priority group ID",
+ "Priority group ID for the 8 priorities."
+ "From left to right (priorities 0-7),"
+ "x is the corresponding priority group ID value,"
+ "which can be 0-7 for priority groups with bandwidth allocations"
+ "or f (priority group ID 15) for the unrestricted priority group.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PG_UPPCT,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PG_UPPCT,
+ "Priority group uppct",
+ "Priority percentage of priority group bandwidth."
+ "From left to right (priorities 0-7),"
+ "x is the percentage of priority group bandwidth"
+ "allocated to the corresponding priority."
+ "The sum of percentages for priorities which belong to"
+ "the same priority group must total 100% (except for priority group 15).",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PG_STRICT,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PG_STRICT,
+ "Priority group strict",
+ "Strict priority setting."
+ "From left to right (priorities 0-7), x is 0 or 1."
+ "1 indicates that the priority may utilize all of the bandwidth"
+ "allocated to its priority group.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PFC_EAW,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PFC_EAW,
+ "Priority flow control eaw",
+ "Control whether this feature is enabled, advertised via DCBX to peer,"
+ "or willing to change operational configuration based on"
+ "what is received from the peer.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+ g_object_class_install_property
+ (object_class, PROP_PFC_UP,
+ _nm_param_spec_specialized (NM_SETTING_DCB_PFC_UP,
+ "Priority flow enalbe/disable",
+ "Enable/disable priority flow control."
+ "From left to right (priorities 0-7), x is 0 or 1."
+ "1 indicates that the corresponding priority is configured"
+ "to transmit priority pause.",
+ DBUS_TYPE_G_UCHAR_ARRAY,
+ G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+}
diff --git a/libnm-util/nm-setting-dcb.h b/libnm-util/nm-setting-dcb.h
new file mode 100644
index 0000000..e07e0f6
--- /dev/null
+++ b/libnm-util/nm-setting-dcb.h
@@ -0,0 +1,159 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * Weiping Pan <wpan redhat com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * (C) Copyright 2012 Red Hat, Inc.
+ */
+
+#ifndef NM_SETTING_DCB_H
+#define NM_SETTING_DCB_H
+
+#include "nm-setting.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_SETTING_DCB (nm_setting_dcb_get_type ())
+#define NM_SETTING_DCB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_DCB, NMSettingDcb))
+#define NM_SETTING_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_DCBCONFIG, NMSettingDcbClass))
+#define NM_IS_SETTING_DCB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_DCB))
+#define NM_IS_SETTING_DCB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_SETTING_DCB))
+#define NM_SETTING_DCB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_DCB, NMSettingDcbClass))
+
+#define NM_SETTING_DCB_SETTING_NAME "dcb"
+
+/**
+ * NMSettingDcbError:
+ * @NM_SETTING_DCB_ERROR_UNKNOWN: unknown or unclassified error
+ * @NM_SETTING_DCB_ERROR_INVALID_PROPERTY: the property was invalid
+ * @NM_SETTING_DCB_ERROR_MISSING_PROPERTY: the property was missing and is
+ * required
+ */
+typedef enum {
+ NM_SETTING_DCB_ERROR_UNKNOWN = 0, /*< nick=Unknown >*/
+ NM_SETTING_DCB_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
+ NM_SETTING_DCB_ERROR_MISSING_PROPERTY /*< nick=MissingProperty >*/
+} NMSettingDcbError;
+
+#define NM_SETTING_DCB_ERROR nm_setting_dcb_error_quark ()
+GQuark nm_setting_dcb_error_quark (void);
+
+/*
+ * What does eaw (EAW) mean ?
+ * e:<0|1>
+ * controls feature enable
+ *
+ * a:<0|1>
+ * controls whether the feature is advertised via DCBX to peer
+ *
+ * w:<0|1>
+ * controls whether the feature is willing to change operational
+ * configuration based on what is received from the peer
+ * */
+
+#define NM_SETTING_DCB_INTERFACE_NAME "interface-name"
+#define NM_SETTING_DCB_ENABLED "dcb-enabled"
+#define NM_SETTING_DCB_APP_SUBTYPE "app-subtype"
+#define NM_SETTING_DCB_APP_CFG "app-cfg"
+#define NM_SETTING_DCB_APP_EAW "app-eaw"
+#define NM_SETTING_DCB_PG_EAW "pg-eaw"
+#define NM_SETTING_DCB_PG_UP2TC "up2tc"
+#define NM_SETTING_DCB_PG_PCT "pg-pct"
+#define NM_SETTING_DCB_PG_PGID "pg-pgid"
+#define NM_SETTING_DCB_PG_UPPCT "pg-uppct"
+#define NM_SETTING_DCB_PG_STRICT "pg-strict"
+#define NM_SETTING_DCB_PFC_EAW "pfc-eaw"
+#define NM_SETTING_DCB_PFC_UP "pfc-up"
+
+#define DCB_MAX_USER_PRIORITIES 8
+#define DCB_MAX_PRIORITY_GROUPS 8
+#define DCB_UNLIMITED_PRIORITY_GROUP 'F'
+#define DCB_MAX_TRAFFIC_CLASSES 8
+#define DCB_LINK_STRICT_PGID 15
+#define DCB_NOT_SUPPLIED 'x'
+
+/* APP */
+#define APP_FCOE_STYPE 0
+#define APP_ISCSI_STYPE 1
+#define APP_FIP_STYPE 2
+#define APP_STYPE_MAX APP_FIP_STYPE
+#define APP_STYPE_ERROR -1
+
+#define EAW_ELEMENT_SIZE 1
+#define EAW_ERROR 'F'
+#define APP_CFG_ELEMENT_SIZE 1
+#define PG_UP2TC_ELEMENT_SIZE 1
+#define PG_PCT_ELEMENT_SIZE 1
+#define PG_PGID_ELEMENT_SIZE 1
+#define PG_UPPCT_ELEMENT_SIZE 1
+#define PG_STRICT_ELEMENT_SIZE 1
+#define PFC_UP_ELEMENT_SIZE 1
+
+typedef struct {
+ NMSetting parent;
+} NMSettingDcb;
+
+typedef struct {
+ NMSettingClass parent;
+
+ /* Padding for future expansion */
+ void (*_reserved1) (void);
+ void (*_reserved2) (void);
+ void (*_reserved3) (void);
+ void (*_reserved4) (void);
+} NMSettingDcbClass;
+
+GType nm_setting_dcb_get_type (void);
+NMSetting * nm_setting_dcb_new (void);
+
+const char * nm_setting_dcb_get_interface_name (NMSettingDcb *setting);
+
+gboolean nm_setting_dcb_get_dcb_enabled (NMSettingDcb *setting);
+
+gint32 nm_setting_dcb_get_app_subtype (NMSettingDcb *setting);
+guint32 nm_setting_dcb_get_num_app_eaw (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_app_eaw (NMSettingDcb *setting, guint32 eaw_index);
+guint32 nm_setting_dcb_get_num_app_cfg (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_app_cfg (NMSettingDcb *setting, guint32 cfg_index);
+
+guint32 nm_setting_dcb_get_num_pg_eaw (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pg_eaw (NMSettingDcb *setting, guint32 index);
+
+guint32 nm_setting_dcb_get_num_pg_up2tc (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pg_up2tc (NMSettingDcb *setting, guint32 index);
+
+guint32 nm_setting_dcb_get_num_pg_pct (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pg_pct (NMSettingDcb *setting, guint32 index);
+
+guint32 nm_setting_dcb_get_num_pg_pgid (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pg_pgid (NMSettingDcb *setting, guint32 index);
+
+guint32 nm_setting_dcb_get_num_pg_uppct (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pg_uppct (NMSettingDcb *setting, guint32 index);
+
+guint32 nm_setting_dcb_get_num_pg_strict (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pg_strict (NMSettingDcb *setting, guint32 index);
+
+guint32 nm_setting_dcb_get_num_pfc_eaw (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pfc_eaw (NMSettingDcb *setting, guint32 index);
+
+guint32 nm_setting_dcb_get_num_pfc_up (NMSettingDcb *setting);
+guint8 nm_setting_dcb_get_pfc_up (NMSettingDcb *setting, guint32 index);
+
+G_END_DECLS
+#endif /* NM_SETTING_DCB_H */
diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c
index a2b08e4..b483b58 100644
--- a/src/settings/plugins/ifcfg-rh/reader.c
+++ b/src/settings/plugins/ifcfg-rh/reader.c
@@ -21,6 +21,7 @@
#include <config.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
@@ -45,6 +46,7 @@
#include <nm-setting-wireless.h>
#include <nm-setting-8021x.h>
#include <nm-setting-bond.h>
+#include <nm-setting-dcb.h>
#include <nm-utils.h>
#include "wifi-utils.h"
@@ -1647,6 +1649,417 @@ error:
return NULL;
}
+static int
+dcb_eaw_is_missing (GArray *eaw)
+{
+ int i, eaw_missing = 1;
+ for (i = 0; i < 3; ++i) {
+ if (g_array_index (eaw, guint8, i) != EAW_ERROR) {
+ eaw_missing = 0;
+ break;
+ }
+ }
+
+ return eaw_missing;
+}
+
+static GArray *
+dcb_get_eaw (shvarFile *ifcfg, const char *type, GArray *array)
+{
+ int i;
+ int value;
+ guint8 eaw_enable = 1, eaw_disable = 0, eaw_error = EAW_ERROR;
+ gchar subtype[3][16] = {"_ENABLE","_ADVERTISE","_WILLING"};
+ gchar key[32];
+
+ g_return_val_if_fail (array != NULL, NULL);
+
+ for (i = 0; i < 3; ++i) {
+ memset (key, '\0', 32);
+ strncpy (key, type, strlen (type));
+ strncat (key, subtype[i], 16);
+ value = svTrueValue (ifcfg, key, eaw_error);
+
+ if (value == 1)
+ g_array_append_val (array, eaw_enable);
+ else if (value == 0)
+ g_array_append_val (array, eaw_disable);
+ else
+ g_array_append_val (array, eaw_error);
+ }
+
+ return array;
+}
+
+static char *app_subtype_array[APP_STYPE_MAX+1] = {"DCB_APP_FCOE","DCB_APP_ISCSI","DCB_APP_FIP"};
+
+static int
+dcb_get_app_cfg (shvarFile *ifcfg, char *app_subtype_str, GArray *app_cfg)
+{
+ gchar app_cfg_str[32] = "\0";
+ gchar *value;
+ gchar *num1, *num2;
+
+ /* app cfg */
+ strncpy (app_cfg_str, app_subtype_str, strlen (app_subtype_str));
+ strcat (app_cfg_str, "_CFG");
+ value = svGetValue (ifcfg, app_cfg_str, FALSE);
+ if (!value || (strlen (value) != 2)) {
+ g_free (value);
+ goto error_return;
+ }
+
+ num1 = value;
+ num2 = num1 + 1;
+ if (isxdigit (*num1) && isxdigit (*num2)) {
+ guint8 num = *num1 - 0x30;
+ g_array_append_val (app_cfg, num);
+ num = *num2 - 0x30;
+ g_array_append_val (app_cfg, num);
+ } else {
+ g_free (value);
+ goto error_return;
+ }
+
+ return 0;
+
+error_return:
+ return -1;
+}
+
+static void
+dcb_initialize_array_not_supplied (GArray *array, int size)
+{
+ int i;
+ char dcb_not_supplied = DCB_NOT_SUPPLIED;
+
+ for (i = 0; i < size; ++i)
+ g_array_append_val (array, dcb_not_supplied);
+}
+
+static NMSetting *
+make_dcb_setting (shvarFile *ifcfg,
+ const char *network_file,
+ GError **error)
+{
+ NMSettingDcb *s_dcb = NULL;
+ int i;
+ guint8 dcb_not_supplied = DCB_NOT_SUPPLIED;
+ guint8 dcb_unlimited_priority_group = DCB_UNLIMITED_PRIORITY_GROUP;
+ char *value, *p;
+ gchar **list, **iter;
+ int times;
+ char *iface_name = NULL;
+ gboolean dcb_enabled = TRUE;
+ gint32 app_subtype;
+ GArray *app_eaw;
+ GArray *app_cfg;
+ GArray *pg_eaw = NULL;
+ GArray *pfc_eaw = NULL;
+ GArray *pg_up2tc = NULL;
+ GArray *pg_pct = NULL;
+ GArray *pg_pgid = NULL;
+ GArray *pg_uppct = NULL;
+ GArray *pg_strict = NULL;
+ GArray *pfc_up = NULL;
+
+ /* malloc memorry */
+ app_eaw = g_array_new (FALSE, TRUE, EAW_ELEMENT_SIZE);
+ if (!app_eaw) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate app_eaw array");
+ return NULL;
+ }
+
+ app_cfg = g_array_new (FALSE, TRUE, APP_CFG_ELEMENT_SIZE);
+ if (!app_cfg) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate app_cfg array");
+ goto free_app_eaw;
+ }
+
+ pg_eaw = g_array_new (FALSE, TRUE, EAW_ELEMENT_SIZE);
+ if (!pg_eaw) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pg_eaw array");
+ goto free_app_cfg;
+ }
+
+ pfc_eaw = g_array_new (FALSE, TRUE, EAW_ELEMENT_SIZE);
+ if (!pfc_eaw) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pfc_eaw array");
+ goto free_pg_eaw;
+ }
+
+ pg_up2tc = g_array_new (FALSE, TRUE, PG_UP2TC_ELEMENT_SIZE);
+ if (!pg_up2tc) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pg_up2tc array");
+ goto free_pfc_eaw;
+ }
+
+ pg_pct = g_array_new (FALSE, TRUE, PG_PCT_ELEMENT_SIZE);
+ if (!pg_pct) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pg_pct array");
+ goto free_pg_up2tc;
+ }
+
+ pg_pgid = g_array_new (FALSE, TRUE, PG_PGID_ELEMENT_SIZE);
+ if (!pg_pgid) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pg_pgid array");
+ goto free_pg_pct;
+ }
+
+ pg_uppct = g_array_new (FALSE, TRUE, PG_UPPCT_ELEMENT_SIZE);
+ if (!pg_uppct) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pg_uppct array");
+ goto free_pg_pgid;
+ }
+
+ pg_strict = g_array_new (FALSE, TRUE, PG_STRICT_ELEMENT_SIZE);
+ if (!pg_strict) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pg_strict array");
+ goto free_pg_uppct;
+ }
+
+ pfc_up = g_array_new (FALSE, TRUE, PFC_UP_ELEMENT_SIZE);
+ if (!pfc_up) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate pfc_up array");
+ goto free_pg_strict;
+ }
+
+ s_dcb = (NMSettingDcb *) nm_setting_dcb_new ();
+ if (!s_dcb) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Could not allocate DCB setting");
+ goto free_pfc_up;
+ }
+
+ iface_name = svGetValue (ifcfg, "DEVICE", FALSE);
+ if (!iface_name) {
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Missing DEVICE property");
+ goto free_pfc_up;
+ }
+
+ g_object_set (s_dcb, NM_SETTING_DCB_INTERFACE_NAME, iface_name, NULL);
+
+ g_object_set (s_dcb, NM_SETTING_DCB_ENABLED, dcb_enabled, NULL);
+
+ /* app setting */
+ for (i = 0; i < APP_STYPE_MAX + 1; ++i) {
+ if (svTrueValue (ifcfg, app_subtype_array[i], FALSE)) {
+ app_subtype = i;
+ g_object_set (s_dcb, NM_SETTING_DCB_APP_SUBTYPE, app_subtype, NULL);
+
+ dcb_get_eaw (ifcfg, app_subtype_array[i], app_eaw);
+ g_object_set (s_dcb, NM_SETTING_DCB_APP_EAW, app_eaw, NULL);
+
+ if (!dcb_get_app_cfg (ifcfg, app_subtype_array[i], app_cfg))
+ g_object_set (s_dcb, NM_SETTING_DCB_APP_CFG, app_cfg, NULL);
+ else if (dcb_eaw_is_missing (app_eaw)) {
+ /* no eaw and no appcfg, invalid command */
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Invalid DCB setting. Both app eaw and appcfg are missing.");
+ goto error_return;
+ }else
+ g_object_set (s_dcb, NM_SETTING_DCB_APP_CFG, NULL, NULL);
+
+ break;
+ }
+ }
+
+ if (i == APP_STYPE_MAX + 1)
+ goto error_return;
+
+ /* priority group settings */
+ /* up2tc */
+ value = svGetValue (ifcfg, "DCB_PG_UP2TC", FALSE);
+ if (value && strlen (value) == 8) {
+ p = value;
+ for (i = 0; i < 8; ++i) {
+ if (*p >= 0) {
+ guint8 tmp = *p - 0x30;
+ g_array_append_val (pg_up2tc, tmp);
+ }
+ else
+ g_array_append_val (pg_up2tc, dcb_not_supplied);
+ p++;
+ }
+ } else {
+ dcb_initialize_array_not_supplied (pg_up2tc, DCB_MAX_USER_PRIORITIES);
+ }
+ g_object_set (s_dcb, NM_SETTING_DCB_PG_UP2TC, pg_up2tc, NULL);
+ g_free (value);
+
+ /* pgpct */
+ /* It is required. */
+ times = 0;
+ list = NULL;
+ value = svGetValue (ifcfg, "DCB_PG_PCT", FALSE);
+ /**
+ * make sure there are 8 integer which is bigger than 0 and
+ * smaller than 100 in this string
+ **/
+ if (value) {
+ list = g_strsplit_set (value, ",", 8);
+ for (iter = list; iter && *iter; iter++) {
+ guint16 percent = 0;
+ percent = strtol (*iter, (char **) NULL, 10);
+ if ((percent >= 0) && (percent <= 100))
+ times++;
+ }
+
+ if (times == 8) {
+ for (iter = list; iter && *iter; iter++) {
+ guint16 percent = 0;
+ percent = strtol (*iter, (char **) NULL, 10);
+ g_array_append_val (pg_pct, percent);
+ }
+ } else {
+ dcb_initialize_array_not_supplied (pg_pct, DCB_MAX_USER_PRIORITIES);
+ }
+ } else {
+ dcb_initialize_array_not_supplied (pg_pct, DCB_MAX_USER_PRIORITIES);
+ }
+ g_object_set (s_dcb, NM_SETTING_DCB_PG_PCT, pg_pct, NULL);
+ g_strfreev (list);
+ g_free (value);
+
+ /* pgid */
+ /* It is required. */
+ value = svGetValue (ifcfg, "DCB_PG_ID", FALSE);
+ if (value && strlen (value) == 8) {
+ p = value;
+ for (i = 0; i < 8; ++i) {
+ guint8 tmp = *p;
+ if (tmp != 'f' && tmp != 'F') {
+ tmp -= 0x30;
+ g_array_append_val (pg_pgid, tmp);
+ } else
+ g_array_append_val (pg_pgid, dcb_unlimited_priority_group);
+ p++;
+ }
+ } else {
+ dcb_initialize_array_not_supplied (pg_pgid, DCB_MAX_USER_PRIORITIES);
+ }
+ g_object_set (s_dcb, NM_SETTING_DCB_PG_PGID, pg_pgid, NULL);
+ g_free (value);
+
+ /* uppct */
+ times = 0;
+ list = NULL;
+ value = svGetValue (ifcfg, "DCB_PG_UPPCT", FALSE);
+ if (value) {
+ /* make sure there are 8 integer which is bigger than 0 and
+ * smaller than 100 in this string */
+ list = g_strsplit_set (value, ",", 8);
+ for (iter = list; iter && *iter; iter++) {
+ guint16 percent = 0;
+ percent = strtol (*iter, (char **) NULL, 10);
+ if ((percent >= 0) && (percent <= 100))
+ times++;
+ }
+ }
+
+ if (times == 8) {
+ for (iter = list; iter && *iter; iter++) {
+ guint16 percent = 0;
+ percent = strtol (*iter, (char **) NULL, 10);
+ g_array_append_val (pg_uppct, percent);
+ }
+ } else {
+ dcb_initialize_array_not_supplied (pg_uppct, DCB_MAX_USER_PRIORITIES);
+ }
+ g_object_set (s_dcb, NM_SETTING_DCB_PG_UPPCT, pg_uppct, NULL);
+ g_strfreev (list);
+ g_free (value);
+
+ /* strict */
+ value = svGetValue (ifcfg, "DCB_PG_STRICT", FALSE);
+ if (value && strlen (value) == 8) {
+ p = value;
+ for (i=0; i<8; ++i) {
+ if (*p >= 0) {
+ guint8 tmp = *p - 0x30;
+ g_array_append_val (pg_strict, tmp);
+ } else
+ g_array_append_val (pg_strict, dcb_not_supplied);
+ p++;
+ }
+ } else {
+ dcb_initialize_array_not_supplied (pg_strict, DCB_MAX_USER_PRIORITIES);
+ }
+ g_object_set (s_dcb, NM_SETTING_DCB_PG_STRICT, pg_strict, NULL);
+ g_free (value);
+
+ /* pg eaw */
+ pg_eaw = dcb_get_eaw (ifcfg, "DCB_PG", pg_eaw);
+ g_object_set (s_dcb, NM_SETTING_DCB_PG_EAW, pg_eaw, NULL);
+
+ /* priority flow control settings */
+ /* pfc eaw */
+ pfc_eaw = dcb_get_eaw (ifcfg, "DCB_PFC", pfc_eaw);
+ g_object_set (s_dcb, NM_SETTING_DCB_PFC_EAW, pfc_eaw, NULL);
+
+ /* pfcup */
+ value = svGetValue (ifcfg, "DCB_PFC_UP", FALSE);
+ if (value && strlen (value) == 8) {
+ p = value;
+ for (i = 0; i < 8; ++i) {
+ if (*p >= 0) {
+ guint8 tmp = *p - 0x30;
+ g_array_append_val (pfc_up, tmp);
+ } else
+ g_array_append_val (pfc_up, dcb_not_supplied);
+ p++;
+ }
+ g_object_set (s_dcb, NM_SETTING_DCB_PFC_UP, pfc_up, NULL);
+ } else if (dcb_eaw_is_missing (pfc_eaw)) {
+ /* no eaw and no pfcup, invalid command */
+ g_set_error (error, IFCFG_PLUGIN_ERROR, 0,
+ "Invalid DCB setting. Both pfc eaw and pfcup are missing.");
+ g_free (value);
+ goto error_return;
+ } else
+ g_object_set (s_dcb, NM_SETTING_DCB_PFC_UP, NULL, NULL);
+
+ g_free (value);
+
+ return (NMSetting *) s_dcb;
+
+error_return:
+ g_object_unref (s_dcb);
+free_pfc_up:
+ g_array_free (pfc_up, TRUE);
+free_pg_strict:
+ g_array_free (pg_strict, TRUE);
+free_pg_uppct:
+ g_array_free (pg_uppct, TRUE);
+free_pg_pgid:
+ g_array_free (pg_pgid, TRUE);
+free_pg_pct:
+ g_array_free (pg_pct, TRUE);
+free_pg_up2tc:
+ g_array_free (pg_up2tc, TRUE);
+free_pfc_eaw:
+ g_array_free (pfc_eaw, TRUE);
+free_pg_eaw:
+ g_array_free (pg_eaw, TRUE);
+free_app_cfg:
+ g_array_free (app_cfg, TRUE);
+free_app_eaw:
+ g_array_free (app_eaw, TRUE);
+
+ return NULL;
+}
+
static gboolean
add_one_wep_key (shvarFile *ifcfg,
const char *shvar_key,
@@ -3924,7 +4337,7 @@ connection_from_file (const char *filename,
NMConnection *connection = NULL;
shvarFile *parsed;
char *type, *nmc = NULL, *bootproto, *tmp;
- NMSetting *s_ip4, *s_ip6;
+ NMSetting *s_ip4, *s_ip6, *s_dcb;
const char *ifcfg_name = NULL;
gboolean nm_controlled = TRUE;
gboolean can_disable_ip4 = FALSE;
@@ -4107,6 +4520,18 @@ connection_from_file (const char *filename,
} else if (s_ip4)
nm_connection_add_setting (connection, s_ip4);
+ tmp = svGetValue (parsed, "DCB", FALSE);
+ if (tmp && !strcasecmp (tmp, "on")) {
+ g_free (tmp);
+ s_dcb = make_dcb_setting (parsed, network_file, &error);
+ if (error) {
+ g_object_unref (connection);
+ connection = NULL;
+ goto done;
+ } else if (s_dcb)
+ nm_connection_add_setting (connection, s_dcb);
+ }
+
/* iSCSI / ibft connections are read-only since their settings are
* stored in NVRAM and can only be changed in BIOS.
*/
diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb
new file mode 100644
index 0000000..38870f8
--- /dev/null
+++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb
@@ -0,0 +1,35 @@
+TYPE=Ethernet
+DEVICE=eth0
+HWADDR=00:11:22:33:44:ee
+BOOTPROTO=none
+IPADDR=1.2.3.4
+PREFIX=24
+GATEWAY=1.1.1.1
+
+# dcb global switch
+# use DCB=off to turn it off
+DCB=on
+
+# application settings
+# It also supports DCB_APP_ISCSI_XXX and DCB_APP_FIP_XXX.
+DCB_APP_FCOE=yes
+DCB_APP_FCOE_CFG=08
+DCB_APP_FCOE_ENABLE=yes
+DCB_APP_FCOE_ADVERTISE=yes
+DCB_APP_FCOE_WILLING=yes
+
+# priority group settings
+DCB_PG_UP2TC=76543210
+DCB_PG_PCT=25,0,0,75,0,0,0,0
+DCB_PG_ID=0000111f
+DCB_PG_UPPCT=25,25,25,25,50,25,25,0
+DCB_PG_STRICT=01010101
+DCB_PG_ENABLE=yes
+DCB_PG_ADVERTISE=yes
+DCB_PG_WILLING=yes
+
+# priority flow control settings
+DCB_PFC_UP=00010000
+DCB_PFC_ENABLE=yes
+DCB_PFC_ADVERTISE=yes
+DCB_PFC_WILLING=no
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 62882a7..bbeb2bb 100644
--- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
+++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c
@@ -45,6 +45,7 @@
#include <nm-setting-cdma.h>
#include <nm-setting-serial.h>
#include <nm-setting-vlan.h>
+#include <nm-setting-dcb.h>
#include "nm-test-helpers.h"
@@ -12714,6 +12715,45 @@ test_write_infiniband (void)
g_object_unref (reread);
}
+#define TEST_IFCFG_DCB_INTERFACE TEST_IFCFG_DIR"/network-scripts/ifcfg-test-dcb"
+
+static void
+test_read_dcb_interface (void)
+{
+ NMConnection *connection;
+ char *unmanaged = NULL;
+ char *keyfile = NULL;
+ char *routefile = NULL;
+ char *route6file = NULL;
+ gboolean ignore_error = FALSE;
+ GError *error = NULL;
+ NMSettingDcb *s_dcb;
+
+ connection = connection_from_file (TEST_IFCFG_DCB_INTERFACE,
+ NULL,
+ TYPE_ETHERNET,
+ NULL,
+ &unmanaged,
+ &keyfile,
+ &routefile,
+ &route6file,
+ &error,
+ &ignore_error);
+
+ g_assert_no_error (error);
+ g_assert (connection != NULL);
+
+ g_free (unmanaged);
+ g_free (keyfile);
+ g_free (routefile);
+ g_free (route6file);
+ s_dcb = nm_connection_get_setting_dcb (connection);
+ g_assert (s_dcb);
+
+ nm_connection_dump(connection);
+ g_object_unref (connection);
+}
+
#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"
@@ -12739,6 +12779,9 @@ 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 ();
--
1.7.4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]