libnm-util: add NMSettingBridgePort
authorDan Williams <dcbw@redhat.com>
Mon, 29 Oct 2012 16:01:38 +0000 (11:01 -0500)
committerDan Williams <dcbw@redhat.com>
Fri, 30 Nov 2012 19:21:50 +0000 (13:21 -0600)
docs/api/generate-settings-spec.c
docs/libnm-util/libnm-util-docs.sgml
libnm-util/Makefile.am
libnm-util/libnm-util.ver
libnm-util/nm-connection.c
libnm-util/nm-connection.h
libnm-util/nm-setting-bridge-port.c [new file with mode: 0644]
libnm-util/nm-setting-bridge-port.h [new file with mode: 0644]

index 9363c45..a72abe4 100644 (file)
@@ -49,6 +49,7 @@
 #include <nm-setting-infiniband.h>
 #include <nm-setting-bond.h>
 #include <nm-setting-bridge.h>
+#include <nm-setting-bridge-port.h>
 #include <nm-setting-vlan.h>
 
 #include <nm-utils.h>
@@ -60,6 +61,7 @@ static SettingNewFunc funcs[] = {
        nm_setting_bluetooth_new,
        nm_setting_bond_new,
        nm_setting_bridge_new,
+       nm_setting_bridge_port_new,
        nm_setting_cdma_new,
        nm_setting_connection_new,
        nm_setting_gsm_new,
index cabc352..eaef262 100644 (file)
@@ -57,6 +57,7 @@
     <xi:include href="xml/nm-setting-wimax.xml"/>
     <xi:include href="xml/nm-setting-bond.xml"/>
     <xi:include href="xml/nm-setting-bridge.xml"/>
+    <xi:include href="xml/nm-setting-bridge-port.xml"/>
     <xi:include href="xml/nm-setting-infiniband.xml"/>
     <xi:include href="xml/nm-setting-vlan.xml"/>
     <xi:include href="xml/nm-setting-olpc-mesh.xml"/>
index 69f7e0d..bd1b3fc 100644 (file)
@@ -19,6 +19,7 @@ libnm_util_include_HEADERS =          \
        nm-setting-bluetooth.h          \
        nm-setting-bond.h               \
        nm-setting-bridge.h             \
+       nm-setting-bridge-port.h        \
        nm-setting-connection.h         \
        nm-setting-infiniband.h         \
        nm-setting-ip4-config.h         \
@@ -54,6 +55,7 @@ libnm_util_la_csources = \
        nm-setting-bluetooth.c          \
        nm-setting-bond.c               \
        nm-setting-bridge.c             \
+       nm-setting-bridge-port.c        \
        nm-setting-connection.c         \
        nm-setting-infiniband.c         \
        nm-setting-ip4-config.c         \
index 1f08615..e40531e 100644 (file)
@@ -19,6 +19,7 @@ global:
        nm_connection_get_setting_bluetooth;
        nm_connection_get_setting_bond;
        nm_connection_get_setting_bridge;
+       nm_connection_get_setting_bridge_port;
        nm_connection_get_setting_by_name;
        nm_connection_get_setting_cdma;
        nm_connection_get_setting_connection;
@@ -213,6 +214,13 @@ global:
        nm_setting_bridge_get_stp;
        nm_setting_bridge_get_type;
        nm_setting_bridge_new;
+       nm_setting_bridge_port_error_get_type;
+       nm_setting_bridge_port_error_quark;
+       nm_setting_bridge_port_get_hairpin_mode;
+       nm_setting_bridge_port_get_path_cost;
+       nm_setting_bridge_port_get_priority;
+       nm_setting_bridge_port_get_type;
+       nm_setting_bridge_port_new;
        nm_setting_cdma_error_get_type;
        nm_setting_cdma_error_quark;
        nm_setting_cdma_get_number;
index 481a015..47a9ec0 100644 (file)
@@ -50,6 +50,7 @@
 #include "nm-setting-olpc-mesh.h"
 #include "nm-setting-bond.h"
 #include "nm-setting-bridge.h"
+#include "nm-setting-bridge-port.h"
 #include "nm-setting-vlan.h"
 #include "nm-setting-serial.h"
 #include "nm-setting-gsm.h"
@@ -1590,6 +1591,23 @@ nm_connection_get_setting_wireless_security (NMConnection *connection)
        return (NMSettingWirelessSecurity *) nm_connection_get_setting (connection, NM_TYPE_SETTING_WIRELESS_SECURITY);
 }
 
+/**
+ * nm_connection_get_setting_bridge_port:
+ * @connection: the #NMConnection
+ *
+ * A shortcut to return any #NMSettingBridgePort the connection might contain.
+ *
+ * Returns: (transfer none): an #NMSettingBridgePort if the connection contains one, otherwise NULL
+ **/
+NMSettingBridgePort *
+nm_connection_get_setting_bridge_port (NMConnection *connection)
+{
+       g_return_val_if_fail (connection != NULL, NULL);
+       g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
+
+       return (NMSettingBridgePort *) nm_connection_get_setting (connection, NM_TYPE_SETTING_BRIDGE_PORT);
+}
+
 /**
  * nm_connection_get_setting_vlan:
  * @connection: the #NMConnection
index 74e9845..4d060cc 100644 (file)
@@ -34,6 +34,7 @@
 #include <nm-setting-bluetooth.h>
 #include <nm-setting-bond.h>
 #include <nm-setting-bridge.h>
+#include <nm-setting-bridge-port.h>
 #include <nm-setting-cdma.h>
 #include <nm-setting-connection.h>
 #include <nm-setting-gsm.h>
@@ -190,6 +191,7 @@ NMSetting8021x *           nm_connection_get_setting_802_1x            (NMConnec
 NMSettingBluetooth *       nm_connection_get_setting_bluetooth         (NMConnection *connection);
 NMSettingBond *            nm_connection_get_setting_bond              (NMConnection *connection);
 NMSettingBridge *          nm_connection_get_setting_bridge            (NMConnection *connection);
+NMSettingBridgePort *      nm_connection_get_setting_bridge_port       (NMConnection *connection);
 NMSettingCdma *            nm_connection_get_setting_cdma              (NMConnection *connection);
 NMSettingConnection *      nm_connection_get_setting_connection        (NMConnection *connection);
 NMSettingGsm *             nm_connection_get_setting_gsm               (NMConnection *connection);
diff --git a/libnm-util/nm-setting-bridge-port.c b/libnm-util/nm-setting-bridge-port.c
new file mode 100644 (file)
index 0000000..557349b
--- /dev/null
@@ -0,0 +1,281 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * Dan Williams <dcbw@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 <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <dbus/dbus-glib.h>
+
+#include "nm-setting-bridge-port.h"
+#include "nm-utils.h"
+#include "nm-utils-private.h"
+#include "nm-setting-private.h"
+
+/**
+ * SECTION:nm-setting-bridge-port
+ * @short_description: Describes connection properties for bridge ports
+ * @include: nm-setting-bridge-port.h
+ *
+ * The #NMSettingBridgePort object is a #NMSetting subclass that describes
+ * optional properties that apply to bridge ports.
+ **/
+
+/**
+ * nm_setting_bridge_port_error_quark:
+ *
+ * Registers an error quark for #NMSettingBridgePort if necessary.
+ *
+ * Returns: the error quark used for #NMSettingBridgePort errors.
+ **/
+GQuark
+nm_setting_bridge_port_error_quark (void)
+{
+       static GQuark quark;
+
+       if (G_UNLIKELY (!quark))
+               quark = g_quark_from_static_string ("nm-setting-bridge-port-error-quark");
+       return quark;
+}
+
+G_DEFINE_TYPE_WITH_CODE (NMSettingBridgePort, nm_setting_bridge_port, NM_TYPE_SETTING,
+                         _nm_register_setting (NM_SETTING_BRIDGE_PORT_SETTING_NAME,
+                                               g_define_type_id,
+                                               3,
+                                               NM_SETTING_BRIDGE_PORT_ERROR))
+NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE_PORT)
+
+#define NM_SETTING_BRIDGE_PORT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortPrivate))
+
+typedef struct {
+       guint16 priority;
+       guint16 path_cost;
+       gboolean hairpin_mode;
+} NMSettingBridgePortPrivate;
+
+enum {
+       PROP_0,
+       PROP_PRIORITY,
+       PROP_PATH_COST,
+       PROP_HAIRPIN_MODE,
+       LAST_PROP
+};
+
+/**************************************************************************/
+
+/**
+ * nm_setting_bridge_port_get_priority
+ * @setting: the #NMSettingBridgePort
+ *
+ * Returns: the #NMSettingBridgePort:priority property of the setting
+ **/
+guint16
+nm_setting_bridge_port_get_priority (NMSettingBridgePort *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), 0);
+
+       return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->priority;
+}
+
+/**
+ * nm_setting_bridge_port_get_path_cost
+ * @setting: the #NMSettingBridgePort
+ *
+ * Returns: the #NMSettingBridgePort:path-cost property of the setting
+ **/
+guint16
+nm_setting_bridge_port_get_path_cost (NMSettingBridgePort *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), 0);
+
+       return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->path_cost;
+}
+
+/**
+ * nm_setting_bridge_port_get_hairpin_mode
+ * @setting: the #NMSettingBridgePort
+ *
+ * Returns: the #NMSettingBridgePort:hairpin-mode property of the setting
+ **/
+gboolean
+nm_setting_bridge_port_get_hairpin_mode (NMSettingBridgePort *setting)
+{
+       g_return_val_if_fail (NM_IS_SETTING_BRIDGE_PORT (setting), FALSE);
+
+       return NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting)->hairpin_mode;
+}
+
+/**************************************************************************/
+
+#define BR_MAX_PORT_PRIORITY 63
+#define BR_DEF_PRIORITY      32
+
+#define BR_MIN_PATH_COST     1
+#define BR_MAX_PATH_COST     65535
+
+static gboolean
+verify (NMSetting *setting, GSList *all_settings, GError **error)
+{
+       NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting);
+
+       if (priv->priority > BR_MAX_PORT_PRIORITY) {
+               g_set_error (error,
+                            NM_SETTING_BRIDGE_PORT_ERROR,
+                            NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY,
+                            NM_SETTING_BRIDGE_PORT_PRIORITY);
+               return FALSE;
+       }
+
+       if (priv->path_cost > BR_MAX_PATH_COST) {
+               g_set_error (error,
+                            NM_SETTING_BRIDGE_PORT_ERROR,
+                            NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY,
+                            NM_SETTING_BRIDGE_PORT_PATH_COST);
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+/**************************************************************************/
+
+/**
+ * nm_setting_bridge_port_new:
+ *
+ * Creates a new #NMSettingBridgePort object with default values.
+ *
+ * Returns: (transfer full): the new empty #NMSettingBridgePort object
+ **/
+NMSetting *
+nm_setting_bridge_port_new (void)
+{
+       return (NMSetting *) g_object_new (NM_TYPE_SETTING_BRIDGE_PORT, NULL);
+}
+
+static void
+nm_setting_bridge_port_init (NMSettingBridgePort *setting)
+{
+       g_object_set (setting, NM_SETTING_NAME, NM_SETTING_BRIDGE_PORT_SETTING_NAME, NULL);
+}
+
+static void
+set_property (GObject *object, guint prop_id,
+              const GValue *value, GParamSpec *pspec)
+{
+       NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (object);
+
+       switch (prop_id) {
+       case PROP_PRIORITY:
+               priv->priority = (guint16) (g_value_get_uint (value) & 0xFFFF);
+               break;
+       case PROP_PATH_COST:
+               priv->path_cost = (guint16) (g_value_get_uint (value) & 0xFFFF);
+               break;
+       case PROP_HAIRPIN_MODE:
+               priv->hairpin_mode = g_value_get_boolean (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)
+{
+       NMSettingBridgePortPrivate *priv = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (object);
+
+       switch (prop_id) {
+       case PROP_PRIORITY:
+               g_value_set_uint (value, priv->priority);
+               break;
+       case PROP_PATH_COST:
+               g_value_set_uint (value, priv->path_cost);
+               break;
+       case PROP_HAIRPIN_MODE:
+               g_value_set_boolean (value, priv->hairpin_mode);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+static void
+nm_setting_bridge_port_class_init (NMSettingBridgePortClass *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 (NMSettingBridgePortPrivate));
+
+       /* virtual methods */
+       object_class->set_property = set_property;
+       object_class->get_property = get_property;
+       parent_class->verify       = verify;
+
+       /* Properties */
+       /**
+        * NMSettingBridgePort:priority:
+        *
+        * The Spanning Tree Protocol (STP) priority of this bridge port.
+        **/
+       g_object_class_install_property
+               (object_class, PROP_PRIORITY,
+                g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PRIORITY,
+                                   "Priority",
+                                   "The Spanning Tree Protocol (STP) priority of this bridge port",
+                                   0, BR_MAX_PORT_PRIORITY, BR_DEF_PRIORITY,
+                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
+
+       /**
+        * NMSettingBridgePort:path-cost:
+        *
+        * The Spanning Tree Protocol (STP) port cost for destinations via this port.
+        **/
+        g_object_class_install_property
+                (object_class, PROP_PATH_COST,
+                g_param_spec_uint (NM_SETTING_BRIDGE_PORT_PATH_COST,
+                                   "Path Cost",
+                                   "The Spanning Tree Protocol (STP) port cost for "
+                                   "destinations via this port.",
+                                   0, BR_MAX_PATH_COST, 100,
+                                   G_PARAM_READWRITE | G_PARAM_CONSTRUCT | NM_SETTING_PARAM_SERIALIZE));
+
+       /**
+        * NMSettingBridgePort:hairpin-mode:
+        *
+        * Enables or disabled 'hairpin mode' for the port, which allows frames to
+        * be sent back out through the port the frame was received on.
+        **/
+        g_object_class_install_property
+                (object_class, PROP_HAIRPIN_MODE,
+                g_param_spec_boolean (NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE,
+                                      "Hairpin Mode",
+                                      "Enables or disabled 'hairpin mode' for the "
+                                      "port, which allows frames to be sent back out "
+                                      "through the port the frame was received on.",
+                                      FALSE,
+                                      G_PARAM_READWRITE | NM_SETTING_PARAM_SERIALIZE));
+
+}
diff --git a/libnm-util/nm-setting-bridge-port.h b/libnm-util/nm-setting-bridge-port.h
new file mode 100644 (file)
index 0000000..5123f0a
--- /dev/null
@@ -0,0 +1,86 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+
+/*
+ * Dan Williams <dcbw@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_BRIDGE_PORT_H
+#define NM_SETTING_BRIDGE_PORT_H
+
+#include <nm-setting.h>
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_SETTING_BRIDGE_PORT            (nm_setting_bridge_port_get_type ())
+#define NM_SETTING_BRIDGE_PORT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePort))
+#define NM_SETTING_BRIDGE_PORT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortClass))
+#define NM_IS_SETTING_BRIDGE_PORT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_SETTING_BRIDGE_PORT))
+#define NM_IS_SETTING_BRIDGE_PORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_SETTING_BRIDGE_PORT))
+#define NM_SETTING_BRIDGE_PORT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_SETTING_BRIDGE_PORT, NMSettingBridgePortClass))
+
+#define NM_SETTING_BRIDGE_PORT_SETTING_NAME "bridge-port"
+
+/**
+ * NMSettingBridgePortError:
+ * @NM_SETTING_BRIDGE_PORT_ERROR_UNKNOWN: unknown or unclassified error
+ * @NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY: the property was invalid
+ * @NM_SETTING_BRIDGE_PORT_ERROR_MISSING_PROPERTY: the property was missing and
+ * is required
+ */
+typedef enum {
+       NM_SETTING_BRIDGE_PORT_ERROR_UNKNOWN = 0,      /*< nick=UnknownError >*/
+       NM_SETTING_BRIDGE_PORT_ERROR_INVALID_PROPERTY, /*< nick=InvalidProperty >*/
+       NM_SETTING_BRIDGE_PORT_ERROR_MISSING_PROPERTY, /*< nick=MissingProperty >*/
+} NMSettingBridgePortError;
+
+#define NM_SETTING_BRIDGE_PORT_ERROR nm_setting_bridge_port_error_quark ()
+GQuark nm_setting_bridge_port_error_quark (void);
+
+#define NM_SETTING_BRIDGE_PORT_PRIORITY     "priority"
+#define NM_SETTING_BRIDGE_PORT_PATH_COST    "path-cost"
+#define NM_SETTING_BRIDGE_PORT_HAIRPIN_MODE "hairpin-mode"
+
+typedef struct {
+       NMSetting parent;
+} NMSettingBridgePort;
+
+typedef struct {
+       NMSettingClass parent;
+
+       /* Padding for future expansion */
+       void (*_reserved1) (void);
+       void (*_reserved2) (void);
+       void (*_reserved3) (void);
+       void (*_reserved4) (void);
+} NMSettingBridgePortClass;
+
+GType nm_setting_bridge_port_get_type (void);
+
+NMSetting * nm_setting_bridge_port_new              (void);
+
+guint16     nm_setting_bridge_port_get_priority     (NMSettingBridgePort *setting);
+
+guint16     nm_setting_bridge_port_get_path_cost    (NMSettingBridgePort *setting);
+
+gboolean    nm_setting_bridge_port_get_hairpin_mode (NMSettingBridgePort *setting);
+
+G_END_DECLS
+
+#endif /* NM_SETTING_BRIDGE_PORT_H */